'#############################################
' Fibonacci Extensions
' Custom drawing tool
' Version 1.0 as of 10/15/2003
' programmed by: Michael Mueller
' contact: www.muellerfinancial.de
' email: michael@muellerfinancial.de
'#############################################
option explicit
function toolname()
toolname="Fibonacci Extension"
end function
function numpoints()
numpoints=3
end function
function usehmult()
usehmult=true
end function
sub add_next_line (c,x1,y1,x2,y2, ByRef list, ByRef i)
list(i)=c
list(i+1)= x1
list(i+2)= y1
list(i+3)= x2
list(i+4)= y2
i=i+5
end sub
sub add_nexttext (c,p1,p2,p3, ByRef list, ByRef i)
list(i)=c
list(i+1)=p1
list(i+2)=p2
list(i+3)=p3
i=i+4
end sub
sub draw2(bounds,xlist,ylist,price,hlist,vlist,flist,clist,ByRef
result)
dim i,j,x1,y1,x2,y2, x3, y3
dim arraysize
dim fiby()
dim fibx
dim ext_val, src_style, src_val
dim textary
dim nolen
dim maxy
dim txtstr
dim xtp()
dim arylen
nolen=6
' in the following lines you can modify the
' look of the fibonacci extension levels
ext_val=1 '1= show extenstion levels as text
' these lines of code set the values for the
' style of the starting points
src_style=1
'1= horizontal lines
'2= vertical lines
'3= horizontal and vertical lines
src_val=1
'1= show source levels as text
'2= show no values
' purging coordinates into array
x1=xlist(0)
x2=xlist(1)
x3=xlist(2)
y1=ylist(0)
y2=ylist(1)
y3=ylist(2)
if x2=0 then x2=x1
if y2=0 then y2=y1
if x3=0 then x3=x2
if y3=0 then y3=y2
if isempty(hlist)=false then
'calculating fibonacci extension levels
if y1<=y2 then maxy=0 else maxy=100000
if isempty(hlist)=true then arylen=0 else arylen=ubound(hlist)-1
for j=0 to arylen
if y1<=y2 then
redim preserve fiby (j+1)
fiby(j)=y3+(y2-y1)*hlist(j) 'upmove
if fiby(j)>maxy then maxy=fiby(j)
redim preserve xtp(j+1)
xtp(j)=price(2)+(price(1)-price(0))*hlist(j)
else
redim preserve fiby(j+1)
fiby(j)=y3-(y1-y2)*hlist(j) 'downmove
if fiby(j)<maxy then maxy=fiby(j)
redim preserve xtp(j+1)
xtp(j)=price(2)-(price(0)-price(1))*hlist(j)
end if
next
'adding drawing commands for source
arraysize=5
textary=4
i=0
if src_style=1 or src_style=3 then 'drawing horizontal lines
redim preserve result(arraysize+ i)
call add_next_line (0,x1,y1,x2,y1, result,i)
redim preserve result(arraysize+ i)
call add_next_line (0,x2,y2,x3,y2, result, i)
redim preserve result(arraysize+ i)
call add_next_line (0,x3,y3,x2,y3,result, i)
end if
If src_style=2 or src_style=3 then 'drawing vertical lines
redim preserve result(arraysize+ i)
call add_next_line (0,x1,y1,x2,y2, result,i)
redim preserve result(arraysize+ i)
call add_next_line (0,x2,y2,x3,y3, result,i)
end if
if src_val=1 then 'show source price figures
redim preserve result(textary+i)
call add_nexttext (22,x1,y1,left(price(0),nolen), result, i)
redim preserve result(textary+i)
call add_nexttext (22,x2,y2,left(price(1),nolen), result, i)
redim preserve result(textary+i)
call add_nexttext (23,x3,y3,left(price(2),nolen), result, i)
end if
'drawing commands for extensions
for j=0 to ubound(fiby)-1
redim preserve result(arraysize+i)
call add_next_line (2,x3,fiby(j),x3+x3-x1,fiby(j),result,i)
if ext_val=1 then
redim preserve result(textary+i)
txtstr= left(xtp(j),nolen) & " (" & left(hlist(j)*100,nolen) & "%)"
call add_nexttext (22,x3,fiby(j),txtstr,result,i)
end if
next
if src_style>1 then
redim preserve result (arraysize+i)
call add_next_line(0,x3,y3,x3+x3-x1,maxy,result,i)
end if
end if
end sub