diff --git a/Classes/x-saherelm.x-chart-objects.class.mq5 b/Classes/x-saherelm.x-chart-objects.class.mq5 index 8e3fe276..3564d8d1 100644 --- a/Classes/x-saherelm.x-chart-objects.class.mq5 +++ b/Classes/x-saherelm.x-chart-objects.class.mq5 @@ -34,20 +34,20 @@ enum ENUM_XCHARTOBJECTS { // // Global ... - X_ZONE, - X_FROM_TO, + X_ZONE = 7861, + X_FROM_TO = 7862, // // Structured ... - X_TRADE_DAY, - X_MARKET_SESSION, - X_SUPPORT_ZONE, - X_RESISTANCE_ZONE, - X_SUPPLY_ZONE, - X_DEMAND_ZONE, - X_BULLISH_ORDERBLOCK, - X_BEARISH_ORDERBLOCK, - X_BULLISH_FVG, - X_BEARISH_FVG, + X_TRADE_DAY = 7863, + X_MARKET_SESSION = 7864, + X_SUPPORT_ZONE = 7865, + X_RESISTANCE_ZONE = 7866, + X_SUPPLY_ZONE = 7867, + X_DEMAND_ZONE = 7868, + X_BULLISH_ORDERBLOCK = 7869, + X_BEARISH_ORDERBLOCK = 78610, + X_BULLISH_FVG = 78611, + X_BEARISH_FVG = 78612, }; enum ENUM_X_CHART_IDS @@ -365,11 +365,6 @@ class XCZoneObject : public XCBaseObject !IsValid(objprefix) ? "" : objprefix + "_"; - result = Name(prefix); - if (!result) - { - return result; - } // // Check Params For Rectangle ... diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 26ca0a93..0ea38681 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -213,6 +213,26 @@ class XCPOI : public XSCBaseAlert // // Trading Days ... + /** + * Get Detect Trading Days State ... + * + * @return ( bool ) + */ + bool AllowTradingDays() + { + return mAllowTradingDays; + } + + /** + * Set Detect Trading Days State ... + * + * @param value: Boolean ... + */ + void AllowTradingDays(bool value) + { + mAllowTradingDays = value; + } + /** * Get Draw Trading Days State ... * @@ -316,6 +336,26 @@ class XCPOI : public XSCBaseAlert // // Sessions ... + /** + * Get Detect Market Sessions State ... + * + * @return ( bool ) + */ + bool AllowMarketSessions() + { + return mAllowMarketSessions; + } + + /** + * Set Detect Market Sessions State ... + * + * @param value: Boolean ... + */ + void AllowMarketSessions(bool value) + { + mAllowMarketSessions = value; + } + /** * Get Draw Market Sessions State ... * @@ -366,6 +406,26 @@ class XCPOI : public XSCBaseAlert // // Swing High ... + /** + * Get Detect Swing Highs State ... + * + * @return ( bool ) + */ + bool AllowSwingHighs() + { + return mAllowSwingHighs; + } + + /** + * Set Detect Swing Highs State ... + * + * @param value: Boolean + */ + void AllowSwingHighs(bool value) + { + mAllowSwingHighs = value; + } + /** * Get Draw Swing Highs State ... * @@ -483,6 +543,26 @@ class XCPOI : public XSCBaseAlert // // Swing Low ... + /** + * Get Detect Swing Lows State ... + * + * @return ( bool ) + */ + bool AllowSwingLows() + { + return mAllowSwingLows; + } + + /** + * Set Detect Swing Lows State ... + * + * @param value: Boolean ... + */ + void AllowSwingLows(bool value) + { + mAllowSwingLows = value; + } + /** * Get Draw Swing Lows State ... * @@ -600,6 +680,26 @@ class XCPOI : public XSCBaseAlert // // Momentum Bars ... + /** + * Get Detect Momentum Bars State ... + * + * @return ( bool ) + */ + bool AllowMomentumBars() + { + return mAllowMomentumBars; + } + + /** + * Set Detect Momentum Bars State ... + * + * @param value: Boolean ... + */ + void AllowMomentumBars(bool value) + { + mAllowMomentumBars = value; + } + /** * Get Draw Momentum Bars State ... * @@ -804,6 +904,26 @@ class XCPOI : public XSCBaseAlert // // Rejection Bars ... + /** + * Get Detect Rejection Bars State ... + * + * @return ( bool ) + */ + bool AllowRejectionBars() + { + return mAllowRejectionBars; + } + + /** + * Set Detect Rejection Bars State ... + * + * @param value: Boolean ... + */ + void AllowRejectionBars(bool value) + { + mAllowRejectionBars = value; + } + /** * Get Draw Rejection Bars State ... * @@ -987,6 +1107,26 @@ class XCPOI : public XSCBaseAlert // // Support Zone ... + /** + * Get Detect Support Zone State ... + * + * @return ( bool ) + */ + bool AllowSupportZones() + { + return mAllowSupportZones; + } + + /** + * Set Detect Support Zone State ... + * + * @param value: Boolean ... + */ + void AllowSupportZones(bool value) + { + mAllowSupportZones = value; + } + /** * Get Draw Support Zone State ... * @@ -1124,6 +1264,26 @@ class XCPOI : public XSCBaseAlert // // Resistance Zone ... + /** + * Get Detect Resistance Zone State ... + * + * @return ( bool ) + */ + bool AllowResistanceZones() + { + return mAllowResistanceZones; + } + + /** + * Set Detect Resistance Zone State ... + * + * @param value: Boolean ... + */ + void AllowResistanceZones(bool value) + { + mAllowResistanceZones = value; + } + /** * Get Draw Resistance Zone State ... * @@ -1261,6 +1421,26 @@ class XCPOI : public XSCBaseAlert // // Supply Zone ... + /** + * Get Detect Supply Zone State ... + * + * @return ( bool ) + */ + bool AllowSupplyZones() + { + return mAllowSupplyZones; + } + + /** + * Set Detect Supply Zone State ... + * + * @param value: Boolean ... + */ + void AllowSupplyZones(bool value) + { + mAllowSupplyZones = value; + } + /** * Get Draw Supply Zone State ... * @@ -1371,6 +1551,26 @@ class XCPOI : public XSCBaseAlert // // Demand Zone ... + /** + * Get Detect Demand Zone State ... + * + * @return ( bool ) + */ + bool AllowDemandZones() + { + return mAllowDemandZones; + } + + /** + * Set Detect Demand Zone State ... + * + * @param value: Boolean ... + */ + void AllowDemandZones(bool value) + { + mAllowDemandZones = value; + } + /** * Get Draw Demand Zone State ... * @@ -1484,6 +1684,26 @@ class XCPOI : public XSCBaseAlert // // Bullish Order Blocks ... + /** + * Get Detect Bullish Order Blocks State ... + * + * @return ( bool ) + */ + bool AllowBullishOrderBlocks() + { + return mAllowBullishOrderBlocks; + } + + /** + * Set Detect Bullish Order Blocks State ... + * + * @param value: Boolean ... + */ + void AllowBullishOrderBlocks(bool value) + { + mAllowBullishOrderBlocks = value; + } + /** * Get Draw Bullish Order Blocks State ... * @@ -1601,6 +1821,26 @@ class XCPOI : public XSCBaseAlert // // Bearish Order Blocks ... + /** + * Get Detect Bearish Order Blocks State ... + * + * @return ( bool ) + */ + bool AllowBearishOrderBlocks() + { + return mAllowBearishOrderBlocks; + } + + /** + * Set Detect Bearish Order Blocks State ... + * + * @param value: Boolean ... + */ + void AllowBearishOrderBlocks(bool value) + { + mAllowBearishOrderBlocks = value; + } + /** * Get Draw Bearish Order Blocks State ... * @@ -1721,6 +1961,26 @@ class XCPOI : public XSCBaseAlert // // Bullis FVGs ... + /** + * Get Detect Bullish Fair Value Gaps State ... + * + * @return ( bool ) + */ + bool AllowBullishFVGs() + { + return mAllowBullishFVGs; + } + + /** + * Set Detect Bullish Fair Value Gaps State ... + * + * @param value: Boolean ... + */ + void AllowBullishFVGs(bool value) + { + mAllowBullishFVGs = value; + } + /** * Get Draw Bullish Fair Value Gaps ... * @@ -1851,6 +2111,26 @@ class XCPOI : public XSCBaseAlert // // Bullis FVGs ... + /** + * Get Detect Bearish Fair Value Gaps State ... + * + * @return ( bool ) + */ + bool AllowBearishFVGs() + { + return mAllowBearishFVGs; + } + + /** + * Set Detect Bearish Fair Value Gaps State ... + * + * @param value: Boolean ... + */ + void AllowBearishFVGs(bool value) + { + mAllowBearishFVGs = value; + } + /** * Get Draw Bearish Fair Value Gaps ... * @@ -2073,54 +2353,59 @@ class XCPOI : public XSCBaseAlert // Trading Days ... // + bool allowTradingDays = AllowTradingDays(); int tradingDaysCount = ArraySize(mTradingDays); - int tradingDayIDX = HasTradeDay(zDayBar.time); - if (IsValidIndex(tradingDayIDX)) + if (allowTradingDays) { // - if (zBar.time == mTradingDays[tradingDayIDX].to) + int tradingDayIDX = HasTradeDay(zDayBar.time); + if (IsValidIndex(tradingDayIDX)) { // - ENUM_XPOI_EVENTS event = X_TRADE_DAY_LAST_BAR; - Add( - event, - state // - ); - OnTradingDayEvent(event); - NotifyTradingDayEventListeners(event); + if (zBar.time == mTradingDays[tradingDayIDX].to) + { + // + ENUM_XPOI_EVENTS event = X_TRADE_DAY_LAST_BAR; + Add( + event, + state // + ); + OnTradingDayEvent(event); + NotifyTradingDayEventListeners(event); + } } - } - else - { - // - // there isn't any Trading Day ... - // create one ... - - // - XTradeDay tradeDay; - tradeDay.from = zDayBar.time; - tradeDay.to = zDayBar.GetLastBarTimeOfPeriod(mPeriod); - - // - AddRef( - tradeDay, - mTradingDays // - ); - - // - DrawTradingDays(); - - // - // Notfy Day Started ... - if (zBar.time == zDayBar.time) + else { // - Add( - X_TRADE_DAY_FIRST_BAR, - state // + // there isn't any Trading Day ... + // create one ... + + // + XTradeDay tradeDay; + tradeDay.from = zDayBar.time; + tradeDay.to = zDayBar.GetLastBarTimeOfPeriod(mPeriod); + + // + AddRef( + tradeDay, + mTradingDays // ); - OnTradingDayEvent(X_TRADE_DAY_FIRST_BAR); - NotifyTradingDayEventListeners(X_TRADE_DAY_FIRST_BAR); + + // + DrawTradingDays(); + + // + // Notfy Day Started ... + if (zBar.time == zDayBar.time) + { + // + Add( + X_TRADE_DAY_FIRST_BAR, + state // + ); + OnTradingDayEvent(X_TRADE_DAY_FIRST_BAR); + NotifyTradingDayEventListeners(X_TRADE_DAY_FIRST_BAR); + } } } @@ -2128,99 +2413,104 @@ class XCPOI : public XSCBaseAlert // Market Session ... // + bool allowMarketSessions = AllowMarketSessions(); int marketSessionsCount = ArraySize(mMarketSessions); - int sessionsCount = ArraySize(mSessions); - bool isSessionFound = false; - if (IsValidSize(sessionsCount)) + if (allowMarketSessions) { // - for (int i = 0; i < sessionsCount; i++) + int sessionsCount = ArraySize(mSessions); + bool isSessionFound = false; + if (IsValidSize(sessionsCount)) { // - XSession iSession = mSessions[i]; - int marketSessionIDX = HasMarketSessionByStartTime( - iSession.session, - zBar.time // - ); - - // - if (!IsValidIndex(marketSessionIDX)) + for (int i = 0; i < sessionsCount; i++) { // - datetime zTimeGMT = GetUTCTime(zBar.time); - string zTimeString = GetTimeString(zTimeGMT); + XSession iSession = mSessions[i]; + int marketSessionIDX = HasMarketSessionByStartTime( + iSession.session, + zBar.time // + ); // - bool isStarted = iSession.start == zTimeString; - - // - if (isStarted) + if (!IsValidIndex(marketSessionIDX)) { // - XMarketSession iMarketSession; - iMarketSession.session = iSession.session; - iMarketSession.from = zBar.time; + datetime zTimeGMT = GetUTCTime(zBar.time); + string zTimeString = GetTimeString(zTimeGMT); // - int iSessionWorkingHoure = SessionOpenHours(); - int iSessionWorkingSeconds = iSessionWorkingHoure * 60 * 60; - iMarketSession.to = (datetime)((int)zBar.time + iSessionWorkingSeconds); + bool isStarted = iSession.start == zTimeString; // - isSessionFound = AddRef( - iMarketSession, - mMarketSessions // - ); + if (isStarted) + { + // + XMarketSession iMarketSession; + iMarketSession.session = iSession.session; + iMarketSession.from = zBar.time; - // - marketSessionsCount = ArraySize(mMarketSessions); + // + int iSessionWorkingHoure = SessionOpenHours(); + int iSessionWorkingSeconds = iSessionWorkingHoure * 60 * 60; + iMarketSession.to = (datetime)((int)zBar.time + iSessionWorkingSeconds); - // - DrawMarketSessions(); + // + isSessionFound = AddRef( + iMarketSession, + mMarketSessions // + ); - // - Add( - X_SESSION_FIRST_BAR, - state // - ); - OnMarketSessionEvent( - iMarketSession.session, - X_SESSION_FIRST_BAR // - ); - NotifyMarketSessionEventListeners( - iMarketSession.session, - X_SESSION_FIRST_BAR // - ); + // + marketSessionsCount = ArraySize(mMarketSessions); + + // + DrawMarketSessions(); + + // + Add( + X_SESSION_FIRST_BAR, + state // + ); + OnMarketSessionEvent( + iMarketSession.session, + X_SESSION_FIRST_BAR // + ); + NotifyMarketSessionEventListeners( + iMarketSession.session, + X_SESSION_FIRST_BAR // + ); + } } - } - - // - // Check End Time for Last Bar ... - for (int i = 0; i < marketSessionsCount; i++) - { - // - XMarketSession iMarketSession = mMarketSessions[i]; // - // Calculate Last Bar Time ... - datetime endTime = iMarketSession.to; - datetime lastBarTime = (datetime)((int)endTime - PeriodSeconds(mPeriod)); - if (zBar.time == lastBarTime) + // Check End Time for Last Bar ... + for (int i = 0; i < marketSessionsCount; i++) { // - ENUM_XPOI_EVENTS event = X_SESSION_LAST_BAR; - Add( - event, - state // - ); - OnMarketSessionEvent( - iMarketSession.session, - event // - ); - NotifyMarketSessionEventListeners( - iMarketSession.session, - event // - ); + XMarketSession iMarketSession = mMarketSessions[i]; + + // + // Calculate Last Bar Time ... + datetime endTime = iMarketSession.to; + datetime lastBarTime = (datetime)((int)endTime - PeriodSeconds(mPeriod)); + if (zBar.time == lastBarTime) + { + // + ENUM_XPOI_EVENTS event = X_SESSION_LAST_BAR; + Add( + event, + state // + ); + OnMarketSessionEvent( + iMarketSession.session, + event // + ); + NotifyMarketSessionEventListeners( + iMarketSession.session, + event // + ); + } } } } @@ -2233,32 +2523,37 @@ class XCPOI : public XSCBaseAlert // Swing Highs ... // + bool allowSwingHighs = AllowSwingHighs(); int swingHighsCount = ArraySize(mSwingHighs); - bool isSingHigh = pBar.IsSimpleSwingHigh(SwingHighThreshold()); - if (isSingHigh) + if (allowSwingHighs) { // - bool isAdded = AddBar( - X_POI_SWING_HIGH, - pBar, - mSwingHighs // - ); - - // - if (isAdded) + bool isSingHigh = pBar.IsSimpleSwingHigh(SwingHighThreshold()); + if (isSingHigh) { // - swingHighsCount = ArraySize(mSwingHighs); - DrawSwingHighs(); + bool isAdded = AddBar( + X_POI_SWING_HIGH, + pBar, + mSwingHighs // + ); // - ENUM_XPOI_EVENTS event = X_SWING_HIGH_DETECTED; - Add( - event, - state // - ); - OnSwingHighEvent(event, pBar); - NotifySwingHighEventListeners(event, pBar); + if (isAdded) + { + // + swingHighsCount = ArraySize(mSwingHighs); + DrawSwingHighs(); + + // + ENUM_XPOI_EVENTS event = X_SWING_HIGH_DETECTED; + Add( + event, + state // + ); + OnSwingHighEvent(event, pBar); + NotifySwingHighEventListeners(event, pBar); + } } } @@ -2266,32 +2561,37 @@ class XCPOI : public XSCBaseAlert // Swing Lows ... // + bool allowSwingLows = AllowSwingLows(); int swingLowsCount = ArraySize(mSwingLows); - bool isSingLow = pBar.IsSimpleSwingLow(SwingLowThreshold()); - if (isSingLow) + if (allowSwingLows) { // - bool isAdded = AddBar( - X_POI_SWING_LOW, - pBar, - mSwingLows // - ); - - // - if (isAdded) + bool isSingLow = pBar.IsSimpleSwingLow(SwingLowThreshold()); + if (isSingLow) { // - swingLowsCount = ArraySize(mSwingLows); - DrawSwingLows(); + bool isAdded = AddBar( + X_POI_SWING_LOW, + pBar, + mSwingLows // + ); // - ENUM_XPOI_EVENTS event = X_SWING_LOW_DETECTED; - Add( - event, - state // - ); - OnSwingLowEvent(event, pBar); - NotifySwingLowEventListeners(event, pBar); + if (isAdded) + { + // + swingLowsCount = ArraySize(mSwingLows); + DrawSwingLows(); + + // + ENUM_XPOI_EVENTS event = X_SWING_LOW_DETECTED; + Add( + event, + state // + ); + OnSwingLowEvent(event, pBar); + NotifySwingLowEventListeners(event, pBar); + } } } @@ -2299,44 +2599,49 @@ class XCPOI : public XSCBaseAlert // Momentum Bars ... // + bool allowMomentumBars = AllowMomentumBars(); int momentumBarsCount = ArraySize(mMomentumBars); - bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); - bool isSharpBullish = cBar.IsSharpBullish( - MomentumBarLoopBack(), - MomentumBarSharpRatio() // - ); - bool isSharpBearish = cBar.IsSharpBearish( - MomentumBarLoopBack(), - MomentumBarSharpRatio() // - ); - bool isMomentumBar = - isStrongBar && - (isSharpBearish || - isSharpBullish); - if (isMomentumBar) + if (allowMomentumBars) { // - bool isAdded = AddBar( - X_POI_MOMENTUM_BAR, - cBar, - mMomentumBars // + bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); + bool isSharpBullish = cBar.IsSharpBullish( + MomentumBarLoopBack(), + MomentumBarSharpRatio() // ); - - // - if (isAdded) + bool isSharpBearish = cBar.IsSharpBearish( + MomentumBarLoopBack(), + MomentumBarSharpRatio() // + ); + bool isMomentumBar = + isStrongBar && + (isSharpBearish || + isSharpBullish); + if (isMomentumBar) { // - momentumBarsCount = ArraySize(mMomentumBars); - DrawMomentumBars(); + bool isAdded = AddBar( + X_POI_MOMENTUM_BAR, + cBar, + mMomentumBars // + ); // - ENUM_XPOI_EVENTS event = X_MOMENTUM_BAR_DETECTED; - Add( - event, - state // - ); - OnMomentumBarEvent(event, cBar); - NotifyMomentumBarEventListeners(event, cBar); + if (isAdded) + { + // + momentumBarsCount = ArraySize(mMomentumBars); + DrawMomentumBars(); + + // + ENUM_XPOI_EVENTS event = X_MOMENTUM_BAR_DETECTED; + Add( + event, + state // + ); + OnMomentumBarEvent(event, cBar); + NotifyMomentumBarEventListeners(event, cBar); + } } } @@ -2344,52 +2649,57 @@ class XCPOI : public XSCBaseAlert // Rejection Bars ... // + bool allowRejectionBars = AllowRejectionBars(); int rejectionBarsCount = ArraySize(mRejectionBars); - int rejectionBarLoopBackBarIndex = RejectionBarLoopBack() + 1; - XOHCL iRBar; - bool isIRBarInited = iRBar.Init( - Symbol(), - Period(), - rejectionBarLoopBackBarIndex // - ); - if (isIRBarInited) + if (allowRejectionBars) { // - bool isRejectionBar = - iRBar.HasStrongLowShadow( - RejectionBarPercent(), - RejectionBarLoopBack(), - RejectionBarSharpRatio() // - ) || - iRBar.HasStrongHighShadow( - RejectionBarPercent(), - RejectionBarLoopBack(), - RejectionBarSharpRatio() // - ); - if (isRejectionBar) + int rejectionBarLoopBackBarIndex = RejectionBarLoopBack() + 1; + XOHCL iRBar; + bool isIRBarInited = iRBar.Init( + Symbol(), + Period(), + rejectionBarLoopBackBarIndex // + ); + if (isIRBarInited) { // - bool isAdded = AddBar( - X_POI_REJECTION_BAR, - iRBar, - mRejectionBars // - ); - - // - if (isAdded) + bool isRejectionBar = + iRBar.HasStrongLowShadow( + RejectionBarPercent(), + RejectionBarLoopBack(), + RejectionBarSharpRatio() // + ) || + iRBar.HasStrongHighShadow( + RejectionBarPercent(), + RejectionBarLoopBack(), + RejectionBarSharpRatio() // + ); + if (isRejectionBar) { // - rejectionBarsCount = ArraySize(mRejectionBars); - DrawRejectionBars(); + bool isAdded = AddBar( + X_POI_REJECTION_BAR, + iRBar, + mRejectionBars // + ); // - ENUM_XPOI_EVENTS event = X_REJECTION_BAR_DETECTED; - Add( - event, - state // - ); - OnRejectionBarEvent(event, iRBar); - NotifyRejectionBarEventListeners(event, iRBar); + if (isAdded) + { + // + rejectionBarsCount = ArraySize(mRejectionBars); + DrawRejectionBars(); + + // + ENUM_XPOI_EVENTS event = X_REJECTION_BAR_DETECTED; + Add( + event, + state // + ); + OnRejectionBarEvent(event, iRBar); + NotifyRejectionBarEventListeners(event, iRBar); + } } } } @@ -2401,37 +2711,42 @@ class XCPOI : public XSCBaseAlert // Support Zones ... // + bool allowSupportZones = AllowSupportZones(); int supportZonesCount = ArraySize(mSupportZones); - XOHCL support; - bool hasSupport = cBar.HasSupport( - support, - SupportZonePriceType(), - SupportZoneLoopBack() // - ); - if (hasSupport) + if (allowSupportZones) { // - bool isAdded = AddBar( - X_POI_SUPPORT_ZONE, + XOHCL support; + bool hasSupport = cBar.HasSupport( support, - mSupportZones // + SupportZonePriceType(), + SupportZoneLoopBack() // ); - - // - if (isAdded) + if (hasSupport) { // - supportZonesCount = ArraySize(mSupportZones); - DrawSupportZones(); + bool isAdded = AddBar( + X_POI_SUPPORT_ZONE, + support, + mSupportZones // + ); // - ENUM_XPOI_EVENTS event = X_SUPPORT_ZONE_DETECTED; - Add( - event, - state // - ); - OnSupportZoneEvent(event, support); - NotifySupportZoneEventListeners(event, support); + if (isAdded) + { + // + supportZonesCount = ArraySize(mSupportZones); + DrawSupportZones(); + + // + ENUM_XPOI_EVENTS event = X_SUPPORT_ZONE_DETECTED; + Add( + event, + state // + ); + OnSupportZoneEvent(event, support); + NotifySupportZoneEventListeners(event, support); + } } } @@ -2439,37 +2754,42 @@ class XCPOI : public XSCBaseAlert // Resistance Zone ... // + bool allowResistanceZones = AllowResistanceZones(); int resistanceZonesCount = ArraySize(mResistanceZones); - XOHCL resistance; - bool hasResistance = cBar.HasResistance( - resistance, - ResistanceZonePriceType(), - ResistanceZoneLoopBack() // - ); - if (hasResistance) + if (allowResistanceZones) { // - bool isAdded = AddBar( - X_POI_RESISTANCE_ZONE, + XOHCL resistance; + bool hasResistance = cBar.HasResistance( resistance, - mResistanceZones // + ResistanceZonePriceType(), + ResistanceZoneLoopBack() // ); - - // - if (isAdded) + if (hasResistance) { // - resistanceZonesCount = ArraySize(mResistanceZones); - DrawResistanceZones(); + bool isAdded = AddBar( + X_POI_RESISTANCE_ZONE, + resistance, + mResistanceZones // + ); // - ENUM_XPOI_EVENTS event = X_RESISTANCE_ZONE_DETECTED; - Add( - event, - state // - ); - OnResistanceZoneEvent(event, resistance); - NotifyResistanceZoneEventListeners(event, resistance); + if (isAdded) + { + // + resistanceZonesCount = ArraySize(mResistanceZones); + DrawResistanceZones(); + + // + ENUM_XPOI_EVENTS event = X_RESISTANCE_ZONE_DETECTED; + Add( + event, + state // + ); + OnResistanceZoneEvent(event, resistance); + NotifyResistanceZoneEventListeners(event, resistance); + } } } @@ -2480,122 +2800,127 @@ class XCPOI : public XSCBaseAlert // Supply Zones ... // + bool allowSupplyZones = AllowSupplyZones(); int supplyZonesCount = ArraySize(mSupplyZones); - datetime endTime = cBar.time; - XOHCL cSupplyBar; - bool isSupplyBarInited = cSupplyBar.Init( - Symbol(), - SupplyZonePeriod(), - 0 // - ); - if (isSupplyBarInited) + if (allowSupplyZones) { // - datetime lastSupplyBarTime = cSupplyBar - .GetLastBarTimeOfPeriod(Period()); - if (zBar.time == lastSupplyBarTime) + datetime endTime = cBar.time; + XOHCL cSupplyBar; + bool isSupplyBarInited = cSupplyBar.Init( + Symbol(), + SupplyZonePeriod(), + 0 // + ); + if (isSupplyBarInited) { // - datetime startTime = cSupplyBar.time; - int cSupplyZonePeriodIndex = iBarShift( - Symbol(), - Period(), - cSupplyBar.time // - ); - - // - // Find Swings ... - XOHCL swings[]; - for (int i = 0; i < cSupplyZonePeriodIndex; i++) + datetime lastSupplyBarTime = cSupplyBar + .GetLastBarTimeOfPeriod(Period()); + if (zBar.time == lastSupplyBarTime) { // - XOHCL iBar; - bool isIBarInited = iBar.Init( + datetime startTime = cSupplyBar.time; + int cSupplyZonePeriodIndex = iBarShift( Symbol(), Period(), - i // + cSupplyBar.time // ); - if (!isIBarInited) - { - continue; - } // - // Check is Bar Swing or not ... - bool isSwing = iBar.IsSimpleSwingHigh(); - if (!isSwing) - { - continue; - } - - // - AddRef( - iBar, - swings // - ); - } - - // - // Select Max Swing for Supply Zone ... - XOHCL selectedSwing; - int swingsCount = ArraySize(swings); - if (IsValidSize(swingsCount)) - { - // - for (int i = 0; i < swingsCount; i++) + // Find Swings ... + XOHCL swings[]; + for (int i = 0; i < cSupplyZonePeriodIndex; i++) { // - XOHCL iSwing = swings[i]; - if (!selectedSwing.IsValid() || - selectedSwing.high < iSwing.high) - { - selectedSwing = iSwing; - } - } - } - - // - // Check Swing ... - if (selectedSwing.IsValid()) - { - // - XZone zone; - bool isInited = zone.Init( - selectedSwing.high, - selectedSwing.low, - ToString(X_POI_SUPPLY_ZONE) + "_" + ToString(SupplyZonePeriod()), - startTime, - endTime // - ); - if (isInited) - { - // - int zoneIDX = FindZoneIndex( - zone, - mSupplyZones // + XOHCL iBar; + bool isIBarInited = iBar.Init( + Symbol(), + Period(), + i // ); + if (!isIBarInited) + { + continue; + } // - if (!IsValidIndex(zoneIDX)) + // Check is Bar Swing or not ... + bool isSwing = iBar.IsSimpleSwingHigh(); + if (!isSwing) + { + continue; + } + + // + AddRef( + iBar, + swings // + ); + } + + // + // Select Max Swing for Supply Zone ... + XOHCL selectedSwing; + int swingsCount = ArraySize(swings); + if (IsValidSize(swingsCount)) + { + // + for (int i = 0; i < swingsCount; i++) { // - AddRef( + XOHCL iSwing = swings[i]; + if (!selectedSwing.IsValid() || + selectedSwing.high < iSwing.high) + { + selectedSwing = iSwing; + } + } + } + + // + // Check Swing ... + if (selectedSwing.IsValid()) + { + // + XZone zone; + bool isInited = zone.Init( + selectedSwing.high, + selectedSwing.low, + ToString(X_POI_SUPPLY_ZONE) + "_" + ToString(SupplyZonePeriod()), + startTime, + endTime // + ); + if (isInited) + { + // + int zoneIDX = FindZoneIndex( zone, mSupplyZones // ); // - supplyZonesCount = ArraySize(mSupplyZones); - DrawSupplyZones(); + if (!IsValidIndex(zoneIDX)) + { + // + AddRef( + zone, + mSupplyZones // + ); - // - ENUM_XPOI_EVENTS event = X_SUPPLY_ZONE_DETECTED; - Add( - event, - state // - ); - OnSupplyZoneEvent(event, zone); - NotifySupplyZoneEventListeners(event, zone); + // + supplyZonesCount = ArraySize(mSupplyZones); + DrawSupplyZones(); + + // + ENUM_XPOI_EVENTS event = X_SUPPLY_ZONE_DETECTED; + Add( + event, + state // + ); + OnSupplyZoneEvent(event, zone); + NotifySupplyZoneEventListeners(event, zone); + } } } } @@ -2606,122 +2931,127 @@ class XCPOI : public XSCBaseAlert // Demand Zones ... // + bool allowDemandZones = AllowDemandZones(); int demandZonesCount = ArraySize(mDemandZones); - endTime = cBar.time; - XOHCL cDemandBar; - bool isDemandBarInited = cDemandBar.Init( - Symbol(), - DemandZonePeriod(), - 0 // - ); - if (isDemandBarInited) + if (allowDemandZones) { // - datetime lastDemandBarTime = cDemandBar - .GetLastBarTimeOfPeriod(Period()); - if (zBar.time == lastDemandBarTime) + endTime = cBar.time; + XOHCL cDemandBar; + bool isDemandBarInited = cDemandBar.Init( + Symbol(), + DemandZonePeriod(), + 0 // + ); + if (isDemandBarInited) { // - datetime startTime = cDemandBar.time; - int cDemandZonePeriodIndex = iBarShift( - Symbol(), - Period(), - cDemandBar.time // - ); - - // - // Find Swings ... - XOHCL swings[]; - for (int i = 0; i < cDemandZonePeriodIndex; i++) + datetime lastDemandBarTime = cDemandBar + .GetLastBarTimeOfPeriod(Period()); + if (zBar.time == lastDemandBarTime) { // - XOHCL iBar; - bool isIBarInited = iBar.Init( + datetime startTime = cDemandBar.time; + int cDemandZonePeriodIndex = iBarShift( Symbol(), Period(), - i // + cDemandBar.time // ); - if (!isIBarInited) - { - continue; - } // - // Check is Bar Swing or not ... - bool isSwing = iBar.IsSimpleSwingLow(); - if (!isSwing) - { - continue; - } - - // - AddRef( - iBar, - swings // - ); - } - - // - // Select Max Swing for Supply Zone ... - XOHCL selectedSwing; - int swingsCount = ArraySize(swings); - if (IsValidSize(swingsCount)) - { - // - for (int i = 0; i < swingsCount; i++) + // Find Swings ... + XOHCL swings[]; + for (int i = 0; i < cDemandZonePeriodIndex; i++) { // - XOHCL iSwing = swings[i]; - if (!selectedSwing.IsValid() || - selectedSwing.low > iSwing.low) - { - selectedSwing = iSwing; - } - } - } - - // - // Check Swing ... - if (selectedSwing.IsValid()) - { - // - XZone zone; - bool isInited = zone.Init( - selectedSwing.high, - selectedSwing.low, - ToString(X_POI_DEMAND_ZONE) + "_" + ToString(SupplyZonePeriod()), - startTime, - endTime // - ); - if (isInited) - { - // - int zoneIDX = FindZoneIndex( - zone, - mDemandZones // + XOHCL iBar; + bool isIBarInited = iBar.Init( + Symbol(), + Period(), + i // ); + if (!isIBarInited) + { + continue; + } // - if (!IsValidIndex(zoneIDX)) + // Check is Bar Swing or not ... + bool isSwing = iBar.IsSimpleSwingLow(); + if (!isSwing) + { + continue; + } + + // + AddRef( + iBar, + swings // + ); + } + + // + // Select Max Swing for Supply Zone ... + XOHCL selectedSwing; + int swingsCount = ArraySize(swings); + if (IsValidSize(swingsCount)) + { + // + for (int i = 0; i < swingsCount; i++) { // - AddRef( + XOHCL iSwing = swings[i]; + if (!selectedSwing.IsValid() || + selectedSwing.low > iSwing.low) + { + selectedSwing = iSwing; + } + } + } + + // + // Check Swing ... + if (selectedSwing.IsValid()) + { + // + XZone zone; + bool isInited = zone.Init( + selectedSwing.high, + selectedSwing.low, + ToString(X_POI_DEMAND_ZONE) + "_" + ToString(SupplyZonePeriod()), + startTime, + endTime // + ); + if (isInited) + { + // + int zoneIDX = FindZoneIndex( zone, mDemandZones // ); // - demandZonesCount = ArraySize(mDemandZones); - DrawDemandZones(); + if (!IsValidIndex(zoneIDX)) + { + // + AddRef( + zone, + mDemandZones // + ); - // - ENUM_XPOI_EVENTS event = X_DEMAND_ZONE_DETECTED; - Add( - event, - state // - ); - OnDemandZoneEvent(event, zone); - NotifyDemandZoneEventListeners(event, zone); + // + demandZonesCount = ArraySize(mDemandZones); + DrawDemandZones(); + + // + ENUM_XPOI_EVENTS event = X_DEMAND_ZONE_DETECTED; + Add( + event, + state // + ); + OnDemandZoneEvent(event, zone); + NotifyDemandZoneEventListeners(event, zone); + } } } } @@ -2735,37 +3065,42 @@ class XCPOI : public XSCBaseAlert // Bullish Order Blocks ... // - XOHCL bullOB; + bool allowBullishOrderBlocks = AllowBullishOrderBlocks(); int bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - bool hasBullOB = cBar.HasBullishOrderBlock( - bullOB, - RequiredBarsForBullishOrderBlock() // - ); - if (hasBullOB) + if (allowBullishOrderBlocks) { // - XZone obZone; - bool isAdded = AddZone( - obZone, // Dest ... + XOHCL bullOB; + bool hasBullOB = cBar.HasBullishOrderBlock( bullOB, - cBar.time, - X_POI_BULLISH_ORDERBLOCK, - mBullishOrderBlocks // + RequiredBarsForBullishOrderBlock() // ); - if (isAdded) + if (hasBullOB) { // - bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - DrawBullishOrderBlocks(); - - // - ENUM_XPOI_EVENTS event = X_BULLISH_ORDERBLOCK_DETECTED; - Add( - event, - state // + XZone obZone; + bool isAdded = AddZone( + obZone, // Dest ... + bullOB, + cBar.time, + X_POI_BULLISH_ORDERBLOCK, + mBullishOrderBlocks // ); - OnBullishOrderBlockEvent(event, obZone); - NotifyBullishOrderBlockEventListeners(event, obZone); + if (isAdded) + { + // + bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); + DrawBullishOrderBlocks(); + + // + ENUM_XPOI_EVENTS event = X_BULLISH_ORDERBLOCK_DETECTED; + Add( + event, + state // + ); + OnBullishOrderBlockEvent(event, obZone); + NotifyBullishOrderBlockEventListeners(event, obZone); + } } } @@ -2773,37 +3108,42 @@ class XCPOI : public XSCBaseAlert // Bearish Order Blocks ... // + bool allowBearishOrderBlocks = AllowBearishOrderBlocks(); int bearishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - XOHCL bearOB; - bool hasBearOB = cBar.HasBearishOrderBlock( - bearOB, - RequiredBarsForBearishOrderBlock() // - ); - if (hasBearOB) + if (allowBearishOrderBlocks) { // - XZone zone; - bool isAdded = AddZone( - zone, // + XOHCL bearOB; + bool hasBearOB = cBar.HasBearishOrderBlock( bearOB, - cBar.time, - X_POI_BEARISH_ORDERBLOCK, - mBearishOrderBlocks // + RequiredBarsForBearishOrderBlock() // ); - if (isAdded) + if (hasBearOB) { // - bullishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - DrawBearishOrderBlocks(); - - // - ENUM_XPOI_EVENTS event = X_BEARISH_ORDERBLOCK_DETECTED; - Add( - event, - state // + XZone zone; + bool isAdded = AddZone( + zone, // + bearOB, + cBar.time, + X_POI_BEARISH_ORDERBLOCK, + mBearishOrderBlocks // ); - OnBullishOrderBlockEvent(event, zone); - NotifyBullishOrderBlockEventListeners(event, zone); + if (isAdded) + { + // + bullishOrderBlocksCount = ArraySize(mBearishOrderBlocks); + DrawBearishOrderBlocks(); + + // + ENUM_XPOI_EVENTS event = X_BEARISH_ORDERBLOCK_DETECTED; + Add( + event, + state // + ); + OnBullishOrderBlockEvent(event, zone); + NotifyBullishOrderBlockEventListeners(event, zone); + } } } @@ -2816,83 +3156,93 @@ class XCPOI : public XSCBaseAlert // // Bullish FVGs ... + bool allowBullishFVGs = AllowBullishFVGs(); int bullishFVGsCount = ArraySize(mBullishFVGs); - bool hasBullishFVG = cBar.HasBullishFVG( - upper, - lower, - start, - end, - BullishFVGForceMiddleBarCheck(), - BullishFVGForceCheckLastBarDirection() // - ); - if (hasBullishFVG) + if (allowBullishFVGs) { // - XZone zone; - bool isAdded = AddZone( - zone, + bool hasBullishFVG = cBar.HasBullishFVG( upper, lower, start, end, - X_POI_BULLISH_FVG, - mBullishFVGs // + BullishFVGForceMiddleBarCheck(), + BullishFVGForceCheckLastBarDirection() // ); - if (isAdded) + if (hasBullishFVG) { // - bullishFVGsCount = ArraySize(mBullishFVGs); - DrawBullishFVGs(); - - // - ENUM_XPOI_EVENTS event = X_BULLISH_FVG_DETECTED; - Add( - event, - state // + XZone zone; + bool isAdded = AddZone( + zone, + upper, + lower, + start, + end, + X_POI_BULLISH_FVG, + mBullishFVGs // ); - OnBullishFVGEvent(event, zone); - NotifyBullishFVGEventListeners(event, zone); + if (isAdded) + { + // + bullishFVGsCount = ArraySize(mBullishFVGs); + DrawBullishFVGs(); + + // + ENUM_XPOI_EVENTS event = X_BULLISH_FVG_DETECTED; + Add( + event, + state // + ); + OnBullishFVGEvent(event, zone); + NotifyBullishFVGEventListeners(event, zone); + } } } // // Bearish FVGs ... + bool allowBearishFVGs = AllowBearishFVGs(); int bearishFVGsCount = ArraySize(mBearishFVGs); - bool hasBearishFVG = cBar.HasBearishFVG( - upper, - lower, - start, - end, - BearishFVGForceMiddleBarCheck(), - BearishFVGForceCheckLastBarDirection() // - ); - if (hasBearishFVG) + if (allowBearishFVGs) { // - XZone zone; - bool isAdded = AddZone( - zone, + bool hasBearishFVG = cBar.HasBearishFVG( upper, lower, start, end, - X_POI_BEARISH_FVG, - mBearishFVGs // + BearishFVGForceMiddleBarCheck(), + BearishFVGForceCheckLastBarDirection() // ); - if (isAdded) + if (hasBearishFVG) { // - bearishFVGsCount = ArraySize(mBearishFVGs); - DrawBearishFVGs(); - - // - ENUM_XPOI_EVENTS event = X_BEARISH_FVG_DETECTED; - Add( - event, - state // + XZone zone; + bool isAdded = AddZone( + zone, + upper, + lower, + start, + end, + X_POI_BEARISH_FVG, + mBearishFVGs // ); - OnBearishFVGEvent(event, zone); - NotifyBearishFVGEventListeners(event, zone); + if (isAdded) + { + // + bearishFVGsCount = ArraySize(mBearishFVGs); + DrawBearishFVGs(); + + // + ENUM_XPOI_EVENTS event = X_BEARISH_FVG_DETECTED; + Add( + event, + state // + ); + OnBearishFVGEvent(event, zone); + NotifyBearishFVGEventListeners(event, zone); + } } } @@ -2912,6 +3262,46 @@ class XCPOI : public XSCBaseAlert return result; } + /** + * Enable All POIs Detection ... + */ + void EnablePOIs() + { + ChangePOIsState(true); + } + + /** + * Disable All POIs Detection ... + */ + void DisablePOIs() + { + ChangePOIsState(false); + } + + /** + * Set All POIs Detection States ... + * + * @param state: Argument 1 + */ + void ChangePOIsState(bool state) + { + // + AllowSwingLows(state); + AllowSwingHighs(state); + AllowTradingDays(state); + AllowSupplyZones(state); + AllowDemandZones(state); + AllowBullishFVGs(state); + AllowBearishFVGs(state); + AllowMomentumBars(state); + AllowSupportZones(state); + AllowRejectionBars(state); + AllowMarketSessions(state); + AllowResistanceZones(state); + AllowBullishOrderBlocks(state); + AllowBearishOrderBlocks(state); + } + /** * Enable Draw All POI(s) ... */ @@ -2965,6 +3355,54 @@ class XCPOI : public XSCBaseAlert } } + // + // Retrievers ... + + /** + * Get Current State of POIs ... + * + * @param state: XPOIState instance ... + */ + void GetState( + XPOIState &state) + { + // + state.Clean(); + + // + state.symbol = Symbol(); + state.period = Period(); + state.reportedAt = TimeCurrent(); + + // + state.FillTradingDays(mTradingDays); + state.FillMarketSessions(mMarketSessions); + + // + state.FillMomentumBars(mMomentumBars); + state.FillRejectionBars(mRejectionBars); + + // + state.FillSwingHighs(mSwingHighs); + state.FillSwingLows(mSwingLows); + + // + state.FillSupportZones(mSupportZones); + state.FillResistanceZones(mResistanceZones); + + // + state.FillSupplyZones(mSupplyZones); + state.FillDemandZones(mDemandZones); + + // + state.FillBullishOrderBlocks(mBullishOrderBlocks); + state.FillBearishOrderBlocks(mBearishOrderBlocks); + + // + state.FillBullishFVGs(mBullishFVGs); + state.FillBearishFVGs(mBearishFVGs); + } + // // Virtual Actions ... @@ -2984,6 +3422,10 @@ class XCPOI : public XSCBaseAlert MaxNumberOfPOIs(10); MaxNumberOfRequiredPOIs(2); + // + EnablePOIs(); + EnableDrawPOIs(); + // // Trading Days ... TradingDaysStartColor(clrYellow); @@ -3712,8 +4154,10 @@ class XCPOI : public XSCBaseAlert // // Trade Days ... + bool allowTradingDays = AllowTradingDays(); int daysCount = ArraySize(mTradingDays); - if (daysCount < requiredPOIs) + if (allowTradingDays && + daysCount < requiredPOIs) { // XOHCL zDayBar; @@ -3765,8 +4209,10 @@ class XCPOI : public XSCBaseAlert // // Market Sessions ... int sessionsCount = ArraySize(mSessions); + bool allowMarketSessions = AllowMarketSessions(); int marketSessionsCount = ArraySize(mMarketSessions); - if (IsValidSize(sessionsCount) && + if (allowMarketSessions && + IsValidSize(sessionsCount) && marketSessionsCount < sessionsCount * requiredPOIs) { // @@ -3832,8 +4278,10 @@ class XCPOI : public XSCBaseAlert // // Swing Highs ... + bool allowSwingHighs = AllowSwingHighs(); int swingHighsCount = ArraySize(mSwingHighs); - if (swingHighsCount < requiredPOIs) + if (allowSwingHighs && + swingHighsCount < requiredPOIs) { // bool isSwingHigh = cBar.IsSimpleSwingHigh(SwingHighThreshold()); @@ -3856,8 +4304,10 @@ class XCPOI : public XSCBaseAlert // // Swing Lows ... + bool allowSwingLows = AllowSwingLows(); int swingLowsCount = ArraySize(mSwingLows); - if (swingLowsCount < requiredPOIs) + if (allowSwingLows && + swingLowsCount < requiredPOIs) { // bool isSwingLow = cBar.IsSimpleSwingLow(SwingLowThreshold()); @@ -3880,8 +4330,10 @@ class XCPOI : public XSCBaseAlert // // Momentum Bars ... + bool allowMomentumBars = AllowMomentumBars(); int momentumBarsCount = ArraySize(mMomentumBars); - if (momentumBarsCount < requiredPOIs) + if (allowMomentumBars && + momentumBarsCount < requiredPOIs) { // bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); @@ -3924,8 +4376,10 @@ class XCPOI : public XSCBaseAlert // // Rejection Bars ... + bool allowRejectionBars = AllowRejectionBars(); int rejectionBarsCount = ArraySize(mRejectionBars); - if (rejectionBarsCount < requiredPOIs) + if (allowRejectionBars && + rejectionBarsCount < requiredPOIs) { // bool isRejectionBar = @@ -3963,8 +4417,10 @@ class XCPOI : public XSCBaseAlert // // Support Zones ... + bool allowSupportZones = AllowSupportZones(); int supportZonesCount = ArraySize(mSupportZones); - if (supportZonesCount < requiredPOIs) + if (allowSupportZones && + supportZonesCount < requiredPOIs) { // XOHCL support; @@ -3994,8 +4450,10 @@ class XCPOI : public XSCBaseAlert // // Resistance Zones ... + bool allowResistanceZones = AllowResistanceZones(); int resistanceZonesCount = ArraySize(mResistanceZones); - if (resistanceZonesCount < requiredPOIs) + if (allowResistanceZones && + resistanceZonesCount < requiredPOIs) { // XOHCL resistance; @@ -4028,8 +4486,10 @@ class XCPOI : public XSCBaseAlert // // Supply Zones ... + bool allowSupplyZones = AllowSupplyZones(); int supplyZonesCount = ArraySize(mSupplyZones); - if (supplyZonesCount < requiredPOIs) + if (allowSupplyZones && + supplyZonesCount < requiredPOIs) { // datetime endTime = cBar.time; @@ -4126,8 +4586,10 @@ class XCPOI : public XSCBaseAlert // // Demand Zones ... + bool allowDemandZones = AllowDemandZones(); int demandZonesCount = ArraySize(mDemandZones); - if (demandZonesCount < requiredPOIs) + if (allowDemandZones && + demandZonesCount < requiredPOIs) { // datetime endTime = cBar.time; @@ -4227,8 +4689,10 @@ class XCPOI : public XSCBaseAlert // // Bullish Order Blocks ... + bool allowBullishOrderBlocks = AllowBullishOrderBlocks(); int bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - if (bullishOrderBlocksCount < requiredPOIs) + if (allowBullishOrderBlocks && + bullishOrderBlocksCount < requiredPOIs) { // XOHCL ob; @@ -4256,8 +4720,10 @@ class XCPOI : public XSCBaseAlert // // Bearish Order Blocks ... + bool allowBearishOrderBlocks = AllowBearishOrderBlocks(); int bearishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - if (bearishOrderBlocksCount < requiredPOIs) + if (allowBearishOrderBlocks && + bearishOrderBlocksCount < requiredPOIs) { // XOHCL ob; @@ -4288,8 +4754,10 @@ class XCPOI : public XSCBaseAlert // // Bullish FVGs ... + bool allowBullishFVGs = AllowBullishFVGs(); int bullishFVGsCount = ArraySize(mBullishFVGs); - if (bullishFVGsCount < requiredPOIs) + if (allowBullishFVGs && + bullishFVGsCount < requiredPOIs) { // double upper; @@ -4326,8 +4794,10 @@ class XCPOI : public XSCBaseAlert // // Bearish FVGs ... + bool allowBearishFVGs = AllowBearishFVGs(); int bearishFVGsCount = ArraySize(mBearishFVGs); - if (bearishFVGsCount < requiredPOIs) + if (allowBearishFVGs && + bearishFVGsCount < requiredPOIs) { // double upper; @@ -4374,36 +4844,50 @@ class XCPOI : public XSCBaseAlert canContinue = // // Trade Days ... - daysCount < requiredPOIs || + (allowTradingDays && + daysCount < requiredPOIs) || // // Market Sessions ... - isNeedMoreMarketSessions || + (allowMarketSessions && + isNeedMoreMarketSessions) || // // Swing High and Low (s) ... - swingHighsCount < requiredPOIs || - swingLowsCount < requiredPOIs || + (allowSwingHighs && + swingHighsCount < requiredPOIs) || + (allowSwingLows && + swingLowsCount < requiredPOIs) || // // Momentum Bars ... - momentumBarsCount < requiredPOIs || + (allowMomentumBars && + momentumBarsCount < requiredPOIs) || // // Rejection Bars ... - rejectionBarsCount < requiredPOIs || + (allowRejectionBars && + rejectionBarsCount < requiredPOIs) || // // Support and Resistance Zones ... - supportZonesCount < requiredPOIs || - resistanceZonesCount < requiredPOIs || + (allowSupportZones && + supportZonesCount < requiredPOIs) || + (allowResistanceZones && + resistanceZonesCount < requiredPOIs) || // // Supply and Demand Zones ... - supplyZonesCount < requiredPOIs || - demandZonesCount < requiredPOIs || + (allowSupplyZones && + supplyZonesCount < requiredPOIs) || + (allowDemandZones && + demandZonesCount < requiredPOIs) || // // Order Blocks ... - bullishOrderBlocksCount < requiredPOIs || - bearishOrderBlocksCount < requiredPOIs || + (allowBullishOrderBlocks && + bullishOrderBlocksCount < requiredPOIs) || + (allowBearishOrderBlocks && + bearishOrderBlocksCount < requiredPOIs) || // // Fair Value Gaps ... - bullishFVGsCount < requiredPOIs || - bearishFVGsCount < requiredPOIs + (allowBullishFVGs && + bullishFVGsCount < requiredPOIs) || + (allowBearishFVGs && + bearishFVGsCount < requiredPOIs) // ; if (canContinue) @@ -4413,12 +4897,12 @@ class XCPOI : public XSCBaseAlert } // - int errorArr[]; - if (canContinue) - { - // - int t = errorArr[5]; - } + // int errorArr[]; + // if (canContinue) + // { + // // + // int t = errorArr[5]; + // } // // Complete Calculations ... @@ -5246,7 +5730,7 @@ class XCPOI : public XSCBaseAlert } // - int count = mMomentumBarObjects.Total(); + int count = mRejectionBarObjects.Total(); if (!IsValidSize(count)) { return result; @@ -5380,9 +5864,8 @@ class XCPOI : public XSCBaseAlert // string iName = iSupportZone.GetTag(ToString(X_POI_SUPPORT_ZONE)); - int iIDX = HasObject( - iName, - mSupportZoneObjects // + int iIDX = HasSupportZoneObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5394,6 +5877,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Suport Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasSupportZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mSupportZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCSupportZoneObject *)mSupportZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Resistance Zones ... */ @@ -5421,9 +5948,8 @@ class XCPOI : public XSCBaseAlert // string iName = iResistanceZone.GetTag(ToString(X_POI_RESISTANCE_ZONE)); - int iIDX = HasObject( - iName, - mResistanceZoneObjects // + int iIDX = HasResistanceZoneObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5431,10 +5957,54 @@ class XCPOI : public XSCBaseAlert } // - // CreateResistanceZoneObject(iResistanceZone, iName); + CreateResistanceZoneObject(iResistanceZone, iName); } } + /** + * Check a Resistance Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasResistanceZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mResistanceZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCResistanceZoneObject *)mResistanceZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Supply Zones ... */ @@ -5462,9 +6032,8 @@ class XCPOI : public XSCBaseAlert // string iName = iSupplyZone.GetTag(); - int iIDX = HasObject( - iName, - mSupplyZoneObjects // + int iIDX = HasSupplyZoneObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5476,6 +6045,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Supply Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasSupplyZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mSupplyZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCSupplyZoneObject *)mSupplyZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Demand Zones ... */ @@ -5503,9 +6116,8 @@ class XCPOI : public XSCBaseAlert // string iName = iDemandZone.GetTag(); - int iIDX = HasObject( - iName, - mDemandZoneObjects // + int iIDX = HasDemandZoneObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5517,6 +6129,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Demand Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasDemandZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mDemandZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCDemandZoneObject *)mDemandZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Bullish Order Blocks ... */ @@ -5544,9 +6200,8 @@ class XCPOI : public XSCBaseAlert // string iName = iBullishOB.GetTag(); - int iIDX = HasObject( - iName, - mBullishOrderBlockObjects // + int iIDX = HasBullishOrderBlockObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5558,6 +6213,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Bullish Order Block is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBullishOrderBlockObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBullishOrderBlockObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBullishOrderBlockObject *)mBullishOrderBlockObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Bearish Order Blocks ... */ @@ -5585,9 +6284,8 @@ class XCPOI : public XSCBaseAlert // string iName = iBearishOB.GetTag(); - int iIDX = HasObject( - iName, - mBearishOrderBlockObjects // + int iIDX = HasBearishOrderBlockObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5599,6 +6297,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Bearish Order Block is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBearishOrderBlockObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBearishOrderBlockObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBearishOrderBlockObject *)mBearishOrderBlockObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Bullish FVGs ... */ @@ -5626,9 +6368,8 @@ class XCPOI : public XSCBaseAlert // string iName = iFVG.GetTag(); - int iIDX = HasObject( - iName, - mBullishFVGObjects // + int iIDX = HasBullishFVGObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5640,6 +6381,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Bullish FVG is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBullishFVGObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBullishFVGObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBullishFVGObject *)mBullishFVGObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + /** * Draw Bearish FVGs ... */ @@ -5667,9 +6452,8 @@ class XCPOI : public XSCBaseAlert // string iName = iFVG.GetTag(); - int iIDX = HasObject( - iName, - mBearishFVGObjects // + int iIDX = HasBearishFVGObject( + iName // ); if (IsValidIndex(iIDX)) { @@ -5681,6 +6465,50 @@ class XCPOI : public XSCBaseAlert } } + /** + * Check a Bearish FVG is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBearishFVGObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBearishFVGObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBearishFVGObject *)mBearishFVGObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + // /** @@ -7371,6 +8199,7 @@ class XCPOI : public XSCBaseAlert // Trading Days ... // + bool mAllowTradingDays; // Detect Trading Days ... bool mAllowDrawTradingDays; // Draw Trading Days ... color mTradingDaysStartColor; // Trading Days Start Color ... ENUM_LINE_STYLE mTradingDaysStartStyle; // Trading Days Start Style ... @@ -7428,6 +8257,7 @@ class XCPOI : public XSCBaseAlert // Market Sessions ... // + bool mAllowMarketSessions; // Detect Market Sessions ... bool mAllowDrawMarketSessions; // Draw Market Sessions ... int mSessionOpenHours; // How many Hours a Session is Open XSession mSessions[]; // Forex Sessions @@ -7495,6 +8325,7 @@ class XCPOI : public XSCBaseAlert // Swing Highs ... // + bool mAllowSwingHighs; // Detect Swing Highs ... bool mAllowDrawSwingHighs; // Draw Swing Highs ... char mSwingHighArrowCode; // Swing High Arrow Code ... color mSwingHighColor; // Swing High Color ... @@ -7552,6 +8383,7 @@ class XCPOI : public XSCBaseAlert // Swing Lows ... // + bool mAllowSwingLows; // Detect Swing Lows ... bool mAllowDrawSwingLows; // Draw Swing Lows ... char mSwingLowArrowCode; // Swing Low Arrow Code ... color mSwingLowColor; // Swing Low Color ... @@ -7609,6 +8441,7 @@ class XCPOI : public XSCBaseAlert // Momentum Bars ... // + bool mAllowMomentumBars; // Detect Momentum Bars ... bool mAllowDrawMomentumBars; // Draw Momentum Bars ... int mMomentumBarPercent; // Momentum Bar Percent ... double mMomentumBarSharpRatio; // Momentum Bar Sharp Ratio ... @@ -7689,6 +8522,7 @@ class XCPOI : public XSCBaseAlert // Rejection Bars .... // + bool mAllowRejectionBars; // Detect Rejection Bars ... bool mAllowDrawRejectionBars; // Draw Rejection Bars ... int mRejectionBarPercent; // Rejection Bar Percent ... double mRejectionBarSharpRatio; // Rejection Bar Sharp Ratio ... @@ -7772,6 +8606,7 @@ class XCPOI : public XSCBaseAlert // Support Zones ... // + bool mAllowSupportZones; // Detect Support Zone ... bool mAllowDrawSupportZones; // Draw Support Zone ... int mSupportZoneLoopBack; // Support Zone Loopback ... int mSupportZoneWidth; // Support Zone Width ... @@ -7842,6 +8677,7 @@ class XCPOI : public XSCBaseAlert // Resistance Zones ... // + bool mAllowResistanceZones; // Detect Resistance Zone ... bool mAllowDrawResistanceZones; // Draw Resistance Zone ... int mResistanceZoneLoopBack; // Resistance Zone Loopback ... int mResistanceZoneWidth; // Resistance Zone Width ... @@ -7915,6 +8751,7 @@ class XCPOI : public XSCBaseAlert // Supply Zones ... // + bool mAllowSupplyZones; // Detect Supply Zone ... bool mAllowDrawSupplyZones; // Draw Supply Zone ... int mSupplyZoneWidth; // Supply Zone Width ... color mSupplyZoneColor; // Supply Zone Color ... @@ -7972,6 +8809,7 @@ class XCPOI : public XSCBaseAlert // Demand Zones ... // + bool mAllowDemandZones; // Detect Demand Zone ... bool mAllowDrawDemandZones; // Draw Demand Zone ... int mDemandZoneWidth; // Demand Zone Width ... color mDemandZoneColor; // Demand Zone Color ... @@ -8032,6 +8870,7 @@ class XCPOI : public XSCBaseAlert // Bullish Order Blocks ... // + bool mAllowBullishOrderBlocks; // Detect Bullish Order Blocks ... bool mAllowDrawBullishOrderBlocks; // Draw Bullish Order Blocks ... int mBullishOrderBlockWidth; // Bullish Order Block Width ... color mBullishOrderBlockColor; // Bullish Order Block Color ... @@ -8089,6 +8928,7 @@ class XCPOI : public XSCBaseAlert // Bearish Order Blocks ... // + bool mAllowBearishOrderBlocks; // Detect Bearish Order Blocks ... bool mAllowDrawBearishOrderBlocks; // Draw Bearish Order Blocks ... int mBearishOrderBlockWidth; // Bearish Order Block Width ... color mBearishOrderBlockColor; // Bearish Order Block Color ... @@ -8149,6 +8989,7 @@ class XCPOI : public XSCBaseAlert // Bullish Fair Value Gaps ... // + bool mAllowBullishFVGs; // Detect Bullish Fair Value Gaps ... bool mAllowDrawBullishFVGs; // Draw Bullish Fair Value Gaps ... bool mBullishFVGForceMiddleBarCheck; // Bullish FVG Force Middle Bar Check ... bool mBullishFVGForceCheckLastBarDirection; // Bullish FVG Check Last Bar Direction ... @@ -8207,6 +9048,7 @@ class XCPOI : public XSCBaseAlert // Bearish Fair Value Gaps ... // + bool mAllowBearishFVGs; // Detect Bearish Fair Value Gaps ... bool mAllowDrawBearishFVGs; // Draw Bearish Fair Value Gaps ... bool mBearishFVGForceMiddleBarCheck; // Bearish FVG Force Middle Bar Check ... bool mBearishFVGForceCheckLastBarDirection; // Bearish FVG Check Last Bar Direction ... diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index 4e463a5e..6c7685a7 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -30,11 +30,6 @@ #include "../X121SMCEA/Classes/x-121.smc.ea.panel.class.mq5" #include "../X121SMCEA/Strategy/x-121.smc.strategy.class.mq5" -// -// TEST ... -#include "../Classes/x-saherelm.x-poi.class.mq5" -XCPOI *eaPOI; - // // Inputs ... @@ -51,6 +46,12 @@ input group "Symbols"; input bool eaMultiSymbol = false; // Use Multi Symbol input string eaSymbols = "EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb"; // Trading Symbols +// +// Signalling ... +input group "Signalling"; +input bool eaAllowLong = true; // Allow Long Signals +input bool eaAllowShort = true; // Allow Short Signals + // // Alert ... // Here we Provider All Requirements for @@ -83,6 +84,12 @@ XSCXCCHelper *eaCCHelper; // Chart Styler Indicator Helper Class ... X121CAppDialog eaMainWindow; // EA Main Dialog ... XCX121SMCStrategy *eaStrategies[]; // Registere Strategies in EA ... +// +// Signalling Controller Conditions ... +bool eaDisableSignalling; +bool eaAllowLongSignalling; +bool eaAllowShortSignalling; + // // Event Handlers ... @@ -105,6 +112,10 @@ int OnInit() return INIT_FAILED; } + // + // Initial Controller Conditions ... + InitControllerConditions(); + // // Initialize all Requirements ... if (!InitEA()) @@ -171,18 +182,7 @@ void OnTick() UpdateGUI(); HandleReportTime(); UpdatePositionsState(); - - // - // TEST ... - ENUM_XPOI_EVENTS states[]; - int statesCount = eaPOI.Update(states); - if (IsValidSize(statesCount)) - { - eaAlert.Log("POI Events Happens: " + ToString(statesCount)); - } - - // - // TODO: Implemetn Tick Processors Algorithm ... + HandleStrategiesOnTick(); } // @@ -271,7 +271,7 @@ void OnPositionForceClosed( */ void OnSignalRecieved( XSignal &signal, - XStrategyConditions &conditions // + X121SMCStrategyConditions &conditions // ) { // @@ -425,122 +425,96 @@ bool InitEA() eaTrader.AddOnForceClosePositionEventHandler(OnPositionForceClosed); // - // TEST ... - eaPOI = new XCPOI( - _Symbol, - _Period // - ); - eaPOI.EnableDrawPOIs(); - // eaPOI.AllowDrawSwingLows(false); - // eaPOI.AllowDrawSwingHighs(false); - // eaPOI.AllowDrawBullishFVGs(false); - // eaPOI.AllowDrawBearishFVGs(false); - // eaPOI.AllowDrawSupplyZones(false); - // eaPOI.AllowDrawDemandZones(false); - // eaPOI.AllowDrawMomentumBars(false); - // eaPOI.AllowDrawSupportZones(false); - // eaPOI.AllowDrawRejectionBars(false); - // eaPOI.AllowDrawMarketSessions(false); - // eaPOI.AllowDrawResistanceZones(false); - // eaPOI.AllowDrawBullishOrderBlocks(false); - // eaPOI.AllowDrawBearishOrderBlocks(false); + // Symbols Parsing ... // - eaPOI.Init(); + // Parsers ... + XSymbolParser _symbolParser; - // // - // // Symbols Parsing ... + // + // Single Symbol ... + if (!eaMultiSymbol) + { + // + // Register Strategy ... - // // - // // Parsers ... - // XSymbolParser _symbolParser; + // + // Create Class Instance ... + XCX121SMCStrategy *iX121SMCStrategy; + iX121SMCStrategy = new XCX121SMCStrategy( + _Symbol, + _Period // + ); - // // - // // Single Symbol ... - // if (!eaMultiSymbol) - // { + // + ConfigureStrategy(iX121SMCStrategy); + RegisterStrategy(iX121SMCStrategy); + } + // + // Multi Symbol ... + else + { + // + // Parse Symbols ... + string symbols[]; + int symbolsCount = SplitContent( + symbols, + eaSymbols // + ); + result = IsValidSize(symbolsCount); + if (!result) + { + return result; + } - // // - // // Register Strategy ... - // } - // // - // // Multi Symbol ... - // else - // { - // // - // // Parse Symbols ... - // string symbols[]; - // int symbolsCount = SplitContent( - // symbols, - // eaSymbols // - // ); - // result = IsValidSize(symbolsCount); - // if (!result) - // { - // return result; - // } + // + for (int i = 0; i < symbolsCount; i++) + { + // + // Select Symbol ... + string iSymbol = symbols[i]; - // // - // for (int i = 0; i < symbolsCount; i++) - // { - // // - // // Select Symbol ... - // string iSymbol = symbols[i]; + // + // Register Strategy Based On Symbol ... - // // - // // Register Strategy Based On Symbol ... + // + // Parse Symbol ... + bool isEURUSD = _symbolParser.IsEURUSD(_Symbol); + bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol); + bool isEURGBP = _symbolParser.IsEURGBP(_Symbol); + bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol); + bool isEURCHF = _symbolParser.IsEURCHF(_Symbol); + bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol); + bool isEURJPY = _symbolParser.IsEURJPY(_Symbol); + bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol); + bool isEURCAD = _symbolParser.IsEURCAD(_Symbol); + bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol); + bool isEURAUD = _symbolParser.IsEURAUD(_Symbol); + bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol); + bool isEURNZD = _symbolParser.IsEURNZD(_Symbol); - // // - // // Parse Symbol ... - // bool isEURUSD = _symbolParser.IsEURUSD(_Symbol); - // bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol); - // bool isEURGBP = _symbolParser.IsEURGBP(_Symbol); - // bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol); - // bool isEURCHF = _symbolParser.IsEURCHF(_Symbol); - // bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol); - // bool isEURJPY = _symbolParser.IsEURJPY(_Symbol); - // bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol); - // bool isEURCAD = _symbolParser.IsEURCAD(_Symbol); - // bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol); - // bool isEURAUD = _symbolParser.IsEURAUD(_Symbol); - // bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol); - // bool isEURNZD = _symbolParser.IsEURNZD(_Symbol); + // + // Check Symbol Can Register or not ... + bool canRegisterStrategy = true; - // // - // // Check Symbol Can Register or not ... - // bool canRegisterStrategy = true; + // + if (canRegisterStrategy) + { + // + // Create Class Instance ... + XCX121SMCStrategy *iX121SMCStrategy; + iX121SMCStrategy = new XCX121SMCStrategy( + iSymbol, + _Period // + ); - // // - // if (canRegisterStrategy) - // { - // // - // // Create Class Instance ... - // XCX121SMCStrategy *iX121SMCStrategy; - // iX121SMCStrategy = new XCX121SMCStrategy( - // iSymbol, - // _Period // - // ); - - // // - // // Configuere Strategy ... - // // iX121SMCStrategy.DrawImportantAreas(false); - // // iX121SMCStrategy.AddXSignalEventHandler(OnSignalRecieved); - - // // // - // // // Configure Alerts ... - // // iX121SMCStrategy.SetAlertPrefix(eaLogTag); - // // iX121SMCStrategy.SetAlertEnableAlerts(eAEnableAlerts); - // // iX121SMCStrategy.SetAlertLogAlerts(eALogAlerts); - // // iX121SMCStrategy.SetAlertMailAlerts(eAMailAlerts); - // // iX121SMCStrategy.SetAlertPushAlerts(eAPushAlerts); - // // iX121SMCStrategy.SetAlertTerminalAlerts(eATerminalAlerts); - - // // - // // Register Strategy ... - // RegisterStrategy(iX121SMCStrategy); - // } - // } - // } + // + // Register Strategy ... + ConfigureStrategy(iX121SMCStrategy); + RegisterStrategy(iX121SMCStrategy); + } + } + } // return result; @@ -557,10 +531,6 @@ void DestroyEA() // delete eaAlert; - - // - // TEST ... - delete eaPOI; } /** @@ -724,8 +694,63 @@ void HandleReportTime() } } +/** + * Initial EA Controller Conditions ... + */ +void InitControllerConditions() +{ + // + // Signalling Conditions ... + eaAllowLongSignalling = eaAllowLong; + eaAllowShortSignalling = eaAllowShort; + + // + eaDisableSignalling = !eaAllowLongSignalling && + !eaAllowShortSignalling; +} + // +/** + * Configure Startegy ... + */ +void ConfigureStrategy(XCX121SMCStrategy *&strategy) +{ + // + if (strategy == NULL) + { + return; + } + + // + // Configure Alerts ... + strategy.SetAlertPrefix(eaLogTag); + strategy.SetAlertLogAlerts(eALogAlerts); + strategy.SetAlertMailAlerts(eAMailAlerts); + strategy.SetAlertPushAlerts(eAPushAlerts); + strategy.SetAlertEnableAlerts(eAEnableAlerts); + strategy.SetAlertTerminalAlerts(eATerminalAlerts); + + // + // Confiugre Signalling ... + + // + strategy.AllowLong(eaAllowLongSignalling); + strategy.AllowShort(eaAllowShortSignalling); + + // + if (eaDisableSignalling) + { + strategy.Disable(); + } + else + { + strategy.Enable(); + } + + // +} + /** * Register an Strategy in EA ... * @@ -749,4 +774,45 @@ void RegisterStrategy(XCX121SMCStrategy *strategy) eaStrategies[ArraySize(eaStrategies) - 1] = strategy; } +/** + * Re Configure All Registered Strategies ... + */ +void ReConfigureAllStrategies() +{ + // + int count = ArraySize(eaStrategies); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + ConfigureStrategy(eaStrategies[i]); + } +} + +/** + * Call all Registered Strategies On Tick ... + */ +void HandleStrategiesOnTick() +{ + // + int count = ArraySize(eaStrategies); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + // Call Tick Handler Function ... + eaStrategies[i].HandleTick(); + } +} + // diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 6be854f3..e47ba42d 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -437,8 +437,7 @@ struct XZone string result = NULL; // - result = prefix + - "_XZone_" + + result = prefix + "_" + ToString(upper) + "_" + ToString(lower); @@ -474,6 +473,655 @@ typedef void (*TXZoneEventHandler)( XZone &zone // ); +// +// Model Exists Founded POIs ... +struct XPOIState +{ + // + string symbol; + ENUM_TIMEFRAMES period; + datetime reportedAt; + + // + XTradeDay tradingDays[]; + XMarketSession marketSessions[]; + + // + XOHCL momentumBars[]; + XOHCL rejectionBars[]; + + // + XOHCL swingHighs[]; + XOHCL swingLows[]; + + // + XOHCL supportZones[]; + XOHCL resistanceZones[]; + + // + XZone supplyZones[]; + XZone demandZones[]; + + // + XZone bullishOrderBlocks[]; + XZone bearishOrderBlocks[]; + + // + XZone bullishFVGs[]; + XZone bearishFVGs[]; + + // + // Constructor ... + void XPOIState() + { + Clean(); + } + + // + // Actions ... + + /** + * Cleanup all props ... + */ + void Clean() + { + // + symbol = NULL; + period = NULL; + reportedAt = NULL; + + // + Clean(tradingDays); + Clean(marketSessions); + + // + Clean(momentumBars); + Clean(rejectionBars); + + // + Clean(swingHighs); + Clean(swingLows); + + // + Clean(supportZones); + Clean(resistanceZones); + + // + Clean(supplyZones); + Clean(demandZones); + + // + Clean(bullishOrderBlocks); + Clean(bearishOrderBlocks); + + // + Clean(bullishFVGs); + Clean(bearishFVGs); + } + + /** + * Fill Trading Days ... + * + * @param source: XTradeDay instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillTradingDays( + XTradeDay &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(tradingDays); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + tradingDays // + ); + result = ArraySize(tradingDays); + + // + return result; + } + + /** + * Fill Market Sessions ... + * + * @param source: XMarketSession instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillMarketSessions( + XMarketSession &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(marketSessions); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + marketSessions // + ); + result = ArraySize(marketSessions); + + // + return result; + } + + /** + * Fill Momentum Bars ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillMomentumBars( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(momentumBars); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + momentumBars // + ); + result = ArraySize(momentumBars); + + // + return result; + } + + /** + * Fill Retection Bars ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillRejectionBars( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(rejectionBars); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + rejectionBars // + ); + result = ArraySize(rejectionBars); + + // + return result; + } + + /** + * Fill Swing Highs ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSwingHighs( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(swingHighs); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + swingHighs // + ); + result = ArraySize(swingHighs); + + // + return result; + } + + /** + * Fill Swing Lows ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSwingLows( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(swingLows); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + swingLows // + ); + result = ArraySize(swingLows); + + // + return result; + } + + /** + * Fill Support Zones ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSupportZones( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(supportZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + supportZones // + ); + result = ArraySize(supportZones); + + // + return result; + } + + /** + * Fill Resistance Zones ... + * + * @param source: XOHCL instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillResistanceZones( + XOHCL &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(resistanceZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + resistanceZones // + ); + result = ArraySize(resistanceZones); + + // + return result; + } + + /** + * Fill Supply Zones ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillSupplyZones( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(supplyZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + supplyZones // + ); + result = ArraySize(supplyZones); + + // + return result; + } + + /** + * Fill Demand Zones ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillDemandZones( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(demandZones); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + demandZones // + ); + result = ArraySize(demandZones); + + // + return result; + } + + /** + * Fill Bullish Order Blockss ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBullishOrderBlocks( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bullishOrderBlocks); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bullishOrderBlocks // + ); + result = ArraySize(bullishOrderBlocks); + + // + return result; + } + + /** + * Fill Bearish Order Blockss ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBearishOrderBlocks( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bearishOrderBlocks); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bearishOrderBlocks // + ); + result = ArraySize(bearishOrderBlocks); + + // + return result; + } + + /** + * Fill Bullish FVGs ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBullishFVGs( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bullishFVGs); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bullishFVGs // + ); + result = ArraySize(bullishFVGs); + + // + return result; + } + + /** + * Fill Bearish FVGs ... + * + * @param source: XZone instance Collection ... + * @param forceClean: Boolean ... + * + * @return ( int ) + */ + int FillBearishFVGs( + XZone &source[], + bool forceClean = true // + ) + { + // + int result = 0; + + // + if (forceClean) + { + Clean(bearishFVGs); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + Copy( + source, + bearishFVGs // + ); + result = ArraySize(bearishFVGs); + + // + return result; + } + + // +}; + // // Extensions ... @@ -611,3 +1259,103 @@ string ToString(ENUM_XSESSION value) // return result; } + +/** + * Generate General Event Messages ... + * + * @param value: ENUM_XPOI_EVENTS member ... + * + * @return ( string ) + */ +string ToString(ENUM_XPOI_EVENTS value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_TRADE_DAY_FIRST_BAR: + result = "First Bar of Day"; + break; + + // + case X_TRADE_DAY_LAST_BAR: + result = "Last Bar of Day"; + break; + + // + case X_SESSION_FIRST_BAR: + result = "First Bar of Session"; + break; + + // + case X_SESSION_LAST_BAR: + result = "Last Bar of Session"; + break; + + // + case X_MOMENTUM_BAR_DETECTED: + result = "Momentum Bar Detected"; + break; + + // + case X_REJECTION_BAR_DETECTED: + result = "Rejection Bar Detected"; + break; + + // + case X_SWING_HIGH_DETECTED: + result = "Swing High Detected"; + break; + + // + case X_SWING_LOW_DETECTED: + result = "Swing Low Detected"; + break; + + // + case X_SUPPORT_ZONE_DETECTED: + result = "Support Zone Detected"; + break; + + // + case X_RESISTANCE_ZONE_DETECTED: + result = "Resistance Zone Detected"; + break; + + // + case X_SUPPLY_ZONE_DETECTED: + result = "Supply Zone Detected"; + break; + + // + case X_DEMAND_ZONE_DETECTED: + result = "Demand Zone Detected"; + break; + + // + case X_BULLISH_ORDERBLOCK_DETECTED: + result = "Bullish Order Block Detected"; + break; + + // + case X_BEARISH_ORDERBLOCK_DETECTED: + result = "Bearish Orer Block Detected"; + break; + + // + case X_BULLISH_FVG_DETECTED: + result = "Bullish FVG Detected"; + break; + + // + case X_BEARISH_FVG_DETECTED: + result = "Bearish FVg Detected"; + break; + } + + // + return result; +} \ No newline at end of file diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 new file mode 100644 index 00000000..bb951e1a --- /dev/null +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -0,0 +1,195 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Seriallize Library +// --------------------------------------- +// Name: X121SMCLib +// Description: All models related to X121SMC ... +// +// +// 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.base.class.mq5" +#include "../../Libraries/x-saherelm.common.lib.mq5" +#include "../../Libraries/x-saherelm.x-poi.lib.mq5" +#include "../../Libraries/x-saherelm.xtrade.lib.mq5" + +// +// Definitions ... + +// +// Specific Identifier(s) of XStrategy ... +string X121SMCStrategyToken = "X121SMC"; + +// +// Condition Structure ... +struct X121SMCStrategyConditions +{ + // + // Props ... + + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Helper Conditions ... + + // + // Constructor ... + void XStrategyConditions() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + period = NULL; + time = NULL; + + // + // Clean Helpers Conditions ... + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(time) && + IsValid(symbol) && + IsValid(period) + // + ; + + // + return result; + } + + // + // Generate Provided Scores ... + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (!IsValid()) + { + return; + } + + // + double bullScore = 0; + double bearScore = 0; + + // + // Generate Helpers Conitions Scores ... + } + + // + // Generate Summary ... + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores, + true // + ); + + // + // Generate Helpers Conditions Strings ... + + // + // Combine Helpers Conditions Strings ... + string conditionsStr = + // + "" + separator + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + "----------" + separator + + (onlyConditions + ? "" + : commonStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return X121SMCStrategyToken; + } + + // +}; + +// +// On Signal Event Handler ... +typedef void (*TOnX121SMCSignal)( + XSignal &signal, + X121SMCStrategyConditions &conditions // +); diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index c4109261..bc0c56c4 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -23,209 +23,14 @@ // Imports ... // +#include "../../Classes/x-saherelm.x-poi.class.mq5" #include "../../Classes/x-saherelm.xalert.class.mq5" #include "../../Classes/x-saherelm.xtrade.class.mq5" +#include "../Libraries/x-121.smc.lib.mq5" // // Helper(s) ... -// -// Definitions ... - -// -// Specific Identifier(s) of XStrategy ... -string X121SMCStrategyToken = "X121SMC"; - -// -// Condition Structure ... -struct XStrategyConditions -{ - // - // Props ... - - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Important Ares attached ... - - // - XOHCL support; - XOHCL resistance; - XOHCL bullishOB; - XOHCL bearishOB; - - // - double bullishFVGUpper; - double bullishFVGLower; - XOHCL bullishFVG; - - // - double bearishFVGUpper; - double bearishFVGLower; - XOHCL bearishFVG; - - // - XOHCL bullishTrendSwingHighs[]; - XOHCL bullishTrendSwingLows[]; - XOHCL bullishTrend; - - // - XOHCL bearishTrendSwingHighs[]; - XOHCL bearishTrendSwingLows[]; - XOHCL bearishTrend; - - // - // Helper Conditions ... - - // - // Constructor ... - void XStrategyConditions() - { - Clean(); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - symbol = NULL; - period = NULL; - time = NULL; - - // - // Clean Helpers Conditions ... - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(time) && - IsValid(symbol) && - IsValid(period) - // - ; - - // - return result; - } - - // - // Generate Provided Scores ... - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - if (!IsValid()) - { - return; - } - - // - double bullScore = 0; - double bearScore = 0; - - // - // Generate Helpers Conitions Scores ... - } - - // - // Generate Summary ... - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores, - true // - ); - - // - // Generate Helpers Conditions Strings ... - - // - // Combine Helpers Conditions Strings ... - string conditionsStr = - // - "" + separator + - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - "----------" + separator + - (onlyConditions - ? "" - : commonStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - // - string GetTag() - { - return X121SMCStrategyToken; - } - - // -}; - -// -// On Signal Event Handler ... -typedef void (*TOnXSignal)( - XSignal &signal, - XStrategyConditions &conditions // -); - // // XStrategy Class Implementation(s) ... class XCX121SMCStrategy : public XSCBaseAlert @@ -233,6 +38,8 @@ class XCX121SMCStrategy : public XSCBaseAlert // // Public ... public: + // + // // Constructor(s) ... void XCX121SMCStrategy( @@ -243,16 +50,18 @@ class XCX121SMCStrategy : public XSCBaseAlert ) { // - SetAlertPrefix(GetTag()); + mSymbol = _symbol; + mPeriod = _period; // - PrepareRequirements(); + Init(); } // // Deconstructor ... void ~XCX121SMCStrategy() { + DeInit(); } // @@ -406,7 +215,7 @@ class XCX121SMCStrategy : public XSCBaseAlert * * @param handler: an Instance of TOnXSignal ... */ - void AddXSignalEventHandler(TOnXSignal handler) + void AddXSignalEventHandler(TOnX121SMCSignal handler) { // Add( @@ -464,7 +273,7 @@ class XCX121SMCStrategy : public XSCBaseAlert // // Check Current Processing Tick has Signal or not ... XSignal signal; - XStrategyConditions conditions; + X121SMCStrategyConditions conditions; bool hasSignal = HasSignal( signal, conditions // @@ -490,7 +299,7 @@ class XCX121SMCStrategy : public XSCBaseAlert // Check Conditions For Signal ... virtual bool HasSignal( XSignal &signal, - XStrategyConditions &conditions // + X121SMCStrategyConditions &conditions // ) { // @@ -515,9 +324,6 @@ class XCX121SMCStrategy : public XSCBaseAlert bool hasLong = false; bool hasShort = false; - // - // Retrieve Helper Conditions ... - // // Start Calculations ... @@ -533,6 +339,19 @@ class XCX121SMCStrategy : public XSCBaseAlert // // Retrieve Bars ... + // + // Zero Bar ... + XOHCL zBar; + result = zBar.Init( + mSymbol, + mPeriod, + zIndex // + ); + if (!result) + { + return result; + } + // // Last Bar ... XOHCL cBar; @@ -554,125 +373,10 @@ class XCX121SMCStrategy : public XSCBaseAlert conditions.period = mPeriod; conditions.time = cBar.time; - // - // Attach Helpers Conditins ... - - // - result = conditions.IsValid(); - if (!result) - { - return result; - } - - // - // Previous Bar of Last Bar ... - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Last Swing Low Bar ... - XOHCL lastSwingLow; - result = cBar.FindLastSwingLow(lastSwingLow); - if (!result) - { - return result; - } - - // - // Last Swing High Bar ... - XOHCL lastSwingHigh; - result = cBar.FindLastSwingHigh(lastSwingHigh); - if (!result) - { - return result; - } - // int pushers = 0; string signallers[]; - // - // Retrieve all Helpers Based Configurations Here ... - - // - // Common Conditions For Bullish and Bearish Powers ... - - // - // For Trend ... - XOHCL tmpHSW[]; - XOHCL tmpLSW[]; - - // - // Detect Bullish/Bearish Patterns and Trends ... - - // - // Bullish ... - bool hasBullishPower = cBar.HasBullishPower(); - bool hasBullishPattern = HasBullishPattern(cBar); - bool hasBullishPressure = cBar.HasBullishPressure(); - bool isBullishTrend = cBar.HasBullishTrend( - tmpHSW, - tmpLSW, - true // - ); - bool isBullishTrend1 = cBar.HasBullishTrend( - tmpHSW, - tmpLSW, - false // - ); - bool hasBullishTrend = - // - isBullishTrend - // - || - // - isBullishTrend1 - // - ; - - // - // Bearish ... - bool hasBearishPower = cBar.HasBearishPower(); - bool hasBearishPattern = HasBearishPattern(cBar); - bool hasBearishPressure = cBar.HasBearishPressure(); - bool isBearishTrend = cBar.HasBearishTrend( - tmpHSW, - tmpLSW, - true // - ); - bool isBearishTrend1 = cBar.HasBearishTrend( - tmpHSW, - tmpLSW, - false // - ); - bool hasBearishTrend = - // - isBearishTrend - // - || - // - isBearishTrend1 - // - ; - - // - bool hasBearishDecision = - // - cBar.IsBearishDecision() - // - ; - - // - bool hasBullishDecision = - // - cBar.IsBullishDecision() - // - ; - // // Define Conditions ... MqlTick ticks[]; @@ -729,35 +433,90 @@ class XCX121SMCStrategy : public XSCBaseAlert } // - // TODO: Complete this ... - bool notHaveBearishPower = false; + // Reading POI(s) ... // - // TODO: Complete this ... - bool notHaveBullishPower = false; + // 4H ... + XPOIState _4HState; + m4HPOI.GetState(_4HState); // - // Detecting Signals ... + // 15M ... + XPOIState _15MState; + m15MPOI.GetState(_15MState); // - bool hasBaseLongConditions = - cBar.IsBullish() && - hasBullishTrend && - (hasBullishPower || - hasBullishPattern || - hasBullishPressure) && - notHaveBearishPower && - isTicksBullishForLong; + // 5M ... + XPOIState _5MState; + m5MPOI.GetState(_5MState); // - bool hasBaseShortConditions = - cBar.IsBearish() && - hasBearishTrend && - (hasBearishPower || - hasBearishPattern || - hasBearishPressure) && - notHaveBullishPower && - isTicksBullishForShort; + // Try to Implement SMC Based Conditions ... + + // + // 1- First Step is Find a Supply and Demand Zone ... + // - [] this Zone must be Fresh ... + // - [] contains Engulfing ... + // - [] has Order Block ... + // - [] has FVG ... + XZone _4hSupplyZone; + XZone _4HDemandZone; + DetectSupplyAndDemandZones( + _4HState, + _4hSupplyZone, + _4HDemandZone // + ); + + // + if (_4hSupplyZone.IsValid()) + { + // + // Update Supply Zone Time ... + string iName = _4hSupplyZone.GetTag(); + _4hSupplyZone.to = zBar.time; + + // + int count = mDrawnObjects.Total(); + if (IsValidSize(count)) + { + // + int idx = -1; + for (int i = 0; i < count; i++) + { + // + int type = ((CChartObject *)mDrawnObjects.At(i)).Type(); + if (type == (int)X_SUPPLY_ZONE) + { + // + string objName = ((XCZoneObject *)mDrawnObjects.At(i)).ObjName(); + if (objName == iName) + { + // + idx = i; + break; + } + } + } + + // + if (IsValidIndex(idx)) + { + mDrawnObjects.Delete(idx); + } + } + + // + iName = _4hSupplyZone.GetTag(); + XCZoneObject *iObj; + bool isCreated = iObj.CreateByZone( + ChartID(), + iName, + 0, + _4hSupplyZone, + NULL, + true // + ); + } // // LONGS ... @@ -765,9 +524,6 @@ class XCX121SMCStrategy : public XSCBaseAlert // bool hasLong1 = // - hasBaseLongConditions && - // - // TODO: Implement Long Conditions ... false // ; @@ -793,8 +549,6 @@ class XCX121SMCStrategy : public XSCBaseAlert // bool hasShort1 = - // - hasBaseShortConditions && // // TODO: Implement Long Conditions ... false @@ -844,16 +598,9 @@ class XCX121SMCStrategy : public XSCBaseAlert result = hasLong || hasShort; if (!result) { - // - CheckImportantAreasValidation(); - - // return result; } - // - DestroyImportantAreas(); - // // Retrieve Entry Price based on Position Type ... entry = GetEntry(mSymbol, type); @@ -925,10 +672,9 @@ class XCX121SMCStrategy : public XSCBaseAlert // Protected ... protected: // - // Props ... // - // Helpers Inputs and Classes Instance ... + // Props ... // // Private ... @@ -949,9 +695,109 @@ class XCX121SMCStrategy : public XSCBaseAlert MqlTick mLastTick; // Last Issued Tick ... XBarTracker mBarTracker; // Strategy Time Tracker ... + // + // Point Of Interests ... + XCPOI *m4HPOI; + XCPOI *m15MPOI; + XCPOI *m5MPOI; + + // + // Collect all Drawn Objects ... + CArrayObj mDrawnObjects; + // // Actions ... + /** + * Install all Helpers and Prepare all Configurations for required Indicators ... + */ + void Init() + { + // + mForceDisabled = false; + + // + string symbol = Symbol(); + ENUM_TIMEFRAMES period = Period(); + + // + // Initialize Bar Tracker ... + mBarTracker.Init( + symbol, + period // + ); + + // + // Initialize POIs ... + + // + // 4H Period ... + m4HPOI = new XCPOI( + symbol, + PERIOD_H4 // + ); + + // + m4HPOI.Window(0); + m4HPOI.DisableDrawPOIs(); + m4HPOI.ChartID(ChartID()); + m4HPOI.MaxNumberOfRequiredPOIs(0); + m4HPOI.SupplyZonePeriod(PERIOD_H4); + m4HPOI.DemandZonePeriod(PERIOD_H4); + + // + m4HPOI.Init(); + + // + // 15M Period ... + m15MPOI = new XCPOI( + symbol, + PERIOD_M15 // + ); + + // + m15MPOI.Window(0); + m15MPOI.DisableDrawPOIs(); + m15MPOI.ChartID(ChartID()); + m15MPOI.MaxNumberOfRequiredPOIs(2); + m15MPOI.SupplyZonePeriod(PERIOD_M15); + m15MPOI.DemandZonePeriod(PERIOD_M15); + + // + m15MPOI.Init(); + + // + // Trigger Period ... + m5MPOI = new XCPOI( + symbol, + period // + ); + + // + m5MPOI.Window(0); + m5MPOI.DisableDrawPOIs(); + m5MPOI.ChartID(ChartID()); + m5MPOI.MaxNumberOfRequiredPOIs(2); + m5MPOI.SupplyZonePeriod(PERIOD_M5); + m5MPOI.DemandZonePeriod(PERIOD_M5); + + // + m5MPOI.Init(); + + // + } + + /** + * De Initialize all Tools ... + */ + void DeInit() + { + // + delete m4HPOI; + delete m5MPOI; + delete m15MPOI; + } + /** * Reste Bar Tracker ... */ @@ -998,9 +844,102 @@ class XCX121SMCStrategy : public XSCBaseAlert return result; } + /** + * Detect Supply and Demand Zones ... + * + * @param state: Argument 1 + * @param supplyZone: Argument 2 + * @param demandZone: Argument 3 + */ + void DetectSupplyAndDemandZones( + XPOIState &state, + XZone &supplyZone, + XZone &demandZone // + ) + { + // + supplyZone.Clean(); + demandZone.Clean(); + + // + int supplyZonesCount = ArraySize(state.supplyZones); + int demandZonesCount = ArraySize(state.demandZones); + if (!IsValidSize(supplyZonesCount) && + !IsValidSize(demandZonesCount)) + { + return; + } + + // + XOHCL zBar; + bool isInited = zBar.Init( + Symbol(), + Period(), + 0 // + ); + if (!isInited) + { + return; + } + + // + // Detect Supply Zone ... + for (int i = 0; i < supplyZonesCount; i++) + { + // + XZone iZone = state.supplyZones[i]; + + // + // Retrieve Zone From Index Based On Current Period ... + int iZoneStartBarIndex = iBarShift( + Symbol(), + Period(), + iZone.from // + ); + + // + // Check Zone is Fresh Or Not ... + bool isFreshZone = true; + for (int j = iZoneStartBarIndex - 1; j >= 0; j++) + { + // + XOHCL jBar; + bool isInited = jBar.Init( + Symbol(), + Period(), + j // + ); + if (!isInited) + { + continue; + } + + // + if (jBar.high > iZone.lower) + { + // + isFreshZone = false; + break; + } + + // + } + + // + if (!isFreshZone) + { + continue; + } + + // + supplyZone = iZone; + break; + } + } + // // On X121 Signal Recieved Event Handler(s) ... - TOnXSignal mSignalEventHandlers[]; + TOnX121SMCSignal mSignalEventHandlers[]; // /** @@ -1011,7 +950,7 @@ class XCX121SMCStrategy : public XSCBaseAlert */ void NotifyOnSignalEventHandlers( XSignal &signal, - XStrategyConditions &conditions // + X121SMCStrategyConditions &conditions // ) { // @@ -1038,764 +977,6 @@ class XCX121SMCStrategy : public XSCBaseAlert } } - /** - * Install all Helpers and Prepare all Configurations for required Indicators ... - */ - void PrepareRequirements() - { - // - mForceDisabled = false; - - // - support.Clean(); - supportTime = NULL; - isSupportTested = false; - - // - resistance.Clean(); - resistanceTime = NULL; - isResistanceTested = false; - - // - // Initialize Bar Tracker ... - // - // Initial Time Tracker ... - mBarTracker.Init( - mSymbol, - mPeriod // - ); - - // - SetAlertPrefix(GetTag()); - - // - // Prepare Default Inputs and Configure Indicator Helpers here ... - - // - } - - // - void FillConditionsImportantAreas(XStrategyConditions &conditions) - { - // - if (!conditions.IsValid()) - { - return; - } - - // - conditions.support = support; - conditions.resistance = resistance; - conditions.bullishOB = bullishOB; - conditions.bearishOB = bearishOB; - conditions.bullishFVG = bullishFVG; - conditions.bearishFVG = bearishFVG; - conditions.bullishTrend = bullishTrend; - conditions.bearishTrend = bearishTrend; - - // - conditions.bullishFVGUpper = bullishFVGUpper; - conditions.bullishFVGLower = bullishFVGLower; - conditions.bearishFVGUpper = bearishFVGUpper; - conditions.bearishFVGLower = bearishFVGLower; - - // - Copy( - bullishTrendSwingHighs, - conditions.bullishTrendSwingHighs, - true // - ); - - // - Copy( - bullishTrendSwingLows, - conditions.bullishTrendSwingLows, - true // - ); - - // - Copy( - bearishTrendSwingHighs, - conditions.bearishTrendSwingHighs, - true // - ); - - // - Copy( - bearishTrendSwingLows, - conditions.bearishTrendSwingLows, - true // - ); - } - - // - // Important Areas ... - - // - bool mDrawImportantAreas; // Draw Important ... - - // - XOHCL support; - XOHCL resistance; - XOHCL bullishOB; - XOHCL bearishOB; - - // - double bullishFVGUpper; - double bullishFVGLower; - XOHCL bullishFVG; - - // - double bearishFVGUpper; - double bearishFVGLower; - XOHCL bearishFVG; - - // - XOHCL bullishTrendSwingHighs[]; - XOHCL bullishTrendSwingLows[]; - XOHCL bullishTrend; - - // - XOHCL bearishTrendSwingHighs[]; - XOHCL bearishTrendSwingLows[]; - XOHCL bearishTrend; - - // - void DetectImportantAreas() - { - // // - // int zIndex = 0; - // int cIndex = zIndex + 1; - - // // - // // Last Bar ... - // XOHCL cBar; - // bool result = cBar.Init( - // mSymbol, - // mPeriod, - // cIndex // - // ); - // if (!result) - // { - // return; - // } - - // // - // // Analyzing Bar ... - // XOHCL aBar; - // if (IsValid(mAnalizePeriod)) - // { - // // - // result = aBar.Init( - // mSymbol, - // mAnalizePeriod, - // cIndex // - // ); - - // // - // if (!result) - // { - // return; - // } - // } - // else - // { - // aBar = cBar; - // } - - // // - // // Support nad Resistance ... - - // // - // // Check Support Exists or Find ... - // bool hasSupport = support.IsValid(); - // if (!hasSupport) - // { - // // - // hasSupport = - // // - // aBar.HasSupport(support) - // // - // ; - - // // - // if (hasSupport) - // { - // // - // if (mDrawImportantAreas) - // { - // // - // DrawSupport( - // support, - // ChartID() // - // ); - // } - - // // - // supportTime = aBar.time; - // } - // } - - // // - // // Check Resistance Exists or Find ... - // bool hasResistance = resistance.IsValid(); - // if (!hasResistance) - // { - // // - // hasResistance = - // // - // aBar.HasResistance(resistance) - // // - // ; - - // // - // if (hasResistance) - // { - // // - // if (mDrawImportantAreas) - // { - // // - // DrawResistance( - // resistance, - // ChartID() // - // ); - // } - - // // - // resistanceTime = aBar.time; - // } - // } - - // // - // // Order Blocks ... - - // // - // bool hasBullishOB = bullishOB.IsValid(); - // if (!hasBullishOB) - // { - // // - // hasBullishOB = - // // - // aBar.HasBullishOrderBlock(bullishOB) - // // - // ; - - // // - // if (hasBullishOB) - // { - // // - // if (mDrawImportantAreas) - // { - // // - // DrawBullishOrderBlock( - // bullishOB, - // ChartID() // - // ); - // } - - // // - // bullishOBTime = aBar.time; - // } - // } - - // // - // bool hasBearishOB = bearishOB.IsValid(); - // if (!hasBearishOB) - // { - // // - // hasBearishOB = - // // - // aBar.HasBearishOrderBlock(bearishOB) - // // - // ; - - // // - // if (hasBearishOB) - // { - // // - // if (mDrawImportantAreas) - // { - // // - // DrawBearishOrderBlock( - // bearishOB, - // ChartID() // - // ); - // } - - // // - // bearishOBTime = aBar.time; - // } - // } - - // // - // // FVG ... - - // // - // bool hasBullishFVG = bullishFVG.IsValid(); - // if (!hasBullishFVG) - // { - // // - // hasBullishFVG = - // // - // aBar.HasBullishFVG( - // bullishFVGUpper, - // bullishFVGLower // - // ) - // // - // ; - - // // - // if (hasBullishFVG) - // { - // // - // bullishFVG = aBar; - - // // - // if (mDrawImportantAreas) - // { - // // - // DrawBullishFVG( - // bullishFVG, - // bullishFVGUpper, - // bullishFVGLower, - // ChartID() // - // ); - // } - - // // - // bullishFVGTime = aBar.time; - // } - // } - - // // - // bool hasBearishFVG = bearishFVG.IsValid(); - // if (!hasBearishFVG) - // { - // // - // hasBearishFVG = - // // - // aBar.HasBearishFVG( - // bearishFVGUpper, - // bearishFVGLower // - // ) - // // - // ; - - // // - // if (hasBearishFVG) - // { - // // - // bearishFVG = aBar; - - // // - // if (mDrawImportantAreas) - // { - // // - // DrawBearishFVG( - // bearishFVG, - // bearishFVGUpper, - // bearishFVGLower, - // ChartID() // - // ); - // } - - // // - // bearishFVGTime = aBar.time; - // } - // } - - // // - // // TREND ... - - // // - // bool hasBullishTrend = bullishTrend.IsValid(); - // if (!hasBullishTrend) - // { - // // - // hasBullishTrend = aBar.HasBullishTrend( - // bullishTrendSwingHighs, - // bullishTrendSwingLows, - // false // - // ); - - // // - // if (hasBullishTrend) - // { - // // - // bullishTrend = aBar; - - // // - // if (mDrawImportantAreas) - // { - // // - // DrawBullishTrend( - // bullishTrend, - // bullishTrendSwingHighs, - // bullishTrendSwingLows, - // ChartID() // - // ); - // } - // } - // } - - // // - // bool hasBearishTrend = bearishTrend.IsValid(); - // if (!hasBearishTrend) - // { - // // - // hasBearishTrend = aBar.HasBearishTrend( - // bearishTrendSwingHighs, - // bearishTrendSwingLows, - // false // - // ); - - // // - // if (hasBearishTrend) - // { - // // - // bearishTrend = aBar; - - // // - // if (mDrawImportantAreas) - // { - // // - // DrawBearishTrend( - // bearishTrend, - // bearishTrendSwingHighs, - // bearishTrendSwingLows, - // ChartID() // - // ); - // } - // } - // } - - // - } - - // - void DestroyImportantAreas() - { - // - bool hasSupport = support.IsValid(); - if (hasSupport) - { - // - supportTime = NULL; - isSupportTested = false; - RemoveSupport(support); - support.Clean(); - } - - // - bool hasResistance = resistance.IsValid(); - if (hasResistance) - { - // - resistanceTime = NULL; - isResistanceTested = false; - RemoveResistance(resistance); - resistance.Clean(); - } - - // - bool hasBullishOB = bullishOB.IsValid(); - if (hasBullishOB) - { - // - bullishOBTime = NULL; - RemoveBullishOrderBlock(bullishOB); - bullishOB.Clean(); - } - - // - bool hasBearishOB = bearishOB.IsValid(); - if (hasBearishOB) - { - // - bearishOBTime = NULL; - RemoveBearishOrderBlock(bearishOB); - bearishOB.Clean(); - } - - // - bool hasBullishFVG = bullishFVG.IsValid(); - if (hasBullishFVG) - { - // - bullishFVGUpper = 0; - bullishFVGLower = 0; - bullishFVGTime = NULL; - RemoveBullishFVG(bullishFVG); - bullishFVG.Clean(); - } - - // - bool hasBearishFVG = bearishFVG.IsValid(); - if (hasBearishFVG) - { - // - bearishFVGUpper = 0; - bearishFVGLower = 0; - bearishFVGTime = NULL; - RemoveBullishFVG(bearishFVG); - bearishFVG.Clean(); - } - - // - bool hasBullishTrend = bullishTrend.IsValid(); - if (hasBullishTrend) - { - // - RemoveBullishTrend(bullishTrend); - bullishTrend.Clean(); - } - - // - bool hasBearishTrend = bearishTrend.IsValid(); - if (hasBearishTrend) - { - // - RemoveBearishTrend(bearishTrend); - bearishTrend.Clean(); - } - } - - // - void CheckImportantAreasValidation() - { - // - CheckSupportValidation(); - CheckResistanceValidation(); - - // - CheckBullishOBValidation(); - CheckBearishOBValidation(); - - // - CheckBullishFVGValidation(); - CheckBearishFVgValidation(); - - // - CheckBullishTrendValidation(); - CheckBearishTrendValidation(); - } - - // - bool isSupportTested; - datetime supportTime; - void CheckSupportValidation() - { - // - if (!isSupportTested) - { - // - if (support.IsValid() && IsValid(supportTime)) - { - // - int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(supportTime))) / PeriodSeconds(mPeriod)); - if (age >= 50) - { - // - isSupportTested = false; - supportTime = NULL; - RemoveSupport(support); - support.Clean(); - } - } - return; - } - - // - XOHCL cBar; - bool isInited = cBar.Init( - mSymbol, - mPeriod, - 1 // - ); - if (!isInited) - { - return; - } - - // - double points = GetPoints(mSymbol); - - // - // Find Price Distance ... - double highDiff = MathAbs(cBar.high - support.high); - double lowDiff = MathAbs(cBar.low - support.high); - - // - bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points; - if (!isBreaked) - { - return; - } - - // - isSupportTested = false; - RemoveSupport(support); - supportTime = NULL; - support.Clean(); - } - - // - bool isResistanceTested; - datetime resistanceTime; - void CheckResistanceValidation() - { - // - if (!isResistanceTested) - { - // - if (resistance.IsValid() && IsValid(resistanceTime)) - { - // - int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(resistanceTime))) / PeriodSeconds(mPeriod)); - if (age >= 50) - { - // - isResistanceTested = false; - resistanceTime = NULL; - RemoveResistance(resistance); - resistance.Clean(); - } - } - return; - } - - // - XOHCL cBar; - bool isInited = cBar.Init( - mSymbol, - mPeriod, - 1 // - ); - if (!isInited) - { - return; - } - - // - double points = GetPoints(mSymbol); - - // - // Find Price Distance ... - double highDiff = MathAbs(cBar.high - resistance.low); - double lowDiff = MathAbs(cBar.low - resistance.low); - - // - bool isBreaked = MathMax(highDiff, lowDiff) >= 100 * points; - if (!isBreaked) - { - return; - } - - // - isResistanceTested = false; - RemoveResistance(resistance); - resistanceTime = NULL; - resistance.Clean(); - } - - // - datetime bullishOBTime; - void CheckBullishOBValidation() - { - // - if (!IsValid(bullishOBTime)) - { - return; - } - - // - int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishOBTime))) / PeriodSeconds(mPeriod)); - if (age >= 50) - { - // - bullishOBTime = NULL; - RemoveBullishOrderBlock(bullishOB); - bullishOB.Clean(); - } - } - - // - datetime bearishOBTime; - void CheckBearishOBValidation() - { - // - if (!IsValid(bearishOBTime)) - { - return; - } - - // - int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishOBTime))) / PeriodSeconds(mPeriod)); - if (age >= 50) - { - // - bearishOBTime = NULL; - RemoveBearishOrderBlock(bearishOB); - bearishOB.Clean(); - } - } - - // - datetime bullishFVGTime; - void CheckBullishFVGValidation() - { - // - if (!IsValid(bullishFVGTime)) - { - return; - } - - // - int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bullishFVGTime))) / PeriodSeconds(mPeriod)); - if (age >= 50) - { - // - bullishFVGTime = NULL; - RemoveBullishFVG(bullishFVG); - bullishFVG.Clean(); - } - } - - // - datetime bearishFVGTime; - void CheckBearishFVgValidation() - { - // - if (!IsValid(bearishFVGTime)) - { - return; - } - - // - int age = (int)(((int)(TimeToSeconds(TimeCurrent()) - TimeToSeconds(bearishFVGTime))) / PeriodSeconds(mPeriod)); - if (age >= 50) - { - // - bearishFVGTime = NULL; - RemoveBearishFVG(bearishFVG); - bearishFVG.Clean(); - } - } - - // - void CheckBullishTrendValidation() - { - // - // TODO: Complete this ... - } - - // - void CheckBearishTrendValidation() - { - // - // TODO: Complete this ... - } - // };