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
Results of an indicator change as I load a different number of bars [SOLVED]
- Anna MultiCharts
- Posts: 560
- Joined: 14 Jul 2017
- Has thanked: 42 times
- Been thanked: 141 times
Re: Results of an indicator change as I load a different number of bars
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.
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.
-
- 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
Try using average or waverage, then the number of bars won't matter.
Re: Results of an indicator change as I load a different number of bars
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Results of an indicator change as I load a different number of bars
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?
What is your MaxBarsBack?
Re: Results of an indicator change as I load a different number of bars
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.
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.
Re: Results of an indicator change as I load a different number of bars
I have not assigned any value to that variable.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?
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");
Code: Select all
inputs:
period ( NumericSimple ),
myUpper ( NumericRef ),
myLower ( NumericRef );
myUpper = Highest(H, period);
myLower = Lowest(L, period);
Re: Results of an indicator change as I load a different number of bars [SOLVED]
Code: Select all
emavola(xAverage(vola, period))
It calculates on the very first script calculation, BUT NOT on each and every subsequent bars.
Add
Code: Select all
emavola = xAverage(vola, period)
Same for all other variables using functions at declaration.
Re: Results of an indicator change as I load a different number of bars
You got the point!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.
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);
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);
Thanks all for your precious replies. Now the problem is really resolved!
- Anna MultiCharts
- Posts: 560
- Joined: 14 Jul 2017
- Has thanked: 42 times
- Been thanked: 141 times
Re: Results of an indicator change as I load a different number of bars
Zheka,
we're currently analyzing this. We'll post a reply from the engineers when it's available.
we're currently analyzing this. We'll post a reply from the engineers when it's available.
- Anna MultiCharts
- Posts: 560
- Joined: 14 Jul 2017
- Has thanked: 42 times
- Been thanked: 141 times
Re: Results of an indicator change as I load a different number of bars
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. 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.
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. 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.
Re: Results of an indicator change as I load a different number of bars
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).
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).
- Anna MultiCharts
- Posts: 560
- Joined: 14 Jul 2017
- Has thanked: 42 times
- Been thanked: 141 times
Re: Results of an indicator change as I load a different number of bars
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.
as you can see at the moment from the screenshot that our engineers provided there’s no difference in calculation between MultiCharts and TS.