META-DELTA 1.2
MetaTrader 4 Bridge
MetaTrader 4 bridge allows you to:
- Execute MetaTrader strategies (Expert Advisors) with Deltastock
- Write MQL4 scripts for trading with Deltastock
- Use MetaTrader to trade with Deltastock
We've built the bridge between MT4 and Delta Trading™
for the MT4 traders who have "Expert Advisors",
which they want to run in Delta Trading.
The main idea is that traders use Meta Trader 4 functionality and interface to trade and run experts.
Once an order is executed in Meta Trader, an identical one
will be executed in Delta Trading™ so that the positions in both accounts remain the same.
Prerequisites:
How to Install the Package?
| 1. |
Stop the Meta Trader terminal if it is running. |
| 2. |
Download MetaDelta1.2.zip and extract it to a temporary directory. |
| 3. |
Run setup.exe and follow the instructions
If you have MetaTrader terminals of more than one broker installed
you have to chooses the directory where Deltastock Meta Trader 4 terminal is installed. For example
C:\Program Files\Deltastock MetaTrader
 |
| 4. |
Restart MetaTrader
|
Getting Started
| 1. |
Start the program "EditInstruments.exe".
You can find its icon on the desktop or in <terminal dir>/MetaDelta.
a) The first thing you need to do is to enter your Deltastock account number
META-DELTA will be trading with.
You can find the account number on the title bar of Delta Trading main window.
(Only when the option "Show user ID and name on title bar" is set to "Yes".
It is in Settings/General Settings/Other Parameters)
b)Then you have to decide which instruments you are going to trade with and
add them to the list. This is necessary as different brokers use different symbols for the same security.
For example Deltastock's symbol for Motorola's CFD is "MOT" and some other broker's symbol might be "Motorola" or "#MT"
The six major currency pairs are set by default:
EUR/USD, GBP/USD, AUD/USD, USD/JPY, USD/CHF, USD/CAD
 |
| 2. |
Start DeltaTrading.exe and login.
It is highly recommended to start with a Delta Trading Demo account to understand how META-DELTA works.
|
| 3. |
Login to your MetaTrader DEMO account.
(It is recomended to use a MetaTrader DEMO account to have better execution time and avoid slippage).
|
| 4. |
Go to "Tools/Options" and select "Expert Advisors" tag. Check "Allow DLL imports" and uncheck "Confirm DLL function calls".

|
| 5. |
Open the "Scripts" folder From the "Navigator" panel and attach the script "META-DELTA"
to an arbitrary chart (by a right click / "Execute on Chart", Drag and Drop or a double click).
In the upper left corner of the chart a yellow label will appear, indicating that the script is running.
The script executes orders for all instruments set by EditInstruments.exe,
not only for the instrument of the chart it is attached to.
In the "Experts" folder you can keep track of the orders sent to Deltastock.

The META-DELTA script can only be attached to ONE chart!
|
| 6. |
Open the folder "User Indicators" and attach the indicator "Positions" to the same chart you have attached META-DELTA to.
The indicator shows the positions of the selected instruments in Deltastock and Meta Trader,
as well as the current result for each instrument.

