Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie Question

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

    #16
    Hello GCO77,

    Thanks for your reply.

    I would suggest posting your complete NT8 code as you have it right now, that way we can compare what you had in NT7 that was working to what you are trying to convert to NT8.


    Comment


      #17
      Originally posted by NinjaTrader_PaulH View Post
      Hello GCO77,

      Thanks for your reply.

      I would suggest posting your complete NT8 code as you have it right now, that way we can compare what you had in NT7 that was working to what you are trying to convert to NT8.

      Thank you,

      NT8 Code,

      PHP Code:
      //This namespace holds Indicators in this folder and is required. Do not change it. 
      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)
                  {                
                      EMA1                = EMA(Close, 15);
                      EMA2                = EMA(Close, 20);
                  }
              }
      
      
              protected override void OnBarUpdate()
              {
                  if (BarsInProgress != 0)
      return;
      
      if (CurrentBars[0] < 256)
      return;
      
      // Set 1
      if ((EMA1[0] > EMA2[0])
      
      {
      trueFalse = 1;
      }
      else
      {
      trueFalse = -1;
      
           // set to zero if coss conditions are not true.
      } // assign to the plot.);
      
                  }    
      #region Properties
              [Browsable(false)]
              [XmlIgnore()]
              public Series<double> SignalPlot
              {
                  get { return Values[0]; }
              }
      #endregion 
          }
      } 
      
      VS

      NT7 Code

      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(15)[0] > EMA(20)[0] )
      {
        Plot0.Set(1);
      }
      else if (  EMA(20)[0] > EMA(15)[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
          }
      } 
      

      Comment


        #18
        Hello GCO77,

        Thanks for your reply.

        I suspect you missed or are unsure of my reply in post # 12:

        "It looks like you are missing assigning the variable to the plot.

        SignalPlot[0] = trueFalse; // assign to the plot."

        So specifically you need you code to look like this:

        if ((EMA1[0] > EMA2[0])
        {
        trueFalse = 1;
        }
        else
        {
        trueFalse = -1;
        }
        SignalPlot[0] = trueFalse; // assign to the plot."



        You could also code it directly like this:

        if ((EMA1[0] > EMA2[0])
        {
        SignalPlot[0] = 1;
        }
        else
        {
        SignalPlot[0] = -1;
        }



        Please note that the above is not duplicating the same logic you are showing in NT7. To duplicate the NT7 logic and assign the output to a plot you would use:

        if ((EMA1[0] > EMA2[0])
        {
        SignalPlot[0] = 1;
        }
        else if (EMA2[0] > EMA1[0])
        {
        SignalPlot[0] = -1;
        }

        Comment


          #19
          Originally posted by NinjaTrader_PaulH View Post
          Hello GCO77,

          Thanks for your reply.

          I suspect you missed or are unsure of my reply in post # 12:




          So specifically you need you code to look like this:

          if ((EMA1[0] &gt; EMA2[0])
          {
          trueFalse = 1;
          }
          else
          {
          trueFalse = -1;
          }
          SignalPlot[0] = trueFalse; // assign to the plot."



          You could also code it directly like this:

          if ((EMA1[0] &gt; EMA2[0])
          {
          SignalPlot[0] = 1;
          }
          else
          {
          SignalPlot[0] = -1;
          }



          Please note that the above is not duplicating the same logic you are showing in NT7. To duplicate the NT7 logic and assign the output to a plot you would use:

          if ((EMA1[0] &gt; EMA2[0])
          {
          SignalPlot[0] = 1;
          }
          else if (EMA2[0] &gt; EMA1[0])
          {
          SignalPlot[0] = -1;
          }
          Thank you. Yes I have tried that way and it is still returning zero in the column.

          I have upload the script below. It is still returning zero in the market analyzer column.
          Attached Files

          Comment


            #20
            Hello GCO77,

            Thanks for your reply.

            I've applied the indicator, as is, to the market analyzer. Here is what I see along with the settings used in the market analyzer indicator column:

            Click image for larger version

Name:	GC077-1.PNG
Views:	120
Size:	97.6 KB
ID:	1085687
            Are you able to replicate?

            If you still see zeros, it may be due to how you have the column configured regarding the bars. The indicator also has a statement: if (CurrentBars[0] < 256) return; to ignore the first 256 bars so if your data is loading less than 256 bars then you would not see anything but zeros. That statement also does not appear in the NT7 code.

            Comment


              #21
              Originally posted by NinjaTrader_PaulH View Post
              Hello GCO77,

              Thanks for your reply.

              I've applied the indicator, as is, to the market analyzer. Here is what I see along with the settings used in the market analyzer indicator column:

              Click image for larger version

Name:	GC077-1.PNG
Views:	120
Size:	97.6 KB
ID:	1085687
              Are you able to replicate?

              If you still see zeros, it may be due to how you have the column configured regarding the bars. The indicator also has a statement: if (CurrentBars[0] < 256) return; to ignore the first 256 bars so if your data is loading less than 256 bars then you would not see anything but zeros. That statement also does not appear in the NT7 code.

              Thanks that was exactly it the 256 bars.

              Thanks again. Cheers

              Comment


                #22
                i will find some time to try out the code in NT8 and let you know.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                115 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                61 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                40 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                43 views
                0 likes
                Last Post TheRealMorford  
                Started by Mindset, 02-28-2026, 06:16 AM
                0 responses
                82 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Working...
                X