Support Board
Date/Time: Tue, 26 Nov 2024 22:13:38 +0000
[Programming Help] - Subgraph is not updating after a custom menu event
View Count: 290
[2023-10-13 02:31:51] |
Mark Lewis - Posts: 25 |
I have pieced together some code so that I select a user drawing (rectangle in this case), right-click and choose my custom menu item. The code triggers a message to the log with the drawing information but I cannot update my subgraph (Subgraph_BalanceZoneTop) to the value retrieved by the code capturing the event. Also, when I add the custom study it puts the subgraph line (Subgraph_BalanceZoneTop ) at 0. How can I fix these two issues? I have searched and searched the custom study examples. Thanks! #include "sierrachart.h" SCDLLName("My Studies") SCSFExport scsf_BalanceZones(SCStudyInterfaceRef sc) { SCString MessageText; SCSubgraphRef Subgraph_BalanceZoneTop = sc.Subgraph[0]; if (sc.SetDefaults) { sc.GraphName = "Balance Zones"; sc.StudyDescription = ""; sc.GraphRegion = 0; Subgraph_BalanceZoneTop.Name = "Balance zone top"; Subgraph_BalanceZoneTop.DrawStyle = DRAWSTYLE_LINE; Subgraph_BalanceZoneTop.PrimaryColor = RGB(127,0,0); // Dark red Subgraph_BalanceZoneTop.DrawZeros = true; return; } int& r_MenuID = sc.GetPersistentInt(1); if (sc.LastCallToFunction) { sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_MenuID); return; } if (sc.UpdateStartIndex == 0) { if (r_MenuID <= 0) { r_MenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Balance zones"); } return; } s_UseTool ChartDrawing; if (sc.MenuEventID != 0 && sc.MenuEventID == r_MenuID) { int selectedLineNumber = sc.GetLineNumberOfSelectedUserDrawnDrawing(); sc.GetUserDrawnDrawingByLineNumber(0, selectedLineNumber, ChartDrawing); float BalanceZoneHeight = ChartDrawing.BeginValue - ChartDrawing.EndValue; Subgraph_BalanceZoneTop[sc.Index] = ChartDrawing.BeginValue; SCString BeginDateTimeString = sc.FormatDateTime(ChartDrawing.BeginDateTime); SCString EndDateTimeString = sc.FormatDateTime(ChartDrawing.EndDateTime); SCString Msg; Msg.Format("Drawing was selected: BeginDateTime=%s, EndDateTime=%s, BeginValue=%f, EndValue=%f, Height=%f." , BeginDateTimeString.GetChars(), EndDateTimeString.GetChars(), ChartDrawing.BeginValue, ChartDrawing.EndValue, BalanceZoneHeight); sc.AddMessageToLog(Msg, 1); return; } } Date Time Of Last Edit: 2023-10-13 02:33:35
|
[2023-10-13 18:26:26] |
Mark Lewis - Posts: 25 |
Okay, I've made a bunch of changes to utilize settings' inputs because I realized I needed to save the value. My input is updated by the right-click menu event, but the subgraph is not drawn in less I open up the settings for the study and click okay. Any ideas? #include "sierrachart.h" SCDLLName("My Studies") SCSFExport scsf_BalanceZones(SCStudyInterfaceRef sc) { SCString MessageText; SCSubgraphRef Subgraph_BalanceZoneTop = sc.Subgraph[0]; SCSubgraphRef Subgraph_BalanceZoneBottom = sc.Subgraph[1]; SCInputRef BalanceHigh = sc.Input[0]; SCInputRef BalanceLow = sc.Input[1]; if (sc.SetDefaults) { sc.GraphName = "Balance Zones"; sc.StudyDescription = ""; sc.DrawZeros = 0; sc.GraphRegion = 0; sc.ValueFormat = 3; sc.AutoLoop = 1; Subgraph_BalanceZoneTop.Name = "Balance zone top"; Subgraph_BalanceZoneBottom.Name = "Balnce zone bottom"; BalanceHigh.Name = "Balance high"; BalanceHigh.SetFloat(0); BalanceLow.Name = "Balance low"; BalanceLow.SetFloat(0); return; } int& r_MenuID = sc.GetPersistentInt(1); if (sc.LastCallToFunction) { sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, r_MenuID); return; } if (sc.UpdateStartIndex == 0) { if (r_MenuID <= 0) { r_MenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Draw balance zones"); } return; } s_UseTool ChartDrawing; if (sc.MenuEventID != 0 && sc.MenuEventID == r_MenuID) { int selectedLineNumber = sc.GetLineNumberOfSelectedUserDrawnDrawing(); sc.GetUserDrawnDrawingByLineNumber(0, selectedLineNumber, ChartDrawing); BalanceHigh.SetFloat(ChartDrawing.BeginValue); BalanceLow.SetFloat(ChartDrawing.EndValue); } float BalanceHighVal = BalanceHigh.GetFloat(); float BalanceLowVal = BalanceLow.GetFloat(); Subgraph_BalanceZoneTop[sc.Index] = BalanceHighVal; Subgraph_BalanceZoneBottom[sc.Index] = BalanceLowVal; } |
[2023-10-13 19:12:24] |
Mark Lewis - Posts: 25 |
Ahhh, calling sc.RecalculateChart() after the drawing values are retrieved solves the issue. Relevant code below. s_UseTool ChartDrawing; if (sc.MenuEventID != 0 && sc.MenuEventID == r_MenuID) { int selectedLineNumber = sc.GetLineNumberOfSelectedUserDrawnDrawing(); sc.GetUserDrawnDrawingByLineNumber(0, selectedLineNumber, ChartDrawing); BalanceHigh.SetFloat(ChartDrawing.BeginValue); BalanceLow.SetFloat(ChartDrawing.EndValue); sc.RecalculateChart(0); } float BalanceHighVal = BalanceHigh.GetFloat(); float BalanceLowVal = BalanceLow.GetFloat(); Subgraph_BalanceZoneTop[sc.Index] = BalanceHighVal; Subgraph_BalanceZoneBottom[sc.Index] = BalanceLowVal; |
To post a message in this thread, you need to log in with your Sierra Chart account: