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 Haiasi, Today, 06:53 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by ScottWalsh, Today, 06:52 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by ScottW, Today, 06:09 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by ftsc2022, 10-25-2022, 12:03 PM
      5 responses
      256 views
      0 likes
      Last Post KeyonMatthews  
      Started by Board game geek, 10-29-2023, 12:00 PM
      14 responses
      244 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Working...
      X