Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, wandaluciaia, 1 invisible), 798 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
My Take on A Mega Script #408047
09/24/12 10:06
09/24/12 10:06

L
liftoff
Unregistered
liftoff
Unregistered
L



I had plans on trading the Z1 on a microlot but due to complications from FXCM it seems it is not such a good idea at this time. So I have decided to combine a couple of scripts I know inside out.

The script will include the trend and cycle trading scripts from the tutorials and hucks trend catcher.

Code:
// Workshop 6: Portfolio trading ///////////////////

function tradeTrend()
{
	TimeFrame = 1;
	var *Price = series(price());
	var *Trend = series(LowPass(Price,optimize(250,100,1000)));
	Stop = optimize(2,1,10) * ATR(100);
	
	if(strstr(Algo,":L") and valley(Trend)) 
		enterLong();
	else if(strstr(Algo,":S") and peak(Trend)) 
		enterShort();
}

function tradeCounterTrend()
{
	var *Price = series(price());
	var Threshold = optimize(1.0,0.5,2,0.1);
	var *DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	var *HP = series(HighPass(Price,LowPeriod*optimize(1,0.5,2)));
	var *Signal = series(Fisher(HP,500));
	Stop = optimize(2,1,10) * ATR(100);

	if(strstr(Algo,":L") and crossUnder(Signal,-Threshold)) 
		enterLong(); 
	else if(strstr(Algo,":S") and crossOver(Signal,Threshold)) 
		enterShort();
}

