Announcement

Collapse
No announcement yet.

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.

    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

        Comment


          #5
          Thanks Bertrand.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sjsj2732, 03-23-2026, 04:31 AM
          0 responses
          69 views
          0 likes
          Last Post sjsj2732  
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          312 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          306 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          146 views
          1 like
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          105 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Working...
          X