NinjaScript > Language Reference > Drawing >

DrawObjects

Print this Topic Previous pageReturn to chapter overviewNext page

Definition
A collection holding all of the draw objects on the chart for the primary bar series. The draw objects can be manually drawn or script generated objects.

 

Property Value

A collection of IDrawObject objects.

 

Syntax

DrawObjects

DrawObjects[string tag]

DrawObjects.Count

 

 

Examples

// Example #1: Finding the draw object of a specific tag

protected override void OnBarUpdate()

{

    if (DrawObjects["someTag"] != null && DrawObjects["someTag"].DrawType == DrawType.Line)

    {

         // Do something

    }

}

 

// Example #2: Number of draw objects on a chart

protected override void OnBarUpdate()

{

    if (DrawObjects.Count == 3)

    {

         // Do something

    }

}

 

// Example #3: Looping through the collection to find specific draw objects

protected override void OnBarUpdate()

{

 // Loops through the DrawObjects collection

 foreach (IDrawObject draw in DrawObjects)

 {

         // Finds line objects that are attached globally to all charts of the same instrument

         if (draw.Tag.StartsWith("@") && draw is ILine)

         {

                 ILine globalLine = (ILine) draw;

 

                 // Changes the line color and prints its starting and end points

                 globalLine.Pen.Color = Color.Black;

                 Print("Start: " + globalLine.StartBarsAgo + " End: " + globalLine.EndBarsAgo);

         }

 

         // Finds non-global line objects

         else if (draw is ILine)

         {

                 ILine drawnLine = (ILine) draw;

 

                 // Determines if this is a manually drawn or script generated line

                 Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn);

         }

 }

}