Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with "Closes"

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

    Problem with "Closes"

    I'm getting an an OnBarUpdate() error - Index out of range (see attachment) when I use "Closes" to reference the close of a bar from BarsArray[1]. I'm using NT7 and the error only appears when attempting to trade live. There's no problem with the code when backtesting with StrategyAnalyzer.

    (Closes[0][0] >= Closes[1][0]) && (Closes[1][0] >= Closes[1][1])

    What can be done to fix this? I don't see any reason why this statement would work in StrategyAnalyzer but not in live trading.
    Attached Files

    #2
    bluelou, are you returning out of OnBarUpdate() if there aren't enough bars (if(CurrentBar < 2) return?

    There are actually a few different ways for that error message to be called, so that might not be it. Could you post the complete code you're using?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin,
      I'm not sure what you're asking me. What I can tell you is that my code runs live if I exclude the following statement:
      (Closes[0][0] >= Closes[1][0]) && (Closes[1][0] >= Closes[1][1])

      But, if I include the above statement then I get the OnBarUpdate error that I mentioned. Also, I don't get the error when backtesting. I only get it when trying to run the strategy live.

      I'm guessing what you mean is that since I'm referencing Closes[x][1], that is, 1 bar ago. Then for both BarsArray I should begin the statement with if(CurrentBar <2)... to accommodate cases where there are < 2 bars. Is that what you're saying?

      Comment


        #4
        bluelou, yes that is what I'm saying - sorry, I could've been more clear. Depending on the timeframe of the secondary bar series, you may need more than two bars, but if both series have the same timeframe, then you'll only have to check for two bars. The code for that is as follows:
        Code:
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 2)
                return;
            
            // rest of your strategy calculations here, including the BarsInProgress checks
        }
        AustinNinjaTrader Customer Service

        Comment


          #5
          Austin,
          What you're saying makes sense to me but I have one question: why did such a simple error make it past the compiler? I have this bug and probably 3 or 4 others that I haven't found yet that don't appear in a backtest using StrategyAnalyzer but do appear as soon as I try to run the strategy live.

          This rarely happened with NT6.5 but it seems to be a regular event with NT7. The fact that the code is compiling and running in StrategyAnalyzer but not running live is very frustrating. I've spent 2 days (and probably have 2-3 more days to go) using Visual Studio to debug NinjaScript because the Ninja compiler isn't doing its job.

          Comment


            #6
            bluelou, the strategy should run the same on backtesting and live testing. Would you mind sharing the code? I would like to test this out on my computer because the behavior you're reporting should not be happening as a strategy doesn't know whether it is being backtested or running live.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Austin,
              Give me a day or so since I'd need to write a version of the strategy w/o certain DLL references. Worth noting is that even when I've commented out the DLL calls the difference b/t the backtests and live errors has persisted.

              Comment


                #8
                Thank you, your time and assistance is very appreciated.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  Austin,
                  Is it possible for you to do some type of remote assistance where you log into my PC (I have LogMeIn)? That way I can show you the several instances where the compiler isn't catching errors w/o having to send you proprietary DLLs and other code. I'm having a few other problems with NT7 also, but the compiler problems are the most serious since I'm unable to trade live until I find a work-around to the compiler problems. Please send me a private message to discuss.

                  Thx,
                  Lou
                  Last edited by bluelou; 08-04-2010, 12:58 PM.

                  Comment


                    #10
                    Hi Lou, here are the links I was talking about:
                    Using OnOrderUpdate() and OnExecution() methods to submit protective orders
                    Using StreamWriter to write to a text file
                    Debugging your NinjaScript Code
                    TraceOrders
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Austin,
                      Thx for this. I'll check out these links.

                      -Lou

                      Comment


                        #12
                        Austin,
                        The changes that were made yesterday to correct the Closes[x][y] issue and other issues are no longer persisting in live trading. I'm back to where I started since the strategy won't run live and the live output window are both different from the StrategyAnalyzer output which runs properly. I've also sent you a p.m. I'm looking forward to your response.

                        Thx,
                        Lou

                        Comment


                          #13
                          Lou,

                          Austin will be in on Saturday. If you posted what you PMed Austin here directly we could see if we can help out till then. Thank you for your patience.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            I'm unable to trade a strategy live and the problem I'm having can only be tested while the FX markets are open. I'll send you a p.m. regarding the problem.

                            Comment


                              #15
                              Josh,
                              It appears that you have your p.m. shut off. Austin had first taken a look at this yesterday but we never really delved into it because I thought the problem had somehow fixed itself. That's not the case.

                              I've worked all day today trying to recreate the success of the one successful live test from yesterday before requesting remote assistance but I'm not making any progress. I would really appreciate you taking time to look at this issue on my PC.

                              As it stands, my strategy runs perfectly fine with StrategyAnalyzer but when attempting to trade live the indicator outputs = 0 in the Output Window. No errors are being thrown in the NT logger and I can't find anything wrong using the Visual Studio debugger. Without any known bugs to resolve I have no idea what the problem is.

                              Please let me know when you might be available.

                              -Lou
                              Last edited by bluelou; 08-05-2010, 03:40 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              630 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              566 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X