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

loop(Assets) : void*

This function takes an arbitrary number of pointers, strings, or asset names as parameters, and returns the first pointer on the first call, the next pointer on the next call and so on. After the last pointer, loop returns 0. The function is normally used to select assets and trade algorithms for a portfolio strategy.

Returns

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

Parameters:

p1, p2 ...

Pointers or strings; normally a string with an asset or algo name, or a trade function pointer.

Assets

Predefined array with all asset names; to be 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