Download MetaTrader 5
To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
samusmus1
173
samusmus1 2016.11.07 17:22 
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);
     }

Marco vd Heijden
Moderator
4240
Marco vd Heijden 2016.11.07 17:46  

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.

whroeder1
13993
whroeder1 2016.11.07 17:56  
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.
Carl Schreiber
6165
Carl Schreiber 2016.11.08 21:19  
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!
Alain Verleyen
Moderator
29679
Alain Verleyen 2016.11.08 23:16  
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 ?
Carl Schreiber
6165
Carl Schreiber 2016.11.09 09:10  
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 ..."

Alain Verleyen
Moderator
29679
Alain Verleyen 2016.11.09 11:00  
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.

/
To add comments, please log in or register