Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Analyzer with tick replay. Ticks Received change based on backtest end date

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

    Strategy Analyzer with tick replay. Ticks Received change based on backtest end date

    Hello,

    I am running into a weird behavior in the strategy analyzer. I coded my strategy on ninjascript and it uses tick replay. I backtested it from January 1st , 2023 to January 9th. At this point the signals are fired and orders submitted correctly. When I set the date to after the 9th, let's say the 10th, signals are not fired for the 9th. After deeper debugging, the ticks processed in onBarUpdate method are not the same for the two backtests. When I stop the backtest at the 9th, I receive all the ticks correctly. When I change it to a later date, only few ticks are processed.

    I don't understand the problem. I tried to remove historical data for the instrument (YM) for that time period and launch the backtest again to force the redownload of historical tick data. Same issue. I also tried to use local data only (Properties window) while checking in the historical data window that I have all ticks for that date. Still doesn't work.

    I appreciate any help.
    Thanks.

    #2
    Hello Ulfheoynn,

    Thanks for your post.

    When you mention you coded your strategy to use tick replay, do you mean that you enable Tick Replay, added a 1-tick series to the script, and are submitting orders to that added secondary 1-tick series?

    How are you testing to see if "only few ticks are processed"?

    Are you able to reproduce the behavior when testing the SampleMACrossover strategy that comes default with NinjaTrader?

    Please send me a reduced exported copy of the script and the exact steps and settings you are using to reproduce this behavior.

    Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

    To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.​

    To export a script, go to Tools > Export > NinjaScript AddOn.

    I look forward to assisting further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello,

      Thank you for your answer.

      When you mention you coded your strategy to use tick replay, do you mean that you enable Tick Replay, added a 1-tick series to the script, and are submitting orders to that added secondary 1-tick series?
      No, I mean, calculate is set to calculate.onEachTick. And of course, tick replay is enabled to be able to process each tick.

      Thanks to your comments, I went back and made more tests. It turns out that the number of ticks processed is the same as calculated by the code :


      Code:
      protected override void OnBarUpdate()
      {
      
      private tot = 0;
      if (BarsInProgress == 0 && Time[0].Hour >= 20 && Time[0].Day == 9)
      {
      tot++;
      
      Print("Total" + tot);
      }
      
      // Entry and exit logic of my orders
      }
      I limit myself to after 20h on january, 9th.
      ​But knowing that my logic enters a trade at 20h06, if I use the following condition :

      Code:
      protected override void OnBarUpdate()
      {
      
      private tot = 0;
      if (BarsInProgress == 0 && Time[0].Hour >= 20 && Time[0].Day == 9 && Position.MarketPosition == MarketPosition.Long)
      {
      tot++;
      
      Print("Total" + tot);
      }
      
      // Entry and exit logic of my orders
      }

      The variable "tot" is equal to 2 when I stop the backtest to January, 10th [CASE 1] and equal to 2001 when I stop it at January, 9th [CASE 2]. This means, that in [Case 1] the order is entered but the value of Position.MarketPosition changes somehow after processing two ticks.

      In the screenshot attached still related to [Case 1]​, we can see that the order is entered along with a profit target and a stop loss and no other order is entered until the exit on session close order. Meaning when the condition is false, there indeed was a long position.

      Click image for larger version  Name:	Capture.png Views:	0 Size:	85.3 KB ID:	1256286
      Unfortunately, I cannot provide you with a code because it would need to enter a position at a particular time calculated only by my indicators which are third party vendor ones'.

      Thanks.
      Best.
      Attached Files
      Last edited by Ulfheoynn; 06-15-2023, 11:32 AM.

      Comment


        #4
        [Update]

        I printed the Position.MarketPosition for the time period after 20h in [Case 1] and it shows that it goes from Long back to flat briefly (two ticks after) the entry. This happens only in [Case 1]. The weird thing is that no order appears to be executed on the order list in the screenshot and there was still a position that was exited at session close.

        Comment


          #5
          Hello Ulfhoeynn,

          Thanks for your notes.

          I am not sure I fully understand exactly what it is that you are reporting.

          Are you reporting that when the strategy places a Long entry order, the Position.MarketPosition is showing that the strategy is Long and then Position.MarketPosition is reporting Flat after the Exit On Session Close order is placed?

          To investigate this matter further, I would need you to send me a reduced exported copy of the script and the exact steps and settings you use to reproduce the behavior so that I may try to reproduce it on my end.

          Otherwise, you would need to debug the script further by adding prints to understand exactly how it is behaving.

          Below is a link to a forum post that demonstrates how to use prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #6
            Hello,

            I am reporting that when I place my long order in [Case 1], the Position.MarketPosition changes to Long at 20h06 which it should but for two ticks only (a matter of milli seconds). After that, it goes to Flat. And no order was executed for it to go back to flat. Although the variable is equal to flat, the order tab on Strategy Analyzer shows that a long position was held until the market close at 23h.

            As I told you, I cannot provide the script since it uses third-party-indicators that handle the entry.

            Best.

            Comment


              #7
              Hello Ulfheoynn,

              Thanks for your notes.

              Without being able to see the code and reproduce the behavior on our end we would not be able to investigate what is causing the reported behavior to provide further guidance.

              Please create a simple test script that does not use third-party indicators and still reproduces the behavior. Then, send me a copy of the test script that does not use third-party indicators and the steps and settings you use to reproduce that behavior so I may investigate this matter further.
              <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              61 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              134 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              75 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              45 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              50 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X