PureBytes Links
Trading Reference Links
|
The following may be a version using arrays.
I have not really checked this out so treat with care.
Clyde
= = = = = = = = = = = = = = = = = = = = = = =
{ Barry Silberman's version of Alexander Elder's "SafeZone Stop" from book
"Come Into My Trading Room" page 173}
inputs: Price((H+L)/2 ),
NDays(15),
Length( 22),
MULTIPLELONG(1),
MULTIPLESHORT(1);
vars: MA(0), LONGSUM(0), SHORTSUM(0) ,
COUNTLONG(0), COUNTSHORT(0), AVGLOW(0),
AVGHIGH(0), LONGSTOP(0), SHORTSTOP(0),
LSTOP(0), SSTOP(0),J(0);
Vars: UseDays(Iff(NDays<150,NDays,15)), IsUP(False), IsDN(False);
Arrays: LDAY[150](0), SDAY[150](0);
{determine trend by slope of EMA}
MA = xaverage( Price, Length );
IsUP = MA > MA[3];
IsDN = MA < MA[3];
{SafeZone for Longs}
IF IsUP THEN BEGIN
For J = 0 to 14 begin
LDAY[J+1] = IFF(L[J+1]>L[J+0], L[J+1] - L[J+0], 0);
End;
End;
{TOTAL ALL VALUES OF LOWS BEING LOWER THAN PRIOR LOW}
LONGSUM = 0;
For J = 1 to 15 begin
LONGSUM = LDAY[J] + LONGSUM;
End;
{COUNT NUMBER OF DAYS WITH LOWS BEING LOWER THAN PRIOR LOW}
COUNTLONG = 0;
For J = 1 to 15 begin
If LDAY[J] > 0 THEN COUNTLONG = COUNTLONG + 1;
End;
{GET AVERAGE OF LOWS LOWER THAN PRIOR LOW}
IF COUNTLONG <> 0 THEN AVGLOW = LONGSUM / COUNTLONG;
{CALCULATE STOP AT "X" TIMES AVGLOW}
LSTOP = LOW[1] - (MULTIPLELONG * AVGLOW[1]);
{PREVENT STOP FROM BEING LOWERED}
LONGSTOP = MAXLIST(LSTOP, LSTOP[1], LSTOP[2], LSTOP[3], LSTOP[4], LSTOP[5]);
{SET PLOT}
IF IsUP THEN PLOT1(LONGSTOP, "STOP");
{SafeZone for SHORTS}
IF IsDN THEN BEGIN
For J = 0 to 14 begin
SDAY[J+1] = IFF(H[J+1]<H[J+0], H[J+0] - H[J+1], 0);
End;
End;
{TOTAL ALL VALUES OF HIGHS BEING HIGHER THAN PRIOR HIGH}
SHORTSUM = 0;
For J = 1 to 15 begin
SHORTSUM = LDAY[J] + SHORTSUM;
End;
{COUNT NUMBER OF DAYS WITH HIGHS BEING HIGHER THAN PRIOR HIGH}
COUNTSHORT = 0;
For J = 1 to 15 begin
If SDAY[J] > 0 THEN COUNTSHORT = COUNTSHORT + 1;
End;
{GET AVERAGE OF HIGHS HIGHER THAN PRIOR HIGH}
IF COUNTSHORT <> 0 THEN
AVGHIGH = SHORTSUM / COUNTSHORT;
{CALCULATE STOP AT "X" TIMES AVGHIGH}
SSTOP = HIGH[1] + (MULTIPLESHORT * AVGHIGH[1]);
{PREVENT STOP FROM RISING}
SHORTSTOP = MINLIST(SSTOP, SSTOP[1], SSTOP[2], SSTOP[3], SSTOP[4],
SSTOP[5]);
{SET PLOT}
IF IsDN THEN PLOT1(SHORTSTOP, "STOP");
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Clyde Lee Chairman/CEO (Home of SwingMachine)
SYTECH Corporation email: clydelee@xxxxxxxxxxxx
7910 Westglen, Suite 105 Office: (713) 783-9540
Houston, TX 77063 Fax: (713) 783-1092
Details at: www.theswingmachine.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
|