different outputs depending on maxbarsback

Questions about MultiCharts and user contributed studies.
kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

different outputs depending on maxbarsback

Postby kernel » 19 Feb 2013

hi,

i put a very short testing script, applying to the same chart data, but with maxbarsback set to 50 and 100, the outputs are different: bullish momentum turns to bearish.

the script is:

variables:
oFastK( 0 ),
oFastD( 0 ),
SlowK( 0 ),
SlowD( 0 );

Value1 = Stochastic( H, L, C, 14, 3, 3, 1, oFastK, oFastD, SlowK, SlowD) ;

if date=1121231 and time>=1000 and time<=1130 then begin
print("========maxbarsback=100============",
"Date:", date,
" time:", time,
" oSlowK:", SlowK, " oSlowD:", SlowD,
"===================================");
end;


the output:

========maxbarsback=50========
Date:1121231.00 time:1000.00 oSlowK: 73.68 oSlowD: 66.59
Date:1121231.00 time:1100.00 oSlowK: 81.85 oSlowD: 72.50
Date:1121231.00 time:1130.00 oSlowK: 85.52 oSlowD: 80.35

========maxbarsback=100============
Date:1121231.00 time:1000.00 oSlowK: 92.08 oSlowD: 92.08
Date:1121231.00 time:1100.00 oSlowK: 90.03 oSlowD: 91.40
Date:1121231.00 time:1130.00 oSlowK: 85.52 oSlowD: 89.21


any clue?

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

Re: different outputs depending on maxbarsback

Postby TJ » 19 Feb 2013

hi,
i put a very short testing script, applying to the same chart data, but with maxbarsback set to 50 and 100, the outputs are different: bullish momentum turns to bearish.
the script is:
variables:
oFastK( 0 ),
oFastD( 0 ),
SlowK( 0 ),
SlowD( 0 );
Value1 = Stochastic( H, L, C, 14, 3, 3, 1, oFastK, oFastD, SlowK, SlowD) ;
if date=1121231 and time>=1000 and time<=1130 then begin
print("========maxbarsback=100============",
"Date:", date,
" time:", time,
" oSlowK:", SlowK, " oSlowD:", SlowD,
"===================================");
end;
the output:
========maxbarsback=50========
Date:1121231.00 time:1000.00 oSlowK: 73.68 oSlowD: 66.59
Date:1121231.00 time:1100.00 oSlowK: 81.85 oSlowD: 72.50
Date:1121231.00 time:1130.00 oSlowK: 85.52 oSlowD: 80.35
=======maxbarsback=100============
Date:1121231.00 time:1000.00 oSlowK: 92.08 oSlowD: 92.08
Date:1121231.00 time:1100.00 oSlowK: 90.03 oSlowD: 91.40
Date:1121231.00 time:1130.00 oSlowK: 85.52 oSlowD: 89.21
any clue?
What is the instrument?
What is the chart resolution?
What is the data range?



ps. This topic in wiki might help
How Scripts Work

ps. please see How to Post Codes

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: different outputs depending on maxbarsback

Postby bowlesj3 » 19 Feb 2013

What does it give you if you set the determination of maxbarsback to automatic and you then print the resulting maxbarsback value it came up with?

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: different outputs depending on maxbarsback

Postby kernel » 20 Feb 2013

TJ and bowlesj3, thank you both for the reply...and the links by TJ, the abnormality occurred a couple of bars right after maxbarsback, i guess this was the cause.

Speaking of maxbarsback, if one uses multiple time frames, saying data1 and data2, because both have to meet the maxbackbars requirement, if it gets applied to data1, the "maxbarsback" of data2 would be different from the return of maxbarsback...this would become an issue when you try to get the displayed "Bar#" matching "currentbar" and put some useful info on the bar.

one may get around this by comparing the offset of the two data series, any function you may directly call that I missed? thanks.

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

Re: different outputs depending on maxbarsback

Postby TJ » 20 Feb 2013

TJ and bowlesj3, thank you both for the reply...and the links by TJ, the abnormality occurred a couple of bars right after maxbarsback, i guess this was the cause.

Speaking of maxbarsback, if one uses multiple time frames, saying data1 and data2, because both have to meet the maxbackbars requirement, if it gets applied to data1, the "maxbarsback" of data2 would be different from the return of maxbarsback...this would become an issue when you try to get the displayed "Bar#" matching "currentbar" and put some useful info on the bar.

one may get around this by comparing the offset of the two data series, any function you may directly call that I missed? thanks.
The minimum maxbarsback is the largest maxbarsback required by all the indicators in all the data series in the chart. It is the requirement to make proper calculations of your indicators; there is no short cuts.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: different outputs depending on maxbarsback

Postby bowlesj3 » 20 Feb 2013

I suspect that the automatic maxbarsback setting works for all built in studies and you would normally only need to set it manually if you are doing something special. I use the special settings (very large settings) because I drop a lot of arrows on the charts and the studies go looking for them (using a binary search) to get the data from that bar and the surrounding bars. With this type of application MC has no way of knowing the size in advance so it must be preset. If your code references bars back past the maxbarsback setting it will do a hidden recalculate on your study meaning it will restart the study just as if you had turned it off then on again. MC does not tell you it did this. It will do it over and over again until it has the MaxBarsBack setting large enough.


Return to “MultiCharts”