Support Board
Date/Time: Wed, 27 Nov 2024 15:51:12 +0000
[Programming Help] - ACSIL: How draw an inclined line with text label and bar calculation
View Count: 543
[2023-07-26 07:20:34] |
User840964 - Posts: 46 |
Hello, I'd like to draw an inclined line starting from any bar of the chart by two mouse clicks and going to the left or to the right. The first click would draw the line startpoint and contemporarily get the bar value, e.g. the Open price. The second click would complete the line drawing its endpoint and a text label next to it, on the left or on the right side. The text label would show the detected bar value (Open price). I haven't found clear examples on how to do that. Many thanks. |
[2023-08-02 07:14:53] |
User840964 - Posts: 46 |
Any chance to get a simple line drawn?
|
[2023-08-03 07:06:31] |
User840964 - Posts: 46 |
Any support from Mr Support?
|
[2023-08-04 13:10:07] |
emmanuel - Posts: 58 |
"While Sierra Chart does not provide programming help, if you have basic technical questions that you need answers for, you can post on the Support Board." - Developing Custom Studies and Systems for Sierra Chart - Advanced Custom Study Interaction With Menus, Control Bar Buttons, Pointer Events: Advanced Custom Study Interaction With Menus, Control Bar Buttons, Pointer Events - Using Drawing Tools From an Advanced Custom Study: Using Drawing Tools From an Advanced Custom Study - Accessing data for the main graph in the chart: ACSIL Interface Members - Variables and Arrays: sc.BaseDataIn[][] / sc.BaseData[][] |
[2023-08-04 15:14:21] |
User840964 - Posts: 46 |
Thank you so much, Emmanuel. That's exactly the answer I expected: "Refer to...". I'll study all of that. |
[2023-08-04 18:56:52] |
JohnR - User831573 - Posts: 306 |
There should be either some samples in the ACS_Source, A search with Notepad++ is what I usually do. Also, I kinda remember seeming some source here in the forums, a user submitted. I think that is where I found the code below as a starting place to do my things. Hope this helps, JohnR #include "sierrachart.h" SCDLLName("Update Issue") int CreateRay(SCStudyGraphRef sc, int i1, float p1, int i2, float p2) { s_UseTool tool; tool.ChartNumber = sc.ChartNumber; tool.DrawingType = DRAWING_RAY; tool.Region = sc.GraphRegion; tool.AddMethod = UTAM_ADD_OR_ADJUST; tool.TextAlignment = DT_RIGHT; tool.BeginValue = p1; tool.BeginIndex = i1; tool.EndValue = p2; tool.EndIndex = i2; tool.Color = COLOR_GREEN; tool.LineWidth = 2; tool.LineStyle = LINESTYLE_SOLID; tool.AddAsUserDrawnDrawing = 1; sc.UseTool(tool); return tool.LineNumber; } SCSFExport scsf_update_issue(SCStudyInterfaceRef sc) { int& line_num = sc.GetPersistentIntFast(1); int& index1 = sc.GetPersistentIntFast(2); if (sc.SetDefaults) { sc.GraphName = "Update Issue"; sc.StudyDescription = ""; sc.AutoLoop = 0; sc.GraphRegion = 0; sc.ReceivePointerEvents = ACS_RECEIVE_POINTER_EVENTS_ALWAYS; return; } if (sc.UpdateStartIndex == 0) { if (line_num == 0) { index1 = sc.ArraySize - 10; line_num = CreateRay(sc, index1, sc.Close[sc.ArraySize-2], index1 + 3, sc.Close[sc.ArraySize - 2]); } return; } if (sc.PointerEventType == SC_POINTER_BUTTON_DOWN) { s_UseTool chart_drawing; if (sc.GetUserDrawnDrawingByLineNumber(sc.ChartNumber, line_num, chart_drawing)) { chart_drawing.BeginDateTime.Clear(); chart_drawing.EndDateTime.Clear(); chart_drawing.BeginIndex = sc.ActiveToolIndex; chart_drawing.BeginValue = sc.ActiveToolYValue; chart_drawing.EndIndex = sc.ActiveToolIndex + 1; chart_drawing.EndValue = sc.ActiveToolYValue; sc.UseTool(chart_drawing); } } } |
[2023-08-04 20:17:35] |
User840964 - Posts: 46 |
Thank you so much John, I had already found this source code but it doesn't do what I mean: it creates a ray and then the user can move it. While I mean to draw a line already in the correct position. As far as I've understood, the matter would be to pass sc.ActiveToolIndex to tool.BeginIndex directly. I need to find how to do that. |
[2023-08-05 21:58:36] |
JohnR - User831573 - Posts: 306 |
There are multiple ways to accomplish what you want. - I think a workable method would be to create a study and tie it to either a button or chart popup menu to activate it. Once you press the button or select menu item, then turn on the ability to receive pointer events This study once activated would do something based on the first mouse click - like save the bar and price value you want for the beginning of the line. then on the 2nd mouse click it would assemble the desired properties of the line you want to draw and draw / create it using sc.UseTools. Also you would use the UseTools to create a text box with your desired info and selected draw location. Then you could turn off receiving pointer events. Just a thought. What Others provided was the parts of ACSIL interface you needed to accomplish what you are trying to do. What I first provided was a study that uses some of that capability. Look in Studies.cpp for this as another example ---> SCSFExport scsf_ButtonAndMenuAndPointerExample(SCStudyInterfaceRef sc) I see it starting on line 3677 in NP++ Hope this helps, JohnR |
[2023-08-14 19:43:20] |
User840964 - Posts: 46 |
Well, I've been able to draw a line but I'd like to fix the following: - For a better alignment I had to add a DRAWING_TEXT, and had to set its TextAlignment = DT_BOTTOM | DT_RIGHT to get it set as top left. This one might worth a platform-side check. - The line shows already built after the 2nd click and not "building in progress" between the 2 clicks like the official Line Tool. Many thanks. |
To post a message in this thread, you need to log in with your Sierra Chart account: