Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancelled expired order

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Cancelled expired order

    Hello Ninjatrader Support,

    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:

    Code:
    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
    The issue occurs

    Code:
    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'
    OnOrderUpdate

    Code:
    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");
    					}
    				}
    }
    OnBarUpdate

    Used to keep the Stop true and adjust for trailing:

    Code:
    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");
    					}
    				}
    The Print("!"); never occurs in the output window, so, I am expecting the error to be somewhere in the OnOrderUpdate.

    Any help is appreciated.

    SodyTexas

    #2
    Initial Stop Code

    Code:
    if(enterLong == order && enterLong != null)
    				{
    					StatusName = "Enter Long";
    					sQty = order.Quantity.ToString();
    					
    					if(order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled)
    					{
    						Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+" - Order: "+StatusName+" - @ Mkt - Order Qty: "+sQty+" - Filled Qty: "+order.Filled.ToString()+" - Status: "+Status+" at "+order.AvgFillPrice.ToString());
    						
    						if(Position.Quantity == 1 && order.Quantity == 1 && Instrument.MasterInstrument.Round2TickSize(Position.AvgPrice - ((Math.Round(GetAccountValue(AccountItem.CashValue),2)*EquityAtRisk)/Instrument.MasterInstrument.PointValue)) > MinCloud[0])
    						{
    							double longstop = Instrument.MasterInstrument.Round2TickSize(Position.AvgPrice - ((Math.Round(GetAccountValue(AccountItem.CashValue),2)*EquityAtRisk)/Instrument.MasterInstrument.PointValue));
    							Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+"Action - Setting Inital Stop too Allowed Risk");
    							exitLongStop = ExitLongStop(longstop,"Enter Long");
    						}
    						else 
    						{
    							if(exitLongStop == null)
    							{
    								double longstop = MinCloud[0];
    								Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+"Action - Setting Initial Stop");
    								exitLongStop = ExitLongStop(longstop,"Enter Long");
    							}
    							
    							if(exitLongStop != null && Position.Quantity != exitLongStop.Quantity) 
    							{
    								double longstop = MinCloud[0];
    								exitLongStop = ExitLongStop(Position.Quantity,longstop,"","Enter Long");
    							}
    						}
    						
    					}
    					if(order.OrderState == OrderState.Filled)
    					{
    						enterLong = null;
    					}
    						else if(order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Rejected )
    						{
    							Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+" - Order: "+StatusName+" - Limit Price: "+sPrice+" - Qty: "+sQty+" - Status: "+Status);
    							enterLong = null;
    						}
    							else if(order.OrderState == OrderState.PartFilled)
    							{
    								Print("Symbol: "+sSymbol+" - Time: "+ order.Time.ToString("hh:mm:ssss")+" - Order: "+StatusName+" - Limit Price: "+sPrice+" - Qty: "+sQty+" - Status: "+Status);	
    							}
    				}

    Comment


      #3
      Never mind, I figured it out..

      I had the OnBarUpdate logic in the MarketPosition.Position.Flat code, which was a simple mistake on my part.

      You can disregard my question.

      Thanks

      Sody

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by yertle, 04-18-2024, 08:38 AM
      9 responses
      40 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by techgetgame, Yesterday, 11:42 PM
      0 responses
      9 views
      0 likes
      Last Post techgetgame  
      Started by sephichapdson, Yesterday, 11:36 PM
      0 responses
      2 views
      0 likes
      Last Post sephichapdson  
      Started by bortz, 11-06-2023, 08:04 AM
      47 responses
      1,615 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Yesterday, 05:56 PM
      0 responses
      10 views
      0 likes
      Last Post jaybedreamin  
      Working...
      X