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

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.
    Paul H.NinjaTrader Customer Service

    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 algospoke, Yesterday, 06:40 PM
      2 responses
      19 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      21 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X