running a loop to examine the pivots tested  [SOLVED]

Questions about MultiCharts and user contributed studies.
kkhorse
Posts: 7
Joined: 08 Jun 2010
Has thanked: 2 times

running a loop to examine the pivots tested  [SOLVED]

Postby kkhorse » 26 Jun 2014

Hi, I am writing a program to track all the pivots in the charts and draw a horizontal trendline btw the pivot and the bar that test it.

when i ran the pivot part alone, it would run from the beginning to the end (about 500 bars); when i introduce the testing pivot part, calculated by running a loop to compare every pivot in the past to the current bar, the program only ran from 300th bar to the end.

i examined the code and couldn't figure out why. any help is appreciate!

sean

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: running a loop to examine the pivots tested

Postby TJ » 26 Jun 2014

Hi, I am writing a program to track all the pivots in the charts and draw a horizontal trendline btw the pivot and the bar that test it.
when i ran the pivot part alone, it would run from the beginning to the end (about 500 bars); when i introduce the testing pivot part, calculated by running a loop to compare every pivot in the past to the current bar, the program only ran from 300th bar to the end.
i examined the code and couldn't figure out why. any help is appreciate!
sean
What would you like us to do?

kkhorse
Posts: 7
Joined: 08 Jun 2010
Has thanked: 2 times

Re: running a loop to examine the pivots tested

Postby kkhorse » 16 May 2015

I checked the occasion when the program will not run from the beginning and i noticed that MaxBarsBack has been reset to a rather large number, in this case it's been reset to 1307 while there are totally 1600 bars.

why is the maxbarsback reset and how can i prevent it from being reset? thanks a lot!

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: running a loop to examine the pivots tested

Postby JoshM » 21 May 2015

I checked the occasion when the program will not run from the beginning and i noticed that MaxBarsBack has been reset to a rather large number, in this case it's been reset to 1307 while there are totally 1600 bars.

why is the maxbarsback reset and how can i prevent it from being reset? thanks a lot!
It seems like you have MaxBarsBack set to auto-detect, in which case it behaves as follows:
When detected automatically, MaxBarsBack will initially be set to the value of the largest data offset in the study; however, if a variable data offset is used in the script, the initial MaxBarsBack value may prove to be too small.

In such a case, the MaxBarsBack value will automatically be increased by 5 or by a factor of 1.618, whichever yields a higher value, and the study recalculated.

The process of automatic MaxBarsBack detection may cause some functions to be executed repeatedly for the first few bars of a chart when a study is first applied; this can be avoided by setting the MaxBarsBack value manually.
Source: How scripts work - wiki.

If you need 1307 historical bars to perform the calculations on, you might want to rewrite the code to use `Symbol_` keywords. Those keywords are not affected/limited by the MaxBarsBack setting and can be used to access any future or past price bar of the data series. That means you don't need to 'give up' 1307 bars before the script calculates for the first time.

Those `Symbol_` keywords can be found here: data information/general - wiki.


Return to “MultiCharts”