Indicator Function in Signal Not Matching Chart Indicator  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
drmrboyc
Posts: 7
Joined: 22 Mar 2013
Has thanked: 1 time

Indicator Function in Signal Not Matching Chart Indicator

Postby drmrboyc » 12 Apr 2013

Hello,

I'm having some trouble matching up two sets of data which should be the same.

1) I have a Signal with uses the function XAverage. It is initialized as such:

Code: Select all

private XAverage slow_ema;

protected override void Create()
{
// Initialize the EMA.
slow_ema = new XAverage(this);
}

protected override void StartCalc()
{
// Initialize the EMA.
price = BarsOfData(1).Close; // Also tried Bars.Close
slow_ema.Price = price;
slow_ema.Length = 21;
}


2) I also have a Mov_Avg_Exponential indicator on the chart with the same parameters: 21 length and 0 displace.

-------------------------

When I run the signal, I access the value of the XAverage function using this method:

Code: Select all

slow_ema[0] // Or sometimes slow_ema[1]
Also, my strategy uses Intrabar order generation:

Code: Select all

[IOGMode(IOGMode.Enabled)]
public class MyEMASignal : SignalObject {
...
To check my data, I output the values of the XAverage function when each bar closes:

Code: Select all

Bars.Status != EBarState.Close // Also tried Bars.Status != EBarState.Open
Yet, the values from my output window and the values on the chart are different! Not just slightly different (like a bar off), but way off, even by 100+ pips sometimes!

Here's what the chart shows:

Image

and here is the EMA value, output from the signal:

Code: Select all

4/11/2013 12:00:00 PM - Slow EMA[0]: 0.850830263588033
4/11/2013 12:00:00 PM - Slow EMA[1]: 0.850830263588033
I noticed that referencing backwards does not change the value. Which leads me to believe that there's something I'm doing wrong with accessing a bar's EMA, and instead getting the current Tick's EMA?

I'm really not sure what else to try to get the correct EMA in my signal. Maybe some of you brilliant MultiCharts.NET users or staff could help shed some light on my predicament?

Thanks very much for your time!

Kenny

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

Re: Indicator Function in Signal Not Matching Chart Indicato

Postby Henry MultiСharts » 15 Apr 2013

Hello Kenny,
To check my data, I output the values of the XAverage function when each bar closes:
Code:
Bars.Status != EBarState.Close // Also tried Bars.Status != EBarState.Open
!= is the inequality operator. This code will not work as described.
Please use the equality operator == to achieve your goal.

Please follow the corresponding wiki article to make the signal and indicator calculations the same:
How to make indicator and signal calculation results the same

If XAverage length is 21 then the max bars back should not be lower than 21.

drmrboyc
Posts: 7
Joined: 22 Mar 2013
Has thanked: 1 time

Re: Indicator Function in Signal Not Matching Chart Indicato

Postby drmrboyc » 15 Apr 2013

To check my data, I output the values of the XAverage function when each bar closes:
Code:
Bars.Status != EBarState.Close // Also tried Bars.Status != EBarState.Open
!= is the inequality operator. This code will not work as described.
Please use the equality operator == to achieve your goal.
Thanks for your response Henry! In this case, I'm actually following that line by a return statement. So, it is achieving the functionality I desire by using the inequality operator. However, thanks for checking my logic so closely, I greatly appreciate your thorough review of my problem!

That wiki article looks like it is exactly what I needed! I'll give it a go and report back here with an update.

drmrboyc
Posts: 7
Joined: 22 Mar 2013
Has thanked: 1 time

Re: Indicator Function in Signal Not Matching Chart Indicato

Postby drmrboyc » 15 Apr 2013

So, I followed the wiki page that you showed me. It was of no avail, as the XAverage function in my signal continues to return values that are different from the Mov_Avg_Exponential indicator on the signal's chart.

I'm going to try breaking my signal down to just the XAverage function and see if something else is causing the issue. In the meantime, is there somewhere I can send my code or someone at MultiCharts who can help me directly?

Thank you Henry!

drmrboyc
Posts: 7
Joined: 22 Mar 2013
Has thanked: 1 time

Re: Indicator Function in Signal Not Matching Chart Indicato  [SOLVED]

Postby drmrboyc » 15 Apr 2013

I was able to get it working!

Honestly, I don't know why this made it work; Probably because it forced a recalculation in the signal. All I had to do was "access" the indicator's information at the beginning of CalcBar().

Code: Select all

double tmp_ema = slow_ema[0];
I don't use the tmp_ema variable anywhere. However, when I print the value of slow_ema[0] later in the signal's calculations, the value is correct.

Honestly, stuff like this makes me a bit apprehensive about using MultiCharts.NET. However, I'm just a couple weeks (and a couple strategies) into the trial, so we'll see how it pans out.

I greatly appreciate your help Henry!


Return to “MultiCharts .NET”