Auto Fibonacci Retracements, Part 2

Editor's Note: In this article, Mueller expands on the Auto Fibonacci study concept covered in his August 27 article. Here he shows how to enhance the study by forcing the calculation to use the same scale as the chart.

Now that we understand the basic code of the AutoFib study, we can enhance it:

If we want to force the whole calculation to automatically use the same scale as the chart, we can use the Share Scale function in CQG. First, we need to highlight the complete code in the Define User Formulas window, select Share Scale in the Formula Toolbox, and click Apply.

Next, we can create parameters for the different levels we want to calculate and an additional parameter to show or not show the line.

Finally, we can create the new lines using an if-then statement:

IF(L1, ShrScale( LoLevel(@,period,0) + ( HiLevel(@,period,0) - LoLevel(@,period,0))*LEV1/1000,@), none)

If the L1 parameter is checked, it will use the calculation in red. If the L1 parameter is unchecked, the result is "none" (i.e., no value). Instead of multiplying the code at the end; for example, fixed with 0.618, we can let each line have an associated parameter: LEV1 - LEV7. To avoid floating point numbers, we use an integer and divide it by 1000:

*LEV1/1000

With the final study, we can set seven different levels with the ability to turn them on and off as well.

Voilà:

Download the PAC file ‌‍‍‍‍


Learn more from CQG HTML Help