Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Lookback period for evaluation

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

    Lookback period for evaluation

    Has anyone done a simple look back period to get some stats? For example, I want to compare some values from current bar to 10 bars ago, vs 10bars ago to 20 bars ago and print values like SMA, slope, etc..

    pseudocode:

    from (current bar to 10bars ago)
    print slope,
    print SMA value
    highest value
    lowest value

    from (10bars ago to 20bars ago)
    print slope,
    print SMA value
    highest value
    lowest value

    #2
    Hello Boonfly8,

    Thanks for your post.

    For each of the methods, you would need to specify the bars ago.

    For example, an SMA(30)[0] provides the 30 period average up to the current bar[0] where SMA(30)[10] would provide the 30 period average 10 bars ago (yes using 30 bars back from that 10 bars ago).

    In the case of Slope() you have to specify the begin barsago and end barsago, reference: https://ninjatrader.com/support/help...-us/?slope.htm

    Regarding the High/low values i am not sure if you mean price or of the SMA itself. I guess in either case you could use the MAX() and MIN() methods which are like the SMA in that you can specify the bars ago index and use the same period: https://ninjatrader.com/support/help...aximum_max.htm https://ninjatrader.com/support/help...inimum_min.htm

    You could use a counter to count every 10 bars and the print the values, something like:

    if (CurrentBar < 30) return; // wait until enough bars for SMA

    counter++; // increment counter

    if (counter == 10)
    {
    Print ("BarClose time: "+Time[0]+ " SMA30: "+SMA(30)[0].ToString())
    Print ("Slope: "+(Slope(SMA(30), 10, 0).ToString()); // 10 bar slope?
    Print ("Highest price: "+MAX(High, 10)[0].ToString())
    Print ("Lowest price: "+MIN(Low, 10)[0].ToString());
    counter = 0; // reset counter to 0
    }

    You would need to create the int variable counter and initialize it to 0.

    Please note the example code above has not been tested and may contain typos, use at your own risk. It is provided to give you a starting point to develop further for your needs.

    Comment


      #3
      WOW, thank you for the very detailed and complete notes Paul. I will definitely sit down with a cup of coffee and look into your suggestions one-by-one.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X