Tutorial Project


An introduction to the Trading System API's functionality comes as a set of tutorials, all combined into a tutorial project. Most of the source code samples in this manual are taken from this tutorial project. This project is located in the 'tutorial' directory of the product installation directory. Each tutorial has its own .cpp file. The main() driver can be found in the TS_API_TUTORIAL.cpp file. On MS-Windows, the project is a Visual Studio Project.

 

When running the various tutorials, users must pass the tutorial number as argument to the executable. In Visual Studio this can be achieved by setting the ‘Debugging -> Command Argument’ in  the 'Project Properties Dialogue' to the corresponding number.

 

The following Project Properties Window is set to run tutorial 301. The executable's main() function uses the given 'command argument' to run the chosen tutorial.

 

Locating Library Source Code


IMPORTANT: The library ships with some source code for frequently used classes as well as the corresponding '.pdb' file. This makes it possible to step through library sources while debugging your own projects. This however only works if you help the IDE locate the source files when you first start stepping through the tutorial code. The is necessary as the '.pdb' file has no knowledge of the directory structure on your computer.

When you first start stepping through the tutorial projects, the IDE will raise a 'source not found' condition and give you a chance to locate the Trading System API's library sources. At that point make sure to point the IDE to: <project-dir>/src/

Setting Breakpoints in Source Code


Stepping through the tutorial in debug mode is a good way to gain familiarity with the API. When debugging strategies, it useful to set breakpoints at the start of the various strategy event handler functions such as strategy::on_start() and strategy::on_bar_close().

 

The following images are snapshots of Tutorial 301 and illustrate where the first breakpoints can be placed (red dot) when first running in debug mode. 

 

 

The strategy::on_start() member is called (once only) when the strategy starts.

 

A further breakpoint can be set in the strategy::on_bar_close() member ( a.k.a strategy::on_next()). strategy::on_bar_close() will be called repeatedly at every strategy interval (bar) and usually is where the strategy's main trading logic is located. 

 

Application Output


Strategy objects produce output in various ways. Text can be written directly to standard output which is useful for debugging purposes. Strategy objects also produce HTML reports and charts if strategy::enable_reports() was invoked. Such output is written to a dedicated output directory that is  created automatically in the application's current working directory.  A user specified alternative can be set via the strategy::output_base_path() member, as shown below. If you want these reports to automatically open in a browser once they are available, invoke strategy::auto_open_reports() before the strategy is evaluated by a call to strategy::run().

 

 

The strategy::auto_open_reports() member can be used to set a flag causing the strategy to automatically open the HTML reports in a web browser once they have been produced. This saves  users from having to manually search through the file system to open reports.