![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
Guys,
I have a strategy that onBarUpdate() determines the market position before trading so as to exit any opposite position first. However, during a backtest a long trade was ignored because a short was open, or so I believe. Here's the trace order output: 3/17/2009 1:23:00 AM Entered internal PlaceOrder() method at 3/17/2009 1:23:00 AM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.3014 StopPrice=0 SignalName='LongX' FromEntrySignal='' 3/17/2009 1:23:00 AM Ignored PlaceOrder() method at 3/17/2009 1:23:00 AM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.3014 StopPrice=0 SignalName=LongX' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.' My OnBarUpdate() code is this: if (Position.MarketPosition == MarketPosition.Short) { if (someCondition) // long entry signal { exitOrder = ExitShort(Position.Quantity, "XShrtOnLongX", "ShortX"); if (stopOrder != null) CancelOrder(stopOrder); entryOrder = EnterLongLimit(simLotsTraded, GetCurrentBid(), "LongX"); As you can see, it should exit before entering and ususally does. However this time it did not. How can I deal with this? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
crmcwi, please try entering code to confirm the order reached indeed 'cancelled' state (confirmed) before you place the opposing order.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
Good idea Bertrand, but let me ask you something that only an experienced NT coder would know.
Can I or should I use a while() loop to wait for the cancelling? In pseudo code, it might be something like: While (stopOrder.OrderState != OrderState.Cancelled) { do something like increment a counter; } the reason I ask is becuase I thought NT should do this in the background and if this should typically be done, it should be documented, yes?
Last edited by crmcwi; 09-25-2009 at 06:39 AM.
Reason: forgot something
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
I don't think you would need a loop for this, as it's all event based - just make sure you received the confirmed cancelled orderstate - this is also a good preparation to take the strategy live as order confirmations would take a bit longer in real life than possibly on the internal Sim101.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jul 2009
Posts: 132
Thanks: 0
Thanked 0 times in 0 posts
|
Ok, thanks Bertrand,
But I'm still confused. My code goes like this: ExitOrder = ..... if stopOrder !=null, cancelOrder (stopOrder) EntryOrder = .... the problem is that the EntryOrder is ignored because the stop order exitorder isn't filled. If I just put a condition to the EntryOrder = , won't the code just process the condition, calculate that the stopOrder is not null, and then proceed past the EntryOrder? In other words, don't I have to make the code wait for the stopOrder to be filled? |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
You want to wait for the fill confirmation in the OnOrderUpdate(), this way you know it's updated / received before you issue your following entry.
http://www.ninjatrader-support2.com/...ead.php?t=7499
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick Question on Internal Order Handling Rules | trader_rick | Automated Trading | 1 | 03-19-2009 07:30 AM |
| Trouble understanding the Internal (interal?) Order Handling | Brian1 | Strategy Development | 9 | 02-13-2009 09:13 AM |
| OCO Order Handling issue | sammano | Strategy Development | 3 | 12-12-2008 06:48 AM |
| Same order is getting fired twice. order state and handling problem | Rocket130713 | Automated Trading | 19 | 09-22-2008 06:58 AM |
| Internal Order Handling Rules for Stop Limits | wayneFH | Strategy Development | 7 | 06-14-2008 06:39 PM |