Now that a trading system and an account are setup, the next step would be to implement an entry function, either “Buy()” or “Sell().” Looking at the “Buy()” function, we see the following parameters:
The Buy entry function’s first parameter, “Order,” is another function. This is because for each entry, we need to tell the trading system what type of order we will be using, and each order type uses a different set of parameters. In the image above, you can see the order types available each followed by “()” indicating that they, in turn, are functions that will require their own parameters.
Notice “New long position”. This function is not used to cover an existing short position. There is an Exit function for that purpose.
Let’s say we want to use a limit order here; we could enter the full “Limit()” function for the “Order” parameter, or we could reference a cell that contains our “Limit()” function. Your choice will depend on what you find is a more effective way to organize your trading logic. For the sake of exploring what a “Limit()” function requires, let’s stop this entry for now and create the “Limit()” function we will reference later. In cell A4, we start over and type “=Limit(”. Or, we could select Shift+f3 to bring up the function wizard. Notice the Limit Order’s parameters are displayed in the dialog.
Limit Order Parameters |
Example |
| ||
Symbol: |
"EP" (quotes are required around strings) |
|||
Size: |
5 (numbers do not use quotes) |
|||
Price: |
2665.25 (numbers do not use quotes) |
|||
Duration: |
"Day" or "GTC" (quotes are required around strings) |
|||
BuyorSell: |
"Buy" or "Sell" (quotes are required around strings) |
|||
ExecInstr: |
[Out of view in image below; use the scroll bar to access] | |||
Account |
Enter an Execution Instruction such as a Trailing Limit (another function) order. For a straight Limit Order leave the parameter blank. Default account is used or you can enter a different account name or number. | |||
|
|
Everything in the above list of parameters can be cell references, such as “Symbol” can be “B3,” where B3 contains “EP” (cell references do not take quotes). Notice that the function wizard resolves that reference and displays a preview of the function result at the bottom of the parameter window:
When we select “OK”, the Limit order function displays as expected:
For the above function, we used a set price. If you referenced a cell for the Limit price, that price could be manually entered or it could be, for example, an RTD call from CQG for a study value.
If the cell displaying the price is blank or displays a #Value! Error or the #N/A error or other invalid values, the order will not be canceled unless you specify in the Execution Instruction parameter to cancel the order by using this function: =CancelIfPriceIsInvalid().
Now we will finish creating our entry by referencing this Limit order function:
Buy/Sell Parameters |
Example |
|
Order: |
A4 (cell references do not take quotes), or |
|
|
Limit(“EP”,5,2665.25,”Day”) (functions do not take wrapping quotes) |
|
When: |
B5 (cell references do not take quotes) |
|
Name: |
“Long1” (quotes are required around strings) |
|
System: |
A1 (cell references do not take quotes) |
For the order, you can use a cell reference to an order function as we first showed (such as “A4”), or you can nest the function such as “Limit(“EP”,5,2665.25,”Day”) inside the “Buy” function.