Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 984 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 4 1 2 3 4
Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485539
03/21/22 23:04
03/21/22 23:04
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
I first tried with loop:

Code
while(algo(loop("DeepLearnKeras1","DeepLearnKeras2"))){


But only loads DeepLearnKeras2.ml file, no way to load first DeepLearnKeras1.ml so I don´t find the way to load both models in the same script/strategy.

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485540
03/21/22 23:09
03/21/22 23:09
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
This is the full code with algo loop:

Code
// Deep Learning Test ///////////////////////////////////////////

//#define DO_SIGNALS  // generate sample set in Train mode
//#define DEEPNET
//#define H2O 
//#define MXNET
#define KERAS

///////////////////////////////////////////////////////////////////////
#include <r.h>

var change(int n)
{
	return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}

var range(int n)
{
	return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}

///////////////////////////////////////////////////////////////////////

function run()
{
	NumCores = -1;
	StartDate = 20170101;
	EndDate= 20190101;
	BarPeriod = 1440;	// 1 hour
	LookBack = 100;

	//WFOPeriod = 252*24; // 1 year
	//DataSplit = 90;

	assetList("AssetsDarwinexFMB");
	asset("EUR/USD");
	set(RULES);
	Spread = RollLong = RollShort = Commission = Slippage = 0;
	LifeTime = 3;
	if(Train) Hedge = 2;
	
	var Threshold = 0.5;
	var vLong,vShort,vLong1,vShort1;
///////////////////////////////////////////////////////////	

	SelectWFO = -1; // use the last WFO cycle for calibrating the neural net

	set(LOGFILE|PLOTNOW);
	if(Init) print(TO_WINDOW,"\nR1 and Keras required"); 

	while(algo(loop("DeepLearnKeras1","DeepLearnKeras2"))){
	
	if(Algo = "DeepLearnKeras1"){
		Script = "DeepLearnKeras1";
	vLong = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
		
		vShort = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
	}
		if(Init) print(TO_WINDOW,"\nR and Keras required"); 
	//Script = "DeepLearnKeras1";
	
	//if (Algo = "DeepLearnKeras2"){
	
	if(Algo = "DeepLearnKeras2"){
		Script = "DeepLearnKeras2";
		
		vLong1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
		
		vShort1 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
	}


		if (vLong > Threshold
		and vLong1 > Threshold )	
		enterLong();

	if(vShort  > Threshold
	and vShort1  > Threshold)
		enterShort();

	plot("Long",vLong,NEW|LINE,BLACK);
	plot("Short",vShort,NEW|LINE,GREY);
		plot("Long1",vLong1,NEW|LINE,BLUE);
	plot("Short1",vShort1,NEW|LINE,RED);
}
	}


If I click Test:

Quote
DeepLearnK1y2ensemble2 compiling..............
R1 and Keras required
R and Keras required
R and Keras required
Test: DeepLearnK1y2ensemble2 EUR/USD 2017..2019
Assets AssetsDarwinexFMB
Load DeepLearnKeras2.ml
Loss -4.93$ MI -0.21$ DD 4.93$ Capital 11.30$
Trades 1 Win 0.0% Avg -49.3p Bars 4
AR -22% PF 0.00 SR 0.00 UI 0% R2 0.00


So no way to use both .ml files (DeepLearnKeras1.ml and DeepLearnKeras2.ml).

Is there someway to do it?

Thank you

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485541
03/21/22 23:35
03/21/22 23:35
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
It doesn´t work this way either:

Code
// Deep Learning Test ///////////////////////////////////////////

//#define DO_SIGNALS  // generate sample set in Train mode
//#define DEEPNET
//#define H2O 
//#define MXNET
#define KERAS

///////////////////////////////////////////////////////////////////////
#include <r.h>

var change(int n)
{
	return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}

var range(int n)
{
	return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}


function DL1()
{
	var vLong,vShort;
	if(Init) print(TO_WINDOW,"\nR DL1 and Keras required"); 
	Script = "DeepLearnKeras1";
	vLong = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
		
	vShort = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
		
		return vLong;
		return vShort;
}
	
	
function DL2()
{
	var vLong1,vShort1;
	if(Init) print(TO_WINDOW,"\nR DL2 and Keras required"); 
	Script = "DeepLearnKeras2";
	vLong1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
		
	vShort1 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4));
		
		return vLong1;
		return vShort1;
}
	


