I'm trying to create a new indicator and having a little problem.
I keep getting these error messages at: Noise = SUM (Diff, Period)[0]; When I Print Diff or Period I can see them but when I want to add them up I get:
The best overloaded method match for 'NinjaTrader.NinjaScript.Strategies.SUM(NinjaTrade r.NinjaScript.ISeries<double>, int)' has some invalid arguments
and
cannot convert from "double" to NinjaTrader.NinjaScript.Series<double>
but when I put Close instead of Diff, then everything is fine.
So far I output everything and all variables print just fine till this point.
i appreciate any help.
here is the whole code which is not much...it's just the start.
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class adaptiveSht3 : Strategy { private Brush Brush1; private EMA EMA1; private EMA EMA2; // int Period = 10; // vars double Diff = 0; //change later double Finalout = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Buy and Sell trading strategy"; Name = "adaveSht3"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.Infinite; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; FastMA = 7; SlowMA = 14; } else if (State == State.Configure) { Brush1 = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF403F45")); Brush1.Freeze(); } else if (State == State.DataLoaded) { EMA1 = EMA(Close, Convert.ToInt32(FastMA)); EMA1.Plots[0].Brush = Brushes.Red; AddChartIndicator(EMA1); EMA2 = EMA(Close, Convert.ToInt32(SlowMA)); EMA2.Plots[0].Brush = Brushes.Goldenrod; AddChartIndicator(EMA2); EMA2 = EMA(Close, Convert.ToInt32(SlowMA)); // these objects and their related members are not available until State.DataLoaded Print(Bars.Count); Print(Instrument.FullName); Print(Period); Print(Filter); Print(Close[0]); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; //New Indicater //Calculate Ratio Diff = (Math.Abs (Close[0] - Close[1])); if (CurrentBars[0] <= Period) { Finalout = Close[0]; } if (CurrentBars[0] > Period) { Signal = (Math.Abs (Close[0] - Close[Period])); Noise = SUM (Diff, Period)[0]; } Print(Noise); Print(Diff); // Set 1 _-_ To Buy if (EMA1[0] >= EMA2[0]) { //background color BackBrush = Brush1; //to buy EnterLong(Convert.ToInt32(50), ""); } // Set 2 _-_ To Sell if (EMA1[0] < EMA2[0]) { //to sell ExitLong(Convert.ToInt32(50), "", ""); } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="FastMA", Description="Fast moving average", Order=1, GroupName="Parameters")] public int FastMA { get; set; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="SlowMA", Description="Slow moving average", Order=2, GroupName="Parameters")] public int SlowMA { get; set; } #endregion } }
Comment