Gamestudio Links
Zorro Links
Newest Posts
Zorro and IB Gateway
by cwford. 04/07/20 00:31
MT4 bridge: Check account number
by tradingest. 04/06/20 12:36
Loging off automatically ?
by jcl. 04/06/20 12:25
zorro contract example
by jcl. 04/06/20 09:22
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
4 registered members (Lozoteva, jbhunter, 3run, Stansmedia), 642 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
vishal, tanhwuser, beo, marsz, gonzalez21
18413 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Group trades by parameters #478318
10/01/19 19:15
10/01/19 19:15
Joined: Oct 2019
Posts: 3
F
filip Offline OP
Guest
filip  Offline OP
Guest
F

Joined: Oct 2019
Posts: 3
Hello everyone, I am developing mean-reversion script on 4 FX pairs (strategy is always one currency long and one currency short). The script relies on 2 parameters and I would like to group trades by these parameters so that I can calculate information ratio for each of the parameter combinations. I am doing this using evaluate() and I found interesting behaviour:

Code
        for(all_algos)
        {
		int algocount = 0;
		
		for(all_trades)
		{
			algocount++;
		}
		
		print(TO_REPORT, "\n%d", algocount);
	}


Produces the correct total number of trades (multiple times). However, I would also except that this gives the same (only once):

Code
	int algocount = 0;
	for(all_algos)
	{
		for(all_trades)
		{
			if(TradeAlgo == Algo)
			{
			algocount++;
			}
		}
	}
	print(TO_REPORT, "\n%d", algocount);


The number produced is the total number of long trades only. Is this behaviour intended? How could I achieve the grouping of all trades?
Thanks a lot.

Re: Group trades by parameters [Re: filip] #478319
10/01/19 19:37
10/01/19 19:37
Joined: Feb 2017
Posts: 908
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 908
Chicago
Post your entire script.

Re: Group trades by parameters [Re: filip] #478320
10/01/19 20:25
10/01/19 20:25
Joined: Oct 2019
Posts: 3
F
filip Offline OP
Guest
filip  Offline OP
Guest
F

Joined: Oct 2019
Posts: 3
The trading logic is from RobotWealth FXbootcamp, so I am not sure if I can post it here. I think this should be reproducible on any strategy that trades different assets and params. Basically I am doing this:

Code
trade_function(some params, param_1, param_2);
algo(strf("lb_%d_re_%d", param_1, param_2);


trade_function cycles through the pairs and selects the ones for trading orders enterShort(), enterLong().

Re: Group trades by parameters [Re: filip] #478322
10/02/19 13:03
10/02/19 13:03
Joined: Feb 2017
Posts: 908
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 908
Chicago
Well, without looking at your full script:
* How do you even know that you are only counting the long trades? I see no use of TradeIsLong. Isolate, isolate, isolate.
* I suggest printing detailed information about every trade for debugging purposes.

https://zorro-project.com/manual/en/fortrades.htm
https://zorro-project.com/manual/en/trade.htm

Re: Group trades by parameters [Re: filip] #478323
10/02/19 21:00
10/02/19 21:00
Joined: Oct 2019
Posts: 3
F
filip Offline OP
Guest
filip  Offline OP
Guest
F

Joined: Oct 2019
Posts: 3
I did some experiments and found that this approach is not right. You can not simply nest the all_algos loop with the all_trades loop. (as these loops are not documented, they should not be used in other way than the official examples) Returning back to the original goal: Grouping trades by params can be for example achieved just by using all_trades and TradeVars. See the two examples, why the nesting approach is flawed:

Code
	for(all_algos)
	{
		for(all_trades)
		{
			print(TO_REPORT, "\n%s", Algo);
		}
	}
}


Does not produce output with multiple algo names. It is just stuck on one. Whereas this code does it:

Code
	for(all_algos)
	{
		print(TO_REPORT, "\n%s", Algo);
		for(all_trades)
		{
			continue;
		}
	}

Re: Group trades by parameters [Re: filip] #478324
10/02/19 22:23
10/02/19 22:23
Joined: Feb 2015
Posts: 588
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 588
Milano, Italy
Well, you are swimming in dangerous waters... From the manual: "The above enumeration loops are macros defined in include\variables.h. Unlike a normal for loop, enumeration loops cannot be nested, and they must not be aborted by break or return statements. The break_trades macro can be used to abort trade loops. "

A better approach might be to write a new macro from scratch, not using the predefined ones in order to avoid unpredictable behaviors...


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