PDA

View Full Version : Slope of EMA


Creamers
04-12-2007, 07:23 AM
What's wrong with this?: It plots nothing as soon as I use those double values.

double slobenow=(EMA(MyInput0)[0])-(EMA(MyInput0)[1]);

double slobe=(EMA(MyInput0)[1])-(EMA(MyInput0)[2]);

if (slobe<0) { slobe=slobe*-1; }

if (slobenow<0) { slobenow=slobenow*-1; }

if (slobe > slobenow )

{

Plot0.Set(1);

}

else

{

Plot0.Set(-1);

}

NinjaTrader_Ray
04-12-2007, 07:32 AM
Check your log, I bet there is an index out of range error?

You are accessing values EMA(MyInput0)[2] (value 2 bars ago) when a value2 bars ago likely does not exist. For example, on the 1st bar on the chart, there is no bar 2 bars ago.

Add something like:

if (CurrentBar < 2)
return;

Ray

Creamers
04-13-2007, 07:03 AM
Damn, you're right! (as always :) Thx!