Hi to all,
I have plotted on my chart the standard averageTrueRange(20)...
then I have made an indicator myATR with these few lines :
plot1(averagetruerange(20),"MyATR",Red, Default , 3);
print(" ||averagetruerange(20): ",averagetruerange(20)*PriceScale);
and I have attached it to the chart....
But the results of the two indicators are differents for the first 20 bars :
BARNUM 22 - ATR : 0.00428 - MYATR : 0.00027
BARNUM 23 - ATR : 0.00431 - MYATR : 0.00051
and so on... until
BARNUM 41 - ATR : 0.00435 - MYATR : 0.00435
Where they finally starts to be in sync with the results....
Why Does it happen?
MaxBarBAck is Auto-Detect
Average true range not sync [SOLVED]
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Average true range not sync
From my understanding, this happens due to a difference in MaxBarsBack. If you set both indicators to the same MaxBarsBack value manually, the difference will likely go away.But the results of the two indicators are differents for the first 20 bars :
BARNUM 22 - ATR : 0.00428 - MYATR : 0.00027
BARNUM 23 - ATR : 0.00431 - MYATR : 0.00051
and so on... until
BARNUM 41 - ATR : 0.00435 - MYATR : 0.00435
Where they finally starts to be in sync with the results....
Why Does it happen?
MaxBarBAck is Auto-Detect
By the way, when MaxBarsBack is set to automatic MultiCharts makes several guesses to arrive at a number of bars back that allows the script to calculate and plot its values:
Source.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.
So there are quite a few steps in determining the automatic value for MaxBarsBack that can cause different scripts to have a different number of MaxBarsBack.
---
Edit: By the way, if I compare your ATR script:
Code: Select all
plot1(averagetruerange(20),"MyATR",Red, Default , 3);
print(" ||averagetruerange(20): ",averagetruerange(20)*PriceScale);
Code: Select all
inputs:
ATRLength( 14 ),
AlertLength( 14 ) ;
variables:
var0( 0 ) ;
var0 = AvgTrueRange( ATRLength ) ;
Plot1( var0, "ATR" ) ;
condition1 = HighestBar( var0, AlertLength ) = 0 ;
if condition1 then
Alert( "Indicator at high" )
else
begin
condition1 = LowestBar( var0, AlertLength ) = 0 ;
if condition1 then
Alert( "Indicator at low" ) ;
end;
Because of that, the initial MaxBarsBack value will be too small for this study (since, given the quote above, MultiCharts doesn't take into account loops when guessing the initial MaxBarsBack value).
And so the Average True Range indicator will have a MaxBarsBack setting that's increased several times until this script (and the functions it uses) can calculate properly. Since your custom ATR indicator doesn't use those functions and simply refers up to 20 historical bars, it can calculate with a different number of MaxBarsBack and MultiCharts won't need to guess with that script.
Re: Average true range not sync
The Problem persists also if I set MaxBarBack Manually ( I have just tried with : 50, 100 etc..)...The firsts 20 results of the script
I have to use averagetruerange(20) in a signal script so....How can I solve the problem?
NOTE:
if I use : averagetruerange(10) the firsts 10 results are wrong.....
It seems like that the averagetruerange() function needs always an amounts of initial bars (in addition to any maxbarsback set) to give right results....so for the firsts "atr lenghts" bars, the output is completely wrong....this can be a problem when I use it in a strategy
are completely wrong.plot1(averagetruerange(20),"MyATR",Red, Default , 3);
print(" ||averagetruerange(20): ",averagetruerange(20)*PriceScale);
I have to use averagetruerange(20) in a signal script so....How can I solve the problem?
NOTE:
if I use : averagetruerange(10) the firsts 10 results are wrong.....
It seems like that the averagetruerange() function needs always an amounts of initial bars (in addition to any maxbarsback set) to give right results....so for the firsts "atr lenghts" bars, the output is completely wrong....this can be a problem when I use it in a strategy
Re: Average true range not sync
The whole <MaxBarsBack> implementation in TS and Multicharts is just wrong. The first idea of it had a totally different approach, but was implemented with misleading sense & results and it was never changed since then.
Last year I wanted to show some evidence to prove it, but felt already the bashing in different discussions and saw that most do not understand it or just see it wrong or not correct. I talked to some respectable coders and traders in this forum which motivated me to open a serious discussion, but they never wanted to do it by them self while they know/knew it will be hard to get people on the right track and confirmed that my argumentation about the wrong implementation of <MaxBarsBack> is right.
So be it ....
Regards
Ben
Last year I wanted to show some evidence to prove it, but felt already the bashing in different discussions and saw that most do not understand it or just see it wrong or not correct. I talked to some respectable coders and traders in this forum which motivated me to open a serious discussion, but they never wanted to do it by them self while they know/knew it will be hard to get people on the right track and confirmed that my argumentation about the wrong implementation of <MaxBarsBack> is right.
So be it ....
Regards
Ben