Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Optimization #463553
12/12/16 14:40
12/12/16 14:40
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Hi,
I was experimenting a script found in the manual
Code:
// Currency Strength Strategy /////////////////////
// Exploits price shocks f.i. by CHF cap and Brexit

function run()
{
	set(PARAMETERS);  // Not as original
 	NumYears = 7; 		// Not as original
  	BarPeriod = 60;
  	Margin = 50;  		// Not as original
  	ccyReset();  // reset strengths at begin of any bar
  
  	string Name;
  	while(Name = (loop(Assets)))
  	{
    	if(assetType(Name) != FOREX) 
      continue; // Currency pairs only
    	asset(Name);
    	vars Prices = series(priceClose());
    	ccySet(ROC(Prices, 1)); // store price change as strength
  	}
  
// get currency pairs with highest and lowest strength difference
  	string Best = ccyMax(), Worst = ccyMin();
  	var Threshold = optimize(1.0, 1.0, 2.0, 0.1);  // Not as original

  	static char OldBest[10], OldWorst[10];  // static for keeping contents between runs
  	if(*OldBest && !strstr(Best,OldBest)) { // new strongest asset?
  		asset(OldBest);
   	exitLong();
  		if(ccyStrength(Best) > Threshold) {
   		asset(Best);
     		enterLong();
   	}
  	} 
  
 	if(*OldWorst && !strstr(Worst,OldWorst)) { // new weakest asset?
   	asset(OldWorst);
   	exitShort();
   	if(ccyStrength(Worst) < -Threshold) {
      	asset(Worst);
      	enterShort();
   	}
  	}



The only modification was few lines in order to optimize the main parameter: Threshold . Unfortunately it does not work.
What Am I missing?

Thank you in advance

Re: Optimization [Re: MatPed] #463561
12/13/16 11:43
12/13/16 11:43
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
The asset is missing. Portfolio strategies optimize the parameters for every asset separately. This won't work in your script since you're optimizing the parameter outside the loop() while no asset is selected.

The solution is simply not to use the loop() function, which indicates a portfolio strategy, but a simple for(..) loop to enumerate the assets. Then Zorro thinks it's no portfolio and you can optimize the threshold regardless of the asset.

int i;
for(i=0; Name=Assets[i]; i++)
...


Re: Optimization [Re: jcl] #463564
12/13/16 16:58
12/13/16 16:58
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline OP
User
MatPed  Offline OP
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Thank you JCL. It works!


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1