0

控制MT4的DLL(包括54个主要函数)

时间:2008-09-06 22:48:34  来源:  作者:
本接口可用于实现针对MT4的外部控制和一些内部控制。是开发MT4外部功能不错的开始。
MetaTrader 4 application program interface.
MT4程序接口。
The whole API consist of 54 functions of the MetaTrader 4 client terminal
implemented in the tzmt4api.dll.
 全部API包含54个控制MT4客户端的函数,他们都整合在tzmt4api.dll中。
Client's functions:
void Dispose_MT4(char *value);
char* VersionGet_MT4( );
Returns API version number.
After using this returns should be freed by the Dispose_MT4 function.

int ServerTotal_MT4( );
Returns the number of server.

char* ServerGet_MT4( const int index );
The function returns a string that is a server or NULL if failed.
Parameters:
index - Order index.
After using this returns should be freed by the Dispose_MT4 function

int LogIn_MT4( const int login, const char *password, const char *server, const char *proxyserver,
               const char *proxytype, const char *proxylogin, const char *proxypassword );
Create a connection with the server. In case of success returns a handle and if mistaken it returns -1.
Parameters:
login         ?the number of the account to connect;
password      ?password for logging into the system.
server        - the name of the trade server to be connected to. The server name is the same as the
                name of the corresponding .srv file;
proxyserver   - proxy server address.
proxytype     - proxy server type.It can be "HTTP", "SOCKS4", or "SOCKS5".
proxylogin    - login to be authorized on proxy server.
proxypassword - password to access to proxy server.

int LogOut_MT4( const int handle );
Break of earlier created connection with the server.
Parameter:
handle ?Connect handle.
//=================================================================================================
int SymbolsTotal_MT4( const int handle );
Returns the number of symbols.
Parameter:
handle ?Connect handle.

char* SymbolGet_MT4( const int handle, const int index );
The function returns a string that is a symbol or NULL if failed.
Parameters:
handle ?Connect handle;
index  - Order index.
After using this returns should be freed by the Dispose_MT4 function
//=================================================================================================
char* HistoryGet_MT4( const int handle, const char *symbol, const int _from, const int _to,
                           const int period, const int maxbars );
Request to the server to getting prices history, returns bars, or NULL if failed.
Parameters:
handle  - Connect handle;
symbol  ?the name of the security on which it is needed to receive quotations;
_from   - date for the start period;
_do     - date for ending period;
period  ?the period of quotations (PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1,
          PERIOD_H4, PERIOD_D1, PERIOD_W1);
maxbars - zero for all.
After using this returns should be freed by the Dispose_MT4 function.

int TickAddSymbol_MT4( const int handle, const char *symbol );
Adding of some instrument to the list of selected instruments for getting streaming prices in
TickGet_MT4().
handle ?socket handle;
symbol ?name of the instrument required to be added.

int TickHideSymbol_MT4( const int handle, const char *symbol );
Deleting instruments from the list of selected instruments. The quotations' stream in the
TickGet_MT4() for this symbol will be stopped.
handle ?socket handle;
symbol ?name of the instrument required to delete.

char* TickGet_MT4( const int handle );
Request to the server to getting last price in the quotation.
Parameter:
handle - Connect handle;
After using this pchar should be freed by the Dispose_MT4 function.

char* TickGetSymbol_MT4( const int handle, const char *symbol  );
Request to the server to getting last price in the quotation for specific symbol.
Parameter:
handle - Connect handle;
symbol ?name of the instrument required;
After using this pchar should be freed by the Dispose_MT4 function.
//=================================================================================================
double AccountBalance_MT4( const int handle );
Returns balance value of the current account (the amount of money on the account).
Parameter:
handle  ?Connect handle.

double AccountCredit_MT4( const int handle );
Returns credit value of the current account.
Parameter:
handle  ?Connect handle.

char* AccountCompany_MT4( const int handle );
Returns the brokerage company name where the current account was registered.
Parameter:
handle  ?Connect handle.
After using this returns should be freed by the Dispose_MT4 function

char* AccountCurrency_MT4( const int handle );
Returns currency name of the current account.
Parameter:
handle  ?Connect handle.
After using this returns should be freed by the Dispose_MT4 function

double AccountEquity_MT4( const int handle );
Returns equity value of the current account. Equity calculation depends on trading server settings. 
Parameter:
handle  ?Connect handle.

double AccountFreeMargin_MT4( const int handle );
Returns free margin value of the current account.
Parameter:
handle  ?Connect handle.

double AccountFreeMarginMode_MT4( const int handle );
Calculation mode of free margin allowed to open positions on the current account.
The calculation mode can take the following values:
0 - floating profit/loss is not used for calculation;
1 - both floating profit and loss on open positions on the current account are used for free margin calculation;
2 - only profit value is used for calculation, the current loss on open positions is not considered;
3 - only loss value is used for calculation, the current loss on open positions is not considered.
Parameter:
handle  ?Connect handle.

int AccountLeverage_MT4( const int handle );
Returns leverage of the current account.
Parameter:
handle  ?Connect handle.

double AccountMargin_MT4( const int handle );
Returns margin value of the current account.
Parameter:
handle  ?Connect handle.

char* AccountName_MT4( const int handle );
Returns the current account name.
Parameter:
handle  ?Connect handle.
After using this returns should be freed by the Dispose_MT4 function

int AccountNumber_MT4( const int handle );
Returns the number of the current account.
Parameter:
handle  ?Connect handle.

double AccountProfit_MT4( const int handle );
Returns profit value of the current account.
Parameter:
handle  ?Connect handle.

char* AccountServer_MT4( const int handle );
Returns the connected server name.
Parameter:
handle  ?Connect handle.
After using this returns should be freed by the Dispose_MT4 function

int AccountStopoutLevel_MT4( const int handle );
Returns the value of the Stop Out level. 
Parameter:
handle  ?Connect handle.

int AccountStopoutMode_MT4( const int handle );
Returns the calculation mode for the Stop Out level.
Calculation mode can take the following values:
0 - calculation of percentage ratio between margin and equity;
1 - comparison of the free margin level to the absolute value.
Parameter:
handle  ?Connect handle.

double AccountFreeMarginCheck_MT4( const int handle, const char *symbol, const int cmd, const double volume );
Returns free margin that remains after the specified position has been opened at the current price
on the current account. If the free margin is insufficient, an error 134 (ERR_NOT_ENOUGH_MONEY)
will be generated.
Parameters:
handle ?Connect handle;
symbol - Symbol for trading operation.
cmd    - Operation type. It can be either OP_BUY (0) or OP_SELL (1).
volume - Number of lots.
//=================================================================================================
int OrdersTotal_MT4( const int handle );
Returns the number of market and pending orders.
Parameter:
handle ?Connect handle.

int OrdersHistoryTotal( const int handle )
Returns the number of closed orders in the account history.
Parameter:
handle ?Connect handle.

int OrderGet_MT4( const int handle, const int index, const int select, const int pool );
The function returns number of the order ticket or -1 if failed.
Parameters:
handle ?Connect handle;
index  - Order index or order ticket depending on the next parameter.
select - Selecting flags. It can be any of the following values:
         SELECT_BY_POS    (0) - index in the order pool,
         SELECT_BY_TICKET (1) - index is order ticket.
pool   - Order pool index. Used when the selected parameter is SELECT_BY_POS. It can be
         any of the following values:
         MODE_TRADES (default) (0) - order selected from trading pool(opened and pending orders),
         MODE_HISTORY          (1) - order selected from history pool (closed and canceled order).

double OrderClosePrice_MT4( const int handle, const int ticket );
Returns close price for the order ticket.
Parameters:
handle ?Connect handle;
ticket - Unique number of the order ticket.

char* OrderComment_MT4( const int handle, const int ticket );
Returns comment for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.
After using this returns should be freed by the Dispose_MT4 function.

double OrderCommission_MT4( const int handle, const int ticket );
Returns calculated commission for the order ticket .
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

int OrderExpiration_MT4( const int handle, const int ticket );
Returns expiration date for the pending order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

double OrderLots_MT4( const int handle, const int ticket );
Returns amount of lots for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

int OrderMagicNumber_MT4( const int handle, const int ticket );
Returns an identifying (magic) number for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

double OrderOpenPrice_MT4( const int handle, const int ticket );
Returns open price for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

int OrderOpenTime_MT4( const int handle, const int ticket );
Returns open time for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

double OrderProfit_MT4( const int handle, const int ticket );
Returns the net profit value (without swaps or commissions) for the selected order.
For open positions, it is the current unrealized profit. For closed orders, it is the fixed profit.
Returns profit for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

double OrderStopLoss_MT4( const int handle, const int ticket );
Returns stop loss value for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

double OrderSwap_MT4( const int handle, const int ticket );
Returns swap value for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

char* OrderSymbol_MT4( const int handle, const int ticket );
Returns the order symbol value.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.
After using this returns should be freed by the Dispose_MT4 function.

double OrderTakeProfit_MT4( const int handle, const int ticket );
Returns take profit value for the order ticket.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

int OrderType_MT4( const int handle, const int ticket );
Returns order operation type for the order ticket. It can be any of the following values:
OP_BUY       - (0) buying position,
OP_SELL      - (1) selling position,
OP_BUYLIMIT  - (2) buy limit pending position,
OP_BUYSTOP   - (3) buy stop pending position,
OP_SELLLIMIT - (4) sell limit pending position,
OP_SELLSTOP  - (5) sell stop pending position.
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

bool OrderClose_MT4( const int handle, const int ticket, const double lots, const double price, const int slippage );
Closes opened order. If the function succeeds, the return value is true. If the function fails,
the return value is false. To get the detailed error information, call GetLastError_MT4().
Parameters:
handle   ?Connect handle.
ticket   - Unique number of the order ticket.
lots     - Number of lots.
price    - Preferred closing price.
slippage - Value of the maximum price slippage in points.

bool OrderCloseBy_MT4( const int handle, const int ticket, const int opposite );
Closes an opened order by another opposite opened order. If the function succeeds, the return value
is true. If the function fails, the return value is false. To get the detailed error information,
call GetLastError_MT4().
Parameters:
handle   ?Connect handle.
ticket   - Unique number of the order ticket.
opposite - Unique number of the opposite order ticket.

bool OrderDelete_MT4( const int handle, const int ticket );
Deletes previously opened pending order. If the function succeeds, the return value is true.
If the function fails, the return value is false. To get the detailed error information,
call GetLastError_MT4().
Parameters:
handle ?Connect handle.
ticket - Unique number of the order ticket.

bool OrderModify_MT4( const int handle, const int ticket, const double price, const double stoploss,
                      const double takeprofit, const int expiration );
Modification of characteristics for the previously opened position or pending orders.
If the function succeeds, the returned value will be TRUE. If the function fails, the returned value
will be FALSE. To get the detailed error information, call GetLastError_MT4() function.
Notes: Open price and expiration time can be changed only for pending orders.
If unchanged values are passed as the function parameters, the error 1 (ERR_NO_RESULT) will be generated.
Pending order expiration time can be disabled in some trade servers. In this case, when a non-zero value
is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED) will be generated.
Parameters:
handle     ?Connect handle.
ticket     - Unique number of the order ticket.
price      - New open price of the pending order.
stoploss   - New StopLoss level.
takeprofit - New TakeProfit level.
expiration - Pending order expiration time.

int OrderSend_MT4( const int handle, const char *symbol, const int cmd, const double volume, const double price,
                   const int slippage, const double stoploss, const double takeprofit, const char *comment,
                   const int magic, const int expiration);
