When is :- If(Bars !=BarCount)

 

I have been reading through some code in the codebase and came across

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
extern bool EachTickMode = False;

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+

int init() 
{
  BarCount = Bars;
  if (EachTickMode) Current = 0; else Current = 1;
   
  return(0);
} // end of function init()


//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+

int start()
{
  if (EachTickMode && Bars != BarCount) 
  {
   TickCheck = False;
  }

  return(0);
} //end of function start()

//+------------------------------------------------------------------+ 
So ignoring the tester and assuming EachTickMode external variable is true when does Bars !=BarCount if ever?
 

BarCount = Bars; is set when the code is first run (or when init runs again, change of timeframe, etc.) so assuming this is an Indicator or EA Bars !=BarCount when a new Bar arrives . . . as long as Max bars on chart has not been reached.

Using Bars is a bad idea . . .

 
Ickyrus:

I have been reading through some code in the codebase and came across

So ignoring the tester and assuming EachTickMode external variable is true when does Bars !=BarCount if ever?

Well since Bars is the number of Bars in the current chart I would venture to suggest the test is true when the number of Bars in the current chart increases or decreases :-)

But seriously,

1) if you change the number of bars in the chart as a chart option

2) the number of bars in the chart history is not yet equal to the max bars per chart option, and a new bar starts, I expect the bar history for that chart will get bigger by one.


EDIT: I started writing this before Raptor's post was visible. He beat me to it :-(

 

Thanks RaptorUK - I guessed it was an odd technique for getting the opening of a new bar and its nice to have the guess confirmed.

Its from an EA in the codebase and wanted to make sure I really understood its pecularities.

 
Bars is unreliable (max bars on chart), Volume is unreliable (can miss ticks), Always use Time
int start(){
   static datetime Time0; if (Time0 == Time[0]) return; Time0 = Time[0];
   // New bar has started
 
WHRoeder:
Bars is unreliable (max bars on chart), Volume is unreliable (can miss ticks), Always use Time


@dabbler Thanks

@WHRoeder Completely agree with you.

 

A quick test shows that the code waits for a new bar to open and then its true for every tick that follows. So its decision making process is either based on each tick after the first newbar or on each tick but instead of using bar 0 it uses bar 1. This is the reason for setting Current to either 0 or 1.

Reason: