NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 08-06-2008, 09:44 AM   #1
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default Buy limit order is not filled

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
Ralph is offline  
Reply With Quote
Old 08-06-2008, 09:53 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

I suspect "Exit on close" parameter is set to true, can you set this to false.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-06-2008, 10:01 AM   #3
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Ralph is offline  
Reply With Quote
Old 08-06-2008, 10:19 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

When you run the strategy, do you set the Time In Force to GTC?
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-06-2008, 10:25 AM   #5
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
When you run the strategy, do you set the Time In Force to GTC?
Yes, I do.
Ralph is offline  
Reply With Quote
Old 08-06-2008, 11:28 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-06-2008, 12:11 PM   #7
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Ralph is offline  
Reply With Quote
Old 08-06-2008, 01:31 PM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

The TIF is not the problem --> Please set Exit on close in the strategy dialog to a value of false.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-06-2008, 02:18 PM   #9
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Ralph is offline  
Reply With Quote
Old 08-06-2008, 03:30 PM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Could you paste in an image of the Strategy dialog screen you see?
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-06-2008, 04:34 PM   #11
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Attached Images
File Type: jpg Analyser.JPG (42.0 KB, 13 views)
Ralph is offline  
Reply With Quote
Old 08-06-2008, 05:35 PM   #12
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-07-2008, 03:20 AM   #13
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
...
Ralph is offline  
Reply With Quote
Old 08-07-2008, 07:52 AM   #14
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

What is the source for your daily data?
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-07-2008, 07:56 AM   #15
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
What is the source for your daily data?
Right, forgot to mention that: It is a 1 year history for EUR/CHF. I imported a 1-day data series and 1-minute data series. Source is IB.
Ralph is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 03:17 AM.