36
John Ehlers John Ehlers 1 ANTICIPATING TURNING POINTS ANTICIPATING TURNING POINTS Left-Brained Concepts Left-Brained Concepts for Traders in for Traders in their Right Minds their Right Minds

2009 Traders Expo John Ehler

Embed Size (px)

Citation preview

Page 1: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

1

ANTICIPATING TURNING POINTSANTICIPATING TURNING POINTS

Left-Brained Concepts Left-Brained Concepts for Traders in their Right Minds for Traders in their Right Minds

Page 2: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

2

This Session is an excerpt from my Runner Up This Session is an excerpt from my Runner Up Paper for the MTA Charles H. Dow AwardPaper for the MTA Charles H. Dow Award

www.mta.orgActivities Tab – Charles H. Dow AwardActivities Tab – Charles H. Dow Award

alsoalsowww.mesasoftware.comTechnical Papers PageTechnical Papers Page

Page 3: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

3

Normal (Gaussian) Probability Distribution Function (PDF) Normal (Gaussian) Probability Distribution Function (PDF) is Commonly Assumed for Market Datais Commonly Assumed for Market Data

0

0.05

0.1

0.15

0.2

0.25

0.3

-3

-2.8

-2.6

-2.4

-2.2 -2

-1.8

-1.6

-1.4

-1.2 -1

-0.8

-0.6

-0.4

-0.2 -0 0.2

0.4

0.6

0.8 1

1.2

1.4

1.6

1.8 2

2.2

2.4

2.6

2.8 3

Normal PDF Cumulative Normal PDF

0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

-3

-2.8

-2.6

-2.4

-2.2 -2

-1.8

-1.6

-1.4

-1.2 -1

-0.8

-0.6

-0.4

-0.2 -0 0.2

0.4

0.6

0.8 1

1.2

1.4

1.6

1.8 2

2.2

2.4

2.6

2.8 3

0 = 50%+1 = 85%+2 = 98%+3 = 99.9%

2

2

2

2

x

eP

Normal PDF is attractive because it can be achieved using several random variables due to the central limit theorem

But is Normal the right PDF for market data?

Page 4: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

4

CONSIDER A THEORETICAL SQUAREWAVECONSIDER A THEORETICAL SQUAREWAVE

-1.5

-1

-0.5

0

0.5

1

1.5

Square Wave Binary PDF of Square Wave

A Square Wave cannot be traded with conventional indicators because the move is over before any indicator can show the move

Page 5: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

5

NEXT - CONSIDER A SINEWAVENEXT - CONSIDER A SINEWAVE

-1

-0.8

-0.6

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

Sine Wave Sine Wave PDF

The Probability Distribution of a Sinewave is similar to that of a Squarewave

This is why most traders have trouble trading with cycles

The cyclic turning point must be anticipated

Page 6: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

6

How Do We Determine the Market PDF?How Do We Determine the Market PDF?

-1-0.9-0.8-0.7-0.6-0.5-0.4-0.3-0.2-0.1

00.10.20.30.40.50.60.70.80.9

1

Create the waveform bystringing beads on a horizontal wire frame

Rotate wire frame toenable beads to stack up

Height of the beadstacks is the PDFof the Waveform

Page 7: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

7

Channel Limited PDF Generator CodeChannel Limited PDF Generator Code

Inputs:Length(20);

Vars:HH(0),LL(0),J(0),I(0);

Arrays:Filt[2000](0),Bin[100](0);

HH = Close;LL = Close;For I = 0 to Length -1 Begin

If Close[I] > HH then HH = Close[I];If Close[I] < LL then LL = Close[I];

End;If HH <> LL Then Value1 = (Close - LL) / (HH - LL);Filt[CurrentBar] = (Value1 + 2*Value1[1] + Value1[2]) / 4;For I = 0 to 100 Begin

If Filt[J] >= I/100 and Filt[J] < (I + 1)/100 Then Bin[I] = Bin[I]+1;End;For I = 0 to 99 Begin

Print(File("c:\tsgrowth\pdf.csv"), I, ",", Bin[I]);End;Plot1(Filt[CurrentBar]);

Page 8: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

8

Channel PDF for Treasury BondsChannel PDF for Treasury Bonds

Clearly, Channel Limited Detrending produces Sinewave-Like PDFs

20 Bar Channel over 30 Years

40 Bar Channel over 30 Years

Page 9: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

9

SPY Weekly for Last Five YearsSPY Weekly for Last Five Years

Consistent 36 Week Cycle is MeasuredConsistent 36 Week Cycle is Measured(code from Jan 2008 Stocks & Commodities)(code from Jan 2008 Stocks & Commodities)

Page 10: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

10

CONVINCED THERE ARE TRADEABLE CYCLES?CONVINCED THERE ARE TRADEABLE CYCLES?

• Market Cycles have been measuredMarket Cycles have been measured– With Probability Distribution FunctionsWith Probability Distribution Functions– With Spectral AnalysisWith Spectral Analysis

• Trading with Cycles is difficult because the Trading with Cycles is difficult because the turning points turning points MUSTMUST be anticipated be anticipated– Conventional Indicators are basically useless Conventional Indicators are basically useless

because of lagbecause of lag

• I will show you two ways to anticipate the I will show you two ways to anticipate the turning points using cyclesturning points using cycles– Correlating prices with a sinewave and advancing Correlating prices with a sinewave and advancing

the phasethe phase– BandPass FilteringBandPass Filtering

Page 11: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

11

Sine Correlation SystemSine Correlation System

Page 12: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

12

Sine Correlation SystemSine Correlation System

• Detrend prices by highpass filteringDetrend prices by highpass filtering• Correlate a sinewave to the detrended price Correlate a sinewave to the detrended price

by maximizing the sum of the product across:by maximizing the sum of the product across:– Full range of cycle periodsFull range of cycle periods– 360 degrees of phase for each period360 degrees of phase for each period

• Resulting sinewave (period and phase) is the Resulting sinewave (period and phase) is the signalsignal

• Advance the signal by two bars to get a Advance the signal by two bars to get a leading signalleading signal

• Crossover of the two signal lines are the Crossover of the two signal lines are the trading signalstrading signals

Page 13: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

13

SINE CORRELATION CODESINE CORRELATION CODE

Inputs:Inputs:Price((H+L)/2), Len(12);Price((H+L)/2), Len(12);

Vars:Vars:alpha(0), Filt(0), MaxCorr(0), Corr(0), I(0), J(0), Phase(0), Signal(0), Lead(0);alpha(0), Filt(0), MaxCorr(0), Corr(0), I(0), J(0), Phase(0), Signal(0), Lead(0);

alpha = (1 - Sine (360 / Len)) / Cosine(360 / Len);alpha = (1 - Sine (360 / Len)) / Cosine(360 / Len);Filt= .5*(1 + alpha)*(Price - Price[1]) + alpha*Filt[1];Filt= .5*(1 + alpha)*(Price - Price[1]) + alpha*Filt[1];MaxCorr = 0;MaxCorr = 0;For I = 0 to Len - 1 BeginFor I = 0 to Len - 1 Begin

Corr = 0;Corr = 0;For J = 0 to Len - 1 BeginFor J = 0 to Len - 1 Begin

Corr = Corr + Filt[J]*Sine(360*(CurrentBar + I + J) / Len);Corr = Corr + Filt[J]*Sine(360*(CurrentBar + I + J) / Len);End;End;If Corr > MaxCorr Then BeginIf Corr > MaxCorr Then Begin

MaxCorr = Corr;MaxCorr = Corr;Phase = I;Phase = I;

