Login Page - Create Account

Support Board


Date/Time: Wed, 24 Apr 2024 02:59:07 +0000



[Programming Help] - GetStudyLineUntilFutureIntersection example

View Count: 503

[2023-05-17 20:42:43]
User133994 - Posts: 75
Support,

Excellent program.

I've seen a couple other posts on this...but no examples. I couldn't find any examples in the provided Studies.cpp files either.

I am aware of the documentation on the website, however, accessing the "future" lines isn't intuitive as they aren't Subgraphs.
sc.GetStudyLineUntilFutureIntersection()

Please provide a simple example that uses GetStudyLineUntilFutureIntersection and highlights a bar that closes above/below one of these lines. Or, maybe a different example as I might not be thinking about it correctly.

Yes, I'm aware of the PerformCloseCrossoverComparison option and I'm using it. I just can't find a way to notify a subgraph that an intersecting line is nearby or on the current bar?

I suppose perhaps the best way to use this function is in a for loop that checks how "near" the 100+ future extended lines are to the current close? But how to call the function properly (which parameters are required) isn't clear (on each bar?).

Goal: know when price is nearing a "cluster" of many of these lines

(I don't expect anyone to code this up for my specific use case--I'll do that, if you can provide a working example.)

Any examples at all would be helpful.

Thanks
[2023-05-18 04:06:57]
Tony - Posts: 458
Are those lines drawings or subgraphs?
[2023-05-18 08:25:36]
User431178 - Posts: 410

auto lineIndex{ 0 };
auto lineID{ 0 };
auto lineEndIndex{ 0 };
auto lineLevel{ 0.0f };
  
while (sc.GetStudyLineUntilFutureIntersection(sc.ChartNumber
, sc.StudyGraphInstanceID
, index
, lineIndex
, lineID
, lineLevel
, lineEndIndex) != 0)
{
// Your code here //
// e.g. check if is intersected already
// i.e. lineEndIndex != 0
// if not, then check distance from current price to lineLevel
}

[2023-05-18 14:33:34]
User133994 - Posts: 75
Thank you for the help!

They aren't line drawings or subgraphs. These lines are created using sc.AddLineUntilFutureIntersectionEx()--which all show very nicely on the chart, but don't have any associated subgraphs nor are they drawn manually or using the ACSIL drawing functions. So, I need a way to do logic and act upon the lines--and that is what GetStudyLineUntilFutureIntersection does.

Nonetheless, wonderful while loop!

ChatGPT came up with something...but I like your simple powerful example much, much better.

One note, I think the function name is:
sc.GetStudyLineUntilFutureIntersectionByIndex()

instead of GetStudyLineUntilFutureIntersection. Check the sierra chart header to be sure.

Many, many thanks!
[2023-05-18 15:02:24]
User431178 - Posts: 410
Both functions exist, the example was taken from working code, however for your purposes GetStudyLineUntilFutureIntersectionByIndex appears the correct choice.
Date Time Of Last Edit: 2023-05-18 15:02:42
[2023-06-30 01:43:49]
User133994 - Posts: 75
Support, et. al.,

While it appears the loop above is easily understood, I continue to fail getting it right.

Would you please post a simple example of how to use:
GetStudyLineUntilFutureIntersectionByIndex

You could simply update this example:
The scsf_SwingHighAndLow study from Studies6.cpp can be updated so that it allows for 'closed' lines to be a different color than 'still extending' lines? That would require using GetStudyLineUntilFutureIntersectionByIndex.

Again, even, just the chunk that uses GetStudyLineUntilFutureIntersectionByIndex would be helpful (including where the looping information is stored/retrieved within the study).

And, there are some nuances that I don't understand:
GetStudyLineUntilFutureIntersectionByIndex assigns 4 parameters, how to iterate properly through this? Is it simply from 0 to (number of total lines)? I've attempted several times and keep checking if lineEndIndex != 0 and exactly 0 lines show 'closed', when on the chart, they've clearly been closed (above/below), and visually the extension stops drawing.
GetStudyLineUntilFutureIntersection only assigns 1 : how is this function to be used in a loop, is the study expected to manage the lineID and indexes and prices for every line in order to use this function?

Thanks in advance
[2023-06-30 07:00:41]
User431178 - Posts: 410
GetStudyLineUntilFutureIntersectionByIndex assigns 4 parameters how to iterate properly through this? Is it simply from 0 to (number of total lines)?
Yes, you just interate the index parameter.

