Login Page - Create Account

Support Board


Date/Time: Sat, 04 May 2024 17:48:00 +0000



Post From: ACSIL SCT_ORDERTYPE_TRAILING_STOP example needs updating

[2015-08-10 23:21:49]
bjohnson777 (Brett Johnson) - Posts: 284
I was banging my head on the table until I realized the old sc.BuyOrder/sc.SellOrder functions in the examples were replaced with sc.BuyExit and sc.SellExit.

New ACSIL example to set a trailing stop for an existing order:

int RC; //Return Code
s_SCNewOrder NewOrder;
s_SCPositionData PositionData;
sc.GetTradePosition(PositionData);
if(PositionData.PositionQuantity == 0) {return;} //no position to work with
NewOrder.Reset(); //good idea to do this if it's in a loop
NewOrder.OrderType = SCT_ORDERTYPE_TRAILING_STOP;
NewOrder.TimeInForce = SCT_TIF_GTC;
if(PositionData.PositionQuantity > 0) { //long position
  NewOrder.OrderQuantity = PositionData.PositionQuantity;
  NewOrder.Price1 = PositionData.AveragePrice - 0.001; //10pips below
  RC = sc.BuyExit(NewOrder); //BuyExit to exit an existing long
  }
else { //short position
  NewOrder.OrderQuantity = PositionData.PositionQuantity * -1.0; //keep it positive
  NewOrder.Price1 = PositionData.AveragePrice + 0.001; //10pips above
  RC = sc.SellExit(NewOrder); //SellExit to exit an existing short
  }
if(RC < 0) {sc.AddMessageToLog(sc.GetTradingErrorTextMessage(RC), 0);} //log errors