ExecOffset (Reserved Word)

image\trumpet2.gif Disclaimer

ExecOffset is a reserved word (meaning "Execution Offset" ) that returns the bars ago offset value for the current function.  For example, if a function is called from a study using the offset syntax, MyFunc[3], within MyFunc the value of ExecOffset is equal to 3.  The ExecOffset value is useful if you need to adjust calculations to take into account the bars ago offset.

  The ExecOffset returns an accumulated offset amount such that if MyFunc[3] is called from within another function that is also offset by a number of bars (e.g., MyOtherFunc[5] calls MyFunc[3] ), the value of ExecOffset within MyOtherFunc is equal to 5, while the value of ExecOffset within MyFunc is equal to 8.

Example

Let's say that your code is running on bar 20, and the code calls HighestBar( High, 5 ).  And let's say that the highest high of the last 5 bars occurred 3 bars ago, on bar 17.  So one would expect that HighestBar(High, 5) would return 3.  Now, let's say that the code calls HighestBar( High, 5 )[1].  This is the same function call, but offset 1 bar back.  And let's say that the highest high over 5 bars, as of one bar ago, is still the high that occurred on the 17th bar.  In this case, HighestBar( High, 5 )[1], if not adjusted for ExecOffset, would return 2 since, as of 1 bar ago (the 19th bar), the highest high occurred 2 bars ago.  So, in order to return a value that is meaningful in the context of the caller the function must add ExecOffset (1) to the return value of 2, and return 3 in this case.  In short, ExecOffset is used to adjust the return value of certain functions that are offset so that they return a value that is meaningful to the calling code, a value relative to the current bar, rather than relative to the bar to which the function is offset.