Download MetaTrader 5

Are all the candles built.

To add comments, please log in or register
mmcspadd
11
mmcspadd  

I have created an indicator that runs only once a day.  After that, the lines can be moved at the discretion of the trader.  The problem I am having is that if the computer goes to sleep, or the trading platform is closed, the indicator runs before all the data is available for analysis.  Is there anyway to determine if the most current data is available before the indicator runs.  So far I have tried many options the latest of which is:

int OnInit()

  {

   if(TimeDay(Time[0])!=TimeDay(TimeCurrent()) && TimeHour(Time[0]) != TimeHour(TimeCurrent()) && TimeMonth(Time[0]) != TimeMonth(TimeCurrent()))

   {

      return(false);

   }

Any ideas?


whroeder1
15902
whroeder1  
mmcspadd Is there anyway to determine if the most current data is available before the indicator runs.
No test required. The chart always has the current data when OnCalculate runs.
Keith Watford
Moderator
10652
Keith Watford  

Never do any calculations that rely on data in OnInit.

If all calculations are with the current chart and timeframe, you may be able to simply check prev_calculated. If it updates more than the current bar, it will return 0, so you know to re-calculate.

whroeder1
15902
whroeder1  
Keith Watford: If it updates more than the current bar, it will return 0, so you know to re-calculate.
Exactly. See How to do your lookbacks correctly.
mmcspadd
11
mmcspadd  
Thanks.  It makes sense not to check on candle data in the init.  I had moved it there from the OnCalculate function so that I could get the latest server time.  In order to run the indi only once a day, at new york open, I set a global variable to day ran.  The global variable is correct, read in an error file, but the latest candles are not used.  If the platform has run continuously, the calculations are correct. prev_calculated is a good idea.  I will give it a try.
To add comments, please log in or register