Help confirm simple code operation - page 2

 
5T3L7H:


"Shift" defines the period from which the calculated value is returned.

yes

 Shift = "0" Will return the value from the "live" candle.

yes

 Shift = "1" will return the value from the first complete candle.

yes

 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.

yes

It doesn't affect calculation as such, only offsets the value being returned by the function.


yes

Correct.......?

almOst ;-)


shift

[in]  Index 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:

 

int start()
  {
   if(oldTime != Time[0] )
      {
      // first tick of new bar found
      // do something useful
      oldTime = Time[0];
      }
   return(0);
   }
 
5T3L7H:

 (even if it was only 0.001 mS ago) ? 

 


yes

 

Brilliant.

 

My learning continues. 

 

Many thanks for taking the time to share your knowledge.

 

:-) 

Reason: