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

Impossibility to perform backtest and optimization strategy made ninjascript editor

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

    Impossibility to perform backtest and optimization strategy made ninjascript editor

    Hi,

    I adapted a strategy in Ninjascript Editor recently, and now I can't backtest or optimize it through Strategy Analyzer.

    I've debugged the entire code and I didn't find the error.

    I need your help to find the problem, please.
    Attached Files

    #2
    Hi EvergreenGain,
    You don't seem to use an "OutputWindow" while running the strategy. New -> NinjaSript Output.
    Otherwise, you would have immediately spotted an error message.

    "Strategy 'GoldPot': Error on calling 'OnBarUpdate' method on bar 3: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    And here is where this comes from. You check, if CurrentBars[0] < 2, if not, you return.

    HOWEVER, in your conditions, you check (amongst other things) if Close[3] < Close [4].
    Now, how shall Ninja be able to evaluate if this condition is true, if you don't have (at least) FOUR bars?

    For debugging, please consider to make excessive use of print statements to the Output Window.
    NT-Roland

    Comment


      #3
      Right to the point. Thank you my friend. His tip solved my problem. Have a great weekend.

      Comment


        #4
        Hello EvergreenGain,

        The steps for debugging a strategy:

        If the strategy is in the Strategy Analyzer, is there data appearing on the Chart Display of the Strategy Analyzer?

        Importantly, are there errors appearing on the Log tab of the Control Center?

        Try testing the Sample MA Crossover strategy included with NinjaTrader on the same chart or Strategy Analyzer using the same instrument, bar type, interval, and date range.

        Do you see results with this strategy? (This would confirm for us data is available and the issue is with the logic in the custom script)

        If the strategy is getting data and the strategy is enabled or a backtest is run with no errors in the Log tab of the Control Center, then would likely indicate the logic conditions did not evaluate as true or orders are being ignored or cancelled.

        In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.

        Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

        https://ninjatrader.com/support/foru...121#post791121

        Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders.

        Let me know if you need any assistance creating a print or enabling TraceOrders.

        Save the output from the output window to a text file and provide this with your reply.


        That said, below is a link to a forum post on indexing errors.
        Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi NT- Roland, do can you help me check another strategy again, please?

          Comment


            #6
            Originally posted by NT-Roland View Post
            Hi EvergreenGain,
            You don't seem to use an "OutputWindow" while running the strategy. New -> NinjaSript Output.
            Otherwise, you would have immediately spotted an error message.

            "Strategy 'GoldPot': Error on calling 'OnBarUpdate' method on bar 3: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

            And here is where this comes from. You check, if CurrentBars[0] < 2, if not, you return.

            HOWEVER, in your conditions, you check (amongst other things) if Close[3] < Close [4].
            Now, how shall Ninja be able to evaluate if this condition is true, if you don't have (at least) FOUR bars?

            For debugging, please consider to make excessive use of print statements to the Output Window.
            NT-Roland
            Hi NT Roland,

            Are you doing? I hope is good!

            Could you help me check another strategy again, please?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            0 views
            0 likes
            Last Post CortexZenUSA  
            Started by usazencortex, Today, 12:43 AM
            0 responses
            2 views
            0 likes
            Last Post usazencortex  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,262 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X