Use 3 zorros, one for trading the other two for calculating

Posted By: tomaslolo

Use 3 zorros, one for trading the other two for calculating - 03/17/22 17:41

Hello, I keep travelling with zorro and the trading world.

I try many things but can't make It work.

My question: Os there a simple way of using diferentes zorro instantes and comunícate between them. Foto example:
Zorro1 calculates SMA(20)
Zorro2 calculates SMA(100)
Zorro3 recibes Zorro1 SMA(20) and Zorro2 SMA(100) and executes if(crossOver(Zorro1SMA(20), Zorro2SMA(100))
enterLong();

I have ZorroS

I've searched the manual, the control zorro section is difficilt to understand for me, I've seen Zorro control.cpp file un source folder but, even worse!!

I've learned to code Zorro, and I'm used to write scripts, sometimes I do wrong and sometimes fine. But can't imagine how to do this. I think is not very documented in the manual.

Any clues?
Posted By: NorbertSz

Re: Use 3 zorros, one for trading the other two for calculating - 03/17/22 18:03

I think you are looking for this feature:
https://zorro-project.com/manual/en/engine.htm
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/17/22 18:36

Yes, that is. But I thought there was an easier way.

Something like:

Code
function run()
{

Script="Zorro1/Strategies/SMA20.c"
//Someway to receive the var or the series generated by Zorro1

Script="Zorro2/Strategies/SMA100.c"
//Someway to receive the var or the series generated by Zorro2

if (crossOver(Zorro1SMA(20), Zorro2SMA(100)) 

enterLong();


Is there a way like this?

Or, is there code samples?

thank you!
Posted By: NorbertSz

Re: Use 3 zorros, one for trading the other two for calculating - 03/18/22 08:00

You can't just "import" the process by the source code, because the computer needs to run something for the calculations. So you need to start 3 different softwares (Zorros) in this case.

But are you sure you can't do all these calculations in one script?

The best way for data exchange between processes (softwares) is the "inter-process communication (IPC)". The good news is that you don't need to write it yourself or find a C library, because Zorro has already implement this by "memory mapping", you just need to use the built-in commands - see the manual above. There is no simpler way.

Alternatively you can write&read txt files for data exchange, but I don't recommend it because there are a lot of ways to do it wrong, and it's much slower than IPC. Also, you can check the method called "named pipes", but it's complicated:
https://www.google.com/search?q=named+pipes+example+c
Before I found Zorro, I made MT4 EAs, and here's the library I used for the interprocess communication:
https://www.fxblue.com/appstore/9/quickchannel

But as far as I see, Zorro's built-in method is much better and simpler than these all.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/18/22 14:02

Thank you for your reply.

I was trying to do it with algo(loop) but can´t make it work.

I have two deepnet models and want to use them at the same time, but as "advise" function is a little blackbox I don´t finf the way to use the loop. It only loads last .ml file. That´s why I though I could use another zorro instance so I can load both models, evaluate and the third Zorro decides to go long or not. But it´s very difficult. I think it "easy" to start a Zorro instance but can´t imagine how to send var results from Zorro1 and Zorro2 to Zorro3.

This is the loop I was trying to use with one Zorro:

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


///////////////////////////////////////////////////////////////////////
#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;
	Script = "DL3kb";
	Script = "DL3kc";
	
	StartDate = 20190301;
	EndDate = 20200501;
	BarPeriod = 60;	// 1 hour
	LookBack = 100;

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

	assetList("AssetsFix");
	asset("EUR/USD");
	set(RULES);
	Spread = RollLong = RollShort = Commission = Slippage = 0;
	LifeTime = 3 ; 
	if(Train) Hedge = 2;

	
			////// MIS SEÑALES ///

	var Signals[9];  // hasta 15 sin problema
	Signal[0]=change(1);
	Signal[1]=change(2);
	Signal[2]=change(3);
	Signal[4]=change(4);
	Signal[5]=range(1);
	Signal[6]=range(2);
	Signal[7]=range(3);
	Signal[8]=range(4);
	
	
	var Threshold = 0.9;
	var Threshold1 = 0.1;
	var vLongb,vShortb,vLongc,vShortc;
	
		
	// aqui empiezo a hacer loop
	while(algo(loop("DN1","DN2"))){
	set(LOGFILE|PLOTNOW);
	if(Algo=="DN1"){
		if(Init) print(TO_WINDOW,"\nR DL1 and Deepnet required"); 
	Script = "DL3b";
	
	var vLongb = adviseLong(NEURAL+BALANCED,0,Signals,9);
	var vShortb = adviseShort(NEURAL+BALANCED,0,Signals,9);

	}

	if(Algo=="DN2"){
		if(Init) print(TO_WINDOW,"\nR DL2 and Deepnet required"); 
	Script = "DL3c";
	var vLongc = adviseLong(NEURAL+BALANCED,0,Signals,9);
	var vShortc = adviseShort(NEURAL+BALANCED,0,Signals,9);
	}
	
///////////////////////////////////////////////////////////	
// logic   //////////////////////////////////////////

if(vLongb> Threshold
and vShortb< Threshold1
and vLongc> Threshold
and vShortc < Threshold1
)	
		enterLong();

	if(vShortb> Threshold
and vLongb < Threshold1
and vShortc> Threshold
and vLongc < Threshold1
)	
	enterShort();
	
// plots  /////////////////////

	plot("Longb",vLongb,NEW|LINE,BLACK);
	plot("Longc",vLongc,NEW|LINE,BLUE);

	plot("Shortb",vShortb,NEW|LINE,GREY);
	plot("Shortc",vShortc,NEW|LINE,MAROON);

	}
}

Only loads last ml file, DL3c and plots are all zero. vLongb, vLongc, etc... don´t evaluate. I tried to defien them as "static var", tried different things but no way.

I think is´t something related wih advise function, but I can´t figure it out.

Do you find a way to use loop and evalute two ml models?

Thank you
Posted By: Petra

Re: Use 3 zorros, one for trading the other two for calculating - 03/18/22 17:22

I see many bugs. The "Script" lines make no sense and why do you call advise twice with the same signals? Also variables with the same name are defined multiple times, that is probably not intended.

There is a deepnet example, start from there and then add your own signals.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/18/22 17:44

Hello Petra!

"Script" lines because I though that way "loads" those r files.

I have two different model files, DL3b.ml and DL3c.ml If I use, for example, Keras I can rename "Script" line in the deeplearn script included in Zorro/Strategy folder

I can run the file to load one model, for example DL3b.ml, but I want to load two models, an evaluate both of them.

vLongb evaluates DL3b.ml and vLongc evaluates DL3c.ml. But I don´t find the way to use both models.

That´s why I wanted to use:

Code
 if(vLongb>threshold and vLongc>threshold) 
enterLong();

or similar logic.

As stated in the manual: https://zorro-project.com/manual/en/advisor.htm
Quote
However, different methods and signals can be used for different assets and algorithm identifiers, so call algo() for combining multiple advise methods in the same script. Ensemble or hybrid methods can also be implemented this way, using different algo identifiers.


But I don´t find the way of doing so. Can I "load" two models in the same script? With keras.

Not sure if I´ve explained well.

Thank you!
Posted By: Petra

Re: Use 3 zorros, one for trading the other two for calculating - 03/20/22 07:54

You can have 1000 models but use different algos for different models. Not "Script".

When you train for trade results you must enter a trade for each result, otherwise it wll obviously not work. Check out the examples.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/21/22 18:25

Yes, but I don´t find the way of using different algos with advice function,

I try with a loop, also without loop. For example, code below It´s supposed to load advice function twice but only loads last one.


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"); 

	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"){
	
	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);
}


I call script because each "script" load different ml files. Don´t know how to call different .ml files with advice function,in the same strategy.

Do I explain well what amI trying to do?

Thank you!
Posted By: Grant

Re: Use 3 zorros, one for trading the other two for calculating - 03/21/22 21:14

Are any of those 2 'if (Algo..' statements ever TRUE? I don't see any algo calls in your code.

https://zorro-project.com/manual/en/algo.htm
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/21/22 23:04

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.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/21/22 23:09

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
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/21/22 23:35

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.
Posted By: Grant

Re: Use 3 zorros, one for trading the other two for calculating - 03/21/22 23:56

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.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 11:11

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.
Posted By: Grant

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 11:25

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?
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 12:03

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???
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 12:06

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
Posted By: Grant

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 13:00

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?
Posted By: Petra

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 17:47

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.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/22/22 18:12

I'm not sure I understand what you mean.

I have previously trained both models as single strategies. I first have trained DeeplearnKeras1 and as another strategy I have trained DeeplearnKeras2.

So individually I can test and trade them. Both open trades, etc... work fine. But individually.

Now I want to test ( and If It works fine, trade) a single strategy using both models at the same time. So if both Vlong's are bigger than Threshold then EnterLong.

I mean, running two advise functions at the same time.

That's why I tried with algo(loop), justo trying to run two advise to get Vlong1 and Vlong2 in the same script.
Posted By: Spirit

Re: Use 3 zorros, one for trading the other two for calculating - 03/23/22 07:15

If youre still stuck you can always ask support for help, they help fix the bugs and make your script work.

I have not much ml experience but i know that you need a training target. If you use trades for a target and your script does not trade, it cannot train.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/23/22 08:29

Hello, I have already trained both models.

I will try wtih support but wanted to use the forum so probably more people can get the idea and may be useful for future questions.

I don´t want to train two models again. What I´m trying is to "ensemble" or use both models at the same time for Test/Trade. No more training is needed. If I test/trade each single strategy with its model, works fine. The problem is to have two different Long signals to enter/not enter the trade.

I´m not sure if I´m explaining well what I´m looking for.

Quote
vLong = adviseLong(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4));

Retuns a "var" value.

Quote

vLong1= adviseLong(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4));

Retunrs the same "var" value if I use the same model (.ml file) but if I use a different model (different .ml file) is a different value

So I want to use those different values (vLong and Vlong1) to enter or not a trade.

¿Have I explain well what I´m trying to do?


Thank you for your help.

Posted By: Petra

Re: Use 3 zorros, one for trading the other two for calculating - 03/24/22 07:42

If you have already trained the 4 models, you need no trades for training, but still need to fix the other bugs.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/24/22 09:51

Yes, that´s why I ask for help.

I don´t find the way to call two different advise functiones, to load both models in the same script.

I have tried dozens of alternatives. Always loads one model or the other, but no both.
Posted By: jcl

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 06:48

Two models are always available. adviseLong/Short can train and use totally different models. For more than 2, just have multiple algos. Check out workshop 6. It's for optimizing, but would work in the same way for machine learning. If you're not making any progress, subscribe a support ticket and get help.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 08:48

Ok, I tried different approaches, including workshop 6.

I´ll reset and restart again.

Probably will be back here.... ;-)

Thank you!!
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 10:04

Hello again, I´m back!

Script adapted to what I´m trying:

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 Keras required"); 
	Script = "DeepLearnKeras1";
	
	bool sube1=false;
	bool baja1=false;
	var Threshold1 = 0.5;
	var vLong1,vShort1;
	
	
	if (vLong1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold1)
		return  sube1=true;
	
	
	
	if (vShort1 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold1)
		
		return  baja1=true;

}

function tradeDOS()
{
	if(Init) print(TO_WINDOW,"\nR and Keras required"); 
	Script = "DeepLearnKeras2";
	
	bool sube2=false;
	bool baja2=false;
	var Threshold2 = 0.5;
	var vLong2,vShort2;
	
	
	if (vLong2 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold2)
		return sube2=true;
	
	
	if (vShort2 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold2)
		
		return baja2=true;
}

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;

	while(algo(loop("TRND","CNTR")))
	{

		if(Algo == "TRND") 
			tradeUNO();
		else if(Algo == "CNTR") 
			tradeDOS();

	}
	
		
	if(sube1 and sube2)  // <<<----- THIS IS LINE 96
		enterLong();
	
	if(baja1 and baja2)
		enterShort();
	
	
	PlotWidth = 600;
	PlotHeight1 = 300;
}


As you may see, I want to enterLong if both conditions "sube1" and "sube2" are true. Same for enterShort with "baja1" and "baja2"

Problems:

1.- I´m not sure how "sube1, sube2, baja1 and baja2" returned values (true/false) can be red inside run() function.

Quote
WDL6 compiling........
Error in 'line 96:
'sube1' undeclared identifier
< if(sube1 and sube2)>.



Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 10:23

If I "declare" bool sube1, sube2, sube3 and sube4 if solves previous issue but then:

Problem 2: Can't go to FALSEGOTO:DOUBLE:: ---> Why is this error? I´m trying to obtain a true statement if a condition is true.

Quote
WDL6 compiling.........
Error in 'line 29:
Syntax error: Can't go to FALSEGOTO:DOUBLE::.
< range(1),range(2),range(3),range(4))>Threshold1) // line 28
>



This is same script with sube1, sube2, baja1 and baja2 declared:


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 Keras required"); 
	Script = "DeepLearnKeras1";
	
	bool sube1=false;
	bool baja1=false;
	var Threshold1 = 0.5;
	var vLong1,vShort1;
	
	
	if (vLong1 = adviseLong(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold1)  // line 28
							// line 29
		return sube1=true;		// line 30
	
	if (vShort1 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold1)
		
		return  baja1=true;

}

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

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

		return sube2=true;
	
	if (vShort2 = adviseShort(NEURAL+BALANCED,0,
	change(1),change(2),change(3),change(4),
		range(1),range(2),range(3),range(4))>Threshold2)

		return baja2=true;
}

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;
	
	bool sube1=false;  [color:#FF0000]//  DECLARED HERE TOO SO THERE´S NO ERROR MESSAGE[/color]
	bool baja1=false;
	bool sube2=false;
	bool baja2=false;
	
	while(algo(loop("TRND","CNTR")))
	{
		if(Algo == "TRND") 
			tradeUNO();
		else if(Algo == "CNTR") 
			tradeDOS();
	}
	
	if(sube1 and sube2)
		enterLong();
	
	if(baja1 and baja2)
		enterShort();
	

	PlotWidth = 600;
	PlotHeight1 = 300;
}



Thank you
Posted By: Grant

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 11:31

Why are you using vLong1 & vShort2? (which should be '==' in an if-statement if that was needed).

if(x == y > z) makes no logical sense

Check the condition example on https://zorro-project.com/manual/en/advisor.htm
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 12:01

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.
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 12:35

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.
Posted By: Grant

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 12:41

Almost there, always use '==' within an if/ifelse statement.
Posted By: AndrewAMD

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 12:59

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
Posted By: tomaslolo

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 14:01

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
Posted By: AndrewAMD

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 14:14

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.
Posted By: Spirit

Re: Use 3 zorros, one for trading the other two for calculating - 03/25/22 15:00

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.
© 2024 lite-C Forums