Do you remember Larry Williams’ 3 bars strategy?
Well, I tried to automate this strategy.
Without much success at the beginning, I admit, with the basic parameters.
I wanted to optimize it by adding a trend indicator, and changing the value of the moving averages.
Among many trend indicators (MACD, long period stochastics, Ichimoku, moving averages, etc.), I finally chose to keep a simple one : the slope of linear regression.
Moreover, this new approach remains in position as long as the linear regression slope is well oriented : the trade is not closed only by the price crossing above / below a moving average.
So I show you a simple code, which trades the bounces in trend, at the level of the bottom or the top of a channel of moving averages.
For the backtest to be efficient, it must be optimized according to the action / index / currency pair concerned.
Here is an example on the DAX, in graphs Daily, with 1 point of spread, over the last 20 years round.
Moving averages period : 12
Slope of linear regression : 28
// Stratégie : X bars de Larry Williams + Pente régression linéaire
// Paramètres (à optimiser) :
mm = 12
rl = 28
MMhaute = average[mm](high)
MMbasse = average[mm](low)
IF not longOnMarket AND PenteRL > 0 THEN
BUY 1 shares AT MMbasse limit
If longonmarket and PenteRL < 0 THEN
SELL at MMhaute limit
IF not shortonmarket AND PenteRL < 0 THEN
SELLSHORT 1 shares AT MMhaute limit
If shortonmarket and PenteRL > 0 THEN
EXITSHORT at MMbasse limit
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.ProRealTime ITF files and other attachments :