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 NullPointStrategies, Today, 05:17 AM
      0 responses
      43 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      124 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      65 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X