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 ageeholdings, Today, 07:43 AM
      0 responses
      7 views
      0 likes
      Last Post ageeholdings  
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Started by rbeckmann05, Yesterday, 06:48 PM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      12 views
      0 likes
      Last Post burtoninlondon  
      Working...
      X