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

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.
      Kate W.NinjaTrader Customer Service

      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 Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,789 views
          0 likes
          Last Post aligator  
          Started by Jimmyk, 01-26-2018, 05:19 AM
          6 responses
          837 views
          0 likes
          Last Post emuns
          by emuns
           
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          6 responses
          3,293 views
          1 like
          Last Post jgualdronc  
          Started by Touch-Ups, Today, 10:36 AM
          0 responses
          13 views
          0 likes
          Last Post Touch-Ups  
          Started by geddyisodin, 04-25-2024, 05:20 AM
          11 responses
          63 views
          0 likes
          Last Post halgo_boulder  
          Working...
          X