Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Nymphodora, Quad), 919 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
trainroutine return & store / reuse #478995
02/02/20 14:27
02/02/20 14:27
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

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:

Code
// 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:

Code
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


Code
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
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Assume using AlgoVar is the choice?

Now I save them with

Code

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] #478997
02/02/20 16:33
02/02/20 16:33
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
First of all, never put optimize() and series() calls inside of if(Train). This will screw up your script.

Next, your traincycles() call should be inside of if(Algo == "TRND"). So either tradeTrend() would have the traincycle as an argument, or you could even call traincycles() inside of tradeTrend().

Re: trainroutine return & store / reuse [Re: danatrader] #478999
02/02/20 16:40
02/02/20 16:40
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

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] #479000
02/02/20 16:45
02/02/20 16:45
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Train mode will optimize the optimize calls. Zorro saves the respective values for the optimize() calls. After you [Train], those optimal values will be retrieved in [Test] and [Trade] modes.

Re: trainroutine return & store / reuse [Re: danatrader] #479001
02/02/20 18:29
02/02/20 18:29
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

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.


Code

#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).

Code
	if(valley(SignalsTrend))
		enterLong();
	if(peak(SignalsTrend))
		enterShort();


Last edited by danatrader; 02/02/20 18:56.
Re: trainroutine return & store / reuse [Re: danatrader] #479002
02/02/20 19:15
02/02/20 19:15
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
It works great with commenting out... as intended, now I got some nicely matching curves and a trigger.

Re: trainroutine return & store / reuse [Re: danatrader] #479007
02/03/20 19:57
02/03/20 19:57
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

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,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
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.
Re: trainroutine return & store / reuse [Re: danatrader] #479015
02/04/20 20:15
02/04/20 20:15
Joined: Mar 2019
Posts: 357
D
danatrader Offline OP
Senior Member
danatrader  Offline OP
Senior Member
D

Joined: Mar 2019
Posts: 357
Thank you again.

Yes learn C, Zorro is my vehicle for doing so.

I got at least now the function running with pointers.
Thank you for the hint.

I assume I still have plenty of mistakes, but sometimes those hints are the really valuable things.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1