I would like to share 2 examples of code for “extended rectangles” in Sierra Chart. This is not an indicator, but a possible basis for further development on your side, in case it meets your need.
These rectangles are created when some conditions are met and are extended to the right until they are filled by price. Here, the chosen condition is a kind of pin bar, but it is just for illustration purpose.
See picture:
Attached please find related source code and DLL (v1). The DLL is only the product of the compilation of the source code. Is it not an "external" DLL to be used with the source code.
Basically, at each new bar:
a) all active rectangles are extended to current bar
b) if price fills a rectangle, this rectangle is erased from the list of active rectangles
c) if conditions are met for a new rectangle (for instance: pin bar), this rectangle is created and added to the list of active rectangles
So the study needs to keep a dynamic list of all active rectangles. I chose to use a std::list
And such list has to be persistent between function calls. However, SC does not provide for persistent variable for such type (std::list). So the list is created, and a pointer to it is stored as an integer in sc.PersistVars->i1 :
std::list * p_LowRectanglesList = (std::list*) sc.PersistVars->i1;
std::list * p_HighRectanglesList = (std::list*) sc.PersistVars->i2;
There are 2 versions of the code, depending on the way the rectangles are created: ACSIL user drawings (code 1) or pure ACSIL drawings (code 2).
Code 1: with ACSIL user drawings
The drawings are created as user drawings (Tool.AddAsUserDrawnDrawing = 1).
This allows their manual modifications by the user.
In the list, we just have to store the LineNumber of the active rectangles, and we can retrieve them with sc.GetUserDrawingByLineNumber
This requires to explicitly delete the rectangles when the study is removed from the chart (if (sc.LastCall ToFunction { … }) or when the study is recalculated, for instance after a change of timeframe.
Code 2: with pure ACSIL drawings
Drawings are not created as user drawings.
They cannot be manually modified by the user.
With such pure ACSIL drawings, it is not possible to retrieve the drawings with their LineNumber. So, in addition to the LineNumber, we have to store the min and max value of each rectangle (in order to check if they are filled). This information (LineNumber + min + max) in store in a dedicated Object named "Rectangle", stored in the above-mentioned list:
std::list * p_LowRectanglesList = (std::list*) sc.PersistVars->i1;
std::list * p_HighRectanglesList = (std::list*) sc.PersistVars->i2;
If you have ideas about ways to improve the code (or program it completely differently), your comments are warmly welcome. :)