diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index b2983039..5c1064aa 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -3332,9 +3332,9 @@ class XCPOIDrawer : public XCBase /** * Draw Specified State Zone ... - * + * * @param source: XStateZones instance Reference ... - * + * * @return ( int ) */ int DrawStateZones( @@ -4363,6 +4363,7 @@ class XCPOIDrawer : public XCBase XPVPivot &pivot, XCBaseObject *&drawnObjects[], bool drawState = false, + bool drawStateAsBox = false, bool drawTicksZone = false, bool ignoreSwingHighs = false, bool ignoreSwingLows = false, @@ -4442,25 +4443,107 @@ class XCPOIDrawer : public XCBase // XCBaseObject *stateObjects[]; - int stateCount = DrawState( - pivot.state, - stateObjects, - drawTicksZone, - ignoreSwingHighs, - ignoreSwingLows, - ignoreSupportZones, - ignoreResistanceZones, - ignoreSupplyZones, - ignoreDemandZones, - ignoreBullishOrderBlocks, - ignoreBearishOrderBlocks, - ignoreBullishFairValueGaps, - ignoreBearishFairValueGaps, - ignoreBullishRejectionBars, - ignoreBearishRejectionBars, - ignoreBullishMomentumBars, - ignoreBearishMomentumBars // - ); + int stateCount = 0; + + // + if (!drawStateAsBox) + { + // + stateCount = DrawState( + pivot.state, + stateObjects, + drawTicksZone, + ignoreSwingHighs, + ignoreSwingLows, + ignoreSupportZones, + ignoreResistanceZones, + ignoreSupplyZones, + ignoreDemandZones, + ignoreBullishOrderBlocks, + ignoreBearishOrderBlocks, + ignoreBullishFairValueGaps, + ignoreBearishFairValueGaps, + ignoreBullishRejectionBars, + ignoreBearishRejectionBars, + ignoreBullishMomentumBars, + ignoreBearishMomentumBars // + ); + } + else + { + // + double peakUpper = 0; + double peakLower = 0; + double valeUpper = 0; + double valeLower = 0; + + // + datetime peakTo = NULL; + datetime valeTo = NULL; + datetime peakFrom = NULL; + datetime valeFrom = NULL; + + // + bool hasBoxData = DetectPivotStateBoxData( + pivot, + peakUpper, + peakLower, + peakFrom, + peakTo, + valeUpper, + valeLower, + valeFrom, + valeTo // + ); + + // + if (hasBoxData) + { + // + XCBoxObject *peakBox; + bool isCreated = CreateBox( + peakBox, + peakUpper, + peakLower, + peakFrom, + peakTo, + clrMagenta, + 1, + false, + STYLE_DASHDOT // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)peakBox, + stateObjects // + ); + } + + // + XCBoxObject *valeBox; + isCreated = CreateBox( + valeBox, + valeUpper, + valeLower, + valeFrom, + valeTo, + clrAqua, + 1, + false, + STYLE_DASHDOT // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)valeBox, + stateObjects // + ); + } + } + } // if (IsValidSize(stateCount)) @@ -4471,6 +4554,9 @@ class XCPOIDrawer : public XCBase drawnObjects, false // Doesn't Clean ... ); + + // + ArrayFree(stateObjects); } // diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 5d52f5d1..694daafd 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -167,6 +167,7 @@ struct X121Conditions double lLLBuffer[]; double hHHBuffer[]; double hLLBuffer[]; + long volumeBuffer[]; double peaksBuffer[]; double valesBuffer[]; double strUpBuffer[]; @@ -198,6 +199,10 @@ struct X121Conditions double donCloseUpperBuffer[]; double donCloseLowerBuffer[]; + // + bool bullishTrendBuffer[]; + bool bearishTrendBuffer[]; + // double rsiSlope; double strSlope; @@ -292,11 +297,15 @@ struct X121Conditions bool isNewPeak; bool isNewPeakOverLast; bool isNewPeakUnderLast; + bool isRejectedPrevPeak; + bool isBreakedUpPrevPeak; // bool isNewVale; bool isNewValeOverLast; bool isNewValeUnderLast; + bool isRejectedPrevVale; + bool isBreakedDownPrevVale; // bool isStrBullish; @@ -488,6 +497,14 @@ struct X121Conditions bool isStrLowerCrossedOverDonLowLower; bool isStrLowerCrossedUnderDonLowLower; + // + bool isTrendBullish; + bool isTrendBearish; + + // + bool isTrendSwirchedToBullish; + bool isTrendSwirchedToBearish; + // bool isAtrUpperOverPeak; bool isAtrUpperEqualsToPeak; @@ -546,6 +563,7 @@ struct X121Conditions Clean(peaksBuffer); Clean(valesBuffer); Clean(strUpBuffer); + Clean(volumeBuffer); Clean(strDownBuffer); Clean(vwapMidBuffer); Clean(le1StartBuffer); @@ -574,6 +592,10 @@ struct X121Conditions Clean(donCloseUpperBuffer); Clean(donCloseLowerBuffer); + // + Clean(bullishTrendBuffer); + Clean(bearishTrendBuffer); + // ArraySetAsSeries(rsiBuffer, true); ArraySetAsSeries(atrBuffer, true); @@ -596,6 +618,7 @@ struct X121Conditions ArraySetAsSeries(peaksBuffer, true); ArraySetAsSeries(valesBuffer, true); ArraySetAsSeries(strUpBuffer, true); + ArraySetAsSeries(volumeBuffer, true); ArraySetAsSeries(strDownBuffer, true); ArraySetAsSeries(vwapMidBuffer, true); ArraySetAsSeries(le1StartBuffer, true); @@ -624,6 +647,10 @@ struct X121Conditions ArraySetAsSeries(donCloseUpperBuffer, true); ArraySetAsSeries(donCloseLowerBuffer, true); + // + ArraySetAsSeries(bullishTrendBuffer, true); + ArraySetAsSeries(bearishTrendBuffer, true); + // cheMin = 0; cheMax = 0; @@ -747,11 +774,15 @@ struct X121Conditions isNewPeak = false; isNewPeakOverLast = false; isNewPeakUnderLast = false; + isRejectedPrevPeak = false; + isBreakedUpPrevPeak = false; // isNewVale = false; isNewValeOverLast = false; isNewValeUnderLast = false; + isRejectedPrevVale = false; + isBreakedDownPrevVale = false; // // STR ... @@ -983,6 +1014,14 @@ struct X121Conditions // isStrLowerCrossedOverDonLowLower = false; isStrLowerCrossedUnderDonLowLower = false; + + // + isTrendBullish = false; + isTrendBearish = false; + + // + isTrendSwirchedToBullish = false; + isTrendSwirchedToBearish = false; } /** @@ -1074,9 +1113,13 @@ struct X121Conditions ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + + ToString("isRejectedPrevPeak", isRejectedPrevPeak, ignoreFalseConditions, separator) + + ToString("isBreakedUpPrevPeak", isBreakedUpPrevPeak, ignoreFalseConditions, separator) + ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + + ToString("isRejectedPrevVale", isRejectedPrevVale, ignoreFalseConditions, separator) + + ToString("isBreakedDownPrevVale", isBreakedDownPrevVale, ignoreFalseConditions, separator) + // "-----------------------" + separator + "> RSI ..." + separator + @@ -1188,6 +1231,10 @@ struct X121Conditions "-----------------------" + separator + "Coplex ..." + separator + "-----------------------" + separator + + ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) + + ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) + + ToString("isTrendSwirchedToBullish", isTrendSwirchedToBullish, ignoreFalseConditions, separator) + + ToString("isTrendSwirchedToBearish", isTrendSwirchedToBearish, ignoreFalseConditions, separator) + ToString("isSarIncreased", isSarIncreased, ignoreFalseConditions, separator) + ToString("isSarDecreased", isSarDecreased, ignoreFalseConditions, separator) + ToString("isSarEqualsToPeak", isSarEqualsToPeak, ignoreFalseConditions, separator) + @@ -1786,6 +1833,25 @@ class XCX121Helper : public XCBase return result; } + // + // Fill Volume Buffer ... + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Reading Bar Valuem ... + long iVol = iVolume( + mSymbol, + mPeriod, + i // + ); + + // + Add( + iVol, + conditions.volumeBuffer // + ); + } + // // Fill X121 Conditions Reference by Using // Retrieved Conditions ... @@ -1878,6 +1944,18 @@ class XCX121Helper : public XCBase conditions.hLLBuffer // ); + // + Copy( + xpvConditions.bullishTrendBuffer, + conditions.bullishTrendBuffer // + ); + + // + Copy( + xpvConditions.bearishTrendBuffer, + conditions.bearishTrendBuffer // + ); + // // Conditions ... @@ -1890,6 +1968,10 @@ class XCX121Helper : public XCBase conditions.isNewValeOverLast = xpvConditions.isNewValeOverLast; conditions.isNewPeakUnderLast = xpvConditions.isNewPeakUnderLast; conditions.isNewValeUnderLast = xpvConditions.isNewValeUnderLast; + conditions.isRejectedPrevVale = xpvConditions.isRejectedPrevVale; + conditions.isRejectedPrevPeak = xpvConditions.isRejectedPrevPeak; + conditions.isBreakedUpPrevPeak = xpvConditions.isBreakedUpPrevPeak; + conditions.isBreakedDownPrevVale = xpvConditions.isBreakedDownPrevVale; conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish; conditions.isSarSwitchedToBearish = xpvConditions.isSarSwitchedToBearish; @@ -2286,6 +2368,20 @@ class XCX121Helper : public XCBase // // Complex Conditions ... + // + bool isTrendBullish = conditions.bullishTrendBuffer[0]; + bool isTrendBullishPrev = conditions.bullishTrendBuffer[1]; + + // + bool isTrendBearish = conditions.bearishTrendBuffer[0]; + bool isTrendBearishPrev = conditions.bearishTrendBuffer[1]; + + // + bool isTrendSwirchedToBullish = isTrendBullish && + !isTrendBullishPrev; + bool isTrendSwirchedToBearish = isTrendBearish && + !isTrendBearishPrev; + // double vwapFast = conditions.vwapFastBuffer[cIDX]; double vwapMid = conditions.vwapMidBuffer[cIDX]; @@ -2705,6 +2801,12 @@ class XCX121Helper : public XCBase conditions.vwapMin = vwapMin; conditions.vwapMax = vwapMax; + // + conditions.isTrendBullish = isTrendBullish; + conditions.isTrendBearish = isTrendBearish; + conditions.isTrendSwirchedToBullish = isTrendSwirchedToBullish; + conditions.isTrendSwirchedToBearish = isTrendSwirchedToBearish; + // conditions.isSarIncreased = isSarIncreased; conditions.isSarDecreased = isSarDecreased; diff --git a/Helpers/x-saherelm.x121.xpv.helper.mq5 b/Helpers/x-saherelm.x121.xpv.helper.mq5 index afa11807..d42b8849 100644 --- a/Helpers/x-saherelm.x121.xpv.helper.mq5 +++ b/Helpers/x-saherelm.x121.xpv.helper.mq5 @@ -270,6 +270,10 @@ struct X121XPVConditions double hHHBuffer[]; double hLLBuffer[]; + // + bool bullishTrendBuffer[]; + bool bearishTrendBuffer[]; + // // Conditions ... @@ -291,11 +295,15 @@ struct X121XPVConditions bool isNewPeak; bool isNewPeakOverLast; bool isNewPeakUnderLast; + bool isRejectedPrevPeak; + bool isBreakedUpPrevPeak; // bool isNewVale; bool isNewValeOverLast; bool isNewValeUnderLast; + bool isRejectedPrevVale; + bool isBreakedDownPrevVale; // // Constructor ... @@ -336,6 +344,10 @@ struct X121XPVConditions Clean(hHHBuffer); Clean(hLLBuffer); + // + Clean(bullishTrendBuffer); + Clean(bearishTrendBuffer); + // ArraySetAsSeries(peaksBuffer, true); ArraySetAsSeries(valesBuffer, true); @@ -351,6 +363,10 @@ struct X121XPVConditions ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hLLBuffer, true); + // + ArraySetAsSeries(bullishTrendBuffer, true); + ArraySetAsSeries(bearishTrendBuffer, true); + // // Conditions ... @@ -366,11 +382,14 @@ struct X121XPVConditions isNewPeak = false; isNewPeakOverLast = false; isNewPeakUnderLast = false; - + isRejectedPrevPeak = false; + isBreakedUpPrevPeak = false; // isNewVale = false; isNewValeOverLast = false; isNewValeUnderLast = false; + isRejectedPrevVale = false; + isBreakedDownPrevVale = false; } /** @@ -450,9 +469,13 @@ struct X121XPVConditions ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + + ToString("isRejectedPrevPeak", isRejectedPrevPeak, ignoreFalseConditions, separator) + + ToString("isBreakedUpPrevPeak", isBreakedUpPrevPeak, ignoreFalseConditions, separator) + ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + + ToString("isRejectedPrevVale", isRejectedPrevVale, ignoreFalseConditions, separator) + + ToString("isBreakedDownPrevVale", isBreakedDownPrevVale, ignoreFalseConditions, separator) + // "" // @@ -1589,6 +1612,107 @@ class XCX121XPVHelper : public XCBaseHelper ); } + // + // Trends ... + + // // + // bool GetBullishTrend( + // int barIndex // Bar Index + // ) + // { + // // + // if (barIndex < 0) + // { + // barIndex = 0; + // } + + // // + // Calculate(); + + // // + // int count = ArraySize(bullishTrendBuffer); + // if (barIndex >= count) + // { + // barIndex = count - 1; + // } + + // // + // return bullishTrendBuffer[barIndex]; + // } + + // // + // int CopyBullishTrend( + // int start, // Start + // int count, // Number of Items for read + // bool &buffer[], // Dest Buffer + // bool forceClean = true // Force To Clean buffer + // ) + // { + // // + // // Update Calculations ... + // Calculate(); + + // // + // // Copy Items ... + // return Copy( + // start, + // count, + // bullishTrendBuffer, + // buffer, + // forceClean + // // + // ); + // } + + // // + // bool GetBearishTrend( + // int barIndex // Bar Index + // ) + // { + // // + // if (barIndex < 0) + // { + // barIndex = 0; + // } + + // // + // Calculate(); + + // // + // int count = ArraySize(bearishTrendBuffer); + // if (barIndex >= count) + // { + // barIndex = count - 1; + // } + + // // + // return bearishTrendBuffer[barIndex]; + // } + + // // + // int CopyBearishTrend( + // int start, // Start + // int count, // Number of Items for read + // bool &buffer[], // Dest Buffer + // bool forceClean = true // Force To Clean buffer + // ) + // { + // // + // // Update Calculations ... + // Calculate(); + + // // + // // Copy Items ... + // return Copy( + // start, + // count, + // bearishTrendBuffer, + // buffer, + // forceClean + // // + // ); + // } + // // Tools Function ... @@ -1812,6 +1936,191 @@ class XCX121XPVHelper : public XCBaseHelper return result; } + /** + * Detect Market Structure Method 2 ... + * + * @param model: XMarketStructure instance Reference ... + * + * @return ( bool ) + */ + bool DetectMarketStructure( + ENUM_X_DIRECTION &dir, + int pivotsCount = 3 // + ) + { + // + bool result = false; + + // + int barIndex = 0; + + // + if (pivotsCount < 3) + { + pivotsCount = 3; + } + + // + dir = X_DIRECTION_NONE; + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + int hpIndex = -1; + int hpIndexes[]; + double hpValues[]; + + // + int lvIndex = -1; + int lvIndexes[]; + double lvValues[]; + + // + for (int i = 0; i < pivotsCount; i++) + { + // + hpIndex = barIndex; + lvIndex = barIndex; + + // + double lastHP = 0; + double lastLV = 0; + + // + int hpCount = ArraySize(hpIndexes); + int lvCount = ArraySize(lvIndexes); + + // + if (IsValidSize(hpCount)) + { + // + lastHP = hpValues[hpCount - 1]; + hpIndex = hpIndexes[hpCount - 1]; + } + + // + if (IsValidSize(lvCount)) + { + // + lastLV = lvValues[lvCount - 1]; + lvIndex = lvIndexes[lvCount - 1]; + } + + // + if (lastHP == 0) + { + // + lastHP = GetPeak(hpIndex); + } + + // + if (lastLV == 0) + { + // + lastLV = GetVale(lvIndex); + } + + // + int highestPeakIndex = -1; + double highesrPeak = + GetHigherPeak( + highestPeakIndex, + lastHP, + hpIndex // + ); + if (IsValidIndex(highestPeakIndex)) + { + // + Add( + highestPeakIndex, + hpIndexes // + ); + + // + Add( + highesrPeak, + hpValues // + ); + } + + // + int lowestValeIndex = -1; + double lowestVale = + GetLowerVale( + lowestValeIndex, + lastLV, + lvIndex // + ); + if (IsValidIndex(lowestValeIndex)) + { + // + Add( + lowestValeIndex, + lvIndexes // + ); + + // + Add( + lowestVale, + lvValues // + ); + } + + // + bool canBreak = ArraySize(hpIndexes) >= pivotsCount || + ArraySize(lvIndexes) >= pivotsCount; + if (canBreak) + { + break; + } + } + + // + ArrayReverse(hpValues); + ArrayReverse(hpIndexes); + int countHPs = ArraySize(hpIndexes); + + // + ArrayReverse(lvValues); + ArrayReverse(lvIndexes); + int countLVs = ArraySize(lvIndexes); + + // + bool isValidHPs = countHPs >= pivotsCount; + bool isValidLVs = countLVs >= pivotsCount; + + // + result = isValidHPs || + isValidLVs; + if (!result) + { + return result; + } + + // + if (isValidHPs && isValidLVs) + { + // + hpIndex = hpIndexes[countHPs - 1]; + lvIndex = lvIndexes[countLVs - 1]; + } + + // + dir = + !isValidHPs && isValidLVs + ? X_DIRECTION_BULLISH + : !isValidLVs && isValidHPs + ? X_DIRECTION_BEARISH + : hpIndex < lvIndex + ? X_DIRECTION_BEARISH + : lvIndex < hpIndex + ? X_DIRECTION_BULLISH + : X_DIRECTION_ALL; + + // + return result; + } + // bool GetConditions( X121XPVConditions &conditions, // @@ -1972,6 +2281,48 @@ class XCX121XPVHelper : public XCBaseHelper conditions.hLLBuffer // ); + // // + // CopyBullishTrend( + // zIndex, + // loopback, + // conditions.bullishTrendBuffer // + // ); + + // // + // CopyBearishTrend( + // zIndex, + // loopback, + // conditions.bearishTrendBuffer // + // ); + + // + for (int i = barIndex + 1; i < barIndex + 3; i++) + { + // + ENUM_X_DIRECTION iDirection; + bool iHasDirection = DetectMarketStructure(iDirection); + + // + bool iHasBullishTrend = iHasDirection && + IsBullish(iDirection); + + // + bool iHasBearishTrend = iHasDirection && + IsBearish(iDirection); + + // + Add( + iHasBullishTrend, + conditions.bullishTrendBuffer // + ); + + // + Add( + iHasBearishTrend, + conditions.bearishTrendBuffer // + ); + } + // // Conditions ... @@ -2005,6 +2356,16 @@ class XCX121XPVHelper : public XCBaseHelper conditions.peaksBuffer[cIDX] > conditions.peaksBuffer[pIDX]; bool isNewPeakUnderLast = isNewPeak && conditions.peaksBuffer[cIDX] < conditions.peaksBuffer[pIDX]; + bool isRejectedPrevPeak = IsBarReject( + conditions.peaksBuffer[pIDX], + X_DIRECTION_BEARISH, + cBar // + ); + bool isBreakedUpPrevPeak = IsBarBreak( + conditions.peaksBuffer[pIDX], + X_DIRECTION_BULLISH, + cBar // + ); // bool isNewVale = conditions.valesBuffer[cIDX] != conditions.valesBuffer[pIDX]; @@ -2012,6 +2373,16 @@ class XCX121XPVHelper : public XCBaseHelper conditions.valesBuffer[cIDX] > conditions.valesBuffer[pIDX]; bool isNewValeUnderLast = isNewVale && conditions.valesBuffer[cIDX] < conditions.valesBuffer[pIDX]; + bool isRejectedPrevVale = IsBarReject( + conditions.valesBuffer[pIDX], + X_DIRECTION_BULLISH, + cBar // + ); + bool isBreakedDownPrevVale = IsBarBreak( + conditions.valesBuffer[pIDX], + X_DIRECTION_BEARISH, + cBar // + ); // conditions.isSarBullish = isSarBullish; @@ -2021,9 +2392,18 @@ class XCX121XPVHelper : public XCBaseHelper conditions.isNewPeak = isNewPeak; conditions.isNewPeakOverLast = isNewPeakOverLast; conditions.isNewPeakUnderLast = isNewPeakUnderLast; + conditions.isRejectedPrevPeak = isRejectedPrevPeak; + conditions.isBreakedUpPrevPeak = isBreakedUpPrevPeak; conditions.isNewVale = isNewVale; conditions.isNewValeOverLast = isNewValeOverLast; conditions.isNewValeUnderLast = isNewValeUnderLast; + conditions.isRejectedPrevVale = isRejectedPrevVale; + conditions.isBreakedDownPrevVale = isBreakedDownPrevVale; + + // // + // if (isNewVale || isNewPeak) { + // CalculateTrend(); + // } // return result; @@ -2055,6 +2435,29 @@ class XCX121XPVHelper : public XCBaseHelper double hHHBuffer[]; double hLLBuffer[]; + // + // bool bullishTrendBuffer[]; + // bool bearishTrendBuffer[]; + + // + // void AddTrend( + // bool isBullish, + // bool isBearish // + // ) + // { + // // + // Add( + // isBullish, + // bullishTrendBuffer // + // ); + + // // + // Add( + // isBearish, + // bearishTrendBuffer // + // ); + // } + // void Calculate() { @@ -2229,6 +2632,28 @@ class XCX121XPVHelper : public XCBaseHelper // ); } + + // + // void CalculateTrend() + // { + // // + // ENUM_X_DIRECTION iDirection; + // bool iHasDirection = DetectMarketStructure(iDirection); + + // // + // bool iHasBullishTrend = iHasDirection && + // IsBullish(iDirection); + + // // + // bool iHasBearishTrend = iHasDirection && + // IsBearish(iDirection); + + // // + // AddTrend( + // iHasBullishTrend, + // iHasBearishTrend // + // ); + // } }; // diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 6261295a..37ccf75e 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -6471,9 +6471,9 @@ struct XFVGOrderBlock /** * Check Model is same as another Istance ... - * + * * @param value: XFVGOrderBlock instance Reference ... - * + * * @return ( bool ) */ bool IsSameAs(XFVGOrderBlock &value) @@ -6510,18 +6510,18 @@ struct XFVGOrderBlock result = // dir == valueDir - // - && - // - orderBlock.From() == value.orderBlock.From() && - orderBlock.Upper() == value.orderBlock.Upper() && - orderBlock.Lower() == value.orderBlock.Lower() - // - && - // - fairValueGap.From() == value.fairValueGap.From() && - fairValueGap.Upper() == value.fairValueGap.Upper() && - fairValueGap.Lower() == value.fairValueGap.Lower() + // + && + // + orderBlock.From() == value.orderBlock.From() && + orderBlock.Upper() == value.orderBlock.Upper() && + orderBlock.Lower() == value.orderBlock.Lower() + // + && + // + fairValueGap.From() == value.fairValueGap.From() && + fairValueGap.Upper() == value.fairValueGap.Upper() && + fairValueGap.Lower() == value.fairValueGap.Lower() // ; @@ -7720,6 +7720,910 @@ void DetectPivotPOIs( } } +/** + * Fill Pivot Tick Zone ... + * + * @param pivot: XPVPivot instance Reference ... + */ +void CalculatePivotTickZone( + XPVPivot &pivot, + int ticksLevels, + int ticksRange, + ENUM_TIMEFRAMES _period = NULL // +) +{ + // + string symbol = pivot.symbol; + ENUM_TIMEFRAMES period = IsValid(_period) + ? _period + : pivot.period; + + // + bool isInited = false; + + // + datetime from = pivot.from; + XOHCL iFromBar; + int iFromBarIndex = iBarShift( + symbol, + period, + from // + ); + isInited = iFromBar.Init( + symbol, + period, + iFromBarIndex // + ); + if (!isInited) + { + return; + } + + // + datetime to = pivot.to; + XOHCL iToBar; + int iToBarIndex = iBarShift( + symbol, + period, + to // + ); + isInited = iToBar.Init( + symbol, + period, + iToBarIndex // + ); + if (!isInited) + { + return; + } + + // + if (iFromBarIndex <= iToBarIndex) + { + return; + } + + // + XCTicksZone *iZone; + iZone = new XCTicksZone(); + + // + isInited = ticksLevels > 0 && + ticksRange > 0; + if (!isInited) + { + return; + } + + // + isInited = iZone.Init( + iFromBar, + iToBar // + ); + if (!isInited) + { + return; + } + + // + pivot.state.ticksZone = iZone; +} + +/** + * Filter State based on Pivot ... + * + * @param pivot: XPVPivot instance Reference ... + * @param state: XPOIState instance Reference ... + */ +void FilterPivotState( + XPVPivot &pivot, + XPOIState &state // +) +{ + // + bool isValid = + pivot.IsValid() && + state.IsValid() && + state.HasChild(); + if (!isValid) + { + return; + } + + // + int count = 0; + + // + double upper = pivot.upper; + double lower = pivot.lower; + + // + // + // + + // + // Resistance ... + count = state.CountResistanceZones(); + if (IsValidSize(count)) + { + // + XCResistanceZone *tmp[]; + Copy( + state.resistanceZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + upper, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.resistanceZones, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // Supply ... + count = state.CountSupplyZones(); + if (IsValidSize(count)) + { + // + XCSupplyZone *tmp[]; + Copy( + state.supplyZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + upper, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.supplyZones, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // Bearish Order Block ... + count = state.CountBearishOrderBlocks(); + if (IsValidSize(count)) + { + // + XCOrderBlock *tmp[]; + Copy( + state.bearishOrderBlocks, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + upper, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.bearishOrderBlocks, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // Bearish Fair Value Gap ... + count = state.CountBearishFairValueGaps(); + if (IsValidSize(count)) + { + // + XCFVG *tmp[]; + Copy( + state.bearishFairValueGaps, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCFVG *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + upper, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.bearishFairValueGaps, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // + // + + // + // Support ... + count = state.CountSupportZones(); + if (IsValidSize(count)) + { + // + XCSupportZone *tmp[]; + Copy( + state.supportZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + lower, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.supportZones, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // Demand ... + count = state.CountDemandZones(); + if (IsValidSize(count)) + { + // + XCDemandZone *tmp[]; + Copy( + state.demandZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCDemandZone *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + lower, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.demandZones, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // Bullish Order Block ... + count = state.CountBullishOrderBlocks(); + if (IsValidSize(count)) + { + // + XCOrderBlock *tmp[]; + Copy( + state.bullishOrderBlocks, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + lower, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.bullishOrderBlocks, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } + + // + // Bullish Fair Value Gap ... + count = state.CountBullishFairValueGaps(); + if (IsValidSize(count)) + { + // + XCFVG *tmp[]; + Copy( + state.bullishFairValueGaps, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCFVG *item = tmp[i]; + + // + bool isValid = IsPriceInsideZone( + lower, + item // + ); + if (!isValid) + { + // + ArrayRemove( + state.bullishFairValueGaps, + i, + 1 // + ); + } + } + + // + ArrayFree(tmp); + } +} + +/** + * Detect Box Date of Specified Pivot ... + */ +bool DetectPivotStateBoxData( + XPVPivot &pivot, + double &peakUpper, + double &peakLower, + datetime &peakFrom, + datetime &peakTo, + double &valeUpper, + double &valeLower, + datetime &valeFrom, + datetime &valeTo // +) +{ + // + bool result = false; + + // + peakUpper = 0; + peakLower = 0; + valeUpper = 0; + valeLower = 0; + + // + peakFrom = NULL; + peakTo = NULL; + valeFrom = NULL; + valeTo = NULL; + + // + result = pivot.IsValid(); + if (!result) + { + return result; + } + + // + int count = 0; + + // + // + // + + // + // Resistance ... + count = pivot.state.CountResistanceZones(); + if (IsValidSize(count)) + { + // + XCResistanceZone *tmp[]; + Copy( + pivot.state.resistanceZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *item = tmp[i]; + + // + if (peakUpper == 0 || + peakUpper < item.Upper()) + { + peakUpper = item.Upper(); + } + + // + if (peakLower == 0 || + peakLower > item.Lower()) + { + peakLower = item.Lower(); + } + + // + if (!IsValid(peakFrom) || + peakFrom > item.From()) + { + peakFrom = item.From(); + } + + // + if (!IsValid(peakTo) || + peakTo < item.To()) + { + peakTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // Supply ... + count = pivot.state.CountSupplyZones(); + if (IsValidSize(count)) + { + // + XCSupplyZone *tmp[]; + Copy( + pivot.state.supplyZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *item = tmp[i]; + + // + if (peakUpper == 0 || + peakUpper < item.Upper()) + { + peakUpper = item.Upper(); + } + + // + if (peakLower == 0 || + peakLower > item.Lower()) + { + peakLower = item.Lower(); + } + + // + if (!IsValid(peakFrom) || + peakFrom > item.From()) + { + peakFrom = item.From(); + } + + // + if (!IsValid(peakTo) || + peakTo < item.To()) + { + peakTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // Bearish Order Block ... + count = pivot.state.CountBearishOrderBlocks(); + if (IsValidSize(count)) + { + // + XCOrderBlock *tmp[]; + Copy( + pivot.state.bearishOrderBlocks, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *item = tmp[i]; + + // + if (peakUpper == 0 || + peakUpper < item.Upper()) + { + peakUpper = item.Upper(); + } + + // + if (peakLower == 0 || + peakLower > item.Lower()) + { + peakLower = item.Lower(); + } + + // + if (!IsValid(peakFrom) || + peakFrom > item.From()) + { + peakFrom = item.From(); + } + + // + if (!IsValid(peakTo) || + peakTo < item.To()) + { + peakTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // Bearish Fair Value Gap ... + count = pivot.state.CountBearishFairValueGaps(); + if (IsValidSize(count)) + { + // + XCFVG *tmp[]; + Copy( + pivot.state.bearishFairValueGaps, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCFVG *item = tmp[i]; + + // + if (peakUpper == 0 || + peakUpper < item.Upper()) + { + peakUpper = item.Upper(); + } + + // + if (peakLower == 0 || + peakLower > item.Lower()) + { + peakLower = item.Lower(); + } + + // + if (!IsValid(peakFrom) || + peakFrom > item.From()) + { + peakFrom = item.From(); + } + + // + if (!IsValid(peakTo) || + peakTo < item.To()) + { + peakTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // + // + + // + // Support ... + count = pivot.state.CountSupportZones(); + if (IsValidSize(count)) + { + // + XCSupportZone *tmp[]; + Copy( + pivot.state.supportZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *item = tmp[i]; + + // + if (valeUpper == 0 || + valeUpper < item.Upper()) + { + valeUpper = item.Upper(); + } + + // + if (valeLower == 0 || + valeLower > item.Lower()) + { + valeLower = item.Lower(); + } + + // + if (!IsValid(valeFrom) || + valeFrom > item.From()) + { + valeFrom = item.From(); + } + + // + if (!IsValid(valeTo) || + valeTo < item.To()) + { + valeTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // Demand ... + count = pivot.state.CountDemandZones(); + if (IsValidSize(count)) + { + // + XCDemandZone *tmp[]; + Copy( + pivot.state.demandZones, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCDemandZone *item = tmp[i]; + + // + if (valeUpper == 0 || + valeUpper < item.Upper()) + { + valeUpper = item.Upper(); + } + + // + if (valeLower == 0 || + valeLower > item.Lower()) + { + valeLower = item.Lower(); + } + + // + if (!IsValid(valeFrom) || + valeFrom > item.From()) + { + valeFrom = item.From(); + } + + // + if (!IsValid(valeTo) || + valeTo < item.To()) + { + valeTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // Bullish Order Block ... + count = pivot.state.CountBullishOrderBlocks(); + if (IsValidSize(count)) + { + // + XCOrderBlock *tmp[]; + Copy( + pivot.state.bullishOrderBlocks, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *item = tmp[i]; + + // + if (valeUpper == 0 || + valeUpper < item.Upper()) + { + valeUpper = item.Upper(); + } + + // + if (valeLower == 0 || + valeLower > item.Lower()) + { + valeLower = item.Lower(); + } + + // + if (!IsValid(valeFrom) || + valeFrom > item.From()) + { + valeFrom = item.From(); + } + + // + if (!IsValid(valeTo) || + valeTo < item.To()) + { + valeTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + // Bullish Fair Value Gap ... + count = pivot.state.CountBullishFairValueGaps(); + if (IsValidSize(count)) + { + // + XCFVG *tmp[]; + Copy( + pivot.state.bullishFairValueGaps, + tmp // + ); + + // + for (int i = 0; i < count; i++) + { + // + XCFVG *item = tmp[i]; + + // + if (valeUpper == 0 || + valeUpper < item.Upper()) + { + valeUpper = item.Upper(); + } + + // + if (valeLower == 0 || + valeLower > item.Lower()) + { + valeLower = item.Lower(); + } + + // + if (!IsValid(valeFrom) || + valeFrom > item.From()) + { + valeFrom = item.From(); + } + + // + if (!IsValid(valeTo) || + valeTo < item.To()) + { + valeTo = item.To(); + } + } + + // + ArrayFree(tmp); + } + + // + result = peakUpper > 0 && + peakLower > 0 && + valeUpper > 0 && + valeLower > 0 && + IsValid(peakTo) && + IsValid(valeTo) && + IsValid(peakFrom) && + IsValid(valeFrom) && + peakTo > peakFrom && + valeTo > valeFrom && + peakUpper > peakLower && + valeUpper > valeLower; + + // + return result; +} + /** * Detect Price Inside Zones ... * @@ -9745,14 +10649,14 @@ double CalculateTarget( /** * Test Market for Detect Order Block FVG ... - * + * * @param forDir: Direction * @param bullishOrderBlocks: Detected Bullish Order Blocks ... * @param bearishOrderBlocks: Detected Bearish Order Blocks ... * @param orderBlockState: Order Block Detection POIState ... * @param fairValueGapState: Fair Value Gap Detection POIState ... * @param barIndex: Bar Index ... - * + * * @return ( bool ) */ bool DetectFVGOB( 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 276f5e8b..181d6666 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -426,656 +426,6 @@ class XC121SMCCycleHelper : public XCBase return result; } - /** - * Detect Market Structure ... - * - * @param model: XMarketStructure instance Reference ... - * - * @return ( bool ) - */ - bool DetectMarketStructure( - XMarketStructure &model // - ) - { - // - bool result = false; - - // - model.Clean(); - - // - int barIndex = 0; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - model.symbol = symbol; - model.period = period; - - // - int highestPeakIndex = -1; - double highestPeakVale = 0; - double highestPeak = - mX121Helper - .xpvHelper - .GetHighestPeak( - barIndex, - highestPeakIndex, - highestPeakVale // - ); - - // - int lowestValeIndex = -1; - double lowestValePeak = 0; - double lowestVale = - mX121Helper - .xpvHelper - .GetLowestVale( - barIndex, - lowestValeIndex, - lowestValePeak // - ); - - // - result = IsValidIndex(highestPeakIndex) && - IsValidIndex(lowestValeIndex); - if (!result) - { - return result; - } - - // - model.bias = - highestPeakIndex < lowestValeIndex - ? X_DIRECTION_BEARISH - : highestPeakIndex > lowestValeIndex - ? X_DIRECTION_BULLISH - : X_DIRECTION_NONE; - - // - result = HasDirection(model.bias); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(model.bias); - - // - // Looking for Change Of Character Proved ... - - // - // Bullish Bias: - // - Price Must Break Up Lowst Vale's Peak; - // - Create a Vale Above Lowest Vale's Peak; - - // - // Bearish Bias: - // - Price Must Breake Down HighestPeak's Vale; - // - Create a Peak Under Highest Peak's Vale; - - // - // Checking Peak Breake Up ... - int lowestValePeakBreakeUpIndex = -1; - for (int i = lowestValeIndex; i >= barIndex; i--) - { - // - XOHCL iBar; - result = GetBar(iBar, i); - if (!result) - { - continue; - } - - // - bool isBreake = IsBarBreak( - lowestValePeak, - X_DIRECTION_BULLISH, - iBar // - ); - if (isBreake) - { - // - lowestValePeakBreakeUpIndex = i; - break; - } - } - bool isValidBreakeUpLowestValePeak = IsValidIndex(lowestValePeakBreakeUpIndex) && - lowestValePeakBreakeUpIndex <= lowestValeIndex; - - // - // Checking Vale Breake Down ... - int highestPeakValeBreakeDownIndex = -1; - for (int i = highestPeakIndex; i >= barIndex; i--) - { - // - XOHCL iBar; - result = GetBar(iBar, i); - if (!result) - { - continue; - } - - // - bool isBreake = IsBarBreak( - highestPeakVale, - X_DIRECTION_BEARISH, - iBar // - ); - if (isBreake) - { - // - highestPeakValeBreakeDownIndex = i; - break; - } - } - bool isValidBreakeDownHighestPeakVale = IsValidIndex(highestPeakValeBreakeDownIndex) && - highestPeakValeBreakeDownIndex <= highestPeakIndex; - // - result = isBullish - ? isValidBreakeUpLowestValePeak - : isValidBreakeDownHighestPeakVale; - if (!result) - { - return result; - } - - // - // Checking Create a Vale above Peak ... - int valeAboveLowestValePeakIndex = -1; - double valeAboveLowestValePeakPeak = 0; - for (int i = lowestValePeakBreakeUpIndex; i >= barIndex; i--) - { - // - double iVale = mX121Helper.xpvHelper.GetVale(i); - - // - bool isValid = - iVale > 0 && - iVale > lowestValePeak; - if (isValid) - { - // - valeAboveLowestValePeakIndex = i; - valeAboveLowestValePeakPeak = mX121Helper.xpvHelper.GetPeak(i); - break; - } - } - bool isValidValeAboveLowestValePeak = IsValidIndex(valeAboveLowestValePeakIndex) && - valeAboveLowestValePeakIndex < lowestValePeakBreakeUpIndex; - - // - // Checking Create a Peak below Vale ... - int peakBelowHighestPeakValeIndex = -1; - double peakBelowHighestPeakValeVale = 0; - for (int i = highestPeakValeBreakeDownIndex; i >= barIndex; i--) - { - // - double iPeak = mX121Helper.xpvHelper.GetPeak(i); - - // - bool isValid = - iPeak > 0 && - iPeak < highestPeakVale; - if (isValid) - { - // - peakBelowHighestPeakValeIndex = i; - peakBelowHighestPeakValeVale = mX121Helper.xpvHelper.GetVale(i); - break; - } - } - bool isValidPeakBelowHighestPeakVale = IsValidIndex(peakBelowHighestPeakValeIndex) && - peakBelowHighestPeakValeIndex < highestPeakValeBreakeDownIndex; - - // - result = isBullish ? isValidValeAboveLowestValePeak - : isValidPeakBelowHighestPeakVale; - if (!result) - { - return result; - } - - // - // Now we Have to Detect Valid Peaks and Valid Vales Here ... - // based on Detected Range ... - - // - XPVPivotPoint iPeakPoint; - XPVPivotPoint iValePoint; - XPriceZones peakPriceZone; - XPriceZones valePriceZone; - - // - XPOIState state; - mPOIDetector.GetState( - state // - ); - - // - int minRepetition = 5; - - // - int from = - isBullish - ? valeAboveLowestValePeakIndex - : peakBelowHighestPeakValeIndex; - for (int i = from; i >= barIndex; i--) - { - // - XOHCL iBar; - bool isInited = GetBar(iBar, i); - - // - double iPeak = mX121Helper.xpvHelper.GetPeak(i); - double iVale = mX121Helper.xpvHelper.GetVale(i); - - // - bool hasPeakPriceInsideZone = CalculatePriceInsideZones( - peakPriceZone, - state, - iPeak // - ); - bool hasValePriceInsideZone = CalculatePriceInsideZones( - valePriceZone, - state, - iVale // - ); - - // - if (hasPeakPriceInsideZone) - { - // - // Peak ... - if (!iPeakPoint.IsValid()) - { - // - // Initialization ... - iPeakPoint.value = iPeak; - iPeakPoint.repetition = 1; - iPeakPoint.type = XPV_PEAK; - iPeakPoint.time = iBar.time; - } - else - { - // - if (iPeakPoint.value == iPeak) - { - iPeakPoint.repetition++; - } - else - { - // - if (iPeakPoint.repetition > minRepetition) - { - // - AddRef( - iPeakPoint, - model.peaks // - ); - - // - AddRef( - peakPriceZone, - model.peakPriceZones // - ); - } - - // - iPeakPoint.Clean(); - peakPriceZone.Clean(); - iPeakPoint.value = iPeak; - iPeakPoint.repetition = 1; - iPeakPoint.type = XPV_PEAK; - iPeakPoint.time = iBar.time; - } - } - } - - // - if (hasValePriceInsideZone) - { - // - // Vale ... - if (!iValePoint.IsValid()) - { - // - // Initialization ... - iValePoint.value = iVale; - iValePoint.repetition = 1; - iValePoint.type = XPV_VALE; - iValePoint.time = iBar.time; - } - else - { - // - if (iValePoint.value == iVale) - { - iValePoint.repetition++; - } - else - { - // - if (iValePoint.repetition > minRepetition) - { - // - AddRef( - iValePoint, - model.vales // - ); - - // - AddRef( - valePriceZone, - model.valePriceZones // - ); - } - - // - iValePoint.Clean(); - valePriceZone.Clean(); - iValePoint.value = iVale; - iValePoint.repetition = 1; - iValePoint.type = XPV_VALE; - iValePoint.time = iBar.time; - } - } - } - } - - // - // in Bullish Bias we Looking for Vales Oder ... - // in Bearish Bias we Looking for Peaks Oder ... - - // - // Bullish Bias Drawn ... - if (isBullish) - { - // - result = GetBar( - model.lowestValeBar, - lowestValeIndex // - ); - if (!result) - { - return result; - } - - // - if (isValidBreakeUpLowestValePeak) - { - // - result = GetBar( - model.lowestValePeakBreakeUpBar, - lowestValePeakBreakeUpIndex // - ); - if (!result) - { - return result; - } - } - - // - if (isValidValeAboveLowestValePeak) - { - // - result = GetBar( - model.valeAboveLowestValePeakBar, - valeAboveLowestValePeakIndex // - ); - if (!result) - { - return result; - } - } - } - - // - // Bearish Bias Drawn ... - if (!isBullish) - { - // - result = GetBar( - model.highestPeakBar, - highestPeakIndex // - ); - if (!result) - { - return result; - } - - // - if (isValidBreakeDownHighestPeakVale) - { - // - result = GetBar( - model.highestPeakValeBreakeDownBar, - highestPeakValeBreakeDownIndex // - ); - if (!result) - { - return result; - } - } - - // - if (isValidPeakBelowHighestPeakVale) - { - // - result = GetBar( - model.peakBelowHighestPeakValeBar, - peakBelowHighestPeakValeIndex // - ); - if (!result) - { - return result; - } - } - } - - // - result = model.IsValid(); - - // - return result; - } - - /** - * Detect Market Structure Method 2 ... - * - * @param model: XMarketStructure instance Reference ... - * - * @return ( bool ) - */ - bool DetectMarketStructure( - ENUM_X_DIRECTION &dir, - int pivotsCount = 3 // - ) - { - // - bool result = false; - - // - int barIndex = 0; - - // - if (pivotsCount < 3) - { - pivotsCount = 3; - } - - // - dir = X_DIRECTION_NONE; - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - int hpIndex = -1; - int hpIndexes[]; - double hpValues[]; - - // - int lvIndex = -1; - int lvIndexes[]; - double lvValues[]; - - // - for (int i = 0; i < pivotsCount; i++) - { - // - hpIndex = barIndex; - lvIndex = barIndex; - - // - double lastHP = 0; - double lastLV = 0; - - // - int hpCount = ArraySize(hpIndexes); - int lvCount = ArraySize(lvIndexes); - - // - if (IsValidSize(hpCount)) - { - // - lastHP = hpValues[hpCount - 1]; - hpIndex = hpIndexes[hpCount - 1]; - } - - // - if (IsValidSize(lvCount)) - { - // - lastLV = lvValues[lvCount - 1]; - lvIndex = lvIndexes[lvCount - 1]; - } - - // - if (lastHP == 0) - { - // - lastHP = mX121Helper - .xpvHelper - .GetPeak(hpIndex); - } - - // - if (lastLV == 0) - { - // - lastLV = mX121Helper - .xpvHelper - .GetVale(lvIndex); - } - - // - int highestPeakIndex = -1; - double highesrPeak = - mX121Helper - .xpvHelper - .GetHigherPeak( - highestPeakIndex, - lastHP, - hpIndex // - ); - if (IsValidIndex(highestPeakIndex)) - { - // - Add( - highestPeakIndex, - hpIndexes // - ); - - // - Add( - highesrPeak, - hpValues // - ); - } - - // - int lowestValeIndex = -1; - double lowestVale = - mX121Helper - .xpvHelper - .GetLowerVale( - lowestValeIndex, - lastLV, - lvIndex // - ); - if (IsValidIndex(lowestValeIndex)) - { - // - Add( - lowestValeIndex, - lvIndexes // - ); - - // - Add( - lowestVale, - lvValues // - ); - } - - // - bool canBreak = ArraySize(hpIndexes) >= pivotsCount || - ArraySize(lvIndexes) >= pivotsCount; - if (canBreak) - { - break; - } - } - - // - ArrayReverse(hpValues); - ArrayReverse(hpIndexes); - int countHPs = ArraySize(hpIndexes); - - // - ArrayReverse(lvValues); - ArrayReverse(lvIndexes); - int countLVs = ArraySize(lvIndexes); - - // - bool isValidHPs = countHPs >= pivotsCount; - bool isValidLVs = countLVs >= pivotsCount; - - // - result = isValidHPs || - isValidLVs; - if (!result) - { - return result; - } - - // - if (isValidHPs && isValidLVs) - { - // - hpIndex = hpIndexes[countHPs - 1]; - lvIndex = lvIndexes[countLVs - 1]; - } - - // - dir = - !isValidHPs && isValidLVs - ? X_DIRECTION_BULLISH - : !isValidLVs && isValidHPs - ? X_DIRECTION_BEARISH - : hpIndex < lvIndex - ? X_DIRECTION_BEARISH - : lvIndex < hpIndex - ? X_DIRECTION_BULLISH - : X_DIRECTION_ALL; - - // - return result; - } - // // Tools ... @@ -1166,91 +516,5 @@ class XC121SMCCycleHelper : public XCBase ChartSetInteger(chartId, CHART_COLOR_VOLUME, mVolumesColor); } - /** - * Fill Pivot Tick Zone ... - * - * @param pivot: XPVPivot instance Reference ... - */ - void CalculatePivotTickZone( - XPVPivot &pivot // - ) - { - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - bool isInited = false; - - // - datetime from = pivot.from; - XOHCL iFromBar; - int iFromBarIndex = iBarShift( - symbol, - period, - from // - ); - isInited = iFromBar.Init( - symbol, - period, - iFromBarIndex // - ); - if (!isInited) - { - return; - } - - // - datetime to = pivot.to; - XOHCL iToBar; - int iToBarIndex = iBarShift( - symbol, - period, - to // - ); - isInited = iToBar.Init( - symbol, - period, - iToBarIndex // - ); - if (!isInited) - { - return; - } - - // - if (iFromBarIndex <= iToBarIndex) - { - return; - } - - // - XCTicksZone *iZone; - iZone = new XCTicksZone(); - - // - int ticksLevels = mPOIDetector.TicksRangeZoneLevel(); - int ticksRange = mPOIDetector.TicksRangeZoneRange(); - isInited = ticksLevels > 0 && - ticksRange > 0; - if (!isInited) - { - return; - } - - // - isInited = iZone.Init( - iFromBar, - iToBar // - ); - if (!isInited) - { - return; - } - - // - pivot.state.ticksZone = iZone; - } - // }; diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index 17dfda8f..06a25067 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -984,7 +984,7 @@ class XC121SMCExpert : public XCBaseExpert // signal.Clean(); - conditions.Clean(); + conditions.Clean(); } // @@ -2001,11 +2001,17 @@ class XC121SMCExpert : public XCBaseExpert // string comment = "Guard Close All ..."; string message = "Guard Close All (" + ToString(positionsCount) + ") Positions Successfully ..."; - mTradeHandler.ForceClose( + int forceClosed = mTradeHandler.ForceClose( positions, comment, message // ); + + // + if (forceClosed) + { + RestEA(120 * 60); + } } } @@ -2040,11 +2046,17 @@ class XC121SMCExpert : public XCBaseExpert // string comment = "Guard Close Longs ..."; string message = "Guard Close (" + ToString(longPositionsCount) + ") Long Positions Successfully ..."; - mTradeHandler.ForceClose( + bool isClosed = mTradeHandler.ForceClose( longPositions, comment, message // ); + + // + if (isClosed) + { + RestEA(120 * 60); + } } } @@ -2079,11 +2091,17 @@ class XC121SMCExpert : public XCBaseExpert // string comment = "Guard Close Shorts ..."; string message = "Guard Close (" + ToString(shortPositionsCount) + ") Short Positions Successfully ..."; - mTradeHandler.ForceClose( + bool isClosed = mTradeHandler.ForceClose( shortPositions, comment, message // ); + + // + if (isClosed) + { + RestEA(120 * 60); + } } } @@ -2114,11 +2132,17 @@ class XC121SMCExpert : public XCBaseExpert // string comment = "Guard Close ..."; string message = "Guard Close " + (isLong ? "Long" : "Short") + " Position: (" + ToString(iGuard.ticket) + ") Successfully ..."; - mTradeHandler.ForceClose( + bool isClosed = mTradeHandler.ForceClose( positions, comment, message // ); + + // + if (isClosed) + { + RestEA(120 * 60); + } } } @@ -2181,6 +2205,9 @@ class XC121SMCExpert : public XCBaseExpert iPosition, comment // ); + + // + RestEA(120 * 60); } } } @@ -2238,11 +2265,17 @@ class XC121SMCExpert : public XCBaseExpert // string comment = "Guard Hedge ..."; string message = "Guard Hedge (" + ToString(count) + ") Positions by: (" + ToString(profits) + ") Successfully ..."; - mTradeHandler.ForceClose( + bool isClosed = mTradeHandler.ForceClose( positions, comment, message // ); + + // + if (isClosed) + { + RestEA(120 * 60); + } } } } @@ -2335,6 +2368,12 @@ class XC121SMCExpert : public XCBaseExpert ArrayFree(guards); } + // + void RestEA(int seconds) + { + // + } + // }; diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 5b6988ad..82f916e8 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -309,35 +309,18 @@ bool DetectX121SMCGuards( // // Trigger ... - ENUM_X_DIRECTION triggerMarketDir; - bool hasTriggerMarketDir = triggerCycleHelper - .DetectMarketStructure(triggerMarketDir); - - // - bool hasTriggerBullishTrend = - hasTriggerMarketDir && - IsBullish(triggerMarketDir); - - // - bool hasTriggerBearishTrend = - hasTriggerMarketDir && - IsBearish(triggerMarketDir); + bool hasTriggerBullishTrend = triggerXConditions.bullishTrendBuffer[1]; + bool hasTriggerBearishTrend = triggerXConditions.bearishTrendBuffer[1]; // // Decision ... - ENUM_X_DIRECTION decisionMarketDir; - bool hasDecisionMarketDir = decisionCycleHelper - .DetectMarketStructure(decisionMarketDir); + bool hasDecisionBullishTrend = decisionXConditions.bullishTrendBuffer[1]; + bool hasDecisionBearishTrend = decisionXConditions.bearishTrendBuffer[1]; // - bool hasDecisionBullishTrend = - hasDecisionMarketDir && - IsBullish(decisionMarketDir); - - // - bool hasDecisionBearishTrend = - hasDecisionMarketDir && - IsBearish(decisionMarketDir); + // Analyse ... + bool hasAnalyseBullishTrend = analyseXConditions.bullishTrendBuffer[1]; + bool hasAnalyseBearishTrend = analyseXConditions.bearishTrendBuffer[1]; // // Consolidation Zone ... @@ -884,6 +867,9 @@ bool DetectX121SMCGuards( iGuard.provider = provider; iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; + // + iGuard.ticket = iPosition.ticket; + // AddGuard( iGuard, @@ -892,6 +878,92 @@ bool DetectX121SMCGuards( } } + // + if (hasLongs) + { + // + bool hasGuard = hasDecisionBearishTrend; + + // + if (hasGuard) + { + // + for (int i = 0; i < longsCount; i++) + { + // + XPosition iPosition = ownLongPositions[i]; + + // + // Position must be in Draw Down ... + if (iPosition.profit > 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; + + // + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); + } + } + } + + // + if (hasShorts) + { + // + bool hasGuard = hasDecisionBullishTrend; + + // + if (hasGuard) + { + // + for (int i = 0; i < shortsCount; i++) + { + // + XPosition iPosition = ownShortPositions[i]; + + // + // Position must be in Draw Down ... + if (iPosition.profit > 0) + { + continue; + } + + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_CLOSE; + + // + iGuard.ticket = iPosition.ticket; + + // + AddGuard( + iGuard, + guards // + ); + } + } + } + // // Close All ... @@ -931,6 +1003,7 @@ bool DetectX121SMCGuards( // bool hasGuard = // + hasAnalyseBearishTrend && hasDecisionBearishTrend // ; @@ -962,6 +1035,7 @@ bool DetectX121SMCGuards( // bool hasGuard = // + hasAnalyseBullishTrend && hasDecisionBullishTrend // ; @@ -998,20 +1072,6 @@ bool DetectX121SMCGuards( hasTriggerBearishTrend || !hasDecisionBullishTrend // - // (hasAnalysePriceZone && - // isAnalysePriceZoneBearish && - // isAnalysePriceZoneValidForPeak && - // (isAnalysePriceZoneUpperRejected || - // isAnalysePriceZoneLowerBreakedDown)) - // // - // || - // // - // (hasVerificationPriceZone && - // isVerificationPriceZoneBearish && - // isVerificationPriceZoneValidForPeak && - // (isVerificationPriceZoneUpperRejected || - // isVerificationPriceZoneLowerBreakedDown)) - // ; // @@ -1054,20 +1114,6 @@ bool DetectX121SMCGuards( hasTriggerBullishTrend || !hasDecisionBearishTrend // - // (hasAnalysePriceZone && - // isAnalysePriceZoneBullish && - // isAnalysePriceZoneValidForVale && - // (isAnalysePriceZoneLowerRejected || - // isAnalysePriceZoneUpperBreakedUp)) - // // - // || - // // - // (hasVerificationPriceZone && - // isVerificationPriceZoneBullish && - // isVerificationPriceZoneValidForVale && - // (isVerificationPriceZoneLowerRejected || - // isVerificationPriceZoneUpperBreakedUp)) - // ; // @@ -1107,6 +1153,9 @@ bool DetectX121SMCGuards( // if (hasLongs) { + // + bool hasTrendGuard = hasDecisionBearishTrend; + // bool hasConsolidationGuard = (hasConsolidationZone && @@ -1137,6 +1186,7 @@ bool DetectX121SMCGuards( // bool hasGuard = // + hasTrendGuard || hasConsolidationGuard || hasDecisionPriceZoneGuard || hasAnalysePriceZoneGuard || @@ -1172,6 +1222,12 @@ bool DetectX121SMCGuards( continue; } + // + if (hasTrendGuard) + { + guardStop = decisionXConditions.strBuffer[1] - decisionXConditions.atrBuffer[1]; + } + // // Price Must Greater than Zone Lower ... if (iPosition.price < guardStop) @@ -1203,11 +1259,9 @@ bool DetectX121SMCGuards( iGuard.provider = provider; iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - // - iGuard.ticket = iPosition.ticket; - // iGuard.sl = guardStop; + iGuard.ticket = iPosition.ticket; // AddGuard( @@ -1221,6 +1275,9 @@ bool DetectX121SMCGuards( // if (hasShorts) { + // + bool hasTrendGuard = hasDecisionBullishTrend; + // bool hasConsolidationGuard = (hasConsolidationZone && @@ -1251,6 +1308,7 @@ bool DetectX121SMCGuards( // bool hasGuard = // + hasTrendGuard || hasConsolidationGuard || hasDecisionPriceZoneGuard || hasAnalysePriceZoneGuard || @@ -1286,6 +1344,12 @@ bool DetectX121SMCGuards( continue; } + // + if (hasTrendGuard) + { + guardStop = decisionXConditions.strBuffer[1] + decisionXConditions.atrBuffer[1]; + } + // // Price Must Lesser than Zone Upper ... if (iPosition.price > guardStop) @@ -1317,11 +1381,9 @@ bool DetectX121SMCGuards( iGuard.provider = provider; iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - // - iGuard.ticket = iPosition.ticket; - // iGuard.sl = guardStop; + iGuard.ticket = iPosition.ticket; // AddGuard( @@ -1397,11 +1459,9 @@ bool DetectX121SMCGuards( iGuard.provider = provider; iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; - // - iGuard.ticket = iPosition.ticket; - // iGuard.tp = guardTP; + iGuard.ticket = iPosition.ticket; // AddGuard( @@ -1474,11 +1534,9 @@ bool DetectX121SMCGuards( iGuard.provider = provider; iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_TARGET; - // - iGuard.ticket = iPosition.ticket; - // iGuard.tp = guardTP; + iGuard.ticket = iPosition.ticket; // AddGuard( diff --git a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 index c1e5c3a0..4a386201 100644 --- a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 @@ -414,67 +414,31 @@ bool DetectX121SMCXPZSiganlSetup( // // Consolidation ... - ENUM_X_DIRECTION consolidationMarketDir; - bool hasConsolidationMarketDir = consolidationCycleHelper - .DetectMarketStructure(consolidationMarketDir); // - bool hasConsolidationBullishTrend = - hasConsolidationMarketDir && - IsBullish(consolidationMarketDir); + if (decisionXConditions.isTrendSwirchedToBearish) + { + Print("Trend Switced To Bearish ..."); + } // - bool hasConsolidationBearishTrend = - hasConsolidationMarketDir && - IsBearish(consolidationMarketDir); + bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; + bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; // // Verification ... - ENUM_X_DIRECTION verificationMarketDir; - bool hasVerificationMarketDir = verificationCycleHelper - .DetectMarketStructure(verificationMarketDir); - - // - bool hasVerificationBullishTrend = - hasVerificationMarketDir && - IsBullish(verificationMarketDir); - - // - bool hasVerificationBearishTrend = - hasVerificationMarketDir && - IsBearish(verificationMarketDir); + bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; + bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; // // Analyse ... - ENUM_X_DIRECTION analyseMarketDir; - bool hasAnalyseMarketDir = analyseCycleHelper - .DetectMarketStructure(analyseMarketDir); - - // - bool hasAnalyseBullishTrend = - hasAnalyseMarketDir && - IsBullish(analyseMarketDir); - - // - bool hasAnalyseBearishTrend = - hasAnalyseMarketDir && - IsBearish(analyseMarketDir); + bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; + bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; // // Decision ... - ENUM_X_DIRECTION decisionMarketDir; - bool hasDecisionMarketDir = decisionCycleHelper - .DetectMarketStructure(decisionMarketDir); - - // - bool hasDecisionBullishTrend = - hasDecisionMarketDir && - IsBullish(decisionMarketDir); - - // - bool hasDecisionBearishTrend = - hasDecisionMarketDir && - IsBearish(decisionMarketDir); + bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; + bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; // // Detect Bar State ... diff --git a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 index eb6d3f34..1339ceb1 100644 --- a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 @@ -33,7 +33,8 @@ enum ENUM_X121_SMC_XRSPVI_CONDITIONS X121_SMC_XRSPVI_CONDITION_1, X121_SMC_XRSPVI_CONDITION_2, X121_SMC_XRSPVI_CONDITION_3, - X121_SMC_XRSPVI_CONDITION_4 + X121_SMC_XRSPVI_CONDITION_4, + X121_SMC_XRSPVI_CONDITION_5, }; // @@ -70,6 +71,7 @@ struct X121SMCStrategyXRSPVISignalConditions bool isPriceZoneValidForVale; // + XPVPivot pivotZone; XConsolidationZone consolidationZone; // @@ -194,6 +196,7 @@ struct X121SMCStrategyXRSPVISignalConditions point = 0; // + pivotZone.Clean(); priceZone.Clean(); consolidationZone.Clean(); isPriceZoneValidForPeak = false; @@ -214,6 +217,13 @@ X121SMCStrategyXRSPVISignalConditions mXRSPVIConditionsCollection[]; // // Extension Functions ... +// +double X121SMCXRSPVIPivotPeak; +double X121SMCXRSPVIPivotVale; +datetime X121SMCXRSPVIPivotEnd; +datetime X121SMCXRSPVIPivotStart; +ENUM_XPV_PIVOTS X121SMCXRSPVIPivotType = XPV_NONE; + // // Detect Setup Conditions ... bool DetectX121SMCXRSPVISiganlSetup( @@ -435,67 +445,25 @@ bool DetectX121SMCXRSPVISiganlSetup( // // Consolidation ... - ENUM_X_DIRECTION consolidationMarketDir; - bool hasConsolidationMarketDir = consolidationCycleHelper - .DetectMarketStructure(consolidationMarketDir); // - bool hasConsolidationBullishTrend = - hasConsolidationMarketDir && - IsBullish(consolidationMarketDir); - - // - bool hasConsolidationBearishTrend = - hasConsolidationMarketDir && - IsBearish(consolidationMarketDir); + bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; + bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; // // Verification ... - ENUM_X_DIRECTION verificationMarketDir; - bool hasVerificationMarketDir = verificationCycleHelper - .DetectMarketStructure(verificationMarketDir); - - // - bool hasVerificationBullishTrend = - hasVerificationMarketDir && - IsBullish(verificationMarketDir); - - // - bool hasVerificationBearishTrend = - hasVerificationMarketDir && - IsBearish(verificationMarketDir); + bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; + bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; // // Analyse ... - ENUM_X_DIRECTION analyseMarketDir; - bool hasAnalyseMarketDir = analyseCycleHelper - .DetectMarketStructure(analyseMarketDir); - - // - bool hasAnalyseBullishTrend = - hasAnalyseMarketDir && - IsBullish(analyseMarketDir); - - // - bool hasAnalyseBearishTrend = - hasAnalyseMarketDir && - IsBearish(analyseMarketDir); + bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; + bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; // // Decision ... - ENUM_X_DIRECTION decisionMarketDir; - bool hasDecisionMarketDir = decisionCycleHelper - .DetectMarketStructure(decisionMarketDir); - - // - bool hasDecisionBullishTrend = - hasDecisionMarketDir && - IsBullish(decisionMarketDir); - - // - bool hasDecisionBearishTrend = - hasDecisionMarketDir && - IsBearish(decisionMarketDir); + bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; + bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; // // Detect Bar State ... @@ -614,6 +582,8 @@ bool DetectX121SMCXRSPVISiganlSetup( bool isDecisionPriceZoneBearish = false; bool isDecisionPriceZoneValidForPeak = false; bool isDecisionPriceZoneValidForVale = false; + + // if (hasDecisionPriceZone) { // @@ -660,6 +630,8 @@ bool DetectX121SMCXRSPVISiganlSetup( bool isAnalysePriceZoneBearish = false; bool isAnalysePriceZoneValidForPeak = false; bool isAnalysePriceZoneValidForVale = false; + + // if (hasAnalysePriceZone) { // @@ -706,6 +678,8 @@ bool DetectX121SMCXRSPVISiganlSetup( bool isVerificationPriceZoneBearish = false; bool isVerificationPriceZoneValidForPeak = false; bool isVerificationPriceZoneValidForVale = false; + + // if (hasVerificationPriceZone) { // @@ -890,6 +864,314 @@ bool DetectX121SMCXRSPVISiganlSetup( // ; + // + // Detect PV Pivot ... + + // + bool isPivotPeakZoneRejected = false; + bool isPivotPeakZoneBreakedUp = false; + bool isPivotPeakZoneBreakedDown = false; + bool isPivotValeZoneRejected = false; + bool isPivotValeZoneBreakedUp = false; + bool isPivotValeZoneBreakedDown = false; + bool hasPivot = conditions.pivotZone.IsValid(); + if (!hasPivot) + { + // + hasPivot = IsValid(X121SMCXRSPVIPivotStart); + if (!hasPivot) + { + // + bool isNewVale = decisionXConditions.isNewVale; + bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; + bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; + bool isSameVales = decisionXConditions.valesBuffer[1] == + decisionXConditions.valesBuffer[2] && + decisionXConditions.valesBuffer[2] == + decisionXConditions.valesBuffer[3]; + bool isSameCycleVales = decisionXConditions.valesBuffer[1] == + analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == + verificationXConditions.valesBuffer[1]; + + // + bool isNewPeak = decisionXConditions.isNewPeak; + bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; + bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; + bool isSamePeaks = decisionXConditions.peaksBuffer[1] == + decisionXConditions.peaksBuffer[2] && + decisionXConditions.peaksBuffer[2] == + decisionXConditions.peaksBuffer[3]; + bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == + analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == + verificationXConditions.peaksBuffer[1]; + + // + bool isValeStart = + // isSameVales; + isSameVales && + isSameCycleVales; + bool isPeakStart = + // isSamePeaks; + isSamePeaks && + isSameCyclePeaks; + + // + bool isStart = isPeakStart || + isValeStart; + if (isStart) + { + // + X121SMCXRSPVIPivotStart = cTime; + X121SMCXRSPVIPivotType = + isPeakStart + ? XPV_PEAK + : XPV_VALE; + + // + X121SMCXRSPVIPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXRSPVIPivotVale = decisionXConditions.valesBuffer[1]; + } + + // + hasPivot = IsValid(X121SMCXRSPVIPivotStart); + + // + // Create XPVPivot instance ... + if (hasPivot) + { + // + conditions.pivotZone.symbol = symbol; + conditions.pivotZone.period = period; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition = 3; + + // + conditions.pivotZone.upper = X121SMCXRSPVIPivotPeak; + conditions.pivotZone.lower = X121SMCXRSPVIPivotVale; + + // + conditions.pivotZone.type = X121SMCXRSPVIPivotType; + conditions.pivotZone.from = X121SMCXRSPVIPivotStart; + } + } + } + + // + if (hasPivot) + { + // + bool isBreaked = X121SMCXRSPVIPivotType == XPV_PEAK + ? decisionXConditions.isBreakedUpPrevPeak + : decisionXConditions.isBreakedDownPrevVale; + + // + if (!isBreaked) + { + // + X121SMCXRSPVIPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXRSPVIPivotVale = decisionXConditions.valesBuffer[1]; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition++; + conditions.pivotZone.upper = X121SMCXRSPVIPivotPeak; + conditions.pivotZone.lower = X121SMCXRSPVIPivotVale; + } + else + { + // + X121SMCXRSPVIPivotEnd = cTime; + conditions.pivotZone.to = cTime; + } + + // + // Fill Pivot State ... + + // + XPOIState analysePivotState; + DetectPivotPOIs( + conditions.pivotZone, + analyseState, + analysePivotState // + ); + + // + XPOIState decisionPivotState; + DetectPivotPOIs( + conditions.pivotZone, + decisionState, + decisionPivotState // + ); + + // + // Combine two State ... + XPOIState combinedPivotState; + XPOIState iStates[]; + AddRef( + analysePivotState, + iStates // + ); + AddRef( + decisionPivotState, + iStates // + ); + CombineStates( + combinedPivotState, + iStates // + ); + combinedPivotState = decisionPivotState; + + // + ArrayFree(iStates); + + // + combinedPivotState.time = decisionPivotState.time; + combinedPivotState.symbol = decisionPivotState.symbol; + combinedPivotState.period = decisionPivotState.period; + + // + // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... + FilterPivotState( + conditions.pivotZone, + combinedPivotState // + ); + + // + conditions.pivotZone.state = combinedPivotState; + + // + double peakUpper = 0; + double peakLower = 0; + double valeUpper = 0; + double valeLower = 0; + + // + datetime peakTo = NULL; + datetime valeTo = NULL; + datetime peakFrom = NULL; + datetime valeFrom = NULL; + + // + bool hasBoxData = DetectPivotStateBoxData( + conditions.pivotZone, + peakUpper, + peakLower, + peakFrom, + peakTo, + valeUpper, + valeLower, + valeFrom, + valeTo // + ); + + // + // Calculate Pivot Tick Zones ... + + // + int ticksLevels = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneLevel(); + int ticksRange = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneRange(); + + // + CalculatePivotTickZone( + conditions.pivotZone, + ticksLevels, + ticksRange // + ); + + // + isPivotPeakZoneRejected = + hasBoxData && + ( + // + IsBarReject( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ) + // + || + // + IsBarReject( + peakUpper, + X_DIRECTION_BEARISH, + cBar // + ) + // + ); + isPivotPeakZoneBreakedUp = + hasBoxData && + IsBarBreak( + peakUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotPeakZoneBreakedDown = + hasBoxData && + IsBarBreak( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isPivotValeZoneRejected = + hasBoxData && + ( + // + IsBarReject( + valeLower, + X_DIRECTION_BULLISH, + cBar // + ) + // + || + // + IsBarReject( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ) + // + ); + isPivotValeZoneBreakedUp = + hasBoxData && + IsBarBreak( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotValeZoneBreakedDown = + hasBoxData && + IsBarBreak( + valeLower, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + bool isPivotEnded = IsValid(X121SMCXRSPVIPivotEnd); + if (isPivotEnded) + { + // + X121SMCXRSPVIPivotPeak = 0; + X121SMCXRSPVIPivotVale = 0; + X121SMCXRSPVIPivotEnd = NULL; + X121SMCXRSPVIPivotStart = NULL; + X121SMCXRSPVIPivotType = XPV_NONE; + + // + conditions.pivotZone.Clean(); + } + // // Summarize Conditions ... @@ -1109,7 +1391,7 @@ bool DetectX121SMCXRSPVISiganlSetup( // // Manipulate Conditions Pivot ... - + // double pivot = decisionXConditions.sarBuffer[1]; pivot = (decisionXConditions.sarBuffer[1] + decisionXConditions.strBuffer[1]) / 2; @@ -1191,19 +1473,45 @@ bool DetectX121SMCXRSPVISiganlSetup( : pzPeak; } + // + // + // + + // + bool isCond5Bullish = + // + hasDecisionBullishTrend && + isPivotValeZoneRejected + // + ; + + // + bool isCond5Bearish = + // + hasDecisionBearishTrend && + isPivotPeakZoneRejected + // + ; + + // + bool hasCond5Conditions = isCond5Bullish || + isCond5Bearish; + // isBullish = - isCond1Bullish || - isCond2Bullish || - isCond3Bullish || - isCond4Bullish; + isCond5Bullish && + (isCond1Bullish || + isCond2Bullish || + isCond3Bullish || + isCond4Bullish); // isBearish = - isCond1Bearish || - isCond2Bearish || - isCond3Bearish || - isCond4Bearish; + isCond5Bearish && + (isCond1Bearish || + isCond2Bearish || + isCond3Bearish || + isCond4Bearish); // result = isBullish || diff --git a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 index ee89de27..9611e159 100644 --- a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 @@ -412,68 +412,26 @@ bool DetectX121SMCXSTRPVSiganlSetup( // // Consolidation ... - ENUM_X_DIRECTION consolidationMarketDir; - bool hasConsolidationMarketDir = consolidationCycleHelper - .DetectMarketStructure(consolidationMarketDir); // - bool hasConsolidationBullishTrend = - hasConsolidationMarketDir && - IsBullish(consolidationMarketDir); - - // - bool hasConsolidationBearishTrend = - hasConsolidationMarketDir && - IsBearish(consolidationMarketDir); + bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; + bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; // // Verification ... - ENUM_X_DIRECTION verificationMarketDir; - bool hasVerificationMarketDir = verificationCycleHelper - .DetectMarketStructure(verificationMarketDir); - - // - bool hasVerificationBullishTrend = - hasVerificationMarketDir && - IsBullish(verificationMarketDir); - - // - bool hasVerificationBearishTrend = - hasVerificationMarketDir && - IsBearish(verificationMarketDir); + bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; + bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; // // Analyse ... - ENUM_X_DIRECTION analyseMarketDir; - bool hasAnalyseMarketDir = analyseCycleHelper - .DetectMarketStructure(analyseMarketDir); - - // - bool hasAnalyseBullishTrend = - hasAnalyseMarketDir && - IsBullish(analyseMarketDir); - - // - bool hasAnalyseBearishTrend = - hasAnalyseMarketDir && - IsBearish(analyseMarketDir); + bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; + bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; // // Decision ... - ENUM_X_DIRECTION decisionMarketDir; - bool hasDecisionMarketDir = decisionCycleHelper - .DetectMarketStructure(decisionMarketDir); - - // - bool hasDecisionBullishTrend = - hasDecisionMarketDir && - IsBullish(decisionMarketDir); - - // - bool hasDecisionBearishTrend = - hasDecisionMarketDir && - IsBearish(decisionMarketDir); - + bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; + bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; + // // Detect Bar State ...