NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-12-2007, 04:23 PM   #1
funk101
Senior Member
 
Join Date: Jan 2006
Location: Margate, Florida, USA
Posts: 426
Thanks: 0
Thanked 2 times in 2 posts
Send a message via AIM to funk101
Post imported post

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?
funk101 is offline  
Reply With Quote
Old 04-12-2007, 08:02 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

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];
which will calculate how may percent the Macd is above or below the Avg.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-13-2007, 03:01 AM   #3
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

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];
NinjaTrader_Dierk is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:47 PM.