![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
|
1. Can anyone help with the formula for calculating the slope of a line? ie: EMA?
2. Also, the formula for calculating the percentage of one line from the next ie: MACD, how far is the fast line away from the slower line, percentage wise? |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
on 2) MACD knows these lines/data series: Macd, Diff, Avg. If you want to find out the difference between e.g. Macd and Avg in percent you could something like:
Code:
100 * (Macd[0] - Avg[0]) / Macd[0];
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
I should have added that Macd[0] could be zero. You then will get a zero divide exception. So you need to add some handling for that case like:
Code:
double val = 0; if (Macd[0] != 0) val = 100 * (Macd[0] - Avg[0]) / Macd[0];
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|