function HuckTrend()
{
	TimeFrame = 1;
	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(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()
{
	set(PARAMETERS+FACTORS+LOGFILE); // use optimized parameters and reinvestment factors
	BarPeriod = 240;	// 4 hour bars
	LookBack = 500;	// needed for Fisher()
	NumWFOCycles = 8; // activate WFO
	NumBarCycles = 4;	// 4 times oversampling
	
	if(ReTrain) {
		UpdateDays = 30;	// reload new price data from the server every 30 days
		SelectWFO = -1;	// select the last cycle for re-optimization
	}
	
// portfolio loop
	while(asset(loop("EUR/USD","USD/CHF","GBP/USD","AUD/USD","USD/CAD","USD/JPY","USD/NZD",)))
	while(algo(loop("TRND:L","TRND:S","CNTR:L","CNTR:S","HuckTrend:L","HuckTrend:S")))
	{
// set up the optimal margin
		if(Train)
			Lots = 1;
		else if(strstr(Algo,":L") and OptimalFLong > 0) {
			Lots = 1;			 
			Margin = clamp((WinLong-LossLong) * OptimalFLong/2, 50, 10000);
		} else if(strstr(Algo,":S") and OptimalFShort > 0) {
			Lots = 1;
			Margin = clamp((WinShort-LossShort) * OptimalFShort/2, 50, 10000);
		} else
			Lots = 0; // switch off trading

		if(strstr(Algo,"TRND")) 
			tradeTrend();
		else if(strstr(Algo,"CNTR")) 
			tradeCounterTrend();
	}
	
	PlotWidth = 1000;
	PlotHeight1 = 320;
}



Script wont comply, can someone help me find the error?

Last edited by liftoff; 09/24/12 10:18.
Re: My Take on A Mega Script [Re: ] #408049
09/24/12 10:31
09/24/12 10:31
Joined: Sep 2012
Posts: 24
G
Gattaca Offline
Newbie
Gattaca  Offline
Newbie
G

Joined: Sep 2012
Posts: 24
The 'delay' variable is not declared.

Re: My Take on A Mega Script [Re: ] #408051
09/24/12 10:46
09/24/12 10:46
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
When you get a message like this:

Error in 'line 44:
'Delay' undeclared identifier
> crossed = Delay; <

you'll know that you've forgotten to define the variable "Delay" before using it in line 44.

Re: My Take on A Mega Script [Re: jcl] #408056
09/24/12 14:50
09/24/12 14:50
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
There's also another problem with this script.

I mentioned in the other thread that the "static" keyword keeps the content of the "crossed" variable even when the function is left. This is not desired here, because the HuckTrend() function is called many times in your portfolio script, every time with a different asset. Thus you need a different way to temporary store the content of "crossed" separately per asset.

There are 8 variables for this purpose, with the name SkillLong[0] ... SkillLong[7]. Instead of defining crossed as static, in a portfolio script you would write at the begin of the function

int crossed = SkillLong[0];

for loading the variable content from SkillLong[0]. And for storing it again after it was modified in the function, add this line at the end:

SkillLong[0] = crossed;

The "crossed" variable can now have a different content for any asset.

Re: My Take on A Mega Script [Re: jcl] #408091
09/25/12 06:37
09/25/12 06:37

L
liftoff
Unregistered
liftoff
Unregistered
L



Will go over everything and try implementing it

Re: My Take on A Mega Script [Re: ] #408151
09/26/12 15:13
09/26/12 15:13

L
liftoff
Unregistered
liftoff
Unregistered
L



Tried implementing the concepts and error again.
Code:
// Workshop 6: Portfolio trading ///////////////////

function tradeTrend()
{
	TimeFrame = 1;
	var *Price = series(price());
	var *Trend = series(LowPass(Price,optimize(250,100,1000)));
	Stop = optimize(2,1,10) * ATR(100);
	
	if(strstr(Algo,":L") and valley(Trend)) 
		enterLong();
	else if(strstr(Algo,":S") and peak(Trend)) 
		enterShort();
}

function tradeCounterTrend()
{
	var *Price = series(price());
	var Threshold = optimize(1.0,0.5,2,0.1);
	var *DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	var *HP = series(HighPass(Price,LowPeriod*optimize(1,0.5,2)));
	var *Signal = series(Fisher(HP,500));
	Stop = optimize(2,1,10) * ATR(100);

	if(strstr(Algo,":L") and crossUnder(Signal,-Threshold)) 
		enterLong(); 
	else if(strstr(Algo,":S") and crossOver(Signal,Threshold)) 
		enterShort();
}

function HuckTrend()
{
	
	TimeFrame = 1;
	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 crossed = SkillLong[0]
	
	
	
	if(crossOver(LP5,LP10))
		crossed = Delay;
	else if(crossUnder(LP5,LP10))
		crossed = -Delay;
		
	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
		SkillLong[0] = crossed;
}

function run()
{
	set(PARAMETERS+FACTORS+LOGFILE); // use optimized parameters and reinvestment factors
	BarPeriod = 240;	// 4 hour bars
	LookBack = 500;	// needed for Fisher()
	NumWFOCycles = 8; // activate WFO
	NumBarCycles = 4;	// 4 times oversampling
	
	if(ReTrain) {
		UpdateDays = 30;	// reload new price data from the server every 30 days
		SelectWFO = -1;	// select the last cycle for re-optimization
	}
	
// portfolio loop
	while(asset(loop("EUR/USD","USD/CHF","GBP/USD","AUD/USD","USD/CAD","USD/JPY","USD/NZD",)))
	while(algo(loop("TRND:L","TRND:S","CNTR:L","CNTR:S","HuckTrend:L","HuckTrend:S")))
	{
// set up the optimal margin
		if(Train)
			Lots = 1;
		else if(strstr(Algo,":L") and OptimalFLong > 0) {
			Lots = 1;			 
			Margin = clamp((WinLong-LossLong) * OptimalFLong/2, 50, 10000);
		} else if(strstr(Algo,":S") and OptimalFShort > 0) {
			Lots = 1;
			Margin = clamp((WinShort-LossShort) * OptimalFShort/2, 50, 10000);
		} else
			Lots = 0; // switch off trading

		if(strstr(Algo,"TRND")) 
			tradeTrend();
		else if(strstr(Algo,"CNTR")) 
			tradeCounterTrend();
		     else if(strstr(Algo,"HuckTrend")) 
			  HuckTrend();	
			
	}
	
	PlotWidth = 1000;
	PlotHeight1 = 320;
}


Last edited by liftoff; 09/26/12 15:22.
Re: My Take on A Mega Script [Re: ] #408535
10/03/12 13:27
10/03/12 13:27

L
liftoff
Unregistered
liftoff
Unregistered
L



JCL I am having a hard time getting this to work. Can you please help me out?

Re: My Take on A Mega Script [Re: ] #408588
10/04/12 07:15
10/04/12 07:15
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
You have still not defined the Delay variable

int Delay = 3;

and there's something garbled now at the end of your function. crossed must be decremented. That was correct in your previous code.

Re: My Take on A Mega Script [Re: ] #408824
10/08/12 09:18
10/08/12 09:18
Joined: Oct 2012
Posts: 22
G
Guiom Offline
Newbie
Guiom  Offline
Newbie
G

Joined: Oct 2012
Posts: 22
Originally Posted By: liftoff
Tried implementing the concepts and error again.


I think that's the code for what you wanted to do, you had a missing ";" after int crossed = SkillLong[0], missing declaration of Delay and an extra "," at the end of while(asset(loop...))

I only tested/optimized with EURUSD and USDCHF and it took almost an hour and the result isn't interesting:
Profit 5934 MI 211 DD 6104 Capital 6861
Trades 218 Win 33% Avg +27.22 Bars 81
AR 37% PF 1.32 SR 0.47 UI 47.9% Error 35%

Code:
// Portfolio trading: Trend, Counter Trend and Huck Trend ///////////////////

function tradeTrend()
{
	TimeFrame = 1;
	var *Price = series(price());
	var *Trend = series(LowPass(Price,optimize(250,100,1000)));
	Stop = optimize(2,1,10) * ATR(100);
	
	if(strstr(Algo,":L") and valley(Trend)) 
		enterLong();
	else if(strstr(Algo,":S") and peak(Trend)) 
		enterShort();
}

function tradeCounterTrend()
{
	var *Price = series(price());
	var Threshold = optimize(1.0,0.5,2,0.1);
	var *DomPeriod = series(DominantPeriod(Price,30));
	var LowPeriod = LowPass(DomPeriod,500);
	var *HP = series(HighPass(Price,LowPeriod*optimize(1,0.5,2)));
	var *Signal = series(Fisher(HP,500));
	Stop = optimize(2,1,10) * ATR(100);

	if(strstr(Algo,":L") and crossUnder(Signal,-Threshold)) 
		enterLong(); 
	else if(strstr(Algo,":S") and crossOver(Signal,Threshold)) 
		enterShort();
}

function HuckTrend()
{
	
	TimeFrame = 1;
	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 crossed = SkillLong[0];
	int Delay = 3;
	
	
	if(crossOver(LP5,LP10))
		crossed = Delay;
	else if(crossUnder(LP5,LP10))
		crossed = -Delay;
		
	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
		SkillLong[0] -= sign(crossed);
}

function run()
{
	set(PARAMETERS+FACTORS+LOGFILE); // use optimized parameters and reinvestment factors
	BarPeriod = 240;	// 4 hour bars
	LookBack = 500;	// needed for Fisher()
	NumWFOCycles = 8; // activate WFO
	NumBarCycles = 4;	// 4 times oversampling
	
	if(ReTrain) {
		UpdateDays = 30;	// reload new price data from the server every 30 days
		SelectWFO = -1;	// select the last cycle for re-optimization
	}
	
// portfolio loop
	while(asset(loop("EUR/USD","USD/CHF")))
	while(algo(loop("TRND:L","TRND:S","CNTR:L","CNTR:S","HuckTrend:L","HuckTrend:S")))
	{
// set up the optimal margin
		if(Train)
			Lots = 1;
		else if(strstr(Algo,":L") and OptimalFLong > 0) {
			Lots = 1;			 
			Margin = clamp((WinLong-LossLong) * OptimalFLong/2, 50, 10000);
		} else if(strstr(Algo,":S") and OptimalFShort > 0) {
			Lots = 1;
			Margin = clamp((WinShort-LossShort) * OptimalFShort/2, 50, 10000);
		} else
			Lots = 0; // switch off trading

		if(strstr(Algo,"TRND")) 
			tradeTrend();
		else if(strstr(Algo,"CNTR")) 
			tradeCounterTrend();
		     else if(strstr(Algo,"HuckTrend")) 
			  HuckTrend();	
			
	}
	
	PlotWidth = 1000;
	PlotHeight1 = 320;
}


Re: My Take on A Mega Script [Re: Guiom] #408835
10/08/12 13:46
10/08/12 13:46

L
liftoff
Unregistered
liftoff
Unregistered
L



Thank you mate. I did the corrections myself over the weekend and tested it... It didn't turn out too great. it was profitable but required too high a capital, I think something like 10,000.

Page 1 of 5 1 2 3 4 5

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