I want to write an add-on that can be used like an indicator from a strategy. I believe i cant pass the Indicator object to my classes - where my classes use indicators. So that means that I must rewrite the indicators that my classes use to use Ninjascript base.
I use the EMA indicator in my classes, so i decided to rewrite that, and came up with the following code below, but it doesnt seem to work.. what am I doing incorrectly..
Thank you in advance.
namespace Khaos_Elements
{
public class Khaos_EMA
{
private NinjaScriptBase NinjaScriptBase;
private int Period;
private double constant1;
private double constant2;
public Series<double> Value { get; private set; }
public Khaos_EMA(NinjaScriptBase NinjaScriptBase)
{
this.NinjaScriptBase = NinjaScriptBase;
this.Period = Period;
constant1 = 2.0 / (1 + Period);
constant2 = 1 - (2.0 / (1 + Period));
Value = new Series<double>(NinjaScriptBase);
}
public Series<double> TickTock(int Period)
{
try
{
Value[0] = (NinjaScriptBase.CurrentBar == 0 ? NinjaScriptBase.Input[0] : NinjaScriptBase.Input[0] * constant1 + constant2 * Value[1]);
return Value;
}
catch (Exception e)
{
NinjaScriptBase.Log ("Cought Error Khaos Moving Average = " + e.ToString(), NinjaTrader.Cbi.LogLevel.Warning);
NinjaScriptBase.Print(NinjaScriptBase.Time[0] + " " + e.ToString());
return Value;
}
}
}
}

Comment