Thursday, September 09, 2010

Andrews Pitchfork [AP]

Descripton
Summary:
Draws a rectangle.


Variables
TypeIdentifierDescription
Number_distance

DrawLine
Function Parameters
TypeIdentifierDescription
Integerx1
Numbery1
Integerx2
Numbery2
Integerindex
Implementation
	 ' Make sure that x1 is the larger of the two core 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 core points don 't share a common X position then calculate all other points.
	If (x1 <> x2) Then
		 ' Draw all points in between the two core 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 - 1)
			End If
			index += 1
		Next
	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 centerX As Integer = DrawingCorePointBarIndex(0)
	 ' Get the Y position of core point 0.
	Define centerY As Number = DrawingCorePointValue(0)
	 ' Get the X position of core point 1.
	Define lengthX As Integer = DrawingCorePointBarIndex(1)
	 ' Get the Y position of core point 1.
	Define lengthY As Number = DrawingCorePointValue(1)
	 ' Get the X position of core point 2.
	Define upperX As Integer = DrawingCorePointBarIndex(2)
	 ' Get the Y position of core point 2.
	Define upperY As Number = DrawingCorePointValue(2)
	 ' Get the X position of core point 3.
	Define lowerX As Integer = DrawingCorePointBarIndex(3)
	 ' Get the Y position of core point 3.
	Define lowerY As Number = DrawingCorePointValue(3)
	 ' Use for the distance between the lines.
	Define distanceUpper, distanceLower As Number 
	
	If (centerX <> lengthX) Then
		Define m As Number = (centerY - lengthY) / (centerX - lengthX)
		distanceUpper = MathAbs(centerY + (upperX - centerX) * m - upperY)
		distanceLower = MathAbs(centerY + (lowerX - centerX) * m - lowerY)
		If (_distance <> distanceUpper And _distance <> distanceLower) Then
			_distance = distanceUpper
		End If
		If (_distance = distanceUpper And _distance <> distanceLower) Then
			_distance = distanceLower
			upperY  = centerY + (upperX - centerX) * m + _distance
			DrawingSetCorePoint(2, upperX, upperY)
		Else If (_distance = distanceLower And _distance <> distanceUpper) Then
			_distance = distanceUpper
			lowerY = centerY + (lowerX - centerX) * m - _distance
			DrawingSetCorePoint(3, lowerX, lowerY)
		End If
		Define index As Number = 0
		index = DrawLine(centerX,centerY,lengthX,lengthY, index)
		index = DrawLine(lowerX,lowerY,lengthX,lengthY - _distance, index)
		index = DrawLine(upperX,upperY,lengthX,lengthY + _distance, index)
	End If	

OnInitialize
Function Parameters
TypeIdentifierDescription
SymbolsymbolIndexUse for the underlying symbol index on which to draw the Andrews Pitchfork.
Implementation
	DrawingInitialize(symbolIndex, 4)

Copyright © 2010 IQBroker, LLC. All rights reserved.