Parameters with a Focus on Boolean

CQG's Formula Builder Toolbox gives you the ability to use parameters (variables) inside your CQG code in order to control studies, conditions, and trade systems externally without the need to edit the code anytime you want to change something. In this article, we look at the different types of parameters you can use, with a focus on Boolean.

Parameters are accessed via the Parm button. In this example, we see the parameters for the Trading system cqg.AMASamp that is available in CQG. In this case, all of the parameters are simple integers, but CQG also provides a larger variety.

If you create a new parameter and click Type, you will open a drop-down menu with the options Integer, Float, Boolean, Date, and Time.

Integer:

You can create any non-floating point with values between 0 and 9.999.999 (or 9,999,999). For example, the integer can be used as a length of a study, the quantity of a trade size, or anything else that is a straight number.

Float:

Float means a floating point number and is used if decimal values are needed, for example, inside exponential moving averages. The values are between 0 and 9.999.999 (or 9,999,999) with three digits after the decimal (9.999.999,123 or 9,999,999.123).

Boolean:

Boolean gives you a checkbox in order to turn things on and off:

I have used Booleans very heavily with the super template trading system, which is outlined in one of my previous articles.

The super template trading system uses all kinds of exits at the same time, and you decide by the checkbox if this exit should be activated or not.

The coding is very simple:

For the End-of-Day exit, I used normal code as before but created a Boolean parameter called EOD. After the initial code of the exit, I added another condition to the signal field of the exit: AND EOD. If the EOD at the parameters is checked, the value for EOD will result in "1" or "true" and the signal becomes valid. If the EOD box remains unchecked, the EOD will result in "0" or "false" and the whole expression will never resolve as true, so the exit will not be used.

MACD2 with a Histogram:

Another example is to use Boolean inside a custom study in order to turn a line on and off. In this case, we have the MACD with or without a histogram.

The Boolean is called HIST and here is the code:

If(HIST, MACD(@,MA1,MA2)- MACDA(@,MA1,MA2,MA3), none)

If HIST resolves in true the calculation is MACD(@,MA1,MA2)- MACDA(@,MA1,MA2,MA3).

If HIST resolves as false the output is "none."

Date and Time:

The Date and Time parameters add the date and time information into studies.

I have not used this type as often. One of my examples is the TimeEQ (time equal to) function:

Download the PAC file ‌‍‍‍‍

File
PARMS.pac1.38 MB

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.