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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      49 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      69 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      36 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      96 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      59 views
      0 likes
      Last Post PaulMohn  
      Working...
      X