Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Orders on Backtest

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

    Market Orders on Backtest

    Hi guys

    I have created an auto strat that uses a stop and reverse technique, initially i wanted to use limits but because of internal order handling i've gone for a method whereby i execute a market order to go short once my long stop has been triggered. The issue with this is that in backtesting it doesn't show the market order in the correct place, it's always at the following bars open. Now initially i thought that was because of the tick data issue but today it occurred to me that I'm firing the logic inside the onexecution event for the stop loss trigger, so it doesn't seem to make sense that the market order should show at the next bars open as I thought the onexecution event fires on the execution of a limit which in this case is in the middle of the previous bar somewhere. Why then does it stick the market order at the beginning of the next bar as if it's only been executed during OnBarClose?

    many thanks
    Ross

    #2
    Ross,

    This is because you are backtesting. When backtesting you are look at snapshots in time for each bar and processing your strategy logic at those snapshots. The snapshot interval is at the end of each bar. Since those bars are always already closed there is absolutely no tradeable location on that bar and so the next available trading location is the open of the next bar. That is why you see it there.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh,

      I'm guessing then that the backtest engine uses a scenario where it only has one event firing at the closure of every bar and doesn't actually fire execution events at fills etc.

      Do you know if there is any scope in the future for the engine to at least take account of order execution, order update event logic so that strategies using market orders based on previous fills would be somewhere in the region of where they should be.

      I have now tried all manner of workarounds to incorporate stop and reverse into my strat and with internal order handling blocking the ability for me to have limits running both ways and backtesting placing my market orders in the wrong place my hands are pretty much tied. I've hit a similar dead end with a strat involving breakouts placed either side of a bar.

      Cheers
      Ross

      Comment


        #4
        Ross,

        You don't have the granularity information to do such types of trades in backtesting. Unfortunately you just cannot trade on a closed bar.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I see, i guess the issue at hand is not the firing of the logic in the onexecution but it's the fact that it's happening late that means the market order is going in at first tick of next bar rather than at the point where it happened.

          I think the issue is more that there is no logic in the after the bar analyser to make the assumption that if execution event fires and market orders are triggered the assumption should be that the market orders went in at the price level that the execution event took place at rather than the current price level which is first tick of next bar. Perhaps something like this would overcomplicate the engine but it does leave a hole in backtesting in strats where market orders need to be placed like this.

          Thanks
          Ross

          Comment


            #6
            Ross,

            If you need additional granularity please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=6652

            But at the end of the day, you are still taking snapshots and you are still processing at the close of each bar.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh how low down does the bar series you can reference go, am I able to reference a tick bar series or would a one minute bar be the smallest?

              Thanks for this.

              Ross

              Comment


                #8
                Ross,

                You can add ticks, but bear in mind ticks series have a lot more bars then minute series and that means you will use a lot more system resources in loading a tick series.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Josh this is fantastic, I think you guys are doing yourself an injustice here, i've been led to believe through a number of posts on this forum that backtesting with tick data on the strategy analyser is not possible, this is entirely inaccurate, using your multiple bar series ability I've now added a 1 tick bar series as my secondary series, what i noticed is that in live it effectively renders the calculateonbarclose option obsolete as it essentially converts it into a tick by tick format but the great thing is that it now works in back test on strategy analyser on a tick by tick basis when checking my order fills. The performance change for me is negligible at the moment although i've never had any of the performance problems that I understand other users have. I do have a brand new top spec system though so that could be the factor.

                  Another thing that I found is that there is a misconception on the forum about historical data for forex with Gain, it seems your ninja servers are carrying months worth of data for tick data and years worth for other bars on the common currencies. This seems to be something that has been added but not really talked about much, I initially didn't realise this was available as I came across allot of older posts complaining about the problem of loading historical data.

                  Perhaps something you guys want to think about it putting an auto filter on the forum search so that it defaults to only the latest 6 months (with option to remove) of posts so that users don't pick up old and out of date things that can confuse about what is and isn't available. I guess though when we move to 7 it will effectively be like a reset.

                  Thanks for the help.
                  Ross

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mgco4you, Today, 09:46 PM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by wzgy0920, Today, 09:53 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post wzgy0920  
                  Started by Rapine Heihei, Today, 08:19 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by Rapine Heihei, Today, 08:25 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Rapine Heihei  
                  Started by f.saeidi, Today, 08:01 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X