From de90f2d5fb8f0bb9df0ea1c8aaa3c90794dd0de9 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 2 Dec 2024 03:11:52 +0330 Subject: [PATCH] last works ... --- Classes/x-saherelm.x-poi.class.mq5 | 2331 +++++++------- Documents/BKP/test.stategy.mq5 | 214 ++ Documents/BKP/tmp.x121.smc.mq5 | 113 + .../BKP/x-121.smc.test.strategy.class.mq5 | 2807 +++++++++++++++++ Libraries/x-saherelm.common.lib.mq5 | 120 + Libraries/x-saherelm.x-poi.lib.mq5 | 54 + .../Classes/x-121.smc.base.strategy.class.mq5 | 2 +- .../x-121.smc.market.cycle.helper.class.mq5 | 122 +- X121SMCEA/Libraries/x-121.smc.lib.mq5 | 26 + .../x-121.smc.test.strategy.class.mq5 | 945 ++++-- 10 files changed, 5360 insertions(+), 1374 deletions(-) create mode 100644 Documents/BKP/test.stategy.mq5 create mode 100644 Documents/BKP/x-121.smc.test.strategy.class.mq5 diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 6a4b3980..c7d77acb 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -1156,7 +1156,7 @@ class XCPOIDetector : public XCBaseAlert // state.ticksZone = mTicksZone; - + // } @@ -1272,6 +1272,1243 @@ class XCPOIDetector : public XCBaseAlert TicksRangeZoneRange(144); } + // + // Detector Functions ... + + /** + * Detect Swing High ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectSwingHigh(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int range = SwingRange(); + int barIndex = bar.Index(); + result = range > 0 && + barIndex >= range; + if (!result) + { + return result; + } + + // + result = mBarAnalyser.IsSwingHigh( + bar, + range // + ); + if (result) + { + // + XCSwing *swing; + swing = new XCSwing(); + result = swing.Init( + bar, + X_POI_SWING_HIGH // + ); + + // + if (result) + { + // + Add( + swing, + mSwingHighs // + ); + + // + // XCSwingHighObject *iObj; + // bool isCreated = mDrawer.CreateSwingHigh( + // swing, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Swing Low ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectSwingLow(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int range = SwingRange(); + int barIndex = bar.Index(); + result = range > 0 && + barIndex >= range; + if (!result) + { + return result; + } + + // + result = mBarAnalyser.IsSwingLow( + bar, + range // + ); + if (result) + { + // + XCSwing *swing; + swing = new XCSwing(); + result = swing.Init( + bar, + X_POI_SWING_LOW // + ); + + // + if (result) + { + // + Add( + swing, + mSwingLows // + ); + + // // + // XCSwingLowObject *iObj; + // bool isCreated = mDrawer.CreateSwingLow( + // swing, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bullish Momentum Bar ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBullishMomentumBar(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid() && + bar.Index() > 0; + if (!result) + { + return result; + } + + // + int extendRange = MomentumBarExtendRange(); + double bodyPercent = MomentumBarBodyPercent(); + ENUM_X_DIRECTION dir; + result = mBarAnalyser.IsMomentumBar( + bar, + dir, + extendRange, + bodyPercent // + ); + result = + result && + dir == X_DIRECTION_BULLISH; + if (result) + { + // + XCMomentumBar *momentumBar; + momentumBar = new XCMomentumBar(); + result = momentumBar.Init(bar); + + // + if (result) + { + // + Add( + momentumBar, + mBullishMomentumBars // + ); + + // + // XCBullishMomentumObject *iObj; + // bool isCreated = mDrawer.CreateBullishMomentumBar( + // momentumBar, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bearish Momentum Bar ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBearishMomentumBar(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid() && + bar.Index() > 0; + if (!result) + { + return result; + } + + // + int extendRange = MomentumBarExtendRange(); + double bodyPercent = MomentumBarBodyPercent(); + ENUM_X_DIRECTION dir; + result = mBarAnalyser.IsMomentumBar( + bar, + dir, + extendRange, + bodyPercent // + ); + result = + result && + dir == X_DIRECTION_BEARISH; + if (result) + { + // + XCMomentumBar *momentumBar; + momentumBar = new XCMomentumBar(); + result = momentumBar.Init(bar); + + // + if (result) + { + // + Add( + momentumBar, + mBearishMomentumBars // + ); + + // + // XCBearishMomentumObject *iObj; + // bool isCreated = mDrawer.CreateBearishMomentumBar( + // momentumBar, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bullish Rejection Bar ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBullishRejectionBar(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid() && + bar.Index() > 0; + if (!result) + { + return result; + } + + // + int extendRange = RejectionBarExtendRange(); + double shadowPercent = RejectionBarShadowPercent(); + ENUM_X_DIRECTION dir; + result = mBarAnalyser.IsRejectionBar( + bar, + dir, + extendRange, + shadowPercent // + ); + result = + result && + dir == X_DIRECTION_BULLISH; + if (result) + { + // + XCRejectionBar *rejectionBar; + rejectionBar = new XCRejectionBar(); + result = rejectionBar.Init(bar); + + // + if (result) + { + // + Add( + rejectionBar, + mBullishRejectionBars // + ); + + // // + // XCBullishRejectionObject *iObj; + // bool isCreated = mDrawer.CreateBullishRejectionBar( + // rejectionBar, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bearish Rejection Bar ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBearishRejectionBar(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid() && + bar.Index() > 0; + if (!result) + { + return result; + } + + // + int extendRange = RejectionBarExtendRange(); + double shadowPercent = RejectionBarShadowPercent(); + ENUM_X_DIRECTION dir; + result = mBarAnalyser.IsRejectionBar( + bar, + dir, + extendRange, + shadowPercent // + ); + result = + result && + dir == X_DIRECTION_BEARISH; + if (result) + { + // + XCRejectionBar *rejectionBar; + rejectionBar = new XCRejectionBar(); + result = rejectionBar.Init(bar); + + // + if (result) + { + // + Add( + rejectionBar, + mBearishRejectionBars // + ); + + // + // XCBearishRejectionObject *iObj; + // bool isCreated = mDrawer.CreateBearishRejectionBar( + // rejectionBar, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Support Zone ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectSupportZone(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int range = SupportAndResistanceRange(); + int barIndex = bar.Index(); + result = range > 0 && + barIndex >= range; + if (!result) + { + return result; + } + + // + result = mBarAnalyser.IsSupport( + bar, + range // + ); + if (result) + { + // + XCSupportZone *support; + support = new XCSupportZone(); + result = support.Init( + bar, + range // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + support.To(cTime); + + // + Add( + support, + mSupportZones // + ); + + // // + // XCSupportZoneObject *iObj; + // bool isCreated = mDrawer.CreateSupportZone( + // support, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Resistance Zone ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectResistanceZone(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int range = SupportAndResistanceRange(); + int barIndex = bar.Index(); + result = range > 0 && + barIndex >= range; + if (!result) + { + return result; + } + + // + result = mBarAnalyser.IsResistance( + bar, + range // + ); + if (result) + { + // + XCResistanceZone *resistance; + resistance = new XCResistanceZone(); + result = resistance.Init( + bar, + range // + ); + + // + if (result) + { + // + Add( + resistance, + mResistanceZones // + ); + + // // + // XCResistanceZoneObject *iObj; + // bool isCreated = mDrawer.CreateResistanceZone( + // resistance, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Supply Zone ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectSupplyZone(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int range = SupplyAndDemandRange(); + result = range > 0; + if (!result) + { + return result; + } + + // + int hhIDX = -1; + double hh = -1; + + // + int llIDX = -1; + double ll = -1; + + // + result = mBarAnalyser + .CalculateLoopbackHLData( + hhIDX, + hh, + llIDX, + ll, + bar, + range // + ); + if (!result) + { + return result; + } + + // + XOHCL supplyBar; + result = supplyBar.Init( + bar.symbol, + bar.period, + hhIDX // + ); + if (result) + { + // + XCSupplyZone *supply; + supply = new XCSupplyZone(); + result = supply.Init( + supplyBar, + range // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + supply.To(cTime); + + // + Add( + supply, + mSupplyZones // + ); + + // // + // XCSupplyZoneObject *iObj; + // bool isCreated = mDrawer.CreateSupplyZone( + // supply, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Demand Zone ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectDemandZone(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int range = SupplyAndDemandRange(); + result = range > 0; + if (!result) + { + return result; + } + + // + int hhIDX = -1; + double hh = -1; + + // + int llIDX = -1; + double ll = -1; + + // + result = mBarAnalyser + .CalculateLoopbackHLData( + hhIDX, + hh, + llIDX, + ll, + bar, + range // + ); + if (!result) + { + return result; + } + + // + XOHCL demandBar; + result = demandBar.Init( + bar.symbol, + bar.period, + llIDX // + ); + if (result) + { + // + XCDemandZone *demand; + demand = new XCDemandZone(); + result = demand.Init( + demandBar, + range // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + demand.To(cTime); + + // + Add( + demand, + mDemandZones // + ); + + // // + // XCDemandZoneObject *iObj; + // bool isCreated = mDrawer.CreateDemandZone( + // demand, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bullish Order Block ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBullishOrderBlock(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int sameBars = OrderBlocksSameBars(); + result = sameBars > 0; + if (!result) + { + return result; + } + + // + XOHCL obBar; + ENUM_X_DIRECTION dir; + result = mBarAnalyser + .HasOrderBlock( + bar, + obBar, + dir, + sameBars // + ); + result = + result && + dir == X_DIRECTION_BULLISH; + if (!result) + { + return result; + } + + // + if (result) + { + // + XCOrderBlock *ob; + ob = new XCOrderBlock(); + result = ob.Init( + obBar, + dir // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + ob.To(cTime); + + // + Add( + ob, + mBullishOrderBlocks // + ); + + // // + // XCBullishOrderBlockObject *iObj; + // bool isCreated = mDrawer.CreateBullishOrderBlock( + // ob, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bullish Order Block ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBullishOrderBlock( + XOHCL &bar, + XCOrderBlock *&ob // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int sameBars = OrderBlocksSameBars(); + result = sameBars > 0; + if (!result) + { + return result; + } + + // + XOHCL obBar; + ENUM_X_DIRECTION dir; + result = mBarAnalyser + .HasOrderBlock( + bar, + obBar, + dir, + sameBars // + ); + result = + result && + dir == X_DIRECTION_BULLISH; + if (!result) + { + return result; + } + + // + if (result) + { + // + ob = new XCOrderBlock(); + result = ob.Init( + obBar, + dir // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + ob.To(cTime); + } + } + + // + return result; + } + + /** + * Detect Bearish Order Block ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBearishOrderBlock(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int sameBars = OrderBlocksSameBars(); + result = sameBars > 0; + if (!result) + { + return result; + } + + // + XOHCL obBar; + ENUM_X_DIRECTION dir; + result = mBarAnalyser + .HasOrderBlock( + bar, + obBar, + dir, + sameBars // + ); + result = + result && + dir == X_DIRECTION_BEARISH; + if (!result) + { + return result; + } + + // + if (result) + { + // + XCOrderBlock *ob; + ob = new XCOrderBlock(); + result = ob.Init( + obBar, + dir // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + ob.To(cTime); + + // + Add( + ob, + mBearishOrderBlocks // + ); + + // // + // XCBearishOrderBlockObject *iObj; + // bool isCreated = mDrawer.CreateBearishOrderBlock( + // ob, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bearish Order Block ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBearishOrderBlock( + XOHCL &bar, + XCOrderBlock *&ob // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int sameBars = OrderBlocksSameBars(); + result = sameBars > 0; + if (!result) + { + return result; + } + + // + XOHCL obBar; + ENUM_X_DIRECTION dir; + result = mBarAnalyser + .HasOrderBlock( + bar, + obBar, + dir, + sameBars // + ); + result = + result && + dir == X_DIRECTION_BEARISH; + if (!result) + { + return result; + } + + // + if (result) + { + // + ob = new XCOrderBlock(); + result = ob.Init( + obBar, + dir // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + ob.To(cTime); + } + } + + // + return result; + } + + /** + * Detect Bullish Fair Value Gap ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBullishFairValueGap(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int sameBars = FairValueGapsSameBars(); + result = sameBars > 0; + if (!result) + { + return result; + } + + // + XOHCL prevBar; + XOHCL nextBar; + ENUM_X_DIRECTION dir; + result = mBarAnalyser + .HasFairValueGap( + bar, + prevBar, + nextBar, + dir, + sameBars // + ); + result = + result && + dir == X_DIRECTION_BULLISH; + if (!result) + { + return result; + } + + // + if (result) + { + // + XCFVG *fvg; + fvg = new XCFVG(); + result = fvg.Init( + prevBar, + nextBar, + dir // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + fvg.To(cTime); + + // + Add( + fvg, + mBullishFairValueGaps // + ); + + // // + // XCBullishFairValueGapObject *iObj; + // bool isCreated = mDrawer.CreateBullishFairValueGap( + // fvg, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + + /** + * Detect Bearish Fair Value Gap ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool DetectBearishFairValueGap(XOHCL &bar) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int sameBars = FairValueGapsSameBars(); + result = sameBars > 0; + if (!result) + { + return result; + } + + // + XOHCL prevBar; + XOHCL nextBar; + ENUM_X_DIRECTION dir; + result = mBarAnalyser + .HasFairValueGap( + bar, + prevBar, + nextBar, + dir, + sameBars // + ); + result = + result && + dir == X_DIRECTION_BEARISH; + if (!result) + { + return result; + } + + // + if (result) + { + // + XCFVG *fvg; + fvg = new XCFVG(); + result = fvg.Init( + prevBar, + nextBar, + dir // + ); + + // + if (result) + { + // + datetime cTime = TimeCurrent(); + fvg.To(cTime); + + // + Add( + fvg, + mBearishFairValueGaps // + ); + + // // + // XCBearishFairValueGapObject *iObj; + // bool isCreated = mDrawer.CreateBearishFairValueGap( + // fvg, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + } + } + + // + return result; + } + // protected: // @@ -2036,76 +3273,6 @@ class XCPOIDetector : public XCBaseAlert // XCSwing *mSwingHighs[]; // Holds Founded Swing Highs ... - /** - * Detect Swing High ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSwingHigh(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SwingRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsSwingHigh( - bar, - range // - ); - if (result) - { - // - XCSwing *swing; - swing = new XCSwing(); - result = swing.Init( - bar, - X_POI_SWING_HIGH // - ); - - // - if (result) - { - // - Add( - swing, - mSwingHighs // - ); - - // - // XCSwingHighObject *iObj; - // bool isCreated = mDrawer.CreateSwingHigh( - // swing, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Swing Highs ... * @@ -2180,76 +3347,6 @@ class XCPOIDetector : public XCBaseAlert // XCSwing *mSwingLows[]; // Holds Founded Swing Lows ... - /** - * Detect Swing Low ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSwingLow(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SwingRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsSwingLow( - bar, - range // - ); - if (result) - { - // - XCSwing *swing; - swing = new XCSwing(); - result = swing.Init( - bar, - X_POI_SWING_LOW // - ); - - // - if (result) - { - // - Add( - swing, - mSwingLows // - ); - - // // - // XCSwingLowObject *iObj; - // bool isCreated = mDrawer.CreateSwingLow( - // swing, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Swing Lows ... * @@ -2327,72 +3424,6 @@ class XCPOIDetector : public XCBaseAlert // Bullish ... XCMomentumBar *mBullishMomentumBars[]; // Holds Founded Bullish Momentum Bars ... - /** - * Detect Bullish Momentum Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishMomentumBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = MomentumBarExtendRange(); - double bodyPercent = MomentumBarBodyPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsMomentumBar( - bar, - dir, - extendRange, - bodyPercent // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (result) - { - // - XCMomentumBar *momentumBar; - momentumBar = new XCMomentumBar(); - result = momentumBar.Init(bar); - - // - if (result) - { - // - Add( - momentumBar, - mBullishMomentumBars // - ); - - // - // XCBullishMomentumObject *iObj; - // bool isCreated = mDrawer.CreateBullishMomentumBar( - // momentumBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bullish Momentum Bars ... * @@ -2458,72 +3489,6 @@ class XCPOIDetector : public XCBaseAlert // Bearish ... XCMomentumBar *mBearishMomentumBars[]; // Holds Founded Bearish Momentum Bars ... - /** - * Detect Bearish Momentum Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishMomentumBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = MomentumBarExtendRange(); - double bodyPercent = MomentumBarBodyPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsMomentumBar( - bar, - dir, - extendRange, - bodyPercent // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (result) - { - // - XCMomentumBar *momentumBar; - momentumBar = new XCMomentumBar(); - result = momentumBar.Init(bar); - - // - if (result) - { - // - Add( - momentumBar, - mBearishMomentumBars // - ); - - // - // XCBearishMomentumObject *iObj; - // bool isCreated = mDrawer.CreateBearishMomentumBar( - // momentumBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bearish Momentum Bars ... * @@ -2594,72 +3559,6 @@ class XCPOIDetector : public XCBaseAlert // Bullish ... XCRejectionBar *mBullishRejectionBars[]; // Holds Founded Bullish Rejection Bars ... - /** - * Detect Bullish Rejection Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishRejectionBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = RejectionBarExtendRange(); - double shadowPercent = RejectionBarShadowPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsRejectionBar( - bar, - dir, - extendRange, - shadowPercent // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (result) - { - // - XCRejectionBar *rejectionBar; - rejectionBar = new XCRejectionBar(); - result = rejectionBar.Init(bar); - - // - if (result) - { - // - Add( - rejectionBar, - mBullishRejectionBars // - ); - - // // - // XCBullishRejectionObject *iObj; - // bool isCreated = mDrawer.CreateBullishRejectionBar( - // rejectionBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bullish Rejection Bars ... * @@ -2725,72 +3624,6 @@ class XCPOIDetector : public XCBaseAlert // Bearish ... XCRejectionBar *mBearishRejectionBars[]; // Holds Founded Bearish Rejection Bars ... - /** - * Detect Bearish Rejection Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishRejectionBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = RejectionBarExtendRange(); - double shadowPercent = RejectionBarShadowPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsRejectionBar( - bar, - dir, - extendRange, - shadowPercent // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (result) - { - // - XCRejectionBar *rejectionBar; - rejectionBar = new XCRejectionBar(); - result = rejectionBar.Init(bar); - - // - if (result) - { - // - Add( - rejectionBar, - mBearishRejectionBars // - ); - - // - // XCBearishRejectionObject *iObj; - // bool isCreated = mDrawer.CreateBearishRejectionBar( - // rejectionBar, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bearish Rejection Bars ... * @@ -2860,80 +3693,6 @@ class XCPOIDetector : public XCBaseAlert // Support Zone(s) ... XCSupportZone *mSupportZones[]; // Holds Founded Support Zones ... - /** - * Detect Support Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSupportZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupportAndResistanceRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsSupport( - bar, - range // - ); - if (result) - { - // - XCSupportZone *support; - support = new XCSupportZone(); - result = support.Init( - bar, - range // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - support.To(cTime); - - // - Add( - support, - mSupportZones // - ); - - // // - // XCSupportZoneObject *iObj; - // bool isCreated = mDrawer.CreateSupportZone( - // support, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Support Zones ... * @@ -3006,76 +3765,6 @@ class XCPOIDetector : public XCBaseAlert // Resistance Zone(s) ... XCResistanceZone *mResistanceZones[]; // Holds Founded Resistance Zones ... - /** - * Detect Resistance Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectResistanceZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupportAndResistanceRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsResistance( - bar, - range // - ); - if (result) - { - // - XCResistanceZone *resistance; - resistance = new XCResistanceZone(); - result = resistance.Init( - bar, - range // - ); - - // - if (result) - { - // - Add( - resistance, - mResistanceZones // - ); - - // // - // XCResistanceZoneObject *iObj; - // bool isCreated = mDrawer.CreateResistanceZone( - // resistance, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Resistance Zones ... * @@ -3152,103 +3841,6 @@ class XCPOIDetector : public XCBaseAlert // Supply Zone(s) ... XCSupplyZone *mSupplyZones[]; // Holds Founded Supply Zones ... - /** - * Detect Supply Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSupplyZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupplyAndDemandRange(); - result = range > 0; - if (!result) - { - return result; - } - - // - int hhIDX = -1; - double hh = -1; - - // - int llIDX = -1; - double ll = -1; - - // - result = mBarAnalyser - .CalculateLoopbackHLData( - hhIDX, - hh, - llIDX, - ll, - bar, - range // - ); - if (!result) - { - return result; - } - - // - XOHCL supplyBar; - result = supplyBar.Init( - bar.symbol, - bar.period, - hhIDX // - ); - if (result) - { - // - XCSupplyZone *supply; - supply = new XCSupplyZone(); - result = supply.Init( - supplyBar, - range // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - supply.To(cTime); - - // - Add( - supply, - mSupplyZones // - ); - - // // - // XCSupplyZoneObject *iObj; - // bool isCreated = mDrawer.CreateSupplyZone( - // supply, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Supply Zones ... * @@ -3321,103 +3913,6 @@ class XCPOIDetector : public XCBaseAlert // Demand Zone(s) ... XCDemandZone *mDemandZones[]; // Holds Founded Demand Zones ... - /** - * Detect Demand Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectDemandZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupplyAndDemandRange(); - result = range > 0; - if (!result) - { - return result; - } - - // - int hhIDX = -1; - double hh = -1; - - // - int llIDX = -1; - double ll = -1; - - // - result = mBarAnalyser - .CalculateLoopbackHLData( - hhIDX, - hh, - llIDX, - ll, - bar, - range // - ); - if (!result) - { - return result; - } - - // - XOHCL demandBar; - result = demandBar.Init( - bar.symbol, - bar.period, - llIDX // - ); - if (result) - { - // - XCDemandZone *demand; - demand = new XCDemandZone(); - result = demand.Init( - demandBar, - range // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - demand.To(cTime); - - // - Add( - demand, - mDemandZones // - ); - - // // - // XCDemandZoneObject *iObj; - // bool isCreated = mDrawer.CreateDemandZone( - // demand, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Demand Zones ... * @@ -3494,92 +3989,6 @@ class XCPOIDetector : public XCBaseAlert // Bullish OB ... XCOrderBlock *mBullishOrderBlocks[]; // Holds Founded Bullish Order Blocks ... - /** - * Detect Bullish Order Block ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishOrderBlock(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasOrderBlock( - bar, - obBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCOrderBlock *ob; - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - ob.To(cTime); - - // - Add( - ob, - mBullishOrderBlocks // - ); - - // // - // XCBullishOrderBlockObject *iObj; - // bool isCreated = mDrawer.CreateBullishOrderBlock( - // ob, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bullish Order Blocks ... * @@ -3652,92 +4061,6 @@ class XCPOIDetector : public XCBaseAlert // Bearish OB ... XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish Order Blocks ... - /** - * Detect Bearish Order Block ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishOrderBlock(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasOrderBlock( - bar, - obBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCOrderBlock *ob; - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - ob.To(cTime); - - // - Add( - ob, - mBearishOrderBlocks // - ); - - // // - // XCBearishOrderBlockObject *iObj; - // bool isCreated = mDrawer.CreateBearishOrderBlock( - // ob, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bearish Order Blocks ... * @@ -3814,95 +4137,6 @@ class XCPOIDetector : public XCBaseAlert // Bullish FVG ... XCFVG *mBullishFairValueGaps[]; // Holds Founded Bullish Fair Value Gaps ... - /** - * Detect Bullish Fair Value Gap ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishFairValueGap(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = FairValueGapsSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL prevBar; - XOHCL nextBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasFairValueGap( - bar, - prevBar, - nextBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCFVG *fvg; - fvg = new XCFVG(); - result = fvg.Init( - prevBar, - nextBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - fvg.To(cTime); - - // - Add( - fvg, - mBullishFairValueGaps // - ); - - // // - // XCBullishFairValueGapObject *iObj; - // bool isCreated = mDrawer.CreateBullishFairValueGap( - // fvg, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bullish Fair Value Gaps ... * @@ -3975,95 +4209,6 @@ class XCPOIDetector : public XCBaseAlert // Bearish FVG ... XCFVG *mBearishFairValueGaps[]; // Holds Founded Bearish Fair Value Gaps ... - /** - * Detect Bearish Fair Value Gap ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishFairValueGap(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = FairValueGapsSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL prevBar; - XOHCL nextBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasFairValueGap( - bar, - prevBar, - nextBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCFVG *fvg; - fvg = new XCFVG(); - result = fvg.Init( - prevBar, - nextBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - fvg.To(cTime); - - // - Add( - fvg, - mBearishFairValueGaps // - ); - - // // - // XCBearishFairValueGapObject *iObj; - // bool isCreated = mDrawer.CreateBearishFairValueGap( - // fvg, - // iObj // - // ); - // if (isCreated) - // { - // AddObjectIfNotExists(iObj); - // } - } - } - - // - return result; - } - /** * Detect Required Bearish Fair Value Gaps ... * diff --git a/Documents/BKP/test.stategy.mq5 b/Documents/BKP/test.stategy.mq5 new file mode 100644 index 00000000..16d7606c --- /dev/null +++ b/Documents/BKP/test.stategy.mq5 @@ -0,0 +1,214 @@ + // + // Draw Last Sar Change ... + string iVLineName = sarChangeBar.GetTag("XSAR"); + CChartObjectVLine *iVLineObj; + iVLineObj = new CChartObjectVLine(); + result = iVLineObj.Create( + ChartID(), + iVLineName, + 0, + sarChangeBar.time // + ); + if (result) + { + iVLineObj.Color(clrYellow); + } + + + + // + // Draw Last Decision Bar ... + string iVLineNameDecision = decisionBar.GetTag("XDECISION"); + CChartObjectVLine *iVLineDecisionObj; + iVLineDecisionObj = new CChartObjectVLine(); + result = iVLineDecisionObj.Create( + ChartID(), + iVLineNameDecision, + 0, + decisionBar.time // + ); + if (result) + { + iVLineDecisionObj.Color(clrYellow); + } + + + // + // Draw Breaker Bar ... + string iVLineNameBreaker = breakerBar.GetTag("XBREAKER"); + CChartObjectVLine *iVLineBreakerObj; + iVLineBreakerObj = new CChartObjectVLine(); + result = iVLineBreakerObj.Create( + ChartID(), + iVLineNameBreaker, + 0, + breakerBar.time // + ); + if (result) + { + iVLineBreakerObj.Color(clrMagenta); + } + + + + // + // TODO: Remove This ... + bool ignoreSwingHighs = true; + bool ignoreSwingLows = true; + bool ignoreSupportZones = true; + bool ignoreResistanceZones = true; + bool ignoreSupplyZones = true; + bool ignoreDemandZones = true; + bool ignoreBullishOrderBlocks = true; + bool ignoreBearishOrderBlocks = true; + bool ignoreBullishFairValueGaps = true; + bool ignoreBearishFairValueGaps = true; + bool ignoreBullishRejectionBars = true; + bool ignoreBearishRejectionBars = true; + bool ignoreBullishMomentumBars = true; + bool ignoreBearishMomentumBars = true; + + // + if (IsBullish(marketStructureDir)) + { + // + ignoreSwingLows = true; + ignoreSupportZones = true; + ignoreDemandZones = true; + ignoreBullishOrderBlocks = true; + ignoreBullishFairValueGaps = false; + ignoreBullishRejectionBars = false; + ignoreBullishMomentumBars = false; + + // + ignoreSwingHighs = true; + ignoreResistanceZones = true; + ignoreSupplyZones = true; + ignoreBearishOrderBlocks = true; + ignoreBearishFairValueGaps = true; + ignoreBearishRejectionBars = true; + ignoreBearishMomentumBars = true; + } + else + { + // + ignoreSwingLows = true; + ignoreSupportZones = true; + ignoreDemandZones = true; + ignoreBullishOrderBlocks = true; + ignoreBullishFairValueGaps = true; + ignoreBullishRejectionBars = true; + ignoreBullishMomentumBars = true; + + // + ignoreSwingHighs = true; + ignoreResistanceZones = true; + ignoreSupplyZones = true; + ignoreBearishOrderBlocks = true; + ignoreBearishFairValueGaps = false; + ignoreBearishRejectionBars = false; + ignoreBearishMomentumBars = false; + } + + // + RedrawOrderFlow( + true, // Force Clean ... + false, // Same Period ... + true, // Order Flow ... + true, // Order Flow State ... + false, // Only Last Order Flow ... + true, // Only Last Order Flow State ... + // + marketStructureDir, // Direction Force ... + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + + + +///////////////////////////////////////////////////// + + /** + * Validate an Order Block is Not Touched ... + * + * @param bar: XOHCL instance, start bar ... + * + * @return ( bool ) + */ + bool ValidateOrderBlock( + XCOrderBlock *ob, + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = + bar.IsValid() && + ob.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = ob.IsBullish(); + + // + XOHCL mBar; + result = bar.BarIn(ob.GetPeriod(), mBar); + if (!result) { + return result; + } + + // + int start = mBar.Index(); + int end = mBar.Index(ob.From()); + result = IsValidIndex(start) && + IsValidIndex(end); + if (!result) + { + return result; + } + + // + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + result = mBar.BarAt( + i, + iBar // + ); + if (!result) + { + break; + } + + // + result = + isBullish + ? iBar.low > ob.Upper() + : iBar.high < ob.Lower(); + if (!result) + { + break; + } + } + + // + return result; + } diff --git a/Documents/BKP/tmp.x121.smc.mq5 b/Documents/BKP/tmp.x121.smc.mq5 index b2aac98e..5730d7c0 100644 --- a/Documents/BKP/tmp.x121.smc.mq5 +++ b/Documents/BKP/tmp.x121.smc.mq5 @@ -2148,3 +2148,116 @@ // } + + +//////////////////////////////////////// + + + bool canContinue = true; + while (canContinue) + { + // + XOHCL iBar; + bool isBarInited = iBar.Init( + mBar.symbol, + mBar.period, + barIndex // + ); + if (!isBarInited) + { + break; + } + + // + if (bullOB == NULL) + { + // + XCOrderBlock *ob; + bool isBullOB = cycleHelper + .mPOIDetector + .DetectBullishOrderBlock( + mBar, + ob // + ); + if (isBullOB) + { + // + bool isPricePassed = bar.low > ob.Upper(); + if (isPricePassed) + { + // + if (mBullOB == NULL) + { + // + mBullOB = ob; + } + else + { + // + bool isRefined = mBullOB.Upper() < ob.Upper(); + if (isRefined) + { + mBullOB = ob; + } + } + } + } + } + + // + if (bearOB == NULL) + { + // + XCOrderBlock *ob; + bool isBearOB = cycleHelper + .mPOIDetector + .DetectBearishOrderBlock( + mBar, + ob // + ); + if (isBearOB) + { + // + bool isPricePassed = bar.high < ob.Lower(); + if (isPricePassed) + { + // + if (mBearOB == NULL) + { + // + mBearOB = ob; + } + else + { + // + bool isRefined = mBearOB.Lower() > ob.Lower(); + if (isRefined) + { + mBearOB = ob; + } + } + } + } + } + + // + canContinue = + (bullOB == NULL && mBullOB == NULL) || + (bearOB == NULL && mBearOB == NULL); + if (canContinue) + { + barIndex++; + } + } + + // + if (mBullOB != NULL) + { + bullOB = mBullOB; + } + + // + if (mBearOB != NULL) + { + bearOB = mBearOB; + } diff --git a/Documents/BKP/x-121.smc.test.strategy.class.mq5 b/Documents/BKP/x-121.smc.test.strategy.class.mq5 new file mode 100644 index 00000000..74023567 --- /dev/null +++ b/Documents/BKP/x-121.smc.test.strategy.class.mq5 @@ -0,0 +1,2807 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XCX121SMCTestStrategy +// Description: provides all based classes for use ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... + +// +#include "../Classes/x-121.smc.base.strategy.class.mq5" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" + +// +// Definitions ... + +// +// XStrategy Class Implementation(s) ... +class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy +{ + // + // Public ... + public: + // + + // + // Constructor(s) ... + void XCX121SMCTestStrategy( + // + // Base ... + string _symbol, // Trading Symbol + ENUM_TIMEFRAMES _period // Trading TimeFrame + ) + : XCX121SMCBaseStrategy(_symbol, _period) + { + InitialHelpers(); + } + + // + // Deconstructur ... + void ~XCX121SMCTestStrategy() + { + } + + // + // Overrides Actions ... + + /** + * Destroy All Class Implementations ... + */ + void Destroy() override + { + // + delete mTriggerCycleHelper; + delete mDecisionCycleHelper; + delete mAnalyseCycleHelper; + delete mVerificationCycleHelper; + delete mConsolidationCycleHelper; + delete mVisionCycleHelper; + } + + /** + * Check Conditions For Signal ... + */ + bool HasSignal( + XSignal &signal, + X121SMCStrategyConditions &conditions // + ) override + { + // + bool result = false; + + // + signal.Clean(); + conditions.Clean(); + + // + int pushers = 0; + + // + double sl = 0; + double tp = 0; + double risk = 0; + double entry = 0; + double reward = 0; + double r2r = R2R(); + string provider = ""; + double volume = Volume(); + ENUM_POSITION_TYPE type = POSITION_TYPE_BUY; + ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; + + // + bool hasLong = false; + bool hasShort = false; + + // + double selectedSL = 0; + + // + // Start Calculations ... + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + double points = GetPoints(symbol); + double pip = GetPipPrice(symbol); + double pip2 = 2 * pip; + + // + // Check Spread ... + bool isSpreadPassed = IsSpreadPass(); + result = isSpreadPassed; + if (!result) + { + // + // string message = "Spread is not Passed for Analysing ..."; + // LogAlert(message); + + // + return result; + } + + // + // Detect Conditions ... + result = DetectConditions(conditions); + if (!result) + { + conditions.Clean(); + return result; + } + + // + // Combine all Signals Conditions ... + selectedSL = conditions.sl; + provider = conditions.provider; + + // + hasLong = + // + IsBullish(conditions.marketStructureDir) + // + ; + + // + hasShort = + // + IsBearish(conditions.marketStructureDir) + // + ; + + // + result = hasLong || + hasShort; + + // + // Rmove Signal Condition ... + if (result) + { + // + // TYPE ... + type = + hasLong + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + ENUM_X_POSITION_TYPES xType = + hasLong + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + entry = GetEntry( + conditions.symbol, + type // + ); + + // + sl = + hasLong + ? selectedSL - pip2 + : selectedSL + pip2; + + // + // RISK Reward ... + risk = + hasLong + ? entry - sl + : sl - entry; + reward = risk * r2r; + tp = + hasLong + ? entry + reward + : entry - reward; + + // + signal.sl = sl; + signal.tp = tp; + signal.type = type; + signal.mode = mode; + signal.entry = entry; + signal.volume = volume; + signal.symbol = symbol; + signal.period = period; + signal.pushers = pushers; + signal.provider = provider; + signal.time = TimeCurrent(); + + // + result = PrepareSignal(signal); + if (result) + { + // + Print("PRV: ", provider); + + // + ENUM_X_DIRECTION forDir = ToDirection(signal.type); + bool ignoreSwingHighs = false; + bool ignoreSwingLows = false; + bool ignoreSupportZones = false; + bool ignoreResistanceZones = false; + bool ignoreSupplyZones = false; + bool ignoreDemandZones = false; + bool ignoreBullishOrderBlocks = false; + bool ignoreBearishOrderBlocks = false; + bool ignoreBullishFairValueGaps = false; + bool ignoreBearishFairValueGaps = false; + bool ignoreBullishRejectionBars = false; + bool ignoreBearishRejectionBars = false; + bool ignoreBullishMomentumBars = false; + bool ignoreBearishMomentumBars = false; + if (IsBullish(forDir)) + { + // + ignoreSwingLows = false; + ignoreDemandZones = false; + ignoreSupportZones = false; + ignoreBullishOrderBlocks = false; + ignoreBullishFairValueGaps = false; + ignoreBullishRejectionBars = false; + ignoreBullishMomentumBars = false; + } + else + { + // + ignoreSwingHighs = true; + ignoreSupplyZones = true; + ignoreResistanceZones = true; + ignoreBearishOrderBlocks = true; + ignoreBearishFairValueGaps = false; + ignoreBearishRejectionBars = true; + ignoreBearishMomentumBars = true; + } + + // + RedrawOrderFlow( + true, // Force Clean ... + false, // Same Period ... + true, // Order Flow ... + true, // Order Flow State ... + false, // Only Last Order Flow ... + true, // Only Last Order Flow State ... + // + forDir, // Direction Force ... + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + DrawSignal(signal); + ClearDraws(); + + // + ResetOrderFlow(); + } + + // + hasLong = false; + hasShort = false; + } + + // + return result; + } + + /** + * Customize Strategy Identifier ... + */ + string GetTag() override + { + return X121SMCStrategyToken; + } + + // + // Protected ... + protected: + // + + // + // Props ... + + // + // Trigger Order Flow ... + XPVPivot mOrderFlow[]; + ENUM_X_DIRECTION mOrderFlowDir; + + // + XC121SMCCycleHelper *mTriggerCycleHelper; + XC121SMCCycleHelper *mDecisionCycleHelper; + XC121SMCCycleHelper *mAnalyseCycleHelper; + XC121SMCCycleHelper *mVerificationCycleHelper; + XC121SMCCycleHelper *mConsolidationCycleHelper; + XC121SMCCycleHelper *mVisionCycleHelper; + + // + // Actions ... + + /** + * Detect and Parse Market Conditions ... + * + * @return ( bool ) + */ + bool DetectConditions( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + string msg = NULL; + + // + double bid = GetBid(symbol); + + // + conditions.symbol = symbol; + conditions.period = period; + conditions.time = TimeCurrent(); + + // + int conditionsLoopback = 7; + + // + // Fill Cycles Conditions ... + + // + // Trigger ... + mTriggerCycleHelper.GetConditions( + conditions.triggerConditions, + zIndex, + conditionsLoopback // + ); + conditions.triggerConditions.state = mTriggerState; + + // + // Decision ... + mDecisionCycleHelper.GetConditions( + conditions.decisionConditions, + zIndex, + conditionsLoopback // + ); + conditions.decisionConditions.state = mDecisionState; + + // + // Analyse ... + mAnalyseCycleHelper.GetConditions( + conditions.analyseConditions, + zIndex, + conditionsLoopback // + ); + conditions.analyseConditions.state = mAnalyseState; + + // + // Verification ... + mVerificationCycleHelper.GetConditions( + conditions.verificationConditions, + zIndex, + conditionsLoopback // + ); + conditions.verificationConditions.state = mVerificationState; + + // + // Consolidation ... + mConsolidationCycleHelper.GetConditions( + conditions.consolidationConditions, + zIndex, + conditionsLoopback // + ); + conditions.consolidationConditions.state = mConsolidationState; + + // + // Vision ... + mVisionCycleHelper.GetConditions( + conditions.visionConditions, + zIndex, + conditionsLoopback // + ); + conditions.visionConditions.state = mVisionState; + + // + // Check Market Conditions for + // Specified Structure ... + ENUM_X_DIRECTION marketStructureDir = X_DIRECTION_NONE; + result = conditions.HasDirection( + marketStructureDir, + cBar // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + msg = "Found Market Strucutre : " + (IsBullish(marketStructureDir) ? "Bullish" : "Berish"); + Alert(msg); + + // // + // // Detect Trigger Order Flow ... + // if (ArraySize(mOrderFlow) == 0 || + // mOrderFlowDir == X_DIRECTION_NONE) + // { + // // + // int samePivots = 40; + // int requiredPivots = 10; + + // // + // bool useVisionState = false; + // bool useConsolidationState = false; + // bool useVerificationState = false; + // bool useAnalyseState = false; + // bool useDecisionState = true; + // bool useTriggerState = false; + + // // + // DetectOrderFlow( + // cIndex, + // samePivots, + // requiredPivots, + // mTriggerCycleHelper, + // mOrderFlow, + // mOrderFlowDir, + // // + // // Filling Pivot State ... + // useVisionState, // Use Vision State ... + // useConsolidationState, // Use Consolidation State ... + // useVerificationState, // Use Verification State ... + // useAnalyseState, // Use Analyse State ... + // useDecisionState, // Use Decision State ... + // useTriggerState // Use Trigger State ... + // ); + + // // + // result = IsValidSize(ArraySize(mOrderFlow)); + // if (!result) + // { + // return result; + // } + // } + // result = HasValidOrderFlow() && + // mOrderFlowDir == marketStructureDir; + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + // msg = "Found OrderFlow : " + (IsBullish(mOrderFlowDir) ? "Bullish" : "Berish"); + // Alert(msg); + + // + conditions.marketStructureDir = marketStructureDir; + + // // + // XPVPivot lastPivot; + // result = GetLastItem( + // lastPivot, + // mOrderFlow // + // ); + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + + // + // Detect Last FVG ... + // XOHCL breakerBar; + // result = DetectLastBreakerBar( + // cBar, + // breakerBar, + // lastPivot, + // marketStructureDir // + // ); + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + // msg = "Found Breaker Bar: " + breakerBar.GetTag(); + // Alert(msg); + + // + // Detect Nearest Momentum or Rejection Bar ... + XOHCL decisionBar; + result = mDecisionCycleHelper.DetectNearestDecisionBar( + decisionBar, + marketStructureDir, + cBar // + ); + if (!result) + { + return result; + } + msg = "Found Decision Bar: " + decisionBar.GetTag(); + Alert(msg); + + // + // Detect Nearest Sar Change ... + XOHCL sarChangeBar; + result = mTriggerCycleHelper.DetectNearestCSARChange( + sarChangeBar, + cBar // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + msg = "Found Sar Change Bar: " + sarChangeBar.GetTag(); + Alert(msg); + + // + // Now we Hvae to Check Other Conditions ... + result = + // breakerBar.time > sarChangeBar.time && + // decisionBar.time > breakerBar.time; + decisionBar.time > sarChangeBar.time; + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + // Now we Have Check Direction Related Conditions ... + if (IsBullish(marketStructureDir)) + { + // + result = + // bid > decisionBar.high && + // bid > breakerBar.high && + bid > sarChangeBar.high && + bid > conditions.triggerConditions.xchsarConditions.cSars[0]; + } + else + { + // + result = + // bid < decisionBar.low && + // bid < breakerBar.low && + bid < sarChangeBar.high && + bid < conditions.triggerConditions.xchsarConditions.cSars[0]; + } + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + conditions.provider = "X121SMC"; + if (IsBullish(marketStructureDir)) + { + // + // conditions.sl = decisionBar.low; + // conditions.sl = breakerBar.low; + conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; + } + else + { + // + // conditions.sl = decisionBar.high; + // conditions.sl = breakerBar.high; + conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; + } + + // + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + return result; + } + + /** + * Detect XPV Based POI(s) ... + * + * @param barIndex: Start Bar Index ... + * @param minRepetition: minimum Repeate of POI for Validation ... + * @param requiredPivots: Number of Min Requirement POI(s) ... + * @param pivotHelper: XC121SMCCycleHelper instance Pointer ... + * @param orderFlow: XPVPivot instance Array Reference ... + * @param orderFlowDirection: ENUM_X_DIRECTION member Reference which represents OrderFlow Direction ... + * @param maxAllowedLoopbackBars: Integer, Max Allowed Loopback Bars ... + * + * @return ( bool ) + */ + bool DetectOrderFlow( + int barIndex, + int minRepetition, + int requiredPivots, + XC121SMCCycleHelper *pivotHelper, // XPV Helper ... + XPVPivot &orderFlow[], // OrderFlows ... + ENUM_X_DIRECTION &orderFlowDirection, // Order Flow Direction ... + // + bool useVisionState = true, // Use Vision State ... + bool useConsolidationState = true, // Use Consolidation State ... + bool useVerificationState = true, // Use Verification State ... + bool useAnalyseState = true, // Use Analyse State ... + bool useDecisionState = true, // Use Decision State ... + bool useTriggerState = true, // Use Trigger State ... + // + int maxAllowedLoopbackBars = 576 // + ) + { + // + bool result = false; + + // + orderFlowDirection = X_DIRECTION_NONE; + + // + if (maxAllowedLoopbackBars <= 0) + { + maxAllowedLoopbackBars = 1000; + } + + // + int start = barIndex; + int end = start + maxAllowedLoopbackBars; + + // + Clean(orderFlow); + + // + result = minRepetition > 0 && + requiredPivots > 0 && + pivotHelper != NULL; + if (!result) + { + return result; + } + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + double peak = 0; + XPVPivot peaks[]; + int peakRepeate = 0; + int peakToBarIndex = 0; + int peakFromBarIndex = 0; + + // + double vale = 0; + XPVPivot vales[]; + int valeRepeate = 0; + int valeToBarIndex = 0; + int valeFromBarIndex = 0; + + // + bool canLookupPeak = true; + bool canLookupVale = true; + bool canLookup = true; + while (canLookup) + { + // + // Check Peak ... + double iPeak = pivotHelper.mXPVHelper.GetPeak(barIndex); + if (iPeak != peak) + { + // + if (peak != 0 && + peakRepeate >= minRepetition) + { + // + bool isExists = false; + int count = ArraySize(peaks); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XPVPivot iPivot = peaks[i]; + + // + if (iPivot.upper == iPeak) + { + // + isExists = true; + break; + } + } + } + if (!isExists) + { + // + XPVPivot iPivot; + + // + iPivot.lower = 0; + iPivot.upper = peak; + iPivot.symbol = symbol; + iPivot.period = period; + iPivot.type = XPV_PEAK; + iPivot.repetition = peakRepeate; + iPivot.to = iTime( + symbol, + period, + peakToBarIndex // + ); + iPivot.from = iTime( + symbol, + period, + peakFromBarIndex // + ); + + // + iPivot.lower = iPivot.CalculateLower(); + + // + bool isValid = iPivot.IsValid(); + if (isValid) + { + // + AddRef( + iPivot, + peaks // + ); + } + } + } + + // + peak = iPeak; + peakRepeate = 0; + peakFromBarIndex = 0; + peakToBarIndex = barIndex; + } + else if (iPeak == peak) + { + // + peakRepeate++; + peakFromBarIndex = barIndex; + } + + // + // Check Vale ... + double iVale = pivotHelper.mXPVHelper.GetVale(barIndex); + if (iVale != vale) + { + // + if (vale != 0 && + valeRepeate >= minRepetition) + { + // + bool isExists = false; + int count = ArraySize(vales); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XPVPivot iPivot = vales[i]; + + // + if (iPivot.lower == iVale) + { + // + isExists = true; + break; + } + } + } + if (!isExists) + { + // + XPVPivot iPivot; + + // + iPivot.upper = 0; + iPivot.lower = vale; + iPivot.symbol = symbol; + iPivot.period = period; + iPivot.type = XPV_VALE; + iPivot.repetition = valeRepeate; + iPivot.to = iTime( + symbol, + period, + valeToBarIndex // + ); + iPivot.from = iTime( + symbol, + period, + valeFromBarIndex // + ); + + // + iPivot.upper = iPivot.CalculateUpper(); + + // + bool isValid = iPivot.IsValid(); + if (isValid) + { + // + AddRef( + iPivot, + vales // + ); + } + } + } + + // + vale = iVale; + valeRepeate = 0; + valeFromBarIndex = 0; + valeToBarIndex = barIndex; + } + else if (iVale == vale) + { + // + valeRepeate++; + valeFromBarIndex = barIndex; + } + + // + canLookupPeak = ArraySize(peaks) < requiredPivots; + canLookupVale = ArraySize(vales) < requiredPivots; + canLookup = barIndex < end && + (canLookupPeak || + canLookupVale); + if (canLookup) + { + barIndex++; + } + } + + // + result = IsValidSize(ArraySize(peaks)) || + IsValidSize(ArraySize(vales)); + if (!result) + { + return result; + } + + // + // Detect Order Flow ... + Copy( + peaks, + orderFlow, + false // + ); + Copy( + vales, + orderFlow, + false // + ); + int count = ArraySize(orderFlow); + result = IsValidSize(orderFlow); + if (!result) + { + return result; + } + + // + // Sort Pivots ... + SortPivots(orderFlow); + + // + // Filter Broken Order Flows ... + FilterBrokenPivots(orderFlow); + + // + // Detect Order Flow Direction ... + result = DetectPivotDirection( + orderFlow, + orderFlowDirection // + ); + if (!result) + { + return result; + } + + // + // Find State Inside Pivots and Attached Them to Pivot ... + int orderFlowCount = ArraySize(mOrderFlow); + if (IsValidSize(orderFlowCount)) + { + // + // Loop Through Order Flow ... + for (int i = 0; i < orderFlowCount; i++) + { + // + FillPivotSate( + i, + useVisionState, // Use Vision State ... + useConsolidationState, // Use Consolidation State ... + useVerificationState, // Use Verification State ... + useAnalyseState, // Use Analyse State ... + useDecisionState, // Use Decision State ... + useTriggerState // Use Trigger State ... + ); + } + } + + // + return result; + } + + /** + * Filling Specified Orer Flow Index ... + * + * @param pivotIDX: Integer ... + * @param lookupSwingHighs: Boolean ... + * @param lookupSwingLows: Boolean ... + * @param lookupSupportZones: Boolean ... + * @param lookupResistanceZones: Boolean ... + * @param lookupSupplyZones: Boolean ... + * @param lookupDemandZones: Boolean ... + * @param lookupBullishOrderBlocks: Boolean ... + * @param lookupBearishOrderBlocks: Boolean ... + * @param lookupBullishFairValueGaps: Boolean ... + * @param lookupBearishFairValueGaps: Boolean ... + * @param lookupBullishRejectionBars: Boolean ... + * @param lookupBearishRejectionBars: Boolean ... + * @param lookupBullishMomentumBars: Boolean ... + * @param lookupBearishMomentumBars: Boolean ... + */ + void FillPivotSate( + int pivotIDX, // + bool useVisionState = true, // Use Vision State ... + bool useConsolidationState = true, // Use Consolidation State ... + bool useVerificationState = true, // Use Verification State ... + bool useAnalyseState = true, // Use Analyse State ... + bool useDecisionState = true, // Use Decision State ... + bool useTriggerState = true, // Use Trigger State ... + bool lookupSwingHighs = true, + bool lookupSwingLows = true, + bool lookupSupportZones = true, + bool lookupResistanceZones = true, + bool lookupSupplyZones = true, + bool lookupDemandZones = true, + bool lookupBullishOrderBlocks = true, + bool lookupBearishOrderBlocks = true, + bool lookupBullishFairValueGaps = true, + bool lookupBearishFairValueGaps = true, + bool lookupBullishRejectionBars = true, + bool lookupBearishRejectionBars = true, + bool lookupBullishMomentumBars = true, + bool lookupBearishMomentumBars = true // + ) + { + // + CalculatePivotTickZone(pivotIDX); + + // + // Trigger ... + XPOIState mPivotTriggerState; + if (useTriggerState && + mTriggerState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mTriggerState, + mPivotTriggerState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mPivotTriggerState.HasChild()) + { + mPivotTriggerState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Decision ... + XPOIState mPivotDecisionState; + if (useDecisionState && + mDecisionState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mDecisionState, + mPivotDecisionState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mPivotDecisionState.HasChild()) + { + mPivotDecisionState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Analyse ... + XPOIState mPivotAnalyseState; + if (useAnalyseState && + mAnalyseState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mAnalyseState, + mPivotAnalyseState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mPivotAnalyseState.HasChild()) + { + mPivotAnalyseState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Verification ... + XPOIState mPivotVerificationState; + if (useVerificationState && + mVerificationState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mVerificationState, + mPivotVerificationState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mPivotVerificationState.HasChild()) + { + mPivotVerificationState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Consolidation ... + XPOIState mPivotConsolidationState; + if (useConsolidationState && + mConsolidationState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mConsolidationState, + mPivotConsolidationState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mPivotConsolidationState.HasChild()) + { + mPivotConsolidationState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Vision ... + XPOIState mPivotVisionState; + if (useVisionState && + mVisionState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mVisionState, + mPivotVisionState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mPivotVisionState.HasChild()) + { + mPivotVisionState.Fill(mOrderFlow[pivotIDX].state); + } + } + } + + /** + * When a BOS Happens ... + * we have to Update Order Flow ... + */ + void UpdateOrderFlow() + { + ResetOrderFlow(); + } + + /** + * Fill Pivot Tick Zone ... + * + * @param pivotIDX: Integer ... + */ + void CalculatePivotTickZone(int pivotIDX) + { + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + bool isInited = false; + + // + datetime from = mOrderFlow[pivotIDX].from; + XOHCL iFromBar; + int iFromBarIndex = iBarShift( + symbol, + period, + from // + ); + isInited = iFromBar.Init( + symbol, + period, + iFromBarIndex // + ); + if (!isInited) + { + return; + } + + // + datetime to = mOrderFlow[pivotIDX].to; + XOHCL iToBar; + int iToBarIndex = iBarShift( + symbol, + period, + to // + ); + isInited = iToBar.Init( + symbol, + period, + iToBarIndex // + ); + if (!isInited) + { + return; + } + + // + XCTicksZone *iZone; + iZone = new XCTicksZone(); + + // + int ticksLevels = mTriggerDetector.TicksRangeZoneLevel(); + int ticksRange = mTriggerDetector.TicksRangeZoneRange(); + isInited = ticksLevels > 0 && + ticksRange > 0; + if (!isInited) + { + return; + } + + // + isInited = iZone.Init( + iFromBar, + iToBar // + ); + if (!isInited) + { + return; + } + + // + mOrderFlow[pivotIDX].state.ticksZone = iZone; + } + + /** + * Validate Order Flow ... + * + * @return ( bool ) + */ + bool HasValidOrderFlow() + { + // + bool result = false; + + // + int orderFlowCount = ArraySize(mOrderFlow); + result = + IsValidSize(orderFlowCount) && + mOrderFlowDir != X_DIRECTION_ALL && + mOrderFlowDir != X_DIRECTION_NONE; + + // + return result; + } + + /** + * Reset Order Flow ... + */ + void ResetOrderFlow() + { + // + Clean(mOrderFlow); + mOrderFlowDir = X_DIRECTION_NONE; + + // + ClearDraws(); + } + + /** + * Detect Breaker Bar ... + * + * @param bar: XOHCL instance ... + * @param breakerBar: XOHCL instance, Breaker Bar ... + * @param pivot: XPVPivot instance ... + * @param forDir: ENUM_X_DIRECTION member, Market Structure Direction ... + * + * @return ( bool ) + */ + bool DetectLastBreakerBar( + XOHCL &bar, + XOHCL &breakerBar, + XPVPivot &pivot, + ENUM_X_DIRECTION forDir // + ) + { + // + bool result = false; + + // + result = + bar.IsValid() && + pivot.IsValid() && + forDir != X_DIRECTION_ALL && + forDir != X_DIRECTION_NONE; + if (!result) + { + return result; + } + + // + // FVG ... + result = DetectLastFVGBreakerBar( + bar, + breakerBar, + pivot, + forDir // + ); + if (result) + { + return result; + } + + // + // Order Block ... + // result = DetectLastOBBreakerBar( + // bar, + // breakerBar, + // pivot, + // forDir // + // ); + // if (result) + // { + // return result; + // } + + // + return result; + } + + bool DetectLastFVGBreakerBar( + XOHCL &bar, + XOHCL &breakerBar, + XPVPivot &pivot, + ENUM_X_DIRECTION forDir // + ) + { + // + bool result = false; + + // + result = + bar.IsValid() && + pivot.IsValid() && + forDir != X_DIRECTION_ALL && + forDir != X_DIRECTION_NONE; + if (!result) + { + return result; + } + + // + bool isBullishDir = IsBullish(forDir); + + // + int fvgsCount = + isBullishDir + ? pivot.state.CountBullishFairValueGaps() + : pivot.state.CountBearishFairValueGaps(); + result = IsValidSize(fvgsCount); + if (!result) + { + return result; + } + + // + int idx = -1; + XCFVG *zone = NULL; + for (int i = 0; i < fvgsCount; i++) + { + // + if (isBullishDir) + { + // + // Bullish FVG ... + if (zone == NULL) + { + // + zone = pivot.state.bullishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + else + { + // + bool isNewer = ((int)zone.From() - (int)bar.time) > ((int)pivot.state.bullishFairValueGaps[i].From() - (int)bar.time); + if (isNewer) + { + // + zone = pivot.state.bullishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + } + } + else + { + // + // Bearish FVG ... + if (zone == NULL) + { + // + zone = pivot.state.bearishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + else + { + // + bool isNewer = ((int)zone.From() - (int)bar.time) > ((int)pivot.state.bearishFairValueGaps[i].From() - (int)bar.time); + if (isNewer) + { + // + zone = pivot.state.bearishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + } + } + } + + // + result = + breakerBar.IsValid() && + IsValidIndex(idx) && + zone.IsValid(); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Check an FVG is Breaked or not ... + * + * @param forDir: ENUM_X_DIRECTION member, Market Structure Direction ... + * @param bar: XOHCL instance ... + * @param breakerBar: XOHCL instance, Breaker Bar ... + * + * @return ( bool ) + */ + bool CheckZoneBreak( + ENUM_X_DIRECTION forDir, + XOHCL &bar, + XOHCL &breakerBar, + XCFVG *&zone // + ) + { + // + bool result = false; + + // + breakerBar.Clean(); + + // + result = bar.IsValid() && + zone.IsValid() && + forDir != X_DIRECTION_ALL && + forDir != X_DIRECTION_NONE; + if (!result) + { + return result; + } + + // + int start = bar.Index(); + int end = iBarShift( + bar.symbol, + bar.period, + zone.From()); + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + if (IsBullish(forDir)) + { + // + // Bullish Break ... + result = iBar.low < zone.Upper() && + iBar.high > zone.Upper() && + iBar.GetDown() < zone.Upper() && + iBar.GetUp() > zone.Upper() && + iBar.IsBullish(); + } + else + { + // + // Bearish Break ... + result = iBar.low < zone.Lower() && + iBar.high > zone.Lower() && + iBar.GetDown() < zone.Lower() && + iBar.GetUp() > zone.Lower() && + iBar.IsBearish(); + } + + // + if (result) + { + // + breakerBar = iBar; + break; + } + } + + // + result = breakerBar.IsValid(); + + // + return result; + } + + // + // Drawings ... + + /** + * Draw Order Flow ... + */ + void RedrawOrderFlow( + bool forceClearDraws = true, + bool forceDrawSamePeriod = true, + bool drawOrderFlow = true, + bool drawOrderFlowState = true, + bool drawOnlyLastOrderFlow = false, + bool drawOnlyLastOrderFlowState = true, + // + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + // + // Ignores List ... + bool ignoreSwingHighs = false, + bool ignoreSwingLows = false, + bool ignoreSupportZones = false, + bool ignoreResistanceZones = false, + bool ignoreSupplyZones = false, + bool ignoreDemandZones = false, + bool ignoreBullishOrderBlocks = false, + bool ignoreBearishOrderBlocks = false, + bool ignoreBullishFairValueGaps = false, + bool ignoreBearishFairValueGaps = false, + bool ignoreBullishRejectionBars = false, + bool ignoreBearishRejectionBars = false, + bool ignoreBullishMomentumBars = false, + bool ignoreBearishMomentumBars = false, + // + // States Drawing ... + bool drawVisionState = false, + bool drawConsolidationState = false, + bool drawVerificationState = false, + bool drawAnalyseState = false, + bool drawDecisionState = false, + bool drawTriggerState = false // + ) + { + // + if (forceClearDraws) + { + ClearDraws(); + } + + // + if (!drawOrderFlow || + !HasValidOrderFlow()) + { + return; + } + + // + int orderFlowCount = ArraySize(mOrderFlow); + for (int i = 0; i < orderFlowCount; i++) + { + // + bool isLast = i == orderFlowCount - 1; + bool canDraw = + !drawOnlyLastOrderFlow || + (isLast && + drawOnlyLastOrderFlow); + if (!canDraw) + { + continue; + } + + // + XPVPivot iPivot = mOrderFlow[i]; + + // + XCXPVPivotObject *iObj; + iObj = new XCXPVPivotObject(); + bool isCreated = iObj.Create( + mPOIDrawer.ChartIdentification(), + mPOIDrawer.SubWindowIdentification(), + iPivot // + ); + if (isCreated) + { + // + bool canDrawState = + drawOrderFlowState && + (!drawOnlyLastOrderFlowState || + (isLast && + drawOnlyLastOrderFlowState)); + if (canDrawState) + { + // + CustomStateDrawing( + iPivot.state, + forceDrawSamePeriod, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + if (iPivot.IsPeak()) + { + // + iObj.PivotWidth(1); + iObj.PivotFill(false); + iObj.PivotColor(clrAqua); + iObj.PivotStyle(STYLE_SOLID); + } + + // + if (iPivot.IsVale()) + { + // + iObj.PivotWidth(1); + iObj.PivotFill(false); + iObj.PivotStyle(STYLE_SOLID); + iObj.PivotColor(clrMagenta); + } + + // + AddObjectIfNotExists(iObj); + } + } + + // + // Draw States ... + + // + // Vision ... + if (drawVisionState) + { + // + CustomStateDrawing( + mVisionState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Consolidation ... + if (drawConsolidationState) + { + // + CustomStateDrawing( + mConsolidationState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Verification ... + if (drawVerificationState) + { + // + CustomStateDrawing( + mVerificationState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Analyse ... + if (drawAnalyseState) + { + // + CustomStateDrawing( + mAnalyseState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Decision ... + if (drawDecisionState) + { + // + CustomStateDrawing( + mDecisionState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + + // + // Trigger ... + if (drawTriggerState) + { + // + CustomStateDrawing( + mTriggerState, + false, + forDir, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + } + + /** + * Custom Drawing State ... + * + * @param state: XPOIState instance reference, Specified Which state to Draw ... + * @param forceDrawSamePeriod: Boolean ... + */ + void CustomStateDrawing( + XPOIState &state, + bool forceDrawSamePeriod = false, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + // + // Ignores List ... + bool ignoreSwingHighs = false, + bool ignoreSwingLows = false, + bool ignoreSupportZones = false, + bool ignoreResistanceZones = false, + bool ignoreSupplyZones = false, + bool ignoreDemandZones = false, + bool ignoreBullishOrderBlocks = false, + bool ignoreBearishOrderBlocks = false, + bool ignoreBullishFairValueGaps = false, + bool ignoreBearishFairValueGaps = false, + bool ignoreBullishRejectionBars = false, + bool ignoreBearishRejectionBars = false, + bool ignoreBullishMomentumBars = false, + bool ignoreBearishMomentumBars = false // + ) + { + // + XPOIState tmpState = state; + if (forceDrawSamePeriod) + { + // + int count = 0; + ENUM_TIMEFRAMES period = GetPeriod(); + + // + count = state.CountSwingHighs(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSwing iSwing = state.swingHighs[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.swingHighs, + i, + 1 // + ); + } + } + } + + // + count = state.CountSwingLows(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSwing iSwing = state.swingLows[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.swingLows, + i, + 1 // + ); + } + } + } + + // + count = state.CountBullishMomentumBars(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCMomentumBar iMomentum = state.bullishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bullishMomentumBars, + i, + 1 // + ); + } + } + } + + // + count = state.CountBearishMomentumBars(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCMomentumBar iMomentum = state.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bearishMomentumBars, + i, + 1 // + ); + } + } + } + + // + count = state.CountBullishRejectionBars(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCRejectionBar iRejection = state.bullishRejectionBars[i]; + + // + XOHCL iBar; + bool isFilled = iRejection.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bullishRejectionBars, + i, + 1 // + ); + } + } + } + + // + count = state.CountBearishRejectionBars(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCRejectionBar iRejection = state.bearishRejectionBars[i]; + + // + XOHCL iBar; + bool isFilled = iRejection.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bearishRejectionBars, + i, + 1 // + ); + } + } + } + + // + count = state.CountSupportZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone iZone = state.supportZones[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.supportZones, + i, + 1 // + ); + } + } + } + + // + count = state.CountResistanceZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone iZone = state.resistanceZones[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.resistanceZones, + i, + 1 // + ); + } + } + } + + // + count = state.CountSupplyZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupplyZone iZone = state.supplyZones[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.supplyZones, + i, + 1 // + ); + } + } + } + + // + count = state.CountDemandZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCDemandZone iZone = state.demandZones[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.demandZones, + i, + 1 // + ); + } + } + } + + // + count = state.CountBullishOrderBlocks(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock iZone = state.bullishOrderBlocks[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bullishOrderBlocks, + i, + 1 // + ); + } + } + } + + // + count = state.CountBearishOrderBlocks(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock iZone = state.bearishOrderBlocks[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bearishOrderBlocks, + i, + 1 // + ); + } + } + } + + // + count = state.CountBullishFairValueGaps(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCFVG iZone = state.bullishFairValueGaps[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillStartBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bullishFairValueGaps, + i, + 1 // + ); + } + } + } + + // + count = state.CountBearishFairValueGaps(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCFVG iZone = state.bearishFairValueGaps[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillStartBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isSamePeriod = iBar.period == period; + if (!isSamePeriod) + { + // + ArrayRemove( + tmpState.bearishFairValueGaps, + i, + 1 // + ); + } + } + } + + // + } + + // + bool drawSwingHighs = true; + bool drawSwingLows = true; + bool drawSupportZones = true; + bool drawResistanceZones = true; + bool drawSupplyZones = true; + bool drawDemandZones = true; + bool drawBullishOrderBlocks = true; + bool drawBearishOrderBlocks = true; + bool drawBullishFairValueGaps = true; + bool drawBearishFairValueGaps = true; + bool drawBullishRejectionBars = true; + bool drawBearishRejectionBars = true; + bool drawBullishMomentumBars = true; + bool drawBearishMomentumBars = true; + + // + // Change Drawing Specs Conditions based on + // Provided Direction ... + if (forDir == X_DIRECTION_BULLISH) + { + // + drawSwingLows = true; + drawDemandZones = true; + drawSupportZones = true; + drawBullishOrderBlocks = true; + drawBullishFairValueGaps = true; + drawBullishRejectionBars = true; + drawBullishMomentumBars = true; + + // + drawSwingHighs = false; + drawSupplyZones = false; + drawResistanceZones = false; + drawBearishOrderBlocks = false; + drawBearishFairValueGaps = false; + drawBearishRejectionBars = false; + drawBearishMomentumBars = false; + } + else if (forDir == X_DIRECTION_BEARISH) + { + // + drawSwingLows = false; + drawDemandZones = false; + drawSupportZones = false; + drawBullishOrderBlocks = false; + drawBullishFairValueGaps = false; + drawBullishRejectionBars = false; + drawBullishMomentumBars = false; + + // + drawSwingHighs = true; + drawSupplyZones = true; + drawResistanceZones = true; + drawBearishOrderBlocks = true; + drawBearishFairValueGaps = true; + drawBearishRejectionBars = true; + drawBearishMomentumBars = true; + } + + // + // Apply Ignore List ... + + // + if (ignoreSwingHighs) + { + drawSwingHighs = false; + } + + // + if (ignoreSwingLows) + { + drawSwingLows = false; + } + + // + if (ignoreSupportZones) + { + drawSupportZones = false; + } + + // + if (ignoreResistanceZones) + { + drawResistanceZones = false; + } + + // + if (ignoreSupplyZones) + { + drawSupplyZones = false; + } + + // + if (ignoreDemandZones) + { + drawDemandZones = false; + } + + // + if (ignoreBullishOrderBlocks) + { + drawBullishOrderBlocks = false; + } + + // + if (ignoreBearishOrderBlocks) + { + drawBearishOrderBlocks = false; + } + + // + if (ignoreBullishFairValueGaps) + { + drawBullishFairValueGaps = false; + } + + // + if (ignoreBearishFairValueGaps) + { + drawBearishFairValueGaps = false; + } + + // + if (ignoreBullishRejectionBars) + { + drawBullishRejectionBars = false; + } + + // + if (ignoreBearishRejectionBars) + { + drawBearishRejectionBars = false; + } + + // + if (ignoreBullishMomentumBars) + { + drawBullishMomentumBars = false; + } + + // + if (ignoreBearishMomentumBars) + { + drawBearishMomentumBars = false; + } + + // + DrawState( + tmpState, // State ... + true, // Update To of all Drawings Till now ... + drawSwingHighs, // Draw SwingHighs .. + drawSwingLows, // Draw SwingLows .. + drawSupportZones, // Draw SupportZones .. + drawResistanceZones, // Draw ResistanceZones .. + drawSupplyZones, // Draw SupplyZones .. + drawDemandZones, // Draw DemandZones .. + drawBullishOrderBlocks, // Draw BullishOrderBlocks .. + drawBearishOrderBlocks, // Draw BearishOrderBlocks .. + drawBullishFairValueGaps, // Draw BullishFairValueGaps .. + drawBearishFairValueGaps, // Draw BearishFairValueGaps .. + drawBullishRejectionBars, // Draw BullishRejectionBars .. + drawBearishRejectionBars, // Draw BearishRejectionBars .. + drawBullishMomentumBars, // Draw BullishMomentumBars .. + drawBearishMomentumBars, // Draw BearishMomentumBars .. + true // Draw Ticks Zone ... + ); + } + + // + // Private ... + private: + // + // Props ... + + /** + * Initial Required Indicators Helper ... + */ + void InitialHelpers() + { + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period + ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period + ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period + ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period + ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + + // + // XPV ... + XPVInputs xpvInputs; + + // + xpvInputs.Default(); + + // + xpvInputs.scMethod = scMethod; + xpvInputs.scPeriod = scPeriod; + xpvInputs.mcMethod = mcMethod; + xpvInputs.mcPeriod = mcPeriod; + xpvInputs.lcMethod = lcMethod; + xpvInputs.lcPeriod = lcPeriod; + xpvInputs.hcMethod = hcMethod; + xpvInputs.hcPeriod = hcPeriod; + + // + xpvInputs.showPeaksAndVales = true; + xpvInputs.showLevels = false; + xpvInputs.showConsolidations = false; + xpvInputs.showFibo1Levels = false; + xpvInputs.showFibo2Levels = false; + xpvInputs.showFibo3Levels = false; + xpvInputs.showFibo4Levels = false; + xpvInputs.showFibo5Levels = false; + + // + // X3MA ... + X3MAInputs x3maInputs; + + // + x3maInputs.Default(); + + // + // x3maInputs.fastLength = 10; + // x3maInputs.midLength = 25; + // x3maInputs.slowLength = 50; + + // + x3maInputs.showFast = true; + x3maInputs.showMid = false; + x3maInputs.showSlow = false; + + // + // X3VWAP ... + X3VWAPInputs x3vwapInputs; + + // + x3vwapInputs.Default(); + + // + // x3vwapInputs.fastLength = 10; + // x3vwapInputs.midLength = 25; + // x3vwapInputs.slowLength = 50; + + // + x3vwapInputs.showFast = true; + x3vwapInputs.showMid = true; + x3vwapInputs.showSlow = true; + + // + // XCHSAR ... + XCHSARInputs xchsarInputs; + + // + xchsarInputs.Default(); + + // + xchsarInputs.scMethod = scMethod; + xchsarInputs.scPeriod = scPeriod; + xchsarInputs.mcMethod = mcMethod; + xchsarInputs.mcPeriod = mcPeriod; + xchsarInputs.lcMethod = lcMethod; + xchsarInputs.lcPeriod = lcPeriod; + xchsarInputs.hcMethod = hcMethod; + xchsarInputs.hcPeriod = hcPeriod; + + // + xchsarInputs.showCurrent = true; + xchsarInputs.showShort = false; + xchsarInputs.showMedium = false; + xchsarInputs.showLong = false; + xchsarInputs.showHind = false; + + // + // Initialize Cycle Helpers ... + + // + mTriggerCycleHelper = new XC121SMCCycleHelper(); + mTriggerCycleHelper.Init( + symbol, + PERIOD_M1, + xpvInputs, + x3maInputs, + x3vwapInputs, + xchsarInputs // + ); + + // + mDecisionCycleHelper = new XC121SMCCycleHelper(); + mDecisionCycleHelper.Init( + symbol, + PERIOD_M5, + xpvInputs, + x3maInputs, + x3vwapInputs, + xchsarInputs // + ); + + // + mAnalyseCycleHelper = new XC121SMCCycleHelper(); + mAnalyseCycleHelper.Init( + symbol, + PERIOD_M15, + xpvInputs, + x3maInputs, + x3vwapInputs, + xchsarInputs // + ); + + // + mVerificationCycleHelper = new XC121SMCCycleHelper(); + mVerificationCycleHelper.Init( + symbol, + PERIOD_M30, + xpvInputs, + x3maInputs, + x3vwapInputs, + xchsarInputs // + ); + + // + mConsolidationCycleHelper = new XC121SMCCycleHelper(); + mConsolidationCycleHelper.Init( + symbol, + PERIOD_H1, + xpvInputs, + x3maInputs, + x3vwapInputs, + xchsarInputs // + ); + + // + mVisionCycleHelper = new XC121SMCCycleHelper(); + mVisionCycleHelper.Init( + symbol, + PERIOD_H4, + xpvInputs, + x3maInputs, + x3vwapInputs, + xchsarInputs // + ); + } + + // +}; + +// \ No newline at end of file diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index b8a93e49..04a269c1 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -1345,6 +1345,74 @@ struct XOHCL return result; } + // + bool BarAt( + int index, + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + if (index < 0) + { + index = 0; + } + + // + result = bar.Init( + symbol, + period, + index // + ); + + // + return result; + } + + // + bool BarIn( + ENUM_TIMEFRAMES _period, + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + result = IsValid() && + IsSpecifiedValid(_period); + if (!result) + { + return result; + } + + // + int index = Index(_period); + result = bar.Init( + symbol, + _period, + index // + ); + + // + return result; + } + // // Find Current Bar Index on Chart ... int Index() @@ -1370,6 +1438,58 @@ struct XOHCL return result; } + // + int Index(datetime value) + { + // + int result = -1; + + // + value = NormalizeTime(value); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + result = iBarShift( + symbol, + period, + value // + ); + + // + return result; + } + + // + int Index(ENUM_TIMEFRAMES value) + { + // + int result = -1; + + // + result = IsValid() && + IsSpecifiedValid(value); + if (!result) + { + return result; + } + + // + result = iBarShift( + symbol, + value, + time // + ); + + // + return result; + } + // bool GetNextBar(XOHCL &bar) { diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 235d580b..aaae41a3 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -683,6 +683,24 @@ class XCBarZone : public XCZone return result; } + ENUM_TIMEFRAMES GetPeriod() { + // + ENUM_TIMEFRAMES result = NULL; + + // + XOHCL bar; + bool isFilled = FillBar(bar); + if (!isFilled) { + return result; + } + + // + result = bar.period; + + // + return result; + } + /** * Set From Date ... * @@ -1003,6 +1021,24 @@ class XCTwoBarZone : public XCZone return result; } + ENUM_TIMEFRAMES GetPeriod() { + // + ENUM_TIMEFRAMES result = NULL; + + // + XOHCL bar; + bool isFilled = FillStartBar(bar); + if (!isFilled) { + return result; + } + + // + result = bar.period; + + // + return result; + } + // // Overrides ... @@ -1202,6 +1238,24 @@ class XCSwing : public XCBasePOI // return result; } + + ENUM_TIMEFRAMES GetPeriod() { + // + ENUM_TIMEFRAMES result = NULL; + + // + XOHCL bar; + bool isFilled = FillBar(bar); + if (!isFilled) { + return result; + } + + // + result = bar.period; + + // + return result; + } /** * Check Swing High or not ... diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index ec2cf845..31b57720 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -1542,7 +1542,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // Initialize POIs ... // - int poiRequired = 10; + int poiRequired = 40; // // Trigger ... 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 3a043afd..5c0b0875 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -53,6 +53,10 @@ class XC121SMCCycleHelper : public XCBase // XCHSAR ... XCXCHSARHelper *mXCHSARHelper; + // + // POI Detector ... + XCPOIDetector *mPOIDetector; + // // Constructor(s) ... XC121SMCCycleHelper() @@ -192,6 +196,14 @@ class XC121SMCCycleHelper : public XCBase return result; } + // + mPOIDetector = new XCPOIDetector( + symbol, + period // + ); + mPOIDetector.MaxNumberOfRequiredPOIs(0); + mPOIDetector.Init(); + // // Initialize Bar Analyser Class Instance ... mBarAnalyser = new XCBarAnalyser(); @@ -204,6 +216,61 @@ class XC121SMCCycleHelper : public XCBase return result; } + /** + * Get Specified Bar ... + * + * @param source: XOHCL instance, Source Bar ... + * @param bar: XOHCL instance, Dest Bar ... + * + * @return ( bool ) + */ + bool GetBar( + XOHCL &source, + XOHCL &bar // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + result = + IsValid(symbol) && + IsValid(period) && + source.IsValid(); + if (!result) + { + return result; + } + + // + int index = iBarShift( + symbol, + period, + source.time // + ); + result = bar.Init( + symbol, + period, + index // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + return result; + } + /** * Retrieve Cycle Conditions ... * @@ -620,59 +687,4 @@ class XC121SMCCycleHelper : public XCBase // return result; } - - /** - * Get Specified Bar ... - * - * @param source: XOHCL instance, Source Bar ... - * @param bar: XOHCL instance, Dest Bar ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &source, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = - IsValid(symbol) && - IsValid(period) && - source.IsValid(); - if (!result) - { - return result; - } - - // - int index = iBarShift( - symbol, - period, - source.time // - ); - result = bar.Init( - symbol, - period, - index // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - return result; - } }; diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 064107e6..19d97b4d 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -748,6 +748,15 @@ struct X121SMCStrategyConditions X121SMCCycleConditions consolidationConditions; X121SMCCycleConditions visionConditions; + // + double sl; + string provider; + XCOrderBlock *visionBullOB; + XCOrderBlock *visionBearOB; + XCOrderBlock *consolidationBullOB; + XCOrderBlock *consolidationBearOB; + ENUM_X_DIRECTION marketStructureDir; + // void X121SMCStrategyConditions() { @@ -767,6 +776,15 @@ struct X121SMCStrategyConditions period = NULL; time = NULL; + // + sl = 0; + provider = NULL; + visionBullOB = NULL; + visionBearOB = NULL; + consolidationBullOB = NULL; + consolidationBearOB = NULL; + marketStructureDir = X_DIRECTION_NONE; + // triggerConditions.Clean(); decisionConditions.Clean(); @@ -795,6 +813,14 @@ struct X121SMCStrategyConditions return result; } + /** + * Check Conditions has Ddirection or not ... + * + * @param dir: ENUM_X_DIRECTIOn member ... + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ bool HasDirection( ENUM_X_DIRECTION &dir, XOHCL &bar // diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index f6193af3..046a000a 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -115,69 +115,14 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // Start Calculations ... // - string _symbol = GetSymbol(); - ENUM_TIMEFRAMES _period = GetPeriod(); + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); // - double points = GetPoints(_symbol); - double pip = GetPipPrice(_symbol); + double points = GetPoints(symbol); + double pip = GetPipPrice(symbol); double pip2 = 2 * pip; - // - datetime cTime = TimeCurrent(); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - // Retrieve Bars ... - - // - // Zero Bar ... - XOHCL zBar; - result = zBar.Init( - _symbol, - _period, - zIndex // - ); - if (!result) - { - return result; - } - - // - // Last Bar ... - XOHCL cBar; - result = cBar.Init( - _symbol, - _period, - cIndex // - ); - if (!result) - { - return result; - } - - // - // Previous Bar ... - XOHCL pBar; - result = pBar.Init( - _symbol, - _period, - pIndex // - ); - if (!result) - { - return result; - } - - // - // Prepare Areas ... - double bid = GetBid(_symbol); - // // Check Spread ... bool isSpreadPassed = IsSpreadPass(); @@ -197,23 +142,26 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy result = DetectConditions(conditions); if (!result) { + conditions.Clean(); return result; } // // Combine all Signals Conditions ... + selectedSL = conditions.sl; + provider = conditions.provider; // hasLong = // - false + IsBullish(conditions.marketStructureDir) // ; // hasShort = // - false + IsBearish(conditions.marketStructureDir) // ; @@ -267,8 +215,8 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy signal.mode = mode; signal.entry = entry; signal.volume = volume; - signal.symbol = _symbol; - signal.period = _period; + signal.symbol = symbol; + signal.period = period; signal.pushers = pushers; signal.provider = provider; signal.time = TimeCurrent(); @@ -439,9 +387,16 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy } // + string msg = NULL; + + // + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + conditions.time = cTime; conditions.symbol = symbol; conditions.period = period; - conditions.time = TimeCurrent(); // int conditionsLoopback = 7; @@ -504,24 +459,104 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy conditions.visionConditions.state = mVisionState; // - // Check Market Conditions for - // Specified Structure ... - ENUM_X_DIRECTION marketStructureDir = X_DIRECTION_NONE; - result = conditions.HasDirection( - marketStructureDir, - cBar // - ); - if (!result) + // Detect an Order Block in Vision ... + if (conditions.visionBullOB == NULL || + conditions.visionBearOB == NULL) { // - conditions.Clean(); - return result; + result = DetectOrderBlocks( + NULL, + NULL, + conditions.visionBullOB, + conditions.visionBearOB, + cBar, + mVisionState // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + XCBullishOrderBlockObject *iBullOBObj; + conditions.visionBullOB.To(cTime); + result = mPOIDrawer.CreateBullishOrderBlock( + conditions.visionBullOB, + iBullOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBullOBObj); + } + + // + XCBearishOrderBlockObject *iBearOBObj; + conditions.visionBearOB.To(cTime); + result = mPOIDrawer.CreateBearishOrderBlock( + conditions.visionBearOB, + iBearOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBearOBObj); + } } + // + // Consolidation Order Blocks ... + if (conditions.consolidationBullOB == NULL || + conditions.consolidationBearOB == NULL) + { + // + result = DetectOrderBlocks( + conditions.visionBullOB, + conditions.visionBearOB, + conditions.consolidationBullOB, + conditions.consolidationBearOB, + cBar, + mConsolidationState // + ); + if (!result) + { + // + conditions.Clean(); + return result; + } + + // + XCBullishOrderBlockObject *iBullOBObj; + conditions.consolidationBullOB.To(cTime); + result = mPOIDrawer.CreateBullishOrderBlock( + conditions.consolidationBullOB, + iBullOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBullOBObj); + } + + // + XCBearishOrderBlockObject *iBearOBObj; + conditions.consolidationBearOB.To(cTime); + result = mPOIDrawer.CreateBearishOrderBlock( + conditions.consolidationBearOB, + iBearOBObj // + ); + if (result) + { + AddObjectIfNotExists(iBearOBObj); + } + } + + // + msg = "OrderBlocks Detected ..."; + Alert(msg); + // // Detect Trigger Order Flow ... - if (ArraySize(mOrderFlow) == 0 || - mOrderFlowDir == X_DIRECTION_NONE) + if (!HasValidOrderFlow()) { // int samePivots = 40; @@ -554,168 +589,199 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ); // - result = IsValidSize(ArraySize(mOrderFlow)); + result = HasValidOrderFlow(); if (!result) { + // + conditions.Clean(); return result; } - } - result = HasValidOrderFlow() && - mOrderFlowDir == marketStructureDir; - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - // Detect Nearest Sar Change ... - XOHCL sarChangeBar; - result = mTriggerCycleHelper.DetectNearestCSARChange( - sarChangeBar, - cBar // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - // Draw Last Sar Change ... - string iVLineName = sarChangeBar.GetTag("XSAR"); - CChartObjectVLine *iVLineObj; - iVLineObj = new CChartObjectVLine(); - result = iVLineObj.Create( - ChartID(), - iVLineName, - 0, - sarChangeBar.time // - ); - if (result) - { - iVLineObj.Color(clrYellow); - } - - // - // Detect Nearest Momentum or Rejection Bar ... - XOHCL decisionBar; - result = mDecisionCycleHelper.DetectNearestDecisionBar( - decisionBar, - marketStructureDir, - cBar // - ); - if (!result) - { - return result; - } - - // - // Draw Last Decision Bar ... - string iVLineNameDecision = decisionBar.GetTag("XDECISION"); - CChartObjectVLine *iVLineDecisionObj; - iVLineDecisionObj = new CChartObjectVLine(); - result = iVLineDecisionObj.Create( - ChartID(), - iVLineNameDecision, - 0, - decisionBar.time // - ); - if (result) - { - iVLineDecisionObj.Color(clrYellow); - } - - // - // TODO: Remove This ... - bool ignoreSwingHighs = true; - bool ignoreSwingLows = true; - bool ignoreSupportZones = true; - bool ignoreResistanceZones = true; - bool ignoreSupplyZones = true; - bool ignoreDemandZones = true; - bool ignoreBullishOrderBlocks = true; - bool ignoreBearishOrderBlocks = true; - bool ignoreBullishFairValueGaps = true; - bool ignoreBearishFairValueGaps = true; - bool ignoreBullishRejectionBars = true; - bool ignoreBearishRejectionBars = true; - bool ignoreBullishMomentumBars = true; - bool ignoreBearishMomentumBars = true; - - // - if (IsBullish(marketStructureDir)) - { - // - ignoreSwingLows = true; - ignoreSupportZones = true; - ignoreDemandZones = true; - ignoreBullishOrderBlocks = true; - ignoreBullishFairValueGaps = false; - ignoreBullishRejectionBars = false; - ignoreBullishMomentumBars = false; // - ignoreSwingHighs = true; - ignoreResistanceZones = true; - ignoreSupplyZones = true; - ignoreBearishOrderBlocks = true; - ignoreBearishFairValueGaps = true; - ignoreBearishRejectionBars = true; - ignoreBearishMomentumBars = true; - } - else - { - // - ignoreSwingLows = true; - ignoreSupportZones = true; - ignoreDemandZones = true; - ignoreBullishOrderBlocks = true; - ignoreBullishFairValueGaps = true; - ignoreBullishRejectionBars = true; - ignoreBullishMomentumBars = true; + bool ignoreSwingHighs = true; + bool ignoreSwingLows = true; + bool ignoreSupportZones = true; + bool ignoreResistanceZones = true; + bool ignoreSupplyZones = true; + bool ignoreDemandZones = true; + bool ignoreBullishOrderBlocks = true; + bool ignoreBearishOrderBlocks = true; + bool ignoreBullishFairValueGaps = true; + bool ignoreBearishFairValueGaps = true; + bool ignoreBullishRejectionBars = true; + bool ignoreBearishRejectionBars = true; + bool ignoreBullishMomentumBars = true; + bool ignoreBearishMomentumBars = true; // - ignoreSwingHighs = true; - ignoreResistanceZones = true; - ignoreSupplyZones = true; - ignoreBearishOrderBlocks = true; - ignoreBearishFairValueGaps = false; - ignoreBearishRejectionBars = false; - ignoreBearishMomentumBars = false; + RedrawOrderFlow( + false, // Force Clean ... + false, // Same Period ... + true, // Order Flow ... + true, // Order Flow State ... + false, // Only Last Order Flow ... + true, // Only Last Order Flow State ... + // + mOrderFlowDir, // Direction Force ... + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); } // - RedrawOrderFlow( - true, // Force Clean ... - false, // Same Period ... - true, // Order Flow ... - true, // Order Flow State ... - false, // Only Last Order Flow ... - true, // Only Last Order Flow State ... - // - marketStructureDir, // Direction Force ... - ignoreSwingHighs, - ignoreSwingLows, - ignoreSupportZones, - ignoreResistanceZones, - ignoreSupplyZones, - ignoreDemandZones, - ignoreBullishOrderBlocks, - ignoreBearishOrderBlocks, - ignoreBullishFairValueGaps, - ignoreBearishFairValueGaps, - ignoreBullishRejectionBars, - ignoreBearishRejectionBars, - ignoreBullishMomentumBars, - ignoreBearishMomentumBars // - ); + msg = "Found OrderFlow : " + (IsBullish(mOrderFlowDir) ? "Bullish" : "Berish"); + Alert(msg); // - // Here we Have to Detect Entry Conditions ... - // TODO: Implement this ... + // Check Market Conditions for + // Specified Structure ... + // ENUM_X_DIRECTION marketStructureDir = X_DIRECTION_NONE; + // result = conditions.HasDirection( + // marketStructureDir, + // cBar // + // ); + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + // msg = "Found Market Strucutre : " + (IsBullish(marketStructureDir) ? "Bullish" : "Berish"); + // Alert(msg); + + // + // conditions.marketStructureDir = marketStructureDir; + + // // + // XPVPivot lastPivot; + // result = GetLastItem( + // lastPivot, + // mOrderFlow // + // ); + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + + // + // Detect Last FVG ... + // XOHCL breakerBar; + // result = DetectLastBreakerBar( + // cBar, + // breakerBar, + // lastPivot, + // marketStructureDir // + // ); + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + // msg = "Found Breaker Bar: " + breakerBar.GetTag(); + // Alert(msg); + + // // + // // Detect Nearest Momentum or Rejection Bar ... + // XOHCL decisionBar; + // result = mDecisionCycleHelper.DetectNearestDecisionBar( + // decisionBar, + // marketStructureDir, + // cBar // + // ); + // if (!result) + // { + // return result; + // } + // msg = "Found Decision Bar: " + decisionBar.GetTag(); + // Alert(msg); + + // // + // // Detect Nearest Sar Change ... + // XOHCL sarChangeBar; + // result = mTriggerCycleHelper.DetectNearestCSARChange( + // sarChangeBar, + // cBar // + // ); + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + // msg = "Found Sar Change Bar: " + sarChangeBar.GetTag(); + // Alert(msg); + + // // + // // Now we Hvae to Check Other Conditions ... + // result = + // // breakerBar.time > sarChangeBar.time && + // // decisionBar.time > breakerBar.time; + // decisionBar.time > sarChangeBar.time; + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + + // // + // // Now we Have Check Direction Related Conditions ... + // if (IsBullish(marketStructureDir)) + // { + // // + // result = + // // bid > decisionBar.high && + // // bid > breakerBar.high && + // bid > sarChangeBar.high && + // bid > conditions.triggerConditions.xchsarConditions.cSars[0]; + // } + // else + // { + // // + // result = + // // bid < decisionBar.low && + // // bid < breakerBar.low && + // bid < sarChangeBar.high && + // bid < conditions.triggerConditions.xchsarConditions.cSars[0]; + // } + // if (!result) + // { + // // + // conditions.Clean(); + // return result; + // } + + // // + // conditions.provider = "X121SMC"; + // if (IsBullish(marketStructureDir)) + // { + // // + // // conditions.sl = decisionBar.low; + // // conditions.sl = breakerBar.low; + // conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; + // } + // else + // { + // // + // // conditions.sl = decisionBar.high; + // // conditions.sl = breakerBar.high; + // conditions.sl = conditions.triggerConditions.xchsarConditions.cSars[0]; + // } // if (!result) @@ -1430,6 +1496,425 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ClearDraws(); } + /** + * Detect Breaker Bar ... + * + * @param bar: XOHCL instance ... + * @param breakerBar: XOHCL instance, Breaker Bar ... + * @param pivot: XPVPivot instance ... + * @param forDir: ENUM_X_DIRECTION member, Market Structure Direction ... + * + * @return ( bool ) + */ + bool DetectLastBreakerBar( + XOHCL &bar, + XOHCL &breakerBar, + XPVPivot &pivot, + ENUM_X_DIRECTION forDir // + ) + { + // + bool result = false; + + // + result = + bar.IsValid() && + pivot.IsValid() && + forDir != X_DIRECTION_ALL && + forDir != X_DIRECTION_NONE; + if (!result) + { + return result; + } + + // + // FVG ... + result = DetectLastFVGBreakerBar( + bar, + breakerBar, + pivot, + forDir // + ); + if (result) + { + return result; + } + + // + // Order Block ... + // result = DetectLastOBBreakerBar( + // bar, + // breakerBar, + // pivot, + // forDir // + // ); + // if (result) + // { + // return result; + // } + + // + return result; + } + + bool DetectLastFVGBreakerBar( + XOHCL &bar, + XOHCL &breakerBar, + XPVPivot &pivot, + ENUM_X_DIRECTION forDir // + ) + { + // + bool result = false; + + // + result = + bar.IsValid() && + pivot.IsValid() && + forDir != X_DIRECTION_ALL && + forDir != X_DIRECTION_NONE; + if (!result) + { + return result; + } + + // + bool isBullishDir = IsBullish(forDir); + + // + int fvgsCount = + isBullishDir + ? pivot.state.CountBullishFairValueGaps() + : pivot.state.CountBearishFairValueGaps(); + result = IsValidSize(fvgsCount); + if (!result) + { + return result; + } + + // + int idx = -1; + XCFVG *zone = NULL; + for (int i = 0; i < fvgsCount; i++) + { + // + if (isBullishDir) + { + // + // Bullish FVG ... + if (zone == NULL) + { + // + zone = pivot.state.bullishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + else + { + // + bool isNewer = ((int)zone.From() - (int)bar.time) > ((int)pivot.state.bullishFairValueGaps[i].From() - (int)bar.time); + if (isNewer) + { + // + zone = pivot.state.bullishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + } + } + else + { + // + // Bearish FVG ... + if (zone == NULL) + { + // + zone = pivot.state.bearishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + else + { + // + bool isNewer = ((int)zone.From() - (int)bar.time) > ((int)pivot.state.bearishFairValueGaps[i].From() - (int)bar.time); + if (isNewer) + { + // + zone = pivot.state.bearishFairValueGaps[i]; + + // + bool isBreaked = CheckZoneBreak( + forDir, + bar, + breakerBar, + zone // + ); + if (isBreaked) + { + idx = i; + } + } + } + } + } + + // + result = + breakerBar.IsValid() && + IsValidIndex(idx) && + zone.IsValid(); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Check an FVG is Breaked or not ... + * + * @param forDir: ENUM_X_DIRECTION member, Market Structure Direction ... + * @param bar: XOHCL instance ... + * @param breakerBar: XOHCL instance, Breaker Bar ... + * + * @return ( bool ) + */ + bool CheckZoneBreak( + ENUM_X_DIRECTION forDir, + XOHCL &bar, + XOHCL &breakerBar, + XCFVG *&zone // + ) + { + // + bool result = false; + + // + breakerBar.Clean(); + + // + result = bar.IsValid() && + zone.IsValid() && + forDir != X_DIRECTION_ALL && + forDir != X_DIRECTION_NONE; + if (!result) + { + return result; + } + + // + int start = bar.Index(); + int end = iBarShift( + bar.symbol, + bar.period, + zone.From()); + for (int i = start; i < end; i++) + { + // + XOHCL iBar; + result = iBar.Init( + bar.symbol, + bar.period, + i // + ); + if (!result) + { + break; + } + + // + if (IsBullish(forDir)) + { + // + // Bullish Break ... + result = iBar.low < zone.Upper() && + iBar.high > zone.Upper() && + iBar.GetDown() < zone.Upper() && + iBar.GetUp() > zone.Upper() && + iBar.IsBullish(); + } + else + { + // + // Bearish Break ... + result = iBar.low < zone.Lower() && + iBar.high > zone.Lower() && + iBar.GetDown() < zone.Lower() && + iBar.GetUp() > zone.Lower() && + iBar.IsBearish(); + } + + // + if (result) + { + // + breakerBar = iBar; + break; + } + } + + // + result = breakerBar.IsValid(); + + // + return result; + } + + /** + * Detect most Upper and Lower Order Blocks ... + * + * @return ( bool ) + */ + bool DetectOrderBlocks( + XCOrderBlock *bullOBBoundary, + XCOrderBlock *bearOBBoundary, + XCOrderBlock *&bullOB, + XCOrderBlock *&bearOB, + XOHCL &bar, + XPOIState &state // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + state.IsValid(); + if (!result) + { + return result; + } + + // + XCOrderBlock *mBullOB = NULL; + if (bullOB == NULL) + { + // + for (int i = 0; i < state.CountBullishOrderBlocks(); i++) + { + // + XCOrderBlock *ob = state.bullishOrderBlocks[i]; + bool isPricePassed = bar.low > ob.Upper(); + if (isPricePassed) + { + // + bool isBoundaryPassed = + bullOBBoundary == NULL + ? true + : ob.Lower() < bullOBBoundary.Upper(); + if (isBoundaryPassed) + { + // + if (mBullOB == NULL) + { + mBullOB = ob; + } + else + { + // + bool isRefined = + mBullOB.Upper() < ob.Upper(); + if (isRefined) + { + mBullOB = ob; + } + } + } + } + } + + // + if (mBullOB != NULL) + { + bullOB = mBullOB; + } + } + + // + XCOrderBlock *mBearOB = NULL; + if (bearOB == NULL) + { + // + for (int i = 0; i < state.CountBearishOrderBlocks(); i++) + { + // + XCOrderBlock *ob = state.bearishOrderBlocks[i]; + bool isPricePassed = bar.high < ob.Lower(); + if (isPricePassed) + { + // + bool isBoundaryPassed = + bearOBBoundary == NULL + ? true + : ob.Upper() > bearOBBoundary.Lower(); + if (isBoundaryPassed) + { + // + if (mBearOB == NULL) + { + mBearOB = ob; + } + else + { + // + bool isRefined = + mBearOB.Lower() > ob.Lower(); + if (isRefined) + { + mBearOB = ob; + } + } + } + } + } + + // + if (mBearOB != NULL) + { + bearOB = mBearOB; + } + } + + // + result = bullOB != NULL && + bearOB != NULL; + + // + return result; + } + // // Drawings ... @@ -2452,6 +2937,11 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // x3maInputs.Default(); + // + // x3maInputs.fastLength = 10; + // x3maInputs.midLength = 25; + // x3maInputs.slowLength = 50; + // x3maInputs.showFast = true; x3maInputs.showMid = false; @@ -2464,6 +2954,11 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // x3vwapInputs.Default(); + // + // x3vwapInputs.fastLength = 10; + // x3vwapInputs.midLength = 25; + // x3vwapInputs.slowLength = 50; + // x3vwapInputs.showFast = true; x3vwapInputs.showMid = true;