Download MetaTrader 5

Need help with mql. PERIOD_D1 and weird behaviour

To add comments, please log in or register
Foed
71
Foed  

Hello guys,

I need advice. I have never met with anything like this. I have EA, where in code I have this ( Im using high of previous day in my calculation)


[source]

 if(den==0) // for historical reason, all is same
      {
            y_high=iHigh(Symbol(),PERIOD_D1,1);//previous day
            y_low=iLow(Symbol(),PERIOD_D1,1); //previous day
      }
      else if(den==1) // for historical reason, all is same
      {
            y_high=iHigh(Symbol(),PERIOD_D1,1); //previous day
            y_low=iLow(Symbol(),PERIOD_D1,1); //previous day
      }
      else // for historical reason, all is same
      {
            y_high=iHigh(Symbol(),PERIOD_D1,1); //previous day
            y_low=iLow(Symbol(),PERIOD_D1,1); //previous day
      }


[source]

Im using it for DAX. I have two brokers - one with night session (u can trade at night) and another one where I can trade only since 8am til 22 pm.

So my problem is that this code is not taking "yesterdays" high, but its taking high of 2 - 3  days before. On monday it took high of thursday of last week. On wednesday it took mondays high.

Im working with yesterday's high 5 minuts after market opens, so my problem can not be caused beacause of - like "Todays is not yte even a tick, so PERIOD_D1 is not yesterday but yesterday-1. EA is on H1 TF.

While backtesting in MT4 everything is fine and ok, but on DEMO account with live data, its causing my problem.

Im really confused. Im programmer a little bit, but this is ridiculous.

Could anyone help me please? Sorry for my english.

Ex Ovo Omnia
3355
Ex Ovo Omnia  

Have either an additional D1 chart open (may be minimized),

or call iBars(Symbol(),PERIOD_D1) a couple of minutes before you call the iHigh.

Foed
71
Foed  

What should it suppose to do? iBARS returns only number of bars right?

Why to have opened D1 graph? Do you think it will recalucate and will it help? Ill give it try. Thank you

Ex Ovo Omnia
3355
Ex Ovo Omnia  
It only triggers the asynchronous chart fetch, you do not need to care about the return value.
Foed
71
Foed  
ok, lets see on monday. Thank you very much.
whroeder1
16076
whroeder1  
Ex Ovo Omnia
3355
Ex Ovo Omnia  
I wrote it here several times here - ERR_HISTORY_WILL_UPDATED does not signal the history state is (or is not) ready, but rather it signals the last command initiated asynchronous chart download. 
whroeder1
16076
whroeder1  
And if you had looked at my code you would have seen that it loops until the "asynchronous chart download" has downloaded.
Ex Ovo Omnia
3355
Ex Ovo Omnia  
WHRoeder:
And if you had looked at my code you would have seen that it loops until the "asynchronous chart download" has downloaded.

Ok, disregard my remark., my fault, sometimes it happens to me. Anyway, I noticed that the correct zero index candle time seemed to be present even if the rest of the chart, i.e. indexes >=1 were still missing, so not sure if it was 100% reliable.

To add comments, please log in or register