Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Slope() question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Slope() question

    Hello,

    I'm learning (attempting ) more about C# and Ninja library, and am trying to figure out the Slope() function. I made a strategy that will enter when the SMA reaches a certain slope, and exit when it reaches another. Here is the code:

    Code:
                if (Slope(IDataSeries (SMA(N)), int 1, int 0)[0] >= S1)
    			{
                    EnterLong(DefaultQuantity, "");
                }
    
                // Condition set 2
                if (Slope(IDataSeries (SMA(N)), int 1, int 0)[0] <= S2)
                {
                    ExitLong("", "");
                }
    I followed the Slope() instructions in the help menu, but it still looks like I'm doing something wrong. Any thoughts?

    #2
    crimsonite,

    The slope function should be calculating something like ( x2 - x1 ) / (t2 - t1).

    The pairs (t1 , x1 ) and (t2, x2 ) are based on the startBarsAgo and endBarsAgo in Slope(IDataSeries series, int startBarsAgo, int endBarsAgo). I also noticed the "int 0" thing, if you are trying to type-cast you should use (int) 1.

    Notice that this value may be quite small because of the price difference, i.e. if we have 1.3001 and 1.3000 the top will be 0.0001, then the (t1 - t2) may be some integer leaving us with a pretty small number.

    You could try to standardize the calculation by dividing by the ticksize or something, then its like the line was calculated based on a grid rather than the tick value. There are also ways to factor in more values using quadrature rules but it would require a custom slope calculation.

    Please let me know if I may assist further.
    Last edited by NinjaTrader_AdamP; 02-14-2012, 09:25 AM.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your insight, I got it to work! Important things to remember about slopes...

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X