loop(void* p1, void* p2, ... ) : void*

loop(Assets) : void*

Special function enumerating assets and/or algos, normally used for training parameters or rules separately per portfolio component. It gets a list of pointers that can be asset or algo names or algo function pointers. In [Test] and [Trade] mode it returns the first pointer on the first call, the next pointer on the next call and so on. After the last pointer, 0 is returned. In [Train] mode it returns the first pointer in the first training cycle, the next pointer in the next training cycle and so on. Training cycles end after the last pointer.

Returns

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

Parameters:

p1, p2 ...

Up to 40 pointers or strings; normally a string with an asset or algo name, or a trade function pointer.

Assets

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

 
The following variables are valid after a loop call:

Loop1

Loop2

Current return value of the first and second loop, the current pointer or 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:

Example (see also Workshop 6):

// portfolio strategy with 3 assets and 3 trade functions
 
function tradeTrendLong()
{
  algo("TRL");
  ...
}
 
function tradeTrendShort()
{
  algo("TRS");
  ...
}

function tradeBollinger()
{
  algo("BOL");
  ...
}
 
function tradeFunc(); // empty function pointer
 
function run()
{
  while(loop(
    "EUR/USD",
    "USD/CHF",
    "GBP/USD")) // loop through 3 assets
  while(tradeFunc = loop(
    tradeTrendLong,
    tradeTrendShort,
    tradeBollinger)) // and 3 different trade algorithms
  {
     asset(Loop1); // select asset
     tradeFunc();  // call the trade function
  }
}

See also:

optimize, while, algo, asset, Assets

► latest version online