Hi Bruce,
I'm guessing you've already done this as it's a pretty common technique. I'm basically looking to plot dots at swing highs and lows similar to this ...
I was reading Trading Systems and Methods by Perry Kaufman on a rainy day, and pulled some stuff from it to clarify the process. I'm including the description in English, the TradeStation EasyLanguage code, and the Excel formulas ... you probably won't need all three but I figured you might prefer one over the others.
Here it is in English ...
Constructing a Classic Swing Chart
A classic technique for finding the swing highs and lows uses the following steps. This can be applied to any data frequency, daily, weekly, hourly, or any intraday period; therefore, references to days in the following example could be replaced by weeks or 15-minute bars.
1. Begin by plotting the high to low of the first day in the first column of the chart. At this point, we do not know the direction of this swing bar or the trend of prices.
2. Add the second day of data.
a. If there is a higher high but not a lower low,
then continue the first swing higher and ignore the low of the day.
We can now call this an upswing.
b. If there is a lower low but not a higher high,
then continue the first swing lower and ignore the high of the day.
This is now a downswing.
c. If there is both a new high and a new low (an outside day),
then continue the current high direction and ignore the low.
(You may choose the low instead, but this choice must be consistently applied.)
d. If the high of the second day is less than the previous high of the column and the low is greater than the previous low (an inside day),
then ignore that day and go to the next day.
3. Once a direction has been established, add the next day’s data.
a. If the current swing is up, then
i. First look at the new daily high.
If the high is higher than the high in the current column,
extend that swing to the new high, ignoring the low.
Go to the next day.
ii. If the new high is lower than the high of the current column then test for a swing reversal.
If the current swing high minus the low of the new day is greater than the swing filter value,
then move one column to the right and plot the range of the new day high to low.
The new swing is down.
b. If the current swing is down, then
i. Look first at the new daily low.
If the low is lower than the low in the current column,
extend that swing down to the new low and ignore the high.
Go to the next day.
ii. If the new low is higher than the low of the current column,
then test for a swing reversal.
If the high of the new day minus the low of the current column is greater than the swing filter value,
then move one column to the right and plot the range of the new day from high to low.
The swing is now up.
4. A new price that does not make a new high or low and does not exceed the swing reversal threshold is ignored.
This particular method is called a 2-day or 2-period technique because it requires only two periods to identify a swing change. The sensitivity of the swing chart can be reduced by requiring that a swing change only occur after three or more days where prices reverse their direction.
Based on William F. Eng, “A Mechanical Trading System,” Technical Analysis of Stocks & Commodities (July 1986). Further information can be found in Eng, The Technical Analysis of Stocks, Options & Futures (Chicago: Probus, 1988).
Source: Trading Systems and Methods (5th ed) - Perry Kaufman
Here's the TradeStation EasyLanguage code. I don't use TradeStation myself but the code is pretty easy to read ...
[LegacyColorValue = true];
{ TSM Swing: Plots swing highs and lows
Copyright 1994-1999, P.J. Kaufman. All rights reserved.
Plot setup:
1. Place on same graph window as price
2. Scale same as price
3. In style, set both values to "point" with weight 2
Inputs for TSM SWING:
type = 0, normal price
= 1, 3-month rate
= 2, bond price at par
swing = price swing in whole % (e.g., 2% = 2.0) }
input: type(0), swing(2.5);
vars: pcswing(0), last(0), curhigh(0), curlow(0), swhigh(0), swlow(0) , highbar(0),
lowbar(0), chighbar(0), clowbar(0), lowp(0), highp(0), xclose(0), xhigh(0),
xlow(0), divide(4), factor(1), par(800);
pcswing = swing / 100.;
if type = 0 then begin
xhigh = high;
xlow = low;
xclose = close;
end
else if type = 1 then begin
xhigh = 100 - low;
xlow = 100 - high;
xclose = 100 - close;
end
else if type = 2 then begin
xhigh = par / low;
xlow = par / high;
xclose = par / close;
end;
{ INITIALIZE MOST RECENT HIGH AND LOW }
if currentbar = 1 then begin
curhigh = xclose; { current high }
curlow = xclose; { current low }
end;
{ SEARCH FOR A NEW HIGH -- favor reversals }
if last<>1 then begin
{ REVERSE FROM HIGH IF MINIMUM % SWING }
if xlow < curhigh - curhigh*pcswing then begin
last = 1; { last high fixed }
swhigh = curhigh; { new verified high }
highbar = chighbar;
curlow = xlow; { initialize new lows }
lowp = xlow; { swing low for plot }
clowbar = currentbar;
if type = 0 then
plot1[currentbar - highbar](high[currentbar - highbar]*1.01,"swinghigh")
else
plot3[currentbar - highbar](low[currentbar - highbar]*.99,"swinglow");
end
else begin
if xhigh > curhigh then begin
curhigh = xhigh; { new current high }
chighbar = currentbar;
end;
end;
end;
{ SEARCH FOR A NEW LOW - favor reversal }
if last <> -1 then begin
{ REVERSAL FROM LOW IF MINIMUM % SWING }
if xhigh > curlow + curlow*pcswing then begin
last = -1;
swlow = curlow;
lowbar = clowbar;
curhigh = xhigh; { initialize current high }
highp = xhigh; { swing high for plot }
chighbar = currentbar;
if type = 0 then
plot2[currentbar - lowbar](low[currentbar - lowbar]*.99,"swinglow")
else
plot4[currentbar - lowbar](high[currentbar - lowbar]*1.01,"swinghigh");
end
else begin
if xlow < curlow then begin
curlow = xlow;
clowbar = currentbar;
end;
end;
end;
And here's how to implement finding swing highs and lows using Excel ...
Set up your columns with the following data:
A Date
B High price
C Low price
D Closing price
Put the minimum swing percentage value in cell C3 (for example, 5% =.05)
Put the following formulas in the corresponding cells. Row 6 initializes the process.
E6 =B6 (the current swing high)
F6 =C6 (the current swing low)
G6 =IF(D6>(E6+F6),-1,1) (where -1 is a downswing and +1 is an upswing)
Row 7 is the beginning of the repeated process. Row 7 can be copied down.
E7 =IF($G6=-1#AND#b7>E6,B7,IF($G6=1,B7,E6)) (the new current low)
F7 =IF($G6=1#AND#C7<F6,C7,IF($G6=-1,C7,F6)) (the new current high)
G7 =IF($G6=-1,IF(C7<E7 - $C$3*D7,1,$G6),IF(B7>F7+$C$3*D7,-1,$G6)) (test high or low)
H7 =IF($G7=1#AND#G6=-1,E7,H6) (the new swing high)
I7 =IF($67=-1#AND#G6=1,F7,I6)) (the new swing low)
Thanks for your help, Bruce!!
|