Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy to indicator runtime issue

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

    strategy to indicator runtime issue

    I am trying to convert an existing strategy I have to an indicator so I can use chart trader. It runs fine as a strategy no issues. I converted it by hand to an indicator, it compiles successfully. It uses a secondary added time frame.

    When I add the indicator to the chart I get a run time error. This is the line of code I get the error on.
    DrawRectangle("Rectangle_up_"+ '_' + CurrentBars[BarsInProgress], false, 0, BarLow, lineLength, BarHigh, Color.Green, Color.PaleGreen, opacity);

    this is the error I get from the log:
    Error on calling 'OnBarUpdate' method for indicator 'zones_9_ms_ind_ind' on bar 20702: zones_9_ms_ind_ind.DrawRectangle: startBarsAgo out of valid range 0 through -1, was 0.

    The drawrectagle is hard coded for startBarsAgo = 0, I tried -1. same error.

    The message says startBarsAgo range must be 0 to -1, and it is 0.

    Last time i checked 0 is in the range of 0 to -1. Not sure how to fix this one.

    #2
    ct, so basically the same code worked normally for you in the strategy but not after conversion to an indicator?

    What checks for enough bars (CurrentBars[x]) are you running for all involved series in the indicator?
    Last edited by NinjaTrader_Bertrand; 10-06-2011, 08:35 AM.

    Comment


      #3
      Bertrand

      I did have to add some logic for this. It was interesting I got dates farther back that the base chart time frame. This did not happen in the strategy. It would appear an added time frame date/time range is different in a strategy from an indicator.

      Here is a code snippet. Do I need to check if the added time frame is referencing a time farther back than the lowest base chart date/time?

      if (BarsInProgress < 1)
      {
      return;
      }
      if (BarsInProgress > 1

      if (CurrentBar < MinBars)
      {
      return;
      }

      Yes if I put in high enough MinBars value the indicator works.

      Comment


        #4
        Yes ct, that could be the case - since you return out of any call to BIP 0 you should not need a dedicated check for this series.

        Comment


          #5
          Bertrand

          Got it. I will put in a check to not use ay times lower the base time frame. That seems to fix it. What is "BIP"?

          Comment


            #6
            That's just short for BarsInProgress - the bars series calling the OnBarUpdate().

            Comment


              #7
              Got it. Not used to the acronym but know what is stands for well.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              576 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X