Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 11:25:21 +0000



[Programming Help] - drawing a marker, issues with repeated drawing

View Count: 360

[2023-10-04 09:20:53]
User138457 - Posts: 36
hi,

following
Using Drawing Tools From an Advanced Custom Study
I use the following code to draw a marker, when the bottom of a bar shows a finished auction



s_UseTool Tool;
int UniqueLineNumber = 74191;//any random number.

//Tool.Clear(); // Reset tool structure. Good practice but unnecessary in this case.
Tool.ChartNumber = sc.ChartNumber;

Tool.DrawingType = DRAWING_MARKER;
Tool.LineNumber = UniqueLineNumber +1;

Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.BeginValue = sc.Low[sc.Index]-0.5;

Tool.Color = RGB(0,200,200);
Tool.AddMethod = UTAM_ADD_OR_ADJUST;

Tool.MarkerType = MARKER_X;
Tool.MarkerSize = 8;

Tool.LineWidth = 5;

sc.UseTool(Tool);


However, this only gives a marker on the most recent bar that fulfills
(worse: "had fullfilled sometime during bar formation") this condition.
What do I need to change to "keep" the drawings?
Addtionally, is there a way to NOT draw during bar formation but only for finished bars?
Otherwise I would need to delete the drawing again, when the bar has a finished auction
somewhen during bar formation, but not at its close.
[2023-10-10 08:35:38]
User138457 - Posts: 36
can anyone guide me, please?
Date Time Of Last Edit: 2023-10-10 08:35:49
[2023-10-10 08:46:09]
User907968 - Posts: 802
However, this only gives a marker on the most recent bar that fulfills
(worse: "had fullfilled sometime during bar formation") this condition.
What do I need to change to "keep" the drawings?

Remove this line, it is not needed.

int UniqueLineNumber = 74191;

Reusing the same drawing number means you have only one instance of the drawing.

Addtionally, is there a way to NOT draw during bar formation but only for finished bars?

sc.GetBarHasClosedStatus()
Date Time Of Last Edit: 2023-10-10 08:46:22
[2023-10-11 08:52:18]
User138457 - Posts: 36
thanks, I'll trz that asap
[2024-03-08 08:37:33]
User138457 - Posts: 36
I almost solved my problem, thanks. One issue remains though:
I'm using

if(condition)
  {  
  s_UseTool Tool;
  Tool.Clear(); // Reset tool structure. Good practice but unnecessary in this case.
  Tool.ChartNumber = sc.ChartNumber;
  Tool.DrawingType = DRAWING_MARKER;
  Tool.LineNumber = ToolID1 +1;
  ToolID1 ++;
  Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
  Tool.BeginValue = sc.Low[sc.Index]-Shiftmarker;
  Tool.Color = RGB(0,128,0);
  Tool.AddMethod = UTAM_ADD_ALWAYS;
  Tool.MarkerType = MARKER_X; //MARKER_TRIANGLEUP;
  Tool.MarkerSize = 4;
  Tool.LineWidth = 5;
  sc.UseTool(Tool);
  }
However, this leads to multiple drawings if the condition is met several times during the formation
of the candle. If I were to use UTAM_ADD_ONLY_IF_NEW I would keep only the FIRST drawing. I need
to keep only the last. How do I achive this?
If I use UTAM_ADD_OR_ADJUST I retain the "correct" drawing for the current candle but loose all
drawing of previous candles, which defies the purpose.

Essentially I would like the drawing to behave like a "color bar based on alert condition"
Any way to delete the previous drawing or "replace" the drawing during candle formation?
Date Time Of Last Edit: 2024-03-08 08:55:51
[2024-03-27 08:35:27]
User138457 - Posts: 36
anyone able to help
[2024-03-27 09:41:08]
User907968 - Posts: 802
1. Use UTAM_ADD_OR_ADJUST
2. Retain the same linenumber (i.e. via persistentint) during bar formation so that you can edit/adjust intrabar
3. Upon new bar set saved linenumber to -1, so new linenumber is generated automatically by usetool
4. Save newly generated linenumber to persistentint and retain during bar formation
5. Rinse and repeat



auto& r_LineNumber = sc.GetPersistentIntFast(0);
auto& r_LastIndex = sc.GetPersistentIntFast(1);

if (sc.Index != r_LastIndex)
{
r_LineNumber = -1;
r_LastIndex = sc.Index;
}

if(condition)
{

s_UseTool Tool;
Tool.Clear(); // Reset tool structure. Good practice but unnecessary in this case.
Tool.ChartNumber = sc.ChartNumber;
Tool.DrawingType = DRAWING_MARKER;
Tool.LineNumber = r_LineNumber;
Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.BeginValue = sc.Low[sc.Index]-Shiftmarker;
Tool.Color = RGB(0,128,0);
Tool.AddMethod = UTAM_ADD_OR_ADJUST;
Tool.MarkerType = MARKER_X; //MARKER_TRIANGLEUP;
Tool.MarkerSize = 4;
Tool.LineWidth = 5;

sc.UseTool(Tool);

r_LineNumber = Tool.LineNumber;

}

[2024-03-27 09:46:16]
User138457 - Posts: 36
thanks, will try that in the evening
[2024-04-09 14:53:59]
User138457 - Posts: 36
thanks a lot, your suggestion did the trick 99,9% of the time. Greatly appreciated!
[2024-04-15 12:39:16]
User138457 - Posts: 36
Last remaining issue:
Sometimes the condition is "true" but changes to "false" almost immediately before bar change, in that case the
MARKER_X remains and is not deleted. Is there any way to circumvent that behavior?

edit: obviously a reload of the chart solve the issue, but there need to be another way, I hope

thanks in advance
Date Time Of Last Edit: 2024-04-15 12:46:12
[2024-04-15 12:58:32]
User431178 - Posts: 412
Delete the drawing if the condition changes from true to false intrabar.

Using Drawing Tools From an Advanced Custom Study: sc.DeleteACSChartDrawing()




if(condition)
{
// code as before
}
else if (r_LineNumber != -1)
{
sc.DeleteACSChartDrawing(sc.ChartNumber, TOOL_DELETE_CHARTDRAWING, r_LineNumber);
r_LineNumber = -1;
}


[2024-04-15 13:32:47]
User138457 - Posts: 36
thanks for the quick help, appears to work like a charm

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

Login

Login Page - Create Account