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

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 Taddypole, 04-26-2024, 02:47 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_Eduardo  
      Started by futtrader, 04-21-2024, 01:50 AM
      6 responses
      58 views
      0 likes
      Last Post futtrader  
      Started by sgordet, Today, 11:48 AM
      0 responses
      4 views
      0 likes
      Last Post sgordet
      by sgordet
       
      Started by Trader146, Today, 11:41 AM
      0 responses
      5 views
      0 likes
      Last Post Trader146  
      Started by jpapa, 04-23-2024, 07:22 AM
      2 responses
      22 views
      0 likes
      Last Post rene69851  
      Working...
      X