Help to refresh iHigh data from MT4 to .CSV

 

Hi Guys,


So I have been trying to export basic price data into a .csv format from MT4.

Basically what im trying to achieve is to get the range of a particular bar at a particular time of day each day that runs in the strategy tester. IE iHigh - iLow @ 9am each day populate that into a .csv on a separate column for each day.

I can get MT4 to print in the journal what each days range was for a particular bar but cant get the formula to work into excel.


Attached is a photo of what it looks like coming out into excel and my code below.



void OnTick()
  {
  string var1=TimeToStr(TimeCurrent(),TIME_MINUTES);
   
   
   
   double high = iHigh(NULL,0,1);
   double low = iLow(NULL,0,1);
   
    
   
   double Range = high - low;
   NormalizeDouble (Range,5);
   
   
   if (var1=="10:00")
      {
      Print(DoubleToStr(Range,5));
      }
      
   int filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV); 
   if(filehandle!=INVALID_HANDLE) 
     { 
      for(int i=0; i<100; i++)
      {
      
      
      FileWrite(filehandle,Range+"\n");
      
      }
      FileClose(filehandle); 
      //Print("FileOpen OK"); 
      
     } 
   else Print("Operation FileOpen failed, error ",GetLastError());
 
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   static datetime preTime=0,curTime=0,cur;
   if(preTime!=(curTime=iTime(_Symbol,PERIOD_M1,0)))
     
     {
      static MqlDateTime dt;
      cur=TimeCurrent();
      TimeToStruct(cur,dt);
      
      if(dt.hour==10 && dt.min==0)
        {
         string var1=TimeToString(cur,TIME_MINUTES);
         
         double high = iHigh(NULL,0,1);
         double low = iLow(NULL,0,1);
         
         double Range = high - low;
         NormalizeDouble (Range,5);
         
         if (var1=="10:00")
            {
            Print(DoubleToString(Range,5));
            }
            
         int filehandle=FileOpen("fractals.csv",FILE_READ|FILE_WRITE|FILE_CSV); 
         if(filehandle!=INVALID_HANDLE) 
           { 
            //for(int i=0; i<100; i++)
            //{
            while(!FileIsEnding(filehandle))
               FileReadString(filehandle);
               
            FileWrite(filehandle,TimeToString(cur,TIME_DATE|TIME_MINUTES)+","+DoubleToString(Range,5));
            //}
            FileClose(filehandle); 
            //Print("FileOpen OK"); 
            
           } 
         else Print("Operation FileOpen failed, error ",GetLastError());
        }
      
      preTime=curTime;   
     }

  }
//+------------------------------------------------------------------+
 
Hi Ernst,

Is this code for MQL4? It looks like MQL5 but I am quite the amateur coder so I may well be wrong
 
Ichimoku Trader:
Hi Ernst,

Is this code for MQL4? It looks like MQL5 but I am quite the amateur coder so I may well be wrong

Hi,

For MQL4, yes.

Edit: compatible with both now.
 
Ernst Van Der Merwe:

Hi,

For MQL4, yes.

Thanks Ernst, the code works perfectly, I will read through what you have done and understand it for the future. Thank you for your help it is much appreciated.

Reason: