Huck's trend catcher

Posted By: jcl

Huck's trend catcher - 09/05/12 12:08

This simple strategy was suggested on another forum:

Code:
function run()
{
	var *Price = series(price());
	var *LP5 = series(LowPass(Price,5));
	var *LP10 = series(LowPass(Price,10));
	var *RSI10 = series(RSI(Price,10));

	Stop = 50*PIP;
	
	if(crossOver(LP5,LP10) && crossOver(RSI10,50))
		enterLong();
	else if(crossUnder(LP5,LP10) && crossUnder(RSI10,50))
		enterShort();
}



The equity curve:



Feel free to improve...
Posted By: stevegee58

Re: Huck's trend catcher - 09/05/12 20:24

I found your posts about this on the other forum. It's interesting how using a low pass filter instead of an MA worked better. A moving average is really just a low pass filter anyway...
Posted By: jcl

Re: Huck's trend catcher - 09/06/12 06:58

An EMA is a 1-pole lowpass filter; the LowPass function is a 2-pole filter. A 2-pole filter has constant amplification - and thus zero lag - below the filter frequency. That's why it works better. EMA lags at any frequency.
Posted By: Anonymous

Re: Huck's trend catcher - 09/19/12 15:02

You didn't post the optimized script? I believe that one is more profitable.
Posted By: jcl

Re: Huck's trend catcher - 09/20/12 08:51

Yes, that's the optimized version with 3x higher profit:

Code:
function run()
{
	BarPeriod = 240;
	StartDate = 2006;
	NumYears = 7;
	NumWFOCycles = 12;
	set(PARAMETERS|TESTNOW);
	
	var *Price = series(price());
	var *LP5 = series(LowPass(Price,5));
	var *LP10 = series(LowPass(Price,optimize(10,6,20))); 
	var *RSI10 = series(RSI(Price,10)); 
	Stop = optimize(5,1,10)*ATR(30);
	int Delay = 3; 
	
	static int crossed = 0;
	if(crossOver(LP5,LP10))
		crossed = Delay;
	else if(crossUnder(LP5,LP10))
		crossed = -Delay;
		
	if(crossed > 0 && crossOver(RSI10,50)) {
		enterLong();
		crossed = 0;
	} else if(crossed < 0 && crossUnder(RSI10,50)) {
		enterShort();
		crossed = 0;
 	} else
		crossed -= sign(crossed);
}



Equity curve:

Posted By: Anonymous

Re: Huck's trend catcher - 09/22/12 10:47

Did a little playing around with the script.
Code:
// Huck Trend Catcher
function HTCS()
{
	var *Price = series(price());
	var *LP5 = series(LowPass(Price,5));
	var *LP10 = series(LowPass(Price,optimize(10,6,20)));
	var *RSI10 = series(RSI(Price,10));
	Stop = optimize(5,1,10)*ATR(30);
	static int crossed = 0;
	
	if(crossOver(LP5,LP10))
	  crossed = 3;
	else if(crossUnder(LP5,LP10))
	 crossed = -3;
	 
	if(strstr(Algo,":L") and crossed > 0 && crossOver(RSI10,50))
	{ 
	enterLong();
	 crossed = 0;
	}
	else if(strstr(Algo,":S") and crossed < 0 && crossUnder(RSI10,50))
	{
	enterShort(); crossed = 0;
	}
	else crossed -= sign(crossed);
} 
function run()
{
	Mode = PARAMETERS+TESTNOW+FACTORS;
	BarPeriod = 240;
	StartDate = 2006;
	NumYears = 7;
	NumWFOCycles = 12;
	
	
	if(ReTrain) {
		SelectWFO = -1;
		UpdateDays = 30;
	}
	
//Asset Classes	
while(asset(loop("EUR/USD","USD/CHF","AUD/USD","USD/JPY","GBP/USD","USD/CAD","NZD/USD","AUD/JPY","")))

while (algo(loop(":L",":S")))
{
	if(Train)
	Lots=1;
	else if(strstr(Algo,":L") and OptimalFLong > 0)
	{
	Lots=1;
	Margin = clamp((WinLong-LossLong) * OptimalFLong/2,50,1000);
   }
   else if(strstr(Algo,":S") and OptimalFShort > 0)
   {
   Lots=1;
   Margin = clamp((WinShort-LossShort) * OptimalFShort/2,50,10000);
   }
	else
	Lots=0;
	
	HTCS();
}
}



I know I did something wrong somewhere because the equity curve doesn't look so pretty

Posted By: TankWolf

Re: Huck's trend catcher - 09/24/12 13:12

Hi jcl,

Been following your thread on babypips and learning your lessons on programming c for backtesting. Thanks for the great work your doing I appreciate it.

I have one question in regards to your code you posted above:

Quote:


function run()
{
BarPeriod = 240;
StartDate = 2006;
NumYears = 7;
NumWFOCycles = 12;
set(PARAMETERS|TESTNOW);

var *Price = series(price());
var *LP5 = series(LowPass(Price,5));
var *LP10 = series(LowPass(Price,optimize(10,6,20)));
var *RSI10 = series(RSI(Price,10));
Stop = optimize(5,1,10)*ATR(30);

static int crossed = 0;
if(crossOver(LP5,LP10))
crossed = Delay;
else if(crossUnder(LP5,LP10))
crossed = -Delay;

if(crossed > 0 && crossOver(RSI10,50)) {
enterLong();
crossed = 0;
} else if(crossed < 0 && crossUnder(RSI10,50)) {
enterShort();
crossed = 0;
} else
crossed -= sign(crossed);
}



The 'Delay' variable is not defined and wont work in Zorro, I understand that it needs to be identified just having a little trouble working out what needs to be done here to rectify your code to acheive that optimised result you posted.

Regards
TankWolf

Edit: Looking over this again and reading what the crossOver and crossUnder functions do is it correct that delay shouldnt actually be there and it should be 1 or -1 because the next part of the code looks to go long if crossed is > 0 since the crossOver function looks if data1 crosses over data2 so then if it does it should assign crossed = 1?
Posted By: jcl

Re: Huck's trend catcher - 09/24/12 14:42

I indeed forgot the Delay in the code:

int Delay = 3;

The variable "crossed" is set to 3 or -3, then counted down or up until it's 0. This has the purpose that the signal stays valid until 3 bars after the crossover.

The "static" keyword is important here, as it keeps the content of the "crossed" variable when the function is left. Otherwise, crossed could not be used as a counter because it would be set to 0 every time the run() function is called.

This is a programming trick that was not mentioned in the course. It's however described in the "Variables" chapter of the manual.
Posted By: TankWolf

Re: Huck's trend catcher - 09/25/12 07:56

I understand what you are saying about making the int static so it keeps its variable when the function is left, what I dont understand is how the "crossed" variable is counted down or up to 0 from -3,3.

Quote:
static int crossed = 0;
int Delay = 3;
if(crossOver(LP5,LP10))
crossed = Delay;
else if(crossUnder(LP5,LP10))
crossed = -Delay;

