![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
I'm backtesting something using using the unmanaged approach, and I noticed a weird result.
If the next bar after the current bar would fill a limit order, the fill event fires off on the current bar rather than the next bar. In other words, a fill event for a limit order doesn't align with the bar that filled it. This misalignment messes up the logic for adjusting stops and targets on the current bar if the entry order's status has already been set to Filled before it actually happens, resulting in occasional errors in the backtest results. I got around this by delaying stoploss and target processing until the bar following the fill event (which is the bar that actually caused the fill). If others are accounting for this misalignment in their code and NinjaTrader corrects this behavior, it might break some things. -Alex |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Thanks for the report Alex, I'm not aware of similiar issues seen sofar so would like to investigate with your help if possible.
Is there any way you could mask your proprietary logic and send me your script for testing to support at ninjatrader dot com Attn Bertrand? Please include datafeed, instrument / expiry and timeframe / chart type as well. Thanks much,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
It isn't a problem in my script. This should be easy to duplicate with a simple script. I was on a 2 minute chart of TF using a Zen-Fire data feed through Mirus Futures, with trades executed on a 20-second secondary data series.
-Alex |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Alex, thanks - so this would be different for you in a managed script, is this correct?
I would be surprised since accessing bar info in the event order / execution method would not be a valid check for your situation, since the executions in backtesting are proccessed before the bar update events.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
It is no different in a managed script.
Here's an example. TF 09-11 contract loaded from ZenFire, 2-minute bars, Default 24/7 session template, 2 days ending on 7/4/2011.
7/4/2011 8:26:00 Entered internal PlaceOrder() method at 7/4/2011 8:26:00: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=839.3 StopPrice=0 SignalName='test' FromEntrySignal='' Filled on bar 298 at 839.3 where high=839 and low=838.8 Regardless of whether I use the managed or unmanaged approach, the fill event fires for 1 bar in the future, not on the bar where the order got filled. PHP Code:
Quote:
The problem is that I need to check order states in OnBarUpdate(), so that I can adjust stops and targets for any positions running. The order state is being set to "Filled" and the position is created before the bar that actually fills the entry. -Alex
Last edited by anachronist; 05-21-2012 at 04:54 PM.
|
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
|
Thanks for the clarifications Alex, this would be expected in backtesting and it would not be different for managed vs unmanaged approach how the fill simulation would work - your CurrentBar print comes from the OnOrderUpdate() and it would report the last seen state, at the point your print this CurrentBar would not have advanced as OnBarUpdate() for the next bar has not yet been called. In simulation with CalculateOnBarClose = false this should align as you expext.
For the ExitOnClose issue - so is the position exited or the order expired at session boundary? For order expiration, please try with a TIF of GTC. http://www.ninjatrader.com/support/h...imeinforce.htm
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Fill trades on currect close in backtesting | freewind | General Programming | 21 | 04-25-2012 08:27 AM |
| ProfitTarget filled on backtesting and did not fill on real scenario | Fabiorp | Strategy Analyzer | 3 | 01-02-2012 11:44 AM |
| backtesting - historical fill processing | adamus | Strategy Development | 5 | 06-21-2010 07:04 AM |
| Backtesting Timestamp/Order Fill Bug | DanielB | Version 7 Beta General Questions & Bug Reports | 12 | 05-28-2010 09:13 PM |
| Fill event notification, choice of ATI interface | sizeup | Automated Trading | 1 | 07-01-2007 04:08 AM |