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:
@@ -0,0 +1,567 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Library
|
||||
// -------------------------------------------------
|
||||
// Name: XCXFIMAEALib ...
|
||||
// Description: XFIMAEA Library ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XFIMAEA Library"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../../Classes/x-saherelm.x-cobject.class.mq5"
|
||||
#include "../../Helpers/x-saherelm.xfima.helper.mq5"
|
||||
#include "../Classes/x-saherelm.xfima.parser.class.mq5"
|
||||
#include "../../Libraries/x-saherelm.x-pivot.analysis.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
/**
|
||||
* XFIMA Base Market Structure ...
|
||||
* AnalyseMarket result ...
|
||||
**/
|
||||
struct XFIMAMarketStructure
|
||||
{
|
||||
//
|
||||
XOHCL bar; // Spacified Start Bar for Analysing ...
|
||||
XPatternAnalysis barAnalysis; // Structure Bar Pattern Analysis ...
|
||||
|
||||
//
|
||||
XPivotAnalysis pvAnalysis; // PV Pivot Analysis Result ...
|
||||
XPivotAnalysis zgAnalysis; // ZG Pivot Analysis Result ...
|
||||
|
||||
//
|
||||
XPatternAnalysis barsAnalysis[]; // Anaysed Bars ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XFIMAMarketStructure()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
bar.Clean();
|
||||
barAnalysis.Clean();
|
||||
|
||||
//
|
||||
pvAnalysis.Clean();
|
||||
zgAnalysis.Clean();
|
||||
XClean(barsAnalysis);
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = bar.IsValid() &&
|
||||
barAnalysis.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Collectors ...
|
||||
|
||||
/**
|
||||
* Collect Required Zones from Structure ...
|
||||
*
|
||||
* @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 ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int CollectZones(
|
||||
XBoxZone &dest[],
|
||||
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE,
|
||||
bool containsOB = false,
|
||||
bool containsFVG = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
XClean(dest);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool has = IsValid();
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool canCollectBullish =
|
||||
IsXBullish(forDir) ||
|
||||
!HasDirection(forDir);
|
||||
|
||||
//
|
||||
bool canCollectBearish =
|
||||
IsXBearish(forDir) ||
|
||||
!HasDirection(forDir);
|
||||
|
||||
//
|
||||
int count = 0;
|
||||
XBoxZone tmpBox;
|
||||
|
||||
//
|
||||
// Check Analysis ...
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
has = pvAnalysis.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// 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 //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// XZG ...
|
||||
has = zgAnalysis.IsValid();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Support ...
|
||||
tmpBox.Clean();
|
||||
has = zgAnalysis.HasSupportBox(tmpBox);
|
||||
if (has && canCollectBullish)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
tmpBox,
|
||||
dest //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Resistance ...
|
||||
tmpBox.Clean();
|
||||
has = zgAnalysis.HasResistanceBox(tmpBox);
|
||||
if (has && canCollectBearish)
|
||||
{
|
||||
//
|
||||
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 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Resistance ...
|
||||
has = barsAnalysis[i].IsResistance();
|
||||
if (has && canCollectBearish)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
barsAnalysis[i].resistance,
|
||||
dest //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// OB ...
|
||||
if (containsOB)
|
||||
{
|
||||
//
|
||||
has = barsAnalysis[i].IsOB();
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
has = (canCollectBullish && barsAnalysis[i].ob.IsBullish()) ||
|
||||
(canCollectBearish && barsAnalysis[i].ob.IsBearish());
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
barsAnalysis[i].ob,
|
||||
dest //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 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 //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
struct XFIMAMarketStructureConfig
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Detector Flags ...
|
||||
|
||||
//
|
||||
bool analysePVPivots; // Analyse PV Pivots ...
|
||||
bool analyseZGPivots; // Analyse ZG Pivots ...
|
||||
|
||||
//
|
||||
bool analyseBarPatterns; // Analyse Bar Patterns ...
|
||||
|
||||
//
|
||||
// Detector Configs ...
|
||||
|
||||
//
|
||||
int loopback; // Max Allowed Looping Back Length ...
|
||||
int requiredPivots; // Required Extracted Pivots for Analysis ...
|
||||
|
||||
//
|
||||
int pvPivotsValidationLength; // PV Pivots Validation Length ...
|
||||
double maCrossValidationDiffMultiplier; // a Point Distance to Validate MA Crosses ...
|
||||
|
||||
//
|
||||
XPatternAnalysisConfig barsAnalysisConfig; // Bars Analyser Config ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XFIMAMarketStructureConfig()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* This function fulfills the will of the developer
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Detector Flags ...
|
||||
analysePVPivots = false;
|
||||
analyseZGPivots = false;
|
||||
analyseBarPatterns = false;
|
||||
|
||||
//
|
||||
// Configure Detectors ...
|
||||
loopback = 0;
|
||||
requiredPivots = 0;
|
||||
pvPivotsValidationLength = 0;
|
||||
maCrossValidationDiffMultiplier = 0;
|
||||
|
||||
//
|
||||
barsAnalysisConfig.Clean();
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Configurations ...
|
||||
*/
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
// Detector Flags ...
|
||||
analysePVPivots = true;
|
||||
analyseZGPivots = true;
|
||||
analyseBarPatterns = true;
|
||||
|
||||
//
|
||||
// Configure Detectors ...
|
||||
loopback = 200;
|
||||
requiredPivots = 10;
|
||||
pvPivotsValidationLength = 5;
|
||||
maCrossValidationDiffMultiplier = 4;
|
||||
|
||||
//
|
||||
barsAnalysisConfig.Default();
|
||||
barsAnalysisConfig.FullPattern();
|
||||
}
|
||||
|
||||
/**
|
||||
* No Draw Abilioty ...
|
||||
*/
|
||||
void Off()
|
||||
{
|
||||
//
|
||||
// Detector Flags ...
|
||||
analysePVPivots = false;
|
||||
analyseZGPivots = false;
|
||||
analyseBarPatterns = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full Draw Abilioty ...
|
||||
*/
|
||||
void Full()
|
||||
{
|
||||
//
|
||||
// Detector Flags ...
|
||||
analysePVPivots = true;
|
||||
analyseZGPivots = true;
|
||||
analyseBarPatterns = true;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
/**
|
||||
* Configure Market Structure Drawer ...
|
||||
**/
|
||||
struct XFIMAMarketStructureDrawerConfig
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
bool drawPVAnalysis;
|
||||
bool drawZGAnalysis;
|
||||
bool drawBarsAnalysis;
|
||||
|
||||
//
|
||||
XPOIDrawConfig drawConfig;
|
||||
XPivotAnalysisDrawConfig pivotAnalysisDrawConfig;
|
||||
XPatternAnalysisDrawConfig barAnalysisDrawConfig;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XFIMAMarketStructureDrawerConfig()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* This function fulfills the will of the developer
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Drawing Flags ...
|
||||
|
||||
//
|
||||
drawPVAnalysis = false;
|
||||
drawZGAnalysis = false;
|
||||
drawBarsAnalysis = false;
|
||||
|
||||
//
|
||||
// Drawing Configs ...
|
||||
drawConfig.Clean();
|
||||
barAnalysisDrawConfig.Clean();
|
||||
pivotAnalysisDrawConfig.Clean();
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Configurations ...
|
||||
*/
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
// Drawing Flags ...
|
||||
|
||||
//
|
||||
drawPVAnalysis = true;
|
||||
drawZGAnalysis = true;
|
||||
drawBarsAnalysis = true;
|
||||
|
||||
//
|
||||
// Drawing Configs ...
|
||||
drawConfig.Default();
|
||||
pivotAnalysisDrawConfig.Default();
|
||||
|
||||
//
|
||||
barAnalysisDrawConfig.Default();
|
||||
barAnalysisDrawConfig.Full();
|
||||
XClean(barAnalysisDrawConfig.allowedDrawZones);
|
||||
Add(
|
||||
X_BAR_PATTERN_SUPPORT,
|
||||
barAnalysisDrawConfig.allowedDrawZones);
|
||||
Add(
|
||||
X_BAR_PATTERN_RESISTANCE,
|
||||
barAnalysisDrawConfig.allowedDrawZones);
|
||||
}
|
||||
|
||||
/**
|
||||
* No Draw Abilioty ...
|
||||
*/
|
||||
void Off()
|
||||
{
|
||||
//
|
||||
// Drawing Flags ...
|
||||
|
||||
//
|
||||
drawPVAnalysis = false;
|
||||
drawZGAnalysis = false;
|
||||
drawBarsAnalysis = false;
|
||||
|
||||
//
|
||||
// Drawing Configs ...
|
||||
barAnalysisDrawConfig.Off();
|
||||
pivotAnalysisDrawConfig.Off();
|
||||
}
|
||||
|
||||
/**
|
||||
* Full Draw Abilioty ...
|
||||
*/
|
||||
void Full()
|
||||
{
|
||||
//
|
||||
// Drawing Flags ...
|
||||
|
||||
//
|
||||
drawPVAnalysis = false;
|
||||
drawZGAnalysis = false;
|
||||
drawBarsAnalysis = false;
|
||||
|
||||
//
|
||||
// Drawing Configs ...
|
||||
barAnalysisDrawConfig.Full();
|
||||
pivotAnalysisDrawConfig.Full();
|
||||
}
|
||||
|
||||
void ApplyDrawConfig()
|
||||
{
|
||||
//
|
||||
barAnalysisDrawConfig.drawConfig = drawConfig;
|
||||
barAnalysisDrawConfig.ConfigureQuarterDraws();
|
||||
pivotAnalysisDrawConfig.drawConfig = drawConfig;
|
||||
}
|
||||
|
||||
void ApplyDrawConfig(XPOIDrawConfig &_drawConfig)
|
||||
{
|
||||
//
|
||||
drawConfig = _drawConfig;
|
||||
ApplyDrawConfig();
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user