Summary:
This drawing script creates vertical lines which are drawn between two extreme points at Fibonacci levels of 0.0, 23.6, 38.2, 50, 61.8, 76.4, 100 percent and several extensions

                    
#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 2 anchor points. DrawingInitialize(symbolIndex, 2); } #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 0.0 line. DrawingRegisterPen("0.0", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 23.6 line. DrawingRegisterPen("23.6", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 38.2 line. DrawingRegisterPen("38.2", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 50.0 line. DrawingRegisterPen("50.0", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 61.8 line. DrawingRegisterPen("61.8", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 76.4 line. DrawingRegisterPen("76.4", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 100.0 line. DrawingRegisterPen("100.0", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 161.8 line. DrawingRegisterPen("161.8", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 261.8 line. DrawingRegisterPen("261.8", new byte[] { 5, 110, 180, 255 }, AT_DashStyle.SOLID, 2); // Register the pen with which to draw the 423.6 line. DrawingRegisterPen("423.6", 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 value of anchor point 0. int x1 = DrawingAnchorPointBarShift(0); // Get the Y value of anchor point 0. double y1 = DrawingAnchorPointValue(0); // Get the X value of anchor point 1. int x2 = DrawingAnchorPointBarShift(1); // Get the Y value of anchor point 1. double y2 = DrawingAnchorPointValue(1); // Check whether y1 is larger than y2. if (y1 > y2) { double tempY = y1; y1 = y2; y2 = tempY; } // Check whether x1 is larger than x2. if (x1 > x2) { int tempX = x1; x1 = x2; x2 = tempX; } // Calculate the bar distance between the two points. int barDistance = Math.Abs(x2 - x1); // Draw the Fibonacci Time Extension lines. DrawingSetLine("0.0", x2, y1, "0.0", x2, y2, "0.0"); DrawingSetLine("23.6", (int)(x2 - 236d / 1000 * barDistance), y1, "23.6", (int)(x2 - 236d / 1000 * barDistance), y2, "23.6"); DrawingSetLine("38.2", (int)(x2 - 382d / 1000 * barDistance), y1, "38.2", (int)(x2 - 382d / 1000 * barDistance), y2, "38.2"); DrawingSetLine("50.0", (int)(x2 - 500d / 1000 * barDistance), y1, "50.0", (int)(x2 - 500d / 1000 * barDistance), y2, "50.0"); DrawingSetLine("61.8", (int)(x2 - 618d / 1000 * barDistance), y1, "61.8", (int)(x2 - 618d / 1000 * barDistance), y2, "61.8"); DrawingSetLine("76.4", (int)(x2 - 764d / 1000 * barDistance), y1, "76.4", (int)(x2 - 764d / 1000 * barDistance), y2, "76.4"); DrawingSetLine("100.0", x1, y1, "", x1, y2, "100.0"); DrawingSetLine("161.8", (int)(x2 - 1618d / 1000 * barDistance), y1, "161.8", (int)(x2 - 1618d / 1000 * barDistance), y2, "161.8"); DrawingSetLine("261.8", (int)(x2 - 2618d / 1000 * barDistance), y1, "261.8", (int)(x2 - 2618d / 1000 * barDistance), y2, "261.8"); DrawingSetLine("423.6", (int)(x2 - 4236d / 1000 * barDistance), y1, "423.6", (int)(x2 - 4236d / 1000 * barDistance), y2, "423.6"); } #endregion } }

The Algorithmic Trading Software for Hedge Funds and Quants