Skip to content

Quick-tips 11 | Using the persist property with drawing objects

In Quicktips 11 I discuss a program sent to me by a Gold Pass member. In the program a text label is created with a click event that draws two horizontal lines. After a few seconds the horizontal lines disappear. The quick tips explains how this behavior can be controlled using the persist property of the horizontal line object.

Video

Quick-tips 11 program

using elsystem.drawingobjects;

vars: HorizontalLine myHighLine( null ),
HorizontalLine myLowLine( null ),
HorizontalLine myCloseLine( null ),
TextLabel TextLabel1( NULL );

method override void InitializeComponent( )
begin
ClearPrintLog;

// Create a text label object
TextLabel1 = new TextLabel;

TextLabel1.TextString = "Draw a Line";
TextLabel1.SetPointValue( new XYPoint( 200, 50 ) );
TextLabel1.HStyle = HorizontalStyle.Center;
TextLabel1.VStyle = VerticalStyle.Center;
TextLabel1.Font = elsystem.drawing.Font.Create( "Microsoft Sans Serif", 25, 0 );
TextLabel1.Persist = false;
TextLabel1.AutoShow = true;
TextLabel1.Name = "TextLabel1";

// Add the taext label to the chart
DrawingObjects.Add( TextLabel1 );
Print( D, T, " Text object added " );

// Set up a click event for the text label
TextLabel1.click += textclicked;
end;

// Method run when the text label is clicked
method void TextClicked( elsystem.Object sender, DrawingObjectEventArgs args )
begin
print( D, T, " Text clicked");

// Create horizontal lines
myHighLine = HorizontalLine.Create( Highest( High, 5 ) );
myHighLine.Color = elsystem.drawing.Color.white;
myHighLine.Weight = Weight.weight5;
myHighLine.Persist = TRUE;
myLowLine = HorizontalLine.Create( Lowest( Low, 5 ) );
myLowLine.Persist = TRUE;

// Add horizontal lines to the chart
DrawingObjects.Add( myHighLine );
DrawingObjects.Add( myLowLine );
End;

// Add a line once
{Once
Begin
//Line at specific level
myCloseLine = HorizontalLine.Create( 1.30445 );
myCloseLine.Color = elsystem.drawing.Color.Magenta;
myCloseLine.Weight = Weight.weight5;

DrawingObjects.Add( myCloseLine );
Print( D, T, " Close line added MaxBarsBack ", MaxBarsBack );
End;}

// Add lines on the last bar of the chart
If LastBarOnChartEx then
Begin
//Line at specific level
myCloseLine = HorizontalLine.Create( C );
myCloseLine.Color = elsystem.drawing.Color.Green;
myCloseLine.Weight = Weight.weight5;
myCloseLine.Persist = FALSE;

DrawingObjects.Add( myCloseLine );
End;