Australian (ASX) Stock Market Forum

Unholy Grails - Amibroker

We're looking at the bollinger breakout system.

Yep, looks like exrem is unnecessary. I saw it in some old AFL library system codes which led me astray.
 
trying to recreate the BBO strategy as exactly as I can has thrown up another couple of issues, which I will post here to see if any light is shed. my concern is unrealistic outliers are unduly flattering the results

The first one I will use the example of PDN

Now the book says on p 49, we will include only stocks with an avg vol of > 500000 shares OR avg turnover > $500000. The table on p 55 could be read as saying BOTH criteria must be met, but in this case I will assume the narrative is correct and it should be an OR rather than an AND. Which did you guys use?

If we use OR in the code, I get CAGR something like the book, but with too many trades. If I use AND the number of trades drops closer to that reported the book, and there are no silly outliers, but the CAGR is consistently lower at around 20%. what gives?

Using OR, on some runs it picks up PDN on 8/8/03 for .016 or 1.6c, which goes on to be a 100 bagger and make us $1.5m. Now it only gets past the liquidity filter because in the previous days there was a sudden flurry of activity averaging probably 2m shares traded, which passes the shares>500000 test. however 2m at 1.6c shares represents about $32000 turnover, and our 'purchase' would have added another 45% to that. would we have either wanted to or been able to make this trade in real life? I think not, I cant believe that this would pass any reasonable liquidity test.

Before I took it out to try to replicate this strategy, I had been using a filter of > 20c, partly because so much of the performance was down to 5c stocks, I also don't believe that in real life you are also going to commit 5% of your capital to a 5c stock just because it goes from 5 to 6c

Its possible there may have been a stock split some time which affects this by making the 1.6c an 'adjusted' and therefore never existed price?

second one looks like a data error. Some runs pick up CQA , a delisted stock, which on 23/2/2010 had a 40:1 stock split according to yahoo , (while we were long) , but the test still shows it was picked up for 0.5 c , making $1.7m of non existent profit for the system, which alone would be adding significant amounts to the test results if not excluded manually or by a liquidity test.
 
Hi,
I'm in the process in re-reading "Unholy Grails" and have purchased Amibroker and trying to learn some code to replicate the systems that Nick has developed and included in his book. I have completed the first example he wrote about, which was the "New Yearly Highs". I'm pretty happy with the results as they are close to what's in the book. I want to include an index filter to this system. That is, the system will only signal buys when the "All Ords" is trading above a 75 day moving average, and sell if the All Ords is trading below the 75 day moving average. From what I have found so far, I will have to use the code "foreign". I would me most grateful if someone could assist.

Code:
//Settings
SetOption("InitialEquity",100000);
SetOption("MaxOpenPositions",20);
SetPositionSize(5,spsPercentOfEquity);
SetTradeDelays(1,1,1,1);

//Rules
HI = HHV(C,250);
LW = LLV(C,250);
DollarTurnover = MA(C*V, 7);
dollarTurnoverOK = dollarTurnover > 500000;
Liquidity = MA(V,7);
LiquidityOK = Liquidity > 500000;


Buy = C >= HI AND LiquidityOK AND dollarTurnoverOK;
Sell = C <= LW;

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
 
Hi,
I'm in the process in re-reading "Unholy Grails" and have purchased Amibroker and trying to learn some code to replicate the systems that Nick has developed and included in his book. I have completed the first example he wrote about, which was the "New Yearly Highs". I'm pretty happy with the results as they are close to what's in the book. I want to include an index filter to this system. That is, the system will only signal buys when the "All Ords" is trading above a 75 day moving average, and sell if the All Ords is trading below the 75 day moving average. From what I have found so far, I will have to use the code "foreign". I would me most grateful if someone could assist.

As always with Amibroker there's a few different ways to code it, here's one way:

Code:
[b]SetForeign( "XAO", True, True );
Buyfilter = Close > MA( C, 75 );
Sellfilter = Close < MA(C, 75);
RestorePriceArrays( True );[/b]

//Settings
SetOption("InitialEquity",100000);
SetOption("MaxOpenPositions",20);
SetPositionSize(5,spsPercentOfEquity);
SetTradeDelays(1,1,1,1);

//Rules
HI = HHV(C,250);
LW = LLV(C,250);
DollarTurnover = MA(C*V, 7);
dollarTurnoverOK = dollarTurnover > 500000;
Liquidity = MA(V,7);
LiquidityOK = Liquidity > 500000;


Buy = C >= HI AND LiquidityOK AND dollarTurnoverOK [b]and Buyfilter[/b];
Sell = C <= LW [b]or Sellfilter[/b];

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

I've bolded the sections I've added. Also note that exrem is not required in backtest code and can occasionally cause issues with backtesting, it's mostly used for indicators to remove excess buy/sell signals.
 
I found the only way to get anything like the returns described in the book was to include additional checks for confirming an established trend, getting out after a number of days, decreasing MA exit time if the AORD filter is Off, fiddling with Std deviation values, etc. I expect Nicks' Turnkey code includes many of these sorts of things, probably coded a lot more professionally. I should add, this was for the filtered BBO strategy.

As for delisted stocks, my analyses were only on current ASX stocks including those outside ASX500. I accept that creates a bias, but as others here have said, its not totally unreasonable to expect a long only trend following strategy will get you out of a tanking stock before it delists. I'd be a lot more concerned about deslistings if I was trading short term and not trend following....
 
As per the Unholy Grails book I think I have constructed the raw strategy for 20% Flipper. The HHiV / LLV range is the one I am not sure on and it does change back test results. The book states any low/high so take your pick (and shovel :p:). The Index filter isn't added until later in the book trial so just the basics. Many tweaks are possible to optimise the strategy such as the HHV/LLV range and other "numbers". ;)

Is it correct and does the Martin Zweig version differ greatly? Ta.

Code:
////////////////// 20% Flipper \\\\\\\\\\\\\\\\\\\


// Settings

SetOption("InitialEquity", 100000);              // Initial Equity
SetOption("MaxOpenPositions", 20);               // Max. 20 open positions 
SetPositionSize(5, spsPercentOfEquity);          // Equally weighted 5% of Equity
SetOption("CommissionAmount", 30);               // Commission of $30 ($29.95 rounded up)
SetTradeDelays(1,1,1,1);                         // Trade next bar after signal at open price
SetOption("UsePrevBarEquityForPosSizing", True);  
PositionScore = mtRandomA();                     // Random Backtest
 
// Index Filter
 
SetForeign("XAO");                               // Yahoo = ^AORD / Premium Data = XAO)
IndexBuyfilter  = C > MA(C, 75); 
IndexSellfilter = C < MA(C, 75);
RestorePriceArrays();

// Rules

HighValueLess20 = HHV(H, 50) * 0.80;             // Close is 20% lower than 50 bar High 
LowValuePlus20  = LLV(L, 50) * 1.20;             // Close is 20% higher than 50 bar Low
Turnover  = MA(C*V, 7) > 500000;                 // Dollar Average for 7 bars is greater than 500000 
Liquidity = MA(V, 7) > 500000;                   // Volume Average for 7 bars is greater than 500000

Buy  = Cross(C, LowValuePlus20) & Liquidity & Turnover;
Sell = Cross(HighValueLess20, C);

Plot(LowValuePlus20,  "LLV", colorBlue,styleLine,styleThick);
Plot(HighValueLess20, "HHV", colorBlack,styleLine,styleThick);
 
I can't get a good score with the 20% flipper because the Low price is only good for 50 bars and will adjust upwards after 50 bars with a rising new Low. Change the range to 100 bar Low and the same issue. For the life of me I cannot see anything of value in this strategy. :bad:

p.s. In the code "Liquidity" should be simply Volume Average as it is not the stocks liquidity factor.
 
I can't get a good score with the 20% flipper because the Low price is only good for 50 bars and will adjust upwards after 50 bars with a rising new Low. Change the range to 100 bar Low and the same issue. For the life of me I cannot see anything of value in this strategy.



Like you, I have spent quite some time investigating the "Unholy Grail" systems. The 20% Flipper is the only one that has an ambiguous entry. I quote from the book:

"A 20% rise from any low is a buy."

What exactly does that mean? It doesn't say the low has to be from the last 50 bars as in your AFL listing. It also doesn't say the stock has to have first dropped 20% and then risen 20% as I have found in somebody else's AFL code.
It simply doesn't say. The low could have been this year or last year or 10 years ago.
If so, this is virtually a random entry. Pretty much any stock will have been 20% lower at SOME time in the past.

But maybe I have misunderstood. Nick says he has derived the entry from Martin Zweig's 4% rule, based upon a single week’s movement of the Value Line Composite Geometric Index. Not applicable here. And the one example quoted in the book of CBA from the 23 Jan 2009 low to the entry 20% higher takes about 35 bars/days.

Of course, if you REALLY want to find out, you know what to do ...

On another note, consider this:

all of the "Unholy Grail" systems are very, very simple, extremely, excessively simple and all of them outperform buy and hold not just handsomely, but spectacularly.
How is this possible? Why doesn't everybody just look for 250-day highs and 75-day SMAs?

Nevertheless, I have enjoyed reading "Unholy Grails" and learnt a few things. It was well worth it.
 
I can't get a good score with the 20% flipper because the Low price is only good for 50 bars and will adjust upwards after 50 bars with a rising new Low. Change the range to 100 bar Low and the same issue. For the life of me I cannot see anything of value in this strategy. :bad:

p.s. In the code "Liquidity" should be simply Volume Average as it is not the stocks liquidity factor.

This is a very good and valid point Wysi

Its best explained here.
https://www.mql5.com/en/code/11094

Ive posed the question to Nick as I'm interested myself--if he has come up with a solution.
I believe there is one and had it explained to me---well above my pay grade but I've been told it can be done
but not with software like Ami.
Metlab I believe but there is a way of doing it.

Once I know Ill let you know if interested.
 
I can't get a good score with the 20% flipper because the Low price is only good for 50 bars and will adjust upwards after 50 bars with a rising new Low. Change the range to 100 bar Low and the same issue. For the life of me I cannot see anything of value in this strategy. :bad:

You will need to use a ZigZag based indicator that works from High to Low and link this with a binary indicator which signals when a 20% low has been "locked in".

AmiBroker is certainly capable of handling both indicators.
 
Rnr
Could you point me in the direction of a working example of the two together.
 
You will need to use a ZigZag based indicator that works from High to Low and link this with a binary indicator which signals when a 20% low has been "locked in".

AmiBroker is certainly capable of handling both indicators.
A 20% change from high to low isn't a rule. The entry is a rise of 20% from a low. As Habakkuk notes you will still need a 'range' to determine when a low is the low we use as the base. In Amibroker Zig uses future data.
 
On another note, consider this:

all of the "Unholy Grail" systems are very, very simple, extremely, excessively simple and all of them outperform buy and hold not just handsomely, but spectacularly.
How is this possible? Why doesn't everybody just look for 250-day highs and 75-day SMAs?

Nevertheless, I have enjoyed reading "Unholy Grails" and learnt a few things. It was well worth it.
Needs a bull market and implemented near the start of the bull market.

Yes I enjoyed reading Unholy Grails too.
 
Your not going to know where that is or when that will be.

Today's ASX 200 price could be twice its price in 5 years.
A sector could way out perform the index.
A stock or three may out perform a sector.

If your systems trading I've found a filter such as an index or portfolio filter to really help.

You'll get average years you'll get below average years and you'll get amazing years
But you will get better than market results and an easy set of rules to follow
 
Rnr
Could you point me in the direction of a working example of the two together.

My apologies tech for the somewhat lengthy delay.

MetaStock snap of AAD

Red line is a HiLo ZigZag Indicator set at 20%.

Red bar and diamond = Valid Trough has formed on this bar and this trough will not change going forward.

Blue bar and diamond = Valid Peak has formed on this bar and this peak will not change going forward.

20% HiLo ZZ Peak & Trough Lock Signal 2014-12-04.gif
 
A 20% change from high to low isn't a rule. The entry is a rise of 20% from a low. As Habakkuk notes you will still need a 'range' to determine when a low is the low we use as the base. In Amibroker Zig uses future data.

It's up to you on how you interpret this system from Unholy Grails and I presume that replicating his results would confirm whether your code is the same as Nick's.

The code used in MetaStock can be written for AmiBroker and will produce the same results.
 
It's up to you on how you interpret this system from Unholy Grails and I presume that replicating his results would confirm whether your code is the same as Nick's.

The code used in MetaStock can be written for AmiBroker and will produce the same results.

Thanks but no thanks. Done thousands of back tests.
 
Rnr
Thanks
I have Metastock
You wouldn't have to code I could look at?
 
Top