![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 |
|
|
#16 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Alex, after looking further into I think the main issue is that the fill / execution time would simply be different for each series you submit to, if you fill on 0 > it would report it as 9:08 execution > which is correct for this series's resolution. If you submit to the finer 1 minute series > it would report it as fill at 9:07 already - in each bars series that's another bar number of course.
For the time of the fill event absent of any OnBarUpdate() event call, you can directly work in OnExecution() - protected override void OnExecution(IExecution execution) { if (entry != null && entry == execution.Order) Print("Executed @ " + execution.Time); } Pushing this DateTime returned to GetBar() would offer you requesting the bar number on which that execution fell. I think that would be the best approach.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#17 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
I forgot to mention that in the code I posted above, the variable barSeries can be 0 or 1, it makes no difference in the result. It still reports bar 631 as the fill bar when it should be 632.
When I modify my test program to get the execution time in OnExecution(), the execution time is correctly recorded at 6:07 (Pacific time). The trouble is, when I pass this DateTime to GetBar() in OnBarUpdate(), I get series 0 filling on bar 376 (should be 377), and series 1 filling on bar 629 (should be 632). I don't understand this. Bar 629 corresponds to a time of 6:04, not the fill time of 6:07. Here's the current test: PHP Code:
5/14/2012 6:04:00 Entered internal SubmitOrder() method at 5/14/2012 6:04:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=780.3 StopPrice=0 OcoId='' Name='test' Executed at 5/14/2012 6:07:00 Filled 5/14/2012 6:07:00 at 780.3 on series 0 bar 376 on series 1 bar 629 The actual fill bars should be 377 and 632. -Alex
Last edited by anachronist; 05-25-2012 at 07:06 PM.
|
|
|
|
|
|
#18 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Alex, here's for example an approach with OnExecution and GetBar that works fine in my testing returning 377 and 632 for your test and the filled bar, which is correct according to the reported execution timestamp :
Code:
protected override void OnBarUpdate()
{
if (entry != null && entry.OrderState == OrderState.Filled && Time[0] >= exeTime)
{
refBack = GetBar(exeTime);
if (BarsInProgress == 0)
Print(CurrentBar - refBack);
if (BarsInProgress == 1)
Print(CurrentBars[1] - refBack);
}
if (BarsInProgress != 0) return;
if (CurrentBar == barNum)
{
DrawDot("dot", true, 0, Low[0], Color.Blue);
DrawText("text", CurrentBar.ToString(), 0, High[0] + TickSize, Color.Blue);
entry = SubmitOrder(barSeries, OrderAction.Buy, OrderType.Limit, 1, limitPrice, 0, "", "test");
}
}
protected override void OnExecution(IExecution execution)
{
if (entry != null && entry == execution.Order)
exeTime = execution.Time;
}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
|
|
#19 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
Thanks Bertrand. The trick I was failing to grasp is to check whether Time[0] >= filltime in my OnBarUpdate(). I also was using GetBar() wrong.
I must say, the documentation for GetBar() isn't clear at all. The example code, which calculates BarsAgo, implies that GetBar() returns the bar number. The documentation text says the index returned is from the first bar "oldest to newest" but seems to be just the opposite. -Alex |
|
|
|
|
|
#20 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
One other thing I don't understand. I have been using OnOrderUpdate() in my ATM backtest code to process all the order events because I need cancellations and rejections too. Does OnExecution() get called only for fills?
|
|
|
|
|
|
#21 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Thanks for the input, we'll oversee the GetBar() docs for your next update. Correct, OnExecution() would only deal with incoming fills (this could be a partial as well). Keep in mind it will be called after OnOrderUpdate.
A good weekend,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#22 | |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
Okay, it was working fine for limit orders but now I'm getting a severe misalignment with market orders. The misalignment also shows up on the chart.
How can a market order get filled 26 bars and 18 minutes later on the primary series?? To reproduce:
Code:
#region Variables
// Parameters for Zen-Fire TF 06-12 3 minute, Default 24/7 template, 1 day ending 5/24/2012
private int barNum = 160;
private IOrder entry = null;
private int [] fillbar;
private DateTime filltime = DateTime.MinValue;
#endregion
protected override void Initialize() {
Add(PeriodType.Tick, 1);
Unmanaged = true;
CalculateOnBarClose = false;
ExitOnClose = false;
TraceOrders = true;
}
protected override void OnStartUp() {
ClearOutputWindow();
fillbar = new int[CurrentBars.GetLength(0)];
}
protected override void OnExecution(IExecution e) {
if (entry != null && entry == e.Order) {
filltime = e.Time;
Print("Executed at "+e.Time.ToString());
}
}
protected override void OnBarUpdate() {
if (entry != null && entry.OrderState == OrderState.Filled && Time[0] >= filltime
&& filltime > DateTime.MinValue && fillbar[BarsInProgress] == 0) {
fillbar[BarsInProgress] = CurrentBars[BarsInProgress] - GetBar(BarsInProgress, filltime);
Print("Filled on series "+BarsInProgress.ToString()+" bar "+fillbar[BarsInProgress].ToString()+", time "+Time[0].ToString());
}
if (BarsInProgress != 0) return;
if (CurrentBar == barNum)
entry = SubmitOrder(1, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "test");
}
Quote:
I know I must be missing something fundamental here, but the above result seems totally nonsensical. If I change the secondary series type to 1 minute bars, it works fine. It just messes up when the secondary series uses PeriodType,Tick or PeriodType.Second. -Alex
Last edited by anachronist; 05-31-2012 at 05:37 PM.
|
|
|
|
|
|
|
#23 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Alex, is the tick data completely loaded as needed? If you added tick data in the strategy and data was missing, NT would not reload that according to the data loading rules internally - this is a limitation we currently experience for added series. I tip on this being a data issue, as for a MultiSeries strategy all series would have to be loaded up and passing their BarsRequired before any action is taken. Can you please check into your tick data loaded up and reload manually if needed?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#24 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
Ah. While I have tick data history, apparently it's only for day-session data, even though the data series on my chart is for 24/7. The bar in question occurs before the session start. This leads me to ask some additional questions:
Alex |
|
|
|
|
|
#25 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
Data requests occur based on these data load rules: http://www.ninjatrader.com/support/h...rical_data.htm This is the historical data servers for your Zenfire connection. All data is recorded, ETH and RTH on the servers. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#26 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
Hmm, I wonder why I can't seem to get ETH tick data then.
-Alex |
|
|
|
|
|
#27 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Alex, same on a standalone chart for the TF for example running on your Default 24/7? Then please try with a fresh cache for NT7. Shutdown the plaftfrom and go to
Documents\NinjaTrader 7\db\cache and delete the sub(!!) folders seen here completely. Once done, restart NT7 and reconnect to your provider. When you open your charts now it will rebuild the cache used. Would you still see issues receiving ETH tick data properly? Thanks,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#28 |
|
Senior Member
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
|
That worked, after I figured out that I have to close all my workspaces before shutting down, and don't try to re-load the data by re-opening one of those workspaces, but rather create a whole new chart. Thanks!
-Alex |
|
|
|
|
|
#29 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Thanks for reporting back Alex, glad to hear.
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 |