Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Script Error Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script Error Help

    I am getting Class Member Declaration expected error on this script and other errors. Can someone please look into this script and guide me on how to fix errors. Thank You.

    #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.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators

    Description = @"SLOPE DIRECTIONAL LINE";
    Name = "SDL";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = false;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    AddPlot(Brushes.Orange, "SDL1");
    }
    {
    public class SDL : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {

    AddPlot(new Stroke(Brushes.Orange), PlotStyle.Line, "Plot1");
    AddLine(Brushes.Blue, 0, "Zeroline");
    period1 = 10;

    IsOverlay = false;
    }

    if (State == State.DataLoaded)
    {
    wMA1 = WMA(Input,period1/2);
    wMA2 = WMA(Input,period1);
    Plots[0].Width = 3;
    }
    }

    protected override void OnBarUpdate()
    {
    PlotSDL1[0] = 2 * wMA1[0] - wMA2[0];

    if (IsRising(PlotSDL1))
    PlotBrushes[0][0] = Brushes.Blue;
    if (IsFalling(PlotSDL1))
    PlotBrushes[0][0] = Brushes.Red;
    }


    else if (State == State.Configure)
    {
    }
    }

    protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
    {

    }

    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {

    }

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    }

    #region Properties

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> SDL1
    {
    get { return Values[0]; }
    }
    #endregion

    }
    }

    #region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private SDL[] cacheSDL;
    public SDL SDL()
    {
    return SDL(Input);
    }

    public SDL SDL(ISeries<double> input)
    {
    if (cacheSDL != null)
    for (int idx = 0; idx < cacheSDL.Length; idx++)
    if (cacheSDL[idx] != null && cacheSDL[idx].EqualsInput(input))
    return cacheSDL[idx];
    return CacheIndicator<SDL>(new SDL(), input, ref cacheSDL);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.SDL SDL()
    {
    return indicator.SDL(Input);
    }

    public Indicators.SDL SDL(ISeries<double> input )
    {
    return indicator.SDL(input);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.SDL SDL()
    {
    return indicator.SDL(Input);
    }

    public Indicators.SDL SDL(ISeries<double> input )
    {
    return indicator.SDL(input);
    }
    }
    }

    #endregion



    #2
    Hello henryk,
    Please find below my observations:-
    1. Name, Description etc. upto Plots should be in State.SetDefaults
    2. You must initialize Indicators you want to use before OnStateChange (WMA in your case)
    3. Must define all inputs, period1 is missing here
    4. PlotSDL1 is not defined, you defined SDL1 & using PlotSDL1
    5. No need for protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate) & protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    6. You have protected override void OnBarUpdate() twice, should be once only
    7. State.Configure should be before State.DataLoaded, can remove it if not required
    I would suggest you to use New Indicator Wizard to start the indicator & then copy just the required code. It seems you've copy paste just everything so getting errors.
    Consider these changes & then compile. Hope it helps!

    Comment


      #3
      Thank you for you help. I did clean up as per your recommendation. I just have one error in compiling. If you can help me out with this, it will be a great help.

      ERROR = "Type 'Ninja Trader Script Indicator SDL' already defines a member called 'On Bar Update" with same parameter tyep"




      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class SDL : Indicator
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "SLOPE DIRECTIONAL LINE";
      Name = "SDL";
      Calculate = Calculate.OnEachTick;
      AddPlot(new Stroke(Brushes.Orange), PlotStyle.Line, "Plot1");
      AddLine(Brushes.Blue, 0, "Zeroline");
      period1 = 10;
      IsOverlay = false;
      //DisplayInDataBox = true;
      //DrawOnPricePanel = true;
      //DrawHorizontalGridLines = true;
      //DrawVerticalGridLines = true;
      //PaintPriceMarkers = true;
      //ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
      //See Help Guide for additional information.
      //IsSuspendedWhileInactive = true;
      }

      if (State == State.DataLoaded)
      {
      //wMA1 = WMA(Input,period1/2);
      //wMA2 = WMA(Input,period2);
      Plots[0].Width = 3;
      }
      }

      protected override void OnBarUpdate()
      {
      Plot1[0] = 2 * WMA(Input,period/2)[0] - WMA(Input,period)[0];

      if (IsRising(Plot1))
      PlotBrushes[0][0] = Brushes.Blue;
      if (IsFalling(Plot1))
      PlotBrushes[0][0] = Brushes.Red;
      }


      protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
      {

      }

      protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
      {

      }

      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here.
      }
      }
      }

      #region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private SDL[] cacheSDL;
      public SDL SDL()
      {
      return SDL(Input);
      }

      public SDL SDL(ISeries<double> input)
      {
      if (cacheSDL != null)
      for (int idx = 0; idx < cacheSDL.Length; idx++)
      if (cacheSDL[idx] != null && cacheSDL[idx].EqualsInput(input))
      return cacheSDL[idx];
      return CacheIndicator<SDL>(new SDL(), input, ref cacheSDL);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.SDL SDL()
      {
      return indicator.SDL(Input);
      }

      public Indicators.SDL SDL(ISeries<double> input )
      {
      return indicator.SDL(input);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.SDL SDL()
      {
      return indicator.SDL(Input);
      }

      public Indicators.SDL SDL(ISeries<double> input )
      {
      return indicator.SDL(input);
      }
      }
      }

      #endregion

      Comment


        #4
        Hello henryk,
        I mentioned about this in Point # 6.
        Here you get the indicator, refer it for better understanding.
        SDL.zip
        Last edited by s.kinra; 11-12-2020, 09:27 AM. Reason: attachment issue

        Comment


          #5
          Hello henryk,

          Thanks for your post and welcome to the NinjaTrader forums!

          In the above post you have two instances of OnBarUpdate():

          protected override void OnBarUpdate()
          {
          Plot1[0] = 2 * WMA(Input,period/2)[0] - WMA(Input,period)[0];

          if (IsRising(Plot1))
          PlotBrushes[0][0] = Brushes.Blue;
          if (IsFalling(Plot1))
          PlotBrushes[0][0] = Brushes.Red;
          }


          and then later

          protected override void OnBarUpdate()
          {
          //Add your custom indicator logic here.
          }



          I would suggest removing as follows:

          protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
          {

          }

          protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
          {

          }

          protected override void OnBarUpdate()
          {
          //Add your custom indicator logic here.
          }

          ​​​​​​​

          I would like to echo forum member s.kinra's advise, for new scripts, to use the Ninjascript wizard to create the structure​​​​​​​ as this will save a lot of time and effort. Please see the help guide here: https://ninjatrader.com/support/help...?ns_wizard.htm The wizard will help create the inputs, outputs and any custom series.

          Comment


            #6
            Paul,

            I worked on your suggestion and worked on resolving errors. Below is the code. Can you please look help me with it. I am not a computer person but trying to learn. So bit frustrated. Thank you for your help. If you can help me fix this and I can copy and paste your code that would be great help. After hitting compile I am getting following errors.

            NAME "WMA1, WMA2, PLOT1, PERIOD1" DOES NOT EXIST IN CURRENT CONTEXT.


            namespace NinjaTrader.NinjaScript.Indicators
            {
            public class SDL : Indicator
            {
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Enter the description for your new custom Indicator here.";
            Name = "SDL";
            AddPlot(new Stroke(Brushes.Orange), PlotStyle.Line, "Plot1");
            AddLine(Brushes.Blue, 0, "Zeroline");
            period1 = 10;
            IsOverlay = false;

            }

            if (State == State.Configure)
            {
            wMA1 = WMA(Input,period1/2);
            wMA2 = WMA(Input,period1);
            Plots[0].Width = 3;
            }
            }

            protected override void OnBarUpdate()
            {
            Plot1[0] = 2 * wMA1[0] - wMA2[0];

            if (IsRising(Plot1))
            PlotBrushes[0][0] = Brushes.Blue;
            if (IsFalling(Plot1))
            PlotBrushes[0][0] = Brushes.Red;
            }
            }
            }

            Comment


              #7
              Hello henryk,

              Thanks for your reply.

              You would need to add private instances of the WMA, and create the data type for period1 like this:

              public class SDL : Indicator
              {
              private WMA wMA1, wMA2;
              private int period1;

              protected override void OnStateChange()
              {



              Please change State == State.Configure to State == State.DataLoaded


              I do not see output for your plot, typically this would appear in #region Properties, as created by the Ninjascript indicator wizard. This code would be after the last "}" of the OnBarUpdate() section but before the last two }}

              protected override void OnBarUpdate()
              {
              Plot1[0] = 2 * wMA1[0] - wMA2[0];

              if (IsRising(Plot1))
              PlotBrushes[0][0] = Brushes.Blue;
              if (IsFalling(Plot1))
              PlotBrushes[0][0] = Brushes.Red;
              }
              #region Properties
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Plot1
              {
              get { return Values[0]; }
              }
              #endregion

              }
              }

              Comment


                #8
                Paul, I got it to work. Thank you again.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                571 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                331 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                549 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                549 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X