Support Board
Date/Time: Sun, 02 Feb 2025 21:56:52 +0000
[Programming Help] - Discrepancies with backtesting an ACSIL trading system
View Count: 789
[2019-10-11 14:41:59] |
User704508 - Posts: 20 |
Hi, I'm currently running into some issues with my trailing stop loss. I'm not a pro so I'm guessing since I'm not using a market order, it is not yet filled and, the stop loss is already getting modified? I'm not sure how to check if the order was filled so I can check the trailing stop loss. Is it an attached order or a separate one? Since I have the orderId, I'd like to use the OrderStatus function but I can't pass the id in parameter. If you could help me on that I'd really appreciate it. Thanks in advance, Matt Here is a part of the code: int& OrderId = sc.GetPersistentInt(1); int& Stop1OrderID = sc.GetPersistentInt(2); if(/*conditions to buy*/) { s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_STOP_LIMIT; NewOrder.TimeInForce = SCT_TIF_DAY; NewOrder.OCOGroup1Quantity = 1; NewOrder.Price1 = currentPrice + 4*sc.TickSize; NewOrder.Price2 = currentPrice + 2*sc.TickSize; NewOrder.Stop1Price = currentPrice + 12*sc.TickSize; sc.SellEntry(NewOrder); // Remember the order ID for subsequent modification and cancellation Stop1OrderID = NewOrder.Stop1InternalOrderID; OrderId = NewOrder.InternalOrderID; orderStop = currentPrice + 12*sc.TickSize; currentStop = orderStop; } //Check this every minute NewPossibleStop = currentLow + 30*sc.TickSize; if (PositionData.PositionQuantity <= -1 && NewPossibleStop < currentStop && NewPossibleStop < orderStop) { s_SCTradeOrder ExistingOrder; if (sc.GetOrderByOrderID(Stop1OrderID, ExistingOrder) != SCTRADING_ORDER_ERROR) { s_SCNewOrder ModifyOrder; ModifyOrder.InternalOrderID = Stop1OrderID; ModifyOrder.Price1 = NewPossibleStop; sc.ModifyOrder(ModifyOrder); currentStop = NewPossibleStop; Date Time Of Last Edit: 2019-10-11 16:28:42
|
[2019-10-13 20:40:28] |
ForgivingComputers.com - Posts: 994 |
Assuming you declared PositionData somewhere: s_SCPositionData PositionData;
You want to do sc.GetTradePosition(PositionData) every minute if you want to know the current PositionQuantity: //Check this every minute NewPossibleStop = currentLow + 30*sc.TickSize; sc.GetTradePosition(PositionData); if (PositionData.PositionQuantity <= -1 && NewPossibleStop < currentStop && NewPossibleStop < orderStop) { s_SCTradeOrder ExistingOrder; // Then, you need to get the get order object ExistingOrder: sc.GetOrderByOrderID(Stop1OrderID, ExistingOrder); // Finally you check the status of the object ExistingOrder // and test if it isn't filled if (ExistingOrder.OrderStatusCode != SCT_OSC_FILLED) { s_SCNewOrder ModifyOrder; ModifyOrder.InternalOrderID = Stop1OrderID; ModifyOrder.Price1 = NewPossibleStop; sc.ModifyOrder(ModifyOrder); currentStop = NewPossibleStop; |
To post a message in this thread, you need to log in with your Sierra Chart account: