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
running a loop to examine the pivots tested [SOLVED]
- TJ
- Posts: 7746
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2225 times
Re: running a loop to examine the pivots tested
What would you like us to do?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
Re: running a loop to examine the pivots tested
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!
why is the maxbarsback reset and how can i prevent it from being reset? thanks a lot!
- 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
It seems like you have MaxBarsBack set to auto-detect, in which case it behaves as follows: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!
Source: How scripts work - wiki.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.
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.