/////////////////////////////////////////////////////// // // 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: // // }; //