Skip to content

Instantly share code, notes, and snippets.

@DexterHaslem
Created July 10, 2012 19:13
Show Gist options
  • Save DexterHaslem/3085590 to your computer and use it in GitHub Desktop.
Save DexterHaslem/3085590 to your computer and use it in GitHub Desktop.
NinjaTrader create Indicator type @ runtime
using System;
using System.ComponentModel;
namespace NinjaTrader.Indicator
{
[Description("f")]
public class derp : Indicator
{
IndicatorBase myEMA;
protected override void Initialize()
{
Overlay = true;
CalculateOnBarClose = false;
}
protected override void OnStartUp()
{
myEMA = CreateInstance("EMA", Input);
}
protected override void OnBarUpdate()
{
if (myEMA == null)
return;
Print("Runtime: " + myEMA[0]);
}
// I highly do not recommend this, as it mimics the NT wrapper code, minus the caching functionality
private IndicatorBase CreateInstance(string indicatorName, Data.IDataSeries inputSeries)
{
Type indicatorType = Type.GetType("NinjaTrader.Indicator." + indicatorName);
if (indicatorType == null)
return null;
IndicatorBase indicatorBase = (IndicatorBase) Activator.CreateInstance(indicatorType);
indicatorBase.BarsRequired = BarsRequired;
indicatorBase.CalculateOnBarClose = CalculateOnBarClose;
indicatorBase.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicatorBase.MaximumBarsLookBack = MaximumBarsLookBack;
indicatorBase.Input = inputSeries;
Indicators.Add(indicatorBase);
indicatorBase.SetUp();
return indicatorBase;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment