#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);
// Set the icon for the drawing tool.
DrawingSetIcon("Fibonacci Fan");
}
#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 int[] {
150, 150, 150, 255
}, C_DashStyle.SOLID, 2);
// Register the pen with which to draw the 23.6 line.
DrawingRegisterPen("23.6", new int[] {
35, 145, 255, 255
}, C_DashStyle.SOLID, 2);
// Register the pen with which to draw the 38.2 line.
DrawingRegisterPen("38.2", new int[] {
100, 150, 235, 255
}, C_DashStyle.SOLID, 2);
// Register the pen with which to draw the 50.0 line.
DrawingRegisterPen("50.0", new int[] {
75, 135, 185, 255
}, C_DashStyle.SOLID, 2);
// Register the pen with which to draw the 61.8 line.
DrawingRegisterPen("61.8", new int[] {
10, 140, 145, 255
}, C_DashStyle.SOLID, 2);
// Register the pen with which to draw the 76.4 line.
DrawingRegisterPen("76.4", new int[] {
50, 140, 90, 255
}, C_DashStyle.SOLID, 2);
// Register the pen with which to draw the 100.0 line.
DrawingRegisterPen("100.0", new int[] {
150, 150, 150, 255
}, C_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);
// Draw the top line.
DrawingSetLine("0.0", line1X, line1Y, "", line2X, line2Y, "0.0");
// Draw the 23.6 line.
DrawingSetLine("23.6", line1X, line1Y, "", line2X, line2Y + 236d / 1000 * Math.Abs(line2Y - line1Y), "23.6");
// Draw the 38.2 line.
DrawingSetLine("38.2", line1X, line1Y, "", line2X, line2Y + 382d / 1000 * Math.Abs(line2Y - line1Y), "38.2");
// Draw the 50.0 line.
DrawingSetLine("50.0", line1X, line1Y, "", line2X, line2Y + 500d / 1000 * Math.Abs(line2Y - line1Y), "50.0");
// Draw the 61.8 line.
DrawingSetLine("61.8", line1X, line1Y, "", line2X, line2Y + 618d / 1000 * Math.Abs(line2Y - line1Y), "61.8");
// Draw the 76.4 line.
DrawingSetLine("76.4", line1X, line1Y, "", line2X, line2Y + 764d / 1000 * Math.Abs(line2Y - line1Y), "76.4");
// Draw the 100.0 line.
DrawingSetLine("100.0", line1X, line1Y, "", line2X, line2Y + Math.Abs(line2Y - line1Y), "100.0");
}
#endregion
}
}