This commit is contained in:
2026-03-05 01:50:37 +03:30
parent 63281ee006
commit 59a718a1b5
16 changed files with 2199 additions and 9 deletions
+125 -1
View File
@@ -25,6 +25,7 @@
#include "../Classes/x-saherelm.x-alert.class.mq5"
#include "../Classes/x-saherelm.x-chart.helper.class.mq5"
#include "../Classes/x-saherelm.x-guard.class.mq5"
#include "../Classes/x-saherelm.x-restrictions.class.mq5"
#include "../Classes/x-saherelm.x-target.class.mq5"
#include "../Classes/x-saherelm.x-trade-manager.class.mq5"
#include "../Classes/x-saherelm.x-trade.class.mq5"
@@ -90,11 +91,19 @@ input bool eaSaveLosts = true; // Save Lost Conditions
input bool eaSaveRestrictions = true; // Save Restriction Reports
// #endregion
// #region Configurable Documents ...
bool eaEnableAnalysis = true; // Most Important Flag for Enable Analysis in EA ...
bool processTicksOnlyOnNewBars = false; // Processing Ticks only on new Bars ...
ENUM_X_SESSION_TYPE eaAllowedSessions[]; // Allowed Sessions for Analysis ...
ENUM_X_SESSION_OVERLAP_TYPE eaAllowedOverlaps[]; // Allowed Overlaps for Analysis ...
// #endregion
// #region Global Variables ...
#define ShortName "XSessionDetectorTestEA"
//
string eaTag; // EA Scoped Tag ...
string eaTag; // EA Scoped Tag ...
bool isNewBar = false; // EA Is New Bar ...
//
XCAlert *eaAlert; // EA Scope Alert Handler ...
@@ -102,7 +111,9 @@ XCGuard *eaGuard; // EA Scope Guard Handler ...
XCTrade *eaTrader; // EA Scope Trade Handler ...
XCVolume *eaVolume; // EA Scope Voluem Handler ...
XCTarget *eaTarget; // EA Scope Target Handler ...
XBarTracker eaBarTracker; // EA Scope Bar Tracker ...
XTimeTracker eaTimeTracker; // EA Scope Time Tracker ...
XCRestrictions *eaRestrictions; // EA Scope Restrictions Handler ...
XCTradeManager *eaTradeManager; // EA Scope Trade Manager Handler ...
XCSessionDetector *eaSessionDetector; // EA Scope Session Detector ...
// #endregion
@@ -131,6 +142,10 @@ int OnInit()
return INIT_FAILED;
}
//
// Configure Dynamic Variables ...
ConfigureEA();
//
result = InitializeRequirements();
if (!result)
@@ -150,6 +165,35 @@ void OnTick()
//
// Perform Session Detector Process ...
eaSessionDetector.Process();
//
// Perform Restrictions Process ...
eaRestrictions.Process();
//
// Check if Is New Bar ...
isNewBar = eaBarTracker.IsNewBar();
//
// Check Analysis Enabled ...
if (eaEnableAnalysis)
{
//
// Check Bar Tracker ...
if (processTicksOnlyOnNewBars)
{
//
// Check New Bar or not ...
if (!isNewBar)
{
return;
}
}
//
// Do Analysis ...
// TODO: Implement this ...
}
}
/**
@@ -157,6 +201,9 @@ void OnTick()
*/
void OnTrade()
{
//
// Calling Event Handler ...
eaTrader.HandleOnTrade();
}
/**
@@ -202,6 +249,7 @@ void OnDeinit(const int reason)
ZeroMemory(eaVolume);
ZeroMemory(eaTarget);
ZeroMemory(eaTradeManager);
ZeroMemory(eaRestrictions);
ZeroMemory(eaSessionDetector);
}
@@ -273,6 +321,32 @@ bool ValidateInputs()
return result;
}
/**
* Configure EA Commons ...
*/
void ConfigureEA()
{
//
// Configure Sessions ...
//
// Configure Overlaps ...
Add(
X_OVERLAP_LONDON_NEWYORK,
eaAllowedOverlaps //
);
//
// Startup eaAnalysis State ...
int sessionsCount = ArraySize(eaAllowedSessions);
int overlapsCount = ArraySize(eaAllowedOverlaps);
//
eaEnableAnalysis =
!IsValidSize(sessionsCount) &&
!IsValidSize(overlapsCount);
}
/**
* Initial Requirements of EA ...
*
@@ -291,6 +365,17 @@ bool InitializeRequirements()
: "") +
ShortName;
// #region Initializing Bar Tracker ...
result = eaBarTracker.Init(
_Symbol,
_Period //
);
if (!result)
{
return result;
}
// #endregion
// #region Alert ...
eaAlert = new XCAlert();
eaAlert.SetPrefix(eaLogSuffix);
@@ -415,6 +500,23 @@ bool InitializeRequirements()
);
// #endregion
// #region Restrictions Handler ...
eaRestrictions = new XCRestrictions();
//
// Configure Restrictions ...
// TODO: Refactor Restrictions Configurations as Input ...
eaRestrictions.SetAllowedLosesInRestrictions(2);
eaRestrictions.SetAllowedTradesInRestrictions(2);
eaRestrictions.SetRestrictionsPeriodMultiplier(2);
eaRestrictions.SetRestrictionsPeriod(X_TRADE_RESTRICATION_DAILY);
//
// Register Event Handlers ...
eaRestrictions.AddRestrictionsEndEventHandler(OnRestrictionsEnd);
eaRestrictions.AddRestrictionsStartEventHandler(OnRestrictionsStart);
// #endregion
//
result = eaSessionDetector != NULL;
if (!result)
@@ -518,7 +620,11 @@ void OnOverlapStartHandler(
datetime startTime //
)
{
//
Print("Overlap Started: ", EnumToString(overlap), " at ", TimeToString(startTime));
//
// Check Over lap Exists in eaSession Everlaps ...
}
/**
@@ -643,6 +749,24 @@ void OnPositionPartialClosed(
void OnTradeStateChanged(const XOnTradeHandlerState &state)
{
}
/**
* Handle Restrictions Start Event ...
* XCRestrictions ...
*/
void OnRestrictionsStart()
{
Print("Restrictions Start ...");
}
/**
* Handle Restrictions End Event ...
* XCRestrictions ...
*/
void OnRestrictionsEnd()
{
Print("Restrictions End ...");
}
// #endregion
//