#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="">Use for the underlying symbol index on which to draw the drawing script.</param> public void OnInitialize(int symbolIndex) { // Initialize the drawing for the symbol to accept 10 anchor points. DrawingInitialize(symbolIndex, 10); } #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() { // Register the pen with which to draw the (Bullish) 9-Wave Triangle Elliott Wave lines. DrawingRegisterPen("Line Pen", new byte[] { 5, 110, 180, 255 }, IQ_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 number of decimals for the symbol. int symbolDecimals = SymbolDecimals(SymbolIndex()); // Get X value of anchor point 0 int x0 = DrawingAnchorPointBarShift(0); // Snap anchor point to lowest y value of bar DrawingSetAnchorPointLow(0, x0); // Get the Y value of anchor point 0 double y0 = DrawingAnchorPointValue(0); // Get X value of anchor point 1 int x1 = DrawingAnchorPointBarShift(1); // Snap anchor point to highest y value of bar DrawingSetAnchorPointHigh(1, x1); // Get the Y value of anchor point 1 double y1 = DrawingAnchorPointValue(1); // Draws the first line DrawingSetLine("Line Pen", x0, y0, "(0)", x1, y1, "(A)\n" + "(" + MathAbs(x0 - x1) + " bars)\n" + MathRound(MathAbs(y0 - y1), symbolDecimals)); // Get X value of anchor point 2 int x2 = DrawingAnchorPointBarShift(2); // Snap anchor point to lowest y value of bar DrawingSetAnchorPointLow(2, x2); // Get the Y value of anchor point 2 double y2 = DrawingAnchorPointValue(2); // Draws the second line if(x2 != x0) DrawingSetLine("Line Pen", x1, y1, "", x2, y2, "(B)\n" + "(" + MathAbs(x1 - x2) + " bars)\n" + MathRound(MathAbs(y1 - y2), symbolDecimals)); // Get X value of anchor point 3 int x3 = DrawingAnchorPointBarShift(3); // Snap anchor point to highest y value of bar DrawingSetAnchorPointHigh(3, x3); // Get the Y value of anchor point 3 double y3 = DrawingAnchorPointValue(3); // Draws the third line if(x3 != x0) DrawingSetLine("Line Pen", x2, y2, "", x3, y3, "(C)\n" + "(" + MathAbs(x2 - x3) + " bars)\n" + MathRound(MathAbs(y2 - y3), symbolDecimals)); // Get X value of anchor point 4 int x4 = DrawingAnchorPointBarShift(4); // Snap anchor point to lowest y value of bar DrawingSetAnchorPointLow(4, x4); // Get the Y value of anchor point 4 double y4 = DrawingAnchorPointValue(4); // Draws the fourth line if(x4 != x0) DrawingSetLine("Line Pen", x3, y3, "", x4, y4, "(D)\n" + "(" + MathAbs(x3 - x4) + " bars)\n" + MathRound(MathAbs(y3 - y4), symbolDecimals)); // Get X value of anchor point 5 int x5 = DrawingAnchorPointBarShift(5); // Snap anchor point to highest y value of bar DrawingSetAnchorPointHigh(5, x5); // Get the Y value of anchor point 5 double y5 = DrawingAnchorPointValue(5); // Draws the fifth line if(x5 != x0) DrawingSetLine("Line Pen", x4, y4, "", x5, y5, "(E)\n" + "(" + MathAbs(x4 - x5) + " bars)\n" + MathRound(MathAbs(y4 - y5), symbolDecimals)); // Get X value of anchor point 6 int x6 = DrawingAnchorPointBarShift(6); // Snap anchor point to lowest y value of bar DrawingSetAnchorPointLow(6, x6); // Get the Y value of anchor point 6 double y6 = DrawingAnchorPointValue(6); // Draws the sixth line if(x6 != x0) DrawingSetLine("Line Pen", x5, y5, "", x6, y6, "(F)\n" + "(" + MathAbs(x5 - x6) + " bars)\n" + MathRound(MathAbs(y5 - y6), symbolDecimals)); // Get X value of anchor point 7 int x7 = DrawingAnchorPointBarShift(7); // Snap anchor point to highest y value of bar DrawingSetAnchorPointHigh(7, x7); // Get the Y value of anchor point 7 double y7 = DrawingAnchorPointValue(7); // Draws the seventh line if(x7 != x0) DrawingSetLine("Line Pen", x6, y6, "", x7, y7, "(G)\n" + "(" + MathAbs(x6 - x7) + " bars)\n" + MathRound(MathAbs(y6 - y7), symbolDecimals)); // Get X value of anchor point 8 int x8 = DrawingAnchorPointBarShift(8); // Snap anchor point to lowest y value of bar DrawingSetAnchorPointLow(8, x8); // Get the Y value of anchor point 8 double y8 = DrawingAnchorPointValue(8); // Draws the eighth line if(x8 != x0) DrawingSetLine("Line Pen", x7, y7, "", x8, y8, "(H)\n" + "(" + MathAbs(x7 - x8) + " bars)\n" + MathRound(MathAbs(y7 - y8), symbolDecimals)); // Get X value of anchor point 9 int x9 = DrawingAnchorPointBarShift(9); // Snap anchor point to highest y value of bar DrawingSetAnchorPointHigh(9, x9); // Get the Y value of anchor point 9 double y9 = DrawingAnchorPointValue(9); // Draws the ninth line if(x9 != x0){ // given the y value of anchor point 0 is greater than the y value of anchor point 9 show this message if(y0 > y9) DrawingSetLine("Line Pen", x8, y8, "", x9, y9, "(I)\n" + "Wave I does not result\nin a net retracement\nof the preceding wave." ); // otherwise execute appropriately else DrawingSetLine("Line Pen", x8, y8, "", x9, y9, "(I)\n" + "(" + MathAbs(x8 - x9) + " bars)\n" + MathRound(MathAbs(y8 - y9), symbolDecimals)); } } #endregion } }

The Algorithmic Trading Software for Hedge Funds and Quants