Highs and lows of the past bars

 

In OnInit(), I need to learn which side (low or high) of a past bar generated firstly?

If I'm correct, there are no tick data for the past bars, so how can I do that?

Thanks.

 
Batuhan:

In OnInit(), I need to learn which side (low or high) of a past bar generated firstly?

If I'm correct, there are no tick data for the past bars, so how can I do that?

Thanks.

Avoid all calculations in OnInit. Data may not be loaded yet.

On higher time-frames, you may be able to determine by using minute timeframe, but is not infallible.

 
Keith Watford:

Avoid all calculations in OnInit. Data may not be loaded yet.

On higher time-frames, you may be able to determine by using minute timeframe, but is not infallible.


Ok, got, thanks a lot.
 
Batuhan: In OnInit(), I need …
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 
William Roeder:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.


So, new history is received after OnInit is called, and as Keith said, "Avoid all calculations in OnInit. Data may not be loaded yet".


My EA was hard coded for EURUSD, for a specified timeframe, and I always use it on the same chart.

I close the terminal at 20:00 at nights and reopen it at 8:00, so it only needs 12 hours of history in every trading morning.

For this specific case, should I move the calculations into OnTick, currently taken place in OnInit?

 
Batuhan: So, new history is received after OnInit is called, and as Keith said,
 

I'm looping with iLow, iHigh, etc functions in OnInit, and never have a problem so far.

Maybe these functions get a bit history needed on the flow, I don't know.


I haven't embedded the functionality of sending orders, but, if I decide to do it later, this point may be important to think about.

Thanks a lot to all.

 
Batuhan Ortay:

I'm looping with iLow, iHigh, etc functions in OnInit, and never have a problem so far.

You may not see any problems now, but there are sure to be times that you will.

I do all my early calculations like this

bool         FirstTick; //global scope variable

//+------------------------------------------------------------------+
int OnInit()
  {
   FirstTick=true;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if(FirstTick)
     {
      //Check that data is updated
      //Do your calcuations here
      FirstTick=false;
     }
     
  }
 
Keith Watford:

You may not see any problems now, but there are sure to be times that you will.

I do all my early calculations like this


Thank you, then let me do it now.

Reason: