Files
All-MQL5-code/Experts/Articles/481/demo_caccountinfo.mq5
T
2018-03-14 11:26:36 +01:00

70 lines
3.0 KiB
Plaintext

//+------------------------------------------------------------------+
//| Demo_CAccountInfo.mq5 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#include <Trade\AccountInfo.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- object for working with the account
CAccountInfo account;
//--- receiving the account number, the Expert Advisor is launched at
long login=account.Login();
Print("Login=",login);
//--- clarifying account type
ENUM_ACCOUNT_TRADE_MODE account_type=account.TradeMode();
//--- if the account is real, the Expert Advisor is stopped immediately!
if(account_type==ACCOUNT_TRADE_MODE_REAL)
{
MessageBox("Trading on a real account is forbidden, disabling","The Expert Advisor has been launched on a real account!");
return(-1);
}
//--- displaying the account type
Print("Account type: ",EnumToString(account_type));
//--- clarifying if we can trade on this account
if(account.TradeAllowed())
Print("Trading on this account is allowed");
else
Print("Trading on this account is forbidden: you may have entered using the Investor password");
//--- clarifying if we can use an Expert Advisor on this account
if(account.TradeExpert())
Print("Automated trading on this account is allowed");
else
Print("Automated trading using Expert Advisors and scripts on this account is forbidden");
//--- if the permissible number of orders has been set
int orders_limit=account.LimitOrders();
if(orders_limit!=0)Print("Maximum permissible amount of active pending orders: ",orders_limit);
//--- displaying company and server names
Print(account.Company(),": server ",account.Server());
//--- displaying balance and current profit on the account in the end
Print("Balance=",account.Balance()," Profit=",account.Profit()," Equity=",account.Equity());
//--- final display
Print(__FUNCTION__," completed");
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
}
//+------------------------------------------------------------------+