Results of an indicator change as I load a different number of bars  [SOLVED]

Questions about MultiCharts and user contributed studies.
giulio
Posts: 13
Joined: 25 Nov 2016
Location: Italy
Has thanked: 4 times

Results of an indicator change as I load a different number of bars

Postby giulio » 22 Oct 2017

Hi all,

I need your help!
I wrote the code to show up pipes in the chart with my personal criteria. But I am experiencing the following problem: the results change as I load a different number of bars.
It is the first time I get such a strange result

Here you can see a video as a probe. For the same security I set 1000 days back as daily range on the left and 2000 days back on the right. The indicator gives me back two different results: https://www.dropbox.com/s/7rpzo9yqqvrds ... 29.7z?dl=0

Regards
Attachments
prova.pla
(5.84 KiB) Downloaded 442 times

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Results of an indicator change as I load a different number of bars

Postby Anna MultiCharts » 27 Oct 2017

Hello, giulio!

In your code you use xAvarage which is a serial function that is calculated on each bar and that takes the calculation results from the previous bar as the basis for calculation of the next bar. Therefore the more bars on the chart you have the more different the results of your indicator will be.

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Results of an indicator change as I load a different number of bars

Postby sptrader » 27 Oct 2017

Try using average or waverage, then the number of bars won't matter.

giulio
Posts: 13
Joined: 25 Nov 2016
Location: Italy
Has thanked: 4 times

Re: Results of an indicator change as I load a different number of bars

Postby giulio » 29 Oct 2017

Hello, giulio!

In your code you use xAvarage which is a serial function that is calculated on each bar and that takes the calculation results from the previous bar as the basis for calculation of the next bar. Therefore the more bars on the chart you have the more different the results of your indicator will be.

Hmmm...

I appreciate the commitment but I disagree with your explanation for at least two motivations and I think the problem is not resolved.

I would like to get exponential moving average of the last 16 values of volatility. And then use this result to make a decision.
Looking at the formula of xAverage function I recognize the formula of ema.

1) So the smoothing costant ( 2 / (len +1)) is always fixed at 2/17 if I choose 16 as the lenght of the period.

2) Taking inspiration from sptrade's comment I have repeated the test changing xAverage with Average (so from ema to sma). And I have got the same strange result that changes as the number of loaded bars changes. I provide two examples.


I don't understand why I should get different results if I load 1000 bars or 2000 bars.

Regards.

PS: The same identical indicator, with the same code, runs smoothly on another two different platforms (Prorealtime and a javascript-based platform). Either give me back the same identical result.
Attachments
Screenshot (479).png
(247.56 KiB) Downloaded 1777 times
Screenshot (478).png
(247.44 KiB) Downloaded 1777 times
Screenshot (477).png
(229.98 KiB) Downloaded 1777 times
Screenshot (476).png
(230.8 KiB) Downloaded 1777 times

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

Re: Results of an indicator change as I load a different number of bars

Postby TJ » 29 Oct 2017

Please post your code in text format. Not everybody wants to compile an unknown code into their PLE because duplicate functions can overwrite existing functions.

What is your MaxBarsBack?

Zheka
Posts: 223
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: Results of an indicator change as I load a different number of bars

Postby Zheka » 29 Oct 2017

Hi,

This is because you do not update the emavola in your code. You only initialize it when declaring a variable.

I also has been under the impression that setting a variable to a function at declaration in EL allows one to avoid explicit assignment to a value later in the code. (this is probably not a good practice anyway, but still...)

@MC:
please clarify if this is a recent change and if this is different to how EL in TS would behave.

giulio
Posts: 13
Joined: 25 Nov 2016
Location: Italy
Has thanked: 4 times

Re: Results of an indicator change as I load a different number of bars

Postby giulio » 29 Oct 2017

Please post your code in text format. Not everybody wants to compile an unknown code into their PLE because duplicate functions can overwrite existing functions.

What is your MaxBarsBack?
I have not assigned any value to that variable.

The code of prova indicator is the following

Code: Select all

inputs:
period(16),
j(0.66),
k(0.5);

variables:
UpCh(Highest(H, period)),
DnCh(Lowest(L, period)),
vola(High - Low),
emavola(xAverage(vola, period)),
minvola(Lowest(vola, period)),
corpo(0),
tipo(0),
pipe(0);

DonchianChannel(period, UpCh, DnCh);


if (Close <= Open) then begin
corpo = Open - Close;
tipo = -1;
end
else begin
corpo = Close - Open;
tipo = 1;
end;

