mql5/Experts/testRefactor2/Position.mqh

70 Zeilen
1,9 KiB
MQL5

2026-02-01 21:39:33 +01:00
//+------------------------------------------------------------------+
//| 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