DeltaStock - Global Forex and CFD Broker

Open a FREE Demo Account
Open a Live Account
Live HelpLive Help Language: English

DeltaStock API for MetaTrader 4

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

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.

Description of the API Functions

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
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


Trading Information Deltastock Accounts Trading Platforms Trading Resources

Instruments Available:

Forex

Contracts for Difference (CFDs)

Gold and Silver

Partnership:

Referring Party Program

White Label

Introducing Broker

Demo Account:

Get a Delta Trading Demo

Get a MetaTrader 4 Demo

Download Delta Trading

Download MetaTrader 4

Live Account:

Open a Delta Trading Live

Open a MetaTrader 4 Live

Deposit Funds:

Information

Delta Trading:

Get a Free Demo

Download Platform

User Guide

Platform Video Tutorials

MetaTrader 4:

Get a Free Demo

Download Platform

Installation Details

Trading Tools:

Economic Calendar

Forex Technical Analysis

Forex and Index Quotes

Currency Calculator

Currency Relation

Trading Widgets

Webmaster Tools:

Free Forex Tools

Your IP-address: 38.107.179.223 phonephone: +359 2 811 50 10; phone24/5 Live Help; phoneE-mail: office@deltastock.com
Copyright © 1999-2012 Deltastock AD Home    Contact us    Legal information    Privacy    Risk warning    Site map

Risk Warning: Trading оn margin carries a high level of risk to your capital and may not be suitable for all investors. You may lose more than your initial investment! Ensure you fully understand the risks involved and seek independent advice if necessary.

Head Office: 115 G Tsarigradsko Shose Blvd., Megapark Office Building, Office Area "E", floor 6, 1784 Sofia, Bulgaria. Regulated by Financial Supervision Commission (FSC) Reg. No: RG-03-0146 and registered in Bulgarian National Bank (BNB) Reg. N BGR00107.

The information on this site is not intended for use by, or for distribution to, any person in any country or jurisdiction, where such use or distribution would contravene the local law or regulation.

EU EU Regulated and Authorised by the Financial Supervision Commission (FSC), Bulgaria, Register Number: RG-03-0146 and Registered with Bulgarian National Bank (BNB) Register Number: BGR00107