Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (howardR), 1,065 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 4 of 4 1 2 3 4
Re: Use 3 zorros, one for trading the other two for calculating [Re: Grant] #485570
03/25/22 12:01
03/25/22 12:01
Joined: Feb 2018
Posts: 68
T
tomaslolo Offline OP
Junior Member
tomaslolo  Offline OP
Junior Member
T

Joined: Feb 2018
Posts: 68
Sorry, I don´t understand what you mean.

vLong1 is a var, returns a value when calling adviseLong with DeepLearnKeras1.ml file.

vShort2 is a different var, returns a value when calling adviseShort with DeepLearnKeras2.ml file.

They can be equal or not, but I just use them to compare with a value (Threshold, 0.5) and decide if is a long/short signal.

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

Joined: Feb 2018
Posts: 68
This is another version of strategy. As it seems to be a probelem to return a True/False value from if condition, I have used an ifelse and return a var value.

Code
// WDL6 trying to make it work ///////////////////

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 tradeUNO()
{
	if(Init) print(TO_WINDOW,"\nR and Keras1 required"); 
	Script = "DeepLearnKeras1";
	set(RULES);
	
	var sube1=3;
	var baja1=3;
	var Threshold1 = 0.5;
	var vLong1,vShort1;
	
	ifelse((vLong1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4))>Threshold1),sube1=5.0,sube1=2.0);
		
	ifelse((vShort1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4))>Threshold1),baja1=5.0,baja1=2.0);

return sube1;
return baja1;
}

function tradeDOS()
{
	if(Init) print(TO_WINDOW,"\nR and Keras2 required"); 
	Script = "DeepLearnKeras2";
	set(RULES);

	var sube2=3;
	var baja2=3;
	var Threshold2 = 0.5;
	var vLong2,vShort2;
	
	ifelse((vLong2 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4))>Threshold2),sube2=5.0,sube2=2.0);
	
	ifelse((vShort2 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold2),baja2=5.0,baja2=2.0);

return sube2;
return baja2;
}

function run()
{
	NumCores = -2;		// use multiple cores (Zorro S only)
	StartDate = 20170101;
	EndDate= 20190101;
	BarPeriod = 1440;	// 1 hour
	LookBack = 100;

	assetList("AssetsDarwinexFMB");
	asset("EUR/USD");
	set(RULES);
	LifeTime=3;
	
	var sube1=1.8;
	var baja1=1.8;
	var sube2=1;
	var baja2=1;
	
	while(algo(loop("TRND","CNTR")))
	{
		if(Algo == "TRND") 
			tradeUNO();
		else if(Algo == "CNTR") 
			tradeDOS();
	}
	
	if(sube1>4 and sube2>4)
		enterLong();
	
	if(baja1>4 and baja2>4)
		enterShort();
	//}
	PlotWidth = 600;
	PlotHeight1 = 300;
	
	plot("sube1",sube1,NEW|LINE,BLACK);
	plot("baja1",baja1,NEW|LINE,GREY);
	plot("sube2",sube2,NEW|LINE,BLUE);
	plot("baja2",baja2,NEW|LINE,RED);
}


Compiles, no errors, ...... But sube1, baja1, sube2 and baja2 always returns the value indicated in run() function (lines below LifeTime=3, 1.8, 1.8, 1, 1)

Seems like it does not run tradeUNO(); and tradeDOS(); functions.

Any clues?

Thank you.

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

Joined: Aug 2017
Posts: 294
Netherlands
Almost there, always use '==' within an if/ifelse statement.

Last edited by Grant; 03/25/22 13:37.
Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485573
03/25/22 12:59
03/25/22 12:59
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
You're using ifelse() incorrectly. Its output is to return a value, not execute a line of code.

Description is here:
https://manual.zorro-project.com/ifelse.htm

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

Joined: Feb 2018
Posts: 68
Ok, then new version. I don´t use "ifelse" to run a code neither "=" in if condition.

Code
// WDL6 trying to make it work ///////////////////

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 tradeUNO()
{
	if(Init) print(TO_WINDOW,"\nR and Keras1 required"); 
	Script = "DeepLearnKeras1";
	set(RULES);
	
	var sube1=3;
	var baja1=3;
	var Threshold1 = 0.5;
	var vLong1,vShort1;
	
	vLong1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4));
	
	if (vLong1>Threshold1)
		sube1=5.0;
	
	vShort1 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4));
	
	if (vShort1>Threshold1)
		baja1=5.0;

return sube1;
return baja1;
}

function tradeDOS()
{
	if(Init) print(TO_WINDOW,"\nR and Keras2 required"); 
	Script = "DeepLearnKeras2";
	asset("EUR/USD");
	set(RULES);

	var sube2=3;
	var baja2=3;
	var Threshold2 = 0.5;
	var vLong2,vShort2;
	
	vLong2 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4));
	
	if (vLong2>Threshold2)
		sube2=5.0;
	
	vShort2 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
	range(1),range(2),range(3),range(4));
	
	if (vShort2>Threshold2)
		baja2=5.0;

return sube2;
return baja2;
}

function run()
{
	set(PLOTNOW);
	NumCores = -1;		// use multiple cores (Zorro S only)
	StartDate = 20170101;
	EndDate= 20190101;
	BarPeriod = 1440;	// 1 hour
	LookBack = 100;

	assetList("AssetsDarwinexFMB");
	asset("EUR/USD");
	set(RULES);
	LifeTime=3;
	
	var sube1=1.5;
	var baja1=1.5;
	var sube2=1;
	var baja2=1;
	
	while(algo(loop("TRND","CNTR")))
	{
		if(Algo == "TRND") 
			tradeUNO();
		else if(Algo == "CNTR") 
			tradeDOS();
	}
	
	if(sube1>4 and sube2>4)
		enterLong();
	
	if(baja1>4 and baja2>4)
		enterShort();
	//}
	PlotWidth = 600;
	PlotHeight1 = 300;
	
	plot("sube1",sube1,NEW|LINE,BLACK);
	plot("baja1",baja1,NEW|LINE,GREY);
	plot("sube2",sube2,NEW|LINE,BLUE);
	plot("baja2",baja2,NEW|LINE,RED);
}


Keeps returning same values for "sube1, baja1, sube2 and baja2". Always returns the value indicated in run() function (lines below LifeTime=3, 1.8, 1.8, 1, 1)

Is tradeUNO() function running and the adviseLong() function running too?

Thank you

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485575
03/25/22 14:14
03/25/22 14:14
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
Your code suggests that you don't know how function return values work.

A function can only return once with one value. Once it returns, the function is done.

Yet, I see you are returning multiple values from your functions tradeUNO and tradeDOS. Actually, only the first value gets returned.

Worse, you're not even making use of the function return value, where the functions were invoked.

Read this. See the section on return values:
https://zorro-project.com/manual/en/function.htm

Also, learn the difference between global and local variables:
https://zorro-trader.com/manual/en/aarray.htm

At the end of the day, your computer does not do what you want it to do, but what you tell it to do.

Re: Use 3 zorros, one for trading the other two for calculating [Re: tomaslolo] #485576
03/25/22 15:00
03/25/22 15:00
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
I think these many script versions also suggest an ineffective way of coding. When your code does not work, it seems you do not try to understand why, but wildly add more code. That will not fix the problem but make it worse.

Page 4 of 4 1 2 3 4

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1