protrader algostudio user manual

60
ALGOSTUDIO USER MANUAL Protrader 2 Knowledge Base www.kb.protrader.net

Upload: bonifaci

Post on 17-Jan-2016

269 views

Category:

Documents


52 download

DESCRIPTION

AlgoStudio is an integral part of the Protrader 3 platform. It is a seperate window which can be openedby navigating to the Tools tab and choosing the AlgoStudio panel.

TRANSCRIPT

AlgoStudio

uSer MAnuAl

Protrader 2 Knowledge Basewww.kb.protrader.net

AlgoStudio User Manual

2

AlgoStudio User Manual

3

Content1. Introduction to AlgoStudio..........................................................................................................4

2. Starting AlgoStudio and preparing the work environment......................................................4

3. Indicator modules, strategies, and scripts................................................................................6

4. Documentation for programming languages MQL4 and C#...................................................11

5. The Editing Panel........................................................................................................................13

6. The Backtesting panel................................................................................................................22

7. The Optimization panel..............................................................................................................39

8. The History Data Manager.........................................................................................................43

9. The Trading System List.............................................................................................................48

10. Running Scripts........................................................................................................................54

AlgoStudio User Manual

4

1. introduCtion to AlgoStudioAlgoStudio is a programming environment for AlgoTraders. It is an integral part of the all-in-one Protrader 2 platform.

• Main Features:• The ability to create indicators, strategies (Expert Advisors) and scripts (macros),• Support for programming languages MQL4 and C# (.NET platform),• The History Data Manager tool for creating customized instruments or importing data from differentsources,• The capability to perform backtesting on custom historical data or data provided by a broker,• Backtesting of single instruments or multiple instruments simultaenously,• The possibility to backtest multilple time intervals (support for non-standard time intervals such as M7, H3, D5, etc.),• The possibility to backtest all chart types available on the platform Protrader 2 (Renko, 3 Line Break, Kagi, Price Range, etc.),• Strategy testing in ticks, minute, or daily data,• The possibility to test strategies at Bid, Ask, and Trade prices,• Two strategy testing modes: with visualization or without visualization,• Two emulation types: one position or multiple positions,• Capability to use functions that provide access to Level II,• Strategy optimization tool,• Plain text and graphic reports,• Editor with IntelliSense support,• Dictionary with a list of all availabile functions in AlgoStudio,• Debugger,• TheProfilertoolforstrategyanalysisandeffeciency,• A tool for importing and exporting parameters of testing strategies.

2. StArting AlgoStudio And prepAring the work environMentAlgoStudio is an integral part of the Protrader 2 platform. It is a seperate window which can be opened by navigating to the Tools tab and choosing the AlgoStudio panel.

AlgoStudio User Manual

5

LikeProtrader2,AlgoStudioisafullycustomizabledevelopmenttool.Userscanconfiguretheworkenvironment according to their preferences. All windows appearing in AlgoStudio can be added, removed,ormovedtoadifferentplace.

ThescreenshotbelowshowsthepossibilitiesforconfiguringAlgoStudio.

AlgoStudio User Manual

6

3. indiCAtor ModuleS, StrAtegieS, And SCriptSTo begin writing source code for a new indicator, strategy (Expert Advisor) or script (macro) open AlgoStudio and choose the New Module icon or use the hotkey Ctrl+N.

A window will appear which requires the user to choose the programming language for the module. The choices are MQL4 and C#.

AlgoStudio User Manual

7

Depending on the choice of programming language, the next step of the creation process prompts the user to select a template for the module. The following templates are available:

• For MQL4 – Indicator, Advisor, Script, Library

• For C# – Indicator, Trading System, Macros

AlgoStudio User Manual

8

Afterselectingatemplate,usersarepromptedtospecifyamodulenameandalocationwherethefilewith source code will be saved. The default location is the Protrader 2 home folder (Users>Username>AppData>Roaming>Protrader2).

The next step allows the user to specify an author name, add comments, and specify company and copyright information.

AlgoStudio User Manual

9

In the last step, users can set the module version and protect the source code with a password. It is also possible to set an expiration date after which the module will not be able to be opened.

Upon clicking Finish, the user template will appear in the source code editor window. Now it is possible to begin writing code.