///////////////////////////////////////////////////////////////////////

function run()
{
	NumCores = -1;
	StartDate = 20170101;
	EndDate= 20190101;
	BarPeriod = 1440;	// 1 hour
	LookBack = 100;

	//WFOPeriod = 252*24; // 1 year
	//DataSplit = 90;

	assetList("AssetsDarwinexFMB");
	asset("EUR/USD");
	set(RULES);
	Spread = RollLong = RollShort = Commission = Slippage = 0;
	LifeTime = 3;
	if(Train) Hedge = 2;
	
	var Threshold = 0.5;
	var vLong,vShort,vLong1,vShort1;
///////////////////////////////////////////////////////////	

	//SelectWFO = -1; // use the last WFO cycle for calibrating the neural net

	set(LOGFILE|PLOTNOW);
	
	while(algo(loop("DeepLearnKeras1","DeepLearnKeras2"))){
	
	if(Algo == "DeepLearnKeras1")
		DL1();

	if(Algo == "DeepLearnKeras2")
		DL2();
		
	
		if (vLong > Threshold
		and vLong1 > Threshold )	
		enterLong();

	if(vShort  > Threshold
	and vShort1  > Threshold)
		enterShort();

	plot("Long",vLong,NEW|LINE,BLACK);
	plot("Short",vShort,NEW|LINE,GREY);
		plot("Long1",vLong1,NEW|LINE,BLUE);
	plot("Short1",vShort1,NEW|LINE,RED);
}
	}



So, I try different things but no success.

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485542
03/21/22 23:56
03/21/22 23:56
Joined: Aug 2017
Posts: 296
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 296
Netherlands
Correct, it should be '==' for 'if(Algo =='

Not sure why it's still not working with the algo loop defined. I would suggest to include some printf() checks for conditions & values.

Last edited by Grant; 03/22/22 00:49.
Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485544
03/22/22 11:11
03/22/22 11:11
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
Prints

Quote
DLK1y2ensemble3 compiling...............
R DL1 and Keras required
R DL2 and Keras required
Test: DLK1y2ensemble3 EUR/USD 2017..2019
Assets AssetsDarwinexFMB
Load DeepLearnKeras2.ml



So runs through function DL1() and function DL2() but only loads DeepLearnKeras2.ml.

Anyway even loading DeepLearnKeras2.ml, vLong1 and vLong2 does not return any values.

So I´m stucked trying to make it work.

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485545
03/22/22 11:25
03/22/22 11:25
Joined: Aug 2017
Posts: 296
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 296
Netherlands
Are you able to load DeepLearnKeras1.ml successfully without calling DeepLearnKeras2.ml as well? Maybe the DeepLearnKeras1.ml file is corrupt or unavailable on its location?

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485546
03/22/22 12:03
03/22/22 12:03
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
Yes I can:

Quote
DLK1y2ensemble3 compiling..............
R DL1 and Keras required
Test: DLK1y2ensemble3 EUR/USD 2017..2019
Assets AssetsDarwinexFMB
Load DeepLearnKeras1.ml


But does not returns any value for vLong and vShort either.

Can´t figure out how to make advise function run twice with different .ml files (keras).

Any idea???

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485547
03/22/22 12:06
03/22/22 12:06
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
ml files exits, If I run a simple strategy with only one funcion can load either DeepLearnKeras1.ml o DeepLearnKeras2.ml and returns correct vlong/vShort or vLong1/vShort1 values.

But can´t load both models in same strategy, neither with loop

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485548
03/22/22 13:00
03/22/22 13:00
Joined: Aug 2017
Posts: 296
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 296
Netherlands
I don't work with Keras myself, so I'm not sure why you can't call the first .ml file.

Maybe Petra or someone else can comment on your most recent code?

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485549
03/22/22 17:47
03/22/22 17:47
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
Still the same bugs, the "Script" lines, wrong defined variables and training trade results with no trading. It seems your algos do not trade at all because the if condition is never true.

If you want to train on trade returns then you must really enter trades, both long and short, and for both algos. Or you use another training target.

This has nothing to do with keras, it is the same with any machine learning method.

Page 2 of 4 1 2 3 4

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1