NexusFi: Find Your Edge


Home Menu

 





Code snippet for calculating slope


Discussion in NinjaTrader

Updated
    1. trending_up 7,000 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Code snippet for calculating slope

  #1 (permalink)
 
Saroj's Avatar
 Saroj 
Arcata, CA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: index futures, oil
Posts: 485 since Jun 2009
Thanks Given: 232
Thanks Received: 415

This is an example of one form that I picked up from a strategy posted by wh. This example is for the 20 simple moving average. You can substitute any series based value for SMA(20) whether it be a standard NT indicator or a custom indicator. The TickSize will modify the scale for the instrument of the chart.


sma20slope = (int)(radToDegrees*(Math.Atan((SMA(20)[0]-(SMA(20)[1]+SMA(20)[2])/2)/1.5/TickSize)));

include the following in the variables section:
privatedouble radToDegrees = 180/Math.PI;
privateint sma20slope = 0;

I have just started using it so I can't comment on how well it works, but you could use a series for the slope result instead of an integer and plot it in a panel for testing. Please report back on your findings.

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #2 (permalink)
 Trendseek 
Leipzig / Germany
 
Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker: Interactive Broker
Trading: Futures, Forex
Posts: 28 since Aug 2009
Thanks Given: 46
Thanks Received: 36

at first - thanks for the snippet

this is the common formula with two enhancements.
- the usage of two older Values (like a "mini" Moving Average) results in a more stable Slope-Calculation
- consider the Ticksize try to standardize price-skales with different amount.

The Snippet DID NOT WORK on Indikators, which oszillate between positiv and negativ Values.

--> you can use the common Slope() Command.

Degree = Slope(SMA(14), 1, 0) / Ticksize;

The Ticksize Standardization is imprecise, because it gives us no adjustment if you switch between a 1Minute and 10 Minute Timeframe, and it also did not differenciate between price-data and indicator-data (i.e. from -1 to +1).

best
Trendseek

Reply With Quote
  #3 (permalink)
 
ThatManFromTexas's Avatar
 ThatManFromTexas 
Houston,Tx
 
Experience: Advanced
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: TF
Posts: 2,265 since Feb 2010
Thanks Given: 1,206
Thanks Received: 4,353



Saroj View Post
This is an example of one form that I picked up from a strategy posted by wh. This example is for the 20 simple moving average. You can substitute any series based value for SMA(20) whether it be a standard NT indicator or a custom indicator. The TickSize will modify the scale for the instrument of the chart.


sma20slope = (int)(radToDegrees*(Math.Atan((SMA(20)[0]-(SMA(20)[1]+SMA(20)[2])/2)/1.5/TickSize)));

include the following in the variables section:
privatedouble radToDegrees = 180/Math.PI;
privateint sma20slope = 0;

I have just started using it so I can't comment on how well it works, but you could use a series for the slope result instead of an integer and plot it in a panel for testing. Please report back on your findings.

This formula is from Woodies CCIClub. Ken Wood (Woodie) uses a calculation of 1.5 bars back . Hence the
 
Code
(SMA(20)[1]+SMA(20)[2])/2)/1.5


Slope is calculated on Rise/Run (From where we are how many bars back).

You can add a variable for Barsback.

emaslope = (int)(radToDegrees*(Math.Atan((EMA(Period)[0]-EMA(Period)[BarsBack])/BarsBack/TickSize)));

I'm just a simple man trading a simple plan.

My daddy always said, "Every day above ground is a good day!"
Reply With Quote




Last Updated on April 6, 2011


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts