Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Syntax for two moving averages

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

    Syntax for two moving averages

    Hello,

    sorry, I have a new question.

    I want to build an indicator that has two moving averages; one move 10 bars ago on the current bar and the other not.

    Type:

    protected overridevoid Initialize()
    {
    Add(new Plot(Color.Red, "SMA"));
    Displacement = 0;
    Add(new Plot(Color.Green, "SMA"));
    Displacement = 10;
    }

    This syntax does not work. How do I do?

    Thank you for your answer.
    germano

    #2
    Hi germano, is this the only code you use for your Indicator? It misses the OnBarUpdate() where the values are calculated for the plots you created.

    You can just load two regular SMA indicators on the chart, both will offer the displacement parameter for setting it to your needs.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I tried even so, but does not work:

      publicclass SMA2 : Indicator
      {
      #region Variables
      privateint period = 28; // Default setting for SMA
      #endregion

      protectedoverridevoid Initialize()
      {
      Add(
      new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "SMA_1")); //Displacement = 0;
      Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "SMA_2")); //Displacement = 10;

      CalculateOnBarClose = true;
      Overlay =
      false;
      PriceTypeSupported =
      false;
      }

      protectedoverridevoid OnBarUpdate()
      {
      SMA_1.Set(SMA(period)[
      0]);
      SMA_2.Set(SMA(period)[
      10]);
      }

      Comment


        #4
        Did you notice errors in the log tab with this new code?

        Most likely related to this - http://www.ninjatrader-support2.com/...ead.php?t=3170
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks Bertrand.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          22 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          21 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X