I have a strategy that is using IOrder's managed, it has three IOrder;s enterLong, exitLongStop, and exitLong.
I have TraceOrders set to true, and I am handling the IOrder objects in the OnOrderUpdate section.
The system goes long as expected sets the Stop on the OnOrderUpdate void but the stop cancels itself on the next bar.
Here is my Output window with my own Updates printing plus the TraceOrder:
11/3/2014 11:48:44 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Long 1a' Mode=Ticks Value=30 Currency=0 Simulated=False 11/3/2014 11:48:44 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Long 1b' Mode=Ticks Value=100 Currency=0 Simulated=False 11/3/2014 11:48:44 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Short 1a' Mode=Ticks Value=30 Currency=0 Simulated=False 11/3/2014 11:48:44 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Short 1b' Mode=Ticks Value=100 Currency=0 Simulated=False **NT** Disabling NinjaScript strategy 'MoneyBallv7/3cb385e6b9be4957bb818df39737cd7b' **NT** Enabling NinjaScript strategy 'MoneyBallv7/3cb385e6b9be4957bb818df39737cd7b' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=TakeNoAction ExitOnClose=False Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=False MaxRestarts=4 in 5 minutes 1/1/2013 7:04:14 PM Entered internal PlaceOrder() method at 1/1/2013 7:04:14 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Enter Long' FromEntrySignal='' Symbol: 'CL' - Time: 07:04:14 - Order: Enter Long - @ Mkt - Order Qty: 1 - Filled Qty: 1 - Status: Filled - Order has been filled at 91.99 Symbol: 'CL' - Time: 07:04:14Action - Setting Inital Stop too Allowed Risk 1/1/2013 7:04:14 PM Entered internal PlaceOrder() method at 1/1/2013 7:04:14 PM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=91.49 SignalName='' FromEntrySignal='Enter Long' Symbol: 'CL' - Time: 07:04:14 - Order: Exit Long Stop - Stop Price: 91.49 - Qty: 1 - Status: PendingSubmit - An order has been submitted Symbol: 'CL' - Time: 07:04:14 - Order: Exit Long Stop - Stop Price: 91.49 - Qty: 1 - Status: Accepted - Order has been acknowledged by the broker 1/1/2013 8:00:31 PM Cancelled expired order: BarsInProgress=0: Order='847fc747f349441ab2e216a677380a38/Replay101' Name='Sell' State=Accepted Instrument='CL ##-##' Action=Sell Limit price=0 Stop price=91.49 Quantity=1 Strategy='MoneyBallv7' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='847fc747f349441ab2e216a677380a38' Gtd='12/1/2099 12:00:00 AM' Symbol: 'CL' - Time: 08:00:31 - Order: Exit Long Stop - Stop Price: 91.49 - Qty: 1 - Status: PendingCancel - An order cancellation request has been submitted Symbol: 'CL' - Time: 08:00:31 - Order: Exit Long Stop - Stop Price: 91.49 - Qty: 1 - Status: Cancelled - Order has been cancelled Symbol: 'CL' - Time: 08:00:31 - Action - Status: Cancelled - Order has been cancelled - Selling @ Mkt 1/1/2013 8:00:31 PM Entered internal PlaceOrder() method at 1/1/2013 8:00:31 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='Enter Long' Symbol: 'CL' - Time: 08:00:31 - Order: Exit Long at Market - Qty: 1 - Status: PendingSubmit - An order has been submitted Symbol: 'CL' - Time: 08:00:31 - Order: Exit Long at Market - Qty: 1 - Status: Accepted - Order has been acknowledged by the broker Symbol: 'CL' - Time: 08:00:31 - Order: Exit Long at Market - Qty: 1 - Status: Working - An order is working at the exchange Symbol: 'CL' - Time: 08:00:31 - Order: Exit Long @ Mkt - Order Qty: 1 - Filled Qty: 1 - Status: Filled - Order has been filled at 92.02
1/1/2013 8:00:31 PM Cancelled expired order: BarsInProgress=0: Order='847fc747f349441ab2e216a677380a38/Replay101' Name='Sell' State=Accepted Instrument='CL ##-##' Action=Sell Limit price=0 Stop price=91.49 Quantity=1 Strategy='MoneyBallv7' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='847fc747f349441ab2e216a677380a38' Gtd='12/1/2099 12:00:00 AM'
protected override void OnOrderUpdate(IOrder order) { if(exitLongStop == order && exitLongStop != null) { StatusName = "Exit Long Stop"; sQty = order.Quantity.ToString(); sPrice = order.StopPrice.ToString(); if(order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled) { Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+" - Order: "+StatusName+" - Stop Price: "+sPrice+" - Qty: "+sQty+" - Filled Qty: "+order.Filled.ToString()+" - Status: "+Status+" at "+order.AvgFillPrice.ToString()); if(order.OrderState == OrderState.Filled) { exitLongStop = null; } } else Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+" - Order: "+StatusName+" - Stop Price: "+sPrice+" - Qty: "+sQty+" - Status: "+Status); if(order.OrderState == OrderState.Rejected || order.OrderState == OrderState.Cancelled) { Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+" - Action - Status: "+Status+ " - Selling @ Mkt"); exitLongStop = null; if(Position.MarketPosition != MarketPosition.Flat) exitLong = ExitLong("Enter Long"); } } }
Used to keep the Stop true and adjust for trailing:
if(exitLongStop != null) { Print("!"); if(exitLongStop.StopPrice < MinCloud[0]) { exitLongStop = ExitLongStop(Position.Quantity,MinCloud[0],"","Enter Long"); } else { exitLongStop = ExitLongStop(Position.Quantity,exitLongStop.StopPrice,"","Enter Long"); } }
Any help is appreciated.
SodyTexas
Comment