The main function used to open a position or place a pending order.
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get
additional error information, one has to call the GetLastError_MT4() function.
Notes:  At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling)
or Ask (for buying) can be used as open price. If operation is performed with a security differing
from the current one, the MarketInfo() function must be used with MODE_BID or MODE_ASK parameter
for the latest quotes for this security to be obtained. Calculated or unnormalized price cannot be
applied. If there has not been the requested open price in the price thread or it has not been
normalized according to the amount of digits after decimal point, the error 129 (ERR_INVALID_PRICE)
will be generated. If the requested open price is fully out of date, the error 138 (ERR_REQUOTE)
will be generated independently on the slippage parameter. If the requested price is out of date,
but present in the thread, the position will be opened at the current price and only if the current
price lies within the range of price+-slippage.
StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop
levels in points can be obtained using the MarketInfo_MT4() function with MODE_STOPLEVEL parameter.
In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS)
will be generated.
At placing of a pending order, the open price cannot be too close to the market. The minimal distance
of the pending price from the current market one in points can be obtained using the MarketInfo_MT4()
function with the MODE_STOPLEVEL parameter. In case of false open price of a pending order, the error
130 (ERR_INVALID_STOPS) will be generated.
Applying of pending order expiration time can be disabled in some trade servers. In this case, when a
non-zero value is specified in the expiration parameter, the error 147 (ERR_TRADE_EXPIRATION_DENIED)
will be generated.
On some trade servers, the total amount of open and pending orders can be limited. If this limit has
been exceeded, no new position will be opened (or no pending order will be placed) and trade server
will return error 148 (ERR_TRADE_TOO_MANY_ORDERS).
Parameters:
handle     ?Connect handle;
symbol     - Symbol for trading.
cmd        - Operation type. It can be any of the Trade operation enumeration.
volume     - Number of lots.
price      - Preferred price of the trade.
slippage   - Maximum price slippage for buy or sell orders.
stoploss   - Stop loss level.
takeprofit - Take profit level.
comment    - Order comment text. Last part of the comment may be changed by server.
magic      - Order magic number. May be used as user defined identifier.
expiration - Order expiration time (for pending orders only).

//=================================================================================================
double MarketInfo_MT4( const int handle, const char *symbol, const int type );
Returns various data about securities (symbol).
Parameters:
handle ?Connect handle;
symbol - Security symbol.
type   - Request identifier that defines the type of information to be returned. Can be any of values
         of request identifiers (1, 2, 5, 9 ... 33).

int GetLastError_MT4( const int handle );
The function returns the last occurred error, then the value of special last_error variable where the
last error code is stored will be zeroized. So, the next call for GetLastError_MT4() will return 0. 
Parameter:
handle ?Connect handle.

char* ErrorDescription_MT4( const int errorcode );
Returns the symbolical description of mistakes. As a parameter it use the return code from any
above described function.
Parameters:
errorcode - Numberobtido in GetLastError_MT4();
After using this returns should be freed by the Dispose_MT4 function.

bool IsConnected_MT4( const int handle );
The function returns the status of the main connection between API and server that performs data
pumping. It returns TRUE if connection to the server was successfully established, otherwise,
it returns FALSE.
Parameter:
handle ?Connect handle.

int GetTickCount_MT4( const int handle );
The function retrieves the number of milliseconds that have elapsed since the system was started.
It is limited to the resolution of the system timer. 
Parameter:
handle ?Connect handle.

bool IsDemo_MT4( const int handle );
Returns TRUE if it's a demo account, otherwise returns FALSE.
Parameter:
handle ?Connect handle.

bool IsTradeContextBusy_MT4( const int handle )
Returns TRUE if the trade server is occupied, otherwise returns FALSE.
Parameter:
handle ?Connect handle.

int TimeCurrent_MT4( const int handle );
Returns the last known server time (time of incoming of the latest quote).
Note: At the testing, the last known server time is modelled.
Parameter:
handle ?Connect handle.
注释:下载安装后,在安装目录下,可以查看接口说明和各种Sample(包括如何在MT程序中使用这个DLL)。
 
关闭 返回顶部
联系我们
Copyright © 2011. 聚财吧. All rights reserved.