End;End;End;End;Signal = Sine(360*(CurrentBar + Phase) / Len);Signal = Sine(360*(CurrentBar + Phase) / Len);Lead = Sine(360*(CurrentBar + Phase - 2) / Len);Lead = Sine(360*(CurrentBar + Phase - 2) / Len);Plot1(Signal);Plot1(Signal);Plot3(Lead);Plot3(Lead);

Page 14: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

14

Sine Correlation PerformanceSine Correlation Performancefor Five Years on @ES.Dfor Five Years on @ES.D

Net Profit:Net Profit: $50,637$50,637# Trades:# Trades: 185 (about one trade every 1.25 weeks)185 (about one trade every 1.25 weeks)% Profitable:% Profitable: 63.8%63.8%Profit Factor:Profit Factor: 1.871.87Trade Drawdown:Trade Drawdown: ($5,375)($5,375)

Page 15: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

15

BandPass FilteringBandPass Filtering

Page 16: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

16

BandPass Filter SystemBandPass Filter System

• BandPass filtering through a narrow passband filter BandPass filtering through a narrow passband filter reduces prices to a sinewave with slowly varying reduces prices to a sinewave with slowly varying phase and amplitudephase and amplitude

• This technique This technique ONLYONLY works because the filtered works because the filtered prices are quasi-sinewaveprices are quasi-sinewave– The period of the cycle must be knownThe period of the cycle must be known– Don’t try this on a Stochastic, RSI, or other oscillatorDon’t try this on a Stochastic, RSI, or other oscillator

• From the calculus we know thatFrom the calculus we know that

d(Sin(d(Sin(t))/dt = t))/dt = *Cos(*Cos(t)t)• Therefore, a 90 degree leading waveform can be Therefore, a 90 degree leading waveform can be

obtained by taking a one bar momentum and dividing obtained by taking a one bar momentum and dividing it by the angular frequency (multiply by Period/2it by the angular frequency (multiply by Period/2))

Page 17: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

17

BandPass Filter SystemBandPass Filter System

• Bandpass filter the price for a selected cycle Bandpass filter the price for a selected cycle period period – Call this I for In-PhaseCall this I for In-Phase

