0 registered members (),
677
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
tomaslolo
OP
Junior Member
|
OP
Junior Member
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. // 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: 296 Netherlands
Grant
Member
|
Member
Joined: Aug 2017
Posts: 296
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]
#485574
03/25/22 14:01
03/25/22 14:01
|
Joined: Feb 2018
Posts: 68
tomaslolo
OP
Junior Member
|
OP
Junior Member
Joined: Feb 2018
Posts: 68
|
Ok, then new version. I don´t use "ifelse" to run a code neither "=" in if condition. // 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,731 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,731
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.htmAlso, learn the difference between global and local variables: https://zorro-trader.com/manual/en/aarray.htmAt the end of the day, your computer does not do what you want it to do, but what you tell it to do.
|
|
|
|