Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unrealistic behavior in backtesting - HFT like behavior

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

    Unrealistic behavior in backtesting - HFT like behavior



    I am working on a strategy that runs tick by tick and when backtesting I get sometimes 100+trades within a single 15second candle which I can't explain.

    Click image for larger version  Name:	StrIssue.JPG Views:	0 Size:	138.5 KB ID:	1209521Click image for larger version  Name:	StrIssueZ.JPG Views:	0 Size:	51.2 KB ID:	1209522

    There are several steps I take to prevent something like this.

    1. Every condition to enter a trade in my code includes "Position.MarketPosition == MarketPosition.Flat &&..."

    2. The OnStateChange includes "EntriesPerDirection = 1;"

    3. The order handling in the backtesting is also set to "EntriesPerDirection = 1"

    ...and yet this happens.


    The range of this 15second candle is just big enough to account for the profit target and I doubt the price went from min to max back and forth 200 times in 15sec and even if so I dont want this in my back testing because realistically I would never get that oder fill speed running i the strategy

    Does anybody know what causes this or more important how to prevent it?


    Thank you in advance!

    WELD

    #2
    Worst case maybe I could try a workaround and code in a cooldown somehow before the next trade can be entered.

    Comment


      #3
      Hello _WELD_,

      Thank you for your posts.

      Are you backtesting using the Strategy Analyzer or in the Playback connection?

      I'd expect this to occur more so on real time data, like in the Playback connection, when the strategy is run OnPriceChange or OnEachTick, as the conditions for entry may become repeatedly true and you may see multiple entries occurring on the same candle.

      To avoid this, you could consider using BarsSinceExitExecution():



      This method will return either the number of bars elapsed since the last exit, or a -1 if no exits have yet been made. You could add checks in your conditions that BarsSinceExitExecution is either 0 or -1 before entering a trade.

      Please let us know if we may be of further assistance to you.

      Comment


        #4
        Hi Kate,
        I am using the Strategy Analyser, not playback.

        The conditions are coming true repeatedly but it shouldn't be allowed to enter again before flat.
        It would be desired to have multiple entries per 15sec bar if it is trade after trade. Just 200 of them are a bit unlikely.
        I just need the results to be realistic.

        But that BarsSinceExitExecution sounds worth a try even though that would prevent a realistic amount of more than one entry within 15sec, thank you very much!
        I'll let you know how it goes.
        Thank you!

        WELD
        Last edited by _WELD_; 07-29-2022, 03:38 PM.

        Comment


          #5
          NinjaTrader_Kate
          Thank you that did the job. Even though it is now not allowing more than one trade per candle but I guess thats a bit more accurate than 200 trades on one.
          Thank you for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          72 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X