Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scripting Errors

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

    Scripting Errors

    I am using the following coding to make an efficiency Indicator and am continually getting errors:

    // This indicator highlights candles that have less volume than the previous candle but are larger in size
    // than a specified minimum threshold

    region Using declarations
    using System.ComponentModel;
    using System.Windows.Media;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Indicators;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    [Description("Highlights candles with less volume than the previous candle but are larger in size than a specified threshold.")]
    public class LessVolumeLargerCandle : Indicator
    {
    private int _threshold = 100;
    private Brush _bullishBrush = Brushes.Cyan;
    private Brush _bearishBrush = Brushes.Magenta;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Highlights candles with less volume than the previous candle but are larger in size than a specified threshold.";
    Name = "LessVolumeLargerCandle";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    PaintPriceMarkers = true;

    AddPlot(Brushes.Transparent, "LessVolumeLargerCandle");
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    }
    else if (State == State.Configure)
    {
    BarsArray[1].LoadHistoricalBars = true;
    ClearOutputWindow();
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0 || CurrentBars[0] < 2)
    return;

    int priorBar = CurrentBar - 1;

    // Check for bullish setup
    if (Close[priorBar] < Open[priorBar] &&
    Open[0] < Close[0] &&
    Volume[0] < Volume[priorBar] &&
    (Close[0] - Open[0]) >= _threshold)
    {
    Draw.Dot(this, "BullishDot" + CurrentBar, true, 0, High[0] + TickSize, _bullishBrush);
    }

    // Check for bearish setup
    if (Close[priorBar] > Open[priorBar] &&
    Open[0] > Close[0] &&
    Volume[0] < Volume[priorBar] &&
    (Open[0] - Close[0]) >= _threshold)
    {
    Draw.Dot(this, "BearishDot" + CurrentBar, true, 0, Low[0] - TickSize, _bearishBrush);
    }
    }

    region Properties
    [Description("The minimum size of the candle that triggers the highlight.")]
    [Category("Parameters")]
    [DisplayName("Threshold")]
    public int Threshold
    {
    get { return _threshold; }
    set { _threshold = Math.Max(value, 0); }
    }

    [XmlIgnore]
    [Browsable(false)]
    public Brush BullishBrush
    {
    get { return _bullishBrush; }
    set { _bullishBrush = value; }
    }

    [XmlIgnore]
    [Browsable(false)]
    public Brush BearishBrush
    {
    get { return _bearishBrush; }
    set { _bearishBrush = value; }
    }
    #endregion
    }
    }


    region NinjaScript generated code. Neither change nor remove.

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

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

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

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

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

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

    #endregion

    I am not too sure about Ninja Script so if anyones knows where I can get this reviewed and edited so i can compile it that would be greatly appreciated

    #2
    What on Earth... is this from ChatGPT?
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      I ask this because this code has some things in it that ChatGPT often does but that don't make sense - they just look good to the model. As an example, it adds a data series and then totally ignores it. Or, it adds parameters that have no way to be set like those brushes there. Or, it does something like an AddDataSeries but puts it in the wrong State. Or it makes up a property like .LoadHistoricalBars that does not exist... using XML markup syntax without any usings to support it... indexing back in the wrong way because it's how some other platform does it... one could go on... ChatGPT can spit out this kind of thing until the end of time but it takes longer to fix it than it does to just write the correct thing in the first place and it puts a burden on the forum community or on NinjaTrader Support to try to clean all this up because it's a bottomless pit that one cannot ever dig one's way out of... there is always more ChatGPT code that is broken no matter how much one rewrites and corrects...

      I (and many others) want to help you learn to program and would happily answer actual programming questions from you, but when you just paste a big blob of ChatGPT output in here as if you're stuck that really puts us in a quandry... maybe someone else wants to clean this up. I've listed where to start. Or another kind soul may ignore the code above and just write you what you are trying to do which would be a lot faster. But I'd much rather help you actually learn to program by answering your questions if you try yourself and get stuck. This is up so many wrong alleys that correcting those would take a lot longer than helping you with the actual task at hand so it's worse than not having a starting point - it's a starting point that's wrong in time-consuming ways and a big setback to just sitting down and asking how to do what you're trying to do.
      Last edited by QuantKey_Bruce; 04-30-2023, 07:05 PM.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Welcome to the forums!

        Originally posted by TMInvestments View Post
        int priorBar = CurrentBar - 1;
        I see many problems.

        For ex, the above statement is very very wrong.

        Can you please just attach your script?

        The way you added the code to your post, all the
        indention was removed ... it's a common problem.

        Comment


          #5
          Here you are with the ChatGPT code fixed, despite my reservations.

          Code:
          // This indicator highlights candles that have less volume than the previous candle but are larger in size
          // than a specified minimum threshold
          
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Windows.Media;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.NinjaScript.Indicators;
          using System.Xml.Serialization;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion
          
          namespace NinjaTrader.NinjaScript.Indicators
          {
          [Description("Highlights candles with less volume than the previous candle but are larger in size than a specified threshold.")]
          public class LessVolumeLargerCandle : Indicator
          {
          private int _threshold = 100;
          private Brush _bullishBrush = Brushes.Cyan;
          private Brush _bearishBrush = Brushes.Magenta;
          
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Highlights candles with less volume than the previous candle but are larger in size than a specified threshold.";
          Name = "LessVolumeLargerCandle";
          Calculate = Calculate.OnBarClose;
          IsOverlay = true;
          DisplayInDataBox = true;
          DrawOnPricePanel = true;
          PaintPriceMarkers = true;
          
          AddPlot(Brushes.Transparent, "LessVolumeLargerCandle");
          }
          }
          
          protected override void OnBarUpdate()
          {
          if (CurrentBar < 1) return;
          
          // Check for bullish setup
          if (Close[1] < Open[1] &&
          Open[0] < Close[0] &&
          Volume[0] < Volume[1] &&
          (Close[0] - Open[0]) >= _threshold)
          {
          Draw.Dot(this, "BullishDot" + CurrentBar, true, 0, High[0] + TickSize, _bullishBrush);
          }
          
          // Check for bearish setup
          if (Close[1] > Open[1] &&
          Open[0] > Close[0] &&
          Volume[0] < Volume[1] &&
          (Open[0] - Close[0]) >= _threshold)
          {
          Draw.Dot(this, "BearishDot" + CurrentBar, true, 0, Low[0] - TickSize, _bearishBrush);
          }
          }
          
          #region Properties
          [Description("The minimum size of the candle that triggers the highlight.")]
          [Category("Parameters")]
          [DisplayName("Threshold")]
          public int Threshold
          {
          get { return _threshold; }
          set { _threshold = Math.Max(value, 0); }
          }
          
          [XmlIgnore]
          [Browsable(false)]
          public Brush BullishBrush
          {
          get { return _bullishBrush; }
          set { _bullishBrush = value; }
          }
          
          [XmlIgnore]
          [Browsable(false)]
          public Brush BearishBrush
          {
          get { return _bearishBrush; }
          set { _bearishBrush = value; }
          }
          #endregion
          }
          }
          
          #region NinjaScript generated code. Neither change nor remove.
          
          namespace NinjaTrader.NinjaScript.Indicators
          {
              public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
              {
                  private LessVolumeLargerCandle[] cacheLessVolumeLargerCandle;
                  public LessVolumeLargerCandle LessVolumeLargerCandle()
                  {
                      return LessVolumeLargerCandle(Input);
                  }
          
                  public LessVolumeLargerCandle LessVolumeLargerCandle(ISeries<double> input)
                  {
                      if (cacheLessVolumeLargerCandle != null)
                          for (int idx = 0; idx < cacheLessVolumeLargerCandle.Length; idx++)
                              if (cacheLessVolumeLargerCandle[idx] != null &&  cacheLessVolumeLargerCandle[idx].EqualsInput(input))
                                  return cacheLessVolumeLargerCandle[idx];
                      return CacheIndicator<LessVolumeLargerCandle>(new LessVolumeLargerCandle(), input, ref cacheLessVolumeLargerCandle);
                  }
              }
          }
          
          namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
          {
              public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
              {
                  public Indicators.LessVolumeLargerCandle LessVolumeLargerCandle()
                  {
                      return indicator.LessVolumeLargerCandle(Input);
                  }
          
                  public Indicators.LessVolumeLargerCandle LessVolumeLargerCandle(ISeries<double> input )
                  {
                      return indicator.LessVolumeLargerCandle(input);
                  }
              }
          }
          
          namespace NinjaTrader.NinjaScript.Strategies
          {
              public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
              {
                  public Indicators.LessVolumeLargerCandle LessVolumeLargerCandle()
                  {
                      return indicator.LessVolumeLargerCandle(Input);
                  }
          
                  public Indicators.LessVolumeLargerCandle LessVolumeLargerCandle(ISeries<double> input )
                  {
                      return indicator.LessVolumeLargerCandle(input);
                  }
              }
          }
          
          #endregion
          ​
          Last edited by QuantKey_Bruce; 04-30-2023, 06:59 PM.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Hello TMInvestments,

            Welcome to the NinjaTrader Forums!

            Was this code provided by ChatGPT or did you code this indicator yourself?

            Please list exactly what the error messages report that appears in the code you shared so may provide insight on how you can go about resolving them.

            At first glance, .LoadHistoricalBars is not a supported NinjaScript property and should be removed from the script. Historical bars will automatically be processed as long as you do not skip historical processing in the script. You are also adding an additional data series to the script but are not utilizing the added series so this could likely be removed.

            From our experience at this time, ChatGPT is not quite adequate to generate valid compilable NinjaScripts that function as the user has intended. We often find that the generated code will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor, and use the code generated by ChatGPT as more as suggestions and guides when coding the script yourself, than using the actual code generated.

            While It would not be within our support model to correct these scripts at user request, we would be happy to provide insight for any direct specific inquiries you may have if you would like to create this script yourself. Our support is able to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

            "I am not too sure about Ninja Script so if anyones knows where I can get this reviewed and edited so i can compile it that would be greatly appreciated"

            You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.




            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              I corrected the code for you but I steadfastly maintain you are making a big mistake here, and would be far ahead to read the documentation and start trying to code these things yourself. Putting the burden on us or support to fix what ChatGPT does not understand is unreasonable and unfair, while the community shows incredible patience and generousity in trying to help people who are trying to learn and have actual questions.
              Bruce DeVault
              QuantKey Trading Vendor Services
              NinjaTrader Ecosystem Vendor - QuantKey

              Comment


                #8
                Coding images above was originally from Trading View but tried to convert it over to Ninja Trader using Chat CPT. Thank you Bruce for your Help

                Comment

                Latest Posts

                Collapse

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