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

loop(Assets) : string

Enumerate assets or algos for training their parameters or rules separately. The loop function gets many pointers, such as asset or algo names, as arguments. 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 of its arguments. In [Train] mode it returns the first pointer in the first component training cycle, the next one in the next cycle and so on. Component training cycles end after the last pointer. Alternatively the single Assets pointer can be given for enumerating all assets.

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

of(Assets) : string

Enumerate 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 arguments, all different, usually 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
 
var CommonParameter;

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

function tradeBollinger()
{
  ...
}
 
function run()
{
  asset("EUR/USD"); // select one of the assets for the common parameter
  CommonParameter = optimize(...);

  while(asset(of("EUR/USD","USD/CHF","GBP/USD"))) // loop through 3 assets witrh no specific optimization
  {
    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 for 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