Profile Picture

ZeroLagEMA

Posted By blousetrader 7 Years Ago
Message
Posted Friday May 21 2010
Trying to create a ZeroLagEMA but its not working (its producng a plot but way off) - whats wrong with this code

public class ZeroLagEMA : SeriesCalculatorBaseWithValues
{
private int _Period;
private double _prevValue;

private EMA ema1;
private EMA ema2;

[ConstructorArgument(Name = "Period",Type = ConstructorArgumentType.Integer,Value = "7",Order = 1)]
public ZeroLagEMA(int Period)
: base(1)
{

_Period = Period;

ema1 = new EMA(_Period);
ema2 = new EMA(_Period);


}

//   When using indicators inside indicators, override the
//   SetInputs, NewBar, and NewSeries methods. Call these
//   methods on the enclosed indicators before calling the
//   base implementation.
public override void SetInputs(params ISeries[] newInputs)
{
//   Input to _ma1 should be the same as the input for the SampleAverageAverage2 indicator
ema1.SetInputs(newInputs);
//   Use _ma1 as input to _ma2 indicator
ema2.SetInputs(ema1);
//   Call base implementation
base.SetInputs(newInputs);
}

public override void NewBar()
{
ema1.NewBar();
ema2.NewBar();
base.NewBar();
}
public override void NewSeries(int count)
{
ema1.NewSeries(count);
ema2.NewSeries(count);
base.NewSeries(count);
}



protected override double CalcNewValue(int lookBack)
{

int index = inputs[0].Count - lookBack - 1;
if (index < _Period*2)
{
_prevValue = inputs[0].LookBack(lookBack);
return _prevValue;
}


double difference = ema1.LookBack(lookBack) - ema2.LookBack(lookBack);

_prevValue = _prevValue + difference;

return _prevValue;

}
Posted Sunday May 23 2010
Never mind - being stupid - was adding to _prevValue instad of current ema


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems