[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ela for Log Spirals



PureBytes Links

Trading Reference Links

Attentaion all spiral mavens,

I've attached a new version of the logarithmic spirals ela I distributed
a couple of years ago. This one makes prettier spirals. 

/Greg Wood

{******************************************************}
{ Logarithmic Spiral }

{ NOTES

The user identifies the center of the spiral as point "A" 
using the text tool, and identifies the first point of the 
spiral as point "B". 


INPUTS

Spirals - number of spirals
Compress - alters the "box size": the calculation assumes one 
   point vertically for each bar. Using 10 for S+P and 100
   for bonds makes the plot look more "spiral-like".


When selecting points with the text tool, be sure to use upper case. 
Placement of "A" and "B" is also important: if the letter is above 
the bar, the bar's High will be used; if the letter is below the bar, 
the bar's Low will be used. 

This code was written by 
   Gregory Wood, 
   SwissFranc@xxxxxxxxx 

It is "quick and dirty" with lots of room for improvement. 
I am not supporting it. 

You may freely re-distribute this code so long as this 
comment block goes with it.

Revision History
08/14/99 v2.0 - Fixed logic to permit more spirals to show.
}

input:Compress(10), Spirals(2);
var: date1(0),time1(0),price1(0),date2(0),time2(0),price2(0);
var: PI(3.14159), CON(.0765838);
var: dx(0), dy(0), x1(0), x2(0), a0(0), r0(0);
var: y(0), ta(0), r(0), aa(0), aa1(0), aa2(0), ab1(0), ab2(0);
var: ii(0), px(0), px2(0), py(0), py2(0),yc1(0), yc2(0);
var: handl(0),ss(""),mid(0),ok2draw(false);


{ Locate the center A, and the first point B on spiral }

if currentbar = 1 then begin 
   handl = text_getfirst(2);
   while handl >= 0 begin
      ss = text_getstring(handl);
      if ss = "A" then begin 
         date1 = text_getdate(handl);
         time1 = text_gettime(handl);
         price1 = text_getvalue(handl);
      end;
      if ss = "B" then begin 
         date2 = text_getdate(handl);
         time2 = text_gettime(handl);
         price2 = text_getvalue(handl);
      end;
      handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if
this is missing!  }
   end;
end;

if date = date1 and time = time1 then begin 
   if absvalue(h-price1) < absvalue(l-price1) then price1 = h else
price1 = l;
   x1 = currentbar; 
   plot1(price1,""); { verify which point we selected }
end;
if date = date2 and time = time2 then begin 
   if absvalue(h-price2) < absvalue(l-price2) then price2 = h else
price2 = l;
   x2 = currentbar; 
   plot1(price2,""); { verify which point we selected }
end;


var: fac(0),han(0);
var: xx(0), yy(0);
if date = lastcalcdate and time = lastcalctime then
if price1 > 0 and price2 > 0 then begin { we have "A" and "B" }
   han =
tl_new(date[currentbar-x1],time[currentbar-x1],price1,date[currentbar-x2],time[currentbar-x2],price2);
   tl_setcolor(han,tool_darkgray);
   tl_setextright(han,false);
   tl_setextleft(han,false);

   { some calculations }
   fac = compress;
   price1=price1*fac;
   price2=price2*fac;
   dx = x2-x1; 
   dy = price2-price1;
   r0 = SquareRoot(dx*dx + dy*dy);
   if dx <> 0 then 
      a0 = Arctangent(dy/dx);
   value1 = 360/(2*PI);

array: imax[5](0), imin[5](0);
var: jj(0), bb(0), xx1(0), cnt(0);
   for ii = a0 to 360*Spirals+a0 begin
      xx1 = xx;
      aa = ii/value1;
      r = r0*ExpValue(CON*aa);
      xx = intportion(r * cosine(value1*aa) + x1);
      yy = r * sine(value1*aa)+price1;

      { now plot the point }
      yy = yy /fac;
      bb = currentbar - xx;
      if xx1 <> xx then if bb > 0 and currentbar > xx then begin
         if xx > xx1 then begin { building to the right }
            if cnt = 0 then begin
	           cnt = 1; 
               for jj = 1 to 5 begin imin[jj] = xx; imax[jj] = xx; end;
            end;
            if cnt = 1 then begin
	           if xx < imin[1] or xx > imax[1] then plot1[bb](yy,"");
imax[5] = xx;
            end;
            if cnt = 2 then begin
	           imin[2] = imin[5]; imax[2] = imax[5]; cnt = 3; imax[5] = xx;
imin[5] = xx;
            end;
            if cnt = 3 then begin
	           if xx < imin[3] or xx > imax[3] then plot3[bb](yy,"");
imax[5] = xx;
            end;
            if cnt = 4 then begin
	           imin[4] = imin[5]; imax[4] = imax[5]; cnt = 1; imax[5] = xx;
imin[5] = xx;
	           if xx < imin[1] or xx > imax[1] then plot1[bb](yy,"");
imax[5] = xx;
            end;
         end else begin
            if cnt = 1 then begin
	           imin[1] = imin[5]; imax[1] = imax[5]; cnt = 2; imax[5] = xx;
imin[5] = xx;
            end;
            if cnt = 2 then begin
	           if xx < imin[2] or xx > imax[2] then plot2[bb](yy,"");
imin[5] = xx;
            end;
            if cnt = 3 then begin
	           imin[3] = imin[5]; imax[3] = imax[5]; cnt = 4; imax[5] = xx;
imin[5] = xx;
            end;
            if cnt = 4 then begin
	           if xx < imin[4] or xx > imax[4] then plot4[bb](yy,"");
imin[5] = xx;
            end;
         end;
      end;
   end;
end;
Attachment Converted: "c:\eudora\attach\LOGSPIRAL.ELA"