diff --git a/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 b/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 new file mode 100644 index 00000000..0da02f7a --- /dev/null +++ b/Documents/BKP/1/x-121.smc.xobpv.signal.orig.old.lib.mq5 @@ -0,0 +1,1688 @@ +/////////////////////////////////////////////////////// +// +// 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 X121SMCStrategyXOBPVSignalConditions +{ + // + // 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; + + // + XCOrderBlock *bullishOBs[]; + XCOrderBlock *bearishOBs[]; + + // + // Constructor ... + X121SMCStrategyXOBPVSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + target = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped() + { + // + bool result = false; + + // + result = IsValid(setupTime) && + HasDirection(dir); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Calculate Setup Age ... + * + * @return ( int ) + */ + int GetSetupAge() + { + // + int result = 0; + + // + if (!IsSetuped()) + { + return result; + } + + // + result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); + + // + return result; + } + + /** + * Detect How we Can Trigger Signal ... + * + * @return ( bool ) + */ + bool CanTrigger() + { + // + bool result = false; + + // + result = + // + sl > 0 && + IsValid(symbol) && + IsValid(period) && + IsValid(triggerTime) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + + // + return result; + } + + // + // Extensions ... + + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + // + pivot = 0; + point = 0; + + // + Clean(bullishOBs); + Clean(bearishOBs); + + // + } + + // + int CountBullishOBs() + { + return ArraySize(bullishOBs); + } + + // + bool HasBullishOBs() + { + return IsValidSize(CountBullishOBs()); + } + + // + int CountBearishOBs() + { + return ArraySize(bearishOBs); + } + + // + bool HasBearishOBs() + { + return IsValidSize(CountBearishOBs()); + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXOBPVSignalConditions mXOBPVConditions; +X121SMCStrategyXOBPVSignalConditions mXOBPVConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXOBPVSignalSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXOBPVSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // +) +{ + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XOHCL zBar; + result = 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 = 3; + 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 ... + + // + // 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 Order Block ... + + // + bool hasBullishOrderBlocks = conditions.HasBullishOBs(); + int bullishOrderBlocksCount = conditions.CountBullishOBs(); + + // + bool hasBearishOrderBlocks = conditions.HasBearishOBs(); + int bearishOrderBlocksCount = conditions.CountBearishOBs(); + + // + bool hasOrderBlocks = hasBullishOrderBlocks && + hasBearishOrderBlocks; + if (!hasOrderBlocks) + { + // + XCOrderBlock *bullishOBs[]; + XCOrderBlock *bearishOBs[]; + bool hasOrderBlocks = visionCycleHelper.DetectOrderBlocks( + bullishOBs, + bearishOBs // + ); + + // + if (!hasBullishOrderBlocks) + { + // + Copy( + bullishOBs, + conditions.bullishOBs // + ); + } + + // + if (!hasBearishOrderBlocks) + { + // + Copy( + bearishOBs, + conditions.bearishOBs // + ); + } + + // + hasBullishOrderBlocks = conditions.HasBullishOBs(); + bullishOrderBlocksCount = conditions.CountBullishOBs(); + + // + hasBearishOrderBlocks = conditions.HasBearishOBs(); + bearishOrderBlocksCount = conditions.CountBearishOBs(); + } + + // + bool hasOldestBullishOB = false; + bool hasYoungestBullishOB = false; + XCOrderBlock *oldestBullishOB = NULL; + XCOrderBlock *youngestBullishOB = NULL; + if (hasBullishOrderBlocks) + { + // + XCZone *zones[]; + bool isConverted = ToZone( + conditions.bullishOBs, + zones // + ); + + // + int oldestIDX = GetOldest(zones); + hasOldestBullishOB = IsValidIndex(oldestIDX); + if (hasOldestBullishOB) + { + oldestBullishOB = conditions.bullishOBs[oldestIDX]; + } + + // + int youngestIDX = GetYoungest(zones); + hasYoungestBullishOB = IsValidIndex(youngestIDX); + if (hasYoungestBullishOB) + { + youngestBullishOB = conditions.bullishOBs[youngestIDX]; + } + } + + // + bool hasOldestBearishOB = false; + bool hasYoungestBearishOB = false; + XCOrderBlock *oldestBearishOB = NULL; + XCOrderBlock *youngestBearishOB = NULL; + if (hasBearishOrderBlocks) + { + // + XCZone *zones[]; + bool isConverted = ToZone( + conditions.bearishOBs, + zones // + ); + + // + int oldestIDX = GetOldest(zones); + hasOldestBearishOB = IsValidIndex(oldestIDX); + if (hasOldestBearishOB) + { + oldestBearishOB = conditions.bearishOBs[oldestIDX]; + } + + // + int youngestIDX = GetYoungest(zones); + hasYoungestBearishOB = IsValidIndex(youngestIDX); + if (hasYoungestBearishOB) + { + youngestBearishOB = conditions.bearishOBs[youngestIDX]; + } + } + + // + bool hasPriceInsideOB = false; + XCOrderBlock *priceInsideOB = NULL; + + // + if (!hasPriceInsideOB && + hasBullishOrderBlocks) + { + // + for (int i = 0; i < bullishOrderBlocksCount; i++) + { + // + XCOrderBlock *iOb = conditions.bullishOBs[i]; + + // + bool isInside = IsPriceInsideZone( + decisionXConditions.valesBuffer[1], + (XCZone *)iOb // + ); + if (isInside) + { + // + hasPriceInsideOB = true; + priceInsideOB = iOb; + break; + } + } + } + + // + if (!hasPriceInsideOB && + hasBearishOrderBlocks) + { + // + for (int i = 0; i < bearishOrderBlocksCount; i++) + { + // + XCOrderBlock *iOb = conditions.bearishOBs[i]; + + // + bool isInside = IsPriceInsideZone( + decisionXConditions.peaksBuffer[1], + (XCZone *)iOb // + ); + if (isInside) + { + // + hasPriceInsideOB = true; + priceInsideOB = iOb; + break; + } + } + } + + // + XStateZones obState; + bool hasOBState = false; + XOHCL priceInsideOBBreakerBar; + if (hasPriceInsideOB) + { + // + XOHCL toBar; + XOHCL fromBar; + ENUM_X_DIRECTION forDir = + priceInsideOB.IsBullish() + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + bool hasBreakerBar = HasBreakerBar( + toBar, + fromBar, + priceInsideOBBreakerBar, + forDir, + priceInsideOB.GetSymbol(), + priceInsideOB.GetPeriod(), + priceInsideOB.Upper(), + priceInsideOB.Lower(), + priceInsideOB.From(), + priceInsideOB.To() // + ); + if (hasBreakerBar) + { + // + CalculateStateZones( + obState, + consolidationState, + priceInsideOB.Upper(), + priceInsideOB.Lower(), + priceInsideOBBreakerBar.time // + ); + } + + // + hasOBState = obState.IsValid(); + } + + // + // DRAW ... + // + + // + XCBaseObject *drawnObjects[]; + + // + if (hasBullishOrderBlocks) + { + // + for (int i = 0; i < bullishOrderBlocksCount; i++) + { + // + XCOrderBlock *iOb = conditions.bullishOBs[i]; + + // + XCBullishOrderBlockObject *iObObj; + bool isCreated = visionCycleHelper + .mPOIDrawer + .CreateBullishOrderBlock( + iOb, + iObObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObObj, + drawnObjects // + ); + } + } + } + + // + if (hasBearishOrderBlocks) + { + // + for (int i = 0; i < bearishOrderBlocksCount; i++) + { + // + XCOrderBlock *iOb = conditions.bearishOBs[i]; + + // + XCBearishOrderBlockObject *iObObj; + bool isCreated = visionCycleHelper + .mPOIDrawer + .CreateBearishOrderBlock( + iOb, + iObObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObObj, + drawnObjects // + ); + } + } + } + + // + if (hasPriceInsideOB) + { + // + bool isBullish = priceInsideOB.IsBullish(); + + // + bool isCreated = false; + XCBaseObject *priceInsideOBObj = NULL; + if (isBullish) + { + // + XCBullishOrderBlockObject *iObj; + isCreated = visionCycleHelper + .mPOIDrawer + .CreateBullishOrderBlock( + priceInsideOB, + iObj // + ); + if (isCreated) + { + // + iObj.ZoneColor(clrYellow); + + // + priceInsideOBObj = (XCBaseObject *)iObj; + } + } + else + { + // + XCBearishOrderBlockObject *iObj; + isCreated = visionCycleHelper + .mPOIDrawer + .CreateBearishOrderBlock( + priceInsideOB, + iObj // + ); + if (isCreated) + { + // + iObj.ZoneColor(clrOrange); + + // + priceInsideOBObj = (XCBaseObject *)iObj; + } + } + + // + if (isCreated) + { + // + Add( + priceInsideOBObj, + drawnObjects // + ); + } + } + + // + // if (hasOldestBullishOB) + // { + // // + // XCBullishOrderBlockObject *iObj; + // bool isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBullishOrderBlock( + // oldestBullishOB, + // iObj // + // ); + // if (isCreated) + // { + // } + // } + + // // + // if (hasYoungestBullishOB) + // { + // // + // XCBullishOrderBlockObject *iObj; + // bool isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBullishOrderBlock( + // youngestBullishOB, + // iObj // + // ); + // if (isCreated) + // { + // } + // } + + // // + // if (hasOldestBearishOB) + // { + // // + // XCBearishOrderBlockObject *iObj; + // bool isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBearishOrderBlock( + // oldestBearishOB, + // iObj // + // ); + // if (isCreated) + // { + // } + // } + + // // + // if (hasYoungestBearishOB) + // { + // // + // XCBearishOrderBlockObject *iObj; + // bool isCreated = visionCycleHelper + // .mPOIDrawer + // .CreateBearishOrderBlock( + // youngestBearishOB, + // iObj // + // ); + // if (isCreated) + // { + // } + // } + + // + // + // + + // + bool isSameCyclesPeak = + // + triggerXConditions.peaksBuffer[1] == decisionXConditions.peaksBuffer[1] && + decisionXConditions.peaksBuffer[1] == analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == verificationXConditions.peaksBuffer[1] + // && + // verificationXConditions.peaksBuffer[1] == consolidationXConditions.peaksBuffer[1] + // + ; + + // + bool isSameCyclesVale = + // + triggerXConditions.valesBuffer[1] == decisionXConditions.valesBuffer[1] && + decisionXConditions.valesBuffer[1] == analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == verificationXConditions.valesBuffer[1] + // && + // verificationXConditions.valesBuffer[1] == consolidationXConditions.valesBuffer[1] + // + ; + + // + bool hasSameCyclesPV = + // hasOBState && + hasPriceInsideOB && + (isSameCyclesPeak || + isSameCyclesVale); + + // + // + // + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + hasSameCyclesPV && + isCBarBullishFormed && + priceInsideOB.IsBullish() && + // + (decisionXConditions.isBreakedUpPrevSar || + decisionXConditions.isBreakedUpPrevStr || + decisionXConditions.isVWapMaxBreakedUp || + decisionXConditions.isBreakedUpPrevCheMax || + decisionXConditions.isBreakedUpPrevAtrLower) && + // + (decisionXConditions.isSarSwitchedToBullish || + decisionXConditions.isStrSwitchedToBullish || + decisionXConditions.isCheSwitchedToBullish || + decisionXConditions.isVWapSwitchedToBullishState || + decisionXConditions.isVWapSwitchedToBullishOrdered) + // + ; + + // + bool isCondition1Bearish = + // + hasSameCyclesPV && + isCBarBearishFormed && + priceInsideOB.IsBearish() && + // + (decisionXConditions.isBreakedDownPrevSar || + decisionXConditions.isBreakedDownPrevStr || + decisionXConditions.isVWapMinBreakedDown || + decisionXConditions.isBreakedDownPrevCheMin || + decisionXConditions.isBreakedDownPrevAtrUpper) && + // + (decisionXConditions.isSarSwitchedToBearish || + decisionXConditions.isStrSwitchedToBearish || + decisionXConditions.isCheSwitchedToBearish || + decisionXConditions.isVWapSwitchedToBearishState || + decisionXConditions.isVWapSwitchedToBearishOrdered) + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + // Manipulate Conditions Point ... + + // + conditions.point = point; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? priceInsideOB.Upper() + : priceInsideOB.Lower(); + } + + // + // + // + + // + isBullish = + // + isCondition1Bullish + // + ; + + // + isBearish = + // + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXOBPVSignalTrigger( + // + X121SMCStrategyXOBPVSignalConditions &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 ... + ArrayFree(decisionPoiEvents); + ArrayFree(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 ... + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + + // + return result; +} + +// +// Detect Guards ... +bool DetectX121SMCXOBPVGuards( + 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 AddX121SMCXOBPVConditionsIfNotExists( + X121SMCStrategyXOBPVSignalConditions &item, + X121SMCStrategyXOBPVSignalConditions &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 ... + X121SMCStrategyXOBPVSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXOBPVSignalConditions 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/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 1bd60dfe..4eae0397 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -926,7 +926,13 @@ bool DetectPriceInsideBox( // if (hasPriceInsideOB) { + // orderBlock = priceInsideOB; + boxDir = priceInsideOB.IsBullish() + ? X_DIRECTION_BULLISH + : priceInsideOB.IsBearish() + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; } // @@ -972,6 +978,7 @@ bool DetectPriceInsideBox( { // // Use Price Inside OB as Box ... + box.dir = boxDir; box.to = priceInsideOB.To(); box.from = priceInsideOB.From(); box.upper = priceInsideOB.Upper(); @@ -994,7 +1001,7 @@ bool DetectPriceInsideBox( { // double price = xConditions.valesBuffer[1]; - ENUM_X_DIRECTION dir = X_DIRECTION_BULLISH; + dir = X_DIRECTION_BULLISH; // // Bullish FVG ... @@ -1144,7 +1151,7 @@ bool DetectPriceInsideBox( { // double price = xConditions.peaksBuffer[1]; - ENUM_X_DIRECTION dir = X_DIRECTION_BEARISH; + dir = X_DIRECTION_BEARISH; // // Bearish FVG ... @@ -1303,6 +1310,13 @@ bool DetectPriceInsideBox( // XBoxZone iBox = boxes[i]; + // + // Direction ... + if (!HasDirection(box.dir) || box.dir != iBox.dir) + { + box.dir = iBox.dir; + } + // // Upper ... if (box.upper == 0 || box.upper < iBox.upper) @@ -1336,6 +1350,7 @@ bool DetectPriceInsideBox( { // // Use Price Inside OB as Box ... + box.dir = boxDir; box.to = priceInsideOB.To(); box.from = priceInsideOB.From(); box.upper = priceInsideOB.Upper(); diff --git a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 index a27f85ae..d9d12549 100644 --- a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 @@ -56,6 +56,8 @@ struct X121SMCStrategyXHKPVSignalConditions // XBoxZone priceBox; + bool isPriceOBActed; + bool isPriceOBBreaked; XCOrderBlock *priceOB; X121SMCCycleState state; @@ -181,6 +183,8 @@ struct X121SMCStrategyXHKPVSignalConditions state.Clean(); priceOB = NULL; priceBox.Clean(); + isPriceOBActed = false; + isPriceOBBreaked = false; } // @@ -235,9 +239,12 @@ bool DetectX121SMCXHKPVSignalSetup( conditions.symbol = symbol; conditions.period = period; + // + XC121SMCCycleHelper *barCycle = triggerCycleHelper; + // XOHCL zBar; - result = decisionCycleHelper.GetBar( + result = barCycle.GetBar( zBar, zIndex // ); @@ -248,7 +255,7 @@ bool DetectX121SMCXHKPVSignalSetup( // XOHCL cBar; - result = decisionCycleHelper.GetBar( + result = barCycle.GetBar( cBar, cIndex // ); @@ -259,7 +266,7 @@ bool DetectX121SMCXHKPVSignalSetup( // XOHCL pBar; - result = decisionCycleHelper.GetBar( + result = barCycle.GetBar( pBar, pIndex // ); @@ -691,6 +698,9 @@ bool DetectX121SMCXHKPVSignalSetup( // Detect Cycle State ... // + bool isPriceOBValid = false; + bool isBullishHappens = false; + bool isBearishHappens = false; bool hasPriceBox = conditions.priceBox.IsValid(); bool hasState = visionCycleHelper.GetCycleState(conditions.state); @@ -743,7 +753,7 @@ bool DetectX121SMCXHKPVSignalSetup( // // Check Validation Conditions ... - bool isPriceOBValid = + isPriceOBValid = // hasPriceBox && (isBullish @@ -751,12 +761,118 @@ bool DetectX121SMCXHKPVSignalSetup( : isSameCyclePeaks) // ; - if (isPriceOBValid) + + // + // 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) { - Print("Valid Conditions ..."); + conditions.isPriceOBActed = isBullishHappens || + isBearishHappens; } } + // + // Detect Accumulation ... + if (conditions.isPriceOBActed) + { + // + // Checking OB Breake on Side ... + if (!conditions.isPriceOBBreaked) + { + // + conditions.isPriceOBBreaked = + conditions.priceOB.IsBullish() + ? (cBar.low < conditions.priceOB.Upper() && + cBar.high > conditions.priceOB.Upper() && + cBar.close > conditions.priceOB.Upper()) + // + || + // + (pBar.high < conditions.priceOB.Upper() && + cBar.low > conditions.priceOB.Upper() && + cBar.open > conditions.priceOB.Upper()) + : (cBar.high > conditions.priceOB.Lower() && + cBar.low < conditions.priceOB.Lower() && + cBar.close < conditions.priceOB.Lower()) + // + || + // + (pBar.low > conditions.priceOB.Lower() && + cBar.high < conditions.priceOB.Lower() && + cBar.open < conditions.priceOB.Lower()); + } + } + + // + // Detect Distribution ... + bool isPriceOBUpperBrekedUp = false; + bool isPriceOBLowerBrekedDown = false; + if (conditions.isPriceOBBreaked) + { + // + isPriceOBUpperBrekedUp = IsBarBreak( + conditions.priceOB.Upper(), + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPriceOBLowerBrekedDown = IsBarBreak( + conditions.priceOB.Lower(), + X_DIRECTION_BEARISH, + cBar // + ); + } + // // Draw ... XCBaseObject *drawnObjects[]; @@ -853,12 +969,6 @@ bool DetectX121SMCXHKPVSignalSetup( } } - // - if (IsValidSize(drawnObjectsCount)) - { - Print("Drawn Objects ..."); - } - // // // @@ -866,21 +976,24 @@ bool DetectX121SMCXHKPVSignalSetup( // // Summarize Conditions ... + // + X121Conditions xConditions = triggerXConditions; + // bool isCondition1Bullish = // - isCBarBullishFormed && - // - false + isPriceOBUpperBrekedUp && + conditions.isPriceOBBreaked && + conditions.priceOB.IsBearish() // ; // bool isCondition1Bearish = // - isCBarBearishFormed && - // - false + isPriceOBLowerBrekedDown && + conditions.isPriceOBBreaked && + conditions.priceOB.IsBullish() // ; @@ -901,11 +1014,18 @@ bool DetectX121SMCXHKPVSignalSetup( pzDir // ); + // + double longPivot = conditions.priceOB.Lower(); // triggerXConditions.valesBuffer[1]; + double shortPivot = conditions.priceOB.Upper(); // triggerXConditions.peaksBuffer[1]; + // // Manipulate Conditions Point ... // - conditions.point = point; + conditions.point = + isCondition1Bullish + ? shortPivot + : longPivot; // // Manipulate Conditions Pivot ... @@ -913,8 +1033,8 @@ bool DetectX121SMCXHKPVSignalSetup( // conditions.pivot = isCondition1Bullish - ? triggerXConditions.valesBuffer[1] - : triggerXConditions.peaksBuffer[1]; + ? longPivot + : shortPivot; } // @@ -1108,7 +1228,7 @@ bool DetectX121SMCXHKPVSignalTrigger( // // Cycle X121Conditions ... - X121Conditions decisionXHKPVConditions = decisionConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; // // Trigger Conditions ... @@ -1117,22 +1237,22 @@ bool DetectX121SMCXHKPVSignalTrigger( // Slopes ... // - bool isRsiSlopeBullish = decisionXHKPVConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXHKPVConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXHKPVConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXHKPVConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXHKPVConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXHKPVConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXHKPVConditions.isVwapSlowSlopeBullish; + 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 = decisionXHKPVConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXHKPVConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXHKPVConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXHKPVConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXHKPVConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXHKPVConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXHKPVConditions.isVwapSlowSlopeBearish; + 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 = @@ -1168,18 +1288,18 @@ bool DetectX121SMCXHKPVSignalTrigger( // isBullish = // - isBullish // && - // isPointBreaked && - // isSlopesBullish + isBullish && + isPointBreaked && + isSlopesBullish // ; // isBearish = // - isBearish // && - // isPointBreaked && - // isSlopesBearish + isBearish && + isPointBreaked && + isSlopesBearish // ; @@ -1224,7 +1344,7 @@ bool DetectX121SMCXHKPVSignalTrigger( ); // - double iAtr = 0; // decisionConditions.x121Conditions.atrBuffer[1]; + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; iAtr *= 1.5; // diff --git a/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 index 3544e464..7ae31ff7 100644 --- a/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xobpv.signal.lib.mq5 @@ -55,8 +55,9 @@ struct X121SMCStrategyXOBPVSignalConditions double point; // - XCOrderBlock *bullishOBs[]; - XCOrderBlock *bearishOBs[]; + XBoxZone priceBox; + XCOrderBlock *priceOB; + X121SMCCycleState state; // // Constructor ... @@ -177,34 +178,9 @@ struct X121SMCStrategyXOBPVSignalConditions point = 0; // - Clean(bullishOBs); - Clean(bearishOBs); - - // - } - - // - int CountBullishOBs() - { - return ArraySize(bullishOBs); - } - - // - bool HasBullishOBs() - { - return IsValidSize(CountBullishOBs()); - } - - // - int CountBearishOBs() - { - return ArraySize(bearishOBs); - } - - // - bool HasBearishOBs() - { - return IsValidSize(CountBearishOBs()); + state.Clean(); + priceOB = NULL; + priceBox.Clean(); } // @@ -259,9 +235,12 @@ bool DetectX121SMCXOBPVSignalSetup( conditions.symbol = symbol; conditions.period = period; + // + XC121SMCCycleHelper *barCycle = triggerCycleHelper; + // XOHCL zBar; - result = decisionCycleHelper.GetBar( + result = barCycle.GetBar( zBar, zIndex // ); @@ -272,7 +251,7 @@ bool DetectX121SMCXOBPVSignalSetup( // XOHCL cBar; - result = decisionCycleHelper.GetBar( + result = barCycle.GetBar( cBar, cIndex // ); @@ -283,7 +262,7 @@ bool DetectX121SMCXOBPVSignalSetup( // XOHCL pBar; - result = decisionCycleHelper.GetBar( + result = barCycle.GetBar( pBar, pIndex // ); @@ -421,12 +400,12 @@ bool DetectX121SMCXOBPVSignalSetup( // // Cycle X121Conditions ... - X121Conditions triggerXOBPVConditions = triggerConditions.x121Conditions; - X121Conditions decisionXOBPVConditions = decisionConditions.x121Conditions; - X121Conditions analyseXOBPVConditions = analyseConditions.x121Conditions; - X121Conditions verificationXOBPVConditions = verificationConditions.x121Conditions; - X121Conditions consolidationXOBPVConditions = consolidationConditions.x121Conditions; - X121Conditions visionXOBPVConditions = visionConditions.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 ... @@ -712,287 +691,110 @@ bool DetectX121SMCXOBPVSignalSetup( ; // - // Detect Order Block ... + // Detect Cycle State ... // - bool hasBullishOrderBlocks = conditions.HasBullishOBs(); - int bullishOrderBlocksCount = conditions.CountBullishOBs(); + bool isPriceOBValid = false; + bool hasPriceBox = conditions.priceBox.IsValid(); + bool hasState = visionCycleHelper.GetCycleState(conditions.state); // - bool hasBearishOrderBlocks = conditions.HasBearishOBs(); - int bearishOrderBlocksCount = conditions.CountBearishOBs(); - - // - bool hasOrderBlocks = hasBullishOrderBlocks && - hasBearishOrderBlocks; - if (!hasOrderBlocks) + // Detect Price Box if not Provided ... + if (hasState && + !hasPriceBox) { // - XCOrderBlock *bullishOBs[]; - XCOrderBlock *bearishOBs[]; - bool hasOrderBlocks = visionCycleHelper.DetectOrderBlocks( - bullishOBs, - bearishOBs // + hasPriceBox = DetectPriceInsideBox( + conditions.priceBox, + conditions.priceOB, + decisionXConditions, + conditions.state // ); - - // - if (!hasBullishOrderBlocks) - { - // - Copy( - bullishOBs, - conditions.bullishOBs // - ); - } - - // - if (!hasBearishOrderBlocks) - { - // - Copy( - bearishOBs, - conditions.bearishOBs // - ); - } - - // - hasBullishOrderBlocks = conditions.HasBullishOBs(); - bullishOrderBlocksCount = conditions.CountBullishOBs(); - - // - hasBearishOrderBlocks = conditions.HasBearishOBs(); - bearishOrderBlocksCount = conditions.CountBearishOBs(); } // - bool hasOldestBullishOB = false; - bool hasYoungestBullishOB = false; - XCOrderBlock *oldestBullishOB = NULL; - XCOrderBlock *youngestBullishOB = NULL; - if (hasBullishOrderBlocks) + if (hasPriceBox) { // - XCZone *zones[]; - bool isConverted = ToZone( - conditions.bullishOBs, - zones // - ); + // Update Price Box Date ... + conditions.priceOB.To(cTime); + conditions.priceBox.to = cTime; // - int oldestIDX = GetOldest(zones); - hasOldestBullishOB = IsValidIndex(oldestIDX); - if (hasOldestBullishOB) - { - oldestBullishOB = conditions.bullishOBs[oldestIDX]; - } + // Here We Can Validate Box by Same Cycles Peaks and Vales ... + bool isBullish = IsBullish(conditions.priceBox.dir); // - int youngestIDX = GetYoungest(zones); - hasYoungestBullishOB = IsValidIndex(youngestIDX); - if (hasYoungestBullishOB) - { - youngestBullishOB = conditions.bullishOBs[youngestIDX]; - } - } - - // - bool hasOldestBearishOB = false; - bool hasYoungestBearishOB = false; - XCOrderBlock *oldestBearishOB = NULL; - XCOrderBlock *youngestBearishOB = NULL; - if (hasBearishOrderBlocks) - { - // - XCZone *zones[]; - bool isConverted = ToZone( - conditions.bearishOBs, - zones // - ); + int cIDX = 1; // - int oldestIDX = GetOldest(zones); - hasOldestBearishOB = IsValidIndex(oldestIDX); - if (hasOldestBearishOB) - { - oldestBearishOB = conditions.bearishOBs[oldestIDX]; - } - - // - int youngestIDX = GetYoungest(zones); - hasYoungestBearishOB = IsValidIndex(youngestIDX); - if (hasYoungestBearishOB) - { - youngestBearishOB = conditions.bearishOBs[youngestIDX]; - } - } - - // - bool hasPriceInsideOB = false; - XCOrderBlock *priceInsideOB = NULL; - - // - if (!hasPriceInsideOB && - hasBullishOrderBlocks) - { - // - for (int i = 0; i < bullishOrderBlocksCount; i++) - { + bool isSameCyclePeaks = // - XCOrderBlock *iOb = conditions.bullishOBs[i]; - + triggerXConditions.peaksBuffer[cIDX] == decisionXConditions.peaksBuffer[cIDX] && + decisionXConditions.peaksBuffer[cIDX] == analyseXConditions.peaksBuffer[cIDX] && + analyseXConditions.peaksBuffer[cIDX] == verificationXConditions.peaksBuffer[cIDX] // - bool isInside = IsPriceInsideZone( - decisionXOBPVConditions.valesBuffer[1], - (XCZone *)iOb // - ); - if (isInside) - { - // - hasPriceInsideOB = true; - priceInsideOB = iOb; - break; - } - } - } - - // - if (!hasPriceInsideOB && - hasBearishOrderBlocks) - { - // - for (int i = 0; i < bearishOrderBlocksCount; i++) - { - // - XCOrderBlock *iOb = conditions.bearishOBs[i]; - - // - bool isInside = IsPriceInsideZone( - decisionXOBPVConditions.peaksBuffer[1], - (XCZone *)iOb // - ); - if (isInside) - { - // - hasPriceInsideOB = true; - priceInsideOB = iOb; - break; - } - } - } - - // - XStateZones obState; - bool hasOBState = false; - XOHCL priceInsideOBBreakerBar; - if (hasPriceInsideOB) - { - // - XOHCL toBar; - XOHCL fromBar; - ENUM_X_DIRECTION forDir = - priceInsideOB.IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - bool hasBreakerBar = HasBreakerBar( - toBar, - fromBar, - priceInsideOBBreakerBar, - forDir, - priceInsideOB.GetSymbol(), - priceInsideOB.GetPeriod(), - priceInsideOB.Upper(), - priceInsideOB.Lower(), - priceInsideOB.From(), - priceInsideOB.To() // - ); - if (hasBreakerBar) - { - // - CalculateStateZones( - obState, - consolidationState, - priceInsideOB.Upper(), - priceInsideOB.Lower(), - priceInsideOBBreakerBar.time // - ); - } + ; // - hasOBState = obState.IsValid(); - } + bool isSameCycleVales = + // + triggerXConditions.valesBuffer[cIDX] == decisionXConditions.valesBuffer[cIDX] && + decisionXConditions.valesBuffer[cIDX] == analyseXConditions.valesBuffer[cIDX] && + analyseXConditions.valesBuffer[cIDX] == verificationXConditions.valesBuffer[cIDX] + // + ; - // - // DRAW ... - // + // + // Check Validation Conditions ... + isPriceOBValid = + // + hasPriceBox && + (isBullish + ? isSameCycleVales + : isSameCyclePeaks) + // + ; + } // // + // // Draw ... // XCBaseObject *drawnObjects[]; + // int drawnObjectsCount = visionCycleHelper.DrawCycleState( + // conditions.state, + // drawnObjects // + // ); // // - // if (hasBullishOrderBlocks) + // if (hasPriceBox) // { // // - // for (int i = 0; i < bullishOrderBlocksCount; i++) + // 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) // { // // - // XCOrderBlock *iOb = conditions.bullishOBs[i]; - - // // - // XCBullishOrderBlockObject *iObObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBullishOrderBlock( - // iOb, - // iObObj // - // ); - // if (isCreated) - // { - // // - // Add( - // (XCBaseObject *)iObObj, - // drawnObjects // - // ); - // } + // Add( + // (XCBaseObject *)iObj, + // drawnObjects // + // ); // } - // } - - // // - // if (hasBearishOrderBlocks) - // { - // // - // for (int i = 0; i < bearishOrderBlocksCount; i++) - // { - // // - // XCOrderBlock *iOb = conditions.bearishOBs[i]; - - // // - // XCBearishOrderBlockObject *iObObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBearishOrderBlock( - // iOb, - // iObObj // - // ); - // if (isCreated) - // { - // // - // Add( - // (XCBaseObject *)iObObj, - // drawnObjects // - // ); - // } - // } - // } - - // // - // if (hasPriceInsideOB) - // { - // // - // bool isBullish = priceInsideOB.IsBullish(); // // - // bool isCreated = false; - // XCBaseObject *priceInsideOBObj = NULL; + // XCBaseObject *priceOBObj = NULL; // if (isBullish) // { // // @@ -1000,16 +802,20 @@ bool DetectX121SMCXOBPVSignalSetup( // isCreated = visionCycleHelper // .mPOIDrawer // .CreateBullishOrderBlock( - // priceInsideOB, + // conditions.priceOB, // iObj // // ); + + // // // if (isCreated) // { // // - // iObj.ZoneColor(clrYellow); + // iObj.ZoneWidth(2); + // iObj.ZoneColor(boxColor); + // iObj.ZoneStyle(STYLE_SOLID); // // - // priceInsideOBObj = (XCBaseObject *)iObj; + // priceOBObj = (XCBaseObject *)iObj; // } // } // else @@ -1019,16 +825,20 @@ bool DetectX121SMCXOBPVSignalSetup( // isCreated = visionCycleHelper // .mPOIDrawer // .CreateBearishOrderBlock( - // priceInsideOB, + // conditions.priceOB, // iObj // // ); + + // // // if (isCreated) // { // // - // iObj.ZoneColor(clrOrange); + // iObj.ZoneWidth(2); + // iObj.ZoneColor(boxColor); + // iObj.ZoneStyle(STYLE_SOLID); // // - // priceInsideOBObj = (XCBaseObject *)iObj; + // priceOBObj = (XCBaseObject *)iObj; // } // } @@ -1037,109 +847,17 @@ bool DetectX121SMCXOBPVSignalSetup( // { // // // Add( - // priceInsideOBObj, + // priceOBObj, // drawnObjects // // ); // } // } - // - // if (hasOldestBullishOB) - // { - // // - // XCBullishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBullishOrderBlock( - // oldestBullishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - // // - // if (hasYoungestBullishOB) + // if (IsValidSize(drawnObjectsCount)) // { - // // - // XCBullishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBullishOrderBlock( - // youngestBullishOB, - // iObj // - // ); - // if (isCreated) - // { - // } // } - // // - // if (hasOldestBearishOB) - // { - // // - // XCBearishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBearishOrderBlock( - // oldestBearishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - - // // - // if (hasYoungestBearishOB) - // { - // // - // XCBearishOrderBlockObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBearishOrderBlock( - // youngestBearishOB, - // iObj // - // ); - // if (isCreated) - // { - // } - // } - - // - // - // - - // - bool isSameCyclesPeak = - // - triggerXOBPVConditions.peaksBuffer[1] == decisionXOBPVConditions.peaksBuffer[1] && - decisionXOBPVConditions.peaksBuffer[1] == analyseXOBPVConditions.peaksBuffer[1] && - analyseXOBPVConditions.peaksBuffer[1] == verificationXOBPVConditions.peaksBuffer[1] - // && - // verificationXOBPVConditions.peaksBuffer[1] == consolidationXOBPVConditions.peaksBuffer[1] - // - ; - - // - bool isSameCyclesVale = - // - triggerXOBPVConditions.valesBuffer[1] == decisionXOBPVConditions.valesBuffer[1] && - decisionXOBPVConditions.valesBuffer[1] == analyseXOBPVConditions.valesBuffer[1] && - analyseXOBPVConditions.valesBuffer[1] == verificationXOBPVConditions.valesBuffer[1] - // && - // verificationXOBPVConditions.valesBuffer[1] == consolidationXOBPVConditions.valesBuffer[1] - // - ; - - // - bool hasSameCyclesPV = - // hasOBState && - hasPriceInsideOB && - (isSameCyclesPeak || - isSameCyclesVale); - // // // @@ -1147,45 +865,50 @@ bool DetectX121SMCXOBPVSignalSetup( // // Summarize Conditions ... + // + X121Conditions xConditions = triggerXConditions; + // bool isCondition1Bullish = // - hasSameCyclesPV && + isPriceOBValid && isCBarBullishFormed && - priceInsideOB.IsBullish() && + conditions.priceOB.IsBullish() && + IsBullish(conditions.priceBox.dir) && // - (decisionXOBPVConditions.isBreakedUpPrevSar || - decisionXOBPVConditions.isBreakedUpPrevStr || - decisionXOBPVConditions.isVWapMaxBreakedUp || - decisionXOBPVConditions.isBreakedUpPrevCheMax || - decisionXOBPVConditions.isBreakedUpPrevAtrLower) && + (xConditions.isBreakedUpPrevSar || + xConditions.isBreakedUpPrevStr || + xConditions.isVWapMaxBreakedUp || + xConditions.isBreakedUpPrevCheMax || + xConditions.isBreakedUpPrevAtrLower) && // - (decisionXOBPVConditions.isSarSwitchedToBullish || - decisionXOBPVConditions.isStrSwitchedToBullish || - decisionXOBPVConditions.isCheSwitchedToBullish || - decisionXOBPVConditions.isVWapSwitchedToBullishState || - decisionXOBPVConditions.isVWapSwitchedToBullishOrdered) + (xConditions.isSarSwitchedToBullish || + xConditions.isStrSwitchedToBullish || + xConditions.isCheSwitchedToBullish || + xConditions.isVWapSwitchedToBullishState || + xConditions.isVWapSwitchedToBullishOrdered) // ; // bool isCondition1Bearish = // - hasSameCyclesPV && + isPriceOBValid && isCBarBearishFormed && - priceInsideOB.IsBearish() && + conditions.priceOB.IsBearish() && + IsBearish(conditions.priceBox.dir) && // - (decisionXOBPVConditions.isBreakedDownPrevSar || - decisionXOBPVConditions.isBreakedDownPrevStr || - decisionXOBPVConditions.isVWapMinBreakedDown || - decisionXOBPVConditions.isBreakedDownPrevCheMin || - decisionXOBPVConditions.isBreakedDownPrevAtrUpper) && + (xConditions.isBreakedDownPrevSar || + xConditions.isBreakedDownPrevStr || + xConditions.isVWapMinBreakedDown || + xConditions.isBreakedDownPrevCheMin || + xConditions.isBreakedDownPrevAtrUpper) && // - (decisionXOBPVConditions.isSarSwitchedToBearish || - decisionXOBPVConditions.isStrSwitchedToBearish || - decisionXOBPVConditions.isCheSwitchedToBearish || - decisionXOBPVConditions.isVWapSwitchedToBearishState || - decisionXOBPVConditions.isVWapSwitchedToBearishOrdered) + (xConditions.isSarSwitchedToBearish || + xConditions.isStrSwitchedToBearish || + xConditions.isCheSwitchedToBearish || + xConditions.isVWapSwitchedToBearishState || + xConditions.isVWapSwitchedToBearishOrdered) // ; @@ -1214,12 +937,14 @@ bool DetectX121SMCXOBPVSignalSetup( // // Manipulate Conditions Pivot ... + double longPivot = triggerXConditions.valesBuffer[1]; // conditions.priceOB.Lower(); + double shortPivot = triggerXConditions.peaksBuffer[1]; // conditions.priceOB.Upper(); // conditions.pivot = isCondition1Bullish - ? priceInsideOB.Upper() - : priceInsideOB.Lower(); + ? longPivot + : shortPivot; } // @@ -1413,7 +1138,7 @@ bool DetectX121SMCXOBPVSignalTrigger( // // Cycle X121Conditions ... - X121Conditions decisionXOBPVConditions = decisionConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; // // Trigger Conditions ... @@ -1422,22 +1147,22 @@ bool DetectX121SMCXOBPVSignalTrigger( // Slopes ... // - bool isRsiSlopeBullish = decisionXOBPVConditions.isRsiSlopeBullish; - bool isStrSlopeBullish = decisionXOBPVConditions.isStrSlopeBullish; - bool isAtrUpperSlopeBullish = decisionXOBPVConditions.isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish = decisionXOBPVConditions.isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish = decisionXOBPVConditions.isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish = decisionXOBPVConditions.isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish = decisionXOBPVConditions.isVwapSlowSlopeBullish; + 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 = decisionXOBPVConditions.isRsiSlopeBearish; - bool isStrSlopeBearish = decisionXOBPVConditions.isStrSlopeBearish; - bool isAtrUpperSlopeBearish = decisionXOBPVConditions.isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish = decisionXOBPVConditions.isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish = decisionXOBPVConditions.isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish = decisionXOBPVConditions.isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish = decisionXOBPVConditions.isVwapSlowSlopeBearish; + 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 =