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

Rate of Change

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

    Rate of Change

    Hi, I've written script to calculate the SMA and plot it. I would now like to compare the rate of change of those SMA points such as the most recent SMA point , SMA[0] vs the SMA of 5 bars ago, SMA[5]. I would also, if possible, like to change the color of the plotted line to reflect positives and negatives rate of change. Could you please provide some guidance? Script is enclosed.
    Attached Files

    #2
    Kay, you can check into this reference sample for how to achieve plot color changes - http://www.ninjatrader-support2.com/...ead.php?t=3227

    The condition in the sample is just a Rising, Falling one, you could replace this then with your custom needed one (i.e. if (SMA[0] > SMA[5]....)
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      I followed most of the code but couldn't get a plot. I suspect it's the SMA(fastperiod)[0] >SMA(fastperiod)[5] portion that I've gotten wrong. Would you mind taking a look? It's to compare whether the current SMA(fastperiod) is greater than SMA(fastperiod) of 5 bars ago. Code is attached.

      Thanks.
      Kay Wai
      Attached Files

      Comment


        #4
        Kay, you need a higher current bar check then if you reference back further like the 5 bars you do in this script.

        Code:
        [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
        protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()
        {
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (CurrentBar<[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]) [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT][/SIZE][/FONT]
        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]....[/SIZE][/FONT][/SIZE][/FONT]
        [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}
        [/SIZE][/FONT][/SIZE][/FONT]
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thanks Bertrand!
          Just one observation. When I add a separate "slower" SMA Line, i.e having 2 SMA lines running from the same script, some points don't even appear on the chart. So I separated the SMA lines into 2 different files. Looks just the way I wanted it!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by hurleydood, 09-12-2019, 10:45 AM
          14 responses
          1,092 views
          0 likes
          Last Post Board game geek  
          Started by cre8able, Yesterday, 04:16 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cre8able, Yesterday, 04:22 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by stafe, 04-15-2024, 08:34 PM
          5 responses
          28 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by StrongLikeBull, Yesterday, 04:05 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X