Support Board
Date/Time: Sun, 11 May 2025 20:58:50 +0000
[Programming Help] - Problems adjusting ChartDrawing that was added as User Drawn Drawing
View Count: 280
[2024-08-28 12:54:23] |
StanThompson94 - Posts: 6 |
Dear Support Team, I was inactive for a long time (about a quarter to half a year) and have now updated Sierra Chart to the current version (2670). A study I implemented back then no longer works as it should. I have attached a simplified version of the code as an image and the code below to reproduce the error: - I add a ChartDrawing and set "AddAsUserDrawnDrawing=1" (Line 42 to 61 in the picture) - If the lines 69 to 74 below "sc.UseTool(Tool1);" are commented out, the tool will be displayed correctly - If I then try to change the color (lines 69 to 74 are not commented out), the chart drawing is no longer visible - However, the tool still needs to exist because in the code the tool can still be accessed via the LineNumber (see lines 78 to 82) I hope you can help me and thank you in advance. s_UseTool Tool1; Tool1.Clear(); Tool1.DrawingType = DRAWING_RECTANGLEHIGHLIGHT; Tool1.BeginDateTime = 0; Tool1.EndDateTime = 150; Tool1.BeginValue = 5600; Tool1.EndValue = 5616; Tool1.Color = COLOR_BLUE; Tool1.LineWidth = 1; //To see the outline this must be 1 or greater. Tool1.SecondaryColor = COLOR_BLUE; Tool1.TransparencyLevel = 75; Tool1.AddMethod = UTAM_ADD_OR_ADJUST; Tool1.ExtendLeft = 1; Tool1.ShowPrice = 1; Tool1.AddAsUserDrawnDrawing = 1; Tool1.TextAlignment = DT_RIGHT; Tool1.ChartNumber = sc.ChartNumber; sc.UseTool(Tool1); //Tool is added correctly and visible if code below is commented out s_UseTool Tool2; sc.GetUserDrawnDrawingByLineNumber(sc.ChartNumber, Tool1.LineNumber, Tool2); //Try to change color from blue to gray if (Tool2.Color != COLOR_GRAY) { Tool2.Color = COLOR_GRAY; Tool2.SecondaryColor = COLOR_GRAY; Tool2.TransparencyLevel = 75; sc.UseTool(Tool2); } //Tool is no more visible, but must be there, because the following code lines provide the values in the comments s_UseTool Tool3; sc.GetUserDrawnDrawingByLineNumber(sc.ChartNumber, Tool2.LineNumber, Tool3); float beginValue = Tool3.BeginValue; //beginValue == 5600 float endValue = Tool3.EndValue; //endValue == 5616 int toolColor = Tool3.Color; //toolColor == COLOR_GRAY |
![]() |
[2024-08-29 14:50:01] |
Sierra_Chart Engineering - Posts: 19547 |
We cannot spend the time debugging your code but we did some testing and modification of an existing function we have to work with user drawn chart drawings and it works properly: SCSFExport scsf_UseToolExampleDrawingLine(SCStudyInterfaceRef sc)
{ // Set configuration variables if (sc.SetDefaults) { sc.GraphName = "UseTool Example: Line"; sc.GraphRegion = 0; sc.AutoLoop = 0; //No automatic looping return; } int& r_LineNumber = sc.GetPersistentInt(1); if (sc.IsFullRecalculation) { //Draw vertical line on prior bar during full recalculation. s_UseTool Tool; Tool.Clear(); Tool.ChartNumber = sc.ChartNumber; //Tool.LineNumber will be automatically set. No need to set this. Tool.DrawingType = DRAWING_LINE; int DrawingIndex = sc.ArraySize - 1; Tool.BeginDateTime = sc.BaseDateTimeIn[DrawingIndex - 20]; Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex]; Tool.BeginValue = sc.Low[DrawingIndex - 20]; Tool.EndValue = sc.High[DrawingIndex]; Tool.Text = "Label 1"; Tool.TextAlignment = DT_BOTTOM | DT_RIGHT; Tool.Region = 0; Tool.Color = RGB(255, 255, 0); Tool.LineWidth = 5; Tool.AddMethod = UTAM_ADD_ALWAYS; Tool.AddAsUserDrawnDrawing = 1; sc.UseTool(Tool); r_LineNumber = Tool.LineNumber; } else if (sc.UpdateStartIndex < sc.ArraySize -1)//Do this when a new bar is added { //Now move the drawing to the last bar when a new bar has been added to the chart s_UseTool Tool; Tool.Clear(); Tool.DrawingType = DRAWING_LINE; Tool.ChartNumber = sc.ChartNumber; int DrawingIndex = sc.ArraySize - 1; Tool.BeginDateTime = sc.BaseDateTimeIn[DrawingIndex - 30]; Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex]; Tool.BeginValue = sc.Low[DrawingIndex - 30]; Tool.EndValue = sc.High[DrawingIndex]; Tool.Region = 0; Tool.Color = RGB(255, 0, 0); Tool.LineWidth = 20; Tool.AddMethod = UTAM_ADD_OR_ADJUST; s_UseTool ExistingDrawing; int Result = sc.GetUserDrawnDrawingByLineNumber(sc.ChartNumber, r_LineNumber, ExistingDrawing); if (Result == 0) r_LineNumber = 0; Tool.LineNumber = r_LineNumber; Tool.AddAsUserDrawnDrawing = 1; sc.UseTool(Tool); r_LineNumber = Tool.LineNumber; } //int Count = sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_ALL, 0); } Sierra Chart Support - Engineering Level Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy: https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing Date Time Of Last Edit: 2024-11-29 01:40:38
|
[2024-08-30 08:58:34] |
StanThompson94 - Posts: 6 |
Dear Support Team, many thanks for the quick response. You helped me with this too and I found the problem. The origin of the error is still a bug on your site that probably crept in in one of the last updates: The StartDateTime and EndDateTime that was set for the Tool is not the same that you get after using sc.GetUserDrawnDrawingByLineNumber() Simplified code: s_UseTool Tool; //Set Tool parameters Tool.BeginDateTime = 1; Tool.EndDateTime = 150; sc.UseTool(Tool); //Tool.BeginDateTime is 1899-12-31 00:00:00.0 //Tool.EndDateTime is 1900-05-29 00:00:00.0 s_UseTool Tool2; sc.GetUserDrawnDrawingByLineNumber(sc.ChartNumber, Tool.LineNumber, Tool2); //Tool2.BeginDateTime is 1899-12-31 01:00:00.0 //Tool2.EndDateTime is 1900-05-29 02:00:00.0 If you continue to work with the reference (Tool2) without re-setting the EndDateTime, this will lead to the error. I think that your developers should take a look at this because I don't think that's the behavior what you want. Thank you and best regards Thomas Date Time Of Last Edit: 2024-08-30 09:00:05
|
To post a message in this thread, you need to log in with your Sierra Chart account: