Friday, August 22, 2008

3 Finger Lead

The 3 Finger Lead (3FL) is a departure from most of my other studies.
First of all, it's a trend following system that seeks to Buy strength in the direction of the trend. No contrarian thinking here, we're just going with the flow and looking to positive momentum in the indices to guide our trades in other ETFs (and stocks).
The study was inspired by an old TS Dow theory study, but I've noodled around with the parameters significantly enough that the original premises are unrecognizable.
The 3FL is also packaged as a "kit of parts" and I plan to play with this thing over the next few weeks in an effort to refine some of those parts and enhance the applicability of the system.
The basic kit component of the system is the "condition" clause and I've offered a couple examples here to kick off the study.
I've arbitrarily chosen EWC (Canada) as the focus ETF and used the big indices DIA, SPY and IWM as the indicators of market momentum. You can test all sorts of stock and ETF combinations and you might be surprised at the versatility of the model.
The system is coded in TS2000i and uses 4 data fields. In TS this is easy to setup, as you simply insert data 2,3 and 4 in the basic chart (Data 1). I have no idea how this is accomplished in various other platform languages, but maybe some of the coding wizzes who visit this blog can help out.
The first thing that jumps out at you on the chart is probably the alignment of the DIA, SPY and IWM. Hard to believe you're looking at three different indices, but there it is. I chose to profile the EWC because it's acted fairly strong in otherwise faltering markets. There are many ways to play this setup. You don't have to use 4 data fields, you can cut it to 3 with a couple quick code edits, and the basic coding can also be used to evaluate possible pairs trades.
Based on our 5 year test period, the system trades an average once/month and delivers fairly impressive results. This version only trades long, although an inverse version will be reviewed in future posts. 52 winners out of 64 trades and only 2 consecutive losers (you know I like that), and with no stops in place the max intraday drawdown is only $310 and the holding time is fixed at 9 days. This is the type of trade to scale in on, although pyramiding has not been turned on.
There are a lot of tactical possibilities tucked away in this system. . .we'll explore a few them in subsequent studies.
I'll just post the code for now, with a line by line explanation to follow next week, if any confusion.
Basically, we're looking for higher closes in the 3 indices, while Data1 is showing a level of strength by holding above a moving average (Len1). Once higher closes in the 3 indices hold for a period of time (Check(10)), a Buy order is triggered.
The Data fields are then reset to zero to avoid false buy triggers.
Finally, the system simply exits on the 9th day of the position.

Inputs: Len1(38), Len2(12), Len3(9), Check(10);
Variables: Dat(0), Dat2(0), Dat3(0), Dat4(0);

Condition1 = Close Data1 > Average(Close Data1, Len1);
Condition2 = BarsSinceEntry = Len3;

If Condition1 AND Dat = 0 Then Dat = 1;
If Dat <> 0 AND Dat <= Check Then Begin
If Close Data2 > Highest(Close Data2, Len2)[1] Then Dat2 = 1;
If Close Data3 > Highest(Close Data3, Len2)[1] Then Dat3 = 1;
If Close Data4 > Highest(Close Data4, Len2)[1] Then Dat4 = 1;
Dat = Dat + 1;
End
Else
Dat = 0;

If Dat <> 0 AND Dat2 + Dat3 + Dat4 = 3
Then Begin
Buy This Bar at Close;
Dat2 = 0;
Dat3 = 0;
Dat4 = 0;
Dat = 0;
End;
If Condition2 Then ExitLong This Bar at Close;

12 comments:

klynn55 said...

if anyone can code bztrader's systems
in amibroker afls, i would appreciate some help. klynn55atnetzero.net

GS751 said...

be careful not to curve fit.

bzbtrader said...

George,
Curve fitting is a real concern and I plan to devote Monday's post to that topic. Thanks for the caution.

GS751 said...

Thats my only beef with quant systems especially in these markets. If I was playing a system the markets seem great for volatility arbitrage. Using some kind of multilinear regression to the mean trading the Russell 2k. Futures and options and maybe even some ETF's on em. I have looked at isolating some of that March 09 IV on the SPY. I have plenty of cash and haven't had any good ideas but am coming up with a couple in these markets.

Angelo said...

I'm an absolute beginner in AFL, but this should be the code of the "3 finger lead system".
You don't need data1, data2, data3.... but access all tickers in a database with the "FOREIGN" command:

Len1= Param ("Len1", 38, 1,100,1);
Len2= Param ("Len2", 12, 1,100,1);
Len3= Param ("Len3", 9, 1,100,1);

/* IMPORTANT: check tickers for indexes in your database
AND use them to replace "DIA", "SPX", "IWM" */
DIA_cl= Foreign("DIA", "C");
SPX_cl = Foreign("SPX", "C");
IWM_cl = Foreign("IWM", "C");


Condition1 = C > MA (C, Len1);
/* Check confirmations from
the three indexes */
Condition3= DIA_cl > Ref (HHV(DIA_cl, Len2), -1);
Condition4= SPX_cl > Ref (HHV(SPX_cl, Len2), -1);
Condition5= IWM_cl > Ref (HHV(IWM_cl, Len2), -1);

Buy = Condition1 AND Condition3 AND Condition4 AND Condition5;
BuyPrice = Close;

/* remove consecutives Buys from array Buy to correctly use BARSINCE to exit after N days */
Sell= 0; Buy = ExRem(Buy, Sell);

// Now the "exit long trade"
Sell = BarsSince (Buy) == Len3;
SellPrice = Close;

Angelo said...

PS Sorry, the above code gives a problem with the exits: CANCEL this line of code:

Sell=0; Buy = exRem(Buy, Sell);

and ADD this line at the end (after SellPrice = Close;):

Buy = exRem(Buy, Sell);

klynn55 said...

thanks, angelo

bf said...

Has anyone coded this routine for the QQQQ's ? I would like to check my results, the last buy signal I receive is on 8/11/2008. In fact, the last time condition 1 fired was on 2/13/2009, and

On the same time period tested as the EWC, I get 45 out of 66 positive trades.

Toptick said...

Hi, a code question. Looks like the intent is that when the trading vehicle is above its Len1-day moving average, you start checking on the next Check number of days for confirmation that the other indices have made a Len2-day highest close. If all comes true within Check days, you Buy. If not, and you are still above the moving average, you start the Check process again.

However, if the Check period expires without a Buy, and you are below the average, some of the flags recording the Len2-day highest closes remain set and could give spurious signals when the vehicle goes back above its moving average. Wouldn't you want to reset those both when you Buy and when you go below the moving average (Condition1 goes false)?

Thanks as always!

bzbtrader said...

TopTick,
I think the Conditon1 and subsequent "Else" statement forego this issue, but I'll check it out further in my spare time.

Toptick said...

I was thinking that would set Dat to 0, but one or more of Dat1, Dat2, or Dat3 could still be set. The next time Condition1 goes true (you go above moving average), it could appear that you already confirmation from the other indices (Dat1,2 or 3), but that could be left over from weeks before, and not within the current move above the average.

Unknown said...

Hi There, we looked at your "3 fingers lead" strategy. The results were quite impressive (with 61% profitable trades) and a P&L of $1324 for the five years ending today.
My trader insists on adding Commission of $8.00 per trade and slippage of $0.10 per share/contract. With these, the strategy does MUCH worse. We now see only 39% profitable trades and a loss of $2168.
Do you test your strategies with Commission and Slippage? Which do you use? Thanks very much in advance.