Files
MQL5Data/Documents/BKP/x-saherelm.xfima.lib copy.mq5
T
2025-10-08 18:47:29 +03:30

695 lines
16 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"
//
// Definitions ...
/**
* Configure Market Structure Detection ...
**/
struct XFIMAPatternDetectorConfig
{
//
// Props ...
//
bool detectSwingTrend;
//
bool detectStarPattern;
bool detectFlagPattern;
bool detectRisingPattern;
bool detectPiercingPattern;
bool detectSignalKeyBarPattern;
//
bool detectPinned;
bool detectMomentum;
bool detectEngulfed;
bool detectTrueGaped;
//
bool analyseFIMAPVPivots;
bool analyseFIMAZigZagPivots;
//
bool detectMACrosses;
double validMACrossDiffMultiplier;
//
bool detectHKSwitches;
bool detectSARSwitches;
//
// Configs ...
//
// Trending ...
int trendingNumberOfSwings;
int trendingSwingShoulders;
//
// Support and Resistance ...
int zonesRequiredNumber;
int zonesValidationLength;
double zonesMinAlloweStrength;
int zonesBreakValidationLength;
double zonesBarShadowMultiplier;
int zonesMaxAllowedLoopbackLength;
//
// TrueGap ...
double truwGapApprovedPointMultiplier;
//
// Flag Pattern ...
int flagPatternMinimumPullbackBars;
//
// Momentum Bar ...
int momentumBarRangeLength;
double momentumBarApprovedMultiplier;
//
// Pinned Bar ...
double pinnedBaarShadowApprovedMultiplier;
double pinnedBarMinimumPinBarRangeMultiplier;
bool pinnedBarForceDirection;
//
// SignalKey Bar ...
double signalKeyBarShadowApprovedMultiplier;
double signalKeyBarMinimumPinBarRangeMultiplier;
bool signalKeyBarForceDirection;
//
// Analyser ...
int pvPivotsValidationLength;
int numberOfRequiredPivotsForAnalysis;
int maxAllowedLoopbackLengthForAnalysis;
//
// Constructor ...
XFIMAPatternDetectorConfig()
{
Clean();
}
//
// Tools ...
/**
* Cleanup Model ...
*/
void Clean()
{
//
detectPinned = false;
detectMomentum = false;
detectEngulfed = false;
detectTrueGaped = false;
detectSwingTrend = false;
detectStarPattern = false;
detectFlagPattern = false;
detectRisingPattern = false;
analyseFIMAPVPivots = false;
detectPiercingPattern = false;
analyseFIMAZigZagPivots = false;
detectSignalKeyBarPattern = false;
//
detectMACrosses = false;
validMACrossDiffMultiplier = 0;
//
detectHKSwitches = false;
detectSARSwitches = false;
//
zonesRequiredNumber = 0;
zonesValidationLength = 0;
zonesMinAlloweStrength = 0;
zonesBarShadowMultiplier = 0;
zonesBreakValidationLength = 0;
zonesMaxAllowedLoopbackLength = 0;
//
trendingNumberOfSwings = 0;
trendingSwingShoulders = 0;
momentumBarRangeLength = 0;
pvPivotsValidationLength = 0;
pinnedBarForceDirection = false;
momentumBarApprovedMultiplier = 0;
signalKeyBarForceDirection = false;
truwGapApprovedPointMultiplier = 0;
flagPatternMinimumPullbackBars = 0;
numberOfRequiredPivotsForAnalysis = 0;
pinnedBaarShadowApprovedMultiplier = 0;
maxAllowedLoopbackLengthForAnalysis = 0;
signalKeyBarShadowApprovedMultiplier = 0;
pinnedBarMinimumPinBarRangeMultiplier = 0;
signalKeyBarMinimumPinBarRangeMultiplier = 0;
//
ZeroMemory(this);
}
/**
* Default Model ...
*/
void Default()
{
//
// Patterns ...
detectStarPattern = false;
detectFlagPattern = false;
detectRisingPattern = false;
detectPiercingPattern = false;
detectSignalKeyBarPattern = false;
//
// Bars ...
detectPinned = false;
detectMomentum = false;
detectEngulfed = false;
detectTrueGaped = false;
//
// Analysers ...
analyseFIMAPVPivots = false;
analyseFIMAZigZagPivots = false;
//
detectMACrosses = true;
validMACrossDiffMultiplier = 1;
//
detectHKSwitches = true;
detectSARSwitches = true;
//
// Trending ...
trendingNumberOfSwings = 3;
trendingSwingShoulders = 11;
//
// Support and Resistance ...
zonesRequiredNumber = 25;
zonesValidationLength = 21;
zonesMinAlloweStrength = 2;
zonesBarShadowMultiplier = 4;
zonesBreakValidationLength = 3;
zonesMaxAllowedLoopbackLength = 200;
//
// TrueGap ...
truwGapApprovedPointMultiplier = 1;
//
// Flag Pattern ...
flagPatternMinimumPullbackBars = 3;
//
// Momentum Bar ...
momentumBarRangeLength = 3;
momentumBarApprovedMultiplier = 2;
//
// Pinned Bar ...
pinnedBaarShadowApprovedMultiplier = 3;
pinnedBarMinimumPinBarRangeMultiplier = 4;
pinnedBarForceDirection = false;
//
// SignalKey Bar ...
signalKeyBarShadowApprovedMultiplier = 3;
signalKeyBarMinimumPinBarRangeMultiplier = 4;
signalKeyBarForceDirection = false;
//
// Length ...
pvPivotsValidationLength = 10;
numberOfRequiredPivotsForAnalysis = 50;
maxAllowedLoopbackLengthForAnalysis = 1500;
}
/**
* Full Detection Model ...
*/
void FullDetect()
{
//
// Patterns ...
detectStarPattern = true;
detectFlagPattern = true;
detectRisingPattern = true;
detectPiercingPattern = true;
detectSignalKeyBarPattern = true;
//
// Bars ...
detectPinned = true;
detectMomentum = true;
detectEngulfed = true;
detectTrueGaped = true;
//
// Analysers ...
analyseFIMAPVPivots = true;
analyseFIMAZigZagPivots = true;
//
detectMACrosses = true;
detectHKSwitches = true;
detectSARSwitches = true;
}
/**
* Default Config, by turn off all detecting flags ...
*/
void OffDetectors()
{
//
// Patterns ...
detectStarPattern = false;
detectFlagPattern = false;
detectRisingPattern = false;
detectPiercingPattern = false;
detectSignalKeyBarPattern = false;
//
// Bars ...
detectPinned = false;
detectMomentum = false;
detectEngulfed = false;
detectTrueGaped = false;
//
// Analysers ...
analyseFIMAPVPivots = false;
analyseFIMAZigZagPivots = false;
//
detectMACrosses = false;
detectHKSwitches = false;
detectSARSwitches = false;
}
//
};
/**
* XFIMA Base Market Structure ...
* AnalyseMarket result ...
**/
struct XFIMAMarketStructure
{
//
XOHCL bar;
//
XBoxZone obs[];
XBoxZone fvgs[];
XBoxZone supports[];
XBoxZone resistances[];
//
XPivot pinBars[];
XPivot engulfBars[];
XPivot trueGapBars[];
XPivot momentumBars[];
//
XBoxZone flagPatterns[];
XBoxZone starPatterns[];
XBoxZone risingPatterns[];
XBoxZone piercingPatterns[];
XBoxZone signalKeyBarPatterns[];
//
// Analysis ...
XPivotAnalysis pvAnalysis;
XPivotAnalysis zigzagAnalysis;
//
ENUM_X_DIRECTION pinnedDir;
ENUM_X_DIRECTION momentumDir;
ENUM_X_DIRECTION engulfedDir;
ENUM_X_DIRECTION trueGapedDir;
//
XOHCL flagSwing;
ENUM_X_DIRECTION flagPatternDir;
//
XOHCL trendSwings[];
ENUM_X_DIRECTION trendDir;
//
ENUM_X_DIRECTION starPatternDir;
ENUM_X_DIRECTION risingPatternDir;
ENUM_X_DIRECTION piercingPatternDir;
ENUM_X_DIRECTION signalKeyBarPatternDir;
//
ENUM_X_DIRECTION maCrossDir;
XPivot maCrosses[];
//
ENUM_X_DIRECTION hkSwitchDir;
XPivot hkSwitches[];
//
ENUM_X_DIRECTION sarSwitchDir;
XPivot sarSwitches[];
//
// Constructor ...
XFIMAMarketStructure()
{
Clean();
}
//
// Tools ...
/**
* Cleanup Model ...
*/
void Clean()
{
//
bar.Clean();
flagSwing.Clean();
//
pvAnalysis.Clean();
zigzagAnalysis.Clean();
//
trendDir = X_DIRECTION_NONE;
pinnedDir = X_DIRECTION_NONE;
momentumDir = X_DIRECTION_NONE;
engulfedDir = X_DIRECTION_NONE;
trueGapedDir = X_DIRECTION_NONE;
flagPatternDir = X_DIRECTION_NONE;
starPatternDir = X_DIRECTION_NONE;
risingPatternDir = X_DIRECTION_NONE;
piercingPatternDir = X_DIRECTION_NONE;
signalKeyBarPatternDir = X_DIRECTION_NONE;
//
maCrossDir = X_DIRECTION_NONE;
SpecifiedClean(maCrosses);
//
hkSwitchDir = X_DIRECTION_NONE;
SpecifiedClean(hkSwitches);
//
sarSwitchDir = X_DIRECTION_NONE;
SpecifiedClean(sarSwitches);
//
SpecifiedClean(obs);
SpecifiedClean(fvgs);
SpecifiedClean(pinBars);
SpecifiedClean(supports);
SpecifiedClean(engulfBars);
SpecifiedClean(resistances);
SpecifiedClean(trueGapBars);
SpecifiedClean(momentumBars);
SpecifiedClean(flagPatterns);
SpecifiedClean(starPatterns);
SpecifiedClean(risingPatterns);
SpecifiedClean(piercingPatterns);
SpecifiedClean(signalKeyBarPatterns);
//
SpecifiedClean(trendSwings);
//
ZeroMemory(this);
}
//
// Checker Functions ...
//
};
/**
* Configure Market Structure Drawer ...
**/
struct XFIMAMarketStructureDrawerConfig
{
//
// Props ...
//
bool drawOB; // Current Order Block ...
bool drawFVG; // Current Fair Value Gap ...
//
bool drawSupport; // Detected Supports ...
bool drawResistance; // Detected Resistances ...
//
bool drawSwingTrend; // Swing Trend ...
bool swingTrendRayLeft; // Ray Left Swing Trend ...
bool swingTrendRayRight; // Ray Right Swing Trend ...
//
// Draw Current Detected Patterns ...
//
bool drawPinned;
bool drawMomentum;
bool drawEngulfed;
bool drawTrueGaped;
//
bool drawStarPattern;
bool drawFlagPattern;
bool drawRisingPattern;
bool drawPiercingPattern;
bool drawSignalKeyBarPattern;
//
// Draw Recently Zones ...
bool drawRecentPatterns;
bool drawFakeBreakedZone;
bool drawRecentlyTestedZones;
bool drawRecentlyBreakedZones;
//
// Draw Analysis Pivots ...
//
// XPV ...
bool drawFIMAPVPivotsAnalysis;
bool drawFIMAPVPivotsAnalysisZones;
bool drawFIMAPVPivotsAnalysisTrends;
bool drawFIMAPVPivotsAnalysisPivots;
//
// XSAR ...
bool drawFIMASARPivotsAnalysis;
bool drawFIMASARPivotsAnalysisZones;
bool drawFIMASARPivotsAnalysisTrends;
bool drawFIMASARPivotsAnalysisPivots;
//
// XZIGZAG ...
bool drawFIMAZigZagPivotsAnalysis;
bool drawFIMAZigZagPivotsAnalysisZones;
bool drawFIMAZigZagPivotsAnalysisTrends;
bool drawFIMAZigZagPivotsAnalysisPivots;
//
// Constructor ...
XFIMAMarketStructureDrawerConfig()
{
Clean();
}
//
// Tools ...
/**
* Cleanup Model ...
*/
void Clean()
{
//
drawOB = false;
drawFVG = false;
drawPinned = false;
drawMomentum = false;
drawSupport = false;
drawEngulfed = false;
drawTrueGaped = false;
drawResistance = false;
drawSwingTrend = false;
drawStarPattern = false;
drawFlagPattern = false;
swingTrendRayLeft = false;
drawRisingPattern = false;
swingTrendRayRight = false;
drawPiercingPattern = false;
drawSignalKeyBarPattern = false;
//
drawRecentPatterns = false;
drawFakeBreakedZone = false;
drawRecentlyTestedZones = false;
drawRecentlyBreakedZones = false;
//
drawFIMAPVPivotsAnalysis = false;
drawFIMAPVPivotsAnalysisZones = false;
drawFIMAPVPivotsAnalysisTrends = false;
drawFIMAPVPivotsAnalysisPivots = false;
//
drawFIMASARPivotsAnalysis = false;
drawFIMASARPivotsAnalysisZones = false;
drawFIMASARPivotsAnalysisTrends = false;
drawFIMASARPivotsAnalysisPivots = false;
//
drawFIMAZigZagPivotsAnalysis = false;
drawFIMAZigZagPivotsAnalysisZones = false;
drawFIMAZigZagPivotsAnalysisTrends = false;
drawFIMAZigZagPivotsAnalysisPivots = false;
//
ZeroMemory(this);
}
/**
* Default Model ...
*/
void Default()
{
drawOB = true;
drawFVG = true;
drawPinned = true;
drawMomentum = true;
drawSupport = true;
drawEngulfed = true;
drawTrueGaped = true;
drawResistance = true;
drawSwingTrend = true;
drawStarPattern = true;
drawFlagPattern = true;
drawRisingPattern = true;
drawPiercingPattern = true;
swingTrendRayLeft = false;
swingTrendRayRight = true;
drawSignalKeyBarPattern = true;
//
drawRecentPatterns = true;
drawFakeBreakedZone = true;
drawRecentlyTestedZones = true;
drawRecentlyBreakedZones = true;
//
drawFIMAPVPivotsAnalysis = true;
drawFIMAPVPivotsAnalysisZones = true;
drawFIMAPVPivotsAnalysisTrends = true;
drawFIMAPVPivotsAnalysisPivots = true;
//
drawFIMASARPivotsAnalysis = true;
drawFIMASARPivotsAnalysisZones = true;
drawFIMASARPivotsAnalysisTrends = true;
drawFIMASARPivotsAnalysisPivots = true;
//
drawFIMAZigZagPivotsAnalysis = true;
drawFIMAZigZagPivotsAnalysisZones = true;
drawFIMAZigZagPivotsAnalysisTrends = true;
drawFIMAZigZagPivotsAnalysisPivots = true;
}
/**
* Configure for Full Drawing ...
*/
void FullDraw()
{
//
Default();
//
drawOB = true;
drawFVG = true;
drawPinned = true;
drawMomentum = true;
drawSupport = true;
drawEngulfed = true;
drawTrueGaped = true;
drawResistance = true;
drawSwingTrend = true;
drawStarPattern = true;
drawFlagPattern = true;
drawRisingPattern = true;
swingTrendRayLeft = true;
swingTrendRayRight = true;
drawPiercingPattern = true;
drawSignalKeyBarPattern = true;
//
drawRecentPatterns = true;
drawFakeBreakedZone = true;
drawRecentlyTestedZones = true;
drawRecentlyBreakedZones = true;
//
drawFIMAPVPivotsAnalysis = true;
drawFIMAPVPivotsAnalysisZones = true;
drawFIMAPVPivotsAnalysisTrends = true;
drawFIMAPVPivotsAnalysisPivots = true;
//
drawFIMASARPivotsAnalysis = true;
drawFIMASARPivotsAnalysisZones = true;
drawFIMASARPivotsAnalysisTrends = true;
drawFIMASARPivotsAnalysisPivots = true;
//
drawFIMAZigZagPivotsAnalysis = true;
drawFIMAZigZagPivotsAnalysisZones = true;
drawFIMAZigZagPivotsAnalysisTrends = true;
drawFIMAZigZagPivotsAnalysisPivots = true;
}
//
};