diff --git a/Documents/BKP/1/x-121.smc.xhkpv.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xhkpv.signal.lib.mq5 new file mode 100644 index 00000000..a1263eeb --- /dev/null +++ b/Documents/BKP/1/x-121.smc.xhkpv.signal.lib.mq5 @@ -0,0 +1,1856 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: X +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXHKPVSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double target; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + + // + XBoxZone priceBox; + datetime priceOBAt; + bool isPriceOBActed; + bool isPriceOBBreaked; + XCOrderBlock *priceOB; + X121SMCCycleState state; + + // + // Constructor ... + X121SMCStrategyXHKPVSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + target = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + + // + ZeroMemory(this); + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped() + { + // + bool result = false; + + // + result = IsValid(setupTime) && + HasDirection(dir); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Calculate Setup Age ... + * + * @return ( int ) + */ + int GetSetupAge() + { + // + int result = 0; + + // + if (!IsSetuped()) + { + return result; + } + + // + result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); + + // + return result; + } + + /** + * Detect How we Can Trigger Signal ... + * + * @return ( bool ) + */ + bool CanTrigger() + { + // + bool result = false; + + // + result = + // + sl > 0 && + IsValid(symbol) && + IsValid(period) && + IsValid(triggerTime) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + + // + return result; + } + + // + // Extensions ... + + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + // + pivot = 0; + point = 0; + + // + state.Clean(); + priceOB = NULL; + priceBox.Clean(); + priceOBAt = NULL; + isPriceOBActed = false; + isPriceOBBreaked = false; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXHKPVSignalConditions mXHKPVConditions; +X121SMCStrategyXHKPVSignalConditions mXHKPVConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXHKPVSignalSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXHKPVSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int resetAfterUnActedZoneInMinutes = 120 + // +) +{ + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XC121SMCCycleHelper *barCycle = triggerCycleHelper; + + // + XOHCL zBar; + result = barCycle.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = barCycle.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = barCycle.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 7; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double ll50 = cBar.FindLowest(50, MODE_LOW); + double hh50 = cBar.FindHighest(50, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Consolidation ... + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Detect Cycle State ... + + // + double upper = 0; + double lower = 0; + bool hasYoungestOB = false; + bool isPriceOBValid = false; + bool isBullishHappens = false; + bool isBearishHappens = false; + XCOrderBlock *youngestOB = NULL; + bool hasPriceBox = conditions.priceBox.IsValid(); + bool hasState = visionCycleHelper.GetCycleState(conditions.state); + + // + // Detect Price Box if not Provided ... + if (hasState && + !hasPriceBox) + { + // + hasPriceBox = DetectPriceInsideBox( + conditions.priceBox, + conditions.priceOB, + decisionXConditions, + conditions.state // + ); + if (hasPriceBox) + { + conditions.priceOBAt = cTime; + } + } + + // + if (hasPriceBox) + { + // + // Update Price Box Date ... + conditions.priceOB.To(cTime); + conditions.priceBox.to = cTime; + upper = conditions.priceOB.Upper(); + lower = conditions.priceOB.Lower(); + + // + hasYoungestOB = conditions.state.GetYoungestOB(youngestOB); + + // + // Here We Can Validate Box by Same Cycles Peaks and Vales ... + bool isBullish = IsBullish(conditions.priceBox.dir); + + // + bool isPriceBoxSameAsOB = + // + conditions.priceBox.upper <= conditions.priceOB.Upper() && + conditions.priceBox.lower >= conditions.priceOB.Lower() + // + ; + + // + int cIDX = 1; + + // + bool isSameCyclePeaks = + // + triggerXConditions.peaksBuffer[cIDX] == decisionXConditions.peaksBuffer[cIDX] && + decisionXConditions.peaksBuffer[cIDX] == analyseXConditions.peaksBuffer[cIDX] && + analyseXConditions.peaksBuffer[cIDX] == verificationXConditions.peaksBuffer[cIDX] + // + ; + + // + bool isSameCycleVales = + // + triggerXConditions.valesBuffer[cIDX] == decisionXConditions.valesBuffer[cIDX] && + decisionXConditions.valesBuffer[cIDX] == analyseXConditions.valesBuffer[cIDX] && + analyseXConditions.valesBuffer[cIDX] == verificationXConditions.valesBuffer[cIDX] + // + ; + + // + // Check Validation Conditions ... + isPriceOBValid = + // + hasPriceBox && + isPriceBoxSameAsOB && + (isBullish + ? isSameCycleVales + : isSameCyclePeaks) + // + ; + + // + // Check Conditions ... + + // + X121Conditions xConditions = triggerXConditions; + + // + isBullishHappens = + // + isPriceOBValid && + isCBarBullishFormed && + conditions.priceOB.IsBullish() && + IsBullish(conditions.priceBox.dir) && + // + (xConditions.isBreakedUpPrevSar || + xConditions.isBreakedUpPrevStr || + xConditions.isVWapMaxBreakedUp || + xConditions.isBreakedUpPrevCheMax || + xConditions.isBreakedUpPrevAtrLower) && + // + (xConditions.isSarSwitchedToBullish || + xConditions.isStrSwitchedToBullish || + xConditions.isCheSwitchedToBullish || + xConditions.isVWapSwitchedToBullishState || + xConditions.isVWapSwitchedToBullishOrdered) + // + ; + + // + isBearishHappens = + // + isPriceOBValid && + isCBarBearishFormed && + conditions.priceOB.IsBearish() && + IsBearish(conditions.priceBox.dir) && + // + (xConditions.isBreakedDownPrevSar || + xConditions.isBreakedDownPrevStr || + xConditions.isVWapMinBreakedDown || + xConditions.isBreakedDownPrevCheMin || + xConditions.isBreakedDownPrevAtrUpper) && + // + (xConditions.isSarSwitchedToBearish || + xConditions.isStrSwitchedToBearish || + xConditions.isCheSwitchedToBearish || + xConditions.isVWapSwitchedToBearishState || + xConditions.isVWapSwitchedToBearishOrdered) + // + ; + + // + if (!conditions.isPriceOBActed) + { + conditions.isPriceOBActed = isBullishHappens || + isBearishHappens; + } + } + + // + // Detect Accumulation ... + if (conditions.isPriceOBActed) + { + // + // Checking OB Breake on Side ... + if (!conditions.isPriceOBBreaked) + { + // + conditions.isPriceOBBreaked = + (conditions.priceOB.IsBullish() && + IsBullish(conditions.priceBox.dir)) + ? (cBar.low < upper && + cBar.high > upper && + cBar.close > upper) + // + || + // + (pBar.high < upper && + cBar.low > upper && + cBar.open > upper) + : (cBar.high > lower && + cBar.low < lower && + cBar.close < lower) + // + || + // + (pBar.low > lower && + cBar.high < lower && + cBar.open < lower); + } + } + + // + // Detect Distribution ... + bool isPriceOBUpperBrekedUp = false; + bool isPriceOBLowerBrekedDown = false; + if (conditions.isPriceOBBreaked) + { + // + isPriceOBUpperBrekedUp = IsBarBreak( + upper, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPriceOBLowerBrekedDown = IsBarBreak( + lower, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // // + // // Draw ... + // XCBaseObject *drawnObjects[]; + // int drawnObjectsCount = visionCycleHelper.DrawCycleState( + // conditions.state, + // drawnObjects // + // ); + + // // + // if (hasPriceBox) + // { + // // + // bool isBullish = IsBullish(conditions.priceBox.dir); + // color boxColor = isBullish ? clrYellow : clrOrange; + + // // + // XCBoxObject *iObj; + // bool isCreated = visionCycleHelper.mPOIDrawer.CreateBox( + // conditions.priceBox, + // iObj, + // boxColor, + // 1, + // false, + // STYLE_DASHDOTDOT // + // ); + + // // + // if (isCreated) + // { + // // + // Add( + // (XCBaseObject *)iObj, + // drawnObjects // + // ); + // } + + // // + // XCBaseObject *priceOBObj = NULL; + // if (isBullish) + // { + // // + // XCBullishOrderBlockObject *iObj; + // isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBullishOrderBlock( + // conditions.priceOB, + // iObj // + // ); + + // // + // if (isCreated) + // { + // // + // iObj.ZoneWidth(2); + // iObj.ZoneColor(boxColor); + // iObj.ZoneStyle(STYLE_SOLID); + + // // + // priceOBObj = (XCBaseObject *)iObj; + // } + // } + // else + // { + // // + // XCBearishOrderBlockObject *iObj; + // isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBearishOrderBlock( + // conditions.priceOB, + // iObj // + // ); + + // // + // if (isCreated) + // { + // // + // iObj.ZoneWidth(2); + // iObj.ZoneColor(boxColor); + // iObj.ZoneStyle(STYLE_SOLID); + + // // + // priceOBObj = (XCBaseObject *)iObj; + // } + // } + + // // + // if (isCreated) + // { + // // + // Add( + // priceOBObj, + // drawnObjects // + // ); + // } + // } + + // + // + // + + // + // Check Verifications Conditions ... + + // + // XHK ... + bool isXHKBullish = false; + bool isXHKBearish = false; + + // + // XSAR ... + bool isXSarBullish = false; + bool isXSarBearish = false; + + // + // XATR ... + bool isXAtrBullish = false; + bool isXAtrBearish = false; + + // + // XSTR ... + bool isXStrBullish = false; + bool isXStrBearish = false; + + // + // XVWAP ... + bool isXVWapBullish = false; + bool isXVWapBearish = false; + + // + // XCHE ... + bool isXCheBullish = false; + bool isXCheBearish = false; + + // + if (hasPriceBox) + { + // + // XHK ... + + // + isXHKBullish = + // + // Trigger ... + triggerXConditions.isSMHKBullish && + triggerXConditions.isRawHKBullish && + triggerXConditions.isClosedOverSMHK && + triggerXConditions.isClosedOverRawHK && + (triggerXConditions.isBreakedUpSMHK || + triggerXConditions.isBreakedUpRawHK) && + triggerXConditions.isRawHKClosedOverSMHK && + // + // Decision ... + decisionXConditions.isSMHKBullish && + decisionXConditions.isRawHKBullish && + decisionXConditions.isClosedOverSMHK && + decisionXConditions.isClosedOverRawHK && + (decisionXConditions.isBreakedUpSMHK || + decisionXConditions.isBreakedUpRawHK) && + decisionXConditions.isRawHKClosedOverSMHK && + // + // Analyse ... + analyseXConditions.isSMHKBullish && + analyseXConditions.isRawHKBullish && + analyseXConditions.isClosedOverSMHK && + analyseXConditions.isClosedOverRawHK && + (analyseXConditions.isBreakedUpSMHK || + analyseXConditions.isBreakedUpRawHK) && + decisionXConditions.isRawHKClosedOverSMHK + // + ; + + // + isXHKBearish = + // + // Trigger ... + triggerXConditions.isSMHKBearish && + triggerXConditions.isRawHKBearish && + triggerXConditions.isClosedUnderSMHK && + triggerXConditions.isClosedUnderRawHK && + (triggerXConditions.isBreakedDownSMHK || + triggerXConditions.isBreakedDownRawHK) && + triggerXConditions.isRawHKClosedUnderSMHK && + // + // Decision ... + decisionXConditions.isSMHKBearish && + decisionXConditions.isRawHKBearish && + decisionXConditions.isClosedUnderSMHK && + decisionXConditions.isClosedUnderRawHK && + (decisionXConditions.isBreakedDownSMHK || + decisionXConditions.isBreakedDownRawHK) && + decisionXConditions.isRawHKClosedUnderSMHK && + // + // Analyse ... + analyseXConditions.isSMHKBearish && + analyseXConditions.isRawHKBearish && + analyseXConditions.isClosedUnderSMHK && + analyseXConditions.isClosedUnderRawHK && + (analyseXConditions.isBreakedDownSMHK || + analyseXConditions.isBreakedDownRawHK) && + analyseXConditions.isRawHKClosedUnderSMHK + // + ; + + // + // XSAR ... + + // + isXSarBullish = + // + // Trigger ... + triggerXConditions.isSarBullish && + triggerXConditions.isSarIncreased && + // + // Decision ... + decisionXConditions.isSarBullish && + decisionXConditions.isSarIncreased && + // + // Analyse ... + analyseXConditions.isSarBullish && + analyseXConditions.isSarIncreased + // + ; + + // + isXSarBearish = + // + // Trigger ... + triggerXConditions.isSarBearish && + triggerXConditions.isSarDecreased && + // + // Decision ... + decisionXConditions.isSarBearish && + decisionXConditions.isSarDecreased && + // + // Analyse ... + analyseXConditions.isSarBearish // && + // + ; + + // + // XATR ... + + // + isXAtrBullish = + // + // Trigger ... + triggerXConditions.isClosedOverAtrUpper && + // + // Decision ... + decisionXConditions.isClosedOverAtrUpper + // + // Analyse ... + // + ; + + // + isXAtrBearish = + // + // Trigger ... + triggerXConditions.isClosedUnderAtrLower && + // + // Decision ... + decisionXConditions.isClosedUnderAtrLower + // + // Analyse ... + // + ; + + // + // XSTR ... + + // + isXStrBullish = + // + // Trigger ... + triggerXConditions.isStrBullish && + // + // Decision ... + decisionXConditions.isStrBullish + // + // Analyse ... + // + ; + + // + isXStrBearish = + // + // Trigger ... + triggerXConditions.isStrBearish && + // + // Decision ... + decisionXConditions.isStrBearish + // + // Analyse ... + // + ; + + // + // XVWAP ... + + // + isXVWapBullish = + // + // Trigger ... + triggerXConditions.isVWapBullishState && + triggerXConditions.isVWapBullishOrdered && + // + // Decision ... + decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapBullishOrdered && + // + // Analyse ... + analyseXConditions.isVWapBullishState && + analyseXConditions.isVWapBullishOrdered + // + ; + + // + isXVWapBearish = + // + // Trigger ... + triggerXConditions.isVWapBearishState && + triggerXConditions.isVWapBearishOrdered && + // + // Decision ... + decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapBearishOrdered && + // + // Analyse ... + analyseXConditions.isVWapBearishState && + analyseXConditions.isVWapBearishOrdered + // + ; + + // + // XCHE ... + + // + isXCheBullish = + // + // Trigger ... + triggerXConditions.isCheBullish && + // + // Decision ... + decisionXConditions.isCheBullish && + // + // Analyse ... + analyseXConditions.isCheBullish + // + ; + + // + isXCheBearish = + // + // Trigger ... + triggerXConditions.isCheBearish && + // + // Decision ... + decisionXConditions.isCheBearish && + // + // Analyse ... + analyseXConditions.isCheBearish + // + ; + } + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + isPriceOBUpperBrekedUp && + conditions.isPriceOBBreaked && + conditions.priceOB.IsBearish() && + // + // XHK ... + isXHKBullish && + // + // XSAR ... + isXSarBullish && + // + // XATR ... + isXAtrBullish && + // + // XSTR ... + isXStrBullish && + // + // XVWAP ... + isXVWapBullish && + // + // XCHE ... + isXCheBullish && + // + true + // + ; + + // + bool isCondition1Bearish = + // + isPriceOBLowerBrekedDown && + conditions.isPriceOBBreaked && + conditions.priceOB.IsBullish() && + // + // XHK ... + isXHKBearish && + // + // XSAR ... + isXSarBearish && + // + // XATR ... + isXAtrBearish && + // + // XSTR ... + isXStrBearish && + // + // XVWAP ... + isXVWapBearish && + // + // XCHE ... + isXCheBearish && + // + true + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + double longPivot = lower; // triggerXConditions.valesBuffer[1]; + double shortPivot = upper; // triggerXConditions.peaksBuffer[1]; + + // + // Manipulate Conditions Point ... + + // + conditions.point = + isCondition1Bullish + ? shortPivot + : longPivot; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? longPivot + : shortPivot; + } + + // + // + // + + // + isBullish = + // + isCondition1Bullish + // + ; + + // + isBearish = + // + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Detect PriceOB Lifetime Bars ... + if (hasPriceBox) + { + // + int obLifetimeBars = (int)(cTime - conditions.priceOBAt) / PeriodSeconds(PERIOD_M1); + bool canReset = + // + !conditions.isPriceOBActed && + obLifetimeBars >= resetAfterUnActedZoneInMinutes + // + ; + if (canReset) + { + conditions.Clean(); + } + } + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXHKPVSignalTrigger( + // + X121SMCStrategyXHKPVSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 // + // +) +{ + // + bool result = false; + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + bool isBullish = IsBullish(setupDir); + bool isBearish = IsBearish(setupDir); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + XOHCL zBar; + result = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 9; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = IsBarBreak( + point, + setupDir, + cBar // + ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + isPointBreaked && + isSlopesBullish + // + ; + + // + isBearish = + // + isBearish && + isPointBreaked && + isSlopesBearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + double sls[]; + Add( + conditions.pivot, + sls // + ); + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 1.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + + // + // Filling Conditions Props ... + conditions.sl = sl; + // conditions.target = target; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; +} + +// +// Detect Guards ... +bool DetectX121SMCXHKPVGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + true, // CloseOnTPNear Guard ... + true, // CloseLongsOnBearishTrend Guard ... + true, // CloseShortsOnBullishTrend Guard ... + true, // CloseAllWeekend Guard ... + true, // PartialCloseOnTrendChange Guard ... + true, // TrailStop Guard ... + true, // TrailTarget Guard ... + true // Hedge Guard ... + // + ); + + // + return result; +} + +// +// Add Conditions to Conditions Collection ... +int AddX121SMCXHKPVConditionsIfNotExists( + X121SMCStrategyXHKPVSignalConditions &item, + X121SMCStrategyXHKPVSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXHKPVSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXHKPVSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// diff --git a/Documents/BKP/1/x-121.smc.xobs.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xobs.signal.lib.mq5 new file mode 100644 index 00000000..a091b8b9 --- /dev/null +++ b/Documents/BKP/1/x-121.smc.xobs.signal.lib.mq5 @@ -0,0 +1,1422 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XOBS +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXOBSSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double target; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + + // + // Extwnsion ... + + // + datetime vOBAt; + XCOrderBlock *vOB; + bool isVOBActivated; + + // + datetime cOBAt; + XCOrderBlock *cOB; + + // + // Constructor ... + X121SMCStrategyXOBSSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + target = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + + // + ZeroMemory(this); + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped() + { + // + bool result = false; + + // + result = IsValid(setupTime) && + HasDirection(dir); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Calculate Setup Age ... + * + * @return ( int ) + */ + int GetSetupAge() + { + // + int result = 0; + + // + if (!IsSetuped()) + { + return result; + } + + // + result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); + + // + return result; + } + + /** + * Detect How we Can Trigger Signal ... + * + * @return ( bool ) + */ + bool CanTrigger() + { + // + bool result = false; + + // + result = + // + sl > 0 && + IsValid(symbol) && + IsValid(period) && + IsValid(triggerTime) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + + // + return result; + } + + // + // Extensions ... + + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + // + pivot = 0; + point = 0; + + // + vOB = NULL; + cOB = NULL; + + // + vOBAt = NULL; + cOBAt = NULL; + + // + isVOBActivated = false; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXOBSSignalConditions mXOBSConditions; +X121SMCStrategyXOBSSignalConditions mXOBSConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXOBSSignalSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXOBSSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int resetAfterUnActedZoneInMinutes = 120 + // +) +{ + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XC121SMCCycleHelper *barCycle = triggerCycleHelper; + + // + XOHCL zBar; + result = barCycle.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = barCycle.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = barCycle.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 7; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double ll50 = cBar.FindLowest(50, MODE_LOW); + double hh50 = cBar.FindHighest(50, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Vision ... + ENUM_X_DIRECTION visionTrendDir; + bool hasVisionTrend = + visionCycleHelper + .DetectMarketStructure( + visionTrendDir // + ); + bool hasVisionBullishTrend = + hasVisionTrend && + IsBullish(visionTrendDir); + bool hasVisionBearishTrend = + hasVisionTrend && + IsBearish(visionTrendDir); + + // + // Consolidation ... + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Detect OrderBlocks ... + + // + bool hasVOB = + conditions.vOB != NULL && + conditions.vOB.IsValid() && + IsValid(conditions.vOBAt); + + // + bool hasCOB = + conditions.cOB != NULL && + conditions.cOB.IsValid() && + IsValid(conditions.cOBAt); + + // + if (!hasVOB) + { + // + int poiEvntsCount = ArraySize(visionPoiEvents); + bool hasEvent = IsValidSize(poiEvntsCount); + if (hasEvent) + { + // + bool hasNewBullOB = Contains( + X_BULLISH_ORDERBLOCK_DETECTED, + visionPoiEvents // + ); + + // + bool hasNewBearOB = Contains( + X_BEARISH_ORDERBLOCK_DETECTED, + visionPoiEvents // + ); + + // + bool hasNewOB = + hasNewBullOB || + hasNewBearOB; + + // + if (hasNewOB) + { + // + if (hasNewBullOB) + { + // + int lastIDX = visionState.CountBullishOrderBlocks() - 1; + conditions.vOB = visionState.bullishOrderBlocks[lastIDX]; + } + else if (hasNewBearOB) + { + // + int lastIDX = visionState.CountBearishOrderBlocks() - 1; + conditions.vOB = visionState.bearishOrderBlocks[lastIDX]; + } + + // + conditions.vOBAt = cTime; + + // + hasVOB = + conditions.vOB != NULL && + conditions.vOB.IsValid() && + IsValid(conditions.vOBAt); + } + } + else + { + // + X121SMCCycleState vState; + bool hasVState = visionCycleHelper.GetCycleState(vState); + + // + bool hasYoungestOB = vState.GetYoungestOB(conditions.vOB); + if (hasYoungestOB) + { + // + conditions.vOBAt = cTime; + + // + hasVOB = + conditions.vOB != NULL && + conditions.vOB.IsValid() && + IsValid(conditions.vOBAt); + } + } + } + + // + // Update To Time ... + if (hasVOB) + { + // + conditions.vOB.To(cTime); + } + + // + // Vait for Order Block Activation ... + if (hasVOB && + !conditions.isVOBActivated) + { + // + conditions.isVOBActivated = + // + cBar.low >= conditions.vOB.Lower() && + cBar.high <= conditions.vOB.Upper() && + // + bid >= conditions.vOB.Lower() && + bid <= conditions.vOB.Upper() + // + ; + } + + // + // Check Result ... + result = hasVOB && + conditions.isVOBActivated; + if (!result) + { + return result; + } + + // + // Check Market Trend ... + bool isTrendOveralBullish = hasVisionBullishTrend && + hasConsolidationBullishTrend; + bool isTrendOveralBearish = hasVisionBearishTrend && + hasConsolidationBearishTrend; + result = (isTrendOveralBullish && + !isTrendOveralBearish) || + (!isTrendOveralBullish && + isTrendOveralBearish); + if (!result) + { + return result; + } + + // + bool isBullishOB = conditions.vOB.IsBullish(); + if (isBullishOB) + { + // + XCBullishOrderBlockObject *iObj; + bool isCreated = visionCycleHelper + .mPOIDrawer + .CreateBullishOrderBlock( + conditions.vOB, + iObj // + ); + } + else + { + // + XCBearishOrderBlockObject *iObj; + bool isCreated = visionCycleHelper + .mPOIDrawer + .CreateBearishOrderBlock( + conditions.vOB, + iObj // + ); + } + + // + double upper = 0; + double lower = 0; + + // + // + // + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + false + // + ; + + // + bool isCondition1Bearish = + // + false + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + double longPivot = lower; // triggerXConditions.valesBuffer[1]; + double shortPivot = upper; // triggerXConditions.peaksBuffer[1]; + + // + // Manipulate Conditions Point ... + + // + conditions.point = + isCondition1Bullish + ? shortPivot + : longPivot; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? longPivot + : shortPivot; + } + + // + // + // + + // + isBullish = + // + isCondition1Bullish + // + ; + + // + isBearish = + // + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Detect PriceOB Lifetime Bars ... + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + Clean(triggerPoiEvents); + Clean(triggerCycleEvents); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + Clean(verificationPoiEvents); + Clean(verificationCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXOBSSignalTrigger( + // + X121SMCStrategyXOBSSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 // + // +) +{ + // + bool result = false; + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + bool isBullish = IsBullish(setupDir); + bool isBearish = IsBearish(setupDir); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + XOHCL zBar; + result = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 9; + double ll = cBar.FindLowest(swingLoopback, MODE_LOW); + double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); + double llDown = cBar.FindLowesttDown(swingLoopback); + double hhUp = cBar.FindHighestUp(swingLoopback); + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = IsBarBreak( + point, + setupDir, + cBar // + ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + isPointBreaked && + isSlopesBullish + // + ; + + // + isBearish = + // + isBearish && + isPointBreaked && + isSlopesBearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + double sls[]; + Add( + conditions.pivot, + sls // + ); + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 1.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + + // + // Filling Conditions Props ... + conditions.sl = sl; + // conditions.target = target; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + // Cleanup Arrays ... + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + return result; +} + +// +// Detect Guards ... +bool DetectX121SMCXOBSGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + true, // CloseOnTPNear Guard ... + true, // CloseLongsOnBearishTrend Guard ... + true, // CloseShortsOnBullishTrend Guard ... + true, // CloseAllWeekend Guard ... + true, // PartialCloseOnTrendChange Guard ... + true, // TrailStop Guard ... + true, // TrailTarget Guard ... + true // Hedge Guard ... + // + ); + + // + return result; +} + +// +// Add Conditions to Conditions Collection ... +int AddX121SMCXOBSConditionsIfNotExists( + X121SMCStrategyXOBSSignalConditions &item, + X121SMCStrategyXOBSSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXOBSSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXOBSSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// diff --git a/Documents/BKP/bos-choch.mq5 b/Documents/BKP/bos-choch.mq5 new file mode 100644 index 00000000..77463c18 --- /dev/null +++ b/Documents/BKP/bos-choch.mq5 @@ -0,0 +1,111 @@ +//+------------------------------------------------------------------+ +//| BOS_CHOCH.mq5| +//| Copyright 2023, MetaQuotes Software Corp. | +//| https://www.mql5.com | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2023, MetaQuotes Software Corp." +#property link "https://www.mql5.com" +#property version "1.00" +#property indicator_chart_window +#property indicator_buffers 2 +#property indicator_plots 2 +#property indicator_color1 clrGreen +#property indicator_color2 clrRed +#property indicator_width1 2 +#property indicator_width2 2 + +// Indicator Buffers +double BOSBuffer[]; +double CHOCHBuffer[]; + +// Input parameters +input int lookbackPeriod = 50; // Number of candles to look back for structure analysis + +//+------------------------------------------------------------------+ +//| Custom indicator initialization function | +//+------------------------------------------------------------------+ +int OnInit() +{ + // Set up indicator buffers + SetIndexBuffer(0, BOSBuffer, INDICATOR_DATA); + SetIndexBuffer(1, CHOCHBuffer, INDICATOR_DATA); + + // Set up indicator labels + IndicatorSetString(INDICATOR_SHORTNAME, "BOS & CHOCH Detector"); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + + return(INIT_SUCCEEDED); +} + +//+------------------------------------------------------------------+ +//| Custom indicator iteration function | +//+------------------------------------------------------------------+ +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) +{ + // Loop through all candles + for (int i = prev_calculated; i < rates_total; i++) + { + // Detect BOS (Break of Structure) + if (IsBOS(i, high, low, lookbackPeriod)) + { + BOSBuffer[i] = high[i]; // Mark BOS on the chart + } + else + { + BOSBuffer[i] = EMPTY_VALUE; + } + + // Detect CHOCH (Change of Character) + if (IsCHOCH(i, high, low, lookbackPeriod)) + { + CHOCHBuffer[i] = low[i]; // Mark CHOCH on the chart + } + else + { + CHOCHBuffer[i] = EMPTY_VALUE; + } + } + + return(rates_total); +} + +//+------------------------------------------------------------------+ +//| Function to detect Break of Structure (BOS) | +//+------------------------------------------------------------------+ +bool IsBOS(int index, const double &high[], const double &low[], int lookback) +{ + // Check if the current high is higher than the previous highs + for (int i = 1; i <= lookback; i++) + { + if (index - i >= 0 && high[index] <= high[index - i]) + { + return false; + } + } + return true; +} + +//+------------------------------------------------------------------+ +//| Function to detect Change of Character (CHOCH) | +//+------------------------------------------------------------------+ +bool IsCHOCH(int index, const double &high[], const double &low[], int lookback) +{ + // Check if the current low is lower than the previous lows + for (int i = 1; i <= lookback; i++) + { + if (index - i >= 0 && low[index] >= low[index - i]) + { + return false; + } + } + return true; +} \ No newline at end of file diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index 55934472..666405e5 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -855,6 +855,90 @@ class XC121SMCCycleHelper : public XCBase return result; } + /** + * Count Prev Peak Repetition ... + * + * @param barIndex: Integer ... + * + * @return ( int ) + */ + int CountPrevPeakRepetition( + int barIndex = 0// + ) { + // + int result = 0; + + // + if (barIndex < 0) { + barIndex = 0; + } + + // + int index = barIndex + 1; + double value = mX121Helper.xpvHelper.GetPeak(index); + index++; + + // + bool canContinue = true; + while(canContinue) { + // + double iValue = mX121Helper.xpvHelper.GetPeak(index); + + // + canContinue = iValue == value; + if (canContinue) { + // + index++; + result++; + } + } + + // + return result; + } + + /** + * Count Prev Vale Repetition ... + * + * @param barIndex: Integer ... + * + * @return ( int ) + */ + int CountPrevValeRepetition( + int barIndex = 0// + ) { + // + int result = 0; + + // + if (barIndex < 0) { + barIndex = 0; + } + + // + int index = barIndex + 1; + double value = mX121Helper.xpvHelper.GetVale(index); + index++; + + // + bool canContinue = true; + while(canContinue) { + // + double iValue = mX121Helper.xpvHelper.GetVale(index); + + // + canContinue = iValue == value; + if (canContinue) { + // + index++; + result++; + } + } + + // + return result; + } + /** * Get Cycle State and Update it ... * diff --git a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 index a1263eeb..b25edd4a 100644 --- a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 @@ -704,631 +704,19 @@ bool DetectX121SMCXHKPVSignalSetup( ; // - // Detect Cycle State ... - - // - double upper = 0; - double lower = 0; - bool hasYoungestOB = false; - bool isPriceOBValid = false; - bool isBullishHappens = false; - bool isBearishHappens = false; - XCOrderBlock *youngestOB = NULL; - bool hasPriceBox = conditions.priceBox.IsValid(); - bool hasState = visionCycleHelper.GetCycleState(conditions.state); - - // - // Detect Price Box if not Provided ... - if (hasState && - !hasPriceBox) - { - // - hasPriceBox = DetectPriceInsideBox( - conditions.priceBox, - conditions.priceOB, - decisionXConditions, - conditions.state // - ); - if (hasPriceBox) - { - conditions.priceOBAt = cTime; - } - } - - // - if (hasPriceBox) - { - // - // Update Price Box Date ... - conditions.priceOB.To(cTime); - conditions.priceBox.to = cTime; - upper = conditions.priceOB.Upper(); - lower = conditions.priceOB.Lower(); - - // - hasYoungestOB = conditions.state.GetYoungestOB(youngestOB); - - // - // Here We Can Validate Box by Same Cycles Peaks and Vales ... - bool isBullish = IsBullish(conditions.priceBox.dir); - - // - bool isPriceBoxSameAsOB = - // - conditions.priceBox.upper <= conditions.priceOB.Upper() && - conditions.priceBox.lower >= conditions.priceOB.Lower() - // - ; - - // - int cIDX = 1; - - // - bool isSameCyclePeaks = - // - triggerXConditions.peaksBuffer[cIDX] == decisionXConditions.peaksBuffer[cIDX] && - decisionXConditions.peaksBuffer[cIDX] == analyseXConditions.peaksBuffer[cIDX] && - analyseXConditions.peaksBuffer[cIDX] == verificationXConditions.peaksBuffer[cIDX] - // - ; - - // - bool isSameCycleVales = - // - triggerXConditions.valesBuffer[cIDX] == decisionXConditions.valesBuffer[cIDX] && - decisionXConditions.valesBuffer[cIDX] == analyseXConditions.valesBuffer[cIDX] && - analyseXConditions.valesBuffer[cIDX] == verificationXConditions.valesBuffer[cIDX] - // - ; - - // - // Check Validation Conditions ... - isPriceOBValid = - // - hasPriceBox && - isPriceBoxSameAsOB && - (isBullish - ? isSameCycleVales - : isSameCyclePeaks) - // - ; - - // - // Check Conditions ... - - // - X121Conditions xConditions = triggerXConditions; - - // - isBullishHappens = - // - isPriceOBValid && - isCBarBullishFormed && - conditions.priceOB.IsBullish() && - IsBullish(conditions.priceBox.dir) && - // - (xConditions.isBreakedUpPrevSar || - xConditions.isBreakedUpPrevStr || - xConditions.isVWapMaxBreakedUp || - xConditions.isBreakedUpPrevCheMax || - xConditions.isBreakedUpPrevAtrLower) && - // - (xConditions.isSarSwitchedToBullish || - xConditions.isStrSwitchedToBullish || - xConditions.isCheSwitchedToBullish || - xConditions.isVWapSwitchedToBullishState || - xConditions.isVWapSwitchedToBullishOrdered) - // - ; - - // - isBearishHappens = - // - isPriceOBValid && - isCBarBearishFormed && - conditions.priceOB.IsBearish() && - IsBearish(conditions.priceBox.dir) && - // - (xConditions.isBreakedDownPrevSar || - xConditions.isBreakedDownPrevStr || - xConditions.isVWapMinBreakedDown || - xConditions.isBreakedDownPrevCheMin || - xConditions.isBreakedDownPrevAtrUpper) && - // - (xConditions.isSarSwitchedToBearish || - xConditions.isStrSwitchedToBearish || - xConditions.isCheSwitchedToBearish || - xConditions.isVWapSwitchedToBearishState || - xConditions.isVWapSwitchedToBearishOrdered) - // - ; - - // - if (!conditions.isPriceOBActed) - { - conditions.isPriceOBActed = isBullishHappens || - isBearishHappens; - } - } - - // - // Detect Accumulation ... - if (conditions.isPriceOBActed) - { - // - // Checking OB Breake on Side ... - if (!conditions.isPriceOBBreaked) - { - // - conditions.isPriceOBBreaked = - (conditions.priceOB.IsBullish() && - IsBullish(conditions.priceBox.dir)) - ? (cBar.low < upper && - cBar.high > upper && - cBar.close > upper) - // - || - // - (pBar.high < upper && - cBar.low > upper && - cBar.open > upper) - : (cBar.high > lower && - cBar.low < lower && - cBar.close < lower) - // - || - // - (pBar.low > lower && - cBar.high < lower && - cBar.open < lower); - } - } - - // - // Detect Distribution ... - bool isPriceOBUpperBrekedUp = false; - bool isPriceOBLowerBrekedDown = false; - if (conditions.isPriceOBBreaked) - { - // - isPriceOBUpperBrekedUp = IsBarBreak( - upper, - X_DIRECTION_BULLISH, - cBar // - ); - - // - isPriceOBLowerBrekedDown = IsBarBreak( - lower, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // // - // // Draw ... - // XCBaseObject *drawnObjects[]; - // int drawnObjectsCount = visionCycleHelper.DrawCycleState( - // conditions.state, - // drawnObjects // - // ); - - // // - // if (hasPriceBox) - // { - // // - // bool isBullish = IsBullish(conditions.priceBox.dir); - // color boxColor = isBullish ? clrYellow : clrOrange; - - // // - // XCBoxObject *iObj; - // bool isCreated = visionCycleHelper.mPOIDrawer.CreateBox( - // conditions.priceBox, - // iObj, - // boxColor, - // 1, - // false, - // STYLE_DASHDOTDOT // - // ); - - // // - // if (isCreated) - // { - // // - // Add( - // (XCBaseObject *)iObj, - // drawnObjects // - // ); - // } - - // // - // XCBaseObject *priceOBObj = NULL; - // if (isBullish) - // { - // // - // XCBullishOrderBlockObject *iObj; - // isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBullishOrderBlock( - // conditions.priceOB, - // iObj // - // ); - - // // - // if (isCreated) - // { - // // - // iObj.ZoneWidth(2); - // iObj.ZoneColor(boxColor); - // iObj.ZoneStyle(STYLE_SOLID); - - // // - // priceOBObj = (XCBaseObject *)iObj; - // } - // } - // else - // { - // // - // XCBearishOrderBlockObject *iObj; - // isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBearishOrderBlock( - // conditions.priceOB, - // iObj // - // ); - - // // - // if (isCreated) - // { - // // - // iObj.ZoneWidth(2); - // iObj.ZoneColor(boxColor); - // iObj.ZoneStyle(STYLE_SOLID); - - // // - // priceOBObj = (XCBaseObject *)iObj; - // } - // } - - // // - // if (isCreated) - // { - // // - // Add( - // priceOBObj, - // drawnObjects // - // ); - // } - // } - - // - // - // - - // - // Check Verifications Conditions ... - - // - // XHK ... - bool isXHKBullish = false; - bool isXHKBearish = false; - - // - // XSAR ... - bool isXSarBullish = false; - bool isXSarBearish = false; - - // - // XATR ... - bool isXAtrBullish = false; - bool isXAtrBearish = false; - - // - // XSTR ... - bool isXStrBullish = false; - bool isXStrBearish = false; - - // - // XVWAP ... - bool isXVWapBullish = false; - bool isXVWapBearish = false; - - // - // XCHE ... - bool isXCheBullish = false; - bool isXCheBearish = false; - - // - if (hasPriceBox) - { - // - // XHK ... - - // - isXHKBullish = - // - // Trigger ... - triggerXConditions.isSMHKBullish && - triggerXConditions.isRawHKBullish && - triggerXConditions.isClosedOverSMHK && - triggerXConditions.isClosedOverRawHK && - (triggerXConditions.isBreakedUpSMHK || - triggerXConditions.isBreakedUpRawHK) && - triggerXConditions.isRawHKClosedOverSMHK && - // - // Decision ... - decisionXConditions.isSMHKBullish && - decisionXConditions.isRawHKBullish && - decisionXConditions.isClosedOverSMHK && - decisionXConditions.isClosedOverRawHK && - (decisionXConditions.isBreakedUpSMHK || - decisionXConditions.isBreakedUpRawHK) && - decisionXConditions.isRawHKClosedOverSMHK && - // - // Analyse ... - analyseXConditions.isSMHKBullish && - analyseXConditions.isRawHKBullish && - analyseXConditions.isClosedOverSMHK && - analyseXConditions.isClosedOverRawHK && - (analyseXConditions.isBreakedUpSMHK || - analyseXConditions.isBreakedUpRawHK) && - decisionXConditions.isRawHKClosedOverSMHK - // - ; - - // - isXHKBearish = - // - // Trigger ... - triggerXConditions.isSMHKBearish && - triggerXConditions.isRawHKBearish && - triggerXConditions.isClosedUnderSMHK && - triggerXConditions.isClosedUnderRawHK && - (triggerXConditions.isBreakedDownSMHK || - triggerXConditions.isBreakedDownRawHK) && - triggerXConditions.isRawHKClosedUnderSMHK && - // - // Decision ... - decisionXConditions.isSMHKBearish && - decisionXConditions.isRawHKBearish && - decisionXConditions.isClosedUnderSMHK && - decisionXConditions.isClosedUnderRawHK && - (decisionXConditions.isBreakedDownSMHK || - decisionXConditions.isBreakedDownRawHK) && - decisionXConditions.isRawHKClosedUnderSMHK && - // - // Analyse ... - analyseXConditions.isSMHKBearish && - analyseXConditions.isRawHKBearish && - analyseXConditions.isClosedUnderSMHK && - analyseXConditions.isClosedUnderRawHK && - (analyseXConditions.isBreakedDownSMHK || - analyseXConditions.isBreakedDownRawHK) && - analyseXConditions.isRawHKClosedUnderSMHK - // - ; - - // - // XSAR ... - - // - isXSarBullish = - // - // Trigger ... - triggerXConditions.isSarBullish && - triggerXConditions.isSarIncreased && - // - // Decision ... - decisionXConditions.isSarBullish && - decisionXConditions.isSarIncreased && - // - // Analyse ... - analyseXConditions.isSarBullish && - analyseXConditions.isSarIncreased - // - ; - - // - isXSarBearish = - // - // Trigger ... - triggerXConditions.isSarBearish && - triggerXConditions.isSarDecreased && - // - // Decision ... - decisionXConditions.isSarBearish && - decisionXConditions.isSarDecreased && - // - // Analyse ... - analyseXConditions.isSarBearish // && - // - ; - - // - // XATR ... - - // - isXAtrBullish = - // - // Trigger ... - triggerXConditions.isClosedOverAtrUpper && - // - // Decision ... - decisionXConditions.isClosedOverAtrUpper - // - // Analyse ... - // - ; - - // - isXAtrBearish = - // - // Trigger ... - triggerXConditions.isClosedUnderAtrLower && - // - // Decision ... - decisionXConditions.isClosedUnderAtrLower - // - // Analyse ... - // - ; - - // - // XSTR ... - - // - isXStrBullish = - // - // Trigger ... - triggerXConditions.isStrBullish && - // - // Decision ... - decisionXConditions.isStrBullish - // - // Analyse ... - // - ; - - // - isXStrBearish = - // - // Trigger ... - triggerXConditions.isStrBearish && - // - // Decision ... - decisionXConditions.isStrBearish - // - // Analyse ... - // - ; - - // - // XVWAP ... - - // - isXVWapBullish = - // - // Trigger ... - triggerXConditions.isVWapBullishState && - triggerXConditions.isVWapBullishOrdered && - // - // Decision ... - decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapBullishOrdered && - // - // Analyse ... - analyseXConditions.isVWapBullishState && - analyseXConditions.isVWapBullishOrdered - // - ; - - // - isXVWapBearish = - // - // Trigger ... - triggerXConditions.isVWapBearishState && - triggerXConditions.isVWapBearishOrdered && - // - // Decision ... - decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapBearishOrdered && - // - // Analyse ... - analyseXConditions.isVWapBearishState && - analyseXConditions.isVWapBearishOrdered - // - ; - - // - // XCHE ... - - // - isXCheBullish = - // - // Trigger ... - triggerXConditions.isCheBullish && - // - // Decision ... - decisionXConditions.isCheBullish && - // - // Analyse ... - analyseXConditions.isCheBullish - // - ; - - // - isXCheBearish = - // - // Trigger ... - triggerXConditions.isCheBearish && - // - // Decision ... - decisionXConditions.isCheBearish && - // - // Analyse ... - analyseXConditions.isCheBearish - // - ; - } - - // - // Summarize Conditions ... + // Detect ... // bool isCondition1Bullish = // - isPriceOBUpperBrekedUp && - conditions.isPriceOBBreaked && - conditions.priceOB.IsBearish() && - // - // XHK ... - isXHKBullish && - // - // XSAR ... - isXSarBullish && - // - // XATR ... - isXAtrBullish && - // - // XSTR ... - isXStrBullish && - // - // XVWAP ... - isXVWapBullish && - // - // XCHE ... - isXCheBullish && - // - true + false // ; // bool isCondition1Bearish = // - isPriceOBLowerBrekedDown && - conditions.isPriceOBBreaked && - conditions.priceOB.IsBullish() && - // - // XHK ... - isXHKBearish && - // - // XSAR ... - isXSarBearish && - // - // XATR ... - isXAtrBearish && - // - // XSTR ... - isXStrBearish && - // - // XVWAP ... - isXVWapBearish && - // - // XCHE ... - isXCheBearish && - // - true + false // ; @@ -1350,8 +738,8 @@ bool DetectX121SMCXHKPVSignalSetup( ); // - double longPivot = lower; // triggerXConditions.valesBuffer[1]; - double shortPivot = upper; // triggerXConditions.peaksBuffer[1]; + double longPivot = triggerXConditions.valesBuffer[1]; + double shortPivot = triggerXConditions.peaksBuffer[1]; // // Manipulate Conditions Point ... @@ -1395,24 +783,6 @@ bool DetectX121SMCXHKPVSignalSetup( isBearish; if (!result) { - // - // Detect PriceOB Lifetime Bars ... - if (hasPriceBox) - { - // - int obLifetimeBars = (int)(cTime - conditions.priceOBAt) / PeriodSeconds(PERIOD_M1); - bool canReset = - // - !conditions.isPriceOBActed && - obLifetimeBars >= resetAfterUnActedZoneInMinutes - // - ; - if (canReset) - { - conditions.Clean(); - } - } - // // Cleanup Arrays ... Clean(triggerPoiEvents); diff --git a/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 index a091b8b9..bf0e592d 100644 --- a/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xobs.signal.lib.mq5 @@ -57,14 +57,17 @@ struct X121SMCStrategyXOBSSignalConditions // // Extwnsion ... - // - datetime vOBAt; - XCOrderBlock *vOB; - bool isVOBActivated; - // datetime cOBAt; XCOrderBlock *cOB; + bool isCOBActivated; + datetime cOBActivatedAt; + + // + datetime aOBAt; + XCOrderBlock *aOB; + bool isAOBActivated; + datetime aOBActivatedAt; // // Constructor ... @@ -188,15 +191,16 @@ struct X121SMCStrategyXOBSSignalConditions point = 0; // - vOB = NULL; cOB = NULL; - - // - vOBAt = NULL; cOBAt = NULL; + cOBActivatedAt = NULL; + isCOBActivated = false; // - isVOBActivated = false; + aOB = NULL; + aOBAt = NULL; + aOBActivatedAt = NULL; + isAOBActivated = false; } // @@ -728,12 +732,6 @@ bool DetectX121SMCXOBSSignalSetup( // // Detect OrderBlocks ... - // - bool hasVOB = - conditions.vOB != NULL && - conditions.vOB.IsValid() && - IsValid(conditions.vOBAt); - // bool hasCOB = conditions.cOB != NULL && @@ -741,23 +739,23 @@ bool DetectX121SMCXOBSSignalSetup( IsValid(conditions.cOBAt); // - if (!hasVOB) + if (!hasCOB) { // - int poiEvntsCount = ArraySize(visionPoiEvents); + int poiEvntsCount = ArraySize(consolidationPoiEvents); bool hasEvent = IsValidSize(poiEvntsCount); if (hasEvent) { // bool hasNewBullOB = Contains( X_BULLISH_ORDERBLOCK_DETECTED, - visionPoiEvents // + consolidationPoiEvents // ); // bool hasNewBearOB = Contains( X_BEARISH_ORDERBLOCK_DETECTED, - visionPoiEvents // + consolidationPoiEvents // ); // @@ -769,110 +767,155 @@ bool DetectX121SMCXOBSSignalSetup( if (hasNewOB) { // + XCOrderBlock *ob = NULL; if (hasNewBullOB) { // - int lastIDX = visionState.CountBullishOrderBlocks() - 1; - conditions.vOB = visionState.bullishOrderBlocks[lastIDX]; + int lastIDX = consolidationState.CountBullishOrderBlocks() - 1; + ob = consolidationState.bullishOrderBlocks[lastIDX]; + + // + // Validate OB ... } else if (hasNewBearOB) { // - int lastIDX = visionState.CountBearishOrderBlocks() - 1; - conditions.vOB = visionState.bearishOrderBlocks[lastIDX]; + int lastIDX = consolidationState.CountBearishOrderBlocks() - 1; + ob = consolidationState.bearishOrderBlocks[lastIDX]; + + // + // Validate OB ... } // - conditions.vOBAt = cTime; + if (ob != NULL && ob.IsValid()) + { + // + conditions.cOB = ob; - // - hasVOB = - conditions.vOB != NULL && - conditions.vOB.IsValid() && - IsValid(conditions.vOBAt); + // + conditions.cOBAt = cTime; + + // + hasCOB = + conditions.cOB != NULL && + conditions.cOB.IsValid() && + IsValid(conditions.cOBAt); + } } } - else + } + + // + if (hasCOB) + { + conditions.cOB.To(cTime); + } + + // + bool hasAOB = + conditions.aOB != NULL && + conditions.aOB.IsValid() && + IsValid(conditions.aOBAt); + + // + if (hasCOB && + !hasAOB) + { + // + int poiEvntsCount = ArraySize(analysePoiEvents); + bool hasEvent = IsValidSize(poiEvntsCount); + if (hasEvent) { // - X121SMCCycleState vState; - bool hasVState = visionCycleHelper.GetCycleState(vState); + bool hasNewBullOB = Contains( + X_BULLISH_ORDERBLOCK_DETECTED, + analysePoiEvents // + ); // - bool hasYoungestOB = vState.GetYoungestOB(conditions.vOB); - if (hasYoungestOB) + bool hasNewBearOB = Contains( + X_BEARISH_ORDERBLOCK_DETECTED, + analysePoiEvents // + ); + + // + bool hasNewOB = + hasNewBullOB || + hasNewBearOB; + + // + if (hasNewOB) { // - conditions.vOBAt = cTime; + XCOrderBlock *ob = NULL; + if (hasNewBullOB) + { + // + int lastIDX = analyseState.CountBullishOrderBlocks() - 1; + ob = analyseState.bullishOrderBlocks[lastIDX]; + + // + // Validate OB ... + } + else if (hasNewBearOB) + { + // + int lastIDX = analyseState.CountBearishOrderBlocks() - 1; + ob = analyseState.bearishOrderBlocks[lastIDX]; + + // + // Validate OB ... + } // - hasVOB = - conditions.vOB != NULL && - conditions.vOB.IsValid() && - IsValid(conditions.vOBAt); + if (ob != NULL && ob.IsValid()) + { + // + conditions.aOB = ob; + + // + conditions.aOBAt = cTime; + + // + hasAOB = + conditions.aOB != NULL && + conditions.aOB.IsValid() && + IsValid(conditions.aOBAt); + } } } } // - // Update To Time ... - if (hasVOB) + if (hasAOB) { - // - conditions.vOB.To(cTime); + conditions.aOB.To(cTime); } // - // Vait for Order Block Activation ... - if (hasVOB && - !conditions.isVOBActivated) - { - // - conditions.isVOBActivated = - // - cBar.low >= conditions.vOB.Lower() && - cBar.high <= conditions.vOB.Upper() && - // - bid >= conditions.vOB.Lower() && - bid <= conditions.vOB.Upper() - // - ; - } - - // - // Check Result ... - result = hasVOB && - conditions.isVOBActivated; + result = hasCOB && + hasAOB; if (!result) { return result; } // - // Check Market Trend ... - bool isTrendOveralBullish = hasVisionBullishTrend && - hasConsolidationBullishTrend; - bool isTrendOveralBearish = hasVisionBearishTrend && - hasConsolidationBearishTrend; - result = (isTrendOveralBullish && - !isTrendOveralBearish) || - (!isTrendOveralBullish && - isTrendOveralBearish); - if (!result) - { - return result; - } + // DRAW ... + // // - bool isBullishOB = conditions.vOB.IsBullish(); - if (isBullishOB) + // Draw Orer Block ... + bool isBullishCOB = conditions.cOB.IsBullish(); + if (isBullishCOB) { // XCBullishOrderBlockObject *iObj; - bool isCreated = visionCycleHelper + bool isCreated = consolidationCycleHelper .mPOIDrawer .CreateBullishOrderBlock( - conditions.vOB, + conditions.cOB, iObj // ); } @@ -880,14 +923,158 @@ bool DetectX121SMCXOBSSignalSetup( { // XCBearishOrderBlockObject *iObj; - bool isCreated = visionCycleHelper + bool isCreated = consolidationCycleHelper .mPOIDrawer .CreateBearishOrderBlock( - conditions.vOB, + conditions.cOB, iObj // ); } + bool isBullishAOB = conditions.aOB.IsBullish(); + if (isBullishAOB) + { + // + XCBullishOrderBlockObject *iObj; + bool isCreated = analyseCycleHelper + .mPOIDrawer + .CreateBullishOrderBlock( + conditions.aOB, + iObj // + ); + } + else + { + // + XCBearishOrderBlockObject *iObj; + bool isCreated = analyseCycleHelper + .mPOIDrawer + .CreateBearishOrderBlock( + conditions.aOB, + iObj // + ); + } + + // + // Draw From Bar ... + XOHCL cOBFromBar; + bool hasCOBFromBar = cOBFromBar.Init( + conditions.cOB.GetSymbol(), + conditions.cOB.GetPeriod(), + conditions.cOB.From() // + ); + if (hasCOBFromBar) + { + // + XCOHCLObject *barObject; + bool iCreated = consolidationCycleHelper + .mPOIDrawer + .CreateBar( + cOBFromBar, + barObject // + ); + } + + // + // Draw From Bar ... + XOHCL aOBFromBar; + bool hasAOBFromBar = aOBFromBar.Init( + conditions.aOB.GetSymbol(), + conditions.aOB.GetPeriod(), + conditions.aOB.From() // + ); + if (hasAOBFromBar) + { + // + XCOHCLObject *barObject; + bool iCreated = analyseCycleHelper + .mPOIDrawer + .CreateBar( + aOBFromBar, + barObject // + ); + } + + // + // END DRAW ... + // + + // + // Check AOB Activation ... + if (!conditions.isAOBActivated) + { + // + int aPeakRepetition = analyseCycleHelper.CountPrevPeakRepetition(); + int aValeRepetition = analyseCycleHelper.CountPrevValeRepetition(); + + // + bool isActivated = + // + bid >= conditions.aOB.Lower() && + bid <= conditions.aOB.Upper() && + // + cBar.low >= conditions.aOB.Lower() && + cBar.high <= conditions.aOB.Upper() && + // + (conditions.aOB.IsBullish() + ? decisionXConditions.valesBuffer[1] >= conditions.aOB.Lower() && + decisionXConditions.valesBuffer[1] <= conditions.aOB.Upper() + : decisionXConditions.peaksBuffer[1] >= conditions.aOB.Lower() && + decisionXConditions.peaksBuffer[1] <= conditions.aOB.Upper()) + // + ; + + // + if (isActivated) + { + // + conditions.aOBActivatedAt = cTime; + conditions.isAOBActivated = isActivated; + } + } + + // + // Check COB Activation ... + if (!conditions.isCOBActivated) + { + // + int aPeakRepetition = analyseCycleHelper.CountPrevPeakRepetition(); + int aValeRepetition = analyseCycleHelper.CountPrevValeRepetition(); + + // + bool isActivated = + // + bid >= conditions.cOB.Lower() && + bid <= conditions.cOB.Upper() && + // + cBar.low >= conditions.cOB.Lower() && + cBar.high <= conditions.cOB.Upper() && + // + (conditions.cOB.IsBullish() + ? decisionXConditions.valesBuffer[1] >= conditions.cOB.Lower() && + decisionXConditions.valesBuffer[1] <= conditions.cOB.Upper() + : decisionXConditions.peaksBuffer[1] >= conditions.cOB.Lower() && + decisionXConditions.peaksBuffer[1] <= conditions.cOB.Upper()) + // + ; + + // + if (isActivated) + { + // + conditions.cOBActivatedAt = cTime; + conditions.isCOBActivated = isActivated; + } + } + + // + result = conditions.isAOBActivated || + conditions.isCOBActivated; + if (!result) + { + return result; + } + // double upper = 0; double lower = 0; diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index aebd7f37..caa8e834 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -1662,10 +1662,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // useXSignal = false; - useXOBSSignal = true; + useXOBSSignal = false; useXHKPVSignal = false; - useXOBPVSignal = false; - useXIOBPVSignal = false; + useXOBPVSignal = true; + useXIOBPVSignal = true; // string symbol = GetSymbol();