From b5003968bc286298766b26bdaabb298de8abd109 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 29 Dec 2024 17:55:52 +0330 Subject: [PATCH] cleanup workspace ... --- .../1/x-121.smc.market.cycle.helper.class.mq5 | 2466 ------- .../BKP/1/x-121.smc.test.signal.class.mq5 | 831 --- .../BKP/1/x-121.smc.test.strategy.class.mq5 | 2088 ------ Documents/BKP/1/x.oepv.tmp.mq5 | 75 - Documents/BKP/2/x-test-signal.smc.mq5 | 830 --- .../3/x-smc.signal.conditions.detector.mq5 | 6565 ----------------- Documents/BKP/3/x-smc.signal.detectors.mq5 | 911 --- Documents/BKP/4/tmp.parent.child.pivot.mq5 | 852 --- Documents/BKP/4/tmp.pivot.draws.mq5 | 73 - .../BKP/5/x-121.smc.xoepv.signal.lib.mq5 | 1058 --- .../BKP/5/x-121.smc.xpvdp.signal.lib.mq5 | 995 --- .../BKP/5/x-121.smc.xpvob.signal.lib.mq5 | 1695 ----- .../BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 | 1239 ---- .../BKP/5/x-121.smc.xvwpb.signal.lib.mq5 | 1113 --- Documents/BKP/temp.supres.found.smc.mq5 | 297 - Documents/BKP/x-121.smc.test.signal.class.mq5 | 787 -- 16 files changed, 21875 deletions(-) delete mode 100644 Documents/BKP/1/x-121.smc.market.cycle.helper.class.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.test.signal.class.mq5 delete mode 100644 Documents/BKP/1/x-121.smc.test.strategy.class.mq5 delete mode 100644 Documents/BKP/1/x.oepv.tmp.mq5 delete mode 100644 Documents/BKP/2/x-test-signal.smc.mq5 delete mode 100644 Documents/BKP/3/x-smc.signal.conditions.detector.mq5 delete mode 100644 Documents/BKP/3/x-smc.signal.detectors.mq5 delete mode 100644 Documents/BKP/4/tmp.parent.child.pivot.mq5 delete mode 100644 Documents/BKP/4/tmp.pivot.draws.mq5 delete mode 100644 Documents/BKP/5/x-121.smc.xoepv.signal.lib.mq5 delete mode 100644 Documents/BKP/5/x-121.smc.xpvdp.signal.lib.mq5 delete mode 100644 Documents/BKP/5/x-121.smc.xpvob.signal.lib.mq5 delete mode 100644 Documents/BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 delete mode 100644 Documents/BKP/5/x-121.smc.xvwpb.signal.lib.mq5 delete mode 100644 Documents/BKP/temp.supres.found.smc.mq5 delete mode 100644 Documents/BKP/x-121.smc.test.signal.class.mq5 diff --git a/Documents/BKP/1/x-121.smc.market.cycle.helper.class.mq5 b/Documents/BKP/1/x-121.smc.market.cycle.helper.class.mq5 deleted file mode 100644 index be6dad69..00000000 --- a/Documents/BKP/1/x-121.smc.market.cycle.helper.class.mq5 +++ /dev/null @@ -1,2466 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XC121SMCCycleHelper -// Description: provides all based classes for use ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../../Classes/x-saherelm.x-poi.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... - -// -// Implementations ... - -enum ENUM_X_CYCLES -{ - X_CYCLE_TRIGGER, - X_CYCLE_DECISION, - X_CYCLE_ANALYSE, - X_CYCLE_VERIFICATION, - X_CYCLE_CONSOLIDATION, - X_CYCLE_VISION, -}; - -enum ENUM_X_CYCLE_EVENTS -{ - SAR_CHANGE_DETECTED, - NEW_PEAK_DETECTED, - NEW_VALE_DETECTED, - PIVOT_POINT_DETECTED, - VWAP_ORDER_CHANGE_ETECTED, - VWAP_STATE_CHANGE_DETCTED, - CONSOLIDATION_BREAKED_DETECTED, - PIVOT_STARTED, - PIVOT_ENDED, -}; - -class XC121SMCCycleHelper : public XCBase -{ - // - public: - // - // Props ... - - // - // X121 ... - XCX121Helper *mX121Helper; - - // - // POI Detector ... - XCPOIDetector *mPOIDetector; - - // - // Bar Analyser - XCBarAnalyser *mBarAnalyser; - - // - // Constructor(s) ... - XC121SMCCycleHelper() - { - Default(); - } - - // - // Deconstructor ... - ~XC121SMCCycleHelper() - { - DeInit(); - } - - // - // Getter/Setter(s) ... - - /** - * Get Max llowed Changes to Save ... - * - * @return ( int ) - */ - int MaxAllowedSavedChanges() - { - return mMaxAllowedSavedChanges; - } - - /** - * Set Max llowed Changes to Save ... - * - * @param value: Integer ... - */ - void MaxAllowedSavedChanges(int value) - { - // - if (value < 10) - { - value = 10; - } - - // - mMaxAllowedSavedChanges = value; - } - - /** - * Get Consolidation Loopback Length ... - * - * @return ( int ) - */ - int ConsolidationLoopback() - { - return mConsolidationLoopback; - } - - /** - * Set Consolidation Loopback Length ... - * - * @param value: Integer ... - */ - void ConsolidationLoopback(int value) - { - // - if (value < 7) - { - value = 7; - } - - // - mConsolidationLoopback = value; - } - - // - // Actions ... - - /** - * Initialize ... - * - * @param symbol: String ... - * @param period: ENUM_TIMEFRAMES member ... - * @param x121Inputs: X121Inputs instance ... - * - * @return ( bool ) - */ - bool Init( - string symbol, - ENUM_TIMEFRAMES period, - X121Inputs &x121Inputs // - ) - { - // - bool result = false; - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - return result; - } - - // - // X121 ... - mX121Helper = new XCX121Helper(); - result = mX121Helper.Init( - symbol, - period, - x121Inputs // - ); - if (!result) - { - return result; - } - - // - mPOIDetector = new XCPOIDetector( - symbol, - period // - ); - mPOIDetector.MaxNumberOfRequiredPOIs(0); - mPOIDetector.Init(); - - // - // Initialize Bar Analyser Class Instance ... - mBarAnalyser = new XCBarAnalyser(); - - // - // Set Chart Style ... - ApplyChartStyle(); - - // - return result; - } - - /** - * Retrieve Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - // - string result = NULL; - - // - result = mX121Helper.GetSymbol(); - - // - return result; - } - - /** - * Retrieve TimeFrame (Period) ... - * - * @return ( ENUM_TIMEFRAMES ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - // - ENUM_TIMEFRAMES result = NULL; - - // - result = mX121Helper.GetPeriod(); - - // - return result; - } - - /** - * Get Specified Bar ... - * - * @param source: XOHCL instance, Source Bar ... - * @param bar: XOHCL instance, Dest Bar ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &source, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = - IsValid(symbol) && - IsValid(period) && - source.IsValid(); - if (!result) - { - return result; - } - - // - int index = iBarShift( - symbol, - period, - source.time // - ); - result = bar.Init( - symbol, - period, - index // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - return result; - } - - /** - * Retrieve Specified Bar ... - * - * @param bar: XOHCL instance ... - * @param index: Integer ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &bar, - int index = 0 // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (index < 0) - { - index = 0; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = bar.Init( - symbol, - period, - index // - ); - - // - return result; - } - - /** - * Retrieve Specified Bar ... - * - * @param bar: XOHCL instance ... - * @param time: Datetime ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &bar, - datetime time = NULL // - ) - { - // - bool result = false; - - // - int index = GetBarIndex(time); - result = GetBar(bar, - index // - ); - - // - return result; - } - - /** - * Retrieve Specified Time Bar Index ... - * - * @param time: DateTime ... - * - * @return ( int ) - */ - int GetBarIndex(datetime time = NULL) - { - // - int result = -1; - - // - time = NormalizeTime(time); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = iBarShift( - symbol, - period, - time // - ); - - // - return result; - } - - /** - * Retrieve Cycle Conditions ... - * - * @param events: ENUM_X_CYCLE_EVENTS member, Array ... - * @param conditions: X121SMCCycleConditions instance ... - * @param barIndex: Integer ... - * @param loopback: Integer ... - * - * @return ( bool ) - */ - bool GetConditions( - ENUM_X_CYCLE_EVENTS &events[], - ENUM_XPOI_EVENTS &poiEvents[], - X121SMCCycleConditions &conditions, - int barIndex = 0, - int loopback = 7 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 5) - { - loopback = 5; - } - - // - Clean(events); - Clean(poiEvents); - conditions.Clean(); - - // - result = mX121Helper.GetConditions( - conditions.x121Conditions, - barIndex, - loopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - mPOIDetector.Update(poiEvents); - mPOIDetector.GetState(conditions.state); - - // - conditions.symbol = conditions.x121Conditions.symbol; - conditions.period = conditions.x121Conditions.period; - conditions.time = TimeCurrent(); - - // - result = conditions.IsValid(); - - // - if (result) - { - // - Calculate( - barIndex, - events, - conditions // - ); - } - - // - return result; - } - - // - // Tools ... - - /** - * Detect Pivot ... - * - * @return ( bool ) - */ - bool DetectPivot( - XPVPivot &pivot, - XOHCL &bar // - ) { - // - bool result = false; - - // - XOHCL cBar; - result = GetBar(bar, cBar); - if (!result) { - return result; - } - - // - int start = cBar.Index(); - double peak = mX121Helper.GetPeak(start); - double vale = mX121Helper.GetVale(start); - bool canContinue = true; - while (canContinue) { - // - - } - - // - return result; - } - - /** - * Get POI State of Specified Pivot ... - * - * @param pivot: XPVPivot instance Reference ... - * @param lookupSwingHighs: Boolean ... - * @param lookupSwingLows: Boolean ... - * @param lookupSupportZones: Boolean ... - * @param lookupResistanceZones: Boolean ... - * @param lookupSupplyZones: Boolean ... - * @param lookupDemandZones: Boolean ... - * @param lookupBullishOrderBlocks: Boolean ... - * @param lookupBearishOrderBlocks: Boolean ... - * @param lookupBullishFairValueGaps: Boolean ... - * @param lookupBearishFairValueGaps: Boolean ... - * @param lookupBullishRejectionBars: Boolean ... - * @param lookupBearishRejectionBars: Boolean ... - * @param lookupBullishMomentumBars: Boolean ... - * @param lookupBearishMomentumBars: Boolean ... - * - * @return ( bool ) - */ - bool FillPivotState( - XPVPivot &pivot, - bool lookupSwingHighs = true, - bool lookupSwingLows = true, - bool lookupSupportZones = true, - bool lookupResistanceZones = true, - bool lookupSupplyZones = true, - bool lookupDemandZones = true, - bool lookupBullishOrderBlocks = true, - bool lookupBearishOrderBlocks = true, - bool lookupBullishFairValueGaps = true, - bool lookupBearishFairValueGaps = true, - bool lookupBullishRejectionBars = true, - bool lookupBearishRejectionBars = true, - bool lookupBullishMomentumBars = true, - bool lookupBearishMomentumBars = true // - ) - { - // - bool result = false; - - // - XPOIState state; - state.Clean(); - - // - result = pivot.IsValid(); - if (!result) - { - return result; - } - - // - XPOIState _state; - mPOIDetector.GetState(_state); - result = _state.IsValid() && - _state.HasChild(); - if (!result) - { - return result; - } - - // - DetectPivotPOIs( - pivot, - _state, - state, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - result = state.IsValid() && - state.HasChild(); - if (result) - { - // - pivot.state = state; - - // - CalculatePivotTickZone(pivot); - } - - // - return result; - } - - /** - * Detect XPV Based POI(s) ... - * - * @param barIndex: Start Bar Index ... - * @param minRepetition: minimum Repeate of POI for Validation ... - * @param requiredPivots: Number of Min Requirement POI(s) ... - * @param pivotHelper: XC121SMCCycleHelper instance Pointer ... - * @param orderFlow: XPVPivot instance Array Reference ... - * @param orderFlowDirection: ENUM_X_DIRECTION member Reference which represents OrderFlow Direction ... - * @param maxAllowedLoopbackBars: Integer, Max Allowed Loopback Bars ... - * - * @return ( bool ) - */ - bool DetectOrderFlow( - int barIndex, - XPVPivot &orderFlow[], // OrderFlows ... - ENUM_X_DIRECTION &orderFlowDirection, // Order Flow Direction ... - int minRepetition = 0, - int requiredPivots = 0, - int maxAllowedLoopbackBars = 576 // - ) - { - // - bool result = false; - - // - orderFlowDirection = X_DIRECTION_NONE; - - // - if (maxAllowedLoopbackBars <= 0) - { - maxAllowedLoopbackBars = 1000; - } - - // - if (minRepetition <= 0) - { - minRepetition = mX121Helper.GetDonChainLength(); - } - - // - if (requiredPivots <= 0) - { - requiredPivots = 3; - } - - // - int start = barIndex; - int end = start + maxAllowedLoopbackBars; - - // - Clean(orderFlow); - - // - result = minRepetition > 0 && - requiredPivots > 0; - if (!result) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - double peak = 0; - XPVPivot peaks[]; - int peakRepeate = 0; - int peakToBarIndex = 0; - int peakFromBarIndex = 0; - - // - double vale = 0; - XPVPivot vales[]; - int valeRepeate = 0; - int valeToBarIndex = 0; - int valeFromBarIndex = 0; - - // - bool canLookupPeak = true; - bool canLookupVale = true; - bool canLookup = true; - while (canLookup) - { - // - // Check Peak ... - double iPeak = mX121Helper.GetPeak(barIndex); - if (iPeak != peak) - { - // - if (peak != 0 && - peakRepeate >= minRepetition) - { - // - bool isExists = false; - int count = ArraySize(peaks); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XPVPivot iPivot = peaks[i]; - - // - if (iPivot.upper == iPeak) - { - // - isExists = true; - break; - } - } - } - if (!isExists) - { - // - XPVPivot iPivot; - - // - iPivot.lower = 0; - iPivot.upper = peak; - iPivot.symbol = symbol; - iPivot.period = period; - iPivot.type = XPV_PEAK; - iPivot.repetition = peakRepeate; - iPivot.to = iTime( - symbol, - period, - peakToBarIndex // - ); - iPivot.from = iTime( - symbol, - period, - peakFromBarIndex // - ); - - // - iPivot.lower = iPivot.CalculateLower(); - - // - bool isValid = iPivot.IsValid(); - if (isValid) - { - // - AddRef( - iPivot, - peaks // - ); - } - } - } - - // - peak = iPeak; - peakRepeate = 0; - peakFromBarIndex = 0; - peakToBarIndex = barIndex; - } - else if (iPeak == peak) - { - // - peakRepeate++; - peakFromBarIndex = barIndex; - } - - // - // Check Vale ... - double iVale = mX121Helper.GetVale(barIndex); - if (iVale != vale) - { - // - if (vale != 0 && - valeRepeate >= minRepetition) - { - // - bool isExists = false; - int count = ArraySize(vales); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XPVPivot iPivot = vales[i]; - - // - if (iPivot.lower == iVale) - { - // - isExists = true; - break; - } - } - } - if (!isExists) - { - // - XPVPivot iPivot; - - // - iPivot.upper = 0; - iPivot.lower = vale; - iPivot.symbol = symbol; - iPivot.period = period; - iPivot.type = XPV_VALE; - iPivot.repetition = valeRepeate; - iPivot.to = iTime( - symbol, - period, - valeToBarIndex // - ); - iPivot.from = iTime( - symbol, - period, - valeFromBarIndex // - ); - - // - iPivot.upper = iPivot.CalculateUpper(); - - // - bool isValid = iPivot.IsValid(); - if (isValid) - { - // - AddRef( - iPivot, - vales // - ); - } - } - } - - // - vale = iVale; - valeRepeate = 0; - valeFromBarIndex = 0; - valeToBarIndex = barIndex; - } - else if (iVale == vale) - { - // - valeRepeate++; - valeFromBarIndex = barIndex; - } - - // - canLookupPeak = ArraySize(peaks) < requiredPivots; - canLookupVale = ArraySize(vales) < requiredPivots; - canLookup = barIndex < end && - (canLookupPeak || - canLookupVale); - if (canLookup) - { - barIndex++; - } - } - - // - result = IsValidSize(ArraySize(peaks)) || - IsValidSize(ArraySize(vales)); - if (!result) - { - return result; - } - - // - // Detect Order Flow ... - Copy( - peaks, - orderFlow, - false // - ); - Copy( - vales, - orderFlow, - false // - ); - int count = ArraySize(orderFlow); - result = IsValidSize(orderFlow); - if (!result) - { - return result; - } - - // - // Sort Pivots ... - SortPivots(orderFlow); - - // - // Filter Broken Order Flows ... - FilterBrokenPivots(orderFlow); - - // - // Detect Order Flow Direction ... - result = DetectPivotDirection( - orderFlow, - orderFlowDirection // - ); - if (!result) - { - return result; - } - - // - return result; - } - - // - // Change Values Actions ... - - /** - * Count Saved Parabolic Sar Changes ... - * - * @return ( int ) - */ - int CountSarChanges() - { - return ArraySize(mSarChanges); - } - - /** - * Fill Saved Sar Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillSarChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mSarChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last Sar Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastSarChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mSarChanges // - ); - - // - return result; - } - - /** - * Count Saved Peaks Changes ... - * - * @return ( int ) - */ - int CountPeaksChanges() - { - return ArraySize(mPeaksChanges); - } - - /** - * Fill Saved Peaks Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillPeaksChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mPeaksChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last Peak Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastPeakChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mPeaksChanges // - ); - - // - return result; - } - - /** - * Count Saved Vales Changes ... - * - * @return ( int ) - */ - int CountValesChanges() - { - return ArraySize(mValesChanges); - } - - /** - * Fill Saved Vales Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillValesChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mValesChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last Vale Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastValeChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mValesChanges // - ); - - // - return result; - } - - /** - * Count Saved VWap Order Changes ... - * - * @return ( int ) - */ - int CountVWapOrderChanges() - { - return ArraySize(mVWapOrderChanges); - } - - /** - * Fill Saved VWap Order Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillVWapOrderChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mVWapOrderChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last VWap Order Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastVWapOrderChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mVWapOrderChanges // - ); - - // - return result; - } - - /** - * Count Saved VWap State Changes ... - * - * @return ( int ) - */ - int CountVWapStateChanges() - { - return ArraySize(mVWapStateChanges); - } - - /** - * Fill Saved VWap State Changes ... - * - * @param changes: XValueChange instance Array Reference ... - * - * @return ( int ) - */ - int FillVWapStateChanges( - XValueChange &changes[] // - ) - { - // - Clean(changes); - - // - Copy( - mVWapStateChanges, - changes // - ); - - // - int result = ArraySize(changes); - - // - return result; - } - - /** - * Retrieve Last VWap State Changes ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastVWapStateChange(XValueChange &change) - { - // - bool result = false; - - // - result = GetLastItem( - change, - mVWapStateChanges // - ); - - // - return result; - } - - /** - * Count Founded Consolidation Zones ... - * - * @return ( int ) - */ - int CountConsolidationZones() - { - return ArraySize(mConsolidationZones); - } - - /** - * Fill Broken Consolidations ... - * - * @param consolidations: XConsolidationZone instance Array Reference ... - * - * @return ( int ) - */ - int FillConsolidationZones( - XConsolidationZone &consolidations[] // - ) - { - // - Clean(consolidations); - - // - Copy( - mConsolidationZones, - consolidations // - ); - - // - int result = ArraySize(consolidations); - - // - return result; - } - - /** - * Retrieve Last Consolidation Breaks ... - * - * @param change: XValueChange instance ... - * - * @return ( bool ) - */ - bool GetLastConsolidationZone(XConsolidationZone &zone) - { - // - bool result = false; - - // - result = GetLastItem( - zone, - mConsolidationZones // - ); - - // - return result; - } - - /** - * Count Pivot Points Change ... - * - * @return ( int ) - */ - int CountPivotPoints() - { - return ArraySize(mPivotPoints); - } - - /** - * Retrieve All Pivot Point Changes as a Collection ... - * - * @param pivots: XPVPivotPoint instance Reference ... - * - * @return ( int ) - */ - int FillPivotPointss(XPVPivotPoint &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = CountPivotPoints(); - if (!IsValidSize(pivots)) - { - return result; - } - - // - Copy( - mPivotPoints, - pivots // - ); - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Retrieve All Peak Pivot Point Changes as a Collection ... - * - * @param pivots: XPVPivotPoint instance Reference ... - * - * @return ( int ) - */ - int FillPeakPivotPoints(XPVPivotPoint &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = CountPivotPoints(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XPVPivotPoint iPivot = mPivotPoints[i]; - - // - bool isValid = iPivot.IsPeak(); - if (isValid) - { - // - AddRef( - iPivot, - pivots // - ); - } - } - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Retrieve All Vale Pivot Point Changes as a Collection ... - * - * @param pivots: XPVPivotPoint instance Reference ... - * - * @return ( int ) - */ - int FillValePivotPoints(XPVPivotPoint &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = CountPivotPoints(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XPVPivotPoint iPivot = mPivotPoints[i]; - - // - bool isValid = iPivot.IsVale(); - if (isValid) - { - // - AddRef( - iPivot, - pivots // - ); - } - } - - // - result = ArraySize(pivots); - - // - return result; - } - - /** - * Get Current Active Pivot ... - * - * @param pivot: XPVPivot instance reference ... - */ - void GetActivePivot(XPVPivot &pivot) - { - // - mActivePivot.to = TimeCurrent(); - pivot = mActivePivot; - } - - /** - * Count Calculated Pivots ... - * - * @return ( int ) - */ - int CountPivots() - { - return ArraySize(mPivots); - } - - /** - * Fill Pivots ... - * - * @param pivots: XPVPivot instance Reference Array ... - * - * @return ( int ) - */ - int FillPivots(XPVPivot &pivots[]) - { - // - int result = 0; - - // - Clean(pivots); - - // - Copy( - mPivots, - pivots // - ); - - // - result = ArraySize(pivots); - - // - return result; - } - - // - // Virtuals ... - - /** - * Set Default Properties Values ... - */ - virtual void Default() - { - // - ConsolidationLoopback(10); - MaxAllowedSavedChanges(50); - } - - // - protected: - // - - /** - * Calculate Requirements ... - * - * @param barIndex: Integer, Bar Index ... - * @param events: ENUM_X_CYCLE_EVENTS member, Array ... - * @param conditions: X121SMCCycleConditions instance ... - */ - void Calculate( - int barIndex, - ENUM_X_CYCLE_EVENTS &events[], - X121SMCCycleConditions &conditions // - ) - { - // - Clean(events); - - // - string symbol = GetSymbol(); - datetime cTime = TimeCurrent(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL changeBar; - int index = - barIndex <= 0 - ? 1 - : barIndex; - bool isInited = GetBar( - changeBar, - index // - ); - if (!isInited) - { - return; - } - - // - // Detect Sar Change ... - bool isSarSwitchedToBullish = conditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = conditions.x121Conditions.isSarSwitchedToBearish; - bool isSarChanged = isSarSwitchedToBullish || - isSarSwitchedToBearish; - - // - if (isSarChanged) - { - // - XValueChange sarChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.sarBuffer[1]; - double before = conditions.x121Conditions.sarBuffer[2]; - ENUM_X_DIRECTION dir = - isSarSwitchedToBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = sarChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddSarChange(sarChanged); - - // - Add( - SAR_CHANGE_DETECTED, - events // - ); - } - } - - // - // Detect Peaks Changes ... - - // - bool isNewPeak = conditions.x121Conditions.isNewPeak; - double peak = conditions.x121Conditions.peaksBuffer[0]; - bool isNewPeakOverLast = conditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = conditions.x121Conditions.isNewPeakUnderLast; - - // - if (isNewPeak) - { - // - XValueChange peaksChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.peaksBuffer[1]; - double before = conditions.x121Conditions.peaksBuffer[2]; - ENUM_X_DIRECTION dir = - isNewPeakOverLast - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = peaksChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddPeaksChange(peaksChanged); - - // - Add( - NEW_PEAK_DETECTED, - events // - ); - } - } - - // - // Detect Vales Changes ... - - // - bool isNewVale = conditions.x121Conditions.isNewVale; - double vale = conditions.x121Conditions.valesBuffer[0]; - bool isNewValeOverLast = conditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = conditions.x121Conditions.isNewValeUnderLast; - - // - if (isNewVale) - { - // - XValueChange valesChanged; - - // - datetime time = changeBar.time; - double after = conditions.x121Conditions.valesBuffer[1]; - double before = conditions.x121Conditions.valesBuffer[2]; - ENUM_X_DIRECTION dir = - isNewValeUnderLast - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Initialize Model ... - isInited = valesChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddValesChange(valesChanged); - - // - Add( - NEW_VALE_DETECTED, - events // - ); - } - } - - // - // VWap Direction Change ... - - // - // Ordered Change ... - bool isVWapSwitchedToBullishOrdered = - conditions.x121Conditions.isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered = - conditions.x121Conditions.isVWapSwitchedToBearishOrdered; - bool isVWAPOrderedChanged = isVWapSwitchedToBullishOrdered || - isVWapSwitchedToBearishOrdered; - // - if (isVWAPOrderedChanged) - { - // - XValueChange vwapOrderChanged; - - // - datetime time = changeBar.time; - ENUM_X_DIRECTION dir = - isVWapSwitchedToBullishOrdered - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double after = 0; - double before = 0; - if (isVWapSwitchedToBullishOrdered) - { - // - // After Max ... - after = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMax( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Min ... - before = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMin( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - else - { - // - // After Min ... - after = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMin( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Max ... - before = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMax( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - - // - // Initialize Model ... - isInited = vwapOrderChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddVWapOrderChange(vwapOrderChanged); - - // - Add( - VWAP_ORDER_CHANGE_ETECTED, - events // - ); - } - } - - // - // States Changed ... - bool isVWapSwitchedToBullishState = - conditions.x121Conditions.isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState = - conditions.x121Conditions.isVWapSwitchedToBearishState; - bool isVWapStatesChanged = isVWapSwitchedToBullishState || - isVWapSwitchedToBearishState; - - // - if (isVWapStatesChanged) - { - // - XValueChange vwapStateChanged; - - // - datetime time = changeBar.time; - ENUM_X_DIRECTION dir = - isVWapSwitchedToBullishState - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double after = 0; - double before = 0; - if (isVWapSwitchedToBullishState) - { - // - // After Max ... - after = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMax( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Min ... - before = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMin( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - else - { - // - // After Min ... - after = MathMin( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - after = MathMin( - after, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - - // - // Before Max ... - before = MathMax( - conditions.x121Conditions.vwapFastBuffer[1], - conditions.x121Conditions.vwapMidBuffer[1] // - ); - before = MathMax( - before, - conditions.x121Conditions.vwapSlowBuffer[1] // - ); - } - - // - // Initialize Model ... - isInited = vwapStateChanged.Init( - before, - after, - dir, - time // - ); - if (isInited) - { - // - isInited = AddVWapStateChange(vwapStateChanged); - - // - Add( - VWAP_STATE_CHANGE_DETCTED, - events // - ); - } - } - - // - // Detect Consolidations ... - - // - int consolidationLoopback = ConsolidationLoopback(); - if (IsValidSize(consolidationLoopback)) - { - // - double upper = 0; - double lower = 0; - bool hasConsolidation = - mBarAnalyser.IsConsolidate( - changeBar, - upper, - lower, - consolidationLoopback // - ); - - // - if (hasConsolidation && - !mActioveConsolidationZone.IsValid()) - { - // - // Initialize Consolidation Zone ... - bool isInited = mActioveConsolidationZone.Init( - changeBar.symbol, - changeBar.period, - upper, - lower, - consolidationLoopback // - ); - } - - // - if (!hasConsolidation && - mActioveConsolidationZone.IsValid()) - { - // - mActioveConsolidationZone.Update(); - bool isBreaked = mActioveConsolidationZone.IsBreaked(); - - // - if (isBreaked) - { - // - // Add Active to List ... - AddRef( - mActioveConsolidationZone, - mConsolidationZones // - ); - - // - // Clean Active Zone ... - mActioveConsolidationZone.Clean(); - - // - Add( - CONSOLIDATION_BREAKED_DETECTED, - events // - ); - } - } - } - - // - // Check Valid Peaks and Vales ... - if (isNewPeak || isNewVale) - { - // - int count = 0; - double value = 0; - int repetition = 0; - ENUM_TIMEFRAMES period = GetPeriod(); - int periodSeconds = PeriodSeconds(period); - int minRepetition = mX121Helper.GetDonChainLength(); - ENUM_XPV_PIVOTS type = isNewPeak - ? XPV_PEAK - : XPV_VALE; - - // - XValueChange lastChange; - XValueChange prevChange; - - // - count = CountPeaksChanges(); - if (isNewPeak && count >= 2) - { - // - lastChange = mPeaksChanges[count - 1]; - prevChange = mPeaksChanges[count - 2]; - } - - // - count = CountValesChanges(); - if (isNewVale && count >= 2) - { - // - lastChange = mValesChanges[count - 1]; - prevChange = mValesChanges[count - 2]; - } - - // - if (lastChange.IsValid() && - prevChange.IsValid()) - { - // - value = prevChange.after; - int delayTime = ((int)lastChange.time - (int)prevChange.time); - repetition = delayTime / periodSeconds; - - // - bool isValidPivot = repetition >= minRepetition; - if (isValidPivot) - { - // - XPVPivotPoint pivotPoint; - pivotPoint.type = type; - pivotPoint.value = value; - pivotPoint.time = prevChange.time; - pivotPoint.repetition = repetition; - - // - AddRef( - pivotPoint, - mPivotPoints // - ); - - // - Add( - PIVOT_POINT_DETECTED, - events // - ); - } - } - } - - // // - // // Calculate Pivots ... - // if (isNewPeak || isNewVale) - // { - // // - // if (!mActivePivot.IsValid()) - // { - // // - // mActivePivot.symbol = symbol; - // mActivePivot.period = period; - - // // - // mActivePivot.upper = peak; - // mActivePivot.lower = vale; - - // // - // mActivePivot.from = cTime; - // mActivePivot.to = cTime; - - // // - // mActivePivot.type = - // isNewPeak - // ? XPV_VALE - // : XPV_PEAK; - // mActivePivot.repetition++; - - // // - // Add( - // PIVOT_STARTED, - // events // - // ); - // } - // else - // { - // // - // mActivePivot.to = cTime; - - // // - // mActivePivot.repetition++; - - // // - // if (mActivePivot.to > mActivePivot.from) - // { - // FillPivotState(mActivePivot); - // } - - // // - // // Check Ticks Zone is Valid ... - // bool isTicksZoneValid = - // // - // mActivePivot.state.IsValid() && - // mActivePivot.state.ticksZone != NULL && - // mActivePivot.state.ticksZone.IsValid() - // // - // ; - // if (isTicksZoneValid) { - // // - // Print("Has Valid Ticks Zone ..."); - // } - // } - // } - } - - // - private: - // - // Props ... - - // - // Change Holders ... - int mMaxAllowedSavedChanges; // Max llowed Changes to Save ... - XValueChange mSarChanges[]; // Holds Parabolic Sar Direction Changes ... - XValueChange mPeaksChanges[]; // Holds Peaks Changes ... - XValueChange mValesChanges[]; // Holds Vales Changes ... - XValueChange mVWapOrderChanges[]; // Holds Vales Changes ... - XValueChange mVWapStateChanges[]; // Holds Vales Changes ... - - // - int mConsolidationLoopback; // Consolidation Loopback Length ... - XConsolidationZone mConsolidationZones[]; // Holds Consolidation Zones ... - XConsolidationZone mActioveConsolidationZone; // Holds Actiove Consolidation Zone ... - - // - XPVPivotPoint mPivotPoints[]; // Holds Pivots ... - - // - XCXPVPivotObject mActivePivotObject; - XPVPivot mActivePivot; - XPVPivot mPivots[]; - - // - // Actions ... - - /** - * Release All Resources ... - */ - void DeInit() - { - // - delete mX121Helper; - - // - delete mBarAnalyser; - } - - /** - * Apply Chart Style ... - */ - void ApplyChartStyle() - { - // - // Retrieve Current Chart ID ... - long chartId = ChartID(); - - // - ENUM_CHART_MODE mMode = CHART_CANDLES; // chart's mMode - bool mShowBidLine = true; // show bid line - bool mShowAskLine = true; // show ask line - bool mShowGrid = false; // show grids on chart - bool mShowVolumes = false; // show volumes - bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) - bool mAutoScroll = true; // chart autoscroll - bool mQuickNavigation = true; // chart quick navigation state - color mForeGroundColor = clrWhite; // chart's foreground color - color mBackGroundColor = clrBlack; // chart's background color - color mUpColor = clrGreen; // Up Color - color mDownColor = clrRed; // Down Color - color mBullishColor = clrGreen; // Bullish color - color mBearishColor = clrRed; // Bearish color - color mGridColor = clrGray; // grid color - color mBidLineColor = clrGray; // bid line color - color mAskLineColor = clrRed; // ask line color - color mLineColor = clrLime; // line mMode and doji candlestick color - color mStopColor = clrGold; // Color of stop order levels (Stop Loss and Take Profit) - color mVolumesColor = clrGreen; // volumes color - - // - ChartSetInteger(chartId, CHART_MODE, mMode); - ChartSetInteger(chartId, CHART_SHOW_BID_LINE, mShowBidLine); - ChartSetInteger(chartId, CHART_SHOW_ASK_LINE, mShowAskLine); - ChartSetInteger(chartId, CHART_SHOW_GRID, mShowGrid); - ChartSetInteger(chartId, CHART_SHOW_VOLUMES, mShowVolumes); - ChartSetInteger(chartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); - ChartSetInteger(chartId, CHART_AUTOSCROLL, mAutoScroll); - ChartSetInteger(chartId, CHART_QUICK_NAVIGATION, mQuickNavigation); - ChartSetInteger(chartId, CHART_COLOR_FOREGROUND, mForeGroundColor); - ChartSetInteger(chartId, CHART_COLOR_BACKGROUND, mBackGroundColor); - ChartSetInteger(chartId, CHART_COLOR_CHART_UP, mUpColor); - ChartSetInteger(chartId, CHART_COLOR_CHART_DOWN, mDownColor); - ChartSetInteger(chartId, CHART_COLOR_CANDLE_BULL, mBullishColor); - ChartSetInteger(chartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); - ChartSetInteger(chartId, CHART_COLOR_GRID, mGridColor); - ChartSetInteger(chartId, CHART_COLOR_BID, mBidLineColor); - ChartSetInteger(chartId, CHART_COLOR_ASK, mAskLineColor); - ChartSetInteger(chartId, CHART_COLOR_STOP_LEVEL, mStopColor); - ChartSetInteger(chartId, CHART_COLOR_CHART_LINE, mLineColor); - ChartSetInteger(chartId, CHART_COLOR_VOLUME, mVolumesColor); - } - - /** - * Fill Pivot Tick Zone ... - * - * @param pivot: XPVPivot instance Reference ... - */ - void CalculatePivotTickZone( - XPVPivot &pivot // - ) - { - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - bool isInited = false; - - // - datetime from = pivot.from; - XOHCL iFromBar; - int iFromBarIndex = iBarShift( - symbol, - period, - from // - ); - isInited = iFromBar.Init( - symbol, - period, - iFromBarIndex // - ); - if (!isInited) - { - return; - } - - // - datetime to = pivot.to; - XOHCL iToBar; - int iToBarIndex = iBarShift( - symbol, - period, - to // - ); - isInited = iToBar.Init( - symbol, - period, - iToBarIndex // - ); - if (!isInited) - { - return; - } - - // - if (iFromBarIndex <= iToBarIndex) - { - return; - } - - // - XCTicksZone *iZone; - iZone = new XCTicksZone(); - - // - int ticksLevels = mPOIDetector.TicksRangeZoneLevel(); - int ticksRange = mPOIDetector.TicksRangeZoneRange(); - isInited = ticksLevels > 0 && - ticksRange > 0; - if (!isInited) - { - return; - } - - // - isInited = iZone.Init( - iFromBar, - iToBar // - ); - if (!isInited) - { - return; - } - - // - pivot.state.ticksZone = iZone; - } - - // - // Change Values Actions ... - - /** - * Add Specified Parabolic Sar Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddSarChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mSarChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mSarChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Peaks Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddPeaksChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mPeaksChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mPeaksChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified Vales Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddValesChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mValesChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mValesChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified VWap Order Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddVWapOrderChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mVWapOrderChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mVWapOrderChanges, - maxAllowed // - ); - } - - // - return result; - } - - /** - * Add Specified VWap State Changed Item ... - * - * @param value: XValueChange instance Reference ... - * - * @return ( bool ) - */ - bool AddVWapStateChange(XValueChange &value) - { - // - bool result = false; - - // - result = value.IsValid(); - if (!result) - { - return result; - } - - // - int beforeCount = CountSarChanges(); - - // - AddIfNotExists( - value, - mVWapStateChanges // - ); - - // - int afterCount = CountSarChanges(); - - // - result = afterCount == beforeCount + 1; - if (result) - { - // - // Cleaning Up Unused Items ... - int maxAllowed = MaxAllowedSavedChanges(); - CleanupArray( - mVWapStateChanges, - maxAllowed // - ); - } - - // - return result; - } - - // -}; diff --git a/Documents/BKP/1/x-121.smc.test.signal.class.mq5 b/Documents/BKP/1/x-121.smc.test.signal.class.mq5 deleted file mode 100644 index 39be1260..00000000 --- a/Documents/BKP/1/x-121.smc.test.signal.class.mq5 +++ /dev/null @@ -1,831 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyTestSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XPVPivot pivot; - - // - // Trigger Props ... - - // - // Constructor ... - X121SMCStrategyTestSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - pivot.Clean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCTestSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyTestSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Detect new Peak or new Vale ... - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - result = isNewPeak || - isNewVale; - if (!result) - { - return result; - } - - // - // Detect Pivot ... - bool hasPivot = conditions.pivot.IsValid(); - if (!hasPivot) - { - // - XPVPivot pivot; - hasPivot = triggerCycleHelper.DetectPivot( - pivot, - cBar // - ); - result = hasPivot; - if (!result) - { - return result; - } - - // - conditions.pivot = pivot; - } - - // - // Check Order Block ... - // TODO: Later ... - // bool hasOrderBlock = conditions.HasOrderBlock(); - // if (hasOrderBlock) - // { - // // - // DetectX121SMCTestSiganlOrderBlock( - // zBar, - // consolidationState, - // conditions // - // ); - // } - - // - bool isMarketBullish = - // - // VWap State ... - decisionConditions.x121Conditions.isVWapBullishState && - analyseConditions.x121Conditions.isVWapBullishState && - verificationConditions.x121Conditions.isVWapBullishState - // - && - // - // VWap Order ... - decisionConditions.x121Conditions.isVWapBullishOrdered && - analyseConditions.x121Conditions.isVWapBullishOrdered && - verificationConditions.x121Conditions.isVWapBullishOrdered - // - && - // - // Sar ... - decisionConditions.x121Conditions.isSarBullish && - analyseConditions.x121Conditions.isSarBullish && - verificationConditions.x121Conditions.isSarBullish - // - ; - - // - bool isMarketBearish = - // - // VWap State ... - decisionConditions.x121Conditions.isVWapBearishState && - analyseConditions.x121Conditions.isVWapBearishState && - verificationConditions.x121Conditions.isVWapBearishState - // - && - // - // VWap Order ... - decisionConditions.x121Conditions.isVWapBearishOrdered && - analyseConditions.x121Conditions.isVWapBearishOrdered && - verificationConditions.x121Conditions.isVWapBearishOrdered - // - && - // - // Sar ... - decisionConditions.x121Conditions.isSarBearish && - analyseConditions.x121Conditions.isSarBearish && - verificationConditions.x121Conditions.isSarBearish - // - ; - - // - // Step 1 - // Detect Market Direction ... - isBullish = isMarketBullish; - isBearish = isMarketBearish; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Step 2 - // VWap Switches or Sar Switches ... - - // - bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - - // - bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered; - bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered; - - // - bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - // - // - - // - bool isSarStartedBullishStructure = - // - isSarSwitchedToBullish && - isVWapBullishState && - isVWapBullishOrdered - // - ; - - // - bool isSarStartedBearishStructure = - // - isSarSwitchedToBearish && - isVWapBearishState && - isVWapBearishOrdered - // - ; - - // - // - // - - // - bool isVWapStateStartedBullishStructure = - // - isVWapSwitchedToBullishState && - isSarBullish && - isVWapBullishOrdered - // - ; - - // - bool isVWapStateStartedBearishStructure = - // - isVWapSwitchedToBearishState && - isSarBearish && - isVWapBearishOrdered - // - ; - - // - // - // - - // - bool isVWapOrderStartedBullishStructure = - // - isVWapSwitchedToBullishOrdered && - isSarBullish && - isVWapBullishState - // - ; - - // - bool isVWapOrderStartedBearishStructure = - // - isVWapSwitchedToBearishOrdered && - isSarBearish && - isVWapBearishState - // - ; - - // - // - // - - // - isBullish = - // - isBullish - // - && - // - ( - // - isSarStartedBullishStructure || - isVWapStateStartedBullishStructure || - isVWapOrderStartedBullishStructure - // - ) - // - ; - - // - isBearish = - // - isBearish - // - && - // - ( - // - isSarStartedBearishStructure || - isVWapStateStartedBearishStructure || - isVWapOrderStartedBearishStructure - // - ) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCTestSiganlTrigger( - // - X121SMCStrategyTestSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_SMPV; - string providerStr = ToString(provider); - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - result = false; - - // - return result; -} - -// -// Tools Functions ... - -// \ No newline at end of file diff --git a/Documents/BKP/1/x-121.smc.test.strategy.class.mq5 b/Documents/BKP/1/x-121.smc.test.strategy.class.mq5 deleted file mode 100644 index d2cf0223..00000000 --- a/Documents/BKP/1/x-121.smc.test.strategy.class.mq5 +++ /dev/null @@ -1,2088 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XCX121SMCTestStrategy -// Description: provides all based classes for use ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... - -// -#include "../Classes/x-121.smc.base.strategy.class.mq5" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Signals/x-121.smc.test.signal.class.mq5" - -// -// Definitions ... - -// -// XStrategy Class Implementation(s) ... -class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy -{ - // - // Public ... - public: - // - - // - // Constructor(s) ... - void XCX121SMCTestStrategy( - // - // Base ... - string _symbol, // Trading Symbol - ENUM_TIMEFRAMES _period // Trading TimeFrame - ) - : XCX121SMCBaseStrategy(_symbol, _period) - { - InitialHelpers(); - } - - // - // Deconstructur ... - void ~XCX121SMCTestStrategy() - { - } - - // - // Overrides Actions ... - - /** - * Destroy All Class Implementations ... - */ - void Destroy() override - { - // - delete mTriggerCycleHelper; - delete mDecisionCycleHelper; - delete mAnalyseCycleHelper; - delete mVerificationCycleHelper; - delete mConsolidationCycleHelper; - delete mVisionCycleHelper; - } - - /** - * Check Conditions For Signal ... - */ - bool HasSignal( - XSignal &signal, - X121SMCStrategyConditions &conditions // - ) override - { - // - bool result = false; - - // - signal.Clean(); - conditions.Clean(); - - // - int pushers = 0; - - // - double sl = 0; - double tp = 0; - double risk = 0; - double entry = 0; - double reward = 0; - double r2r = R2R(); - string provider = ""; - double volume = Volume(); - ENUM_POSITION_TYPE type = POSITION_TYPE_BUY; - ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; - - // - bool hasLong = false; - bool hasShort = false; - - // - double selectedSL = 0; - - // - // Start Calculations ... - - // - // Retrieve Common Data ... - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - // Required Value For SL/TP Calculations ... - double points = GetPoints(symbol); - double pip = GetPipPrice(symbol); - double pip2 = 2 * pip; - - // - // Retrieve and Fill Cycle Conditions ... - result = GetCyclesConditions(conditions); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - // Check Spread for Signalling Conditions ... - bool isSpreadPassed = IsSpreadPass(); - result = isSpreadPassed; - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - // Detect Signal Conditions ... - bool hasSignal = false; - - // - bool hasSMPVSignal = false; - bool hasRJBPVSignal = false; - bool hasVWAPCSignal = false; - bool hasTestSignal = false; - - // - // X_121_SMC_PROVIDER_SMPV ... - if (!hasSignal) - { - // - // hasSMPVSignal = DetectSamePeaksAndValesSignal(conditions); - // hasSignal = hasSMPVSignal; - } - - // - // X_121_SMC_PROVIDER_RJBPV ... - if (!hasSignal) - { - // // - // hasRJBPVSignal = DetectRJBPVSignal(conditions); - // hasSignal = hasRJBPVSignal; - } - - // - // X_121_SMC_PROVIDER_VWAPC ... - if (!hasSignal) - { - // // - // hasVWAPCSignal = DetectVWAPCSignal(conditions); - // hasSignal = hasVWAPCSignal; - } - - // - if (!hasSignal) - { - // - hasTestSignal = DetectTestSignal(conditions); - hasSignal = hasTestSignal; - } - - // - result = hasSignal; - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - // Combine all Signals Conditions ... - selectedSL = conditions.sl; - provider = conditions.provider; - - // - hasLong = - // - IsBullish(conditions.signalDir) - // - ; - - // - hasShort = - // - IsBearish(conditions.signalDir) - // - ; - - // - result = hasLong || - hasShort; - - // - // Rmove Signal Condition ... - if (result) - { - // - // TYPE ... - type = - hasLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; - ENUM_X_POSITION_TYPES xType = - hasLong - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - entry = GetEntry( - conditions.symbol, - type // - ); - - // - double slAddition = 0; - sl = - hasLong - ? selectedSL - slAddition - : selectedSL + slAddition; - - // - // RISK Reward ... - risk = - hasLong - ? entry - sl - : sl - entry; - reward = risk * r2r; - tp = - hasLong - ? entry + reward - : entry - reward; - - // - signal.sl = sl; - signal.tp = tp; - signal.type = type; - signal.mode = mode; - signal.entry = entry; - signal.volume = volume; - signal.symbol = symbol; - signal.period = period; - signal.pushers = pushers; - signal.provider = provider; - signal.time = TimeCurrent(); - - // - result = PrepareSignal(signal); - if (result) - { - DrawSignal(signal); - } - - // - hasLong = false; - hasShort = false; - } - - // - return result; - } - - /** - * Customize Strategy Identifier ... - */ - string GetTag() override - { - return X121SMCStrategyToken; - } - - // - // Protected ... - protected: - // - - // - // Props ... - - // - // Trigger Order Flow ... - XPVPivot mOrderFlow[]; - ENUM_X_DIRECTION mOrderFlowDir; - - // - ENUM_XPOI_EVENTS mTriggerPOIEvents[]; - ENUM_X_CYCLE_EVENTS mTriggerCycleEvents[]; - XC121SMCCycleHelper *mTriggerCycleHelper; - - // - ENUM_XPOI_EVENTS mDecisionPOIEvents[]; - ENUM_X_CYCLE_EVENTS mDecisionCycleEvents[]; - XC121SMCCycleHelper *mDecisionCycleHelper; - - // - ENUM_XPOI_EVENTS mAnalysePOIEvents[]; - ENUM_X_CYCLE_EVENTS mAnalyseCycleEvents[]; - XC121SMCCycleHelper *mAnalyseCycleHelper; - - // - ENUM_XPOI_EVENTS mVerificationPOIEvents[]; - ENUM_X_CYCLE_EVENTS mVerificationCycleEvents[]; - XC121SMCCycleHelper *mVerificationCycleHelper; - - // - ENUM_XPOI_EVENTS mConsolidationPOIEvents[]; - ENUM_X_CYCLE_EVENTS mConsolidationCycleEvents[]; - XC121SMCCycleHelper *mConsolidationCycleHelper; - - // - ENUM_XPOI_EVENTS mVisionPOIEvents[]; - ENUM_X_CYCLE_EVENTS mVisionCycleEvents[]; - XC121SMCCycleHelper *mVisionCycleHelper; - - // - // Actions ... - - /** - * Retrieve Cycles Conditions ... - * - * @param conditions: X121SMCStrategyConditions instance Reference ... - * - * @return ( bool ) - */ - bool GetCyclesConditions( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - datetime cTime = TimeCurrent(); - - // - conditions.time = cTime; - conditions.symbol = symbol; - conditions.period = period; - - // - int conditionsLoopback = 7; - - // - // Fill Cycles Conditions ... - - // - // Trigger ... - result = mTriggerCycleHelper.GetConditions( - mTriggerCycleEvents, - mTriggerPOIEvents, - conditions.triggerConditions, - zIndex, - conditionsLoopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - conditions.triggerConditions.state = mTriggerState; - - // - // Decision ... - result = mDecisionCycleHelper.GetConditions( - mDecisionCycleEvents, - mDecisionPOIEvents, - conditions.decisionConditions, - zIndex, - conditionsLoopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - conditions.decisionConditions.state = mDecisionState; - - // - // Analyse ... - result = mAnalyseCycleHelper.GetConditions( - mAnalyseCycleEvents, - mAnalysePOIEvents, - conditions.analyseConditions, - zIndex, - conditionsLoopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - conditions.analyseConditions.state = mAnalyseState; - - // - // Verification ... - result = mVerificationCycleHelper.GetConditions( - mVerificationCycleEvents, - mVerificationPOIEvents, - conditions.verificationConditions, - zIndex, - conditionsLoopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - conditions.verificationConditions.state = mVerificationState; - - // - // Consolidation ... - result = mConsolidationCycleHelper.GetConditions( - mConsolidationCycleEvents, - mConsolidationPOIEvents, - conditions.consolidationConditions, - zIndex, - conditionsLoopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - conditions.consolidationConditions.state = mConsolidationState; - - // - // Vision ... - result = mVisionCycleHelper.GetConditions( - mVisionCycleEvents, - mVisionPOIEvents, - conditions.visionConditions, - zIndex, - conditionsLoopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - conditions.visionConditions.state = mVisionState; - - // // - // XPVPivot triggerPivot; - // mTriggerCycleHelper.GetActivePivot(triggerPivot); - // result = triggerPivot.IsValid(); - // if (!result) - // { - // return result; - // } - - // // - // ClearDraws(); - // DrawPivot( - // triggerPivot, - // true, // Draw State ... - // true // Filter By Price ... - // ); - - // - return result; - } - - // - // Signalling Functions ... - - // - // TODO: Remove this ... - X121SMCStrategyTestSignalConditions mTestConditions; - bool DetectTestSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_SMPV; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mTestConditions.setupTime; - bool isSetuped = mTestConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mTestConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCTestSiganlSetup( - symbol, - period, - mTestConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - setupDir = mTestConditions.dir; - setupTime = mTestConditions.setupTime; - } - - // // - // ClearDraws(); - // CustomStateDrawing( - // mTriggerState, - // true // Filter By Price ... - // ); - - // - // Detect Trigger Conditions ... - // bool canTrigger = mTestConditions.CanTrigger(); - // datetime triggerTime = mTestConditions.triggerTime; - // result = canTrigger; - // if (!canTrigger) - // { - // // - // // Detect Signal Trigger ... - // canTrigger = DetectX121SMCTestSiganlTrigger( - // mTestConditions, - // symbol, - // period, - // mTriggerCycleHelper, - // mDecisionCycleHelper, - // mAnalyseCycleHelper, - // mVerificationCycleHelper, - // mConsolidationCycleHelper, - // mVisionCycleHelper // - // ); - - // // - // result = canTrigger; - // if (!result) - // { - // return result; - // } - - // // - // triggerTime = mTestConditions.triggerTime; - // } - - // - // Check Signal Direction ... - - // // - // isBullish = IsBullish(setupDir); - // isBearish = IsBearish(setupDir); - - // - // result = isBullish || - // isBearish; - // if (!result) - // { - // return result; - // } - - // // - // if (cTime - setupTime > 2400) - // { - // // - // ClearDraws(); - - // // - // mTestConditions.Clean(); - // } - - // // - // // Issues Signal on Conditions ... - // conditions.signalDir = setupDir; - // conditions.provider = providerStr; - // conditions.sl = mTestConditions.sl; - - // - mTestConditions.Clean(); - - // - return result; - } - - // - // Private ... - private: - // - // Props ... - - /** - * Initial Required Indicators Helper ... - */ - void InitialHelpers() - { - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - // Short ... - ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period - ENUM_TIMEFRAMES scPeriod = NULL; // Time Period - - // - // Medium ... - ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period - ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period - - // - // Long ... - ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period - ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period - - // - // Hind ... - ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period - ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period - - // - // XPV ... - X121Inputs x121Inputs; - - // - x121Inputs.Default(); - - // - x121Inputs.scMethod = scMethod; - x121Inputs.scPeriod = scPeriod; - x121Inputs.mcMethod = mcMethod; - x121Inputs.mcPeriod = mcPeriod; - x121Inputs.lcMethod = lcMethod; - x121Inputs.lcPeriod = lcPeriod; - x121Inputs.hcMethod = hcMethod; - x121Inputs.hcPeriod = hcPeriod; - - // - x121Inputs.showFibo2Levels = false; - x121Inputs.showFibo3Levels = true; - x121Inputs.showFibo4Levels = false; - - // - // Initialize Cycle Helpers ... - - // - mTriggerCycleHelper = new XC121SMCCycleHelper(); - mTriggerCycleHelper.Init( - symbol, - PERIOD_M1, - x121Inputs // - ); - - // - mDecisionCycleHelper = new XC121SMCCycleHelper(); - mDecisionCycleHelper.Init( - symbol, - PERIOD_M5, - x121Inputs // - ); - - // - mAnalyseCycleHelper = new XC121SMCCycleHelper(); - mAnalyseCycleHelper.Init( - symbol, - PERIOD_M15, - x121Inputs // - ); - - // - mVerificationCycleHelper = new XC121SMCCycleHelper(); - mVerificationCycleHelper.Init( - symbol, - PERIOD_M30, - x121Inputs // - ); - - // - mConsolidationCycleHelper = new XC121SMCCycleHelper(); - mConsolidationCycleHelper.Init( - symbol, - PERIOD_H1, - x121Inputs // - ); - - // - mVisionCycleHelper = new XC121SMCCycleHelper(); - mVisionCycleHelper.Init( - symbol, - PERIOD_H4, - x121Inputs // - ); - } - - // - // SL Selector Methods ... - - /** - * Select Specified Type of Stop Loss ... - * - * @param conditions: X121SMCStrategyConditions instance Reference ... - * @param forDir: ENUM_X_DIRECTION member, Signal Direction ... - * @param type: ENUM_X_121_SMC_SL_TYPES member, Specified Required SL Type ... - * - * @return ( double ) - */ - double SelectSL( - X121SMCStrategyConditions &conditions, - ENUM_X_DIRECTION forDir, - ENUM_X_121_SMC_SL_TYPES type // - ) - { - // - double result = 0; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - bool isValid = - // - HasDirection(forDir) && - conditions.IsValid() && - type != X_121_SMC_SL_TYPE_NONE - // - ; - if (!isValid) - { - return result; - } - - // - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - period, - 0 // - ); - if (!isInited) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (type == X_121_SMC_SL_TYPE_FIBO_LEVEL_3) - { - result = conditions.triggerConditions.x121Conditions.fl3Buffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_FIBO_LEVEL_1_5) - { - // - result = - isBullish - ? conditions.triggerConditions.x121Conditions.fl1Buffer[0] - : conditions.triggerConditions.x121Conditions.fl5Buffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_DON_CLOSE_BOX) - { - // - result = - isBullish - ? conditions.triggerConditions.x121Conditions.donCloseLowerBuffer[0] - : conditions.triggerConditions.x121Conditions.donCloseUpperBuffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_SWING) - { - // - int swingLowsCount = conditions.triggerConditions.state.CountSwingLows(); - int swingHighsCount = conditions.triggerConditions.state.CountSwingHighs(); - result = - isBullish - ? conditions.triggerConditions.state.swingLows[swingLowsCount - 1].GetValue() - : conditions.triggerConditions.state.swingHighs[swingHighsCount - 1].GetValue(); - } - else if (type == X_121_SMC_SL_TYPE_REJECTION) - { - // - result = - isBullish - ? conditions.triggerConditions.state.bullishRejectionBars[conditions.triggerConditions.state.CountBullishRejectionBars() - 1].Lower() - : conditions.triggerConditions.state.bearishRejectionBars[conditions.triggerConditions.state.CountBearishRejectionBars() - 1].Upper(); - } - else if (type == X_121_SMC_SL_TYPE_MOMENTUM) - { - // - result = - isBullish - ? conditions.triggerConditions.state.bullishMomentumBars[conditions.triggerConditions.state.CountBullishMomentumBars() - 1].Lower() - : conditions.triggerConditions.state.bearishMomentumBars[conditions.triggerConditions.state.CountBearishMomentumBars() - 1].Upper(); - } - else if (type == X_121_SMC_SL_TYPE_VWAP_FAST) - { - result = conditions.triggerConditions.x121Conditions.vwapFastBuffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_VWAP_MID) - { - result = conditions.triggerConditions.x121Conditions.vwapMidBuffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_VWAP_SLOW) - { - result = conditions.triggerConditions.x121Conditions.vwapSlowBuffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_CURRENT_SAR) - { - result = conditions.triggerConditions.x121Conditions.sarBuffer[0]; - } - else if (type == X_121_SMC_SL_TYPE_TENKAN_SEN) - { - // - double hh = zBar.FindHighest( - 9, - MODE_HIGH // - ); - double ll = zBar.FindLowest( - 9, - MODE_LOW // - ); - double mid = (hh - ll) / 2; - result = isBullish - ? ll - mid - : hh + mid; - } - else if (type == X_121_SMC_SL_TYPE_CURRENT_SAR_BOX || - type == X_121_SMC_SL_TYPE_LAST_SAR_CHANGED_BAR || - type == X_121_SMC_SL_TYPE_LAST_DIRECTIONAL_SAR) - { - // - XOHCL cSarChangeBar; - XOHCL pSarChangeBar; - XValueChange cSarChange; // Current Sar Change (IsDirect) ... - XValueChange pSarChange; // Prev Sar Change (Direct) ... - XValueChange sarChanges[]; - int sarChangesCount = mTriggerCycleHelper - .FillSarChanges(sarChanges); - if (!IsValidSize(sarChangesCount) || sarChangesCount < 2) - { - return result; - } - - // - // - cSarChange = sarChanges[sarChangesCount - 1]; - pSarChange = sarChanges[sarChangesCount - 2]; - - // - bool isFilled = cSarChange.FillBar( - cSarChangeBar, - symbol, - period // - ); - if (!isFilled) - { - return result; - } - - // - isFilled = pSarChange.FillBar( - pSarChangeBar, - symbol, - period // - ); - if (!isFilled) - { - return result; - } - - // - if (type == X_121_SMC_SL_TYPE_LAST_SAR_CHANGED_BAR) - { - // - result = isBullish - ? pSarChangeBar.low - : pSarChangeBar.high; - } - else if (type == X_121_SMC_SL_TYPE_CURRENT_SAR_BOX) - { - // - result = - isBullish - ? zBar.FindLowest( - MathAbs(cSarChangeBar.Index() - 1), - MODE_LOW // - ) - : zBar.FindHighest( - MathAbs(cSarChangeBar.Index() - 1), - MODE_HIGH // - ); - } - else if (type == X_121_SMC_SL_TYPE_LAST_DIRECTIONAL_SAR) - { - // - XOHCL prevBar; - bool isInited = cSarChangeBar.GetPreviousBar(prevBar); - if (!isInited) - { - return result; - } - - // - result = isBullish - ? prevBar.low - : prevBar.high; - } - } - - // - return result; - } - - // - // Drawing Functions ... - - /** - * Custom Drawing State ... - * - * @param state: XPOIState instance reference, Specified Which state to Draw ... - * @param forceDrawSamePeriod: Boolean ... - */ - void CustomStateDrawing( - XPOIState &state, - bool filterByPrice = false, - bool forceDrawSamePeriod = false, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - // - // Ignores List ... - bool ignoreSwingHighs = false, - bool ignoreSwingLows = false, - bool ignoreSupportZones = false, - bool ignoreResistanceZones = false, - bool ignoreSupplyZones = false, - bool ignoreDemandZones = false, - bool ignoreBullishOrderBlocks = false, - bool ignoreBearishOrderBlocks = false, - bool ignoreBullishFairValueGaps = false, - bool ignoreBearishFairValueGaps = false, - bool ignoreBullishRejectionBars = false, - bool ignoreBearishRejectionBars = false, - bool ignoreBullishMomentumBars = false, - bool ignoreBearishMomentumBars = false // - ) - { - // - XPOIState tmpState = state; - - // - if (forceDrawSamePeriod) - { - // - int count = 0; - ENUM_TIMEFRAMES period = GetPeriod(); - - // - count = state.CountSwingHighs(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSwing iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.swingHighs, - i, - 1 // - ); - } - } - } - - // - count = state.CountSwingLows(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSwing iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.swingLows, - i, - 1 // - ); - } - } - } - - // - count = state.CountBullishMomentumBars(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCMomentumBar iMomentum = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bullishMomentumBars, - i, - 1 // - ); - } - } - } - - // - count = state.CountBearishMomentumBars(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCMomentumBar iMomentum = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iMomentum.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bearishMomentumBars, - i, - 1 // - ); - } - } - } - - // - count = state.CountBullishRejectionBars(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCRejectionBar iRejection = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iRejection.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bullishRejectionBars, - i, - 1 // - ); - } - } - } - - // - count = state.CountBearishRejectionBars(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCRejectionBar iRejection = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iRejection.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bearishRejectionBars, - i, - 1 // - ); - } - } - } - - // - count = state.CountSupportZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone iZone = state.supportZones[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.supportZones, - i, - 1 // - ); - } - } - } - - // - count = state.CountResistanceZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone iZone = state.resistanceZones[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.resistanceZones, - i, - 1 // - ); - } - } - } - - // - count = state.CountSupplyZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupplyZone iZone = state.supplyZones[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.supplyZones, - i, - 1 // - ); - } - } - } - - // - count = state.CountDemandZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCDemandZone iZone = state.demandZones[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.demandZones, - i, - 1 // - ); - } - } - } - - // - count = state.CountBullishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock iZone = state.bullishOrderBlocks[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bullishOrderBlocks, - i, - 1 // - ); - } - } - } - - // - count = state.CountBearishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock iZone = state.bearishOrderBlocks[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bearishOrderBlocks, - i, - 1 // - ); - } - } - } - - // - count = state.CountBullishFairValueGaps(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG iZone = state.bullishFairValueGaps[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillStartBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bullishFairValueGaps, - i, - 1 // - ); - } - } - } - - // - count = state.CountBearishFairValueGaps(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG iZone = state.bearishFairValueGaps[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillStartBar(iBar); - if (!isFilled) - { - continue; - } - - // - bool isSamePeriod = iBar.period == period; - if (!isSamePeriod) - { - // - ArrayRemove( - tmpState.bearishFairValueGaps, - i, - 1 // - ); - } - } - } - - // - } - - // - if (filterByPrice) - { - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - 1 // - ); - - // - if (isInited) - { - // - // Support Zones ... - int supportZonesCount = ArraySize(tmpState.supportZones); - if (IsValidSize(supportZonesCount)) - { - // - XCSupportZone *supports[]; - for (int i = 0; i < supportZonesCount; i++) - { - // - XCSupportZone *iZone = tmpState.supportZones[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - supports // - ); - } - } - - // - Clean(tmpState.supportZones); - Copy( - supports, - tmpState.supportZones // - ); - } - - // - // Resistance Zones ... - int resistanceZonesCount = ArraySize(tmpState.resistanceZones); - if (IsValidSize(resistanceZonesCount)) - { - // - XCResistanceZone *resistances[]; - for (int i = 0; i < resistanceZonesCount; i++) - { - // - XCResistanceZone *iZone = tmpState.resistanceZones[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - resistances // - ); - } - } - - // - Clean(tmpState.resistanceZones); - Copy( - resistances, - tmpState.resistanceZones // - ); - } - - // - // Supply Zones ... - int supplyZonesCount = ArraySize(tmpState.supplyZones); - if (IsValidSize(supplyZonesCount)) - { - // - XCSupplyZone *supplies[]; - for (int i = 0; i < supplyZonesCount; i++) - { - // - XCSupplyZone *iZone = tmpState.supplyZones[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - supplies // - ); - } - } - - // - Clean(tmpState.supplyZones); - Copy( - supplies, - tmpState.supplyZones // - ); - } - - // - // Demand Zones ... - int demandZonesCount = ArraySize(tmpState.demandZones); - if (IsValidSize(demandZonesCount)) - { - // - XCDemandZone *demands[]; - for (int i = 0; i < demandZonesCount; i++) - { - // - XCDemandZone *iZone = tmpState.demandZones[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - demands // - ); - } - } - - // - Clean(tmpState.demandZones); - Copy( - demands, - tmpState.demandZones // - ); - } - - // - // Bullish Order Blocks ... - int bullishOrderBlocksCount = ArraySize(tmpState.bullishOrderBlocks); - if (IsValidSize(bullishOrderBlocksCount)) - { - // - XCOrderBlock *obs[]; - for (int i = 0; i < bullishOrderBlocksCount; i++) - { - // - XCOrderBlock *iZone = tmpState.bullishOrderBlocks[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - obs // - ); - } - } - - // - Clean(tmpState.bullishOrderBlocks); - Copy( - obs, - tmpState.bullishOrderBlocks // - ); - } - - // - // Bearish Order Blocks ... - int bearishOrderBlocksCount = ArraySize(tmpState.bearishOrderBlocks); - if (IsValidSize(bearishOrderBlocksCount)) - { - // - XCOrderBlock *obs[]; - for (int i = 0; i < bearishOrderBlocksCount; i++) - { - // - XCOrderBlock *iZone = tmpState.bearishOrderBlocks[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - obs // - ); - } - } - - // - Clean(tmpState.bearishOrderBlocks); - Copy( - obs, - tmpState.bearishOrderBlocks // - ); - } - - // - // Bullish Fair Value Gaps ... - int bullishFairValueGapsCount = ArraySize(tmpState.bullishFairValueGaps); - if (IsValidSize(bullishFairValueGapsCount)) - { - // - XCFVG *obs[]; - for (int i = 0; i < bullishFairValueGapsCount; i++) - { - // - XCFVG *iZone = tmpState.bullishFairValueGaps[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - obs // - ); - } - } - - // - Clean(tmpState.bullishFairValueGaps); - Copy( - obs, - tmpState.bullishFairValueGaps // - ); - } - - // - // Bearish Fair Value Gaps ... - int bearishFairValueGapsCount = ArraySize(tmpState.bearishFairValueGaps); - if (IsValidSize(bearishFairValueGapsCount)) - { - // - XCFVG *obs[]; - for (int i = 0; i < bearishFairValueGapsCount; i++) - { - // - XCFVG *iZone = tmpState.bearishFairValueGaps[i]; - - // - bool isValid = - // - (bar.low < iZone.Upper() && - bar.high > iZone.Upper()) || - (bar.high > iZone.Lower() && - bar.low < iZone.Lower()) || - (bar.low > iZone.Lower() && - bar.high < iZone.Upper()) - // - ; - if (isValid) - { - Add( - iZone, - obs // - ); - } - } - - // - Clean(tmpState.bearishFairValueGaps); - Copy( - obs, - tmpState.bearishFairValueGaps // - ); - } - } - } - - // - bool drawSwingHighs = true; - bool drawSwingLows = true; - bool drawSupportZones = true; - bool drawResistanceZones = true; - bool drawSupplyZones = true; - bool drawDemandZones = true; - bool drawBullishOrderBlocks = true; - bool drawBearishOrderBlocks = true; - bool drawBullishFairValueGaps = true; - bool drawBearishFairValueGaps = true; - bool drawBullishRejectionBars = true; - bool drawBearishRejectionBars = true; - bool drawBullishMomentumBars = true; - bool drawBearishMomentumBars = true; - - // - // Change Drawing Specs Conditions based on - // Provided Direction ... - if (forDir == X_DIRECTION_BULLISH) - { - // - drawSwingLows = true; - drawDemandZones = true; - drawSupportZones = true; - drawBullishOrderBlocks = true; - drawBullishFairValueGaps = true; - drawBullishRejectionBars = true; - drawBullishMomentumBars = true; - - // - drawSwingHighs = false; - drawSupplyZones = false; - drawResistanceZones = false; - drawBearishOrderBlocks = false; - drawBearishFairValueGaps = false; - drawBearishRejectionBars = false; - drawBearishMomentumBars = false; - } - else if (forDir == X_DIRECTION_BEARISH) - { - // - drawSwingLows = false; - drawDemandZones = false; - drawSupportZones = false; - drawBullishOrderBlocks = false; - drawBullishFairValueGaps = false; - drawBullishRejectionBars = false; - drawBullishMomentumBars = false; - - // - drawSwingHighs = true; - drawSupplyZones = true; - drawResistanceZones = true; - drawBearishOrderBlocks = true; - drawBearishFairValueGaps = true; - drawBearishRejectionBars = true; - drawBearishMomentumBars = true; - } - - // - // Apply Ignore List ... - - // - if (ignoreSwingHighs) - { - drawSwingHighs = false; - } - - // - if (ignoreSwingLows) - { - drawSwingLows = false; - } - - // - if (ignoreSupportZones) - { - drawSupportZones = false; - } - - // - if (ignoreResistanceZones) - { - drawResistanceZones = false; - } - - // - if (ignoreSupplyZones) - { - drawSupplyZones = false; - } - - // - if (ignoreDemandZones) - { - drawDemandZones = false; - } - - // - if (ignoreBullishOrderBlocks) - { - drawBullishOrderBlocks = false; - } - - // - if (ignoreBearishOrderBlocks) - { - drawBearishOrderBlocks = false; - } - - // - if (ignoreBullishFairValueGaps) - { - drawBullishFairValueGaps = false; - } - - // - if (ignoreBearishFairValueGaps) - { - drawBearishFairValueGaps = false; - } - - // - if (ignoreBullishRejectionBars) - { - drawBullishRejectionBars = false; - } - - // - if (ignoreBearishRejectionBars) - { - drawBearishRejectionBars = false; - } - - // - if (ignoreBullishMomentumBars) - { - drawBullishMomentumBars = false; - } - - // - if (ignoreBearishMomentumBars) - { - drawBearishMomentumBars = false; - } - - // - DrawState( - tmpState, // State ... - true, // Update To of all Drawings Till now ... - drawSwingHighs, // Draw SwingHighs .. - drawSwingLows, // Draw SwingLows .. - drawSupportZones, // Draw SupportZones .. - drawResistanceZones, // Draw ResistanceZones .. - drawSupplyZones, // Draw SupplyZones .. - drawDemandZones, // Draw DemandZones .. - drawBullishOrderBlocks, // Draw BullishOrderBlocks .. - drawBearishOrderBlocks, // Draw BearishOrderBlocks .. - drawBullishFairValueGaps, // Draw BullishFairValueGaps .. - drawBearishFairValueGaps, // Draw BearishFairValueGaps .. - drawBullishRejectionBars, // Draw BullishRejectionBars .. - drawBearishRejectionBars, // Draw BearishRejectionBars .. - drawBullishMomentumBars, // Draw BullishMomentumBars .. - drawBearishMomentumBars, // Draw BearishMomentumBars .. - true // Draw Ticks Zone ... - ); - } - - /** - * Draw Specific Pivot ... - * - * @param pivot: XPVPivot instance Reference ... - * @param drawState: Boolean ... - * @param filterByPrice: Boolean ... - * @param ignoreSwingHighs: Boolean ... - * @param ignoreSwingLows: Boolean ... - * @param ignoreSupportZones: Boolean ... - * @param ignoreResistanceZones: Boolean ... - * @param ignoreSupplyZones: Boolean ... - * @param ignoreDemandZones: Boolean ... - * @param ignoreBullishOrderBlocks: Boolean ... - * @param ignoreBearishOrderBlocks: Boolean ... - * @param ignoreBullishFairValueGaps: Boolean ... - * @param ignoreBearishFairValueGaps: Boolean ... - * @param ignoreBullishRejectionBars: Boolean ... - * @param ignoreBearishRejectionBars: Boolean ... - * @param ignoreBullishMomentumBars: Boolean ... - * @param ignoreBearishMomentumBars: Boolean ... - */ - void DrawPivot( - XPVPivot &pivot, - bool drawState = true, - bool filterByPrice = false, - bool ignoreSwingHighs = false, - bool ignoreSwingLows = false, - bool ignoreSupportZones = false, - bool ignoreResistanceZones = false, - bool ignoreSupplyZones = false, - bool ignoreDemandZones = false, - bool ignoreBullishOrderBlocks = false, - bool ignoreBearishOrderBlocks = false, - bool ignoreBullishFairValueGaps = false, - bool ignoreBearishFairValueGaps = false, - bool ignoreBullishRejectionBars = false, - bool ignoreBearishRejectionBars = false, - bool ignoreBullishMomentumBars = false, - bool ignoreBearishMomentumBars = false // - ) - { - // - if (!pivot.IsValid()) - { - return; - } - - // - // Draw Pivot it self ... - XCXPVPivotObject *iPivotObj; - iPivotObj = new XCXPVPivotObject(); - bool isCreated = iPivotObj.Create( - mPOIDrawer.ChartIdentification(), - mPOIDrawer.SubWindowIdentification(), - pivot // - ); - if (!isCreated) - { - return; - } - - // - color clrPivotColor = pivot.IsPeak() - ? clrAqua - : clrMagenta; - iPivotObj.PivotColor(clrPivotColor); - iPivotObj.PivotWidth(2); - - // - AddObjectIfNotExists(iPivotObj); - - // - if (!drawState) - { - return; - } - - // - if (!pivot.state.IsValid()) - { - return; - } - - // - CustomStateDrawing( - pivot.state, - filterByPrice, - false, // forceDrawSamePeriod - X_DIRECTION_NONE, // forDir - ignoreSwingHighs, - ignoreSwingLows, - ignoreSupportZones, - ignoreResistanceZones, - ignoreSupplyZones, - ignoreDemandZones, - ignoreBullishOrderBlocks, - ignoreBearishOrderBlocks, - ignoreBullishFairValueGaps, - ignoreBearishFairValueGaps, - ignoreBullishRejectionBars, - ignoreBearishRejectionBars, - ignoreBullishMomentumBars, - ignoreBearishMomentumBars // - ); - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/1/x.oepv.tmp.mq5 b/Documents/BKP/1/x.oepv.tmp.mq5 deleted file mode 100644 index 4ff13044..00000000 --- a/Documents/BKP/1/x.oepv.tmp.mq5 +++ /dev/null @@ -1,75 +0,0 @@ - // - // Decision ... - - // - // Peak ... - bool isDecisionNewPeak = decisionConditions.x121Conditions.isNewPeak; - bool isDecisionNewPeakOverLast = decisionConditions.x121Conditions.isNewPeakOverLast; - bool isDecisionNewPeakUnderLast = decisionConditions.x121Conditions.isNewPeakUnderLast; - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - XPVPivotPoint decisionPeakPivots[]; - XPVPivotPoint decisionLastPeakPivot; - XPVPivotPoint decisionPrevPeakPivot; - int decisionPeakPivotsCount = decisionCycleHelper - .FillPeakPivotPoints(decisionPeakPivots); - bool hasDecisionPeak = decisionPeakPivotsCount >= 2; - if (hasDecisionPeak) - { - // - decisionLastPeakPivot = decisionPeakPivots[decisionPeakPivotsCount - 1]; - decisionPrevPeakPivot = decisionPeakPivots[decisionPeakPivotsCount - 2]; - } - - // - // Vale ... - bool isDecisionNewVale = decisionConditions.x121Conditions.isNewVale; - bool isDecisionNewValeOverLast = decisionConditions.x121Conditions.isNewValeOverLast; - bool isDecisionNewValeUnderLast = decisionConditions.x121Conditions.isNewValeUnderLast; - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - XPVPivotPoint decisionValePivots[]; - XPVPivotPoint decisionLastValePivot; - XPVPivotPoint decisionPrevValePivot; - int decisionValePivotsCount = decisionCycleHelper - .FillValePivotPoints(decisionValePivots); - bool hasDecisionVale = decisionValePivotsCount >= 2; - if (hasDecisionVale) - { - // - decisionLastValePivot = decisionValePivots[decisionValePivotsCount - 1]; - decisionPrevValePivot = decisionValePivots[decisionValePivotsCount - 2]; - } - - // - bool isDecisionBullish = - // - hasDecisionVale && - isDecisionNewVale && - isDecisionNewValeUnderLast && - decisionLastValePivot.value > decisionPrevValePivot.value - // - ; - - // - bool isDecisionBearish = - // - false && - hasDecisionPeak && - decisionLastPeakPivot.value - // - ; - - // - if (isDecisionBullish || - isDecisionBearish) - { - // - conditions.pivot = - isDecisionBullish - ? decisionVale - : decisionPeak; - conditions.dir = - isDecisionBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - conditions.cycle = X_CYCLE_DECISION; - } diff --git a/Documents/BKP/2/x-test-signal.smc.mq5 b/Documents/BKP/2/x-test-signal.smc.mq5 deleted file mode 100644 index 524e508c..00000000 --- a/Documents/BKP/2/x-test-signal.smc.mq5 +++ /dev/null @@ -1,830 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyTestSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - // Constructor ... - X121SMCStrategyTestSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCTestSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyTestSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - isBullish = - // - false - // - ; - - // - isBearish = - // - false - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCTestSiganlTrigger( - // - X121SMCStrategyTestSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - isBullish = - // - false - // - ; - - // - isBearish = - // - false - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? 0 - : 0; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - - -////////////////////////////////////////////////////////////////////////////////////////// - - - // - // Test Signal ... - X121SMCStrategyTestSignalConditions mTestConditions; - bool DetectTestSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTEST; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mTestConditions.setupTime; - bool isSetuped = mTestConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mTestConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCTestSiganlSetup( - symbol, - period, - mTestConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mTestConditions.dir; - setupTime = mTestConditions.setupTime; - } - - // ClearDraws(); - // ENUM_X_DIRECTION activeZoneDir; - // bool hasTicksZone = mTestConditions.HasTicksZone(); - // bool hasActiveZone = mTestConditions.HasActiveZone(activeZoneDir); - // if (hasActiveZone) - // { - // // - // if (IsBullish(activeZoneDir)) - // { - // // - // mTestConditions.activeDemandZone.To(cTime); - // XCDemandZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateDemandZone( - // mTestConditions.activeDemandZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // else - // { - // // - // mTestConditions.activeSupplyZone.To(cTime); - // XCSupplyZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateSupplyZone( - // mTestConditions.activeSupplyZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // } - // if (hasTicksZone) - // { - // // - // XCTicksZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateTicksZone( - // mTestConditions.ticksZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mTestConditions.CanTrigger(); - datetime triggerTime = mTestConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCTestSiganlTrigger( - mTestConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mTestConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mTestConditions.sl; - - // - mTestConditions.Clean(); - - // - return result; - } - - -////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Documents/BKP/3/x-smc.signal.conditions.detector.mq5 b/Documents/BKP/3/x-smc.signal.conditions.detector.mq5 deleted file mode 100644 index 2a7f7e2c..00000000 --- a/Documents/BKP/3/x-smc.signal.conditions.detector.mq5 +++ /dev/null @@ -1,6565 +0,0 @@ -//////////////////////////////////////////// - - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXVWPBSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - // Constructor ... - X121SMCStrategyXVWPBSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXVWPBSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXVWPBSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - // ENUM_X_DIRECTION trend; - // bool hasTrend = consolidationCycleHelper - // .DetectTrend(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - // result = hasBullishTrend || - // hasBearishTrend; - // if (!result) - // { - // return result; - // } - - // - // Detect VWAP Bearish ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - bool isCloseOverVwapMax = - // - ask > vwapMax && - bid > vwapMax && - (cBar.low > vwapMax || - cBar.close > vwapMax) - // - ; - - // - bool isCloseUnderVwapMin = - // - ask < vwapMin && - bid < vwapMin && - (cBar.high < vwapMin || - cBar.close < vwapMin) - // - ; - - // - bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered; - bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered; - bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - // Summary VWap ... - - // - bool isVwapBullishFormed = - // - isVWapSwitchedToBullishState - // isCloseOverVwapMax - // // - // && - // - // ( - // // - // // (isVWapBullishOrdered && - // // isVWapSwitchedToBullishState) - // // // - // // || - // // // - // // (isVWapBullishState && - // // isVWapSwitchedToBullishOrdered) - // // - // ) - // - ; - - // - bool isVwapBearishFormed = - // - isVWapSwitchedToBearishState - // isCloseUnderVwapMin - // // - // && - // - // ( - // // - // // (isVWapBearishOrdered && - // // isVWapSwitchedToBearishState) - // // // - // // || - // // // - // // (isVWapBearishState && - // // isVWapSwitchedToBearishOrdered) - // // - // ) - // - ; - - // - isBullish = - // hasBullishTrend && - isVwapBullishFormed; - - // - isBearish = - // hasBearishTrend && - isVwapBearishFormed; - - // - result = isBullish || - isBearish; - - // - // if (!result) - // { - // return result; - // } - - // // - // double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // // - // bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - // bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - - // // - // bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - // bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // // - // bool isSarBullishFormed = isSarBullish || - // isSarSwitchedToBullish; - - // // - // bool isSarBearishFormed = isSarBearish || - // isSarSwitchedToBearish; - - // // - // isBullish = - // isBullish && - // isSarBullishFormed; - - // // - // isBearish = - // isBearish && - // isSarBearishFormed; - - // // - // result = isBullish || - // isBearish; - // if (!result) - // { - // return result; - // } - - // // - // // Detect Pull Backs ... - - // // - // bool isSignalBarBullishPullBackFormed = - // cBar.IsBearish() && - // pBar.IsBullish() && - // cBar.low > pBar.low; - - // // - // bool isSignalBarBearishPullBackFormed = - // cBar.IsBullish() && - // pBar.IsBearish() && - // cBar.high < pBar.high; - - // // - // // Summary Pull Backs ... - - // // - // bool isBullishBarFormed = - // isSignalBarBullishPullBackFormed; - - // // - // bool isBearishhBarFormed = - // isSignalBarBearishPullBackFormed; - - // // - // isBullish = - // isBullish && - // isBullishBarFormed; - - // // - // isBearish = - // isBearish && - // isBearishhBarFormed; - - // // - // result = isBullish || - // isBearish; - // if (!result) - // { - // return result; - // } - - // // - // isBullish = - // // - // false - // // - // ; - - // // - // isBearish = - // // - // false - // // - // ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXVWPBSiganlTrigger( - // - X121SMCStrategyXVWPBSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1]; - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1]; - double verificationPeak = verificationConditions.x121Conditions.peaksBuffer[1]; - double consolidationPeak = consolidationConditions.x121Conditions.peaksBuffer[1]; - - // - double triggerVale = triggerConditions.x121Conditions.valesBuffer[1]; - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - double analyseVale = analyseConditions.x121Conditions.valesBuffer[1]; - double verificationVale = verificationConditions.x121Conditions.valesBuffer[1]; - double consolidationVale = consolidationConditions.x121Conditions.valesBuffer[1]; - - // - bool isPeaksSameFormed = - // - ( - // - triggerPeak == decisionPeak - // - ) - // - || - // - ( - // - triggerPeak == decisionPeak && - triggerPeak == analysePeak - // - ) - // - || - // - ( - // - triggerPeak == decisionPeak && - triggerPeak == analysePeak && - triggerPeak == verificationPeak - // - ) - // - || - // - ( - // - triggerPeak == decisionPeak && - triggerPeak == analysePeak && - triggerPeak == verificationPeak && - triggerPeak == consolidationPeak - // - ) - // - ; - - // - bool isValesSameFormed = - // - ( - // - triggerVale == decisionVale - // - ) - // - || - // - ( - // - triggerVale == decisionVale && - triggerVale == analyseVale - // - ) - // - || - // - ( - // - triggerVale == decisionVale && - triggerVale == analyseVale && - triggerVale == verificationVale - // - ) - // - || - // - ( - // - triggerVale == decisionVale && - triggerVale == analyseVale && - triggerVale == verificationVale && - triggerVale == consolidationVale - // - ) - // - ; - - // - isBullish = - // isValesSameFormed && - IsBullish(setupDir); - - // - isBearish = - // isPeaksSameFormed && - IsBearish(setupDir); - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check Last VWap State Change ... - XValueChange vwapStateChnges[]; - int vwapStateChngesCount = triggerCycleHelper - .FillVWapStateChanges(vwapStateChnges); - XValueChange lastVWapStateChnged; - bool hasLastVWapStateChanged = false; - if (IsValidSize(vwapStateChngesCount) && - vwapStateChngesCount >= 2) - { - // - lastVWapStateChnged = vwapStateChnges[vwapStateChngesCount - 2]; - hasLastVWapStateChanged = lastVWapStateChnged.IsValid(); - } - - // - double donOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; - double donOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; - - // - double donCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; - double donCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; - - // - bool isDonUpperBullish = donCloseUpper > donOpenUpper; - bool isDonUpperBearish = donCloseUpper < donOpenUpper; - - // - bool isDonLowerBullish = donCloseLower > donOpenLower; - bool isDonLowerBearish = donCloseLower < donOpenLower; - - // - bool isDonBullishFormed = - // - (isDonUpperBullish || - isDonLowerBullish) - // - ; - - // - bool isDonBearishFormed = - // - (isDonUpperBearish || - isDonLowerBearish) - // - ; - - // - isBullish = - (isNewValeOverLast || - isNewPeakOverLast) && - isDonBullishFormed && - hasLastVWapStateChanged && - (isBullish && - IsBullish(lastVWapStateChnged.dir)); - - // - isBearish = - (isNewPeakUnderLast || - isNewValeUnderLast) && - isDonBearishFormed && - hasLastVWapStateChanged && - (isBearish && - IsBearish(lastVWapStateChnged.dir)); - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Selecting SL ... - - // - double longSL = 0; - double shortSL = 0; - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - double longDistance = MathAbs(vwapMax - MathMax(triggerVale, donCloseLower)) / 2; - double shortDistance = MathAbs(vwapMin - MathMin(triggerPeak, donCloseUpper)) / 2; - - // - longSL = entry - longDistance; - shortSL = entry + shortDistance; - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? vwapMin - : vwapMax; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - - -////////////////////////////////////////// - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - // ENUM_X_DIRECTION trend; - // bool hasTrend = verificationCycleHelper - // .DetectTrend(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - // result = hasBullishTrend || - // hasBearishTrend; - // if (!result) - // { - // return result; - // } - - // - // Check Exists Valid Peaks or Vales ... - - // - // Peaks ... - XPVPivotPoint validPeaks[]; - XPVPivotPoint lastValidPeak; - int validPeaksCount = triggerCycleHelper - .FillPeakPivotPoints(validPeaks); - bool hasValidPeaks = IsValidSize(validPeaksCount); - if (hasValidPeaks) - { - lastValidPeak = validPeaks[validPeaksCount - 1]; - } - - // - // Vales ... - XPVPivotPoint validVales[]; - XPVPivotPoint lastValidVale; - int validValesCount = triggerCycleHelper - .FillValePivotPoints(validVales); - bool hasValidVales = IsValidSize(validValesCount); - if (hasValidVales) - { - lastValidVale = validVales[validValesCount - 1]; - } - - // - // Looking For New Peak or Vale ... - - // - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double cale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - isBullish = - // - isNewPeak && - hasValidPeaks && - isNewPeakUnderLast && - lastValidPeak.IsValid() - // - ; - - // - isBearish = - // - isNewVale && - hasValidVales && - isNewValeOverLast && - lastValidVale.IsValid() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check Sar Change ... - - // - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - - // - XValueChange lastSarChange; - bool hasLastSarChange = triggerCycleHelper - .GetLastSarChange(lastSarChange); - - // - isBullish = - // - isBullish && - isSarBullish && - hasLastSarChange && - sar > lastSarChange.before && - ask > lastSarChange.before && - bid > lastSarChange.before - // - ; - - // - isBearish = - // - isBearish && - isSarBearish && - hasLastSarChange && - sar < lastSarChange.before && - ask < lastSarChange.before && - bid < lastSarChange.before - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Check VWap State ... - - // - bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - - // - isBullish = - IsBullish(setupDir) && - isVWapBullishState; - - // - isBearish = - IsBearish(setupDir) && - isVWapBearishState; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Waitings For Sar Switched to Direction ... - - // - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - isBullish = - // - isBullish && - isSarSwitchedToBullish - // - ; - - // - isBearish = - // - isBearish && - isSarSwitchedToBearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest FVG or Supply Zone For Traget ... - - // - // Select Source State ... - XPOIState state = triggerState; - - // - double target = CalculateTarget( - cBar, - state, - setupDir // - ); - - // - result = target > 0; - if (!result) - { - return result; - } - - // - conditions.target = target; - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? sar - : sar; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - -////////////////////////////////////////// - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Lib -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVSUPDEMSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XCTicksZone *ticksZone; - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; - datetime activeZoneFoundedAt; - XCSupplyZone *activeSupplyZone; - XCDemandZone *activeDemandZone; - - // - // Constructor ... - X121SMCStrategyXPVSUPDEMSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - ticksZone = NULL; - activeSupplyZone = NULL; - activeDemandZone = NULL; - activeZoneFoundedAt = NULL; - - // - Clean(supplyZones); - Clean(demandZones); - } - - /** - * Count Supply Zones ... - * - * @return ( int ) - */ - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - /** - * Count Demand Zones ... - * - * @return ( int ) - */ - int CountDemandZones() - { - return ArraySize(demandZones); - } - - /** - * Check Has Supply Zones ... - * - * @return ( bool ) - */ - bool HasSupplyZones() - { - return IsValidSize(CountSupplyZones()); - } - - /** - * Check Has Demand Zones ... - * - * @return ( bool ) - */ - bool HasDemandZones() - { - return IsValidSize(CountDemandZones()); - } - - /** - * Check Has Active Supply or Demand Zone ... - * - * @param _dir: ENUM_X_DIRECTION member Reference for Specify Active Zone ... - * - * @return ( bool ) - */ - bool HasActiveZone(ENUM_X_DIRECTION &_dir) - { - // - bool result = false; - - // - _dir = X_DIRECTION_NONE; - - // - // Check Supplies ... - bool hasActiveSupplyZone = activeSupplyZone != NULL && - activeSupplyZone.IsValid(); - - // - // Check Demnds ... - bool hasActiveDemandZone = activeDemandZone != NULL && - activeDemandZone.IsValid(); - - // - result = hasActiveSupplyZone || - hasActiveDemandZone; - if (!result) - { - return result; - } - - // - _dir = hasActiveDemandZone - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Retrieve Active Zone Reference if Exists ... - * - * @return ( bool ) - */ - bool GetActiveZone(XCBarZone *&activeZone) - { - // - bool result = false; - - // - activeZone = NULL; - - // - ENUM_X_DIRECTION activeZoneDir; - result = HasActiveZone(activeZoneDir); - if (!result) - { - return result; - } - - // - if (IsBullish(activeZoneDir)) - { - // - activeDemandZone.To(TimeCurrent()); - activeZone = activeDemandZone; - } - else - { - // - activeSupplyZone.To(TimeCurrent()); - activeZone = activeSupplyZone; - } - - // - return result; - } - - /** - * Clean Active Zone ... - */ - void CleanActiveZone() - { - // - activeSupplyZone = NULL; - activeDemandZone = NULL; - activeZoneFoundedAt = NULL; - } - - /** - * Check Ticks Zone is Initialized or not ... - * @return ( bool ) - */ - bool HasTicksZone() - { - // - bool result = false; - - // - result = - // - ticksZone != NULL && - ticksZone.IsValid() && - IsValidSize(ticksZone.Count()) - // - ; - - // - return result; - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVSUPDEMSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVSUPDEMSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = consolidationCycleHelper - .DetectTrend(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasBullishTrend || - hasBearishTrend; - if (!result) - { - return result; - } - - // - // Select Source State ... - XPOIState state = consolidationState; - - // - // Detect Supply and Demand Zones ... - - // - // Supply ... - bool hasSupplyZones = conditions.HasSupplyZones(); - if (!hasSupplyZones) - { - // - int count = state.CountSupplyZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCSupplyZone *iZone = state.supplyZones[i]; - - // - bool isValid = - // - ask < iZone.Lower() && - bid < iZone.Lower() && - cBar.high < iZone.Lower() - // - ; - if (isValid) - { - // - Add( - iZone, - conditions.supplyZones // - ); - } - } - - // - hasSupplyZones = conditions.HasSupplyZones(); - result = hasSupplyZones; - if (!result) - { - return result; - } - } - - // - // Demand ... - bool hasDemandZones = conditions.HasDemandZones(); - if (!hasDemandZones) - { - // - int count = state.CountDemandZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCDemandZone *iZone = state.demandZones[i]; - - // - bool isValid = - // - ask > iZone.Upper() && - bid > iZone.Upper() && - cBar.low > iZone.Upper() - // - ; - if (isValid) - { - // - Add( - iZone, - conditions.demandZones // - ); - } - } - - // - hasDemandZones = conditions.HasDemandZones(); - result = hasDemandZones; - if (!result) - { - return result; - } - } - - // - // Waits For Price to Go Inside a Zone ... - ENUM_X_DIRECTION activeZoneDir = X_DIRECTION_NONE; - bool hasActiveZone = conditions.HasActiveZone(activeZoneDir); - if (!hasActiveZone) - { - // - // Looking Up For Active Zone ... - - // - // Supply ... - if (hasSupplyZones) - { - // - int count = conditions.CountSupplyZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCSupplyZone *iZone = conditions.supplyZones[i]; - - // - bool isValid = - // - ask <= iZone.Upper() && - bid <= iZone.Upper() && - ask >= iZone.Lower() && - bid >= iZone.Lower() && - cBar.high <= iZone.Upper() && - cBar.low >= iZone.Lower() - // - ; - if (isValid) - { - // - conditions.activeSupplyZone = iZone; - break; - } - } - } - - // - hasActiveZone = conditions.HasActiveZone(activeZoneDir); - if (!hasActiveZone) - { - // - // Demand ... - if (hasDemandZones) - { - // - int count = conditions.CountDemandZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCDemandZone *iZone = conditions.demandZones[i]; - - // - bool isValid = - // - ask <= iZone.Upper() && - bid <= iZone.Upper() && - ask >= iZone.Lower() && - bid >= iZone.Lower() && - cBar.high <= iZone.Upper() && - cBar.low >= iZone.Lower() - // - ; - if (isValid) - { - // - conditions.activeDemandZone = iZone; - break; - } - } - } - } - - // - hasActiveZone = conditions.HasActiveZone(activeZoneDir); - result = hasActiveZone; - if (!result) - { - return result; - } - - // - conditions.activeZoneFoundedAt = cTime; - } - - // - // Now we Have to Calculate Active Zones Ticks ... - - // - bool isValidDemandZone = - hasActiveZone && - hasBullishTrend && - IsBullish(activeZoneDir); - - // - bool isValidSupplyZone = - hasActiveZone && - hasBearishTrend && - IsBearish(activeZoneDir); - - // - result = isValidDemandZone || - isValidSupplyZone; - if (!result) - { - // - conditions.CleanActiveZone(); - return result; - } - - // - // Select Active Zone ... - XCBarZone *activeZone = NULL; - result = conditions.GetActiveZone(activeZone); - if (!result) - { - return result; - } - - // - // Extract Active Zone Start Bar ... - XOHCL fromBar; - datetime fromTime = activeZone.BarTime(); - result = triggerCycleHelper.GetBar( - fromBar, - fromTime // - ); - if (!result) - { - return result; - } - - // - bool hasTicksZone = conditions.HasTicksZone(); - if (!hasTicksZone) - { - // - // Istantiate Ticks Zone ... - conditions.ticksZone = new XCTicksZone(); - conditions.ticksZone.Levels(40); - } - - // - // Update Ticks Zone ... - result = conditions.ticksZone.Init( - fromBar, - cBar // - ); - if (!result) - { - return result; - } - - // - // Regenrate Conditions ... - hasTicksZone = conditions.HasTicksZone(); - result = hasTicksZone; - if (!result) - { - return result; - } - - // - // Make Sure we Have a Direction for Setup ... - isBullish = IsBullish(activeZoneDir); - isBearish = IsBearish(activeZoneDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check New Peaks or Vales Happens inside Zero Tick or Volume Percent Zone and - // also Active Zone ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - bool isPeakInsideActiveZone = - // - peak <= activeZone.Upper() && - peak >= activeZone.Lower() - // - ; - bool isValeInsideActiveZone = - // - vale <= activeZone.Upper() && - vale >= activeZone.Lower() - // - ; - - // - bool isPeakInsideZeroZone = false; - bool isValeInsideZeroZone = false; - int tzCount = conditions.ticksZone.Count(); - if (IsValidSize(tzCount)) - { - // - for (int i = 0; i < tzCount; i++) - { - // - XCTickZone *iTZ = conditions.ticksZone.GetZone(i); - - // - if (isBearish && - !isPeakInsideZeroZone) - { - // - isPeakInsideZeroZone = - // - peak <= iTZ.high && - peak >= iTZ.low && - (iTZ.percent == 0 || - iTZ.volumePercent == 0) - // - ; - } - - // - if (isBullish && - !isValeInsideZeroZone) - { - // - isValeInsideZeroZone = - // - vale <= iTZ.high && - vale >= iTZ.low && - (iTZ.percent == 0 || - iTZ.volumePercent == 0) - // - ; - } - - // - if (isPeakInsideZeroZone || - isValeInsideZeroZone) - { - break; - } - } - } - - // - isBullish = - // - isBullish && - isNewValeUnderLast && - isValeInsideZeroZone && - isValeInsideActiveZone - // - ; - - // - isBearish = - // - isBearish && - isNewPeakOverLast && - isPeakInsideZeroZone && - isPeakInsideActiveZone - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - int activeZoneAge = (int)(cTime - conditions.activeZoneFoundedAt) / PeriodSeconds(conditions.period); - if (activeZoneAge >= 200) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVSUPDEMSiganlTrigger( - // - X121SMCStrategyXPVSUPDEMSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Select Active Zone Class ... - XCBarZone *activeZone = NULL; - result = conditions.GetActiveZone(activeZone); - if (!result) - { - return result; - } - - // - // Check Last Valid Peak or Last Valid Vales Breaks ... - // Beak Of Structure ... - - // - // Peak ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - XPVPivotPoint lastPeakPivot; - bool hasLastPeakPivot = triggerCycleHelper - .GetLastPeakPivotPoint(lastPeakPivot); - bool isLastPeakPivotBreaked = - // - lastPeakPivot.IsPeak() && - lastPeakPivot.IsValid() && - peak > lastPeakPivot.value - // - ; - - // - // Vale ... - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - XPVPivotPoint lastValePivot; - bool hasLastValePivot = triggerCycleHelper - .GetLastValePivotPoint(lastValePivot); - bool isLastValePivotBreaked = - // - lastValePivot.IsVale() && - lastValePivot.IsValid() && - vale < lastValePivot.value - // - ; - - // - isBullish = - // - IsBullish(setupDir) && - isLastValePivotBreaked - // - ; - - // - isBearish = - // - IsBearish(setupDir) && - isLastPeakPivotBreaked - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? activeZone.Lower() - : activeZone.Upper(); - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - -////////////////////////////////////////// - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Lib -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVOBSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XCOrderBlock *bullishOBs[]; - XCOrderBlock *bearishOBs[]; - - // - XCFVG *activeFVG; - XCFVG *bullishFVGs[]; - XCFVG *bearishFVGs[]; - - // - // Constructor ... - X121SMCStrategyXPVOBSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - activeFVG = NULL; - Clean(bullishOBs); - Clean(bearishOBs); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - // - int CountBullishOBs() - { - return ArraySize(bullishOBs); - } - - // - int CountBearishOBs() - { - return ArraySize(bearishOBs); - } - - // - bool HasBullishOB() - { - return IsValidSize(CountBullishOBs()); - } - - // - bool HasBearishOB() - { - return IsValidSize(CountBearishOBs()); - } - - // - int CountBullishFVGs() - { - return ArraySize(bullishFVGs); - } - - // - int CountBearishFVGs() - { - return ArraySize(bearishFVGs); - } - - // - bool HasBullishFVG() - { - return IsValidSize(CountBullishFVGs()); - } - - // - bool HasBearishFVG() - { - return IsValidSize(CountBearishFVGs()); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVOBSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVOBSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = consolidationCycleHelper - .DetectTrend(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasBullishTrend || - hasBearishTrend; - if (!result) - { - return result; - } - - // - // Select Source State ... - XPOIState state = decisionState; - - // - // Detect Imbalance ... - - // - bool hasBullishOB = conditions.HasBullishOB(); - if (!hasBullishOB) - { - // - int count = state.CountBullishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = state.bullishOrderBlocks[i]; - - // - // Validate Order Block ... - bool isValid = - // - cBar.low > iOB.Upper() - // - ; - if (isValid) - { - // - Add( - iOB, - conditions.bullishOBs // - ); - } - } - } - - // - hasBullishOB = conditions.HasBullishOB(); - } - - // - bool hasBearishOB = conditions.HasBearishOB(); - if (!hasBearishOB) - { - // - int count = state.CountBearishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = state.bearishOrderBlocks[i]; - - // - // Validate Order Block ... - bool isValid = - // - cBar.high < iOB.Lower() - // - ; - if (isValid) - { - // - Add( - iOB, - conditions.bearishOBs // - ); - } - } - } - - // - hasBearishOB = conditions.HasBearishOB(); - } - - // - result = hasBullishOB || - hasBearishOB; - if (!result) - { - return result; - } - - // - int fvgValidationLength = 5; - - // - bool hasBullishFVG = conditions.HasBullishFVG(); - if (!hasBullishFVG) - { - // - if (hasBullishOB) - { - // - int obsCount = conditions.CountBullishOBs(); - int count = state.CountBullishFairValueGaps(); - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = conditions.bullishOBs[i]; - - // - for (int j = 0; j < count; j++) - { - // - XCFVG *jFVG = state.bullishFairValueGaps[j]; - - // - bool isValid = - // - cBar.low > iOB.Upper() && - cBar.low > jFVG.Upper() && - // - jFVG.From() > iOB.From() && - (((int)(jFVG.From() - iOB.From())) / PeriodSeconds(state.period)) <= fvgValidationLength - // - ; - if (isValid) - { - // - Add( - jFVG, - conditions.bullishFVGs // - ); - } - } - } - } - - // - hasBullishFVG = conditions.HasBullishFVG(); - } - - // - bool hasBearishFVG = conditions.HasBearishFVG(); - if (!hasBearishFVG) - { - // - if (hasBullishOB) - { - // - int obsCount = conditions.CountBearishOBs(); - int count = state.CountBearishFairValueGaps(); - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = conditions.bearishOBs[i]; - - // - for (int j = 0; j < count; j++) - { - // - XCFVG *jFVG = state.bearishFairValueGaps[j]; - - // - bool isValid = - // - cBar.high < iOB.Lower() && - cBar.high < jFVG.Lower() && - // - jFVG.From() > iOB.From() && - (((int)(jFVG.From() - iOB.From())) / PeriodSeconds(state.period)) <= fvgValidationLength - // - ; - if (isValid) - { - // - Add( - jFVG, - conditions.bearishFVGs // - ); - } - } - } - } - - // - hasBearishFVG = conditions.HasBearishFVG(); - } - - // - result = (hasBullishOB && - hasBullishFVG) || - (hasBearishOB && - hasBearishFVG); - if (!result) - { - return result; - } - - // - // Detect new Peak or new Vale ... - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - result = isNewPeak || - isNewVale; - if (!result) - { - return result; - } - - // - // Detect Setup Conditions based on Peaks or Vales Occurance ... - - // - bool lookupForLong = isNewVale && - hasBullishOB && - hasBullishFVG && - hasBullishTrend; - - // - bool lookupForShort = isNewPeak && - hasBearishOB && - hasBearishFVG && - hasBearishTrend; - - // - result = lookupForLong || - lookupForShort; - if (!result) - { - return result; - } - - // - XCFVG *fvg = NULL; - double fvgZoneValidationRangePercent = 0; - if (lookupForLong) - { - // - // Long Conditions ... - // Vales must be Happens Inside Bullish Fair Value Gaps ... - int count = conditions.CountBullishFVGs(); - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = conditions.bullishFVGs[i]; - - // - bool isValid = - // - vale <= iFVG.Upper() && - vale >= iFVG.Lower() && - (fvgZoneValidationRangePercent <= 0 - ? true - : (vale < iFVG.Upper() - (iFVG.RangePercent() * fvgZoneValidationRangePercent))) - // - ; - if (isValid) - { - // - fvg = iFVG; - break; - } - } - - // - isBullish = - // - fvg != NULL && - fvg.IsValid() - // - ; - if (isBullish) - { - conditions.activeFVG = fvg; - } - } - else if (lookupForShort) - { - // - // Short Conditions ... - // Peaks Must be Happens Inside Bearish Fair Value Gaps ... - int count = conditions.CountBearishFVGs(); - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = conditions.bearishFVGs[i]; - - // - bool isValid = - // - peak <= iFVG.Upper() && - peak >= iFVG.Lower() && - (fvgZoneValidationRangePercent <= 0 - ? true - : (peak > iFVG.Lower() + (iFVG.RangePercent() * fvgZoneValidationRangePercent))) - // - ; - if (isValid) - { - // - fvg = iFVG; - break; - } - } - - // - isBearish = - // - fvg != NULL && - fvg.IsValid() - // - ; - if (isBearish) - { - conditions.activeFVG = fvg; - } - } - - // - result = isBullish || - isBearish; - if (!result) - { - // - if (lookupForLong) - { - // - conditions.activeFVG = NULL; - Clean(conditions.bullishOBs); - Clean(conditions.bullishFVGs); - } - else if (lookupForShort) - { - // - conditions.activeFVG = NULL; - Clean(conditions.bearishOBs); - Clean(conditions.bearishFVGs); - } - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVOBSiganlTrigger( - // - X121SMCStrategyXPVOBSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - XCFVG *iFVG = conditions.activeFVG; - result = iFVG != NULL && - iFVG.IsValid(); - if (!result) - { - return result; - } - - // - bool lookupLong = IsBullish(setupDir) && - iFVG.IsBullish(); - bool lookupShort = IsBearish(setupDir) && - iFVG.IsBearish(); - result = lookupLong || - lookupShort; - if (!result) - { - return result; - } - - // - // Check PEAKS and Vales ... - - // - // Trigger ... - - // - // Peaks and Vales ... - double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1]; - double triggerVale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - bool isTriggerPeakInsideFVG = - // - triggerPeak <= iFVG.Upper() && - triggerPeak >= iFVG.Lower() - // - ; - bool isTriggerValeInsideFVG = - // - triggerVale <= iFVG.Upper() && - triggerVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isTriggerVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish; - bool isTriggerVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish; - bool isTriggerVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish; - - // - bool isTriggerVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid; - bool isTriggerVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isTriggerVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish; - bool isTriggerVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish; - bool isTriggerVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish; - - // - bool isTriggerVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid; - bool isTriggerVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isTriggerMarketBullish = - // - // State ... - ( - // - (isTriggerVWapFastBullish && - isTriggerVWapMidBullish && - isTriggerVWapSlowBullish) - // - || - // - (isTriggerVWapMidBullish && - isTriggerVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isTriggerVWapFastOverMid && - isTriggerVWapMidOverSlow) - // - || - // - isTriggerVWapMidOverSlow - // - ) - // - ; - - // - bool isTriggerMarketBearish = - // - // State ... - ( - // - (isTriggerVWapFastBearish && - isTriggerVWapMidBearish && - isTriggerVWapSlowBearish) - // - || - // - (isTriggerVWapMidBearish && - isTriggerVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isTriggerVWapFastUnderMid && - isTriggerVWapMidUnderSlow) - // - || - // - isTriggerVWapMidUnderSlow - // - ) - // - ; - - // - // Decision ... - - // - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - - // - bool isDecisionPeakInsideFVG = - // - decisionPeak <= iFVG.Upper() && - decisionPeak >= iFVG.Lower() - // - ; - bool isDecisionValeInsideFVG = - // - decisionVale <= iFVG.Upper() && - decisionVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isDecisionVWapFastBullish = decisionConditions.x121Conditions.isVWapFastBullish; - bool isDecisionVWapMidBullish = decisionConditions.x121Conditions.isVWapMidBullish; - bool isDecisionVWapSlowBullish = decisionConditions.x121Conditions.isVWapSlowBullish; - - // - bool isDecisionVWapFastOverMid = decisionConditions.x121Conditions.isVWapFastOverMid; - bool isDecisionVWapMidOverSlow = decisionConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isDecisionVWapFastBearish = decisionConditions.x121Conditions.isVWapFastBearish; - bool isDecisionVWapMidBearish = decisionConditions.x121Conditions.isVWapMidBearish; - bool isDecisionVWapSlowBearish = decisionConditions.x121Conditions.isVWapSlowBearish; - - // - bool isDecisionVWapFastUnderMid = decisionConditions.x121Conditions.isVWapFastUnderMid; - bool isDecisionVWapMidUnderSlow = decisionConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isDecisionMarketBullish = - // - // State ... - ( - // - (isDecisionVWapFastBullish && - isDecisionVWapMidBullish && - isDecisionVWapSlowBullish) - // - || - // - (isDecisionVWapMidBullish && - isDecisionVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isDecisionVWapFastOverMid && - isDecisionVWapMidOverSlow) - // - || - // - isDecisionVWapMidOverSlow - // - ) - // - ; - - // - bool isDecisionMarketBearish = - // - // State ... - ( - // - (isDecisionVWapFastBearish && - isDecisionVWapMidBearish && - isDecisionVWapSlowBearish) - // - || - // - (isDecisionVWapMidBearish && - isDecisionVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isDecisionVWapFastUnderMid && - isDecisionVWapMidUnderSlow) - // - || - // - isDecisionVWapMidUnderSlow - // - ) - // - ; - - // - // Analyse ... - - // - double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1]; - double analyseVale = analyseConditions.x121Conditions.valesBuffer[1]; - - // - bool isAnalysePeakInsideFVG = - // - analysePeak <= iFVG.Upper() && - analysePeak >= iFVG.Lower() - // - ; - bool isAnalyseValeInsideFVG = - // - analyseVale <= iFVG.Upper() && - analyseVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isAnalyseVWapFastBullish = analyseConditions.x121Conditions.isVWapFastBullish; - bool isAnalyseVWapMidBullish = analyseConditions.x121Conditions.isVWapMidBullish; - bool isAnalyseVWapSlowBullish = analyseConditions.x121Conditions.isVWapSlowBullish; - - // - bool isAnalyseVWapFastOverMid = analyseConditions.x121Conditions.isVWapFastOverMid; - bool isAnalyseVWapMidOverSlow = analyseConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isAnalyseVWapFastBearish = analyseConditions.x121Conditions.isVWapFastBearish; - bool isAnalyseVWapMidBearish = analyseConditions.x121Conditions.isVWapMidBearish; - bool isAnalyseVWapSlowBearish = analyseConditions.x121Conditions.isVWapSlowBearish; - - // - bool isAnalyseVWapFastUnderMid = analyseConditions.x121Conditions.isVWapFastUnderMid; - bool isAnalyseVWapMidUnderSlow = analyseConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isAnalyseMarketBullish = - // - // State ... - ( - // - (isAnalyseVWapFastBullish && - isAnalyseVWapMidBullish && - isAnalyseVWapSlowBullish) - // - || - // - (isAnalyseVWapMidBullish && - isAnalyseVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isAnalyseVWapFastOverMid && - isAnalyseVWapMidOverSlow) - // - || - // - isAnalyseVWapMidOverSlow - // - ) - // - ; - - // - bool isAnalyseMarketBearish = - // - // State ... - ( - // - (isAnalyseVWapFastBearish && - isAnalyseVWapMidBearish && - isAnalyseVWapSlowBearish) - // - || - // - (isAnalyseVWapMidBearish && - isAnalyseVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isAnalyseVWapFastUnderMid && - isAnalyseVWapMidUnderSlow) - // - || - // - isAnalyseVWapMidUnderSlow - // - ) - // - ; - - // - // Verification ... - - // - double verificationPeak = verificationConditions.x121Conditions.peaksBuffer[1]; - double verificationVale = verificationConditions.x121Conditions.valesBuffer[1]; - - // - bool isVerificationPeakInsideFVG = - // - verificationPeak <= iFVG.Upper() && - verificationPeak >= iFVG.Lower() - // - ; - bool isVerificationValeInsideFVG = - // - verificationVale <= iFVG.Upper() && - verificationVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isVerificationVWapFastBullish = verificationConditions.x121Conditions.isVWapFastBullish; - bool isVerificationVWapMidBullish = verificationConditions.x121Conditions.isVWapMidBullish; - bool isVerificationVWapSlowBullish = verificationConditions.x121Conditions.isVWapSlowBullish; - - // - bool isVerificationVWapFastOverMid = verificationConditions.x121Conditions.isVWapFastOverMid; - bool isVerificationVWapMidOverSlow = verificationConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isVerificationVWapFastBearish = verificationConditions.x121Conditions.isVWapFastBearish; - bool isVerificationVWapMidBearish = verificationConditions.x121Conditions.isVWapMidBearish; - bool isVerificationVWapSlowBearish = verificationConditions.x121Conditions.isVWapSlowBearish; - - // - bool isVerificationVWapFastUnderMid = verificationConditions.x121Conditions.isVWapFastUnderMid; - bool isVerificationVWapMidUnderSlow = verificationConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isVerificationMarketBullish = - // - // State ... - ( - // - (isVerificationVWapFastBullish && - isVerificationVWapMidBullish && - isVerificationVWapSlowBullish) - // - || - // - (isVerificationVWapMidBullish && - isVerificationVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isVerificationVWapFastOverMid && - isVerificationVWapMidOverSlow) - // - || - // - isVerificationVWapMidOverSlow - // - ) - // - ; - - // - bool isVerificationMarketBearish = - // - // State ... - ( - // - (isVerificationVWapFastBearish && - isVerificationVWapMidBearish && - isVerificationVWapSlowBearish) - // - || - // - (isVerificationVWapMidBearish && - isVerificationVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isVerificationVWapFastUnderMid && - isVerificationVWapMidUnderSlow) - // - || - // - isVerificationVWapMidUnderSlow - // - ) - // - ; - - // - // Consolidation ... - - // - double consolidationPeak = consolidationConditions.x121Conditions.peaksBuffer[1]; - double consolidationVale = consolidationConditions.x121Conditions.valesBuffer[1]; - - // - bool isConsolidationPeakInsideFVG = - // - consolidationPeak <= iFVG.Upper() && - consolidationPeak >= iFVG.Lower() - // - ; - bool isConsolidationValeInsideFVG = - // - consolidationVale <= iFVG.Upper() && - consolidationVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isConsolidationVWapFastBullish = consolidationConditions.x121Conditions.isVWapFastBullish; - bool isConsolidationVWapMidBullish = consolidationConditions.x121Conditions.isVWapMidBullish; - bool isConsolidationVWapSlowBullish = consolidationConditions.x121Conditions.isVWapSlowBullish; - - // - bool isConsolidationVWapFastOverMid = consolidationConditions.x121Conditions.isVWapFastOverMid; - bool isConsolidationVWapMidOverSlow = consolidationConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isConsolidationVWapFastBearish = consolidationConditions.x121Conditions.isVWapFastBearish; - bool isConsolidationVWapMidBearish = consolidationConditions.x121Conditions.isVWapMidBearish; - bool isConsolidationVWapSlowBearish = consolidationConditions.x121Conditions.isVWapSlowBearish; - - // - bool isConsolidationVWapFastUnderMid = consolidationConditions.x121Conditions.isVWapFastUnderMid; - bool isConsolidationVWapMidUnderSlow = consolidationConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isConsolidationMarketBullish = - // - // State ... - ( - // - (isConsolidationVWapFastBullish && - isConsolidationVWapMidBullish && - isConsolidationVWapSlowBullish) - // - || - // - (isConsolidationVWapMidBullish && - isConsolidationVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isConsolidationVWapFastOverMid && - isConsolidationVWapMidOverSlow) - // - || - // - isConsolidationVWapMidOverSlow - // - ) - // - ; - - // - bool isConsolidationMarketBearish = - // - // State ... - ( - // - (isConsolidationVWapFastBearish && - isConsolidationVWapMidBearish && - isConsolidationVWapSlowBearish) - // - || - // - (isConsolidationVWapMidBearish && - isConsolidationVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isConsolidationVWapFastUnderMid && - isConsolidationVWapMidUnderSlow) - // - || - // - isConsolidationVWapMidUnderSlow - // - ) - // - ; - - // - // Sar ... - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - // Summarize Conditions ... - - // - bool isSamePeak = - triggerPeak == decisionPeak && - triggerPeak == analysePeak && - triggerPeak == verificationPeak; - - // - bool isPeaksInsideFVG = - // - isTriggerPeakInsideFVG && - isDecisionPeakInsideFVG && - isAnalysePeakInsideFVG && - isVerificationPeakInsideFVG - // - ; - - // - bool isSameVale = - triggerVale == decisionVale && - triggerVale == analyseVale && - triggerVale == verificationVale; - - // - bool isValesInsideFVG = - // - isTriggerValeInsideFVG && - isDecisionValeInsideFVG && - isAnalyseValeInsideFVG && - isVerificationValeInsideFVG - // - ; - - // - bool isMarketReadyForLong = - // - // !isTriggerMarketBearish && - // !isDecisionMarketBearish && - // !isAnalyseMarketBearish && - isTriggerMarketBullish && - !isVerificationMarketBearish && - !isConsolidationMarketBearish - // - ; - - // - bool isMarketReadyForShort = - // - // !isTriggerMarketBullish && - // !isDecisionMarketBullish && - // !isAnalyseMarketBullish && - isTriggerMarketBearish && - !isVerificationMarketBullish && - !isConsolidationMarketBullish - // - ; - - // - // Create Trigger ... - - // - isBullish = - // isSameVale && - lookupLong && - isValesInsideFVG && - // isMarketReadyForLong && - isSarSwitchedToBullish && - triggerVale <= iFVG.Upper() && - triggerVale >= iFVG.Lower(); - - // - isBearish = - // isSamePeak && - lookupShort && - isPeaksInsideFVG && - // isMarketReadyForShort && - isSarSwitchedToBearish && - triggerPeak <= iFVG.Upper() && - triggerPeak >= iFVG.Lower(); - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? iFVG.Lower() - : iFVG.Upper(); - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - -////////////////////////////////////////// - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Lib -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVDPSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double peak; - double vale; - - // - // Constructor ... - X121SMCStrategyXPVDPSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - peak = 0; - vale = 0; - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVDPSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVDPSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = consolidationCycleHelper - .DetectTrend(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasBullishTrend || - hasBearishTrend; - if (!result) - { - return result; - } - - // - // Select Source State ... - XPOIState state = decisionState; - - // - // Detect High Equals to Peaks or Low Equals to Vale ... - - // - // Peak ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - // Vale ... - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - bool isHighEqualsToPeak = - isNewPeak && - peak == cBar.high; - - // - bool isLowEqualsToVale = - isNewVale && - vale == cBar.low; - - // - result = isHighEqualsToPeak || - isLowEqualsToVale; - if (!result) - { - return result; - } - - // - // Now We Have To Check DONChain Status ... - - // - double donCUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; - double donCUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2]; - - // - double donCLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; - double donCLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2]; - - // - double donOUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; - double donOUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2]; - - // - double donOLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; - double donOLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2]; - - // - bool isDonUpperBullish = donCUpper > donOUpper; - bool isDonUpperBullishPrev = donCUpperPrev > donOUpperPrev; - - // - bool isDonUpperBearish = donCUpper < donOUpper; - bool isDonUpperBearishPrev = donCUpperPrev < donOUpperPrev; - - // - bool isDonUpperSwitchedToBullish = isDonUpperBullish && - !isDonUpperBullishPrev; - - // - bool isDonUpperSwitchedToBearish = isDonUpperBearish && - !isDonUpperBearishPrev; - - // - bool isDonLowerBullish = donCLower > donOLower; - bool isDonLowerBullishPrev = donCLowerPrev > donOLowerPrev; - - // - bool isDonLowerBearish = donCLower < donOLower; - bool isDonLowerBearishPrev = donCLowerPrev < donOLowerPrev; - - // - bool isDonLowerSwitchedToBullish = isDonLowerBullish && - !isDonLowerBullishPrev; - - // - bool isDonLowerSwitchedToBearish = isDonLowerBearish && - !isDonLowerBearishPrev; - - // - // Calculate State ... - - // - bool isDonInBullishState = - // - // Upper ... - (isDonUpperBullish || - isDonUpperSwitchedToBullish) - // - && - // - // Lower ... - (isDonLowerBullish || - isDonLowerSwitchedToBullish) - // - ; - - // - bool isDonInBearishState = - // - // Upper ... - (isDonUpperBearish || - isDonUpperSwitchedToBearish) - // - && - // - // Lower ... - (isDonLowerBearish || - isDonLowerSwitchedToBearish) - // - ; - - // - // Summary DonChain State ... - - // - isBullish = - // - hasBullishTrend - // - && - // - isDonInBullishState - // - && - // - (isHighEqualsToPeak || - isLowEqualsToVale) - // - ; - - // - isBearish = - // - hasBearishTrend - // - && - // - isDonInBearishState - // - && - // - (isHighEqualsToPeak || - isLowEqualsToVale) - // - ; - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check VWap Conditions ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - bool isCloseOverVwapMax = - // - ask > vwapMax && - bid > vwapMax && - (cBar.low > vwapMax || - cBar.close > vwapMax) - // - ; - - // - bool isCloseUnderVwapMin = - // - ask < vwapMin && - bid < vwapMin && - (cBar.high < vwapMin || - cBar.close < vwapMin) - // - ; - - // - bool isVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish; - bool isVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish; - bool isVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish; - bool isVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish; - bool isVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish; - bool isVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish; - bool isVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid; - bool isVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow; - bool isVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid; - bool isVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isVwapBullishFormed = - // - // Order ... - (isVWapFastOverMid || - isVWapMidOverSlow || - (isVWapFastOverMid && - isVWapMidOverSlow)) - // - && - // State ... - ((isVWapFastBullish && - isVWapMidBullish) || - (isVWapMidBullish && - isVWapSlowBullish) || - (isVWapFastBullish && - isVWapMidBullish && - isVWapSlowBullish)) - // - ; - - // - bool isVwapBearishFormed = - // - // Order ... - (isVWapFastUnderMid || - isVWapMidUnderSlow || - (isVWapFastUnderMid && - isVWapMidUnderSlow)) - // - && - // State ... - ((isVWapFastBearish && - isVWapMidBearish) || - (isVWapMidBearish && - isVWapSlowBearish) || - (isVWapFastBearish && - isVWapMidBearish && - isVWapSlowBearish)) - // - ; - - // - // Summar VWap State ... - - // - isBullish = - isBullish && - isCloseOverVwapMax && - isVwapBullishFormed; - - // - isBearish = - isBearish && - isCloseUnderVwapMin && - isVwapBearishFormed; - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check Sar State ... - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - - // - bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - // Summary Sar ... - - // - bool isSarBullishFormed = isSarBullish || - isSarSwitchedToBullish; - - // - bool isSarBearishFormed = isSarBearish || - isSarSwitchedToBearish; - - // - isBullish = - isBullish && - isSarBullishFormed; - - // - isBearish = - isBearish && - isSarBearishFormed; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVDPSiganlTrigger( - // - X121SMCStrategyXPVDPSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - isBullish = - // - IsBullish(setupDir) - // - ; - - // - isBearish = - // - IsBearish(setupDir) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? MathMin(sar, vwapMin) - : MathMin(sar, vwapMax); - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - -////////////////////////////////////////// - -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyTestSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - // Constructor ... - X121SMCStrategyTestSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCTestSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyTestSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - isBullish = - // - false - // - ; - - // - isBearish = - // - false - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCTestSiganlTrigger( - // - X121SMCStrategyTestSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - isBullish = - // - false - // - ; - - // - isBearish = - // - false - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? 0 - : 0; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// - -////////////////////////////////////////// - - -////////////////////////////////////////// - - -////////////////////////////////////////// \ No newline at end of file diff --git a/Documents/BKP/3/x-smc.signal.detectors.mq5 b/Documents/BKP/3/x-smc.signal.detectors.mq5 deleted file mode 100644 index c0bf4049..00000000 --- a/Documents/BKP/3/x-smc.signal.detectors.mq5 +++ /dev/null @@ -1,911 +0,0 @@ -///////////////////////////////////////////////////////////////////////// - - // - // Detect Signal Conditions ... - bool hasSignal = false; - - // - bool useTestSignal = false; - bool useXPVOBSignal = false; - bool useXPVDPSignal = false; - bool useXVWPBSignal = false; - bool useXTWPVSignal = true; - bool useXPVSUPDEMSignal = false; - - // - bool hasTestSignal = false; - bool hasXPVOBSignal = false; - bool hasXPVDPSignal = false; - bool hasXVWPBSignal = false; - bool hasXTWPVSignal = false; - bool hasXPVSUPDEMSignal = false; - - // - // Test Signal ... - if (useTestSignal && !hasSignal) - { - // - hasTestSignal = DetectTestSignal(conditions); - hasSignal = hasTestSignal; - } - - // - // XPVOB Signal ... - if (useXPVOBSignal && !hasSignal) - { - // - hasXPVOBSignal = DetectXPVOBSignal(conditions); - hasSignal = hasXPVOBSignal; - } - - // - // XPVDP Signal ... - if (useXPVDPSignal && !hasSignal) - { - // - hasXPVDPSignal = DetectXPVDPSignal(conditions); - hasSignal = hasXPVDPSignal; - } - - // - // XVWPB Signal ... - if (useXVWPBSignal && !hasSignal) - { - // - hasXVWPBSignal = DetectXVWPBSignal(conditions); - hasSignal = hasXVWPBSignal; - } - - // - // XTWPV Signal ... - if (useXTWPVSignal && !hasSignal) - { - // - hasXTWPVSignal = DetectXTWPVSignal(conditions); - hasSignal = hasXTWPVSignal; - } - - // - // XPVSUPDEM Signal ... - if (useXPVSUPDEMSignal && !hasSignal) - { - // - hasXPVSUPDEMSignal = DetectXPVSUPDEMSignal(conditions); - hasSignal = hasXPVSUPDEMSignal; - } - -//////////////////////////////////////////////////////////////////////// - - - // - // Test Signal ... - X121SMCStrategyTestSignalConditions mTestConditions; - bool DetectTestSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTEST; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mTestConditions.setupTime; - bool isSetuped = mTestConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mTestConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCTestSiganlSetup( - symbol, - period, - mTestConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mTestConditions.dir; - setupTime = mTestConditions.setupTime; - } - - // ClearDraws(); - // ENUM_X_DIRECTION activeZoneDir; - // bool hasTicksZone = mTestConditions.HasTicksZone(); - // bool hasActiveZone = mTestConditions.HasActiveZone(activeZoneDir); - // if (hasActiveZone) - // { - // // - // if (IsBullish(activeZoneDir)) - // { - // // - // mTestConditions.activeDemandZone.To(cTime); - // XCDemandZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateDemandZone( - // mTestConditions.activeDemandZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // else - // { - // // - // mTestConditions.activeSupplyZone.To(cTime); - // XCSupplyZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateSupplyZone( - // mTestConditions.activeSupplyZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // } - // if (hasTicksZone) - // { - // // - // XCTicksZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateTicksZone( - // mTestConditions.ticksZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mTestConditions.CanTrigger(); - datetime triggerTime = mTestConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCTestSiganlTrigger( - mTestConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mTestConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mTestConditions.sl; - conditions.target = mTestConditions.target; - - // - mTestConditions.Clean(); - - // - return result; - } - - // - // XPVOB Signal ... - X121SMCStrategyXPVOBSignalConditions mXPVOBConditions; - bool DetectXPVOBSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVOB; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVOBConditions.setupTime; - bool isSetuped = mXPVOBConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVOBConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVOBSiganlSetup( - symbol, - period, - mXPVOBConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - setupDir = mXPVOBConditions.dir; - setupTime = mXPVOBConditions.setupTime; - } - - // - // Draw Conditions Active FVG ... - // if (isSetuped) - // { - // // - // XCFVG *iFVG = mXPVOBConditions.activeFVG; - // if (iFVG != NULL && iFVG.IsValid()) - // { - // // - // ClearDraws(); - // iFVG.To(cTime); - // if (IsBullish(setupDir) && iFVG.IsBullish()) - // { - // // - // XCBullishFairValueGapObject *iObj; - // bool isCreated = mPOIDrawer.CreateBullishFairValueGap( - // iFVG, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // else if (IsBearish(setupDir) && iFVG.IsBearish()) - // { - // // - // XCBearishFairValueGapObject *iObj; - // bool isCreated = mPOIDrawer.CreateBearishFairValueGap( - // iFVG, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // } - // } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXPVOBConditions.CanTrigger(); - datetime triggerTime = mXPVOBConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVOBSiganlTrigger( - mXPVOBConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXPVOBConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXPVOBConditions.sl; - conditions.target = mXPVOBConditions.target; - - // - mXPVOBConditions.Clean(); - - // - return result; - } - - // - // XPVDP Signal ... - X121SMCStrategyXPVDPSignalConditions mXPVDPConditions; - bool DetectXPVDPSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVDP; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVDPConditions.setupTime; - bool isSetuped = mXPVDPConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVDPConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVDPSiganlSetup( - symbol, - period, - mXPVDPConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXPVDPConditions.dir; - setupTime = mXPVDPConditions.setupTime; - } - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXPVDPConditions.CanTrigger(); - datetime triggerTime = mXPVDPConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVDPSiganlTrigger( - mXPVDPConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXPVDPConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXPVDPConditions.sl; - conditions.target = mXPVDPConditions.target; - - // - mXPVDPConditions.Clean(); - - // - return result; - } - - // - // XVWPB Signal ... - X121SMCStrategyXVWPBSignalConditions mXVWPBConditions; - bool DetectXVWPBSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XVWPB; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXVWPBConditions.setupTime; - bool isSetuped = mXVWPBConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXVWPBConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXVWPBSiganlSetup( - symbol, - period, - mXVWPBConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXVWPBConditions.dir; - setupTime = mXVWPBConditions.setupTime; - } - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXVWPBConditions.CanTrigger(); - datetime triggerTime = mXVWPBConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXVWPBSiganlTrigger( - mXVWPBConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXVWPBConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXVWPBConditions.sl; - conditions.target = mXVWPBConditions.target; - - // - mXVWPBConditions.Clean(); - - // - return result; - } - - // - // XTWPV Signal ... - X121SMCStrategyXTWPVSignalConditions mXTWPVConditions; - bool DetectXTWPVSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTWPV; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXTWPVConditions.setupTime; - bool isSetuped = mXTWPVConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXTWPVConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXTWPVSiganlSetup( - symbol, - period, - mXTWPVConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXTWPVConditions.dir; - setupTime = mXTWPVConditions.setupTime; - } - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXTWPVConditions.CanTrigger(); - datetime triggerTime = mXTWPVConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXTWPVSiganlTrigger( - mXTWPVConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXTWPVConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXTWPVConditions.sl; - conditions.target = mXTWPVConditions.target; - - // - mXTWPVConditions.Clean(); - - // - return result; - } - - // - // XPVSUPDEM Signal ... - X121SMCStrategyXPVSUPDEMSignalConditions mXPVSUPDEMConditions; - bool DetectXPVSUPDEMSignal( - X121SMCStrategyConditions &conditions // - ) - { - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVSUPDEM; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXPVSUPDEMConditions.setupTime; - bool isSetuped = mXPVSUPDEMConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXPVSUPDEMConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = DetectX121SMCXPVSUPDEMSiganlSetup( - symbol, - period, - mXPVSUPDEMConditions, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXPVSUPDEMConditions.dir; - setupTime = mXPVSUPDEMConditions.setupTime; - } - - // ClearDraws(); - // ENUM_X_DIRECTION activeZoneDir; - // bool hasTicksZone = mXPVSUPDEMConditions.HasTicksZone(); - // bool hasActiveZone = mXPVSUPDEMConditions.HasActiveZone(activeZoneDir); - // if (hasActiveZone) - // { - // // - // if (IsBullish(activeZoneDir)) - // { - // // - // mXPVSUPDEMConditions.activeDemandZone.To(cTime); - // XCDemandZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateDemandZone( - // mXPVSUPDEMConditions.activeDemandZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // else - // { - // // - // mXPVSUPDEMConditions.activeSupplyZone.To(cTime); - // XCSupplyZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateSupplyZone( - // mXPVSUPDEMConditions.activeSupplyZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - // } - // if (hasTicksZone) - // { - // // - // XCTicksZoneObject *iObj; - // bool isCreated = mPOIDrawer.CreateTicksZone( - // mXPVSUPDEMConditions.ticksZone, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - // } - - // - result = isSetuped; - if (!result) - { - return result; - } - - // - // Detect Trigger Conditions ... - bool canTrigger = mXPVSUPDEMConditions.CanTrigger(); - datetime triggerTime = mXPVSUPDEMConditions.triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXPVSUPDEMSiganlTrigger( - mXPVSUPDEMConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - return result; - } - - // - triggerTime = mXPVSUPDEMConditions.triggerTime; - } - - // - // Check Signal Direction ... - - // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.signalDir = setupDir; - conditions.provider = providerStr; - conditions.sl = mXPVSUPDEMConditions.sl; - conditions.target = mXPVSUPDEMConditions.target; - - // - mXPVSUPDEMConditions.Clean(); - - // - return result; - } - - -/////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/Documents/BKP/4/tmp.parent.child.pivot.mq5 b/Documents/BKP/4/tmp.parent.child.pivot.mq5 deleted file mode 100644 index c09d77cb..00000000 --- a/Documents/BKP/4/tmp.parent.child.pivot.mq5 +++ /dev/null @@ -1,852 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXTWPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XPVPivot parentPivot; - XPVPivot childPivot; - - // - // Constructor ... - X121SMCStrategyXTWPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - CleanPivots(); - } - - void CleanPivots() - { - // - parentPivot.Clean(); - childPivot.Clean(); - } - - bool HasParentPivot() - { - return parentPivot.IsValid(); - } - - bool HasChildPivot() - { - return childPivot.IsValid(); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXTWPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - // ENUM_X_DIRECTION trend; - // bool hasTrend = verificationCycleHelper - // .DetectTrend(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - // result = hasBullishTrend || - // hasBearishTrend; - // if (!result) - // { - // return result; - // } - - // - // Retrieve Active Pivots ... - - // - XPVPivot peakPivot; - bool hasPeakPivot = analyseCycleHelper - .GetActivePeakPivot(peakPivot); - - // - XPVPivot valePivot; - bool hasValePivot = analyseCycleHelper - .GetActiveValePivot(valePivot); - - // - // Check Parent Pivot ... - bool hasParentPivot = conditions.HasParentPivot(); - if (!hasParentPivot) - { - // - if (hasPeakPivot && !hasValePivot) - { - conditions.parentPivot = peakPivot; - } - else if (hasValePivot && !hasPeakPivot) - { - conditions.parentPivot = valePivot; - } - else if (hasPeakPivot && hasValePivot) - { - // - if (peakPivot.from < valePivot.from) - { - // - conditions.parentPivot = peakPivot; - conditions.childPivot = valePivot; - } - else if (valePivot.from < peakPivot.from) - { - // - conditions.parentPivot = valePivot; - conditions.childPivot = peakPivot; - } - } - - // - hasParentPivot = conditions.HasParentPivot(); - result = hasParentPivot; - if (!result) - { - return result; - } - } - - // - // Check Child Pivot ... - bool hasChildPivot = conditions.HasChildPivot(); - if (!hasChildPivot) - { - // - if (hasPeakPivot && !hasValePivot) - { - conditions.childPivot = peakPivot; - } - else if (hasValePivot && !hasPeakPivot) - { - conditions.childPivot = valePivot; - } - else if (hasPeakPivot && hasValePivot) - { - // - if (peakPivot.from < valePivot.from) - { - conditions.childPivot = peakPivot; - } - else if (valePivot.from < peakPivot.from) - { - conditions.childPivot = valePivot; - } - } - - // - hasChildPivot = conditions.HasChildPivot(); - result = hasChildPivot; - if (!result) - { - return result; - } - } - - // - if (hasParentPivot && hasChildPivot) - { - // - bool isChildSame = - conditions.childPivot.from == peakPivot.from || - conditions.childPivot.from == valePivot.from; - result = isChildSame; - if (!result) - { - // - conditions.CleanPivots(); - return result; - } - } - - // - // Detect Direction ... - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXTWPVSiganlTrigger( - // - X121SMCStrategyXTWPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Check VWap State ... - - // - bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - - // - isBullish = - IsBullish(setupDir) && - isVWapBullishState; - - // - isBearish = - IsBearish(setupDir) && - isVWapBearishState; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Waitings For Sar Switched to Direction ... - - // - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - isBullish = - // - isBullish && - isSarSwitchedToBullish - // - ; - - // - isBearish = - // - isBearish && - isSarSwitchedToBearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Detect Nearest FVG or Supply Zone For Traget ... - - // - // Select Source State ... - XPOIState state = triggerState; - - // - double target = CalculateTarget( - cBar, - state, - setupDir // - ); - - // - result = target > 0; - if (!result) - { - return result; - } - - // - conditions.target = target; - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? sar - : sar; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// diff --git a/Documents/BKP/4/tmp.pivot.draws.mq5 b/Documents/BKP/4/tmp.pivot.draws.mq5 deleted file mode 100644 index 51d415ea..00000000 --- a/Documents/BKP/4/tmp.pivot.draws.mq5 +++ /dev/null @@ -1,73 +0,0 @@ - // - ClearDraws(); - XPVPivot peakPivot; - bool hasActivePeakPivot = - mTriggerCycleHelper - .GetActivePeakPivot(peakPivot); - if (hasActivePeakPivot) - { - // - XCBaseObject *iPivotObjs[]; - int drawnCount = mPOIDrawer.DrawPivot( - peakPivot, - iPivotObjs // - ); - - // - if (IsValidSize(drawnCount)) - { - AddObjectsIfNotExists(iPivotObjs); - } - } - - // - XPVPivot valePivot; - bool hasActiveValePivot = - mTriggerCycleHelper - .GetActiveValePivot(valePivot); - if (hasActiveValePivot) - { - // - XCBaseObject *iPivotObjs[]; - int drawnCount = mPOIDrawer.DrawPivot( - valePivot, - iPivotObjs // - ); - - // - if (IsValidSize(drawnCount)) - { - AddObjectsIfNotExists(iPivotObjs); - } - } - - // XPVPivot pivots[]; - // int pivotsCount = mTriggerCycleHelper.FillPivots(pivots); - // if (IsValidSize(pivotsCount)) - // { - // // - // for (int i = 0; i < pivotsCount; i++) - // { - // // - // XPVPivot iPivot = pivots[i]; - - // // - // XCBaseObject *iPivotObjects[]; - // mPOIDrawer.DrawPivot( - // iPivot, - // iPivotObjects, - // false // Don't Draw State ... - // ); - - // // - // int iPivotObjectsCount = ArraySize(iPivotObjects); - // if (IsValidSize(iPivotObjectsCount)) - // { - // // - // for (int j = 0; j < iPivotObjectsCount; j++) - // { - // AddObjectIfNotExists(iPivotObjects[j]); - // } - // } - // } - // } diff --git a/Documents/BKP/5/x-121.smc.xoepv.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xoepv.signal.lib.mq5 deleted file mode 100644 index 894ce1ae..00000000 --- a/Documents/BKP/5/x-121.smc.xoepv.signal.lib.mq5 +++ /dev/null @@ -1,1058 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXOEPVSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XCFVG *bullishOBs[]; - XCFVG *bearishOBs[]; - - // - // Constructor ... - X121SMCStrategyXOEPVSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - CleanOBs(); - } - - void CleanOBs() - { - // - Clean(bullishOBs); - Clean(bearishOBs); - } - - int CountBullishOBs() - { - return ArraySize(bullishOBs); - } - - bool HasBullishOBs() - { - return CountBullishOBs() >= 3; - } - - int CountBearishOBs() - { - return ArraySize(bearishOBs); - } - - bool HasBearishOBs() - { - return CountBearishOBs() >= 3; - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXOEPVSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXOEPVSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Vision ... - - // - double visionVWapFast = visionConditions.x121Conditions.vwapFastBuffer[1]; - double visionVWapMid = visionConditions.x121Conditions.vwapMidBuffer[1]; - double visionVWapSlow = visionConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double visionVWapFastPrev = visionConditions.x121Conditions.vwapFastBuffer[2]; - double visionVWapMidPrev = visionConditions.x121Conditions.vwapMidBuffer[2]; - double visionVWapSlowPrev = visionConditions.x121Conditions.vwapSlowBuffer[2]; - - // - double visionVWaps[3] = { - visionVWapFast, - visionVWapMid, - visionVWapSlow, - }; - double visionVWapMax = GetMax(visionVWaps); - double visionVWapMin = GetMin(visionVWaps); - - // - bool isVisionVWapFastCrossedOverMid = visionVWapFast > visionVWapMid && - !(visionVWapFastPrev > visionVWapMidPrev); - - // - bool isVisionVWapFastCrossedUnderMid = visionVWapFast < visionVWapMid && - !(visionVWapFastPrev < visionVWapMidPrev); - - // - bool isVisionVWapBullishState = visionConditions.x121Conditions.isVWapBullishState; - bool isVisionVWapSwitchedToBullishState = visionConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isVisionVWapBearishState = visionConditions.x121Conditions.isVWapBearishState; - bool isVisionVWapSwitchedToBearishState = visionConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isVisionVWapBullishOrdered = visionConditions.x121Conditions.isVWapBullishOrdered; - bool isVisionVWapSwitchedToBullishOrdered = visionConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isVisionVWapBearishOrdered = visionConditions.x121Conditions.isVWapBearishOrdered; - bool isVisionVWapSwitchedToBearishOrdered = visionConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isVisionVWapBullishFormed = - // - (isVisionVWapBullishOrdered || - isVisionVWapSwitchedToBullishOrdered) && - (isVisionVWapBullishState || - isVisionVWapSwitchedToBullishState) - // - ; - - // - bool isVisionVWapBearishFormed = - // - (isVisionVWapBearishOrdered || - isVisionVWapSwitchedToBearishOrdered) && - (isVisionVWapBearishState || - isVisionVWapSwitchedToBearishState) - // - ; - - // - // Consolidation ... - - // - double consolidationVWapFast = consolidationConditions.x121Conditions.vwapFastBuffer[1]; - double consolidationVWapMid = consolidationConditions.x121Conditions.vwapMidBuffer[1]; - double consolidationVWapSlow = consolidationConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double consolidationVWapFastPrev = consolidationConditions.x121Conditions.vwapFastBuffer[2]; - double consolidationVWapMidPrev = consolidationConditions.x121Conditions.vwapMidBuffer[2]; - double consolidationVWapSlowPrev = consolidationConditions.x121Conditions.vwapSlowBuffer[2]; - - // - double consolidationVWaps[3] = { - consolidationVWapFast, - consolidationVWapMid, - consolidationVWapSlow, - }; - double consolidationVWapMax = GetMax(consolidationVWaps); - double consolidationVWapMin = GetMin(consolidationVWaps); - - // - bool isConsolidationVWapBullishState = consolidationConditions.x121Conditions.isVWapBullishState; - bool isConsolidationVWapSwitchedToBullishState = consolidationConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isConsolidationVWapBearishState = consolidationConditions.x121Conditions.isVWapBearishState; - bool isConsolidationVWapSwitchedToBearishState = consolidationConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isConsolidationVWapBullishOrdered = consolidationConditions.x121Conditions.isVWapBullishOrdered; - bool isConsolidationVWapSwitchedToBullishOrdered = consolidationConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isConsolidationVWapBearishOrdered = consolidationConditions.x121Conditions.isVWapBearishOrdered; - bool isConsolidationVWapSwitchedToBearishOrdered = consolidationConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isConsolidationVWapBullishFormed = - // - (isConsolidationVWapBullishOrdered || - isConsolidationVWapSwitchedToBullishOrdered) && - (isConsolidationVWapBullishState || - isConsolidationVWapSwitchedToBullishState) - // - ; - - // - bool isConsolidationVWapBearishFormed = - // - (isConsolidationVWapBearishOrdered || - isConsolidationVWapSwitchedToBearishOrdered) && - (isConsolidationVWapBearishState || - isConsolidationVWapSwitchedToBearishState) - // - ; - - // - // Verification ... - - // - double verificationVWapFast = verificationConditions.x121Conditions.vwapFastBuffer[1]; - double verificationVWapMid = verificationConditions.x121Conditions.vwapMidBuffer[1]; - double verificationVWapSlow = verificationConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double verificationVWapFastPrev = verificationConditions.x121Conditions.vwapFastBuffer[2]; - double verificationVWapMidPrev = verificationConditions.x121Conditions.vwapMidBuffer[2]; - double verificationVWapSlowPrev = verificationConditions.x121Conditions.vwapSlowBuffer[2]; - - // - double verificationVWaps[3] = { - verificationVWapFast, - verificationVWapMid, - verificationVWapSlow, - }; - double verificationVWapMax = GetMax(verificationVWaps); - double verificationVWapMin = GetMin(verificationVWaps); - - // - bool isVerificationVWapBullishState = verificationConditions.x121Conditions.isVWapBullishState; - bool isVerificationVWapSwitchedToBullishState = verificationConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isVerificationVWapBearishState = verificationConditions.x121Conditions.isVWapBearishState; - bool isVerificationVWapSwitchedToBearishState = verificationConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isVerificationVWapBullishOrdered = verificationConditions.x121Conditions.isVWapBullishOrdered; - bool isVerificationVWapSwitchedToBullishOrdered = verificationConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isVerificationVWapBearishOrdered = verificationConditions.x121Conditions.isVWapBearishOrdered; - bool isVerificationVWapSwitchedToBearishOrdered = verificationConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isVerificationVWapBullishFormed = - // - (isVerificationVWapBullishOrdered || - isVerificationVWapSwitchedToBullishOrdered) && - (isVerificationVWapBullishState || - isVerificationVWapSwitchedToBullishState) - // - ; - - // - bool isVerificationVWapBearishFormed = - // - (isVerificationVWapBearishOrdered || - isVerificationVWapSwitchedToBearishOrdered) && - (isVerificationVWapBearishState || - isVerificationVWapSwitchedToBearishState) - // - ; - - // - // Analyse ... - - // - double analyseVWapFast = analyseConditions.x121Conditions.vwapFastBuffer[1]; - double analyseVWapMid = analyseConditions.x121Conditions.vwapMidBuffer[1]; - double analyseVWapSlow = analyseConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double analyseVWapFastPrev = analyseConditions.x121Conditions.vwapFastBuffer[2]; - double analyseVWapMidPrev = analyseConditions.x121Conditions.vwapMidBuffer[2]; - double analyseVWapSlowPrev = analyseConditions.x121Conditions.vwapSlowBuffer[2]; - - // - double analyseVWaps[3] = { - analyseVWapFast, - analyseVWapMid, - analyseVWapSlow, - }; - double analyseVWapMax = GetMax(analyseVWaps); - double analyseVWapMin = GetMin(analyseVWaps); - - // - bool isAnalyseVWapBullishState = analyseConditions.x121Conditions.isVWapBullishState; - bool isAnalyseVWapSwitchedToBullishState = analyseConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isAnalyseVWapBearishState = analyseConditions.x121Conditions.isVWapBearishState; - bool isAnalyseVWapSwitchedToBearishState = analyseConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isAnalyseVWapBullishOrdered = analyseConditions.x121Conditions.isVWapBullishOrdered; - bool isAnalyseVWapSwitchedToBullishOrdered = analyseConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isAnalyseVWapBearishOrdered = analyseConditions.x121Conditions.isVWapBearishOrdered; - bool isAnalyseVWapSwitchedToBearishOrdered = analyseConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isAnalyseVWapBullishFormed = - // - (isAnalyseVWapBullishOrdered || - isAnalyseVWapSwitchedToBullishOrdered) && - (isAnalyseVWapBullishState || - isAnalyseVWapSwitchedToBullishState) - // - ; - - // - bool isAnalyseVWapBearishFormed = - // - (isAnalyseVWapBearishOrdered || - isAnalyseVWapSwitchedToBearishOrdered) && - (isAnalyseVWapBearishState || - isAnalyseVWapSwitchedToBearishState) - // - ; - - // - // Summary VWap ... - - // - isBullish = - // isVisionVWapBullishFormed && - isConsolidationVWapBullishFormed && - isVerificationVWapBullishFormed && - isAnalyseVWapBullishFormed; - - // - isBearish = - // isVisionVWapBearishFormed && - isConsolidationVWapBearishFormed && - isVerificationVWapBearishFormed && - isAnalyseVWapBearishFormed; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - conditions.CleanOBs(); - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXOEPVSiganlTrigger( - // - X121SMCStrategyXOEPVSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Decision ... - - // - double decisionVWapFast = decisionConditions.x121Conditions.vwapFastBuffer[1]; - double decisionVWapMid = decisionConditions.x121Conditions.vwapMidBuffer[1]; - double decisionVWapSlow = decisionConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double decisionVWapFastPrev = decisionConditions.x121Conditions.vwapFastBuffer[2]; - double decisionVWapMidPrev = decisionConditions.x121Conditions.vwapMidBuffer[2]; - double decisionVWapSlowPrev = decisionConditions.x121Conditions.vwapSlowBuffer[2]; - - // - double decisionVWaps[3] = { - decisionVWapFast, - decisionVWapMid, - decisionVWapSlow, - }; - double decisionVWapMax = GetMax(decisionVWaps); - double decisionVWapMin = GetMin(decisionVWaps); - - // - bool isDecisionVWapBullishState = decisionConditions.x121Conditions.isVWapBullishState; - bool isDecisionVWapSwitchedToBullishState = decisionConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isDecisionVWapBearishState = decisionConditions.x121Conditions.isVWapBearishState; - bool isDecisionVWapSwitchedToBearishState = decisionConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isDecisionVWapBullishOrdered = decisionConditions.x121Conditions.isVWapBullishOrdered; - bool isDecisionVWapSwitchedToBullishOrdered = decisionConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isDecisionVWapBearishOrdered = decisionConditions.x121Conditions.isVWapBearishOrdered; - bool isDecisionVWapSwitchedToBearishOrdered = decisionConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isDecisionVWapBullishFormed = - // - (isDecisionVWapBullishOrdered || - isDecisionVWapSwitchedToBullishOrdered) && - (isDecisionVWapBullishState || - isDecisionVWapSwitchedToBullishState) - // - ; - - // - bool isDecisionVWapBearishFormed = - // - (isDecisionVWapBearishOrdered || - isDecisionVWapSwitchedToBearishOrdered) && - (isDecisionVWapBearishState || - isDecisionVWapSwitchedToBearishState) - // - ; - - // - // Trigger ... - - // - double triggerVWapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double triggerVWapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double triggerVWapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double triggerVWapFastPrev = triggerConditions.x121Conditions.vwapFastBuffer[2]; - double triggerVWapMidPrev = triggerConditions.x121Conditions.vwapMidBuffer[2]; - double triggerVWapSlowPrev = triggerConditions.x121Conditions.vwapSlowBuffer[2]; - - // - double triggerVWaps[3] = { - triggerVWapFast, - triggerVWapMid, - triggerVWapSlow, - }; - double triggerVWapMax = GetMax(triggerVWaps); - double triggerVWapMin = GetMin(triggerVWaps); - - // - bool isTriggerVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isTriggerVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isTriggerVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - bool isTriggerVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isTriggerVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered; - bool isTriggerVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isTriggerVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered; - bool isTriggerVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - bool isTriggerVWapBullishFormed = - // - (isTriggerVWapBullishState && - isTriggerVWapSwitchedToBullishOrdered) || - (isTriggerVWapBullishOrdered && - isTriggerVWapSwitchedToBullishState) - // - ; - - // - bool isTriggerVWapBearishFormed = - // - (isTriggerVWapBearishState && - isTriggerVWapSwitchedToBearishOrdered) || - (isTriggerVWapBearishOrdered && - isTriggerVWapSwitchedToBearishState) - // - ; - - // - isBullish = - // - isBullish && - isTriggerVWapBullishFormed && - isDecisionVWapBullishFormed - // - ; - - // - isBearish = - // - isBearish && - isTriggerVWapBearishFormed && - isDecisionVWapBearishFormed - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? triggerVWapMin - : triggerVWapMax; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// diff --git a/Documents/BKP/5/x-121.smc.xpvdp.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xpvdp.signal.lib.mq5 deleted file mode 100644 index c1008ead..00000000 --- a/Documents/BKP/5/x-121.smc.xpvdp.signal.lib.mq5 +++ /dev/null @@ -1,995 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Lib -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVDPSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double peak; - double vale; - - // - // Constructor ... - X121SMCStrategyXPVDPSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - peak = 0; - vale = 0; - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVDPSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVDPSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = consolidationCycleHelper - .DetectTrend(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasBullishTrend || - hasBearishTrend; - if (!result) - { - return result; - } - - // - // Select Source State ... - XPOIState state = decisionState; - - // - // Detect High Equals to Peaks or Low Equals to Vale ... - - // - // Peak ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - // Vale ... - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - bool isHighEqualsToPeak = - isNewPeak && - peak == cBar.high; - - // - bool isLowEqualsToVale = - isNewVale && - vale == cBar.low; - - // - result = isHighEqualsToPeak || - isLowEqualsToVale; - if (!result) - { - return result; - } - - // - // Now We Have To Check DONChain Status ... - - // - double donCUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; - double donCUpperPrev = triggerConditions.x121Conditions.donCloseUpperBuffer[2]; - - // - double donCLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; - double donCLowerPrev = triggerConditions.x121Conditions.donCloseLowerBuffer[2]; - - // - double donOUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; - double donOUpperPrev = triggerConditions.x121Conditions.donOpenUpperBuffer[2]; - - // - double donOLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; - double donOLowerPrev = triggerConditions.x121Conditions.donOpenLowerBuffer[2]; - - // - bool isDonUpperBullish = donCUpper > donOUpper; - bool isDonUpperBullishPrev = donCUpperPrev > donOUpperPrev; - - // - bool isDonUpperBearish = donCUpper < donOUpper; - bool isDonUpperBearishPrev = donCUpperPrev < donOUpperPrev; - - // - bool isDonUpperSwitchedToBullish = isDonUpperBullish && - !isDonUpperBullishPrev; - - // - bool isDonUpperSwitchedToBearish = isDonUpperBearish && - !isDonUpperBearishPrev; - - // - bool isDonLowerBullish = donCLower > donOLower; - bool isDonLowerBullishPrev = donCLowerPrev > donOLowerPrev; - - // - bool isDonLowerBearish = donCLower < donOLower; - bool isDonLowerBearishPrev = donCLowerPrev < donOLowerPrev; - - // - bool isDonLowerSwitchedToBullish = isDonLowerBullish && - !isDonLowerBullishPrev; - - // - bool isDonLowerSwitchedToBearish = isDonLowerBearish && - !isDonLowerBearishPrev; - - // - // Calculate State ... - - // - bool isDonInBullishState = - // - // Upper ... - (isDonUpperBullish || - isDonUpperSwitchedToBullish) - // - && - // - // Lower ... - (isDonLowerBullish || - isDonLowerSwitchedToBullish) - // - ; - - // - bool isDonInBearishState = - // - // Upper ... - (isDonUpperBearish || - isDonUpperSwitchedToBearish) - // - && - // - // Lower ... - (isDonLowerBearish || - isDonLowerSwitchedToBearish) - // - ; - - // - // Summary DonChain State ... - - // - isBullish = - // - hasBullishTrend - // - && - // - isDonInBullishState - // - && - // - (isHighEqualsToPeak || - isLowEqualsToVale) - // - ; - - // - isBearish = - // - hasBearishTrend - // - && - // - isDonInBearishState - // - && - // - (isHighEqualsToPeak || - isLowEqualsToVale) - // - ; - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check VWap Conditions ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - bool isCloseOverVwapMax = - // - ask > vwapMax && - bid > vwapMax && - (cBar.low > vwapMax || - cBar.close > vwapMax) - // - ; - - // - bool isCloseUnderVwapMin = - // - ask < vwapMin && - bid < vwapMin && - (cBar.high < vwapMin || - cBar.close < vwapMin) - // - ; - - // - bool isVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish; - bool isVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish; - bool isVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish; - bool isVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish; - bool isVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish; - bool isVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish; - bool isVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid; - bool isVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow; - bool isVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid; - bool isVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isVwapBullishFormed = - // - // Order ... - (isVWapFastOverMid || - isVWapMidOverSlow || - (isVWapFastOverMid && - isVWapMidOverSlow)) - // - && - // State ... - ((isVWapFastBullish && - isVWapMidBullish) || - (isVWapMidBullish && - isVWapSlowBullish) || - (isVWapFastBullish && - isVWapMidBullish && - isVWapSlowBullish)) - // - ; - - // - bool isVwapBearishFormed = - // - // Order ... - (isVWapFastUnderMid || - isVWapMidUnderSlow || - (isVWapFastUnderMid && - isVWapMidUnderSlow)) - // - && - // State ... - ((isVWapFastBearish && - isVWapMidBearish) || - (isVWapMidBearish && - isVWapSlowBearish) || - (isVWapFastBearish && - isVWapMidBearish && - isVWapSlowBearish)) - // - ; - - // - // Summar VWap State ... - - // - isBullish = - isBullish && - isCloseOverVwapMax && - isVwapBullishFormed; - - // - isBearish = - isBearish && - isCloseUnderVwapMin && - isVwapBearishFormed; - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check Sar State ... - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - - // - bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - // Summary Sar ... - - // - bool isSarBullishFormed = isSarBullish || - isSarSwitchedToBullish; - - // - bool isSarBearishFormed = isSarBearish || - isSarSwitchedToBearish; - - // - isBullish = - isBullish && - isSarBullishFormed; - - // - isBearish = - isBearish && - isSarBearishFormed; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVDPSiganlTrigger( - // - X121SMCStrategyXPVDPSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // - isBullish = - // - IsBullish(setupDir) - // - ; - - // - isBearish = - // - IsBearish(setupDir) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? MathMin(sar, vwapMin) - : MathMin(sar, vwapMax); - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/5/x-121.smc.xpvob.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xpvob.signal.lib.mq5 deleted file mode 100644 index 61cbd8d6..00000000 --- a/Documents/BKP/5/x-121.smc.xpvob.signal.lib.mq5 +++ /dev/null @@ -1,1695 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Lib -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVOBSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XCOrderBlock *bullishOBs[]; - XCOrderBlock *bearishOBs[]; - - // - XCFVG *activeFVG; - XCFVG *bullishFVGs[]; - XCFVG *bearishFVGs[]; - - // - // Constructor ... - X121SMCStrategyXPVOBSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - activeFVG = NULL; - Clean(bullishOBs); - Clean(bearishOBs); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - // - int CountBullishOBs() - { - return ArraySize(bullishOBs); - } - - // - int CountBearishOBs() - { - return ArraySize(bearishOBs); - } - - // - bool HasBullishOB() - { - return IsValidSize(CountBullishOBs()); - } - - // - bool HasBearishOB() - { - return IsValidSize(CountBearishOBs()); - } - - // - int CountBullishFVGs() - { - return ArraySize(bullishFVGs); - } - - // - int CountBearishFVGs() - { - return ArraySize(bearishFVGs); - } - - // - bool HasBullishFVG() - { - return IsValidSize(CountBullishFVGs()); - } - - // - bool HasBearishFVG() - { - return IsValidSize(CountBearishFVGs()); - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVOBSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVOBSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = consolidationCycleHelper - .DetectTrend(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasBullishTrend || - hasBearishTrend; - if (!result) - { - return result; - } - - // - // Select Source State ... - XPOIState state = decisionState; - - // - // Detect Imbalance ... - - // - bool hasBullishOB = conditions.HasBullishOB(); - if (!hasBullishOB) - { - // - int count = state.CountBullishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = state.bullishOrderBlocks[i]; - - // - // Validate Order Block ... - bool isValid = - // - cBar.low > iOB.Upper() - // - ; - if (isValid) - { - // - Add( - iOB, - conditions.bullishOBs // - ); - } - } - } - - // - hasBullishOB = conditions.HasBullishOB(); - } - - // - bool hasBearishOB = conditions.HasBearishOB(); - if (!hasBearishOB) - { - // - int count = state.CountBearishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = state.bearishOrderBlocks[i]; - - // - // Validate Order Block ... - bool isValid = - // - cBar.high < iOB.Lower() - // - ; - if (isValid) - { - // - Add( - iOB, - conditions.bearishOBs // - ); - } - } - } - - // - hasBearishOB = conditions.HasBearishOB(); - } - - // - result = hasBullishOB || - hasBearishOB; - if (!result) - { - return result; - } - - // - int fvgValidationLength = 5; - - // - bool hasBullishFVG = conditions.HasBullishFVG(); - if (!hasBullishFVG) - { - // - if (hasBullishOB) - { - // - int obsCount = conditions.CountBullishOBs(); - int count = state.CountBullishFairValueGaps(); - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = conditions.bullishOBs[i]; - - // - for (int j = 0; j < count; j++) - { - // - XCFVG *jFVG = state.bullishFairValueGaps[j]; - - // - bool isValid = - // - cBar.low > iOB.Upper() && - cBar.low > jFVG.Upper() && - // - jFVG.From() > iOB.From() && - (((int)(jFVG.From() - iOB.From())) / PeriodSeconds(state.period)) <= fvgValidationLength - // - ; - if (isValid) - { - // - Add( - jFVG, - conditions.bullishFVGs // - ); - } - } - } - } - - // - hasBullishFVG = conditions.HasBullishFVG(); - } - - // - bool hasBearishFVG = conditions.HasBearishFVG(); - if (!hasBearishFVG) - { - // - if (hasBullishOB) - { - // - int obsCount = conditions.CountBearishOBs(); - int count = state.CountBearishFairValueGaps(); - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = conditions.bearishOBs[i]; - - // - for (int j = 0; j < count; j++) - { - // - XCFVG *jFVG = state.bearishFairValueGaps[j]; - - // - bool isValid = - // - cBar.high < iOB.Lower() && - cBar.high < jFVG.Lower() && - // - jFVG.From() > iOB.From() && - (((int)(jFVG.From() - iOB.From())) / PeriodSeconds(state.period)) <= fvgValidationLength - // - ; - if (isValid) - { - // - Add( - jFVG, - conditions.bearishFVGs // - ); - } - } - } - } - - // - hasBearishFVG = conditions.HasBearishFVG(); - } - - // - result = (hasBullishOB && - hasBullishFVG) || - (hasBearishOB && - hasBearishFVG); - if (!result) - { - return result; - } - - // - // Detect new Peak or new Vale ... - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - result = isNewPeak || - isNewVale; - if (!result) - { - return result; - } - - // - // Detect Setup Conditions based on Peaks or Vales Occurance ... - - // - bool lookupForLong = isNewVale && - hasBullishOB && - hasBullishFVG && - hasBullishTrend; - - // - bool lookupForShort = isNewPeak && - hasBearishOB && - hasBearishFVG && - hasBearishTrend; - - // - result = lookupForLong || - lookupForShort; - if (!result) - { - return result; - } - - // - XCFVG *fvg = NULL; - double fvgZoneValidationRangePercent = 0; - if (lookupForLong) - { - // - // Long Conditions ... - // Vales must be Happens Inside Bullish Fair Value Gaps ... - int count = conditions.CountBullishFVGs(); - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = conditions.bullishFVGs[i]; - - // - bool isValid = - // - vale <= iFVG.Upper() && - vale >= iFVG.Lower() && - (fvgZoneValidationRangePercent <= 0 - ? true - : (vale < iFVG.Upper() - (iFVG.RangePercent() * fvgZoneValidationRangePercent))) - // - ; - if (isValid) - { - // - fvg = iFVG; - break; - } - } - - // - isBullish = - // - fvg != NULL && - fvg.IsValid() - // - ; - if (isBullish) - { - conditions.activeFVG = fvg; - } - } - else if (lookupForShort) - { - // - // Short Conditions ... - // Peaks Must be Happens Inside Bearish Fair Value Gaps ... - int count = conditions.CountBearishFVGs(); - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = conditions.bearishFVGs[i]; - - // - bool isValid = - // - peak <= iFVG.Upper() && - peak >= iFVG.Lower() && - (fvgZoneValidationRangePercent <= 0 - ? true - : (peak > iFVG.Lower() + (iFVG.RangePercent() * fvgZoneValidationRangePercent))) - // - ; - if (isValid) - { - // - fvg = iFVG; - break; - } - } - - // - isBearish = - // - fvg != NULL && - fvg.IsValid() - // - ; - if (isBearish) - { - conditions.activeFVG = fvg; - } - } - - // - result = isBullish || - isBearish; - if (!result) - { - // - if (lookupForLong) - { - // - conditions.activeFVG = NULL; - Clean(conditions.bullishOBs); - Clean(conditions.bullishFVGs); - } - else if (lookupForShort) - { - // - conditions.activeFVG = NULL; - Clean(conditions.bearishOBs); - Clean(conditions.bearishFVGs); - } - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVOBSiganlTrigger( - // - X121SMCStrategyXPVOBSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - XCFVG *iFVG = conditions.activeFVG; - result = iFVG != NULL && - iFVG.IsValid(); - if (!result) - { - return result; - } - - // - bool lookupLong = IsBullish(setupDir) && - iFVG.IsBullish(); - bool lookupShort = IsBearish(setupDir) && - iFVG.IsBearish(); - result = lookupLong || - lookupShort; - if (!result) - { - return result; - } - - // - // Check PEAKS and Vales ... - - // - // Trigger ... - - // - // Peaks and Vales ... - double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1]; - double triggerVale = triggerConditions.x121Conditions.valesBuffer[1]; - - // - bool isTriggerPeakInsideFVG = - // - triggerPeak <= iFVG.Upper() && - triggerPeak >= iFVG.Lower() - // - ; - bool isTriggerValeInsideFVG = - // - triggerVale <= iFVG.Upper() && - triggerVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isTriggerVWapFastBullish = triggerConditions.x121Conditions.isVWapFastBullish; - bool isTriggerVWapMidBullish = triggerConditions.x121Conditions.isVWapMidBullish; - bool isTriggerVWapSlowBullish = triggerConditions.x121Conditions.isVWapSlowBullish; - - // - bool isTriggerVWapFastOverMid = triggerConditions.x121Conditions.isVWapFastOverMid; - bool isTriggerVWapMidOverSlow = triggerConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isTriggerVWapFastBearish = triggerConditions.x121Conditions.isVWapFastBearish; - bool isTriggerVWapMidBearish = triggerConditions.x121Conditions.isVWapMidBearish; - bool isTriggerVWapSlowBearish = triggerConditions.x121Conditions.isVWapSlowBearish; - - // - bool isTriggerVWapFastUnderMid = triggerConditions.x121Conditions.isVWapFastUnderMid; - bool isTriggerVWapMidUnderSlow = triggerConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isTriggerMarketBullish = - // - // State ... - ( - // - (isTriggerVWapFastBullish && - isTriggerVWapMidBullish && - isTriggerVWapSlowBullish) - // - || - // - (isTriggerVWapMidBullish && - isTriggerVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isTriggerVWapFastOverMid && - isTriggerVWapMidOverSlow) - // - || - // - isTriggerVWapMidOverSlow - // - ) - // - ; - - // - bool isTriggerMarketBearish = - // - // State ... - ( - // - (isTriggerVWapFastBearish && - isTriggerVWapMidBearish && - isTriggerVWapSlowBearish) - // - || - // - (isTriggerVWapMidBearish && - isTriggerVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isTriggerVWapFastUnderMid && - isTriggerVWapMidUnderSlow) - // - || - // - isTriggerVWapMidUnderSlow - // - ) - // - ; - - // - // Decision ... - - // - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - - // - bool isDecisionPeakInsideFVG = - // - decisionPeak <= iFVG.Upper() && - decisionPeak >= iFVG.Lower() - // - ; - bool isDecisionValeInsideFVG = - // - decisionVale <= iFVG.Upper() && - decisionVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isDecisionVWapFastBullish = decisionConditions.x121Conditions.isVWapFastBullish; - bool isDecisionVWapMidBullish = decisionConditions.x121Conditions.isVWapMidBullish; - bool isDecisionVWapSlowBullish = decisionConditions.x121Conditions.isVWapSlowBullish; - - // - bool isDecisionVWapFastOverMid = decisionConditions.x121Conditions.isVWapFastOverMid; - bool isDecisionVWapMidOverSlow = decisionConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isDecisionVWapFastBearish = decisionConditions.x121Conditions.isVWapFastBearish; - bool isDecisionVWapMidBearish = decisionConditions.x121Conditions.isVWapMidBearish; - bool isDecisionVWapSlowBearish = decisionConditions.x121Conditions.isVWapSlowBearish; - - // - bool isDecisionVWapFastUnderMid = decisionConditions.x121Conditions.isVWapFastUnderMid; - bool isDecisionVWapMidUnderSlow = decisionConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isDecisionMarketBullish = - // - // State ... - ( - // - (isDecisionVWapFastBullish && - isDecisionVWapMidBullish && - isDecisionVWapSlowBullish) - // - || - // - (isDecisionVWapMidBullish && - isDecisionVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isDecisionVWapFastOverMid && - isDecisionVWapMidOverSlow) - // - || - // - isDecisionVWapMidOverSlow - // - ) - // - ; - - // - bool isDecisionMarketBearish = - // - // State ... - ( - // - (isDecisionVWapFastBearish && - isDecisionVWapMidBearish && - isDecisionVWapSlowBearish) - // - || - // - (isDecisionVWapMidBearish && - isDecisionVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isDecisionVWapFastUnderMid && - isDecisionVWapMidUnderSlow) - // - || - // - isDecisionVWapMidUnderSlow - // - ) - // - ; - - // - // Analyse ... - - // - double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1]; - double analyseVale = analyseConditions.x121Conditions.valesBuffer[1]; - - // - bool isAnalysePeakInsideFVG = - // - analysePeak <= iFVG.Upper() && - analysePeak >= iFVG.Lower() - // - ; - bool isAnalyseValeInsideFVG = - // - analyseVale <= iFVG.Upper() && - analyseVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isAnalyseVWapFastBullish = analyseConditions.x121Conditions.isVWapFastBullish; - bool isAnalyseVWapMidBullish = analyseConditions.x121Conditions.isVWapMidBullish; - bool isAnalyseVWapSlowBullish = analyseConditions.x121Conditions.isVWapSlowBullish; - - // - bool isAnalyseVWapFastOverMid = analyseConditions.x121Conditions.isVWapFastOverMid; - bool isAnalyseVWapMidOverSlow = analyseConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isAnalyseVWapFastBearish = analyseConditions.x121Conditions.isVWapFastBearish; - bool isAnalyseVWapMidBearish = analyseConditions.x121Conditions.isVWapMidBearish; - bool isAnalyseVWapSlowBearish = analyseConditions.x121Conditions.isVWapSlowBearish; - - // - bool isAnalyseVWapFastUnderMid = analyseConditions.x121Conditions.isVWapFastUnderMid; - bool isAnalyseVWapMidUnderSlow = analyseConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isAnalyseMarketBullish = - // - // State ... - ( - // - (isAnalyseVWapFastBullish && - isAnalyseVWapMidBullish && - isAnalyseVWapSlowBullish) - // - || - // - (isAnalyseVWapMidBullish && - isAnalyseVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isAnalyseVWapFastOverMid && - isAnalyseVWapMidOverSlow) - // - || - // - isAnalyseVWapMidOverSlow - // - ) - // - ; - - // - bool isAnalyseMarketBearish = - // - // State ... - ( - // - (isAnalyseVWapFastBearish && - isAnalyseVWapMidBearish && - isAnalyseVWapSlowBearish) - // - || - // - (isAnalyseVWapMidBearish && - isAnalyseVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isAnalyseVWapFastUnderMid && - isAnalyseVWapMidUnderSlow) - // - || - // - isAnalyseVWapMidUnderSlow - // - ) - // - ; - - // - // Verification ... - - // - double verificationPeak = verificationConditions.x121Conditions.peaksBuffer[1]; - double verificationVale = verificationConditions.x121Conditions.valesBuffer[1]; - - // - bool isVerificationPeakInsideFVG = - // - verificationPeak <= iFVG.Upper() && - verificationPeak >= iFVG.Lower() - // - ; - bool isVerificationValeInsideFVG = - // - verificationVale <= iFVG.Upper() && - verificationVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isVerificationVWapFastBullish = verificationConditions.x121Conditions.isVWapFastBullish; - bool isVerificationVWapMidBullish = verificationConditions.x121Conditions.isVWapMidBullish; - bool isVerificationVWapSlowBullish = verificationConditions.x121Conditions.isVWapSlowBullish; - - // - bool isVerificationVWapFastOverMid = verificationConditions.x121Conditions.isVWapFastOverMid; - bool isVerificationVWapMidOverSlow = verificationConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isVerificationVWapFastBearish = verificationConditions.x121Conditions.isVWapFastBearish; - bool isVerificationVWapMidBearish = verificationConditions.x121Conditions.isVWapMidBearish; - bool isVerificationVWapSlowBearish = verificationConditions.x121Conditions.isVWapSlowBearish; - - // - bool isVerificationVWapFastUnderMid = verificationConditions.x121Conditions.isVWapFastUnderMid; - bool isVerificationVWapMidUnderSlow = verificationConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isVerificationMarketBullish = - // - // State ... - ( - // - (isVerificationVWapFastBullish && - isVerificationVWapMidBullish && - isVerificationVWapSlowBullish) - // - || - // - (isVerificationVWapMidBullish && - isVerificationVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isVerificationVWapFastOverMid && - isVerificationVWapMidOverSlow) - // - || - // - isVerificationVWapMidOverSlow - // - ) - // - ; - - // - bool isVerificationMarketBearish = - // - // State ... - ( - // - (isVerificationVWapFastBearish && - isVerificationVWapMidBearish && - isVerificationVWapSlowBearish) - // - || - // - (isVerificationVWapMidBearish && - isVerificationVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isVerificationVWapFastUnderMid && - isVerificationVWapMidUnderSlow) - // - || - // - isVerificationVWapMidUnderSlow - // - ) - // - ; - - // - // Consolidation ... - - // - double consolidationPeak = consolidationConditions.x121Conditions.peaksBuffer[1]; - double consolidationVale = consolidationConditions.x121Conditions.valesBuffer[1]; - - // - bool isConsolidationPeakInsideFVG = - // - consolidationPeak <= iFVG.Upper() && - consolidationPeak >= iFVG.Lower() - // - ; - bool isConsolidationValeInsideFVG = - // - consolidationVale <= iFVG.Upper() && - consolidationVale >= iFVG.Lower() - // - ; - - // - // VWap ... - - // - bool isConsolidationVWapFastBullish = consolidationConditions.x121Conditions.isVWapFastBullish; - bool isConsolidationVWapMidBullish = consolidationConditions.x121Conditions.isVWapMidBullish; - bool isConsolidationVWapSlowBullish = consolidationConditions.x121Conditions.isVWapSlowBullish; - - // - bool isConsolidationVWapFastOverMid = consolidationConditions.x121Conditions.isVWapFastOverMid; - bool isConsolidationVWapMidOverSlow = consolidationConditions.x121Conditions.isVWapMidOverSlow; - - // - bool isConsolidationVWapFastBearish = consolidationConditions.x121Conditions.isVWapFastBearish; - bool isConsolidationVWapMidBearish = consolidationConditions.x121Conditions.isVWapMidBearish; - bool isConsolidationVWapSlowBearish = consolidationConditions.x121Conditions.isVWapSlowBearish; - - // - bool isConsolidationVWapFastUnderMid = consolidationConditions.x121Conditions.isVWapFastUnderMid; - bool isConsolidationVWapMidUnderSlow = consolidationConditions.x121Conditions.isVWapMidUnderSlow; - - // - bool isConsolidationMarketBullish = - // - // State ... - ( - // - (isConsolidationVWapFastBullish && - isConsolidationVWapMidBullish && - isConsolidationVWapSlowBullish) - // - || - // - (isConsolidationVWapMidBullish && - isConsolidationVWapSlowBullish) - // - ) - // - && - // - // Order ... - ( - // - (isConsolidationVWapFastOverMid && - isConsolidationVWapMidOverSlow) - // - || - // - isConsolidationVWapMidOverSlow - // - ) - // - ; - - // - bool isConsolidationMarketBearish = - // - // State ... - ( - // - (isConsolidationVWapFastBearish && - isConsolidationVWapMidBearish && - isConsolidationVWapSlowBearish) - // - || - // - (isConsolidationVWapMidBearish && - isConsolidationVWapSlowBearish) - // - ) - // - && - // - // Order ... - ( - // - (isConsolidationVWapFastUnderMid && - isConsolidationVWapMidUnderSlow) - // - || - // - isConsolidationVWapMidUnderSlow - // - ) - // - ; - - // - // Sar ... - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - // Summarize Conditions ... - - // - bool isSamePeak = - triggerPeak == decisionPeak && - triggerPeak == analysePeak && - triggerPeak == verificationPeak; - - // - bool isPeaksInsideFVG = - // - isTriggerPeakInsideFVG && - isDecisionPeakInsideFVG && - isAnalysePeakInsideFVG && - isVerificationPeakInsideFVG - // - ; - - // - bool isSameVale = - triggerVale == decisionVale && - triggerVale == analyseVale && - triggerVale == verificationVale; - - // - bool isValesInsideFVG = - // - isTriggerValeInsideFVG && - isDecisionValeInsideFVG && - isAnalyseValeInsideFVG && - isVerificationValeInsideFVG - // - ; - - // - bool isMarketReadyForLong = - // - // !isTriggerMarketBearish && - // !isDecisionMarketBearish && - // !isAnalyseMarketBearish && - isTriggerMarketBullish && - !isVerificationMarketBearish && - !isConsolidationMarketBearish - // - ; - - // - bool isMarketReadyForShort = - // - // !isTriggerMarketBullish && - // !isDecisionMarketBullish && - // !isAnalyseMarketBullish && - isTriggerMarketBearish && - !isVerificationMarketBullish && - !isConsolidationMarketBullish - // - ; - - // - // Create Trigger ... - - // - isBullish = - // isSameVale && - lookupLong && - isValesInsideFVG && - // isMarketReadyForLong && - isSarSwitchedToBullish && - triggerVale <= iFVG.Upper() && - triggerVale >= iFVG.Lower(); - - // - isBearish = - // isSamePeak && - lookupShort && - isPeaksInsideFVG && - // isMarketReadyForShort && - isSarSwitchedToBearish && - triggerPeak <= iFVG.Upper() && - triggerPeak >= iFVG.Lower(); - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? iFVG.Lower() - : iFVG.Upper(); - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 deleted file mode 100644 index c9cd5493..00000000 --- a/Documents/BKP/5/x-121.smc.xpvsupdem.signal.lib.mq5 +++ /dev/null @@ -1,1239 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Lib -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXPVSUPDEMSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XCTicksZone *ticksZone; - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; - datetime activeZoneFoundedAt; - XCSupplyZone *activeSupplyZone; - XCDemandZone *activeDemandZone; - - // - // Constructor ... - X121SMCStrategyXPVSUPDEMSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - ticksZone = NULL; - activeSupplyZone = NULL; - activeDemandZone = NULL; - activeZoneFoundedAt = NULL; - - // - Clean(supplyZones); - Clean(demandZones); - } - - /** - * Count Supply Zones ... - * - * @return ( int ) - */ - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - /** - * Count Demand Zones ... - * - * @return ( int ) - */ - int CountDemandZones() - { - return ArraySize(demandZones); - } - - /** - * Check Has Supply Zones ... - * - * @return ( bool ) - */ - bool HasSupplyZones() - { - return IsValidSize(CountSupplyZones()); - } - - /** - * Check Has Demand Zones ... - * - * @return ( bool ) - */ - bool HasDemandZones() - { - return IsValidSize(CountDemandZones()); - } - - /** - * Check Has Active Supply or Demand Zone ... - * - * @param _dir: ENUM_X_DIRECTION member Reference for Specify Active Zone ... - * - * @return ( bool ) - */ - bool HasActiveZone(ENUM_X_DIRECTION &_dir) - { - // - bool result = false; - - // - _dir = X_DIRECTION_NONE; - - // - // Check Supplies ... - bool hasActiveSupplyZone = activeSupplyZone != NULL && - activeSupplyZone.IsValid(); - - // - // Check Demnds ... - bool hasActiveDemandZone = activeDemandZone != NULL && - activeDemandZone.IsValid(); - - // - result = hasActiveSupplyZone || - hasActiveDemandZone; - if (!result) - { - return result; - } - - // - _dir = hasActiveDemandZone - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Retrieve Active Zone Reference if Exists ... - * - * @return ( bool ) - */ - bool GetActiveZone(XCBarZone *&activeZone) - { - // - bool result = false; - - // - activeZone = NULL; - - // - ENUM_X_DIRECTION activeZoneDir; - result = HasActiveZone(activeZoneDir); - if (!result) - { - return result; - } - - // - if (IsBullish(activeZoneDir)) - { - // - activeDemandZone.To(TimeCurrent()); - activeZone = activeDemandZone; - } - else - { - // - activeSupplyZone.To(TimeCurrent()); - activeZone = activeSupplyZone; - } - - // - return result; - } - - /** - * Clean Active Zone ... - */ - void CleanActiveZone() - { - // - activeSupplyZone = NULL; - activeDemandZone = NULL; - activeZoneFoundedAt = NULL; - } - - /** - * Check Ticks Zone is Initialized or not ... - * @return ( bool ) - */ - bool HasTicksZone() - { - // - bool result = false; - - // - result = - // - ticksZone != NULL && - ticksZone.IsValid() && - IsValidSize(ticksZone.Count()) - // - ; - - // - return result; - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXPVSUPDEMSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXPVSUPDEMSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = consolidationCycleHelper - .DetectTrend(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasBullishTrend || - hasBearishTrend; - if (!result) - { - return result; - } - - // - // Select Source State ... - XPOIState state = consolidationState; - - // - // Detect Supply and Demand Zones ... - - // - // Supply ... - bool hasSupplyZones = conditions.HasSupplyZones(); - if (!hasSupplyZones) - { - // - int count = state.CountSupplyZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCSupplyZone *iZone = state.supplyZones[i]; - - // - bool isValid = - // - ask < iZone.Lower() && - bid < iZone.Lower() && - cBar.high < iZone.Lower() - // - ; - if (isValid) - { - // - Add( - iZone, - conditions.supplyZones // - ); - } - } - - // - hasSupplyZones = conditions.HasSupplyZones(); - result = hasSupplyZones; - if (!result) - { - return result; - } - } - - // - // Demand ... - bool hasDemandZones = conditions.HasDemandZones(); - if (!hasDemandZones) - { - // - int count = state.CountDemandZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCDemandZone *iZone = state.demandZones[i]; - - // - bool isValid = - // - ask > iZone.Upper() && - bid > iZone.Upper() && - cBar.low > iZone.Upper() - // - ; - if (isValid) - { - // - Add( - iZone, - conditions.demandZones // - ); - } - } - - // - hasDemandZones = conditions.HasDemandZones(); - result = hasDemandZones; - if (!result) - { - return result; - } - } - - // - // Waits For Price to Go Inside a Zone ... - ENUM_X_DIRECTION activeZoneDir = X_DIRECTION_NONE; - bool hasActiveZone = conditions.HasActiveZone(activeZoneDir); - if (!hasActiveZone) - { - // - // Looking Up For Active Zone ... - - // - // Supply ... - if (hasSupplyZones) - { - // - int count = conditions.CountSupplyZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCSupplyZone *iZone = conditions.supplyZones[i]; - - // - bool isValid = - // - ask <= iZone.Upper() && - bid <= iZone.Upper() && - ask >= iZone.Lower() && - bid >= iZone.Lower() && - cBar.high <= iZone.Upper() && - cBar.low >= iZone.Lower() - // - ; - if (isValid) - { - // - conditions.activeSupplyZone = iZone; - break; - } - } - } - - // - hasActiveZone = conditions.HasActiveZone(activeZoneDir); - if (!hasActiveZone) - { - // - // Demand ... - if (hasDemandZones) - { - // - int count = conditions.CountDemandZones(); - for (int i = count - 1; i >= 0; i--) - { - // - XCDemandZone *iZone = conditions.demandZones[i]; - - // - bool isValid = - // - ask <= iZone.Upper() && - bid <= iZone.Upper() && - ask >= iZone.Lower() && - bid >= iZone.Lower() && - cBar.high <= iZone.Upper() && - cBar.low >= iZone.Lower() - // - ; - if (isValid) - { - // - conditions.activeDemandZone = iZone; - break; - } - } - } - } - - // - hasActiveZone = conditions.HasActiveZone(activeZoneDir); - result = hasActiveZone; - if (!result) - { - return result; - } - - // - conditions.activeZoneFoundedAt = cTime; - } - - // - // Now we Have to Calculate Active Zones Ticks ... - - // - bool isValidDemandZone = - hasActiveZone && - hasBullishTrend && - IsBullish(activeZoneDir); - - // - bool isValidSupplyZone = - hasActiveZone && - hasBearishTrend && - IsBearish(activeZoneDir); - - // - result = isValidDemandZone || - isValidSupplyZone; - if (!result) - { - // - conditions.CleanActiveZone(); - return result; - } - - // - // Select Active Zone ... - XCBarZone *activeZone = NULL; - result = conditions.GetActiveZone(activeZone); - if (!result) - { - return result; - } - - // - // Extract Active Zone Start Bar ... - XOHCL fromBar; - datetime fromTime = activeZone.BarTime(); - result = triggerCycleHelper.GetBar( - fromBar, - fromTime // - ); - if (!result) - { - return result; - } - - // - bool hasTicksZone = conditions.HasTicksZone(); - if (!hasTicksZone) - { - // - // Istantiate Ticks Zone ... - conditions.ticksZone = new XCTicksZone(); - conditions.ticksZone.Levels(40); - } - - // - // Update Ticks Zone ... - result = conditions.ticksZone.Init( - fromBar, - cBar // - ); - if (!result) - { - return result; - } - - // - // Regenrate Conditions ... - hasTicksZone = conditions.HasTicksZone(); - result = hasTicksZone; - if (!result) - { - return result; - } - - // - // Make Sure we Have a Direction for Setup ... - isBullish = IsBullish(activeZoneDir); - isBearish = IsBearish(activeZoneDir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check New Peaks or Vales Happens inside Zero Tick or Volume Percent Zone and - // also Active Zone ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - bool isPeakInsideActiveZone = - // - peak <= activeZone.Upper() && - peak >= activeZone.Lower() - // - ; - bool isValeInsideActiveZone = - // - vale <= activeZone.Upper() && - vale >= activeZone.Lower() - // - ; - - // - bool isPeakInsideZeroZone = false; - bool isValeInsideZeroZone = false; - int tzCount = conditions.ticksZone.Count(); - if (IsValidSize(tzCount)) - { - // - for (int i = 0; i < tzCount; i++) - { - // - XCTickZone *iTZ = conditions.ticksZone.GetZone(i); - - // - if (isBearish && - !isPeakInsideZeroZone) - { - // - isPeakInsideZeroZone = - // - peak <= iTZ.high && - peak >= iTZ.low && - (iTZ.percent == 0 || - iTZ.volumePercent == 0) - // - ; - } - - // - if (isBullish && - !isValeInsideZeroZone) - { - // - isValeInsideZeroZone = - // - vale <= iTZ.high && - vale >= iTZ.low && - (iTZ.percent == 0 || - iTZ.volumePercent == 0) - // - ; - } - - // - if (isPeakInsideZeroZone || - isValeInsideZeroZone) - { - break; - } - } - } - - // - isBullish = - // - isBullish && - isNewValeUnderLast && - isValeInsideZeroZone && - isValeInsideActiveZone - // - ; - - // - isBearish = - // - isBearish && - isNewPeakOverLast && - isPeakInsideZeroZone && - isPeakInsideActiveZone - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - int activeZoneAge = (int)(cTime - conditions.activeZoneFoundedAt) / PeriodSeconds(conditions.period); - if (activeZoneAge >= 200) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXPVSUPDEMSiganlTrigger( - // - X121SMCStrategyXPVSUPDEMSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - // Select Active Zone Class ... - XCBarZone *activeZone = NULL; - result = conditions.GetActiveZone(activeZone); - if (!result) - { - return result; - } - - // - // Check Last Valid Peak or Last Valid Vales Breaks ... - // Beak Of Structure ... - - // - // Peak ... - double peak = triggerConditions.x121Conditions.peaksBuffer[1]; - XPVPivotPoint lastPeakPivot; - bool hasLastPeakPivot = triggerCycleHelper - .GetLastPeakPivotPoint(lastPeakPivot); - bool isLastPeakPivotBreaked = - // - lastPeakPivot.IsPeak() && - lastPeakPivot.IsValid() && - peak > lastPeakPivot.value - // - ; - - // - // Vale ... - double vale = triggerConditions.x121Conditions.valesBuffer[1]; - XPVPivotPoint lastValePivot; - bool hasLastValePivot = triggerCycleHelper - .GetLastValePivotPoint(lastValePivot); - bool isLastValePivotBreaked = - // - lastValePivot.IsVale() && - lastValePivot.IsValid() && - vale < lastValePivot.value - // - ; - - // - isBullish = - // - IsBullish(setupDir) && - isLastValePivotBreaked - // - ; - - // - isBearish = - // - IsBearish(setupDir) && - isLastPeakPivotBreaked - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? activeZone.Lower() - : activeZone.Upper(); - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/5/x-121.smc.xvwpb.signal.lib.mq5 b/Documents/BKP/5/x-121.smc.xvwpb.signal.lib.mq5 deleted file mode 100644 index 130c7684..00000000 --- a/Documents/BKP/5/x-121.smc.xvwpb.signal.lib.mq5 +++ /dev/null @@ -1,1113 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyXVWPBSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - // Constructor ... - X121SMCStrategyXVWPBSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCXVWPBSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyXVWPBSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - // Detect Market Trend ... - // ENUM_X_DIRECTION trend; - // bool hasTrend = consolidationCycleHelper - // .DetectTrend(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - // result = hasBullishTrend || - // hasBearishTrend; - // if (!result) - // { - // return result; - // } - - // - // Detect VWAP Bearish ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - bool isCloseOverVwapMax = - // - ask > vwapMax && - bid > vwapMax && - (cBar.low > vwapMax || - cBar.close > vwapMax) - // - ; - - // - bool isCloseUnderVwapMin = - // - ask < vwapMin && - bid < vwapMin && - (cBar.high < vwapMin || - cBar.close < vwapMin) - // - ; - - // - bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState; - - // - bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered; - bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - - // - bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered; - bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - // Summary VWap ... - - // - bool isVwapBullishFormed = - // - isVWapSwitchedToBullishState - // isCloseOverVwapMax - // // - // && - // - // ( - // // - // // (isVWapBullishOrdered && - // // isVWapSwitchedToBullishState) - // // // - // // || - // // // - // // (isVWapBullishState && - // // isVWapSwitchedToBullishOrdered) - // // - // ) - // - ; - - // - bool isVwapBearishFormed = - // - isVWapSwitchedToBearishState - // isCloseUnderVwapMin - // // - // && - // - // ( - // // - // // (isVWapBearishOrdered && - // // isVWapSwitchedToBearishState) - // // // - // // || - // // // - // // (isVWapBearishState && - // // isVWapSwitchedToBearishOrdered) - // // - // ) - // - ; - - // - isBullish = - // hasBullishTrend && - isVwapBullishFormed; - - // - isBearish = - // hasBearishTrend && - isVwapBearishFormed; - - // - result = isBullish || - isBearish; - - // - // if (!result) - // { - // return result; - // } - - // // - // double sar = triggerConditions.x121Conditions.sarBuffer[1]; - - // // - // bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - // bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - - // // - // bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - // bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // // - // bool isSarBullishFormed = isSarBullish || - // isSarSwitchedToBullish; - - // // - // bool isSarBearishFormed = isSarBearish || - // isSarSwitchedToBearish; - - // // - // isBullish = - // isBullish && - // isSarBullishFormed; - - // // - // isBearish = - // isBearish && - // isSarBearishFormed; - - // // - // result = isBullish || - // isBearish; - // if (!result) - // { - // return result; - // } - - // // - // // Detect Pull Backs ... - - // // - // bool isSignalBarBullishPullBackFormed = - // cBar.IsBearish() && - // pBar.IsBullish() && - // cBar.low > pBar.low; - - // // - // bool isSignalBarBearishPullBackFormed = - // cBar.IsBullish() && - // pBar.IsBearish() && - // cBar.high < pBar.high; - - // // - // // Summary Pull Backs ... - - // // - // bool isBullishBarFormed = - // isSignalBarBullishPullBackFormed; - - // // - // bool isBearishhBarFormed = - // isSignalBarBearishPullBackFormed; - - // // - // isBullish = - // isBullish && - // isBullishBarFormed; - - // // - // isBearish = - // isBearish && - // isBearishhBarFormed; - - // // - // result = isBullish || - // isBearish; - // if (!result) - // { - // return result; - // } - - // // - // isBullish = - // // - // false - // // - // ; - - // // - // isBearish = - // // - // false - // // - // ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCXVWPBSiganlTrigger( - // - X121SMCStrategyXVWPBSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - double vwapFast = triggerConditions.x121Conditions.vwapFastBuffer[1]; - double vwapMid = triggerConditions.x121Conditions.vwapMidBuffer[1]; - double vwapSlow = triggerConditions.x121Conditions.vwapSlowBuffer[1]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow, - }; - double vwapMax = GetMax(vwaps); - double vwapMin = GetMin(vwaps); - - // - bool isNewPeak = triggerConditions.x121Conditions.isNewPeak; - bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; - bool isNewPeakUnderLast = triggerConditions.x121Conditions.isNewPeakUnderLast; - - // - bool isNewVale = triggerConditions.x121Conditions.isNewVale; - bool isNewValeOverLast = triggerConditions.x121Conditions.isNewValeOverLast; - bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; - - // - double triggerPeak = triggerConditions.x121Conditions.peaksBuffer[1]; - double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; - double analysePeak = analyseConditions.x121Conditions.peaksBuffer[1]; - double verificationPeak = verificationConditions.x121Conditions.peaksBuffer[1]; - double consolidationPeak = consolidationConditions.x121Conditions.peaksBuffer[1]; - - // - double triggerVale = triggerConditions.x121Conditions.valesBuffer[1]; - double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; - double analyseVale = analyseConditions.x121Conditions.valesBuffer[1]; - double verificationVale = verificationConditions.x121Conditions.valesBuffer[1]; - double consolidationVale = consolidationConditions.x121Conditions.valesBuffer[1]; - - // - bool isPeaksSameFormed = - // - ( - // - triggerPeak == decisionPeak - // - ) - // - || - // - ( - // - triggerPeak == decisionPeak && - triggerPeak == analysePeak - // - ) - // - || - // - ( - // - triggerPeak == decisionPeak && - triggerPeak == analysePeak && - triggerPeak == verificationPeak - // - ) - // - || - // - ( - // - triggerPeak == decisionPeak && - triggerPeak == analysePeak && - triggerPeak == verificationPeak && - triggerPeak == consolidationPeak - // - ) - // - ; - - // - bool isValesSameFormed = - // - ( - // - triggerVale == decisionVale - // - ) - // - || - // - ( - // - triggerVale == decisionVale && - triggerVale == analyseVale - // - ) - // - || - // - ( - // - triggerVale == decisionVale && - triggerVale == analyseVale && - triggerVale == verificationVale - // - ) - // - || - // - ( - // - triggerVale == decisionVale && - triggerVale == analyseVale && - triggerVale == verificationVale && - triggerVale == consolidationVale - // - ) - // - ; - - // - isBullish = - // isValesSameFormed && - IsBullish(setupDir); - - // - isBearish = - // isPeaksSameFormed && - IsBearish(setupDir); - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Check Last VWap State Change ... - XValueChange vwapStateChnges[]; - int vwapStateChngesCount = triggerCycleHelper - .FillVWapStateChanges(vwapStateChnges); - XValueChange lastVWapStateChnged; - bool hasLastVWapStateChanged = false; - if (IsValidSize(vwapStateChngesCount) && - vwapStateChngesCount >= 2) - { - // - lastVWapStateChnged = vwapStateChnges[vwapStateChngesCount - 2]; - hasLastVWapStateChanged = lastVWapStateChnged.IsValid(); - } - - // - double donOpenUpper = triggerConditions.x121Conditions.donOpenUpperBuffer[1]; - double donOpenLower = triggerConditions.x121Conditions.donOpenLowerBuffer[1]; - - // - double donCloseUpper = triggerConditions.x121Conditions.donCloseUpperBuffer[1]; - double donCloseLower = triggerConditions.x121Conditions.donCloseLowerBuffer[1]; - - // - bool isDonUpperBullish = donCloseUpper > donOpenUpper; - bool isDonUpperBearish = donCloseUpper < donOpenUpper; - - // - bool isDonLowerBullish = donCloseLower > donOpenLower; - bool isDonLowerBearish = donCloseLower < donOpenLower; - - // - bool isDonBullishFormed = - // - (isDonUpperBullish || - isDonLowerBullish) - // - ; - - // - bool isDonBearishFormed = - // - (isDonUpperBearish || - isDonLowerBearish) - // - ; - - // - isBullish = - (isNewValeOverLast || - isNewPeakOverLast) && - isDonBullishFormed && - hasLastVWapStateChanged && - (isBullish && - IsBullish(lastVWapStateChnged.dir)); - - // - isBearish = - (isNewPeakUnderLast || - isNewValeUnderLast) && - isDonBearishFormed && - hasLastVWapStateChanged && - (isBearish && - IsBearish(lastVWapStateChnged.dir)); - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - // Selecting SL ... - - // - double longSL = 0; - double shortSL = 0; - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - double longDistance = MathAbs(vwapMax - MathMax(triggerVale, donCloseLower)) / 2; - double shortDistance = MathAbs(vwapMin - MathMin(triggerPeak, donCloseUpper)) / 2; - - // - longSL = entry - longDistance; - shortSL = entry + shortDistance; - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? vwapMin - : vwapMax; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - return result; -} - -// diff --git a/Documents/BKP/temp.supres.found.smc.mq5 b/Documents/BKP/temp.supres.found.smc.mq5 deleted file mode 100644 index a59b35a9..00000000 --- a/Documents/BKP/temp.supres.found.smc.mq5 +++ /dev/null @@ -1,297 +0,0 @@ - -// -// Find a Support or Resistance Zone ... - -// // -// // Support Zone ... -// bool hasSupportZone = conditions.HasSupportZone(); -// if (isLowEqualsToVale && !hasSupportZone) -// { -// // -// int count = state.CountSupportZones(); -// if (IsValidSize(count)) -// { -// // -// for (int i = count - 1; i >= 0; i--) -// { -// // -// XCSupportZone *iZone = state.supportZones[i]; - -// // -// bool isValid = -// vale >= iZone.Lower() && -// vale <= iZone.Upper(); -// if (isValid) -// { -// // -// conditions.supportZone = iZone; -// break; -// } -// } - -// // -// hasSupportZone = conditions.HasSupportZone(); -// } -// } - -// // -// // Resistance Zone ... -// bool hasResistanceZone = conditions.HasResistanceZone(); -// if (isHighEqualsToPeak && !hasResistanceZone) -// { -// // -// int count = state.CountResistanceZones(); -// if (IsValidSize(count)) -// { -// // -// for (int i = count - 1; i >= 0; i--) -// { -// // -// XCResistanceZone *iZone = state.resistanceZones[i]; - -// // -// bool isValid = -// peak >= iZone.Lower() && -// peak <= iZone.Upper(); -// if (isValid) -// { -// // -// conditions.resistanceZone = iZone; -// break; -// } -// } - -// // -// hasResistanceZone = conditions.HasResistanceZone(); -// } -// } - -// // -// isBullish = -// isLowEqualsToVale && -// hasSupportZone; - -// // -// isBearish = -// isHighEqualsToPeak && -// hasResistanceZone; - -// // -// result = isBullish || -// isBearish; -// if (!result) -// { -// return result; -// } - -// // -// // Retrieve Active Zone ... -// XCBarZone *activeZone; -// result = conditions.HasActiveZone(activeZone); -// if (!result) -// { -// return result; -// } - -// // -// // Draw ... -// if (hasSupportZone) -// { -// // -// XCSupportZoneObject *iObj; -// bool isCreated = drawer.CreateSupportZone( -// conditions.supportZone, -// iObj // -// ); -// } - -// // -// if (hasResistanceZone) -// { -// // -// XCResistanceZoneObject *iObj; -// bool isCreated = drawer.CreateResistanceZone( -// conditions.resistanceZone, -// iObj // -// ); -// } - -// -XCSupportZone *supportZone; -XCResistanceZone *resistanceZone; -datetime activeZoneFoundedAt; - -// -supportZone = NULL; -resistanceZone = NULL; -activeZoneFoundedAt = NULL; - -bool HasSupportZone() -{ - // - bool result = false; - - // - result = - supportZone != NULL && - supportZone.IsValid(); - - // - return result; -} - -bool HasResistanceZone() -{ - // - bool result = false; - - // - result = - resistanceZone != NULL && - resistanceZone.IsValid(); - - // - return result; -} - -bool HasActiveZone(XCBarZone *&zone) -{ - // - bool result = false; - - // - zone = NULL; - - // - bool hasSupportZone = HasSupportZone(); - bool hasResistanceZone = HasResistanceZone(); - - // - result = hasSupportZone || - hasResistanceZone; - if (!result) - { - return result; - } - - // - if (hasSupportZone) - { - // - supportZone.To(TimeCurrent()); - zone = supportZone; - } - - // - if (hasResistanceZone) - { - // - resistanceZone.To(TimeCurrent()); - zone = resistanceZone; - } - - // - return result; -} - - -//////////////////////////////////////////////////////////////////////////// - - /** - * Detect Cycle Trend Based On Pivots ... - * - * @param dir: ENUM_X_DIRECTION member Reference ... - * @param numberOfPivots: Integer ... - * - * @return ( bool ) - */ - bool DetectTrend( - ENUM_X_DIRECTION &dir, - int numberOfPivots = 3 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - if (numberOfPivots < 2) - { - numberOfPivots = 2; - } - - // - int verifications = 0; - XValueChange changes[]; - - // - // Bearish Trend ... - int peaksChangesCount = CountPeaksChanges(); - if (!result && - peaksChangesCount > numberOfPivots) - { - // - Clean(changes); - FillPeaksChanges(changes); - - // - verifications = 0; - for (int i = peaksChangesCount - 1 - numberOfPivots; i < peaksChangesCount - 2; i++) - { - // - XValueChange cChange = changes[i]; - XValueChange nChange = changes[i + 1]; - - // - if (cChange.after > nChange.after) - { - verifications++; - } - } - - // - result = verifications == numberOfPivots - 1; - if (result) - { - dir = X_DIRECTION_BEARISH; - } - } - - // - // Bullish Trend ... - int valesChangesCount = CountValesChanges(); - if (!result && - valesChangesCount > numberOfPivots) - { - // - Clean(changes); - FillValesChanges(changes); - - // - verifications = 0; - for (int i = valesChangesCount - 1 - numberOfPivots; i < valesChangesCount - 2; i++) - { - // - XValueChange cChange = changes[i]; - XValueChange nChange = changes[i + 1]; - - // - if (cChange.after < nChange.after) - { - verifications++; - } - } - - // - result = verifications == numberOfPivots - 1; - if (result) - { - dir = X_DIRECTION_BULLISH; - } - } - - // - return result; - } diff --git a/Documents/BKP/x-121.smc.test.signal.class.mq5 b/Documents/BKP/x-121.smc.test.signal.class.mq5 deleted file mode 100644 index 20cdf644..00000000 --- a/Documents/BKP/x-121.smc.test.signal.class.mq5 +++ /dev/null @@ -1,787 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyTestSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - XPVPivot pivot; - - // - // Trigger Props ... - - // - // Constructor ... - X121SMCStrategyTestSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - pivot.Clean(); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCTestSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyTestSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Check Order Block ... - // TODO: Later ... - // bool hasOrderBlock = conditions.HasOrderBlock(); - // if (hasOrderBlock) - // { - // // - // DetectX121SMCTestSiganlOrderBlock( - // zBar, - // consolidationState, - // conditions // - // ); - // } - - // - bool isMarketBullish = - // - // VWap State ... - decisionConditions.x121Conditions.isVWapBullishState && - analyseConditions.x121Conditions.isVWapBullishState && - verificationConditions.x121Conditions.isVWapBullishState - // - && - // - // VWap Order ... - decisionConditions.x121Conditions.isVWapBullishOrdered && - analyseConditions.x121Conditions.isVWapBullishOrdered && - verificationConditions.x121Conditions.isVWapBullishOrdered - // - && - // - // Sar ... - decisionConditions.x121Conditions.isSarBullish && - analyseConditions.x121Conditions.isSarBullish && - verificationConditions.x121Conditions.isSarBullish - // - ; - - // - bool isMarketBearish = - // - // VWap State ... - decisionConditions.x121Conditions.isVWapBearishState && - analyseConditions.x121Conditions.isVWapBearishState && - verificationConditions.x121Conditions.isVWapBearishState - // - && - // - // VWap Order ... - decisionConditions.x121Conditions.isVWapBearishOrdered && - analyseConditions.x121Conditions.isVWapBearishOrdered && - verificationConditions.x121Conditions.isVWapBearishOrdered - // - && - // - // Sar ... - decisionConditions.x121Conditions.isSarBearish && - analyseConditions.x121Conditions.isSarBearish && - verificationConditions.x121Conditions.isSarBearish - // - ; - - // - // Step 1 - // Detect Market Direction ... - isBullish = isMarketBullish; - isBearish = isMarketBearish; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Step 2 - // VWap Switches or Sar Switches ... - - // - bool isSarBullish = triggerConditions.x121Conditions.isSarBullish; - bool isSarBearish = triggerConditions.x121Conditions.isSarBearish; - - // - bool isSarSwitchedToBullish = triggerConditions.x121Conditions.isSarSwitchedToBullish; - bool isSarSwitchedToBearish = triggerConditions.x121Conditions.isSarSwitchedToBearish; - - // - bool isVWapBullishState = triggerConditions.x121Conditions.isVWapBullishState; - bool isVWapBearishState = triggerConditions.x121Conditions.isVWapBearishState; - - // - bool isVWapSwitchedToBullishState = triggerConditions.x121Conditions.isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState = triggerConditions.x121Conditions.isVWapSwitchedToBearishState; - - // - bool isVWapBullishOrdered = triggerConditions.x121Conditions.isVWapBullishOrdered; - bool isVWapBearishOrdered = triggerConditions.x121Conditions.isVWapBearishOrdered; - - // - bool isVWapSwitchedToBullishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered = triggerConditions.x121Conditions.isVWapSwitchedToBearishOrdered; - - // - // - // - - // - bool isSarStartedBullishStructure = - // - isSarSwitchedToBullish && - isVWapBullishState && - isVWapBullishOrdered - // - ; - - // - bool isSarStartedBearishStructure = - // - isSarSwitchedToBearish && - isVWapBearishState && - isVWapBearishOrdered - // - ; - - // - // - // - - // - bool isVWapStateStartedBullishStructure = - // - isVWapSwitchedToBullishState && - isSarBullish && - isVWapBullishOrdered - // - ; - - // - bool isVWapStateStartedBearishStructure = - // - isVWapSwitchedToBearishState && - isSarBearish && - isVWapBearishOrdered - // - ; - - // - // - // - - // - bool isVWapOrderStartedBullishStructure = - // - isVWapSwitchedToBullishOrdered && - isSarBullish && - isVWapBullishState - // - ; - - // - bool isVWapOrderStartedBearishStructure = - // - isVWapSwitchedToBearishOrdered && - isSarBearish && - isVWapBearishState - // - ; - - // - // - // - - // - isBullish = - // - isBullish - // - && - // - ( - // - isSarStartedBullishStructure || - isVWapStateStartedBullishStructure || - isVWapOrderStartedBullishStructure - // - ) - // - ; - - // - isBearish = - // - isBearish - // - && - // - ( - // - isSarStartedBearishStructure || - isVWapStateStartedBearishStructure || - isVWapOrderStartedBearishStructure - // - ) - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCTestSiganlTrigger( - // - X121SMCStrategyTestSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_SMPV; - string providerStr = ToString(provider); - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = triggerCycleHelper.mX121Helper - .GetDonChainLength(); - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - result = false; - - // - return result; -} - -// -// Tools Functions ... - -// \ No newline at end of file