|
| 7. |
You can trade with MetaTrader and/or start a strategy. Every order sent will be duplicated in Delta Trading and will be executed by Deltastock. The STOP and LIMIT orders are not send to Deltastock. They get executed by Deltastock once they are executed in MT.
Remember that the Bridge will only be trading with the instruments predefined in EditInstruments.exe!
|
| 8. |
If you have different positions in Deltastock and Meta Trader, they will be
adjusted when you start the script for the first time, for example:
| Meta Trader | Deltastock |
EUR/USD BUY 0,07 LOTS*
EUR/USD SELL 0,01 LOTS
|
EUR/USD 2000 UNITS
|
META-DELTA will send an order "BUY 4000 EUR/USD" to Deltastock, as the position in Meta Trader is
0,07 - 0,01 = 0,06 LOTS * 100 000 = 6000 UNITS
2000 + 4000 = 6000 UNITS in Deltastock
____ *Presuming the lot size in MetaTrader is 100 000 units.
|
How Meta-Delta works?
The package consists of:
- The DLL delta.dll - it connects MetaTrader to Delta Trading.
- MQL4 script - META-DELTA.mq4 Can be found in the
"Scripts" folder of the "Navigator" panel. Once attached to an
arbitrary chart it constantly callculates the positions of the
instruments selected in advance. If they differ the script
adjusts their positions by sending an order to Deltastock.
The instruments you are going to trade with have to be pre-defined by "EditInstruments.exe"
(placed on your desktop or in <terminal_dir>/MetaDelta).
Scripts for trading with Deltastock
This part addresses those MetaTrader users who have experience in writing MQL4 scrips as well as programmers.
Deltastock's API cannot be used directly from MQL4 script, because the script does not allow use of ActiveX components,
but only external DLL libraries.
That is why we have created a normal DLL (delta.dll) containing
most of the API functions available in DSAPI so you can use them in your MQL4 scripts.
"delta.dll" should be placed in <terminal_dir> or
<WINDIR>\system32.
The DLL file
is automatically installed in <terminal_dir>.
Examples of how to use the functions can be found in DELTA_Samples.mq4
Descriptions of the functions which you can use with a Meta Trader script
All functions start with "DELTA_" and are
declared in metadelta.mqh (which is in <terminal_dir/experts/include>).
All functions return 0 if there is no error and non-zero otherwise.
A value between -500 and -1 indicates a DSAPI error, which can be found
in the DSAPI error description table.
A value smaller than -500, is an OLE error. And finally,
if the value is greater than 0, it is an Exception number.
All functions take as a first parameter the Deltastock account number
the API is trading with. This is necessary as Delta Trading allows multiple copies to run
simultaneously, so this number shows wich copy the API uses.
In order to use the DLL functions you must include metadelta.mqh
at the beginning of the script in which you intend to use them by
#include <metadelta.mqh>
If you will be using the API functions in a Meta Trader script you should call DELTA_Init(AccNumber) before
calling any other function.
And at the end of the script you should call DELTA_Uninit()
If the script is an Expert Advisor, this is not necessary.
In the sections below we have described all the functions in detail:
DELTA_Init()
int DELTA_Init(string DS_AccNumber)
This function initializes the API
Parameters:
DS_AccNumber - The account number in Deltastock the API will be trading with
Meta Trader script:
DELTA_Init() should be called once before any other function. And respectively,
you should call DELTA_UnInit() before the end of the script.
Expert Advisor: If the script is an Expert Advisor,
there is no need to call DELTA_Init() nor DELTA_UnInit().
|
|
DELTA_UnInit()
int DELTA_UnInit()
Releases the resources used by DSAPI.
* Meta Trader scripts:
- the DELTA_UnInit() has to be called at the end of the script, after all other functions.
* Expert Advisors: there is no
need to call DELTA_Init nor DELTA_UnInit
|
|

