Summary:
This drawing script draws two parallel trend lines, forming the channel in the trend direction and connecting extreme maximum and minimum prices

                    
#region Namespaces using System; #endregion namespace ScriptCode { /// <summary> /// Drawing scripts are used for drawing a visual object. /// /// This script can be used in several ways: /// (1) It can be used on a chart by clicking the chart in order to set the drawing's anchor points. /// (2) It can be used from another script by having that script set the drawing's anchor points. /// </summary> public partial class MyDrawing : DrawingScriptBase // NEVER CHANGE THE CLASS NAME { #region Variables #endregion #region OnInitialize /// <summary> /// This function is called when a new drawing instance is created. /// </summary> /// -------------------------------------------------------------------------------------------------- /// THIS FUNCTION MUST ACCEPT THE SYMBOL INDEX PARAMETER AND SHOULD NOT ACCEPT ANY OTHER PARAMETERS. /// -------------------------------------------------------------------------------------------------- /// <param name="symbolIndex" type="Symbol" default="">The underlying symbol index for the drawing.</param> public void OnInitialize( int symbolIndex) { // Initialize the drawing for the symbol to accept 3 anchor points. DrawingInitialize(symbolIndex, 3); } #endregion #region OnChartSetup /// <summary> /// This function is used for setting up the drawing on the chart and registering its pens (see the DrawingRegisterPen function). /// </summary> public override void OnChartSetup() { DrawingRegisterPen("Line Pen", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); } #endregion #region OnDraw /// <summary> /// This function is used to draw the drawing by setting all of its anchor points, lines and labels on a virtual canvas. /// The canvas x-axis values are the date and time of the underlying symbol bars and its y-axis values are the symbol prices. /// /// The location of the drawing on the canvas is specified by the drawing anchor points, which can either be specified by /// clicking on a chart or from another script (see the Drawing functions). /// </summary> public override void OnDraw() { // Get the X position of anchor point 0. int line1X = DrawingAnchorPointBarShift(0); // Get the Y position of anchor point 0. double line1Y = DrawingAnchorPointValue(0); // Get the X position of anchor point 1. int line2X = DrawingAnchorPointBarShift(1); // Get the Y position of anchor point 1. double line2Y = DrawingAnchorPointValue(1); // Get the X position of anchor point 2. int line3X = DrawingAnchorPointBarShift(2); // Get the Y position of anchor point 2. double line3Y = DrawingAnchorPointValue(2); // Update the anchor point so that it is on the drawing. DrawingSetAnchorPoint(2, line1X, line1Y + (line3Y - line1Y)); // Draw the first line. DrawingSetLine("Line Pen", line1X, line1Y, "", line2X, line2Y, ""); // Draw the parallel line. DrawingSetLine("Line Pen", line1X, line1Y + (line3Y - line1Y), "", line2X, line2Y + (line3Y - line1Y), ""); } #endregion } }

The Algorithmic Trading Software for Hedge Funds and Quants