mirror of
https://github.com/rithsila/MT5-EA-Sniper-Strategy.git
synced 2026-08-25 00:28:19 +00:00
67 lines
1.5 KiB
Plaintext
67 lines
1.5 KiB
Plaintext
/*
|
|
Trade.mqh
|
|
(For MQL5)
|
|
|
|
Copyright 2013-2020, Orchard Forex
|
|
https://www.orchardforex.com
|
|
|
|
*/
|
|
|
|
#include <Trade/Trade.mqh>
|
|
|
|
class CTradeCustom : public CTrade {
|
|
|
|
private:
|
|
|
|
protected: // member variables
|
|
|
|
public: // constructors
|
|
|
|
public:
|
|
|
|
bool PositionCloseByType(const string symbol, ENUM_POSITION_TYPE positionType,const ulong deviation=ULONG_MAX);
|
|
////New
|
|
void PositionCountByType(const string symbol, int &count[]);
|
|
|
|
};
|
|
|
|
bool CTradeCustom::PositionCloseByType(const string symbol, ENUM_POSITION_TYPE positionType, const ulong deviation=ULONG_MAX) {
|
|
|
|
bool result = true;
|
|
int cnt = PositionsTotal();
|
|
for (int i = cnt-1; i>=0; i--) {
|
|
ulong ticket = PositionGetTicket(i);
|
|
if (PositionSelectByTicket(ticket)) {
|
|
if (PositionGetString(POSITION_SYMBOL)==symbol && PositionGetInteger(POSITION_TYPE)==positionType && PositionGetInteger(POSITION_MAGIC)==m_magic) {
|
|
result &= PositionClose(ticket, deviation);
|
|
}
|
|
} else {
|
|
m_result.retcode=TRADE_RETCODE_REJECT;
|
|
result = false;
|
|
}
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
////New
|
|
void CTradeCustom::PositionCountByType(const string symbol, int &count[]) {
|
|
|
|
ArrayResize(count, 6);
|
|
ArrayInitialize(count, 0);
|
|
|
|
int cnt = PositionsTotal();
|
|
for (int i = cnt-1; i>=0; i--) {
|
|
ulong ticket = PositionGetTicket(i);
|
|
if (PositionSelectByTicket(ticket)) {
|
|
if (PositionGetString(POSITION_SYMBOL)==symbol && PositionGetInteger(POSITION_MAGIC)==m_magic) {
|
|
count[(int)PositionGetInteger(POSITION_TYPE)]++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
|
|
}
|