The Dynamic Market Lab The Dynamic Market Lab right border
Knowledge Base » Examples and Formulas » General Loop Conversion Technique

For those of you interested in trying to understand the process of converting a loop from a higher level language into and ASI formula, we suggest these steps:

Step 1.) Separate the loop into as many individual loops as possible, and convert each loop separately.

Step 2.) If the loop uses a "varying" (non-constant) counter variable, replace it with a constant, preferably a small number, like 3 or 5.

Step 3.) Create an equivelant function in Metastock for the static version of the loop (i.e., a loop with a constant counter).

Step 4.) Analyze the logical output of the formula and try to convert it into existing Metastock indicators.

Step 5.) Compare the output from Steps 3 and 4, and make sure they are equal.

Step 6.) Finally, replace the calls to fixed-period Metastock indicators with calls to the ASI functions, and replace the fixed length with the original "variable loop counter" function.

You may find that this process does not always fit your style, but we recommend it as a starting point.