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
Slope() value
Collapse
X
-
Slope() value
I am using the function LinRegSlope() or similarly Slope(LinReg()). When I output the the values they are typically around -.05 to .05. I'm wondering what the highest and lowest these values could go. I'm also trying to relate these values to what I know as the slope of a line in geometry (typically 45 degree, 90 degree [straight up] etc.). I was thinking .45 would correspond to 45 degree line (slope) but that doesn't seem to be the case. Can somebody help me make sense of the values that Slope() outputs as they relate to high, low and the angle of a line. Much thanks.Tags: None
-
Ethan,
Slope just outputs the value in units price per bar so to speak. It's simply something like :
(Price[index2] - Price[index1] )/ (index2-index1)
As such the bounds on what it can output is highly dependent on the underlying series that its being calculated for. If you convert this to degrees or radians you could theoretically get between -90 and 90 degrees (but not including -90 or 90).
Slope actually can have some scaling issues if you don't normalize for volatility or something similar like ATR. Also the slope isn't based on the angles you see on your chart, i.e. if you rescale the chart by dragging the axes the slope doesn't change.
You may want to consider doing something like :
Arctan( (Price[0] - Price[1] ) / Timeframe )
This would return the value in radians, then you can simply convert to degrees. It also takes into account the time between one bar and the next.
I believe this would be similar :
Arctan ( Slope(Close,index1,index2) / timeframe )
Using some trigonometry :
Tangent ( angle ) = (Price[index2] - Price[index1] ) / (index2 - index1)
So taking the inverse function :
angle = Arctangent ( (Price[index2] - Price[index1] ) / (index2 - index1) )
Please note this is all pseudo-code / formulas. Math.ATan() is the method you can use for arctangent (inverse function for tangent) in C#.Last edited by NinjaTrader_AdamP; 11-07-2012, 02:26 PM.Adam P.NinjaTrader Customer Service
-
Thanks for your responses Adam. I am not a Trig expert (took it in High School a long time ago). I like your chart and I see your formula. I like the circle with the degrees/angle line--THAT IS WHAT I'M TRYING TO CALCULATE. Are you saying take P2-P1/T2-T1 and normalize that somehow. I agree with the basic formula but don't see how to normalize it. Can you provide the actual code that would normalize. You say all pseudo-code / formulas but Math.ATan() is what I would use. What is the actual code to accomplish this? Thanks.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by DayTradingDEMON, Today, 09:28 AM
|
1 response
10 views
0 likes
|
Last Post Today, 09:40 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
8 responses
31 views
0 likes
|
Last Post Today, 09:34 AM | ||
Started by helpwanted, Today, 03:06 AM
|
2 responses
21 views
0 likes
|
Last Post Today, 09:30 AM | ||
Started by navyguy06, Today, 09:28 AM
|
0 responses
4 views
0 likes
|
Last Post
by navyguy06
Today, 09:28 AM
|
||
Started by rjbtrade1, 11-30-2023, 04:38 PM
|
2 responses
77 views
0 likes
|
Last Post
by DavidHP
Today, 08:12 AM
|
Comment