5 registered members (AndrewAMD, ozgur, Ayumi, 2 invisible),
690
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
trainroutine return & store / reuse
#478995
02/02/20 14:27
02/02/20 14:27
|
Joined: Mar 2019
Posts: 357
danatrader
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2019
Posts: 357
|
Hi, I try to establish a subroutine / function that measures market cycle length in train mode. Already somwhat working. So I call the following:
// double portfolio loop
while(asset(loop("EUR/USD")))
if(Train){
traincycles();
}
while(algo(loop("TRND")))
{
Margin = 0.5 * OptimalF * Capital;
if(Algo == "TRND")
tradeTrend();
The function itself contains the following:
function traincycles()
{
vars Prices = series(priceClose());
int Cycle = optimize(10, 1, 55, 1);
int CycleFast = optimize(10, 1, Cycle, 1);
int TrendCycle = (Cycle+CycleFast)/2;
vars Signals = series(ReFlex(Prices,Cycle));
vars SignalsFast = series(ReFlex(Prices,CycleFast));
//Good Cycle Train Algo II
if(SignalsFast[0] > 0 && Signals[0] > 0) enterShort();
if(SignalsFast[0] < 0 && Signals[0] < 0) enterLong();
return(TrendCycle);
}
Now the question is, how to store the return value global and make it available for
while(algo(loop("TRND")))
{
Margin = 0.5 * OptimalF * Capital;
if(Algo == "TRND")
tradeTrend();
???
Last edited by danatrader; 02/02/20 14:27.
|
|
|
Re: trainroutine return & store / reuse
[Re: danatrader]
#478996
02/02/20 15:14
02/02/20 15:14
|
Joined: Mar 2019
Posts: 357
danatrader
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2019
Posts: 357
|
Assume using AlgoVar is the choice? Now I save them with
if(Train && TrainCycle == 1){
SaveMode = SV_ALGOVARS+SV_ALGOVARS2;
AlgoVar[0] = traincycles();
}
Is that correct? How do I make use of the AlgoVar specified by the Asset / Algo it was generated for? Is that handled internally by Zorro or is that something I have to do?
Last edited by danatrader; 02/02/20 16:03.
|
|
|
Re: trainroutine return & store / reuse
[Re: danatrader]
#478999
02/02/20 16:40
02/02/20 16:40
|
Joined: Mar 2019
Posts: 357
danatrader
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2019
Posts: 357
|
Thank you Andrew, I will change it.
But how do I make sure the traincycle result is saved for later use on the specific asset / algo?
I will fight my way through, I am thankful for your advice.
Last edited by danatrader; 02/02/20 16:42.
|
|
|
Re: trainroutine return & store / reuse
[Re: danatrader]
#479001
02/02/20 18:29
02/02/20 18:29
|
Joined: Mar 2019
Posts: 357
danatrader
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2019
Posts: 357
|
Great, thank you a lot, I call it from inside the trend. Passing everything as argument. Step by step, getting there. Looks actually a lot nicer. Okay, now that brings another problem. I have a nice function to train the curves, I can also look at them in TEST. But things change, once I try to add the real trading rules. Either they are included in the train run, or in test, they are not shown. Below full script so far.
#include <default.c>
#include <Reflex.c>
function traincycles(vars Prices, int Cycle, int CycleFast, vars Signals, vars SignalsFast)
{
if(SignalsFast[0] > 0 && Signals[0] > 0) enterShort();
if(SignalsFast[0] < 0 && Signals[0] < 0) enterLong();
}
function tradeTrend()
{
vars Prices = series(priceClose());
int Cycle = optimize(10, 1, 55, 1);
int CycleFast = optimize(1, 1, Cycle, 1);
vars Signals = series(ReFlex(Prices,Cycle));
vars SignalsFast = series(ReFlex(Prices,CycleFast));
if(Train && !Test){
traincycles(Prices, Cycle, CycleFast, Signals, SignalsFast);
}
int TrendCycle = Cycle + CycleFast;
vars SignalsTrend = series(TrendFlex(Prices,TrendCycle));
plot("ReFlex",Signals,NEW|LINE,RED);
plot("ReFlexFast",SignalsFast,LINE,GREEN);
plot("TrendFlex",SignalsTrend,LINE,YELLOW);
}
function run()
{
if (is(INITRUN)) NumCores = 16;
set(PARAMETERS+FACTORS+LOGFILE);
BarPeriod = 1440;
LookBack = 2000;
StartDate = 2005;
NumTrainCycles = 3;
//NumWFOCycles = 10;
Capital = 10000;
MaxLong = MaxShort = 1;
Hedge=5;
if(ReTrain) {
UpdateDays = -1;
SelectWFO = -1;
reset(FACTORS);
}
// double portfolio loop
while(asset(loop("EUR/USD")))
while(algo(loop("TRND")))
{
Margin = 0.5 * OptimalF * Capital;
if(Algo == "TRND")
tradeTrend();
}
}
Now I want to start adding simple "real rules" in the TREND Algo. They should not be part of Train, but be part of Test, while the call off the traincycles function should be called always in test, but only in train on demand (e.g. edit script).
if(valley(SignalsTrend))
enterLong();
if(peak(SignalsTrend))
enterShort();
Last edited by danatrader; 02/02/20 18:56.
|
|
|
Re: trainroutine return & store / reuse
[Re: danatrader]
#479007
02/03/20 19:57
02/03/20 19:57
|
Joined: Mar 2019
Posts: 357
danatrader
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2019
Posts: 357
|
Well, the curves are nice, the idea behind seems to work, BUT,
I am still lacking some dev skills.
How would I transfer the
optimize(10, 1, 55, 1) and optimize(1, 1, Cycle, 1)
to the function traincycles???
Second question, how would I pass back two values to the calling function.
Or, is it possible to directly modify them in the function traincycles? I know that is not (if possible in C) good practice, to modify global variables inside a function instead of handing them back out.
|
|
|
Re: trainroutine return & store / reuse
[Re: danatrader]
#479009
02/03/20 22:01
02/03/20 22:01
|
Joined: Feb 2017
Posts: 1,731 Chicago
AndrewAMD
Serious User
|
Serious User
Joined: Feb 2017
Posts: 1,731
Chicago
|
You're already passing the optimized values into the function. Simply use them.
EDIT: If you want to edit the values and retain the edits in the original variables, pass pointers instead of values. If you don't know what that means, either learn C or eliminate the function entirely and move the functionality into the body so you don't have to worry about pointers.
Last edited by AndrewAMD; 02/03/20 22:33.
|
|
|
|