Created
July 10, 2012 19:13
-
-
Save DexterHaslem/3085590 to your computer and use it in GitHub Desktop.
NinjaTrader create Indicator type @ runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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