Formula Toolbox

This toolbox contains all of the components and operators available for point-and-click programming.

To open this window, click the Toolbox button at the bottom of the Formula Builder window. By default, the toolbox attaches to the side of  the Formula Builder window. When you move Formula Builder, the toolbox moves with it. To separate the windows, move the Formula Toolbox window.

Hold down the Ctrl key when you click the Toolbox button, and the window returns to its default location.

Double-click an item on the components list to open parameters. If you double-click on a custom parameter, the expression in the editor is replaced with that parameter.

 

 

Three display check boxes are at the bottom of the window:

      Clear the Tooltips check box to hide tooltips on the Toolbox window.

      Clear the Title bar check box to remove the title bar from the window.

      Clear the Scalable buttons check box to make the buttons on this window a static size. Otherwise, the buttons are made larger and smaller as the window is made larger and smaller.

 

Note: Trade Systems are available only with CQG IC.

Toolbox Buttons

These buttons are at the top of the Formula Toolbox window.

Button

Description

(…)

Adds parentheses around the selected elements, so those mathematical operations are completed first.

+

Addition

-

Subtraction

*

Multiplication

/

Division

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

=

Equal

<> 

Not equal

AND

Both

OR

Either

WHEN

Inserts a conditional operator that evaluates as true when the expression that follows the WHEN operator evaluates as true.

NOT

Inserts an operator that negates that value of the expression that follows it. The expression evaluates as true when the value on the right side evaluates as false.

IF( , , )

Inserts a conditional operator that changes the value used in the Formula, depending on the evaluation of an expression in the IF( , , ) operator.

After the IF( , , ) operator has been inserted into a Formula expression, the expression must be edited to include three parameters:

The first parameter, entered between the open parenthesis and the first comma, should contain the expression that is evaluated for the IF( , , ) operator. The expression must result in either a True or False value.

The second parameter, entered between the first and second commas, should contain the value or expression used in the Formula expression if the IF( , , ) expression (first parameter) evaluates as True.

The third parameter, entered between the second comma and the close parenthesis, should contain the value or expression to be used in the Formula expression if the IF( , , ) expression (first parameter) evaluates as False.

XABOVE

Is true when the Study Operator, Bar Value, or other item on the left side was smaller (one bar ago) and is now larger than the Study Operator, Bar Value, or other item on the right side. This would be true when the value on the left "crosses above" the value on the right.

XBELOW

Is true when the Study Operator, Bar Value, or other item on the left side was larger (one bar ago) and is now smaller than the Study Operator, Bar Value, or other item on the right side. This would be true when the value on the left "crosses below" the value on the right.

GOINGUP

Is true when the Study Operator, Bar Value, or other item was smaller one bar ago.

GOINGDN

Is true when the Study Operator, Bar Value, or other item was larger one bar ago.

TURNSUP

Inserts a relational operator that evaluates as true when the Study Operator, Bar Value, or other item was larger one bar earlier and one bar later.

TURNSDN

Inserts a relational operator that evaluates as true when the Study Operator, Bar Value, or other item was smaller one bar earlier and one bar later.

\*…*\

Designates a comment, which is not used in calculations.

Line

New line (line feed)

Order of Operations

These operations are listed from highest priority to lowest, so operators at top of this table are calculated before the operators located lower, if no strict order is defined by parentheses.

Operators of same precedence are left-associative, so they are calculated from left to right.

Precedence

Operator

Description

0

CONCATENATE

Expression concatenation

1

?

Offset to most active contract

1

??

Offset to most active contract includes cash/spot

2

:

Output selector

2

,

Bar interval selector

2

[ ]

Bar offset

3

STARTINGAT

Starting value fill-in

4

*

Multiplication

4

/

Division

5

+

Addition

5

Subtraction

6

Relational less

6

Relational greater

6

=

Relational equality

6

<=

Relational less or equal

6

>=

Relational greater or equal

6

<> 

Relational inequality

6

XABOVE 

XA

Crosses above

6

XBELOW 

XB

Crosses below

6

GOINGUP

Going up

6

GOINGDN

Going down

6

TURNSUP

Turns up

6

TURNSDOWN

Turns down

7

!  

NOT

Logical not

8

&  

AND

Logical and

9

|  

OR

Logical or

10

WHEN

When

11

:=

Assignment

12

;

Statement separator

 

Components of Formulas

Component

Description

Bar Value

Displays the bar values (corresponds to chart types) that can be used in formulas. For each bar value, there is a list of available data points.

Bar values are detailed in Chart Types

Study

Displays the studies that can be used in formulas. For each study, there is a list of available data points.

All study calculations that require a current bar value (open, high, low or close) use the close of the previous bar to calculate values when the current bar is incomplete.

Study display parameters cannot be changed here.

Study values are explained in Studies.

Function

Displays the functions that can be used in formulas. For each function, there is a list of available data points.

Function values are detailed in Functions.

Condition

Displays the conditions that can be used in formulas. For each condition, there is a list of available data points.

To enable you to quickly identify conditions in your formulas, CQG inserts the letter “B” in front of the condition name.

User Value

Displays the user values that can be used in formulas. For each user value, there is a list of available data points.

To enable you to quickly identify user values in your formulas, CQG inserts the letter “V” in front of the condition name.

Trade System

Displays the trade systems that can be used in formulas. For each trade system, there is a list of available data points.

 

Toolbox Setup button

Click the Setup button to open the Setup Study parameters window.

Toolbox Offset checkbox and field

Select the Offset checkbox to add an offset to the value to be entered in the expression.  The offset value determines which bar is examined when the expression is evaluated.

For example, an offset value of [-1] for a close bar indicates that the expression uses the close of one bar back from the current bar. An offset of [1] the next bar.

To insert a value with an offset:

1.  Click a value in the list.

2.  Select the Offset check box.

3.  Use the arrows to select an offset value.

4.  Click Insert. The value with offset is added to the Formula Editor.

To add an offset to an expression:

1.  Select the Offset check box.

2.  Use the arrows to select an offset value.

3.  Click the Replace button. The value with offset is added to the Formula Editor.

 

The offset feature in CQG Formulas(@[-offset]) now allow the formula to set offset in years (example: @[-1Y]), month (example: @[-1M]), week (example: @[-1W]) and days (example: @[-1D]).

Years offset should be calculated as follow:

Take -1Y offset from current day, so

1. Calculate number of trading dates between current trading day and first trading day in the current year = N

2. Take same Nth trading day from the last year.

Toolbox Apply button

Click the Apply button to apply a toolbox item to an existing expression.

For example:

Expression selected in editor =

RSI(@,9)

Toolbox selection to be applied to expression =

MA(Sim,21)

As applied =

MA(RSI(@,9),Sim,21)

 

When evaluated, the modified expression produces a 21-period Simple Moving Average of a 9-period Relative Strength Index.

This button is unavailable if the expression does not allow this application.

Toolbox Undo button

The Undo button reverses the last action made. The button becomes unavailable when no other reversals can be made.

Toolbox Insert/Replace button

Click the Insert button to add the toolbox selection to the Formula Editor. The element is added at the cursor location in the editor.

When an expression is selected in the editor, this button becomes a Replace button. Click it to overwrite the expression in the editor with the toolbox selection.

Toolbox Insert Param button and field

 

The Parameters field lists parameters that have been defined for the selected condition, user value, or custom study. To add the parameter in a different location in the expression, click the Insert Param button.