Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting double order need help

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

    Getting double order need help

    I am working on a feature in my strategy to call for cancel stop order and exit position at market when a parameter is met (s1) and it is intermittently sending in double exit order. My code for this is as follows:

    ONBARUPDATE

    if (Position.MarketPosition == MarketPosition.Long && s1 == true && ordercancelled == false)
    {
    CancelOrder (stopLossLong);
    ordercancelled = true;
    }
    if (Position.MarketPosition == MarketPosition.Short && s1 == true && ordercancelled == false)
    {
    CancelOrder (stopLossShort);
    ordercancelled = true;
    }

    ONORDERUPDATE

    if (order.OrderState == OrderState.Cancelled && Position.MarketPosition == MarketPosition.Long && s1 == true && ordercancelled == true)
    {
    SubmitOrderUnmanaged (1, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", "StopLossLong");
    ordercancelled = false;
    }
    if (order.OrderState == OrderState.Cancelled && Position.MarketPosition == MarketPosition.Short && s1 == true && ordercancelled == true)
    {
    SubmitOrderUnmanaged (1, OrderAction.BuyToCover, OrderType.Market, Position.Quantity, 0, 0, "", "StopLossShort");
    ordercancelled = false;
    }

    the double order typically looks like this:

    4/21/2022 11:38:16 AM Strategy 'OCOCHOP3 NT8/248797137': Cancelled custom managed order: orderId='527cca619dea48d18594dff41275c48e' account='Sim101' name='StopLossShort' orderState=Accepted instrument='ES 06-22' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=4471.75 quantity=1 tif=Gtc oco='4ded62d82e314d3d969029938a78fc8bShortExits' filled=0 averageFillPrice=0 onBehalfOf='' id=114795 time='2022-04-21 11:38:06' gtd='2099-12-01' statementDate='2022-04-21'
    4/21/2022 11:38:16 AM Strategy 'OCOCHOP3 NT8/248797137': Entered internal SubmitOrderUnmanaged() method at 4/21/2022 11:38:16 AM: BarsInProgress=1 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='StopLossShort'
    4/21/2022 11:38:16 AM Strategy 'OCOCHOP3 NT8/248797137': Entered internal SubmitOrderUnmanaged() method at 4/21/2022 11:38:16 AM: BarsInProgress=1 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='StopLossShort'

    sometimes i get something like this:

    4/21/2022 12:10:40 PM Strategy 'OCOCHOP3 NT8/248797137': Cancelled custom managed order: orderId='2ad9a7e4b0c549b4b52aabb6e9f5eb83' account='Sim101' name='StopLossLong' orderState=Accepted instrument='ES 06-22' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4446.75 quantity=1 tif=Gtc oco='9db26c0a07a440958b1e1d052f6157ceLongExits' filled=0 averageFillPrice=0 onBehalfOf='' id=114904 time='2022-04-21 12:10:34' gtd='2099-12-01' statementDate='2022-04-21'
    4/21/2022 12:10:41 PM Strategy 'OCOCHOP3 NT8/248797137': Entered internal SubmitOrderUnmanaged() method at 4/21/2022 12:10:41 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='StopLossLong'
    4/21/2022 12:10:41 PM Strategy 'OCOCHOP3 NT8/248797137': Entered internal SubmitOrderUnmanaged() method at 4/21/2022 12:10:41 PM: BarsInProgress=1 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='StopLossLong'
    4/21/2022 12:10:47 PMSubmit Order Unmanaged market
    4/21/2022 12:10:47 PMSubmit Order Unmanaged market

    #2
    Hello metical1,

    I would suggest to use a Print to output if your condition is true multiple times from OnOrderUpdate. You can also output the order update events to see which specific events are triggering the entry. That would let you get a better idea of what events are triggering the multiple entries.

    Comment


      #3
      I figured this out. Since there was an OCO order it was seeing two cancelled orders and submitting 2 market orders. I changed the script to only look for one of the orders and it seems to be working properly in testing the past few days.

      if (order.OrderState == OrderState.Cancelled && order.OrderType == OrderType.StopMarket && Position.MarketPosition == MarketPosition.Long && s1 == true)
      {
      SubmitOrderUnmanaged (1, OrderAction.Sell, OrderType.Market, Position.Quantity, 0, 0, "", "StopLossLong");
      }
      if (order.OrderState == OrderState.Cancelled && order.OrderType == OrderType.StopMarket && Position.MarketPosition == MarketPosition.Short && s1 == true)
      {
      SubmitOrderUnmanaged (1, OrderAction.BuyToCover, OrderType.Market, Position.Quantity, 0, 0, "", "StopLossShort");
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      58 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X