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
+26 -26
View File
@@ -513,6 +513,32 @@ class XCBaseHelper : public XCBase
return result;
}
/**
* Normalizing Bar Index ...
*
* @param barIndex: int, Provided Bar Index ...
*
* @return ( int )
*/
int NormalizeBarIndex(int barIndex)
{
//
int result = barIndex;
//
if (!IsValid())
{
return result;
}
//
int count = CountBars() - 1;
result = NormalizeInt(result, 0, count - 1);
//
return result;
}
//
// Protected ...
protected:
@@ -635,32 +661,6 @@ class XCBaseHelper : public XCBase
return result;
}
/**
* Normalizing Bar Index ...
*
* @param barIndex: int, Provided Bar Index ...
*
* @return ( int )
*/
int NormalizeBarIndex(int barIndex)
{
//
int result = barIndex;
//
if (!IsValid())
{
return result;
}
//
int count = CountBars() - 1;
result = NormalizeInt(result, 0, count - 1);
//
return result;
}
//
// Private ...
private:
File diff suppressed because it is too large Load Diff
+43
View File
@@ -1460,6 +1460,49 @@ class XCPOIDrawer : public XCBase
}
}
/**
* Draw Pivots ...
*
* @param pivots: XPivot, collection reference to Draw ...
* @param config: XPOIDrawConfig, reference to Specified Draw Style ...
*/
void DrawPivots(
XPivot &pivots[],
XPOIDrawConfig &config //
)
{
//
// Validate ...
bool has = HasChild(pivots);
if (!has)
{
return;
}
//
XPivot tmps[];
int count = ArraySize(pivots);
for (int i = 0; i < count; i++)
{
//
XClean(tmps);
int sameCounts = ExtractSameTimePivots(pivots[i], tmps, pivots);
has = IsValidSize(sameCounts);
if (has)
{
//
for (int j = 0; j < sameCounts; j++)
{
DrawPivot(tmps[j], config, j + 1);
}
}
}
//
// Cleanup ...
XClean(tmps);
}
/**
* Draw Specified Pattern info ...
*
+5582 -463
View File
File diff suppressed because it is too large Load Diff
+43
View File
@@ -334,3 +334,46 @@
//
return result;
}
//
// Testing Draws ...
//
XFIMAMarketStructure pivots[];
//
XPivot pvPivots[];
XPivot hkPivots[];
XPivot maPivots[];
XPivot zgPivots[];
XPivot sarPivots[];
//
poiDetector.CollectZGPivots(zgPivots);
poiDetector.CollectMAPivots(maPivots);
poiDetector.CollectHKPivots(hkPivots);
poiDetector.CollectPVPivots(pvPivots);
poiDetector.CollectSARPivots(sarPivots);
//
// Merging All Pivots ...
Copy(pvPivots, pivots, false);
Copy(zgPivots, pivots, false);
Copy(maPivots, pivots, false);
Copy(hkPivots, pivots, false);
Copy(sarPivots, pivots, false);
//
if (HasChild(pivots))
{
poiDrawer.DrawPivots(pivots, iDrawConfig);
}
//
// Cleanup ...
XClean(pivots);
XClean(pvPivots);
XClean(hkPivots);
XClean(maPivots);
XClean(zgPivots);
XClean(sarPivots);
+129 -5
View File
@@ -5384,11 +5384,8 @@ class XCSession : public XCFromToZone
//
};
//
template <typename T>
bool ToBox(
T *&source[],
@@ -6307,7 +6304,6 @@ void SpecifiedUpdateTo(
}
}
/**
* Check a Box is Used or not ...
*
@@ -6682,7 +6678,6 @@ bool IsBoxPlaceValidForBar(
return result;
}
/**
* Check Source Box is Below Dest ...
*
@@ -7056,3 +7051,132 @@ bool HasInsideBox(
//
return result;
}
/////////////////////////////////////////////
//
// Analyse Bar Patterns ...
if (result && config.analyseBarPatterns)
{
//
// Try to Detect Bars Analysis ...
int fromIndex = -1;
if (!IsXValid(fromTime))
{
fromIndex = barIndex + config.loopback;
}
else
{
fromIndex = GetBarIndex(
symbol,
period,
fromTime //
);
}
result = IsValidIndex(fromIndex);
if (result)
{
//
fromIndex = MathMin(fromIndex, barIndex + config.requiredPivots);
//
for (int i = barIndex; i < fromIndex; i++)
{
//
tmpBar.Clean();
tmpBarAnalysis.Clean();
result = structure.bar.BarAt(i, tmpBar);
result = result &&
AnalyseBarPatterns(
tmpBar,
tmpBarAnalysis,
config.barsAnalysisConfig //
);
if (!result)
{
break;
}
//
AddRef(
tmpBarAnalysis,
structure.barsAnalysis //
);
}
}
}
////////////////////////////////////////////////
/**
* Draw Specified Market Structure Based on Given Configs ...
*
* @param structure: XFIMAMarketStructure, reference to Provide Specifid Market Structure ...
* @param config: XFIMAMarketStructureDrawerConfig, reference to Provide Drawing Configurations ...
*/
void DrawMarketStructure(
XFIMAMarketStructure &structure,
XFIMAMarketStructureDrawerConfig &config //
)
{
//
// Validate ...
bool has = structure.IsValid();
if (!has)
{
return;
}
//
// PV Analysis ...
if (config.drawPVAnalysis)
{
//
has = structure.pvAnalysis.IsValid();
if (has)
{
//
DrawPivotAnalysis(
structure.pvAnalysis,
config.pivotAnalysisDrawConfig //
);
}
}
//
// ZG Analysis ...
if (config.drawZGAnalysis)
{
//
has = structure.zgAnalysis.IsValid();
if (has)
{
//
DrawPivotAnalysis(
structure.zgAnalysis,
config.pivotAnalysisDrawConfig //
);
}
}
//
// Bars Analysis ...
if (config.drawBarsAnalysis)
{
//
int count = ArraySize(structure.barsAnalysis);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
DrawPatternAnalysis(
structure.barsAnalysis[i],
config.barAnalysisDrawConfig //
);
}
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -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();
}
//
};
//
@@ -0,0 +1,495 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class
// -------------------------------------------------
// Name: XCXFIMAPoiDetector ...
// Description: XFIMA POI Detector Class ...
//
//
// 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 XFIMA POI Detector Class"
#property strict
//
// Imports ...
#include "../../Classes/x-saherelm.base.class.mq5"
#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5"
#include "../../Classes/x-saherelm.x-market.pattern.class.mq5"
#include "../Libraries/x-saherelm.xfima.lib.mq5"
//
// Implementation ...
class XCXFIMAPOIDetector : public XCMarketPatternDetector
{
//
// Public ...
public:
//
// Props ...
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCXFIMAHelper *fimaHelper; // XFIMA Helper ...
//
// Constructor ...
XCXFIMAPOIDetector(
XCXFIMAHelper *_fimaHelper //
) : XCMarketPatternDetector()
{
//
barAnalyser = new XCBarAnalyser();
fimaHelper = _fimaHelper;
}
//
// Deconstructor ...
~XCXFIMAPOIDetector()
{
Destroy();
}
//
// Actions and Tools ...
//
// Pivot Analysors ...
/**
* Analyse Market based on Specified Kind of Pivots ...
*
* @param analysis: XPivotAnalysis, reference to hold result ...
* @param barIndex: int, Bar Index ...
* @param requiredNumberOFPivots: int, Specified which Number of Pivots must be Extracted ...
* @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ...
* @param validationLength: int, Specified Pivots Validation Length ignore if <= 0 ...
*
* @return ( bool )
*/
bool AnalysePVPivots(
XPivotAnalysis &analysis,
int barIndex = 0,
int requiredNumberOFPivots = 50,
int maxAllowedLoopbackLength = 1500,
int validationLength = 0 //
)
{
//
bool result = false;
//
// Prepare ...
analysis.Clean();
//
// Reading Pivots ...
XPivot pivots[];
int count = fimaHelper.ExtractPVPivots(
pivots, // Result ...
barIndex, // Bar Index ...
requiredNumberOFPivots, // Required Number of Pivots ...
maxAllowedLoopbackLength, // Max Allowed Loopback ...
validationLength // Validation Length ...
);
result = IsValidSize(count);
if (!result)
{
//
SpecifiedClean(pivots);
return result;
}
//
string symbol = fimaHelper.GetSymbol();
ENUM_TIMEFRAMES period = fimaHelper.GetPeriod();
//
// Initialize Analysis ...
result = analysis.Init(
"XFIMA_XPV",
symbol,
period,
pivots //
);
//
// Cleanup Resources ...
if (!result)
{
analysis.Clean();
}
SpecifiedClean(pivots);
//
return result;
}
/**
* Analyse Market based on Specified Kind of Pivots ...
*
* @param analysis: XPivotAnalysis, reference to hold result ...
* @param barIndex: int, Bar Index ...
* @param requiredNumberOFPivots: int, Specified which Number of Pivots must be Extracted ...
* @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ...
* @param validationLength: int, Specified Pivots Validation Length ignore if <= 0 ...
*
* @return ( bool )
*/
bool AnalyseMAPivots(
XPivotAnalysis &analysis,
int barIndex = 0,
int requiredNumberOFPivots = 50,
int maxAllowedLoopbackLength = 1500,
int validationLength = 0 //
)
{
//
bool result = false;
//
// Prepare ...
analysis.Clean();
//
// Reading Pivots ...
XPivot pivots[];
int count = fimaHelper.ExtractMAPivots(
pivots, // Result ...
barIndex, // Bar Index ...
requiredNumberOFPivots, // Required Number of Pivots ...
maxAllowedLoopbackLength, // Max Allowed Loopback ...
validationLength // Validation Length ...
);
result = IsValidSize(count);
if (!result)
{
//
SpecifiedClean(pivots);
return result;
}
//
string symbol = fimaHelper.GetSymbol();
ENUM_TIMEFRAMES period = fimaHelper.GetPeriod();
//
// Initialize Analysis ...
result = analysis.Init(
"XFIMA_XMA",
symbol,
period,
pivots //
);
//
// Cleanup Resources ...
if (!result)
{
analysis.Clean();
}
SpecifiedClean(pivots);
//
return result;
}
/**
* Analyse Market based on Specified Kind of Pivots ...
*
* @param analysis: XPivotAnalysis, reference to hold result ...
* @param barIndex: int, Bar Index ...
* @param requiredNumberOFPivots: int, Specified which Number of Pivots must be Extracted ...
* @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ...
*
* @return ( bool )
*/
bool AnalyseSARPivots(
XPivotAnalysis &analysis,
int barIndex = 0,
int requiredNumberOFPivots = 50,
int maxAllowedLoopbackLength = 1500 //
)
{
//
bool result = false;
//
// Prepare ...
analysis.Clean();
//
// Reading Pivots ...
XPivot pivots[];
int count = fimaHelper.ExtractSARPivots(
pivots, // Result ...
barIndex, // Bar Index ...
requiredNumberOFPivots, // Required Number of Pivots ...
maxAllowedLoopbackLength // Max Allowed Loopback ...
);
result = IsValidSize(count);
if (!result)
{
//
SpecifiedClean(pivots);
return result;
}
//
string symbol = fimaHelper.GetSymbol();
ENUM_TIMEFRAMES period = fimaHelper.GetPeriod();
//
// Initialize Analysis ...
result = analysis.Init(
"XFIMA_XSAR",
symbol,
period,
pivots //
);
//
// Cleanup Resources ...
if (!result)
{
analysis.Clean();
}
SpecifiedClean(pivots);
//
return result;
}
/**
* Analyse Market based on Specified Kind of Pivots ...
*
* @param analysis: XPivotAnalysis, reference to hold result ...
* @param barIndex: int, Bar Index ...
* @param requiredNumberOFPivots: int, Specified which Number of Pivots must be Extracted ...
* @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ...
*
* @return ( bool )
*/
bool AnalyseZigZagPivots(
XPivotAnalysis &analysis,
int barIndex = 0,
int requiredNumberOFPivots = 50,
int maxAllowedLoopbackLength = 1500 //
)
{
//
bool result = false;
//
// Prepare ...
analysis.Clean();
//
// Reading Pivots ...
XPivot pivots[];
int count = fimaHelper.ExtractZigZagPivots(
pivots, // Result ...
barIndex, // Bar Index ...
requiredNumberOFPivots, // Required Number of Pivots ...
maxAllowedLoopbackLength // Max Allowed Loopback ...
);
result = IsValidSize(count);
if (!result)
{
//
SpecifiedClean(pivots);
return result;
}
//
string symbol = fimaHelper.GetSymbol();
ENUM_TIMEFRAMES period = fimaHelper.GetPeriod();
//
// Initialize Analysis ...
result = analysis.Init(
"XFIMA_XZG",
symbol,
period,
pivots //
);
//
// Cleanup Resources ...
if (!result)
{
analysis.Clean();
}
SpecifiedClean(pivots);
//
return result;
}
/**
* Destroy ...
*/
void Destroy()
{
//
delete barAnalyser;
ZeroMemory(barAnalyser);
}
//
// Testers ...
/**
* Analyse Market based on Specified Bar ...
*
* @param structure: XFIMAMarketStructure, reference to holds result ...
* @param config: XFIMAMarketStructureConfig, reference to Configure Detector ...
* @param barIndex: int, Bar Index ...
*/
void AnalyseMarket(
XFIMAMarketStructure &structure,
XFIMAMarketStructureConfig &config,
int barIndex = 0 //
)
{
//
// Prepare ...
structure.Clean();
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
//
bool has = false;
//
string symbol = fimaHelper.GetSymbol();
ENUM_TIMEFRAMES period = fimaHelper.GetPeriod();
has = structure.bar.Init(
symbol,
period,
barIndex //
);
if (!has)
{
//
structure.Clean();
return;
}
//
// Reading Bar Patterns ...
XOHCL iBar;
XPatternAnalysis iPatternAnalysis;
for (int i = barIndex; i < barIndex + config.loopback; i++)
{
//
// Cleanup ...
iBar.Clean();
iPatternAnalysis.Clean();
//
// Initialize Indexed Bar ...
//
has = structure.bar.BarAt(i, iBar);
if (!has)
{
break;
}
//
// Analyse Indexed Bar ...
has = AnalyseBarPatterns(iBar, iPatternAnalysis, config.barsAnalysisConfig);
if (has)
{
//
AddRef(
iPatternAnalysis,
structure.barsAnalysis //
);
//
if (i == barIndex)
{
structure.barAnalysis = iPatternAnalysis;
}
}
//
// Check Satisfied ...
has = ArraySize(structure.barsAnalysis) >= config.requiredPivots;
if (has)
{
break;
}
}
//
// Handle Pivot Analysis ...
//
// XPV ...
if (config.analysePVPivots)
{
//
// Reading Pivots ...
has = AnalysePVPivots(
structure.pvAnalysis,
barIndex,
config.requiredPivots,
config.loopback,
config.pvPivotsValidationLength //
);
if (!has)
{
structure.pvAnalysis.Clean();
}
}
//
// XZG ...
if (config.analyseZGPivots)
{
//
// Reading Pivots ...
has = AnalyseZigZagPivots(
structure.zgAnalysis,
barIndex,
config.requiredPivots,
config.loopback //
);
if (!has)
{
structure.zgAnalysis.Clean();
}
}
//
// Cleanup ...
iBar.Clean();
iPatternAnalysis.Clean();
}
//
// Protected ...
protected:
//
// Props ...
//
// Private ...
private:
//
//
};
//
+7 -7
View File
@@ -111,7 +111,7 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input int maFastLength = 7; // Fast MA Length
input int maSlowLength = 20; // Slow MA Length
input int maBondLength = 7; // MA Bond Length
input int maBandLength = 7; // MA Band Length
input int zigzagDepth = 12; // ZigZag Depth
input int zigzagDeviation = 5; // ZigZag Deviation
input int zigzagBackStep = 3; // ZigZag Back Step
@@ -137,8 +137,8 @@ input bool showSAR = false; // Show Sar
input bool showBars = true; // Show Bars
input bool showMAFast = false; // Show MA Fast
input bool showMASlow = false; // Show MA Slow
input bool showMABond = false; // Show MA Bond
input bool showHKBond = false; // Show HK Bond
input bool showMABand = false; // Show MA Band
input bool showHKBand = false; // Show HK Band
input bool showBarTime = true; // Show Bar Time
input bool showZigZag = false; // Show ZigZag
input bool showFiboZone = false; // Show Fibo Zone
@@ -312,7 +312,7 @@ int OnInit()
fimaInputs.maAppliedTo = maAppliedTo;
fimaInputs.maFastLength = maFastLength;
fimaInputs.maSlowLength = maSlowLength;
fimaInputs.maBondLength = maBondLength;
fimaInputs.maBandLength = maBandLength;
fimaInputs.zigzagDepth = zigzagDepth;
fimaInputs.zigzagDeviation = zigzagDeviation;
fimaInputs.zigzagBackStep = zigzagBackStep;
@@ -326,8 +326,8 @@ int OnInit()
fimaInputs.showSAR = showSAR;
fimaInputs.showMAFast = showMAFast;
fimaInputs.showMASlow = showMASlow;
fimaInputs.showMABond = showMABond;
fimaInputs.showHKBond = showHKBond;
fimaInputs.showMABand = showMABand;
fimaInputs.showHKBand = showHKBand;
fimaInputs.showZigZag = showZigZag;
fimaInputs.showFiboZone = showFiboZone;
fimaInputs.startCalculationForLastBars = startCalculationForLastBars;
@@ -354,7 +354,7 @@ int OnInit()
// Configure Signaller ...
fima1Signaller.ignoreTargets = false;
fima1Signaller.slAdditionDistance = 30;
fima1Signaller.maxAllowedRiskDistance = 200;
fima1Signaller.maxAllowedRiskDistance = 350;
fima1Signaller.AddOnSignalEventHandler(OnSignalTriggered);
//
File diff suppressed because it is too large Load Diff
+331 -105
View File
@@ -83,7 +83,7 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input int maFastLength = 7; // Fast MA Length
input int maSlowLength = 21; // Slow MA Length
input int maBondLength = 21; // MA Bond Length
input int maBandLength = 21; // MA Band Length
input int zigzagDepth = 12; // ZigZag Depth
input int zigzagDeviation = 5; // ZigZag Deviation
input int zigzagBackStep = 3; // ZigZag Back Step
@@ -92,6 +92,12 @@ input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low D
input bool hkIgnoreShadows = true; // HK Remove noises
input int hkSmoothingLength = 21; // HK Smoothing Length
input ENUM_X_MA_METHOD hkSmoothingMode = X_MA_MODE_EMA; // HK Smoothing Method
input int atrLength = 14; // ATR Length
input double atrMultiplier = 1.5; // ATR Band Multiplier
input int atrSmoothingLength = 21; // ATR Smoothing Length
input ENUM_X_PRICE atrUpperPriceType = X_PRICE_HIGH; // ATR Upper Zone Applied To
input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // ATR Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // ATR Smoothing Method
//
// Presentation ...
@@ -101,8 +107,9 @@ input bool showHK = true; // Show HK
input bool showSAR = true; // Show Sar
input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow
input bool showMABond = true; // Show MA Bond
input bool showHKBond = true; // Show HK Bond
input bool showMABand = true; // Show MA Band
input bool showHKBand = true; // Show HK Band
input bool showATRBand = true; // Show ATR Band
input bool showZigZag = true; // Show ZigZag
input bool showFiboZone = true; // Show Fibo Zone
@@ -138,8 +145,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 44
#property indicator_plots 16
#property indicator_buffers 49
#property indicator_plots 18
//
// Plot Buffers ...
@@ -160,7 +167,7 @@ double maFastColorBuffer[];
#property indicator_label1 "FastMA"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrLime, clrLime, clrLime // clrYellow, clrOrangeRed, clrGray
#property indicator_width1 3
#property indicator_width1 2
//
// Slow MA ...
@@ -178,7 +185,7 @@ double maSlowColorBuffer[];
#property indicator_label2 "SlowMA"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 CLR_NONE, clrRed, clrRed, clrRed // clrLime, clrRed, clrGray
#property indicator_width2 3
#property indicator_width2 2
//
// SAR ...
@@ -286,29 +293,29 @@ double zigzagBuffer[];
// MA Upper ...
//
#define maBondUpperBufferIndex 12
double maBondUpperBuffer[];
#define maBandUpperBufferIndex 12
double maBandUpperBuffer[];
//
#define maBondUpperBufferPlotIndex 9
#define maBandUpperBufferPlotIndex 9
#property indicator_label10 "UpperMA"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrLime
#property indicator_width10 3
#property indicator_width10 2
//
// MA Lower ...
//
#define maBondLowerBufferIndex 13
double maBondLowerBuffer[];
#define maBandLowerBufferIndex 13
double maBandLowerBuffer[];
//
#define maBondLowerBufferPlotIndex 10
#define maBandLowerBufferPlotIndex 10
#property indicator_label11 "LowerMA"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrRed
#property indicator_width11 3
#property indicator_width11 2
//
// XHK ...
@@ -340,60 +347,88 @@ double hkColorBuffer[];
#property indicator_color12 CLR_NONE, clrAqua, clrMagenta, clrGray
//
#define hkBondUpperBufferIndex 19
double hkBondUpperBuffer[];
#define hkBandUpperBufferIndex 19
double hkBandUpperBuffer[];
//
#define hkBondUpperBufferPlotIndex 12
#define hkBandUpperBufferPlotIndex 12
#property indicator_label13 "UpperHK"
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrAqua
#property indicator_width13 3
#property indicator_width13 2
//
#define hkBondLowerBufferIndex 20
double hkBondLowerBuffer[];
#define hkBandLowerBufferIndex 20
double hkBandLowerBuffer[];
//
#define hkBondLowerBufferPlotIndex 13
#define hkBandLowerBufferPlotIndex 13
#property indicator_label14 "LowerHK"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrMagenta
#property indicator_width14 3
#property indicator_width14 2
//
// PB Upper ...
//
#define pbBondUpperBufferIndex 21
double pbBondUpperBuffer[];
#define pbBandUpperBufferIndex 21
double pbBandUpperBuffer[];
//
#define pbBondUpperBufferPlotIndex 14
#define pbBandUpperBufferPlotIndex 14
#property indicator_label15 "UpperPB"
#property indicator_type15 DRAW_LINE
#property indicator_color15 clrRoyalBlue
#property indicator_width15 3
#property indicator_width15 2
//
// PB Lower ...
//
#define pbBondLowerBufferIndex 22
double pbBondLowerBuffer[];
#define pbBandLowerBufferIndex 22
double pbBandLowerBuffer[];
//
#define pbBondLowerBufferPlotIndex 15
#define pbBandLowerBufferPlotIndex 15
#property indicator_label16 "LowerPB"
#property indicator_type16 DRAW_LINE
#property indicator_color16 clrOrangeRed
#property indicator_width16 3
#property indicator_color16 clrRoyalBlue
#property indicator_width16 2
//
// ATR Upper ...
//
#define atrBandUpperBufferIndex 23
double atrBandUpperBuffer[];
//
#define atrBandUpperBufferPlotIndex 16
#property indicator_label17 "UpperATR"
#property indicator_type17 DRAW_LINE
#property indicator_color17 clrOrange
#property indicator_width17 2
//
// ATR Lower ...
//
#define atrBandLowerBufferIndex 24
double atrBandLowerBuffer[];
//
#define atrBandLowerBufferPlotIndex 17
#property indicator_label18 "LowerATR"
#property indicator_type18 DRAW_LINE
#property indicator_color18 clrOrange
#property indicator_width18 2
//
// Data Buffers ...
//
#define mLastBufferIndex 22
#define mLastBufferIndex 24
//
// MA ...
@@ -502,12 +537,27 @@ double hkRawCloseBuffer[];
// XPB Data ...
//
#define pbBondRawUpperBufferIndex mLastBufferIndex + 20
double pbBondRawUpperBuffer[];
#define pbBandRawUpperBufferIndex mLastBufferIndex + 20
double pbBandRawUpperBuffer[];
//
#define pbBondRawLowerBufferIndex mLastBufferIndex + 21
double pbBondRawLowerBuffer[];
#define pbBandRawLowerBufferIndex mLastBufferIndex + 21
double pbBandRawLowerBuffer[];
//
// XATR Data ...
//
#define atrBufferIndex mLastBufferIndex + 22
double atrBuffer[];
//
#define atrBandRawUpperBufferIndex mLastBufferIndex + 23
double atrBandRawUpperBuffer[];
//
#define atrBandRawLowerBufferIndex mLastBufferIndex + 24
double atrBandRawLowerBuffer[];
//
// Variables, Properties and etc ...
@@ -534,6 +584,7 @@ ENUM_TIMEFRAMES mHCPeriod = NULL;
//
int sarHandler = INVALID_HANDLE;
int atrHandler = INVALID_HANDLE;
int maFastHandler = INVALID_HANDLE;
int maSlowHandler = INVALID_HANDLE;
int maUpperHandler = INVALID_HANDLE;
@@ -662,6 +713,7 @@ void OnDeinit(const int reason)
//
// De Initialize all Handlers and etc ...
IndicatorRelease(sarHandler);
IndicatorRelease(atrHandler);
IndicatorRelease(maFastHandler);
IndicatorRelease(maSlowHandler);
IndicatorRelease(maUpperHandler);
@@ -739,6 +791,10 @@ int OnCalculate(
// SAR ...
int sarCalculatedBars = BarsCalculated(sarHandler);
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
bool isPassedRequiredCalculatedBars =
//
@@ -749,7 +805,10 @@ int OnCalculate(
maLowerCalculatedBars >= maxLength &&
//
// SAR ...
sarCalculatedBars >= maxLength
sarCalculatedBars >= maxLength &&
//
// ATR ...
atrCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
@@ -769,13 +828,17 @@ int OnCalculate(
// MA ...
int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer);
int copiedMASlows = CopyBuffer(maSlowHandler, MAIN_LINE, 0, limit, maSlowBuffer);
int copiedMAUppers = CopyBuffer(maUpperHandler, MAIN_LINE, 0, limit, maBondUpperBuffer);
int copiedMALowers = CopyBuffer(maLowerHandler, MAIN_LINE, 0, limit, maBondLowerBuffer);
int copiedMAUppers = CopyBuffer(maUpperHandler, MAIN_LINE, 0, limit, maBandUpperBuffer);
int copiedMALowers = CopyBuffer(maLowerHandler, MAIN_LINE, 0, limit, maBandLowerBuffer);
//
// SAR ...
int copiedSARs = CopyBuffer(sarHandler, MAIN_LINE, 0, limit, sarBuffer);
//
// ATR ...
int copiedATRs = CopyBuffer(atrHandler, MAIN_LINE, 0, limit, atrBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
@@ -787,7 +850,10 @@ int OnCalculate(
copiedMALowers >= limit &&
//
// SAR ...
copiedSARs >= limit
copiedSARs >= limit &&
//
// ATR ...
copiedATRs >= limit
//
;
if (!isPassedRequiredCopiedItems)
@@ -846,7 +912,7 @@ bool ValidateInputs()
// MA ...
maFastLength >= 2 &&
maSlowLength >= 2 &&
maBondLength >= 2 &&
maBandLength >= 2 &&
maSlowLength > maFastLength &&
//
// SAR ...
@@ -854,6 +920,12 @@ bool ValidateInputs()
sarStep > 0 &&
sarMax > sarStep &&
//
// ATR ...
atrLength > 0 &&
atrMultiplier >= 1 &&
IsXValid(atrUpperPriceType) &&
IsXValid(atrLowerPriceType) &&
//
// CYCLES ...
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
@@ -893,7 +965,8 @@ int ExtractMaxLengthOfInputs()
result = MathMax(result, mHCLength);
result = MathMax(result, maFastLength);
result = MathMax(result, maSlowLength);
result = MathMax(result, maBondLength);
result = MathMax(result, maBandLength);
result = MathMax(result, atrLength);
//
return result;
@@ -1039,63 +1112,63 @@ void DefineBuffers()
PlotIndexSetDouble(zigzagBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// MA Bond ...
// MA Band ...
//
ENUM_DRAW_TYPE maBondDrawType = showMABond ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE maBandDrawType = showMABand ? DRAW_LINE : DRAW_NONE;
//
// Upper Bond ...
// Upper Band ...
//
ArraySetAsSeries(maBondUpperBuffer, true);
SetIndexBuffer(maBondUpperBufferIndex, maBondUpperBuffer, INDICATOR_DATA);
ArraySetAsSeries(maBandUpperBuffer, true);
SetIndexBuffer(maBandUpperBufferIndex, maBandUpperBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(maBondUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
PlotIndexSetInteger(maBondUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
PlotIndexSetInteger(maBondUpperBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maBondUpperBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(maBandUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
PlotIndexSetInteger(maBandUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
PlotIndexSetInteger(maBandUpperBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maBandUpperBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// Lower Bond ...
// Lower Band ...
//
ArraySetAsSeries(maBondLowerBuffer, true);
SetIndexBuffer(maBondLowerBufferIndex, maBondLowerBuffer, INDICATOR_DATA);
ArraySetAsSeries(maBandLowerBuffer, true);
SetIndexBuffer(maBandLowerBufferIndex, maBandLowerBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(maBondLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
PlotIndexSetInteger(maBondLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
PlotIndexSetInteger(maBondLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maBondLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
PlotIndexSetInteger(maBandLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
PlotIndexSetInteger(maBandLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
PlotIndexSetInteger(maBandLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maBandLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// XPB Bond ...
// XPB Band ...
//
// Upper Bond ...
// Upper Band ...
//
ArraySetAsSeries(pbBondUpperBuffer, true);
SetIndexBuffer(pbBondUpperBufferIndex, pbBondUpperBuffer, INDICATOR_DATA);
ArraySetAsSeries(pbBandUpperBuffer, true);
SetIndexBuffer(pbBandUpperBufferIndex, pbBandUpperBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(pbBondUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
PlotIndexSetInteger(pbBondUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
PlotIndexSetDouble(pbBondUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(pbBandUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
PlotIndexSetInteger(pbBandUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
PlotIndexSetDouble(pbBandUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// Lower Bond ...
// Lower Band ...
//
ArraySetAsSeries(pbBondLowerBuffer, true);
SetIndexBuffer(pbBondLowerBufferIndex, pbBondLowerBuffer, INDICATOR_DATA);
ArraySetAsSeries(pbBandLowerBuffer, true);
SetIndexBuffer(pbBandLowerBufferIndex, pbBandLowerBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(pbBondLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABond);
PlotIndexSetInteger(pbBondLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBondDrawType);
PlotIndexSetDouble(pbBondLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(pbBandLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABand);
PlotIndexSetInteger(pbBandLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType);
PlotIndexSetDouble(pbBandLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// XHK ...
@@ -1131,29 +1204,54 @@ void DefineBuffers()
SetIndexBuffer(hkCloseBufferIndex, hkCloseBuffer, INDICATOR_DATA);
//
// XHK Bond ...
// XHK Band ...
//
ENUM_DRAW_TYPE hkBondDrawType = showHKBond ? DRAW_LINE : DRAW_NONE;
ENUM_DRAW_TYPE hkBandDrawType = showHKBand ? DRAW_LINE : DRAW_NONE;
//
// Upper ...
ArraySetAsSeries(hkBondUpperBuffer, true);
SetIndexBuffer(hkBondUpperBufferIndex, hkBondUpperBuffer, INDICATOR_DATA);
ArraySetAsSeries(hkBandUpperBuffer, true);
SetIndexBuffer(hkBandUpperBufferIndex, hkBandUpperBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hkBondUpperBufferPlotIndex, PLOT_SHOW_DATA, showHKBond);
PlotIndexSetInteger(hkBondUpperBufferPlotIndex, PLOT_DRAW_TYPE, hkBondDrawType);
PlotIndexSetDouble(hkBondUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(hkBandUpperBufferPlotIndex, PLOT_SHOW_DATA, showHKBand);
PlotIndexSetInteger(hkBandUpperBufferPlotIndex, PLOT_DRAW_TYPE, hkBandDrawType);
PlotIndexSetDouble(hkBandUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// Lower ...
ArraySetAsSeries(hkBondLowerBuffer, true);
SetIndexBuffer(hkBondLowerBufferIndex, hkBondLowerBuffer, INDICATOR_DATA);
ArraySetAsSeries(hkBandLowerBuffer, true);
SetIndexBuffer(hkBandLowerBufferIndex, hkBandLowerBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(hkBondLowerBufferPlotIndex, PLOT_SHOW_DATA, showHKBond);
PlotIndexSetInteger(hkBondLowerBufferPlotIndex, PLOT_DRAW_TYPE, hkBondDrawType);
PlotIndexSetDouble(hkBondLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(hkBandLowerBufferPlotIndex, PLOT_SHOW_DATA, showHKBand);
PlotIndexSetInteger(hkBandLowerBufferPlotIndex, PLOT_DRAW_TYPE, hkBandDrawType);
PlotIndexSetDouble(hkBandLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// XATR Band ...
//
ENUM_DRAW_TYPE atrBandDrawType = showATRBand ? DRAW_LINE : DRAW_NONE;
//
// Upper ...
ArraySetAsSeries(atrBandUpperBuffer, true);
SetIndexBuffer(atrBandUpperBufferIndex, atrBandUpperBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(atrBandUpperBufferPlotIndex, PLOT_SHOW_DATA, showATRBand);
PlotIndexSetInteger(atrBandUpperBufferPlotIndex, PLOT_DRAW_TYPE, atrBandDrawType);
PlotIndexSetDouble(atrBandUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// Lower ...
ArraySetAsSeries(atrBandLowerBuffer, true);
SetIndexBuffer(atrBandLowerBufferIndex, atrBandLowerBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(atrBandLowerBufferPlotIndex, PLOT_SHOW_DATA, showATRBand);
PlotIndexSetInteger(atrBandLowerBufferPlotIndex, PLOT_DRAW_TYPE, atrBandDrawType);
PlotIndexSetDouble(atrBandLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// Data Buffers ...
@@ -1250,12 +1348,27 @@ void DefineBuffers()
// XPB Data ...
//
ArraySetAsSeries(pbBondRawUpperBuffer, true);
SetIndexBuffer(pbBondRawUpperBufferIndex, pbBondRawUpperBuffer, INDICATOR_CALCULATIONS);
ArraySetAsSeries(pbBandRawUpperBuffer, true);
SetIndexBuffer(pbBandRawUpperBufferIndex, pbBandRawUpperBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(pbBondRawLowerBuffer, true);
SetIndexBuffer(pbBondRawLowerBufferIndex, pbBondRawLowerBuffer, INDICATOR_CALCULATIONS);
ArraySetAsSeries(pbBandRawLowerBuffer, true);
SetIndexBuffer(pbBandRawLowerBufferIndex, pbBandRawLowerBuffer, INDICATOR_CALCULATIONS);
//
// XATR Data ...
//
ArraySetAsSeries(atrBuffer, true);
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrBandRawUpperBuffer, true);
SetIndexBuffer(atrBandRawUpperBufferIndex, atrBandRawUpperBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(atrBandRawLowerBuffer, true);
SetIndexBuffer(atrBandRawLowerBufferIndex, atrBandRawLowerBuffer, INDICATOR_CALCULATIONS);
//
}
@@ -1418,11 +1531,11 @@ bool InitRequirements()
}
//
// MA Bond Upper ...
// MA Band Upper ...
maUpperHandler = iMA(
_Symbol,
_Period,
maBondLength,
maBandLength,
0,
maMethod,
PRICE_HIGH //
@@ -1434,11 +1547,11 @@ bool InitRequirements()
}
//
// MA Bond Lower ...
// MA Band Lower ...
maLowerHandler = iMA(
_Symbol,
_Period,
maBondLength,
maBandLength,
0,
maMethod,
PRICE_LOW //
@@ -1463,6 +1576,19 @@ bool InitRequirements()
return result;
}
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
atrLength //
);
result = atrHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
mDrawer = new XCPOIDrawer();
@@ -1620,6 +1746,19 @@ void CalculateValues(
tickVolume //
);
//
// XATR ...
CalculateATR(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Fast MA ...
double iFastMa = maFastBuffer[barIndex];
@@ -1718,15 +1857,15 @@ void CalculateValues(
double iPBLower = MathMin(close[barIndex], open[barIndex]);
//
pbBondUpperBuffer[barIndex] = iPBUpper;
pbBondRawUpperBuffer[barIndex] = iPBUpper;
pbBandUpperBuffer[barIndex] = iPBUpper;
pbBandRawUpperBuffer[barIndex] = iPBUpper;
//
pbBondLowerBuffer[barIndex] = iPBLower;
pbBondRawLowerBuffer[barIndex] = iPBLower;
pbBandLowerBuffer[barIndex] = iPBLower;
pbBandRawLowerBuffer[barIndex] = iPBLower;
//
if (IsXValid(iPBMethod) && maBondLength > 0)
if (IsXValid(iPBMethod) && maBandLength > 0)
{
//
// XPB Upper ...
@@ -1734,9 +1873,9 @@ void CalculateValues(
ratesTotal,
prevCalculated,
barIndex,
maBondLength,
pbBondRawUpperBuffer,
pbBondUpperBuffer,
maBandLength,
pbBandRawUpperBuffer,
pbBandUpperBuffer,
iPBMethod //
);
@@ -1746,9 +1885,9 @@ void CalculateValues(
ratesTotal,
prevCalculated,
barIndex,
maBondLength,
pbBondRawLowerBuffer,
pbBondLowerBuffer,
maBandLength,
pbBandRawLowerBuffer,
pbBandLowerBuffer,
iPBMethod //
);
}
@@ -2334,8 +2473,8 @@ void CalculateHKBar(
}
//
hkBondUpperBuffer[barIndex] = hkHighBuffer[barIndex];
hkBondLowerBuffer[barIndex] = hkLowBuffer[barIndex];
hkBandUpperBuffer[barIndex] = hkHighBuffer[barIndex];
hkBandLowerBuffer[barIndex] = hkLowBuffer[barIndex];
//
// Calculate HK Color ...
@@ -2351,6 +2490,93 @@ void CalculateHKBar(
: hideColorIDX;
}
//
void CalculateATR(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
double iAtr = atrBuffer[barIndex];
double iAppliedAtr = atrMultiplier <= 0
? iAtr
: atrMultiplier * iAtr;
double iUpperPrice = GetAppliedPrice(
atrUpperPriceType,
open,
high,
low,
close,
barIndex //
);
double iLowerPrice = GetAppliedPrice(
atrLowerPriceType,
open,
high,
low,
close,
barIndex //
);
double iPriceMid = iLowerPrice + ((iUpperPrice - iLowerPrice) / 2);
//
double iUpperAtr = iPriceMid + iAppliedAtr;
double iLowerAtr = iPriceMid - iAppliedAtr;
//
atrBandRawUpperBuffer[barIndex] = iUpperAtr;
atrBandRawLowerBuffer[barIndex] = iLowerAtr;
//
// Check Can Smooth Atr ...
if (IsXValid(atrSmoothingMode) &&
atrSmoothingLength > 0)
{
//
// Upper ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
atrSmoothingLength,
atrBandRawUpperBuffer,
atrBandUpperBuffer,
atrSmoothingMode //
);
//
// Lower ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
barIndex,
atrSmoothingLength,
atrBandRawLowerBuffer,
atrBandLowerBuffer,
atrSmoothingMode //
);
}
else
{
//
atrBandUpperBuffer[barIndex] = iUpperAtr;
atrBandLowerBuffer[barIndex] = iLowerAtr;
}
}
//
void CalculateCycleRanges(
int barIndex,
+105 -18
View File
@@ -2452,6 +2452,64 @@ struct XPatternAnalysis
return result;
}
/**
* Extract All Exists Patterns Pivots ...
*
* @param dest: XPivot, collection reference to holds Extracted Patterns ...
* @param forDir: ENUM_X_DIRECTION, Specified Direction of Extractions ...
*
* @return ( int )
*/
int GetPatterns(
XPivot &dest[],
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE //
)
{
//
int result = 0;
//
// Prepare ...
XClean(dest);
//
// Validate ...
bool has = IsValid() &&
HasChild(patterns);
if (!has)
{
return result;
}
//
// Do ...
XOHCL iBar;
XPivot iPivot;
XBoxZone iZone;
int count = ArraySize(patterns);
for (int i = 0; i < count; i++)
{
//
has = GetPattern(iBar, iPivot, iZone, patterns[i], forDir);
if (has)
{
AddIfNotExists(iPivot, dest);
}
}
//
result = ArraySize(dest);
//
// Cleanup ...
iBar.Clean();
iZone.Clean();
iPivot.Clean();
//
return result;
}
//
};
@@ -2460,12 +2518,6 @@ struct XPatternAnalysisConfig
//
// Props ...
//
// Quarter ...
int quarterZonesRequiredToStart;
int quarterZoneDetectionLoopback;
int quarterZonesValidationLength;
//
// PV ...
int pvValidationLength;
@@ -2523,12 +2575,6 @@ struct XPatternAnalysisConfig
*/
void Clean()
{
//
// Quarter ...
quarterZonesRequiredToStart = 0;
quarterZoneDetectionLoopback = 0;
quarterZonesValidationLength = 0;
//
// PV ...
pvValidationLength = 0;
@@ -2580,12 +2626,6 @@ struct XPatternAnalysisConfig
*/
void Default()
{
//
// Quarter ...
quarterZonesRequiredToStart = 20;
quarterZonesValidationLength = 3;
quarterZoneDetectionLoopback = 1500;
//
// PV ...
pvValidationLength = 5;
@@ -3073,4 +3113,51 @@ struct XPatternAnalysisDrawConfig
}
};
//
// Extensions ...
bool FindByTime(
int &index,
datetime time,
XPatternAnalysis &source[] //
)
{
//
bool result = false;
//
// Prepare ...
index = -1;
//
// Validate ...
result = IsXValid(time) &&
HasChild(source);
if (!result)
{
return result;
}
//
// Do ...
int count = ArraySize(source);
for (int i = 0; i < count; i++)
{
//
result = source[i].bar.time == time;
if (result)
{
//
index = i;
break;
}
}
//
result = IsValidIndex(index);
//
return result;
}
//
@@ -2271,6 +2271,7 @@ void SortBar(
//+------------------------------------------------------------------+
//| Extraction |
//+------------------------------------------------------------------+
/**
* Extract Specific Types of Pivots From a Collection ...
*
@@ -2329,6 +2330,61 @@ int ExtractPivots(
return result;
}
/**
* Extract Same Time Pivots ...
*
* @param item: XPivot, reference to Specified Pivot for Detect Same Times ...
* @param dest: XPivot, collection reference to holds Same Times Pivots ...
* @param source: XPivot, collection reference to Provide Data Source ...
*
* @return ( int )
*/
int ExtractSameTimePivots(
XPivot &item,
XPivot &dest[],
XPivot &source[] //
)
{
//
int result = 0;
//
// Prepare ...
XClean(dest);
//
// Validate ...
bool has = HasChild(source) &&
item.IsValid();
if (!has)
{
return result;
}
//
// Do ...
int count = ArraySize(source);
for (int i = 0; i < count; i++)
{
//
has = item.time == source[i].time;
if (has)
{
AddIfNotExists(source[i], dest);
}
}
//
// Add item as a Child ...
AddIfNotExists(item, dest);
//
result = ArraySize(dest);
//
return result;
}
/**
* Extract Pivots Data for Linear Regression Calculations ...
*
+11 -2
View File
@@ -333,9 +333,9 @@ enum ENUM_X_DETECTOR_ZONE_ACTION
/**
* Validate an ENUM member ...
*
*
* @param value: ENUM_X_DETECTOR_ZONE_ACTION ...
*
*
* @return ( bool )
*/
bool IsXValid(ENUM_X_DETECTOR_ZONE_ACTION value)
@@ -636,6 +636,15 @@ struct XPivot
symbol == item.symbol &&
period == item.period;
//
if (result && IsXValid(prefix))
{
//
result =
result &&
prefix == item.prefix;
}
//
return result;
}
File diff suppressed because it is too large Load Diff
@@ -24,6 +24,7 @@
// Imports ...
#include "../../Classes/x-saherelm.x-signaller.class.mq5"
#include "../../Helpers/x-saherelm.xfima.helper.mq5"
#include "../Classes/x-saherelm.xfima.parser.class.mq5"
#include "../Classes/x-saherelm.xfima.x-poi.detector.class.mq5"
#include "../Classes/x-saherelm.xfima.x-poi.drawer.class.mq5"
@@ -45,6 +46,7 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
XFIMAInputs fimaInputs; // XFIMA Inputs ...
XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ...
XCXFIMAPOIDrawer *poiDrawer; // XFIMA POI Drawer ...
XCXFIMAHelperParser *fimaParser; // XFIMA Helper Parser ...
XCXFIMAPOIDetector *poiDetector; // XFIMA POI Detector ...
XFIMAMarketStructureConfig structureConfig; // XFIMA Market Structure Detector Config ...
XFIMAMarketStructureDrawerConfig structureDrawConfig; // XFIMA Market Structure Draw Config ...
@@ -92,9 +94,13 @@ class XCXFIMABaseSignaller : public XCBaseSignaller
}
}
//
// Instantiate XFIMA Helper Parser ...
fimaParser = new XCXFIMAHelperParser(fimaHelper);
//
poiDrawer = new XCXFIMAPOIDrawer();
poiDetector = new XCXFIMAPOIDetector(fimaHelper);
poiDetector = new XCXFIMAPOIDetector(fimaHelper, fimaParser);
//
// Configure ...
@@ -556,25 +562,17 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// Draw Flags ...
bool draw = true;
bool drawZone = true;
bool drawOrderFlow = true;
bool drawMarketStructurePivots = true;
bool drawMarketStructureAnalysis = true;
bool drawMarketStructureOrderFlow = true;
XPOIDrawConfig iDrawConfig;
//
// Signal Checking ...
//
// Detecting OrderFlow ...
XBoxZone orderFlow[];
ENUM_X_DIRECTION orderFlowDir;
bool hasOrderFlow = poiDetector.HasOrderFlow(
bar,
orderFlowDir,
orderFlow,
2,
false, // Contains OB ...
true, // Contains FVG ...
false // Contains Support and Resistances ...
);
// Analyse Market Strucutre ...
XFIMAMarketStructure marketStructure;
//
// Signaller 1 ...
@@ -660,14 +658,24 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
if (result && validateByOrderFlow)
{
//
bool isBullish = hasOrderFlow &&
IsXBullish(dir) &&
IsXBullish(orderFlowDir);
// Analyse Market Structure if Required ...
if (!marketStructure.IsValid())
{
//
poiDetector.AnalyseMarket(
marketStructure,
structureConfig,
bar.Index() //
);
}
//
bool isBearish = hasOrderFlow &&
IsXBearish(dir) &&
IsXBearish(orderFlowDir);
bool isBullish = IsXBullish(dir) &&
marketStructure.HasBullishOrderFlow();
//
bool isBearish = IsXBearish(dir) &&
marketStructure.HasBearishOrderFlow();
//
// Summarizing result ...
@@ -749,7 +757,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Partial Close on TP 1 ...
if (hasPartialCloseOnTp1 && tp > tp1)
if (hasPartialCloseOnTp1)
{
//
iTarget.Clean();
@@ -814,10 +822,52 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
}
//
// Draw Order Flow ...
if (drawOrderFlow && HasChild(orderFlow))
// Draw Market Structure ...
//
// Analyse Market Structure if Required ...
if (!marketStructure.IsValid())
{
poiDrawer.DrawZones(orderFlow, iDrawConfig);
//
poiDetector.AnalyseMarket(
marketStructure,
structureConfig,
bar.Index() //
);
}
if (marketStructure.IsValid())
{
//
// Order Flow ...
if (drawMarketStructureOrderFlow && marketStructure.HasOrderFlow())
{
poiDrawer.DrawZones(marketStructure.orderFlow, iDrawConfig);
}
//
// Pivots ...
if (drawMarketStructurePivots)
{
//
XPivot pivots[];
int pivotsCount = marketStructure.CollectPivots(
pivots,
true // Contains Patterns ...
);
if (IsValidSize(pivotsCount))
{
poiDrawer.DrawPivots(pivots, iDrawConfig);
}
//
XClean(pivots);
}
//
// Analysis ...
if (drawMarketStructureAnalysis)
{
//
}
}
//
@@ -841,6 +891,11 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
DebugBreak();
}
//
// Cleanup ...
iDrawConfig.Clean();
marketStructure.Clean();
//
return result;
}
@@ -918,13 +973,13 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
}
//
// Reading HK Bond ...
// Reading HK Band ...
//
double pHKBondUpper = fimaHelper.GetHKBondUpper(pBar.Index());
double pHKBondLower = fimaHelper.GetHKBondLower(pBar.Index());
int overHKBondUpperCount = fimaHelper.CountOverHKBondUpper(pullBackStartBar, X_PRICE_LOW);
int underHKBondLowerCount = fimaHelper.CountUnderHKBondLower(pullBackStartBar, X_PRICE_HIGH);
double pHKBandUpper = fimaHelper.GetHKBandUpper(pBar.Index());
double pHKBandLower = fimaHelper.GetHKBandLower(pBar.Index());
int overHKBandUpperCount = fimaParser.CountOverHKBandUpper(pullBackStartBar, X_PRICE_LOW);
int underHKBandLowerCount = fimaParser.CountUnderHKBandLower(pullBackStartBar, X_PRICE_HIGH);
//
// Reading PV Requirements ...
@@ -934,10 +989,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
int lastValeUnderLastIDX = -1;
double pPeak = fimaHelper.GetPeak(pBar.Index());
double pVale = fimaHelper.GetVale(pBar.Index());
int samePeaks = fimaHelper.CountSamePeaks(pBar.Index());
int sameVales = fimaHelper.CountSameVales(pBar.Index());
fimaHelper.FindLastPeakOverLast(lastPeakOverLastIDX, pBar.Index());
fimaHelper.FindLastValeUnderLast(lastValeUnderLastIDX, pBar.Index());
int samePeaks = fimaParser.CountSamePeaks(pBar.Index());
int sameVales = fimaParser.CountSameVales(pBar.Index());
fimaParser.FindLastPeakOverLast(lastPeakOverLastIDX, pBar.Index());
fimaParser.FindLastValeUnderLast(lastValeUnderLastIDX, pBar.Index());
//
// Reading pBar Patterns ...
@@ -1040,7 +1095,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
hasBullishInside &&
isPullbackBullish &&
isPBarHasBullishPatterns &&
fimaHelper.IsSarBullish(pBar.Index()) &&
fimaParser.IsSARBullish(pBar.Index()) &&
(pVale >= affectedZonesBullish[insideBullishIDX].lower &&
pVale <= affectedZonesBullish[insideBullishIDX].upper)
//
@@ -1052,7 +1107,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
hasBearishInside &&
isPullbackBearish &&
isPBarHasBearishPatterns &&
fimaHelper.IsSarBearish(pBar.Index()) &&
fimaParser.IsSARBearish(pBar.Index()) &&
(pPeak >= affectedZonesBearish[insideBearishIDX].lower &&
pPeak <= affectedZonesBearish[insideBearishIDX].upper)
//
@@ -1064,24 +1119,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
isBearish;
if (result)
{
//
if (isBullish)
{
//
poiDrawer.DrawZone(
affectedZonesBullish[insideBullishIDX],
structureDrawConfig.drawConfig //
);
}
else
{
//
poiDrawer.DrawZone(
affectedZonesBearish[insideBearishIDX],
structureDrawConfig.drawConfig //
);
}
//
dir =
isBullish
@@ -1238,10 +1275,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
double pVale = fimaHelper.GetVale(pBar.Index());
double p2Peak = fimaHelper.GetPeak(p2Bar.Index());
double p2Vale = fimaHelper.GetVale(p2Bar.Index());
bool isPPeakOverLast = fimaHelper.IsPeakOverLast(pBar.Index());
bool isPValeUnderLast = fimaHelper.IsValeUnderLast(pBar.Index());
bool isP2PeakOverLast = fimaHelper.IsPeakOverLast(p2Bar.Index());
bool isP2ValeUnderLast = fimaHelper.IsValeUnderLast(p2Bar.Index());
bool isPPeakOverLast = fimaParser.IsPeakOverLast(pBar.Index());
bool isPValeUnderLast = fimaParser.IsValeUnderLast(pBar.Index());
bool isP2PeakOverLast = fimaParser.IsPeakOverLast(p2Bar.Index());
bool isP2ValeUnderLast = fimaParser.IsValeUnderLast(p2Bar.Index());
bool isPeakOverLast = isPPeakOverLast ||
isP2PeakOverLast;
bool isValeUnderLast = isPValeUnderLast ||
@@ -1473,7 +1510,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
// XFIMA Consolidation ...
//
bool isConsolidation = fimaHelper.HasPVConsolidationZone(
bool isConsolidation = poiDetector.DetectPVConsolidationZone(
zone,
pBar.Index(),
true, // Force PV Break ...
@@ -1707,12 +1744,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
result = isBullish ||
isBearish;
if (result)
{
//
poiDrawer.DrawZones(orderFlow, structureDrawConfig.drawConfig);
Print("OrderFlow Detected ...");
}
//
isBullish =
File diff suppressed because it is too large Load Diff
@@ -702,79 +702,6 @@ class XCXFIMAPOIDrawer : public XCPOIDrawer
}
}
/**
* Draw Specified Market Structure Based on Given Configs ...
*
* @param structure: XFIMAMarketStructure, reference to Provide Specifid Market Structure ...
* @param config: XFIMAMarketStructureDrawerConfig, reference to Provide Drawing Configurations ...
*/
void DrawMarketStructure(
XFIMAMarketStructure &structure,
XFIMAMarketStructureDrawerConfig &config //
)
{
//
// Validate ...
bool has = structure.IsValid();
if (!has)
{
return;
}
//
// PV Analysis ...
if (config.drawPVAnalysis)
{
//
has = structure.pvAnalysis.IsValid();
if (has)
{
//
DrawPivotAnalysis(
structure.pvAnalysis,
config.pivotAnalysisDrawConfig //
);
}
}
//
// ZG Analysis ...
if (config.drawZGAnalysis)
{
//
has = structure.zgAnalysis.IsValid();
if (has)
{
//
DrawPivotAnalysis(
structure.zgAnalysis,
config.pivotAnalysisDrawConfig //
);
}
}
//
// Bars Analysis ...
if (config.drawBarsAnalysis)
{
//
int count = ArraySize(structure.barsAnalysis);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
DrawPatternAnalysis(
structure.barsAnalysis[i],
config.barAnalysisDrawConfig //
);
}
}
}
}
//
};
+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 ...