if(crossed > 0 && crossOver(RSI10,50)) {
enterLong();
crossed = 0;


The way I read that code is that crossed would become either 3 or -3 after completing the first if/else statement then the next part of the code looks to see if crossed is greater than 0 and the RSI has crossOver 50 from below. If crossed is greater ie (3) the algo goes long. Where does the count down actually take place? Shouldnt there be a loop statement somewhere to count the crossed variable down or up to 0?

Regards
TankWolf
Posted By: jcl

Re: Huck's trend catcher - 09/25/12 09:32

It happens here:

crossed -= sign(crossed);

If a trade takes place, crosses is immediately set to 0 for not triggering a trade again. Otherwise, its sign is subtracted, which means that its absolute value is reduced by 1. The sign is -1 or 1 dependent on whether the number is negative or positive.
Posted By: TankWolf

Re: Huck's trend catcher - 10/07/12 04:14

I found another trending system funnily enough called Huck Loves Her Bucks which can be seen here on babypips. http://forums.babypips.com/free-forex-trading-systems/39293-huck-loves-her-bucks-system.html

I have used all of the rules except for the profit & stop rules posted. I tried to incorporate them but when I did it made the results worse. This could of been however because of my poor coding. Anyway here is the code & results if anyone wants to play with it further without the profit & stop rules.

Quote:

function run()
{
BarPeriod = 240;
StartDate = 2006;
NumYears = 7;
NumWFOCycles = 12;
set(PARAMETERS|TESTNOW);

asset("EUR/USD");

var *Price = series(priceClose());
var *EMA10 = series(EMA(Price,optimize(10,5,20)));
var *EMA20 = series(EMA(Price,optimize(20,10,40)));
var Stoch50 = Stoch(optimize(14,10,20),optimize(3,1,5),MAType_SMA,optimize(3,1,5),MAType_SMA);

static int crossed = 0;
int Delay = optimize(3,1,5);
if(crossOver(EMA10,EMA20))
crossed = Delay;
else if(crossUnder(EMA10,EMA20))
crossed = -Delay;

if(crossed > 0 && Stoch50 > 50 && Stoch50 < 80) {
enterLong();
crossed = 0;
} else if(crossed < 0 && Stoch50 < 50 && Stoch50 > 20) {
enterShort();
crossed = 0;
} else
crossed -= sign(crossed);
}


Quote:

Annual return 147%
Profit factor 2.37 (PRR 1.85)
Sharpe ratio 1.34
Kelly criterion 1.21
OptimalF .068
Ulcer index 5%
Prediction error 39%
Posted By: Dalla

Re: Huck's trend catcher - 05/11/17 05:33

Originally Posted By: jcl
Yes, that's the optimized version with 3x higher profit:

Code:
function run()
{
	BarPeriod = 240;
	StartDate = 2006;
	NumYears = 7;
	NumWFOCycles = 12;
	set(PARAMETERS|TESTNOW);
	
	var *Price = series(price());
	var *LP5 = series(LowPass(Price,5));
	var *LP10 = series(LowPass(Price,optimize(10,6,20))); 
	var *RSI10 = series(RSI(Price,10)); 
	Stop = optimize(5,1,10)*ATR(30);
	int Delay = 3; 
	
	static int crossed = 0;
	if(crossOver(LP5,LP10))
		crossed = Delay;
	else if(crossUnder(LP5,LP10))
		crossed = -Delay;
		
	if(crossed > 0 && crossOver(RSI10,50)) {
		enterLong();
		crossed = 0;
	} else if(crossed < 0 && crossUnder(RSI10,50)) {
		enterShort();
		crossed = 0;
 	} else
		crossed -= sign(crossed);
}



Equity curve:



Sorry for waking up an old thread, but I wanted to see if I could reproduce these results. I'm running with Zorro 1.58, I've copy pasted the code above, and I'm not seeing anywhere near the same equity curve.



Attached picture Zorro.png
Posted By: PeWi

Re: Huck's trend catcher - 05/11/17 09:41

Hi to all,

I am currently trying the first steps with Zorro after reading the book of jcl.

I copied the optimized script from jcl, started training and testing.

The result I got is about a tenth of jcl (about 1.6k instead of 16k).

What am I doing wrong? I use the free Zorro 1.54 and a demo account of fxcm.

Help or hints would be greatly appreciated ...
Kind regards, Peter
Posted By: jcl

Re: Huck's trend catcher - 05/11/17 10:29

Hi Pewi - since the English book version comes out soon, I've tested 2 weeks ago all the scripts with the latest Zorro version 1.58. You should get the same results as in the book, with some differences due to different trading costs.

Make sure you have Zorro version 1.58 and also the latest book scripts from the financial hacker website - a few things have been changed in the scripts.
Posted By: Dalla

Re: Huck's trend catcher - 05/11/17 11:11

Not sure what you mean now, I cannot find anything resembling this strategy in among the book scripts? (assuming you mean http://financial-hacker.com/boersenhackerbuch.zip)
Posted By: jcl

Re: Huck's trend catcher - 05/11/17 16:17

@Dalla, I did not mean you, but it's the same in your case: Differences are usuaally caused by either different test periods, or by different trading costs. You can see that the curves are somewhat similar, only the profit is lower. I suppose that the result back in 2012 was based on no commission. Also the test periods look different and the default test/training split was probably different in that early version.
Posted By: PeWi

Re: Huck's trend catcher - 05/11/17 17:07

Hello jcl,

thanks for your quick reply. I will try with Zorro 1.58.

I am a little bit surprised that a relative short script like your optimized version of Huck's trend catcher depends so much of the Zorro version?

Also thanks for the tip with the updated book coming soon. Is there a german version planned also? I am not so familiar with english nor with such statistics nor with the special trading stuff that I am happy if at least the language barrier misses ...

BTW: Are there enough members for a german speaking sub forum?

Kind regards, Peter
Posted By: Dalla

Re: Huck's trend catcher - 05/11/17 17:33

The german book has been around for some time I think
http://www.amazon.de/Das-B%C3%B6rsenhackerbuch-Finanziell-algorithmische-Handelssysteme/dp/1530310784
Posted By: PeWi

Re: Huck's trend catcher - 05/11/17 18:08

Hello Dalla,

by chance I stumbled over the current german version some weeks ago and started to get interested by forex, algorithmic trading and zorro.

Kind regards, Peter
Posted By: PeWi

Re: Huck's trend catcher - 05/11/17 18:47

Hi jcl,

also with 1.58 I get for Huck's trend catcher and your optimized script only a result of 1.6k and not 16k as you (FXCM demo account). How can such a big difference happen?

Kind regards, Peter
Posted By: jcl

Re: Huck's trend catcher - 05/12/17 06:54

I don't know, but aside from the other mentioned reasons, a 10 times smaller balance usually results from a 10 times smaller investment. I guess FXCM introduced micro accounts somewhat after 2012.
Posted By: PeWi

Re: Huck's trend catcher - 05/18/17 06:29

Thanks again for helping; one more of a long chain of failures of a Zorro starter ;-)

Peter
© 2024 lite-C Forums