Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help Changing MACD from Ema to Sma

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

    Help Changing MACD from Ema to Sma

    Hi All,

    I posted this awhile back and thought to try again. I'm reaching out to see if anyone has modified a MACD from Exponential to Simple? I would like to be able to switch the Fast, Slow, and Smooth to either Ema or Sma. I tried tweaking the MACD that comes with NT8, but not sure I did anything.

    I turned the slowEma to slowSma, but again not sure that worked correctly. Also, I have no idea where to even start with the Smooth making it either Ema or Sma.

    Thanks in advance.
    -Shaun

    #2
    Hello schaun_oh, and thank you for your question. I am leaving this question on the forums in case a member of the community would like to create this indicator. This said, if you would like to try your hand at creating this indicator yourself, we can compare the EMA's source to the MACD's source. When we do so we see that both contain lines of code like the following :

    Code:
    [FONT=Courier New]// @EMS.cs
    constant1 = 2.0 / (1 + Period);
    constant2 = 1 - (2.0 / (1 + Period));
    // ...
    Value[0] = (CurrentBar == 0 ? Input[0] : Input[0] * constant1 + constant2 * Value[1]);[/FONT]
    Code:
    [FONT=Courier New]// @MACD.cs
    constant1    = 2.0 / (1 + Fast);
    constant2    = (1 - (2.0 / (1 + Fast)));
    // ...
    if (CurrentBar == 0)
    {    
        fastEma[0]        = input0;
    // ...
    }
    else
    {
        double fastEma0    = constant1 * input0 + constant2 * fastEma[1];
    // ...
        fastEma[0]        = fastEma0;
    }[/FONT]
    We can also see that the SMA indicator has this code :

    Code:
    [FONT=Courier New]
                    if (CurrentBar == 0)
                        Value[0] = Input[0];
                    else
                    {
                        double last = Value[1] * Math.Min(CurrentBar, Period);
    
                        if (CurrentBar >= Period)
                            Value[0] = (last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period);
                        else
                            Value[0] = ((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
                    }[/FONT]
    Therefore, you can probably convert this indicator by

    • open the MACD indicator and SMA indicator in the NS editor
    • in the MACD window, right click, "Save As", and give this a new name
    • in the MACD copy, removing the constants section
    • keep the if (CurrentBar == 0) section as is
    • in the SMA window (changes here will not be saved), add curly braces to the SMA's if (CurrentBar >= Period) / else closes, e.g.

    Code:
    [FONT=Courier New]                    if (CurrentBar >= Period)[/FONT]
    [FONT=Courier New]                    {[/FONT]
    [FONT=Courier New]                        Value[0] = (last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period);[/FONT]
    [FONT=Courier New]                    }[/FONT]
    [FONT=Courier New]                    else[/FONT]
    [FONT=Courier New]                    {[/FONT]
    [FONT=Courier New]                        Value[0] = ((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));[/FONT]
    [FONT=Courier New]                    }[/FONT]

    • replace Value[0] with fastEma[0] and Period with Fast in the same code
    • repeat the sections this leaves you with for slow, value, and avg
    • (optional) rename Ema -> Sma
    • copy your modified code into your new MACD indicator
    • undo your changes to the SMA indicator and close this window
    • test your new MACD indicator
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica P,

      Thanks for taking the time out to write up this response. It may be above my pay scale, however I will at least give it a try. I'll let you know if I crash and burn.

      Stay tuned

      Best,
      -Shaun

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      636 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      568 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      571 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X