Consolidate Python ignore rules into root gitignore

This commit is contained in:
Hiroaki86
2026-05-27 23:01:28 +09:00
commit fa3394415d
399 changed files with 509103 additions and 0 deletions
+397
View File
@@ -0,0 +1,397 @@
//+------------------------------------------------------------------+
//| AccountInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CAccountInfo. |
//| Appointment: Class for access to account info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class CAccountInfo : public CObject
{
public:
CAccountInfo(void);
~CAccountInfo(void);
//--- fast access methods to the integer account propertyes
long Login(void) const;
ENUM_ACCOUNT_TRADE_MODE TradeMode(void) const;
string TradeModeDescription(void) const;
long Leverage(void) const;
ENUM_ACCOUNT_STOPOUT_MODE StopoutMode(void) const;
string StopoutModeDescription(void) const;
ENUM_ACCOUNT_MARGIN_MODE MarginMode(void) const;
string MarginModeDescription(void) const;
bool TradeAllowed(void) const;
bool TradeExpert(void) const;
int LimitOrders(void) const;
//--- fast access methods to the double account propertyes
double Balance(void) const;
double Credit(void) const;
double Profit(void) const;
double Equity(void) const;
double Margin(void) const;
double FreeMargin(void) const;
double MarginLevel(void) const;
double MarginCall(void) const;
double MarginStopOut(void) const;
//--- fast access methods to the string account propertyes
string Name(void) const;
string Server(void) const;
string Currency(void) const;
string Company(void) const;
//--- access methods to the API MQL5 functions
long InfoInteger(const ENUM_ACCOUNT_INFO_INTEGER prop_id) const;
double InfoDouble(const ENUM_ACCOUNT_INFO_DOUBLE prop_id) const;
string InfoString(const ENUM_ACCOUNT_INFO_STRING prop_id) const;
//--- checks
double OrderProfitCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double volume,const double price_open,const double price_close) const;
double MarginCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double volume,const double price) const;
double FreeMarginCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double volume,const double price) const;
double MaxLotCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double price,const double percent=100) const;
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CAccountInfo::CAccountInfo(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CAccountInfo::~CAccountInfo(void)
{
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_LOGIN" |
//+------------------------------------------------------------------+
long CAccountInfo::Login(void) const
{
return(AccountInfoInteger(ACCOUNT_LOGIN));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_TRADE_MODE" |
//+------------------------------------------------------------------+
ENUM_ACCOUNT_TRADE_MODE CAccountInfo::TradeMode(void) const
{
return((ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_TRADE_MODE" as string |
//+------------------------------------------------------------------+
string CAccountInfo::TradeModeDescription(void) const
{
string str;
//---
switch(TradeMode())
{
case ACCOUNT_TRADE_MODE_DEMO:
str="Demo trading account";
break;
case ACCOUNT_TRADE_MODE_CONTEST:
str="Contest trading account";
break;
case ACCOUNT_TRADE_MODE_REAL:
str="Real trading account";
break;
default:
str="Unknown trade account";
}
//---
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_LEVERAGE" |
//+------------------------------------------------------------------+
long CAccountInfo::Leverage(void) const
{
return(AccountInfoInteger(ACCOUNT_LEVERAGE));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_SO_MODE" |
//+------------------------------------------------------------------+
ENUM_ACCOUNT_STOPOUT_MODE CAccountInfo::StopoutMode(void) const
{
return((ENUM_ACCOUNT_STOPOUT_MODE)AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_SO_MODE" as string |
//+------------------------------------------------------------------+
string CAccountInfo::StopoutModeDescription(void) const
{
string str;
//---
switch(StopoutMode())
{
case ACCOUNT_STOPOUT_MODE_PERCENT:
str="Level is specified in percentage";
break;
case ACCOUNT_STOPOUT_MODE_MONEY:
str="Level is specified in money";
break;
default:
str="Unknown stopout mode";
}
//---
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_MODE" |
//+------------------------------------------------------------------+
ENUM_ACCOUNT_MARGIN_MODE CAccountInfo::MarginMode(void) const
{
return((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_MODE" as string |
//+------------------------------------------------------------------+
string CAccountInfo::MarginModeDescription(void) const
{
string str;
//---
switch(MarginMode())
{
case ACCOUNT_MARGIN_MODE_RETAIL_NETTING:
str="Netting";
break;
case ACCOUNT_MARGIN_MODE_EXCHANGE:
str="Exchange";
break;
case ACCOUNT_MARGIN_MODE_RETAIL_HEDGING:
str="Hedging";
break;
default:
str="Unknown margin mode";
}
//---
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_TRADE_ALLOWED" |
//+------------------------------------------------------------------+
bool CAccountInfo::TradeAllowed(void) const
{
return((bool)AccountInfoInteger(ACCOUNT_TRADE_ALLOWED));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_TRADE_EXPERT" |
//+------------------------------------------------------------------+
bool CAccountInfo::TradeExpert(void) const
{
return((bool)AccountInfoInteger(ACCOUNT_TRADE_EXPERT));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_LIMIT_ORDERS" |
//+------------------------------------------------------------------+
int CAccountInfo::LimitOrders(void) const
{
return((int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_BALANCE" |
//+------------------------------------------------------------------+
double CAccountInfo::Balance(void) const
{
return(AccountInfoDouble(ACCOUNT_BALANCE));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_CREDIT" |
//+------------------------------------------------------------------+
double CAccountInfo::Credit(void) const
{
return(AccountInfoDouble(ACCOUNT_CREDIT));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_PROFIT" |
//+------------------------------------------------------------------+
double CAccountInfo::Profit(void) const
{
return(AccountInfoDouble(ACCOUNT_PROFIT));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_EQUITY" |
//+------------------------------------------------------------------+
double CAccountInfo::Equity(void) const
{
return(AccountInfoDouble(ACCOUNT_EQUITY));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN" |
//+------------------------------------------------------------------+
double CAccountInfo::Margin(void) const
{
return(AccountInfoDouble(ACCOUNT_MARGIN));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_FREE" |
//+------------------------------------------------------------------+
double CAccountInfo::FreeMargin(void) const
{
return(AccountInfoDouble(ACCOUNT_MARGIN_FREE));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_LEVEL" |
//+------------------------------------------------------------------+
double CAccountInfo::MarginLevel(void) const
{
return(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_SO_CALL" |
//+------------------------------------------------------------------+
double CAccountInfo::MarginCall(void) const
{
return(AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_MARGIN_SO_SO" |
//+------------------------------------------------------------------+
double CAccountInfo::MarginStopOut(void) const
{
return(AccountInfoDouble(ACCOUNT_MARGIN_SO_SO));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_NAME" |
//+------------------------------------------------------------------+
string CAccountInfo::Name(void) const
{
return(AccountInfoString(ACCOUNT_NAME));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_SERVER" |
//+------------------------------------------------------------------+
string CAccountInfo::Server(void) const
{
return(AccountInfoString(ACCOUNT_SERVER));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_CURRENCY" |
//+------------------------------------------------------------------+
string CAccountInfo::Currency(void) const
{
return(AccountInfoString(ACCOUNT_CURRENCY));
}
//+------------------------------------------------------------------+
//| Get the property value "ACCOUNT_COMPANY" |
//+------------------------------------------------------------------+
string CAccountInfo::Company(void) const
{
return(AccountInfoString(ACCOUNT_COMPANY));
}
//+------------------------------------------------------------------+
//| Access functions AccountInfoInteger(...) |
//+------------------------------------------------------------------+
long CAccountInfo::InfoInteger(const ENUM_ACCOUNT_INFO_INTEGER prop_id) const
{
return(AccountInfoInteger(prop_id));
}
//+------------------------------------------------------------------+
//| Access functions AccountInfoDouble(...) |
//+------------------------------------------------------------------+
double CAccountInfo::InfoDouble(const ENUM_ACCOUNT_INFO_DOUBLE prop_id) const
{
return(AccountInfoDouble(prop_id));
}
//+------------------------------------------------------------------+
//| Access functions AccountInfoString(...) |
//+------------------------------------------------------------------+
string CAccountInfo::InfoString(const ENUM_ACCOUNT_INFO_STRING prop_id) const
{
return(AccountInfoString(prop_id));
}
//+------------------------------------------------------------------+
//| Access functions OrderCalcProfit(...). |
//| INPUT: name - symbol name, |
//| trade_operation - trade operation, |
//| volume - volume of the opening position, |
//| price_open - price of the opening position, |
//| price_close - price of the closing position. |
//+------------------------------------------------------------------+
double CAccountInfo::OrderProfitCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double volume,const double price_open,const double price_close) const
{
double profit=EMPTY_VALUE;
//---
if(!OrderCalcProfit(trade_operation,symbol,volume,price_open,price_close,profit))
return(EMPTY_VALUE);
//---
return(profit);
}
//+------------------------------------------------------------------+
//| Access functions OrderCalcMargin(...). |
//| INPUT: name - symbol name, |
//| trade_operation - trade operation, |
//| volume - volume of the opening position, |
//| price - price of the opening position. |
//+------------------------------------------------------------------+
double CAccountInfo::MarginCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double volume,const double price) const
{
double margin=EMPTY_VALUE;
//---
if(!OrderCalcMargin(trade_operation,symbol,volume,price,margin))
return(EMPTY_VALUE);
//---
return(margin);
}
//+------------------------------------------------------------------+
//| Access functions OrderCalcMargin(...). |
//| INPUT: name - symbol name, |
//| trade_operation - trade operation, |
//| volume - volume of the opening position, |
//| price - price of the opening position. |
//+------------------------------------------------------------------+
double CAccountInfo::FreeMarginCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double volume,const double price) const
{
return(FreeMargin()-MarginCheck(symbol,trade_operation,volume,price));
}
//+------------------------------------------------------------------+
//| Access functions OrderCalcMargin(...). |
//| INPUT: name - symbol name, |
//| trade_operation - trade operation, |
//| price - price of the opening position, |
//| percent - percent of available margin [1-100%]. |
//+------------------------------------------------------------------+
double CAccountInfo::MaxLotCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation,
const double price,const double percent) const
{
double margin=0.0;
//--- checks
if(symbol=="" || price<=0.0 || percent<1 || percent>100)
{
Print("CAccountInfo::MaxLotCheck invalid parameters");
return(0.0);
}
//--- calculate margin requirements for 1 lot
if(!OrderCalcMargin(trade_operation,symbol,1.0,price,margin) || margin<0.0)
{
Print("CAccountInfo::MaxLotCheck margin calculation failed");
return(0.0);
}
//---
if(margin==0.0) // for pending orders
return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX));
//--- calculate maximum volume
double volume=NormalizeDouble(FreeMargin()*percent/100.0/margin,2);
//--- normalize and check limits
double stepvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP);
if(stepvol>0.0)
volume=stepvol*MathFloor(volume/stepvol);
//---
double minvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
if(volume<minvol)
volume=0.0;
//---
double maxvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
if(volume>maxvol)
volume=maxvol;
//--- return volume
return(volume);
}
//+------------------------------------------------------------------+
+430
View File
@@ -0,0 +1,430 @@
//+------------------------------------------------------------------+
//| DealInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CDealInfo. |
//| Appointment: Class for access to history deal info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class CDealInfo : public CObject
{
protected:
ulong m_ticket; // ticket of history order
public:
CDealInfo(void);
~CDealInfo(void);
//--- methods of access to protected data
void Ticket(const ulong ticket) { m_ticket=ticket; }
ulong Ticket(void) const { return(m_ticket); }
//--- fast access methods to the integer position propertyes
long Order(void) const;
datetime Time(void) const;
ulong TimeMsc(void) const;
ENUM_DEAL_TYPE DealType(void) const;
string TypeDescription(void) const;
ENUM_DEAL_ENTRY Entry(void) const;
string EntryDescription(void) const;
long Magic(void) const;
long PositionId(void) const;
//--- fast access methods to the double position propertyes
double Volume(void) const;
double Price(void) const;
double Commission(void) const;
double Swap(void) const;
double Profit(void) const;
//--- fast access methods to the string position propertyes
string Symbol(void) const;
string Comment(void) const;
string ExternalId(void) const;
//--- access methods to the API MQL5 functions
bool InfoInteger(ENUM_DEAL_PROPERTY_INTEGER prop_id,long &var) const;
bool InfoDouble(ENUM_DEAL_PROPERTY_DOUBLE prop_id,double &var) const;
bool InfoString(ENUM_DEAL_PROPERTY_STRING prop_id,string &var) const;
//--- info methods
string FormatAction(string &str,const uint action) const;
string FormatEntry(string &str,const uint entry) const;
string FormatDeal(string &str) const;
//--- method for select deal
bool SelectByIndex(const int index);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CDealInfo::CDealInfo(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CDealInfo::~CDealInfo(void)
{
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_ORDER" |
//+------------------------------------------------------------------+
long CDealInfo::Order(void) const
{
return(HistoryDealGetInteger(m_ticket,DEAL_ORDER));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_TIME" |
//+------------------------------------------------------------------+
datetime CDealInfo::Time(void) const
{
return((datetime)HistoryDealGetInteger(m_ticket,DEAL_TIME));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_TIME_MSC" |
//+------------------------------------------------------------------+
ulong CDealInfo::TimeMsc(void) const
{
return(HistoryDealGetInteger(m_ticket,DEAL_TIME_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_TYPE" |
//+------------------------------------------------------------------+
ENUM_DEAL_TYPE CDealInfo::DealType(void) const
{
return((ENUM_DEAL_TYPE)HistoryDealGetInteger(m_ticket,DEAL_TYPE));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_TYPE" as string |
//+------------------------------------------------------------------+
string CDealInfo::TypeDescription(void) const
{
string str;
//---
switch(DealType())
{
case DEAL_TYPE_BUY:
str="Buy type";
break;
case DEAL_TYPE_SELL:
str="Sell type";
break;
case DEAL_TYPE_BALANCE:
str="Balance type";
break;
case DEAL_TYPE_CREDIT:
str="Credit type";
break;
case DEAL_TYPE_CHARGE:
str="Charge type";
break;
case DEAL_TYPE_CORRECTION:
str="Correction type";
break;
case DEAL_TYPE_BONUS:
str="Bonus type";
break;
case DEAL_TYPE_COMMISSION:
str="Commission type";
break;
case DEAL_TYPE_COMMISSION_DAILY:
str="Daily Commission type";
break;
case DEAL_TYPE_COMMISSION_MONTHLY:
str="Monthly Commission type";
break;
case DEAL_TYPE_COMMISSION_AGENT_DAILY:
str="Daily Agent Commission type";
break;
case DEAL_TYPE_COMMISSION_AGENT_MONTHLY:
str="Monthly Agent Commission type";
break;
case DEAL_TYPE_INTEREST:
str="Interest Rate type";
break;
case DEAL_TYPE_BUY_CANCELED:
str="Canceled Buy type";
break;
case DEAL_TYPE_SELL_CANCELED:
str="Canceled Sell type";
break;
default:
str="Unknown type";
}
//---
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_ENTRY" |
//+------------------------------------------------------------------+
ENUM_DEAL_ENTRY CDealInfo::Entry(void) const
{
return((ENUM_DEAL_ENTRY)HistoryDealGetInteger(m_ticket,DEAL_ENTRY));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_ENTRY" as string |
//+------------------------------------------------------------------+
string CDealInfo::EntryDescription(void) const
{
string str;
//---
switch(CDealInfo::Entry())
{
case DEAL_ENTRY_IN:
str="In entry";
break;
case DEAL_ENTRY_OUT:
str="Out entry";
break;
case DEAL_ENTRY_INOUT:
str="InOut entry";
break;
case DEAL_ENTRY_STATE:
str="Status record";
break;
case DEAL_ENTRY_OUT_BY:
str="Out By entry";
break;
default:
str="Unknown entry";
}
//---
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_MAGIC" |
//+------------------------------------------------------------------+
long CDealInfo::Magic(void) const
{
return(HistoryDealGetInteger(m_ticket,DEAL_MAGIC));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_POSITION_ID" |
//+------------------------------------------------------------------+
long CDealInfo::PositionId(void) const
{
return(HistoryDealGetInteger(m_ticket,DEAL_POSITION_ID));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_VOLUME" |
//+------------------------------------------------------------------+
double CDealInfo::Volume(void) const
{
return(HistoryDealGetDouble(m_ticket,DEAL_VOLUME));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_PRICE_OPEN" |
//+------------------------------------------------------------------+
double CDealInfo::Price(void) const
{
return(HistoryDealGetDouble(m_ticket,DEAL_PRICE));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_COMMISSION" |
//+------------------------------------------------------------------+
double CDealInfo::Commission(void) const
{
return(HistoryDealGetDouble(m_ticket,DEAL_COMMISSION));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_SWAP" |
//+------------------------------------------------------------------+
double CDealInfo::Swap(void) const
{
return(HistoryDealGetDouble(m_ticket,DEAL_SWAP));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_PROFIT" |
//+------------------------------------------------------------------+
double CDealInfo::Profit(void) const
{
return(HistoryDealGetDouble(m_ticket,DEAL_PROFIT));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_SYMBOL" |
//+------------------------------------------------------------------+
string CDealInfo::Symbol(void) const
{
return(HistoryDealGetString(m_ticket,DEAL_SYMBOL));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_COMMENT" |
//+------------------------------------------------------------------+
string CDealInfo::Comment(void) const
{
return(HistoryDealGetString(m_ticket,DEAL_COMMENT));
}
//+------------------------------------------------------------------+
//| Get the property value "DEAL_EXTERNAL_ID" |
//+------------------------------------------------------------------+
string CDealInfo::ExternalId(void) const
{
return(HistoryDealGetString(m_ticket,DEAL_EXTERNAL_ID));
}
//+------------------------------------------------------------------+
//| Access functions HistoryDealGetInteger(...) |
//+------------------------------------------------------------------+
bool CDealInfo::InfoInteger(ENUM_DEAL_PROPERTY_INTEGER prop_id,long &var) const
{
return(HistoryDealGetInteger(m_ticket,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions HistoryDealGetDouble(...) |
//+------------------------------------------------------------------+
bool CDealInfo::InfoDouble(ENUM_DEAL_PROPERTY_DOUBLE prop_id,double &var) const
{
return(HistoryDealGetDouble(m_ticket,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions HistoryDealGetString(...) |
//+------------------------------------------------------------------+
bool CDealInfo::InfoString(ENUM_DEAL_PROPERTY_STRING prop_id,string &var) const
{
return(HistoryDealGetString(m_ticket,prop_id,var));
}
//+------------------------------------------------------------------+
//| Converths the type of a deal to text |
//+------------------------------------------------------------------+
string CDealInfo::FormatAction(string &str,const uint action) const
{
//--- see the type
switch(action)
{
case DEAL_TYPE_BUY:
str="buy";
break;
case DEAL_TYPE_SELL:
str="sell";
break;
case DEAL_TYPE_BALANCE:
str="balance";
break;
case DEAL_TYPE_CREDIT:
str="credit";
break;
case DEAL_TYPE_CHARGE:
str="charge";
break;
case DEAL_TYPE_CORRECTION:
str="correction";
break;
case DEAL_TYPE_BONUS:
str="bonus";
break;
case DEAL_TYPE_COMMISSION:
str="commission";
break;
case DEAL_TYPE_COMMISSION_DAILY:
str="daily commission";
break;
case DEAL_TYPE_COMMISSION_MONTHLY:
str="monthly commission";
break;
case DEAL_TYPE_COMMISSION_AGENT_DAILY:
str="daily agent commission";
break;
case DEAL_TYPE_COMMISSION_AGENT_MONTHLY:
str="monthly agent commission";
break;
case DEAL_TYPE_INTEREST:
str="interest rate";
break;
case DEAL_TYPE_BUY_CANCELED:
str="canceled buy";
break;
case DEAL_TYPE_SELL_CANCELED:
str="canceled sell";
break;
default:
str="unknown deal type "+(string)action;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the deal direction to text |
//+------------------------------------------------------------------+
string CDealInfo::FormatEntry(string &str,const uint entry) const
{
//--- see the type
switch(entry)
{
case DEAL_ENTRY_IN:
str="in";
break;
case DEAL_ENTRY_OUT:
str="out";
break;
case DEAL_ENTRY_INOUT:
str="in/out";
break;
case DEAL_ENTRY_OUT_BY:
str="out by";
break;
default:
str="unknown deal entry "+(string)entry;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the deal parameters to text |
//+------------------------------------------------------------------+
string CDealInfo::FormatDeal(string &str) const
{
string type;
long tmp_long;
//--- set up
string symbol_name=this.Symbol();
int digits=_Digits;
if(SymbolInfoInteger(symbol_name,SYMBOL_DIGITS,tmp_long))
digits=(int)tmp_long;
//--- form the description of the deal
switch(DealType())
{
//--- Buy-Sell
case DEAL_TYPE_BUY:
case DEAL_TYPE_SELL:
str=StringFormat("#%I64u %s %s %s at %s",
Ticket(),
FormatAction(type,DealType()),
DoubleToString(Volume(),2),
symbol_name,
DoubleToString(Price(),digits));
break;
//--- balance operations
case DEAL_TYPE_BALANCE:
case DEAL_TYPE_CREDIT:
case DEAL_TYPE_CHARGE:
case DEAL_TYPE_CORRECTION:
case DEAL_TYPE_BONUS:
case DEAL_TYPE_COMMISSION:
case DEAL_TYPE_COMMISSION_DAILY:
case DEAL_TYPE_COMMISSION_MONTHLY:
case DEAL_TYPE_COMMISSION_AGENT_DAILY:
case DEAL_TYPE_COMMISSION_AGENT_MONTHLY:
case DEAL_TYPE_INTEREST:
str=StringFormat("#%I64u %s %s [%s]",
Ticket(),
FormatAction(type,DealType()),
DoubleToString(Profit(),2),
this.Comment());
break;
default:
str="unknown deal type "+(string)DealType();
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Select a deal on the index |
//+------------------------------------------------------------------+
bool CDealInfo::SelectByIndex(const int index)
{
ulong ticket=HistoryDealGetTicket(index);
if(ticket==0)
return(false);
Ticket(ticket);
//---
return(true);
}
//+------------------------------------------------------------------+
+472
View File
@@ -0,0 +1,472 @@
//+------------------------------------------------------------------+
//| HistoryOrderInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CHistoryOrderInfo. |
//| Appointment: Class for access to history order info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class CHistoryOrderInfo : public CObject
{
protected:
ulong m_ticket; // ticket of history order
public:
CHistoryOrderInfo(void);
~CHistoryOrderInfo(void);
//--- methods of access to protected data
void Ticket(const ulong ticket) { m_ticket=ticket; }
ulong Ticket(void) const { return(m_ticket); }
//--- fast access methods to the integer order propertyes
datetime TimeSetup(void) const;
ulong TimeSetupMsc(void) const;
datetime TimeDone(void) const;
ulong TimeDoneMsc(void) const;
ENUM_ORDER_TYPE OrderType(void) const;
string TypeDescription(void) const;
ENUM_ORDER_STATE State(void) const;
string StateDescription(void) const;
datetime TimeExpiration(void) const;
ENUM_ORDER_TYPE_FILLING TypeFilling(void) const;
string TypeFillingDescription(void) const;
ENUM_ORDER_TYPE_TIME TypeTime(void) const;
string TypeTimeDescription(void) const;
long Magic(void) const;
long PositionId(void) const;
long PositionById(void) const;
//--- fast access methods to the double order propertyes
double VolumeInitial(void) const;
double VolumeCurrent(void) const;
double PriceOpen(void) const;
double StopLoss(void) const;
double TakeProfit(void) const;
double PriceCurrent(void) const;
double PriceStopLimit(void) const;
//--- fast access methods to the string order propertyes
string Symbol(void) const;
string Comment(void) const;
string ExternalId(void) const;
//--- access methods to the API MQL5 functions
bool InfoInteger(const ENUM_ORDER_PROPERTY_INTEGER prop_id,long &var) const;
bool InfoDouble(const ENUM_ORDER_PROPERTY_DOUBLE prop_id,double &var) const;
bool InfoString(const ENUM_ORDER_PROPERTY_STRING prop_id,string &var) const;
//--- info methods
string FormatType(string &str,const uint type) const;
string FormatStatus(string &str,const uint status) const;
string FormatTypeFilling(string &str,const uint type) const;
string FormatTypeTime(string &str,const uint type) const;
string FormatOrder(string &str) const;
string FormatPrice(string &str,const double price_order,const double price_trigger,const uint digits) const;
//--- method for select history order
bool SelectByIndex(const int index);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CHistoryOrderInfo::CHistoryOrderInfo(void) : m_ticket(0)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CHistoryOrderInfo::~CHistoryOrderInfo(void)
{
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_SETUP" |
//+------------------------------------------------------------------+
datetime CHistoryOrderInfo::TimeSetup(void) const
{
return((datetime)HistoryOrderGetInteger(m_ticket,ORDER_TIME_SETUP));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_SETUP_MSC" |
//+------------------------------------------------------------------+
ulong CHistoryOrderInfo::TimeSetupMsc(void) const
{
return(HistoryOrderGetInteger(m_ticket,ORDER_TIME_SETUP_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_DONE" |
//+------------------------------------------------------------------+
datetime CHistoryOrderInfo::TimeDone(void) const
{
return((datetime)HistoryOrderGetInteger(m_ticket,ORDER_TIME_DONE));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_DONE_MSC" |
//+------------------------------------------------------------------+
ulong CHistoryOrderInfo::TimeDoneMsc(void) const
{
return(HistoryOrderGetInteger(m_ticket,ORDER_TIME_DONE_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE" |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE CHistoryOrderInfo::OrderType(void) const
{
return((ENUM_ORDER_TYPE)HistoryOrderGetInteger(m_ticket,ORDER_TYPE));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE" as string |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::TypeDescription(void) const
{
string str;
//---
return(FormatType(str,OrderType()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_STATE" |
//+------------------------------------------------------------------+
ENUM_ORDER_STATE CHistoryOrderInfo::State(void) const
{
return((ENUM_ORDER_STATE)HistoryOrderGetInteger(m_ticket,ORDER_STATE));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_STATE" as string |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::StateDescription(void) const
{
string str;
//---
return(FormatStatus(str,State()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_EXPIRATION" |
//+------------------------------------------------------------------+
datetime CHistoryOrderInfo::TimeExpiration(void) const
{
return((datetime)HistoryOrderGetInteger(m_ticket,ORDER_TIME_EXPIRATION));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_FILLING" |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_FILLING CHistoryOrderInfo::TypeFilling(void) const
{
return((ENUM_ORDER_TYPE_FILLING)HistoryOrderGetInteger(m_ticket,ORDER_TYPE_FILLING));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_FILLING" as string |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::TypeFillingDescription(void) const
{
string str;
//---
return(FormatTypeFilling(str,TypeFilling()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_TIME" |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_TIME CHistoryOrderInfo::TypeTime(void) const
{
return((ENUM_ORDER_TYPE_TIME)HistoryOrderGetInteger(m_ticket,ORDER_TYPE_TIME));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_TIME" as string |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::TypeTimeDescription(void) const
{
string str;
//---
return(FormatTypeTime(str,TypeTime()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_EXPERT" |
//+------------------------------------------------------------------+
long CHistoryOrderInfo::Magic(void) const
{
return(HistoryOrderGetInteger(m_ticket,ORDER_MAGIC));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_POSITION_ID" |
//+------------------------------------------------------------------+
long CHistoryOrderInfo::PositionId(void) const
{
return(HistoryOrderGetInteger(m_ticket,ORDER_POSITION_ID));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_POSITION_BY_ID" |
//+------------------------------------------------------------------+
long CHistoryOrderInfo::PositionById(void) const
{
return(HistoryOrderGetInteger(m_ticket,ORDER_POSITION_BY_ID));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_VOLUME_INITIAL" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::VolumeInitial(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_VOLUME_INITIAL));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_VOLUME_CURRENT" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::VolumeCurrent(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_VOLUME_CURRENT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_PRICE_OPEN" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::PriceOpen(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_PRICE_OPEN));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_SL" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::StopLoss(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_SL));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TP" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::TakeProfit(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_TP));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_PRICE_CURRENT" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::PriceCurrent(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_PRICE_CURRENT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_PRICE_STOPLIMIT" |
//+------------------------------------------------------------------+
double CHistoryOrderInfo::PriceStopLimit(void) const
{
return(HistoryOrderGetDouble(m_ticket,ORDER_PRICE_STOPLIMIT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_SYMBOL" |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::Symbol(void) const
{
return(HistoryOrderGetString(m_ticket,ORDER_SYMBOL));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_COMMENT" |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::Comment(void) const
{
return(HistoryOrderGetString(m_ticket,ORDER_COMMENT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_EXTERNAL_ID" |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::ExternalId(void) const
{
return(HistoryOrderGetString(m_ticket,ORDER_EXTERNAL_ID));
}
//+------------------------------------------------------------------+
//| Access functions OrderGetInteger(...) |
//+------------------------------------------------------------------+
bool CHistoryOrderInfo::InfoInteger(const ENUM_ORDER_PROPERTY_INTEGER prop_id,long &var) const
{
return(HistoryOrderGetInteger(m_ticket,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions OrderGetDouble(...) |
//+------------------------------------------------------------------+
bool CHistoryOrderInfo::InfoDouble(const ENUM_ORDER_PROPERTY_DOUBLE prop_id,double &var) const
{
return(HistoryOrderGetDouble(m_ticket,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions OrderGetString(...) |
//+------------------------------------------------------------------+
bool CHistoryOrderInfo::InfoString(const ENUM_ORDER_PROPERTY_STRING prop_id,string &var) const
{
return(HistoryOrderGetString(m_ticket,prop_id,var));
}
//+------------------------------------------------------------------+
//| Converts the order type to text |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::FormatType(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case ORDER_TYPE_BUY:
str="buy";
break;
case ORDER_TYPE_SELL:
str="sell";
break;
case ORDER_TYPE_BUY_LIMIT:
str="buy limit";
break;
case ORDER_TYPE_SELL_LIMIT:
str="sell limit";
break;
case ORDER_TYPE_BUY_STOP:
str="buy stop";
break;
case ORDER_TYPE_SELL_STOP:
str="sell stop";
break;
case ORDER_TYPE_BUY_STOP_LIMIT:
str="buy stop limit";
break;
case ORDER_TYPE_SELL_STOP_LIMIT:
str="sell stop limit";
break;
case ORDER_TYPE_CLOSE_BY:
str="close by";
break;
default:
str="unknown order type "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order status to text |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::FormatStatus(string &str,const uint status) const
{
//--- see the type
switch(status)
{
case ORDER_STATE_STARTED:
str="started";
break;
case ORDER_STATE_PLACED:
str="placed";
break;
case ORDER_STATE_CANCELED:
str="canceled";
break;
case ORDER_STATE_PARTIAL:
str="partial";
break;
case ORDER_STATE_FILLED:
str="filled";
break;
case ORDER_STATE_REJECTED:
str="rejected";
break;
case ORDER_STATE_EXPIRED:
str="expired";
break;
default:
str="unknown order status "+(string)status;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order filling type to text |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::FormatTypeFilling(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case ORDER_FILLING_RETURN:
str="return remainder";
break;
case ORDER_FILLING_IOC:
str="cancel remainder";
break;
case ORDER_FILLING_FOK:
str="fill or kill";
break;
default:
str="unknown type filling "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the type of order by expiration to text |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::FormatTypeTime(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case ORDER_TIME_GTC:
str="gtc";
break;
case ORDER_TIME_DAY:
str="day";
break;
case ORDER_TIME_SPECIFIED:
str="specified";
break;
case ORDER_TIME_SPECIFIED_DAY:
str="specified day";
break;
default:
str="unknown type time "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order parameters to text |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::FormatOrder(string &str) const
{
string type,price;
long tmp_long;
//--- set up
string symbol_name=this.Symbol();
int digits=_Digits;
if(SymbolInfoInteger(symbol_name,SYMBOL_DIGITS,tmp_long))
digits=(int)tmp_long;
//--- form the order description
str=StringFormat("#%I64u %s %s %s",
Ticket(),
FormatType(type,OrderType()),
DoubleToString(VolumeInitial(),2),
symbol_name);
//--- receive the price of the order
FormatPrice(price,PriceOpen(),PriceStopLimit(),digits);
//--- if there is price, write it
if(price!="")
{
str+=" at ";
str+=price;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order prices to text |
//+------------------------------------------------------------------+
string CHistoryOrderInfo::FormatPrice(string &str,const double price_order,const double price_trigger,const uint digits) const
{
string price,trigger;
//--- Is there its trigger price?
if(price_trigger)
{
price =DoubleToString(price_order,digits);
trigger=DoubleToString(price_trigger,digits);
str =StringFormat("%s (%s)",price,trigger);
}
else
str=DoubleToString(price_order,digits);
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Select a history order on the index |
//+------------------------------------------------------------------+
bool CHistoryOrderInfo::SelectByIndex(const int index)
{
ulong ticket=HistoryOrderGetTicket(index);
if(ticket==0)
return(false);
Ticket(ticket);
//---
return(true);
}
//+------------------------------------------------------------------+
+553
View File
@@ -0,0 +1,553 @@
//+------------------------------------------------------------------+
//| OrderInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class COrderInfo. |
//| Appointment: Class for access to order info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class COrderInfo : public CObject
{
protected:
ulong m_ticket;
ENUM_ORDER_TYPE m_type;
ENUM_ORDER_STATE m_state;
datetime m_expiration;
double m_volume_curr;
double m_price_open;
double m_stop_loss;
double m_take_profit;
public:
COrderInfo(void);
~COrderInfo(void);
//--- methods of access to protected data
ulong Ticket(void) const { return(m_ticket); }
//--- fast access methods to the integer order propertyes
datetime TimeSetup(void) const;
ulong TimeSetupMsc(void) const;
datetime TimeDone(void) const;
ulong TimeDoneMsc(void) const;
ENUM_ORDER_TYPE OrderType(void) const;
string TypeDescription(void) const;
ENUM_ORDER_STATE State(void) const;
string StateDescription(void) const;
datetime TimeExpiration(void) const;
ENUM_ORDER_TYPE_FILLING TypeFilling(void) const;
string TypeFillingDescription(void) const;
ENUM_ORDER_TYPE_TIME TypeTime(void) const;
string TypeTimeDescription(void) const;
long Magic(void) const;
long PositionId(void) const;
long PositionById(void) const;
//--- fast access methods to the double order propertyes
double VolumeInitial(void) const;
double VolumeCurrent(void) const;
double PriceOpen(void) const;
double StopLoss(void) const;
double TakeProfit(void) const;
double PriceCurrent(void) const;
double PriceStopLimit(void) const;
//--- fast access methods to the string order propertyes
string Symbol(void) const;
string Comment(void) const;
string ExternalId(void) const;
//--- access methods to the API MQL5 functions
bool InfoInteger(const ENUM_ORDER_PROPERTY_INTEGER prop_id,long &var) const;
bool InfoDouble(const ENUM_ORDER_PROPERTY_DOUBLE prop_id,double &var) const;
bool InfoString(const ENUM_ORDER_PROPERTY_STRING prop_id,string &var) const;
//--- info methods
string FormatType(string &str,const uint type) const;
string FormatStatus(string &str,const uint status) const;
string FormatTypeFilling(string &str,const uint type) const;
string FormatTypeTime(string &str,const uint type) const;
string FormatOrder(string &str) const;
string FormatPrice(string &str,const double price_order,const double price_trigger,const uint digits) const;
//--- method for select order
bool Select(void);
bool Select(const ulong ticket);
bool SelectByIndex(const int index);
//--- additional methods
void StoreState(void);
bool CheckState(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
COrderInfo::COrderInfo(void) : m_ticket(ULONG_MAX),
m_type(WRONG_VALUE),
m_state(WRONG_VALUE),
m_expiration(0),
m_volume_curr(0.0),
m_price_open(0.0),
m_stop_loss(0.0),
m_take_profit(0.0)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
COrderInfo::~COrderInfo(void)
{
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_SETUP" |
//+------------------------------------------------------------------+
datetime COrderInfo::TimeSetup(void) const
{
return((datetime)OrderGetInteger(ORDER_TIME_SETUP));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_SETUP_MSC" |
//+------------------------------------------------------------------+
ulong COrderInfo::TimeSetupMsc(void) const
{
return(OrderGetInteger(ORDER_TIME_SETUP_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_DONE" |
//+------------------------------------------------------------------+
datetime COrderInfo::TimeDone(void) const
{
return((datetime)OrderGetInteger(ORDER_TIME_DONE));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_DONE_MSC" |
//+------------------------------------------------------------------+
ulong COrderInfo::TimeDoneMsc(void) const
{
return(OrderGetInteger(ORDER_TIME_DONE_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE" |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE COrderInfo::OrderType(void) const
{
return((ENUM_ORDER_TYPE)OrderGetInteger(ORDER_TYPE));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE" as string |
//+------------------------------------------------------------------+
string COrderInfo::TypeDescription(void) const
{
string str;
//---
return(FormatType(str,OrderType()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_STATE" |
//+------------------------------------------------------------------+
ENUM_ORDER_STATE COrderInfo::State(void) const
{
return((ENUM_ORDER_STATE)OrderGetInteger(ORDER_STATE));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_STATE" as string |
//+------------------------------------------------------------------+
string COrderInfo::StateDescription(void) const
{
string str;
//---
return(FormatStatus(str,State()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TIME_EXPIRATION" |
//+------------------------------------------------------------------+
datetime COrderInfo::TimeExpiration(void) const
{
return((datetime)OrderGetInteger(ORDER_TIME_EXPIRATION));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_FILLING" |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_FILLING COrderInfo::TypeFilling(void) const
{
return((ENUM_ORDER_TYPE_FILLING)OrderGetInteger(ORDER_TYPE_FILLING));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_FILLING" as string |
//+------------------------------------------------------------------+
string COrderInfo::TypeFillingDescription(void) const
{
string str;
//---
return(FormatTypeFilling(str,TypeFilling()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_TIME" |
//+------------------------------------------------------------------+
ENUM_ORDER_TYPE_TIME COrderInfo::TypeTime(void) const
{
return((ENUM_ORDER_TYPE_TIME)OrderGetInteger(ORDER_TYPE_TIME));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TYPE_TIME" as string |
//+------------------------------------------------------------------+
string COrderInfo::TypeTimeDescription(void) const
{
string str;
//---
return(FormatTypeTime(str,TypeFilling()));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_MAGIC" |
//+------------------------------------------------------------------+
long COrderInfo::Magic(void) const
{
return(OrderGetInteger(ORDER_MAGIC));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_POSITION_ID" |
//+------------------------------------------------------------------+
long COrderInfo::PositionId(void) const
{
return(OrderGetInteger(ORDER_POSITION_ID));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_POSITION_BY_ID" |
//+------------------------------------------------------------------+
long COrderInfo::PositionById(void) const
{
return(OrderGetInteger(ORDER_POSITION_BY_ID));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_VOLUME_INITIAL" |
//+------------------------------------------------------------------+
double COrderInfo::VolumeInitial(void) const
{
return(OrderGetDouble(ORDER_VOLUME_INITIAL));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_VOLUME_CURRENT" |
//+------------------------------------------------------------------+
double COrderInfo::VolumeCurrent(void) const
{
return(OrderGetDouble(ORDER_VOLUME_CURRENT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_PRICE_OPEN" |
//+------------------------------------------------------------------+
double COrderInfo::PriceOpen(void) const
{
return(OrderGetDouble(ORDER_PRICE_OPEN));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_SL" |
//+------------------------------------------------------------------+
double COrderInfo::StopLoss(void) const
{
return(OrderGetDouble(ORDER_SL));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_TP" |
//+------------------------------------------------------------------+
double COrderInfo::TakeProfit(void) const
{
return(OrderGetDouble(ORDER_TP));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_PRICE_CURRENT" |
//+------------------------------------------------------------------+
double COrderInfo::PriceCurrent(void) const
{
return(OrderGetDouble(ORDER_PRICE_CURRENT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_PRICE_STOPLIMIT" |
//+------------------------------------------------------------------+
double COrderInfo::PriceStopLimit(void) const
{
return(OrderGetDouble(ORDER_PRICE_STOPLIMIT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_SYMBOL" |
//+------------------------------------------------------------------+
string COrderInfo::Symbol(void) const
{
return(OrderGetString(ORDER_SYMBOL));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_COMMENT" |
//+------------------------------------------------------------------+
string COrderInfo::Comment(void) const
{
return(OrderGetString(ORDER_COMMENT));
}
//+------------------------------------------------------------------+
//| Get the property value "ORDER_EXTERNAL_ID" |
//+------------------------------------------------------------------+
string COrderInfo::ExternalId(void) const
{
return(OrderGetString(ORDER_EXTERNAL_ID));
}
//+------------------------------------------------------------------+
//| Access functions OrderGetInteger(...) |
//+------------------------------------------------------------------+
bool COrderInfo::InfoInteger(const ENUM_ORDER_PROPERTY_INTEGER prop_id,long &var) const
{
return(OrderGetInteger(prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions OrderGetDouble(...) |
//+------------------------------------------------------------------+
bool COrderInfo::InfoDouble(const ENUM_ORDER_PROPERTY_DOUBLE prop_id,double &var) const
{
return(OrderGetDouble(prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions OrderGetString(...) |
//+------------------------------------------------------------------+
bool COrderInfo::InfoString(const ENUM_ORDER_PROPERTY_STRING prop_id,string &var) const
{
return(OrderGetString(prop_id,var));
}
//+------------------------------------------------------------------+
//| Converts the order type to text |
//+------------------------------------------------------------------+
string COrderInfo::FormatType(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case ORDER_TYPE_BUY:
str="buy";
break;
case ORDER_TYPE_SELL:
str="sell";
break;
case ORDER_TYPE_BUY_LIMIT:
str="buy limit";
break;
case ORDER_TYPE_SELL_LIMIT:
str="sell limit";
break;
case ORDER_TYPE_BUY_STOP:
str="buy stop";
break;
case ORDER_TYPE_SELL_STOP:
str="sell stop";
break;
case ORDER_TYPE_BUY_STOP_LIMIT:
str="buy stop limit";
break;
case ORDER_TYPE_SELL_STOP_LIMIT:
str="sell stop limit";
break;
case ORDER_TYPE_CLOSE_BY:
str="close by";
break;
default :
str="unknown order type "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order status to text |
//+------------------------------------------------------------------+
string COrderInfo::FormatStatus(string &str,const uint status) const
{
//--- see the type
switch(status)
{
case ORDER_STATE_STARTED:
str="started";
break;
case ORDER_STATE_PLACED:
str="placed";
break;
case ORDER_STATE_CANCELED:
str="canceled";
break;
case ORDER_STATE_PARTIAL:
str="partial";
break;
case ORDER_STATE_FILLED:
str="filled";
break;
case ORDER_STATE_REJECTED:
str="rejected";
break;
case ORDER_STATE_EXPIRED:
str="expired";
break;
case ORDER_STATE_REQUEST_ADD:
str="request adding";
break;
case ORDER_STATE_REQUEST_MODIFY:
str="request modifying";
break;
case ORDER_STATE_REQUEST_CANCEL:
str="request cancelling";
break;
default :
str="unknown order status "+(string)status;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order filling type to text |
//+------------------------------------------------------------------+
string COrderInfo::FormatTypeFilling(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case ORDER_FILLING_RETURN:
str="return remainder";
break;
case ORDER_FILLING_IOC:
str="cancel remainder";
break;
case ORDER_FILLING_FOK:
str="fill or kill";
break;
default:
str="unknown type filling "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the type of order by expiration to text |
//+------------------------------------------------------------------+
string COrderInfo::FormatTypeTime(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case ORDER_TIME_GTC:
str="gtc";
break;
case ORDER_TIME_DAY:
str="day";
break;
case ORDER_TIME_SPECIFIED:
str="specified";
break;
case ORDER_TIME_SPECIFIED_DAY:
str="specified day";
break;
default:
str="unknown type time "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order parameters to text |
//+------------------------------------------------------------------+
string COrderInfo::FormatOrder(string &str) const
{
string type,price;
long tmp_long;
//--- set up
string symbol_name=this.Symbol();
int digits=_Digits;
if(SymbolInfoInteger(symbol_name,SYMBOL_DIGITS,tmp_long))
digits=(int)tmp_long;
//--- form the order description
str=StringFormat("#%I64u %s %s %s",
Ticket(),
FormatType(type,OrderType()),
DoubleToString(VolumeInitial(),2),
symbol_name);
//--- receive the price of the order
FormatPrice(price,PriceOpen(),PriceStopLimit(),digits);
//--- if there is price, write it
if(price!="")
{
str+=" at ";
str+=price;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the order prices to text |
//+------------------------------------------------------------------+
string COrderInfo::FormatPrice(string &str,const double price_order,const double price_trigger,const uint digits) const
{
string price,trigger;
//--- Is there its trigger price?
if(price_trigger)
{
price =DoubleToString(price_order,digits);
trigger=DoubleToString(price_trigger,digits);
str =StringFormat("%s (%s)",price,trigger);
}
else
str=DoubleToString(price_order,digits);
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Selecting an order to access |
//+------------------------------------------------------------------+
bool COrderInfo::Select(void)
{
return(OrderSelect(m_ticket));
}
//+------------------------------------------------------------------+
//| Selecting an order to access |
//+------------------------------------------------------------------+
bool COrderInfo::Select(const ulong ticket)
{
if(OrderSelect(ticket))
{
m_ticket=ticket;
return(true);
}
m_ticket=ULONG_MAX;
//---
return(false);
}
//+------------------------------------------------------------------+
//| Select an order by the index |
//+------------------------------------------------------------------+
bool COrderInfo::SelectByIndex(const int index)
{
ulong ticket=OrderGetTicket(index);
if(ticket==0)
{
m_ticket=ULONG_MAX;
return(false);
}
m_ticket=ticket;
//---
return(true);
}
//+------------------------------------------------------------------+
//| Stored order's current state |
//+------------------------------------------------------------------+
void COrderInfo::StoreState(void)
{
m_type =OrderType();
m_state =State();
m_expiration =TimeExpiration();
m_volume_curr=VolumeCurrent();
m_price_open =PriceOpen();
m_stop_loss =StopLoss();
m_take_profit=TakeProfit();
}
//+------------------------------------------------------------------+
//| Check order change |
//+------------------------------------------------------------------+
bool COrderInfo::CheckState(void)
{
if(m_type==OrderType() &&
m_state==State() &&
m_expiration==TimeExpiration() &&
m_volume_curr==VolumeCurrent() &&
m_price_open==PriceOpen() &&
m_stop_loss==StopLoss() &&
m_take_profit==TakeProfit())
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
+366
View File
@@ -0,0 +1,366 @@
//+------------------------------------------------------------------+
//| PositionInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CPositionInfo. |
//| Appointment: Class for access to position info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class CPositionInfo : public CObject
{
protected:
ENUM_POSITION_TYPE m_type;
double m_volume;
double m_price;
double m_stop_loss;
double m_take_profit;
public:
CPositionInfo(void);
~CPositionInfo(void);
//--- fast access methods to the integer position propertyes
ulong Ticket(void) const;
datetime Time(void) const;
ulong TimeMsc(void) const;
datetime TimeUpdate(void) const;
ulong TimeUpdateMsc(void) const;
ENUM_POSITION_TYPE PositionType(void) const;
string TypeDescription(void) const;
long Magic(void) const;
long Identifier(void) const;
//--- fast access methods to the double position propertyes
double Volume(void) const;
double PriceOpen(void) const;
double StopLoss(void) const;
double TakeProfit(void) const;
double PriceCurrent(void) const;
double Commission(void) const;
double Swap(void) const;
double Profit(void) const;
//--- fast access methods to the string position propertyes
string Symbol(void) const;
string Comment(void) const;
//--- access methods to the API MQL5 functions
bool InfoInteger(const ENUM_POSITION_PROPERTY_INTEGER prop_id,long &var) const;
bool InfoDouble(const ENUM_POSITION_PROPERTY_DOUBLE prop_id,double &var) const;
bool InfoString(const ENUM_POSITION_PROPERTY_STRING prop_id,string &var) const;
//--- info methods
string FormatType(string &str,const uint type) const;
string FormatPosition(string &str) const;
//--- methods for select position
bool Select(const string symbol);
bool SelectByMagic(const string symbol,const ulong magic);
bool SelectByTicket(const ulong ticket);
bool SelectByIndex(const int index);
//---
void StoreState(void);
bool CheckState(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CPositionInfo::CPositionInfo(void) : m_type(WRONG_VALUE),
m_volume(0.0),
m_price(0.0),
m_stop_loss(0.0),
m_take_profit(0.0)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CPositionInfo::~CPositionInfo(void)
{
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TICKET" |
//+------------------------------------------------------------------+
ulong CPositionInfo::Ticket(void) const
{
return((ulong)PositionGetInteger(POSITION_TICKET));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TIME" |
//+------------------------------------------------------------------+
datetime CPositionInfo::Time(void) const
{
return((datetime)PositionGetInteger(POSITION_TIME));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TIME_MSC" |
//+------------------------------------------------------------------+
ulong CPositionInfo::TimeMsc(void) const
{
return((ulong)PositionGetInteger(POSITION_TIME_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TIME_UPDATE" |
//+------------------------------------------------------------------+
datetime CPositionInfo::TimeUpdate(void) const
{
return((datetime)PositionGetInteger(POSITION_TIME_UPDATE));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TIME_UPDATE_MSC" |
//+------------------------------------------------------------------+
ulong CPositionInfo::TimeUpdateMsc(void) const
{
return((ulong)PositionGetInteger(POSITION_TIME_UPDATE_MSC));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TYPE" |
//+------------------------------------------------------------------+
ENUM_POSITION_TYPE CPositionInfo::PositionType(void) const
{
return((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TYPE" as string |
//+------------------------------------------------------------------+
string CPositionInfo::TypeDescription(void) const
{
string str;
//---
return(FormatType(str,PositionType()));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_MAGIC" |
//+------------------------------------------------------------------+
long CPositionInfo::Magic(void) const
{
return(PositionGetInteger(POSITION_MAGIC));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_IDENTIFIER" |
//+------------------------------------------------------------------+
long CPositionInfo::Identifier(void) const
{
return(PositionGetInteger(POSITION_IDENTIFIER));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_VOLUME" |
//+------------------------------------------------------------------+
double CPositionInfo::Volume(void) const
{
return(PositionGetDouble(POSITION_VOLUME));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PRICE_OPEN" |
//+------------------------------------------------------------------+
double CPositionInfo::PriceOpen(void) const
{
return(PositionGetDouble(POSITION_PRICE_OPEN));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SL" |
//+------------------------------------------------------------------+
double CPositionInfo::StopLoss(void) const
{
return(PositionGetDouble(POSITION_SL));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_TP" |
//+------------------------------------------------------------------+
double CPositionInfo::TakeProfit(void) const
{
return(PositionGetDouble(POSITION_TP));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PRICE_CURRENT" |
//+------------------------------------------------------------------+
double CPositionInfo::PriceCurrent(void) const
{
return(PositionGetDouble(POSITION_PRICE_CURRENT));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_COMMISSION" |
//+------------------------------------------------------------------+
double CPositionInfo::Commission(void) const
{
//--- property POSITION_COMMISSION is deprecated
SetUserError(ERR_FUNCTION_NOT_ALLOWED);
return(0);
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SWAP" |
//+------------------------------------------------------------------+
double CPositionInfo::Swap(void) const
{
return(PositionGetDouble(POSITION_SWAP));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_PROFIT" |
//+------------------------------------------------------------------+
double CPositionInfo::Profit(void) const
{
return(PositionGetDouble(POSITION_PROFIT));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_SYMBOL" |
//+------------------------------------------------------------------+
string CPositionInfo::Symbol(void) const
{
return(PositionGetString(POSITION_SYMBOL));
}
//+------------------------------------------------------------------+
//| Get the property value "POSITION_COMMENT" |
//+------------------------------------------------------------------+
string CPositionInfo::Comment(void) const
{
return(PositionGetString(POSITION_COMMENT));
}
//+------------------------------------------------------------------+
//| Access functions PositionGetInteger(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::InfoInteger(const ENUM_POSITION_PROPERTY_INTEGER prop_id,long &var) const
{
return(PositionGetInteger(prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions PositionGetDouble(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::InfoDouble(const ENUM_POSITION_PROPERTY_DOUBLE prop_id,double &var) const
{
return(PositionGetDouble(prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions PositionGetString(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::InfoString(const ENUM_POSITION_PROPERTY_STRING prop_id,string &var) const
{
return(PositionGetString(prop_id,var));
}
//+------------------------------------------------------------------+
//| Converts the position type to text |
//+------------------------------------------------------------------+
string CPositionInfo::FormatType(string &str,const uint type) const
{
//--- see the type
switch(type)
{
case POSITION_TYPE_BUY:
str="buy";
break;
case POSITION_TYPE_SELL:
str="sell";
break;
default:
str="unknown position type "+(string)type;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Converts the position parameters to text |
//+------------------------------------------------------------------+
string CPositionInfo::FormatPosition(string &str) const
{
string tmp,type;
long tmp_long;
ENUM_ACCOUNT_MARGIN_MODE margin_mode=(ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);
//--- set up
string symbol_name=this.Symbol();
int digits=_Digits;
if(SymbolInfoInteger(symbol_name,SYMBOL_DIGITS,tmp_long))
digits=(int)tmp_long;
//--- form the position description
if(margin_mode==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING)
str=StringFormat("#%I64u %s %s %s %s",
Ticket(),
FormatType(type,PositionType()),
DoubleToString(Volume(),2),
symbol_name,
DoubleToString(PriceOpen(),digits+3));
else
str=StringFormat("%s %s %s %s",
FormatType(type,PositionType()),
DoubleToString(Volume(),2),
symbol_name,
DoubleToString(PriceOpen(),digits+3));
//--- add stops if there are any
double sl=StopLoss();
double tp=TakeProfit();
if(sl!=0.0)
{
tmp=StringFormat(" sl: %s",DoubleToString(sl,digits));
str+=tmp;
}
if(tp!=0.0)
{
tmp=StringFormat(" tp: %s",DoubleToString(tp,digits));
str+=tmp;
}
//--- return the result
return(str);
}
//+------------------------------------------------------------------+
//| Access functions PositionSelect(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::Select(const string symbol)
{
return(PositionSelect(symbol));
}
//+------------------------------------------------------------------+
//| Access functions PositionSelect(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::SelectByMagic(const string symbol,const ulong magic)
{
bool res=false;
uint total=PositionsTotal();
//---
for(uint i=0; i<total; i++)
{
string position_symbol=PositionGetSymbol(i);
if(position_symbol==symbol && magic==PositionGetInteger(POSITION_MAGIC))
{
res=true;
break;
}
}
//---
return(res);
}
//+------------------------------------------------------------------+
//| Access functions PositionSelectByTicket(...) |
//+------------------------------------------------------------------+
bool CPositionInfo::SelectByTicket(const ulong ticket)
{
return(PositionSelectByTicket(ticket));
}
//+------------------------------------------------------------------+
//| Select a position on the index |
//+------------------------------------------------------------------+
bool CPositionInfo::SelectByIndex(const int index)
{
ulong ticket=PositionGetTicket(index);
return(ticket>0);
}
//+------------------------------------------------------------------+
//| Stored position's current state |
//+------------------------------------------------------------------+
void CPositionInfo::StoreState(void)
{
m_type =PositionType();
m_volume =Volume();
m_price =PriceOpen();
m_stop_loss =StopLoss();
m_take_profit=TakeProfit();
}
//+------------------------------------------------------------------+
//| Check position change |
//+------------------------------------------------------------------+
bool CPositionInfo::CheckState(void)
{
if(m_type==PositionType() &&
m_volume==Volume() &&
m_price==PriceOpen() &&
m_stop_loss==StopLoss() &&
m_take_profit==TakeProfit())
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
+789
View File
@@ -0,0 +1,789 @@
//+------------------------------------------------------------------+
//| SymbolInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CSymbolInfo. |
//| Appointment: Class for access to symbol info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class CSymbolInfo : public CObject
{
protected:
string m_name; // symbol name
MqlTick m_tick; // structure of tick;
double m_point; // symbol point
double m_tick_value; // symbol tick value
double m_tick_value_profit; // symbol tick value profit
double m_tick_value_loss; // symbol tick value loss
double m_tick_size; // symbol tick size
double m_contract_size; // symbol contract size
double m_lots_min; // symbol lots min
double m_lots_max; // symbol lots max
double m_lots_step; // symbol lots step
double m_lots_limit; // symbol lots limit
double m_swap_long; // symbol swap long
double m_swap_short; // symbol swap short
int m_digits; // symbol digits
int m_order_mode; // symbol valid orders
ENUM_SYMBOL_TRADE_EXECUTION m_trade_execution; // symbol trade execution
ENUM_SYMBOL_CALC_MODE m_trade_calcmode; // symbol trade calcmode
ENUM_SYMBOL_TRADE_MODE m_trade_mode; // symbol trade mode
ENUM_SYMBOL_SWAP_MODE m_swap_mode; // symbol swap mode
ENUM_DAY_OF_WEEK m_swap3; // symbol swap3
double m_margin_initial; // symbol margin initial
double m_margin_maintenance; // symbol margin maintenance
bool m_margin_hedged_use_leg; // calculate hedged margin using larger leg
double m_margin_hedged; // symbol margin hedged
int m_trade_time_flags; // symbol trade time flags
int m_trade_fill_flags; // symbol trade fill flags
public:
CSymbolInfo(void);
~CSymbolInfo(void);
//--- methods of access to protected data
string Name(void) const { return(m_name); }
bool Name(const string name);
bool Refresh(void);
bool RefreshRates(void);
//--- fast access methods to the integer symbol propertyes
bool Select(void) const;
bool Select(const bool select);
bool IsSynchronized(void) const;
//--- volumes
ulong Volume(void) const { return(m_tick.volume); }
ulong VolumeHigh(void) const;
ulong VolumeLow(void) const;
//--- miscellaneous
datetime Time(void) const { return(m_tick.time); }
int Spread(void) const;
bool SpreadFloat(void) const;
int TicksBookDepth(void) const;
//--- trade levels
int StopsLevel(void) const;
int FreezeLevel(void) const;
//--- fast access methods to the double symbol propertyes
//--- bid parameters
double Bid(void) const { return(m_tick.bid); }
double BidHigh(void) const;
double BidLow(void) const;
//--- ask parameters
double Ask(void) const { return(m_tick.ask); }
double AskHigh(void) const;
double AskLow(void) const;
//--- last parameters
double Last(void) const { return(m_tick.last); }
double LastHigh(void) const;
double LastLow(void) const;
//--- fast access methods to the mix symbol propertyes
int OrderMode(void) const { return(m_order_mode); }
//--- terms of trade
ENUM_SYMBOL_CALC_MODE TradeCalcMode(void) const { return(m_trade_calcmode); }
string TradeCalcModeDescription(void) const;
ENUM_SYMBOL_TRADE_MODE TradeMode(void) const { return(m_trade_mode); }
string TradeModeDescription(void) const;
//--- execution terms of trade
ENUM_SYMBOL_TRADE_EXECUTION TradeExecution(void) const { return(m_trade_execution); }
string TradeExecutionDescription(void) const;
//--- swap terms of trade
ENUM_SYMBOL_SWAP_MODE SwapMode(void) const { return(m_swap_mode); }
string SwapModeDescription(void) const;
ENUM_DAY_OF_WEEK SwapRollover3days(void) const { return(m_swap3); }
string SwapRollover3daysDescription(void) const;
//--- dates for futures
datetime StartTime(void) const;
datetime ExpirationTime(void) const;
//--- margin parameters
double MarginInitial(void) const { return(m_margin_initial); }
double MarginMaintenance(void) const { return(m_margin_maintenance); }
bool MarginHedgedUseLeg(void) const { return(m_margin_hedged_use_leg); }
double MarginHedged(void) const { return(m_margin_hedged); }
//--- left for backward compatibility
double MarginLong(void) const { return(0.0); }
double MarginShort(void) const { return(0.0); }
double MarginLimit(void) const { return(0.0); }
double MarginStop(void) const { return(0.0); }
double MarginStopLimit(void) const { return(0.0); }
//--- trade flags parameters
int TradeTimeFlags(void) const { return(m_trade_time_flags); }
int TradeFillFlags(void) const { return(m_trade_fill_flags); }
//--- tick parameters
int Digits(void) const { return(m_digits); }
double Point(void) const { return(m_point); }
double TickValue(void) const { return(m_tick_value); }
double TickValueProfit(void) const { return(m_tick_value_profit); }
double TickValueLoss(void) const { return(m_tick_value_loss); }
double TickSize(void) const { return(m_tick_size); }
//--- lots parameters
double ContractSize(void) const { return(m_contract_size); }
double LotsMin(void) const { return(m_lots_min); }
double LotsMax(void) const { return(m_lots_max); }
double LotsStep(void) const { return(m_lots_step); }
double LotsLimit(void) const { return(m_lots_limit); }
//--- swaps
double SwapLong(void) const { return(m_swap_long); }
double SwapShort(void) const { return(m_swap_short); }
//--- fast access methods to the string symbol propertyes
string CurrencyBase(void) const;
string CurrencyProfit(void) const;
string CurrencyMargin(void) const;
string Bank(void) const;
string Description(void) const;
string Path(void) const;
//--- session information
long SessionDeals(void) const;
long SessionBuyOrders(void) const;
long SessionSellOrders(void) const;
double SessionTurnover(void) const;
double SessionInterest(void) const;
double SessionBuyOrdersVolume(void) const;
double SessionSellOrdersVolume(void) const;
double SessionOpen(void) const;
double SessionClose(void) const;
double SessionAW(void) const;
double SessionPriceSettlement(void) const;
double SessionPriceLimitMin(void) const;
double SessionPriceLimitMax(void) const;
//--- access methods to the API MQL5 functions
bool InfoInteger(const ENUM_SYMBOL_INFO_INTEGER prop_id,long& var) const;
bool InfoDouble(const ENUM_SYMBOL_INFO_DOUBLE prop_id,double& var) const;
bool InfoString(const ENUM_SYMBOL_INFO_STRING prop_id,string& var) const;
bool InfoMarginRate(const ENUM_ORDER_TYPE order_type,double& initial_margin_rate,double& maintenance_margin_rate) const;
//--- service methods
double NormalizePrice(const double price) const;
bool CheckMarketWatch(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CSymbolInfo::CSymbolInfo(void) : m_name(NULL),
m_point(0.0),
m_tick_value(0.0),
m_tick_value_profit(0.0),
m_tick_value_loss(0.0),
m_tick_size(0.0),
m_contract_size(0.0),
m_lots_min(0.0),
m_lots_max(0.0),
m_lots_step(0.0),
m_swap_long(0.0),
m_swap_short(0.0),
m_digits(0),
m_order_mode(0),
m_trade_execution(0),
m_trade_calcmode(0),
m_trade_mode(0),
m_swap_mode(0),
m_swap3(0),
m_margin_initial(0.0),
m_margin_maintenance(0.0),
m_margin_hedged_use_leg(false),
m_margin_hedged(0.0),
m_trade_time_flags(0),
m_trade_fill_flags(0)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CSymbolInfo::~CSymbolInfo(void)
{
}
//+------------------------------------------------------------------+
//| Set name |
//+------------------------------------------------------------------+
bool CSymbolInfo::Name(const string name)
{
string symbol_name=StringLen(name)>0 ? name : _Symbol;
//--- check previous set name
if(m_name!=symbol_name)
{
m_name=symbol_name;
//---
if(!CheckMarketWatch())
return(false);
//---
if(!Refresh())
{
m_name="";
Print(__FUNCTION__+": invalid data of symbol '"+symbol_name+"'");
return(false);
}
}
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Refresh cached data |
//+------------------------------------------------------------------+
bool CSymbolInfo::Refresh(void)
{
long tmp_long=0;
//---
if(!SymbolInfoDouble(m_name,SYMBOL_POINT,m_point))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_VALUE,m_tick_value))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_VALUE_PROFIT,m_tick_value_profit))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_VALUE_LOSS,m_tick_value_loss))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_SIZE,m_tick_size))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_CONTRACT_SIZE,m_contract_size))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_VOLUME_MIN,m_lots_min))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_VOLUME_MAX,m_lots_max))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_VOLUME_STEP,m_lots_step))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_VOLUME_LIMIT,m_lots_limit))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_SWAP_LONG,m_swap_long))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_SWAP_SHORT,m_swap_short))
return(false);
if(!SymbolInfoInteger(m_name,SYMBOL_DIGITS,tmp_long))
return(false);
m_digits=(int)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_ORDER_MODE,tmp_long))
return(false);
m_order_mode=(int)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_TRADE_EXEMODE,tmp_long))
return(false);
m_trade_execution=(ENUM_SYMBOL_TRADE_EXECUTION)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_TRADE_CALC_MODE,tmp_long))
return(false);
m_trade_calcmode=(ENUM_SYMBOL_CALC_MODE)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_TRADE_MODE,tmp_long))
return(false);
m_trade_mode=(ENUM_SYMBOL_TRADE_MODE)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_SWAP_MODE,tmp_long))
return(false);
m_swap_mode=(ENUM_SYMBOL_SWAP_MODE)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_SWAP_ROLLOVER3DAYS,tmp_long))
return(false);
m_swap3=(ENUM_DAY_OF_WEEK)tmp_long;
if(!SymbolInfoDouble(m_name,SYMBOL_MARGIN_INITIAL,m_margin_initial))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_MARGIN_MAINTENANCE,m_margin_maintenance))
return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_MARGIN_HEDGED,m_margin_hedged))
return(false);
if(!SymbolInfoInteger(m_name,SYMBOL_MARGIN_HEDGED_USE_LEG,tmp_long))
return(false);
m_margin_hedged_use_leg=(bool)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_EXPIRATION_MODE,tmp_long))
return(false);
m_trade_time_flags=(int)tmp_long;
if(!SymbolInfoInteger(m_name,SYMBOL_FILLING_MODE,tmp_long))
return(false);
m_trade_fill_flags=(int)tmp_long;
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
//| Refresh cached data |
//+------------------------------------------------------------------+
bool CSymbolInfo::RefreshRates(void)
{
return(SymbolInfoTick(m_name,m_tick));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SELECT" |
//+------------------------------------------------------------------+
bool CSymbolInfo::Select(void) const
{
return((bool)SymbolInfoInteger(m_name,SYMBOL_SELECT));
}
//+------------------------------------------------------------------+
//| Set the property value "SYMBOL_SELECT" |
//+------------------------------------------------------------------+
bool CSymbolInfo::Select(const bool select)
{
return(SymbolSelect(m_name,select));
}
//+------------------------------------------------------------------+
//| Check synchronize symbol |
//+------------------------------------------------------------------+
bool CSymbolInfo::IsSynchronized(void) const
{
return(SymbolIsSynchronized(m_name));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_VOLUMEHIGH" |
//+------------------------------------------------------------------+
ulong CSymbolInfo::VolumeHigh(void) const
{
return(SymbolInfoInteger(m_name,SYMBOL_VOLUMEHIGH));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_VOLUMELOW" |
//+------------------------------------------------------------------+
ulong CSymbolInfo::VolumeLow(void) const
{
return(SymbolInfoInteger(m_name,SYMBOL_VOLUMELOW));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SPREAD" |
//+------------------------------------------------------------------+
int CSymbolInfo::Spread(void) const
{
return((int)SymbolInfoInteger(m_name,SYMBOL_SPREAD));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SPREAD_FLOAT" |
//+------------------------------------------------------------------+
bool CSymbolInfo::SpreadFloat(void) const
{
return((bool)SymbolInfoInteger(m_name,SYMBOL_SPREAD_FLOAT));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_TICKS_BOOKDEPTH" |
//+------------------------------------------------------------------+
int CSymbolInfo::TicksBookDepth(void) const
{
return((int)SymbolInfoInteger(m_name,SYMBOL_TICKS_BOOKDEPTH));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_TRADE_STOPS_LEVEL" |
//+------------------------------------------------------------------+
int CSymbolInfo::StopsLevel(void) const
{
return((int)SymbolInfoInteger(m_name,SYMBOL_TRADE_STOPS_LEVEL));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_TRADE_FREEZE_LEVEL" |
//+------------------------------------------------------------------+
int CSymbolInfo::FreezeLevel(void) const
{
return((int)SymbolInfoInteger(m_name,SYMBOL_TRADE_FREEZE_LEVEL));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_BIDHIGH" |
//+------------------------------------------------------------------+
double CSymbolInfo::BidHigh(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_BIDHIGH));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_BIDLOW" |
//+------------------------------------------------------------------+
double CSymbolInfo::BidLow(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_BIDLOW));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_ASKHIGH" |
//+------------------------------------------------------------------+
double CSymbolInfo::AskHigh(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_ASKHIGH));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_ASKLOW" |
//+------------------------------------------------------------------+
double CSymbolInfo::AskLow(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_ASKLOW));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_LASTHIGH" |
//+------------------------------------------------------------------+
double CSymbolInfo::LastHigh(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_LASTHIGH));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_LASTLOW" |
//+------------------------------------------------------------------+
double CSymbolInfo::LastLow(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_LASTLOW));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_TRADE_CALC_MODE" as string |
//+------------------------------------------------------------------+
string CSymbolInfo::TradeCalcModeDescription(void) const
{
string str;
//---
switch(m_trade_calcmode)
{
case SYMBOL_CALC_MODE_FOREX:
str="Calculation of profit and margin for Forex";
break;
case SYMBOL_CALC_MODE_CFD:
str="Calculation of collateral and earnings for CFD";
break;
case SYMBOL_CALC_MODE_FUTURES:
str="Calculation of collateral and profits for futures";
break;
case SYMBOL_CALC_MODE_CFDINDEX:
str="Calculation of collateral and earnings for CFD on indices";
break;
case SYMBOL_CALC_MODE_CFDLEVERAGE:
str="Calculation of collateral and earnings for the CFD when trading with leverage";
break;
case SYMBOL_CALC_MODE_EXCH_STOCKS:
str="Calculation for exchange stocks";
break;
case SYMBOL_CALC_MODE_EXCH_FUTURES:
str="Calculation for exchange futures";
break;
case SYMBOL_CALC_MODE_EXCH_FUTURES_FORTS:
str="Calculation for FORTS futures";
break;
default:
str="Unknown calculation mode";
}
//--- result
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_TRADE_MODE" as string |
//+------------------------------------------------------------------+
string CSymbolInfo::TradeModeDescription(void) const
{
string str;
//---
switch(m_trade_mode)
{
case SYMBOL_TRADE_MODE_DISABLED:
str="Disabled";
break;
case SYMBOL_TRADE_MODE_LONGONLY:
str="Long only";
break;
case SYMBOL_TRADE_MODE_SHORTONLY:
str="Short only";
break;
case SYMBOL_TRADE_MODE_CLOSEONLY:
str="Close only";
break;
case SYMBOL_TRADE_MODE_FULL:
str="Full access";
break;
default:
str="Unknown trade mode";
}
//--- result
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_TRADE_EXEMODE" as string |
//+------------------------------------------------------------------+
string CSymbolInfo::TradeExecutionDescription(void) const
{
string str;
//---
switch(m_trade_execution)
{
case SYMBOL_TRADE_EXECUTION_REQUEST:
str="Trading on request";
break;
case SYMBOL_TRADE_EXECUTION_INSTANT:
str="Trading on live streaming prices";
break;
case SYMBOL_TRADE_EXECUTION_MARKET:
str="Execution of orders on the market";
break;
case SYMBOL_TRADE_EXECUTION_EXCHANGE:
str="Exchange execution";
break;
default:
str="Unknown trade execution";
}
//--- result
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SWAP_MODE" as string |
//+------------------------------------------------------------------+
string CSymbolInfo::SwapModeDescription(void) const
{
string str;
//---
switch(m_swap_mode)
{
case SYMBOL_SWAP_MODE_DISABLED:
str="No swaps";
break;
case SYMBOL_SWAP_MODE_POINTS:
str="Swaps are calculated in points";
break;
case SYMBOL_SWAP_MODE_CURRENCY_SYMBOL:
str="Swaps are calculated in base currency";
break;
case SYMBOL_SWAP_MODE_CURRENCY_MARGIN:
str="Swaps are calculated in margin currency";
break;
case SYMBOL_SWAP_MODE_CURRENCY_DEPOSIT:
str="Swaps are calculated in deposit currency";
break;
case SYMBOL_SWAP_MODE_INTEREST_CURRENT:
str="Swaps are calculated as annual interest using the current price";
break;
case SYMBOL_SWAP_MODE_INTEREST_OPEN:
str="Swaps are calculated as annual interest using the open price";
break;
case SYMBOL_SWAP_MODE_REOPEN_CURRENT:
str="Swaps are charged by reopening positions at the close price";
break;
case SYMBOL_SWAP_MODE_REOPEN_BID:
str="Swaps are charged by reopening positions at the Bid price";
break;
default:
str="Unknown swap mode";
}
//--- result
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SWAP_ROLLOVER3DAYS" as string |
//+------------------------------------------------------------------+
string CSymbolInfo::SwapRollover3daysDescription(void) const
{
string str;
//---
switch(m_swap3)
{
case SUNDAY:
str="Sunday";
break;
case MONDAY:
str="Monday";
break;
case TUESDAY:
str="Tuesday";
break;
case WEDNESDAY:
str="Wednesday";
break;
case THURSDAY:
str="Thursday";
break;
case FRIDAY:
str="Friday";
break;
case SATURDAY:
str="Saturday";
break;
default:
str="Unknown";
}
//--- result
return(str);
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_START_TIME" |
//+------------------------------------------------------------------+
datetime CSymbolInfo::StartTime(void) const
{
return((datetime)SymbolInfoInteger(m_name,SYMBOL_START_TIME));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_EXPIRATION_TIME" |
//+------------------------------------------------------------------+
datetime CSymbolInfo::ExpirationTime(void) const
{
return((datetime)SymbolInfoInteger(m_name,SYMBOL_EXPIRATION_TIME));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_CURRENCY_BASE" |
//+------------------------------------------------------------------+
string CSymbolInfo::CurrencyBase(void) const
{
return(SymbolInfoString(m_name,SYMBOL_CURRENCY_BASE));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_CURRENCY_PROFIT" |
//+------------------------------------------------------------------+
string CSymbolInfo::CurrencyProfit(void) const
{
return(SymbolInfoString(m_name,SYMBOL_CURRENCY_PROFIT));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_CURRENCY_MARGIN" |
//+------------------------------------------------------------------+
string CSymbolInfo::CurrencyMargin(void) const
{
return(SymbolInfoString(m_name,SYMBOL_CURRENCY_MARGIN));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_BANK" |
//+------------------------------------------------------------------+
string CSymbolInfo::Bank(void) const
{
return(SymbolInfoString(m_name,SYMBOL_BANK));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_DESCRIPTION" |
//+------------------------------------------------------------------+
string CSymbolInfo::Description(void) const
{
return(SymbolInfoString(m_name,SYMBOL_DESCRIPTION));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_PATH" |
//+------------------------------------------------------------------+
string CSymbolInfo::Path(void) const
{
return(SymbolInfoString(m_name,SYMBOL_PATH));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_DEALS" |
//+------------------------------------------------------------------+
long CSymbolInfo::SessionDeals(void) const
{
return(SymbolInfoInteger(m_name,SYMBOL_SESSION_DEALS));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_BUY_ORDERS" |
//+------------------------------------------------------------------+
long CSymbolInfo::SessionBuyOrders(void) const
{
return(SymbolInfoInteger(m_name,SYMBOL_SESSION_BUY_ORDERS));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_SELL_ORDERS" |
//+------------------------------------------------------------------+
long CSymbolInfo::SessionSellOrders(void) const
{
return(SymbolInfoInteger(m_name,SYMBOL_SESSION_SELL_ORDERS));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_TURNOVER" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionTurnover(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_TURNOVER));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_INTEREST" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionInterest(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_INTEREST));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_BUY_ORDERS_VOLUME" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionBuyOrdersVolume(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_BUY_ORDERS_VOLUME));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_SELL_ORDERS_VOLUME" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionSellOrdersVolume(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_SELL_ORDERS_VOLUME));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_OPEN" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionOpen(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_OPEN));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_CLOSE" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionClose(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_CLOSE));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_AW" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionAW(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_AW));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_PRICE_SETTLEMENT" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionPriceSettlement(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_PRICE_SETTLEMENT));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_PRICE_LIMIT_MIN" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionPriceLimitMin(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_PRICE_LIMIT_MIN));
}
//+------------------------------------------------------------------+
//| Get the property value "SYMBOL_SESSION_PRICE_LIMIT_MAX" |
//+------------------------------------------------------------------+
double CSymbolInfo::SessionPriceLimitMax(void) const
{
return(SymbolInfoDouble(m_name,SYMBOL_SESSION_PRICE_LIMIT_MAX));
}
//+------------------------------------------------------------------+
//| Access functions SymbolInfoInteger(...) |
//+------------------------------------------------------------------+
bool CSymbolInfo::InfoInteger(const ENUM_SYMBOL_INFO_INTEGER prop_id,long &var) const
{
return(SymbolInfoInteger(m_name,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions SymbolInfoDouble(...) |
//+------------------------------------------------------------------+
bool CSymbolInfo::InfoDouble(const ENUM_SYMBOL_INFO_DOUBLE prop_id,double &var) const
{
return(SymbolInfoDouble(m_name,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions SymbolInfoString(...) |
//+------------------------------------------------------------------+
bool CSymbolInfo::InfoString(const ENUM_SYMBOL_INFO_STRING prop_id,string &var) const
{
return(SymbolInfoString(m_name,prop_id,var));
}
//+------------------------------------------------------------------+
//| Access functions SymbolInfoMarginRate(...) |
//+------------------------------------------------------------------+
bool CSymbolInfo::InfoMarginRate(const ENUM_ORDER_TYPE order_type,double& initial_margin_rate,double& maintenance_margin_rate) const
{
return(SymbolInfoMarginRate(m_name,order_type,initial_margin_rate,maintenance_margin_rate));
}
//+------------------------------------------------------------------+
//| Normalize price |
//+------------------------------------------------------------------+
double CSymbolInfo::NormalizePrice(const double price) const
{
if(m_tick_size!=0)
return(NormalizeDouble(MathRound(price/m_tick_size)*m_tick_size,m_digits));
//---
return(NormalizeDouble(price,m_digits));
}
//+------------------------------------------------------------------+
//| Checks if symbol is selected in the MarketWatch |
//| and adds symbol to the MarketWatch, if necessary |
//+------------------------------------------------------------------+
bool CSymbolInfo::CheckMarketWatch(void)
{
//--- check if symbol is selected in the MarketWatch
if(!Select())
{
if(GetLastError()==ERR_MARKET_UNKNOWN_SYMBOL)
{
printf(__FUNCTION__+": Unknown symbol '%s'",m_name);
return(false);
}
if(!Select(true))
{
printf(__FUNCTION__+": Error adding symbol %d",GetLastError());
return(false);
}
}
//--- succeed
return(true);
}
//+------------------------------------------------------------------+
+225
View File
@@ -0,0 +1,225 @@
//+------------------------------------------------------------------+
//| TerminalInfo.mqh |
//| Copyright 2000-2026, MetaQuotes Ltd. |
//| www.mql5.com |
//+------------------------------------------------------------------+
#include <Object.mqh>
//+------------------------------------------------------------------+
//| Class CTerminalInfo. |
//| Appointment: Class for access to terminal info. |
//| Derives from class CObject. |
//+------------------------------------------------------------------+
class CTerminalInfo : public CObject
{
public:
CTerminalInfo(void);
~CTerminalInfo(void);
//--- fast access methods to the integer terminal propertyes
int Build(void) const;
bool IsConnected(void) const;
bool IsDLLsAllowed(void) const;
bool IsTradeAllowed(void) const;
bool IsEmailEnabled(void) const;
bool IsFtpEnabled(void) const;
int MaxBars(void) const;
int CodePage(void) const;
int CPUCores(void) const;
int MemoryPhysical(void) const;
int MemoryTotal(void) const;
int MemoryAvailable(void) const;
int MemoryUsed(void) const;
bool IsX64(void) const;
int OpenCLSupport(void) const;
int DiskSpace(void) const;
//--- fast access methods to the string terminal propertyes
string Language(void) const;
string Name(void) const;
string Company(void) const;
string Path(void) const;
string DataPath(void) const;
string CommonDataPath(void) const;
//--- access methods to the API MQL5 functions
long InfoInteger(const ENUM_TERMINAL_INFO_INTEGER prop_id) const;
string InfoString(const ENUM_TERMINAL_INFO_STRING prop_id) const;
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CTerminalInfo::CTerminalInfo(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CTerminalInfo::~CTerminalInfo(void)
{
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_BUILD" |
//+------------------------------------------------------------------+
int CTerminalInfo::Build(void) const
{
return((int)TerminalInfoInteger(TERMINAL_BUILD));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_CONNECTED" |
//+------------------------------------------------------------------+
bool CTerminalInfo::IsConnected(void) const
{
return((bool)TerminalInfoInteger(TERMINAL_CONNECTED));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_DLLS_ALLOWED" |
//+------------------------------------------------------------------+
bool CTerminalInfo::IsDLLsAllowed(void) const
{
return((bool)TerminalInfoInteger(TERMINAL_DLLS_ALLOWED));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_TRADE_ALLOWED" |
//+------------------------------------------------------------------+
bool CTerminalInfo::IsTradeAllowed(void) const
{
return((bool)TerminalInfoInteger(TERMINAL_TRADE_ALLOWED));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_EMAIL_ENABLED" |
//+------------------------------------------------------------------+
bool CTerminalInfo::IsEmailEnabled(void) const
{
return((bool)TerminalInfoInteger(TERMINAL_EMAIL_ENABLED));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_FTP_ENABLED" |
//+------------------------------------------------------------------+
bool CTerminalInfo::IsFtpEnabled(void) const
{
return((bool)TerminalInfoInteger(TERMINAL_FTP_ENABLED));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_MAXBARS" |
//+------------------------------------------------------------------+
int CTerminalInfo::MaxBars(void) const
{
return((int)TerminalInfoInteger(TERMINAL_MAXBARS));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_CODEPAGE" |
//+------------------------------------------------------------------+
int CTerminalInfo::CodePage(void) const
{
return((int)TerminalInfoInteger(TERMINAL_CODEPAGE));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_CPU_CORES" |
//+------------------------------------------------------------------+
int CTerminalInfo::CPUCores(void) const
{
return((int)TerminalInfoInteger(TERMINAL_CPU_CORES));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_MEMORY_PHYSICAL" |
//+------------------------------------------------------------------+
int CTerminalInfo::MemoryPhysical(void) const
{
return((int)TerminalInfoInteger(TERMINAL_MEMORY_PHYSICAL));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_MEMORY_TOTAL" |
//+------------------------------------------------------------------+
int CTerminalInfo::MemoryTotal(void) const
{
return((int)TerminalInfoInteger(TERMINAL_MEMORY_TOTAL));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_MEMORY_AVAILABLE" |
//+------------------------------------------------------------------+
int CTerminalInfo::MemoryAvailable(void) const
{
return((int)TerminalInfoInteger(TERMINAL_MEMORY_AVAILABLE));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_MEMORY_USED" |
//+------------------------------------------------------------------+
int CTerminalInfo::MemoryUsed(void) const
{
return((int)TerminalInfoInteger(TERMINAL_MEMORY_USED));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_X64" |
//+------------------------------------------------------------------+
bool CTerminalInfo::IsX64(void) const
{
return((bool)TerminalInfoInteger(TERMINAL_X64));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_OPENCL_SUPPORT" |
//+------------------------------------------------------------------+
int CTerminalInfo::OpenCLSupport(void) const
{
return((int)TerminalInfoInteger(TERMINAL_OPENCL_SUPPORT));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_DISK_SPACE" |
//+------------------------------------------------------------------+
int CTerminalInfo::DiskSpace(void) const
{
return((int)TerminalInfoInteger(TERMINAL_DISK_SPACE));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_LANGUAGE" |
//+------------------------------------------------------------------+
string CTerminalInfo::Language(void) const
{
return(TerminalInfoString(TERMINAL_LANGUAGE));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_NAME" |
//+------------------------------------------------------------------+
string CTerminalInfo::Name(void) const
{
return(TerminalInfoString(TERMINAL_NAME));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_COMPANY" |
//+------------------------------------------------------------------+
string CTerminalInfo::Company(void) const
{
return(TerminalInfoString(TERMINAL_COMPANY));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_PATH" |
//+------------------------------------------------------------------+
string CTerminalInfo::Path(void) const
{
return(TerminalInfoString(TERMINAL_PATH));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_DATA_PATH" |
//+------------------------------------------------------------------+
string CTerminalInfo::DataPath(void) const
{
return(TerminalInfoString(TERMINAL_DATA_PATH));
}
//+------------------------------------------------------------------+
//| Get the property value "TERMINAL_COMMONDATA_PATH" |
//+------------------------------------------------------------------+
string CTerminalInfo::CommonDataPath(void) const
{
return(TerminalInfoString(TERMINAL_COMMONDATA_PATH));
}
//+------------------------------------------------------------------+
//| Access functions AccountInfoInteger(...) |
//+------------------------------------------------------------------+
long CTerminalInfo::InfoInteger(const ENUM_TERMINAL_INFO_INTEGER prop_id) const
{
return(TerminalInfoInteger(prop_id));
}
//+------------------------------------------------------------------+
//| Access functions AccountInfoString(...) |
//+------------------------------------------------------------------+
string CTerminalInfo::InfoString(const ENUM_TERMINAL_INFO_STRING prop_id) const
{
return(TerminalInfoString(prop_id));
}
//+------------------------------------------------------------------+
File diff suppressed because it is too large Load Diff