Wrong values accessing previous candle low

 

I need your help with this particular bug i am facing

1. I am building a EA using MQL4 the ea place Stop orders at the low and high of the previous day candles depending on bullish or bearish candle,

2. The trade will be only places when the new candle is open to achieve this i am using the following code.

static datetime bar_time=0;
void OnTick(){

   if(bar_time!=Time[0])
     {
      bar_time=Time[0];

3. The EA is attached to EURUSD chart

4. I am trading all the currencies present in market watch using the following code.

   for(int i =0; i< SymbolsTotal(true); i++){

5. I am accessing the previous day low and high using the following code

OrderSend(SymbolName(i,true),OP_SELLSTOP,0.01,(iLow(SymbolName(i,true),PERIOD_H4,1)),1,(iHigh(SymbolName(i,true),PERIOD_H4,1)),0,"",4,0,clrGreen);  
               

6. The problem i am facing is the ea is accessing low and high of EURUSD properly which the chart EA is attached to rest all the currencies they before yesterdays low and high is being used this is the bug. For all the currencies last day low and high need to be used please help.

 
ROYAL ARWIN DSOUZA:

I need your help with this particular bug i am facing

1. I am building a EA using MQL4 the ea place Stop orders at the low and high of the previous day candles depending on bullish or bearish candle,

2. The trade will be only places when the new candle is open to achieve this i am using the following code.

3. The EA is attached to EURUSD chart

4. I am trading all the currencies present in market watch using the following code.

5. I am accessing the previous day low and high using the following code

6. The problem i am facing is the ea is accessing low and high of EURUSD properly which the chart EA is attached to rest all the currencies they before yesterdays low and high is being used this is the bug. For all the currencies last day low and high need to be used please help.

EURUSD_high = iHigh( SymbolName(i,true), PERIOD_D1, 1);

try something like this https://docs.mql4.com/series/ihigh

but note: the symbol needs to be shown to get the value, if you are trading multiple currencies be sure to enable the ones you are using
iHigh - Timeseries and Indicators Access - MQL4 Reference
iHigh - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
High value for the bar of specified symbol with timeframe and shift. If local history is empty (not loaded), function returns 0. To check errors, one has to call the GetLastError() function.
 

Thank you for the reply.

I am using iHigh and iLow please look at the code in Sl No. 5
I am only accesing the values which are present in Market watch please look at the code in sl no 4.

 
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
 
Thank You william that was really helpful. I got the problem and i fixed it
Reason: