70 lines
1.9 KiB
MQL5
70 lines
1.9 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Position.mqh – jedna otevřená pozice, čtení dat z terminálu |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "TestRefactor"
|
|
#property strict
|
|
|
|
#ifndef __POSITION_MQH__
|
|
#define __POSITION_MQH__
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| CPosition – informace o jedné otevřené pozici; data z terminálu |
|
|
//+------------------------------------------------------------------+
|
|
class CPosition {
|
|
private:
|
|
ulong m_ticket;
|
|
string m_symbol;
|
|
|
|
public:
|
|
CPosition() : m_ticket(0), m_symbol("") {}
|
|
CPosition(ulong ticket, string symbol) : m_ticket(ticket), m_symbol(symbol) {}
|
|
|
|
void Set(ulong ticket, string symbol) { m_ticket = ticket; m_symbol = symbol; }
|
|
ulong GetTicket() const { return m_ticket; }
|
|
string GetSymbol() const { return m_symbol; }
|
|
|
|
bool Select() const {
|
|
if(m_ticket == 0) return false;
|
|
return PositionSelectByTicket(m_ticket);
|
|
}
|
|
|
|
long GetType() const {
|
|
if(!Select()) return -1;
|
|
return PositionGetInteger(POSITION_TYPE);
|
|
}
|
|
|
|
double GetOpenPrice() const {
|
|
if(!Select()) return 0;
|
|
return PositionGetDouble(POSITION_PRICE_OPEN);
|
|
}
|
|
|
|
double GetVolume() const {
|
|
if(!Select()) return 0;
|
|
return PositionGetDouble(POSITION_VOLUME);
|
|
}
|
|
|
|
double GetProfit() const {
|
|
if(!Select()) return 0;
|
|
return PositionGetDouble(POSITION_PROFIT);
|
|
}
|
|
|
|
double GetSwap() const {
|
|
if(!Select()) return 0;
|
|
return PositionGetDouble(POSITION_SWAP);
|
|
}
|
|
|
|
double GetSL() const {
|
|
if(!Select()) return 0;
|
|
return PositionGetDouble(POSITION_SL);
|
|
}
|
|
|
|
double GetTP() const {
|
|
if(!Select()) return 0;
|
|
return PositionGetDouble(POSITION_TP);
|
|
}
|
|
|
|
bool IsBuy() const { return GetType() == POSITION_TYPE_BUY; }
|
|
bool IsSell() const { return GetType() == POSITION_TYPE_SELL; }
|
|
};
|
|
|
|
#endif
|