Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TMO from chatgpt has many errors can any expert fix please?

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

    TMO from chatgpt has many errors can any expert fix please?

    // TMO (True Momentum Oscillator) for NinjaTrader 8
    // Original concept by Mobius, converted by ChatGPT

    region Using declarations
    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript.Strategies;
    using NinjaTrader.NinjaScript.Indicators;
    #endregion

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class TMO : Indicator
    {
    private Series<double> rawMomentum;
    private EMA ema1;
    private EMA mainEMA;
    private EMA signalEMA;

    [NinjaScriptProperty]
    [Range(1, int.MaxValue), Gui.Label("Length")]
    public int Length { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue), Gui.Label("Calculation Length")]
    public int CalcLength { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue), Gui.Label("Smooth Length")]
    public int SmoothLength { get; set; }

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"TMO (True Momentum Oscillator) by Mobius";
    Name = "TMO";
    Calculate = MarketCalculate.OnBarClose;
    IsOverlay = false;

    Length = 14;
    CalcLength = 5;
    SmoothLength = 3;

    AddPlot(Brushes.LimeGreen, "Main");
    AddPlot(Brushes.Gray, "Signal");
    }
    else if (State == State.DataLoaded)
    {
    rawMomentum = new Series<double>(this);
    ema1 = EMA(rawMomentum, CalcLength);
    mainEMA = EMA(ema1, SmoothLength);
    signalEMA = EMA(mainEMA, SmoothLength);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < Length)
    return;

    double sum = 0.0;
    for (int i = 0; i <= Length && CurrentBar - i >= 0; i++)
    {
    double delta = Close[0] > Open[i] ? 1 : Close[0] < Open[i] ? -1 : 0;
    sum += delta;
    }

    rawMomentum[0] = sum;

    Values[0][0] = mainEMA[0]; // Main line
    Values[1][0] = signalEMA[0]; // Signal line
    }
    }
    }​

    #2
    Hello geo123,

    Thank you for your post.

    While our support team cannot debug this script for you, we can assist you with debugging and guiding you through fixing the compile errors if you are interested in resolving the errors yourself. If you are, please provide a screenshot of the compile errors.

    If you are using an external AI tool those generally cannot create valid NinjaScript, I have included some information about that below.


    From our experience at this time, ChatGPT and other AI models are not quite adequate to reliably and consistently generate valid compilable NinjaScripts that function as the user intends. We often find that the AI-generated code will call non-existent properties and methods, use improper classes or inheritance, exclude necessary components such as using statements, 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 guide than the actual code generated.

    Below is a link to a forum thread that discusses ChatGPT and it's limitations.


    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.

    Below I am providing a link to a support article with helpful resources on getting started with NinjaScript and C#.


    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

    Comment


      #3
      Hi Gaby Thanks for your reply. I would like to try I have got the errors down some.
      your help is much appreciated.
      Attached Files

      Comment


        #4
        Hello geo123,

        It appears you have written in to support via email already with this screenshot, I've replied to your email with further instructions.

        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