Tuesday, September 07, 2010

Equidistant Channel [EQC]

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


Variables
TypeIdentifierDescription
Number_distanceUse for the distance between the parallel lines.

DrawLine
Function Parameters
TypeIdentifierDescription
Integerx1
Numbery1
Integerx2
Numbery2
Integerindex
Implementation
	 ' Make sure that x1 is the smaller of the two points.
	If (x1 > x2) Then
		Define tempX As Integer = x1
		x1 = x2
		x2 = tempX
		Define tempY As Number = y1
		y1 = y2
		y2 = tempY
	End If
	 ' Calculate the slope.
	Define m As Number = (y2 - y1) / (x2 - x1)
	Define y As Number
	 ' If the two points don 't share a common X value then calculate all other points.
	If (x1 <> x2) Then
		Define firstIndex As Integer = index
		 ' Draw all points in between the two points.
		For x As Integer = x1 To x2 Step 1
			y = y1 + (x - x1) * m
			If (x = x1)
				DrawingSetPoint(index, x, y, "", index)
			Else 
				DrawingSetPoint(index, x, y, "", index)
			End If
			index += 1
		Next
		DrawingSetPoint(firstIndex, x1, y1, "", index - 1)
	Else
		DrawingSetPoint(index ,x1, y1, "", index)
		index += 1
		DrawingSetPoint(index, x2, y2, "", index - 1)
		index += 1
	End If
	Return index

OnDraw
Function Parameters
TypeIdentifierDescription
Implementation
	 ' Get the X position of core point 0.
	Define line1X As Integer = DrawingCorePointBarIndex(0)
	 ' Get the Y position of core point 0.
	Define line1Y As Number = DrawingCorePointValue(0)
	 ' Get the X position of core point 1.
	Define line2X As Integer = DrawingCorePointBarIndex(1)
	 ' Get the Y position of core point 1.
	Define line2Y As Number = DrawingCorePointValue(1)
	
	Define index As Integer = 0
	 ' Draw the top line.
	index = DrawLine(line1X, line1Y, line2X, line2Y, index)
	 ' Draw the parallel line.
	index = DrawLine(line1X, line1Y + _distance, line2X, line2Y + _distance, index)

OnInitialize
Function Parameters
TypeIdentifierDescription
SymbolsymbolIndexUse for the underlying symbol index on which to draw the Equidistant Channel.
NumberdistanceUse for the distance between the parallel lines. [Default 1]
Implementation
	 ' Initialize the Equidistant Channel.
	DrawingInitialize(symbolIndex, 2)
	_distance = distance

Copyright © 2010 IQBroker, LLC. All rights reserved.