You are here

Algo Studio

Algo Studio

 

AlgoStudio is an integral module of the Protrader platform and is run as a separate process which allows it to operate independently from the main application although the module permits users to open several windows simultaneously.
The key features of AlgoStudio include

  • Ability to create indicators, strategies (Expert advisors) and scripts (Macros).
  • Supports C# (.NET platform) programming language.
  • History data manager tool for creating customized instruments or importing data from other sources.
  • Capability to back- test historical data and multiple symbols simultaneously.
  • Permits back-testing of multiple time intervals.
  • Facility to back-test all chart types available on the trading platform. Ex: Renko, 3 Line break, Kagi, Price range, etc.
  • Strategy testing in ticks, minutes or daily data.
  • Possibility to test strategies at Bid, Ask, LTP.
  • Two strategy testing modes: With visualization/ without visualization
  • Two emulation types: Position/ Multiple positions.
  • Capability to use functions that provide access to Level II quotes.
  • Strategy optimization tool.
  • Plain text and graphic reports.
  • Editor with IntelliSense support.
  • Dictionary with a list of all available functions.
  • Debugger.
  • Tool for importing/ exporting parameters of strategies being tested.

To open Algo Studio, Go to Tools >> Algo Studio OR Click on this icon in the toolbar ribbon. The following window will open up

 

 

To add a strategy, go to script editor, select the strategy and double click

 

 

AlgoStudio is a fully customizable development tool. Users can configure the work environment according to their preferences. All panels appearing in AlgoStudio can be added, removed or moved to a different location. The panels are attached by default but can be moved using the following button.

 

 

Creating a new module-

To begin writing source code for a new indicator, strategy (Advisor), script (Macros) or Library, open AlgoStudio and click on the button located in the toolbar ribbon. The following window will throw up. Select C# as the programming language and choose from the existing options that include Indicator, Trading system, Macros and Custom column. Click the “Next” button to continue

 

 

Users can choose the

  • Module name and the location where the file with the source code should be saved.
  • For C# modules, security settings such as module version and password protection are available. For demo versions, it is also possible to the set expiration date after which demo users will not be able to open the module.

 

 

After selecting the required parameters, click on the button. A new module will be shaped and the template will appear in the source code editor window.

Creating custom columns-

As a developer, you can add custom columns to any information panel in the terminal, using codes.
Custom columns can be created in two ways

1. Open AlgoStudio and click on the highlighted button located in the main menu of the window.

 

 

The following window will show up. Select “Custom column” and choose the panel to be customized from the drop-down list.

 

 

2. Go to settings in any of the panels in the Desktop and select the 'Columns' tab. Click on the button located in the header of the settings window.
Input the name of the Custom column in the field "Header text" and click "New" to run AlgoStudio in order to create a new script for Custom column. Please refer to C# language documentation for more information.

Ex: MarginAvilCross.cs, MarginUsedcross.cs, GrossCross.cs

 

 

For additional information on creating custom columns, click HERE

C# dictionary

AlgoStudio features a Dictionary tool which allows to view brief descriptions and all classes and methods in C# that can be used to write source code.
To open the Dictionary panel, click the button located in the toolbar ribbon. On the right side of the panel, users can find detailed information on the selected variable. Users can also search for variables from the search field which is present under the panel header.

 

 

Protrader has reference database for a large number of functions used in coding various parameters. Users can view the database HERE

Editing Panel

Script Navigator-

The Script navigator is a tool which shows all modules created by a user. Pre-existing code or fragments of source code can be uploaded to AlgoStudio from any source file. To upload an existing source code, click the button and choose the file. The drop- down arrow beside the button will show a list of source code files that were previously opened in the AlgoStudio editor. Source codes can also be uploaded to the editor with help of the Script navigator panel by clicking on the button.

 

 

Two directories will be displayed in the panel-
The first is the installation directory: C:\Users\Username\AppData\Roaming\'Folder with terminal'.
The second directory titled “My scripts” is where all modules will be saved by default. There is also a folder bin where all compiled versions of the files are saved.
Please note that all scripts are stored in the directory Macroses: C:\Users\ User name\Documents\'Folder with terminal'.

