Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy backtest showing a trade exiting 4 days before it was entered

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

    strategy backtest showing a trade exiting 4 days before it was entered

    This is a screenshot from the trades tab of the strategy analyzer. There seems to be something wrong with the tick data and I'm not sure how to correct it but it's showing a trade exiting several days before it was entered. I've tried isolating this trade by comparing dates and getting the strategy to skip them (both for the 16th and the 20th) but although this approach has worked in other case it is not removing (or skipping) the offending trade in this instance.

    I'm guessing this has something to do with an error in the contract merge process as it's on the rollover date. How would you suggest I correct this portion of the tick data? I've already tried re-downloading the data from Ninjatrader and that hasn't corrected the problem.

    As additional background information I have the trade details being recorded with TraceOrders set to true and also print statements in the OnExecutionUpdate method printing out information from the trade object. That info shows the trade was both entered and exited on the 16th at the same exact time but roughly $4 apart in price.


    Code:
    10/16/2023 12:37:58 PM Strategy 'A1ESvT/-1': Entered internal SubmitOrderManaged() method at 10/16/2023 12:37:58 PM: BarsInProgress=2 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L-REG3-42' FromEntrySignal=''
    
    10/16/2023 12:37:58 PM Strategy 'A1ESvT/-1': Entered internal SubmitOrderManaged() method at 10/16/2023 12:37:58 PM: BarsInProgress=2 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='S-REG3-43' FromEntrySignal=''
    
    10/20/2023 12:00:00 AM Strategy 'A1ESvT/-1': Cancelled pending entry order on opposite side of the market: BarsInProgress=2, orderId='NT-00083-4163' account='Backtest' name='S-REG3-43' orderState=Working instrument='MCL 12-23' orderAction=SellShort orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-10-16 12:37:58' gtd='2099-12-01' statementDate='2023-11-11'
    
    # 42. - LONG - 10/16/2023 12:37:58 PM - A1ESvT
    ------------------
    Entry for L-REG3-42 : 89.44 on bar: 621
    ATR: 0.38
    Target for L-REG3-42 : 89.49
    
    UseHardStop: True HardStop: 10
    Hard Stop: 89.34
    o.StopLoss: 89.34
    Setting ParaStop...
    ParaStop for order: L-REG3-42 : 89.34
    
    10/16/2023 12:37:58 PM - Closing L-REG3-42 on SESS condition at 85.23
    Net: -421 Cumulative Profit: -373
    
    10/23/2023 1:34:19 AM Strategy 'A1ESvT/-1': Entered internal SubmitOrderManaged() method at 10/23/2023 1:34:19 AM: BarsInProgress=2 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='L-REG3-44' FromEntrySignal=''
    ​
    Mark


    Click image for larger version  Name:	Screenshot 2023-11-11 at 7.13.14â¯PM.png Views:	0 Size:	67.2 KB ID:	1277513
    Last edited by markdshark; 11-12-2023, 07:37 AM.

    #2
    Hello markdshark,

    Thanks for your post.

    What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)​

    Please send us a reduced test strategy that demonstrates the behavior you are reporting and a screenshot of the Strategy Analyzer settings you are using to reproduce the behavior so we may look into this matter further.

    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 the test script, go to Tools > Export > NinjaScript AddOn.
    <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
      Thanks Brandon. It's the latest and greatest. 8.1.1.7 64-bit. I was hoping the behavior I described might prompt some recognition of what might be causing the issue or how to work around it. One of the suggestions I foresaw was "your tick data is corrupt, try redownloading it" which I did but that hasn't helped.

      I'll see if I can distill a reduced version although I'm not immediately seeing how. After all it's not as though the problems something like a file not opening in which case one can simply send the relevant section. However when it's a matter of the error occurring in the course of opening and managing the trade then it's not immediately clear to see how I might produce a reduced script that yet contains all the trade logic to recreate the issue.


      Best,
      Mark​

      Comment


        #4
        Hello Mark,

        Thanks for your notes.

        When testing the SampleMACrossover strategy in the Strategy Analyzer on MCL 12-23 from 10/01/2023 to 10/25/2023, I am not able to reproduce the behavior you are reporting. The Exit time of a trade is always reporting a time after the Entry time of a trade.

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

        Overall, we would need to be able to reproduce the behavior so that we may investigate what is causing the behavior. If you are not able to reproduce the behavior using the SampleMACrossover strategy, please try creating a simple test script that demonstrates the behavior along with the steps and settings you are using to reproduce the behavior with the test script.
        <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


          #5
          Thank you Brandon. I hadn't thought of isolating the issue in this fashion but I will add this approach to my toolkit now. It's helpful to know the issue is not with the data and I will test in this manner to make certain.

          I now also fuzzily remember reading at some point in the docs something about there possibly being synchronization issues when running multi timeframe and multi-instrument strategies using tick replay. At the moment my strategy tracks the CL contract and trades on the MCL. Since I posted I have also found that when trading on the primary series I'm not experiencing this anomaly. I have not isolated the MCL as the primary series to test since its patterns form different from what the strategy looks for but do you think this might be it?


          Best,
          Mark​
          Last edited by markdshark; 11-12-2023, 06:34 PM.

          Comment


            #6
            Hello Mark,

            Thanks for your notes.

            Are you referring to this note from the 'Working with Multi-Timeframe Objects' section of the Multi-Timeframe/Multi-Instrument help guide documentation?

            "During historical data processing, NinjaTrader updates the two series strictly according to their timestamps, calling the primary bar series of the corresponding timestamps first, and then calling the secondary series.

            Note: Historical bars are processed according to their timestamps with the primary bars first, followed by the secondary, which is NOT guaranteed to be the same sequence that these events occurred in real-time. If your development requires ticks to process in the same sequence historically as well as in real-time, you will need to enable Tick Replay (utilizes more PC resources)."

            Multi-Timeframe/Multi-Instrument: https://ninjatrader.com/support/help...nstruments.htm
            <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


              #7
              Hmm. yes I think that's it. However.. That seems to suggest CL/MCL would be fine when using tick replay. The remaining wrinkle is my local development is on a Mac using Parallels and my remote run uses a small instance on AWS. I know that's not supported. So that's probably where things blow up then I guess.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              51 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              127 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              69 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              46 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X