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 judysamnt7, 03-13-2023, 09:11 AM
          4 responses
          57 views
          0 likes
          Last Post DynamicTest  
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          36 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          7 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          20 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          9 views
          0 likes
          Last Post cre8able  
          Working...
          X