hi,
I'm new to MetaTrader and have a question to the start function when writing an expert advisor.
As far the documentation says, the start function will be executed every new tick.
Assume that a tick wil be emitted every second, then I have 60 ticks per minute, 3600 tick per hour.
Assume I have a chart with hour timeframe.
So if I write a start function like iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); will this be calcuted 3600 times for the same hour bar?
So if I write a start function like iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); will this be calcuted 3600 times for the same hour bar?
yes, for shift 0.
in other words: start() will be executed this many times, indicator calculation may depend on which bar's value you want to get and the use of IndicatorCalculated() in the indi. code.
use bar numbers >0. bar. nr (or shift) is usually parameter.
I understand, but I have still a question.
The bar=1 would be a complete bar, thats good.
If I have a signal to buy for bar=1, I would get 3600 signals.
To avoid this, I have to remember that I buyed, correct?
Is ther a function for this, I haven't found anything
If I have a signal to buy for bar=1, I would get 3600 signals.
To avoid this, I have to remember that I buyed, correct?
it is enough to calculate the things you want once per bar. that is why I mentioned new bar checking. there are several ways to check, below is an example.
this returns true when a new bar is formed (it happens after when the the next (#1) bar is completed).
//+------------------------------------------------------------------+ //| isNewBar() | //+------------------------------------------------------------------+ bool isNewBar() { bool blnReturn = false; static datetime dtLastTime = 0; if ( Time[0] != dtLastTime ) { dtLastTime = Time[0]; blnReturn = true; } return( blnReturn ); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi,
I'm new to MetaTrader and have a question to the start function when writing an expert advisor.
As far the documentation says, the start function will be executed every new tick.
Assume that a tick wil be emitted every second, then I have 60 ticks per minute, 3600 tick per hour.
Assume I have a chart with hour timeframe.
So if I write a start function like iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); will this be calcuted 3600 times for the same hour bar?
Thanks,
Ilhan