Login Page - Create Account

Support Board


Date/Time: Sun, 12 Jan 2025 11:39:53 +0000



What is proper way to modify tool drawings of type DRAWING_LINE?

View Count: 1451

[2017-02-01 20:37:52]
Edge Player Trading - Posts: 9
The following code for a study (sc.AutoLoop = 1) draws a rectangle and two vertical lines on the right side of the rectangle during processing of a single bar (although the chart type is P&F so not sure whether single bar applies). The vertical lines have text associated with them and the text appears at the top of the upward vertical line and the bottom of the downward vertical line.

On subsequent bars, the code may modify these drawings by extending the rectangle and moving the vertical lines to the right. The problem I am running into is that the text of the modified downward vertical line is showing up at the top of the line rather than at the bottom of the line as was the case when it was first drawn. Also, unless the code re-adds the text associated with both lines the modified versions will not display the text associated with the original line. Any guidance on how to correct these issues will be greatly appreciated.

//If new congestion pattern found, draw rectangle around congestion and
//print both upside and downside targets
if (CongestionFound && NewRectangle)
{
Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index - CongestionPatternHurdle];
Tool.EndDateTime = sc.BaseDateTimeIn[sc.Index];


Tool.BeginValue = sc.BaseData[SC_POINT_FIGURE_LOW][sc.Index - CongestionPatternHurdle];

Tool.EndValue = sc.BaseData[SC_POINT_FIGURE_HIGH][sc.Index];

Tool.Color = TargetsLineColor;
Tool.LineStyle = TargetsLineStyle;
Tool.LineWidth = TargetsLineWidth;

//Draw rectangle
sc.UseTool(Tool);
        
//Save info in case rectangle/congestion pattern has to be extended
NewRectangle = false;
LastLineNum = Tool.LineNumber;
RectangleHighLimit = Tool.EndValue + (1 * PFBoxSize);
RectangleLowLimit = Tool.BeginValue - (1 * PFBoxSize);

//Save target info for use below
UpSideTarget = Tool.BeginValue + (CongestionPatternHurdle * PFBoxSize);
DnSideTarget = Tool.EndValue - (CongestionPatternHurdle * PFBoxSize);

//setup to draw vertical line to upside target
Tool.LineNumber = -1;
Tool.DrawingType = DRAWING_LINE;

Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.EndDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.BeginValue = sc.BaseData[SC_POINT_FIGURE_HIGH][sc.Index];
Tool.EndValue = UpSideTarget;
Buffer.Format("%.2f", UpSideTarget);
Tool.Text = Buffer;

//Draw upside target vertical line at right side of rectangle
sc.UseTool(Tool);

//Save the line number in case this vertical line needs to be move because of
//rectangle expansion
UpSideTargetLineNum = Tool.LineNumber;

//setup to draw vertical line to downside target
Tool.LineNumber = -1;
Tool.DrawingType = DRAWING_LINE;

Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.EndDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.BeginValue = sc.BaseData[SC_POINT_FIGURE_LOW][sc.Index];
Tool.EndValue = DnSideTarget;
Buffer.Format("%.2f", DnSideTarget);
Tool.Text = Buffer;

//Draw downside target vertical line at right side of rectangel
sc.UseTool(Tool);

//Save the line number in case this vertical line needs to be move because of
//rectangle expansion
DnSideTargetLineNum = Tool.LineNumber;

}
else if (CongestionFound && !NewRectangle) //if congestion pattern expands, expand the enclosing rectangle
{
// Expand rectangle enclosing congestion
Tool.LineNumber = LastLineNum;
Tool.EndDateTime = sc.BaseDateTimeIn[sc.Index];
sc.UseTool(Tool);

//Move vertical line to upside target
Tool.LineNumber = UpSideTargetLineNum;
Tool.AddMethod = UTAM_ADD_OR_ADJUST;
Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.EndDateTime = sc.BaseDateTimeIn[sc.Index];
// for some reason Tool does not remember text
Buffer.Format("%.2f", UpSideTarget);
Tool.Text = Buffer;
sc.UseTool(Tool);
        

//Move vertical line to downside target
Tool.LineNumber = DnSideTargetLineNum;
Tool.AddMethod = UTAM_ADD_OR_ADJUST;
Tool.BeginDateTime = sc.BaseDateTimeIn[sc.Index];
Tool.EndDateTime = sc.BaseDateTimeIn[sc.Index];
// for some reason Tool does not remember text from original drawing
// and in case of downside targets moves the text to the beginning of the line
// rather than to the end of the line where it should be.
Buffer.Format("%.2f", DnSideTarget);
Tool.Text = Buffer;

sc.UseTool(Tool);
        
}