if ((tipo[1] = -1 and tipo = 1) and ((Low[1] <= DnCh[2]) or (Low <= DnCh[1]))) and (((corpo >= j*corpo[1]) and (corpo[1] >= j*corpo)) and ((vola + vola[1]) >= (emavola[1] + emavola[2])) and ((corpo + corpo[1]) >= k*(vola + vola[1])) and ((Open >= (Close[1] - minvola[1])) and (Open <= (Close[1] + minvola[1])))) then begin
pipe = 1;
end
else begin
if ((tipo[1] = 1 and tipo = -1) and ((High[1] >= UpCh[2]) or (High >= UpCh[1]))) and (((corpo >= j*corpo[1]) and (corpo[1] >= j*corpo)) and ((vola + vola[1]) >= (emavola[1] + emavola[2])) and ((corpo + corpo[1]) >= k*(vola + vola[1])) and ((Open >= (Close[1] - minvola[1])) and (Open <= (Close[1] + minvola[1])))) then begin
pipe = -1;
end
else begin
pipe = 0;
end;
end;
plot1(pipe, "Pipe");
where DonchianChannel(period, UpCh, DnCh) function reads as

Code: Select all

inputs:
period ( NumericSimple ),
myUpper ( NumericRef ),
myLower ( NumericRef );

myUpper = Highest(H, period);
myLower = Lowest(L, period);
Regards

Zheka
Posts: 223
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: Results of an indicator change as I load a different number of bars  [SOLVED]

Postby Zheka » 29 Oct 2017

Code: Select all

emavola(xAverage(vola, period))
This is your initial assignment in Variables declaration.
It calculates on the very first script calculation, BUT NOT on each and every subsequent bars.

Add

Code: Select all

emavola = xAverage(vola, period)
explicitly later in the code.

Same for all other variables using functions at declaration.

giulio
Posts: 13
Joined: 25 Nov 2016
Location: Italy
Has thanked: 4 times

Re: Results of an indicator change as I load a different number of bars

Postby giulio » 29 Oct 2017

Hi,

This is because you do not update the emavola in your code. You only initialize it when declaring a variable.

I also has been under the impression that setting a variable to a function at declaration in EL allows one to avoid explicit assignment to a value later in the code. (this is probably not a good practice anyway, but still...)

@MC:
please clarify if this is a recent change and if this is different to how EL in TS would behave.
You got the point!

I have just changed the code from:

Code: Select all

variables:
UpCh(Highest(H, period)),
DnCh(Lowest(L, period)),
vola(High - Low),
emavola(xAverage(vola, period)),
minvola(Lowest(vola, period)),
corpo(0),
tipo(0),
pipe(0);

DonchianChannel(period, UpCh, DnCh);
to

Code: Select all

variables:
UpCh(Highest(H, period)),
DnCh(Lowest(L, period)),
vola(0),
emavola(0),
minvola(0),
corpo(0),
tipo(0),
pipe(0);

vola = High - Low;
DonchianChannel(period, UpCh, DnCh);
emavola = XAverage(vola, period);
minvola = Lowest(vola, period);
and now everything is ok. The indicator gives me back the exact result.

Thanks all for your precious replies. Now the problem is really resolved!

Zheka
Posts: 223
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: Results of an indicator change as I load a different number of bars

Postby Zheka » 29 Oct 2017

Great:-)

The question to MC however:
is it supposed to (not) work this way?
Is this different from EL/ TS?

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Results of an indicator change as I load a different number of bars

Postby Anna MultiCharts » 07 Nov 2017

Zheka,

we're currently analyzing this. We'll post a reply from the engineers when it's available.

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Results of an indicator change as I load a different number of bars

Postby Anna MultiCharts » 10 Nov 2017

Hello, Zheka!

Our engineers have analyzed this and came to the conclusion that there’s no difference between the indicator plots in MultiCharts and in TS. Please, see the screenshot.
1.png
(141.53 KiB) Downloaded 1669 times
The difference between

“emavola = XAverage(vola, period);”

and

“variables:
emavola(xAverage(vola, period))”

is that in the first case the calculation is done on each bar, and in the second case the variable is calculated only once on the first bar.
Also the difference in calculations can be caused by different starting points of the indicator’s calculation.

Zheka
Posts: 223
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: Results of an indicator change as I load a different number of bars

Postby Zheka » 10 Nov 2017

Anna,
but that was exactly the point! As far as I know, in TS a variable initialization with the function will make it calculate on each bar...
And this is how it used to work in MC previously (to the best of my knowledge).

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 140 times

Re: Results of an indicator change as I load a different number of bars

Postby Anna MultiCharts » 15 Nov 2017

Zheka,

as you can see at the moment from the screenshot that our engineers provided there’s no difference in calculation between MultiCharts and TS.


Return to “MultiCharts”