user guide - megatrader 1.4.en.pdf · • install the megatraderexchange 1.2 ea in mt4. • set the...

168
MegaTrader 1.4 User guide

Upload: others

Post on 20-Jun-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

MegaTrader 1.4

User guide

Page 2: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Table of ContentsMegaTrader 1.4 ..................................................................................................................................... 5

Overview .............................................................................................................................................. 6Getting started ..................................................................................................................................... 7

Installation .......................................................................................................................................... 8Setting up MetaTrader ...................................................................................................................... 9Setting up SaxoTrader .................................................................................................................... 14Program setting up .......................................................................................................................... 15Working with multiple Megatrader instances ................................................................................... 21Launching Megatrader ..................................................................................................................... 22

Program interface .............................................................................................................................. 23Main menu ....................................................................................................................................... 25

File ................................................................................................................................................. 26Connection .................................................................................................................................... 28Chart .............................................................................................................................................. 30Script ............................................................................................................................................. 32Settings ......................................................................................................................................... 33Help ............................................................................................................................................... 34

Chart ................................................................................................................................................ 35Trade panel ..................................................................................................................................... 37

Trading tab .................................................................................................................................... 38Messages tab ................................................................................................................................ 40

Settings ............................................................................................................................................ 41Common settings .......................................................................................................................... 43MetaTrader settings ...................................................................................................................... 45

Composite instrument settings ........................................................................................................ 46Instruments tab ............................................................................................................................. 48Additional settings ......................................................................................................................... 52

MetaTrader instrument settings ....................................................................................................... 53Common settings .......................................................................................................................... 54Additional settings ......................................................................................................................... 56

SaxoTrader instrument settings ...................................................................................................... 57Common settings .......................................................................................................................... 58Additional settings ......................................................................................................................... 59

QuoteSpeed instrument settings ..................................................................................................... 60Common settings .......................................................................................................................... 61Additional settings ......................................................................................................................... 62

Script editor ..................................................................................................................................... 63Toolbar ........................................................................................................................................... 64Menu ............................................................................................................................................. 66

File .............................................................................................................................................. 67Edit .............................................................................................................................................. 68

Global variables ............................................................................................................................... 69Script backtester .............................................................................................................................. 71

Settings tab ................................................................................................................................... 73Report tab ..................................................................................................................................... 75Transactions tab ............................................................................................................................ 76Balance chart tab .......................................................................................................................... 77

Indicator parameters ....................................................................................................................... 78License management ...................................................................................................................... 80

Indicators ........................................................................................................................................... 81

Page 3: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Mean Price ...................................................................................................................................... 82Moving Average .............................................................................................................................. 83Exponential Moving Average ........................................................................................................... 84Bollinger Bands ............................................................................................................................... 85

Scripting language ............................................................................................................................. 86Language description ...................................................................................................................... 87

Language elements ....................................................................................................................... 88Operations and expressions ......................................................................................................... 90Statements .................................................................................................................................... 92Data types ..................................................................................................................................... 95Variables ........................................................................................................................................ 97Functions ....................................................................................................................................... 99Program execution ...................................................................................................................... 100

Built-in functions ............................................................................................................................ 101Type conversion .......................................................................................................................... 102

Integer ....................................................................................................................................... 103Float .......................................................................................................................................... 104String ......................................................................................................................................... 105

Date and time ............................................................................................................................. 106DataTimeToStr .......................................................................................................................... 107DateToStr .................................................................................................................................. 108TimeToStr .................................................................................................................................. 109StrToDateTime .......................................................................................................................... 110StrToDate .................................................................................................................................. 111StrToTime .................................................................................................................................. 112Day ............................................................................................................................................ 113Month ........................................................................................................................................ 114Year ........................................................................................................................................... 115Hour .......................................................................................................................................... 116Minute ....................................................................................................................................... 117Sec ............................................................................................................................................ 118MilliSec ...................................................................................................................................... 119DayOfWeek ............................................................................................................................... 120

Global variables .......................................................................................................................... 121GetGlobVar ................................................................................................................................ 122SetGlobVar ................................................................................................................................ 123

Mathematics ................................................................................................................................ 124Abs ............................................................................................................................................ 125Ceil ............................................................................................................................................ 126Floor .......................................................................................................................................... 127Sign ........................................................................................................................................... 128Max ........................................................................................................................................... 129Min ............................................................................................................................................ 130Pow ........................................................................................................................................... 131Sqrt ............................................................................................................................................ 132

Data ............................................................................................................................................. 133Bid ............................................................................................................................................. 134Offer .......................................................................................................................................... 135SymbolBid ................................................................................................................................. 136SymbolOffer .............................................................................................................................. 137SymbolLastChange ................................................................................................................... 138

Page 4: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Chart data functions .................................................................................................................... 139PointCount ................................................................................................................................ 140Point .......................................................................................................................................... 141SymbolBidPoint ......................................................................................................................... 142SymbolOfferPoint ...................................................................................................................... 143DateTime ................................................................................................................................... 144Index ......................................................................................................................................... 145Shift ........................................................................................................................................... 146

Trading functions ......................................................................................................................... 147Balance ..................................................................................................................................... 148Disbalance ................................................................................................................................ 149TradeQnty ................................................................................................................................. 150GetMaxQnty .............................................................................................................................. 151SetMaxQnty .............................................................................................................................. 152Buy ............................................................................................................................................ 153Sell ............................................................................................................................................ 154Close ......................................................................................................................................... 155

Information output ....................................................................................................................... 156Message .................................................................................................................................... 157Alert ........................................................................................................................................... 158FileClear .................................................................................................................................... 159FileWrite .................................................................................................................................... 160

System functions ......................................................................................................................... 161CurrentDateTime ....................................................................................................................... 162GetTickCount ............................................................................................................................ 163

Script examples ............................................................................................................................. 164Additional modules .......................................................................................................................... 167

SaxoExporter ................................................................................................................................. 168

Page 5: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

MegaTrader 1.4

USER GUIDE

Page 6: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Overview

MegaTrader 1.4 is a software complex for spread and basket trading automation, including pair trading andarbitrage strategies. MegaTrader 1.4's functionality covers all the aspects of spread trading and uncovers all itsadvantages, from spread creation and charting to automatic strategy backtesting and trading on live accounts.One of game-breaker features of MegaTrader 1.4 is the ability to create spreads and baskets of any complexity,combining different instruments from a majority of trading platforms including the popular Metatrader 4. Key features:

• Creating spreads of any complexity

• Simultaneous work with MetaTrader 4, QuoteSpeed and SaxoTrader (can also beconnected to Quik - russian equities market platform) platforms with the possibility ofcombining instruments from different terminals provides a bunch of opportunities:

• Cross-broker Forex arbitrage;• Latency Forex arbitrage (MetaTrader to MetaTrader or SaxoTrader to

MetaTrader, one-legged and two-legged);• Spread trading (pair trading) between ANY instruments available on ANY

MetaTrader 4 broker (a lot of variations);• Basket trading on Forex and derivatives market;• and many others.

• Spread charting with the possibility to apply basic integrated indicators (movingaverages, Bollinger bands, etc.)

• One-click buying/selling of spread.

• Creation of automated trading systems using an integrated scripting language

• Backtesting strategies on historical data.

• Ability to backfill orders with trade delays during backtesting to emulate real marketconditions

How does the program work? Megatrader can receive quotes from any combination of MetaTrader 4, Quik, QuoteSpeed or SaxoTraderterminals. Then according to entered spread parameters it automatically calculates and charts the spread in realtime. When you need to buy or sell spread, the program sends orders to appropriate trading terminals, wherethey are executed according to their weight in spread (lotsizes are calculated automatically). So, one can justanalyze synthetic composite instrument like it’s an individual one: look at the chart, buy or sell the whole basket,while Megatrader does all the needed calculations and cross-program communications.

Page 7: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Getting started

Page 8: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Installation

To install the program you should first download the setup file and run it. Next, you will need to choose theinstallation directory and then follow the installer instructions. If you want to run multiple instances of the program, you will need to install each instance in a separate directory(see Working with multiple Megatrader instances). By default, installer will create a "Start" menu group "MegaTrader", with which you can launch the program, openthe help file, and delete the program from your computer. In addition, the program can be run directly from theinstallation directory. To do this, run a file called "MegaTrader 1.4.exe". Remark. You cannot run two copies of the program at the same time from the same directory. To run multipleinstances of the program, you must install the appropriate number of copies in different directories.

Page 9: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Setting up MetaTrader

For MegaTrader 1.4 to exchange data with and send trade orders to MetaTrader 4, the following actions must beperformed:

• Install the MegaTraderExchange 1.2 EA in MT4.• Set the MetaTrader 4 terminal up.• Launch the MegaTraderExchange 1.2 EA.

Installing the expert advisor MegaTraderExchange 1.2 EA was developed to provide a data exchange channel between MegaTrader 1.4 andMetaTrader 4. EA file is called "MegaTraderExchange 1.2.ex4" and is located in MegaTrader 1.4's installationdirectory. You should place the file into "experts" folder of Metatrader 4 directory. If done correctly, MegaTraderExchange 1.2 should appear in the "Navigator" tab:

Setting up MetaTrader 4 First open settings window by going to "Tools > Options":

In the appearing window choose the "Experts" tab, then you should check "Enable expert advisors", "Allow livetrading", "Allow DLL imports", "Allow external experts imports" and turn "Ask manual confirmation" and "ConfirmDLL functions calls" off:

Page 10: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Also, it would make terminal faster and lessen internet traffic consumption if symbols that are not used wereremoved from Market Watch window. To set up symbols list right-click on the "Market Watch" and in the resulting menu choose "Hide all":

Page 11: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