AlgoStudio User Manual

10

Pre-existing code or fragments of source code can be uploaded to AlgoStudio by saving to the Protraderlocalfolder.Toopenafile,clicktheOpen icon in AlgoStudio or press the hotkey Ctrl+O. Source code can also be uploaded to the editor with help of the Script Navigator.

Clicking the down arrow beside the Openiconwillshowalistofsourcecodefilesthatwerepreviouslyopened in the AlgoStudio editor.

AlgoStudio User Manual

11

Likewise,tosaveworktoafile,clicktheSave icon in AlgoStudio.

OrclickthedownarrowtouseSaveAs…whichallowssavingthefileunderadifferentname.

4. doCuMentAtion for progrAMMing lAnguAgeS MQl4 And C#AlgoStudio features a Dictionary tool, which shows all functions of the MQL4 language with brief descriptions and all classes and methods in C# that can be used for writing source code.

The Dictionary tool can be started from AlgoStudio by choosing the Dictionary icon.

AlgoStudio User Manual

12

The Dictionary will open as a new panel. Select Advanced > Language to choose a language.

Users can also use the Search panel in the Dictionarytooltofindspecificfunctions.

AlgoStudio User Manual

13

Full documentation on the MQL4 language can be found on the MetaQuotes company site: http://docs.mql4.com/

Likewise, full documentation on the C# language can be foudn on the Microsoft company site: http://msdn.microsoft.com/en-us/library/ff361664.aspx

5. the editing pAnelThis chapter is about the Editor panel which is one of the three main AlgoStudio panels.

the SourCe Code editor

The source code editor in AlgoStudio is a fully professional tool to facilitate the writing of source code. It features syntax highlighting and supports Intellisense technology.

ThetoppartoftheEditorpanelfeaturesahelptoolbarforeasysearching,filtering,insertingcomments,and undoing work.

Thefirstbuttoninthetoolbar,Undo,allowsuserstoreversechangesstepbystepuntiltheyhavefindthe necessary stopping point.

AlgoStudio User Manual

14

The next button, Redo, allows users to move forward step by step after using Undo..

The next available button, Find,allowsuserstosearchforaspecificphraseinthesourcecodeorreplace an existing phrase with another phrase.

AlgoStudio User Manual

15

The Comment button adds a comment to the code.

Likewise the Uncomment button removes a comment from the code.

The last feature of the Editor toolbar is a dropdown list of methods, functions, properties, variables, andfieldswhichcanbefoundinthesourcecode.Thelistwasdesignedforthebestnavigationwithincode. Selecting from this menu places the cursor immediately at the corresponding place in the code.

AlgoStudio User Manual

16

SCript nAvigAtor

The Script Navigator is a tool, which shows all indicators, strategies (EA) and scripts (macros) created by the user. Note however that all scripts are stored in the directory Macros. Clickonthefileandthesource code will open in the Editor panel.

propertieS

The properties window shows all information about indicators, strategies (Expert Advisors) and scripts (macros). It has three sections. First, Script info shows general information about an indicator, strategy (Expert Advisor) or script (macro). The following section Back testing setup gives all parameters of backtests. The last section Optimization setupoffersachoiceofparametersforoptimizingstrategies(Expert Advisor).

AlgoStudio User Manual

17

teSter

The Tester panel is a chart which can be used to show backtests conducted on historical data.

ThistoolcanitselfbeconfiguredjustlikeanyotherpanelinProtrader2.Ithasamenuthatcanbeaccessed by right clicking the mouse. When viewing the menu, selecting Settings will open a new window that allows users to select their own preferences.

AlgoStudio User Manual

18

profiler

TheProfilerisusedtooptimizesourcecode.Itgivesusersavisualrepresentationofhowfunctionsarerunthroughthebacktester,andthenumberoftimesafunctionwasinvoked.TheProfilershowstheexact working time of the function in milliseconds and percent as well as the function type.

TheProfilertoolcanbestartedfromwithinAlgoStudiobyclickingontheProfiler icon.

diCtionAry

The Dictionary is described in detail in chapter 4.

AlgoStudio User Manual

19

output

The Output tool is used to show system communication (such as errors) during compilation,

or messages from the strategy (Expert Advisor) to the Output tool during backtesting.

AlgoStudio User Manual

20

wAtCh

The Watch tool is used for debugging source code. Users can debug both C# and MQL4 code.

Tobegindebuggingsourcecode,usersshouldfirstsetbreakpoints.

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. After placing a breakpoint it will be visible in the margin as a red circle.

Next, select the variables which are to be checked and add them to the Watch tool. In order to do this, put the mouse over the variable to add to Watch, then click on the right click and select Add Watch from the menu.

AlgoStudio User Manual

21

The chosen variable will appear in the Watch window.

Now the code can be debugged by selecting Debug from the dropdown menu in the AlgoStudio toolbar.

The Debug tool is also available by pressing the hotkey F5. Each keystroke of F5 will run the debugger.

AlgoStudio User Manual

22

If using tables in the Watch tool, users can click on View the button to see the value of an array.

6. the BACkteSting pAnel.The Backtesting panel is the heart of AlgoStudio. It is used for testing strategies on historical data. To view this panel simply click on the Backtesting tab.

AlgoStudio User Manual

23

Now a strategy can be prepared with which we will conduct tests on historical data. To do this set the parameters in the Properties window.

InthefirstfieldchoosetheSymbol for backtesting from the list of available instruments.

AlgoStudio User Manual

24

Next specify the time frame or chart type in the Time Framefield.

Usershavetheoptiontocreatedefinenon-standardtimeframsorchart types.TodothisclicktheCustom button.

AlgoStudio User Manual

25

Upon clicking the Custom button, the Custom time frame window will show with editable parameters for creating custom time periods or chart types.

Next, a Rangemustbedefinedduringwhichthestrategytestingwillbeconducted.

AlgoStudio User Manual

26

Choosing the Custom option in the drop-down menu will allow users to select a custom date range with start and stop times.

ThenextstepistodefinetheData Type with which the backtest should be carried out. There are three data type options: Bid, Ask, Trade.

The next step is to determine any Additional Data which will be used for backtesting. To do this select the Additional Data button and a popup window will open with Backtesting data edit. Here users can select all additional needed instruments simultaenously and their relative periods, ranges, and data types.

AlgoStudio User Manual

27

To remove an instrument from the Backtesting data edit window simply click the Remove button.

The next step is to determine the backtesting Type (typ backtestu). The following options are available: C, OHLC, OHMLC, O OH/2 H HL/2 L LC/2 C (the letters are abbreviated from candle types on the chart: Open, High, Low, Close).

The type of backtest is the main type that the backtester will use if the user does not select additional data for the test.

InthecasewhenauseraddsaninstrumenttotheBacktestingdataeditwindowandspecifiestheperiodatatickor1M,thebacktesterwilltestthetickdataor1Mwithoutthemainbacktesttype.Inthiswayitispossibletobacktesttickdataor1Mdata.

AlgoStudio User Manual

28

The next step is to specify a Balance (an initial deposit) and a percentage level at which there will be a Stop Out operation.

The Commission Type can also be set. The following options are available: Lot and Deal.

Then Commission Value and Leveragecanbedefined.

AlgoStudio User Manual

29

The last option is for OnePositionMode. This option limits the test to open only one position upon fulfillmentofcertainconditionsfromthesourcecode.Itwillonlybepossibletoopenanotherpositionafterthefirstpositionisclosed.

Onceallparametersofthebacktesthavebeenconfigured,theusercanproceedtoteststrategieson historical data. To do this the user must choose the type of backtesting. In the upper toolbar of the Backtesting window the user can choose from one of the two backtest options: Quick backtesting lub Visualize backtesting.

The Quick backtesting option allows users to rapidly test strategies on historical data without the graph visualization during backtesting. In this mode, the chart with all details about opened and closed positionswillonlyappearafterthebacktestinghasfinished.

AlgoStudio User Manual

30

The Visualize backtesting option allows users to see what is happening on the chart while the backtest is taking place.

After selecting the backtest type, press F5 or click the Run button in the menu bar to launch the backtester.

When conducting the strategy test in Visualize backtesting mode the user is able to control the backtest’s speed but moving the slider on the graph.

AlgoStudio User Manual

31

When conducting a strategy test on a number of instruments, which were added to the Backtesting data edit window, the user can switch between instruments and view the results in the chart window for instruments.

Uponfinishingthebacktest,theChart tab will show a graph with all positions that were opened and closed during the test run and also all automatic indicators that were used during the test.

AlgoStudio User Manual

32

The next tab, Trades history, shows the history of transactions that were made during backtesting.

UserscanconfiguretheTrades history tab according to their preferences by right clicking within the Tradeshistorytabandselectingsettingsfield.

AlgoStudio User Manual

33

After selecting Settings…theuserwillbeabletoconfigurethetableandcolumnsofTrades history.

The Positions tabshowsonlythepositionsthatwereopenedduringthetest.Itcanbeconfiguredinthe same way as the Trades history tab.

AlgoStudio User Manual

34

The following tab is the Order book,whichshowsallordersopenedduringthetest.Itcanbeconfiguredin the same way as the Trades history tab.

Another important tab for analysis is the Performance tab. The Balance Gain or positions is shown as a graph of balance and equity on the chart.

Using the Summary table within the Performance tab, users can see the summary of performance in table form.

AlgoStudio User Manual

35

The chart also shows P/L by month(Profit/Losspermonth).

AlgoStudio User Manual

36

P/L by day of the weekgivesavisualizationofprofitandlossoneachdayoftheweek.

Likewise, P/L by hour of the daygivesavisualizationofprofitandlossoneachhouroftheday.

AlgoStudio User Manual

37

The last chart in the Performance tab is the Trade population illustration. It shows a graph of the number of completed trades for each individual instrument.

The last tab in the Backtesting panel is the Logs tab, in which we see all information from the backtest in step-by-step form.

AlgoStudio User Manual

38

After successfully testing a strategy against historical data, users can save the settings to a strategy file.Todothis,selecttheExport icon from the AlgoStudio toolbar.

This will open the Export Strategy params window, where the users can select which parameters toaddtothefile.

Users can also import previously saved settings from earlier tests of strategies. To do this, click on the Import button in the AlgoStudio toolbar.

AlgoStudio User Manual

39

Testing compiled indicators or strategies (without source code)

If a user has compiled an indicator or strategy in AlgoStudio but does not have the source code for it, AlgoStudio will still allow the user to run the code and test it on historical data. To do this select the recompiledfilewiththestrategyanduploadittoAlgoStudio.Thensimplyproceedtotestingasif itwere an indicator or strategy with source code.

7. the optiMizAtion pAnelThe Optimization panel is the last available panel in AlgoStudio and is used for strategy optimization.

Tobegintheoptimizationstrategy,usersmustfirstuploadandtesttheirstrategiesagainsthistoricaldata. Then in the Strategy Variables window variables will appear which can be subjected tooptimization. The user can now choose which parameters to optimize.

AlgoStudio User Manual

40

In the next step the user can select (it is not mandatory) the optimization limits with which the strategy will be optimized. To do this, simply click Add limit, andthenchoosefromtheavailableoptions:Profit,GrossProfit,AverageProfit,ProfitFactor,PayoffRatio,AnnualizedGain,MaxDrawDown.

Upon selecting optimization parameters, use the hotkey F5 or click on the Run icon to start the optimization process.

The optimization process is visible in the Table.

AlgoStudio User Manual

41

UserscanconfiguretheTable by right clicking within the Optimization window and selecting Settings.

AlgoStudio User Manual

42

Optimization setings are also represented graphically in the Chart.

Users can select which data is presented on the X and Y axis. Currently there are 35 variable choices.

AlgoStudio User Manual

43

Similarly, there are 3 available graph views: Line, Histogram, Point.

8. the hiStory dAtA MAnAgerHistory Data Manager is used for creating custom instruments and importing data to them. These instruments can be used during testing of strategies on historical data in AlgoStudio.

History Data Manager is not directly integrated into AlgoStudio. It can be launched by going to Tools and clicking on the History Data Manager icon in the Protrader 2 menu.

To create a new instrument select the Create button and specify a name for the instrument.

AlgoStudio User Manual

44

After doing this, users can proceed to import historical data. History Data Manager allows 3 types of historical data: Intraday, Day, and Tick.

Next the user must specify a Period for the imported data. The below illustration shows the periods for Intraday data.

