Login Page - Create Account

Support Board


Date/Time: Fri, 03 May 2024 22:04:47 +0000



[Programming Help] - deleting tool drawing

View Count: 525

[2021-02-25 20:46:17]
User30743 - Posts: 364
I have been writing some utils functions one of them is to display text on the chart, the problem is the text is still there even though i hide or remove the study, and even though i reload the chart afterwards. I just need to completely close it and load it again.

I found two studies in sierrachart.h that i used as reference
void AddAndManageSingleTextDrawingForStudy
and
void AddAndManageSingleTextUserDrawnDrawingForStudy
I basically copied and paste the code from the studies, did some changes into argument list and wrap it into a class.

Here is my code

class Display {
public:
static void displayText(SCStudyInterfaceRef& sc, const SCString& textToDisplay, int horizontalPosition, int verticalPosition, SCString description = "") {
int& r_DrawingTextLineNumber = *static_cast<int*>(sc.StorageBlock);

// delete it when i remove
if (sc.LastCallToFunction) {
if (r_DrawingTextLineNumber != 0 && sc.UserDrawnChartDrawingExists(sc.ChartNumber, r_DrawingTextLineNumber) > 0) {
sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, r_DrawingTextLineNumber);
}

return;
}

//Reset the line number if the drawing no longer exists.
if (r_DrawingTextLineNumber != 0 && sc.UserDrawnChartDrawingExists(sc.ChartNumber, r_DrawingTextLineNumber) == 0) {
r_DrawingTextLineNumber = 0;
}

if (sc.HideStudy && r_DrawingTextLineNumber != 0) {
sc.DeleteUserDrawnACSDrawing(sc.ChartNumber, r_DrawingTextLineNumber);
r_DrawingTextLineNumber = 0;
}

if (sc.HideStudy)
return;

SCString text;
text += description;
text += " ";
text += textToDisplay;

s_UseTool t;
t.ChartNumber = sc.ChartNumber;
t.DrawingType = DRAWING_TEXT;
t.FontBackColor = RGB(0, 0, 0);
t.FontSize = 10;
t.FontBold = false;
t.AddMethod = UTAM_ADD_OR_ADJUST;
t.UseRelativeVerticalValues = 1;
t.Color = RGB(255, 255, 255);
t.Region = 0;
t.Text = text;
t.BeginDateTime = horizontalPosition;
t.BeginValue = verticalPosition;

if (r_DrawingTextLineNumber != 0)
t.LineNumber = r_DrawingTextLineNumber;

if (sc.UseTool(t) > 0)
r_DrawingTextLineNumber = t.LineNumber;
}
};

here is how i call it in the main study

SCSFExport scsf_DrawTextToChart(SCStudyInterfaceRef sc) {
if (sc.SetDefaults) {
sc.GraphRegion = 0;
}

util::Display::displayText(sc, "testing..", 5, 85);
}

it does the job BUT it stays on the chart forever. Why is that so? I am deleting in at the beginning no? Have been trying to figure out for last two hours but no success
Date Time Of Last Edit: 2021-02-25 20:50:59
[2021-02-26 10:02:36]
User907968 - Posts: 802
If you want to manage as user drawn drawing, then you need to set 'AddAsUserDrawnDrawing' in the s_UseTool struct - https://www.sierrachart.com/index.php?page=doc/ACSILDrawingTools.html#s_UseTool_AddAsUserDrawnDrawing.
[2021-02-26 10:25:48]
User30743 - Posts: 364
genius

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account