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

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.

    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, 02-11-2023, 05:43 PM
        3 responses
        236 views
        0 likes
        Last Post rhubear
        by rhubear
         
        Started by frslvr, 04-11-2024, 07:26 AM
        8 responses
        113 views
        1 like
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        10 responses
        46 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by rocketman7, Today, 09:41 AM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by traderqz, Today, 09:44 AM
        2 responses
        10 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X