+1 888 340 6572

# Miscellaneous > LogSpiralv3

File Includes: Indicator - LogSpiralv3

Category: Indicators > Miscellaneous

Description:

This version uses trendlines instead of plots to draw the spiral.

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".

NOTES: 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@home.com.

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.
08/15/99 v3.0 - Use trendlines instead of plots, fix initial R bug.

Usage:

Inputs:

Center - use the Text Tool to specify the center...
First - ...and the first point on the spiral
Color - of the spiral
Spirals - number of rotations
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".

EasyLanguage Code:
```INPUT:CENTER("A"), FIRST("B"), COLOR(DARKCYAN), 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(TRUE);
VAR: FAC(0),HAN(0);
VAR: XX(0), YY(0);
VAR: DRAWBAR(0);

{ 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 = CENTER THEN BEGIN
DATE1 = TEXT_GETDATE(HANDL);
TIME1 = TEXT_GETTIME(HANDL);
PRICE1 = TEXT_GETVALUE(HANDL);
END;
IF SS = FIRST 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;

VAR: CHANDL(-1);
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 }
CHANDL = TEXT_NEW(DATE,TIME,PRICE1,"SPIRAL REQUIRES MORE BARS TO DRAW CORRECTLY ");
TEXT_SETSTYLE(CHANDL,1,1);
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 }

{ 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);

R = INTPORTION(R0*EXPVALUE(CON*SPIRALS*2*PI));
DRAWBAR = X1+R+1;
END;

{IF DATE = LASTCALCDATE AND TIME = LASTCALCTIME THEN}
{IF FALSE THEN }
IF CURRENTBAR = DRAWBAR OR (DATE = LASTCALCDATE AND TIME = LASTCALCTIME) THEN
IF OK2DRAW 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);
}

VAR: BB(0), XX1(0), CNT(0), YY1(0), BB1(0);
BB1 = CURRENTBAR - X1;
YY1 = PRICE1/FAC;
FOR II = 0 TO 360*SPIRALS BEGIN
AA = II/VALUE1;
R = R0*EXPVALUE(CON*AA);
XX = INTPORTION(R * COSINE(II+A0)) + X1;
YY = R * SINE(II+A0)+PRICE1;

{ NOW PLOT THE POINT }
YY = YY /FAC;
BB = CURRENTBAR - XX;
IF BB1 <> BB THEN IF BB >= 0 AND CURRENTBAR >= XX THEN BEGIN
IF BB1 > 0 THEN IF ABSVALUE(YY1-YY) < R/FAC THEN BEGIN
HAN = TL_NEW(DATE[BB1],TIME[BB1],YY1,DATE[BB],TIME[BB],YY);
TL_SETCOLOR(HAN, COLOR);
TL_SETSIZE(HAN, 0);
TL_SETEXTRIGHT(HAN,FALSE);
TL_SETEXTLEFT(HAN,FALSE);
END;
XX1 = XX;
BB1 = BB;
YY1 = YY;
END;
END;
IF CHANDL <> -1 THEN TEXT_DELETE(CHANDL);
OK2DRAW = FALSE;
END;```