Support Board
Date/Time: Sun, 31 Aug 2025 10:11:20 +0000
Post From: Closing all open trades multiple symbols
[2025-07-25 17:33:13] |
TonyCipriani - Posts: 47 |
Update: If you're looking for a way to have different auto-liquidation times apart from the one currently within the Global Profit / Loss Management setting, where you require closing positions at different times due to trading multiple markets, you can use this custom ACSIL study that I've attached. This was generated with the assistance of Google's Gemini AI. Disclaimer: This code was generated to meet a specific request. Please test it thoroughly in a simulated or replay environment before using it in a live trading account. Use at your own risk. #include "sierrachart.h"
SCDLLName("SymbolSpecificAutoCloseWithSeconds") SCSFExport scsf_SymbolSpecificAutoCloseWithSeconds(SCStudyInterfaceRef sc) { // A single input for the user to set the liquidation time as a string SCInputRef LiquidationTimeInput = sc.Input[0]; if (sc.SetDefaults) { sc.GraphName = "Symbol Specific Auto Close (HH:MM:SS)"; sc.StudyDescription = "Closes all positions for the chart's symbol at a specified time entered in HH:MM:SS format."; sc.AutoLoop = 1; // Process the study on every chart update sc.GraphRegion = 0; LiquidationTimeInput.Name = "Liquidation Time (HH:MM:SS format)"; LiquidationTimeInput.SetString("15:59:50"); // Set default value return; } // Get the time string from the input const char* liqTimeString = LiquidationTimeInput.GetString(); // Parse the string to get hour, minute, and second int liqHour = 0, liqMinute = 0, liqSecond = 0; int parseResult = sscanf_s(liqTimeString, "%d:%d:%d", &liqHour, &liqMinute, &liqSecond); // Only proceed if the string was parsed correctly into three numbers if (parseResult == 3) { // Get the current time from the Sierra Chart server SCDateTime CurrentDateTime = sc.GetCurrentDateTime(); int CurrentHour = CurrentDateTime.GetHour(); int CurrentMinute = CurrentDateTime.GetMinute(); int CurrentSecond = CurrentDateTime.GetSecond(); // Check if the current time is at or past the liquidation time if (CurrentHour > liqHour || (CurrentHour == liqHour && CurrentMinute > liqMinute) || (CurrentHour == liqHour && CurrentMinute == liqMinute && CurrentSecond >= liqSecond)) { // Check if there is an open position for the chart's symbol s_SCPositionData PositionData; sc.GetTradePosition(PositionData); if (PositionData.PositionQuantity != 0) { sc.FlattenAndCancelAllOrders(); } } } } |