Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

for loop in OBU

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

    for loop in OBU

    Hello,

    I try to for loop in OBU from my variable Index to the beginning of the chart. Index is the lowest value in the chart.

    Code:
    for(int barIndex = index; barIndex <= 0; barIndex--)
            {
          sumOfVolumes4 += Bars.GetVolume(barIndex);
                if (sumOfVolumes4 >= sumvolfibo)
                {
                    foundIndex = barIndex;
    
          }
    
         }
    Why using 0 wont work? I cant use chartfromIndex because it will return the visible bars in the chart. I did use 0 to find the lowest low and it work but not on the opposite side. What can i use?

    thank you

    #2
    Hello frankduc,

    I would suggest using a Print here to better understand what values you are using in the loop.

    Is barIndex less than or equal to 0?

    If bar index is greater than 0 your loop won't do anything.



    Please let me know if I may be of further assistance.

    Comment


      #3
      Jesse,

      barIndex = 588

      So if
      Code:
        for(int barIndex = index; barIndex >= 0; barIndex--)
      it should count 588, 587, 586 till 0?

      Is there a method in OnBarUpdate to replace charttoindex and chartfromindex to loop outside of the visible scope of the chart?

      Ty

      Comment


        #4
        Hello frankduc,

        Based on the previous sample 588 is greater than 0 so that is why that loop did not work.

        it should count 588, 587, 586 till 0?
        This is something you should test by using a Print to observe the result. That can help with learning how to use loops. Loops are not a NinjaScript concept so this is something we always suggest to just test if you are not clear on what would happen if loop does X.


        Is there a method in OnBarUpdate to replace charttoindex and chartfromindex to loop outside of the visible scope of the chart?
        Using the visible bars from OnBarUpdate is not something which would normally be used. Normally from OnBarUpdate you just use the CurrentBar to know what bar you are in processing. If you wanted to loop the bars of the chart you could just use CurrentBar to go from Now in processing to 0. You can also use the Count property to get the count of bars on the chart however that only works if TickReplay is off. Using the current bar would be reverse of the index of your loop, you would use a BarsAgo so your loop could start a 0 and work its way back to CurrentBar barsAgo.


        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        639 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        569 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        572 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X