I have a strange problem with an NT7 strategy's orders. There are three sub-positions in the strategy, filled by entry orders named LE1,LE2,LE3, and of course SE1, SE2,SE3. There are target and stoploss orders for each, named LT1, LT2, LT3, ST1, ST2, ST3, and LS1, LS2, LS3, SS1, SS2, SS3.
While reversing a position, I usually use the following technique:
1) Cancel all the working orders.
2) When they are all cancelled, close the position.
3) Place the entry orders for the new position.
This has worked as a technique for years and for many strategies. However, I am having trouble with one particular strategy. By adding logging to various stages in the activity, I can see that orders are reaching a cancelled state before an OnOrderUpdate() event occurs for them. This is messing with the strategy's ability to perform the reversal correctly. Below are comments and log entries for a specific example.
I would greatly appreciate comments and assistance on this matter.
saltminer
------
Cancel all the working orders after finding they are working....
AllOrdersInactive(): ST1=True ST2=True ST3=True SS1=True SS2=True SS3=True
AllOrdersInactive() result is False
Cancelled custom managed order at 28/08/2018 2:53:00 PM: Order='NT-00004/Replay101' Name='ST1' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=68.75 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d8790329c8bd453b858837b587a8cc68' Gtd='1/12/2099 12:00:00 AM'
Cancelled custom managed order at 28/08/2018 2:53:00 PM: Order='NT-00006/Replay101' Name='ST2' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=68.73 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='fbe7215c04bf4668b6d1d3c86f94c594' Gtd='1/12/2099 12:00:00 AM'
Cancelled custom managed order at 28/08/2018 2:53:00 PM: Order='NT-00008/Replay101' Name='ST3' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=68.7 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7c64d3dc51aa4305b37a9e03f6a7580b' Gtd='1/12/2099 12:00:00 AM'
Cancelled custom managed order at 28/08/2018 2:53:00 PM: Order='NT-00003/Replay101' Name='SS1' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ae07c0ab3d5f4d26bf105d2a8dc3b370' Gtd='1/12/2099 12:00:00 AM'
Cancelled custom managed order at 28/08/2018 2:53:00 PM: Order='NT-00005/Replay101' Name='SS2' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='cbc4e6cf6d88440eb9aad41128646b2c' Gtd='1/12/2099 12:00:00 AM'
Cancelled custom managed order at 28/08/2018 2:53:00 PM: Order='NT-00007/Replay101' Name='SS3' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='91ff7b418aaf40609613b0eb0feda696' Gtd='1/12/2099 12:00:00 AM'
At this point, 5 of the 6 orders IMMEDIATELY become OrderState=Cancelled!!!
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00004/Replay101' Name='ST1' State=PendingCancel Instrument='CL 10-18' Action=BuyToCover Limit price=68.75 Stop price=0
Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d8790329c8bd453b858837b587a8cc68' Gtd='1/12/2099 12:00:00 AM'
AllOrdersInactive(): ST1=True ST2=False ST3=False SS1=False SS2=False SS3=False
AllOrdersInactive() result is False
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00004/Replay101' Name='ST1' State=Cancelled Instrument='CL 10-18' Action=BuyToCover Limit price=68.75 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='d8790329c8bd453b858837b587a8cc68' Gtd='1/12/2099 12:00:00 AM'
AllOrdersInactive(): ST1=False ST2=False ST3=False SS1=False SS2=False SS3=False
AllOrdersInactive() result is True
A single order, ST1, triggers OnOrderUpdate events moving through PendingCancel and then Cancelled. The strategy now proceeds believing all orders are cancelled when they are actually not. You can see below eventually the OnOrderUpdate() events occur to cancel these orders.
28/08/2018 2:53:00 PM going Long from OnOrderUpdate()
28/08/2018 2:53:00 PM GoLong()
28/08/2018 2:53:00 PM Entered internal PlaceOrder() method at 28/08/2018 2:53:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=68.88 StopPrice=0 SignalName='LE1' FromEntrySignal=''
28/08/2018 2:53:00 PM Entered internal PlaceOrder() method at 28/08/2018 2:53:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=68.88 StopPrice=0 SignalName='LE2' FromEntrySignal=''
28/08/2018 2:53:00 PM Ignored PlaceOrder() method at 28/08/2018 2:53:00 PM: Action=Buy OrderType=Limit Quantity=1 LimitPrice=68.88 StopPrice=0 SignalName=LE2' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'
**NT** An Enter() method to submit an entry order at '28/08/2018 2:53:00 PM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
28/08/2018 2:53:00 PM Entered internal PlaceOrder() method at 28/08/2018 2:53:00 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=68.88 StopPrice=0 SignalName='LE3' FromEntrySignal=''
28/08/2018 2:53:00 PM ORDER UPDATE Order='NT-00009/Replay101' Name='Close position' State=PendingSubmit Instrument='CL 10-18' Action=BuyToCover Limit price=68.88 Stop price=0 Quantity=3 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='69488fdd88144c0dbf06ffc223db3b39' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:53:00 PM ORDER UPDATE Order='NT-00009/Replay101' Name='Close position' State=Accepted Instrument='CL 10-18' Action=BuyToCover Limit price=68.88 Stop price=0 Quantity=3 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='69488fdd88144c0dbf06ffc223db3b39' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:53:00 PM ORDER UPDATE Order='NT-00009/Replay101' Name='Close position' State=Working Instrument='CL 10-18' Action=BuyToCover Limit price=68.88 Stop price=0 Quantity=3 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='69488fdd88144c0dbf06ffc223db3b39' Gtd='1/12/2099 12:00:00 AM'
(irrelevant text removed to shorten this forum post)
Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='eceb091054754920825e8652f2aacdbb' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00006/Replay101' Name='ST2' State=PendingCancel Instrument='CL 10-18' Action=BuyToCover Limit price=68.73 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='fbe7215c04bf4668b6d1d3c86f94c594' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00006/Replay101' Name='ST2' State=Cancelled Instrument='CL 10-18' Action=BuyToCover Limit price=68.73 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='fbe7215c04bf4668b6d1d3c86f94c594' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00008/Replay101' Name='ST3' State=PendingCancel Instrument='CL 10-18' Action=BuyToCover Limit price=68.7 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7c64d3dc51aa4305b37a9e03f6a7580b' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00008/Replay101' Name='ST3' State=Cancelled Instrument='CL 10-18' Action=BuyToCover Limit price=68.7 Stop price=0 Quantity=1 Strategy='agEMA_Turbo' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7c64d3dc51aa4305b37a9e03f6a7580b' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00003/Replay101' Name='SS1' State=PendingCancel Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ae07c0ab3d5f4d26bf105d2a8dc3b370' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00003/Replay101' Name='SS1' State=Cancelled Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='ae07c0ab3d5f4d26bf105d2a8dc3b370' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00005/Replay101' Name='SS2' State=PendingCancel Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='cbc4e6cf6d88440eb9aad41128646b2c' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00005/Replay101' Name='SS2' State=Cancelled Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='cbc4e6cf6d88440eb9aad41128646b2c' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00007/Replay101' Name='SS3' State=PendingCancel Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='91ff7b418aaf40609613b0eb0feda696' Gtd='1/12/2099 12:00:00 AM'
28/08/2018 2:23:00 PM ORDER UPDATE Order='NT-00007/Replay101' Name='SS3' State=Cancelled Instrument='CL 10-18' Action=BuyToCover Limit price=0 Stop price=68.95 Quantity=1 Strategy='agEMA_Turbo' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='91ff7b418aaf40609613b0eb0feda696' Gtd='1/12/2099 12:00:00 AM'
Comment