Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please fix this code

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

    Please fix this code

    Hi guys, I had chatGPT attempt to code an indicator for me as I have no coding experience. I have attempted to fix the bugs however failed greatly. It would be greatly appreciated if one of you coding genies could help me and show me the way forward in fixing this indicator!!! Thank you in advance

    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

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

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators.MyIndicators
    {
    public class myindicator : Indicator
    {
    private int xDays;
    private SMA absCloseOpenSMA;
    private SMA trueRangeSMA;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Moving Average (Abs (Close - Open), X Days) / Moving Average ((True High - True Low), X Days) * 100";
    Name = "Blast Off";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;

    XDays = 10;

    AddPlot(Brushes.Blue, "BlastOff");
    }
    else if (State == State.DataLoaded)
    {
    absCloseOpenSMA[0] = SMA(Math.Abs(Inputs[0] - Inputs[3]), XDays);
    trueRangeSMA = SMA(TrueRange(), XDays);

    AddChartIndicator(BlastOff);
    }
    }

    protected override void OnBarUpdate()
    {
    double blastOffValue = absCloseOpenSMA[0] / trueRangeSMA[0] * 100;

    PlotBrushes[0][0] = Brushes.Blue;
    PlotValues[0][0] = blastOffValue;
    }

    region Properties
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "XDays", GroupName = "NinjaScriptParameters", Order = 0)]
    public int XDays
    {
    get { return xDays; }
    set { xDays = value; }
    }
    #endregion
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private MyIndicators.myindicator[] cachemyindicator;
    public MyIndicators.myindicator myindicator(int xDays)
    {
    return myindicator(Input, xDays);
    }

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

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.MyIndicators.myindicator myindicator(int xDays)
    {
    return indicator.myindicator(Input, xDays);
    }

    public Indicators.MyIndicators.myindicator myindicator(ISeries<double> input , int xDays)
    {
    return indicator.myindicator(input, xDays);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.MyIndicators.myindicator myindicator(int xDays)
    {
    return indicator.myindicator(Input, xDays);
    }

    public Indicators.MyIndicators.myindicator myindicator(ISeries<double> input , int xDays)
    {
    return indicator.myindicator(input, xDays);
    }
    }
    }

    #endregion


    #2
    Hello Burkey0411,

    Thank you for your post and welcome to the NinjaTrader forums!

    In the support department at NinjaTrader, it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates. This thread will remain open for any community members who would like to assist you with modifying this script.

    That said, through email or on the forum we are happy to answer any specific questions you may have about NinjaScript if you decide to code this yourself. We are also happy 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.

    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.

    Please let me know if I may be of further assistance.​

    Comment


      #3
      Hi Burkey0411, it looks like you have not plotted anything. I don't know what PlotValues[0][0] is but try replacing that with Value[0] = blastOffValue;
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        This code is absolute junk. You'd be better off explaining what you need the indicator to do and asking for guidance, rather than posting junk code from a AI chatbot.

        Comment


          #5
          I spent some hours testing chatGPT testing its code. I agree with @kevinenergy​, the code produced by chatGPT is absolutely junk.

          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
          330 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
          548 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