Here is a link to a chart showing the problem:
http://www.sierrachart.com/image.php?Image=1485980821353.png

The rectangle and verticals on the left are un-modified. The two rectangles and verticals on the right have been modified.
[2017-02-02 17:29:08]
Sierra Chart Engineering - Posts: 104368
We will be looking this over. Just give us a couple of days.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2017-02-05 02:40:42]
Sierra Chart Engineering - Posts: 104368
(although the chart type is P&F so not sure whether single bar applies).
Yes.

For every use of sc.UseTool, make a call to Tool.Clear() and set all of the members of the Tool structure that will be used. This makes the code easy to understand. Otherwise it is too difficult.

This is the very first step before we proceed. So modify the code above and let us know when that is done.

The problem I am running into is that the text of the modified downward vertical line is showing up at the top of the line rather than at the bottom of the line as was the case when it was first drawn. Also, unless the code re-adds the text associated with both lines the modified versions will not display the text associated with the original line. Any guidance on how to correct these issues will be greatly appreciated.
We need to look into this.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2017-02-14 05:23:25]
Sierra Chart Engineering - Posts: 104368
. Also, unless the code re-adds the text associated with both lines the modified versions will not display the text associated with the original line. . Also, unless the code re-adds the text associated with both lines the modified versions will not display the text associated with the original line.
This will be fixed in 1519 which we will release in an hour.

In regards to this:
The problem I am running into is that the text of the modified downward vertical line is showing up at the top of the line rather than at the bottom of the line as was the case when it was first drawn.

The text is always going to be at the end anchor point of the Line drawing. Do you need to display it at the beginning point? In any case, make sure you are setting the value and Date-Time coordinates of the end anchor point as intended.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2017-02-14 05:36:13]
Sierra Chart Engineering - Posts: 104368
Here is the code example we used for testing:



/*==========================================================================*/
SCSFExport scsf_UseToolExampleLine(SCStudyInterfaceRef sc)
{
  // Set configuration variables
  if (sc.SetDefaults)
  {
    sc.GraphName = "UseTool Example: Line";
    sc.GraphRegion = 0;
    sc.FreeDLL = 0;
    sc.AutoLoop = 0; //No automatic looping

    return;
  }

  
  int &LineNumber = sc.GetPersistentInt(1);
  if (sc.IsFullRecalculation)
  {
    //Draw vertical line on prior bar during full recalculation.
    s_UseTool Tool;
    Tool.Clear();
    Tool.ChartNumber = sc.ChartNumber;
    //Tool.LineNumber will be automatically set. No need to set this.
    Tool.DrawingType = DRAWING_LINE;
    int DrawingIndex = sc.ArraySize - 4;
    Tool.BeginDateTime = sc.BaseDateTimeIn[DrawingIndex];
    Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex];
    Tool.BeginValue = sc.Low[DrawingIndex];
    Tool.EndValue = sc.High[DrawingIndex];
    Tool.Text = "Label 1";
    Tool.TextAlignment = DT_BOTTOM | DT_LEFT;
    Tool.Region = 0;
    Tool.Color = RGB(255, 255, 0);
    Tool.LineWidth = 5;
    Tool.AddMethod = UTAM_ADD_ALWAYS;

    sc.UseTool(Tool);
    LineNumber = Tool.LineNumber;
  }
  else if (sc.UpdateStartIndex < sc.ArraySize -1)
  {
    //Now move the drawing to the last bar when a new bar has been added to the chart
    s_UseTool Tool;
    Tool.Clear();
    Tool.ChartNumber = sc.ChartNumber;
    //Tool.LineNumber will be automatically set. No need to set this.
    int DrawingIndex = sc.ArraySize - 1;
    Tool.BeginDateTime = sc.BaseDateTimeIn[DrawingIndex];
    Tool.EndDateTime = sc.BaseDateTimeIn[DrawingIndex];
    Tool.BeginValue = sc.Low[DrawingIndex];
    Tool.EndValue = sc.High[DrawingIndex];
    Tool.AddMethod = UTAM_ADD_OR_ADJUST;
    Tool.LineNumber = LineNumber;
    sc.UseTool(Tool);
    
  }
}


Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-02-14 05:37:54

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

Login

Login Page - Create Account