Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
Huck's trend catcher #407043
09/05/12 12:08
09/05/12 12:08
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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...

Re: Huck's trend catcher [Re: jcl] #407082
09/05/12 20:24
09/05/12 20:24
Joined: Feb 2012
Posts: 37
S
stevegee58 Offline
Newbie
stevegee58  Offline
Newbie
S

Joined: Feb 2012
Posts: 37
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...

Re: Huck's trend catcher [Re: stevegee58] #407084
09/06/12 06:58
09/06/12 06:58
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.

Re: Huck's trend catcher [Re: jcl] #407805
09/19/12 15:02
09/19/12 15:02

L
liftoff
Unregistered
liftoff
Unregistered
L



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

Re: Huck's trend catcher [Re: ] #407857
09/20/12 08:51
09/20/12 08:51
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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:


Last edited by jcl; 09/24/12 14:38.
Re: Huck's trend catcher [Re: jcl] #407965
09/22/12 10:47
09/22/12 10:47

L
liftoff
Unregistered
liftoff
Unregistered
L



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


Last edited by liftoff; 09/22/12 11:04.
Re: Huck's trend catcher [Re: ] #408053
09/24/12 13:12
09/24/12 13:12
Joined: Sep 2012
Posts: 99
T
TankWolf Offline
Junior Member
TankWolf  Offline
Junior Member
T

Joined: Sep 2012
Posts: 99
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?

Last edited by TankWolf; 09/24/12 13:25.
Re: Huck's trend catcher [Re: TankWolf] #408055
09/24/12 14:42
09/24/12 14:42
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.

Re: Huck's trend catcher [Re: jcl] #408092
09/25/12 07:56
09/25/12 07:56
Joined: Sep 2012
Posts: 99
T
TankWolf Offline
Junior Member
TankWolf  Offline
Junior Member
T

Joined: Sep 2012
Posts: 99
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

Last edited by TankWolf; 09/25/12 08:58.
Re: Huck's trend catcher [Re: TankWolf] #408097
09/25/12 09:32
09/25/12 09:32
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline OP

Chief Engineer
jcl  Offline OP

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.

Page 1 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1