In my last article I showed a little workaround to feed a calculation into a Study Parameter. We can use a very similar trick for all functions that require a separate condition for a reset. There are a few benefits of avoiding the separate condition: the coding is all in one place and the chance of losing track of the conditions involved is reduced. With embedded code you can also use the variables for optimization, which would not be possible with a separate condition.
There a quite a few functions in the Formula Toolbox that do require a seperate condition as a reset trigger. One of them is Accumulation.
This function is available on the Add Study window and in the Formula Toolbox.
Accumulation adds successive chart values until a user-specified condition is met. At that point, the Accumulation value is reset to zero and the process repeated.
In this very simple example we accumulate the closes since the new day starts and divide them by the number of bars elapsed. This is another way of calculating the fluid indicator from my previous last article.
FL:= Accum(Close(@),B.ENDOFDAY(@)) / (BarIx(@,StartOfDay)+1);
IF(FL > 0, FL, none)
The condition B.ENDOFDAY needs to be created separately in CQG's Conditions tab.
It would be much easier to combine the whole code inside the study itself – and here we will see how.
First I create a placeholder condition named ANY under the Conditions tab. This condition does not do anything.
The ANY condition is only used in order to be selected via the setup dialog as the reset for the Accumulation function. After this is done the system internally uses the variable we created before to calculate the reset. This way I can use the fake condition to trick the setup dialog, but the actual coding for the reset will take place in the ANY variable.
This is my embedded condition: