![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi,
I try to submit a buy limit order at market on close and valid for the next day. The backtest is executed based on daily bars. I also add a 1 minute timeframe to have intraday granularity. But the buy limit order is ignored and I don't understand why. According to the high/low values of the concerning trading day, it should got filled, I guess. Here is the code: protectedoverridevoid Initialize() { Add(PeriodType.Minute, 1); CalculateOnBarClose = true; TraceOrders = true; } protectedoverridevoid OnBarUpdate() { if (BarsInProgress == 0) { Print("Time: " + Time[0].ToString()); Print("High: " + High[0].ToString()); Print("Low: " + Low[0].ToString()); if (Close[0] > Close[1] && counter == 0) { EnterLongLimit(1, true, 1, Low[0] - 10 * TickSize, "Buy limit"); counter = 1; } } } Here is the log: Time: 19.09.2007 00:00:00 High: 1,6559 Low: 1,6492 19.09.2007 00:00:00 Entered internal PlaceOrder() method at 19.09.2007 00:00:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1,6491 StopPrice=0 SignalName='Buy limit' FromEntrySignal='' 20.09.2007 00:00:00 Cancelled order due to end of session handling: BarsInProgress=1: Order='NT-00000/Back101' Name='Buy limit' State=Working Instrument='$EURCHF' Action=Buy Limit price=1,6491 Stop price=0 Quantity=1 Strategy='gtctest' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='e598d36379a94519a6370639446fdcee' Gtd='01.12.2099 00:00:00' Time: 20.09.2007 00:00:00 High: 1,6534 Low: 1,6444 Regards Ralph |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
I suspect "Exit on close" parameter is set to true, can you set this to false.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
OK, I added this: ExitOnClose = false;
But the behaviour is the same. From the log I got the impression, that the order was activ at the 20.09.2007 as desired but not executed and cancelled at the end of that day. Regards Ralph |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
When you run the strategy, do you set the Time In Force to GTC?
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
|
|
|
|
|
|
#6 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Just checked our code and the line "Cancellled order due to end of session handling..." would trigger on the last bar of a session AND either
- DAY TIF is used - Exit on close is set to true I can see in the trace ouput you posted that TIF is in fact GTC which means that Exit on close is set to true. Although you set this programatically, please ensure that when running the strategy, this paramter is in fact set to false.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi Ray,
thanks for the explanation. No matter if I set TIF to DAY or GTC, the trace report always states, that the limit order is cancelled at 20.09.07 EOD. And the problem is, I don't expect this cancelation, but I do expect to see the order is getting filled. The range of the day 20.09.07 is High: 1,6534 Low: 1,6444 and the buy limit is 1,6491 that's in between the range. But the order wasn't filled. Regards Ralph |
|
|
|
|
|
#8 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
The TIF is not the problem --> Please set Exit on close in the strategy dialog to a value of false.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi Ray,
understand now what you mean, because I had a look into the Stratagy Analyser Documentation. However, the field "Exit on close" doesn't show up in the dialog window (only "Entries per direction" and "Entry handling"). I use the simulated version of NT 6.5.1000.5. ??? Regards Ralph |
|
|
|
|
|
#10 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Could you paste in an image of the Strategy dialog screen you see?
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi Ray,
the dialog box is attached. When starting NT and open the dialog box first time, I can see the "Exit on close" entry. After executing the backtest and recalling the dialog box again, the statement is gone. Regards Ralph |
|
|
|
|
|
#12 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Thanks. I see the problem now. ExitOnClose disappears on Daily Bars, this is expected. However, since you have additional intraday bar, this is causing the Exit on close to be handled.
Do this, in OnBarUpdate() code something like: if (CurrentBar == 0) ExitOnClose = false; and retry and see if this resolves this issue.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi Ray,
the behaviour is changing now. (see log below). - The 19.09.07 is the first bar processed (Min. bars required = 8) and as you can see, ExitOnClose is set to false at this bar. - On the same day the buy limit order is issued correctly (as before). - The cancelation on 20.09.07 doesn't occure anymore (because of ExitOnClose=false). - Looking at the chart window the buy limit order is filled on 21.09.07. That is one day to late, should have happen one day earlier. The fill is displayed only on the chart, but is not logged into the output window. Conclusion: The order execution isn't scheduled correctly and the execution confirmation is missing in the output window. Here is the actual log: Time: 19.09.2007 00:00:00 ExitOnClose: False 19.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 8 Time: 19.09.2007 00:00:00 High: 1,6559 Low: 1,6492 19.09.2007 00:00:00 Entered internal PlaceOrder() method at 19.09.2007 00:00:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1,6491 StopPrice=0 SignalName='Buy limit' FromEntrySignal='' 20.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 9 Time: 20.09.2007 00:00:00 High: 1,6534 Low: 1,6444 21.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 10 Time: 21.09.2007 00:00:00 High: 1,6537 Low: 1,6483 24.09.2007 00:00:00 BarsInProgress==0 CurrentBar: 11 ... |
|
|
|
|
|
#14 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
What is the source for your daily data?
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Order not filled | bulegila | ATM Strategies (Discretionary Trading) | 3 | 05-23-2008 11:54 AM |
| Why can't I see the line of my filled price or stop or limit on the chart? | asalada | Miscellaneous Support | 1 | 03-24-2008 05:44 AM |
| Cancel/Remove Limit order if not filled | mwyatt | Strategy Development | 1 | 03-08-2008 07:51 PM |
| Limit orders filled at different price | Richard Von | SuperDOM and other Order Entry Windows | 4 | 01-28-2008 12:02 PM |
| Managing partially filled limit orders | EvolveK | Automated Trading | 1 | 10-30-2007 11:17 AM |