loop(string Name1, string Name2, ... ) : string

loop(Assets) : string

Enumerate assets or algos for training their parameters or rules separately. The loop function gets a list of pointers, such as asset or algo name strings. In [Test] and [Trade] mode it returns the first pointer on the first call, the next pointer on the next call and so on. It returns 0 after the last pointer. In [Train] mode it returns the first pointer in the first component training cycle, the next pointer in the next cycle and so on. Component training cycles end after the last pointer.

of(string Name1, string Name2, ... ) : string

of(Assets) : string

Enumerate strings or pointers as above, but for general purposes and without the special behavior in [Train] mode.

Returns

Name1 on the first call or training cycle, Name2 on the next call or training cycle, and so on. The last call or cycle returns 0.

Parameters:

Name1, Name2 ...

Up to 40 pointers, all different, normally strings with an asset or algo name.

Assets

Predefined array with all asset names; used for enumerating all assets in the asset list.

 
The following variables are valid after a loop call (not used for of):

Loop1

Loop2

Current return value of the first and second loop, normally the current asset/algo name.

Itor1

Itor2

Current cycle number of the first and second loop, starting with 0.

NumLoops1

NumLoops2

Total number of cycles of the first and second loop.
 

Remarks:

Examples (see also Workshop 6):

// of() nesting
string Str1,Str2,Str3;
while(Str1 = of("AA","BB","CC"))
while(Str2 = of("XX","YY","ZZ"))
while(Str3 = of("11","22","33"))
  printf("\n %s %s %s",Str1,Str2,Str3);

// filling a string array
string Strings[5];
for(i=0; Strings[i]=of("A","B","C","D","E"); i++);
// portfolio strategy with 3 assets and 3 trade algos, 
// all components separately trained, using loop()
 
function tradeTrendLong()
{
  var MyParameter = optimize(...);
  ...
}
 
function tradeTrendShort()
{
  var MyParameter = optimize(...);
  ...
}

function tradeBollinger()
{
  var MyParameter = optimize(...);
  ...
}
 
function run()
{
  while(asset(loop("EUR/USD","USD/CHF","GBP/USD"))) // loop through 3 assets
  while(algo(loop("TRL","TRS","BOL"))) // and 3 different trade algorithms
  { 
    if(Algo == "TRL") tradeTrendLong();
    else if(Algo == "TRS") tradeTrendShort();
    else if(Algo == "BOL") tradeBollinger();   
  }
}
// portfolio strategy with 3 assets and 3 trade algos, 
// with common trained parameters, using for(used_assets)
 
var CommonParameter;

function tradeTrendLong()
{
  ...
}
 
function tradeTrendShort()
{
  ...
}

function tradeBollinger()
{
  ...
}
 
function run()
{
  asset("EUR/USD");
  asset("USD/CHF");
  asset("GBP/USD"); // select 3 assets
  
  CommonParameter = optimize(...);

  for(used_assets) // loop through the 3 assets
  {
    algo("TRL"); tradeTrendLong();
    algo("TRS"); tradeTrendShort()
    algo("BOL"); tradeBollinger()
  }
}
// portfolio strategy with 3 assets and 3 trade algos, 
// with a combination common and separately trained parameters, 
// using of()
 
var CommonParameter,MyParameter1,MyParameter2,MyParameter3;

function tradeTrendLong()
{
  // uses CommonParameter,MyParameter1;
  ...
}
 
function tradeTrendShort()
{
  // uses CommonParameter,MyParameter2;
  ...
}

function tradeBollinger()
{
  // uses CommonParameter,MyParameter3;
  ...
}
 
function run()
{
  ...
  asset("EUR/USD"); // select asset before optimize()

  CommonParameter = optimize(...);
  MyParameter1 = optimize(...);
  MyParameter2 = optimize(...);
  MyParameter3 = optimize(...);

  while(asset(of("EUR/USD","USD/CHF","GBP/USD"))) // loop through 3 assets
  while(algo(of("TRL","TRS","BOL"))) // and 3 different trade algorithms
  { 
    if(Algo == "TRL") tradeTrendLong();
    else if(Algo == "TRS") tradeTrendShort();
    else if(Algo == "BOL") tradeBollinger();   
  }
}

See also:

optimize, while, algo, asset, Assets

► latest version online