How to make a CTL program and how to run it?
There are two types of programs you can write in CTL, Indicators and Strategies.
Indicators are used to display some visual information about the chart data either for manual trading or as development tools and final input to Strategies.
Strategies are programs that can do something... ultimately to place and close trades automatically.
Assuming you have very little programming experience first we will make an Indicator program that does nothing but print the veritable "Hello World" message. Printing in CTL is restricted to either the ‘debug window’ or to a file. We cannot print any text to the chart window .
To write a CTL you could use any text editor… but to compile the program (to make it useable in Dealbook) we need to compile it in the ‘Integrated Development Environment” or IDE, otherwise known as Chartstudio. The IDE is a combined editor and compiler that also registers a successfully compiled program to Dealbook.
After installing Dealbook there should be a desktop icon called Chartstudio, as well as a Chartstudio item in the start>programs>global forex trading folder. (or WH SELFINVEST if you have Prostation).
Double click the Chartstudio icon, then click
indicator HelloWorld;
draw myLine("myLine");
begin
print("hello World");
end.
Now find the lightning bolt icon to click (or press F7, or select
You will now be prompted for a file name to save your program to. It is good practice to make the file name the same as the indicator or strategy name. Another useful practice is to suffix the indicator names with “_I” and strategies with “_S” following the same with the file name. Sometime in the future you will have indicators and strategies that are based on the same formulas and will need to differentiate them. So our HelloWorld indicator should be named “HelloWorld_I” and the file name also “HelloWorld_I”. This will then save you program as “HelloWorld_I.ctl”.
The verify process will confirm there are no syntax errors in your program, that is, the format of the instructions are correct… there may still be logic errors in how you are telling it to operate – we’ll deal with that another day.
Now find the “Output” tab which by default will be at the bottom of Chartstudio (but may be dragged to other places). Assuming you typed everything as above, and changed the name to HelloWorld_I, you should see the message
“Verifying file: C:\…… \HelloWorld_I.ctl”
“Done”
CTL programs need to follow a structured layout in order to compile. The first and obvious thing is to tell the compiler and Dealbook what kind of program this is and give it a name that we can all recognise.
indicator HelloWorld_I;
This name must be unique, no other compiled program can have the same name ~ actually if you do have the same name the existing one will be replaced, unless it is a ‘system’ indicator, one that was supplied with deal book. Names must start with a letter and can then contain numbers and letters but not spaces or special characters.
CTL is not a case sensitive language but many programmers use upper and lowercase to improve readability.
In our HelloWorld program we have skipped some optional sections that we will come back to. However, in an Indicator we must have a “draw” section since that is the primary purpose of an indicator – to draw some lines on the charts. In our program here we don’t use the line, but we must define at least one.
draw myLine("myLine");
Again we skip some optional declaration sections and identify that we are going to write some code. The first part of the coding section is
Begin
This must also have a matching end at the very end of the program.
Now we finally do something, tell Dealbook to write the text “Hello World” to the ‘debug window’.
print("Hello World");
The print statement only writes readable text, not numbers, but we can convert numbers for printing using the numbertostring() function ~ later.
Finally our program must end… the “end” statement of the program is terminated by a dot (full stop/period).
end.
Compile your program by finding the “Install” icon or menu item.
After a good compile resulting in the message “Module Installed Successfully” in the ‘Output’ tab we are ready to attach it to a chart.
Open Dealbook and get a chart running (Dealbook can be open while developing CTL programs).
Find the ‘Setup Indicators” icon on the toolbar, or right click the chart and click “Add Studies” near the bottom of the popup window. If you used the “Setup Indicators” icon you will have the “Chart Indicators” window, now click “Add” at the bottom left. You should now see the “New Indicator” window with a list of compiled and installed indicators. Scroll through to find, or type the name of our new indicator “HelloWorld_I”. Highlight it with a single click, don’t double click… first we need to uncheck the “Add on new subgraph” box.
Now click “ok” on the “HelloWorld_I parameters” window.
On the Dealbook menu bar navigate to and click
We should have at least one message “Hello World”.. probably more as it will print every time there is a price movement on the chart you attached to.Find the ‘Setup Indicators” icon on the toolbar, or right click the chart and click “Add Studies” near the bottom of the popup window. If you used the “Setup Indicators” icon you will have the “Chart Indicators” window, now click “Add” at the bottom left. You should now see the “New Indicator” window with a list of compiled and installed indicators. Scroll through to find, or type the name of our new indicator “HelloWorld_I”. Highlight it with a single click, don’t double click… first we need to uncheck the “Add on new subgraph” box.
So that’s it.. a very sedate and almost useless indicator… but.. the print function is very useful for debugging programs.. I expect you will learn to use it a lot !