• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 bbdjad, Today, 04:36 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post bbdjad
                  by bbdjad
                   
                  Started by mittie3, Today, 03:33 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post mittie3
                  by mittie3
                   
                  Started by Againmain1, Today, 03:04 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post Againmain1  
                  Started by tonytimpa, Today, 01:33 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post tonytimpa  
                  Started by kiwidtrader, Yesterday, 11:49 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post kiwidtrader  
                  Working...
                  X