Files
MQL5Data/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5
T
2025-10-24 08:20:27 +03:30

590 lines
13 KiB
Plaintext

///////////////////////////////////////////////////////
//
// 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 "../../Libraries/x-saherelm.x-pivot.analysis.lib.mq5"
#include "../Classes/x-saherelm.xfima.parser.class.mq5"
//
// Definitions ...
/**
* XFIMA Base Market Structure ...
* AnalyseMarket result ...
**/
struct XFIMAMarketStructure
{
//
XOHCL bar; // Spacified Start Bar for Analysing ...
XPatternAnalysis barAnalysis; // Structure Bar Pattern Analysis ...
//
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 ...
//
// Constructor ...
XFIMAMarketStructure()
{
Clean();
}
//
// Tools ...
/**
* Cleanup ...
*/
void Clean()
{
//
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);
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
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 all Pivots ...
*
* @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 CollectPivots(
XPivot &dest[],
bool containsPatterns = false,
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE //
)
{
//
int result = 0;
//
// Prepare ...
XClean(dest);
//
// Normalize ...
bool has = IsValid();
if (!has)
{
return result;
}
//
// Do ...
//
Copy(pvPivots, dest, false);
Copy(hkPivots, dest, false);
Copy(maPivots, dest, false);
Copy(zgPivots, dest, false);
Copy(sarPivots, dest, false);
//
// Apply Direction Filtering ...
if (HasDirection(forDir))
{
//
XPivot tmps[];
ExtractByDirection(
tmps,
dest,
forDir //
);
XClean(dest);
Copy(tmps, dest);
XClean(tmps);
}
//
// Contains Pattern Pivots ...
if (containsPatterns && HasChild(dest) && HasChild(barsAnalysis))
{
//
XPivot tmp;
int idx = -1;
XPivot tmps[];
XPivot sames[];
XPivot patterns[];
Copy(dest, tmps);
XClean(dest);
//
while (HasChild(tmps))
{
//
tmp.Clean();
tmp = tmps[0];
ArrayRemove(tmps, 0, 1);
//
XClean(sames);
ExtractSameTimePivots(tmp, sames, tmps);
if (HasChild(sames))
{
//
has = FindByTime(idx, tmp.time, barsAnalysis);
if (has)
{
//
barsAnalysis[idx].GetPatterns(patterns, sames[0].dir);
Copy(patterns, dest, false);
}
//
Copy(sames, dest, false);
Removes(sames, tmps);
}
}
//
XClean(tmps);
XClean(sames);
XClean(patterns);
}
//
result = ArraySize(dest);
//
return result;
}
//
};
/**
* Configure How to Detect Market Structure ...
**/
struct XFIMAMarketStructureConfig
{
//
// Props ...
//
// Detector Flags ...
//
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 ...
//
int loopback; // Max Allowed Looping Back Length ...
int requiredPivots; // Required Extracted Pivots for Analysis ...
//
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 ...
//
// Constructor ...
XFIMAMarketStructureConfig()
{
Clean();
}
//
// Tools ...
/**
* This function fulfills the will of the developer
*/
void Clean()
{
//
// Detector Flags ...
detectOrderFlow = false;
analysePVPivots = false;
analyseZGPivots = false;
analyseHKPivots = false;
analyseMAPivots = false;
analyseSARPivots = false;
analyseBarPatterns = false;
//
// Configure Detectors ...
loopback = 0;
requiredPivots = 0;
//
orderFlowValidation = 0;
orderFlowUseOB = false;
orderFlowUseFVG = false;
orderFlowUseSupportAndResistance = false;
//
barsAnalysisConfig.Clean();
//
ZeroMemory(this);
}
/**
* Default Configurations ...
*/
void Default()
{
//
// Detector Flags ...
detectOrderFlow = true;
analysePVPivots = true;
analyseZGPivots = true;
analyseHKPivots = true;
analyseMAPivots = true;
analyseSARPivots = true;
analyseBarPatterns = true;
//
// Configure Detectors ...
loopback = 200;
requiredPivots = 10;
//
orderFlowValidation = 2;
orderFlowUseOB = false;
orderFlowUseFVG = true;
orderFlowUseSupportAndResistance = false;
//
barsAnalysisConfig.Default();
barsAnalysisConfig.FullPattern();
//
barsAnalysisConfig.supportAndResistanceLoopbackLength = 5;
barsAnalysisConfig.supportAndResistanceValidationLength = 11;
}
/**
* No Draw Abilioty ...
*/
void Off()
{
//
// Detector Flags ...
detectOrderFlow = false;
analysePVPivots = false;
analyseZGPivots = false;
analyseHKPivots = false;
analyseMAPivots = false;
analyseSARPivots = false;
analyseBarPatterns = false;
}
/**
* Full Draw Abilioty ...
*/
void Full()
{
//
// Detector Flags ...
detectOrderFlow = true;
analysePVPivots = true;
analyseZGPivots = true;
analyseHKPivots = true;
analyseMAPivots = true;
analyseSARPivots = true;
analyseBarPatterns = true;
}
//
};
/**
* Configure Market Structure Drawer ...
**/
struct XFIMAMarketStructureDrawerConfig
{
//
// Props ...
//
bool drawPVAnalysis;
bool drawZGAnalysis;
bool drawMAAnalysis;
bool drawHKAnalysis;
bool drawSARAnalysis;
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;
drawMAAnalysis = false;
drawHKAnalysis = false;
drawSARAnalysis = false;
drawBarsAnalysis = false;
//
// Drawing Configs ...
drawConfig.Clean();
barAnalysisDrawConfig.Clean();
pivotAnalysisDrawConfig.Clean();
//
ZeroMemory(this);
}
/**
* Default Configurations ...
*/
void Default()
{
//
// Drawing Flags ...
//
drawPVAnalysis = true;
drawZGAnalysis = true;
drawMAAnalysis = true;
drawHKAnalysis = true;
drawSARAnalysis = 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;
drawMAAnalysis = false;
drawHKAnalysis = false;
drawSARAnalysis = false;
drawBarsAnalysis = false;
//
// Drawing Configs ...
barAnalysisDrawConfig.Off();
pivotAnalysisDrawConfig.Off();
}
/**
* Full Draw Abilioty ...
*/
void Full()
{
//
// Drawing Flags ...
//
drawPVAnalysis = true;
drawZGAnalysis = true;
drawMAAnalysis = true;
drawHKAnalysis = true;
drawSARAnalysis = true;
drawBarsAnalysis = true;
//
// Drawing Configs ...
barAnalysisDrawConfig.Full();
pivotAnalysisDrawConfig.Full();
}
void ApplyDrawConfig()
{
//
barAnalysisDrawConfig.drawConfig = drawConfig;
pivotAnalysisDrawConfig.drawConfig = drawConfig;
}
void ApplyDrawConfig(XPOIDrawConfig &_drawConfig)
{
//
drawConfig = _drawConfig;
ApplyDrawConfig();
}
//
};
//