Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Successive bars lookback

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

    Successive bars lookback

    Hi,

    I'm trying to code an indicator which checks all 11 previous bars for every new bar printed to see whether the condition is true. Unfortunately, I'm not getting the desired result. My code is as follows:-

    Code:
    if(CurrentBar < 13) return;
    
    if(Close[1] < Close[5])
    {
    for( int x = 1; x <= 11; x++)
    {
    if( Close[0] > High[x])
    {
    Draw.TriangleUp(this,"lvup"+CurrentBar, true, 0, (Low[0]-SMA(Range(),9)[0]*0.15), Brushes.Green);
    }
    }
    }
    What am I missing? This is the result I'm getting (^SP500 (Daily) 2021_11_12 (11_39_13 AM).png) when I'm looking to get this (Screenshot 2022-04-25 114426.png). The rectangles are the reference area.

    Could you please point me in the right direction?

    Regards
    Kay Wai

    Attached Files

    #2
    Hello kaywai,

    I'm not clear on the rule you are wanting. The condition is checking the close of the current bar is greater than the high of a previous bar, x bars ago?
    What is the check of the Close of 1 bar ago being less than the Close of 5 bars ago doing?
    Is this meant to draw on each bar or just the current bar?

    Possibly:

    for (int index = 1; index < 12; index++)
    {
    if (Close[0] > High[index])
    Draw.TriangleUp(this,"lvup"+(CurrentBar-index).ToString(), true, index, (Low[index]-SMA(Range(),9)[index]*0.15), Brushes.Green);
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Sorry for the trouble Chelsea. It was the first criteria that was causing the problem.

      Regards

      Kay Wai
      ​​​​​​​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      630 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      566 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X