int GetStudyLineUntilFutureIntersectionByIndex(int ChartNumber, int StudyID, int Index, int& r_LineIDForBar, int& r_StartIndex, float& r_LineValue, int& r_ExtensionLineChartColumnEndIndex);


I've attempted several times and keep checking if lineEndIndex != 0 and exactly 0 lines show 'closed', when on the chart, they've clearly been closed (above/below), and visually the extension stops drawing.
Is your study using manual looping? If so, lineEndIndex is not going to be populated until the subsequent call into your study function.


Here is a working example that check for and deletes any intersected lines at the close of each bar.
To modify the line instead of deleting it you would just need to change DeleteLineUntilFutureIntersection for AddLineUntilFutureIntersection and re-add/edit the line using the parameter set by GetStudyLineUntilFutureIntersectionByIndex.


if (!sc.IsFullRecalculation
&& sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED)
{
auto lineIndex{ 0 };
auto lineID{ 0 };
auto startIndex{ 0 };
auto endIndex{ 0 };
auto lineValue{ 0.0f };

while (sc.GetStudyLineUntilFutureIntersectionByIndex(sc.ChartNumber
, sc.StudyGraphInstanceID
, lineIndex
, lineID
, startIndex
, lineValue
, endIndex))
{
if (endIndex > 0)
sc.DeleteLineUntilFutureIntersection(startIndex, lineID);
else
lineIndex++;
}
}


GetStudyLineUntilFutureIntersection only assigns 1 : how is this function to be used in a loop, is the study expected to manage the lineID and indexes and prices for every line in order to use this function?

int GetStudyLineUntilFutureIntersection(int ChartNumber, int StudyID, int BarIndex, int LineIndex, int& LineIDForBar, float &LineValue, int &ExtensionLineChartColumnEndIndex));

GetStudyLineUntilFutureIntersection assigns 3 parameters, shown in bold above, and no you don't need to manage anything (although you can use the lineID for your purposes).
With this function you iterate the LineIndex parameter from 0 until the function returns 0 (i.e. until no more lines are found for that bar). This does mean that if you want to look at multiple bars you would also need an outer loop that iterates the BarIndex parameter.
Date Time Of Last Edit: 2023-07-01 09:08:53
[2023-06-30 21:27:10]
User133994 - Posts: 75
many thanks for the help. I'm still not seeing it work.

I've added the GetStudyLineUntilFutureIntersectionByIndex() for loop to the bottom of the Studies6.cpp scsf_SwingHighAndLow study. However, I'm still seeing red and blue extensions that are closed on the screen. Nothing is being deleted.

I've attached the .cpp file for you to inspect and try out. Maybe I have a configuration issue? If the attached file works on your system (i.e. no closed extensions paint, only the extension lines above the highest high or below the lowest low) then let me know if there is something else I should try.

Image of the chart https://www.sierrachart.com/image.php?Image=1688160312574.png
- you can see green /red lines inbetween peaks/valleys, those should be the deleted lines because they are closed, but they are still visible.
attachmentlines_example.cpp - Attached On 2023-06-30 21:18:38 UTC - Size: 8.33 KB - 77 views
[2023-07-01 09:05:48]
User431178 - Posts: 410
Is your study using manual looping? If so, lineEndIndex is not going to be populated until the subsequent call into your study function.

Seems this is also true for auto looping, lineEndIndex is not going to be populated until the after the study is calculated.
In both cases this means the the line would not be deleted until the close of the next bar after the study is first calculated.

Also should have used a while loop as we are deleting elements, my bad.

Attached modified code that has the option to delete or re-color the lines after intersection.
Also sets a flag to indicate that the lines should be updated immediately on the next call to the functions after the initial calculation.

Test this on replay (or with live data) and you will see that the lines are updated correctly.
attachmentlines_example.cpp - Attached On 2023-07-01 09:05:45 UTC - Size: 11.55 KB - 94 views
[2023-07-03 01:57:22]
User133994 - Posts: 75
Many, many thanks.

You are correct, I missed this note:
Is your study using manual looping? If so, lineEndIndex is not going to be populated until the subsequent call into your study function.

The updated example does exactly what I was trying to accomplish and more. Many, many thanks.

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

Login

Login Page - Create Account