Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error: Class member declaration expected (Line 122 Column 26) Plz help me fix it

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

    Error: Class member declaration expected (Line 122 Column 26) Plz help me fix it

    using System;
    using System.Windows.Media;

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class OrderBlockIndicator : Indicator
    {
    private double _marketVolume;
    private double _limitVolume;
    private double _totalVolume;

    private int _startBar;
    private int _endBar;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Identify potential order blocks";
    Name = "OrderBlockIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = false;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = false;
    ScaleJustification = ScaleJustification.Right;
    IsSuspendedWhileInactive = true;

    BlockVolumeRatio = 2.0;
    ContourLineColor = Brushes.Yellow;
    ContourLineWidth = 2;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1)
    {
    // Calculate market and limit volumes
    double volume = Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[1][0]) : Volume[1][0];
    if (Close[1][0] > Open[1][0])
    {
    _marketVolume += volume;
    }
    else
    {
    _limitVolume += volume;
    }
    _totalVolume += volume;

    // Check for potential order block
    double blockVolume = BlockVolumeRatio * _marketVolume;
    if (_limitVolume >= blockVolume)
    {
    _startBar = Math.Max(0, CurrentBar - Bars.Period.Value);
    }
    if (_marketVolume >= blockVolume && _startBar > 0)
    {
    _endBar = CurrentBar;

    // Mark order block with contour line
    double low = Low[1][_startBar];
    double high = High[1][_endBar];
    Draw.Rectangle(this, "OrderBlock" + _startBar, true, _startBar, low, _endBar, high, null, ContourLineColor, ContourLineWidth);
    }
    }
    else if (BarsInProgress == 0)
    {
    // Reset volumes at the start of a new session
    if (Bars.IsFirstBarOfSession)
    {
    _marketVolume = 0;
    _limitVolume = 0;
    _totalVolume = 0;
    _startBar = -1;
    _endBar = -1;
    }
    }
    }

    region Properties

    [NinjaScriptProperty]
    [Range(0.1, double.MaxValue)]
    [Display(Name = "BlockVolumeRatio", Description = "Ratio of market order volume to limit order volume for a potential order block", Order = 1, GroupName = "Parameters")]
    public double BlockVolumeRatio { get; set; }

    [NinjaScriptProperty]
    [XmlIgnore]
    [Display(Name = "ContourLineColor", Description = "Color of contour line marking potential order blocks", Order = 2, GroupName = "Parameters")]
    public Brush ContourLineColor { get; set; }

    [Browsable(false)]

    #2
    Originally posted by minhthinh1608 View Post
    using System;
    using System.Windows.Media;

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class OrderBlockIndicator : Indicator
    {
    private double _marketVolume;
    private double _limitVolume;
    private double _totalVolume;

    private int _startBar;
    private int _endBar;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Identify potential order blocks";
    Name = "OrderBlockIndicator";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = false;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = false;
    ScaleJustification = ScaleJustification.Right;
    IsSuspendedWhileInactive = true;

    BlockVolumeRatio = 2.0;
    ContourLineColor = Brushes.Yellow;
    ContourLineWidth = 2;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1)
    {
    // Calculate market and limit volumes
    double volume = Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[1][0]) : Volume[1][0];
    if (Close[1][0] > Open[1][0])
    {
    _marketVolume += volume;
    }
    else
    {
    _limitVolume += volume;
    }
    _totalVolume += volume;

    // Check for potential order block
    double blockVolume = BlockVolumeRatio * _marketVolume;
    if (_limitVolume >= blockVolume)
    {
    _startBar = Math.Max(0, CurrentBar - Bars.Period.Value);
    }
    if (_marketVolume >= blockVolume && _startBar > 0)
    {
    _endBar = CurrentBar;

    // Mark order block with contour line
    double low = Low[1][_startBar];
    double high = High[1][_endBar];
    Draw.Rectangle(this, "OrderBlock" + _startBar, true, _startBar, low, _endBar, high, null, ContourLineColor, ContourLineWidth);
    }
    }
    else if (BarsInProgress == 0)
    {
    // Reset volumes at the start of a new session
    if (Bars.IsFirstBarOfSession)
    {
    _marketVolume = 0;
    _limitVolume = 0;
    _totalVolume = 0;
    _startBar = -1;
    _endBar = -1;
    }
    }
    }

    region Properties

    [NinjaScriptProperty]
    [Range(0.1, double.MaxValue)]
    [Display(Name = "BlockVolumeRatio", Description = "Ratio of market order volume to limit order volume for a potential order block", Order = 1, GroupName = "Parameters")]
    public double BlockVolumeRatio { get; set; }

    [NinjaScriptProperty]
    [XmlIgnore]
    [Display(Name = "ContourLineColor", Description = "Color of contour line marking potential order blocks", Order = 2, GroupName = "Parameters")]
    public Brush ContourLineColor { get; set; }

    [Browsable(false)]
    This is pic

    Comment


      #3
      Hello minhthinh1608,

      Thanks for your post.

      This error generally refers to a NinjaScript property that you have created.

      What exactly is the line of code that the error is referring to in the code you shared (Line 122 Column 26)?

      ​Is Line 122 part of a NinjaScript property you created? If so, how is that property being made in the script?

      Thanks in advance; I look forward to assisting further.
      Brandon H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by minhthinh1608 View Post
        This is pic
        Error are: Class member declaration expected; '}' expected Code CS1513. NinjaScript property i'm created. You can see in my post

        Comment


          #5
          Hello minhthinh1608,

          Thanks for your note.

          When testing the properties you shared in post # 1 and # 2, I am able to compile the script without errors. See the attached screenshot.

          This error, CS1513, indicates that the compiler expected a closing curly brace '}' that was not found.

          To resolve this, you will need to go through each line of code in your script to ensure that each one of the opening curly braces '{' has a closing curly brace '}' accompanying it. Note that each opening curly brace must have a closing curly brace.

          For more information about this error, you could do a quick Google search for 'C# CS1513 Compile Error' and view the MSDN documentation that appears in the search results.

          Please let me know if I may assist further.​
          Attached Files
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            I have checked all of them but can't find any missing

            Comment


              #7
              Hello minhthinh1608,

              Thanks for your note.

              If you run a compile and still get the error message stating "}" expected, this means there is a missing closing curly brace somewhere in the script.

              Based on the code you shared, it seems like you might be missing a closing curly brace to go with the 'namespace NinjaTrader.NinjaScript.Indicators' opening curly brace. You might be missing a closing curly brace to go with the public class OrderBlockIndicator : Indicator opening curly brace.

              Ultimately, it would be up to you to locate the missing closing curly brace(s) in your indicator's code to resolve the compile error.

              Also, please note the Properties region should be added directly after the OnBarUpdate() section of code. You could open a New > Strategy Builder window, create a couple user-defined inputs on the Inputs and Variables screen, and click the 'View code' button to see the generated syntax for how properties should be placed in a script.

              The screenshot in post # 5 also demonstrates how properties should be added in a script.

              Let me know if you have further questions.
              Last edited by NinjaTrader_BrandonH; 02-21-2023, 11:38 AM.
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                I see this error ALL the time - but for the life of me I don't know why. As you can see in both the image and the copied code all curly brackets are closed, yet the error persists.


                Click image for larger version

Name:	Capture.jpg
Views:	104
Size:	208.2 KB
ID:	1282131

                Here is the complete code -

                namespace NinjaTrader.NinjaScript.Indicators
                {
                public class DirectionalImbalances : Indicator
                {
                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"Highlights an Up or Down gap between candlesticks in a trend.";
                Name = "DirectionalImbalances";
                Calculate = Calculate.OnPriceChange;
                IsOverlay = true;
                DisplayInDataBox = false;
                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;
                }
                else if (State == State.Configure)
                {
                }
                }

                protected override void OnBarUpdate()
                {
                if (BarsInProgress != 0)
                return;

                if (CurrentBars[0] < 1)
                return;

                // Set 1
                if ((Open[0] > Close[1])
                && (Close[1] > Open[1])
                && (Close[0] > Open[0]))
                {
                CandleOutlineBrush = Brushes.MediumSpringGreen;
                Draw.ArrowUp(this, @"Gap_Up " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] + (-2 * TickSize)) , Brushes.MediumSpringGreen);
                BarBrush = Brushes.MediumSpringGreen;
                }

                // Set 2
                if ((Open[0] < Close[1])
                && (Close[1] < Open[1])
                && (Close[0] < Open[0]))
                {
                CandleOutlineBrush = Brushes.DeepPink;
                Draw.ArrowDown(this, @"Gap_Down " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + (2 * TickSize)) , Brushes.DeepPink);
                BarBrush = Brushes.DeepPink;
                }
                }
                }

                region NinjaScript generated code. Neither change nor remove.

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

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

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

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

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

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

                #endregion

                Comment


                  #9
                  Hello CampervanSeth,

                  Thanks for your notes.

                  This error indicates that you have a missing closing curly brace somewhere in your script.

                  You would need to ensure you go through each curly brace in your code to make sure that every open curly brace has a closing curly brace to go with it.

                  It seems like you may be missing a closing curly brace for the namespace open curly brace but I suggest going through each curly brace in your code to identify exactly which open curly brace is missing a closing curly brace.
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Yes - I understand this - I cannot find it which is why I am asking for help. It says line 135 - I have one there. For giggles I added another one and only got more errors. This is why I posted both the image and the full code. Please help me. I have read the section on the error code and am still lost.

                    Comment


                      #11
                      Hello CamperSeth,

                      Thanks for your notes.

                      As noted in post # 9, it seems like you may need to add a closing curly brace for the namespace open curly brace to resolve the error.

                      namespace NinjaTrader.NinjaScript.Indicators
                      {
                      public class DirectionalImbalances : Indicator
                      {
                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = @"Highlights an Up or Down gap between candlesticks in a trend.";
                      Name = "DirectionalImbalances";
                      Calculate = Calculate.OnPriceChange;
                      IsOverlay = true;
                      DisplayInDataBox = false;
                      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;
                      }
                      else if (State == State.Configure)
                      {
                      }
                      }

                      protected override void OnBarUpdate()
                      {
                      if (BarsInProgress != 0)
                      return;

                      if (CurrentBars[0] < 1)
                      return;

                      // Set 1
                      if ((Open[0] > Close[1])
                      && (Close[1] > Open[1])
                      && (Close[0] > Open[0]))
                      {
                      CandleOutlineBrush = Brushes.MediumSpringGreen;
                      Draw.ArrowUp(this, @"Gap_Up " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] + (-2 * TickSize)) , Brushes.MediumSpringGreen);
                      BarBrush = Brushes.MediumSpringGreen;
                      }

                      // Set 2
                      if ((Open[0] < Close[1])
                      && (Close[1] < Open[1])
                      && (Close[0] < Open[0]))
                      {
                      CandleOutlineBrush = Brushes.DeepPink;
                      Draw.ArrowDown(this, @"Gap_Down " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + (2 * TickSize)) , Brushes.DeepPink);
                      BarBrush = Brushes.DeepPink;
                      }
                      }
                      }
                      } //add this closing curly brace


                      That said, it would ultimately be up to you to debug your script and determine exactly where in the script the closing curly brace needs to be placed.

                      Note in the Support Department at NinjaTrader we do not provide debugging services in our support.
                      Brandon H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Jonafare, 12-06-2012, 03:48 PM
                      5 responses
                      3,986 views
                      0 likes
                      Last Post rene69851  
                      Started by Fitspressorest, Today, 01:38 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Fitspressorest  
                      Started by Jonker, Today, 01:19 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post Jonker
                      by Jonker
                       
                      Started by futtrader, Today, 01:16 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post futtrader  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      14 responses
                      1,792 views
                      0 likes
                      Last Post aligator  
                      Working...
                      X