could I change it to use simple moving averages . tia
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!
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
NinjaTrader
SMA Macd ?
Collapse
X
-
Hello,
Thank you for your post.
You will want to go to Tools>Edit NinjaScript>Indicator>select MACD>OK.
When you see the code right click within the code>Save As...>name it something like MACDSMA (or whatever you want to call it).
Then the easiest way would be to change this code:
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]);
To this code:
fastEma.Set(SMA(Input, Fast)[0]);
slowEma.Set(SMA(Input, Slow)[0]);
Then right click>compile.
DenNinjaTrader Customer Service
-
also need sma for the avg
I also need to change the avg calculation to SMA. I guess the following line need to be replaced also with SMA syntax?
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] [SIZE=2][FONT=Courier New][COLOR=#0000ff]double[/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] macdAvg = ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2.0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] / ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + Smooth)) * macd + ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] - ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2.0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] / ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + Smooth))) * Avg[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT] [/SIZE][/FONT]
Originally posted by NinjaTrader_Ben View PostHello,
Thank you for your post.
You will want to go to Tools>Edit NinjaScript>Indicator>select MACD>OK.
When you see the code right click within the code>Save As...>name it something like MACDSMA (or whatever you want to call it).
Then the easiest way would be to change this code:
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]);
To this code:
fastEma.Set(SMA(Input, Fast)[0]);
slowEma.Set(SMA(Input, Slow)[0]);
Then right click>compile.
Comment
-
Hi cbratton, this would need custom coding - you can use something like this for a 10 bar SMA of the normal MACD histogram -
Code:[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2] macdHistoSMA = SMA(MACD([/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]12[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]26[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2], [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]9[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]).Diff, [/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2])[[/SIZE][/SIZE][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2]];[/SIZE] [/SIZE]
BertrandNinjaTrader Customer Service
Comment
-
Originally posted by ygold View PostI also need to change the avg calculation to SMA. I guess the following line need to be replaced also with SMA syntax?
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] [SIZE=2][FONT=Courier New][COLOR=#0000ff]double[/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] macdAvg = ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2.0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] / ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + Smooth)) * macd + ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] - ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2.0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] / ([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + Smooth))) * Avg[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]];[/SIZE][/FONT] [/SIZE][/FONT]
The code below is in place of the "else" code block. Notice I commented out the old method of calculating macdAvg and also moved Value.Set(macd); above the calculation.
Code:fastEma.Set(SMA(Close, Fast)[0]); slowEma.Set(SMA(Close, Slow)[0]); double macd = fastEma[0] - slowEma[0]; Value.Set(macd); //double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; double macdAvg = SMA(Value, Smooth)[0]; Avg.Set(macdAvg); Diff.Set(macd - macdAvg);
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Aviram Y, Today, 05:29 AM
|
0 responses
1 view
0 likes
|
Last Post
by Aviram Y
Today, 05:29 AM
|
||
Started by quantismo, 04-17-2024, 05:13 PM
|
3 responses
25 views
0 likes
|
Last Post Today, 05:23 AM | ||
Started by ScottWalsh, 04-16-2024, 04:29 PM
|
7 responses
34 views
0 likes
|
Last Post Today, 05:15 AM | ||
Started by cls71, Today, 04:45 AM
|
0 responses
6 views
0 likes
|
Last Post
by cls71
Today, 04:45 AM
|
||
Started by mjairg, 07-20-2023, 11:57 PM
|
3 responses
216 views
1 like
|
Last Post
by PaulMohn
Today, 04:22 AM
|
Comment