Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer Glitch

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

    Strategy Analyzer Glitch

    Hello All-

    I am trying to run a Strategy Analyzer for a script I have written. It comes back with information and shows that the test has been completed. Summary page shows data. However, the strategy is taking WAY too many trades. When I looked at the chart I noticed a lot of candles where the system seems to have glitched. The other trades that are taken are done correctly, it is just that every so often there is a candle where hundreds of trades are made. This obviously creates an issue when I try to see the overall profitability of my script. See attached. How do I fix this?

    Thank you,

    Nick
    Attached Files

    #2
    Hello njmeyer713,

    Is the script running with Calculate OnPriceChange or OnEachTick?

    Are the conditions in the script evaluating as true many times and triggering the order action?

    Below is a link to a forum post that demonstrates how to use Print() and TraceOrders to understand behavior.


    You might add to the script the position has be flat to place a new entry.
    Or you could use a bool to prevent new entries until the bar count is different (meaning a bar has closed).
    I know technically every price change the computer is registering that the previous bar has closed. But I have some bools and other functionality that need to be reset after the current bar officially closes. Is it possible to do that in an "On price change" strategy?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      Yes, I will attach a screenshot of the Output window. Please take a look. I enabled trace orders.

      As for you suggestions, it looks like from the Output window that my position is flat, the strategy is buying 2 contracts and selling them quickly. Then buying again. You can see there is a pattern in the Output Window. This pattern continues for probably a thousand or so lines. I also do not want to use the bool to prevent new entries. I'd like for the strategy to take a retrigger on the same candle after a stop out loss.

      Let me know what you think may be causing this issue.

      Thank you,

      Nick
      Attached Files

      Comment


        #4
        Hello Nick,

        This would indicate the conditions to submit the orders are evaluating as true.

        Print all of the values used in the condition set to understand why this evaluating as true as many times as it is.

        What logic would you want to change so that condition set is true less often?

        If you are wanting multiple orders per bar, is that not what the strategy is already doing?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello-

          I am not sure how the conditions are being evaluated as true that many times in a single candle. I am not saying it is impossible for the price to move 16 ticks (my stop) and then back to my entry trigger price and then back to my stop, over and over and over again. It might once in a while on a single bar but it seems unlikely to that it does it this often and this quickly.

          Below you are two screenshots. The Market Replay screenshot is how the strategy should trade. The trade occurs around 13:00 on March 31st.

          The other screenshot is from the Strategy Analyzer Backtest over the same time period with the exact same strategy using tick replay.

          As you can see the same strategy trades completely different. This is not how I want the strategy to trade.

          Please let me know what I need to do to fix this.

          Thank you,

          Nick
          Attached Files

          Comment


            #6
            Hello Nick,

            Below is a link to forum post that demonstrates how to print or write to file all the information needed to understand why the results are different.
            Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


            I am happy to assist with analyzing the output either in the NinjaScript Output window or to file.

            This information would let you know why orders are being submitted when they are being submitted.


            Tick Replay does not affect order fill prices. You must have 1-tick intra-bar granularity for accurate fill prices.
            Below is a link to a forum post about intra-bar granularity.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea-

              Thank you for you response. I have tried to to follow the print() youtube video but I am not sure still.

              Here is the bit of code that triggers the trade mentioned above, 2U-2D.

              if ((High[1] <= High[2])
              && (Low[1] >= Low[2])
              && (GetCurrentBid(0) < Low[1])
              && (GetCurrentBid(2) < Opens[2][0])
              && (GetCurrentBid(3) < Opens[3][0])
              && (GetCurrentBid(4) < Opens[4][0])
              && (GetCurrentBid(1) < Opens[1][0])
              && (GetCurrentBid(0) < Lows[4][1])
              && (ChoppinessIndex1[0] < 59)
              // Condition group 1
              && ((BarsSinceExitExecution(0, @"BreakEvenStop", 0) > 0)
              || (BarsSinceExitExecution(0, @"BreakEvenStop", 0) == -1)))

              {
              EnterShortLimit(Convert.ToInt32(2), (Low[1] + (-1 * TickSize)) , @"Short1-2");
              }

              Can you write out for me what exactly I need to put in the Print() please?

              Thank you,

              Nick

              Comment


                #8
                Hello Nick,

                I'll start it out for you as an example, then you can finish adding all variables and values to the print.

                Print(string.Format("{0} | High[1]: {1} <= High[2]: {2} && Low[1]: {3} >= Low[2]: {4}", Time[0], High[1], High[2], Low[1], Low[2]));
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Chelsea-

                  Thank you for getting it started for me. I got that working. Could you please help me with the rest. I don't want to be a pain, but if I could figure it out myself, I would. I cannot figure out how the syntax for the current bid and the higher timeframes.

                  Thank you,

                  Nick

                  Comment


                    #10
                    Hello Nick,

                    You are referring to GetCurrentBid(0), Opens[2][0], etc, in the code you suggested from post #7?
                    You should be able to just copy and paste these into the parameters of string.Format(). And be sure to add labels to the format string so we know what each value in the output is. (i.e. "High[1]: {1}")

                    I am happy to assist but I cannot debug or write code on your behalf.

                    Let me see what code you have added and I will be happy to assist by providing direction.


                    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                    That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Chelsea-

                      I appreciate the response. Here is what I have come up with so far and it won't let me compile.

                      Print(string.Format("{0} | High[1]: {1} <= High[2]: {2} && Low[1]: {3} >= Low[2]: {4} && GetCurrentBid[0]: {5} < Low[1]: {3} && GetCurrentBid[0]: {5} < Opens [2]{0]: {6}", Time[0], High[1], High[2], Low[1], Low[2], GetCurrentBid[0], Opens[2][0]));

                      This is for the code in post #7. I am attaching the error upon compiling.

                      Thank you again,

                      Nick


                      Attached Files

                      Comment


                        #12
                        Hello Nick,

                        The issue with this is 'GetCurrentBid[0]' GetCurrentBid() is a method (not a series) and uses parenthesis for a parameter, and not brackets for a bars ago index.

                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Chelsea-

                          Thank you for the help so far. I have a another question related to the backtest on this. I am looking at the trades that don't glitch. And noticed something interesting, see the attached screenshot.

                          My initial reaction is that the strategy isn't using Tick Replay for intrabar fills. As you can see I have checked tick replay and I have this data series in my code. However, I feel confident that it is using the Tick Replay because the fill price is correct.

                          The fill is supposed to be one tick below the low of the previous bar. But the strategy then sells the contracts at the open of the bar. It should sell one of the two contracts at a 16 tick profit target and then let the other contract run until price reaches the high of a previous bar.

                          To note, this strategy work like it should both Sim Trading live and when enabled on Market Replay.

                          Is there something I am or am not doing that you can see or think of that is causing this to happen during the Strategy Analyzer?

                          Thanks again Chelsea,

                          Nick
                          Attached Files

                          Comment


                            #14
                            Hello njmeyer713,

                            TickReplay cannot be used for order fill prices.

                            From the help guide:
                            "Notes:
                            1.Tick Replay was NOT designed to provide accuracy in backtesting concerning order fills and execution and should NOT be used to expect the exact sequence of executions as running a strategy on live data. For greater order-fill resolution and accuracy in strategy backtesting, you can use the High Fill Resolution in the Strategy Analyzer. Furthermore you cannot combine both Tick Replay and High Order Fill resolution."


                            Instead, you would need to add a 1-tick series for intra-bar granularity and submit the orders to the BarsInProgress index of that added 1-tick series.

                            Below is a link to a forum post that includes details and a link to the reference sample.

                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Chelsea-

                              Thank you for the response. I have read and re-read the articles, help guides and forum posts about fills and executions. I have to admit, it seems the more I read the less clear it becomes.

                              I have a multi-timeframe, therefore a multi-series strategy. My understanding is that I cannot use the High Order fill resolution. Correct?

                              To try and get as close as possible, I needed to add the 1-tick data series in the State.Configure sections, which I had done previously.

                              It would seem to me that this information is being used because I am getting filled at the correct price, (low or high of previous bar +/- 1 tick.)

                              However, what is unclear is why the intra-bar fill price is correct but the exit price is wrong.

                              I understand and I have read into the differences with historical data/back testing and live data. I understand it won't be exactly the same.

                              But can you answer for me the following:
                              • What is the most accurate way to backtest a multi-series strategy using the strategy analyzer?
                              • Why is it that the fill price is correct and seems to be filling intra-bar but the exit is wrong?

                              Thank you,

                              Nick

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, 03-13-2026, 05:17 AM
                              0 responses
                              93 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              152 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              80 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              53 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              65 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X