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

MAX with lookback period

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

    MAX with lookback period

    Hello,
    I am going around in circles on a piece of coding that I think should be quite easy. I have a plot, and I want to look back 20 bars at the changes in value from bar 1 to bar 0 and if the current change is higher, take some action. I am not sure about the Input part of the MAX coding.
    Code:
    if (Values[1][0]-Values[1][1] > MAX(?, 20)[0])
    It needs to be > than Values[1][0]-Values[1][1] over the previous 20 bars, but the inputs part of the code where I have the ? will not accept that as an argument.

    Any help would be appreciated.

    Thanks!

    #2
    Originally posted by GeorgeW View Post
    Hello,
    I am going around in circles on a piece of coding that I think should be quite easy. I have a plot, and I want to look back 20 bars at the changes in value from bar 1 to bar 0 and if the current change is higher, take some action. I am not sure about the Input part of the MAX coding.
    Code:
    if (Values[1][0]-Values[1][1] > MAX(?, 20)[0])
    It needs to be > than Values[1][0]-Values[1][1] over the previous 20 bars, but the inputs part of the code where I have the ? will not accept that as an argument.

    Any help would be appreciated.

    Thanks!
    The "?" part of what you have written is to be a Series<T>, so create a Series<double> to hold the difference values, then feed that Series to the MAX() method.

    ref: http://ninjatrader.com/support/helpG...us/seriest.htm

    The last example on that page is a mirror of what you are seeking. You just need to look for a different difference from the one in the example.

    Comment


      #3
      Thanks Koganam,
      I went for a walk to clear my head and figured out I needed to use Series<T> 5 mins into my walk. I'll have to remember to do that more often when I'm stuck. I've done it and my calculations now work.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by tony_28217, Today, 07:04 PM
      0 responses
      3 views
      0 likes
      Last Post tony_28217  
      Started by flybuzz, Today, 10:33 AM
      1 response
      9 views
      0 likes
      Last Post flybuzz
      by flybuzz
       
      Started by spencerp92, 10-10-2023, 09:56 AM
      4 responses
      304 views
      0 likes
      Last Post flybuzz
      by flybuzz
       
      Started by samish18, Yesterday, 10:13 AM
      1 response
      25 views
      0 likes
      Last Post NinjaTrader_Eduardo  
      Started by Austiner87, Today, 05:02 PM
      0 responses
      7 views
      0 likes
      Last Post Austiner87  
      Working...
      X