Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Improved MACD Indicator how to...

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

    Improved MACD Indicator how to...

    Hi!
    My question is: Can I rewrite the MACD in the way that will use Weighted moving averages(SlowMA and FastMA). For example in ThinkOrSwim platform MACD comes with 4th parameter and you can choice the AverageType - The type of moving average to be used in calculations for MACD : simple, exponential, weighted, Wilder's, or Hull.). I will need only weighted....

    Thank You in advance.

    #2
    Hello krasisoft,

    Thanks for your post and welcome to the forums!

    Yes, it is certainly possible to edit the Macd's ninjascript file to change from ema to the ma of your choosing. You may also want to review the file sharing section of the forums to see if there is something there that will meet your needs or something that may provide an added feature that you might want to incorporate in your version of the macd.

    Here is a link to the helpguide section concerning developing indicators: http://ninjatrader.com/support/helpG...indicators.htm

    Comment


      #3
      This is what I changed:

      fastEma.Set((2.0 / (1 + Fast)) * Weighted[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
      slowEma.Set((2.0 / (1 + Slow)) * Weighted[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);

      // fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);
      // slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]);

      The last two lines are the original code from MACD indicator, but doesn't do the job....may be need more experienced programer in ninja script... HELP how can i weighted the fast and slowMA?
      Last edited by krasisoft; 07-24-2015, 12:45 PM.

      Comment


        #4
        Hello krasisoft,

        Thanks for your post.

        The lines you changed are the equation for the EMA itself so comment them out.

        Change this line: double macd = fastEma[0] - slowEma[0];

        To this: double macd = WMA(fast)[0] - WMA(slow)[0];

        Comment


          #5
          I think i did it!!!!!!! I made a mistake the EMA = Exponential moving avrg....and i stilll calculated the EMA on instead WMA but with this code below it did what i need (i think) i will test it later on.....

          this is the code:
          protected override void OnBarUpdate()
          {

          if (CurrentBar == 0)
          {
          fastEma.Set(Input[0]);
          slowEma.Set(Input[0]);
          Value.Set(0);
          Avg.Set(0);
          Diff.Set(0);
          }
          else
          {
          int back = Math.Min(fast - 1, CurrentBar);
          double val = 0;
          int weight = 0;
          for (int idx = back; idx >=0; idx--)
          {
          val += (idx + 1) * Input[back - idx];
          weight += (idx + 1);
          }
          fastEma.Set(val / weight);


          back = Math.Min(slow - 1, CurrentBar);
          val = 0;
          weight = 0;
          for (int idx = back; idx >=0; idx--)
          {
          val += (idx + 1) * Input[back - idx];
          weight += (idx + 1);
          }
          slowEma.Set(val / weight);

          double macd = (fastEma[0] - slowEma[0]);
          double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1];

          Value.Set(macd);
          Avg.Set(macdAvg);
          Diff.Set((macd - macdAvg));
          }
          }

          Comment


            #6
            DO YOU have this code for ninja 8? IT LOOKS GOOD

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            580 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            335 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            102 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X