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
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.
- 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 Workshop 6).
- 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]
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 predefined variables LoopNum1 and LoopNum2 contain the current cycle number in the first and second loop, starting with 1; Loop1 and Loop2 contain the current return values from the first and second loop, f.i. an asset or algo name; NumLoops1 and NumLoops2 contain the total number of cycles of the first and second loop. The variables are valid inside the loop.
- Since a loops 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,
- Use loop(Assets) together with individual asset lists
for externally specifying the assets to be traded.
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
optimize, while, algo, asset, Assets