Login Page - Create Account

Support Board


Date/Time: Sun, 24 Nov 2024 23:35:38 +0000



[Programming Help] - ACSIL Move to Break-Even issue

View Count: 188

[2024-04-22 12:25:39]
User92573 - Posts: 530
Dear Support

I have a study that implements a move to breakeven at a specified offset.

Same SYMBOL Same Chart so sc.BuyEntry / sc.SellEntry and I am closely following the example in "tradingsystem.cpp" line 1744 with the
exception of sc.BuyEntry instead of sc.BuyOrder etc.


{

  //Move to breakeven on Stop Attached order

  // Create an s_SCNewOrder object.
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = 2;
  NewOrder.OrderType = SCT_ORDERTYPE_MARKET;
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;

  //Define the Attached Orders to be attached to the main Market order
  //Target 1
  NewOrder.Target1Offset = 10*sc.TickSize;
  NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;

  //Common Stop
  NewOrder.StopAllOffset = 10*sc.TickSize;
  NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_STOP;


  // Set up a move to breakeven action for the common stop.

  // This is a common setting and applies to all Stop Attached Orders set on the main order.
  NewOrder.MoveToBreakEven.Type=MOVETO_BE_ACTION_TYPE_OFFSET_TRIGGERED;

  //After 5 ticks of profit, the stop order will be moved to breakeven
  NewOrder.MoveToBreakEven.TriggerOffsetInTicks= 5;
  NewOrder.MoveToBreakEven.BreakEvenLevelOffsetInTicks= 0;

  sc.BuyOrder(NewOrder); // replaced with the below


}


My version is as follows:

{  

  // Create an new order object. (Note this is the Object, not the Order!)        
  s_SCNewOrder NewOrder;
  NewOrder.OrderQuantity = i_Orders_Quantity_For_Trade;
  
  
  if(Direction == 1 && Entry_Price > Last_Trade_Price)
  {
    NewOrder.OrderType = SCT_ORDERTYPE_STOP;
  }
  else if(Direction == 1 && Entry_Price < Last_Trade_Price)
  {
    NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
  }
  else if(Direction == -1 && Entry_Price < Last_Trade_Price)
  {
    NewOrder.OrderType = SCT_ORDERTYPE_STOP;
  }
  else if(Direction == -1 && Entry_Price > Last_Trade_Price)
  {
    NewOrder.OrderType = SCT_ORDERTYPE_LIMIT;
  }
    
    
  //NewOrder.OrderType = SCT_ORDERTYPE_STOP; //SCT_ORDERTYPE_MARKET - SCT_ORDERTYPE_LIMIT
  NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED;
  NewOrder.Price1 = Entry_Price;      

  //Define the Attached Orders  
  NewOrder.Target1Offset = Target_Price_Offset;        
  NewOrder.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT;
  
  //Common Stop
  NewOrder.StopAllOffset = Stoploss_Price_Offset;  
  NewOrder.AttachedOrderStopAllType = SCT_ORDERTYPE_STOP;
  
  // This is a common setting and applies to all Attached Stop Orders that are attached to the main order.
  NewOrder.MoveToBreakEven.Type = MOVETO_BE_ACTION_TYPE_OFFSET_TRIGGERED;  
  NewOrder.MoveToBreakEven.TriggerOffsetInTicks = BreakEven_Trigger_Offset);  


  // Entry Order
  
  if(Direction == 1)
  {
    sc.BuyEntry(NewOrder);
  }
  else if(Direction == -1)
  {          
    sc.SellEntry(NewOrder);
  }
  
  // Remember the order IDs for subsequent modification and cancellation        
  Target1OrderID = NewOrder.Target1InternalOrderID;
  Stop1OrderID = NewOrder.Stop1InternalOrderID;
  InternalOrderID = NewOrder.InternalOrderID;
  
  // I added "r_InternalOrderID = NewOrder.InternalOrderID" as I'm not sure if using "InternalOrderID" with "NewOrder.InternalOrderID"
  // might cause a conflict. I'm not sure if it's reserved word?
  r_InternalOrderID = NewOrder.InternalOrderID;


}    

The example does not suggest a test for working status is required however when I place a Buy_Limit order or a Sell_Limit order and it is not filled I still get an unexpected line
when the Breakeven offset is triggered. This is shown in the attached image. It also seems to present the PnL from the Entry?

The line can only be removed buy "Clearing all Sim Orders and Data."

Any help or direction appreciated.
imageSierra ACSIL Move to BreakEven.png / V - Attached On 2024-04-22 12:25:14 UTC - Size: 81.1 KB - 65 views

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account