last ...
This commit is contained in:
Vendored
+18
-18
@@ -10,24 +10,6 @@
|
|||||||
"references": [],
|
"references": [],
|
||||||
"title": "add support for OB in XCAEA POI Detector"
|
"title": "add support for OB in XCAEA POI Detector"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"assignedTo": {
|
|
||||||
"name": "Hadi Khazaee Asl"
|
|
||||||
},
|
|
||||||
"creation_time": "2025-05-08T10:51:12.522Z",
|
|
||||||
"id": "5",
|
|
||||||
"references": [],
|
|
||||||
"title": "add Trade Session Support and Multi Symbol Structure"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"assignedTo": {
|
|
||||||
"name": "Hadi Khazaee Asl"
|
|
||||||
},
|
|
||||||
"creation_time": "2025-05-08T10:52:04.074Z",
|
|
||||||
"id": "6",
|
|
||||||
"references": [],
|
|
||||||
"title": "Complete Perday Trade Management based on SL(s) and TP(s)"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"assignedTo": {
|
"assignedTo": {
|
||||||
"name": "Hadi Khazaee Asl"
|
"name": "Hadi Khazaee Asl"
|
||||||
@@ -36,6 +18,15 @@
|
|||||||
"id": "7",
|
"id": "7",
|
||||||
"references": [],
|
"references": [],
|
||||||
"title": "add support for Swings on Block Detection ..."
|
"title": "add support for Swings on Block Detection ..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"assignedTo": {
|
||||||
|
"name": "Hadi Khazaee Asl"
|
||||||
|
},
|
||||||
|
"creation_time": "2025-05-08T10:51:12.522Z",
|
||||||
|
"id": "5",
|
||||||
|
"references": [],
|
||||||
|
"title": "add Trade Session Support and Multi Symbol Structure"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"testing": [
|
"testing": [
|
||||||
@@ -80,6 +71,15 @@
|
|||||||
"id": "2",
|
"id": "2",
|
||||||
"references": [],
|
"references": [],
|
||||||
"title": "Add Support for Daily Max Volume and Ticks Box in XCAEA POI Detector ..."
|
"title": "Add Support for Daily Max Volume and Ticks Box in XCAEA POI Detector ..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"assignedTo": {
|
||||||
|
"name": "Hadi Khazaee Asl"
|
||||||
|
},
|
||||||
|
"creation_time": "2025-05-08T10:52:04.074Z",
|
||||||
|
"id": "6",
|
||||||
|
"references": [],
|
||||||
|
"title": "Complete Perday Trade Management based on SL(s) and TP(s)"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"done": []
|
"done": []
|
||||||
|
|||||||
@@ -665,12 +665,23 @@ void InitRequirements()
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Setting Trade Restrictions ...
|
// Setting Trade Restrictions ...
|
||||||
eaTradeManager.SetTradeRestrictions(
|
eaTradeManager
|
||||||
eaRestrictionsPeriod,
|
.SetTradeRestrictions(
|
||||||
eaMaxAllowedTPs,
|
eaRestrictionsPeriod,
|
||||||
eaMaxAllowedSLs,
|
eaMaxAllowedTPs,
|
||||||
eaMaxAllowedTrades //
|
eaMaxAllowedSLs,
|
||||||
);
|
eaMaxAllowedTrades //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Setting Sessions ...
|
||||||
|
eaTradeManager
|
||||||
|
.SetTradeSession(
|
||||||
|
_Symbol,
|
||||||
|
"03:00", // Start ...
|
||||||
|
"20:00", // End ...
|
||||||
|
"XSaherSession" // Name ...
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// EA Signaller ...
|
// EA Signaller ...
|
||||||
|
|||||||
@@ -79,23 +79,26 @@ string ToString(ENUM_XCAEA_TRADE_FINALIZATION value)
|
|||||||
struct XCAEASymbolInfo
|
struct XCAEASymbolInfo
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
string symbol;
|
// Properties ...
|
||||||
|
|
||||||
//
|
//
|
||||||
int longs;
|
string symbol; // Trading Symbol
|
||||||
int shorts;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
int trades;
|
int longs; // All Long Trades
|
||||||
|
int shorts; // All Short Trades
|
||||||
|
|
||||||
//
|
//
|
||||||
int losses;
|
int trades; // All Trades
|
||||||
int profits;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
int managedSLs;
|
int losses; // All Loosing Trades
|
||||||
int managedTPs;
|
int profits; // All Winning Trades
|
||||||
int managedTrades;
|
|
||||||
|
//
|
||||||
|
int managedSLs; // Managed SL(s)
|
||||||
|
int managedTPs; // Managed TP(s)
|
||||||
|
int managedTrades; // Managed Trades
|
||||||
|
|
||||||
//
|
//
|
||||||
// Constructor ...
|
// Constructor ...
|
||||||
@@ -164,6 +167,179 @@ struct XCAEASymbolInfo
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
struct XCAEATradeSession
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Properties ...
|
||||||
|
string start; // Session Start Time (hh:mm)
|
||||||
|
string end; // Session End Time (hh:mm)
|
||||||
|
string name; // Session Name
|
||||||
|
|
||||||
|
//
|
||||||
|
// Constructor ...
|
||||||
|
XCAEATradeSession()
|
||||||
|
{
|
||||||
|
Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup ...
|
||||||
|
void Clean()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
end = NULL;
|
||||||
|
name = NULL;
|
||||||
|
start = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
ZeroMemory(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
bool IsValid()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(start) &&
|
||||||
|
IsValid(end);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Session is Active or Not ...
|
||||||
|
bool IsActive(datetime time = NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
time = NormalizeTime(time);
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsTimeInRange(
|
||||||
|
time,
|
||||||
|
start,
|
||||||
|
end //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct XCAEASymbolSession
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Propeties ...
|
||||||
|
|
||||||
|
//
|
||||||
|
string symbol; // Trading Symbol
|
||||||
|
XCAEATradeSession sessions[]; // Trading Sessions
|
||||||
|
|
||||||
|
//
|
||||||
|
// Constructor ...
|
||||||
|
XCAEASymbolSession()
|
||||||
|
{
|
||||||
|
Clean();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Tools ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup ...
|
||||||
|
void Clean()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
symbol = NULL;
|
||||||
|
Clean(sessions);
|
||||||
|
|
||||||
|
//
|
||||||
|
ZeroMemory(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
bool IsValid()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(symbol);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Allow Trade in Active Sessions ...
|
||||||
|
bool CanTrade(datetime time = NULL)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Normalize Args ...
|
||||||
|
time = NormalizeTime(time);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validating ...
|
||||||
|
result = IsValid();
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// if there is not any defined sessions for Symbol ...
|
||||||
|
// it's allow Trading in all times ...
|
||||||
|
result = !HasChild(sessions);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Detect an Active Session ...
|
||||||
|
int count = ArraySize(sessions);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = sessions[i].IsActive(time);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
struct XCAEATrade
|
struct XCAEATrade
|
||||||
{
|
{
|
||||||
@@ -496,21 +672,79 @@ class XCXCAEATradeManager : public XCBaseAlert
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Implement this ...
|
|
||||||
void SetTradeSession(
|
void SetTradeSession(
|
||||||
|
string symbol,
|
||||||
string start,
|
string start,
|
||||||
string end //
|
string end,
|
||||||
|
string name = NULL //
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool has = IsValid(start) ||
|
// Validate Args ...
|
||||||
IsValid(end);
|
bool has = IsValid(end) &&
|
||||||
|
IsValid(start) &&
|
||||||
|
IsValid(symbol);
|
||||||
if (!has)
|
if (!has)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
// Create Session ...
|
||||||
|
|
||||||
|
//
|
||||||
|
XCAEATradeSession session;
|
||||||
|
|
||||||
|
//
|
||||||
|
session.end = end;
|
||||||
|
session.name = name;
|
||||||
|
session.start = start;
|
||||||
|
|
||||||
|
//
|
||||||
|
int sessionIDX = -1;
|
||||||
|
has = FindSymbolSession(
|
||||||
|
sessionIDX,
|
||||||
|
symbol //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Add New Symbol Session ...
|
||||||
|
|
||||||
|
//
|
||||||
|
XCAEASymbolSession iSymbolSession;
|
||||||
|
iSymbolSession.symbol = symbol;
|
||||||
|
|
||||||
|
//
|
||||||
|
AddTradingSession(
|
||||||
|
session,
|
||||||
|
iSymbolSession //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
iSymbolSession,
|
||||||
|
sessions //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
iSymbolSession.Clean();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Update Trading Sessions of Exists Symbol Session ...
|
||||||
|
AddTradingSession(
|
||||||
|
session,
|
||||||
|
sessions[sessionIDX] //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup Resources ...
|
||||||
|
session.Clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -974,36 +1208,54 @@ class XCXCAEATradeManager : public XCBaseAlert
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Check Symbol Info Exists or not ...
|
// Check Symbol Info Exists or not ...
|
||||||
int symbolIDX = -1;
|
int symbolInfoIDX = -1;
|
||||||
bool isSymbolExists = FindSymbolIndex(
|
bool isSymbolInfoExists = FindSymbolIndex(
|
||||||
symbolIDX,
|
symbolInfoIDX,
|
||||||
signal.symbol //
|
signal.symbol //
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: Complete this ...
|
// Check Symbol Session Exists or not ...
|
||||||
// Implementing Trade Session Validating ...
|
int symbolSessionIDX = -1;
|
||||||
|
bool isSymbolSessionExists = FindSymbolSession(
|
||||||
|
symbolSessionIDX,
|
||||||
|
signal.symbol //
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Implementing Trade Permissions Based on SL(s) Count ...
|
// Chack Trade Session Validating ...
|
||||||
|
if (isSymbolSessionExists) {
|
||||||
|
//
|
||||||
|
result = sessions[symbolSessionIDX].CanTrade();
|
||||||
|
if (!result) {
|
||||||
|
//
|
||||||
|
executionResult = X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Trade Permissions Based on SL(s) Count ...
|
||||||
bool hasRestrictions = restrictionsPeriod != XCAEA_TRADE_RESTRICATION_NONE;
|
bool hasRestrictions = restrictionsPeriod != XCAEA_TRADE_RESTRICATION_NONE;
|
||||||
if (hasRestrictions)
|
if (hasRestrictions)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Only Can Check Restrictions when
|
// Only Can Check Restrictions when
|
||||||
// Symbol Info Exists ...
|
// Symbol Info Exists ...
|
||||||
if (isSymbolExists)
|
if (isSymbolInfoExists)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
bool isTPAllowed = maxAllowedTPs == 0
|
bool isTPAllowed = maxAllowedTPs == 0
|
||||||
? true
|
? true
|
||||||
: symbols[symbolIDX].managedTPs < maxAllowedTPs;
|
: symbols[symbolInfoIDX].managedTPs < maxAllowedTPs;
|
||||||
bool isSLAllowed = maxAllowedSLs == 0
|
bool isSLAllowed = maxAllowedSLs == 0
|
||||||
? true
|
? true
|
||||||
: symbols[symbolIDX].managedSLs < maxAllowedSLs;
|
: symbols[symbolInfoIDX].managedSLs < maxAllowedSLs;
|
||||||
bool isTradeAllowed = maxAllowedTrades == 0
|
bool isTradeAllowed = maxAllowedTrades == 0
|
||||||
? true
|
? true
|
||||||
: symbols[symbolIDX].managedTrades < maxAllowedTrades;
|
: symbols[symbolInfoIDX].managedTrades < maxAllowedTrades;
|
||||||
|
|
||||||
//
|
//
|
||||||
result = isTPAllowed &&
|
result = isTPAllowed &&
|
||||||
@@ -1823,6 +2075,94 @@ class XCXCAEATradeManager : public XCBaseAlert
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Symbol Session ...
|
||||||
|
|
||||||
|
//
|
||||||
|
bool FindSymbolSession(
|
||||||
|
int &index,
|
||||||
|
string symbol //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValid(symbol) &&
|
||||||
|
HasChild(sessions);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int count = ArraySize(sessions);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
result = sessions[i].symbol == symbol;
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = IsValidIndex(index);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void AddTradingSession(
|
||||||
|
XCAEATradeSession &session,
|
||||||
|
XCAEASymbolSession &symbolSession //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
bool has = session.IsValid() &&
|
||||||
|
symbolSession.IsValid();
|
||||||
|
if (!has)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Session Exists in Symbol Session ...
|
||||||
|
bool isExists = false;
|
||||||
|
if (HasChild(symbolSession.sessions))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
int count = ArraySize(symbolSession.sessions);
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
isExists = symbolSession.sessions[i].end == session.end &&
|
||||||
|
symbolSession.sessions[i].start == session.start;
|
||||||
|
if (isExists)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!isExists)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
AddRef(
|
||||||
|
session,
|
||||||
|
symbolSession.sessions //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Private ...
|
// Private ...
|
||||||
private:
|
private:
|
||||||
@@ -1855,6 +2195,7 @@ class XCXCAEATradeManager : public XCBaseAlert
|
|||||||
//
|
//
|
||||||
XCAEATrade trades[];
|
XCAEATrade trades[];
|
||||||
XCAEASymbolInfo symbols[];
|
XCAEASymbolInfo symbols[];
|
||||||
|
XCAEASymbolSession sessions[];
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user