Discrepency with EMA values in indicator and signal  [SOLVED]

Questions about MultiCharts and user contributed studies.
champski
Posts: 71
Joined: 28 Jun 2011
Has thanked: 20 times
Been thanked: 1 time

Discrepency with EMA values in indicator and signal

Postby champski » 01 Apr 2014

Hi,

I have a signal with IOG enabled and I'm writting some code to analyse the current status of price in relation to the 72ema (for example)

Code: Select all

if barstatus(1) = 2 then begin
ema4 = XAverage( close, 72 ) ;
end;
If close <= ema4 then buy at next bar etc
The problem I'm having is that the value for ema4 on the chart does not equal the value for ema4 in the signal. I have tested this by using print.

Code: Select all

if barstatus(1) = 0 then print("ema4, ", ema4:1:5)
Why is the plotted value different? Has it got anything to do with maxbarsback or properties of the indicator.....?

Regards
Champski

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Discrepency with EMA values in indicator and signal

Postby Henry MultiСharts » 01 Apr 2014

Hello champski,

Please refer to the following article: How to make indicator and signal calculation results the same.

champski
Posts: 71
Joined: 28 Jun 2011
Has thanked: 20 times
Been thanked: 1 time

Re: Discrepency with EMA values in indicator and signal

Postby champski » 14 Apr 2014

Hello champski,

Please refer to the following article: How to make indicator and signal calculation results the same.
Thanks Henry, that worked for me to correctly line-up the indicator with the signal.
I did however find another discrepency with the 72ema that I'm hoping you can further assist me with..

This is what I found - If you have 2 charts, Chart1 starts 2 months before (or even 6 months before) Chart2 and you have 72 ema potted on both. The value(s) of the 72ema will not be the same on both charts until approx 350 bars into chart 2 (23 days). Therefore, a 72ema has a delay of about 350 bars before the data is actually correct. Essentially, when it comes to backtesting, the first 350 bars need to be ignored before considering the entry of a trade.

Am I doing something wrong to get this result?

Regards
Champski

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Discrepency with EMA values in indicator and signal  [SOLVED]

Postby Henry MultiСharts » 16 Apr 2014

XAverage(EMA) function is using its own previous values for the calculation. If you want the function calculation results to match - you need to have the function calculated on the same data range.


Return to “MultiCharts”