/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class // ------------------------------------------------- // Name: XCXFIMASignaller ... // Description: XFIMA Signaller 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 Signaller Class" #property strict // // Imports ... #include "../../Classes/x-saherelm.x-signaller.class.mq5" #include "../../Helpers/x-saherelm.xfima.helper.mq5" #include "../Classes/x-saherelm.xfima.x-poi.detector.class.mq5" #include "../Classes/x-saherelm.xfima.x-poi.drawer.class.mq5" // // Implementation ... // // Base XFIMA base Signaller ... class XCXFIMABaseSignaller : public XCBaseSignaller { // // Public ... public: // // Props ... // bool ignoreTargets; // Ignore Signal Targets ... CArrayObj drawnObjects; // Drawing Objects Holder ... XFIMAInputs fimaInputs; // XFIMA Inputs ... XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ... XCXFIMAPOIDrawer *poiDrawer; // XFIMA POI Drawer ... XCXFIMAPOIDetector *poiDetector; // XFIMA POI Detector ... XFIMAMarketStructureConfig structureConfig; // XFIMA Market Structure Detector Config ... XFIMAMarketStructureDrawerConfig structureDrawConfig; // XFIMA Market Structure Draw Config ... // // Constructor ... XCXFIMABaseSignaller( string _name, // Name ... string _symbol, // Symbol ... ENUM_TIMEFRAMES _period, // Period ... XFIMAInputs &_fimaInputs, // XFIMAInputs ... bool _processAllTicks = false, // Process All Ticks ... double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ... double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ... double _defaultSignalVolume = 0.01 // Default Signal Volume ... ) : XCBaseSignaller(_name, _symbol, _period, _processAllTicks, _defaultSignalR2R, _defaultSignalRiskInPoint, _defaultSignalVolume // ) { // // Instantiating XFIMA Indicator Helper Class ... if (_fimaInputs.IsValid()) { // fimaHelper = new XCXFIMAHelper(); bool isInited = fimaHelper.Init( _symbol, _period, _fimaInputs // ); if (isInited) { fimaInputs = _fimaInputs; } else { // delete fimaHelper; ZeroMemory(fimaHelper); } } // poiDrawer = new XCXFIMAPOIDrawer(); poiDetector = new XCXFIMAPOIDetector(fimaHelper); // // Configure ... structureConfig.Default(); structureDrawConfig.Default(); } // // Deconstructor ... ~XCXFIMABaseSignaller() { Destroy(); } // // Overrides ... // // Actions ... /** * Destroy ... */ void Destroy() { // BeforeDestroy(); // fimaInputs.Clean(); // delete fimaHelper; ZeroMemory(fimaHelper); // delete poiDrawer; ZeroMemory(poiDrawer); // delete poiDetector; ZeroMemory(poiDetector); // structureConfig.Clean(); structureDrawConfig.Clean(); } // // Virtuals ... /** * Before Destroy ... */ void virtual BeforeDestroy() { } /** * Processing Tick ... * * @param barIndex: int, Specified Bar Index ... */ virtual void ProcessTick(int barIndex = 0) { } /** * Processing New Bar ... * * @param barIndex: int, Specified Bar Index ... */ virtual void ProcessNewBar(int barIndex = 0) { } /** * Check Guards Based on MarketConditions ... * * @param guards: XGuard, reference collection to holds result ... * @param positions: XPosition, reference collection to provides positions ... * @param barIndex: int * * @return ( int ) */ int virtual CheckForGuard( XGuard &guards[], XPosition &positions[], int barIndex = 0 // ) { // int result = 0; // SpecifiedClean(guards); // result = ArraySize(guards); // return result; } /** * Check Additional Validations on Childs Instances ... * * @return ( bool virtual ) */ bool virtual CheckAdditionslSignallerValidations() { // bool result = false; // // Validate Fima Helper Requirements ... result = fimaInputs.IsValid() && fimaHelper != NULL && poiDetector != NULL; // return result; } /** * Normalizing Signal by Signaller Custom Props ... * * @param signal: XSignal ... */ void virtual NormalizeSignal(XSignal &signal) { } // // Protected ... protected: // // // Protected Actions ... // // Private ... private: // }; // // XFIMA Strategy 2 Signaller Class ... class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller { // // Public ... public: // // Props ... XFIMAMarketStructure structure; // XFIMA Market Structure ... // // Constructor ... XCXFIMAStrategy1Signaller( string _symbol, // Symbol ... ENUM_TIMEFRAMES _period, // Period ... XFIMAInputs &_fimaInputs, // XFIMAInputs ... bool _processAllTicks = false, // Process All Ticks ... double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ... double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ... double _defaultSignalVolume = 0.01 // Default Signal Volume ... ) : XCXFIMABaseSignaller("XFIMA1", _symbol, _period, _fimaInputs, _processAllTicks, _defaultSignalR2R, _defaultSignalRiskInPoint, _defaultSignalVolume // ) { // // Configure ... structureConfig.Default(); structureDrawConfig.Default(); // structure.Clean(); // // Ignore Signal Targets ... ignoreTargets = true; } // // Deconstructor ... ~XCXFIMAStrategy1Signaller() { // Destroy(); // structure.Clean(); } // // Overrides ... /** * Processing Tick ... * * @param barIndex: int, Specified Bar Index ... */ virtual void ProcessTick(int barIndex = 0) { } /** * Processing New Bar ... * * @param barIndex: int, Specified Bar Index ... */ virtual void ProcessNewBar(int barIndex = 0) { // // Normalize ... barIndex = NormalizeInt(barIndex, 0); // XOHCL iBar; int count = 0; XBoxZone iZone; XSignal iSignal; bool has = false; XTarget iTargets[]; string iName = NULL; bool isBullish = false; bool isBearish = false; XPatternAnalysis iBarAnalysis; XFIMAConditions iFIMAConditions; XFIMAMarketStructure iStructure; ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; // // Initialize Bar as CBar ... has = iBar.Init( symbol, period, barIndex // ); if (!has) { // iBar.Clean(); return; } // // Retrieve Conditions ... has = fimaHelper.GetConditions( iFIMAConditions, barIndex, 10 // Loopback ... ); if (!has) { // iBar.Clean(); iFIMAConditions.Clean(); // return; } // structure.Clean(); poiDetector.AnalyseMarket( structure, structureConfig, barIndex // ); poiDrawer.drawnObjects.Clear(); poiDrawer.DrawMarketStructure( structure, structureDrawConfig // ); // // Disable Signallers ... has = false; iDir = X_DIRECTION_NONE; // // Strategy 1 ... // Works on Support or Resistances Areas ... // has = Strategy1HasSignal( // iBar, // iZone, // iTargets, // iDir, // iFIMAConditions, // iStructure // // ); // // Strategy 2 ... // Works on MA Crosses ... if (!has) { // // has = Strategy2HasSignal( // iBar, // iZone, // iTargets, // iDir, // iFIMAConditions, // iStructure // // ); } // has = HasDirection(iDir); if (has) { // isBullish = IsXBullish(iDir); isBearish = IsXBearish(iDir); // // TODO: Provided SL ... double _point = GetPoints(iBar.symbol); double slAddition = 5 * _point; double slPrice = isBullish ? iZone.lower - slAddition : iZone.upper + slAddition; // // Prepare Founded Signal ... // // Handle Signal Targets ... if (ignoreTargets) { XClean(iTargets); } // has = PrepareSignal( iSignal, iDir, iTargets, 0, // Use Default R2R ... slPrice, // Provided Price for SL ... 0 // Specified Risk in Point .... ); if (has) { // // Notify On Signal Event ... NotifySignalEventListeners(iSignal); } } // // Cleanup Resources ... iBar.Clean(); iZone.Clean(); iSignal.Clean(); iStructure.Clean(); iBarAnalysis.Clean(); iFIMAConditions.Clean(); SpecifiedClean(iTargets); } /** * Check Guards Based on MarketConditions ... * * @param guards: XGuard, reference collection to holds result ... * @param positions: XPosition, reference collection to provides positions ... * @param barIndex: int * * @return ( int ) */ int virtual CheckForGuard( XGuard &guards[], XPosition &positions[], int barIndex = 0 // ) { // int result = 0; // SpecifiedClean(guards); // result = ArraySize(guards); // return result; } // // Private ... private: // // Props ... // // Implementing Strategies ... /** * Check Bar Has Signal Based on Strategy 1 ... * * @param bar: XOHCL, reference to Bar ... * @param zone: XBoxZone, reference to holds affected zone ... * @param targets: XTarget, reference to detected Signal's Targets collections ... * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... * @param conditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... * * @return ( bool ) */ bool Strategy1HasSignal( XOHCL &bar, XBoxZone &zone, XTarget &targets[], ENUM_X_DIRECTION &dir, XFIMAConditions &conditions, XFIMAMarketStructure &_structure // ) { // bool result = false; // // Prepare ... zone.Clean(); XClean(targets); dir = X_DIRECTION_NONE; // // Validate ... result = bar.IsValid(); if (!result) { return result; } // // Prepare zone ... if (result) { // zone.to = bar.time; zone.from = GetBarTime( bar.symbol, bar.period, bar.Index() + 2 // ); zone.symbol = bar.symbol; zone.period = bar.period; // zone.dir = structure.maCrossDir; zone.lower = bar.FindLowest(2, MODE_LOW); zone.upper = bar.FindHighest(2, MODE_HIGH); // zone.type = name + "_" + ToXString(structure.maCrossDir); // result = zone.IsValid(); } // // Check Result ... if (result) { // // dir = structure.maCrossDir; // // Handle Targets Detection ... } // // Cleanup Resources ... if (!result) { // zone.Clean(); XClean(targets); } // return result; } /** * Check Bar Has Signal Based on Strategy 1 ... * * @param bar: XOHCL, reference to Bar ... * @param zone: XBoxZone, reference to holds affected zone ... * @param targets: XTarget, reference to detected Signal's Targets collections ... * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... * @param conditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... * * @return ( bool ) */ bool Strategy2HasSignal( XOHCL &bar, XBoxZone &zone, XTarget &targets[], ENUM_X_DIRECTION &dir, XFIMAConditions &conditions, XFIMAMarketStructure &_structure // ) { // bool result = false; // // Prepare ... zone.Clean(); XClean(targets); dir = X_DIRECTION_NONE; // // Validate ... result = bar.IsValid(); if (!result) { return result; } // // Detect Specified MA Cross ... // result = HasDirection(structure.maCrossDir); // // Prepare zone ... if (result) { // zone.to = bar.time; zone.from = GetBarTime( bar.symbol, bar.period, bar.Index() + 2 // ); zone.symbol = bar.symbol; zone.period = bar.period; // zone.dir = structure.maCrossDir; zone.lower = bar.FindLowest(2, MODE_LOW); zone.upper = bar.FindHighest(2, MODE_HIGH); // zone.type = name + "_" + ToXString(structure.maCrossDir); // result = zone.IsValid(); } // // Check Result ... if (result) { // // dir = structure.maCrossDir; // // Handle Targets Detection ... } // // Cleanup Resources ... if (!result) { // zone.Clean(); XClean(targets); } // return result; } // }; //