Example scenario:
Strategy is Long, wants to set a Stop below the latest price.
Closing price before session break (Close[0]) was 103.815
Open of bar-being-built (the latest price at OnBarUpdate() is 104.02.
If this was realtime strategy should be able to select any price below 104.02 for a stop.
Lets say strategy detected the gap-up and wants to lock-in the gap-up by setting a stop at the last Close.
Problem: The current 'managed' rule gets in the way and incorrectly prevents this (even though if we were realtime the broker would allow it).
To reproduce the problem run the attached script (see settings recording in first line of output).
Example output:
Historical
CurrentBar=0 01/09/2016 22:00:00. Flat. EnterLong().
01/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Entered internal SubmitOrderManaged() method at 01/09/2016 22:00:00: BarsInProgress=0 Action=Buy OrderType=Market Quantity=100,000 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
OnOrderUpdate Name=Buy, OrderState=Submitted
OnOrderUpdate Name=Buy, OrderState=Accepted
OnOrderUpdate Name=Buy, OrderState=Working
OnOrderUpdate Name=Buy, Qty=100000, filled=100000, avgFillPrice=103.24
CurrentBar=1 02/09/2016 22:00:00. Long. New bar has opened higher at 104.02 than Close[0]=103.815, so SHOULD be OK to use ExitLongStopLimit(limitPrice=103.815, stopPrice=103.815)
02/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Entered internal SubmitOrderManaged() method at 02/09/2016 22:00:00: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=0 LimitPrice=103.81'5 StopPrice=103.81'5 SignalName='' FromEntrySignal=''
Strategy 'sTestExitLongStopLimit/-1': A Sell stop order placed at '02/09/2016 22:00:00' has been ignored since the stop price is greater than or equal to the close price of the current bar. This is an invalid order and subsequent orders may also be ignored. Please fix your strategy.
02/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Ignored SubmitOrderManaged() method at 02/09/2016 22:00:00: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=0 LimitPrice=103.81'5 StopPrice=103.81'5 SignalName='Sell' FromEntrySignal='' Reason='Invalid order price, please see log tab'
CurrentBar=3 06/09/2016 22:00:00. Long. New bar has opened higher at 102.035 than Close[0]=102.011, so SHOULD be OK to use ExitLongStopLimit(limitPrice=102.011, stopPrice=102.011)
06/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Entered internal SubmitOrderManaged() method at 06/09/2016 22:00:00: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=0 LimitPrice=102.01'1 StopPrice=102.01'1 SignalName='' FromEntrySignal=''
06/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Ignored SubmitOrderManaged() method at 06/09/2016 22:00:00: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=0 LimitPrice=102.01'1 StopPrice=102.01'1 SignalName='Sell' FromEntrySignal='' Reason='Invalid order price, please see log tab'
CurrentBar=9 14/09/2016 22:00:00. Long. New bar has opened higher at 102.41 than Close[0]=102.407, so SHOULD be OK to use ExitLongStopLimit(limitPrice=102.407, stopPrice=102.407)
14/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Entered internal SubmitOrderManaged() method at 14/09/2016 22:00:00: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=0 LimitPrice=102.40'7 StopPrice=102.40'7 SignalName='' FromEntrySignal=''
14/09/2016 22:00:00 Strategy 'sTestExitLongStopLimit/-1': Ignored SubmitOrderManaged() method at 14/09/2016 22:00:00: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=0 LimitPrice=102.40'7 StopPrice=102.40'7 SignalName='Sell' FromEntrySignal='' Reason='Invalid order price, please see log tab'
Lets call the current rule
1) I dont see this rule documented anywhere. All the 'managed' rules that stop users doing things should be documented. And ideally each should be assigned a unique reference number. This would make discussion about these rules much easier, and should help NTs testing department.
2) The current rule logs its violations inconsistently: It only logs the first violation. But will show all of them in Output only if TraceOrders=true.
3) The rule SHOULD be
obviously something similar applies to Buy stop orders. Correct rule would be
How could NT have been using an incorrect rule for so long?
1) Many users are using intra-day dataseries. So usually Close[0] will happen to be the same as Open of bar-being built. Difference may appear only after session break, where many people have learned not to trade.
2) Many users may be hitting this violation regularly, but ignoring it since only the first instance gets logged. So their problem may be much worse than log indicates and they might be getting a lot stops that should be valid silently 'ignored' thus causing unexpected order behavior in Historic.
Comment