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

loop(Assets) : void*

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.

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