Why put this in an EA: Bars<100 ?

 
why do people use this protection in their EA? I mean, if you make your MT4 window smaller, you WANT the EA to continue trading, right? But with this protection, the EA will stop working and won't open any orders. I think it's useless, because if you don't want to trade, just turn off the EA. Or does this have another useful function?

if(Bars<100)
     {
      Print("bars less than 100");
      return(0);
     }

 

Bars

Returns the number of bars count in the history for a specified symbol and period.

So this has got nothing to do with the number of bars on the chart and so it will not be affected by you changing the chart dimensions.

Maybe you are referring to:

VisibleBars

Gets total number of visible chart bars.

In any case if you are running an EA that uses for example a Moving Average of 100, then in order to calculate the value of this moving average, at least 100 bars have to be present, or the function will give a false reading.

If there are less then 100 bars in history, the correct value can not be calculated and if you are not using this filter it can result in unwanted or false entries.

 
samusmus1: why do people use this protection in their EA?
They are following what some moron did 15 years ago and don't know any better. They aren't a complete idiot, some parts are missing.
 
In case of a symbol change, timeframe change, account change or terminal (re-) start it could be that the EA, indicator or script starts working while the quotes and other stuff (e.g. tickvalue) hasn't been available yet. OnInit() has already been passed and some of your values could have been set incorrectly!
 
Carl Schreiber:
In case of a symbol change, timeframe change, account change or terminal (re-) start it could be that the EA, indicator or script starts working while the quotes and other stuff (e.g. tickvalue) hasn't been available yet. OnInit() has already been passed and some of your values could have been set incorrectly!
I don't see how what you wrote is related to the topic ?
 
Alain Verleyen:
I don't see how what you wrote is related to the topic ?

The question was: "Why..."

Bars>100 is a protection against this kind of problem I described.

I check as well MarketInfo(Symbol(),MODE_TICKVALUE)) in start() or OnTick() or OnCalculate() ..

It is the reason and the answer of "Why ..."

 
Carl Schreiber:

The question was: "Why..."

Bars>100 is a protection against this kind of problem I described.

I check as well MarketInfo(Symbol(),MODE_TICKVALUE)) in start() or OnTick() or OnCalculate() ..

It is the reason and the answer of "Why ..."

Sure, I know it's your answer ;-)

But what I don't see is how "Bars  < 100" is a protection against "the quotes and other stuff (e.g. tickvalue) hasn't been available yet" ? I mean, if it's one, it's not a good one in my opinion.

Anyway, probably not important.

Reason: