"Shift" defines the period from which the calculated value is returned.
Shift = "0" Will return the value from the "live" candle.
Shift = "1" will return the value from the first complete candle.
Shift = "100" will return the value from 100 candles prior.
no, 100 = the 100 closed candle = the 101 bar
This applies to EA and Indicator functions, of all types. eg. iMACD, iMA, iRSI, etc.
It doesn't affect calculation as such, only offsets the value being returned by the function.
of the value taken from the indicator buffer (shift relative to the current bar
the given amount of periods ago).
Thanks qjol. Got my logic sorted now!
Actually, a related question while I think of it:
If I run an EA designed to carry out it's functionality ONLY on the formation of a new bar (rather than on every tick), should the calculations in said code use a shift value of 1?
I'm curious to know, will the code be carried out at the instant the new bar is formed, meaning I should refer to the current bar (shift = 0) for the most complete and current period? Or at this point in time, will that data have moved to the position of shift = 1 (even if it was only 0.001 mS ago) ?
I refer to the following code, taken from a post by mrchuckw:
if(oldTime != Time )
// first tick of new bar found
// do something useful
oldTime = Time;
My learning continues.
Many thanks for taking the time to share your knowledge.