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 memonic, Yesterday, 01:23 PM
          2 responses
          12 views
          0 likes
          Last Post memonic
          by memonic
           
          Started by merc410, Today, 03:41 AM
          2 responses
          13 views
          0 likes
          Last Post merc410
          by merc410
           
          Started by sugalt, 04-30-2024, 04:02 AM
          2 responses
          13 views
          0 likes
          Last Post sugalt
          by sugalt
           
          Started by Ndakotan1313, 03-14-2024, 05:02 PM
          2 responses
          64 views
          0 likes
          Last Post blaise_code  
          Started by claxxical, 05-30-2017, 12:30 PM
          37 responses
          4,465 views
          0 likes
          Last Post Padan
          by Padan
           
          Working...
          X