Source Code Editing-

The source code editor in AlgoStudio is a fully professional tool to facilitate the writing of source codes. It features syntax highlighting and supports Intellisense technology. Place the cursor in the required area and press Ctrl+ Space to open the Intellisense menu.

 

 

The top end of the Editor panel features a help toolbar for easy searching, filtering, inserting comments and undoing work. The initial buttons in the toolbar are “Undo” and “Redo” denoted by the symbols correspondingly. The Undo and Redo buttons allow users to reverse step by step changes or move forward.
The next available button “Find”, allows users to search for a specific phrase in the source code or replace an existing phrase with another phrase. Click on the button to search

 

 

Users can also replace phrases by clicking the “Replace” button either from the Editor toolbar or from the dropdown in the “Find and Replace” window.

 

 

The “Comment” and “Uncomment” buttons allows users to add or remove comments from the code. Use the buttons to carry out this operation.
There is also an “Errors control box” under the main source code window which can be accessed by clicking
The other feature of the Editor toolbar is a dropdown list of methods, functions, properties, variables, and fields which can be found in the source code. The list was designed to navigate codes. Selecting from this menu places the cursor immediately at the corresponding place in the code. To open the list, click on the button.

Editing types-

To select “Editing types” click on the button in the main menu. There are three modes for users to choose from
Release mode
This mode of compilation is used as Product ready mode. If the source code is free from errors and ready for application, users can select this mode.
Profile mode
This mode is used for source code optimization. If any function is used more than once in the source code, then the Profiler panel will show the number, code line where this function was invoked and the exact processing time of this function.
Debug mode
This mode of compilation is used for debugging source code. It is very important to identify errors before script usage. Users can debug C# code.
Debug mode can be selected from the main Panel button, by hitting the Hotkey ‘F5’ or by using any of the following three buttons.
Step info (F11) – allows going through all code lines independently of breakpoints.
Step over (F10) – allows going over certain program steps.
Step out (Shift+F11) –running the script until breakpoint.
To begin debugging the source code, users should first set breakpoints. A breakpoint can be set by clicking the left mouse button between the code line numbers and the edge of the source code editor window or by
using menu Run> Toggle breakpoint. After placing the breakpoint, it will be visible in the margin as a red circle. User can remove all breakpoints from the source code using the menu, ‘Run> Clear all breakpoints.’

Properties-

The properties window shows all information about a selected module and has five sections:
Script info- Shows general information about the selected module. This information is specified during the creation of any algorithm.
Script inputs- Shows settings of the external script variables.
Back testing setup- Gives all parameters of backtests.
Optimization setup- Gives all parameters for optimizing strategies (Expert Advisor’s).
Walk forward setup- Shows time settings for this type of optimization. This setup type appears when users choose the Optimization tab> Walk forward> Properties.

 

 

Backtester-

The backtester panel generally comprises of a chart which can be used to show backtest results conducted on historical data. To open Backtester, click on the button. The following window will open up

 

 

This backtester tool can be configured just like any other panel in the terminal by making changes in the backtesting setup under properties.

 

 

The context menu can be invoked by right- clicking anywhere in the chart area

 

 

  • Style – Chart display (Bars, Candles, Line, etc.).
  • Indicators – Add existing indicators to the current chart.
  • Drawing tools – Add useful objects and drawings to the chart (Lines, Andrew's pitchfork, Price channel etc).
  • Refresh – Used to update charts.
  • Layouts – Evokes the layout manager window with the option to import/export ready-made settings for the chart.
  • Save layout – Allows saving chart layouts and/or setting them as default.
  • View – Allows choosing settings for chart panel (Grid, Volume bars, etc.)
  • Export – Allows printing, saving/ emailing snapshot of the current chart and opening the historical data manager.
  • Settings – Allows opening chart panel settings.

Output-

The Output tool is used to show system communication (Ex: errors) during compilation or messages from the strategy agent such as the Expert advisor during backtesting. To open the output panel, click on the button

 

 

Watch-

Watch tool is used to debug source codes. To begin, users are required to set breakpoints, select variables to be checked and add them to the Watch panel. In order to do this, place the mouse over the variable to add to Watch then open context menu and select Add watch from the menu. The selected variable will appear in the Watch window

Select the Debug mode and run debugging (F5).
If tables are used in the Watch tool, users can click on View button to see the value of an array.
Through the Context menu of the panel, users can

  • Add watch – Allows to start typing variable name for watch.
  • Delete watch – Allows deleting selected variable from watch.
  • Clear – Allows deleting all variables from watch.

Profiler-

They are used to optimize source code. It gives users a visual representation of how functions are run through the Backtester and the number of times a function was invoked. Profiler shows the exact working time of the function in milliseconds and percent as well as the function type. To launch Profiler, click on the button.

 

 

Backtesting

Charts-

The Chart tab typically shows a graph with all open/ closed positions during the test run and also all automatic indicators that were used during the test.
Indicators are shown in the bottom of Chart panel and can be hidden by clicking on the button placed below the chart.

 

 

Trades History-

The Trades history tab shows all transactions that were carried out during backtesting.

 

 

Users can view the following columns from this tab

 

 

Users can also use standard functions mentioned below from the context menu of the panel

  • View on chart – Displays trades on the chart.
  • Layouts – Evokes the Layout manager window to import/export ready-made settings for the tab.
  • Save layout – To save the layouts and/or setting them as default.
  • Filter – Used for filtering functions.
  • Export – Permits exporting data to external sources.
  • Group by – To group information in the table.
  • Table alerts – Settings to set- up table alerts.
  • Settings – To open the settings panel for the tab.

Orders/ Positions-

This tab shows the orders/positions that were opened during backtesting.

 

 

Performance-

The performance panel contains trade statistics, P/L charts, data related to trade population and drawdowns. All information from the panel is divided into the following three tabs:

1) Cumulative P/L:

Here, users can see the entire information about trading results and their capital. Firstly, all operations are considered together (Total tab) but they can also be viewed independently based on the operation side (Buy and Sell tabs). The section allows users to view changes in the balance and P/L graphically. The cumulative P/L chart in the OPERATIONS MODE displays how a user’s balance was altered while trading for specific time periods.

 

 

Cumulative P/L chart in the TRADES AND FEES mode displays how user’s Net P/L was altered for trade operations performed for specific time periods.

 

 

The section 'Total' is displayed by default in all the tabs. Volume bars are plotted on the chart regardless of the selected horizontal scale type (Operations, Trades & Fees, Days, etc.) and is displayed in lots.

The horizontal scale allows plotting the P/L chart by operations or by hours/days/months. If the section 'hours/days/months' are selected, then all operations are aggregated by hours/days/months.

 

 

Cumulative P/L tab- Aggregated mode

Aggregated P/L charts display Gross and Net P/L for selected 'aggregation' interval. In order to enable aggregated mode, use the button 'Aggregate'.

Aggregation interval allows aggregating P/L chart according to the required periods. Ex: Months, days and hours. The charts can be also displayed based on the trading side or set to “Total.”

 

 

2) Trades population-

Trades population is a combination of winning/losing trades and trades populated by symbol’s.
Winning/losing trades section displays data by Total number of trades for a certain period and can be viewed separately for Buy and Sell trades.
Each tab contains the following data:

  • Loss – shows total loss for the selected period.
  • Win – shows total profit for the selected period.
  • Trades – displays the total number of trades for the selected period, number of losing/winning trades and their total percentage.
  • Average – displays the average value of P/L and the average loss/win for losing/winning trades.
  • Max consecutive – shows the longest series of wins/losses and their value in monetary terms.
  • Largest – displays the largest profit (win)/loss of a single trade for a selected period.

 

 

Trades population consists of two charts:
Pie chart- Illustrates the number of completed trades for individual symbol’s and shows their values in % of total trades
Profitable chart- Selected symbol from the pie chart.

When a user clicks on a certain sector of the pie chart, the corresponding line in the symbol list is highlighted and the corresponding profitable chart by this symbol is displayed. Likewise, when a user clicks on the row from the symbol list, the corresponding sector of the pie chart is highlighted and the corresponding profitable chart by this symbol is displayed. Profitable chart displays Cumulative P/L and trade volumes for the selected symbol within the period of strategy work.

3) Drawdowns-

The last tab of the Performance panel is the Drawdown chart. The chart shows the graphical distribution of drawdowns built trade by trade. Trade volumes, shown in lots are also displayed on the chart.

In addition, the tab displays three indicators
Maximal drawdown – Highest difference between one of the local upper extremums of the balance chart and the following lower extremums.
Absolute drawdown – Difference between the current capital and the current local upper extremum.
Average drawdown – Arithmetic average of all drawdowns over a given time period.

 

 

Logs-

Logs tab shows information about the backtesting process and errors if there are any. They can be cleared or copied through the context menu.

 

 

Positions History-

The positions history tab shows the trading history of positions during backtesting. The backtesting range can be set in Backtesting setup >> Range. Column headers can be customized by right- clicking on the existing headers and ticking the ones to be displayed.

 

 

Backtesting Types-

There are two ways of backtesting strategies on AlgoStudio

  • Quick backtesting
  • Visualize backtesting.

To go to the Backtesting mode, click on the button. The Backtesting type can be selected from the drop-down menu
Quick backtesting allows users to rapidly test strategies on historical data without including graph visualization during backtesting. Here, the chart with all details about open and closed positions will only appear after the backtesting is completed.
Visualize backtesting allows users to view actual trading visuals on the chart during the backtesting process.

Backtesting Properties-

Before beginning backtesting, users can setup all the required parameters from the Properties panel

  •  

     

    To include more than one symbol to backtest data, click on “Additional data” and add the required symbols

     

     

    After selecting the backtesting type, users can start backtesting by hitting the F5 key or clicking the button from the main menu. To stop backtesting, hit the button and to compile modules, click

    Saving, importing & exporting strategies-

    After successfully testing a strategy against historical data, users can save the source code. To do this, click on the buttons to SAVE, SAVE AS and SAVE ALL correspondingly. To export strategies, click on the button from the AlgoStudio toolbar or from the main menu and select “Export Script Settings” to export

     

       

     

    Users can also import strategies by clicking the button from the AlgoStudio toolbar. Additionally, if users have compiled an indicator or strategy in AlgoStudio but do not have the source code for it, AlgoStudio will still permit the user to run the code and test historical data.
    To do this, select the recompiled file with the strategy and upload it to AlgoStudio. Then simply proceed to testing as if it were an indicator or a strategy with source code.

    Optimization

    The last stage of testing strategies in AlgoStudio involves optimization of the created module. Users can do this using the Optimization panel. To open the panel, click on the button under the main header in AlgoStudio. Users can select any of the two options from the optimization panel using the drop-down menu

    Optimization mode-

    It is the simplest way to carry out optimization by using the whole range of data for optimization purposes. After completing the process, user’s will view the table and the results of the optimization process.

    Walk forward mode-

    Walk forward is a type of step-optimization where the entire range is split into In-Sample and Out-of-sample periods. The process involves testing In-sample periods with Out-of-sample by following the same procedure used to generate In-sample optimization. This type of optimization is used to get rid of script “addiction” to a particular behaviour of an instrument which generally arises during the optimization period.

    Strategy variables, targets, optimizer limits-

    By clicking the Optimization panel, users can access and setup optimization parameters such as Strategy variables, targets and optimization limits.

    Strategy variables-

    Here, users can select all strategy variables which can be used as subjects of optimization. Minimum and maximum values can be set for each selected variable.

     

     

    Targets-

    It is necessary to set Target functions for modules. These functions can be set for individual modules separately. Target functions comprise off-

    • Profit
    • Gross profit
    • Average profit
    • Profit factor
    • Recovery ratio
    • Payoff ratio
    • Sharpe ratio
    • Annualized gain
    • Relative drawdown
    • Max drawdown
    • #Trades
    • Win/Loss ratio

    Optimization limits-

    Finally, users can select optimization limits with which the strategy will be optimized

     

     

    Click the button and choose from the following options:

    • Profit
    • Gross profit
    • Average profit
    • Profit factor
    • Recovery ratio
    • Payoff ratio
    • Sharpe ratio
    • Annualized gain
    • Relative drawdown
    • Maximal drawdown
    • # Trades
    • # Avg. trades per day
    • Win/Loss ratio
    • Average win
    • Average loss

    Optimization result table-

    The optimization process and the results are visible in the Optimization result table. Here, users can find all optimization results and choose the best strategy variables/ values for future requirements.

     

     

    Export/Import optimization results-

    Optimization results can be exported/ imported to/ from a .XML file for further analysis by right- clicking in the optimization window and selecting “Results” from the context menu. Likewise, the results can also be exported to multiple sources by choosing “Export” in the context menu.

     

     

    Walk forward result table-

    The walk forward result table starts from the row with the best version of first-step optimization and the backtesting row for this version. All other rows show information for Optimization and Backtesting. Walk forward optimization stops when the range ends.
    The results of walk forward can also be exported/ imported to/ from a .XML file

     

     

    Optimization chart-

    Optimization settings and results can also be viewed graphically by clicking on the “Chart icon.” Select parameters for X and Y axis to see the dependence between them. Users can also select the Optimization index and different kinds of chart types.

     

     

    Database

     

    Using database in Algo Studio-

    Database comprises of instrument settings to test strategies accurately which can eventually be updated on request. It is an integral part of AlgoStudio and contains historical data loaded from the server.
    When a user runs AlgoStudio for the first time, the database created from the PFSOFT demo server will run by default. If there is no existing databases, users will have to create it from Database>> Create.
    For more information on the process to create database, click HERE
    To familiarise with the components of a database, go to Database >> View.
    Database view tab consists of three sections: Symbols, Assets and History.

    The ‘Symbols’ section contains the list of all the available symbols of scrips. Choose any symbol from the list to view its parameters.

     

     

    Likewise, the ‘Assets’ section contains all assets that are currently available for trading and their parameters.
    The last section is ‘History.’ It displays historical data for tradable instruments. The data can be used to test scripts and construct indicators.

     

     

    To run the script in AlgoStudio, users should choose the symbol and its parameters according to the existing history in the Properties tab. If the symbol and its parameters are chosen correctly, then the symbol’s chart will be displayed in the Backtester panel which can be used to run the script.

    Creating a database-

    If there are no active databases while opening AlgoStudio, the system will indicate the same to the user to create a new database or open an existing one.

     

     

    If a user is also logging in to AlgoStudio for the first time, a new database has to be created.
    To create a new database, go to Database >> Create
    Choose any of existing connections in the Connection field or use a new one. Users should also specify the name and path for the database which will be created in the corresponding fields. After filling out all the fields, click the 'Create' button. AlgoStudio will connect to the server and load all the required data excluding historical data.

     

     

    To load historical data, select the scrips, the required parameters to be downloaded and click on 'Create.’ The historical data for all the selected parameters will be applied to the new database.

     

     

    Adding/Running scripts-

    To run scripts on the trading platform, assign hotkeys in the “Main terminal settings.”
    Go to Environment >> Settings >> Hotkeys.
    In the Hotkey section, click on the button and the following drop-down menu will open up. Here, users can choose either of the two types of macro assignments: Run macros and Quick run macros.
    If “Run macros” is selected and a macro is initiated by the hotkey, users will be able to change the default parameters for the script.
    In “Quick run macros,” the parameters are set when the hotkey is hit and they can’t be changed during script execution.
    After selecting one of the functions, the “Scripts lookup” will open up and users can select scripts to be added to the hotkeys list. If a user chooses “Quick run macros,” all strategy parameters should also be selected from the properties window.