Formula Builder is used to create your own custom formulas: QFormulas, Conditions, User Values, Custom Studies, and Trade Systems.
Each formula type has its own tabbed window. Many of the window components are similar between formula types, but there are minor differences.
To open Formula Builder, click the Formula button. You can also click the Symbols button, then click Formula.
Note: Trade Systems are available only with CQG IC.
3.Formula Builder Components
All tabbed windows share these highlighted components:
Other components differ by formula type.
Manage Folders menu
Organizing formulas into folders allows you to select a folder to export into a pac instead of having to choose each formula individually.
This drop down menu lists folders already created and an option to manage folders (create, rename, delete).
Managing folders
Click the drop down arrow, and click Manage Folders to open the Manage Folders window. (You can also right-click the formula list or click the Folders button on the Utility toolbar|topic=Utility Toolbar.)
To create a folder and add formulas to it:
4.Click the Create Folder button.
5.Type a name for the folder.
6.Click OK.
7.Select a formula type from the Component Type drop down menu.
8.Click the formula to add to the folder.
9.Click the >> button.
10.When you are finished adding formulas to folders, click Close. Formulas in a folder must all be of the same type, that is, you cannot have a folder with both Trade Systems and Conditions.
If a formula is included in a folder, that folder name is indicated to the right of formula name.
To rename a folder:
-
Select the folder from the Folder drop down menu.
-
Click the Rename Folder button.
-
Type the new name.
-
Click OK.
To delete a folder:
-
Select the folder from the Folder drop down menu.
-
Click the Delete Folder button.
-
Click Yes to confirm.
To move a formula to another folder:
-
Right-click the formula.
-
Point to Move to Folder.
-
Click a folder.
Search field (Formula Builder)
Click in the Search field, and type a search term. As you type, the formula list is filtered.
If you want to limit your search to either the Name field or the Description field, clear one of the check boxes.
To clear the field, click the X.
Formula list and buttons
Each list has columns for the name, description, and folder location of each formula. QFormulas and Custom Studies have an additional column. Each list also has associated buttons. Custom Studies and Trade Systems have sub-lists.
Formula Type
|
List Columns
|
List Buttons
|
Sub-lists
|
Sub-list Buttons
|
QFormulas
|
QNum, Name, Description, Folder
|
New, Copy, Del
|
none
|
none
|
Conditions
|
Name, Description, Folder
|
New, Copy, Del, Parm
|
none
|
none
|
User Values
|
Name, Description, Folder
|
New, Copy, Del, Parm
|
none
|
none
|
Custom Studies
|
Name, MarkIt, Description, Folder
|
New, Copy, Del, Parm
|
Curve Name
|
New, Copy, Del
|
Trade Systems
|
Name, Description, Folder
|
New, Copy, Del, Parm, Note
|
Trade Name/ Use As
|
New, Copy, Del, Note
|
To sort, click a column to sort by it; click it twice to sort descending rather than ascending. To resize columns, drag the column boundary. To resize this area, drag the splitter bar between it and the editor.
List columns
Column
|
Image
|
Description
|
QNum
|
|
Identifies the assigned QNumber. To assign or change a number, type a number in the field or select a number from the list. Numbers already in use are not displayed.
|
Name
|
|
Formula names are assigned when you create the formula. These names must be unique.
To change the name, click the field and type a new name, then ENTER.
You cannot change the name of CQG-defined formulas.
|
MarkIt
|
|
Click this field to open the Specify Conditions window.
|
Description
|
|
Provides details about the formula.
To add or change a description, click the field and type a description, then ENTER.
You can change the description of CQG-defined formulas.
|
Folder
|
|
Indicates the folder that contains the formula.
|
List buttons
Button
|
Description
|
New
|
Click to create a new formula.
|
Copy
|
Click to copy and rename the selected formula.
|
Del
|
Click to delete a formula.
|
Parm
|
Click to change parameters.
|
Note
|
Click to add a note.
|
Sub-lists and sub-list buttons
See Custom Studies and Trade Systems.
Formula editor
Create and update formulas in the editor. This area is empty when a new formula is defined. Otherwise, the selected formula is displayed. Its name is above the editor. Click the name to copy it to the clipboard.
The formula editor differs slightly among formula types: the editor buttons are different and the Trade Systems editor includes tabbed windows for Entry, Exits, and Costs.
Formula Type
|
Editor buttons
|
QFormulas
|
Setup, Offset, XData, Trade Execution Patterns
|
Conditions
|
Setup, Offset
|
User Values
|
Setup, Offset
|
Custom Studies
|
Setup, Offset
|
Trade Systems
|
Setup, Offset
|
There are several ways to edit formulas:
Type directly in the editor.
Select components from the Toolbox.
Use the editor buttons
When working in the editor:
Hold down the Ctrl key and click the formula to select both the input and parameters.
Double-click the formula to open parameters.
If you want to hide a formula that is not allowed to be copied, select the Hide Formula check box above the Formula Editor.
The editor includes an Undo button and a Redo button. The Undo button reverses the last action. The Redo button reverses the undo.
To resize this area, drag the splitter bar between it and the formula list.
The colors used for the text in the editor are governed by preferences.
Formula validation
When you move from the formula, the system validates it. If the formula is not validly formatted, you receive this message:
Click No to fix the expression later. Once you click no, the system validates that formula only if you change it, click the Apply button, or use it in an application.
Setup button
Click this button to open parameters for the study selected in the editor. The Setup button is active only when a study expression or part of a study expression is highlighted. See CQG Studies|topic=Studies for more information about study parameters.
For spread formulas, this button opens the Setup Synthetic Spread Calculation Parameters window.
Offset button
Click this button to open time parameters.
Select whether to offset by a number of bars to restrict the chart’s time interval.
XData button
Click this button to open the Setup XData window.
To learn more about XData, see “To create XData QFormula” on page 137.
Trade Execution Patterns button
Click this button to open the Set Up Trading Parameters|topic=Setting Spread Trading Parameters window.
Value Preview and Tick Preview fields
When a spread is entered in the editor, the Tick size preview and Value preview fields are displayed:
These fields provide a preview of the selected tick size and the value. If the tick size in this example were changed from Auto to 10, the Tick size preview would change to 10. Value preview shows the best ask.
The value preview is displayed for non-spread formulas.
Edit Permissions and Unlock links
Click the permissions link to open component information, where you can update permissions|topic=To change component permissions and password.
Only a permissions link is visible for your own custom formulas. For CQG-defined formulas, there’s also an Unlock link, so that you can enter a password|topic=To open passworded components to unlock the formula in order to change it.
Toolbox button
Click this button to open the Formula Toolbox.
Preferences button
Click this button to open Formula Builder preferences.
QFormula Display Format button
Click this button to open Symbol System Preferences. On this window, you can change how QFormulas are displayed, by name, number, or formula.
Printing and saving formulas
Right-click the formula list, then click:
Print: to print the formula as it is displayed in the editor (display string).
Print Details: to print the display string and adds the parameter details (study string).
Print All: to print all the formulas in the list as display strings.
Send to > File: to save the formula on your PC. If Details is checked, the study string is printed.
Send to > Clipboard: to save the formula to the clipboard. If Details is checked, the study string is printed.
11.Setting Formula Builder Preferences
To open this window, click the Preferences button at the bottom of the Formula Builder window.
Preference
|
Description
|
Font
|
Font, size, and formatting for editor text.
|
Syntax Highlighting
|
Clear this check box if you want all editor text color and background to be determined by your operating system settings.
To change the color of the elements listed, click the colored square to open a standard color palette.
Identifier = symbol, @, and parameter names
Operator = mathematical and relational operators, commas, and question marks
Brackets
Keyword = logical and movement operators
Number = numeral
QFormula
Condition
User Value
Built-in study = pre-defined studies
Custom Study
Commentary = comments
|
Display inactive editor caret
|
Colors your place in the formula when you move the mouse cursor to a different location.
For example, the mouse cursor is at the end of formula in the editor. You then use the mouse to click the Preferences button. The previous location of the mouse in the formula is colored.
|
Custom background color
|
Colors the background of the editor pane.
|
Custom read-only background
|
Colors the background of the editor when the formula is read-only (password protected).
|
Highlight balanced brackets
|
Colors properly formatted brackets.
|
Shade parenthesis scope
|
Colors the background of the part of the formula that is governed by the brackets the mouse cursor is in.
|
Highlight first unbalanced bracket
|
Colors an opening bracket until the closing bracket is added.
|
Save Scheme
Load Scheme
|
Click the Save Scheme button to save these preferences to an ini file.
Click the Load Scheme button to import a saved preferences ini file.
|
Defaults
|
Click this button to return to default settings.
|
Allow auto-comments
|
When you type SPREAD, NC, YIELD, or AGGR followed by an initial parenthesis, the system automatically displays a comment that contains the formula components and examples. To turn these comments off, clear this check box.
For example:
/* SPREAD(linear expression, [calculation mode], [tick size], [trade ratio], [BAT filter], [roll-over], [rounding mode])
Examples:
SPREAD(42*HOE-CLE, L1, 0.01, 1:2, T:BA, 1)
SPREAD(EP-ENQ, L1, 0.01, 1:1.33, T:BA, 1, MATH)
SPREAD(EP/ENQ) */
| 12.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 will be 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|topic=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 CQG Studies|topic=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:
-
Click a value in the list.
-
Select the Offset check box.
-
Use the arrows to select an offset value.
-
Click Insert. The value with offset is added to the Formula Editor.
To add an offset to an expression:
-
Select the Offset check box.
-
Use the arrows to select an offset value.
-
Click the Replace button. The value with offset is added to the Formula Editor.
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.
Share with your friends: |