# Another Secret Revealed: Using an Embedded Condition

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.

Accumulation (Accum)

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.

Example: Accum(@,none)

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.

BarIx(@,EndOfDay)=0

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:

ANY:=BarIx(@,EndOfDay)=0;

Tags

#### Disclaimer

Trading and investment carry a high level of risk, and CQG, Inc. does not make any recommendations for buying or selling any financial instruments. We offer educational information on ways to use our sophisticated CQG trading tools, but it is up to our customers and other readers to make their own trading and investment decisions or to consult with a registered investment advisor. The opinions expressed here are solely those of the author and do not reflect the opinions of CQG, Inc. or its affiliates.