Download MetaTrader 5

Write to file on OnCalculate() event

To add comments, please log in or register
mauro21pl
8
mauro21pl  

Hi traders

I am currently in the middle of programming in mql5, and I got stuck on saving data into a .csv file upon every tick. This kind of does not make sense. I know I have the right syntax for writing to the file, and I know that the method is being executed on every tick, however, in 'Strategy Testing' the method does not update the csv file. Would you guys know what I am missing. In short the question is how to output custom data into external csv file, lets say on every tick through custom OnCalculate() event.


When I do

Comment(PriceDistanceFromKijunSenInPipsH1);

in method below, within 'Strategy Tester' the chart is being updated with correct value, however that value is not being updated into csv file. I also able to see the 'FileOpen OK' message, which means that the method is being executed successfully, and the file is being open successfully as well (every tick).

For simplicity I I simple update the file, however the end goal will be to append my calculations into csv file on every tick or so


Here is my method

//+------------------------------------------------------------------+
//| Indicator iteration function                                     |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   
      Comment(PriceDistanceFromKijunSenInPipsH1);

      //WriteToFile();
       int filehandle=FileOpen("fractals3.csv",FILE_WRITE|FILE_READ|FILE_CSV|FILE_SHARE_READ|FILE_ACCESS_DATE|FILE_IS_WRITABLE|FILE_IS_READABLE);
   if(filehandle!=INVALID_HANDLE)
     {
      FileWrite(filehandle,TimeCurrent()," - ",Symbol()," - ",PERIOD_CURRENT,PriceDistanceFromKijunSenInPipsH1 );
      FileClose(filehandle);
      Print(PriceDistanceFromKijunSenInPipsH1);
      Print("FileOpen OK");
     }    
   
   return(rates_total);
  }
Rodrigo Malacarne
Moderator
10572
Rodrigo Malacarne  
mauro21pl:

Hi traders

Here is my method

Hello Mauro, welcome to the MQL5.com forum!

Please take a look at this topic. I believe your file could be located inside the "tester" directory under Agent... \MQL5\Files. Please take a look at the tester directory and tell us if you found the file.

I hope it helps,
Malacarne

To add comments, please log in or register