AlgoStudio User Manual

45

In the next stage users need to specify the History type. This is the type of historical data that will be imported into the instrument.

The Setup tab allows users to select instrument settings.

AlgoStudio User Manual

46

After completing the instrument settings, users can proceed to import historical data. Historical data canbeimportedfromonesinglefileofagroupoffilesinthesamedirectory.Forthispurposeweseethe buttons Group Import and Import.

Upon selecting one of the options the Import data window appears. In this window users must select thepathtothedatafile,thefieldseperator,date,andtimeformat.Userscanalsospecifyadditionalinformationsuchastimezoneofoffset.

After clicking on the Importbuttonallspecifiedhistoricaldatawillbeloadedintotheinstrumentandwill be seen in the graph window of History Data Manager.

AlgoStudio User Manual

47

Upon retrieving the historical data, users can convert time periods. To do this, click Highest Periods and the Build Highest Periods window will appear where users can select the period to which the data should be converted.

AlgoStudio User Manual

48

If the user does not have any historical data, it can be downloaded directly from the PFSoft server. To do this click the Load button and select the instrument and time interval for each type of data.

9. the trAding SySteM liStOnce a user has tested a strategy on historical data they can run the strategy on a Protrader demo server or a Protrader live server. For this purpose we have the Trading System List. To run the Trading System List, navigate to the Terminal part of the ribbon and select the icon Trading System List.

AlgoStudio User Manual

49

The Trading System List can be docked into the Protrader 2 interface.

Users can add one or more of their strategies in the Strategies section of the panel. To do this click on the Add strategy button.

This will open the Script Lookup window where users can select the appropriate strategy to load into the Trading System List. The chosen strategy will show in the Strategies section.

AlgoStudio User Manual

50

The next step for setting up a strategy is to edit parameters in the Propertieswindow.Thefirstoptionis choice of the account that the strategy will run on.

The next choice is the instrument.

AlgoStudio User Manual

51

The user can also specify (not mandatory) a Hotkey which will run the strategy.

The next option is the Time Frame that will be used when the strategy launches. As with AlgoStudio users can create custom time intervals and chart types for the strategy by clicking Custom.

AlgoStudio User Manual

52

Lastly, the user must specify input parameters for the strategy.

Upon selecting all necessary Properties, users can run the strategy by clicking on the start button in the Strategies window.

When a strategy is running all open orders are visible on the chart.

AlgoStudio User Manual

53

Choosing the Performance tab gives users access to real-time strategy results in tabular and graphic form. These results are presented in the exact same manner as in AlgoStudio.

All currently open positions are visible in the Positions tab.

The Order book tab gives indicitave information about orders.

Trades history shows the historical information of all trades.

AlgoStudio User Manual

54

The Logs tab shows the history of strategy runs.

The Strategy info window gives all up-to-date information on running strategies.

10. running SCriptSRunning a script on the Protrader 2 platform is done assigning hotkeys in the main settings for Protrader 2.

To do this, select the Settings icon from the Environment tab in the ribbon. Then select the Hotkeys section in settings.

AlgoStudio User Manual

55

Then in the Hotkeys section click on Create custom action. A window will appear with a choice between type types of macro assignments: Run Macros and Quick run Macros.

AlgoStudio User Manual

56

ThedifferencebetweenthetwoiswhenRun macros is selected and a macro is initiated bya hotkey the user will have the possibility to change default parameters for the script.

Quick run Macros has parameters that are set when the hotkey is hit and they can not be changed during script execution.

The screenshots below show both situations:

Making a script with Run macros takes place in the following manner.

A window appears with a list of scripts (macros) that can be used.

AlgoStudio User Manual

57

Select a script and assign a hotkey then press the Set button.

Scripts can be edited by clicking on Edit. Scripts can be deleted by selecting Remove.

AlgoStudio User Manual

58

If choosing a script with type Quick Run Macros users should proceed in the same way.

Theonlydifference is thatafterselectionof thescript (macro)userswillbeprompted toselectallparameters for the script which will then be invoked automatically.

AlgoStudio User Manual

59

PFSoft LLC

Office#70110B,MechnikovaStreetDnepropetrovsk,Ukraine,[email protected]

www.protrader.net