If local history is empty (not loaded), function returns 0. what does it mean ?

 

Hi,

I made a script which uses Open[i] and now I want to replace with iOpen(symbol,period,i) but it returns 0. I don't understand the help which says:

If local history is empty (not loaded), function returns 0. what does it mean ?

Thanks.

 

I assume you are using the backtester.

So go into history centre.

Select the symbol you are attempting to test and check that there is data for the period you wish to use.

Note that the backtester can only work with one symbol per test run.

CB

 
forexgenuine:

Hi,

I made a script which uses Open[i] and now I want to replace with iOpen(symbol,period,i) but it returns 0. I don't understand the help which says:

If local history is empty (not loaded), function returns 0. what does it mean ?

Thanks.

If you have never viewed a chart of that pair and that period there will be no history for that pair. Open a chart for that pair and just click through the timeframes. Let the chart update each time. This will download history data from your broker.
 
dabbler:
If you have never viewed a chart of that pair and that period there will be no history for that pair. Open a chart for that pair and just click through the timeframes. Let the chart update each time. This will download history data from your broker.

Hello,

@dabbler I have all charts opened in current profile: I have viewed them so why would iOpen gives zero, why would I also need to open history ? I want to loop through all symbols and periods to export them programmatically and not by hand, is it impossible ?

Here's my script which works except if I use iOpen:

//+------------------------------------------------------------------+
//|                                                       Export.mq4 |
//|                                                     Forexgenuine |
//|                                          http://forexgenuine.com |
//+------------------------------------------------------------------+
#property copyright "Forexgenuine"
#property link      "http://forexgenuine.com"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   string symbol = StringSubstr(Symbol(),0,6);
   string period = Period();
   int handle = FileOpen(symbol + period + ".csv", FILE_CSV|FILE_WRITE, ";");
   if(handle>0)
   {
      // table column headers recording
      FileWrite(handle, "Time;Open;High;Low;Close;Volume");
      // data recording
      MessageBox(Bars);
      for(int i=Bars; i>0; i--) {
       datetime t = Time[i];
       int year = TimeYear(t);
       if (year > 1970) {
         // int day = TimeDay(t);
         // int month = TimeMonth(t);
         // int hour = TimeHour(t);
         // int minute = TimeMinute(t);
         // int seconds = TimeMinute(t);
         string strdatetime = TimeToStr(t);
         strdatetime = StringSetChar(strdatetime,4,'-');
         strdatetime = StringSetChar(strdatetime,7,'-');
         
         // double Open_i = Open[i];
         double Open_i = iOpen(symbol,period,i);
         double High_i = High[i];
         double Low_i = Low[i];
         double Close_i = Close[i];
         double Volume_i = Volume[i];
         
         //FileWrite(handle, year + "-" + month + "-" + month + " " + hour + ":" + minute + ":" + seconds, Open[i], High[i], Low[i], Close[i], Volume[i]);
         FileWrite(handle, strdatetime, Open_i, High_i, Low_i, Close_i, Volume_i);
         
       }
      }
      FileClose(handle);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
if your broker uses some postfix (for example EURUSDm order EURUSD.) or something with more letters than 6, your script will not work since you use the trunkated symbol instead of Symbol()
 
forexgenuine:

Hello,

@dabbler I have all charts opened in current profile: I have viewed them so why would iOpen gives zero, why would I also need to open history ? I want to loop through all symbols and periods to export them programmatically and not by hand, is it impossible ?

Here's my script which works except if I use iOpen:

Well the problem may be the MLQ4 error checking!

double iOpen( string symbol, int timeframe, int shift)


You put timeframe as a string when it should be an int. The compiler just coerces data types rather than flagging errors. Note that the function Period() also returns type int.

Watch your data types and you will be fine :-)

Happy coding.

 
dabbler:

Well the problem may be the MLQ4 error checking!

double iOpen( string symbol, int timeframe, int shift)


You put timeframe as a string when it should be an int. The compiler just coerces data types rather than flagging errors. Note that the function Period() also returns type int.

Watch your data types and you will be fine :-)

Happy coding.


@zzuegg dabbler thanks so much guys now it works perfect :)


Reason: