Can you please (again) post the complete code you're using? That helps us get a full look at any errors that could be happening.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
2 EMA crossover need to convert strategy script to an Indicator
Collapse
X
-
Originally posted by NinjaTrader_Austin View PostHi simpletrades, are there any errors in your logs (right-most tab in Control Center)?
Can you please (again) post the complete code you're using? That helps us get a full look at any errors that could be happening.HTML Code://TwoEMAsCleanedUP as of 8-28 #region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// 2 EMAs Crossing /// </summary> [Description("2 EMAs Crossing")] public class TwoEMAsCleanedUP : Indicator { #region Variables private int periodF = 5; private int periodS = 6; private DataSeries fast; private DataSeries slow; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { Add(new Plot(Color.Orange, "Fast")); Add(new Plot(Color.Magenta, "Slow")); Overlay = true; CalculateOnBarClose = false; PriceTypeSupported = true; fast = new DataSeries(this); slow = new DataSeries(this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { { if (CurrentBar < 7) return; } fast.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + periodF)) + (1 - (2.0 / (1 + periodF))) * fast[1]); slow.Set(CurrentBar == 0 ? Open[0] : Open[0] * (2.0 / (1 + periodS)) + (1 - (2.0 / (1 + periodS))) * slow[1]); } #region Properties [Description("Fast EMA")] [Category("Parameters")] public int PeriodF { get { return periodF; } set { periodF = Math.Max(1, value); } } [Description("SlowEMA")] [Category("Parameters")] public int PeriodS { get { return periodS; } set { periodS = Math.Max(1, value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private TwoEMAsCleanedUP[] cacheTwoEMAsCleanedUP = null; private static TwoEMAsCleanedUP checkTwoEMAsCleanedUP = new TwoEMAsCleanedUP(); /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public TwoEMAsCleanedUP TwoEMAsCleanedUP(int periodF, int periodS) { return TwoEMAsCleanedUP(Input, periodF, periodS); } /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public TwoEMAsCleanedUP TwoEMAsCleanedUP(Data.IDataSeries input, int periodF, int periodS) { checkTwoEMAsCleanedUP.PeriodF = periodF; periodF = checkTwoEMAsCleanedUP.PeriodF; checkTwoEMAsCleanedUP.PeriodS = periodS; periodS = checkTwoEMAsCleanedUP.PeriodS; if (cacheTwoEMAsCleanedUP != null) for (int idx = 0; idx < cacheTwoEMAsCleanedUP.Length; idx++) if (cacheTwoEMAsCleanedUP[idx].PeriodF == periodF && cacheTwoEMAsCleanedUP[idx].PeriodS == periodS && cacheTwoEMAsCleanedUP[idx].EqualsInput(input)) return cacheTwoEMAsCleanedUP[idx]; TwoEMAsCleanedUP indicator = new TwoEMAsCleanedUP(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.Input = input; indicator.PeriodF = periodF; indicator.PeriodS = periodS; indicator.SetUp(); TwoEMAsCleanedUP[] tmp = new TwoEMAsCleanedUP[cacheTwoEMAsCleanedUP == null ? 1 : cacheTwoEMAsCleanedUP.Length + 1]; if (cacheTwoEMAsCleanedUP != null) cacheTwoEMAsCleanedUP.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheTwoEMAsCleanedUP = tmp; Indicators.Add(indicator); return indicator; } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(int periodF, int periodS) { return _indicator.TwoEMAsCleanedUP(Input, periodF, periodS); } /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(Data.IDataSeries input, int periodF, int periodS) { return _indicator.TwoEMAsCleanedUP(input, periodF, periodS); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(int periodF, int periodS) { return _indicator.TwoEMAsCleanedUP(Input, periodF, periodS); } /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(Data.IDataSeries input, int periodF, int periodS) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.TwoEMAsCleanedUP(input, periodF, periodS); } } } #endregion
Comment
-
Simpletrades, it looks like some private and public DataSeries are getting mixed up in your code. I'm pretty sure the below code is what you're looking for. Please take a look at what I've commented out and changed around.
Basically, plots need to be declared with an Add(...) statement (lines 35, 36), then they need to be .Set (lines 51-52), and lastly they need to be made public (lines 70-82).
Code://TwoEMAsCleanedUP as of 8-30 #region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// 2 EMAs Crossing /// </summary> [Description("2 EMAs Crossing")] public class TwoEMAsCleanedUP : Indicator { #region Variables private int periodF = 5; private int periodS = 6; //private DataSeries fast; //private DataSeries slow; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { Add(new Plot(Color.Orange, "Fast")); Add(new Plot(Color.Magenta, "Slow")); Overlay = true; CalculateOnBarClose = false; PriceTypeSupported = true; //fast = new DataSeries(this); //slow = new DataSeries(this); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 1) return; Fast.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + periodF)) + (1 - (2.0 / (1 + periodF))) * Fast[1]); Slow.Set(CurrentBar == 0 ? Open[0] : Open[0] * (2.0 / (1 + periodS)) + (1 - (2.0 / (1 + periodS))) * Slow[1]); } #region Properties [Description("Fast EMA")] [Category("Parameters")] public int PeriodF { get { return periodF; } set { periodF = Math.Max(1, value); } } [Description("SlowEMA")] [Category("Parameters")] public int PeriodS { get { return periodS; } set { periodS = Math.Max(1, value); } } [Browsable(false)] [XmlIgnore()] public DataSeries Fast { get { return Values[0]; } } [Browsable(false)] [XmlIgnore()] public DataSeries Slow { get { return Values[1]; } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private TwoEMAsCleanedUP[] cacheTwoEMAsCleanedUP = null; private static TwoEMAsCleanedUP checkTwoEMAsCleanedUP = new TwoEMAsCleanedUP(); /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public TwoEMAsCleanedUP TwoEMAsCleanedUP(int periodF, int periodS) { return TwoEMAsCleanedUP(Inputs[0], periodF, periodS); } /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public TwoEMAsCleanedUP TwoEMAsCleanedUP(Data.IDataSeries input, int periodF, int periodS) { if (cacheTwoEMAsCleanedUP != null) for (int idx = 0; idx < cacheTwoEMAsCleanedUP.Length; idx++) if (cacheTwoEMAsCleanedUP[idx].PeriodF == periodF && cacheTwoEMAsCleanedUP[idx].PeriodS == periodS && cacheTwoEMAsCleanedUP[idx].EqualsInput(input)) return cacheTwoEMAsCleanedUP[idx]; lock (checkTwoEMAsCleanedUP) { checkTwoEMAsCleanedUP.PeriodF = periodF; periodF = checkTwoEMAsCleanedUP.PeriodF; } lock (checkTwoEMAsCleanedUP) { checkTwoEMAsCleanedUP.PeriodS = periodS; periodS = checkTwoEMAsCleanedUP.PeriodS; } if (cacheTwoEMAsCleanedUP != null) for (int idx = 0; idx < cacheTwoEMAsCleanedUP.Length; idx++) if (cacheTwoEMAsCleanedUP[idx].PeriodF == periodF && cacheTwoEMAsCleanedUP[idx].PeriodS == periodS && cacheTwoEMAsCleanedUP[idx].EqualsInput(input)) return cacheTwoEMAsCleanedUP[idx]; TwoEMAsCleanedUP indicator = new TwoEMAsCleanedUP(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; indicator.Input = input; indicator.PeriodF = periodF; indicator.PeriodS = periodS; indicator.SetUp(); TwoEMAsCleanedUP[] tmp = new TwoEMAsCleanedUP[cacheTwoEMAsCleanedUP == null ? 1 : cacheTwoEMAsCleanedUP.Length + 1]; if (cacheTwoEMAsCleanedUP != null) cacheTwoEMAsCleanedUP.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheTwoEMAsCleanedUP = tmp; Indicators.Add(indicator); return indicator; } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(int periodF, int periodS) { return _indicator.TwoEMAsCleanedUP(Inputs[0], periodF, periodS); } /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(Data.IDataSeries input, int periodF, int periodS) { return _indicator.TwoEMAsCleanedUP(input, periodF, periodS); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> [Gui.Design.WizardCondition("Indicator")] public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(int periodF, int periodS) { return _indicator.TwoEMAsCleanedUP(Inputs[0], periodF, periodS); } /// <summary> /// 2 EMAs Crossing /// </summary> /// <returns></returns> public Indicator.TwoEMAsCleanedUP TwoEMAsCleanedUP(Data.IDataSeries input, int periodF, int periodS) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.TwoEMAsCleanedUP(input, periodF, periodS); } } } #endregionAustinNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
602 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
559 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment