Login Page - Create Account

Support Board


Date/Time: Mon, 21 Apr 2025 13:47:36 +0000



Post From: ACSIL Custom OCO

[2025-03-09 23:24:55]
Gradient - Posts: 121
Hi,

I've noticed that some firms don't process orders properly and thus when sending OCOs, etc, the only order that appears on their end is the ParentOrder.

I decided to manually code the logic of an OCO to alleviate this and ensure that Stops and Targets get sent, but noticed when testing in Replay only the ParentOrders appear.

After getting the ParentOrder by OrderId I do the following:

note: exposure is an SCInputRef int value; tradeTarget is an int value
#################################################################################################################################################################
//check to see if in a position and if change from arrival price hits stop or target send order to exit
    if(ParentOrder.OrderStatusCode==SCT_OSC_FILLED){
      
      s_SCPositionData PositionData;
    
      sc.GetTradePosition(PositionData);
      
//Normalizing PnL into Ticks for comparison

      double pnlTicks=((PositionData.OpenProfitLoss)/50)/sc.TickSize;
      
      double TargetPnL=(tradeTarget*12.50)*PositionData.PositionQuantity;
      
      double StopPnL= -(exposure.GetInt()*12.50)*PositionData.PositionQuantity;
      
      double entryPrice=PositionData.AveragePrice;
      
      //Break Even
      if(pnlTicks==exposure.GetInt()){
        
        
        s_SCNewOrder BreakEven;
        
        BreakEven.OrderType=SCT_ORDERTYPE_MARKET_IF_TOUCHED;
        BreakEven.Price1=entryPrice;
        BreakEven.OrderQuantity=PositionData.PositionQuantity;
        
        if(PositionData.PositionQuantity>0){
          float BEResponse=static_cast<int>(sc.SellOrder(BreakEven));
        }
        else if(PositionData.PositionQuantity<0){
          float BEResponse=static_cast<int>(sc.BuyOrder(BreakEven));
        }
        sc.SetAlert(1,"Moved to BE");
        
        
      }//Target
      
      if(pnlTicks>=tradeTarget){
      
        
        s_SCNewOrder Target;
        
        Target.OrderType=SCT_ORDERTYPE_LIMIT;
        
        Target.OrderQuantity=PositionData.PositionQuantity;
        
        if(PositionData.PositionQuantity>0){
          Target.Price1=entryPrice+(tradeTarget*sc.TickSize);
          float TargetResponse=static_cast<int>(sc.SellOrder(Target));
        }
        else if(PositionData.PositionQuantity<0){
          Target.Price1=entryPrice-(tradeTarget*sc.TickSize);
          float TargetResponse=static_cast<int>(sc.BuyOrder(Target));
        }
        sc.SetAlert(1,"Target Sent");
        
        
      }//Stop
      
      if(pnlTicks<= -exposure.GetInt()){
        
        
        s_SCNewOrder Stop;
        
        Stop.OrderType=SCT_ORDERTYPE_MARKET;
        
        Stop.OrderQuantity=PositionData.PositionQuantity;
        
        if(PositionData.PositionQuantity>0){
          Stop.Price1=entryPrice-(tradeTarget*sc.TickSize);
          float TargetResponse=static_cast<int>(sc.SellOrder(Stop));
        }
        else if(PositionData.PositionQuantity<0){
          Stop.Price1=entryPrice+(tradeTarget*sc.TickSize);
          float TargetResponse=static_cast<int>(sc.BuyOrder(Stop));
        }
        sc.SetAlert(1,"Stop Sent");
        
        
      }
      
      //Exit Position if Stop or Target Achieved
      if(pnlTicks>=tradeTarget || pnlTicks <= -exposure.GetInt()){
        sc.SetAlert(1,"Flattened Positions");
        sc.FlattenAndCancelAllOrders();
      }
      
    }


#################################################################################################################################################################

Is there any logic within this code block that might explain this behavior?

Thanks