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

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

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

        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().
            BertrandNinjaTrader Customer Service

            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 kujista, Today, 06:23 AM
              4 responses
              14 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by traderqz, Yesterday, 09:06 AM
              2 responses
              16 views
              0 likes
              Last Post traderqz  
              Started by traderqz, Today, 12:06 AM
              3 responses
              6 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by RideMe, 04-07-2024, 04:54 PM
              5 responses
              28 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by f.saeidi, Today, 08:13 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X