diff --git a/Helpers/x-saherelm.xchhk.helper.mq5 b/Helpers/x-saherelm.xchhk.helper.mq5 index 3051ae10..84d3a28b 100644 --- a/Helpers/x-saherelm.xchhk.helper.mq5 +++ b/Helpers/x-saherelm.xchhk.helper.mq5 @@ -246,6 +246,17 @@ struct XCHHKConditions // // Conditions ... + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + // // Current ... @@ -331,6 +342,17 @@ struct XCHHKConditions // // Conditions ... + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + // // Current ... @@ -416,6 +438,41 @@ struct XCHHKConditions // // Conditions ... + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + // // Current ... if (isCBullish) @@ -592,6 +649,16 @@ struct XCHHKConditions // string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + // // Current ... ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + @@ -2461,13 +2528,406 @@ public: // Tools ... // - double GetCyclesMaxHigh( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + int GetBars( + XOHCL &bars[], + int barIndex // Bar Index ) { // - double result = 0; + int result = 0; + + // + Clean(bars); + + // + XOHCL bar; + bool hasBar = false; + + // + // CURRENT ... + bar.Clean(); + hasBar = CAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // SHORT ... + bar.Clean(); + hasBar = SAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // MEDIUM ... + bar.Clean(); + hasBar = MAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // LONG ... + bar.Clean(); + hasBar = LAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // HIND ... + bar.Clean(); + hasBar = HAsOHCL( + bar, + barIndex // + ); + if (hasBar && bar.IsValid()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetBullishBars( + XOHCL &bars[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(bars); + + // + XOHCL bar; + bool hasBar = false; + + // + // CURRENT ... + bar.Clean(); + hasBar = CAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // SHORT ... + bar.Clean(); + hasBar = SAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // MEDIUM ... + bar.Clean(); + hasBar = MAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // LONG ... + bar.Clean(); + hasBar = LAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // HIND ... + bar.Clean(); + hasBar = HAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBullish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetBearishBars( + XOHCL &bars[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(bars); + + // + XOHCL bar; + bool hasBar = false; + + // + // CURRENT ... + bar.Clean(); + hasBar = CAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // SHORT ... + bar.Clean(); + hasBar = SAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // MEDIUM ... + bar.Clean(); + hasBar = MAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // LONG ... + bar.Clean(); + hasBar = LAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + // HIND ... + bar.Clean(); + hasBar = HAsOHCL( + bar, + barIndex // + ); + if (hasBar && + bar.IsValid() && + bar.IsBearish()) + { + // + AddRef( + bar, + bars // + ); + + // + hasBar = false; + bar.Clean(); + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetCyclesBars( + XOHCL &bars[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(bars); // int cyclesCount = ArraySize(cycles); @@ -2477,12 +2937,11 @@ public: } // - double values[]; for (int i = 0; i < cyclesCount; i++) { // XOHCL iBar; - bool isBarInited = false; + bool hasBar = false; // switch (cycles[i]) @@ -2490,65 +2949,238 @@ public: // // CURRENT ... case X_MARKET_CYCLE_UNKNOWN: - // - isBarInited = CAsOHCL( - iBar, - barIndex // - ); + hasBar = CAsOHCL(iBar, barIndex); break; - // // SHORT ... case X_MARKET_CYCLE_SHORT: - // - isBarInited = SAsOHCL( - iBar, - barIndex // - ); + hasBar = SAsOHCL(iBar, barIndex); break; - // // MEDIUM ... case X_MARKET_CYCLE_MEDIUM: - // - isBarInited = MAsOHCL( - iBar, - barIndex // - ); + hasBar = MAsOHCL(iBar, barIndex); break; - // // LONG ... case X_MARKET_CYCLE_LONG: - // - isBarInited = LAsOHCL( - iBar, - barIndex // - ); + hasBar = LAsOHCL(iBar, barIndex); break; - // // HIND ... case X_MARKET_CYCLE_HIND: - // - isBarInited = HAsOHCL( - iBar, - barIndex // - ); + hasBar = HAsOHCL(iBar, barIndex); break; } // - if (isBarInited) + if (hasBar && iBar.IsValid()) { // - Add( - iBar.high, - values // + AddRef( + iBar, + bars // ); } } + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetCyclesBullishBars( + XOHCL &bars[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(bars); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iBar; + bool hasBar = false; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + hasBar = CAsOHCL(iBar, barIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + hasBar = SAsOHCL(iBar, barIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + hasBar = MAsOHCL(iBar, barIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + hasBar = LAsOHCL(iBar, barIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + hasBar = HAsOHCL(iBar, barIndex); + break; + } + + // + if (hasBar && + iBar.IsValid() && + iBar.IsBullish()) + { + // + AddRef( + iBar, + bars // + ); + } + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + int GetCyclesBearishBars( + XOHCL &bars[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(bars); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + XOHCL iBar; + bool hasBar = false; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + hasBar = CAsOHCL(iBar, barIndex); + break; + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + hasBar = SAsOHCL(iBar, barIndex); + break; + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + hasBar = MAsOHCL(iBar, barIndex); + break; + // + // LONG ... + case X_MARKET_CYCLE_LONG: + hasBar = LAsOHCL(iBar, barIndex); + break; + // + // HIND ... + case X_MARKET_CYCLE_HIND: + hasBar = HAsOHCL(iBar, barIndex); + break; + } + + // + if (hasBar && + iBar.IsValid() && + iBar.IsBearish()) + { + // + AddRef( + iBar, + bars // + ); + } + } + + // + result = ArraySize(bars); + + // + return result; + } + + // + double GetMaxHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + // result = GetMax(values); @@ -2557,92 +3189,39 @@ public: } // - double GetCyclesMinHigh( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + double GetMinHigh( + int barIndex // Bar Index ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); - if (!IsValidSize(cyclesCount)) + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) { return result; } // double values[]; - for (int i = 0; i < cyclesCount; i++) + for (int i = 0; i < barsCount; i++) { // - XOHCL iBar; - bool isBarInited = false; + Add( + bars[i].high, + values); + } - // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - isBarInited = CAsOHCL( - iBar, - barIndex // - ); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - isBarInited = SAsOHCL( - iBar, - barIndex // - ); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - isBarInited = MAsOHCL( - iBar, - barIndex // - ); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - isBarInited = LAsOHCL( - iBar, - barIndex // - ); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - isBarInited = HAsOHCL( - iBar, - barIndex // - ); - break; - } - - // - if (isBarInited) - { - // - Add( - iBar.high, - values // - ); - } + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; } // @@ -2653,92 +3232,39 @@ public: } // - double GetCyclesMaxLow( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + double GetMaxLow( + int barIndex // Bar Index ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); - if (!IsValidSize(cyclesCount)) + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) { return result; } // double values[]; - for (int i = 0; i < cyclesCount; i++) + for (int i = 0; i < barsCount; i++) { // - XOHCL iBar; - bool isBarInited = false; + Add( + bars[i].low, + values); + } - // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - isBarInited = CAsOHCL( - iBar, - barIndex // - ); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - isBarInited = SAsOHCL( - iBar, - barIndex // - ); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - isBarInited = MAsOHCL( - iBar, - barIndex // - ); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - isBarInited = LAsOHCL( - iBar, - barIndex // - ); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - isBarInited = HAsOHCL( - iBar, - barIndex // - ); - break; - } - - // - if (isBarInited) - { - // - Add( - iBar.low, - values // - ); - } + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; } // @@ -2749,92 +3275,755 @@ public: } // - double GetCyclesMinLow( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + double GetMinLow( + int barIndex // Bar Index ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); - if (!IsValidSize(cyclesCount)) + XOHCL bars[]; + int barsCount = GetBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) { return result; } // double values[]; - for (int i = 0; i < cyclesCount; i++) + for (int i = 0; i < barsCount; i++) { // - XOHCL iBar; - bool isBarInited = false; + Add( + bars[i].low, + values); + } + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Bullish ... + + // + double GetMaxBullishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBullishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxBullishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBullishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Bearish ... + + // + double GetMaxBearishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - isBarInited = CAsOHCL( - iBar, - barIndex // - ); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - isBarInited = SAsOHCL( - iBar, - barIndex // - ); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - isBarInited = MAsOHCL( - iBar, - barIndex // - ); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - isBarInited = LAsOHCL( - iBar, - barIndex // - ); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - isBarInited = HAsOHCL( - iBar, - barIndex // - ); - break; - } - - // - if (isBarInited) - { - // - Add( - iBar.low, - values // - ); - } + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBearishHigh( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxBearishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinBearishLow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, + barIndex // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Cycles Bullish ... + + // + double GetMaxCyclesBullishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBullishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxCyclesBullishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBullishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + // Cycles Bearish ... + + // + double GetMaxCyclesBearishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBearishHigh( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].high, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMin(values); + + // + return result; + } + + // + double GetMaxCyclesBearishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetMax(values); + + // + return result; + } + + // + double GetMinCyclesBearishLow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // + ); + if (!IsValidSize(barsCount)) + { + return result; + } + + // + double values[]; + for (int i = 0; i < barsCount; i++) + { + // + Add( + bars[i].low, + values); + } + + // + int valuesCount = ArraySize(values); + if (!IsValidSize(valuesCount)) + { + return result; } // @@ -2845,7 +4034,6 @@ public: } // - // Calculate Bullish Power ... double GetBullishPower( int barIndex // Bar Index ) @@ -2854,88 +4042,20 @@ public: double result = 0; // - XOHCL cBar; - bool isInited = CAsOHCL( - cBar, + XOHCL bars[]; + int barsCount = GetBullishBars( + bars, barIndex // ); - if (!isInited) + if (!IsValidSize(barsCount)) { return result; } // - if (cBar.IsBullish()) + for (int i = 0; i < barsCount; i++) { - result += cBar.GetBody(); - } - - // - XOHCL sBar; - isInited = SAsOHCL( - sBar, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - if (sBar.IsBullish()) - { - result += sBar.GetBody(); - } - - // - XOHCL mBar; - isInited = MAsOHCL( - mBar, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - if (mBar.IsBullish()) - { - result += mBar.GetBody(); - } - - // - XOHCL lBar; - isInited = LAsOHCL( - lBar, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - if (lBar.IsBullish()) - { - result += lBar.GetBody(); - } - - // - XOHCL hBar; - isInited = HAsOHCL( - hBar, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - if (hBar.IsBullish()) - { - result += hBar.GetBody(); + result = bars[i].GetBody(); } // @@ -2943,7 +4063,6 @@ public: } // - // Calculate Bearish Power ... double GetBearishPower( int barIndex // Bar Index ) @@ -2952,88 +4071,82 @@ public: double result = 0; // - XOHCL cBar; - bool isInited = CAsOHCL( - cBar, + XOHCL bars[]; + int barsCount = GetBearishBars( + bars, barIndex // ); - if (!isInited) + if (!IsValidSize(barsCount)) { return result; } // - if (cBar.IsBearish()) + for (int i = 0; i < barsCount; i++) { - result += cBar.GetBody(); + result = bars[i].GetBody(); } // - XOHCL sBar; - isInited = SAsOHCL( - sBar, - barIndex // - ); - if (!isInited) - { - return result; - } + return result; + } + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { // - if (sBar.IsBearish()) - { - result += sBar.GetBody(); - } + double result = 0; // - XOHCL mBar; - isInited = MAsOHCL( - mBar, - barIndex // + XOHCL bars[]; + int barsCount = GetCyclesBullishBars( + bars, + barIndex, + cycles // ); - if (!isInited) + if (!IsValidSize(barsCount)) { return result; } // - if (mBar.IsBearish()) + for (int i = 0; i < barsCount; i++) { - result += mBar.GetBody(); + result = bars[i].GetBody(); } // - XOHCL lBar; - isInited = LAsOHCL( - lBar, - barIndex // - ); - if (!isInited) - { - return result; - } + return result; + } + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { // - if (lBar.IsBearish()) - { - result += lBar.GetBody(); - } + double result = 0; // - XOHCL hBar; - isInited = HAsOHCL( - hBar, - barIndex // + XOHCL bars[]; + int barsCount = GetCyclesBearishBars( + bars, + barIndex, + cycles // ); - if (!isInited) + if (!IsValidSize(barsCount)) { return result; } // - if (hBar.IsBearish()) + for (int i = 0; i < barsCount; i++) { - result += hBar.GetBody(); + result = bars[i].GetBody(); } // @@ -3041,7 +4154,6 @@ public: } // - // Check Bullish Power is Up ... bool HasBullishPower( int barIndex // Bar Index ) @@ -3066,7 +4178,6 @@ public: } // - // Check Bearish Power is Up ... bool HasBearishPower( int barIndex // Bar Index ) @@ -3090,6 +4201,56 @@ public: return result; } + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + // // Check Bullish Power Increasing ... bool IsBullishPowerIncreasing( @@ -3314,6 +4475,234 @@ public: return result; } + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + // // Conditions ... @@ -3417,6 +4806,39 @@ public: return result; } + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + // // Current ... diff --git a/Helpers/x-saherelm.xchm.helper.mq5 b/Helpers/x-saherelm.xchm.helper.mq5 index 2de52918..ac8e817b 100644 --- a/Helpers/x-saherelm.xchm.helper.mq5 +++ b/Helpers/x-saherelm.xchm.helper.mq5 @@ -277,6 +277,17 @@ struct XCHMConditions // // Conditions ... + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; + // // AVG ... @@ -398,6 +409,17 @@ struct XCHMConditions ArraySetAsSeries(hFast, true); ArraySetAsSeries(hSlow, true); + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + // // AVG ... @@ -505,6 +527,41 @@ struct XCHMConditions // We Can Ignore Scoring ... // or Complete this later ... + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + // // AVG ... @@ -720,6 +777,16 @@ struct XCHMConditions // string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + // // AVG ... ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) + @@ -1589,306 +1656,220 @@ public: // Tools ... // - double GetCyclesMaxFast( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + void GetCycle( + double &fast, + double &slow, + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + fast = 0; + slow = 0; + + // + switch (cycle) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + fast = GetCFast(barIndex); + slow = GetCSlow(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + fast = GetSFast(barIndex); + slow = GetSSlow(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + fast = GetMFast(barIndex); + slow = GetMSlow(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + fast = GetLFast(barIndex); + slow = GetLSlow(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + fast = GetHFast(barIndex); + slow = GetHSlow(barIndex); + break; + } + } + + // + double GetCyclePower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); - if (!IsValidSize(cyclesCount)) - { - return result; - } + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); // - double values[]; - for (int i = 0; i < cyclesCount; i++) - { - // - double iValue = 0; - - // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - iValue = GetCFast(barIndex); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - iValue = GetSFast(barIndex); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - iValue = GetMFast(barIndex); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - iValue = GetLFast(barIndex); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - iValue = GetHFast(barIndex); - break; - } - - // - if (iValue > 0) - { - // - Add( - iValue, - values // - ); - } - } - - // - result = GetMax(values); + result = MathAbs(fast - slow); // return result; } // - double GetCyclesMinFast( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + double GetCycleFast( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); - if (!IsValidSize(cyclesCount)) - { - return result; - } + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); // - double values[]; - for (int i = 0; i < cyclesCount; i++) - { - // - double iValue = 0; - - // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - iValue = GetCFast(barIndex); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - iValue = GetSFast(barIndex); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - iValue = GetMFast(barIndex); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - iValue = GetLFast(barIndex); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - iValue = GetHFast(barIndex); - break; - } - - // - if (iValue > 0) - { - // - Add( - iValue, - values // - ); - } - } - - // - result = GetMin(values); + result = fast; // return result; } // - double GetCyclesMaxSlow( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + double GetCycleSlow( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); - if (!IsValidSize(cyclesCount)) - { - return result; - } + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); // - double values[]; - for (int i = 0; i < cyclesCount; i++) - { - // - double iValue = 0; - - // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - iValue = GetCSlow(barIndex); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - iValue = GetSSlow(barIndex); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - iValue = GetMSlow(barIndex); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - iValue = GetLSlow(barIndex); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - iValue = GetHSlow(barIndex); - break; - } - - // - if (iValue > 0) - { - // - Add( - iValue, - values // - ); - } - } - - // - result = GetMax(values); + result = slow; // return result; } // - double GetCyclesMinSlow( - int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + double GetCycleMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // ) { // double result = 0; // - int cyclesCount = ArraySize(cycles); + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = MathMax(fast, slow); + + // + return result; + } + + // + double GetCycleMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle // + ) + { + // + double result = 0; + + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycle // + ); + + // + result = MathMin(fast, slow); + + // + return result; + } + + // + int GetFasts( + double &values[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); if (!IsValidSize(cyclesCount)) { return result; } // - double values[]; for (int i = 0; i < cyclesCount; i++) { // - double iValue = 0; - - // - switch (cycles[i]) - { - // - // CURRENT ... - case X_MARKET_CYCLE_UNKNOWN: - // - iValue = GetCSlow(barIndex); - break; - - // - // SHORT ... - case X_MARKET_CYCLE_SHORT: - // - iValue = GetSSlow(barIndex); - break; - - // - // MEDIUM ... - case X_MARKET_CYCLE_MEDIUM: - // - iValue = GetMSlow(barIndex); - break; - - // - // LONG ... - case X_MARKET_CYCLE_LONG: - // - iValue = GetLSlow(barIndex); - break; - - // - // HIND ... - case X_MARKET_CYCLE_HIND: - // - iValue = GetHSlow(barIndex); - break; - } + double iValue = GetCycleFast( + barIndex, + cycles[i] // + ); // if (iValue > 0) @@ -1902,7 +1883,328 @@ public: } // - result = GetMin(values); + result = ArraySize(values); + + // + return result; + } + + // + int GetSlows( + double &values[], + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(values); + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleSlow( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesFast( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleFast( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesSlow( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleSlow( + barIndex, + cycles[i] // + ); + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishCycles( + ENUM_X_MARKET_CYCLES &cycles[], // Holds Result + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES mCycles[]; + int cyclesCount = GetAllMarketCycles( + mCycles // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + mCycles[i] // + ); + + // + bool isBullish = fast > slow; + if (isBullish) + { + // + Add( + mCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + int GetBearishCycles( + ENUM_X_MARKET_CYCLES &cycles[], // Holds Result + int barIndex // Bar Index + ) + { + // + int result = 0; + + // + Clean(cycles); + + // + ENUM_X_MARKET_CYCLES mCycles[]; + int cyclesCount = GetAllMarketCycles( + mCycles // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + mCycles[i] // + ); + + // + bool isBearish = fast < slow; + if (isBearish) + { + // + Add( + mCycles[i], + cycles // + ); + } + } + + // + result = ArraySize(cycles); + + // + return result; + } + + // + double GetMax( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMin( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetAllMarketCycles(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } // return result; @@ -1911,24 +2213,34 @@ public: // double GetCyclesMax( int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ENUM_X_MARKET_CYCLES &cycles[] // ) { // double result = 0; // - double maxFast = GetCyclesMaxFast( - barIndex, - cycles // - ); - double maxSlow = GetCyclesMaxSlow( - barIndex, - cycles // - ); + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } // - result = MathMax(maxFast, maxSlow); + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } // return result; @@ -1937,31 +2249,500 @@ public: // double GetCyclesMin( int barIndex, // Bar Index - ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ENUM_X_MARKET_CYCLES &cycles[] // ) { // double result = 0; // - double minFast = GetCyclesMinFast( - barIndex, - cycles // - ); - double minSlow = GetCyclesMinSlow( - barIndex, - cycles // - ); + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } // - result = MathMin(minFast, minSlow); + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMaxBullish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMinBullish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMaxBearish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMax( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue > result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMinBearish( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = GetCycleMin( + barIndex, + cycles[i] // + ); + + // + result = + result == 0 || iValue < result + ? iValue + : result; + } + + // + return result; + } + + // + double GetMaxBullishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBullishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBullishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBullishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBearishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBearishFast( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesFast( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetMaxBearishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetMinBearishSlow( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + double values[]; + int valuesCount = GetCyclesSlow( + values, + barIndex, + cycles // + ); + if (!IsValidSize(valuesCount)) + { + return result; + } + + // + result = GetSpecifiedMin(values); // return result; } // - // Calculate Bullish Power ... double GetBullishPower( int barIndex // Bar Index ) @@ -1970,58 +2751,30 @@ public: double result = 0; // - double fast = 0; - double slow = 0; - double delta = 0; - - // - // CURRENT ... - fast = GetCFast(barIndex); - slow = GetCSlow(barIndex); - delta = MathAbs(fast - slow); - if (fast > slow) + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBullishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) { - result += delta; + return result; } // - // SHORT ... - fast = GetSFast(barIndex); - slow = GetSSlow(barIndex); - delta = MathAbs(fast - slow); - if (fast > slow) + for (int i = 0; i < cyclesCount; i++) { - result += delta; - } + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); - // - // MEDIUM ... - fast = GetMFast(barIndex); - slow = GetMSlow(barIndex); - delta = MathAbs(fast - slow); - if (fast > slow) - { - result += delta; - } - - // - // LONG ... - fast = GetLFast(barIndex); - slow = GetLSlow(barIndex); - delta = MathAbs(fast - slow); - if (fast > slow) - { - result += delta; - } - - // - // HIND ... - fast = GetHFast(barIndex); - slow = GetHSlow(barIndex); - delta = MathAbs(fast - slow); - if (fast > slow) - { - result += delta; + // + if (iPower > 0) + { + result += iPower; + } } // @@ -2029,7 +2782,6 @@ public: } // - // Calculate Bearish Power ... double GetBearishPower( int barIndex // Bar Index ) @@ -2038,58 +2790,130 @@ public: double result = 0; // - double fast = 0; - double slow = 0; - double delta = 0; - - // - // CURRENT ... - fast = GetCFast(barIndex); - slow = GetCSlow(barIndex); - delta = MathAbs(slow - fast); - if (fast < slow) + ENUM_X_MARKET_CYCLES cycles[]; + int cyclesCount = GetBearishCycles( + cycles, + barIndex // + ); + if (!IsValidSize(cyclesCount)) { - result += delta; + return result; } // - // SHORT ... - fast = GetSFast(barIndex); - slow = GetSSlow(barIndex); - delta = MathAbs(slow - fast); - if (fast < slow) + for (int i = 0; i < cyclesCount; i++) { - result += delta; - } + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + // + if (iPower > 0) + { + result += iPower; + } + } + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + // - // MEDIUM ... - fast = GetMFast(barIndex); - slow = GetMSlow(barIndex); - delta = MathAbs(slow - fast); - if (fast < slow) + for (int i = 0; i < cyclesCount; i++) { - result += delta; + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycles[i] // + ); + + // + if (fast > slow) + { + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + if (iPower > 0) + { + result += iPower; + } + } } + + // + return result; + } + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { // - // LONG ... - fast = GetLFast(barIndex); - slow = GetLSlow(barIndex); - delta = MathAbs(slow - fast); - if (fast < slow) + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) { - result += delta; + return result; } // - // HIND ... - fast = GetHFast(barIndex); - slow = GetHSlow(barIndex); - delta = MathAbs(slow - fast); - if (fast < slow) + for (int i = 0; i < cyclesCount; i++) { - result += delta; + // + double fast = 0; + double slow = 0; + GetCycle( + fast, + slow, + barIndex, + cycles[i] // + ); + + // + if (fast < slow) + { + // + double iPower = GetCyclePower( + barIndex, + cycles[i] // + ); + + // + if (iPower > 0) + { + result += iPower; + } + } } // @@ -2097,7 +2921,6 @@ public: } // - // Check Bullish Power is Up ... bool HasBullishPower( int barIndex // Bar Index ) @@ -2122,7 +2945,6 @@ public: } // - // Check Bearish Power is Up ... bool HasBearishPower( int barIndex // Bar Index ) @@ -2146,6 +2968,56 @@ public: return result; } + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + // // Check Bullish Power Increasing ... bool IsBullishPowerIncreasing( @@ -2370,6 +3242,234 @@ public: return result; } + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + // // Conditions ... @@ -2582,6 +3682,39 @@ public: double maxValuePrev = 0; double minValuePrev = 0; + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + // // AVG ... diff --git a/Helpers/x-saherelm.xchstr.helper.mq5 b/Helpers/x-saherelm.xchstr.helper.mq5 index 7bb47a28..4ca1e329 100644 --- a/Helpers/x-saherelm.xchstr.helper.mq5 +++ b/Helpers/x-saherelm.xchstr.helper.mq5 @@ -246,6 +246,16 @@ struct XCHSTRConditions // // Conditions ... + // + // Power ... + bool hasBullishPower; + bool hasBearishPower; + bool isBullishPowerUp; + bool isBearishPowerUp; + bool isBullishPowerIncreasing; + bool isBullishPowerDecreasing; + bool isBearishPowerIncreasing; + bool isBearishPowerDecreasing; // // Current ... @@ -312,6 +322,17 @@ struct XCHSTRConditions // // Conditions ... + // + // Power ... + hasBullishPower = false; + hasBearishPower = false; + isBullishPowerUp = false; + isBearishPowerUp = false; + isBullishPowerIncreasing = false; + isBullishPowerDecreasing = false; + isBearishPowerIncreasing = false; + isBearishPowerDecreasing = false; + // // Current ... isCBullish = false; @@ -367,6 +388,41 @@ struct XCHSTRConditions // // Conditions ... + // + // Power ... + if (hasBullishPower) + { + bullishScore++; + } + if (hasBearishPower) + { + bearishScore++; + } + if (isBullishPowerUp) + { + bullishScore++; + } + if (isBearishPowerUp) + { + bearishScore++; + } + if (isBullishPowerIncreasing) + { + bullishScore++; + } + if (isBullishPowerDecreasing) + { + bearishScore++; + } + if (isBearishPowerIncreasing) + { + bearishScore++; + } + if (isBearishPowerDecreasing) + { + bullishScore++; + } + // // Current ... if (isCBullish) @@ -503,6 +559,16 @@ struct XCHSTRConditions // string conditionsStr = + // + // Power ... + ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + // // Current ... ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + @@ -1237,6 +1303,1289 @@ public: return result; } + // + int GetTrends( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = 0; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + iValue = GetCTrend(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + iValue = GetSTrend(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + iValue = GetMTrend(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + iValue = GetLTrend(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + iValue = GetHTrend(barIndex); + break; + } + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBullishTrends( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = 0; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + if (IsBullish((double)GetCState(barIndex))) + { + iValue = GetCTrend(barIndex); + } + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + if (IsBullish((double)GetSState(barIndex))) + { + iValue = GetSTrend(barIndex); + } + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + if (IsBullish((double)GetMState(barIndex))) + { + iValue = GetMTrend(barIndex); + } + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + if (IsBullish((double)GetLState(barIndex))) + { + iValue = GetLTrend(barIndex); + } + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + if (IsBullish((double)GetHState(barIndex))) + { + iValue = GetHTrend(barIndex); + } + break; + } + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetBearishTrends( + double &values[], + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + int result = 0; + + // + Clean(values); + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double iValue = 0; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + if (IsBearish((double)GetCState(barIndex))) + { + iValue = GetCTrend(barIndex); + } + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + if (IsBearish((double)GetSState(barIndex))) + { + iValue = GetSTrend(barIndex); + } + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + if (IsBearish((double)GetMState(barIndex))) + { + iValue = GetMTrend(barIndex); + } + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + if (IsBearish((double)GetLState(barIndex))) + { + iValue = GetLTrend(barIndex); + } + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + if (IsBearish((double)GetHState(barIndex))) + { + iValue = GetHTrend(barIndex); + } + break; + } + + // + if (iValue > 0) + { + // + Add( + iValue, + values // + ); + } + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetCyclesMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetMax(trends); + + // + return result; + } + + // + double GetCyclesMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetMin(trends); + + // + return result; + } + + // + double GetCyclesMaxBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBullishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetMax(trends); + + // + return result; + } + + // + double GetCyclesMinBullish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBullishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetMin(trends); + + // + return result; + } + + // + double GetCyclesMaxBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBearishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetMax(trends); + + // + return result; + } + + // + double GetCyclesMinBearish( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + double trends[]; + int trendsCount = GetBearishTrends( + trends, + barIndex, + cycles // + ); + if (!IsValidSize(trendsCount)) + { + return result; + } + + // + result = GetMin(trends); + + // + return result; + } + + // + double GetBullishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double power = 0; + double state = -100; + + // + // CURRENT ... + power = GetCTrend(barIndex); + state = (double)GetCState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // SHORT ... + power = GetSTrend(barIndex); + state = (double)GetSState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // MEDIUM ... + power = GetMTrend(barIndex); + state = (double)GetMState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // LONG ... + power = GetLTrend(barIndex); + state = (double)GetLState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + // HIND ... + power = GetHTrend(barIndex); + state = (double)GetHState(barIndex); + if (IsBullish(state)) + { + result += power; + } + + // + return result; + } + + // + double GetBearishPower( + int barIndex // Bar Index + ) + { + // + double result = 0; + + // + double power = 0; + double state = -100; + + // + // CURRENT ... + power = GetCTrend(barIndex); + state = (double)GetCState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // SHORT ... + power = GetSTrend(barIndex); + state = (double)GetSState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // MEDIUM ... + power = GetMTrend(barIndex); + state = (double)GetMState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // LONG ... + power = GetLTrend(barIndex); + state = (double)GetLState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + // HIND ... + power = GetHTrend(barIndex); + state = (double)GetHState(barIndex); + if (IsBearish(state)) + { + result += power; + } + + // + return result; + } + + // + double GetCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = 0; + double state = -100; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + power = GetCTrend(barIndex); + state = GetCState(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + power = GetSTrend(barIndex); + state = GetSState(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + power = GetMTrend(barIndex); + state = GetMState(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + power = GetLTrend(barIndex); + state = GetLState(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + power = GetHTrend(barIndex); + state = GetHState(barIndex); + break; + } + + // + if (power > 0 && state != -100) + { + // + if (IsBullish(state)) + { + result += power; + } + } + } + + // + return result; + } + + // + double GetCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + double result = 0; + + // + int cyclesCount = ArraySize(cycles); + if (!IsValidSize(cyclesCount)) + { + return result; + } + + // + for (int i = 0; i < cyclesCount; i++) + { + // + double power = 0; + double state = -100; + + // + switch (cycles[i]) + { + // + // CURRENT ... + case X_MARKET_CYCLE_UNKNOWN: + // + power = GetCTrend(barIndex); + state = GetCState(barIndex); + break; + + // + // SHORT ... + case X_MARKET_CYCLE_SHORT: + // + power = GetSTrend(barIndex); + state = GetSState(barIndex); + break; + + // + // MEDIUM ... + case X_MARKET_CYCLE_MEDIUM: + // + power = GetMTrend(barIndex); + state = GetMState(barIndex); + break; + + // + // LONG ... + case X_MARKET_CYCLE_LONG: + // + power = GetLTrend(barIndex); + state = GetLState(barIndex); + break; + + // + // HIND ... + case X_MARKET_CYCLE_HIND: + // + power = GetHTrend(barIndex); + state = GetHState(barIndex); + break; + } + + // + if (power > 0 && state != -100) + { + // + if (IsBearish(state)) + { + result += power; + } + } + } + + // + return result; + } + + // + bool HasBullishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasBearishPower( + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + double bullishPower = GetBullishPower(barIndex); + double bearishPower = GetBearishPower(barIndex); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBullishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bearishPower >= 0 && + bullishPower > bearishPower + // + ; + + // + return result; + } + + // + bool HasCyclesBearishPower( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // + ) + { + // + bool result = false; + + // + double bullishPower = GetCyclesBullishPower(barIndex, cycles); + double bearishPower = GetCyclesBearishPower(barIndex, cycles); + + // + result = + // + bullishPower >= 0 && + bearishPower > bullishPower + // + ; + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsBullishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsBullishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBullishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBullishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsBearishPowerIncreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsBearishPowerDecreasing( + int barIndex, // Bar Index + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetBearishPower(barIndex); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetBearishPower(i); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Increasing ... + bool IsCyclesBullishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bullish Power Decreasing ... + bool IsCyclesBullishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBullishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBullishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Increasing ... + bool IsCyclesBearishPowerIncreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower > iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower > lastPower + // + ; + } + + // + return result; + } + + // + // Check Bearish Power Decreasing ... + bool IsCyclesBearishPowerDecreasing( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[], // + int loopback = 5 // Loopback + ) + { + // + bool result = false; + + // + if (loopback <= 0) + { + loopback = 5; + } + + // + double firstPower = GetCyclesBearishPower(barIndex, cycles); + double lastPower = firstPower; + for (int i = barIndex + 1; i < barIndex + loopback; i++) + { + // + double iPower = GetCyclesBearishPower(i, cycles); + + // + result = + // + iPower > 0 && + firstPower > 0 && + lastPower < iPower + // + ; + if (!result) + { + break; + } + + // + lastPower = iPower; + } + + // + if (result) + { + // + result = + // + firstPower < lastPower + // + ; + } + + // + return result; + } + // // Conditions ... @@ -1365,6 +2714,39 @@ public: return result; } + // + // Power ... + + // + bool hasBullishPower = HasBullishPower(cIndex); + bool hasBullishPowerPrev = HasBullishPower(pIndex); + + // + bool hasBearishPower = HasBearishPower(cIndex); + bool hasBearishPowerPrev = HasBearishPower(pIndex); + + // + bool isBullishPowerUp = hasBullishPower && + !hasBullishPowerPrev; + bool isBearishPowerUp = hasBearishPower && + !hasBearishPowerPrev; + + // + bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); + bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); + bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); + bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); + + // + conditions.hasBullishPower = hasBullishPower; + conditions.hasBearishPower = hasBearishPower; + conditions.isBullishPowerUp = isBullishPowerUp; + conditions.isBearishPowerUp = isBearishPowerUp; + conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; + conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; + conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; + conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; + // // Current ... diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 2d66e138..7f96e8a3 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -9004,6 +9004,19 @@ T GetMax( // return result; } +template +T GetSpecifiedMax( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + return GetMax( + buffer, + start, + count // + ); +} // // Get Min of Specific Loopback of a Buffer ... @@ -9059,6 +9072,19 @@ T GetMin( // return result; } +template +T GetSpecifiedMin( + T &buffer[], // the Buffer which required to search + int start = 0, // Start Index + int count = 0 // Count for Search +) +{ + return GetMin( + buffer, + start, + count // + ); +} // // Find a Value less than Specified ... @@ -10868,7 +10894,8 @@ int GetAllMarketCycles(ENUM_X_MARKET_CYCLES &result[]) // Copy( tmp, - result); + result // + ); // Clean(tmp);