Runs once new day starts

 

Hi all,

I have a function to store some daily data and this need to be refresh once a new day starts.

My EA is put on 1H chart

How to go about doing so?

Thanks

 

use something like

static datetime currentDay = 0
...
  bool newDayStarted = false;
  if(currentDay != iTime(NULL, PERIOD_D1, 0))
  {
    newDayStarted = true;
    currentDay != iTime(NULL, PERIOD_D1, 0)
  }

code just typed; not checked or compiled, etc

 
thanks, will KIV and test the code
 
bool NewDay()
{
   static datetime PrevDay;

   if(PrevDay < iTime(NULL, PERIOD_D1, 0))
   {
      PrevDay = iTime(NULL, PERIOD_D1, 0);
      return(true);
   }
   else
   {
      return(false);
   }
}
correct code should be this?
 
if(PrevDay < iTime(NULL, PERIOD_D1, 0))

will fail to recalc for indicator on refresh that restarts from oldest bar. That why I used '!=' not equal

 
brewmanz:

will fail to recalc for indicator on refresh that restarts from oldest bar. That why I used '!=' not equal


Sorry, I don't get what you mean. Please explain more.
 

(the following is my understanding anyway)

Let's say that you do a Refresh to update some missing bars.

Then deinit(), init(), and start (with IndicatorCounted() of 0) will happen.

Any variables set up/initialised in init() will be just fine.

However, static variables will NOT be initialised again, so a check of PrevDay against iTime will not trigger recalcs, as Prevday will be never be lower than any bars, until a new latest bar is created

 
brewmanz:

(the following is my understanding anyway)

Let's say that you do a Refresh to update some missing bars.

Then deinit(), init(), and start (with IndicatorCounted() of 0) will happen.

Any variables set up/initialised in init() will be just fine.

However, static variables will NOT be initialised again, so a check of PrevDay against iTime will not trigger recalcs, as Prevday will be never be lower than any bars, until a new latest bar is created

I understand you now.

Thanks for the information.

 
brewmanz:

use something like

code just typed; not checked or compiled, etc

currentDay != iTime(NULL, PERIOD_D1, 0)

here is type error. fix it. there should be = instead o f !=