Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

translate an easy language indicator to Ninjia8

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

    translate an easy language indicator to Ninjia8

    hi-
    before trying other avenues i wanted to kindly ask if anyone could do me a favor translating the following simple easy language indicator in whatever ninjia8 requires. i am new to Ninja and i cant focus on coding at this moment. This EL script works, and what it does is printing in the chart a dot above(red) /below (blue) a candle when the slow stochastics is above/below 80/20. the indicator below already sets the stochastics input, and i am fine with. See also a screenshot of how it looks like in TS (red and blue dots) thanks




    inputs:
    PriceH(High),
    PriceL(Low),
    PriceC(Close),
    StochLength(9),
    SmoothingLength1(3),
    SmoothingLength2(3),
    SmoothingType(1),
    OverSold(20),
    OverBought(80),
    L1(4), // lunghezza media per calcolo offset
    per(1.5);

    variables:
    ReturnValue(0),
    oFastK(0),
    oFastD(0),
    oSlowK(0),
    oSlowD(0);


    ReturnValue = Stochastic(High, Low, Close, StochLength, SmoothingLength1,
    SmoothingLength2, SmoothingType, oFastK, oFastD, oSlowK, oSlowD);


    if oSlowD > OverBought Then
    plot1(high + per * average(range, L1), "Sopra soglia", red)
    Else
    if oSlowD < OverSold Then
    plot2(low - per * average(range, L1), "Sotto soglia", blue);




    //Plot1(oSlowK, "SlowK");
    //Plot1(oSlowD, "SlowD");
    //Plot3( OverBought, !( "OverBot" ) ) ;
    //Plot4( OverSold, !( "OverSld" ) ) ;





    Attached Files

    #2
    This code creates a custom NinjaTrader strategy that calculates the Stochastic Oscillator values (oSlowK and oSlowD) and plots lines above or below the current price based on the oSlowD value crossing overbought and oversold levels. The per and L1 variables are used to determine the distance of the plotted lines from the high and low prices, respectively.

    Note that the smoothingType variable in EasyLanguage might correspond to different moving average types in NinjaTrader, and I've assumed it to be a Simple Moving Average (SMA) with a value of 1. You may need to adjust this based on the specific requirements of your strategy.

    I'm developing a GPT specifically for NT so I gave it this task to translate the code. Hopefully someone with more C# experience than me can check and alter the code if there's more that needs to be done to it. I didn't run this through the complier either to see if it works off the bat but with a little luck, maybe it does.

    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;
    using NinjaTrader.NinjaScript.StrategyAnalyzer;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;
    using NinjaTrader.NinjaScript.StrategyGenerator;
    using NinjaTrader.NinjaScript.AddOns;
    using NinjaTrader.NinjaScript.AddOns.MarketAnalyzer;
    using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
    using NinjaTrader.NinjaScript.Strategies.PositionSizers;
    using NinjaTrader.NinjaScript.StrategyAnalyzer;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;
    using NinjaTrader.NinjaScript.Strategies;
    using NinjaTrader.Gui.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
    using NinjaTrader.NinjaScript.Strategies.PositionSizers;
    using NinjaTrader.NinjaScript.StrategyGenerator;
    using NinjaTrader.NinjaScript.StrategyAnalyzer;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;
    using NinjaTrader.NinjaScript.Strategies;
    using NinjaTrader.Gui.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
    using NinjaTrader.NinjaScript.Strategies.PositionSizers;
    using NinjaTrader.NinjaScript.StrategyGenerator;
    using NinjaTrader.NinjaScript.StrategyAnalyzer;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
    using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class CustomStochasticIndicator : Strategy
    {
    private double oSlowK;
    private double oSlowD;

    private int stochLength = 9;
    private int smoothingLength1 = 3;
    private int smoothingLength2 = 3;
    private int smoothingType = 1; // 1 corresponds to SMA in NinjaTrader
    private int overSold = 20;
    private int overBought = 80;
    private int L1 = 4;
    private double per = 1.5;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Custom Stochastic Indicator based on EasyLanguage script.";
    Name = "CustomStochasticIndicator";
    }
    }

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

    oSlowK = Stochastics(High, Low, Close, stochLength, smoothingLength1, smoothingLength2).K[0];
    oSlowD = Stochastics(High, Low, Close, stochLength, smoothingLength1, smoothingLength2).D[0];

    if (oSlowD > overBought)
    {
    // Plotting above threshold line
    Draw.Line(this, "AboveThreshold" + CurrentBar, false, L1, High[0] + per * SMA(Range(), L1)[0], 0, High[0] + per * SMA(Range(), L1)[0], Brushes.Red);
    }
    else if (oSlowD < overSold)
    {
    // Plotting below threshold line
    Draw.Line(this, "BelowThreshold" + CurrentBar, false, L1, Low[0] - per * SMA(Range(), L1)[0], 0, Low[0] - per * SMA(Range(), L1)[0], Brushes.Blue);
    }
    }
    }
    }

    Comment


      #3
      thank you i will try it. one question: is the first section (copied here after) also part of the indicator? thanks


      using System;
      using NinjaTrader.Cbi;
      using NinjaTrader.Gui.Tools;
      using NinjaTrader.NinjaScript;
      using NinjaTrader.NinjaScript.Strategies;
      using NinjaTrader.NinjaScript.StrategyAnalyzer;
      using NinjaTrader.Data;
      using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;
      using NinjaTrader.NinjaScript.StrategyGenerator;
      using NinjaTrader.NinjaScript.AddOns;
      using NinjaTrader.NinjaScript.AddOns.MarketAnalyzer;
      using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
      using NinjaTrader.NinjaScript.Strategies.PositionSizers;
      using NinjaTrader.NinjaScript.StrategyAnalyzer;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;
      using NinjaTrader.NinjaScript.Strategies;
      using NinjaTrader.Gui.NinjaScript;
      using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
      using NinjaTrader.NinjaScript.Strategies.PositionSizers;
      using NinjaTrader.NinjaScript.StrategyGenerator;
      using NinjaTrader.NinjaScript.StrategyAnalyzer;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;
      using NinjaTrader.NinjaScript.Strategies;
      using NinjaTrader.Gui.NinjaScript;
      using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
      using NinjaTrader.NinjaScript.Strategies.PositionSizers;
      using NinjaTrader.NinjaScript.StrategyGenerator;
      using NinjaTrader.NinjaScript.StrategyAnalyzer;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.ColumnDef s;
      using NinjaTrader.NinjaScript.StrategyAnalyzer.Metrics;​

      Comment


        #4
        Those are the inputs or the library header files. You will need those but they go in a collapsable folder in the script.

        Comment


          #5
          i am sincerely thank full for your attention and inputs, but with my current the lack of knowledge on the subject i am unable to get then into a working indicator. I would tell you that i have tried, but the nature and amount of error msgs i get from the "compile" command are a "foreign language" to me. If you have some spare time to complete the work for me this time around i would be happy; if rather this is too much to ask i surely understand it and still i like to thank you very much. happy Sunday

          Comment


            #6
            Using machine-generated code is not going to be helpful in a case like this. It's actually of negative value, because it's a huge distraction and you end up spending all your time trying to figure out what the code generator did wrong which is usually a lot, together with a good number of random inclusions of things that don't matter and sometimes some hallucinated methods and function calls to APIs that do not exist. It would be much faster to just focus on coding what it is you want to code and learning what it is you need to learn.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment

            Latest Posts

            Collapse

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