DELTA_NewOrder
int DELTA_NewOrder
(
string DS_AccNumber,
string Instrument,
int ordCount,
double ordPriceReq1,
double ordPriceReq2,
int ordType, string
ordBuySell, string ordValidity,
int & OrderID[] );
Places an order for execution
Parameters:
| DS_AccNumber |
The Deltastock account number the API is trading with |
| Instrument |
The instrument symbol in Delta Trading™ (i.e. EUR/USD) |
| ordCount |
The quantity in units (not lots). Should be divisible by 1000
|
| ordPriceReq1 |
Placed price |
| ordPriceReq2 |
The second price (For OCO orders) |
| ordType |
Order type: 1 – market, 2 – limit, 3 – stop, 4 – OCO
are defined as constants in metadelta.mqh as follows:
int DELTA_MARKET = 1;
int DELTA_LIMIT = 2;
int DELTA_STOP = 3;
int DELTA_OCO = 4;
|
| ordBuySell |
Buy – "B" or sell – "S" |
| ordValidity |
For the day – "1" Good till cancelled (GTC) – "2" |
| ordID |
The order ID if executed successfully |
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetOrderStatus
int DELTA_GetOrderStatus
(
string DS_AccNumber,
int orderID, int & Status[]);
Returns the status of an order.
Parameters:
OrdID – The ID of the order which status you are checking
Status - The result is returned in the status parameter as follows:
1, 2, 3, 4, 5 – pending/confirmed/executed/cancelled/awaiting cancellation.
You can also use the defined constants in metadelta.mqh:
int ORD_PENDING = 1;
int ORD_CONFIRMED = 2;
int ORD_EXECUTED = 3;
int ORD_CANCELED = 4;
int ORD_AWAITING_CANCELATION = 5;
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetOrderParams
int DELTA_GetOrderParams
(
string DS_AccNumber,
int OrderID,
string DS_Symbol,
string Oper,
double& PriceExecuted[],
int& Units[]),
int& Status[],
int& Type[],
double& PricePlaced[],
double& PriceOCO[]);
Returns the parameters of an order
Parameters:
DS_AccNumber
- Deltastock account number(e.g "000142775")
Price, Units и Status parameters should be declared
as single elements arrays in order to be populated by the function.
OrderID – Order ID
DS_Symbol – Order symbol
Oper - Order operation - "B" - BUY, "S" - SELL
Price - execution price
Status - Order status:
ORD_PENDING = 1;
ORD_CONFIRMED = 2;
ORD_EXECUTED = 3;
ORD_CANCELED = 4;
ORD_AWAITING_CANCELATION = 5;
Type - order type: 1-market,2-limit,3-stop,4-OCO
PricePlaced - Placed Price (for LIMIT and STOP orders)
PriceOCO - Second Price for OCO Orders
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetPosition
int DELTA_GetPosition
(string DS_AccNumber, string Instrument, double& Count[], double& Price[]);
The function returns the volume and the average price of a position
Parameters:
DS_AccNumber - The account number in Deltastock the API is trading with.
Instrument – The instrument of the position.
Count - The position in units (not lots).
Price - The average price of the position.
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_FreeMargin
int DELTA_FreeMargin
(string DS_AccNumber, string Currency, double& Margin[]);
Returns the free margin of the account in the currency specified
Parameters:
DS_AccNumber - The account number in Deltastock
Currency – The currency in which the margin is calculated.
Margin - The free margin in the currency specified.
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_CancelOrder
int DELTA_CancelOrder
(string DS_AccNumber, int OrdID);
This function sends an order for cancellation.
Parameters:
DS_AccNumber - The account number in Deltastock
OrderID – The ID of the order you want to cancel.
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_ClosePosition
int DELTA_ClosePosition
(string DS_AccNumber, string Instrument);
This function closes the position of an instrument at the current market price.
Parameters:
DS_AccNumber - The account number in Deltastock
Instrument – The instrument symbol.
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetPositionRes
int DELTA_GetPositionRes
(string DS_AccNumber, string Instrument, string Currency, double& result[]);
This function returns the current result of a position.
Parameters:
DS_AccNumber - The account number in Deltastock.
Instrument – The symbol of the instrument.
Currency – The currency in which the result will be calculated (i.e.: InCurrency = "EUR").
Result - The current result of the position.
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetErrMsg
int DELTA_GetErrMsg
(string DS_AccNumber, int err_no, string errMsg, int errMsgLen);
This function returns the description of error number err_no.
Parameters:
DS_AccNumber - The account number in Deltastock the API is trading with
err_no – The number of the error you want to get a description.
errMsg – The error description.
errMsgLen - The length of errMsg string
errMsg should be initialized with a number of symbols equal to errMsgLen:
string ErrMsg =
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetQuote
int DELTA_GetQuote
(string DS_AccNumber,
string Instrument,
double& QBid[],
double& QAsk[],
double& QHi[],
double& QLow[]););
Returns the quotes for an instrument
Parameters:
DS_AccNumber - The account number in Deltastock
The function returns the result in the parameters below.
These parameters must be declared as single element arrays so that they can return the result.
QBid – Buy
QAsk – Sell
QHi - High
QLow - Low
Result:
Returns 0 if OK and non-zero otherwise.
Example:
double QBid[1], QAsk[1], QHi[1], QLow[1];
err = DELTA_GetQuote(Instrument, QBid, QAsk, QHi, QLow);
if(err != 0)
{
Print("ERROR calling DELTA_GetQuote: " err);
return(-1);
}
else
{
Print ("bid = " + QBid[0] + "ask = " + QAsk[0] + "hi = " + QHi[0] + "low = " + QLow[0]);
}
|
|
DELTA_GetPrecision
int DELTA_GetPrecision
( string DS_AccNumber,
string Instrument,
double& Precision[]);
Returns the quotes precision of an instrument (the number of digits after the decimal point)
Parameters:
DS_AccNumber
- The account number in Deltastock (e.g.: "000142775")
Instrument
- The instrument we want the precision for
Precision - The precision is returned in this parameter.
Should be declared as a single element array (for example: double prec[1]).
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_Log
int DELTA_Log
( string DS_AccNumber,
int on_off
);
Toggles logging. The log file resides in <DeltaTrading_dir>/Logs.
To switch logging on you also need to set the option "Write to log" (Settings/Common/General Settings/Client)
in DeltaTrading to "Yes"
When the option is set additional error information is written to the log file.
Parameters:
DS_AccNumber
- The account number in Deltastock (e.g.: "000142775")
Precision
- 1 turns the logging on, 0 turns it off.
Result:
Returns 0 if OK and non-zero otherwise.
|
|
DELTA_GetPip
int DELTA_GetPip
( string DS_AccNumber,
double& pip[]
);
Returns the point value of an instrument.
Parameters:
DS_AccNumber
- The account number in Deltastock (e.g.: "000142775")
pip
- the point value of the instrument
Result:
Returns 0 if OK and non-zero otherwise.
|
|
Changes in version 1.2
Two new parameters have been added to GetOrderParams - double& PricePlaced[] and double& PriceOCO[].
They return Limit & Stop orders placed price and the second price of OCT orders.
Please, add the two new parameters if you are using DELTA_GetOrderParams in scripts or in experts!
The function DELTA_GetOrderStatus will now return 0 when an order has been successfully executed.
(There was an error in the previous version, and the function returned 1 in case of success)
Three new functions have been added:
DELTA_Log - toggles logging
DELTA_GetPrecision - returns the quotes precision of an instrument
DELTA_GetPip - returns the pip value of certain instrument