door Paul M » za 19 jul 2003, 17:49
Hallo Dirk en de rest,
Alexander Elder?s ?SafeZone Stop? :
INPUTS:
Price((H+L)/2), MALength(22), Lookback(15), Trend(3), AutomaticLookBack(True), Multiplelong(2), Multipleshort(2);
VARIABLES:
MA(0), ?Ldiff(0), Lday(0), Sdiff(0), Sday(0), Longsum(0), ?Shortsum(0) , Countlong(0), Countshort(0), Avglow(0), Avghigh(0), Longstop(0), Shortstop(0), Lstop(0), Sstop(0), ii(0), LookBackTemp(0);
{Determine trend by slope of EMA}
MA = xaverage( Price, MALength );
Condition1 = MA > MA[Trend];
Condition2 = MA < MA[Trend];
{Determine Lookback Period (to prior swing extreme)}
IF LookBackTemp<LookBack THEN LookBackTemp=LookBackTemp+1;
IF Condition1<>Condition1[1] THEN BEGIN
LookBackTemp=LookBack;
Value1=MinList(MALength*0.66,LookBack);
IF Condition1 and AutomaticLookBack THEN IF LowestBar(L,Value1)<LookBack THEN LookBackTemp=LowestBar(L,Value1);
IF Condition2 and AutomaticLookBack THEN IF HighestBar(H,Value1)<LookBack THEN LookBackTemp=HighestBar(H,Value1);
END;
{determine and count number of days with:
for longs - ?lows being lower than prior lows
for shorts - ?highs being higher than prior highs}
Ldiff = IFF(L[1] > L, L[1] - L, 0); ? { Difference of lows }
Lday ?= IFF(L[1] > L, 1, 0); ? ? ? ? ?{ 1 if this is a "low's" day }
Sdiff = IFF(H[1] < H, H - H[1], 0); ? { Difference of highs }
Sday ?= IFF(H[1] < H, 1, 0); ? ? ? ? ?{ 1 if this is a "high's" day }
{SAFEZONE FOR LONGS}
{Get average of lows lower than prior low}
Longsum = summation(Ldiff, Lookbacktemp);
Countlong = summation(Lday, Lookbacktemp);
IF Countlong <> 0 THEN Avglow = Longsum / Countlong;
{Calculate stop at "X" times avglow}
Lstop = LOW - (Multiplelong * Avglow);
{Prevent stop from being lowered}
Longstop = MAXLIST(Lstop, Lstop[1], Lstop[2], Lstop[3], Lstop[4], Lstop[5]);
{Set Plot}
IF Condition1 THEN BEGIN
PLOT1(Longstop[1], "STOP");
END;
IF lastbaronchart THEN BEGIN
Plot1(Longstop[1], "STOP"); ? ? ? ? ?
Plot2(Longstop, "StopNext"); ? ? ? ? ? ? ? ? ? ? ?
END;
{SAFEZONE FOR SHORTS}
{Get average of highs higher than prior high}
Shortsum = summation(Sdiff, Lookbacktemp);
Countshort = summation(Sday, Lookbacktemp);
IF Countshort <> 0 THEN Avghigh = Shortsum / Countshort;
{Calculate stop at "X" times avghigh}
Sstop = HIGH + (Multipleshort * Avghigh);
{Prevent stop from rising}
Shortstop = MINLIST(Sstop, Sstop[1], Sstop[2], Sstop[3], Sstop[4], Sstop[5]);
{Set Plot}
IF Condition2 THEN BEGIN
PLOT1(Shortstop[1], "STOP");
END;
IF lastbaronchart THEN BEGIN
Plot1(Shortstop[1], "STOP"); ? ?
Plot2(Shortstop, "StopNext"); ? ? ? ? ?
END;
Groetjes Paul
(Edited by Paul M at 6:57 pm op 19,juli 2003)
(Edited by Paul M at 12:09 am op 20,juli 2003)