refactor all requirements for draw and detect pois and also add Fima Helper, Parser Class Implementations for Separation of Concerns ...

This commit is contained in:
2025-10-24 05:03:31 +03:30
parent d63c5596fc
commit 0b0cd70049
21 changed files with 25191 additions and 8447 deletions
+197 -172
View File
@@ -25,6 +25,7 @@
#include "../../Classes/x-saherelm.x-cobject.class.mq5"
#include "../../Helpers/x-saherelm.xfima.helper.mq5"
#include "../../Libraries/x-saherelm.x-pivot.analysis.lib.mq5"
#include "../Classes/x-saherelm.xfima.parser.class.mq5"
//
// Definitions ...
@@ -40,8 +41,22 @@ struct XFIMAMarketStructure
XPatternAnalysis barAnalysis; // Structure Bar Pattern Analysis ...
//
XPivotAnalysis pvAnalysis; // PV Pivot Analysis Result ...
XPivotAnalysis zgAnalysis; // ZG Pivot Analysis Result ...
XBoxZone orderFlow[]; // Specified Order Flow Zones ...
ENUM_X_DIRECTION orderFlowDir; // Specified Order Flow Direction ...
//
XPivot pvPivots[]; // XPV Pivots ...
XPivot zgPivots[]; // XZG Pivots ...
XPivot maPivots[]; // XMA Pivots ...
XPivot hkPivots[]; // XHK Pivots ...
XPivot sarPivots[]; // XSAR Pivots ...
//
XPivotAnalysis pvAnalysis; // XPV Pivot Analysis Result ...
XPivotAnalysis zgAnalysis; // XZG Pivot Analysis Result ...
XPivotAnalysis maAnalysis; // XMA Pivot Analysis Result ...
XPivotAnalysis hkAnalysis; // XHK Pivot Analysis Result ...
XPivotAnalysis sarAnalysis; // XSAR Pivot Analysis Result ...
//
XPatternAnalysis barsAnalysis[]; // Anaysed Bars ...
@@ -65,11 +80,27 @@ struct XFIMAMarketStructure
bar.Clean();
barAnalysis.Clean();
//
XClean(pvPivots);
XClean(zgPivots);
XClean(maPivots);
XClean(hkPivots);
XClean(sarPivots);
//
pvAnalysis.Clean();
zgAnalysis.Clean();
maAnalysis.Clean();
hkAnalysis.Clean();
sarAnalysis.Clean();
//
XClean(barsAnalysis);
//
XClean(orderFlow);
orderFlowDir = X_DIRECTION_NONE;
//
ZeroMemory(this);
}
@@ -85,31 +116,73 @@ struct XFIMAMarketStructure
bool result = false;
//
result = bar.IsValid() &&
barAnalysis.IsValid();
result = bar.IsValid() &&
barAnalysis.IsValid();
//
return result;
}
//
// Checkers ...
/**
* Check Market Strucutre Has Order Flow or not ...
*
* @return ( bool )
*/
bool HasOrderFlow()
{
//
bool result = false;
//
result = IsValid() &&
HasChild(orderFlow) &&
HasDirection(orderFlowDir);
//
return result;
}
/**
* Check Market Structure Has Bullish Order Flow or not ...
*
* @return ( bool )
*/
bool HasBullishOrderFlow()
{
return HasOrderFlow() &&
IsXBullish(orderFlowDir);
}
/**
* Check Market Structure Has Bearish Order Flow or not ...
*
* @return ( bool )
*/
bool HasBearishOrderFlow()
{
return HasOrderFlow() &&
IsXBearish(orderFlowDir);
}
//
// Collectors ...
/**
* Collect Required Zones from Structure ...
* Collect all Pivots ...
*
* @param dest: XBoxZone, reference collection to holds result ...
* @param forDir: ENUM_X_DIRECTION, Specified Collectiong ones Direction ...
* @param containsOB: bool, Contains OB Zones ...
* @param containsFVG: bool, Contains FVG Zones ...
* @param dest: XPivot, collection reference to holds result ...
* @param containsPatterns: bool, Specified to Add Pivots Bar Directionl Patterns ...
* @param forDir: ENUM_X_DIRECTION, Specified Extraction Direction ...
*
* @return ( int )
*/
int CollectZones(
XBoxZone &dest[],
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE,
bool containsOB = false,
bool containsFVG = false //
int CollectPivots(
XPivot &dest[],
bool containsPatterns = false,
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE //
)
{
//
@@ -120,7 +193,7 @@ struct XFIMAMarketStructure
XClean(dest);
//
// Validate ...
// Normalize ...
bool has = IsValid();
if (!has)
{
@@ -128,182 +201,80 @@ struct XFIMAMarketStructure
}
//
bool canCollectBullish =
IsXBullish(forDir) ||
!HasDirection(forDir);
// Do ...
//
bool canCollectBearish =
IsXBearish(forDir) ||
!HasDirection(forDir);
Copy(pvPivots, dest, false);
Copy(hkPivots, dest, false);
Copy(maPivots, dest, false);
Copy(zgPivots, dest, false);
Copy(sarPivots, dest, false);
//
int count = 0;
XBoxZone tmpBox;
//
// Check Analysis ...
//
// XPV ...
has = pvAnalysis.IsValid();
if (has)
// Apply Direction Filtering ...
if (HasDirection(forDir))
{
//
// Support ...
tmpBox.Clean();
has = pvAnalysis.HasSupportBox(tmpBox);
if (has && canCollectBullish)
{
//
AddIfNotExists(
tmpBox,
dest //
);
}
//
// Resistance ...
tmpBox.Clean();
has = pvAnalysis.HasResistanceBox(tmpBox);
if (has && canCollectBearish)
{
//
AddIfNotExists(
tmpBox,
dest //
);
}
XPivot tmps[];
ExtractByDirection(
tmps,
dest,
forDir //
);
XClean(dest);
Copy(tmps, dest);
XClean(tmps);
}
//
// XZG ...
has = zgAnalysis.IsValid();
if (has)
// Contains Pattern Pivots ...
if (containsPatterns && HasChild(dest) && HasChild(barsAnalysis))
{
//
// Support ...
tmpBox.Clean();
has = zgAnalysis.HasSupportBox(tmpBox);
if (has && canCollectBullish)
{
//
AddIfNotExists(
tmpBox,
dest //
);
}
XPivot tmp;
int idx = -1;
XPivot tmps[];
XPivot sames[];
XPivot patterns[];
Copy(dest, tmps);
XClean(dest);
//
// Resistance ...
tmpBox.Clean();
has = zgAnalysis.HasResistanceBox(tmpBox);
if (has && canCollectBearish)
while (HasChild(tmps))
{
//
AddIfNotExists(
tmpBox,
dest //
);
}
}
//
// Bar Patterns ...
has = HasChild(barsAnalysis);
if (has)
{
//
count = ArraySize(barsAnalysis);
for (int i = 0; i < count; i++)
{
//
// Support ...
has = barsAnalysis[i].IsSupport();
if (has && canCollectBullish)
{
//
AddIfNotExists(
barsAnalysis[i].support,
dest //
);
}
tmp.Clean();
tmp = tmps[0];
ArrayRemove(tmps, 0, 1);
//
// Resistance ...
has = barsAnalysis[i].IsResistance();
if (has && canCollectBearish)
XClean(sames);
ExtractSameTimePivots(tmp, sames, tmps);
if (HasChild(sames))
{
//
AddIfNotExists(
barsAnalysis[i].resistance,
dest //
);
}
//
// OB ...
if (containsOB)
{
//
has = barsAnalysis[i].IsOB();
has = FindByTime(idx, tmp.time, barsAnalysis);
if (has)
{
//
has = (canCollectBullish && barsAnalysis[i].ob.IsBullish()) ||
(canCollectBearish && barsAnalysis[i].ob.IsBearish());
if (has)
{
//
AddIfNotExists(
barsAnalysis[i].ob,
dest //
);
}
barsAnalysis[idx].GetPatterns(patterns, sames[0].dir);
Copy(patterns, dest, false);
}
}
//
// FVG ...
if (containsFVG)
{
has = barsAnalysis[i].IsFVG();
if (has)
{
//
has = (canCollectBullish && barsAnalysis[i].fvg.IsBullish()) ||
(canCollectBearish && barsAnalysis[i].fvg.IsBearish());
if (has)
{
//
AddIfNotExists(
barsAnalysis[i].fvg,
dest //
);
}
}
//
Copy(sames, dest, false);
Removes(sames, tmps);
}
}
//
XClean(tmps);
XClean(sames);
XClean(patterns);
}
//
result = ArraySize(dest);
has = IsValidSize(result);
if (has)
{
//
// Update To Time ...
// and also we Can Validate Zones Here ...
datetime cTime = TimeCurrent();
for (int i = 0; i < result; i++)
{
dest[i].to = cTime;
}
}
//
// Cleanup ...
tmpBox.Clean();
//
return result;
@@ -312,6 +283,9 @@ struct XFIMAMarketStructure
//
};
/**
* Configure How to Detect Market Structure ...
**/
struct XFIMAMarketStructureConfig
{
//
@@ -321,12 +295,18 @@ struct XFIMAMarketStructureConfig
// Detector Flags ...
//
bool analysePVPivots; // Analyse PV Pivots ...
bool analyseZGPivots; // Analyse ZG Pivots ...
bool analysePVPivots; // Analyse PV Pivots ...
bool analyseZGPivots; // Analyse ZG Pivots ...
bool analyseHKPivots; // Analyse HK Pivots ...
bool analyseMAPivots; // Analyse MA Pivots ...
bool analyseSARPivots; // Analyse SAR Pivots ...
//
bool analyseBarPatterns; // Analyse Bar Patterns ...
//
bool detectOrderFlow; // Detect Order Flow ...
//
// Detector Configs ...
@@ -335,8 +315,10 @@ struct XFIMAMarketStructureConfig
int requiredPivots; // Required Extracted Pivots for Analysis ...
//
int pvPivotsValidationLength; // PV Pivots Validation Length ...
double maCrossValidationDiffMultiplier; // a Point Distance to Validate MA Crosses ...
int orderFlowValidation; // Order Flow Sequential Validation ...
bool orderFlowUseOB; // Order Flow Use Order Blocks ...
bool orderFlowUseFVG; // Order Flow Use Fair Value Gaps ...
bool orderFlowUseSupportAndResistance; // Order Flow Use Support and Resistance (s) ...
//
XPatternAnalysisConfig barsAnalysisConfig; // Bars Analyser Config ...
@@ -358,16 +340,24 @@ struct XFIMAMarketStructureConfig
{
//
// Detector Flags ...
detectOrderFlow = false;
analysePVPivots = false;
analyseZGPivots = false;
analyseHKPivots = false;
analyseMAPivots = false;
analyseSARPivots = false;
analyseBarPatterns = false;
//
// Configure Detectors ...
loopback = 0;
requiredPivots = 0;
pvPivotsValidationLength = 0;
maCrossValidationDiffMultiplier = 0;
//
orderFlowValidation = 0;
orderFlowUseOB = false;
orderFlowUseFVG = false;
orderFlowUseSupportAndResistance = false;
//
barsAnalysisConfig.Clean();
@@ -383,20 +373,32 @@ struct XFIMAMarketStructureConfig
{
//
// Detector Flags ...
detectOrderFlow = true;
analysePVPivots = true;
analyseZGPivots = true;
analyseHKPivots = true;
analyseMAPivots = true;
analyseSARPivots = true;
analyseBarPatterns = true;
//
// Configure Detectors ...
loopback = 200;
requiredPivots = 10;
pvPivotsValidationLength = 5;
maCrossValidationDiffMultiplier = 4;
//
orderFlowValidation = 2;
orderFlowUseOB = false;
orderFlowUseFVG = true;
orderFlowUseSupportAndResistance = false;
//
barsAnalysisConfig.Default();
barsAnalysisConfig.FullPattern();
//
barsAnalysisConfig.supportAndResistanceLoopbackLength = 5;
barsAnalysisConfig.supportAndResistanceValidationLength = 11;
}
/**
@@ -406,8 +408,12 @@ struct XFIMAMarketStructureConfig
{
//
// Detector Flags ...
detectOrderFlow = false;
analysePVPivots = false;
analyseZGPivots = false;
analyseHKPivots = false;
analyseMAPivots = false;
analyseSARPivots = false;
analyseBarPatterns = false;
}
@@ -418,8 +424,12 @@ struct XFIMAMarketStructureConfig
{
//
// Detector Flags ...
detectOrderFlow = true;
analysePVPivots = true;
analyseZGPivots = true;
analyseHKPivots = true;
analyseMAPivots = true;
analyseSARPivots = true;
analyseBarPatterns = true;
}
@@ -437,6 +447,9 @@ struct XFIMAMarketStructureDrawerConfig
//
bool drawPVAnalysis;
bool drawZGAnalysis;
bool drawMAAnalysis;
bool drawHKAnalysis;
bool drawSARAnalysis;
bool drawBarsAnalysis;
//
@@ -465,6 +478,9 @@ struct XFIMAMarketStructureDrawerConfig
//
drawPVAnalysis = false;
drawZGAnalysis = false;
drawMAAnalysis = false;
drawHKAnalysis = false;
drawSARAnalysis = false;
drawBarsAnalysis = false;
//
@@ -488,6 +504,9 @@ struct XFIMAMarketStructureDrawerConfig
//
drawPVAnalysis = true;
drawZGAnalysis = true;
drawMAAnalysis = true;
drawHKAnalysis = true;
drawSARAnalysis = true;
drawBarsAnalysis = true;
//
@@ -518,6 +537,9 @@ struct XFIMAMarketStructureDrawerConfig
//
drawPVAnalysis = false;
drawZGAnalysis = false;
drawMAAnalysis = false;
drawHKAnalysis = false;
drawSARAnalysis = false;
drawBarsAnalysis = false;
//
@@ -535,9 +557,12 @@ struct XFIMAMarketStructureDrawerConfig
// Drawing Flags ...
//
drawPVAnalysis = false;
drawZGAnalysis = false;
drawBarsAnalysis = false;
drawPVAnalysis = true;
drawZGAnalysis = true;
drawMAAnalysis = true;
drawHKAnalysis = true;
drawSARAnalysis = true;
drawBarsAnalysis = true;
//
// Drawing Configs ...