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

WMA_Slope_Color?

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

    WMA_Slope_Color?

    (EN)
    Hello, someone who has this flag but instead of being Exponential Moving Average (EMA) refers to Weighted Moving Average (WMA).

    Thanks.

    (ES)
    Hola, alguien que tenga este indicador pero de vez de ser Exponential Moving Average (EMA) haga referencia a Weighted Moving Average (WMA).

    Gracias.
    Attached Files

    #2
    nikelado80, the change should be simple...you would just need to comment the current Value.Set...and replace with the one using WMA smoothing - Value.Set(WMA(Input, Period)[0]);
    BertrandNinjaTrader Customer Service

    Comment


      #3
      (EN)
      Hi Bertrand, I did what you told me you can see below, but still can not see the WMA.
      Will I have to change anything. You can look at the code to see if it is okay?

      Thanks for the help.Escuchar
      Leer fonéticamente

      (ES)
      Hola Bertrand, he hecho lo que me dijiste lo puedes ver abajo, pero sigo sin poder ver la WMA.
      Será que tengo que cambiar otra cosa. Puedes mirar el código para ver si está bien?

      Gracias por la ayuda.


      EMA_Slope_Color


      protected override void OnBarUpdate()
      {
      Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);


      if(Rising(Value))
      {
      if(slopeColor)
      PlotColors[0][0] = upColor;
      }
      if(Falling(Value))
      {
      if(slopeColor)
      PlotColors[0][0] = dnColor;
      }

      }


      WMA

      protected override void OnBarUpdate()
      {
      if (CurrentBar == 0)
      Value.Set(Input[0]);
      else
      {
      int back = Math.Min(Period - 1, CurrentBar);
      double val = 0;
      int weight = 0;
      for (int idx = back; idx >=0; idx--)
      {
      val += (idx + 1) * Input[back - idx];
      weight += (idx + 1);
      }
      Value.Set(val / weight);
      }
      }

      WMA_Slope_Color

      protected override void OnBarUpdate()
      {
      if (CurrentBar == 0)
      Value.Set(Input[0]);
      else
      {
      int back = Math.Min(Period - 1, CurrentBar);
      double val = 0;
      int weight = 0;
      for (int idx = back; idx >=0; idx--)
      {
      val += (idx + 1) * Input[back - idx];
      weight += (idx + 1);
      }
      Value.Set(val / weight);
      }

      if(Rising(Value))
      {
      if(slopeColor)
      PlotColors[0][0] = upColor;
      }
      if(Falling(Value))
      {
      if(slopeColor)
      PlotColors[0][0] = dnColor;
      }

      }

      Comment


        #4
        Do you see any errors in the log tab? There would be no need to calculate the WMA again...it's already available as a method so you only need to use the snippet I posted earlier to call it and put it's values into your indicator's Value.Set to work with it.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi Bertrand, has been pretty easy, I thought it would be much more complicated.

          Thank you very much for your help

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by lorem, Yesterday, 09:18 AM
          4 responses
          14 views
          0 likes
          Last Post lorem
          by lorem
           
          Started by Spiderbird, Today, 12:15 PM
          0 responses
          5 views
          0 likes
          Last Post Spiderbird  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          12 responses
          42 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by FrazMann, Today, 11:21 AM
          0 responses
          6 views
          0 likes
          Last Post FrazMann  
          Started by geddyisodin, Yesterday, 05:20 AM
          8 responses
          52 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X