Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Three moving averages

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

    Three moving averages

    Hi,

    Who can help me?
    I would like an indicator with three exponential moving averages. What is wrong in your code? (I see only one!)

    This is the code:

    [Description()]
    publicclass EMAs3 : Indicator
    {
    #region Variables

    privateint fast = 7; // Default setting for Fast
    privateint average = 14; // Default setting for Average
    privateint slow = 21; // Default setting for Slow

    #endregion

    protectedoverridevoid Initialize()
    {
    Add(new Plot(Color.Red, "EMA Fast"));
    Add(new Plot(Color.DarkViolet, "EMA Average"));
    Add(new Plot(Color.Blue, "EMA Slow"));

    Overlay = true;
    PriceTypeSupported = true;
    }

    protectedoverridevoid OnBarUpdate()
    {
    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Fast)) + (1 - (2.0 / (1 + Fast))) * Value[1]);

    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Average)) + (1 - (2.0 / (1 + Average))) * Value[1]);

    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Slow)) + (1 - (2.0 / (1 + Slow))) * Value[1]);
    }

    Thank you for your help

    germano

    #2
    germano,

    You cannot do Value.Set for all of them. Value.Set is only used when the indicator has one plot. If your indicator has multiple plots you need to call the appropriate plot names.

    Please see the MACD indicator for an example. Please note how the plots are named in the Properties region of the code.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh for suggestion; I am going to study the code of the MACD indicator.

      Hello

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      563 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      329 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X