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!
See more
See less

Partner 728x90

Collapse

Need help understanding Slope() in Ninjascript 8

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

    Need help understanding Slope() in Ninjascript 8

    I am currently learning C# so I can write my own indicators. I am understanding things that I see in Ninjascript and am making some trial attempts at indicator development. However, I am having trouble with Slope(). The description in the help guide isn't very good for beginner people like myself. There aren't enough examples of what they are talking about. I ultimately want to write a 3 colored MA with a built in slope parameter that I can adjust based on my parameter settings. I don't want someone to write it for me. However, I do want someone to explain with plenty of examples of what I would need to know so I can write the indicator myself.

    #2
    Hello jamestrader21x,

    Thanks for your post.

    The help guide lays out the syntax of the method which is Slope(ISeries<double> series, int startBarsAgo, int endBarsAgo) I have shown the required input parameters as bold
    The parameters table specifies:
    series : Any Series<double> type object such as an indicator, Close, High, Low, etc...
    startBarsAgo: The starting point of a series to be evaluated.
    endBarsAgo: The ending point of a series to be evaluated.
    Reference: https://ninjatrader.com/support/help...-us/?slope.htm

    The series, in your case, would be the moving average to evaluate.
    The start bars ago would be when you want the analysis to begin relative to the end bars ago. Bars ago is relative to the current bar being processed.

    In the help guide, it shows this example: Print(Slope(SMA(20), 10, 0)); which will print to the Ninja script output window the 10 bar slope starting 10 bars ago to the current bar, of a 20 period Simple Moving average.

    The slope is determined by (series[endBarsAgo] - series[startBarsAgo]) / (startBarsAgo - endBarsAgo), using the above example this would take the SMA value 10 bars ago minus the SMA value of the current bar, the difference is then divided by 10 minus 0 (or just 10 in that example). You might try testing the example using different lengths of look back, for example, a 3 bars ago start would be more reactive than 10 bars ago and 10 would react quicker than 20 bars ago, etc.

    Perhaps what may be confusing is understanding that the moving averages are a data series and that the data series at an index point (IE: on any historical bar) will have a value based on its input period. (20 in the example).

    This example: Print(Slope(SMA(20), 10, 0)); when placed in the OnbarUpdate() method would provide a slope value based on the latest 10 bars every time OnBarUpdate() is called. OnBarUpdate() is called based on the Calculate setting (OnBarClose, OnEachTick, or OnPriceChange).

    If you would like further information on slope I recommend doing an internet search on the subject.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      It looks like you recited what the help guide says. I don't understand it. I need to see examples of how to write the code. I'm not trying to code strings on a chart. Like my post said, I'm ultimately want to write an MA indicator with 3 colors. If the MA reaches a certain slope it change to the up color until the conditions are no longer met. the same for the down color. if the slope parameter isn't met, then the ma stays the neutral range color. I wanted help examples of how to go about write the actual code...I know it has something to do with math.atan. However, like I said, I'm new to C# and still learning this stuff. I want to understand why I'm writing the code.

      Comment


        #4
        Hello jamestrader21x,

        Thanks for your reply.

        Please see the help guide on PlotBrushes for an example of how to color the plot based on conditions: https://ninjatrader.com/support/help...lotbrushes.htm

        Here is an example of checking for a slope condition and plotbrushes for your convenience.

        If (Slope(SMA(20), 10, 0) > 0)
        {
        PlotBrushes[0][0] = Brushes.Green;
        }
        else if (Slope(SMA(20), 10, 0) < 0)
        {
        PlotBrushes[0][0] = Brushes.Red;
        }
        else
        {
        PlotBrushes[0][0] = Brushes.Yellow;
        }

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        29 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        28 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        21 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        6 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X