How do I know when a new bar is being drawn???

 

Hwlp!!


Noob Alert! I am trying to identify when a bar crosses an indicator line. I thought if i checked each time a new bar starts to be drawn - and used iClose, iHigh and iLow, i could some how measure when a bar has crossed over and indicator line and do some calculaion with that data.


Any help would be appreciated


Thanks


Alistair

 

Hi Alistair


Time[0] is the time the current bar started, so I use a variable to record the time a new bar appears and check it against Time[0], which will update when a new bar appears.

For example,

datetime ThisBarTime;                  // the time of the current bar

int init()
{
   ThisBarTime = Time[0];   // or ThisBarTime = Time[1]; to suit your purpose
}

int start()
{
   //----------------------------------------------------------------------------------------------
   // New bar checks
   if( ThisBarTime != Time[0] ) {  // if it's a new bar
      ThisBarTime = Time[0];

      // stuff to do when it's a new bar...
   }

   // more stuff...
}


 
AlistairTKing:

Hwlp!!


Noob Alert! I am trying to identify when a bar crosses an indicator line. I thought if i checked each time a new bar starts to be drawn - and used iClose, iHigh and iLow, i could some how measure when a bar has crossed over and indicator line and do some calculaion with that data.


Any help would be appreciated


Thanks


Alistair

Hwi!


with iBars() you have the number of bars (or candles) so if iBars() increases you are on a new candle. Then effectively, you can use iClose with the appropriate shift to compare with your indicator based on that same shift.

 
AlistairTKing:

Hwlp!!


Noob Alert! I am trying to identify when a bar crosses an indicator line. I thought if i checked each time a new bar starts to be drawn - and used iClose, iHigh and iLow, i could some how measure when a bar has crossed over and indicator line and do some calculaion with that data.


Any help would be appreciated


Thanks


Alistair

Thanks Jaques366 and JellyBean for your Help - Most Helpfull.

Reason: