diff --git a/Documents/BKP/tmp.x121.smc.mq5 b/Documents/BKP/tmp.x121.smc.mq5 index 06229e30..5af02e04 100644 --- a/Documents/BKP/tmp.x121.smc.mq5 +++ b/Documents/BKP/tmp.x121.smc.mq5 @@ -1041,3 +1041,1038 @@ // return result; } + + +//////////////////////////////////////////////////////////////////////////// + + + + // + // Detect Order Blocks ... + // int obsCount = 0; + + // + // Find Bullish Order Block ... + // XCOrderBlock *bullishOB = NULL; + // XCRejectionBar *bullishOBRejectionBar = NULL; + // obsCount = lastPivot.state.CountBullishOrderBlocks(); + // if (IsValidSize(obsCount)) + // { + // // + // for (int i = 0; i < obsCount; i++) + // { + // // + // XCOrderBlock *iOB = lastPivot.state.bullishOrderBlocks[i]; + + // // + // XOHCL iBar; + // bool hasBar = iOB.FillBar(iBar); + // bool isPeriodSame = hasBar && + // iBar.period == _period; + + // // + // if (iOB.Upper() <= pivotMid && + // iOB.Lower() >= lastPivot.lower) + // { + // // + // bullishOB = iOB; + // break; + // } + // } + // } + // bool hasBullishOB = bullishOB != NULL; + // bool isBullishOBRejected = false; + // if (hasBullishOB) + // { + // // + // int bullishRejectedBarsCount = lastPivot.state.CountBullishRejectionBars(); + // if (IsValidSize(bullishRejectedBarsCount)) + // { + // // + // for (int i = 0; i < bullishRejectedBarsCount; i++) + // { + // // + // XCRejectionBar *item = lastPivot.state.bullishRejectionBars[i]; + + // // + // XOHCL iBar; + // bool isFilled = item.FillBar(iBar); + // if (!isFilled) + // { + // continue; + // } + + // // + // bool isRejected = iBar.low <= bullishOB.Lower() && + // (iBar.GetDown() <= bullishOB.Upper() || + // iBar.GetDown() > bullishOB.Upper()); + + // // + // isBullishOBRejected = + // bullishOBRejectionBar == NULL + // ? isRejected + // : isRejected && + // item.From() > bullishOBRejectionBar.From(); + // if (isBullishOBRejected) + // { + // bullishOBRejectionBar = item; + // } + // } + // } + // if (isBullishOBRejected) + // { + // // + // bullishOBRejectionBar.To(cTime); + // XCBullishRejectionBarObject *iObj; + // bool isCreated = mPOIDrawer.CreateBullishRejectionBar( + // bullishOBRejectionBar, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + + // // + // bullishOB.To(cTime); + // XCBullishOrderBlockObject *iObj; + // bool isCreated = mPOIDrawer.CreateBullishOrderBlock( + // bullishOB, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + + // + // Find Bearish Order Block ... + // XCOrderBlock *bearishOB = NULL; + // XCRejectionBar *bearishOBRejectionBar = NULL; + // obsCount = lastPivot.state.CountBearishOrderBlocks(); + // if (IsValidSize(obsCount)) + // { + // // + // for (int i = 0; i < obsCount; i++) + // { + // // + // XCOrderBlock *iOB = lastPivot.state.bearishOrderBlocks[i]; + + // // + // XOHCL iBar; + // bool hasBar = iOB.FillBar(iBar); + // bool isPeriodSame = hasBar && + // iBar.period == _period; + + // // + // if (iOB.Lower() >= pivotMid && + // iOB.Upper() <= lastPivot.upper) + // { + // // + // bearishOB = iOB; + // break; + // } + // } + // } + // bool hasBearishOB = bearishOB != NULL; + // bool isBearishOBRejected = false; + // if (hasBearishOB) + // { + // // + // int bearishRejectedBarsCount = lastPivot.state.CountBearishRejectionBars(); + // if (IsValidSize(bearishRejectedBarsCount)) + // { + // // + // for (int i = 0; i < bearishRejectedBarsCount; i++) + // { + // // + // XCRejectionBar *item = lastPivot.state.bearishRejectionBars[i]; + + // // + // XOHCL iBar; + // bool isFilled = item.FillBar(iBar); + // if (!isFilled) + // { + // continue; + // } + + // // + // bool isRejected = iBar.high >= bearishOB.Upper() && + // (iBar.GetUp() <= bearishOB.Lower() || + // iBar.GetUp() > bearishOB.Lower()); + + // // + // isBearishOBRejected = + // bearishOBRejectionBar == NULL + // ? isRejected + // : isRejected && + // item.From() > bearishOBRejectionBar.From(); + // if (isBearishOBRejected) + // { + // bearishOBRejectionBar = item; + // } + // } + // } + // if (isBearishOBRejected) + // { + // // + // bearishOBRejectionBar.To(cTime); + // XCBearishRejectionBarObject *iObj; + // bool isCreated = mPOIDrawer.CreateBearishRejectionBar( + // bearishOBRejectionBar, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + + // // + // bearishOB.To(cTime); + // XCBearishOrderBlockObject *iObj; + // bool isCreated = mPOIDrawer.CreateBearishOrderBlock( + // bearishOB, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + + // // + // // Find an Order Block ... + // bool isBearishOrderBlockRejected = false; + + +///////////////////////////////////////////////////////////////////////////// + + + + // + RedrawOrderFlow(); + + // + // Check Candlestick PullBacks ... + ENUM_X_DIRECTION pullBackDir; + bool hasPullBack = mBarAnalyser.HasPullBack( + pullBackDir, + cBar, + 3, // Loopback ... + true // Force Body ... + ); + bool hasBullishPullback = + hasPullBack && + pullBackDir == X_DIRECTION_BULLISH; + bool hasBearishPullback = + hasPullBack && + pullBackDir == X_DIRECTION_BEARISH; + + + + // + bool isInDiscount = + bid < pivotMid && + bid > lastPivot.lower; + + // + bool isInPremium = + bid > pivotMid && + bid < lastPivot.upper; + + // + // Check Order Flow Validation ... + + // + // For Bullish Order Flow ... + // if Price Breakes Lower to Down, means Change of Charcter Happens ... + bool isCHOCHHappens = + isBullishOrderFlow ? bid < lastPivot.lower - pip + : bid > lastPivot.upper + pip; + + // + // For Bullish Order Flow ... + // if Price Breakes Upper to Up, means Breake of Structure Happens ... + bool isBOSHappens = + isBullishOrderFlow ? bid > lastPivot.upper + pip + : bid < lastPivot.lower - pip; + + // + if (isBOSHappens) + { + // + // RedrawOrderFlow(); + Print(""); + } + + // + if (isCHOCHHappens) + { + // + result = false; + ResetOrderFlow(); + return result; + } + + + + // + // Check 3MA and 3VWAP State ... + + // + bool isVWAPBullishOrdered = + // + ( + // + (conditions.x3vwapConditions.isBullishOrdered || + conditions.x3vwapConditions.isSwitchedToBullishOrdered) + // + || + // + conditions.x3vwapConditions.fasts[cIndex] > conditions.x3vwapConditions.mids[cIndex] + // + || + // + conditions.x3vwapConditions.mids[cIndex] > conditions.x3vwapConditions.slows[cIndex] + // + ) + // + ; + + // + bool isVWAPBearishOrdered = + // + ( + // + (conditions.x3vwapConditions.isBearishOrdered || + conditions.x3vwapConditions.isSwitchedToBearishOrdered) + // + || + // + conditions.x3vwapConditions.fasts[cIndex] < conditions.x3vwapConditions.mids[cIndex] + // + || + // + conditions.x3vwapConditions.mids[cIndex] < conditions.x3vwapConditions.slows[cIndex] + // + ) + // + ; + + // + bool isVWapBullishState = + // + ( + // + (conditions.x3vwapConditions.isBullishState || + conditions.x3vwapConditions.isSwitchedToBullishState) + // + || + // + (x3vwapHelper.IsBullish(conditions.x3vwapConditions.fastStates[cIndex]) && + x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex])) + // + || + // + (x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex]) && + x3vwapHelper.IsBullish(conditions.x3vwapConditions.slowStates[cIndex])) + // + ) + // + ; + + // + bool isVWapBearishState = + // + ( + // + (conditions.x3vwapConditions.isBearishState || + conditions.x3vwapConditions.isSwitchedToBearishState) + // + || + // + (x3vwapHelper.IsBearish(conditions.x3vwapConditions.fastStates[cIndex]) && + x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex])) + // + || + // + (x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex]) && + x3vwapHelper.IsBearish(conditions.x3vwapConditions.slowStates[cIndex])) + // + ) + // + ; + + // + bool isVWapOverFastMA = + // + ( + // + (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex]) + // + || + // + (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.slows[cIndex] > conditions.x3maConditions.fasts[cIndex]) + // + ) + // + ; + + // + bool isVWapUnderFastMA = + // + ( + // + (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex]) + // + || + // + (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex] && + conditions.x3vwapConditions.slows[cIndex] < conditions.x3maConditions.fasts[cIndex]) + // + ) + // + ; + + // + bool is3Bullish = + // + ( + // + (isVWAPBullishOrdered && + isVWapBullishState) + // + || + // + (isVWAPBullishOrdered && + isVWapOverFastMA) + // + || + // + (isVWapBullishState && + isVWapOverFastMA) + // + ) + // + ; + + // + bool is3Bearish = + // + ( + // + (isVWAPBearishOrdered && + isVWapBearishState) + // + || + // + (isVWAPBearishOrdered && + isVWapUnderFastMA) + // + || + // + (isVWapBearishState && + isVWapUnderFastMA) + // + ) + // + ; + + // + // Check Parabolic Sars State ... + + // + bool isSarBullish = + // + (conditions.xchsarConditions.isCBullish && + conditions.xchsarConditions.isSSwitchedBullish) + // + || + // + (conditions.xchsarConditions.isSBullish && + conditions.xchsarConditions.isCSwitchedBullish) + // + ; + bool isSarBearish = + // + (conditions.xchsarConditions.isCBearish && + conditions.xchsarConditions.isSSwitchedBearish) + // + || + // + (conditions.xchsarConditions.isSBearish && + conditions.xchsarConditions.isCSwitchedBearish) + // + ; + + + + // // + // hasLong = + // // + // is3Bullish && + // // isInDiscount && + // isSarBullish // && + // // hasBullishPullback && + // // bullishLiquidityPercent > 30 + // // + // ; + + // // + // hasShort = + // // + // is3Bearish && + // // isInPremium && + // isSarBearish // && + // // hasBearishPullback && + // // bearishLiquidityPercent > 30 + // // + // ; + + + + +////////////////////// + + // + XPVPivot lastPivot; + result = GetLastItem( + lastPivot, + mOrderFlow // + ); + if (!result) + { + return result; + } + bool isBullishOrderFlow = IsBullish(mOrderFlowDir); + bool isBearishOrderFlow = IsBearish(mOrderFlowDir); + double pivotMid = lastPivot.CalculateMid(); + + // + // Calculate Liquidity Percent ... + double bullishLiquidityPercent = lastPivot + .CalculateLiquidityPercent(X_DIRECTION_BULLISH); + double bearishLiquidityPercent = lastPivot + .CalculateLiquidityPercent(X_DIRECTION_BEARISH); + double minLiquidityPercent = 35; + bool hasBullishLiquidity = bullishLiquidityPercent >= minLiquidityPercent; + bool hasBearishLiquidity = bearishLiquidityPercent >= minLiquidityPercent; + result = hasBullishLiquidity || + hasBearishLiquidity; + if (!result) + { + return result; + } + + +///////////////////////////////////////////////////////////////// + + // // + // // 1D Period ... + // // POI Detector ... + // m1DPOI = new XCPOIDetector( + // symbol, + // PERIOD_D1 // + // ); + + // // + // m1DPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m1DPOI.Init(); + + // // + // // 4H Period ... + // // POI Detector ... + // m4HPOI = new XCPOIDetector( + // symbol, + // PERIOD_H4 // + // ); + + // // + // m4HPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m4HPOI.Init(); + + // // + // // 2H Period ... + // // POI Detector ... + // m2HPOI = new XCPOIDetector( + // symbol, + // PERIOD_H2 // + // ); + + // // + // m2HPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m2HPOI.Init(); + + // + // 1H Period ... + // POI Detector ... + // m1HPOI = new XCPOIDetector( + // symbol, + // PERIOD_H1 // + // ); + + // // + // m1HPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m1HPOI.Init(); + + // + // 15M Period ... + // POI Detector ... + // m15MPOI = new XCPOIDetector( + // symbol, + // PERIOD_M15 // + // ); + + // // + // m15MPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m15MPOI.Init(); + + // // + // // 5M Period ... + // // POI Detector ... + // m5MPOI = new XCPOIDetector( + // symbol, + // PERIOD_M5 // + // ); + + // // + // m5MPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m5MPOI.Init(); + + // // + // // 1M Period ... + // // POI Detector ... + // m1MPOI = new XCPOIDetector( + // symbol, + // PERIOD_M1 // + // ); + + // // + // m1MPOI.MaxNumberOfRequiredPOIs(poiRequired); + + // // + // m1MPOI.Init(); + + +//////////////////////////////// + + // delete m1DPOI; + // delete m4HPOI; + // delete m2HPOI; + delete m1HPOI; + delete m15MPOI; + // delete m5MPOI; + // delete m1MPOI; + + +/////////////////////////////////// + + + // + // Point Of Interests ... + XCPOIDetector *mTriggerPOIDetector; + XCPOIDetector *mAnalysePOIDetector; + XCPOIDetector *mVisionPOIDetector; + + // + // XCPOIDetector *m1DPOI; + // XCPOIDetector *m4HPOI; + // XCPOIDetector *m2HPOI; + // XCPOIDetector *m1HPOI; + // XCPOIDetector *m15MPOI; + // XCPOIDetector *m5MPOI; + // XCPOIDetector *m1MPOI; + + // + XPOIState mTriggerPOIState; + XPOIState mAnalysePOIState; + XPOIState mVisionPOIState; + + // XPOIState _1DState; + // XPOIState _4HState; + // XPOIState _2HState; + // XPOIState _1HState; + // XPOIState _15MState; + // XPOIState _5MState; + // XPOIState _1MState; + // XPOIState _CombineState; + + + +/////////////////////////////////////////// + + // + // Update POIs ... + + // + ENUM_XPOI_EVENTS _events[]; + mPOIDetector.Update(_events); + + // // + // ENUM_XPOI_EVENTS _1DStates[]; + // m1DPOI.Update(_1DStates); + + // // + // ENUM_XPOI_EVENTS _4HStates[]; + // m4HPOI.Update(_4HStates); + + // // + // ENUM_XPOI_EVENTS _2HStates[]; + // m2HPOI.Update(_2HStates); + + // + ENUM_XPOI_EVENTS _1HStates[]; + m1HPOI.Update(_1HStates); + + // // + // ENUM_XPOI_EVENTS _15MStates[]; + // m15MPOI.Update(_15MStates); + + // // + // ENUM_XPOI_EVENTS _5MStates[]; + // m5MPOI.Update(_5MStates); + + // // + // ENUM_XPOI_EVENTS _1MStates[]; + // m1MPOI.Update(_1MStates); + + // // + // // Read all POI States ... + mPOIDetector.GetState(_state); + // m1DPOI.GetState(_1DState); + // m4HPOI.GetState(_4HState); + // m2HPOI.GetState(_2HState); + m1HPOI.GetState(_1HState); + // m15MPOI.GetState(_15MState); + // m5MPOI.GetState(_5MState); + // m1MPOI.GetState(_1MState); + + // + // Combine States ... + // XPOIState _States[]; + // AddRef( + // _1DState, + // _States // + // ); + // AddRef( + // _4HState, + // _States // + // ); + // AddRef( + // _2HState, + // _States // + // ); + // AddRef( + // _1HState, + // _States // + // ); + // AddRef( + // _15MState, + // _States // + // ); + // AddRef( + // _5MState, + // _States // + // ); + // AddRef( + // _1MState, + // _States // + // ); + // CombineStates( + // _CombineState, + // _States // + // ); + + +//////////////////////////////////////////////////////////////// + + // + // Works by WVAP and PSar ... + bool long1 = + // + conditions.x3vwapConditions.isBullishState && + conditions.x3vwapConditions.isBullishOrdered && + // conditions.xpvConditions.vales[cIndex] == conditions.xchsarConditions.cSars[cIndex] && + conditions.xchsarConditions.cSars[cIndex] < conditions.x3vwapConditions.slows[cIndex] + // + ; + if (long1) + { + // + CustomStateDrawing(_1HState); + selectedSL = conditions.xpvConditions.vales[cIndex]; + } + + // + // Works by WVAP and PSar ... + bool short1 = + // + conditions.x3vwapConditions.isBearishState && + conditions.x3vwapConditions.isBearishOrdered && + // conditions.xpvConditions.peaks[cIndex] == conditions.xchsarConditions.cSars[cIndex] && + conditions.xchsarConditions.cSars[cIndex] > conditions.x3vwapConditions.slows[cIndex] + // + ; + if (short1) + { + // + CustomStateDrawing(_1HState); + selectedSL = conditions.xpvConditions.peaks[cIndex]; + } + + +///////////////////////////////////////////////////////////////////////////////////////////////////// + + // mOrderFlow[pivotIDX].state.ticksZone = + //_15MState.ticksZone; + + // // + // // D1 ... + // XPOIState d1; + // if (_1DState.HasChild()) + // { + // // + // DetectPivotPOIs( + // mOrderFlow[pivotIDX], + // _1DState, + // d1, + // lookupSwingHighs, + // lookupSwingLows, + // lookupSupportZones, + // lookupResistanceZones, + // lookupSupplyZones, + // lookupDemandZones, + // lookupBullishOrderBlocks, + // lookupBearishOrderBlocks, + // lookupBullishFairValueGaps, + // lookupBearishFairValueGaps, + // lookupBullishRejectionBars, + // lookupBearishRejectionBars, + // lookupBullishMomentumBars, + // lookupBearishMomentumBars // + // ); + + // // + // if (d1.HasChild()) + // { + // d1.Fill(mOrderFlow[pivotIDX].state); + // } + // } + + // // + // // H4 ... + // XPOIState h4; + // if (_4HState.HasChild()) + // { + // // + // DetectPivotPOIs( + // mOrderFlow[pivotIDX], + // _4HState, + // h4, + // lookupSwingHighs, + // lookupSwingLows, + // lookupSupportZones, + // lookupResistanceZones, + // lookupSupplyZones, + // lookupDemandZones, + // lookupBullishOrderBlocks, + // lookupBearishOrderBlocks, + // lookupBullishFairValueGaps, + // lookupBearishFairValueGaps, + // lookupBullishRejectionBars, + // lookupBearishRejectionBars, + // lookupBullishMomentumBars, + // lookupBearishMomentumBars // + // ); + + // // + // if (h4.HasChild()) + // { + // h4.Fill(mOrderFlow[pivotIDX].state); + // } + // } + + // + // H2 ... + // XPOIState h2; + // if (_2HState.HasChild()) + // { + // // + // DetectPivotPOIs( + // mOrderFlow[pivotIDX], + // _2HState, + // h2, + // lookupSwingHighs, + // lookupSwingLows, + // lookupSupportZones, + // lookupResistanceZones, + // lookupSupplyZones, + // lookupDemandZones, + // lookupBullishOrderBlocks, + // lookupBearishOrderBlocks, + // lookupBullishFairValueGaps, + // lookupBearishFairValueGaps, + // lookupBullishRejectionBars, + // lookupBearishRejectionBars, + // lookupBullishMomentumBars, + // lookupBearishMomentumBars // + // ); + + // // + // if (h2.HasChild()) + // { + // h2.Fill(mOrderFlow[pivotIDX].state); + // } + // } + + // + // H1 ... + XPOIState h1; + if (_1HState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + _1HState, + h1, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (h1.HasChild()) + { + h1.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // M15 ... + // XPOIState m15; + // if (_15MState.HasChild()) + // { + // // + // DetectPivotPOIs( + // mOrderFlow[pivotIDX], + // _15MState, + // m15, + // lookupSwingHighs, + // lookupSwingLows, + // lookupSupportZones, + // lookupResistanceZones, + // lookupSupplyZones, + // lookupDemandZones, + // lookupBullishOrderBlocks, + // lookupBearishOrderBlocks, + // lookupBullishFairValueGaps, + // lookupBearishFairValueGaps, + // lookupBullishRejectionBars, + // lookupBearishRejectionBars, + // lookupBullishMomentumBars, + // lookupBearishMomentumBars // + // ); + + // // + // if (m15.HasChild()) + // { + // m15.Fill(mOrderFlow[pivotIDX].state); + // } + // } + + // + // M5 ... + // XPOIState m5; + // if (_5MState.HasChild()) + // { + // // + // DetectPivotPOIs( + // mOrderFlow[pivotIDX], + // _5MState, + // m5, + // lookupSwingHighs, + // lookupSwingLows, + // lookupSupportZones, + // lookupResistanceZones, + // lookupSupplyZones, + // lookupDemandZones, + // lookupBullishOrderBlocks, + // lookupBearishOrderBlocks, + // lookupBullishFairValueGaps, + // lookupBearishFairValueGaps, + // lookupBullishRejectionBars, + // lookupBearishRejectionBars, + // lookupBullishMomentumBars, + // lookupBearishMomentumBars // + // ); + + // // + // if (m5.HasChild()) + // { + // m5.Fill(mOrderFlow[pivotIDX].state); + // } + // } + + // + // M1 ... + // XPOIState m1; + // if (_1MState.HasChild()) + // { + // // + // DetectPivotPOIs( + // mOrderFlow[pivotIDX], + // _1MState, + // m1, + // lookupSwingHighs, + // lookupSwingLows, + // lookupSupportZones, + // lookupResistanceZones, + // lookupSupplyZones, + // lookupDemandZones, + // lookupBullishOrderBlocks, + // lookupBearishOrderBlocks, + // lookupBullishFairValueGaps, + // lookupBearishFairValueGaps, + // lookupBullishRejectionBars, + // lookupBearishRejectionBars, + // lookupBullishMomentumBars, + // lookupBearishMomentumBars // + // ); + + // // + // if (m1.HasChild()) + // { + // m1.Fill(mOrderFlow[pivotIDX].state); + // } + // } diff --git a/Indicators/x-saherelm.xct.mq5 b/Indicators/x-saherelm.xct.mq5 index 547940d5..ebb08a4e 100644 --- a/Indicators/x-saherelm.xct.mq5 +++ b/Indicators/x-saherelm.xct.mq5 @@ -43,7 +43,7 @@ input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position // input group "Presentation"; -input bool showCandleTime = true; // Show Candle Time +input bool showTimer = true; // Show Candle Time // // END Inputs ... @@ -67,6 +67,7 @@ input bool showCandleTime = true; // Show Candle Time // // START Global Definitions: Variables, Properties and etc ... // +bool isCreatedObject; string tag; // // END Global Definitions: Variables, Properties and etc ... @@ -86,16 +87,6 @@ int OnInit() // tag = ShortName + _Symbol + ToString(_Period); - // - if (showCandleTime) - { - CreateIndicatorObject(); - } - else - { - ObjectDelete(0, tag); - } - // // Set Indicator ShortName ... SetIndicatorName(); @@ -145,21 +136,11 @@ int OnCalculate( ) { // - ArraySetAsSeries(time, true); - - // - if (!showCandleTime) + if (!showTimer) { return rates_total; } - // - ulong chID = FindChartID( - _Symbol, - _Period - // - ); - // XBarRemainsTime barRemains; barRemains.Init( @@ -191,20 +172,20 @@ int OnCalculate( else if (mSpread < 100) _sp = "."; - // - // int offset = TimeGMTOffset(); - // string timeString = - // ", Time: " + string(TimeCurrent()) + "\n" + - // ", ServerTime: " + string(TimeTradeServer()) + "\n" + - // ", GMT Offset: " + (string)offset; - // timeString = timeString; - // Comment(timeString); - // string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg; // - ObjectSetString(0, tag, OBJPROP_TEXT, objText); + if (IsValid(tag) && !isCreatedObject) + { + CreateIndicatorObject(); + } + + // + if (isCreatedObject) + { + ObjectSetString(0, tag, OBJPROP_TEXT, objText); + } // return rates_total; @@ -229,16 +210,17 @@ void SetIndicatorName() void CreateIndicatorObject() { // - if (!showCandleTime) + if (!showTimer || + !IsValid(tag)) { return; } // - ObjectCreate(0, tag, OBJ_LABEL, 0, 0, 0); + isCreatedObject = ObjectCreate(0, tag, OBJ_LABEL, 0, 0, 0); ObjectSetInteger(0, tag, OBJPROP_CORNER, corner); ObjectSetInteger(0, tag, OBJPROP_XDISTANCE, 10); - ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); + ObjectSetInteger(0, tag, OBJPROP_YDISTANCE, 2); // ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER; diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index fae4b2e2..235d580b 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -2382,6 +2382,10 @@ class XCTickZone : public CObject int ticks; double percent; + // + ulong volume; + double volumePercent; + // // Compare Two Zone With Each Other ... virtual int Compare( @@ -2535,6 +2539,25 @@ class XCTicksZone : public XCTwoBarZone toM // ); + // + // Ticks Volumes ... + int ticksVolumeCount = CopyTickVolume( + symbol, + PERIOD_M1, + from, + to, + mTickVolumes // + ); + if (IsValidSize(ticksVolumeCount)) + { + // + mVolumes = 0; + for (int i = 0; i < ticksVolumeCount; i++) + { + mVolumes += mTickVolumes[i]; + } + } + // // Retrieve Highs ... SpecificClean(mHighs); @@ -2664,6 +2687,74 @@ class XCTicksZone : public XCTwoBarZone // result = IsValid(); + // + // Try to Find Out PERIOD_1M times in each zone ... + datetime to1M = (datetime)((int)endBar.time + PeriodSeconds(period) - 60); + int to1MIndex = iBarShift( + symbol, + PERIOD_M1, + to1M // + ); + int from1MIndex = iBarShift( + symbol, + PERIOD_M1, + from // + ); + for (int i = from1MIndex; i > to1MIndex; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + PERIOD_M1, + i // + ); + if (!isInited) + { + continue; + } + ulong iVolume = iTickVolume( + symbol, + PERIOD_M1, + i // + ); + + // + // Loop through Zones ... + for (int j = 0; j < Levels(); j++) + { + // + XCTickZone *jZone = mZones.At(j); + if (!jZone.IsValid()) + { + continue; + } + + // + // Check iBar is Inside jZone ... + bool isIBarInside = + iBar.GetUp() < jZone.high && + iBar.GetDown() > jZone.low; + // iBar.low < jZone.high || + // iBar.high > jZone.low; + if (isIBarInside) + { + jZone.volume += iVolume; + } + } + } + + // + // Calculate Volume Percent ... + for (int i = 0; i < Levels(); i++) + { + // + XCTickZone *iZone = mZones.At(i); + + // + iZone.volumePercent = (double)(iZone.volume * 100 / mVolumes); + } + // return result; } @@ -2787,6 +2878,8 @@ class XCTicksZone : public XCTwoBarZone MqlTick mTicks[]; double mHighs[]; double mLows[]; + ulong mVolumes; + ulong mTickVolumes[]; double mRangeHigh; datetime mRangeHighTime; double mRangeLow; diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index f26cc049..184ee21e 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -368,78 +368,22 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // Update POIs ... // - ENUM_XPOI_EVENTS _1DStates[]; - m1DPOI.Update(_1DStates); + // Trigger ... + ENUM_XPOI_EVENTS triggerPOIEvents[]; + mTriggerPOIDetector.Update(triggerPOIEvents); + mTriggerPOIDetector.GetState(mTriggerPOIState); // - ENUM_XPOI_EVENTS _4HStates[]; - m4HPOI.Update(_4HStates); + // Analyse ... + ENUM_XPOI_EVENTS analysePOIEvents[]; + mAnalysePOIDetector.Update(analysePOIEvents); + mAnalysePOIDetector.GetState(mAnalysePOIState); // - ENUM_XPOI_EVENTS _2HStates[]; - m2HPOI.Update(_2HStates); - - // - ENUM_XPOI_EVENTS _1HStates[]; - m1HPOI.Update(_1HStates); - - // - ENUM_XPOI_EVENTS _15MStates[]; - m15MPOI.Update(_15MStates); - - // - ENUM_XPOI_EVENTS _5MStates[]; - m5MPOI.Update(_5MStates); - - // - ENUM_XPOI_EVENTS _1MStates[]; - m1MPOI.Update(_1MStates); - - // - // Read all POI States ... - m1DPOI.GetState(_1DState); - m4HPOI.GetState(_4HState); - m2HPOI.GetState(_2HState); - m1HPOI.GetState(_1HState); - m15MPOI.GetState(_15MState); - m5MPOI.GetState(_5MState); - m1MPOI.GetState(_1MState); - - // - // Combine States ... - XPOIState _States[]; - AddRef( - _1DState, - _States // - ); - AddRef( - _4HState, - _States // - ); - AddRef( - _2HState, - _States // - ); - AddRef( - _1HState, - _States // - ); - AddRef( - _15MState, - _States // - ); - AddRef( - _5MState, - _States // - ); - AddRef( - _1MState, - _States // - ); - CombineStates( - _CombineState, - _States // - ); + // Trigger ... + ENUM_XPOI_EVENTS visionPOIEvents[]; + mVisionPOIDetector.Update(visionPOIEvents); + mVisionPOIDetector.GetState(mVisionPOIState); // // Check Current Processing Tick has Signal or not ... @@ -530,23 +474,14 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // // Point Of Interests ... - XCPOIDetector *m1DPOI; - XCPOIDetector *m4HPOI; - XCPOIDetector *m2HPOI; - XCPOIDetector *m1HPOI; - XCPOIDetector *m15MPOI; - XCPOIDetector *m5MPOI; - XCPOIDetector *m1MPOI; + XCPOIDetector *mTriggerPOIDetector; + XCPOIDetector *mAnalysePOIDetector; + XCPOIDetector *mVisionPOIDetector; // - XPOIState _1DState; - XPOIState _4HState; - XPOIState _2HState; - XPOIState _1HState; - XPOIState _15MState; - XPOIState _5MState; - XPOIState _1MState; - XPOIState _CombineState; + XPOIState mTriggerPOIState; + XPOIState mAnalysePOIState; + XPOIState mVisionPOIState; // XCPOIDrawer *mPOIDrawer; // POI Drawer Class ... @@ -1586,102 +1521,33 @@ class XCX121SMCBaseStrategy : public XCBaseAlert int poiRequired = 10; // - // 1D Period ... - // POI Detector ... - m1DPOI = new XCPOIDetector( + // Trigger ... + mTriggerPOIDetector = new XCPOIDetector( symbol, - PERIOD_D1 // + period // ); + mTriggerPOIDetector.MaxNumberOfRequiredPOIs(poiRequired); + mTriggerPOIDetector.Init(); // - m1DPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m1DPOI.Init(); - - // - // 4H Period ... - // POI Detector ... - m4HPOI = new XCPOIDetector( + // Analyse ... + ENUM_TIMEFRAMES analysePeriod = GetAnalysePeriod(period); + mAnalysePOIDetector = new XCPOIDetector( symbol, - PERIOD_H4 // + analysePeriod // ); + mAnalysePOIDetector.MaxNumberOfRequiredPOIs(poiRequired); + mAnalysePOIDetector.Init(); // - m4HPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m4HPOI.Init(); - - // - // 2H Period ... - // POI Detector ... - m2HPOI = new XCPOIDetector( + // Vision ... + ENUM_TIMEFRAMES visionPeriod = GetVisionPeriod(period); + mVisionPOIDetector = new XCPOIDetector( symbol, - PERIOD_H2 // + visionPeriod // ); - - // - m2HPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m2HPOI.Init(); - - // - // 1H Period ... - // POI Detector ... - m1HPOI = new XCPOIDetector( - symbol, - PERIOD_H1 // - ); - - // - m1HPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m1HPOI.Init(); - - // - // 15M Period ... - // POI Detector ... - m15MPOI = new XCPOIDetector( - symbol, - PERIOD_M15 // - ); - - // - m15MPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m15MPOI.Init(); - - // - // 5M Period ... - // POI Detector ... - m5MPOI = new XCPOIDetector( - symbol, - PERIOD_M5 // - ); - - // - m5MPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m5MPOI.Init(); - - // - // 1M Period ... - // POI Detector ... - m1MPOI = new XCPOIDetector( - symbol, - PERIOD_M1 // - ); - - // - m1MPOI.MaxNumberOfRequiredPOIs(poiRequired); - - // - m1MPOI.Init(); + mVisionPOIDetector.MaxNumberOfRequiredPOIs(poiRequired); + mVisionPOIDetector.Init(); // } @@ -1692,11 +1558,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert void DeInit() { // - delete m1DPOI; - delete m4HPOI; - delete m5MPOI; - delete m1MPOI; - delete m15MPOI; + delete mTriggerPOIDetector; + delete mAnalysePOIDetector; + delete mVisionPOIDetector; // delete mPOIDrawer; diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 80b23001..2c49e97b 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -619,6 +619,155 @@ typedef void (*TOnX121SMCSignal)( X121SMCStrategyConditions &conditions // ); +// +// Time Frames Tools ... + +/** + * Calculate Analyse Period ... + * + * @param value: ENUM_TIMEFRAMES member, Specified Trigger Period ... + * + * @return ( ENUM_TIMEFRAMES ) + */ +ENUM_TIMEFRAMES GetAnalysePeriod(ENUM_TIMEFRAMES value) +{ + // + ENUM_TIMEFRAMES result = NULL; + + // + value = NormalizePeriod(value); + + // + switch (value) + { + // + case PERIOD_M1: + case PERIOD_M2: + case PERIOD_M3: + case PERIOD_M4: + case PERIOD_M5: + case PERIOD_M6: + case PERIOD_M10: + case PERIOD_M12: + result = PERIOD_M15; + break; + + // + case PERIOD_M15: + case PERIOD_M20: + result = PERIOD_M30; + break; + + // + case PERIOD_H1: + case PERIOD_H2: + case PERIOD_H3: + result = PERIOD_H4; + break; + + // + case PERIOD_H4: + case PERIOD_H6: + case PERIOD_H8: + result = PERIOD_H12; + break; + + // + default: + result = NULL; + } + + // + return result; +} +bool HasValidAnalysePeriod( + ENUM_TIMEFRAMES value, + ENUM_TIMEFRAMES &period // +) +{ + // + bool result = false; + + period = GetAnalysePeriod(value); + result = IsValid(period); + + // + return result; +} + +/** + * Calculate Vision Period ... + * + * @param value: ENUM_TIMEFRAMES member, Specified Trigger Period ... + * + * @return ( ENUM_TIMEFRAMES ) + */ +ENUM_TIMEFRAMES GetVisionPeriod(ENUM_TIMEFRAMES value) +{ + // + ENUM_TIMEFRAMES result = NULL; + + // + value = NormalizePeriod(value); + + // + switch (value) + { + // + case PERIOD_M1: + case PERIOD_M2: + case PERIOD_M3: + case PERIOD_M4: + case PERIOD_M5: + case PERIOD_M6: + case PERIOD_M10: + case PERIOD_M12: + result = PERIOD_H1; + break; + + // + case PERIOD_M15: + case PERIOD_M20: + result = PERIOD_H2; + break; + + // + case PERIOD_H1: + case PERIOD_H2: + case PERIOD_H3: + result = PERIOD_H6; + break; + + // + case PERIOD_H4: + case PERIOD_H6: + case PERIOD_H8: + result = PERIOD_D1; + break; + + // + default: + result = NULL; + } + + // + return result; +} +bool HasValidVisionPeriod( + ENUM_TIMEFRAMES value, + ENUM_TIMEFRAMES &period // +) +{ + // + bool result = false; + + period = GetVisionPeriod(value); + result = IsValid(period); + + // + return result; +} + // // Extentions ... diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 1c7c1d5d..8e8b94e9 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -108,6 +108,9 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy bool hasLong = false; bool hasShort = false; + // + double selectedSL = 0; + // // Start Calculations ... @@ -171,6 +174,38 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + // + // Prepare Areas ... + double bid = GetBid(_symbol); + + // + // Check Momentum Bar ... + ENUM_X_DIRECTION momentumBarDir; + bool isCMomentumBar = mBarAnalyser.IsMomentumBar( + cBar, + momentumBarDir // + ); + bool isCBullishMomentumBar = + isCMomentumBar && + IsBullish(momentumBarDir); + bool isCBearishMomentumBar = + isCMomentumBar && + IsBearish(momentumBarDir); + + // + // Check Rejection Bar ... + ENUM_X_DIRECTION rejectionBarDir; + bool isCRejectionBar = mBarAnalyser.IsRejectionBar( + cBar, + rejectionBarDir // + ); + bool isCBullishRejectionBar = + isCRejectionBar && + IsBullish(rejectionBarDir); + bool isCBearishRejectionBar = + isCRejectionBar && + IsBearish(rejectionBarDir); + // bool isSpreadPassed = IsSpreadPass(); result = isSpreadPassed; @@ -187,6 +222,15 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } + // + // Validate Order Flow ... + bool isValidOrderFlow = HasValidOrderFlow(); + result = isValidOrderFlow; + if (!result) + { + return result; + } + // XPVPivot lastPivot; result = GetLastItem( @@ -197,390 +241,154 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy { return result; } - bool isBullishOrderFlow = IsBullish(mOrderFlowDir); - bool isBearishOrderFlow = IsBearish(mOrderFlowDir); - double pivotMid = lastPivot.CalculateMid(); - // RedrawOrderFlow(); // - // Calculate Liquidity Percent ... - double bullishLiquidityPercent = lastPivot - .CalculateLiquidityPercent(X_DIRECTION_BULLISH); - double bearishLiquidityPercent = lastPivot - .CalculateLiquidityPercent(X_DIRECTION_BEARISH); + bool isOrderFlowBullish = IsBullish(mOrderFlowDir); // - // Detect Order Blocks ... - int obsCount = 0; + // Check BOS or CHOCH Happens ... + bool hasBOS = + isOrderFlowBullish + ? + // + // Price Close Over Pivot's High ... + cBar.IsBullish() && + cBar.close > lastPivot.upper + // + : + // + // Price Must Close Under Pivots Low ... + cBar.IsBearish() && + cBar.close < lastPivot.lower + // + ; + bool hasCHOCH = + isOrderFlowBullish + ? + // + // Price Close Under Pivot's Low ... + cBar.IsBearish() && + cBar.close < lastPivot.lower + // + : + // + // Price Must Close Over Pivots High ... + cBar.IsBullish() && + cBar.close > lastPivot.upper + // + ; // - // Find Bullish Order Block ... - XCOrderBlock *bullishOB = NULL; - obsCount = lastPivot.state.CountBullishOrderBlocks(); - if (IsValidSize(obsCount)) + if (hasBOS || hasCHOCH) { // - for (int i = 0; i < obsCount; i++) + RedrawOrderFlow(); + + // + string mTitle = + hasBOS ? "BOS" + : "CHOCH"; + + // + Print(mTitle); + + // + // Here We Have to Decide How to Act Based On + // Conditions for Updating Order Flow ... + if (hasCHOCH) { // - XCOrderBlock *iOB = lastPivot.state.bullishOrderBlocks[i]; - - // - XOHCL iBar; - bool hasBar = iOB.FillBar(iBar); - bool isPeriodSame = hasBar && - iBar.period == _period; - - // - if (iOB.Upper() <= pivotMid && - iOB.Lower() >= lastPivot.lower) - { + hasLong = // - bullishOB = iOB; - break; + !isOrderFlowBullish && + cBar.IsBullish() && + (isCBullishMomentumBar || + isCBullishRejectionBar) && + conditions.xchsarConditions.cSars[0] < cBar.low + // + ; + if (hasLong) { + // + // selectedSL = conditions.xpvConditions.peaks[1]; + selectedSL = conditions.xchsarConditions.cSars[1]; + } + + // + hasShort = + // + isOrderFlowBullish && + cBar.IsBearish() && + (isCBearishMomentumBar || + isCBearishRejectionBar) && + conditions.xchsarConditions.cSars[0] > cBar.high + // + ; + if (hasLong) { + // + // selectedSL = conditions.xpvConditions.vales[1]; + selectedSL = conditions.xchsarConditions.cSars[1]; } } } - bool hasBullishOB = bullishOB != NULL; - if (hasBullishOB) + + // + // Check Parabolic Sar is in Order of Order Flow ... + bool isPSarInDirectionOfOrderFlow = + isOrderFlowBullish + ? conditions.xchsarConditions.cSars[0] < cBar.low && + conditions.xchsarConditions.cSars[1] >= pBar.low + : conditions.xchsarConditions.cSars[0] > cBar.high && + conditions.xchsarConditions.cSars[1] <= pBar.high; + + // + if (isPSarInDirectionOfOrderFlow) { - // - bullishOB.To(cTime); - XCBullishOrderBlockObject *iObj; - bool isCreated = mPOIDrawer.CreateBullishOrderBlock( - bullishOB, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } + RedrawOrderFlow(); + Print(""); + } + else + { + ClearDraws(); } // - // Find Bearish Order Block ... - XCOrderBlock *bearishOB = NULL; - obsCount = lastPivot.state.CountBearishOrderBlocks(); - if (IsValidSize(obsCount)) + bool long1 = + // + false + // + ; + if (long1) { // - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = lastPivot.state.bearishOrderBlocks[i]; - - // - XOHCL iBar; - bool hasBar = iOB.FillBar(iBar); - bool isPeriodSame = hasBar && - iBar.period == _period; - - // - if (iOB.Lower() >= pivotMid && - iOB.Upper() <= lastPivot.upper) - { - // - bearishOB = iOB; - break; - } - } - } - bool hasBearishOB = bearishOB != NULL; - if (hasBearishOB) - { - // - bearishOB.To(cTime); - XCBearishOrderBlockObject *iObj; - bool isCreated = mPOIDrawer.CreateBearishOrderBlock( - bearishOB, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } + CustomStateDrawing(mTriggerPOIState); + selectedSL = conditions.xpvConditions.vales[cIndex]; } // - // Find an Order Block ... - bool isBearishOrderBlockRejected = false; - - // - // Check Candlestick PullBacks ... - ENUM_X_DIRECTION pullBackDir; - bool hasPullBack = mBarAnalyser.HasPullBack( - pullBackDir, - cBar, - 3, // Loopback ... - true // Force Body ... - ); - bool hasBullishPullback = - hasPullBack && - pullBackDir == X_DIRECTION_BULLISH; - bool hasBearishPullback = - hasPullBack && - pullBackDir == X_DIRECTION_BEARISH; - - // - // Check 3MA and 3VWAP State ... - - // - bool isVWAPBullishOrdered = + // Works by WVAP and PSar ... + bool short1 = // - ( - // - (conditions.x3vwapConditions.isBullishOrdered || - conditions.x3vwapConditions.isSwitchedToBullishOrdered) - // - || - // - conditions.x3vwapConditions.fasts[cIndex] > conditions.x3vwapConditions.mids[cIndex] - // - || - // - conditions.x3vwapConditions.mids[cIndex] > conditions.x3vwapConditions.slows[cIndex] - // - ) + false // ; - - // - bool isVWAPBearishOrdered = - // - ( - // - (conditions.x3vwapConditions.isBearishOrdered || - conditions.x3vwapConditions.isSwitchedToBearishOrdered) - // - || - // - conditions.x3vwapConditions.fasts[cIndex] < conditions.x3vwapConditions.mids[cIndex] - // - || - // - conditions.x3vwapConditions.mids[cIndex] < conditions.x3vwapConditions.slows[cIndex] - // - ) - // - ; - - // - bool isVWapBullishState = - // - ( - // - (conditions.x3vwapConditions.isBullishState || - conditions.x3vwapConditions.isSwitchedToBullishState) - // - || - // - (x3vwapHelper.IsBullish(conditions.x3vwapConditions.fastStates[cIndex]) && - x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex])) - // - || - // - (x3vwapHelper.IsBullish(conditions.x3vwapConditions.midStates[cIndex]) && - x3vwapHelper.IsBullish(conditions.x3vwapConditions.slowStates[cIndex])) - // - ) - // - ; - - // - bool isVWapBearishState = - // - ( - // - (conditions.x3vwapConditions.isBearishState || - conditions.x3vwapConditions.isSwitchedToBearishState) - // - || - // - (x3vwapHelper.IsBearish(conditions.x3vwapConditions.fastStates[cIndex]) && - x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex])) - // - || - // - (x3vwapHelper.IsBearish(conditions.x3vwapConditions.midStates[cIndex]) && - x3vwapHelper.IsBearish(conditions.x3vwapConditions.slowStates[cIndex])) - // - ) - // - ; - - // - bool isVWapOverFastMA = - // - ( - // - (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex]) - // - || - // - (conditions.x3vwapConditions.fasts[cIndex] > conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] > conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.slows[cIndex] > conditions.x3maConditions.fasts[cIndex]) - // - ) - // - ; - - // - bool isVWapUnderFastMA = - // - ( - // - (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex]) - // - || - // - (conditions.x3vwapConditions.fasts[cIndex] < conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.mids[cIndex] < conditions.x3maConditions.fasts[cIndex] && - conditions.x3vwapConditions.slows[cIndex] < conditions.x3maConditions.fasts[cIndex]) - // - ) - // - ; - - // - bool is3Bullish = - // - ( - // - (isVWAPBullishOrdered && - isVWapBullishState) - // - || - // - (isVWAPBullishOrdered && - isVWapOverFastMA) - // - || - // - (isVWapBullishState && - isVWapOverFastMA) - // - ) - // - ; - - // - bool is3Bearish = - // - ( - // - (isVWAPBearishOrdered && - isVWapBearishState) - // - || - // - (isVWAPBearishOrdered && - isVWapUnderFastMA) - // - || - // - (isVWapBearishState && - isVWapUnderFastMA) - // - ) - // - ; - - // - // Check Parabolic Sars State ... - - // - bool isSarBullish = - // - (conditions.xchsarConditions.isCBullish && - conditions.xchsarConditions.isSSwitchedBullish) - // - || - // - (conditions.xchsarConditions.isSBullish && - conditions.xchsarConditions.isCSwitchedBullish) - // - ; - bool isSarBearish = - // - (conditions.xchsarConditions.isCBearish && - conditions.xchsarConditions.isSSwitchedBearish) - // - || - // - (conditions.xchsarConditions.isSBearish && - conditions.xchsarConditions.isCSwitchedBearish) - // - ; - - // - // Prepare Areas ... - double bid = GetBid(_symbol); - - // - bool isInDiscount = - bid < pivotMid && - bid > lastPivot.lower; - - // - bool isInPremium = - bid > pivotMid && - bid < lastPivot.upper; - - // - // Check Order Flow Validation ... - - // - // For Bullish Order Flow ... - // if Price Breakes Lower to Down, means Change of Charcter Happens ... - bool isCHOCHHappens = - isBullishOrderFlow ? bid < lastPivot.lower - pip - : bid > lastPivot.upper + pip; - - // - // For Bullish Order Flow ... - // if Price Breakes Upper to Up, means Breake of Structure Happens ... - bool isBOSHappens = - isBullishOrderFlow ? bid > lastPivot.upper + pip - : bid < lastPivot.lower - pip; - - // - if (isBOSHappens) + if (short1) { // - // RedrawOrderFlow(); - } - - // - if (isCHOCHHappens) - { - // - result = false; - ResetOrderFlow(); - return result; + CustomStateDrawing(mTriggerPOIState); + selectedSL = conditions.xpvConditions.peaks[cIndex]; } // // // hasLong = // // - // is3Bullish && - // // isInDiscount && - // isSarBullish // && - // // hasBullishPullback && - // // bullishLiquidityPercent > 30 + // long1 // // // ; // // // hasShort = // // - // is3Bearish && - // // isInPremium && - // isSarBearish // && - // // hasBearishPullback && - // // bearishLiquidityPercent > 30 + // short1 // // // ; @@ -610,17 +418,17 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ); // - double candidates[]; - DetectSLCandidates( - candidates, - entry, - conditions, - xType // - ); - double selectedSL = - hasLong - ? GetMax(candidates) - : GetMin(candidates); + // double candidates[]; + // DetectSLCandidates( + // candidates, + // entry, + // conditions, + // xType // + // ); + // double selectedSL = + // hasLong + // ? GetMax(candidates) + // : GetMin(candidates); sl = hasLong ? selectedSL - pip2 @@ -649,10 +457,10 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy signal.entry = entry; signal.volume = volume; signal.symbol = _symbol; + signal.period = _period; signal.pushers = pushers; signal.provider = GetTag(); signal.time = TimeCurrent(); - signal.period = _5MState.period; // result = PrepareSignal(signal); @@ -720,6 +528,18 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy result // ); + // + Add( + conditions.xpvConditions.vales[cIndex], + result // + ); + + // + Add( + conditions.xpvConditions.peaks[cIndex], + result // + ); + // } @@ -849,13 +669,12 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy if (ArraySize(mOrderFlow) == 0 || mOrderFlowDir == X_DIRECTION_NONE) { - // // int samePivots = 40; int requiredPivots = 10; // - DetectPVPivots( + DetectOrderFlow( cIndex, samePivots, requiredPivots, @@ -872,12 +691,15 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy } // - // Check Order Flow Direction ... - // result = mOrderFlowDir != X_DIRECTION_NONE; - // if (!result) - // { - // return result; - // } + if (result) + { + // + int lastPivotIDX = ArraySize(mOrderFlow) - 1; + if (IsValidSize(lastPivotIDX)) + { + FillPivotSate(lastPivotIDX); + } + } // return result; @@ -895,7 +717,7 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy * * @return ( bool ) */ - bool DetectPVPivots( + bool DetectOrderFlow( int barIndex, int minRepetition, int requiredPivots, @@ -1180,260 +1002,11 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy int orderFlowCount = ArraySize(mOrderFlow); if (IsValidSize(orderFlowCount)) { - // - 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; - // // Loop Through Order Flow ... for (int i = 0; i < orderFlowCount; i++) { - // - XPVPivot iPivot = mOrderFlow[i]; - mOrderFlow[i].state.ticksZone = _5MState.ticksZone; - - // - // D1 ... - XPOIState d1; - if (_1DState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _1DState, - d1, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (d1.HasChild()) - { - d1.Fill(mOrderFlow[i].state); - } - } - - // - // H4 ... - XPOIState h4; - if (_4HState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _4HState, - h4, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (h4.HasChild()) - { - h4.Fill(mOrderFlow[i].state); - } - } - - // - // H2 ... - XPOIState h2; - if (_2HState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _2HState, - h2, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (h2.HasChild()) - { - h2.Fill(mOrderFlow[i].state); - } - } - - // - // H1 ... - XPOIState h1; - if (_1HState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _1HState, - h1, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (h1.HasChild()) - { - h1.Fill(mOrderFlow[i].state); - } - } - - // - // M15 ... - XPOIState m15; - if (_15MState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _15MState, - m15, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (m15.HasChild()) - { - m15.Fill(mOrderFlow[i].state); - } - } - - // - // M5 ... - XPOIState m5; - if (_5MState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _5MState, - m5, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (m5.HasChild()) - { - m5.Fill(mOrderFlow[i].state); - } - } - - // - // M1 ... - XPOIState m1; - if (_1MState.HasChild()) - { - // - DetectPivotPOIs( - iPivot, - _1MState, - m1, - lookupSwingHighs, - lookupSwingLows, - lookupSupportZones, - lookupResistanceZones, - lookupSupplyZones, - lookupDemandZones, - lookupBullishOrderBlocks, - lookupBearishOrderBlocks, - lookupBullishFairValueGaps, - lookupBearishFairValueGaps, - lookupBullishRejectionBars, - lookupBearishRejectionBars, - lookupBullishMomentumBars, - lookupBearishMomentumBars // - ); - - // - if (m1.HasChild()) - { - m1.Fill(mOrderFlow[i].state); - } - } + FillPivotSate(i); } } @@ -1441,6 +1014,224 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy 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 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 mTriggerState; + if (mTriggerPOIState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mTriggerPOIState, + mTriggerState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mTriggerState.HasChild()) + { + mTriggerState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Analyse ... + XPOIState mAnalyseState; + if (mAnalysePOIState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mTriggerPOIState, + mAnalyseState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mAnalyseState.HasChild()) + { + mAnalyseState.Fill(mOrderFlow[pivotIDX].state); + } + } + + // + // Vision ... + XPOIState mVisionState; + if (mVisionPOIState.HasChild()) + { + // + DetectPivotPOIs( + mOrderFlow[pivotIDX], + mTriggerPOIState, + mVisionState, + lookupSwingHighs, + lookupSwingLows, + lookupSupportZones, + lookupResistanceZones, + lookupSupplyZones, + lookupDemandZones, + lookupBullishOrderBlocks, + lookupBearishOrderBlocks, + lookupBullishFairValueGaps, + lookupBearishFairValueGaps, + lookupBullishRejectionBars, + lookupBearishRejectionBars, + lookupBullishMomentumBars, + lookupBearishMomentumBars // + ); + + // + if (mVisionState.HasChild()) + { + mVisionState.Fill(mOrderFlow[pivotIDX].state); + } + } + } + + /** + * 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 = mTriggerPOIDetector.TicksRangeZoneLevel(); + int ticksRange = mTriggerPOIDetector.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 ... * @@ -2043,20 +1834,20 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy DrawState( tmpState, // State ... true, // Update To of all Drawings Till now ... - false, // Draw SwingHighs .. - false, // Draw SwingLows .. + true, // Draw SwingHighs .. + true, // Draw SwingLows .. false, // Draw SupportZones .. false, // Draw ResistanceZones .. false, // Draw SupplyZones .. false, // Draw DemandZones .. - true, // Draw BullishOrderBlocks .. - true, // Draw BearishOrderBlocks .. + false, // Draw BullishOrderBlocks .. + false, // Draw BearishOrderBlocks .. false, // Draw BullishFairValueGaps .. false, // Draw BearishFairValueGaps .. - false, // Draw BullishRejectionBars .. - false, // Draw BearishRejectionBars .. - false, // Draw BullishMomentumBars .. - false, // Draw BearishMomentumBars .. + true, // Draw BullishRejectionBars .. + true, // Draw BearishRejectionBars .. + true, // Draw BullishMomentumBars .. + true, // Draw BearishMomentumBars .. true // Draw Ticks Zone ... ); } @@ -2078,23 +1869,23 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Short ... - ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_MANUALLY; // How to Find Period - ENUM_TIMEFRAMES scPeriod = PERIOD_M15; // Time Period + 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_MANUALLY; // How to Find Period - ENUM_TIMEFRAMES mcPeriod = PERIOD_M30; // Time Period + 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_MANUALLY; // How to Find Period - ENUM_TIMEFRAMES lcPeriod = PERIOD_H1; // Time Period + 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_MANUALLY; // How to Find Period - ENUM_TIMEFRAMES hcPeriod = PERIOD_H2; // Time Period + ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period + ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period // // XPV ...