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:
+5582
-463
File diff suppressed because it is too large
Load Diff
@@ -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
@@ -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:
|
||||
//
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user