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 not working

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

    For loop not working

    Hi Guys,

    I wrote the following "for" loop in an indicator and if I set the loop limit to 5, the indicator will not output anything. If I set the loop limit to 4 then it will work.

    limit = 5;
    dHigh = High[0];

    for (int i = 1; i<limit; i++)
    {
    if (High[i] > dHigh)
    dHigh = High[i];
    }

    Why won't this loop work? I can't see any reason why this won't work.

    Please advise....

    #2
    It's possible that you don't have enough bars loaded to access High[4], but what is the error you're getting?

    Comment


      #3
      Thanks for your reply.

      I checked with this code....

      If (CurrentBar < 10)
      return;


      This is why I am so confused, especially since I put in this code.

      Comment


        #4
        Originally posted by bradleg View Post
        Thanks for your reply.

        I checked with this code....

        If (CurrentBar < 10)
        return;


        This is why I am so confused, especially since I put in this code.
        Does a higher # work?

        What time frames are you working in? (primary and secondary).

        Have you restarted NT?

        Comment


          #5
          Higher numbers don't wok.

          Time frame is 360 minute. There is no secondary timeframe.


          I have restarted NT twice over two days.


          Again thanks or he reply, I don't understand it...

          Comment


            #6
            Originally posted by bradleg View Post
            Higher numbers don't wok.

            Time frame is 360 minute. There is no secondary timeframe.


            I have restarted NT twice over two days.


            Again thanks or he reply, I don't understand it...
            360 minute bars are 360/60=5.83333 hours per bar.

            What is your session template? Is this a stock or future?

            Whats are your days loaded set to for the chart? if it is 1 or 2 you would have troubles..., even with currentbar check, you might start working on day 3...


            Are there errors in the output window?

            Ill try this in the morning...

            Comment


              #7
              Originally posted by sledge View Post
              Are there errors in the output window?.
              Like sledge said, this would be helpful to know.

              Comment


                #8
                Originally posted by bradleg View Post
                Higher numbers don't wok.

                Time frame is 360 minute. There is no secondary timeframe.


                I have restarted NT twice over two days.


                Again thanks or he reply, I don't understand it...
                I had to load up 50 days of data in my data series to get your for loop to work on 360 minute time frame.

                If I did not, I would get this error in the output window:

                Error on calling 'OnBarUpdate' method for indicator 'HighTest' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                To bring up the output window, in Control Center, Tools->Output Window.

                Comment


                  #9
                  Good Morning, Good Traders!!!

                  Thanks for the testing. I will look to replicate this later today.

                  Background:
                  I have loaded 800 days of data, and I have created 360 minute bars with that data.

                  I have calculate on close set to True.

                  I am not getting an explicit error, so I may have to check the output window for that -- thanks for the suggestion.

                  I am getting NO output on the chart. If I change the length to 4, then I get output to the screen, but 5 or higher -- NO output.

                  Thanks for all of your assistance.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by gentlebenthebear, Today, 01:30 AM
                  2 responses
                  13 views
                  0 likes
                  Last Post gentlebenthebear  
                  Started by Kaledus, Today, 01:29 PM
                  2 responses
                  8 views
                  0 likes
                  Last Post Kaledus
                  by Kaledus
                   
                  Started by frankthearm, Yesterday, 09:08 AM
                  13 responses
                  45 views
                  0 likes
                  Last Post frankthearm  
                  Started by PaulMohn, Today, 12:36 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post PaulMohn  
                  Started by Conceptzx, 10-11-2022, 06:38 AM
                  2 responses
                  56 views
                  0 likes
                  Last Post PhillT
                  by PhillT
                   
                  Working...
                  X