Spread recorder

Created at 08 May 2014, 17:38
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
TE

tete13

Joined 06.05.2014

Spread recorder
08 May 2014, 17:38


I found that MT4 has a very useful indicator named "Spread recorder". This indicator will record spread in a text file when we attach it to selected chart.

Detail : http://www.forexfactory.com/showthread.php?t=195290

 

MQL4 code for reference

#property copyright "Zen_Leow"
#property link      ""
#property indicator_chart_window

#include <stdlib.mqh>
#include <stderror.mqh>


string msg = "";
double CustomSpread = 0;
double LastKnownSpread = 0;
int PipFactor = 1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   // Cater for fractional pips
   if (Digits == 3 || Digits == 5)
   {
      PipFactor = 10;
   }
   GetSpread();

   msg = "";
   WriteToLogFile(msg);
   
   LastKnownSpread = CustomSpread;
   WriteMessage();
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }

void WriteMessage()
{
   msg = "Ask: "+DoubleToStr(Ask,Digits)+" | Bid: "+DoubleToStr(Bid,Digits)+" | Spread: "+DoubleToStr(CustomSpread,2)+" pips";
   WriteToLogFile(msg);
}

void GetSpread()
{
   CustomSpread = (MarketInfo(Symbol(),MODE_SPREAD)) / PipFactor;
}

void WriteToLogFile(string input)
{
   string filename = "Spread_Recording/"+Symbol()+"-Spread_Recorder-"+Day()+"-"+Month()+"-"+Year()+".log";
   input = TimeHour(TimeCurrent())+":"+TimeMinute(TimeCurrent())+":"+TimeSeconds(TimeCurrent())+" - "+input;
   int handle = FileOpen(filename,FILE_READ|FILE_WRITE);
   if (handle>1)
   {
      FileSeek(handle, 0, SEEK_END); // go to end of file
      FileWrite(handle, input);
      FileClose(handle);
   }
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
//----
   GetSpread();
   if (CustomSpread != LastKnownSpread)
   {
      WriteMessage();
   }
   LastKnownSpread = CustomSpread;
//----
   return(0);
}
//+------------------------------------------------------------------+

Can you guys write the same indicator for cTrader?

Many thanks!


@tete13