• Multiply one bar momentum of the bandpass Multiply one bar momentum of the bandpass filtered signal by (Period/2filtered signal by (Period/2– Call this Q for QuadratureCall this Q for Quadrature

• Create a 60 degree leading signalCreate a 60 degree leading signal– Lead = .5*I + .866*QLead = .5*I + .866*Q

• Crossovers of “I” and “Lead” are the trading Crossovers of “I” and “Lead” are the trading signalssignals

Page 18: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

18

BANDPASS FILTER CODEBANDPASS FILTER CODE

Inputs:Inputs:Price((H+L)/2), Period(15), Delta(.1);Price((H+L)/2), Period(15), Delta(.1);

Vars:Vars:gamma(0), alpha(0), beta(0), I(0), Q(0), Lead60(0);gamma(0), alpha(0), beta(0), I(0), Q(0), Lead60(0);

beta = Cosine(360 / Period);beta = Cosine(360 / Period);gamma = 1 / Cosine(720*delta / Period);gamma = 1 / Cosine(720*delta / Period);alpha = gamma - SquareRoot(gamma*gamma - 1);alpha = gamma - SquareRoot(gamma*gamma - 1);I = .5*(1 - alpha)*(Price - Price[2]) + beta*(1 + alpha)*I[1] - alpha*I[2];I = .5*(1 - alpha)*(Price - Price[2]) + beta*(1 + alpha)*I[1] - alpha*I[2];Q = (Period / 6.28318)*(I - I[1]);Q = (Period / 6.28318)*(I - I[1]);Lead60 = .5*BP + .866*Q;Lead60 = .5*BP + .866*Q;

Plot1(I,“I");Plot1(I,“I");Plot2(Lead60, “Lead60");Plot2(Lead60, “Lead60");

Page 19: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

19

BandPass System PerformanceBandPass System Performance

• Net Profit:Net Profit: $40,037$40,037• # Trades:# Trades: 133 (about one trade every 1.75 weeks)133 (about one trade every 1.75 weeks)• % Profitable:% Profitable: 59.4%59.4%• Profit Factor:Profit Factor: 1.841.84• Trade Drawdown:Trade Drawdown: ($3,550)($3,550)

Page 20: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

20

Probability Distribution Varies with DetrendingProbability Distribution Varies with Detrending

• Channel Limited detrending (Stochastic) generally Channel Limited detrending (Stochastic) generally yields PDFs similar to the PDF of a Sine Waveyields PDFs similar to the PDF of a Sine Wave

• Two more detrending approaches will be described Two more detrending approaches will be described where that is not necessarily truewhere that is not necessarily true

– HighPass FilteringHighPass Filtering– RSI RSI

Page 21: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

21

Highpass Filter PDF Generator CodeHighpass Filter PDF Generator Code

Inputs:HPPeriod(40);

Vars:alpha(0), HP(0), HH(0), LL(0), Count(0), Psn(0), I(0);

Arrays:Bin[100](0);

alpha = (1 - Sine (360 / HPPeriod)) / Cosine(360 / HPPeriod);HP = .5*(1 + alpha)*(Close - Close[1]) + alpha*HP[1];IF CurrentBar = 1 THEN HP = 0;If CurrentBar > HPPeriod Then Begin

HH = HP;LL = HP;For Count = 0 to HPPeriod -1 Begin

If HP[Count] > HH Then HH = HP[Count];If HP[Count] < LL Then LL = HP[Count];

End;If HH <> LL Then Value1 = 100*(HP - LL) / (HH - LL);Psn = (Value1 + 2*Value1[1] + Value1[2]) / 4;

For I = 1 to 100 BeginIf Psn > I - 1 and Psn <= I Then Bin[I] = Bin[I] + 1;

End;Plot1(Psn);

End;If LastBarOnChart Then Begin

For I = 1 to 99 BeginPrint(File("C:\TSGrowth\PDF_HP.CSV"), I, ",", Bin[I]);

End;End;

Page 22: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

22

HP Filtered PDF for Treasury BondsHP Filtered PDF for Treasury Bonds

40 Bar Cutoff over 30 Years

PDFs produced by filtering have nearly uniform probability

Page 23: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

23

MyRSI PDF Generator CodeMyRSI PDF Generator Code

Inputs:Length(10);

Vars:CU(0), CD(0), I(0), MyRSI(0), Psn(0);

Arrays:Bin[100](0),PDF[100](0);

If CurrentBar > Length Then BeginCU = 0;CD = 0;For I = 0 to Length -1 Begin

If Close[I] - Close[I + 1] > 0 Then CU = CU + Close[I] - Close[I + 1];If Close[I] - Close[I + 1] < 0 Then CD = CD + Close[I + 1] - Close[I];

End;If CU + CD <> 0 Then MyRSI = 50*((CU - CD) / (CU + CD) + 1);Psn = (MyRSI + 2*MyRSI[1] + MyRSI[2]) / 4;For I = 1 to 100 Begin

If Psn > I - 1 and Psn <= I Then Bin[I] = Bin[I] + 1;End;

End;If LastBarOnChart Then Begin

For I = 1 to 99 BeginPrint(File("C:\TSGrowth\PDF_RSI.CSV"), I, ",", PDF[I]);

End;End;

Page 24: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

24

MyRSI PDF for Treasury BondsMyRSI PDF for Treasury Bonds

10 Bar RSI over 30 Years

RSI Detrending yields PDFs that appear Gaussian-Like

Page 25: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

25

RSI PDF Suggests a Trading StrategyRSI PDF Suggests a Trading Strategy

• The RSI PDF appears to be Gaussian-LikeThe RSI PDF appears to be Gaussian-Like• Probability of events at the amplitude Probability of events at the amplitude

extremes are very lowextremes are very low• Strategy is based on the higher probability of Strategy is based on the higher probability of

prices reversing prices reversing – Sell Short when prices cross over some upper Sell Short when prices cross over some upper

thresholdthreshold– Buy when prices cross under some lower Buy when prices cross under some lower

thresholdthreshold

Page 26: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

26

RSI StrategyRSI Strategy

• Compute RSICompute RSI• Buy when RSI crosses below 20%Buy when RSI crosses below 20%• Sell when RSI crosses above 80%Sell when RSI crosses above 80%

Page 27: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

27

Fisher TransformFisher Transform

A PDF of virtually any processed data can be A PDF of virtually any processed data can be converted to a Normal PDF using the Fisher converted to a Normal PDF using the Fisher TransformTransform

Page 28: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

28

Fisher TransformFisher Transform

A Fisher Transform has no lag – it expands range near the endpointsA Fisher Transform has no lag – it expands range near the endpoints

x

xy

1

1ln*5.0

Page 29: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

29

Fisherized PDF for Treasury BondsFisherized PDF for Treasury Bonds

Fisherized Detrended Signal Over 30 Years

The Fisher Transform enables the use of the same kind of strategy as beforeWhere we reverse position when extreme amplitude thresholds are exceeded

Page 30: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

30

Fisher Transform SystemFisher Transform System

• Highpass Filter pricesHighpass Filter prices• Normalize between -.999 and +.999 using a Normalize between -.999 and +.999 using a

Stochastic-like approachStochastic-like approach• Buy when transformed prices cross below an Buy when transformed prices cross below an

optimizable lower boundoptimizable lower bound• Sell when transformed prices cross above an Sell when transformed prices cross above an

optimizable lower bound optimizable lower bound

Page 31: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

31

TRADING SYSTEM RESULTSTRADING SYSTEM RESULTS

Page 32: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

32

RSI Trading System ResultsRSI Trading System Results

• @SP.P for the life of the contract (from April 1982)@SP.P for the life of the contract (from April 1982)• 576 Trades (about once every two weeks)576 Trades (about once every two weeks)• 68.6% Profitable Trades68.6% Profitable Trades• Profit Factor = 1.62Profit Factor = 1.62

The strategy is robust across the entire life of the contract!

Page 33: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

33

RSI Trading System Results (2)RSI Trading System Results (2)

• @US.P for last 10 [email protected] for last 10 years• 196 Trades (about once every two and a half weeks)196 Trades (about once every two and a half weeks)• 63.8% Profitable Trades63.8% Profitable Trades• Profit Factor = 1.60Profit Factor = 1.60

The strategy is robust for the last ten years!

Page 34: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

34

CONVENTIONAL RSI @SP.P EQUITYCONVENTIONAL RSI @SP.P EQUITY

Waiting for confirmation is not a good plan!

Page 35: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

35

Fisher Transform System ResultsFisher Transform System Results

• @SP.P for the life of the contract (from April 1982)@SP.P for the life of the contract (from April 1982)• 802 Trades (a little more than once every two weeks)802 Trades (a little more than once every two weeks)• 65.2% Profitable Trades65.2% Profitable Trades• Profit Factor = 1.53Profit Factor = 1.53

The strategy is robust across the entire life of the contract!

Page 36: 2009 Traders Expo John Ehler

John EhlersJohn Ehlers

36

TRADING STRATEGY COMMENTSTRADING STRATEGY COMMENTS

• The concepts are provided for educational The concepts are provided for educational purposes onlypurposes only

• There was no allowance for slippage and There was no allowance for slippage and commissioncommission

• Results were shown using in-sample Results were shown using in-sample optimizationoptimization

• No stops or disaster reversals were usedNo stops or disaster reversals were used• The strategies are not adaptive to current The strategies are not adaptive to current

market conditionsmarket conditions