Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Transferring Ninja Trader 7 Script into Ninja Trader 8

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

    Transferring Ninja Trader 7 Script into Ninja Trader 8

    I think I might have more luck posting in this forum.

    Trying to convert an old NinjaTrader Custom script I made for market analyzer into a custom indicator script for market analyzer in NinjaTrader 8.



    PHP Code:
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        [Description("Enter the description of your new custom indicator here")]
        public class EMACrossover : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay                = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
               if(  EMA(50)[0] > EMA(100)[0] )
    {
      Plot0.Set(1);
    }
    else if (  EMA(100)[0] > EMA(50)[0]  )
    {
      Plot0.Set(-1);
    }
            }
    
            #region Properties
            [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot0
            {
                get { return Values[0]; }
            }
    
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        } 
    

    #2
    Hello GCO7,

    Thank you for the post.

    Can you provide more detail on your questions? Are you asking in total what is required to convert this or about a specific part of the existing script?

    We have a list of code breaking changes in the following page which can help with conversions: https://ninjatrader.com/support/help...ng_changes.htm


    I look forward to being of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello GCO7,

      Thank you for the post.

      Can you provide more detail on your questions? Are you asking in total what is required to convert this or about a specific part of the existing script?

      We have a list of code breaking changes in the following page which can help with conversions: https://ninjatrader.com/support/help...ng_changes.htm


      I look forward to being of further assistance.
      Yes, I have tried to change the entire script by making my own in strategy builder in NT8 but my script keeps on showing 0 in the market analyzer column.

      Comment


        #4
        Hello GCO77,

        Thank you for the additional details.

        if you wanted to replicate this you would need to use the same type or an Indicator. A strategy specifically cannot be used with the market analyzer.

        In general the code for your script should be very similar however the overall file structure has changed some. I would suggest to generate a new empty indicator and then view the generated code before you start so you can see the difference in how the file is laid out.

        From the NinjaScript editor Click the Plus symbol or Right click on the indicator folder -> New indicator.

        Your script uses a Plot and an Input which you can configure using the new indicator wizard.

        If you use the indicator wizard to generate the script the only code you will need to convert from this file is the OnBarUpdate logic.

        Plots are no longer set using the .Set method, you would instead set a plot like the following:

        Code:
        Plot0[0] = 1;

        I look forward to being of further assistance.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello GCO77,

          Thank you for the additional details.

          if you wanted to replicate this you would need to use the same type or an Indicator. A strategy specifically cannot be used with the market analyzer.

          In general the code for your script should be very similar however the overall file structure has changed some. I would suggest to generate a new empty indicator and then view the generated code before you start so you can see the difference in how the file is laid out.

          From the NinjaScript editor Click the Plus symbol or Right click on the indicator folder -> New indicator.

          Your script uses a Plot and an Input which you can configure using the new indicator wizard.

          If you use the indicator wizard to generate the script the only code you will need to convert from this file is the OnBarUpdate logic.

          Plots are no longer set using the .Set method, you would instead set a plot like the following:

          Code:
          Plot0[0] = 1;

          I look forward to being of further assistance.
          This is the current script I have from NT 8 and in market analyzer the column is always showing up as zero.

          PHP Code:
          namespace NinjaTrader.NinjaScript.Indicators
          {
              public class TripleMov : Indicator
              {
          
                  private EMA EMA1;
                  private EMA EMA2;
                  private int trueFalse = 1;
          
                  protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          Description                                    = @"Enter the description for your new custom Indicator here.";
                          Name                                        = "TripleMov";
          
          
                          AddPlot(Brushes.Orange, "trueFalse"); // no need to show the plot so use Transparent    
                          Calculate                                    = Calculate.OnBarClose;
                          IsOverlay                                    = false;
                          DisplayInDataBox                            = true;
                          DrawOnPricePanel                            = true;
                          DrawHorizontalGridLines                        = true;
                          DrawVerticalGridLines                        = true;
                          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)
                      {
                      }
                  else if (State == State.DataLoaded)
                      {                
          
                      }
                  }
          
          
                  protected override void OnBarUpdate()
                  {
                      if (BarsInProgress != 0)
          return;
          
          if (CurrentBars[0] < 256)
          return;
          
          // Set 1
          if ((EMA(15)[0] > EMA(20)[0]))
          
          {
          trueFalse = 1;
          }
          else if (EMA(20)[0] > EMA(15)[0])
          {
          trueFalse = -1;
          }
          SignalPlot[0] = trueFalse; // assign to the plot."
          
                      }    
          #region Properties
                  [Browsable(false)]
                  [XmlIgnore()]
                  public Series<double> SignalPlot
                  {
                      get { return Values[0]; }
                  }
          #endregion 
          


          Thanks
          Attached Files
          Last edited by GCO77; 01-30-2020, 02:15 PM.

          Comment


            #6
            Hello GCO77,

            I tried this script however i see either ... (three dots) while it is loading or a value such as 1 or -1, I was not able to see 0 specifically.

            As far as I can tell this works, were there any other changes you made between posting this file and observing the 0 on your end which may have changed the result?

            I see you have a BarsInProgress condition, were you creating a multi series script? A new indicator is empty when you generate it, it would not have the other conditions you have for a multi series which may be part of the problem in your test.

            I also see the following condition:
            Code:
            if (CurrentBars[0] < 256)
            return;
            Are you loading more than 256 bars in the analyzer? If not you would not be able to plot the indicator because it will need to wait for 256 bars to process.



            I look forward to being of further assistance.

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello GCO77,

              I tried this script however i see either ... (three dots) while it is loading or a value such as 1 or -1, I was not able to see 0 specifically.

              As far as I can tell this works, were there any other changes you made between posting this file and observing the 0 on your end which may have changed the result?

              I see you have a BarsInProgress condition, were you creating a multi series script? A new indicator is empty when you generate it, it would not have the other conditions you have for a multi series which may be part of the problem in your test.

              I also see the following condition:
              Code:
              if (CurrentBars[0] < 256)
              return;


              Are you loading more than 256 bars in the analyzer? If not you would not be able to plot the indicator because it will need to wait for 256 bars to process.



              I look forward to being of further assistance.

              Thanks that was exactly it. Problem has been solved thanks again.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              649 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              370 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              576 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X