View Full Version : Slope()...
funk101
05-19-2007, 02:54 AM
Thanks for the Slope(). Please explain this. My 2 studies are clearly pointing up for currentbar and previous bar. However, as you can see, my readout is showing a negative number. Why? (see attached)
My code:
slowLine = Slope(CCI(14), 1, 0);
fastLine = Slope(CCI(6), 1, 0);
I tried Slope(CCI(14), CurrentBar-1, 0); But got some really funky output. A very large number. I just want the slope from previous bar to current bar.
BTW, what is your formula for the calc'ing of Slope();?
NinjaTrader_Ray
05-19-2007, 04:51 PM
Forumula was incorrect. Here is what I am changing it to for the next update. Thanks for pointing this out. I had endBar - startBar, which is correct if the parameters passed in were absolute bar numbers which they are not. They reference the number of bars ago.
return (series[endBar] - series[startBar]) / (startBar - endBar);
funk101
05-19-2007, 05:11 PM
Whew! I thought it was me. Glad I could be of service. :) Thanks, let me know when the update is available.
Any idea when we'll have the updated slope() method available? I'm unable to edit the indicator because I can't see it.
NinjaTrader_Ray
05-26-2007, 06:01 PM
Likely end of this coming week.
Bump any date on the update?
NinjaTrader_Ray
06-16-2007, 11:02 AM
I am hoping early this coming week. Just doing some final testing.
pdawg
06-20-2007, 01:47 PM
Ray,
Is this slope() function using math.atan to calculate slope?
NinjaTrader_Ray
06-20-2007, 02:35 PM
No it is not.
edgeliner
12-04-2007, 07:41 PM
If I just want to buy when the 50 EMA slope was greater than 20 degrees, could I use the Slope() to do that? If so, how?
NinjaTrader_Josh
12-04-2007, 07:45 PM
Yes. Just place the slope function inside an if statement.
http://www.ninjatrader-support.com/HelpGuideV6/Slope.html
edgeliner
12-04-2007, 08:08 PM
Can you give me an example?
NinjaTrader_Josh
12-04-2007, 08:17 PM
if ((System.Math.Atan(Slope(EMA(50),CurrentBar-1,CurrentBar))*180/Math.PI) > 20)
// Do somethingReview the discussion here about slope. http://www.ninjatrader-support.com/vb/showthread.php?t=2660&highlight=slope
It has many examples and many different implementation variants that people like to use.
Note: A condition of 20 degrees in slope is pretty rare. You usually don't even see 10 degrees of slope.
edgeliner
12-04-2007, 08:25 PM
You are the best Josh!
edgeliner
12-04-2007, 08:32 PM
This is good stuff.....weeds out the flat times!
How would......
if ((System.Math.Atan(Slope(EMA(50),CurrentBar-1,CurrentBar))*180/Math.PI) > 20)
// Do something
look on a 5 minute chart?
NinjaTrader_Josh
12-04-2007, 08:48 PM
I'm not sure what it will look like. You'll have to take it from here and play with it yourself.
Elliott Wave
04-13-2008, 12:18 AM
Is this code still correct? I've been 'playing' with it and its not very fun... ;)
Searching in the forums for help, it appears the syntax has changed numerous times which makes it even more confusing.
If you have time, it might be helpful to make a sample ninjascript that shows how both kinds of slope work in the context of both long and short positions.
Slope seems like it would be perfect to help avoid rapid whipsaw trades in a sideways markets, but for some reason, what is so obvious visually is so hard to code.
http://shup.com/Shup/35915/slope.jpg
-EDIT-
The MASlopeBox indicator has been updated, which is very helpful.
http://www.ninjatrader-support.com/vb/showthread.php?t=2660
NinjaTrader_Ray
04-13-2008, 08:13 AM
The current DOC accurately demonstrates that proper syntax for the Slope() method.
Elliott Wave
04-13-2008, 01:02 PM
Thanks, for the clarification. :)
I couldn't find much in the manual on "system.math.atan" type slopes and how they differ, whether or not the value is in degrees, between 1, -1, etc and with the syntax change, looking for answers in the forum raised as many questions as it answered.
Now that the MASlopeBox works, I'm using that for sample code and by including it in a wizard generated strategy I can see the code in a more usable context, which 'Print(Slope(SMA(20), 10, 0)); ' didn't quite provide.
NinjaTrader_Josh
04-13-2008, 01:39 PM
If I remember correct the System.Math.Atan provides the answer in radians. You can check the MSDN documents to confirm.
Elliott Wave
04-13-2008, 05:51 PM
I'm pretty sure thats right, from looking at the MASlopeBox code.
To see if I get this straight:
((180/Math.PI) *(Math.Atan(Slope(EMA(Period),1,0)))
returns a slope value in degrees whereas the NT Slope function returns a value between -1 and 1.
i.e if the first example returns a 10 degree slope, the NT slope function would return 0.1...