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 Brevo, Today, 01:45 AM
              0 responses
              6 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by aussugardefender, Today, 01:07 AM
              0 responses
              3 views
              0 likes
              Last Post aussugardefender  
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              242 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              384 views
              1 like
              Last Post Gavini
              by Gavini
               
              Started by oviejo, Today, 12:28 AM
              0 responses
              6 views
              0 likes
              Last Post oviejo
              by oviejo
               
              Working...
              X