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 hazylizard, Today, 08:38 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by geddyisodin, Today, 05:20 AM
        2 responses
        17 views
        0 likes
        Last Post geddyisodin  
        Started by Max238, Today, 01:28 AM
        5 responses
        45 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Working...
        X