Support Board
Date/Time: Thu, 06 Mar 2025 18:51:21 +0000
[Programming Help] - ACSIL string
View Count: 1492
[2022-02-07 02:41:54] |
User909252 - Posts: 20 |
How would I work with SCString to see if it starts with another string? For instance, if I wanted to check if a drawing object text begins with "DEL", then erase the drawing. Also, when I modify a horizontal line drawing, it changes the text alignment to above the line. |
[2022-02-07 08:42:57] |
User907968 - Posts: 836 |
How would I work with SCString to see if it starts with another string? For instance, if I wanted to check if a drawing object text begins with "DEL", then erase the drawing.
ACSIL Programming Concepts: Working with SCString, Text Strings and Setting ACSIL Structure Member Name Strings Compare CompareNoCase Also, when I modify a horizontal line drawing, it changes the text alignment to above the line.
Do you set the text alignment variable? Using Drawing Tools From an Advanced Custom Study: s_UseTool::TextAlignment
|
[2022-02-07 12:32:52] |
User909252 - Posts: 20 |
Thanks for the compare. As far as alignment goes, no, I'm not setting it. I'm only setting ".Text". I've tried setting the TextAlignment equal to the current TextAlignment but it still moves to the top. |
[2022-02-07 13:03:25] |
User909252 - Posts: 20 |
Here is the code. Figured it would be simple enough. #include "sierrachart.h" SCDLLName("Prefixer") SCSFExport scsf_Prefixer(SCStudyInterfaceRef sc) { int& MenuID = sc.GetPersistentInt(1); if (sc.SetDefaults) { sc.GraphName = "Drawing Prefixer"; sc.AutoLoop = 1; //Automatic looping is enabled. sc.Input[0].Name = "Prefix"; sc.Input[0].SetString(""); sc.GraphRegion = 0; return; } if (sc.Index == 0)// Only do this when calculating the first bar. { // Add chart short cut menu item if (MenuID <= 0) MenuID = sc.AddACSChartShortcutMenuItem(sc.ChartNumber, "Update Drawings"); if (MenuID < 0) sc.AddMessageToLog("Add ACS Chart Shortcut Menu Item failed", 1); } if (sc.MenuEventID != 0 && sc.MenuEventID == MenuID){ int DrawingIndex = 0; s_UseTool DrawingObject; const SCString Prefix = sc.Input[0].GetString(); while( sc.GetUserDrawnChartDrawing(sc.ChartNumber, DRAWING_HORIZONTAL_RAY , DrawingObject, DrawingIndex) ) { int strLen = DrawingObject.Text.GetLength(); const SCString curStr = DrawingObject.Text.GetSubString(strLen); sc.AddMessageToLog(curStr,1); sc.AddMessageToLog(Prefix,1); if(curStr!=Prefix){ DrawingObject.Text = Prefix + " " + DrawingObject.Text; DrawingObject.TextAlignment = DrawingObject.TextAlignment; sc.UseTool(DrawingObject); } DrawingIndex++; } } if (sc.LastCallToFunction) { // Be sure to remove the menu command when study is removed sc.RemoveACSChartShortcutMenuItem(sc.ChartNumber, MenuID); } } curString and Prefix will output fine to the message log, and will be the same, yet it will continue to add the prefix to the text. As you can see, it also moves the text from bottom of line to top of line. Draw a horizontal ray, then right click the chart and do Update Drawings. Ideally I wanted this to run automatically after a new drawing is added but it doesn't really need to run on every tick or every new candle so I couldn't find another way to do it besides a menu option. Date Time Of Last Edit: 2022-02-07 13:04:05
|
[2022-02-07 14:02:22] |
User907968 - Posts: 836 |
curString and Prefix will output fine to the message log, and will be the same, yet it will continue to add the prefix to the text.
Yes, because you are comparing the full text of the drawing object against the prefix, therefore they will never be equal (except when the drawing had no text to begin with) and the prefix will always be added again. Instead you could use the example below, which would only compare characters from the beginning of the string, up to the length of the prefix string. while( sc.GetUserDrawnChartDrawing(sc.ChartNumber, DRAWING_HORIZONTAL_RAY , DrawingObject, DrawingIndex) ) { DrawingIndex++; if (Prefix.CompareNoCase(DrawingObject.Text, Prefix.GetLength()) == 0) continue; sc.AddMessageToLog(DrawingObject.Text, 1); sc.AddMessageToLog(Prefix, 1); DrawingObject.Text = Prefix + " " + DrawingObject.Text; DrawingObject.TextAlignment = DT_RIGHT | DT_BOTTOM; sc.UseTool(DrawingObject); } |
[2022-02-07 14:10:55] |
User909252 - Posts: 20 |
Ah yes, thanks. This line int strLen = DrawingObject.Text.GetLength(); was suppose to be Prefix not DrawingObject.Any thoughts on keeping the drawings text alignment how the user has it set? This sets it to right/bottom. If you don't set it, it automatically goes to the top. |
[2022-02-07 14:18:04] |
User907968 - Posts: 836 |
Any thoughts on keeping the drawings text alignment how the user has it set? This sets it to right/bottom. If you don't set it, it automatically goes to the top.
No, sorry, seems maybe only horizontal alignment is set when using sc.GetUserDrawnChartDrawing. |
To post a message in this thread, you need to log in with your Sierra Chart account: