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.
p1 on the first call or training cycle, p2 on
the next call or training cycle, and so on. The last call returns 0.
|p1, p2 ...
Up to 40 pointers or strings; normally a string with
an asset or algo name, or a trade function pointer.
Predefined array with all asset names; used
for looping through all assets in the asset list.
The following variables are valid after a loop
Current return value of the first and second loop, the current
pointer or asset/algo name.
Current cycle number of the first and second loop, starting with
Total number of cycles of the first and second loop.
- In [Train] mode the loop function
is handled in a special way. A complete training cycle is executed for every
loop parameter. This ensures that parameters, rules, and factors
are generated separately for every strategy component. The
algo function can be used to identify the strategy component
in the parameter, factor, or rule file (see the example in
- When optimizing parameters or generating rules, have not more than 2
loop calls in the run function: an asset
loop, or an algo loop, or an algo
loop nested in the asset loop. For more loops through
assets or algos, or for avoiding the special loop behavior
in [Train] mode, use standard C
for or while loops or
for(...assets) / for(...algos)
for enumerating assets and algos.
- Do not abort a loop with break or
return, or else the remaining assets or algos won't be executed.
Use continue for prematurely aborting a loop and continuing
with the next pointer.
- The returned string or pointer remains valid until the next loop
call. Since a loop runs several times, use a static
or global variable inside a loop only
when its content is independent of the asset or algo. Otherwise use a
AlgoVar, or a series, or
- Use loop(Assets) together with individual
asset lists for externally specifying the assets to
Example (see also Workshop 6):
// portfolio strategy with 3 assets and 3 trade functions
function tradeFunc(); // empty function pointer
"GBP/USD")) // loop through 3 assets
while(tradeFunc = loop(
tradeBollinger)) // and 3 different trade algorithms
asset(Loop1); // select asset
tradeFunc(); // call the trade function
latest version online