Support Board
Date/Time: Mon, 21 Apr 2025 13:17:31 +0000
How is ZigZag2 drawing it's lines?
View Count: 164
[2025-03-05 16:06:36] |
User153286 - Posts: 57 |
I am building my own study with ACSIL. I am wondering what the recommended way is to draw lines similar to ZigZag2? I would just look at the code, but that code based is not available. Does ZigZag2 use sc.UseTool or is it using something else such as a GL approach? I read somewhere the overuse of sc.UseTool can be a performance hit. I am considering to limit to visible bars only. Any examples to look at or words of wisdom here? |
[2025-03-05 16:21:40] |
User431178 - Posts: 651 |
Does ZigZag2 use sc.UseTool or is it using something else such as a GL approach? No, ZigZag2 does not draw anything. I am wondering what the recommended way is to draw lines similar to ZigZag2
What does lines similar to zigzag mean?ZigZag uses subgraphs, check the example in acs_source/studies7.cpp, search "scsf_ZigZagStudy". |
[2025-03-05 16:42:41] |
User153286 - Posts: 57 |
I have researched studies7.cpp extensively. I based my question on the comment that is above the switch code block starting on line 1618 in studies7.cpp specifically interested in case 2. Based on this it seems the lines are created within the invocation of sc.ZigZag2 //Calculate and set the zigzag lines switch (Input_CalculationMode.GetInt()) { case 1: sc.ZigZag( sc.BaseData[Input_DataHigh.GetInputDataIndex()], sc.BaseData[Input_DataLow.GetInputDataIndex()], Subgraph_ZigZagLine, CalcIndex, Input_ReversalPercent.GetFloat() * 0.01f, ZigZagStartIndex); break; case 2: sc.ZigZag2( sc.BaseData[Input_DataHigh.GetInputDataIndex()], sc.BaseData[Input_DataLow.GetInputDataIndex()], Subgraph_ZigZagLine, CalcIndex, Input_NumberBarsForReversal.GetInt(), Input_ReversalAmount.GetFloat(), ZigZagStartIndex); break; case 3: sc.ZigZag( sc.BaseData[Input_DataHigh.GetInputDataIndex()], sc.BaseData[Input_DataLow.GetInputDataIndex()], Subgraph_ZigZagLine, CalcIndex, 0.0f, Input_ReversalAmount.GetFloat(), ZigZagStartIndex); break; } |
[2025-03-05 16:46:37] |
User431178 - Posts: 651 |
sc.ZigZag2( sc.BaseData[Input_DataHigh.GetInputDataIndex()], sc.BaseData[Input_DataLow.GetInputDataIndex()], Subgraph_ZigZagLine, CalcIndex, Input_NumberBarsForReversal.GetInt(), Input_ReversalAmount.GetFloat(), ZigZagStartIndex); What is the third argument passed to the function? It is the subgraph for zig zag line. Subgraph draws the line, sc.ZigZag2 populates the subgraph with values. |
[2025-03-05 18:22:35] |
User153286 - Posts: 57 |
Thank you for that clarification, that greatly helps. I could not figure out how ZigZag was "skipping" bars when the drawing lines. I now suspect it is skipping bars because of Subgraph_ZigZagLine.DrawZeros = false; that is set in the zigzag code. I assume if I set the value of a barindex to 0 ( sc.Subgraph[0].Data[barindex] = 0; ) SC will "skip it" when drawing to the screen. Can you confirm that's what's going on with ZigZag? |
[2025-03-05 18:35:57] |
User431178 - Posts: 651 |
I could not figure out how ZigZag was "skipping" bars when the drawing lines.
What do you mean by skipping bars?
|
[2025-03-05 19:12:06] |
User153286 - Posts: 57 |
See the attached file The dotted white lines are created by the standard zigzag study using using mode 2. I drew a blue line over two of these white lines to illustrate what I mean by skipping bars. The first blue line spans 5 bars. The low of the bar 1 is connected to the high of the bar 5. The second blue line does not skip bars, simply connecting the high of the first to low of the second bar In my ASCIL study, setting the don't use 0.0 values, given a 5 bar example, is it "correct" to set subgraph[0].data[index-of-bar1] = low of bar 1, then use 0.0 values for the data values of bars 2, 3, 4 and finally set the data value of bar 5 to the high value of bar 5? Is that the "correct" recipe to use in SC writing a ACSIL study that draws similar types of lines with a subgraph structure? |
![]() |
[2025-03-05 19:35:06] |
User431178 - Posts: 651 |
The second blue line does not skip bars, simply connecting the high of the first to low of the second bar
Check the tool values window, no bars are being skipped, the zig-zag line subgraph is populated at each bar. If you are setting the subgraphs in your study to zero, you could use the Line Skip Zeros subgraph as the drawstyle I think. or You could fill the bar values in between with interpolated values, using the function sc.FillSubgraphElementsWithLinearValuesBetweenBeginEndValues. ACSIL Interface Members - Functions: sc.FillSubgraphElementsWithLinearValuesBetweenBeginEndValues |
[2025-03-05 20:14:38] |
User153286 - Posts: 57 |
Ah that helps my brain even more! I always over think things. This is simple and it helps we with some other concepts to incorporate. If only trading was this easy. Thanks again...
|
[2025-03-07 16:50:06] |
User153286 - Posts: 57 |
I posted this reply to help others in the future. I hate when I read a post here and there is no follow up. My goal is to build a study similar to zigzag. While I have not yet played with the interpolation api suggested above, I did create something that is/was outputting text (HH, LL, HL, LH) using the SC.usetool. My logic requires to alter previous text items based on the closing of a future bar. In my attempted approach I did this by deleting the previously drawn SC.usetool item and re-creating a new one as required. Oh that was a bad idea... That approach absolutely killed performance. It's not the delete, it's the number of SC.usetool elements in "edit mode" as they are all uniquely selectable in the chart. I had hundreds of them on the chart. I could barely even move the mouse on the chart. Furthermore, the only way I could clear this mess once drawn was to delete the entire chart. All those "editable", unique SC.usertool draw text items could only be individually deleted, even using using the Tool menu delete all feature did not work. What a PITA. Using SC.usetool to draw lines in my custom zigzag study would have been a disaster. I found if I used the same linenumber for each tool it seemed ok, but when I let the system auto generate the id and the tool was configured in "edit mode", that combo was so taxing on the system. I think if the linenumber is the same and I delete the SC.usetool, it would have deleted all of them, not just the "previous" one which is what my logic requires. At this point I have given up on using SC.usetool for multiple items (100's of them) on the screen via a custom study. There are numerous posts here and on the web showing how to code SC.usetool so I am not going into that detail. FYI I am able to use the standard graph structure and alter previous bar values for that graph structure (set value to 0 at barindex). So instead of using text labels, I am going to use a number of graph structures with different markers (red/green dots, up/down triangles, red/green dashes-hashes). The graph structure approach does not seem to affect performance. From my perspective this can be closed. Oh and thanks for the interpolation approach, I foresee some cool things from using the interpolation approach. SC support I do not need a reply unless there is something you deem should be added. |
To post a message in this thread, you need to log in with your Sierra Chart account: