Support Board
Date/Time: Fri, 16 Jan 2026 05:40:01 +0000
Post From: Hello - Request for a Button to toggle 1/0 or 1/-1 in a Subgraph value
| [2025-11-28 20:34:36] |
| HumblyTrading - Posts: 217 |
|
This code works, with the help of Grok... I can assign an ACS hotkey and it will maintain the toggle now as a subgraph Value: For anyone else interested, just save it in the usual file and run the remote build... #include "sierrachart.h" SCDLLName("Toggle Subgraph - Perfect ACS Sync") SCSFExport scsf_ToggleSubgraphPerfect(SCStudyInterfaceRef sc) { SCInputRef ButtonNumberInput = sc.Input[0]; SCSubgraphRef ToggleValue = sc.Subgraph[0]; if (sc.SetDefaults) { sc.GraphName = "Toggle Subgraph - Perfect ACS Sync"; sc.StudyDescription = "One-click toggle. Button depressed = 1, released = 0. Perfect sync."; sc.AutoLoop = 0; ButtonNumberInput.Name = "ACS Button Number (1-150)"; ButtonNumberInput.SetInt(1); ButtonNumberInput.SetIntLimits(1, 150); ToggleValue.Name = "Toggle State"; ToggleValue.DrawStyle = DRAWSTYLE_LINE; ToggleValue.PrimaryColor = RGB(0,255,0); ToggleValue.LineWidth = 2; ToggleValue.DrawZeros = true; // Required for ACS button events sc.ReceivePointerEvents = ACS_RECEIVE_POINTER_EVENTS_ALWAYS; // Initialize button state to off (matches default persistent 0) int InitialTargetID = ACS_BUTTON_1; // Default to button 1 sc.SetCustomStudyControlBarButtonEnable(InitialTargetID, false); return; } int SelectedBtn = ButtonNumberInput.GetInt(); if (SelectedBtn < 1 || SelectedBtn > 150) SelectedBtn = 1; int TargetID = ACS_BUTTON_1 + (SelectedBtn - 1); // === Detect and process ACS button toggle event === if ((sc.PointerEventType == SC_ACS_BUTTON_ON || sc.PointerEventType == SC_ACS_BUTTON_OFF) && sc.MenuEventID == TargetID) { int NewState = (sc.PointerEventType == SC_ACS_BUTTON_ON) ? 1 : 0; sc.SetPersistentInt(1, NewState); SCString Msg; Msg.Format("ACS Button %d → %s", SelectedBtn, NewState ? "ON" : "OFF"); sc.AddMessageToLog(Msg, 1); } // === Synchronize button visual state to persistent value === int CurrentState = sc.GetPersistentInt(1); // 0 or 1 sc.SetCustomStudyControlBarButtonEnable(TargetID, CurrentState != 0); // === Output to subgraph === for (int i = sc.UpdateStartIndex; i < sc.ArraySize; i++) ToggleValue = static_cast<float>(CurrentState); } |
