![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Aug 2008
Posts: 62
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I found the following formula to calculate the slope of a line: public int CalcSlope(IDataSeries line) { double radToDegrees = 180/Math.PI; return (int)(radToDegrees*(Math.Atan((line[0]-(line[1]+line[2])/2) /1.5/TickSize))) ; } I want to enable the calculation of the slope in degrees given any number of bars, from 1 to n. I don't understand why the line is divided by 1.5. Would the following formula be valid? Say I want to calculate the slope for the last 3 bars: return (int)(radToDegrees*(Math.Atan((line[0]-(line[1]+line[2]+line[3])/3) /1.5/TickSize))) If not, what is the formula? Thanks. rpq |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
rpg, you could also check into our Slope() method - http://www.ninjatrader-support.com/H...eV6/Slope.html
This will give you a rise over run calculation between two points, you would then need to add logic for converting to degrees... The cited logic for converting to degress is valid, not sure why the 1.5 divisor is needed - best is to print / plot the result and then verify by hand / visuals.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2006
Posts: 111
Thanks: 0
Thanked 1 time in 1 post
|
It looks as if (line[1]+line[2])/2) is calculating the value of 'line' at a point 1/2 way between 2bars ago and 1bar ago ~ that is 1 1/2 bars ago from line[0]. Hence the use of 1.5 which is normalizing the slope to give a rise value for one bar.
To get the angle in degrees for 3 bars, I think this will work, but not tested:- return (int)(radToDegrees*(Math.Atan((line[0]-line[3])/3/TickSize))); |
|
|
|
|
|
#4 |
|
Member
Join Date: Aug 2008
Posts: 62
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks MJT..... I'll try it out to see if it works. I tried with the Slope() function, but it doesn't seem to give correct results.
Regards, RPQ |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calculating fair value? | Bogan7 | NinjaScript File Sharing Discussion | 4 | 04-30-2012 01:46 PM |
| Calculating P&L by day? | leonchan1204 | Strategy Development | 1 | 06-08-2009 06:14 AM |
| Calculating a limit entry | kevinh786 | Strategy Development | 5 | 12-08-2008 05:35 AM |
| Calculating on Bar Close... | kjkraus | Strategy Analyzer | 1 | 09-07-2007 07:28 PM |
| Calculating slope & percentage... | funk101 | General Programming | 2 | 04-13-2007 03:01 AM |