As a result,all symbols except those with open charts will dissapear. Now only necessary symbols can be added.From the "Market Watch" menu "Symbols" should be chosen:

A window with a list of available symbols, divided into groups, appears. To add a symbol to the list of instrumentsthat need to get quotes, just select the symbol and click "Show" or simply double-click it in the list:

Running advisor

Page 12: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

To start EA it should be attached to any chart. To do this, just drag the MegaTraderExchange 1.1 from the"Navigator" tab on any open schedule. In this case, a window appears expert special settings, two tabs:"General" and "Inputs". On the "Common" tab, make sure that the "Positions" are set to "Long & Short", check the "Allow live trading","Allow DLL imports", "Allow external experts imports" to be turned on and flags "Ask manual confirmation" and"Confirm DLL functions calls" off:

"Inputs" tab contains expert advisor's settings:

"RestartTerminal" - this parameter specifies if the EA should restart Metatrader in the case of error. It is a wellknown issue with Metatrader 4 that it does not recover correctly after disconnecting from the server or othererrors. The only solution in this situation is to restart the terminal. If set to true, in the event of such failure, theterminal will be automatically restarted. "ModifyOrders" - this parameter specifies method of setting SL and TP levels. When using a broker with MarketExecution (most ECN/STP brokers), order should first be placed without TP and SL, then the values are sent

Page 13: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

with an order modification request (OrderModify function). So you should better turn it on if on a ECN broker andusing TP and SL. After configuring the advisor and clicking "Ok" it will be attached to the chart. In the upper-right corner a smileywith the name of EA should appear:

Make sure that "Expert advisors" is turned on on the toolbar, if turned off click it to turn it on:

If everything is set up correctly, the smiley icon will smile, otherwise it will be a sad smiley.

Page 14: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Setting up SaxoTrader

SaxoTrader does not support any means of direct quotes export like MetaTrader, so we had to develop a specialmodule, SaxoExporter, which gets quotes directly from Saxotrader’s “Forex Orders” and "Futures Orders"windows. So, all the pairs that are exported from SaxoTrader should have a "Futures Orders" or “Forex Orders”window opened:

Page 15: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Program setting up

Standard configuration of the program includes two steps:

• General software set-up.• Spread creation

Note. This section covers only basic settings required for software's correct operation. Detailed description ofall program settings can be found in sections Main settings window, Composite instrument settings window,MetaTrader instrument window and SaxoTrader instrument window. 1. Main settings Common settings can be changed in Main settings window, you can get here by going "Settings > Main settings". Common Tab of Main settings shows the parameters to be changed:

These parameters can basically be left default if needed otherwise. You can read about each parameter'sfunction here. Metatrader settings, if needed, are set in the MetaTrader tab:

Page 16: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

A unique ID number of 0 to 19 should be set for each instance of MegaTrader 1.4 working with Metatrader 4 inthe "Terminal ID" tab (more information here). 2. Spread creation. You can create a spread symbol in Composite instrument settings, going to "Settings > Composite instrumentsettings". On Instruments Tab you can see two lists of instruments. In the left list positive symbols (they arecalculated with a + sign in spread) are listed, while negative symbols, calculated with a minus sign, are in theright list:

Page 17: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

You can edit the instruments making the spread using the "Add", "Delete" and "Edit" buttons. When adding a symbol to a composite instrument you will first be prompted with a terminal (Quik, MetaTrader,SaxoTrader or QuoteSpeed) selection window:

Then, depending of your choice, MetaTrader instrument settings, SaxoTrader instrument settings or QuoteSpeedinstrument settings window will appear for further setting up. If Metatrader was chosen, MetaTrader instrument settings window appears:

Page 18: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Those are mandatory fields when adding a Metatrader symbol:

• "Account" - your account number in MetaTrader (can usually be found in Metatrader's caption).• "Instrument" - instrument name in Metatrader (exactly as is, with suffixes/prefixes, e.g. EURUSD.arm or

i_EURUSD).• "Weight" - weight coefficient for spread calculation.• "Lots in spread unit" - a parameter that determines the actual number of lots that will be traded when buying

or selling one unit of the spread.

Note. Detailed description of all settings can be found in section MetaTrader instrument settings. SaxoTrader's symbols set up is made in SaxoTrader instrument settings:

Mandatory fields when adding a SaxoTrader symbol are:

• "Instrument" - instrument name in SaxoTrader (if Saxo has EUR/USD, you should write EURUSD withoutslash).

• "Weight" - weight coefficient for spread calculation.

Note. Detailed description of all settings can be found in sectionSaxoTrader instrument settings. If QuoteSpeed symbol is going to be added, there go QuoteSpeed instrument settings:

Page 19: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Mandatory fields for QuoteSpeed:

• "Instrument" - instrument name in QuoteSpeed.• "Weight" - weight coefficient for spread calculation.• "DDE Bid code" - DDE code for Bid price (is as follows .• "DDE Ask code" - DDE код лучшей цены предложения (Ask) в терминале QuoteSpeed.

Note. Detailed description of all settings can be found in section QuoteSpeed instrument settings. For software to work correctly trading time should be set. It can be set Additional Composite instrument settingsby changing the "Trading time" parameter:

When trading Forex and Futures time should best be set 00:00:00 до 23:59:59. For stock trading, trade sessiontime is better set. If your trading strategy operates in different time "brackets", you should set them (please takethe GMT time difference set in each composite instrument Additional settings into consideration!).

Page 20: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing
Page 21: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Working with multiple Megatrader instances

One copy of MegaTrader 1.4 can simultaneously work with only one spread, with its parameters set in compositeinstrument options. To be able to simultaneously trade multiple spreads, you can run multiple instancessimultaneously, each configured to work with any spread. To work correctly with multiple instances of theprogram, observe the following rules:

1. Each copy must be installed in a separate directory.

2. When working with MetaTrader it is required that each instance has been assigned a unique ID-number (0 to19) (see "Terminal ID" на Main settings\Metatrader).

Page 22: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Launching Megatrader

Depending on terminals used with MegaTrader 1.4, following steps to software launch can be mentioned:

• System launch when working with MetaTrader.• System launch when working with SaxoTrader.• System launch when working with QuoteSpeed.

In the case of using multiple terminals combining all necessary for each terminal steps is enough. Working with MetaTrader terminals Following steps are required: 1. Launch MegaTrader 1.4 and all the necessary MetaTrader terminals. Note. Please make sure that MegaTraderExchange 1.2 expert advisor is started in all Metatrader terminals(Setting up MetaTrader). 2. Establish MegaTrader 1.4 connection to MetaTrader. To do that, go to "Connection > Connect to MetaTrader". Working with SaxoTrader Following steps are required: 1. Launch MegaTrader 1.4 and SaxoTrader terminal. 2. Every symbol used should have an Orders window opened in SaxoTrader (Setting up SaxoTrader). 3. Establish MegaTrader 1.4 connection to SaxoTrader. To do that, go to "Connection > Connect to SaxoTrader". Working with QuoteSpeed Following steps are required: 1. Launch MegaTrader 1.4 and QuoteSpeed. 2. Establish MegaTrader 1.4 connection to QuoteSpeed. To do that, go to "Connection > Connect toQuoteSpeed".

Page 23: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Program interface

MegaTrader's user interface consists of the following:

• Main menu. All the basic commands and functions can be found here, except for the trade execution andmanagement functions.

• Chart. The spread chart represents the spread's movement in time. Also, indicators can be displayed on thechart.

• Trade panel. Trade panel is a multifuntional trading execution and management tab where tradingoperations can be performed and program logs can be viewed.

There are also auxilliary windows that can be opened by choosing them in the main menu.:

• Settings window. Here MegaTrader's common settings can be changed (chart display settings, data archivesize etc.) and MetaTrader terminal settings.

• Composite instrument settings. Here user can form the spread from several trading instruments and changeparameters for each instrument.

• MetaTrader instrument settings, SaxoTrader instrument settings и QuoteSpeed instrument settings. Thesewindows are used to change the parameters of each instrument in the spread.

• Script editor. User can create and edit scripts - trading robots on a special built-in programming languagethat enables the development of automated trading systems, with the help of script editor.

• Global variables. Global variables window allow creating, changing and removing global variables. Globalvariables allow storing persistent information (data is not lost between script and Megatrader launches).

• Script backtester. With the help of script backtester user can assess his trading script for profitability onhistorical data. In the process, backtester executes the script on each tick and emulates trading results.

• Indicator parameters. Here user can change indicators' parameters. The window appears everytime a newindicator is added to the spread chart or when changing an indicator's parameters.

• License management. User can purchase, install or delete a license from here.

Page 24: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing
Page 25: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Main menu

All program's functions and commands are in the main menu, except of those.

File

File menu group.

Connection

Connection menu group.

Chart

Chart menu group.

Script

Script menu group.

Settings

Settings menu group.

Help

Help menu group.

Page 26: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

File

Load settings

Loads settings from file. Note. When saving or loading settings file its location is automatically storen within the program. Afterthis operation, program will automatically load settings from it upon its launch and save settings on exit.

Save settings

Save settings to file. Note. When saving or loading settings file its location is automatically storen within the program. Afterthis operation, program will automatically load settings from it upon its launch and save settings on exit.

Clear data

Clears tick data history in the program (current program settings are not changed).

Load data

Loads tick history data from file (current program settings are not changed). Note. When saving or loading settings file its location is automatically storen within the program. Afterthis operation, program will automatically load settings from it upon its launch and save settings on exit.

Page 27: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Save data

Saves tick history data to a file. Note. When saving or loading settings file its location is automatically storen within the program. Afterthis operation, program will automatically load settings from it upon its launch and save settings on exit.

Exit

Quits the program. Current settings and data archive are automatically saved on exit.

Page 28: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Connection

Connect to Quik

Connects to Quik. Orders can be sent to Quik only if the connection is active (Quik should have externaltransactions support enabled or it will be impossible to establish connection).

Disconnect from Quik

Disconnects from Quik. While disconnected it's impossible to send orders to Quik, although receivingquotes is still possible.

Connect to Meta Trader

Connects to MetaTrader. After establishing the connection program will be able to get quotes fromMetaTrader and send trade orders (MegaTraderExchange 1.2 should be running in MetaTrader).

Disconnect from MetaTrader

Disconnects from MetaTrader. After disconnecting getting quotes and sending orders will be impossible.

Connect to SaxoTrader

Connects to SaxoTrader. After establishing the connection program will be able to get quotes fromSaxoTrader. SaxoExporter is automatically launched by MegaTrader when clicking "Connection > Connect toSaxoTrader". Module's icon should appear in system tray when it's running.

Page 29: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Note. Auxiliary module SaxoExporter is developed to allow quotes import from SaxoTrader terminal toMegaTrader. As SaxoTrader does not have any quote export functions, they are being read directly fromthe program interface, or rather - "Forex orders" and "Futures orders" modal windows. So, for quoteexport to be possible from SaxoTrader, it is necessary to have the corresponding windows opened for allthe instruments you plan to work with.

Disconnect from SaxoTrader

Disconnects from SaxoTrader. After disconnecting Megatrader will stop getting quotes.

Connect to QuoteSpeed

Connects to QuoteSpeed. After establishing the connection program will be able to get quotes fromQuoteSpeed.

Disconnect from QuoteSpeed

Disconnects from QuoteSpeed. After disconnecting Megatrader will stop getting quotes.

Page 30: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Chart

Add chart

Add an indicator to the spread chart. When this option is selected, a list of all available indicatorsappears. After selecting to add an indicator on the screen, Indicator parameters window will appear toset its parameters.

Chart parameters

This menu allows user to change indicator settings. When selecting this option, a list of all currently usedindicators will appear, among which user chooses. After selecting, Indicator parameters window willappear.

Remove chart

Removes an indicator from the chart. When selecting this option, a list of all currently used indicators willappear, among which user chooses the indicator to delete. Along with the indicator itself all indicators itwas the data source for will also be deleted.

Cursor

Changes chart cursor mode to "Cursor".

Magnifier

Changes chart cursor mode to "Magnifier". It becomes possible to change chart zoom using the mousein this mode (Chart).

Page 31: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Zoom in

Zooms the chart in.

Zoom out

Zooms the chart out.

Show all

Shows all the available data on the chart.

Page 32: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Script

Script editor

Opens Script editor window. User can create and edit scripts - trading robots on a special built-inprogramming language that enables the development of automated trading systems, with the help ofscript editor.

Global variables

Opens Global variables window. Global variables allow storing persistent information (data is not lostbetween script and Megatrader launches).

Script backtester

Opens Script backtester window. With the help of script backtester user can assess his trading script forprofitability on historical data. In the process, backtester executes the script on each tick and emulatestrading results.

Run script

Starts script execution. If launched, script will execute and calculate on each tick.

Stop script

Stops script execution.

Page 33: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Settings

Settings

Opens Settings window. Here user can change general program settings.

Composite instrument settings

Open Composite instrument settings window. Here user can form the spread from several tradinginstruments and change parameters for each instrument.

Language

Changing MegaTrader's interface language.

Page 34: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Help

Help

Opens help file.

License

Opens License management window. User can purchase, install or delete a license from here.

Page 35: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Chart

Spread chart displays the spread's price dynamics in time. The chart always shows two lines: red line is Offer(selling at that price) line and green line is Bid (buying at that price) line. Charts also can have an unlimitednumber of indicators applied. Note. In Common settings two parameters: "Maximum ticks on chart" и "Maximum ticks in data archive" can beset. These options allow controlling the data shown on the chart and data stored on HDD.

Chart tools Chart scalingChart scaling can be achieved either via main menu or with the help of your mouse. Chart scaling can be done with the help of "Zoom in" and "Zoom out" Chart menu commands. Zooming can becancelled via "Show all" command. Zooming with mouse can be done with "Magnifier" chart mode turned on (Chart menu). To zoom, you shouldselect the zooming zone with your mouse pressed down, moving the crosshair down and right. After releasingmouse the chart will be zoomed to the selected area. To reset the zooming, press the left mouse buttonanywhere on the plot, and while holding the button down, move the cursor left and up. Once the button isreleased, the scale will be reset. Chart scrolling and auto-scrollingScrolling is offsetting data displayed to the left or right. Scrolling may be realized using either the scroll bar graphlocated beneath the window , or using the mouse. To scroll the chart by using the mouse , press the right mousebutton and, move the cursor in the direction needed while keeping the button pressed down. Auto-scrolling is automatic data offsetting on the chart when new ticks arrive. It will work if chart zooming isturned on and the last tick can be seen on the chart. In this case chart is automatically scrolled upon receiving anew tick. If zoom is turned off (all available data is shown), chart will be automatically rescaled to fit all data eachtick. IndicatorsIn addition to Bid and Offer price lines an unlimited number of indicators can be added to a chart. Adding,changing parameters and deleting indicators is managed with "Add chart", "Delete chart" и "Chart parameters"commands of Chart menu group. Also, indicator parameters can be changed by pressing right mouse button on an indicator line on the chart.Context menu appearing consists of two options:

Page 36: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

• "Parameters" - Indicator parameters.• "Delete" - deletes an indicator from the chart.

Page 37: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Trade panel

Trade panel allows user to view program messages and trade manually, as well as monitor current tradingstatistics.

Trading tab

Trading buttons and elements are concentrated here (Trading tab).

Messages tab

This tab shows messages generated by the program (Messages tab).

Page 38: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Trading tab

Balance

Balance is the current market position. Balance value shows a balanced number of units spread inmarket position, and the sign of balance is the position's direction: positive - buying (long), negative -selling, or short (for example, the balance of 2 means having 2 units of spread in long position, if it is -2 -short position of the corresponding size ). Note. Only balanced spread units number is shown in Balance tab. Unbalanced units are counted on"Disbalance" tab.

Disbalance

The disbalance shows the unbalanced number of spread units in current position. The disbalance is theresult of portfolio lacking positions on some instruments. The disbalance shows the number of spreadunits to be added to the current position balance if missing positions will be opened (long/short), andimbalance sign is the direction of potential position added.

Bid

Current spread's best Bid price (spread can be sold at that price) is shown.

Offer

Current spread's best Offer price (spread can be bought at that price) is shown.

Buy button

Page 39: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Buys spread unit/units (quantity is set by "Quantity" parameter).

Sell button

Sells spread unit/units (quantity is set by "Quantity" parameter).

Close button

Closes all opened positions on click.

Restore balance button

Pressing this button will get rid of the imbalance by buying/selling missing instruments. As a result, if theoperation is successful, the unbalanced number of units of the spread will be balanced and added to thecurrent balance.

Quantity

Here number of spread units to be bought/sold in each buy/sell order can be changed.

Maximum quantity

This option sets a limit on maximum number of spread units in open positions (so the program can'tbuy or sell spread units over this number). Restrictions imposed by this parameter apply to both tradesperformed manually and ones performed by a script.

Page 40: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Messages tab

"Messages" tab records information about events that occurred during program execution. Event log is stored in"MegaTrader.log", located in the same folder where the program is.

Page 41: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Settings

In Settings window, general settings (chart parameters, data file size, etc.) and settings for interaction withMetaTrader terminal are located. You can get here by pressing "Settings" of Settings menu group.

Common

Tab where common system settings are located. (Common settings).

Quik

Quik settings are located here.

MetaTrader

Tab with MetaTrader interaction settings.(MetaTrader settings).

Ok

Closes the window saving and applying the changes.

Page 42: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Cancel

Closing the window without saving the changes.

Page 43: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Common settings

Chart update

Selects the charting update period

• "When new tick arrives" - chart will be updated with each tick update arriving to the program• "Every n seconds" - chart will be updated each specified number of seconds (ie. 1, 60, 3600 -

interval of your choice).

Selecting "When new tick arrives" may boggle system performance when tick stream is tight and fast.Thus, in order to save resources, when the refresh rate schedule is not important (for example, whenthe system is trading in automatic mode), as well as on slower computers, it is always recommended tochoose "every n seconds" update period.

Maximal ticks on chart

Specifies the maximum number of ticks that are displayed on chart. This parameter strongly influencesthe speed of chart rendering and updating, so there is no need to set it too large (ie. 10000 ticks is morethan enough in most cases).

Maximal ticks in data archive

Specifies maximum number of ticks that are saved to data archive. Each time program is closed it savesno more than specified number of ticks into the achive file.

Last order number

Page 44: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Displays the counter of transactions sent to MetaTrader terminal. Transaction count is used for statisticsof received and filled orders, changing it does not change the way program behaves.

Page 45: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

MetaTrader settings

Terminal ID

Current MegaTrader's instance ID. Up to 20 MegaTrader instances can be working with multipleMetaTrader terminals simultaneously. A unique ID number of 0 to 19 should be set for each instance ofMegaTrader 1.4 working with MetaTrader 4.

Page 46: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Composite instrument settings

Here the intrument list a spread consists of can be created and edited. You can get here by pressing "Composite instrument settings" of Settings menu group.

Instruments tab

Instrument list settings tab (Instruments tab).

Additional tab

Additional spread settings tab (Additional settings).

OK button

Closes and saves the changes.

Close button

Page 47: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Closes without saving the changes.

Page 48: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Instruments tab

Positive spread side list

List for instruments included in the positive part of composite symbol (they are used in the formula withthe "+" sign.

Move upper

Moves selected instrument one position upper.

Page 49: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Move lower

Moves selected instrument one position lower.

Add

Adds a new instrument to the list. First you should choose a terminal from which the instrument will beimported.

Then, depending on your choice, MetaTrader instrument settings window, SaxoTrader instrumentsettings window or QuoteSpeed instrument settings window appear, where you can thoroughly set up theinstrument.

Delete

Deletes an instrument from the list.

Edit

Edits selected instrument. Depending on the terminal, a corresponding Instrument settings window willappear.

Negative spread side list

Page 50: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

List for instruments included in the negative part of composite symbol (they are used in the formula withthe "-" sign.

Move upper

Moves selected instrument one position upper.

Move lower

Moves selected instrument one position lower.

Add

Adds a new instrument to the list. First you should choose a terminal from which the instrument will beimported.

Then, depending on your choice, MetaTrader instrument settings window, SaxoTrader instrumentsettings window or QuoteSpeed instrument settings window appear, where you can thoroughly set up theinstrument.

Delete

Page 51: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Deletes an instrument from the list.

Edit

Edits selected instrument. Depending on the terminal, a corresponding Instrument settings window willappear.

Move to the right list

Transfers an instrument to the right list.

Move to the left list

Transfers an instrument to the left list.

Page 52: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Additional settings

Trading time

Specifies time interval during which the program will collect data and trade.

Page 53: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

MetaTrader instrument settings

This window appears when you add or edit MetaTrader instruments in Composite instrument settings.

Common settings

Common instrument settings tab (Common settings tab).

Additional settings

Additional instrument settings tab (Additional settings tab).

OK button

Closes the window and saves the changes.

Close button

Closes the window without saving the changes.

Page 54: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Common settings

Account number

MetaTrader account number (can be often seen in the MetaTrader's title).

Instrument code

Instrument name in MetaTrader. Should be mentioned as seen in MetaTrader, with suffixes and prefixes.

Weight in spread

Multiplication factor for an instrument in spread This option only affects the spread calculation, the actual number of lots that will be bought or sold is setby the "lots in spread unit" parameter.

Lots in spread unit

Lots that will be traded when buying or selling one unit of the spread.

Execute first

Turning the "Execute first" option on means that program will try to fill the order by the price at themoment of sending the order (taking the preset slippage amount in consideration). If the order gets filledby the specified price, then orders will be sent to other instruments in the spread, if not (if price exceedsone of the slippage levels) - no other instruments will be traded. The use of this option, in some cases, can significantly reduce the slippage, because it ensures that atleast one instrument transaction will be implemented a fair price.

Page 55: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Slippage

Admitted slippage value for opening and closing orders.

Page 56: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Additional settings

Time source

Specifies the timestamp source for incoming quotes:

• "Terminal" - trading terminal's time (MetaTrader) will be used.• "Computes" - local computer's time will be used.

If there are several data sources, "Computer" is best used, because it helps avoiding time laggingproblems in different terminals. This happens because time in some terminals (even without taking GMTdifference into calculation) can lag or lead other terminals' time by several seconds. If "Computer" timesource is chosen, quotes timestamp will be the actual PC's time which will eliminate the lagging problemand calculate the spread correctly.

Time difference

Specifies quotes timestamp shift in hours.

Accumulate data

If this option is turned on, tick data for the selected instrument will be saved, which will allow individualbacktesting in it. (It will become available in Settings tab of Script backtester.

Стопы

These options allow you to set stop-loss and take profit levels for each order placed in MetaTrader. "TakeProfit" specifies the distance from opening price (in profit direction) where profit target will be placed."Stop-loss" sets the distance from opening (in losing direction), where a stop-loss will be placed. A zerovalue of a parameter means that either SL or TP will not be placed.

Page 57: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SaxoTrader instrument settings

This window appears when you add or edit SaxoTrader instruments in Composite instrument settings.

Common settings

Common instrument settings tab (Common settings tab).

Additional settings

Additional instrument settings tab (Additional settings tab).

OK button

Closes the window and saves the changes.

Close button

Closes the window without saving the changes.

Page 58: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Common settings

Instrument code

Instrument name in SaxoTrader.

Weight in spread

Multiplication factor for an instrument in spread

Page 59: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Additional settings

Time source

Specifies the timestamp source for incoming quotes:

• "Terminal" - trading terminal's time (MetaTrader) will be used.• "Computes" - local computer's time will be used.

If there are several data sources, "Computer" is best used, because it helps avoiding time lagging problemsin different terminals. This happens because time in some terminals (even without taking GMT differenceinto calculation) can lag or lead other terminals' time by several seconds. If "Computer" time source ischosen, quotes timestamp will be the actual PC's time which will eliminate the lagging problem and calculatethe spread correctly.

Time difference

Specifies quotes timestamp shift in hours.

Accumulate data

If this option is turned on, tick data for the selected instrument will be saved, which will allow individualbacktesting in it. (It will become available in Settings tab of Script backtester.

Page 60: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

QuoteSpeed instrument settings

This window appears when you add or edit QuoteSpeed instruments in Composite instrument settings.

Common settings

Common instrument settings tab (Common settings tab).

Additional settings

Additional instrument settings tab (Additional settings tab).

OK button

Closes the window and saves the changes.

Close button

Closes the window without saving the changes.

Page 61: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Common settings

Instrument

Instrument's name in QuoteSpeed.

Weight

Multiplication factor for an instrument in spread

DDE Bid code

Current best Bid price DDE code in QuoteSpeed.

DDE Ask code

Current best Ask (Offer) price DDE code in QuoteSpeed.

Page 62: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Additional settings

Time source

Specifies the timestamp source for incoming quotes:

• "Terminal" - trading terminal's time (MetaTrader) will be used.• "Computes" - local computer's time will be used.

If there are several data sources, "Computer" is best used, because it helps avoiding time lagging problemsin different terminals. This happens because time in some terminals (even without taking GMT differenceinto calculation) can lag or lead other terminals' time by several seconds. If "Computer" time source ischosen, quotes timestamp will be the actual PC's time which will eliminate the lagging problem and calculatethe spread correctly.

Time difference

Specifies quotes timestamp shift in hours.

Accumulate data

If this option is turned on, tick data for the selected instrument will be saved, which will allow individualbacktesting in it. (It will become available in Settings tab of Script backtester.

Page 63: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Script editor

Script editor allows to create and edit scripts - automated trading systems written in a special built-inprogramming language. This window appears when "Script editor" command is launched from the Script menu group.

Menu

Code redactor's main menu.

Toolbar

Code redactor's toolbar.

Page 64: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Toolbar

Toolbar provides user with buttons for most commonly used operations, such as opening a file, copying andpasting text etc.

New script

Creates new script (a blank file).

Open script

Loads script from a file.

Save script

Saves script in a file with current name.

Undo

Reverts the last change done to the script (equivalent to CTRL+Z hotkey).

Cut

Cuts selected text out of the script editor and puts it into copy buffer (equivalent to CTRL+X hotkey).

Copy

Copies selected text and puts it into copy buffer (equivalent to CTRL+C hotkey).

Paste

Page 65: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Pastes text from copy buffer (equivalent to CTRL+V hotkey).

Page 66: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Menu

File

File menu group.

Edit

Edit menu group.

Page 67: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

File

New

Creates new script (a blank file).

Open

Loads script from a file.

Save

Saves script in a file with current name.

Save as...

Saves script in a file with another name (file saving window will appear).

Exit

Exits script editor.

Page 68: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Edit

Undo

Reverts the last change done to the script (equivalent to CTRL+Z hotkey).

Cut

Cuts selected text out of the script editor and puts it into copy buffer (equivalent to CTRL+X hotkey).

Copy

Copies selected text and puts it into copy buffer (equivalent to CTRL+C hotkey).

Paste

Pastes text from copy buffer (equivalent to CTRL+V hotkey).

Select all

Selects all text (equivalent to CTRL+A hotkey).

Page 69: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Global variables

This window allows to manage global variables. Global variables allow user to store information between differentscript launches, as well as between program launches and restart (unlike local variables declared within thescript, values of which are lost at the end of script execution). This window appears upon choosing "Global variables" in Script menu group.

Global variables table

Page 70: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Here all the global variables's names are as well as their values. To change a global variable's name orvalue simply click the corresponding text field and write necessary value.

Add

Adds new global variable.

Delete

Deletes selected global variable.

OK button

Closes the window and saves the changes.

Close button

Closes the window without saving the changes.

Page 71: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Script backtester

Script backtester allows user to test script performance on historical data, thus measuring its profitability andeffectiveness. During backtesting script executes on each tick of historical data, emulating order managementand quote stream. This window appears upon choosing "Script backtester" of Script menu group.

Settings tab

Backtesting settings are here to be analyzed or changed (Settings tab).

Report tab

Generalized backtesting results are shown here (Report tab).

Transactions tab

All transactions made during the backtesting are presented here (Transactions).

Page 72: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Chart tab

Balance graph is displayed here (Balance chart).

Test

Pressing this button launches script backtesting with parameters specified on Settings tab. Duringbacktesting script executes on each tick of historical data, emulating order management and quotestream. After backtesting its results become available on Report, Transaction and Chart tabs.

Close

Closes the backtester.

Page 73: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Settings tab

Backtesting period

Data period used for script backtesting.

Instrument

Instrument on which the script will be backtested. Note. In addition to Spread instrument itself, only instruments with "Accumulate data" option turned onwill be available for individual instrument backtesting.

Comission

Commision size for buying or selling one spread unit (it's half-turn comission).

Backtesting step

If set to 1 (default), all the ticks will be backtested on. If more than 1, each n tick will be backtested on,where n - backtesting step. Setting backtesting step to more than 1 can significantly reduce backtesting time: this way overall datapoint number for backtesting is reduced by n times, because only each n tick will be backtested on, sobacktesting time will also be approximately n times less. But it should be taken into consideration that

Page 74: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

such way of backtesting gives only approximate results. Thus it is recommended to use backtesting stepover 1 only for getting acquainted with approximate system results on large data archives.

Delay (ticks)

Number of ticks transaction execution will be delayed during backtesting. A certain time passes between forming a trade order in the program and its registration on the exchange.During this time, the price can change, and, as a result, the transaction can be made at a price different(most of the time detriment for the trader) from the one that was at the time of trade order sending. Suchdelays in the execution may be the reason why some trading system give good results when tested onhistorical data but lose during real-time trading. Using the "Delay (ticks)" parameter can simulate thedelays appearing while trading real-time, thus assessing their influence on system's profitability.

Delay (milliseconds)

Number of milliseconds transaction execution will be delayed during backtesting. A certain time passes between forming a trade order in the program and its registration on the exchange.During this time, the price can change, and, as a result, the transaction can be made at a price different(most of the time detriment for the trader) from the one that was at the time of trade order sending. Suchdelays in the execution may be the reason why some trading system give good results when tested onhistorical data but lose during real-time trading. Using the "Delay (milliseconds)" parameter can simulatethe delays appearing while trading real-time, thus assessing their influence on system's profitability.

Page 75: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Report tab

Generalized backtesting results are presented in "Report" tab, such as:

• Net profit - financial result of all transactions. Represents the difference in the "Gross profit" and "Grossloss";

• Gross profit - sum of all profitable trades;• Gross loss - sum of all losing trades;• Total trades - total number of trades;• Profit trades - number of profitable trades;• Profit trades percent - share of profitable trades in total trades represented as percentage;• Loss trades - number of losing trades;• Loss trades percent - share of losing trades in total trades represented as percentage;• Average trade - average profit/loss per trade ("Net profit" divided by "Total trades");• Average profit - average profit per profitable trade ("Gross profit" divided by "Total trades");• Average loss - average loss per losing trade ("Gross loss" divided by "Total trades");• Maximal drawdown - maximum loss relative to last local profit maximum, achieved while backtesting.

A trade is considered to be an opened and then closed position (a round-turn trade). Note. If opened positions exist by the end of backtesting, they are closed on the last tick.

Page 76: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Transactions tab

A table in "Transactions" tab shows detailed information about all executed orders during script backtesting. Eachtable line represents a trade and contains the following information:

• Date - transaction date;• Time - transaction time;• Type- transaction type: buying/selling the spread;• Size - spread units bought or sold;• Price - spread price at the moment of transaction;• Balance - total number of spread units in the portfolio after the transaction;• Profit - profit value (net profit) since backtesting started.

Note. If opened positions exist by the end of backtesting, they are closed on the last tick.

Page 77: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Balance chart tab

"Balance chart" tab shows a chart picturing the changes of account balance and profit/loss over time. It allowsuser to profoundly analyze backtesting results in an easy visual fashion. Note. If opened positions exist by the end of backtesting, they are closed on the last tick.

Page 78: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Indicator parameters

This window allows user to change indicators parameters. This window appears every time an indicator is added to the chart ("Add chart" of Chart menu group) or uponchanging an indicator's parameters ("Chart parameters" of группы меню График). Also parameters window canbe opened using the "Settings" in the context menu that appears upon right-clicking an indicator line in the chartwindow.

Input parameters

Input parameters panel. Certain indicators have their own parameter sets, for example, "MovingAverage" indicator has two: data source and period while "Bollinger Bands" has three - data source,period and deviation.

Page 79: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Output parameters

Output parameters panel. Indicator's output is a set of lines that are the indicator's calculations results.Certain indicators have their own output parameter sets, for example, "Moving Average" has one - theaverage line itself, "Bollinger Bands" - three: top BB line, middle BB line and bottom BB line. Each output parameter has two of its own parameters to change:

• "Identifier" - identifier to call the said parameter from a script.• "Line color" - chart window line color.

OK button

Closes the window and saves the changes.

Cancel button

Closes the window without saving the changes.

Page 80: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

License management

Here you can purchase, install or delete program license. This window appears upon choosing "License" of Help menu group.

Purchase license

Allows user to read the instructions on purchasing a program license and save the registration file (whichis required to purchase a license.)

Install license

Starts the license installation process. First, user will be offered to accept the License Agreement. If useragrees to the terms of the Agreement installation will proceed offering user to locate license key file. Afterinstalling license it is necessary to restart the program.

Delete license

Deletes current program license. License will be removed permanently so it won't be possible to restoreit. After removal new registration file will be generated. License removal is most commonly used whenuser needs to transfer his license to another computer or after a OS/hardware installation.

Page 81: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Indicators

An indicator is a mathematical transformation that converts one set of time series, serving as a data source intoanother, which is the result of the conversion. The indicators usually have a set of input parameters, that include the data source and conversion parameters,and a set of output parameters - time series resulting from the conversion. Each output parameter may bedisplayed as a curve. The program contains a set of built-in indicators. To add indicators on the chart use the command "Add chart" in Chart menu group.

Page 82: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Mean Price

Mean Price (Average Price) indicator shows the average of best bid and offer prices. This indicator is primarilyintended for use as a data source for other indicators. Output: Mean price (MP) - arithmetic mean of bid and offer prices. MP = (Bid+Ask)/2

Page 83: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Moving Average

Moving Average shows the time series' average value for a certain period of time. Input parameters Source - time series used for calculation. Period - averaging period. Output parameters Average line (MA) - arithmetic mean of the source time series for the specified period of time. MA(i) = ( V(i) + V(i-1) + ... + V(i-(N-1)) ) / N where:V(i) - value of data source time series at the time i,N - period

Page 84: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Exponential Moving Average

Indicator Exponential Moving Average performs time series smoothing by adding a certain percentage of thecurrent time series value to the previous value of the moving average. When using an exponential movingaverage greater weight are given to last values of the series. Input parameters Source - time series used for calculation. Period - averaging period. Output parameters Average line (EMA) - the result of source time series exponential smoothing. EMA(i) = (1-P) * EMA(i-1) + P * V(i) где:V(i) - value of data source time series at the time i,P = 2 / (N+1) - smoothing coefficient,N - period.

Page 85: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Bollinger Bands

Bollinger Bands set the upper and lower limit of normal range the time series' distribution. The Bollinger bandstop and bottom lines are calculated as a certain number of standard deviations from the moving average. Sincestandard deviation is a measure of the time series' oscillations, the bands' width increases during high volatilitytimes and decreases during flat or nonvolatile market times. Input parameters Source - time series used for calculation. Period - averaging period. Отклонение - number of deviations which determine how far BB top and bottom will be from the movingaverage Output parameters Central line (ML) - moving average of the source time series. ML(i) = ( V(i) + V(i-1) + ... + V(i-(N-1)) ) / N Top bands line (TL) - central line shifted a defined number of standard deviations up. TL(i) = ML(i) + D * StdDev(i) Bottom bands line (BL) - central line shifted a defined number of standard deviations up. BL(i) = ML(i) - D * StdDev(i) where:V(i) - value of data source time series at the time i,N - period,D - number of standard deviations,StdDev(i) - standard deviation for i moment of time,Sqrt - root square. StdDev(i) = Sqrt( ( (V(i) - ML(i))^2 + (V(i-1) - ML(i))^2 + ... + (V(i-(N-1)) - ML(i))^2 ) / N )

Page 86: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Scripting language

MegaTrader 1.4 includes a special programming language allowing to create scripts - programs that automatetrading processes. The language includes a large number of built-in functions that are required for marketanalysis and trade management. Language is very simple to learn, in addition script examples are included, which allows you to quickly master thelanguage and begin implementing your own trading strategies.

Page 87: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Language description

Page 88: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Language elements

Space delimiters Space delimiters are used to determine the beginning and end of lexemes - minimum language units. By spacedelimiters spaces, tabs, and new line characters are meant. Comments Comment is a part of program's text, which is ignored during program compilation and execution. First of all, theyserve to explain different sections of code. The system supports two types of comments: single-line and multiline.Multiple-line comments start with /* and end with */. They can not be nested. Single-line comments start with apair of slashes // on a new line and can be embedded in multi-line comments. Comments are allowed whereverspaces are possible, and allow an unlimited number of spaces. Examples. // Single-line comment /* Multiple-line comment*/ Lexemes Lexeme is a minimum unit of language with a meaning. There are five types of lexemes:

• identifiers;• keywords;• constants;• operation signs;• punctuation signs.

Identifiers Identifiers are used as variable and function names. Identifiers can consist of latin letters (uppercase andlowercase letters are not distinguished), 0-9 and the underscore character (_). The first character must be aletter. Keywords Keywords are identifiers already reserved by the language: doelseforifnullreturnvarwhile Constants

Page 89: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Constants are lexemes representing a fixed, numeric, string, or a character value. Numeric constants consist of an integer part and , optionally, a period (.) and the fraction. The integer andfractional parts are sequences of decimal digits. String constants are a sequence of characters enclosed in double quotes ("). Character constants - is a single character enclosed in single quotes. The internal representation of a characterconstant is an integer containing the character code. Examples: 10, -3.14, 0.0001 // numeric constants"This is a string" // string constants't', '$' // character constants Operation signs Operation signs help the development and evaluation of expressions. In language, there are following operationsigns:=,+,-,*,/,%,!,&&,||,==,!=,<,<=,>,>=. Punctuation signs Punctuations signs include the following:() {} , ; The parentheses () are used to group expressions and change the order of operations. In addition, parenthesesare used in conditional statement if and loop statement for. The curly braces {} denote beginning and end of the compound statement or block. The comma (,) is used as a parameter separator in functions, as well as a generic separator - in cycle statementfor. The semicolon (;) terminates each statement. Any valid expression followed by a semicolon is treated as anstatement.

Page 90: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Operations and expressions

Exressions An expression consists of one or more operands and operation symbols. Examples: x=10;y=(x+5)/2; Expressions ending with a semicolon (;) are statements. Assignment = Value assignment The assignment statement can be used only once in an assignment expression. Arithmetic operations + Addition

- Subtraction

- Change of sign

* Multiplication

/ Division

% Modulo operation Logic operations ! Logical "NOT"

&& Logical "AND"

|| Logical "OR" Relation operations == Equal

!= Not equal

< Less

<= Less or equal

> More

>= More or equal Function call f(x1,x2,...,xn) Calling a function named f with arguments x1, x2, ... , Xn. The

argument can be a constant, variable or expression.

Page 91: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Operation priority f(x1,x2,...,xn) - Function call

() - Parentheses

- - Change of sign! - Logical "NO"

* - Multiplication/ - Division% - Modulo operation+ - Addition- - Subtraction

== - Equal!= - Not equal< - Less<= - Less or equal> - More>= - More or equal&& - Logical "AND"

|| - Logical "OR"

= - Value assignment Each group of operations in the table has the same priority. The higher the priority, the higher is the groupsituated in the table. Parentheses (), which have the highest priority, are used for changing operation priority.. Example. x=2*(1+3); // Result: x=8

Page 92: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Statements

Language statements describe the basic algorithmic steps that a program performs. The body of the program isliterally a sequence of statements. statements must be separated by a semicolon (;). Expression statements Any expression ending with a semicolon (;) is considered an statement. Examples. // A value of 5 is assigned to x variable: x=5; // A result of using an Abs function to// y variable is assigned to x variable: x=Abs(y); Compound statements Compound statements (blocks) are composed of one or more statements of any type, enclosed in curly braces {}.There should be no semicolon (;) after a closing curly bracket. An example. if(x<2){ Alert("x less then 2"); } Conditional if-else statement if(expression){ statement1; } else{ statement2; } If the expression is true, statement1 is performed, otherwise statement2 is. The braces {} are mandatory. Example. if(x>y){ z=x; } else{ z=y; } Else and statement2 part can be omitted. In this case, if the expression is false, no action will be performed: if(expression){ statement1;

Page 93: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

} Example. if(x<0){ x=-x; } Statement1 and statement2 can be compound statements, even nested ones: Example. if(x>0){ if(x>y){ z=x; } else{ z=y; } } else{ z=0; } while loop statement while(expression){ statement; } If expression is true, statement will perform until expression becomes false. The expression value should bedetermined before loop execution. So, if the expression is false from the very beginning, the loop will be simplyskipped and not executed. Example. // Example calculates the factorial of 4: i=1;x=1;while(i<5){ x=x*i; i=i+1; } do-while loop statement do{ statement; }while(expression); If expression is true, statement will perform until expression becomes false. The expression value is determinedafter loop execution. So, the loop will be executed at least once. Example.

Page 94: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

// Example of sum calculation - 10+20+30+40: i=1;x=0;do{ x=x+i*10; i=i+1; }while(i<5) for loop statement for(expression1;expression2;expression3){ statement; } Expression1 determines the cycle initialization. Expression2 checks its condition within every cycle. Loop body isexecuted while expression2 is true. Expression3 is evaluated after each iteration. Example. // An example calculates the average best bid// value within the last 5 ticks: x=0;for(i=0;i<5;i=i+1){ x=x+Point("Bid",i); }x=x/5; return statement return expression; The return statement terminates the current function execution and returns the value of the expression. Example. // Function returns the sum of its arguments Sum(x,y){ return x+y; }

Page 95: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Data types

Basic data types Following data types are used in the language:

• variant - non-specific data type.• integer - integer data type.• float - floating point value.• string - string data type.• bool - boolean data type.•

Type casting Language uses implicit casting. This means that program attempts to convert all variables to the same data type.However, in some situations where such type conversion is not possible, an error occurs. Example. // Type casting error var x;x=5+"Str"; // Error To avoid such errors, you must explicitly convert variables to the correct data type. For these purposes, there arebuilt-in functions used for data type conversion (look Type conversion). Пример. // Example of explicit type conversion// After the program's execution// x variable will have a value of "5Str": var x;x=String(5)+"Str"; Date and time Date and time appear in the form of a floating point type variable (float), the integer part of which is equal to thenumber of days since 30.12.1899, and the fractional part - the proportion of elapsed time to the 24-hour day. Some examples of floating point values and the corresponding date and time: 0 30.12.1899 00:00:00

2.75 01.01.1900 18:00:00

35065.5 01.01.1996 12:00:00

Such a representation of date and time is convenient because it allows correct date comparison, as well asaddition and subtraction. For example, to get the number of days, hours, minutes and seconds between twodates, simply subtract one value from another. The resulting integer will represent the number of days andfractional part will show hours, minutes and seconds separating the dates. Similarly, you can increase the valueby a needed number of days, hours, minutes and seconds, to do so convert the number of days, hours, minutes

Page 96: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

and seconds in the format of a floating point value (e.g. a day and 16 hours will be 1.66), then just add it to givendate and time. It's enough to drop the fractional part to get date without time . To get time value without date, you need to dropthe integer part. Example. // Getting current computer time// without date. var x;x=CurrentDateTime();x=x-Floor(x); The null value The null value has variant data type and is used to represent non-specific data. Null is returned by manybuilt-in functions if they cannot execute correctly or if errors appear while the execution. Пример. x=Float(s);if(x==null){ Alert("Could not convert to a number"); }

Page 97: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Variables

Variable is an indicator of a certain area in memory that stores the value of the variable. This value can changeduring program execution. Variable declaration Before using a variable it should be declared with a keyword var. var var_name1,var_name2,...,var_nameN; Variables of the language are not explicitly typed and can change their data type during program execution. Example. var i,j,k;var x,y; Variable initialization Variable initialization occurs at the time of assigning a value. Before that a variable posesses the variant datatype. After assigning a value the variable converts to a type matching the value's data type. Example. // Variable declaration and initialization: var x; // Data type is variantx="Str"; // Data type converts to string Because of variables not strictly typed, they can change their data type during program execution. Example. // Variable data type change// during program execution: var x; // Data type is variantx=0.001 // Data type converts to floatx="Str"; // Data type changes to string Variable visibility Variable scope is the part of the program where the variable can be referenced and called. There are local andglobal visibility scopes in the language. Variable declared in the body of some function has a local visibility scope. It can be referenced only in the body offunction it has been declared in. A variable declared outside of any function has global visibility scope. It can be called from entire program andany function defined in the program Examples. // In this example variable a with a global

Page 98: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

// visibility scope and x, y variables with// local scope are declared.// Variables x and y can be referenced only// in main() function body. var a; main(){var x,y;} // Variable x has a global// scope and can be referenced to in// all the program's functions.// Program execution result// will be an alert message with "10" text. var x; f(){x=10;} main(){f();Alert(String(x)); } If local and global variables' names are the same, local variable will have the call priority when referencing to it. Пример. // Variable x with global scope// and another variable x, but with local// scope are declared.// Program execution will result// in alert message with "1" text, because// local variable has the call priority// when referencing to it. var x; // global variable f(){x=10; // global x reference} main(){var x; // local variablex=1;f();Alert(String(x)); // local variable reference}

Page 99: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Functions

User functions Function is a named part of program which can be called from other program parts. function_name(parameter1,parameter2,...,parameterN){ statement; } Function consists of a name function_name, function parameters parameter1, parameter2, ... ,parameterN, and a compound operator (block) containing function body with statements and expressions forexecution. Example. // Function displays a message box with the value of// its parameter: Show(x){ Alert("value is "+String(x)); } If a function should return some value, return operator must be used. Example. // The function calculates the average best bid// value within the last Num ticks: Average(Num){ var i,x; x=0; for(i=0;i<Num;i=i+1){ x=x+Point("Bid",i); } x=x/Num; return x; } Function call function_name(parameter1,parameter2,...,parameterN); Function call is an expression with the value being calculations' result returned by the function. The function calltransfers code execution from the place of a function call to the function body. Arguments, if any, are passed byvalue, ie every argument1, argument2 ... , argumentN value is calculated and passed to the function. At the endof its execution function returns the calculations' result to the place of its call. If the function does not return avalue, its call cannot be placed on the right side of assignment operation (ie x = function();).

Page 100: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Program execution

Program structure The script must have a main() function to execute. main() should not have any parameters. Example. main(){// function body} Script execution starts from the main()function call, other functions can be called from the main function's body.End of main() function execution means script execution end. Script execution Script can be executed by choosing one of two options: first, running the script (см. команду "Run the script"Script menu group), and the second, backtesting script on historical data (см. Script backtester window). If the script is launched, it will be executed when new ticks arrive. If script iteration started on previous tick stillexecutes when new tick arrives, the tick will be ignored. Until a script iteration is executed, all incoming ticks willbe ignored. After that, a new iteration of script will be started only when a new tick arrives. If script backtesting is launched, backtester software will execute the script on every tick in the historical dataprovided. The software will only start a new iteration of script when current tick iteration ends executing.

Page 101: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Built-in functions

Page 102: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Type conversion

Page 103: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Integer

integer Integer(variant value) The function converts the transmitted numeric or string value to an integer. In case of failure, null value isreturned. Parameters: value - nonspecific data.

Page 104: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Float

float Float(variant value) The function converts the transmitted numeric or string value to a float value. In case of failure, null value isreturned. Parameters: value - nonspecific data.

Page 105: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

String

string String(variant value) The function converts the transmitted numeric or string value to a string. In case of failure, null value isreturned. Parameters: value - nonspecific data.

Page 106: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Date and time

Page 107: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

DataTimeToStr

string DateTimeToStr(float datetime) Returns a string representation of date and time given. The representation format depends on current OSsettings. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 108: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

DateToStr

string DateToStr(float datetime) Returns a string representation of date and time given (time is omitted). The representation format depends oncurrent OS settings. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 109: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

TimeToStr

string TimeToStr(float datetime) Returns a string representation of date and time given (date is omitted). The representation format depends oncurrent OS settings. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 110: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

StrToDateTime

float StrToDateTime(string str) Converts the specified string in the date-time float value. The string format must match the format of the date /time set in OS settings. In case of failure, returns null. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: str - String containing date and time value.

Page 111: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

StrToDate

float StrToDate(string str) Converts the specified string in the date-time float value (time will be set to 00:00). The string format must matchthe format of the date / time set in OS settings. In case of failure, returns null. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: str - String containing date value.

Page 112: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

StrToTime

float StrToTime(string str) Converts the specified string in the date-time float value (date will be set to 30.12.1899). The string format mustmatch the format of the date / time set in OS settings. In case of failure, returns null. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: str - String containing time value.

Page 113: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Day

integer Day(float datetime) Returns the day of the month (1 - 31) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 114: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Month

integer Month(float datetime) Returns the month number (1 - 12) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 115: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Year

integer Year(float datetime) Returns the year number (0 - 9999) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 116: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Hour

integer Hour(float datetime) Returns the hour (0 - 23) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 117: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Minute

integer Minute(float datetime) Returns the minute (0 - 59) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 118: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Sec

integer Sec(float datetime) Returns the second (0 - 59) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 119: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

MilliSec

integer MilliSec(float datetime) Returns the millisecond (0 - 999) for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 120: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

DayOfWeek

integer DayOfWeek(float datetime) Returns day of the week (1 - 7, where 1 - monday, 2 - tuesday, ... , 7 - sunday), for specified date and time. Note. Date and time in the program is represented as a float, the whole part equal to the number of days since30.12.1899, the fractional part is the proportion of elapsed time in the 24-hour day. Parameters: datetime - Date-time value.

Page 121: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Global variables

Page 122: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

GetGlobVar

variant GetGlobVar(string name) Returns the value of global variable name. If no variable with such name exists, returns null. Parameters: name - Global variable name.

Page 123: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SetGlobVar

SetGlobVar(string name,variant value) Writes new value to the global variable name. If no variable with such name exists, new global variable iscreated. Parameters: name - Global variable name.value - New global variable value.

Page 124: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Mathematics

Page 125: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Abs

float Abs(float value) Returns the absolute value (or modulus) of the passed number. Parameters: value - Numeric value.

Page 126: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Ceil

integer Ceil(float value) Returns the smallest integer greater or equal than value (performs rounding up). Parameters: value - Numeric value.

Page 127: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Floor

integer Floor(float x) Returns the largest integer that is less or equal than value (performs rounding down). Parameters: value - Numeric value.

Page 128: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Sign

integer Sign(float value) Determines the sign of the number passed. Returns:

• 0 - the value is zero.• 1 - the value is greater than zero.• -1 - the value is less than zero.

Parameters: value - Numeric value.

Page 129: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Max

float Max(float value1, float value2) Returns the maximum of two numeric values passed. Parameters: value1 - First numeric value.value2 - Second numeric value.

Page 130: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Min

float Min(float value1, float value2) Returns the maximum of two numeric values passed. Parameters: value1 - First numeric value.value2 - Second numeric value.

Page 131: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Pow

float Pow(float base, float exponent) Returns the value of base raised to a power of exponent. Parameters: base - Base value.exponent - Power value.

Page 132: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Sqrt

float Sqrt(float value) Returns the square root of value. If value is less than zero, returns null. Parameters: value - Numeric value.

Page 133: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Data

Page 134: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Bid

float Bid() Returns current best Bid value.

Page 135: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Offer

float Offer() Returns current best Offer value.

Page 136: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SymbolBid

float SymbolBid(string name, integer account) Returns current best Bid value for the instrument with name name (code) and account account number. If noistrument with such name and account number exists, returns null. Note. Depending on trading terminal, instrument code is set in various composite instrument windows (egMetaTrader instrument settings, SaxoTrader instrument settings and QuoteSpeed instrument settings). Accountnumber should be given only for MetaTrader instruments in MetaTrader instrument settings. For other tradingterminals you should set account to 0. Function will only work correctly when the script is launched for real-time execution (eg script is started). Whenbacktesting (in Script Backtester) function always returns null. Parameters: name - Instrument name (code)account - Instrument account number. For non-MetaTrader instruments should be set to 0.

Page 137: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SymbolOffer

float SymbolOffer(string name, integer account) Returns current best Offer value for the instrument with name name (code) and account account number. If noistrument with such name and account number exists, returns null. Note. Depending on trading terminal, instrument code is set in various composite instrument windows (egMetaTrader instrument settings, SaxoTrader instrument settings and QuoteSpeed instrument settings). Accountnumber should be given only for MetaTrader instruments in MetaTrader instrument settings. For other tradingterminals you should set account to 0. Function will only work correctly when the script is launched for real-time execution (eg script is started). Whenbacktesting (in Script Backtester) function always returns null. Parameters: name - Instrument name (code)account - Instrument account number. For non-MetaTrader instruments should be set to 0.

Page 138: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SymbolLastChange

float SymbolLastChange(string name, integer account) Returns last tick date-time value for the instrument with name name (code) and account account number. If noistrument with such name and account number exists, returns null. Note. Depending on trading terminal, instrument code is set in various composite instrument windows (egMetaTrader instrument settings, SaxoTrader instrument settings and QuoteSpeed instrument settings). Accountnumber should be given only for MetaTrader instruments in MetaTrader instrument settings. For other tradingterminals you should set account to 0. When backtesting (in Script Backtester) function will only work correctly when an "Accumulate data" tickeris checked (eg. MetaTrader instrument Additional settings, SaxoTrader instrument Additional settings иQuoteSpeed instrument Additional settings). Otherwise function will always return null. Parameters: name - Instrument name (code)account - Instrument account number. For non-MetaTrader instruments should be set to 0.

Page 139: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Chart data functions

Page 140: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

PointCount

float PointCount() Returns number of ticks in the historical data archive.

Page 141: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Point

float Point(string id,integer shift) Returns a time series line value with id identifier at a point offset backwards to the last point by shift points. Ifa line with such id does not exist or a point specified by shift goes beyond available data, returns null. Note. Line ID is set in the indicator settings for each indicator (eg. Indicator parameters). Bid and Offer lines havetheir IDs preset as "Bid" and "Offer". Example. Point("Bid",0) will return current (the last) best bid value,Point("Bid",1) will return previous best bid value. Parameters: id - Line identifiershift - Offset value relative to the last line point.

Page 142: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SymbolBidPoint

float SymbolBidPoint(string name, integer account,integer shift) Returns current best Bid value for the instrument with name name (code) and account account number, offsetbackwards from the current value by shift. If a line with such id does not exist or a point specified by shiftgoes beyond available data, returns null. Note. Depending on trading terminal, instrument code is set in various composite instrument windows (egMetaTrader instrument settings, SaxoTrader instrument settings and QuoteSpeed instrument settings). Accountnumber should be given only for MetaTrader instruments in MetaTrader instrument settings. For other tradingterminals you should set account to 0. Function will only work correctly when an "Accumulate data" ticker is checked (eg. MetaTrader instrumentAdditional settings, SaxoTrader instrument Additional settings и QuoteSpeed instrument Additional settings).Otherwise function will always return null. Example. SymbolBidPoint("EURUSD",12345,0) will return current (the last) best bid value for "EURUSD" instrumentand "12345" account number,SymbolBidPoint("EURUSD",12345,1) will return previous best bid value for "EURUSD" instrument and"12345" account number Parameters: name - Instrument name (code)account - Instrument account number. For non-MetaTrader instruments should be set to 0.shift - Offset value relative to the last line point.

Page 143: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SymbolOfferPoint

float SymbolOfferPoint(string name, integer account,integer shift) Returns current best Offer value for the instrument with name name (code) and account account number,offset backwards from the current value by shift. If a line with such id does not exist or a point specified byshift goes beyond available data, returns null. Note. Depending on trading terminal, instrument code is set in various composite instrument windows (egMetaTrader instrument settings, SaxoTrader instrument settings and QuoteSpeed instrument settings). Accountnumber should be given only for MetaTrader instruments in MetaTrader instrument settings. For other tradingterminals you should set account to 0. Function will only work correctly when an "Accumulate data" ticker is checked (eg. MetaTrader instrumentAdditional settings, SaxoTrader instrument Additional settings и QuoteSpeed instrument Additional settings).Otherwise function will always return null. Рассмотрим пример. SymbolOfferPoint("EURUSD",12345,0) will return current (the last) best bid value for "EURUSD"instrument and "12345" account number,SymbolOfferPoint("EURUSD",12345,1) will return previous best offer value for "EURUSD" instrument and"12345" account number. Parameters: name - Instrument name (code)account - Instrument account number. For non-MetaTrader instruments should be set to 0.shift - Offset value relative to the last line point.

Page 144: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

DateTime

float DateTime(integer shift) Returns date-time value of the point offset backwards from the last point by shift. If a point specified by shiftgoes beyond available data, returns null. Example: DateTime(0) will return current (the last) point date-time value.DateTime(1) will return previous point date-time value. Parameters: shift - Offset value relative to the last line point.

Page 145: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Index

integer Index(integer shift) Returns the index of a point offset from the last data point by shift. Indexing starts with 0. If resulting index isless than zero (ie. beyond available data), the returns null. For example: Let the number of data archive points be N. Then the first point has 0 index, and current (last) hasN-1 index. Index(0) will return N-1,Index(1) will return N-2,...Index(N-1) will return 0. Parameters: shift - Offset value relative to the last line point.

Page 146: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Shift

integer Shift(integer index) Returns an index number data point's shift relative to last data point. Indexing starts with 0. If index is beyondavailable data, returns null. For example: Let the number of data archive points be N. Then the first point has 0 index, and current (last) hasN-1 index. Shift(N-1) will return 0,Shift(N-2) will return 1,...Shift(0) will return N-1. Parameters: index - Offset index.

Page 147: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Trading functions

Page 148: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Balance

integer Balance() Returns the current market position balance. Balance value shows a balanced number of units spread in marketposition, and the sign of balance is the position's direction: positive - buying (long), negative - selling, or short(for example, the balance of 2 means having 2 units of spread in long position, if it is -2 - short position of thecorresponding size ).

Page 149: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Disbalance

integer Disbalance() Returns the current position imbalance. The imbalance shows the unbalanced number of spread units in currentposition. The imbalance is the result of portfolio lacking positions on some instruments. The imbalance showsthe number of spread units to be added to the current position balance if missing positions will be opened (long/short), and imbalance sign is the direction of potential position added.

Page 150: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

TradeQnty

integer TradeQnty() Returns the default number of spread units to be bought/sold in each buy/sell order. Note. This parameter can be set in "Quantity" field Trading tab.

Page 151: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

GetMaxQnty

integer GetMaxQnty() Returns the maximum number of spread units in open positions (ie. specified number of spread units is themaximum to be in Balance tab). Note. The parameter can be set with "Max. quantity" option on Trading tab, or set with SetMaxQnty function.

Page 152: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SetMaxQnty

SetMaxQnty(integer quantity) Sets the maximum number of spread units in open positions (ie. specified number of spread units is themaximum to be in Balance tab). The limit applies to both positions opened by the user and ones opened byscript. Note. The parameter can be set with "Max. quantity" option on Trading tab Parameters: quantity - Limit in spread units.

Page 153: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Buy

Buy(integer quantity) Buys quantity spread units. Parameters: quantity - Spread units quantity.

Page 154: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Sell

Sell(integer quantity) Sells quantity spread units. Parameters: quantity - Spread units quantity.

Page 155: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Close

Close() Closes all opened positions.

Page 156: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Information output

Page 157: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Message

Message(string msg) Displays the msg message to messages tab on the trade panel (см. Messages tab). Parameters: msg - String - message text.

Page 158: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Alert

Alert(string msg) Displays a modal window with msg message. Parameters: msg - String - message text.

Page 159: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

FileClear

integer FileClear(string file) Clears a text file with file name. Returns 1 if successful, 0 otherwise. Parameters: file - File name.

Page 160: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

FileWrite

integer FileWrite(string file,string str) Adds a str string to a text file with file name. If file with such name doesn't exist, it is automatically created.Returns 1 if successful, 0 otherwise. Parameters: file - File name.str - String.

Page 161: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

System functions

Page 162: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

CurrentDateTime

float CurrentDateTime() Returns the current OS date-time value.

Page 163: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

GetTickCount

integer GetTickCount() Returns the number of milliseconds elapsed since system start. The counter is limited to system timer'sresolution.

Page 164: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Script examples

Example 1 A simplistic strategy, buying one spread unit when the best Bid price exceeds a set level and selling it when bestOffer price goes below the level. 01234567

main(){if(Bid()>10){Sell(1);}if(Offer()<-10){Buy(1);}}

////If Bid price exceeds 10//Sell one spread unit////If Offer price is less than -10//Buy one spread unit////

Example 2 This example shows a classic pair trading strategy, selling as a spread rises above a set number of standarddeviations from a moving average and buying when it falls below a set number of standard deviations from a movingaverage. Closing of positions occurs when the spread returns to the mean. To implement the strategy, it is necessary to add the Bollinger Bands indicator to the spread chart. The Bollingerbands top and bottom lines are calculated as a certain number of standard deviations from the moving average.It's better to use Mean Price showing an average of Bid and Offer prices as a data source for Bollinger Bands. Inorder for the script to work correctly, you must set the Bollinger Bands output parameters as follows: the central line -"BBandCenter", top line - "BBandTop", bottom line - "BBandBottom". 01234567891011121314151617181920212223242526

main(){var BBTop,BBBottom,BBCenter;BBCenter=Point("BBandCenter",0);BBTop=Point("BBandTop",0);BBBottom=Point("BBandBottom",0);if(BBCenter!=null){if(Balance()==0){ if(Bid()>BBTop){ Sell(1); } else{ if(Offer()<BBBottom){ Buy(1); } } } else{ if(Balance()>0){ if(Bid()>BBCenter){ Close(); } } else{ if(Offer()<BBCenter){ Close(); } }

//////Central BB line//Top BB line//Bottom BB line//If indicator values are available//If no market position is present//If Bid is above BB top line//We sell one spread unit//////If Offer is below BB bottom line//We buy one spread unit//////////If current market position is Long//If Bid is above BB central line//We close the position//////If current market position is Short//If Offer is below BB central line//We close the position////

Page 165: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

272829

}}}

//////

In this example the program first gets current top, center and bottom Bollinger Bands values and stores them inBBCenter, BBTop and BBBottom variables (strings 2-4). Then if(BBCenter!=null) condition (string 5) checksif the indicator values are available. It is because if Bollinger Bands has an N averaging period, data will be availableafter only N-1 index data point occurs. So, if current point index is less than BB averaging period, Point function willreturn null. Then program checks the opened positions. If market balance equals zero (string 6), script checks position openingconditions: if current best Bid price goes above Bollinger Bands top line (string 7), one spread unit is sold (string 8),and if Offer price goes below BB bottom line ( string 11), one spread unit is bought (string 12). If current position ispositive - long (string 17), then if Bid goes above BB central line (string 18), position is closed (string 19). Vice versa,if we are in a short position (string 22), position is closed when Offer price goes below Bollinger Bands central line(string 23). Example 3 This example is basically a more complex example 2 due to adding position averaging (increasing the volume size oflosing positions). Position averaging is performed at set levels from order opening price. It is enough to add just a bit of code to Example 2 to get Example 3 working: 012345678910111213141516171819202122232425262728293031

main(){var BBTop,BBBottom,BBCenter;var Price,Level;BBCenter=Point("BBandCenter",0);BBTop=Point("BBandTop",0);BBBottom=Point("BBandBottom",0);Level=20;if(BBCenter!=null){if(Balance()==0){ if(Bid()>BBTop){ Sell(1); SetGlobVar("OpenPrice",Bid()); } else{ if(Offer()<BBBottom){ Buy(1); SetGlobVar("OpenPrice",Offer()); } } } else{ if(Balance()>0){ if(Bid()>BBCenter){ Close(); } else{ Price=GetGlobVar("OpenPrice"); if(Price!=null){ if(Offer()<Price-Level*Balance()){ Buy(1); } }

////////Central BB line//Top BB line//Bottom BB line//Distance between averaging levels//If indicator values are available//If no market position is present//If Bid is above BB top line//We sell one spread unit//We memorize opening price//////If Offer is below BB bottom line//We buy one spread unit//We memorize opening price//////////If current market position is Long//If Bid is above BB central line//We close the position//////Getting opening price from glob. var.//If successful//If Offer is below averaging level//We buy one more spread unit////

Page 166: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

323334353637383940414243444546474849

} } else{ if(Offer()<BBCenter){ Close(); } else{ Price=GetGlobVar("OpenPrice"); if(Price!=null){ if(Bid()>Price-Level*Balance()){ Sell(1); } } } } } }}

//////If current market position is Short//If Offer is below BB central line//We close the position//////Getting opening price from glob. var.//If successful//If Bid is above averaging level//We sell one more spread unit//////////////

In this example script stores the spread price at the moment of opening a position in a global variable OpenPrice(string 11 and 16). Then, if position is a long one (string 21) or a short one (string 34), first position closing conditionsare checked for (string 22 and 35), and averaging condition is checked for if unsuccessful (string 28 and 41).Averaging condition is checked as follows: first opening price is restored from OpenPrice global variable (string 26and 39), then script checks if spread's price had gone through preset averaging levels (string 28 and 41). Averaginglevels are calculated by a formula: Price-Level*Balance(), where Level is the distance between the averaginglevels. If spread reaches the level, position averaging occurs (string 29 and 42).

Page 167: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

Additional modules

Page 168: User guide - MegaTrader 1.4.en.pdf · • Install the MegaTraderExchange 1.2 EA in MT4. • Set the MetaTrader 4 terminal up. • Launch the MegaTraderExchange 1.2 EA. Installing

SaxoExporter

Auxiliary module SaxoExporter is developed to allow quotes import from SaxoTrader terminal to MegaTrader.As SaxoTrader does not have any quote export functions, they are being read directly from the programinterface, or rather - "Forex orders" and "Futures orders" modal windows. So, for quote export to be possible fromSaxoTrader, it is necessary to have the corresponding windows opened for all the instruments you plan to workwith. Module's UI consists of only two buttons: "Run" and "Stop", which launch and stop quote export respectively. If a new Orders window is opened in SaxoTrader after quotes export already started, for SaxoExporter to "fetch"it module should be restarted by pressing "Stop" and then "Run"). SaxoExporter is automatically launched by MegaTrader when clicking "Connection > Connect to SaxoTrader".So in most cases manual intervention will not be required. Module's icon should appear in system tray when it'srunning.