Using another curreny's data in EA - page 2

 

Trying to handle errors 4066/4073 I used the Comment function to fetch values for iBarShift and iTime for other Symbols and timeframes.

When accessing price data for another symbol/TF that has not been updated, for example iTime returns 2019.01.01 (expected) but iBarshift sometimes returns 0 or -1.

I can not find the answer to this problem as I would expect iBarshift to always return -1 if the chart is not updated.

I have also tried the request data from another symbols, sleep for 5 seconds and re request again, but in some cases some charts were returning non updated price values.

I don't want to increase the time for sleep as that would slow down the EA.

string symbol[]={"EURJPY","GBPUSD",...,"USDCHF"};//10 symbols
string timeframe[]={...};//10 timeframes

struct signals
  {
   string               breakout;
  };
signals Symbols[9];




OnTimer()//it runs every 1 second.
{
//If it is a new day RESET StoreSymbols
   DayNow=TimeToStr(TimeCurrent(),TIME_DATE);

   if(DayNow!=DayUpdated)
     {
      for(int y=0; y<10; y++)
        {
         Symbols[y].breakout=NULL;
        }
      DayUpdated=DayNow;
     }

 for(int y=0; y<10; y++)
        {

         if(Symbols[y].breakout=="SELL" || Symbols[y].breakout==NULL)
            if(last_price(y)>GetDAILYhighs(y))
                if(iBarShift(symbol[y],(int)timeframe[y],TimeCurrent(),true)!=-1)//or set it to ==0
                 {
                  SendMail("BREAKOUT signal","Current price is ABOVE previous daily highs. "+symbol[y]+" "+"Period: "+FixTimeFrameDisplay(y)+"  "+TimeToString(TimeCurrent()));
                  SendNotification("Current price is ABOVE previous daily highs. "+symbol[y]+" "+"Period: "+FixTimeFrameDisplay(y)+"  "+TimeToString(TimeCurrent()));
                  Alert("Current price is ABOVE previous daily highs. "+symbol[y]+" "+"Period: "+FixTimeFrameDisplay(y)+"  "+TimeToString(TimeCurrent()));
                  Symbols[y].breakout="BUY";
                 }

         if(Symbols[y].breakout=="BUY" || Symbols[y].breakout==NULL)
            if(last_price(y)<GetDAILYlows(y))
                if(iBarShift(symbol[y],(int)timeframe[y],TimeCurrent(),true)!=-1)//or set it to ==0
                 {
                  SendMail("BREAKOUT signal","Current price is BELOW previous daily lows. "+symbol[y]+" "+"Period: "+FixTimeFrameDisplay(y)+"  "+TimeToString(TimeCurrent()));
                  SendNotification("Current price is BELOW previous daily lows. "+symbol[y]+" "+"Period: "+FixTimeFrameDisplay(y)+"  "+TimeToString(TimeCurrent()));
                  Alert("Current price is BELOW previous daily lows. "+symbol[y]+" "+"Period: "+FixTimeFrameDisplay(y)+"  "+TimeToString(TimeCurrent()));
                  Symbols[y].breakout="SELL";
                 }
        }
}
//+------------------------------------------------------------------+
double last_price(int y)
  {
   double close;
   close=iClose(symbol[y],1440,iBarShift(symbol[y],1440,TimeCurrent(),true));

   return(close);
  }
//+------------------------------------------------------------------+
double GetDAILYhighs(int y)
  {
   double high;
   high=iHigh(symbol[y],1440,iBarShift(symbol[y],1440,TimeCurrent()-1440*60,true));

   return(high);
  }
//+------------------------------------------------------------------+
double GetDAILYlows(int y)
  {
   double low;
   low=iLow(symbol[y],1440,iBarShift(symbol[y],1440,TimeCurrent()-1440*60,true));

   return(low);
  }
//+------------------------------------------------------------------+
Documentation on MQL5: Common Functions / Comment
Documentation on MQL5: Common Functions / Comment
  • www.mql5.com
[in]   Any values, separated by commas. To delimit output information into several lines, a line break symbol "\n" or "\r\n" is used. Number of parameters cannot exceed 64. Total length of the input comment (including invisible symbols) cannot exceed 2045 characters (excess symbols will be cut out during output). Data of double type are output...
 

Forgot to add it but DayNow and DayUpdated are globally declared string variables.

EDIT: Alright, I found the error.

if(iBarShift(symbol[y],(int)timeframe[y],TimeCurrent(),true)!=-1)

should be

 if(iBarShift(symbol[y],1440,TimeCurrent(),true)!=-1)


I will print values and report if iBarShift return -1 as expected.

 

So there seems to be a discrepancy between iTime and iBarShift.

When I requested price data for the EURNOK, which I never did before, iTime's date is 1970.01.01, which makes sense. But the iBarShift returns 0 when I was expecting -1.

  iTime and iBarshift 

 
Kevin Keena: Trying to handle errors 4066/4073

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

You haven't tried to handle anything. Go through your array of symbols/timeframes first and handle them.

 
Kevin Beltran Keena #:

Trying to handle errors 4066/4073 I used the Comment function to fetch values for iBarShift and iTime for other Symbols and timeframes.

When accessing price data for another symbol/TF that has not been updated, for example iTime returns 2019.01.01 (expected) but iBarshift sometimes returns 0 or -1.

I can not find the answer to this problem as I would expect iBarshift to always return -1 if the chart is not updated.

I have also tried the request data from another symbols, sleep for 5 seconds and re request again, but in some cases some charts were returning non updated price values.

I don't want to increase the time for sleep as that would slow down the EA.

Why Symbols array size 9 when operating on 10 symbols ?