Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X