From ed417a1a81c998b9fe072f701ef1bf5b36c2283b Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 23 Mar 2025 04:08:12 +0330 Subject: [PATCH] cleanup backup folder ... --- Documents/BKP/1.mq5 | 245 - Documents/BKP/inside.box.sig.mq5 | 830 --- Documents/BKP/signalling.parsers.mq5 | 1563 ----- Documents/BKP/support_and_resistance.mq5 | 121 - Documents/BKP/test.waiting.boxes.mq5 | 584 -- Documents/BKP/tmp.bar.anal.mq5 | 5209 -------------- Documents/BKP/tmp.drawer.mq5 | 520 -- Documents/BKP/workingZone.zone.box.mq5 | 3099 --------- .../x-121.smc.market.cycle.helper.class.mq5 | 4033 ----------- Documents/BKP/x-cmn.tmp.codes.mq5 | 1413 ---- Documents/BKP/x-ob.fvg.tmp.mq5 | 1386 ---- Documents/BKP/x-omid.signalling.mq5 | 543 -- .../BKP/x-saherelm.x-bar.analyser.class.mq5 | 6043 ----------------- Documents/BKP/x-saherelm.x-poi.class copy.mq5 | 3334 --------- Documents/BKP/x-saherelm.x-poi.class.mq5 | 3334 --------- Documents/BKP/x-saherelm.x121.xsessions.mq5 | 197 - Documents/BKP/x-saherelm.x121.xwz.mq5 | 2780 -------- Documents/BKP/x-saherelm.xohcl.lib.mq5 | 1352 ---- Documents/BKP/x-saherelm.xpoi.test.ea.mq5 | 377 - Documents/BKP/x-tmp.structs.mq5 | 2508 ------- .../BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 | 2621 ------- Documents/BKP/x121.usin-xtrend.mq5 | 4637 ------------- 22 files changed, 46729 deletions(-) delete mode 100644 Documents/BKP/1.mq5 delete mode 100644 Documents/BKP/inside.box.sig.mq5 delete mode 100644 Documents/BKP/signalling.parsers.mq5 delete mode 100644 Documents/BKP/support_and_resistance.mq5 delete mode 100644 Documents/BKP/test.waiting.boxes.mq5 delete mode 100644 Documents/BKP/tmp.bar.anal.mq5 delete mode 100644 Documents/BKP/tmp.drawer.mq5 delete mode 100644 Documents/BKP/workingZone.zone.box.mq5 delete mode 100644 Documents/BKP/x-121.smc.market.cycle.helper.class.mq5 delete mode 100644 Documents/BKP/x-cmn.tmp.codes.mq5 delete mode 100644 Documents/BKP/x-ob.fvg.tmp.mq5 delete mode 100644 Documents/BKP/x-omid.signalling.mq5 delete mode 100644 Documents/BKP/x-saherelm.x-bar.analyser.class.mq5 delete mode 100644 Documents/BKP/x-saherelm.x-poi.class copy.mq5 delete mode 100644 Documents/BKP/x-saherelm.x-poi.class.mq5 delete mode 100644 Documents/BKP/x-saherelm.x121.xsessions.mq5 delete mode 100644 Documents/BKP/x-saherelm.x121.xwz.mq5 delete mode 100644 Documents/BKP/x-saherelm.xohcl.lib.mq5 delete mode 100644 Documents/BKP/x-saherelm.xpoi.test.ea.mq5 delete mode 100644 Documents/BKP/x-tmp.structs.mq5 delete mode 100644 Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 delete mode 100644 Documents/BKP/x121.usin-xtrend.mq5 diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 deleted file mode 100644 index d1801624..00000000 --- a/Documents/BKP/1.mq5 +++ /dev/null @@ -1,245 +0,0 @@ -//+------------------------------------------------------------------+ -//| Valid_Break_Detector | -//| Copyright 2023, MetaQuotes Software Corp. | -//| https://www.mql5.com | -//+------------------------------------------------------------------+ -#property copyright "Copyright 2023, MetaQuotes Software Corp." -#property link "https://www.mql5.com" -#property version "1.00" -#property description "Detects Valid Breakouts of Zones with Rejection Confirmation" - -// Input Parameters -input double LotSize = 0.1; // Lot size for trades -input int StopLoss = 50; // Stop Loss in points -input int TakeProfit = 100; // Take Profit in points -input bool RequireVolumeSpike = true; // Enable volume spike filter -input double VolumeThreshold = 1.5; // Minimum volume increase factor -input bool RequireCloseBeyond = true; // Require candle close beyond the zone -input int RejectionConfirmationCandles = 2; // Number of candles to confirm rejection - -// Global Variables -int MagicNumber = 789101; - -// -double _Ask = 0; -double _Bid = 0; - -// Zone Boundaries -double ZoneHigh = 0; -double ZoneLow = 0; - -// -double maBuffer[]; -int maHandler = INVALID_HANDLE; - -// Breakout Status -bool BullishBreakoutDetected = false; -bool BearishBreakoutDetected = false; - -//+------------------------------------------------------------------+ -//| Expert initialization function | -//+------------------------------------------------------------------+ -int OnInit() -{ - // - ArraySetAsSeries(maBuffer, true); - maHandler = iMA( - _Symbol, - _Period, - 14, - 0, - MODE_SMA, - VOLUME_TICK // - ); - if (maHandler == INVALID_HANDLE) - { - return (INIT_FAILED); - } - - // - Print("Valid Break Detector EA Initialized"); - return (INIT_SUCCEEDED); -} - -//+------------------------------------------------------------------+ -//| Expert deinitialization function | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) -{ - // - IndicatorRelease(maHandler); - Print("Valid Break Detector EA Deinitialized"); -} - -//+------------------------------------------------------------------+ -//| Expert tick function | -//+------------------------------------------------------------------+ -void OnTick() -{ - // - _Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); - _Bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); - CopyBuffer(maHandler, MAIN_LINE, 0, 14, maBuffer); - - // Define the zone dynamically (e.g., based on recent highs/lows) - DefineZone(); - - // Check for valid break of the zone - CheckValidBreak(); - - // Confirm rejection after breakout - if (BullishBreakoutDetected || BearishBreakoutDetected) - ConfirmRejection(); -} - -//+------------------------------------------------------------------+ -//| Function to define the zone dynamically | -//+------------------------------------------------------------------+ -void DefineZone() -{ - // Example: Define zone based on recent highs and lows - ZoneHigh = iHigh(_Symbol, _Period, 1); // Recent high - ZoneLow = iLow(_Symbol, _Period, 2); // Recent low -} - -//+------------------------------------------------------------------+ -//| Function to check for a valid break of the zone | -//+------------------------------------------------------------------+ -void CheckValidBreak() -{ - double currentPrice = _Bid; - - // Check if price breaks above the zone - if (!BullishBreakoutDetected && currentPrice > ZoneHigh) - { - if (IsValidBreak(ZoneHigh, true)) - { - Print("Potential Bullish Break Above Zone Detected at ", TimeToString(TimeCurrent(), TIME_DATE)); - BullishBreakoutDetected = true; - } - } - - // Check if price breaks below the zone - if (!BearishBreakoutDetected && currentPrice < ZoneLow) - { - if (IsValidBreak(ZoneLow, false)) - { - Print("Potential Bearish Break Below Zone Detected at ", TimeToString(TimeCurrent(), TIME_DATE)); - BearishBreakoutDetected = true; - } - } -} - -//+------------------------------------------------------------------+ -//| Function to validate the breakout | -//+------------------------------------------------------------------+ -bool IsValidBreak(double zoneLevel, bool isAbove) -{ - // Check if the candle closed beyond the zone - if (RequireCloseBeyond) - { - double closePrice = iClose(_Symbol, _Period, 1); - if ((isAbove && closePrice <= zoneLevel) || (!isAbove && closePrice >= zoneLevel)) - return false; - } - - // Check for a volume spike - if (RequireVolumeSpike) - { - double currentVolume = (double) iVolume(_Symbol, _Period, 1); - double averageVolume = maBuffer[1]; - if (currentVolume < VolumeThreshold * averageVolume) - return false; - } - - // All conditions met, valid breakout - return true; -} - -//+------------------------------------------------------------------+ -//| Function to confirm rejection | -//+------------------------------------------------------------------+ -void ConfirmRejection() -{ - double currentPrice = _Bid; - - if (BullishBreakoutDetected) - { - // Check if price rejects lower levels and confirms bullish breakout - bool confirmed = true; - for (int i = 1; i <= RejectionConfirmationCandles; i++) - { - double closePrice = iClose(_Symbol, _Period, i); - if (closePrice < ZoneHigh) - { - confirmed = false; - break; - } - } - - if (confirmed) - { - Print("Bullish Breakout Confirmed at ", TimeToString(TimeCurrent(), TIME_DATE)); - PlaceTrade(ORDER_TYPE_BUY, "Confirmed Bullish Breakout Buy"); - BullishBreakoutDetected = false; // Reset breakout status - } - } - - if (BearishBreakoutDetected) - { - // Check if price rejects higher levels and confirms bearish breakout - bool confirmed = true; - for (int i = 1; i <= RejectionConfirmationCandles; i++) - { - double closePrice = iClose(_Symbol, _Period, i); - if (closePrice > ZoneLow) - { - confirmed = false; - break; - } - } - - if (confirmed) - { - Print("Bearish Breakout Confirmed at ", TimeToString(TimeCurrent(), TIME_DATE)); - PlaceTrade(ORDER_TYPE_SELL, "Confirmed Bearish Breakout Sell"); - BearishBreakoutDetected = false; // Reset breakout status - } - } -} - -//+------------------------------------------------------------------+ -//| Function to place a trade | -//+------------------------------------------------------------------+ -void PlaceTrade(int orderType, string comment) -{ - double price = (orderType == ORDER_TYPE_BUY) ? _Ask : _Bid; - double sl = (orderType == ORDER_TYPE_BUY) ? price - StopLoss * Point() : price + StopLoss * Point(); - double tp = (orderType == ORDER_TYPE_BUY) ? price + TakeProfit * Point() : price - TakeProfit * Point(); - - MqlTradeRequest request; - MqlTradeResult result; - - ZeroMemory(request); - ZeroMemory(result); - - request.action = TRADE_ACTION_DEAL; - request.symbol = _Symbol; - request.volume = LotSize; - request.type = orderType; - request.price = price; - request.sl = sl; - request.tp = tp; - request.deviation = 10; - request.magic = MagicNumber; - request.comment = comment; - - if (!OrderSend(request, result)) - { - Print("Error placing order: ", result.retcode); - } - else - { - Print(comment, " Order placed successfully."); - } -} \ No newline at end of file diff --git a/Documents/BKP/inside.box.sig.mq5 b/Documents/BKP/inside.box.sig.mq5 deleted file mode 100644 index d9f48a2b..00000000 --- a/Documents/BKP/inside.box.sig.mq5 +++ /dev/null @@ -1,830 +0,0 @@ - // - bool HasSenario1Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XBoxZone &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XPOIStateEvents cStateEvents; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XPOIStateEvents chStateEvents; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chStateEvents, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - chStateEvents.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - XCPOIDrawer *drawer = provider - .visionCycleHelper - .mPOIDrawer; - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int ppIDX = pIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // Detect Inside Box ... - XBoxZone insideBox; - count = ArraySize(waitingBoxes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - bool isBullish = iBox.IsBullish(); - double iMid = iBox.lower + ((iBox.upper - iBox.lower) / 2); - - // - has = - // - isBullish - ? cBar.low < iMid && - cBar.low > iBox.lower - : cBar.high > iMid && - cBar.high < iBox.upper - // - ; - if (has) - { - // - insideBox = iBox; - break; - } - } - } - has = insideBox.IsValid(); - - // - ENUM_X_DIRECTION iBarPosDir; - bool isBarValidForDir = cHelper - .mBarAnalyser - .IsValidForPosition( - cBar, - iBarPosDir // - ); - bool isBarValidForBullish = - isBarValidForDir && - IsBullish(iBarPosDir); - bool isBarValidForBearish = - isBarValidForDir && - IsBearish(iBarPosDir); - - // - if (has) - { - // - XCBoxObject *iObj; - has = drawer.DrawBox( - insideBox, - iObj // - ); - if (has) - { - // - Print("Dec Scores:"); - Print("-------------"); - Print("Bull: ", provider.decisionBullishScore); - Print("Bear: ", provider.decisionBearishScore); - Print("-------------"); - Print("Anal Scores:"); - Print("-------------"); - Print("Bull: ", provider.analyseBullishScore); - Print("Bear: ", provider.analyseBearishScore); - Print("-------------"); - Print("Bar Valid For: " + ToString(iBarPosDir)); - Print("-------------"); - Print(ToString(insideBox.dir), " Inside ..."); - Print("-------------"); - } - } - - // - result = has; - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - insideBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - insideBox.IsBullish() && - isBarValidForBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - insideBox.IsBearish() && - isBarValidForBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.from = insideBox.from; - box.upper = insideBox.upper; - box.lower = insideBox.lower; - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - insideBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chStateEvents.Clean(); - chXConditions.Clean(); - - // - return result; - } - - ///////////////////////////////////////////////////// - - - /** - * Checking a Box Exists in Collections or not ... - * - * @param box: XBoxZone instance reference ... - * - * @return ( bool ) - */ - bool IsExists(XBoxZone &box) - { - // - bool result = false; - - // - // Check Validation ... - result = box.IsValid() && - (HasWaitingBoxes() || - HasBreakedBoxes() || - HasUnavailableBoxes()); - if (!result) - { - return result; - } - - // - int idx = -1; - bool has = false; - - // - // Check Index in Waiting Boxes ... - has = HasWaitingBoxes(); - if (has) - { - // - idx = FindIndex( - box, - waitingBoxes // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - } - - // - // Check Index in Breaked Boxes ... - has = HasBreakedBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedBoxes // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - } - - // - // Check Index in Unavailable Boxes ... - has = HasUnavailableBoxes(); - if (has) - { - // - idx = FindIndex( - box, - unavailableBoxes // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - } - - // - return result; - } - - - /** - * Detect Signal Boxes ... - * - * @param cycle: ENUM_X_CYCLES member ... - * @param provider: X121SMCStrategySignalProviderData instance reference ... - * @param barIndex: int ... - * - * @return ( bool ) - */ - bool DetectSignalBoxes( - ENUM_X_CYCLES cycle, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Select Cycle ... - XPOIState cState; - XPOIStateEvents cStateEvents; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - // Select Rejection Boxes ... - - // // - // // Select Validate Rejection Boxes ... - // XBoxZone rejections[]; - // int count = cHelper - // .DetectRejections( - // rejections, - // barIndex // - // ); - - // // - // result = IsValidSize(count); - // if (result) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // has = IsExists(rejections[i]); - // if (!has) - // { - // // - // AddRef( - // rejections[i], - // waitingBoxes // - // ); - // } - // } - // } - - // // - // // Select Order Blocks ... - // if (cStateEvents.hasNewOrderBlock) - // { - // // - // idx = GetYoungest(cState.orderBlocks); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // XCOrderBlock *iOB = cState.orderBlocks[idx]; - - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // iOB // - // ); - // if (has) - // { - // // - // has = IsExists(iBox); - // if (!has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - // } - // } - // } - - // - // Select Fair Value Gaps ... - // if (cStateEvents.hasNewFairValueGap) - // { - // // - // idx = GetYoungest(cState.fairValueGaps); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // XCFVG *iOB = cState.fairValueGaps[idx]; - - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // iOB // - // ); - // if (has) - // { - // // - // has = IsExists(iBox); - // if (!has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - // } - // } - // } - - // - // Select Supply/Demand Zones ... - // if (cStateEvents.hasNewSupplyZone) - // { - // // - // idx = GetYoungest(cState.supplyZones); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // XCSupplyZone *iSupply = cState.supplyZones[idx]; - - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // iSupply // - // ); - // if (has) - // { - // // - // has = IsExists(iBox); - // if (!has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - // } - // } - // } - // if (cStateEvents.hasNewDemandZone) - // { - // // - // idx = GetYoungest(cState.demandZones); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // XCDemandZone *iDemand = cState.demandZones[idx]; - - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // iDemand // - // ); - // if (has) - // { - // // - // has = IsExists(iBox); - // if (!has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - // } - // } - // } - - // - // Select Support/Resistance Zones ... - // if (cStateEvents.hasNewSupportZone) - // { - // // - // idx = GetYoungest(cState.supportZones); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // XCSupportZone *iSupport = cState.supportZones[idx]; - - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // iSupport // - // ); - // if (has) - // { - // // - // has = IsExists(iBox); - // if (!has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - // } - // } - // } - // if (cStateEvents.hasNewResistanceZone) - // { - // // - // idx = GetYoungest(cState.resistanceZones); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // XCResistanceZone *iResistance = cState.resistanceZones[idx]; - - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // iResistance // - // ); - // if (has) - // { - // // - // has = IsExists(iBox); - // if (!has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - // } - // } - // } - - // - count = CountWaitingBoxes(); - result = IsValidSize(count); - - // - // Cleanup Resources ... - - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - - /** - * Validating Waiting Boxes and Detect Breaked Boxes ... - * - * @param barIndex: int ... - * - * @return ( int ) - */ - int ValidateWaitingBoxes( - int barIndex = 0 // - ) - { - // - int result = 0; - - // - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex = 1; - } - - // - has = HasWaitingBoxes(); - if (!has) - { - return result; - } - - // - int removeIDX[]; - result = CountWaitingBoxes(); - for (int i = 0; i < result; i++) - { - // - XOHCL iBar; - XBoxZone iBox = waitingBoxes[i]; - bool isInite = iBar - .Init( - iBox.symbol, - iBox.period, - iBox.from // - ); - - // - has = isInite && - IsBoxBreaked( - iBox, - iBar.Index() - 1, - barIndex, - period // - ); - if (has) - { - // - Add( - i, - removeIDX // - ); - - // - AddRef( - iBox, - breakedBoxes // - ); - } - - // - iBox.Clean(); - iBar.Clean(); - } - - // - has = HasChild(removeIDX); - if (has) - { - // - CleanupArray( - removeIDX, - waitingBoxes // - ); - } - Clean(removeIDX); - - // - result = CountWaitingBoxes(); - - // - return result; - } diff --git a/Documents/BKP/signalling.parsers.mq5 b/Documents/BKP/signalling.parsers.mq5 deleted file mode 100644 index 8020ed75..00000000 --- a/Documents/BKP/signalling.parsers.mq5 +++ /dev/null @@ -1,1563 +0,0 @@ - // - bool HasSenario1Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - cXConditions.isSMHKSwitchedToBullish && - ( - // - // Validate CBar ... - cBar.IsBullish() && - // - (cBar.low >= cXConditions.valesGoldenBuffer[cIDX] || - (cBar.low < cXConditions.valesGoldenBuffer[cIDX] && - cXConditions.isSarSwitchedToBullish)) && - // - (cBar.open == cXConditions.xhkSMOpenBuffer[cIDX] || - (cBar.low < cXConditions.xhkSMLowBuffer[cIDX] && - cBar.GetDown() > cXConditions.xhkSMHighBuffer[cIDX])) && - // - cXConditions.isSarBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - cXConditions.isSMHKSwitchedToBearish && - ( - // - // Validate CBar ... - cBar.IsBearish() && - // - (cBar.high <= cXConditions.peaksGoldenBuffer[cIDX] || - (cBar.high > cXConditions.peaksGoldenBuffer[cIDX] && - cXConditions.isSarSwitchedToBearish)) && - // - (cBar.open == cXConditions.xhkSMOpenBuffer[cIDX] || - (cBar.high > cXConditions.xhkSMHighBuffer[cIDX] && - cBar.GetUp() < cXConditions.xhkSMLowBuffer[cIDX])) && - // - cXConditions.isSarBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Fix Box Upper and Lower based on Strategy ... - - // - double points = GetPoints(box.symbol); - double minPointsDiff = points * 20; - - // - double prefferSL = 0; - - // - // Other SL Conditions ... - if (prefferSL <= 0) - { - // - if (isBullish) - { - // - if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesBuffer[cIDX]; - } - else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX] && - zBar.open < cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - else if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - // - if (cXConditions.sarBuffer[cIDX] > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.sarBuffer[cIDX]; - } - else - { - prefferSL = zBar.open > cXConditions.peaksGoldenBuffer[cIDX]; - } - } - } - else - { - // - if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksBuffer[cIDX]; - } - else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX] && - zBar.open > cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksGoldenBuffer[cIDX]; - } - else if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - // - if (cXConditions.sarBuffer[cIDX] < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.sarBuffer[cIDX]; - } - else - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - } - } - } - - // - if (prefferSL > 0) - { - // - box.upper = - isBullish - ? zBar.open - : prefferSL; - - // - box.lower = - isBullish - ? prefferSL - : zBar.open; - } - - // - // Validate Conditions to Force Has Holder Box ... - - result = - result && - holderBox.IsValid() && - dir == holderBox.dir; - - // - if (!result) - { - // - isBullish = false; - isBearish = false; - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - bool HasSenario2Conditions( - ENUM_X_CYCLES ttfCycle, - XBoxZone &breakedBoxes[], - XBoxZone &box, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0, - bool forceBarType = false, - bool forceFiboPressure = false // - ) - { - // - bool result = false; - - // - // Validate Args ... - result = - IsValid(ttfCycle) && - HasChild(breakedBoxes); - if (!result) - { - return result; - } - - // - // TODO: Add support for Extracting Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // TTF Cycle Extract ... - XPOIState ttfState; - X121Conditions ttfXConditions; - XC121SMCCycleHelper *ttfHelper; - X121SMCCycleConditions ttfConditions; - result = provider.SelectCycle( - ttfCycle, - ttfState, - ttfXConditions, - ttfHelper, - ttfConditions // - ); - if (!result) - { - // - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - Parse(ttfXConditions); - - // - // Normalize Args ... - - // - box.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Define Resources ... - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - double ask = GetAsk(ttfState.symbol); - double bid = GetBid(ttfState.symbol); - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - ttfState.symbol, - ttfState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - - // - // Conditions ... - - // - // First we Have to Detect Inside Box ... - XBoxZone insideBox; - count = ArraySize(breakedBoxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = breakedBoxes[i]; - - // - bool isInside = - IsInsideBox( - zBar, - iBox // - ); - if (isInside) - { - // - // Since we have to Follow Trend based on Breaked Boxes ... - // we have to use: - // - Breaked Bullish Boxes on Bearish Trend ... - // - Breaked Bearish Boxes on Bullish Trend ... - isInside = - hasBullishTrend - ? iBox.IsBearish() - : hasBearishTrend - ? iBox.IsBullish() - : false; - - // - // Check Inside ... - if (isInside) - { - // - insideBox = iBox; - iBox.Clean(); - - // - break; - } - } - - // - iBox.Clean(); - } - - // - // Check Inside Box is Valid or not ... - result = insideBox.IsValid(); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ttfState.Clean(); - insideBox.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - } - - // - // Update Inside Box From and To ... - // Based on Breaked ... - insideBox.from = insideBox.to; - insideBox.to = TimeCurrent(); - - // - // Detect Breaked Box Direction ... - bool isInsideBoxBullish = insideBox.IsBullish(); - bool isInsideBoxBearish = insideBox.IsBearish(); - - // - // Detect Inside Box Rejection ... - - // - bool isUpperBearishReject = - cBar.high >= insideBox.upper && - cBar.GetUp() < insideBox.upper; - - // - bool isUpperBullishReject = - cBar.low <= insideBox.upper && - cBar.GetDown() > insideBox.upper; - - // - bool isLowerBearishReject = - cBar.high >= insideBox.lower && - cBar.GetUp() < insideBox.lower; - - // - bool isLowerBullishReject = - cBar.low <= insideBox.lower && - cBar.GetDown() > insideBox.lower; - - // - // Apply Force Bar Type ... - if (forceBarType) - { - // - isUpperBearishReject = - isUpperBearishReject && - cBar.IsBearish(); - - // - isUpperBullishReject = - isUpperBullishReject && - cBar.IsBullish(); - - // - isLowerBearishReject = - isLowerBearishReject && - cBar.IsBearish(); - - // - isLowerBullishReject = - isLowerBullishReject && - cBar.IsBullish(); - } - - // - // Apply Force Fibo Pressure ... - if (forceBarType) - { - // - isUpperBearishReject = - isUpperBearishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - isUpperBullishReject = - isUpperBullishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - isLowerBearishReject = - isLowerBearishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - isLowerBullishReject = - isLowerBullishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - } - - // - // Bullish Conditions ... - isBullish = ( - // - hasBullishTrend && - isInsideBoxBearish && - isLowerBullishReject - // - ); - - // - // Bearish Conditions ... - isBearish = ( - // - hasBearishTrend && - isInsideBoxBullish && - isUpperBearishReject - // - ); - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - box = insideBox; - - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish // - ); - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - ttfState.Clean(); - insideBox.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - - // - bool HasSenario4Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - cBar.IsBullish() && - zBar.open >= cBar.close && - ( - // - // Regular Reject ... - (pBar.low > cBar.low && - cBar.low < cXConditions.valesGoldenBuffer[cIDX] && - cBar.GetDown() > cXConditions.valesGoldenBuffer[cIDX]) - // - || - // - // Regular Exit ... - (pBar.low < cXConditions.valesGoldenBuffer[cIDX] && - (cBar.low > cXConditions.valesGoldenBuffer[cIDX] || - cBar.GetUp() > cXConditions.valesGoldenBuffer[cIDX])) - // - || - // - IsBarBreak( - cXConditions.valesGoldenBuffer[cIDX], - X_DIRECTION_BULLISH, - cBar // - ) - // - || - // - IsBarReject( - cXConditions.valesGoldenBuffer[cIDX], - X_DIRECTION_BULLISH, - cBar // - ) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSAR ... - cXConditions.isSarBullish && - // - // XSTR ... - cXConditions.isStrSwitchedToBullish && - // - // // X3MA ... - // // XVWAP ... - // (cXConditions.isX3MaFastOverMid || - // cXConditions.isVWapFastOverMid) && - // - // XHK ... - cXConditions.isSMHKBullish && - cXConditions.isRawHKBullish && - // - // XCHE ... - cXConditions.isCheBullish && - cXConditions.le1Buffer[cIDX] < cBar.low && - cXConditions.le2Buffer[cIDX] < cBar.low - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - cBar.IsBearish() && - zBar.open <= cBar.close && - ( - // - // Regular Reject ... - (pBar.high < cBar.high && - cBar.high > cXConditions.peaksGoldenBuffer[cIDX] && - cBar.GetUp() < cXConditions.peaksGoldenBuffer[cIDX]) - // - || - // - // Regular Exit ... - (pBar.high > cXConditions.peaksGoldenBuffer[cIDX] && - (cBar.high < cXConditions.peaksGoldenBuffer[cIDX] || - cBar.GetDown() < cXConditions.peaksGoldenBuffer[cIDX])) - // - || - // - IsBarBreak( - cXConditions.peaksGoldenBuffer[cIDX], - X_DIRECTION_BEARISH, - cBar // - ) - // - || - // - IsBarReject( - cXConditions.peaksGoldenBuffer[cIDX], - X_DIRECTION_BEARISH, - cBar // - ) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSAR ... - cXConditions.isSarBearish && - // - // XSTR ... - cXConditions.isStrSwitchedToBearish && - // - // // X3MA ... - // // XVWAP ... - // (cXConditions.isX3MaFastUnderMid || - // cXConditions.isVWapFastUnderMid) && - // - // XHK ... - cXConditions.isSMHKBearish && - cXConditions.isRawHKBearish && - // - // XCHE ... - cXConditions.isCheBearish && - cXConditions.se1Buffer[cIDX] > cBar.high && - cXConditions.se2Buffer[cIDX] > cBar.high - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Validate Conditions to Force Has Holder Box ... - result = - result && - holderBox.IsValid(); - if (!result) - { - // - isBullish = false; - isBearish = false; - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - \ No newline at end of file diff --git a/Documents/BKP/support_and_resistance.mq5 b/Documents/BKP/support_and_resistance.mq5 deleted file mode 100644 index fe5b2730..00000000 --- a/Documents/BKP/support_and_resistance.mq5 +++ /dev/null @@ -1,121 +0,0 @@ -//+------------------------------------------------------------------+ -//| Support and Resistance.mq5 | -//| https://t.me/ForexEaPremium | -//+------------------------------------------------------------------+ -#property copyright "https://t.me/ForexEaPremium" -#property version "2.02" - -#property description "Blue and red support and resistance levels displayed directly on the chart." -#property description "Alerts for close above resistance and close below support." - -#property indicator_chart_window -#property indicator_buffers 2 -#property indicator_plots 2 -#property indicator_color1 clrRed -#property indicator_type1 DRAW_ARROW -#property indicator_width1 2 -#property indicator_label1 "Resistance" -#property indicator_color2 clrBlue -#property indicator_type2 DRAW_ARROW -#property indicator_width2 2 -#property indicator_label2 "Support" - -enum enum_candle_to_check -{ - Current, - Previous -}; - -input bool EnableNativeAlerts = false; -input bool EnableEmailAlerts = false; -input bool EnablePushAlerts = false; -input enum_candle_to_check TriggerCandle = Previous; - -double Resistance[]; -double Support[]; - -int myFractal; - -datetime LastAlertTime = D'01.01.1970'; - -void OnInit() -{ - PlotIndexSetInteger(0, PLOT_ARROW, 119); - PlotIndexSetInteger(1, PLOT_ARROW, 119); - - SetIndexBuffer(0, Resistance); - SetIndexBuffer(1, Support); - - ArraySetAsSeries(Resistance, true); - ArraySetAsSeries(Support, true); - - PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 5); - PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 5); - - myFractal = iFractals(NULL, 0); -} - -int OnCalculate(const int rates_total, - const int prev_calculated, - const datetime &Time[], - const double &open[], - const double &High[], - const double &Low[], - const double &Close[], - const long &tick_volume[], - const long &volume[], - const int &spread[]) -{ - ArraySetAsSeries(High, true); - ArraySetAsSeries(Low, true); - ArraySetAsSeries(Close, true); - ArraySetAsSeries(Time, true); - - //Get the values of the Fractals indicator before entering the cycle. - double FractalUpperBuffer[]; - double FractalLowerBuffer[]; - - CopyBuffer(myFractal, 0, 0, rates_total, FractalUpperBuffer); - CopyBuffer(myFractal, 1, 0, rates_total, FractalLowerBuffer); - - ArraySetAsSeries(FractalUpperBuffer, true); - ArraySetAsSeries(FractalLowerBuffer, true); - - for (int i = rates_total - 2; i >= 0; i--) - { - if (FractalUpperBuffer[i] != EMPTY_VALUE) Resistance[i] = High[i]; - else Resistance[i] = Resistance[i + 1]; - - if (FractalLowerBuffer[i] != EMPTY_VALUE) Support[i] = Low[i]; - else Support[i] = Support[i + 1]; - } - - // Alerts - if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0)) - { - string Text, TextNative; - // Resistance. - if ((Close[TriggerCandle] > Resistance[TriggerCandle]) && (Close[TriggerCandle + 1] <= Resistance[TriggerCandle])) - { - Text = "S&R: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - Closed above Resistance: " + DoubleToString(Resistance[TriggerCandle], _Digits) + "."; - TextNative = "S&R: Closed above Resistance: " + DoubleToString(Resistance[TriggerCandle], _Digits) + "."; - if (EnableNativeAlerts) Alert(TextNative); - if (EnableEmailAlerts) SendMail("S&R Alert", Text); - if (EnablePushAlerts) SendNotification(Text); - LastAlertTime = Time[0]; - } - // Support. - if ((Close[TriggerCandle] < Support[TriggerCandle]) && (Close[TriggerCandle + 1] >= Support[TriggerCandle])) - { - Text = "S&R: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - Closed below Support: " + DoubleToString(Support[TriggerCandle], _Digits) + "."; - TextNative = "S&R: Closed below Support: " + DoubleToString(Support[TriggerCandle], _Digits) + "."; - if (EnableNativeAlerts) Alert(TextNative); - if (EnableEmailAlerts) SendMail("S&R Alert", Text); - if (EnablePushAlerts) SendNotification(Text); - LastAlertTime = Time[0]; - } - } - - return rates_total; -} -//+------------------------------------------------------------------+ \ No newline at end of file diff --git a/Documents/BKP/test.waiting.boxes.mq5 b/Documents/BKP/test.waiting.boxes.mq5 deleted file mode 100644 index 90410de4..00000000 --- a/Documents/BKP/test.waiting.boxes.mq5 +++ /dev/null @@ -1,584 +0,0 @@ - - // - // Configurations ... - bool useSharpChange = false; - bool useOrderBlockFVG = false; - - // - // Select Order Blocks ... - if (useOrderBlockFVG) - { - // - if (obStateEvents.hasNewOrderBlock) - { - // - idx = GetYoungest(obState.orderBlocks); - has = IsValidIndex(idx); - if (has) - { - // - XCFVG *iFVG = NULL; - XCOrderBlock *iOB = obState.orderBlocks[idx]; - bool isBullish = iOB.IsBullish(); - - // - // Detecting Inside FVG ... - has = fvgState.HasFairValueGaps(); - if (has) - { - // - XCFVG *tmpFVGs[]; - count = fvgState.CountFairValueGaps(); - for (int i = 0; i < count; i++) - { - // - XCFVG *jFVG = fvgState.fairValueGaps[i]; - - // - bool isDirPassed = jFVG.GetDirection() == iOB.GetDirection(); - bool isFromPassed = jFVG.From() >= iOB.From(); - bool isPlacePassed = IsInsideOrDiff( - jFVG, - iOB, - false // - ); - - // - has = isDirPassed && - isFromPassed && - isPlacePassed; - if (has) - { - // - Add( - jFVG, - tmpFVGs // - ); - } - - // - ZeroMemory(jFVG); - } - - // - // Selecting iFVG Based on Direction of OB ... - has = HasChild(tmpFVGs); - if (has) - { - // - idx = - isBullish - ? GetLowest(tmpFVGs) - : GetHighest(tmpFVGs); - has = IsValidIndex(idx); - if (has) - { - iFVG = tmpFVGs[idx]; - } - } - - // - Clean(tmpFVGs); - } - - // - XBoxZone iOBBox; - XBoxZone iFVGBox; - if (iFVG != NULL) - { - // - has = ToBox( - iFVGBox, - iFVG // - ); - } - - // - has = ToBox( - iOBBox, - iOB // - ); - - // - has = iOBBox.IsValid() && - iFVGBox.IsValid(); - if (has) - { - // - XSignalBox iSignalBox; - - // - iSignalBox.ob = iOBBox; - iSignalBox.fvg = iFVGBox; - - // - // Here We Check Waiting Box Contains Other Zones ... - // Like Support/Resistances ... - bool forceVerification = false; - if (forceVerification) - { - // - XBoxZone iVerificationBox; - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - ToBox( - provider.decisionState.supportZones, - tmpBoxes // - ); - } - else - { - // - ToBox( - provider.decisionState.resistanceZones, - tmpBoxes // - ); - } - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - // Select Box ... - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - // Validate Box ... - bool isValidPassed = !IsBoxValid( - iBox, - barIndex // - ); - bool isDirPassed = iBox.dir == iOBBox.dir; - bool isPlacePassed = - IsBoxInside( - iBox, - iOBBox // - ) - // - && - // - (!iFVGBox.IsValid() - ? true - : IsBoxInsideOr( - iBox, - iFVGBox // - )); - - // - has = - isDirPassed && - isValidPassed && - isPlacePassed; - if (has) - { - // - iVerificationBox = iBox; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - has = iVerificationBox.IsValid(); - Clean(tmpBoxes); - iVerificationBox.Clean(); - } - - // - if (has) - { - // - AddRef( - iSignalBox, - waitingBoxes // - ); - } - - // - iSignalBox.Clean(); - } - - // - iOBBox.Clean(); - iFVGBox.Clean(); - ZeroMemory(iOB); - ZeroMemory(iFVG); - } - } - } - - // - // Checking Other Senario for Waiting Boxes ... - if (useSharpChange) - { - // - if (obStateEvents.hasNewSharp) - { - // - XBoxZone currSharp; - XBoxZone prevSharp; - XBoxZone sharpConsolidation; - - // - // Retrieve Current Sharp ... - XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; - XBoxZone tmpBoxes[]; - Copy( - obState.sharps, - tmpBoxes // - ); - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (has) - { - // - currSharp = tmpBoxes[idx]; - bool isBullish = currSharp.IsBullish(); - - // - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - while (HasChild(tmpBoxes)) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - - // - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - if (iBox.dir == currSharp.dir) - { - // - prevSharp = iBox; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - - // - Clean(tmpBoxes); - } - Clean(tmpBoxes); - - // - // Preparing Sharp Consolidation Box ... - has = currSharp.IsValid() && - prevSharp.IsValid() && - prevSharp.lower < currSharp.upper; - if (has) - { - // - sharpConsolidation.type = "XSHCNZ"; - sharpConsolidation.dir = currSharp.dir; - sharpConsolidation.symbol = currSharp.symbol; - sharpConsolidation.period = currSharp.period; - - // - sharpConsolidation.from = prevSharp.to; - sharpConsolidation.to = currSharp.from; - - // - int toIDX = GetBarIndex( - currSharp.symbol, - currSharp.period, - sharpConsolidation.to // - ); - int fromIDX = GetBarIndex( - currSharp.symbol, - currSharp.period, - sharpConsolidation.from // - ); - int length = fromIDX - toIDX; - - // - XOHCL toBar; - has = toBar.Init( - sharpConsolidation.symbol, - sharpConsolidation.period, - toIDX // - ); - - // - if (has) - { - // - double upper = toBar.FindHighest( - length, - MODE_HIGH // - ); - - // - double lower = toBar.FindLowest( - length, - MODE_LOW // - ); - - // - sharpConsolidation.upper = upper; - sharpConsolidation.lower = lower; - } - - // - has = sharpConsolidation.IsValid(); - if (has) - { - // - XSignalBox iBox; - - // - iBox.ob = sharpConsolidation; - - // - AddRef( - iBox, - waitingBoxes // - ); - - // - iBox.Clean(); - - // // - // XCBoxObject *iCBoxObj; - // XCBoxObject *iPBoxObj; - // provider.visionCycleHelper.mPOIDrawer.DrawBox( - // currSharp, - // iCBoxObj // - // ); - // provider.visionCycleHelper.mPOIDrawer.DrawBox( - // prevSharp, - // iPBoxObj // - // ); - } - - // - currSharp.Clean(); - prevSharp.Clean(); - sharpConsolidation.Clean(); - } - } - - // - // Update Exists Box ... - // XBoxZone fvgs[]; - // count = ArraySize(waitingBoxes); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // bool isSharpBox = waitingBoxes[i].ob.type == "XSHCNZ"; - // if (!isSharpBox) - // { - // continue; - // } - - // // - // bool isBullish = waitingBoxes[i].ob.IsBullish(); - - // // - // // Extract Inside FVGS ... - // if (isBullish) - // { - // // - // ToBox( - // fvgState.bullishFairValueGaps, - // fvgs // - // ); - // } - // else - // { - // // - // ToBox( - // fvgState.bearishFairValueGaps, - // fvgs // - // ); - // } - // has = HasChild(fvgs); - // if (has) - // { - // // - // int removeds[]; - // int iFVGsCount = ArraySize(fvgs); - // for (int j = 0; j < iFVGsCount; j++) - // { - // // - // XBoxZone iFVGBox = fvgs[j]; - // bool isFromPassed = iFVGBox.from >= waitingBoxes[i].ob.from; - // bool isBoundaryPassed = - // isBullish - // ? iFVGBox.lower < waitingBoxes[i].ob.upper - // : iFVGBox.upper > waitingBoxes[i].ob.lower; - - // // - // has = isFromPassed && - // isBoundaryPassed; - // if (!has) - // { - // // - // Add( - // j, - // removeds // - // ); - // } - // } - - // // - // CleanupArray( - // removeds, - // fvgs // - // ); - // Clean(removeds); - // } - - // // - // // Select FVG ... - // has = HasChild(fvgs); - // if (has) - // { - // // - // idx = isBullish - // ? GetLowest(fvgs) - // : GetHighest(fvgs); - // has = IsValidIndex(idx); - // if (has) - // { - // waitingBoxes[i].fvg = fvgs[idx]; - // } - // } - // else - // { - // waitingBoxes[i].fvg.Clean(); - // } - // } - // } - - // - // Clean(fvgs); - } - - -///////////////////////////////////////////////////////////////////////////////////// - -if (signalProvider == X121SMC_XWZ_PROVIDER_XHKMA) -{ - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 0; - - // - // Prepare Box fro SL ... - iSL = pivot; - Add( - iSL, - sls // - ); - - // - // Fix rf Reward ... - rfRewar = 2; -} -else if (signalProvider == X121SMC_XWZ_PROVIDER_XREJECTED_BOX) -{ - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 0; - - // - Clean(sls); - - // - // Prepare Box fro SL ... - iSL = signalBox.lower + ((signalBox.upper - signalBox.lower) / 2); - Add( - iSL, - sls // - ); - - // - // Fix rf Reward ... - rfRewar = 2; -} -else if (signalProvider == X121SMC_XWZ_PROVIDER_XACTIVATED_BOX) -{ - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 0; - - // - Clean(sls); - - // - // Prepare Box fro SL ... - iSL = pivot; - Add( - iSL, - sls // - ); - - // - // Fix rf Reward ... - rfRewar = 2; -} -else if (signalProvider == X121SMC_XWZ_PROVIDER_XBREAKED_BOX) -{ - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 0; - - // - Clean(sls); - - // - // Prepare Box fro SL ... - iSL = pivot; - Add( - iSL, - sls // - ); - - // - // Fix rf Reward ... - rfRewar = 2; -} diff --git a/Documents/BKP/tmp.bar.anal.mq5 b/Documents/BKP/tmp.bar.anal.mq5 deleted file mode 100644 index e02f03c3..00000000 --- a/Documents/BKP/tmp.bar.anal.mq5 +++ /dev/null @@ -1,5209 +0,0 @@ - /** - * Detect Price Consolidation ... - * - * @param bar: XOHCL instance Reference, Start Bar ... - * @param loopback: Integer, Consolidation Length Finder ... - * @param consolidationRange: Integer, Consolidation Range Finder ... - * @param upper: Double Reference ... - * @param lower: Double Reference ... - * @param upperAppliedTo: ENUM_APPLIED_PRICE member, Upper Price ... - * @param lowerAppliedTo: ENUM_APPLIED_PRICE member, Lower Price ... - * - * @return ( bool ) - */ - bool IsConsolidate( - XOHCL &bar, - double &upper, - double &lower, - int loopback = 30, - int consolidationRange = 50, - ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH, - ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW // - ) - { - // - bool result = false; - - // - upper = 0; - lower = 0; - - // - if (loopback < 7) - { - loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double points = GetPoints(bar.symbol); - int index = bar.Index(); - - // - double upperPrice[]; - int upperPriceCount = FillPrice( - upperPrice, - upperAppliedTo, - bar.symbol, - bar.period, - index, - loopback // - ); - - // - double lowerPrice[]; - int lowerPriceCount = FillPrice( - lowerPrice, - lowerAppliedTo, - bar.symbol, - bar.period, - index, - loopback // - ); - - // - result = upperPriceCount == lowerPriceCount && - lowerPriceCount == loopback; - if (!result) - { - return result; - } - - // - upper = upperPrice[ArrayMaximum(upperPrice)]; - lower = lowerPrice[ArrayMinimum(lowerPrice)]; - - // - double range = upper - lower; - result = range <= consolidationRange * points; - - // - return result; - } - - bool HasConsolidationZone( - XOHCL &bar, - XConsolidationZone &zone, - int minLoopback = 3, - double range = 50, - ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH, - ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW // - ) - { - // - bool result = false; - - // - zone.Clean(); - - // - result = bar.IsValid() && - minLoopback > 0 && - range > 0; - if (!result) - { - return result; - } - - // - double points = GetPoints(bar.symbol); - int index = bar.Index() + 1; - int length = minLoopback; - - // - double upperPrice[]; - int upperPriceCount = FillPrice( - upperPrice, - upperAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - double lowerPrice[]; - int lowerPriceCount = FillPrice( - lowerPrice, - lowerAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - result = upperPriceCount == lowerPriceCount && - lowerPriceCount == length; - if (!result) - { - // - Clean(upperPrice); - Clean(lowerPrice); - - // - return result; - } - - // - double upper = upperPrice[ArrayMaximum(upperPrice)]; - double lower = lowerPrice[ArrayMinimum(lowerPrice)]; - - // - bool isBullishBreake = - bar.low > lower && - bar.high > upper && - bar.GetUp() > upper; - bool isBearishBreake = - bar.high < upper && - bar.low < lower && - bar.GetDown() < lower; - result = isBullishBreake || - isBearishBreake; - if (!result) - { - // - Clean(upperPrice); - Clean(lowerPrice); - - // - return result; - } - - // - double delta = upper - lower; - result = delta <= range * points; - if (!result) - { - // - Clean(upperPrice); - Clean(lowerPrice); - - // - return result; - } - - // - while (delta <= range * points) - { - // - length++; - - // - upperPriceCount = FillPrice( - upperPrice, - upperAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - lowerPriceCount = FillPrice( - lowerPrice, - lowerAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - bool isValid = upperPriceCount == lowerPriceCount && - lowerPriceCount == length; - if (!isValid) - { - break; - } - - // - double iUpper = upperPrice[ArrayMaximum(upperPrice)]; - double iLower = lowerPrice[ArrayMinimum(lowerPrice)]; - - // - delta = iUpper - iLower; - if (delta <= range * points) - { - // - upper = iUpper; - lower = iLower; - } - } - - // - Clean(upperPrice); - Clean(lowerPrice); - - // - // Filling Zone ... - zone.upper = upper; - zone.lower = lower; - zone.symbol = bar.symbol; - zone.period = bar.period; - zone.to = iTime( - bar.symbol, - bar.period, - bar.Index() + 1 // - ); - zone.from = iTime( - bar.symbol, - bar.period, - bar.Index() + length // - ); - zone.dir = isBullishBreake - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - result = zone.IsValid(); - if (!result) - { - zone.Clean(); - } - - // - return result; - } - - // - // Commons ... - - /** - * Check Specified Bar's Range is Extended or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool HasExtendedRange( - XOHCL &bar, - int loopback = 3 // - ) - { - // - bool result = false; - - // - if (loopback < 3) - { - loopback = 3; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - int start = index + 1; - int end = start + loopback; - int count = end - start; - result = count >= 1; - if (!result) - { - return result; - } - - // - double sum = 0; - XOHCL iBar = bar; - for (int i = start; i < end; i++) - { - // - bool isRetrieved = iBar.GetPreviousBar(iBar); - if (!isRetrieved) - { - continue; - } - - // - sum += iBar.GetRange(); - } - - // - result = sum > 0; - if (!result) - { - return result; - } - - // - double avg = sum / count; - - // - result = bar.GetRange() >= avg; - - // - return result; - } - - /** - * Check Specified Bar's Body is Extended or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool HasExtendedBody( - XOHCL &bar, - int loopback = 3 // - ) - { - // - bool result = false; - - // - if (loopback < 3) - { - loopback = 3; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - int start = index + 1; - int end = start + loopback; - int count = end - start; - result = count >= 1; - if (!result) - { - return result; - } - - // - double sum = 0; - XOHCL iBar = bar; - for (int i = start; i < end; i++) - { - // - bool isRetrieved = iBar.GetPreviousBar(iBar); - if (!isRetrieved) - { - continue; - } - - // - sum += iBar.GetBody(); - } - - // - result = sum > 0; - if (!result) - { - return result; - } - - // - double avg = sum / count; - - // - result = bar.GetBody() >= avg; - - // - return result; - } - - /** - * Check Specified Bar's Body and Range is Extended or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool IsExtended( - XOHCL &bar, - int loopback = 3 // - ) - { - // - bool result = false; - - // - bool hasExtendedBody = HasExtendedBody(bar, loopback); - bool hasExtendedRange = HasExtendedRange(bar, loopback); - result = hasExtendedBody && - hasExtendedRange; - - // - return result; - } - - /** - * Check Specified Bar is Swing High or not ... - * - * @param bar: XOHCL instnce ... - * @param range: Integer, Specified Range ... - * - * @return ( bool ) - */ - bool IsSwingHigh( - XOHCL &bar, - int range = 2 // - ) - { - // - bool result = false; - - // - if (range < 1) - { - range = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - index + i // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - index - i // - ); - if (!result) - { - break; - } - - // - result = bar.high >= iPrevBar.high && - bar.high >= iNextBar.high; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check Specified Bar is Swing Low or not ... - * - * @param bar: XOHCL instnce ... - * @param range: Integer, Specified Range ... - * - * @return ( bool ) - */ - bool IsSwingLow( - XOHCL &bar, - int range = 2 // - ) - { - // - bool result = false; - - // - if (range < 1) - { - range = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - index + i // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - index - i // - ); - if (!result) - { - break; - } - - // - result = bar.low <= iPrevBar.low && - bar.low <= iNextBar.low; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check Specified Bar is Swing or not ... - * - * @param bar: XOHCL instnce ... - * @param dir: ENUM_X_DIRECTION member ... - * @param range: Integer, Specified Range ... - * - * @return ( bool ) - */ - bool IsSwing( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int range = 2 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - bool isSwingLow = IsSwingLow(bar, range); - bool isSwingHigh = IsSwingHigh(bar, range); - - // - result = isSwingLow || - isSwingHigh; - if (result) - { - // - if (isSwingLow) - { - dir = X_DIRECTION_BULLISH; - } - else - { - dir = X_DIRECTION_BEARISH; - } - } - - // - return result; - } - - /** - * Check a Bar is Momentum Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param bodyPercent: Double ... - * - * @return ( bool ) - */ - bool IsMomentumBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double bodyPercent = 70 // - ) - { - // - bool result = false; - - // - if (extend < 0) - { - extend = 0; - } - - // - if (bodyPercent < 50) - { - bodyPercent = 50; - } - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (extend > 0) - { - // - result = IsExtended( - bar, - extend // - ); - - // - if (!result) - { - return result; - } - } - - // - double body = bar.GetBody(); - double rp = GetBarRangePercent(bar); - - // - result = body >= rp * bodyPercent; - - // - if (result) - { - // - dir = - bar.IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - /** - * Check a Bar is Rejection Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param shadowPercent: Double ... - * - * @return ( bool ) - */ - bool IsRejectionBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double shadowPercent = 60 // - ) - { - // - bool result = false; - - // - if (extend < 0) - { - extend = 0; - } - - // - if (shadowPercent < 50) - { - shadowPercent = 50; - } - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (extend > 0) - { - // - result = IsExtended( - bar, - extend // - ); - - // - if (!result) - { - return result; - } - } - - // - double body = bar.GetBody(); - double range = bar.GetRange(); - double shadows = bar.GetShadows(); - double lowShadow = bar.GetLowShadow(); - double highShadow = bar.GetHighShadow(); - double rp = GetBarRangePercent(bar); - - // - result = shadows >= rp * shadowPercent; - - // - if (result) - { - // - dir = - lowShadow > highShadow - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - /** - * Check Specified Bar is Engulfing Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param bodyPercent: Double ... - * - * @return ( bool ) - */ - bool IsEngulfBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double bodyPercent = 60 // - ) - { - // - bool result = false; - - // - if (extend < 0) - { - extend = 0; - } - - // - if (bodyPercent < 50) - { - bodyPercent = 50; - } - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - if (extend > 0) - { - // - result = IsExtended( - pBar, - extend // - ); - - // - if (!result) - { - return result; - } - } - - // - // Check Engulfig ... - result = - bar.GetUp() > pBar.GetUp() && - bar.GetDown() < pBar.GetDown(); - if (!result) - { - return result; - } - - // - // Check Engulfing Direction ... - bool isBullishEngulfed = - pBar.IsBearish() && - bar.IsBullish(); - bool isBearishEngulfed = - pBar.IsBullish() && - bar.IsBearish(); - - // - result = isBullishEngulfed || - isBearishEngulfed; - if (!result) - { - return result; - } - - // - dir = isBullishEngulfed - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Check Specified Bar is Pin Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param shadowPercent: Double ... - * @param bodyPercent: Double ... - * - * @return ( bool ) - */ - bool IsPinBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double shadowPercent = 65, - double bodyPercent = 25 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0 && - bodyPercent > 0 && - shadowPercent > 0 && - bodyPercent < shadowPercent; - if (!result) - { - return result; - } - - // - // Chack Range Extends ... - if (extend > 0) - { - // - result = HasExtendedRange( - bar, - extend // - ); - if (!result) - { - return result; - } - } - - // - // Check Body ... - double rangePercent = GetBarRangePercent(bar); - result = rangePercent > 0; - if (!result) - { - return result; - } - - // - double body = bar.GetBody(); - double highShadow = bar.GetHighShadow(); - double lowShadow = bar.GetLowShadow(); - - // - // Check Body ... - result = body / rangePercent >= bodyPercent; - if (!result) - { - return result; - } - - // - bool isPassedHighShadow = - highShadow / rangePercent >= shadowPercent; - bool isPassedLowShadow = - lowShadow / rangePercent >= shadowPercent; - result = - isPassedLowShadow || - isPassedHighShadow; - if (!result) - { - return result; - } - - // - dir = isPassedLowShadow - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Decision Bar (Pin, Momentum or Rejection) ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param shadowForPinAndRejectionBarPercent: Double ... - * @param bodyForPinBarPercent: Double ... - * @param bodyForEngulfBarPercent: Double ... - * @param bodyForMomentumBarPercent: Double ... - * - * @return ( bool ) - */ - bool IsDecisionBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double shadowForPinAndRejectionBarPercent = 65, - double bodyForPinBarPercent = 25, - double bodyForEngulfBarPercent = 65, - double bodyForMomentumBarPercent = 70 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Pin Bar ... - ENUM_X_DIRECTION pinDir; - bool isPiBar = IsPinBar( - bar, - pinDir, - extend, - shadowForPinAndRejectionBarPercent, - bodyForPinBarPercent // - ); - - // - // Engulfing Bar ... - ENUM_X_DIRECTION engulfDir; - bool isEngulfBar = IsEngulfBar( - bar, - engulfDir, - extend, - bodyForEngulfBarPercent // - ); - - // - // Momentum Bar ... - ENUM_X_DIRECTION momentumDir; - bool isMomentumBar = IsMomentumBar( - bar, - momentumDir, - extend, - bodyForMomentumBarPercent // - ); - - // - // Rejection Bar ... - ENUM_X_DIRECTION rejectionDir; - bool isRejectionBar = IsRejectionBar( - bar, - rejectionDir, - extend, - shadowForPinAndRejectionBarPercent // - ); - - // - result = isPiBar || - isEngulfBar || - isMomentumBar || - isRejectionBar; - if (result) - { - // - if (isPiBar) - { - dir = pinDir; - } - else if (isEngulfBar) - { - dir = engulfDir; - } - else if (isMomentumBar) - { - dir = momentumDir; - } - else - { - dir = rejectionDir; - } - } - - // - result = IsBullish(dir) || - IsBearish(dir); - - // - return result; - } - - - // - // Support and Resistance Zones ... - - /** - * Check a Bar is Support Bar or not ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Specified Verifiation Range ... - * - * @return ( bool ) - */ - bool IsSupport( - XOHCL &bar, - int range = 21 // - ) - { - // - bool result = false; - - // - if (range < 2) - { - range = 2; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - int prevIDX = index + i; - int nextIDX = index - 1; - - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - prevIDX // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - nextIDX // - ); - if (!result) - { - break; - } - - // - result = bar.low <= iPrevBar.low && - bar.low <= iNextBar.low; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check a Bar Has Support or not ... - * - * @param bar: XOHCL instance ... - * @param supportBar: XOHCL instance Specified Support Bar ... - * @param rage: int, - * @return ( bool ) - */ - bool HasSupport( - XOHCL &bar, - XOHCL &supportBar, - int range = 21 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int barIndex = bar.Index() + range; - result = IsValidIndex(barIndex); - if (!result) - { - // - supportBar.Clean(); - return result; - } - result = supportBar.Init( - bar.symbol, - bar.period, - barIndex // - ); - - // - result = supportBar.low < supportBar.GetDown(); - if (!result) - { - // - supportBar.Clean(); - return result; - } - - // - double selectedValue = supportBar.GetDown(); - - // - int llIDX = bar.FindLowestIndex(range - 1, MODE_LOW); - result = IsValidIndex(llIDX); - if (!result) - { - // - supportBar.Clean(); - return result; - } - - // - double llValue = iLow( - bar.symbol, - bar.period, - llIDX // - ); - - // - result = llValue >= selectedValue; - if (!result) - { - // - supportBar.Clean(); - return result; - } - - // - result = supportBar.IsValid(); - - // - return result; - } - - /** - * Check a Bar is Resistance Bar or not ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Specified Verifiation Range ... - * - * @return ( bool ) - */ - bool IsResistance( - XOHCL &bar, - int range = 21 // - ) - { - // - bool result = false; - - // - if (range < 2) - { - range = 2; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - int prevIDX = index + i; - int nextIDX = index - 1; - - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - prevIDX // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - nextIDX // - ); - if (!result) - { - break; - } - - // - result = bar.high >= iPrevBar.high && - bar.high >= iNextBar.high; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check a Bar Has Resistance or not ... - * - * @param bar: XOHCL instance ... - * @param resistanceBar: XOHCL instance Specified Resistance Bar ... - * @param rage: int, - * @return ( bool ) - */ - bool HasResistance( - XOHCL &bar, - XOHCL &resistanceBar, - int range = 21 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int barIndex = bar.Index() + range; - result = IsValidIndex(barIndex); - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - result = resistanceBar.Init( - bar.symbol, - bar.period, - barIndex // - ); - - // - result = resistanceBar.low < resistanceBar.GetDown(); - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - - // - double selectedValue = resistanceBar.GetUp(); - - // - int hhIDX = bar.FindHighestIndex(range - 1, MODE_HIGH); - result = IsValidIndex(hhIDX); - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - - // - double hhValue = iHigh( - bar.symbol, - bar.period, - hhIDX // - ); - - // - result = hhValue >= selectedValue; - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - - // - result = resistanceBar.IsValid(); - - // - return result; - } - - // - // Order Blocks ... - - /** - * Detect an Order Block Based on Given Bar ... - * - * @param bar: XOHCL instance, Specified Start Bar ... - * @param ob: XOHCL instance, Fill it if Order Block Found ... - * @param dir: ENUM_X_DIRECTION member, Specified Founded Order Block Direction ... - * @param sameBars: Integer, Specified Min Same Bars for Detecting Order Block ... - * - * @return ( bool ) - */ - bool HasOrderBlock( - XOHCL &bar, - XOHCL &ob, - ENUM_X_DIRECTION &dir, - int sameBars = 3 // - ) - { - // - bool result = false; - - // - ob.Clean(); - dir = X_DIRECTION_NONE; - - // - if (sameBars < 1) - { - sameBars = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = 0; - result = HasSameBars( - bar, - dir, - index, - sameBars // - ); - if (!result) - { - return result; - } - - // - int obIndex = index + 1; - result = ob.Init( - bar.symbol, - bar.period, - obIndex // - ); - if (!result) - { - return result; - } - - // - return result; - } - - // - // Fair Value Gaps ... - - /** - * Detect a Fair Value Gap Based on Given Bar ... - * - * @param bar: XOHCL instance, Specified Start Bar ... - * @param dir: ENUM_X_DIRECTION member, Specified Founded Order Block Direction ... - * @param sameBars: Integer, Specified Min Same Bars for Detecting Order Block ... - * - * @return ( bool ) - */ - bool HasFairValueGap( - XOHCL &bar, - XOHCL &prevBar, - XOHCL &nextBar, - ENUM_X_DIRECTION &dir, - int sameBars = 3 // - ) - { - // - bool result = false; - - // - prevBar.Clean(); - nextBar.Clean(); - dir = X_DIRECTION_NONE; - - // - if (sameBars < 1) - { - sameBars = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = 0; - result = HasSameBars( - bar, - dir, - index, - sameBars // - ); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(dir); - - // - int to = bar.Index(); - int from = - index > (to + sameBars) - ? to + sameBars - : index; - for (int i = from; i > to; i--) - { - // - result = prevBar.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - break; - } - - // - result = nextBar.Init( - bar.symbol, - bar.period, - i - 2 // - ); - if (!result) - { - break; - } - - // - result = isBullish - ? prevBar.high < nextBar.low - : prevBar.low > nextBar.high; - if (result) - { - break; - } - } - - // - if (!result) - { - // - prevBar.Clean(); - nextBar.Clean(); - dir = X_DIRECTION_NONE; - } - - // - return result; - } - - // - // Bar CHOCH ... - - /** - * Check Specified Bar Has PullBack or not ... - * - * @param dir: ENUM_X_DIRECTION member, Specified Direction ... - * @param bar: XOHCL instance, Speciied Bar ... - * @param loopback: Integer, loopback Length ... - * @param forceBody: Boolean, Specified Choch Happens only by Bar's Body ... - * - * @return ( bool ) - */ - bool HasPullBack( - ENUM_X_DIRECTION &dir, - XOHCL &bar, - int loopback = 3, - bool forceBody = false // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - if (loopback < 1) - { - loopback = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - // Calculate Loopback Data ... - int index = -1; - int start = -1; - int end = -1; - int count = -1; - result = CalculateLoopBackData( - index, - start, - end, - count, - bar, - loopback // - ); - if (!result) - { - return result; - } - - // - // Calculate Loopback HH and LL Data ... - int hhIDX = -1; - double hh = -1; - int llIDX = -1; - double ll = -1; - result = CalculateLoopbackHLData( - hhIDX, - hh, - llIDX, - ll, - bar, - loopback // - ); - if (!result) - { - return result; - } - - // - bool isBullishDirection = - bar.high > hh && - bar.low > ll; - bool isBearishDirection = - bar.high < hh && - bar.low < ll; - result = isBullishDirection || - isBearishDirection; - if (!result) - { - return result; - } - - // - if (forceBody) - { - // - isBullishDirection = - bar.GetUp() > hh && - bar.GetDown() > ll; - isBearishDirection = - bar.GetUp() < hh && - bar.GetDown() < ll; - result = isBullishDirection || - isBearishDirection; - if (!result) - { - return result; - } - } - - // - // Check Bar's Direction in related to CHOCH Direction ... - result = - isBullishDirection - ? bar.IsBullish() - : bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Set Direction ... - dir = - isBullishDirection - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Check Loopback End Bar ... - XOHCL endBar; - result = endBar.Init( - symbol, - period, - end - 1 // - ); - if (!result) - { - return result; - } - - // - // End Bar Must be InDirect by Specified Bar ... - result = - isBullishDirection - ? endBar.IsBearish() - : endBar.IsBullish(); - - // - // Check Loopback for Directional Bars ... - - // - return result; - } - - // - // Tools ... - - // - bool IsStrong( - XOHCL &bar, - double percent = 50 // Percent of Body - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = - (bar.GetRange() * percent) / 100 <= bar.GetBody(); - - // - return result; - } - - // - bool HasStrongLowShadow( - XOHCL &bar, - double percent = 50, // Percent of Body - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = - (bar.GetRange() * percent) / 100 <= bar.GetLowShadow(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - result = bar.Index() > __loopback; - if (!result) - { - return result; - } - - // - // Get Highest High and Lowest Low in loopback Range ... - int startIndex = bar.Index() - __loopback; - int endIndex = bar.Index() + __loopback; - int requiredBars = MathAbs(endIndex - startIndex); - - // - // Highs ... - double highs[]; - int copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - - // - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - int highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - double highestHigh = highs[highestHighIDX]; - - // - // Lows ... - double lows[]; - int copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - - // - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - int lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - double lowestLow = lows[lowestLowIDX]; - - // - result = bar.low == lowestLow && - highestHigh > bar.high; - if (!result) - { - return result; - } - - // - // Try to Validate Sharp Ratio ... - - // - Clean(highs); - Clean(lows); - - // - // Left Side ... - startIndex = bar.Index() + 1; - endIndex = startIndex + (__loopback / 2) - 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double leftDiff = highestHigh - lowestLow; - - // - Clean(highs); - Clean(lows); - - // - // Right Side ... - startIndex = bar.Index() - 1; - endIndex = startIndex - (__loopback / 2) + 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double rightDiff = highestHigh - lowestLow; - double diff = MathMax(leftDiff, rightDiff); - result = bar.GetLowShadow() >= (diff / 100) * _sharpRatio; - - // - return result; - } - - // - bool HasStrongHighShadow( - XOHCL &bar, - double percent = 50, // Percent of Body - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = - (bar.GetRange() * percent) / 100 <= bar.GetHighShadow(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - result = bar.Index() > __loopback; - if (!result) - { - return result; - } - - // - // Get Highest High and Lowest Low in loopback Range ... - int startIndex = bar.Index() - __loopback; - int endIndex = bar.Index() + __loopback; - int requiredBars = MathAbs(endIndex - startIndex); - - // - // Highs ... - double highs[]; - int copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - - // - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - int highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - double highestHigh = highs[highestHighIDX]; - - // - // Lows ... - double lows[]; - int copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - - // - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - int lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - double lowestLow = lows[lowestLowIDX]; - - // - result = bar.high == highestHigh && - lowestLow < bar.low; - if (!result) - { - return result; - } - - // - // Try to Validate Sharp Ratio ... - - // - Clean(highs); - Clean(lows); - - // - // Left Side ... - startIndex = bar.Index() + 1; - endIndex = startIndex + (__loopback / 2) - 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double leftDiff = highestHigh - lowestLow; - - // - Clean(highs); - Clean(lows); - - // - // Right Side ... - startIndex = bar.Index() - 1; - endIndex = startIndex - (__loopback / 2) + 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double rightDiff = highestHigh - lowestLow; - double diff = MathMax(leftDiff, rightDiff); - result = bar.GetHighShadow() >= (diff / 100) * _sharpRatio; - - // - return result; - } - - // - bool IsStrongBullish( - XOHCL &bar, - double percent = 50 // Percent of Body - ) - { - // - bool result = false; - - // - result = - bar.IsValid() && - bar.IsBullish() && - IsStrong(bar, percent); - - // - return result; - } - - // - bool IsStrongBearish( - XOHCL &bar, - double percent = 50 // Percent of Body - ) - { - // - bool result = false; - - // - result = - bar.IsValid() && - bar.IsBearish() && - IsStrong(bar, percent); - - // - return result; - } - - // - bool IsSharpBullish( - XOHCL &bar, - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - int hIDX = bar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - int lIDX = bar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - result = - // - hIDX >= 0 && - lIDX >= 0 && - MathAbs(hIDX - bar.Index()) < 2 - // - ; - - // - if (!result) - { - return result; - } - - // - XOHCL hBar; - result = hBar.Init( - bar.symbol, - bar.period, - hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL lBar; - result = lBar.Init( - bar.symbol, - bar.period, - lIDX // - ); - if (!result) - { - return result; - } - - // - double lhDif = hBar.high - lBar.low; - - // - int hhIDX = hBar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - - // - int llIDX = lBar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - XOHCL hhBar; - result = hhBar.Init( - bar.symbol, - bar.period, - hhIDX + hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL llBar; - result = llBar.Init( - bar.symbol, - bar.period, - llIDX + lIDX // - ); - if (!result) - { - return result; - } - - // - double llhhDif = hhBar.high - llBar.low; - - // - result = - // - lBar.low > llBar.low && - hBar.high > hhBar.high && - lhDif >= llhhDif * _sharpRatio - // - ; - - // - return result; - } - - // - bool IsSharpBearish( - XOHCL &bar, - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - int hIDX = bar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - int lIDX = bar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - result = - // - hIDX >= 0 && - lIDX >= 0 && - MathAbs(hIDX - bar.Index()) < 2 - // - ; - - // - if (!result) - { - return result; - } - - // - XOHCL hBar; - result = hBar.Init( - bar.symbol, - bar.period, - hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL lBar; - result = lBar.Init( - bar.symbol, - bar.period, - lIDX // - ); - if (!result) - { - return result; - } - - // - double lhDif = hBar.high - lBar.low; - - // - int hhIDX = hBar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - - // - int llIDX = lBar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - XOHCL hhBar; - result = hhBar.Init( - bar.symbol, - bar.period, - hhIDX + hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL llBar; - result = llBar.Init( - bar.symbol, - bar.period, - llIDX + lIDX // - ); - if (!result) - { - return result; - } - - // - double llhhDif = hhBar.high - llBar.low; - - // - result = - // - lBar.low < llBar.low && - hBar.high < hhBar.high && - lhDif >= llhhDif * _sharpRatio - // - ; - - // - return result; - } - - // - // - // - - // - // Retrieve Bullish Pressure ... - double GetBullishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - result += bars[i].GetLowShadow(); - } - - // - return result; - } - - // - // Retrieve Bearish Pressure ... - double GetBearishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - result += bars[i].GetHighShadow(); - } - - // - return result; - } - - // - bool HasBullishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPressure(bar, __loopback); - double bearishPressure = GetBearishPressure(bar, __loopback); - - // - result = - // - bullishPressure > 0 && - bearishPressure >= 0 && - bullishPressure > bearishPressure - // - ; - - // - return result; - } - - // - bool HasBearishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPressure(bar, __loopback); - double bearishPressure = GetBearishPressure(bar, __loopback); - - // - result = - // - bearishPressure > 0 && - bullishPressure >= 0 && - bearishPressure > bullishPressure - // - ; - - // - return result; - } - - // - // Retrieve Bullish Power ... - double GetBullishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - // - if (bars[i].IsBullish()) - { - result += bars[i].GetBody(); - } - } - - // - return result; - } - - // - // Retrieve Bearish Pressure ... - double GetBearishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - // - if (bars[i].IsBearish()) - { - result += bars[i].GetBody(); - } - } - - // - return result; - } - - // - bool HasBullishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPower(bar, __loopback); - double bearishPressure = GetBearishPower(bar, __loopback); - - // - result = - // - bullishPressure > 0 && - bearishPressure >= 0 && - bullishPressure > bearishPressure - // - ; - - // - return result; - } - - // - bool HasBearishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPower(bar, __loopback); - double bearishPressure = GetBearishPower(bar, __loopback); - - // - result = - // - bearishPressure > 0 && - bullishPressure >= 0 && - bearishPressure > bullishPressure - // - ; - - // - return result; - } - - // - // Decisions ... - - // - // Candlestic Patterns ... - - // - // Check Doji ... - bool IsDoji( - XOHCL &bar // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = bar.open == bar.close; - - // - return result; - } - - // - // Check Hammer ... - bool IsHammer( - XOHCL &bar, - double _upShadowFactor = 0.1, - double _downShadowFactor = 0.6, - bool applyFib382Check = true, - bool applyPrevShadowCheck = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_upShadowFactor < 0) - { - _upShadowFactor = 0.1; - } - - // - if (_downShadowFactor < 0) - { - _upShadowFactor = 0.6; - } - - // - double range = bar.GetRange(); - - // - // Check Upper Shadow Must be 0 or Under 10% ... - double upShadow = bar.GetHighShadow(); - result = upShadow < range * _upShadowFactor; - if (!result) - { - return result; - } - - // - // Check Down Shadow Must at least 60% ... - double downShadow = bar.GetLowShadow(); - result = downShadow > range * _downShadowFactor; - if (!result) - { - return result; - } - - // - // Check Fib 382 ... - if (result && applyFib382Check) - { - // - double fib382 = GetFibonacciLevel( - bar.high, - bar.low, - 0.382, - -1 // - ); - result = bar.GetDown() > fib382; - } - - // - // Check Shadow Based on Prev Bar ... - if (result && applyPrevShadowCheck) - { - // - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - result = bar.low < pBar.low; - } - - // - return result; - } - - // - // Check Sgooting Star ... - // Reversal Hammer ... - bool IsShootingStar( - XOHCL &bar, - double _upShadowFactor = 0.6, - double _downShadowFactor = 0.1, - bool applyFib382Check = true, - bool applyPrevShadowCheck = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_upShadowFactor < 0) - { - _upShadowFactor = 0.6; - } - - // - if (_downShadowFactor < 0) - { - _upShadowFactor = 0.1; - } - - // - double range = bar.GetRange(); - - // - // Check Upper Shadow Must be 0 or Under 10% ... - double upShadow = bar.GetHighShadow(); - result = upShadow > range * _upShadowFactor; - if (!result) - { - return result; - } - - // - // Check Down Shadow Must at least 60% ... - double downShadow = bar.GetLowShadow(); - result = downShadow < range * _downShadowFactor; - if (!result) - { - return result; - } - - // - // Check Fib 382 ... - if (result && applyFib382Check) - { - // - double fib382 = GetFibonacciLevel( - bar.high, - bar.low, - 0.382, - 1 // - ); - result = bar.GetUp() < fib382; - } - - // - // Check Shadow Based on Prev Bar ... - if (result && applyPrevShadowCheck) - { - // - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - result = bar.high > pBar.high; - } - - // - return result; - } - - // - // Check Bullish Engulfing ... - bool IsBullishEngulfing( - XOHCL &bar, - double _engulfBarBodyFactor = 0.7 // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_engulfBarBodyFactor < 0) - { - _engulfBarBodyFactor = 0.7; - } - - // - // Check Bar Is Bullish ... - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double body = bar.GetBody(); - - // - // Check Prev Bar Must Bearish ... - result = pBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Check Shadows Engulf Prev Bar ... - result = - // - bar.high > pBar.high && - bar.low <= pBar.low - // - ; - if (!result) - { - return result; - } - - // - // Check Engulfed Bar Must Inside Engulfer Body ... - result = - // - bar.GetUp() > pBar.GetUp() && - bar.GetDown() < pBar.GetDown() - // - ; - if (!result) - { - return result; - } - - // - // Check Body of Engulfing Bar ... - if (result && _engulfBarBodyFactor > 0) - { - result = body >= range * _engulfBarBodyFactor; - } - - // - return result; - } - - // - // Check Bearish Engulfing ... - bool IsBearishEngulfing( - XOHCL &bar, - double _engulfBarBodyFactor = 0.7 // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_engulfBarBodyFactor < 0) - { - _engulfBarBodyFactor = 0.7; - } - - // - // Check Bar Is Bearish ... - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double body = bar.GetBody(); - - // - // Check Prev Bar Must Bullish ... - result = pBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Check Shadows Engulf Prev Bar ... - result = bar.high >= pBar.high && - bar.low < pBar.low; - if (!result) - { - return result; - } - - // - // Check Engulfed Bar Must Inside Engulfer Body ... - result = - // - bar.GetUp() > pBar.GetUp() && - bar.GetDown() < pBar.GetDown() - // - ; - if (!result) - { - return result; - } - - // - // Check Body of Engulfing Bar ... - if (result && _engulfBarBodyFactor > 0) - { - result = body >= range * _engulfBarBodyFactor; - } - - // - return result; - } - - // - // Check Morning Star Pattern ... - bool IsMorningStar( - XOHCL &bar, - double _middleRangeFactor = 0.3, - double _startBodyFactor = 0.6, - bool forceCheckMiddleBarDirection = true, - bool forceCheckStartBody = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_middleRangeFactor < 0) - { - _middleRangeFactor = 0.3; - } - - // - if (_startBodyFactor < 0) - { - _startBodyFactor = 0.6; - } - - // - // Current Bar Must be Bullish ... - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar must be Bearish ... - if (result && forceCheckMiddleBarDirection) - { - // - result = pBar.IsBearish(); - if (!result) - { - return result; - } - } - - // - // Retrieve Previous Bar of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev Of Prev Bar Must be Bearish ... - result = ppBar.IsBearish(); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double pRange = pBar.GetRange(); - double ppRange = ppBar.GetRange(); - - // - // Middle Bar must be Smaller than Ratio of other ... - result = - // - pRange < range * _middleRangeFactor && - pRange < ppRange * _middleRangeFactor - // - ; - if (!result) - { - return result; - } - - // - if (result && forceCheckStartBody) - { - // - result = ppBar.GetBody() > ppRange * _startBodyFactor; - if (!result) - { - return result; - } - } - - // - return result; - } - - // - // Check Evening Star Pattern ... - bool IsEveningStar( - XOHCL &bar, - double _middleRangeFactor = 0.3, - double _startBodyFactor = 0.6, - bool forceCheckMiddleBarDirection = true, - bool forceCheckStartBody = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_middleRangeFactor < 0) - { - _middleRangeFactor = 0.3; - } - - // - if (_startBodyFactor < 0) - { - _startBodyFactor = 0.6; - } - - // - // Current Bar Must be Bearish ... - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar must be Bullish ... - if (result && forceCheckMiddleBarDirection) - { - // - result = pBar.IsBullish(); - if (!result) - { - return result; - } - } - - // - // Retrieve Previous Bar of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev Of Prev Bar Must be Bullish ... - result = ppBar.IsBullish(); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double pRange = pBar.GetRange(); - double ppRange = ppBar.GetRange(); - - // - // Middle Bar must be Smaller than Ratio of other ... - result = - // - pRange < range * _middleRangeFactor && - pRange < ppRange * _middleRangeFactor - // - ; - if (!result) - { - return result; - } - - // - if (result && forceCheckStartBody) - { - // - result = ppBar.GetBody() > ppRange * _startBodyFactor; - if (!result) - { - return result; - } - } - - // - return result; - } - - // - // Bullish Marubozu ... - bool IsBullishMarubozu(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - result = - // - bar.GetUp() == bar.high && - bar.GetDown() == bar.low - // - ; - - // - return result; - } - - // - // Bearish Marubozu ... - bool IsBearishMarubozu(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - result = - // - bar.GetUp() == bar.high && - bar.GetDown() == bar.low - // - ; - - // - return result; - } - - // - // Contextual Patterns ... - - // - // Check Swing High ... - bool IsBarSwingHigh(XOHCL &bar) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bearish ... - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bullish ... - result = pBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bullish ... - result = ppBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Check All Highs ... - result = - // - bar.high < pBar.high && - pBar.high > ppBar.high - // - ; - - // - return result; - } - - // - // Find Simple 3 Candle Based Swing High ... - bool IsSimpleSwingHigh( - XOHCL &bar, - double thresholdInPoint = 1 // - ) - { - // - bool result = false; - - // - int index = bar.Index(); - result = index > 0; - if (!result) - { - return result; - } - - // - XOHCL nextBar; - result = bar.GetNextBar(nextBar); - if (!result) - { - return result; - } - - // - XOHCL prevBar; - result = bar.GetPreviousBar(prevBar); - if (!result) - { - return result; - } - - // - double point = GetPoints(bar.symbol); - double requiredOffset = point * thresholdInPoint; - - // - result = - bar.high > nextBar.high && - bar.high > prevBar.high && - (thresholdInPoint <= 0 - ? true - : MathAbs( - MathMax( - nextBar.high, - prevBar.high) - - bar.high) >= requiredOffset); - - // - return result; - } - - // - // Find Last Swing High ... - bool FindLastSwingHigh( - XOHCL &bar, - XOHCL &swing // - ) - { - // - bool result = false; - - // - swing.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = iBars( - bar.symbol, - bar.period // - ); - int maxAllowed = MathMin(100, (totalBars / 100)); - - // - int idx = bar.Index(); - for (int i = idx; i <= idx + maxAllowed; i++) - { - // - swing.Clean(); - result = swing.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - // - swing.Clean(); - break; - } - - // - result = IsBarSwingHigh(swing); - if (result) - { - break; - } - } - - // - return result; - } - - // - // Check Swing Low ... - bool IsBarSwingLow(XOHCL &bar) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bullish ... - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bearish ... - result = pBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bearish ... - result = ppBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Check All Lows ... - result = - // - bar.low > pBar.low && - pBar.low < ppBar.low - // - ; - - // - return result; - } - - // - // Find Simple 3 Candle Based Swing Low ... - bool IsSimpleSwingLow( - XOHCL &bar, - double thresholdInPoint = 1 // - ) - { - // - bool result = false; - - // - int index = bar.Index(); - result = index > 0; - if (!result) - { - return result; - } - - // - XOHCL nextBar; - result = bar.GetNextBar(nextBar); - if (!result) - { - return result; - } - - // - XOHCL prevBar; - result = bar.GetPreviousBar(prevBar); - if (!result) - { - return result; - } - - // - double point = GetPoints(bar.symbol); - double requiredOffset = point * thresholdInPoint; - - // - result = - bar.low < nextBar.low && - bar.low < prevBar.low && - (thresholdInPoint <= 0 - ? true - : MathAbs( - MathMax( - nextBar.low, - prevBar.low) - - bar.low) >= requiredOffset); - - // - return result; - } - - // - // Find Last Swing Low ... - bool FindLastSwingLow( - XOHCL &bar, - XOHCL &swing // - ) - { - // - bool result = false; - - // - swing.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = iBars( - bar.symbol, - bar.period // - ); - int maxAllowed = MathMin(100, (totalBars / 100)); - - // - int idx = bar.Index(); - for (int i = idx; i <= idx + maxAllowed; i++) - { - // - swing.Clean(); - result = swing.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - // - swing.Clean(); - break; - } - - // - result = IsBarSwingLow(swing); - if (result) - { - break; - } - } - - // - return result; - } - - // - // Check Bullish FVG ... - bool HasBullishFVG( - XOHCL &bar, - double &upper, - double &lower, - datetime &start, - datetime &end, - bool forceMiddleBarCheck = true, - bool forceCheckLastBarDirection = false // - ) - { - // - bool result = false; - - // - upper = 0; - lower = 0; - - // - end = NULL; - start = NULL; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bullish ... - result = - !forceCheckLastBarDirection - ? true - : bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bullish ... - result = pBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bullish ... - result = ppBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Other Conditions ... - result = - // - bar.low > ppBar.high - // - ; - - // - // Check Middle Bar Range ... - if (result && forceMiddleBarCheck) - { - // - result = - // - pBar.high > bar.low && - pBar.low < ppBar.high - // - ; - - // - if (!result) - { - return result; - } - } - - // - if (result) - { - // - end = bar.time; - upper = bar.low; - lower = ppBar.high; - start = ppBar.time; - } - - // - return result; - } - - // - // Check Bearish FVG ... - bool HasBearishFVG( - XOHCL &bar, - double &upper, - double &lower, - datetime &start, - datetime &end, - bool forceMiddleBarCheck = true, - bool forceCheckLastBarDirection = false // - ) - { - // - bool result = false; - - // - upper = 0; - lower = 0; - - // - end = NULL; - start = NULL; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bearish ... - result = - !forceCheckLastBarDirection - ? true - : bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bearish ... - result = pBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bearish ... - result = ppBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Other Conditions ... - result = - // - bar.high < ppBar.low - // - ; - - // - // Check Middle Bar Range ... - if (result && forceMiddleBarCheck) - { - // - result = - // - pBar.high > bar.low && - pBar.low < ppBar.high - // - ; - - // - if (!result) - { - return result; - } - } - - // - if (result) - { - // - end = bar.time; - lower = bar.high; - upper = ppBar.low; - start = ppBar.time; - } - - // - return result; - } - - // - // Find Support ... - bool HasSupport( - XOHCL &bar, - XOHCL &dest, - ENUM_X_PRICE type = X_PRICE_CLOSE, - int _loopback = 21, - int tries = 100 // - ) - { - // - bool result = false; - - // - dest.Clean(); - - // - if (_loopback < 0) - { - _loopback = 21; - } - - // - if (tries < 0) - { - tries = 100; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - for (int i = 1; i < tries; i++) - { - // - int _length = _loopback * i; - - // - int lowestIDX = bar.FindLowestIndex( - _length, - MODE_LOW // - ); - result = IsValidIndex(lowestIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - lowestIDX // - ); - if (!result) - { - break; - } - - // - result = - // - price > iLBar.high - // - ; - if (result) - { - // - dest = iLBar; - break; - } - } - - // - result = dest.IsValid(); - - // - return result; - } - - // - // Find Resistance ... - bool HasResistance( - XOHCL &bar, - XOHCL &dest, - ENUM_X_PRICE type = X_PRICE_CLOSE, - int _loopback = 21, - int tries = 100 // - ) - { - // - bool result = false; - - // - dest.Clean(); - - // - if (_loopback < 0) - { - _loopback = 21; - } - - // - if (tries < 0) - { - tries = 100; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - for (int i = 1; i < tries; i++) - { - // - int _length = _loopback * i; - - // - int highestIDX = bar.FindHighestIndex( - _length, - MODE_LOW // - ); - result = IsValidIndex(highestIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - highestIDX // - ); - if (!result) - { - break; - } - - // - result = - // - price < iHBar.high - // - ; - if (result) - { - // - dest = iHBar; - break; - } - } - - // - result = dest.IsValid(); - - // - return result; - } - - // - // Trend Detection ... - - // - // Find Bullish Trend ... - bool HasBullishTrend( - XOHCL &bar, - XOHCL &highSwingBars[], - XOHCL &lowSwingBars[], - bool forceMethod2 = false, - int _loopback = 3, - int tries = 3, - ENUM_X_PRICE type = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - Clean(lowSwingBars); - Clean(highSwingBars); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - int lastIDX = bar.Index(); - double lastH = 0; - double lastL = 0; - for (int i = 1; i < tries + 1; i++) - { - // - // Use Regular Method ... - if (!forceMethod2) - { - // - int iHIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_HIGH, - _loopback, - lastIDX // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH < lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_LOW, - _loopback, - lastIDX // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL < lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - // - // Use Other MEthod ... - else - { - // - int _length = i * _loopback; - int start = - // - i == 1 - ? 1 - : _length - _loopback - // - ; - - // - int iHIDX = iHighest( - bar.symbol, - bar.period, - MODE_HIGH, - _loopback, - start // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH < lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = iLowest( - bar.symbol, - bar.period, - MODE_LOW, - _loopback, - start // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL < lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - } - - // - if (result) - { - // - result = - // - ArraySize(lowSwingBars) == tries && - ArraySize(highSwingBars) == tries - // - ; - } - - // - if (!result) - { - // - Clean(lowSwingBars); - Clean(highSwingBars); - } - - // - return result; - } - - // - // Find Bearish Trend ... - bool HasBearishTrend( - XOHCL &bar, - XOHCL &highSwingBars[], - XOHCL &lowSwingBars[], - bool forceMethod2 = false, - int _loopback = 3, - int tries = 3, - ENUM_X_PRICE type = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - Clean(lowSwingBars); - Clean(highSwingBars); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - int lastIDX = bar.Index(); - double lastH = 0; - double lastL = 0; - for (int i = 1; i < tries + 1; i++) - { - // - // Use Regular Method ... - if (!forceMethod2) - { - // - int iHIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_HIGH, - _loopback, - lastIDX // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH > lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_LOW, - _loopback, - lastIDX // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL > lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - // - // Use Other MEthod ... - else - { - // - int _length = i * _loopback; - int start = - // - i == 1 - ? 1 - : _length - _loopback - // - ; - - // - int iHIDX = iHighest( - bar.symbol, - bar.period, - MODE_HIGH, - _loopback, - start // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH > lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = iLowest( - bar.symbol, - bar.period, - MODE_LOW, - _loopback, - start // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL > lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - } - - // - if (result) - { - // - result = - // - ArraySize(lowSwingBars) == tries && - ArraySize(highSwingBars) == tries - // - ; - } - - // - if (!result) - { - // - Clean(lowSwingBars); - Clean(highSwingBars); - } - - // - return result; - } - - // - // Order Blocks ... - - // - // Find Bullish Order Block ... - bool HasBullishOrderBlock( - XOHCL &bar, - XOHCL &orderBlock, - int _minimumSameBars = 4 // - ) - { - // - bool result = false; - - // - orderBlock.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (_minimumSameBars < 0) - { - _minimumSameBars = 4; - } - - // - XOHCL cBar; - int founded = 0; - int cIDX = bar.Index(); - bool isEnough = false; - while (!isEnough) - { - // - result = cBar.Init( - bar.symbol, - bar.period, - cIDX // - ); - if (!result) - { - break; - } - - // - result = cBar.IsBullish(); - if (!result && cBar.IsBearish()) - { - break; - } - - // - cIDX++; - founded++; - } - - // - // Here we have to check founded and if it's fill - // our requirements ... - // cIDX is Order Block Index ... - result = - // - cBar.IsValid() && - bar.high > cBar.high && - founded >= _minimumSameBars - // - ; - if (!result) - { - return result; - } - - // - result = orderBlock.Init( - bar.symbol, - bar.period, - cIDX // - ); - if (!result) - { - // - orderBlock.Clean(); - return result; - } - - // - return result; - } - - // - // Find Bearish Order Block ... - bool HasBearishOrderBlock( - XOHCL &bar, - XOHCL &orderBlock, - int _minimumSameBars = 4 // - ) - { - // - bool result = false; - - // - orderBlock.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (_minimumSameBars < 0) - { - _minimumSameBars = 4; - } - - // - XOHCL cBar; - int founded = 0; - int cIDX = bar.Index(); - bool isEnough = false; - while (!isEnough) - { - // - bool isInited = cBar.Init( - bar.symbol, - bar.period, - cIDX // - ); - - // - result = cBar.IsBearish(); - if (!result && cBar.IsBullish()) - { - break; - } - - // - cIDX++; - founded++; - } - - // - // Here we have to check founded and if it's fill - // our requirements ... - // cIDX is Order Block Index ... - result = - // - cBar.IsValid() && - bar.high < cBar.low && - founded >= _minimumSameBars - // - ; - if (!result) - { - return result; - } - - // - result = orderBlock.Init( - bar.symbol, - bar.period, - cIDX // - ); - if (!result) - { - // - orderBlock.Clean(); - return result; - } - - // - return result; - } diff --git a/Documents/BKP/tmp.drawer.mq5 b/Documents/BKP/tmp.drawer.mq5 deleted file mode 100644 index 0d035cd5..00000000 --- a/Documents/BKP/tmp.drawer.mq5 +++ /dev/null @@ -1,520 +0,0 @@ - - // - int DrawOrderBlock( - XCOrderBlock *zone, - XCBaseObject *&objects[], - // - bool drawStartedBar = true, - bool drawActivatedBar = true, - bool drawBreakedBar = true, - bool drawWorkedBar = true, - // - int widthStartedBar = 1, - color clrStartedBar = clrYellow, - ENUM_LINE_STYLE styleStartedBar = STYLE_SOLID, - // - int widthActivatedBar = 1, - color clrActivatedBar = clrLime, - ENUM_LINE_STYLE styleActivatedBar = STYLE_SOLID, - // - int widthBreakedBar = 1, - color clrBreakedBar = clrRed, - ENUM_LINE_STYLE styleBreakedBar = STYLE_SOLID, - // - int widthWorkedBar = 1, - color clrWorkedBar = clrAqua, - ENUM_LINE_STYLE styleWorkedBar = STYLE_SOLID - // - ) - { - // - int result = 0; - - // - Clean(objects); - - // - if (zone == NULL || - !zone.IsValid()) - { - return result; - } - - // - ENUM_X_DIRECTION zoneDir = zone.GetDirection(); - - // - // Started Bar ... - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone - .IsStarted( - zoneDir, - startedBar, - isBodyOut // - ); - if (isStarted) - { - // - datetime iBarTo = startedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - startedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthStartedBar); - iBarObj.LowShadowWidth(widthStartedBar); - iBarObj.HighShadowWidth(widthStartedBar); - - // - iBarObj.BodyStyle(styleStartedBar); - iBarObj.LowShadowStyle(styleStartedBar); - iBarObj.HighShadowStyle(styleStartedBar); - - // - iBarObj.BodyColor(clrStartedBar); - iBarObj.LowShadowColor(clrStartedBar); - iBarObj.HighShadowColor(clrStartedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Activated Bar ... - XOHCL activatedBar; - bool isBodyIn = false; - bool isActivated = zone - .IsActivated( - zoneDir, - activatedBar, - isBodyIn, - false // Force Body Out Started ... - ); - if (isActivated) - { - // - datetime iBarTo = activatedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - activatedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthActivatedBar); - iBarObj.LowShadowWidth(widthActivatedBar); - iBarObj.HighShadowWidth(widthActivatedBar); - - // - iBarObj.BodyStyle(styleActivatedBar); - iBarObj.LowShadowStyle(styleActivatedBar); - iBarObj.HighShadowStyle(styleActivatedBar); - - // - iBarObj.BodyColor(clrActivatedBar); - iBarObj.LowShadowColor(clrActivatedBar); - iBarObj.HighShadowColor(clrActivatedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Breaked Bar ... - XOHCL breakedBar; - isBodyOut = false; - bool isBreaked = zone - .IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, // Ignore Start ... - false // Force Body Out Started ... - ); - if (isBreaked) - { - // - datetime iBarTo = breakedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - breakedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthBreakedBar); - iBarObj.LowShadowWidth(widthBreakedBar); - iBarObj.HighShadowWidth(widthBreakedBar); - - // - iBarObj.BodyStyle(styleBreakedBar); - iBarObj.LowShadowStyle(styleBreakedBar); - iBarObj.HighShadowStyle(styleBreakedBar); - - // - iBarObj.BodyColor(clrBreakedBar); - iBarObj.LowShadowColor(clrBreakedBar); - iBarObj.HighShadowColor(clrBreakedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Worked Bar ... - XOHCL workedBar; - isBodyOut = false; - bool isWorked = zone - .IsWorked( - zoneDir, - workedBar, - isBodyOut, - false, // Ignore Activation ... - false, // Force Body Out Started ... - false // Force Body In Activated ... - ); - if (isWorked) - { - // - datetime iBarTo = workedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - workedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthWorkedBar); - iBarObj.LowShadowWidth(widthWorkedBar); - iBarObj.HighShadowWidth(widthWorkedBar); - - // - iBarObj.BodyStyle(styleWorkedBar); - iBarObj.LowShadowStyle(styleWorkedBar); - iBarObj.HighShadowStyle(styleWorkedBar); - - // - iBarObj.BodyColor(clrWorkedBar); - iBarObj.LowShadowColor(clrWorkedBar); - iBarObj.HighShadowColor(clrWorkedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - XCBaseObject *iObj; - bool isCreated = CreateOrderBlock( - zone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } - - // - result = ArraySize(objects); - - // - return result; - } - - // - int DrawFairValueGap( - XCFVG *zone, - XCBaseObject *&objects[], - // - bool drawStartedBar = true, - bool drawActivatedBar = true, - bool drawBreakedBar = true, - bool drawWorkedBar = true, - // - int widthStartedBar = 1, - color clrStartedBar = clrYellow, - ENUM_LINE_STYLE styleStartedBar = STYLE_SOLID, - // - int widthActivatedBar = 1, - color clrActivatedBar = clrLime, - ENUM_LINE_STYLE styleActivatedBar = STYLE_SOLID, - // - int widthBreakedBar = 1, - color clrBreakedBar = clrRed, - ENUM_LINE_STYLE styleBreakedBar = STYLE_SOLID, - // - int widthWorkedBar = 1, - color clrWorkedBar = clrAqua, - ENUM_LINE_STYLE styleWorkedBar = STYLE_SOLID - // - ) - { - // - int result = 0; - - // - Clean(objects); - - // - if (zone == NULL || - !zone.IsValid()) - { - return result; - } - - // - ENUM_X_DIRECTION zoneDir = zone.GetDirection(); - - // - // Started Bar ... - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone - .IsStarted( - zoneDir, - startedBar, - isBodyOut // - ); - if (isStarted) - { - // - datetime iBarTo = startedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - startedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthStartedBar); - iBarObj.LowShadowWidth(widthStartedBar); - iBarObj.HighShadowWidth(widthStartedBar); - - // - iBarObj.BodyStyle(styleStartedBar); - iBarObj.LowShadowStyle(styleStartedBar); - iBarObj.HighShadowStyle(styleStartedBar); - - // - iBarObj.BodyColor(clrStartedBar); - iBarObj.LowShadowColor(clrStartedBar); - iBarObj.HighShadowColor(clrStartedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Activated Bar ... - XOHCL activatedBar; - bool isBodyIn = false; - bool isActivated = zone - .IsActivated( - zoneDir, - activatedBar, - isBodyIn, - false // Force Body Out Started ... - ); - if (isActivated) - { - // - datetime iBarTo = activatedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - activatedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthActivatedBar); - iBarObj.LowShadowWidth(widthActivatedBar); - iBarObj.HighShadowWidth(widthActivatedBar); - - // - iBarObj.BodyStyle(styleActivatedBar); - iBarObj.LowShadowStyle(styleActivatedBar); - iBarObj.HighShadowStyle(styleActivatedBar); - - // - iBarObj.BodyColor(clrActivatedBar); - iBarObj.LowShadowColor(clrActivatedBar); - iBarObj.HighShadowColor(clrActivatedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Breaked Bar ... - XOHCL breakedBar; - isBodyOut = false; - bool isBreaked = zone - .IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, // Ignore Start ... - false // Force Body Out Started ... - ); - if (isBreaked) - { - // - datetime iBarTo = breakedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - breakedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthBreakedBar); - iBarObj.LowShadowWidth(widthBreakedBar); - iBarObj.HighShadowWidth(widthBreakedBar); - - // - iBarObj.BodyStyle(styleBreakedBar); - iBarObj.LowShadowStyle(styleBreakedBar); - iBarObj.HighShadowStyle(styleBreakedBar); - - // - iBarObj.BodyColor(clrBreakedBar); - iBarObj.LowShadowColor(clrBreakedBar); - iBarObj.HighShadowColor(clrBreakedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Worked Bar ... - XOHCL workedBar; - isBodyOut = false; - bool isWorked = zone - .IsWorked( - zoneDir, - workedBar, - isBodyOut, - false, // Ignore Activation ... - false, // Force Body Out Started ... - false // Force Body In Activated ... - ); - if (isWorked) - { - // - datetime iBarTo = workedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - workedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthWorkedBar); - iBarObj.LowShadowWidth(widthWorkedBar); - iBarObj.HighShadowWidth(widthWorkedBar); - - // - iBarObj.BodyStyle(styleWorkedBar); - iBarObj.LowShadowStyle(styleWorkedBar); - iBarObj.HighShadowStyle(styleWorkedBar); - - // - iBarObj.BodyColor(clrWorkedBar); - iBarObj.LowShadowColor(clrWorkedBar); - iBarObj.HighShadowColor(clrWorkedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - XCBaseObject *iObj; - bool isCreated = CreateFairValueGap( - zone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } - - // - result = ArraySize(objects); - - // - return result; - } diff --git a/Documents/BKP/workingZone.zone.box.mq5 b/Documents/BKP/workingZone.zone.box.mq5 deleted file mode 100644 index 3b5d3ae8..00000000 --- a/Documents/BKP/workingZone.zone.box.mq5 +++ /dev/null @@ -1,3099 +0,0 @@ -// -bool IsZoneActivated( - int &zoneIDX, - int &fvgIDX, - ENUM_X_DIRECTION &dir, - ENUM_X121SMC_XWZ_PROVIDERS &signalProvider, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - fvgIDX = -1; - zoneIDX = -1; - dir = X_DIRECTION_NONE; - signalProvider = X121SMC_XWZ_PROVIDER_NONE; - - // - // Normalize Bar Index ... - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex = 1; - } - - // - // Validate ... - result = IsValid() && - HasWaitingZones(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - - // - return result; - } - - // - double peak = provider.decisionXConditions.peaksBuffer[1]; - double vale = provider.decisionXConditions.valesBuffer[1]; - - // - double analysePeak = provider.analyseXConditions.peaksBuffer[1]; - double analyseVale = provider.analyseXConditions.valesBuffer[1]; - - // - double consolidationPeak = provider.consolidationXConditions.peaksBuffer[1]; - double consolidationVale = provider.consolidationXConditions.valesBuffer[1]; - - // - double visionPeak = provider.visionXConditions.peaksBuffer[1]; - double visionVale = provider.visionXConditions.valesBuffer[1]; - - // - bool isPeaksSame = - peak == analysePeak && - analysePeak == consolidationPeak; - - // - bool isValesSame = - vale == analyseVale && - analyseVale == consolidationVale; - - // - // - // - - // - bool isDecisionScoreBullish = - provider.decisionBullishScore > provider.decisionBearishScore; - - // - bool isDecisionScoreBearish = - provider.decisionBearishScore > provider.decisionBullishScore; - - // - bool isAnalyseScoreBullish = - provider.analyseBullishScore > provider.analyseBearishScore; - - // - bool isAnalyseScoreBearish = - provider.analyseBearishScore > provider.analyseBullishScore; - - // - bool isConsolidationScoreBullish = - provider.consolidationBullishScore > provider.consolidationBearishScore; - - // - bool isConsolidationScoreBearish = - provider.consolidationBearishScore > provider.consolidationBullishScore; - - // - bool isVisionScoreBullish = - provider.visionBullishScore > provider.visionBearishScore; - - // - bool isVisionScoreBearish = - provider.visionBearishScore > provider.visionBullishScore; - - // - int count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = waitingZones[i]; - - // - ENUM_X_DIRECTION iDir = iOBFVG.GetDirection(); - bool isBullish = iOBFVG.IsBullish(); - - // - int fvgsCount = iOBFVG.CountFVGs(); - bool has = IsValidSize(fvgsCount); - if (has) - { - // - for (int j = 0; j < fvgsCount; j++) - { - // - XCFVG *jFVG = iOBFVG.fvgs[j]; - - // - XBoxZone iBox; - has = ToBox( - iBox, - jFVG // - ); - if (has) - { - // - double iRange = iBox.lower + ((iBox.upper - iBox.lower) / 2); - - // - // Activate Zone Using PV ... - bool isPVPassed = - isBullish - ? vale <= iBox.upper && - vale >= iBox.lower - : peak <= iBox.upper && - peak >= iBox.lower; - bool isPV50Passed = - isBullish - ? vale < iBox.upper && - vale <= iRange && - vale > iBox.lower - : peak < iBox.upper && - peak >= iRange && - peak > iBox.lower; - - // - // Activate Zone using Rejection ... - bool isRejected = - isBullish - ? bar.low <= iBox.upper && - bar.GetDown() > iBox.upper - : bar.high >= iBox.lower && - bar.GetUp() < iBox.lower; - - // - // Combine Result ... - // result = isPVPassed; - // || isPVPassed - // || isPV50Passed - // || isRejected; - - // - result = isPVPassed; - - if (result) - { - // - fvgIDX = j; - iBox.Clean(); - zoneIDX = i; - - // - break; - } - } - - // - if (result) - { - // - iBox.Clean(); - ZeroMemory(jFVG); - - // - break; - } - - // - iBox.Clean(); - } - } - - // - if (result) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG.Clean(); - } - - // - result = - IsValidIndex(fvgIDX) && - IsValidIndex(zoneIDX); - - // - bar.Clean(); - - // - if (result) - { - bar.Clean(); - } - - // - return result; -} - -// -bool IsBoxActivated( - XBoxZone &box, - ENUM_X_DIRECTION &dir, - ENUM_X121SMC_XWZ_PROVIDERS &signalProvider, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - box.Clean(); - dir = X_DIRECTION_NONE; - signalProvider = X121SMC_XWZ_PROVIDER_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasWaitingBoxes(); - if (!result) - { - return result; - } - - // - XOHCL bar; - XOHCL cBar; - XOHCL pBar; - result = bar.Init( - symbol, - period, - barIndex // - ); - result = - result && - bar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - bar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - // Retrieve Some Required Data ... - - // - double peakZ = provider.decisionXConditions.peaksBuffer[0]; - double valeZ = provider.decisionXConditions.valesBuffer[0]; - double peak = provider.decisionXConditions.peaksBuffer[1]; - double vale = provider.decisionXConditions.valesBuffer[1]; - - // - double analysePeak = provider.analyseXConditions.peaksBuffer[1]; - double analyseVale = provider.analyseXConditions.valesBuffer[1]; - - // - double consolidationPeak = provider.consolidationXConditions.peaksBuffer[1]; - double consolidationVale = provider.consolidationXConditions.valesBuffer[1]; - - // - double visionPeak = provider.visionXConditions.peaksBuffer[1]; - double visionVale = provider.visionXConditions.valesBuffer[1]; - - // - bool isPeaksSame = - peak == analysePeak && - analysePeak == consolidationPeak; - - // - bool isValesSame = - vale == analyseVale && - analyseVale == consolidationVale; - - // - // Calculate Scores Conditions ... - - // - bool isDecisionScoreBullish = - provider.decisionBullishScore > provider.decisionBearishScore; - - // - bool isDecisionScoreBearish = - provider.decisionBearishScore > provider.decisionBullishScore; - - // - bool isAnalyseScoreBullish = - provider.analyseBullishScore > provider.analyseBearishScore; - - // - bool isAnalyseScoreBearish = - provider.analyseBearishScore > provider.analyseBullishScore; - - // - bool isConsolidationScoreBullish = - provider.consolidationBullishScore > provider.consolidationBearishScore; - - // - bool isConsolidationScoreBearish = - provider.consolidationBearishScore > provider.consolidationBullishScore; - - // - bool isVisionScoreBullish = - provider.visionBullishScore > provider.visionBearishScore; - - // - bool isVisionScoreBearish = - provider.visionBearishScore > provider.visionBullishScore; - - // - bool isScoreBullish = - isVisionScoreBullish && - isAnalyseScoreBullish && - isConsolidationScoreBullish; - - // - bool isScoreBearish = - isVisionScoreBearish && - isAnalyseScoreBearish && - isConsolidationScoreBearish; - - // - // Waiting Boxes ... - int count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - bool isBullish = iBox.IsBullish(); - - // - // Check Score ... - - // - bool isScorePassed = - isBullish - ? isScoreBullish - : isScoreBearish; - - // - // Check Bar Insides ... - - // - bool isPBarInside = - (pBar.high <= iBox.upper && - pBar.low >= iBox.lower) || - (isBullish - ? pBar.low < iBox.upper && - pBar.GetDown() < iBox.upper - : pBar.high > iBox.lower && - pBar.GetUp() > iBox.lower); - - // - bool isCBarInside = - (cBar.high <= iBox.upper && - cBar.low >= iBox.lower) || - (isBullish - ? cBar.low < iBox.upper && - cBar.GetDown() < iBox.upper - : cBar.high > iBox.lower && - cBar.GetUp() > iBox.lower); - - // - // Checking Rejection ... - - // - // Bullish ... - bool isBullishRejected = - isBullish && - cBar.low <= iBox.upper && - cBar.GetDown() > iBox.upper; - - // - // Bearish ... - bool isBearishRejected = - !isBullish && - cBar.high >= iBox.lower && - cBar.GetUp() < iBox.lower; - - // - // Check Breaktion ... - - // - // Bullish ... - bool isBullishBreaked = - isBullish && - cBar.high > iBox.upper && - cBar.GetUp() > iBox.upper && - cBar.low >= iBox.lower; - - // - // Bearish ... - bool isBearishBreaked = - !isBullish && - cBar.low < iBox.lower && - cBar.GetDown() < iBox.lower && - cBar.high <= iBox.upper; - - // - // Checking PV Pass ... - - // - bool isBullishPVPassed = - isBullish && - vale == valeZ && - vale > iBox.lower && - vale < iBox.upper; - - // - bool isBearishPVPassed = - !isBullish && - peak == peakZ && - peak > iBox.lower && - peak < iBox.upper; - - // - // Summarise ... - - // - // Rejection ... - bool isRejected = isBullishRejected || - isBearishRejected; - - // - // Breaktion ... - bool isBreaked = - isPBarInside && - (isBullishBreaked || - isBearishBreaked); - - // - bool isPVPassed = - (isBullishPVPassed || - isBearishPVPassed); - - // - // Trend Conditions ... - - // - bool isX3MABullish = - provider.decisionXConditions.isX3MaFastOverMid && - provider.decisionXConditions.x3maMidBuffer[1] > provider.decisionXConditions.x3maSlowBuffer[1]; - - // - bool isX3MABearish = - provider.decisionXConditions.isX3MaFastUnderMid && - provider.decisionXConditions.x3maMidBuffer[1] < provider.decisionXConditions.x3maSlowBuffer[1]; - - // - bool isVWapBullish = - provider.decisionXConditions.isVWapFastOverMid && - provider.decisionXConditions.vwapMidBuffer[1] > provider.decisionXConditions.vwapSlowBuffer[1]; - - // - bool isVWapBearish = - provider.decisionXConditions.isX3MaFastUnderMid && - provider.decisionXConditions.vwapMidBuffer[1] < provider.decisionXConditions.vwapSlowBuffer[1]; - - // - bool isTrendBullish = - isX3MABullish && - isVWapBullish; - - // - bool isTrendBearish = - isX3MABearish && - isVWapBearish; - - // - bool isTrendPassed = - isBullish - ? isTrendBullish - : isTrendBearish; - - // - // Summarize Conditions ... - - // - result = - // - // isBreaked || - // isRejected || - isPVPassed && - isRejected && - isTrendPassed && - isScorePassed - // - ; - - // - if (result) - { - // - box = iBox; - dir = iBox.dir; - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - - // - iBox.Clean(); - break; - } - - // - iBox.Clean(); - - // - } - - // - // MA Trends ... - if (!result) - { - // - result = provider.analyseState.HasOrderBlocks(); - if (result) - { - // - // - // Trend Conditions ... - - // - bool isX3MABullish = - provider.decisionXConditions.isX3MaFastCrossedOverMid; - - // - bool isX3MABearish = - provider.decisionXConditions.isX3MaFastCrossedUnderMid; - - // - bool isVWapBullish = - provider.decisionXConditions.isVWapFastCrossedOverMid; - - // - bool isVWapBearish = - provider.decisionXConditions.isVWapFastCrossedUnderMid; - - // - // - // - - // - bool isTrendBullish = - (isX3MABullish || - isVWapBullish) && - provider.decisionXConditions.isNewPeakOverLast; - - // - bool isTrendBearish = - (isX3MABearish || - isVWapBearish) && - provider.decisionXConditions.isNewValeUnderLast; - - // - result = isTrendBullish || - isTrendBearish; - if (result) - { - // - // Select Signal Box ... - - // - bool isScorePassed = - isTrendBullish - ? isScoreBullish - : isScoreBearish; - - // - XBoxZone tmpBoxes[]; - ToBox( - provider.analyseState.orderBlocks, - tmpBoxes // - ); - Copy( - waitingBoxes, - tmpBoxes, - false // - ); - int idx = -1; - // bool has = false; - while (HasChild(tmpBoxes)) - { - // - if (isTrendBullish) - { - idx = GetHighest(tmpBoxes); - } - else - { - idx = GetLowest(tmpBoxes); - } - - // - result = IsValidIndex(idx); - if (!result) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - - // - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - int insideIDX = -1; - bool hasInsideBox = HasInsideBox( - insideIDX, - iBox, - tmpBoxes // - ); - if (hasInsideBox) - { - // - hasInsideBox = - isTrendBullish - ? iBox.lower < tmpBoxes[insideIDX].lower - : iBox.upper > tmpBoxes[insideIDX].upper; - } - - // - bool isBullishPlacePassed = - // !hasInsideBox && - isTrendBullish && - iBox.IsBullish() && - bar.low >= iBox.upper && - cBar.low >= iBox.upper && - provider.decisionXConditions.x3maMin >= iBox.lower && - provider.decisionXConditions.vwapMin >= iBox.lower; - - // - bool isBearishPlacePassed = - // !hasInsideBox && - isTrendBearish && - iBox.IsBearish() && - bar.high <= iBox.lower && - cBar.high <= iBox.lower && - provider.decisionXConditions.x3maMax <= iBox.upper && - provider.decisionXConditions.vwapMax <= iBox.upper; - - // - result = isScorePassed && - (isBullishPlacePassed || - isBearishPlacePassed); - if (result) - { - // - box = iBox; - iBox.Clean(); - dir = - isTrendBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_MA; - break; - } - - // - } - Clean(tmpBoxes); - } - } - } - - // - // Supply and Demand ... - if (false && !result) - { - // - int idx = -1; - bool has = false; - XBoxZone tmpBoxes[]; - - // - // Detecting Youngest Zones ... - - // - XBoxZone bullishBox; - bool hasBullishBox = false; - if (!hasBullishBox) - { - // - XCOrderBlock *ob = NULL; - idx = GetYoungest(provider.analyseState.bullishOrderBlocks); - has = IsValidIndex(idx); - if (has) - { - // - ob = provider.analyseState.bullishOrderBlocks[idx]; - - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = ob.IsStarted( - ob.GetDirection(), - startedBar, - isBodyOut // - ); - has = isStarted && - isBodyOut; - if (has) - { - // - hasBullishBox = ToBox( - bullishBox, - ob // - ); - } - } - - // - if (!hasBullishBox) - { - bullishBox.Clean(); - } - - // - ZeroMemory(ob); - } - - // - XBoxZone bearishBox; - bool hasBearishBox = false; - if (!hasBearishBox) - { - // - XCOrderBlock *ob = NULL; - idx = GetYoungest(provider.analyseState.bearishOrderBlocks); - has = IsValidIndex(idx); - if (has) - { - // - ob = provider.analyseState.bearishOrderBlocks[idx]; - - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = ob.IsStarted( - ob.GetDirection(), - startedBar, - isBodyOut // - ); - has = isStarted && - isBodyOut; - if (has) - { - // - hasBearishBox = ToBox( - bearishBox, - ob // - ); - } - } - - // - if (!hasBearishBox) - { - bearishBox.Clean(); - } - - // - ZeroMemory(ob); - } - - // - XBoxZone bullishCZBox; - bool hasBullishConsolidationZone = false; - XConsolidationZone bullishConsolidationZone; - hasBullishConsolidationZone = provider.decisionState.HasBullishConsolidationZones(); - if (hasBullishConsolidationZone) - { - // - idx = GetYoungest(provider.decisionState.bullishConsolidationZones); - hasBullishConsolidationZone = IsValidIndex(idx); - if (hasBullishConsolidationZone) - { - // - bullishConsolidationZone = provider.decisionState.bullishConsolidationZones[idx]; - if (hasBullishConsolidationZone) - { - // - hasBullishConsolidationZone = ToBox( - bullishCZBox, - bullishConsolidationZone // - ); - } - } - } - - // - XBoxZone bearishCZBox; - bool hasBearishConsolidationZone = false; - XConsolidationZone bearishConsolidationZone; - hasBearishConsolidationZone = provider.decisionState.HasBearishConsolidationZones(); - if (hasBearishConsolidationZone) - { - // - idx = GetYoungest(provider.decisionState.bearishConsolidationZones); - hasBearishConsolidationZone = IsValidIndex(idx); - if (hasBearishConsolidationZone) - { - // - bearishConsolidationZone = provider.decisionState.bearishConsolidationZones[idx]; - if (hasBearishConsolidationZone) - { - // - hasBearishConsolidationZone = ToBox( - bearishCZBox, - bearishConsolidationZone // - ); - } - } - } - - // - // - // - - // - // Supply Zone ... - has = provider.visionState.HasSupplyZones(); - if (has) - { - // - ToBox( - provider.visionState.supplyZones, - tmpBoxes // - ); - - // - while (HasChild(tmpBoxes)) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - // Price Must Be Inside a Zonne More Than 5 Bar ... - bool isPriceInside = - // - bar.high < iBox.upper && - bar.low > iBox.lower && - // - cBar.high < iBox.upper && - cBar.low > iBox.lower && - // - pBar.high < iBox.upper && - pBar.low > iBox.lower - // - ; - - // - bool isBearishBoxPassed = - hasBearishBox && - IsBoxInside( - bearishBox, - iBox // - ); - - // - bool isBearishCZBoxPassed = - hasBearishConsolidationZone && - IsBoxInside( - bearishCZBox, - iBox // - ); - - // - result = isPriceInside && - (isBearishBoxPassed || - isBearishCZBoxPassed); - if (result) - { - // - if (isBearishBoxPassed) - { - box = bearishBox; - } - else - { - box = bearishCZBox; - } - - // - iBox.to = TimeCurrent(); - XCBoxObject *iObj; - provider.visionCycleHelper.mPOIDrawer.DrawBox( - iBox, - iObj // - ); - - // - dir = X_DIRECTION_BEARISH; - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_AREA; - - // - iBox.Clean(); - - // - break; - } - - // - iBox.Clean(); - } - - // - Clean(tmpBoxes); - } - - // - // Demand Zone ... - has = provider.visionState.HasDemandZones(); - if (!result && has) - { - // - ToBox( - provider.visionState.demandZones, - tmpBoxes // - ); - - // - while (HasChild(tmpBoxes)) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - // Price Must Be Inside a Zonne More Than 5 Bar ... - bool isPriceInside = - // - bar.high < iBox.upper && - bar.low > iBox.lower && - // - cBar.high < iBox.upper && - cBar.low > iBox.lower && - // - pBar.high < iBox.upper && - pBar.low > iBox.lower - // - ; - - // - bool isBullishBoxPassed = - hasBullishBox && - IsBoxInside( - bullishBox, - iBox // - ); - - // - bool isBullishCZBoxPassed = - hasBullishConsolidationZone && - IsBoxInside( - bullishCZBox, - iBox // - ); - - // - result = isPriceInside && - (isBullishBoxPassed || - isBullishCZBoxPassed); - if (result) - { - // - if (isBullishBoxPassed) - { - box = bullishBox; - } - else - { - box = bullishCZBox; - } - - // - iBox.to = TimeCurrent(); - XCBoxObject *iObj; - provider.visionCycleHelper.mPOIDrawer.DrawBox( - iBox, - iObj // - ); - - // - dir = X_DIRECTION_BULLISH; - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_AREA; - - // - iBox.Clean(); - - // - break; - } - - // - iBox.Clean(); - } - - // - Clean(tmpBoxes); - } - - // - Clean(tmpBoxes); - - // - bullishBox.Clean(); - bearishBox.Clean(); - bullishCZBox.Clean(); - bearishCZBox.Clean(); - bullishConsolidationZone.Clean(); - bearishConsolidationZone.Clean(); - - // - } - - // - bar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; -} - -//////////////////////////////////////////////////////////////////////// - -// // -// bool isZoneActivated = -// hasWorkingZone && -// hasWaitingZones && -// workingZone.IsZoneActivated( -// activatedZoneIDX, -// activatedFVGIDX, -// signalBoxDir, -// signalProvider, -// provider, -// zIndex // -// ); - -// -// hasSignalBox = -// hasWorkingZone && -// hasWaitingBoxes && -// workingZone.IsBoxActivated( -// signalBox, -// signalBoxDir, -// signalProvider, -// provider, -// zIndex // -// ); - -//////////////////////////////////////////////////////////////////////// - -int activatedFVGIDX = -1; -int activatedZoneIDX = -1; -bool hasWaitingZones = false; - -// -// Remove Invalidate Zones ... -if (hasWaitingZones) -{ - // - // Validate Waiting Zones ... - workingZone.ValidateWaitingZones(zIndex); - hasWaitingZones = workingZone.HasWaitingZones(); -} - -// -// Detect Zones and Boxes ... -// hasWaitingZones = workingZone.DetectZone( -// provider // -// ); - -// -hasWaitingBoxes = workingZone.HasWaitingBoxes(); - -//////////////////////////////////////////////////////////////////////// - -// -// Senario 1: -// ---------- -bool useSenario1 = true; -bool isSenario1Happend = false; -bool isSenario1Bullish = false; -bool isSenario1Bearish = false; -if (useSenario1) -{ - // - // Senario 1 Bullish Conditions ... - isSenario1Bullish = - // - // X3Ma / XVwap Switched To Bulish ... - ( - // - // X3Ma Switched To Bulish ... - ( - // - (provider.decisionXConditions.isX3MaFastCrossedOverMid && - decisionParser.isX3MaBullishStateUnderValesGoldenZone) - // - ) - // - || - // - // XVWap Switched To Bulish ... - ( - // - (provider.decisionXConditions.isVWapFastCrossedOverMid && - decisionParser.isVWapBullishStateUnderValesGoldenZone) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSTR ... - provider.decisionXConditions.isStrBullish && - // - // XCHE ... - provider.decisionXConditions.isCheBullish && - provider.decisionXConditions.le1Buffer[cIDX] < cBar.low && - provider.decisionXConditions.le2Buffer[cIDX] < cBar.low - // - ) - // - ; - - // - // Senario 1 Bearish Conditions ... - isSenario1Bearish = - // - // X3Ma / XVwap Switched To Bearish ... - ( - // - // X3Ma Switched To Bearish ... - ( - // - (provider.decisionXConditions.isX3MaFastCrossedUnderMid && - decisionParser.isX3MaBearishStateOverPeaksGoldenZone) - // - ) - // - || - // - // XVWap Switched To Bearish ... - ( - // - (provider.decisionXConditions.isVWapFastCrossedUnderMid && - decisionParser.isVWapBearishStateOverPeaksGoldenZone) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSTR ... - provider.decisionXConditions.isStrBearish && - // - // XCHE ... - provider.decisionXConditions.isCheBearish && - provider.decisionXConditions.se1Buffer[cIDX] > cBar.high && - provider.decisionXConditions.se2Buffer[cIDX] > cBar.high - // - ) - // - ; - - //////////////////////////////////////////////////////////////////////// - - // - isSenario2Happend = cParser.HasSenario2Conditions( - X_CYCLE_DECISION, // TFT Cycle ... - X_CYCLE_ANALYSE, // MTF Cycle ... - X_CYCLE_CONSOLIDATION, // HTF Cycle ... - box, - holderBox, - dir, - provider, - barIndex // - ); - - // - isSenario2Bullish = - isSenario2Happend && - IsBullish(dir); - - // - isSenario2Bearish = - isSenario2Happend && - IsBearish(dir); - - // - if (isSenario2Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } - - //////////////////////////////////////////////////////////////////////// - // - // Extract Cycles ... - - // - // TTF Cycle ... - XPOIState ttfState; - X121Conditions ttfXConditions; - XC121SMCCycleHelper *ttfHelper; - X121SMCCycleConditions ttfConditions; - result = provider.SelectCycle( - ttfCycle, - ttfState, - ttfXConditions, - ttfHelper, - ttfConditions // - ); - if (!result) - { - // - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - Parse(ttfXConditions); - - // - // MTF Cycle ... - XPOIState mtfState; - X121Conditions mtfXConditions; - XC121SMCCycleHelper *mtfHelper; - X121SMCCycleConditions mtfConditions; - result = provider.SelectCycle( - mtfCycle, - mtfState, - mtfXConditions, - mtfHelper, - mtfConditions // - ); - if (!result) - { - // - ttfState.Clean(); - mtfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ZeroMemory(mtfHelper); - mtfConditions.Clean(); - ttfXConditions.Clean(); - mtfXConditions.Clean(); - - // - return result; - } - Parse(mtfXConditions); - - // - // HTF Cycle ... - XPOIState htfState; - X121Conditions htfXConditions; - XC121SMCCycleHelper *htfHelper; - X121SMCCycleConditions htfConditions; - result = provider.SelectCycle( - htfCycle, - htfState, - htfXConditions, - htfHelper, - htfConditions // - ); - if (!result) - { - // - ttfState.Clean(); - mtfState.Clean(); - htfState.Clean(); - ZeroMemory(ttfHelper); - ZeroMemory(mtfHelper); - ZeroMemory(htfHelper); - ttfConditions.Clean(); - mtfConditions.Clean(); - htfConditions.Clean(); - ttfXConditions.Clean(); - mtfXConditions.Clean(); - htfXConditions.Clean(); - - // - return result; - } - Parse(htfXConditions); - - //////////////////////////////////////////////////////////////////////// - - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = ttfXConditions.symbol; - box.period = ttfXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = ttfXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = ttfXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = ttfHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = ttfHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = ttfXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = ttfXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = ttfHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = ttfHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (htfState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - htfState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - htfState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - htfState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - htfState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - htfState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - htfState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Validate Conditions to Force Has Holder Box ... - result = - result && - holderBox.IsValid(); - if (!result) - { - // - isBullish = false; - isBearish = false; - } - - //////////////////////////////////////////////////////////////////////// - - // - // Here we Looking for Detectiong Signal Conditions ... - if (result) - { - // - insideBox.from = insideBox.to; - insideBox.to = zBar.time; - - // - XCBoxObject *iObj; - has = ttfHelper.mPOIDrawer.DrawBox( - insideBox, - iObj // - ); - if (has) - { - // - iObj.Width(2); - iObj.BoxColor(clrGray); - } - - // - Print("Has Inside Box ..."); - } - - //////////////////////////////////////////////////////////////////////// - - // - XOBFVG waitingZones[]; - XOBFVG unavailableZones[]; - - //////////////////////////////////////////////////////////////////////// - - // - bool DetectZone( - X121SMCStrategySignalProviderData & provider // - ) - { - // - bool result = false; - - // - result = IsValid() && - provider.IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - int count = 0; - bool has = false; - datetime cTime = TimeCurrent(); - - // - XOBFVG obFVG; - XBoxZone obBox; - XBoxZone fvgBox; - XBoxZone supplyBox; - XBoxZone demandBox; - - // - XCFVG *fvg = NULL; - XCOrderBlock *ob = NULL; - XCSupplyZone *supply = NULL; - XCDemandZone *demand = NULL; - - // - // Check New Supply Zone Detection ... - bool hasNewSupply = - Contains( - X_SUPPLY_ZONE_DETECTED, - provider.consolidationPoiEvents // - ); - if (hasNewSupply) - { - // - idx = GetYoungest(provider - .consolidationState - .supplyZones // - ); - has = IsValidIndex(idx); - if (has) - { - // - supply = provider - .consolidationState - .supplyZones[idx]; - has = ToBox( - supplyBox, - supply // - ); - if (has) - { - // - supply.To(cTime); - supplyBox.to = cTime; - hasNewSupply = supplyBox.IsValid(); - } - } - } - - // - // Check New Demand Zone Detection ... - bool hasNewDemand = - Contains( - X_DEMAND_ZONE_DETECTED, - provider - .consolidationPoiEvents // - ); - if (hasNewDemand) - { - // - idx = GetYoungest(provider - .consolidationState - .demandZones // - ); - has = IsValidIndex(idx); - if (has) - { - // - demand = provider - .consolidationState - .demandZones[idx]; - has = ToBox( - demandBox, - demand // - ); - if (has) - { - // - demand.To(cTime); - demandBox.to = cTime; - hasNewDemand = demandBox.IsValid(); - } - } - } - - // - // Check New Fair Value Gap Detection ... - bool hasNewFairValueGap = - Contains( - X_BULLISH_FVG_DETECTED, - provider - .analysePoiEvents // - ) || - Contains( - X_BEARISH_FVG_DETECTED, - provider - .analysePoiEvents // - ); - if (hasNewFairValueGap) - { - // - idx = GetYoungest(provider - .analyseState - .fairValueGaps // - ); - has = IsValidIndex(idx); - if (has) - { - // - fvg = provider - .analyseState - .fairValueGaps[idx]; - has = ToBox( - fvgBox, - fvg // - ); - if (has) - { - // - fvg.To(cTime); - fvgBox.to = cTime; - hasNewFairValueGap = fvgBox.IsValid(); - } - } - } - - // - // Check New Order Block Detection ... - bool hasNewOrderBlock = - Contains( - X_BULLISH_ORDERBLOCK_DETECTED, - provider - .consolidationPoiEvents // - ) || - Contains( - X_BEARISH_ORDERBLOCK_DETECTED, - provider - .consolidationPoiEvents // - ); - if (hasNewOrderBlock) - { - // - idx = GetYoungest(provider - .consolidationState - .orderBlocks // - ); - has = IsValidIndex(idx); - if (has) - { - // - ob = provider - .consolidationState - .orderBlocks[idx]; - has = ToBox( - obBox, - ob // - ); - if (has) - { - // - ob.To(cTime); - obBox.to = cTime; - hasNewOrderBlock = obBox.IsValid(); - } - } - } - - // - // Detect OB FVG ... - if (hasNewOrderBlock) - { - // - XOHCL obStartedBar; - bool isOBStartedBodyOut = false; - bool isOBStarted = ob.IsStarted( - ob.GetDirection(), - obStartedBar, - isOBStartedBodyOut // - ); - - // - has = isOBStarted; - if (has) - { - // - obFVG.ob = ob; - - // - // Select FVGs ... - count = provider - .analyseState - .CountFairValueGaps(); - has = IsValidSize(count); - if (!has) - { - obFVG.Clean(); - } - else - { - // - // Select FVG ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = provider - .analyseState - .fairValueGaps[i]; - bool isBullish = iFVG.IsBullish(); - - // - XOHCL iStartedBar; - bool isBodyOut = false; - bool isStarted = iFVG.IsStarted( - iFVG.GetDirection(), - iStartedBar, - isBodyOut // - ); - iStartedBar.Clean(); - - // - bool isKindPassed = isStarted && - isBodyOut; - bool isSameDir = iFVG.GetDirection() == ob.GetDirection(); - bool isFromPassed = iFVG.From() >= obStartedBar.time; - bool isPlacePassed = - // - IsInsideOrDiff( - iFVG, - ob // - ) - // - // || - // // - // (isBullish - // ? IsAboveDiff( - // iFVG, - // ob, - // true // Ignore Inside ... - // ) - // : IsBelowDiff( - // iFVG, - // ob, - // true // Ignore Inside ... - // ) - // // - // ) - // - ; - - // - has = isSameDir && - isKindPassed && - isFromPassed && - isPlacePassed; - if (has) - { - obFVG.AddFVG(iFVG); - } - - // - ZeroMemory(iFVG); - } - } - } - - // - has = obFVG.IsValid(); - if (has) - { - // - has = IsExists(obFVG); - if (!has) - { - // - // New Waiting Zone ... - AddRef( - obFVG, - waitingZones // - ); - } - else - { - // - // Check Item Is not Exists ... - idx = FindIndex( - obFVG, - waitingZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - // Update Exists Waiting Zone ... - waitingZones[idx].AddFVG(fvg); - } - } - } - - // - obFVG.Clean(); - obStartedBar.Clean(); - } - - // - // - // - - // - bool lookingOthers = false; - if (lookingOthers) - { - // - // Check New Order Block Detection Analyse ... - XBoxZone analyseOBBox; - XCOrderBlock *analyseOB = NULL; - bool hasNewAnalyseOrderBlock = - Contains( - X_BULLISH_ORDERBLOCK_DETECTED, - provider - .analysePoiEvents // - ) || - Contains( - X_BEARISH_ORDERBLOCK_DETECTED, - provider - .analysePoiEvents // - ); - if (hasNewAnalyseOrderBlock) - { - // - idx = GetYoungest(provider - .analyseState - .orderBlocks // - ); - has = IsValidIndex(idx); - if (has) - { - // - analyseOB = provider - .analyseState - .orderBlocks[idx]; - has = ToBox( - analyseOBBox, - analyseOB // - ); - if (has) - { - // - analyseOB.To(cTime); - analyseOBBox.to = cTime; - hasNewAnalyseOrderBlock = analyseOBBox.IsValid(); - } - } - } - - // - // Checking Analyse Order Block ... - if (hasNewAnalyseOrderBlock) - { - // - XOHCL obStartedBar; - bool isOBStartedBodyOut = false; - bool isOBStarted = analyseOB.IsStarted( - analyseOB.GetDirection(), - obStartedBar, - isOBStartedBodyOut // - ); - - // - has = isOBStarted && - isOBStartedBodyOut; - if (has) - { - // - analyseOBBox.from = - obStartedBar.NextAt(); - - // - has = IsExists(analyseOBBox); - if (!has) - { - // - AddRef( - analyseOBBox, - waitingBoxes // - ); - } - } - } - - // - analyseOBBox.Clean(); - ZeroMemory(analyseOB); - } - - // - // - // - - // - result = HasWaitingZones(); - - // - // Cleanup Resources ... - - // - obFVG.Clean(); - obBox.Clean(); - fvgBox.Clean(); - supplyBox.Clean(); - demandBox.Clean(); - - // - ZeroMemory(ob); - ZeroMemory(fvg); - ZeroMemory(supply); - ZeroMemory(demand); - - // - return result; - } - - //////////////////////////////////////////////////////////////////////// - - // - int ValidateWaitingZones( - int barIndex = 0 // - ) - { - // - int result = 0; - - // - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex = 1; - } - - // - has = IsValid() && - HasWaitingZones(); - if (!has) - { - return result; - } - - // - int removeIDX[]; - result = CountWaitingZones(); - for (int i = 0; i < result; i++) - { - // - has = waitingZones[i].IsValidZone( - barIndex // - ); - if (!has) - { - // - Add( - i, - removeIDX // - ); - - // - AddRef( - waitingZones[i], - unavailableZones // - ); - } - } - - // - has = HasChild(removeIDX); - if (has) - { - // - CleanupArray( - removeIDX, - waitingZones // - ); - } - Clean(removeIDX); - - // - result = CountWaitingZones(); - - // - return result; - } - - //////////////////////////////////////////////////////////////////////// - - // - bool IsExists(XOBFVG & zone) - { - // - bool result = false; - - // - // Check Validation ... - result = zone.IsValid() && - (HasWaitingZones() || - HasUnavailableZones()); - if (!result) - { - return result; - } - - // - int idx = -1; - - // - // Check Index in Waiting Zones ... - idx = FindIndex( - zone, - waitingZones // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - - // - // Check Index in Unavailable Zones ... - idx = FindIndex( - zone, - unavailableZones // - ); - result = IsValidIndex(idx); - if (result) - { - return result; - } - - // - return result; - } - - //////////////////////////////////////////////////////////////////////// - - // - Clean(waitingZones); - Clean(unavailableZones); - - // - bool HasWaitingZones() - { - return HasChild(waitingZones); - } - - // - int CountWaitingZones() - { - return ArraySize(waitingZones); - } - - // - bool HasUnavailableZones() - { - return HasChild(unavailableZones); - } - - //////////////////////////////////////////////////////////////////////// - - // - has = HasWaitingZones(); - if (has) - { - // - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - waitingZones[i].UpdateTo(value); - } - } - - //////////////////////////////////////////////////////////////////////// - - // - has = HasWaitingZones(); - if (has) - { - // - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *iObjects[]; - int iObjectsCount = drawer.DrawOBFVG( - waitingZones[i], - iObjects, - true, // Draw Order Block ... - true, // Draw Fair Value Gaps ... - true, // Draw All Fair Value Gaps ... - // - true, // Draw OB StartedBar ... - true, // Draw OB ActivatedBar ... - true, // Draw OB BreakedBar ... - true, // Draw OB WorkedBar ... - // - true, // Draw FVG StartedBar ... - true, // Draw FVG ActivatedBar ... - true, // Draw FVG BreakedBar ... - true // Draw FVG WorkedBar ... - // - ); - has = IsValidSize(iObjectsCount); - if (has) - { - // - for (int j = 0; j < iObjectsCount; j++) - { - mDrawnObjects.Add(iObjects[j]); - } - } - - // - // if (drawWaitingZonesBoxArea) - // { - // // - // XBoxZone iBox; - // has = waitingZones[i].ToZone( - // iBox // - // ); - // if (has) - // { - // // - // XCBoxObject *iBoxObj; - // has = drawer.DrawBox( - // iBox, - // iBoxObj // - // ); - // if (has) - // { - // mDrawnObjects.Add(iBoxObj); - // } - // } - - // // - // iBox.Clean(); - // } - } - } - -//////////////////////////////////////////////////////////////////////// - // - bool HasSenario1Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL cSMHKBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - cHelper - .mX121Helper - .xhkHelper - .GetSMHKAsXOHCL( - cIDX, - cSMHKBar // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - cSMHKBar.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - cXConditions.isSMHKSwitchedToBullish && - ( - // - // Validate CBar ... - cBar.IsBullish() && - (cBar.open == cSMHKBar.open || - (cBar.low < cSMHKBar.open && - cBar.GetDown() > cSMHKBar.close)) && - // - cXConditions.isSarBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - cXConditions.isSMHKSwitchedToBearish && - ( - // - // Validate CBar ... - cBar.IsBearish() && - (cBar.open == cSMHKBar.open || - (cBar.high > cSMHKBar.open && - cBar.GetUp() < cSMHKBar.close)) && - // - cXConditions.isSarBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Fix Box Upper and Lower based on Strategy ... - - // - double points = GetPoints(box.symbol); - double minPointsDiff = points * 20; - - // - double prefferSL = 0; - - // - // First Check Based on Prev Bar ... - // double prevDiff = - // isBullish - // ? cBar.low < zBar.open - // ? zBar.open - cBar.low - // : 0 - // : isBearish - // ? cBar.high > zBar.open - // ? cBar.high - zBar.open - // : 0 - // : 0; - // if (prevDiff >= minPointsDiff) - // { - // // - // prefferSL = - // isBullish - // ? cBar.low - // : cBar.high; - // } - - // - // Other SL Conditions ... - if (prefferSL <= 0) - { - // - if (isBullish) - { - // - if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesBuffer[cIDX]; - } - else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - } - else - { - // - if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksBuffer[cIDX]; - } - else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksGoldenBuffer[cIDX]; - } - } - } - - // - if (prefferSL > 0) - { - // - prefferSL = - prefferSL <= minPointsDiff - ? minPointsDiff - : prefferSL; - - // - box.upper = - isBullish - ? zBar.open - : prefferSL; - - // - box.lower = - isBullish - ? prefferSL - : zBar.open; - } - - // - // Validate Conditions to Force Has Holder Box ... - // result = - // result && - // holderBox.IsValid(); - result = box.IsValid(); - if (!result) - { - // - isBullish = false; - isBearish = false; - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - cSMHKBar.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - -//////////////////////////////////////////////////////////////////////// - -// -// FRACTALS ... -int copiedFractalsUppers = CopyBuffer(fractalHandler, 0, UPPER_LINE, limit, fractalsUpperBuffer); -int copiedFractalsLowers = CopyBuffer(fractalHandler, 1, LOWER_LINE, limit, fractalsLowerBuffer); - -// -// FRACTALS ... -copiedFractalsUppers > 0 && -copiedFractalsLowers > 0 - -// -// FRACTALS ... -int fractalsCalculatedBars = BarsCalculated(fractalHandler); - -// -// FRACTALS ... -fractalsCalculatedBars >= maxLength - - - // - // SUPPORT and RESISTANCE ... - - // - double iHighValue = iHigh( - _Symbol, - _Period, - barIndex // - ); - double iLastHighValue = iHigh( - _Symbol, - _Period, - lastIndex // - ); - - // - double iLowValue = iLow( - _Symbol, - _Period, - barIndex // - ); - double iLastLowValue = iLow( - _Symbol, - _Period, - lastIndex // - ); - - // - // Resistance ... - // double lastResistance = - // lastIndex < barsCount - // ? resistancesBuffer[lastIndex] - // : iLastHighValue; - // double iFractalsUpper = fractalsUpperBuffer[barIndex]; - // double iResistance = - // NotEmptyZero(iFractalsUpper) - // ? iHighValue - // : lastResistance; - // resistancesBuffer[barIndex] = iResistance; - - // - // Support ... - // double lastSupport = - // lastIndex < barsCount - // ? supportsBuffer[lastIndex] - // : iLastLowValue; - // double iFractalsLower = fractalsLowerBuffer[barIndex]; - // double iSupport = - // NotEmptyZero(iFractalsLower) - // ? iLowValue - // : lastSupport; - // supportsBuffer[barIndex] = iSupport; - - // - double iFractalsUpper = fractalsUpperBuffer[barIndex]; - double iResistance = iFractalsUpper; - resistancesBuffer[barIndex] = iResistance; - - - // - double iFractalsLower = fractalsLowerBuffer[barIndex]; - double iSupport = iFractalsLower; - supportsBuffer[barIndex] = iSupport; - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// diff --git a/Documents/BKP/x-121.smc.market.cycle.helper.class.mq5 b/Documents/BKP/x-121.smc.market.cycle.helper.class.mq5 deleted file mode 100644 index 3d8f8ed2..00000000 --- a/Documents/BKP/x-121.smc.market.cycle.helper.class.mq5 +++ /dev/null @@ -1,4033 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XC121SMCCycleHelper -// Description: provides all based classes for use ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../../Classes/x-saherelm.x-poi.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... - -// -// Implementations ... - -// -// Cycles Enumeration ... -enum ENUM_X_CYCLES -{ - X_CYCLE_NONE, - X_CYCLE_TRIGGER, - X_CYCLE_DECISION, - X_CYCLE_ANALYSE, - X_CYCLE_VERIFICATION, - X_CYCLE_CONSOLIDATION, - X_CYCLE_VISION, -}; - -// -// String Representation of Cycles Enumeration ... -string ToString(ENUM_X_CYCLES value) -{ - // - string result = EnumToString(value); - - // - StringReplace(result, "X_CYCLE_", ""); - - // - return result; -} - -// -// Validate a Cycle ... -bool IsValid(ENUM_X_CYCLES value) -{ - // - bool result = false; - - // - result = - value != X_CYCLE_NONE; - - // - return result; -} - -// -// Cycle Events Enumeration ... -enum ENUM_X_CYCLE_EVENTS -{ - SAR_CHANGE_DETECTED, - NEW_PEAK_DETECTED, - NEW_VALE_DETECTED, - PIVOT_POINT_DETECTED, - VWAP_ORDER_CHANGE_ETECTED, - VWAP_STATE_CHANGE_DETCTED, - CONSOLIDATION_BREAKED_DETECTED, - PEAK_PIVOT_STARTED, - PEAK_PIVOT_ENDED, - VALE_PIVOT_STARTED, - VALE_PIVOT_ENDED, -}; - -// -// Cycle Helper ... -class XC121SMCCycleHelper : public XCBase -{ - // - public: - // - // Props ... - - // - // X121 ... - XCX121Helper *mX121Helper; - - // - // POI Detector ... - XCPOIDrawer *mPOIDrawer; - XCPOIDetector *mPOIDetector; - - // - // Bar Analyser - XCBarAnalyser *mBarAnalyser; - - // - // Constructor(s) ... - XC121SMCCycleHelper() - { - Default(); - } - - // - // Deconstructor ... - ~XC121SMCCycleHelper() - { - DeInit(); - } - - // - // Getter/Setter(s) ... - - // - // Actions ... - - /** - * Initialize ... - * - * @param symbol: String ... - * @param period: ENUM_TIMEFRAMES member ... - * @param x121Inputs: X121Inputs instance ... - * - * @return ( bool ) - */ - bool Init( - string symbol, - ENUM_TIMEFRAMES period, - X121Inputs &x121Inputs, - int requiredPOIs = 50 // - ) - { - // - bool result = false; - - // - if (requiredPOIs < 0) - { - requiredPOIs = 0; - } - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - return result; - } - - // - mSymbol = symbol; - mPeriod = period; - - // - // X121 ... - mX121Helper = new XCX121Helper(); - result = mX121Helper.Init( - symbol, - period, - x121Inputs // - ); - if (!result) - { - return result; - } - - // - mPOIDetector = new XCPOIDetector( - symbol, - period // - ); - mPOIDetector.MaxRequiredPOIs(requiredPOIs); - - // - int maxLoopbackBars = mPOIDetector.MaxAllowedLoopbackForInit(); - int periodSeconds = PeriodSeconds(period); - if (periodSeconds > PeriodSeconds(PERIOD_M15)) - { - // - int multiplier = periodSeconds / PeriodSeconds(PERIOD_M15); - - // - if (multiplier >= 1) - { - maxLoopbackBars *= 2; - } - } - mPOIDetector.MaxAllowedLoopbackForInit(maxLoopbackBars); - mPOIDetector.Init(); - - // - // Initialize Bar Analyser Class Instance ... - mBarAnalyser = new XCBarAnalyser(); - - // - // Initial and Configure POI Drawer if Required ... - mPOIDrawer = new XCPOIDrawer(); - mPOIDrawer.ChartIdentification(0); - mPOIDrawer.SubWindowIdentification(0); - - // - mPOIDrawer.DemandZoneFill(false); - mPOIDrawer.SupplyZoneFill(false); - mPOIDrawer.BullishFVGFill(false); - mPOIDrawer.BearishFVGFill(false); - mPOIDrawer.SupportZoneFill(false); - mPOIDrawer.ResistanceZoneFill(false); - mPOIDrawer.BullishOrderBlockFill(false); - mPOIDrawer.BearishOrderBlockFill(false); - - // - // Set Chart Style ... - ApplyChartStyle(); - - // - return result; - } - - /** - * Retrieve Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - return mSymbol; - } - - /** - * Retrieve TimeFrame (Period) ... - * - * @return ( ENUM_TIMEFRAMES ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - return mPeriod; - } - - /** - * Get Specified Bar ... - * - * @param source: XOHCL instance, Source Bar ... - * @param bar: XOHCL instance, Dest Bar ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &source, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = - IsValid(symbol) && - IsValid(period) && - source.IsValid(); - if (!result) - { - return result; - } - - // - int index = iBarShift( - symbol, - period, - source.time // - ); - result = bar.Init( - symbol, - period, - index // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - return result; - } - - /** - * Retrieve Specified Bar ... - * - * @param bar: XOHCL instance ... - * @param index: Integer ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &bar, - int index = 0 // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (index < 0) - { - index = 0; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = bar.Init( - symbol, - period, - index // - ); - - // - return result; - } - - /** - * Retrieve Specified Bar ... - * - * @param bar: XOHCL instance ... - * @param time: Datetime ... - * - * @return ( bool ) - */ - bool GetBar( - XOHCL &bar, - datetime time = NULL // - ) - { - // - bool result = false; - - // - int index = GetBarIndex(time); - result = GetBar(bar, - index // - ); - - // - return result; - } - - /** - * Retrieve Specified Time Bar Index ... - * - * @param time: DateTime ... - * - * @return ( int ) - */ - int GetBarIndex(datetime time = NULL) - { - // - int result = -1; - - // - time = NormalizeTime(time); - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - result = iBarShift( - symbol, - period, - time // - ); - - // - return result; - } - - /** - * Retrieve Cycle Conditions ... - * - * @param events: ENUM_X_CYCLE_EVENTS member, Array ... - * @param conditions: X121SMCCycleConditions instance ... - * @param barIndex: Integer ... - * @param loopback: Integer ... - * - * @return ( bool ) - */ - bool GetConditions( - ENUM_X_CYCLE_EVENTS &events[], - ENUM_XPOI_EVENTS &poiEvents[], - X121SMCCycleConditions &conditions, - int barIndex = 0, - int loopback = 7 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 5) - { - loopback = 5; - } - - // - Clean(events); - Clean(poiEvents); - conditions.Clean(); - - // - result = mX121Helper.GetConditions( - conditions.x121Conditions, - barIndex, - loopback // - ); - if (!result) - { - // - conditions.Clean(); - return result; - } - - // - mPOIDetector.Update(poiEvents); - mPOIDetector.GetState(conditions.state); - - // - conditions.symbol = GetSymbol(); - conditions.period = GetPeriod(); - conditions.time = TimeCurrent(); - - // - // Update(); - - // - result = conditions.IsValid(); - - // - return result; - } - - // - bool GeneratePVBox( - XBoxZone &box, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - box.Clean(); - box.symbol = GetSymbol(); - box.period = GetPeriod(); - - // - int index = barIndex; - - // - // Peak ... - datetime peaksSameFrom = NULL; - double peak = mX121Helper.xpvHelper.GetPeak(index); - double prevPeak = mX121Helper.xpvHelper.GetPeak(index + 1); - bool startsByPeak = peak == prevPeak; - - // - // Vale ... - datetime valesSameFrom = NULL; - double vale = mX121Helper.xpvHelper.GetVale(index); - double prevVale = mX121Helper.xpvHelper.GetVale(index + 1); - bool startsByVale = - !startsByPeak && - vale == prevVale; - - // - bool canBreak = false; - while (!canBreak) - { - // - index++; - - // - datetime cTime = iTime( - box.symbol, - box.period, - index // - ); - - // - // Peak ... - double iPeak = mX121Helper.xpvHelper.GetPeak(index); - - // - // Vale ... - double iVale = mX121Helper.xpvHelper.GetVale(index); - - // - // Start By Peak or Value ... - bool isSame = false; - if (startsByPeak) - { - // - isSame = iPeak == peak; - bool canSetVale = vale == 0 - ? true - : iVale > vale; - if (canSetVale) - { - vale = iVale; - } - } - else if (startsByVale) - { - // - isSame = iVale == vale; - bool canSetPeak = peak == 0 - ? true - : iPeak < peak; - if (canSetPeak) - { - peak = iPeak; - } - } - - // - if (isSame) - { - // - box.from = cTime; - box.upper = peak; - box.lower = vale; - } - else if (IsValid(box.from)) - { - // - // Complete Box ... - box.to = iTime( - box.symbol, - box.period, - barIndex // - ); - - // - box.type = "XPVBox"; - box.dir = startsByPeak - ? X_DIRECTION_BEARISH - : startsByVale - ? X_DIRECTION_BULLISH - : X_DIRECTION_NONE; - } - - // - canBreak = !isSame; - } - - // - result = box.IsValid(); - if (!result) - { - box.Clean(); - } - - // - return result; - } - - // - int DetectRejections( - XBoxZone &rejections[], - int barIndex = 0, - bool forceBarType = true, - bool forceFiboPressure = true, - bool forceUnUsedRejections = true, - int maxAllowedLoopback = 587 // - ) - { - // - int result = 0; - - // - // Normalize Args ... - Clean(rejections); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - bool has = false; - for (int i = barIndex + 1; i < barIndex + maxAllowedLoopback; i++) - { - // - // Init Indexed Bar ... - XOHCL iBar; - XOHCL iCBar; - XOHCL iPBar; - has = GetBar(iBar, i); - has = - has && - iBar.GetPreviousBar(iCBar); - has = - has && - iCBar.GetPreviousBar(iPBar); - if (!has) - { - // - iBar.Clean(); - iCBar.Clean(); - iPBar.Clean(); - break; - } - - // - // Check CBar Bullish Fibo Pressure ... - bool cBarHasBullishFiboPressure = - mBarAnalyser - .HasFiboPressure( - iCBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - // Check CBar Bearish Fibo Pressure ... - bool cBarHasBearishFiboPressure = - mBarAnalyser - .HasFiboPressure( - iCBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - // Check Bar is Bullish Rejection Swing ... - bool isBullishRejection = - // - iCBar.low < iBar.low && - iCBar.low < iPBar.low && - // - iCBar.low < iCBar.GetDown() && - iCBar.GetLowShadow() > iCBar.GetBody() && - iCBar.GetLowShadow() > iCBar.GetHighShadow() - // - ; - - // - // Check Bar is Bearish Rejection Swing ... - bool isBearishRejection = - // - iCBar.high > iBar.high && - iCBar.high > iPBar.high && - // - iCBar.high > iCBar.GetUp() && - iCBar.GetHighShadow() > iCBar.GetBody() && - iCBar.GetHighShadow() > iCBar.GetLowShadow() - // - ; - - // - // Apply Fibo Pressure ... - if (forceFiboPressure) - { - // - isBullishRejection = - isBullishRejection && - cBarHasBullishFiboPressure; - - // - isBearishRejection = - isBearishRejection && - cBarHasBearishFiboPressure; - } - - // - // Apply Force Bar Type ... - if (forceBarType) - { - // - isBullishRejection = - isBullishRejection && - iCBar.IsBullish(); - - // - isBearishRejection = - isBearishRejection && - iCBar.IsBearish(); - } - - // - // Summarize Result ... - has = isBullishRejection || - isBearishRejection; - if (has) - { - // - XBoxZone iBox; - - // - iBox.to = iBar.time; - iBox.from = iCBar.time; - iBox.period = iBar.period; - iBox.symbol = iBar.symbol; - - // - iBox.dir = - isBullishRejection - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - iBox.upper = - isBullishRejection - ? iCBar.GetDown() - : iCBar.high; - - // - iBox.lower = - isBullishRejection - ? iCBar.low - : iCBar.GetUp(); - - // - iBox.type = - isBullishRejection - ? "XSwingLow" - : "XSwingHigh"; - - // - // Validate Box ... - has = iBox.IsValid(); - if (has) - { - // - // Apply Force Unused Rejections ... - if (forceUnUsedRejections) - { - // - has = !IsBoxBreaked( - iBox, - iCBar.Index() + 1, - barIndex // - ); - } - - // - if (has) - { - // - idx = FindIndex( - iBox, - rejections // - ); - has = !IsValidIndex(idx); - if (has) - { - // - AddRef( - iBox, - rejections // - ); - } - } - } - - // - iBox.Clean(); - } - - // - iBar.Clean(); - iCBar.Clean(); - iPBar.Clean(); - } - - // - result = ArraySize(rejections); - - // - return result; - } - - // - // Virtuals ... - - /** - * Set Default Properties Values ... - */ - virtual void Default() - { - } - - // - protected: - // - - // - private: - // - // Props ... - string mSymbol; - ENUM_TIMEFRAMES mPeriod; - - // - // Actions ... - - /** - * Release All Resources ... - */ - void DeInit() - { - // - ZeroMemory(mX121Helper); - ZeroMemory(mPOIDetector); - ZeroMemory(mBarAnalyser); - - // - delete mX121Helper; - delete mPOIDetector; - delete mBarAnalyser; - } - - /** - * Apply Chart Style ... - */ - void ApplyChartStyle() - { - // - // Retrieve Current Chart ID ... - long chartId = ChartID(); - - // - ENUM_CHART_MODE mMode = CHART_CANDLES; // chart's mMode - bool mShowBidLine = true; // show bid line - bool mShowAskLine = true; // show ask line - bool mShowGrid = false; // show grids on chart - bool mShowVolumes = true; // show volumes - bool mShowTradeLevels = true; // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) - bool mAutoScroll = true; // chart autoscroll - bool mQuickNavigation = true; // chart quick navigation state - color mForeGroundColor = clrWhite; // chart's foreground color - color mBackGroundColor = clrBlack; // chart's background color - color mUpColor = clrGreen; // Up Color - color mDownColor = clrRed; // Down Color - color mBullishColor = clrGreen; // Bullish color - color mBearishColor = clrRed; // Bearish color - color mGridColor = clrGray; // grid color - color mBidLineColor = clrGray; // bid line color - color mAskLineColor = clrRed; // ask line color - color mLineColor = clrLime; // line mMode and doji candlestick color - color mStopColor = clrGold; // Color of stop order levels (Stop Loss and Take Profit) - color mVolumesColor = clrGreen; // volumes color - - // - ChartSetInteger(chartId, CHART_SHOW_BID_LINE, mShowBidLine); - ChartSetInteger(chartId, CHART_SHOW_ASK_LINE, mShowAskLine); - ChartSetInteger(chartId, CHART_SHOW_GRID, mShowGrid); - ChartSetInteger(chartId, CHART_SHOW_VOLUMES, mShowVolumes); - ChartSetInteger(chartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); - ChartSetInteger(chartId, CHART_AUTOSCROLL, mAutoScroll); - ChartSetInteger(chartId, CHART_QUICK_NAVIGATION, mQuickNavigation); - ChartSetInteger(chartId, CHART_COLOR_FOREGROUND, mForeGroundColor); - ChartSetInteger(chartId, CHART_COLOR_BACKGROUND, mBackGroundColor); - ChartSetInteger(chartId, CHART_COLOR_GRID, mGridColor); - ChartSetInteger(chartId, CHART_COLOR_BID, mBidLineColor); - ChartSetInteger(chartId, CHART_COLOR_ASK, mAskLineColor); - ChartSetInteger(chartId, CHART_COLOR_STOP_LEVEL, mStopColor); - ChartSetInteger(chartId, CHART_COLOR_VOLUME, mVolumesColor); - - // - // For Enabling XCC ... - // ChartSetInteger(chartId, CHART_MODE, mMode); - // ChartSetInteger(chartId, CHART_COLOR_CHART_UP, mUpColor); - // ChartSetInteger(chartId, CHART_COLOR_CHART_DOWN, mDownColor); - // ChartSetInteger(chartId, CHART_COLOR_CANDLE_BULL, mBullishColor); - // ChartSetInteger(chartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); - // ChartSetInteger(chartId, CHART_COLOR_CHART_LINE, mLineColor); - } - - // -}; - -// -// Signal Provider Data ... -struct X121SMCStrategySignalProviderData -{ - // - // Props ... - - // - // Trigger ... - XPOIState triggerState; - double triggerBullishScore; - double triggerBearishScore; - X121Conditions triggerXConditions; - ENUM_XPOI_EVENTS triggerPoiEvents[]; - XC121SMCCycleHelper *triggerCycleHelper; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - - // - // Decision ... - XPOIState decisionState; - double decisionBullishScore; - double decisionBearishScore; - X121Conditions decisionXConditions; - ENUM_XPOI_EVENTS decisionPoiEvents[]; - XC121SMCCycleHelper *decisionCycleHelper; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - - // - // Analyse ... - XPOIState analyseState; - double analyseBullishScore; - double analyseBearishScore; - X121Conditions analyseXConditions; - ENUM_XPOI_EVENTS analysePoiEvents[]; - XC121SMCCycleHelper *analyseCycleHelper; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - - // - // Verification ... - XPOIState verificationState; - double verificationBullishScore; - double verificationBearishScore; - X121Conditions verificationXConditions; - ENUM_XPOI_EVENTS verificationPoiEvents[]; - XC121SMCCycleHelper *verificationCycleHelper; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - - // - // Consolidation ... - XPOIState consolidationState; - double consolidationBullishScore; - double consolidationBearishScore; - X121Conditions consolidationXConditions; - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - XC121SMCCycleHelper *consolidationCycleHelper; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - - // - // Vision ... - XPOIState visionState; - double visionBullishScore; - double visionBearishScore; - X121Conditions visionXConditions; - ENUM_XPOI_EVENTS visionPoiEvents[]; - XC121SMCCycleHelper *visionCycleHelper; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - - // - // Constructor ... - X121SMCStrategySignalProviderData() - { - Clean(); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - // Trigger ... - triggerState.Clean(); - triggerBullishScore = 0; - triggerBearishScore = 0; - Clean(triggerPoiEvents); - Clean(triggerCycleEvents); - triggerConditions.Clean(); - triggerXConditions.Clean(); - - // - // Decision ... - decisionState.Clean(); - decisionBullishScore = 0; - decisionBearishScore = 0; - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - // Analyse ... - analyseState.Clean(); - analyseBullishScore = 0; - analyseBearishScore = 0; - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - analyseConditions.Clean(); - analyseXConditions.Clean(); - - // - // Verification ... - verificationState.Clean(); - verificationBullishScore = 0; - verificationBearishScore = 0; - Clean(verificationPoiEvents); - Clean(verificationCycleEvents); - verificationConditions.Clean(); - verificationXConditions.Clean(); - - // - // Consolidation ... - consolidationState.Clean(); - consolidationBullishScore = 0; - consolidationBearishScore = 0; - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - // Vision ... - visionState.Clean(); - visionBullishScore = 0; - visionBearishScore = 0; - Clean(visionPoiEvents); - Clean(visionCycleEvents); - visionConditions.Clean(); - visionXConditions.Clean(); - } - - // - void Destroy() - { - // - Clean(); - - // - ZeroMemory(visionCycleHelper); - ZeroMemory(triggerCycleHelper); - ZeroMemory(analyseCycleHelper); - ZeroMemory(decisionCycleHelper); - ZeroMemory(verificationCycleHelper); - ZeroMemory(consolidationCycleHelper); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - visionCycleHelper != NULL && - triggerCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - verificationCycleHelper != NULL && - consolidationCycleHelper != NULL; - - // - return result; - } - - // - // Initialize ... - bool Init( - XC121SMCCycleHelper *_triggerCycleHelper, - XC121SMCCycleHelper *_decisionCycleHelper, - XC121SMCCycleHelper *_analyseCycleHelper, - XC121SMCCycleHelper *_verificationCycleHelper, - XC121SMCCycleHelper *_consolidationCycleHelper, - XC121SMCCycleHelper *_visionCycleHelper // - ) - { - // - bool result = false; - - // - // Validate Cycle Helpers ... - result = - // - _visionCycleHelper != NULL && - _triggerCycleHelper != NULL && - _analyseCycleHelper != NULL && - _decisionCycleHelper != NULL && - _verificationCycleHelper != NULL && - _consolidationCycleHelper != NULL - // - ; - if (!result) - { - return result; - } - - // - visionCycleHelper = _visionCycleHelper; - triggerCycleHelper = _triggerCycleHelper; - analyseCycleHelper = _analyseCycleHelper; - decisionCycleHelper = _decisionCycleHelper; - verificationCycleHelper = _verificationCycleHelper; - consolidationCycleHelper = _consolidationCycleHelper; - - // - result = IsValid(); - - // - return result; - } - - // - // Prepare all ... - bool Prepare( - int barIndex = 0, - int loopback = 10, - bool trigger = false, - bool decision = true, - bool analyse = true, - bool verification = false, - bool consolidation = true, - bool vision = true // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (loopback < 7) - { - loopback = 7; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - // Trigger ... - if (trigger) - { - // - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(triggerPoiEvents); - Clean(triggerCycleEvents); - - // - triggerConditions.Clean(); - - // - return result; - } - } - - // - // Decision ... - if (decision) - { - // - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(triggerPoiEvents); - Clean(decisionPoiEvents); - Clean(triggerCycleEvents); - triggerConditions.Clean(); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - - // - return result; - } - } - - // - // Analyse ... - if (analyse) - { - // - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(triggerPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(triggerCycleEvents); - Clean(analyseCycleEvents); - triggerConditions.Clean(); - analyseConditions.Clean(); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - - // - return result; - } - } - - // - // Verification ... - if (verification) - { - // - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(triggerPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(triggerCycleEvents); - Clean(analyseCycleEvents); - triggerConditions.Clean(); - analyseConditions.Clean(); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - Clean(verificationPoiEvents); - Clean(verificationCycleEvents); - verificationConditions.Clean(); - - // - return result; - } - } - - // - // Consolidation ... - if (consolidation) - { - // - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(triggerPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(triggerCycleEvents); - Clean(analyseCycleEvents); - triggerConditions.Clean(); - analyseConditions.Clean(); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - Clean(verificationPoiEvents); - Clean(consolidationPoiEvents); - Clean(verificationCycleEvents); - verificationConditions.Clean(); - Clean(consolidationCycleEvents); - consolidationConditions.Clean(); - - // - return result; - } - } - - // - // Vision ... - if (vision) - { - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(triggerPoiEvents); - Clean(analysePoiEvents); - Clean(visionCycleEvents); - visionConditions.Clean(); - Clean(decisionPoiEvents); - Clean(triggerCycleEvents); - Clean(analyseCycleEvents); - triggerConditions.Clean(); - analyseConditions.Clean(); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - Clean(verificationPoiEvents); - Clean(consolidationPoiEvents); - Clean(verificationCycleEvents); - verificationConditions.Clean(); - Clean(consolidationCycleEvents); - consolidationConditions.Clean(); - - // - return result; - } - } - - // - // Cycles POI States ... - visionState = visionConditions.state; - triggerState = triggerConditions.state; - analyseState = analyseConditions.state; - decisionState = decisionConditions.state; - verificationState = verificationConditions.state; - consolidationState = consolidationConditions.state; - - // - // Cycle X121Conditions ... - visionXConditions = visionConditions.x121Conditions; - triggerXConditions = triggerConditions.x121Conditions; - analyseXConditions = analyseConditions.x121Conditions; - decisionXConditions = decisionConditions.x121Conditions; - verificationXConditions = verificationConditions.x121Conditions; - consolidationXConditions = consolidationConditions.x121Conditions; - - // - // Trigger ... - triggerXConditions.GenerateScore( - triggerBullishScore, - triggerBearishScore // - ); - - // - // Decision ... - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Verification ... - verificationXConditions.GenerateScore( - verificationBullishScore, - verificationBearishScore // - ); - - // - // Consolidation ... - consolidationXConditions.GenerateScore( - consolidationBullishScore, - consolidationBearishScore // - ); - - // - // Vision ... - visionXConditions.GenerateScore( - visionBullishScore, - visionBearishScore // - ); - - // - return result; - } - - // - bool SelectCycle( - ENUM_X_CYCLES cycle, - XPOIState &cState, - X121Conditions &cXConditions, - XC121SMCCycleHelper *&cHelper, - X121SMCCycleConditions &cConditions // - ) - { - // - bool result = false; - - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - result = cycle != X_CYCLE_NONE; - if (!result) - { - return result; - } - - // - if (cycle == X_CYCLE_TRIGGER) - { - // - cState = triggerState; - cHelper = triggerCycleHelper; - cConditions = triggerConditions; - cXConditions = triggerXConditions; - } - else if (cycle == X_CYCLE_DECISION) - { - // - cState = decisionState; - cHelper = decisionCycleHelper; - cConditions = decisionConditions; - cXConditions = decisionXConditions; - } - else if (cycle == X_CYCLE_ANALYSE) - { - // - cState = analyseState; - cHelper = analyseCycleHelper; - cConditions = analyseConditions; - cXConditions = analyseXConditions; - } - else if (cycle == X_CYCLE_VERIFICATION) - { - // - cState = verificationState; - cHelper = verificationCycleHelper; - cConditions = verificationConditions; - cXConditions = verificationXConditions; - } - else if (cycle == X_CYCLE_CONSOLIDATION) - { - // - cState = consolidationState; - cHelper = consolidationCycleHelper; - cConditions = consolidationConditions; - cXConditions = consolidationXConditions; - } - else if (cycle == X_CYCLE_VISION) - { - // - cState = visionState; - cHelper = visionCycleHelper; - cConditions = visionConditions; - cXConditions = visionXConditions; - } - - // - result = cState.IsValid() && - cHelper != NULL; - - // - return result; - } - - // - void MaxRequiredPOIs(int value) - { - // - if (!IsValid()) - { - return; - } - - // - visionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - } - - // - void MaxAllowedLoopbackForInit(int value) - { - // - if (!IsValid()) - { - return; - } - - // - visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - } - - // -}; - -// -// Condition Parser ... -struct X121SMCStrategyConditionParser -{ - // - // Props ... - - // - // XSAR ... - - // - bool isSarBullishOverPeaksGoldenZone; - bool isSarSwitchedToBullishOverPeaksGoldenZone; - bool isSarBearishOverPeaksGoldenZone; - bool isSarSwitchedToBearishOverPeaksGoldenZone; - bool isSarBullishUnderValesGoldenZone; - bool isSarSwitchedToBullishUnderValesGoldenZone; - bool isSarBearishUnderValesGoldenZone; - bool isSarSwitchedToBearishUnderValesGoldenZone; - - // - // XMA ... - - // - bool isX3MaFastUnderValesGoldenZone; - bool isX3MaFastCrossedUnderValesGoldenZone; - bool isX3MaFastOverPeaksGoldenZone; - bool isX3MaFastCrossedOverPeaksGoldenZone; - - // - bool isX3MaInsidePeaksGoldenZone; - bool isX3MaCrossedInsidePeaksGoldenZone; - bool isX3MaInsideValesGoldenZone; - bool isX3MaCrossedInsideValesGoldenZone; - - // - bool isX3MaBullishStateOverPeaksGoldenZone; - bool isX3MaBearishStateOverPeaksGoldenZone; - bool isX3MaSwitchedToBullishStateOverPeaksGoldenZone; - bool isX3MaSwitchedToBearishStateOverPeaksGoldenZone; - - // - bool isX3MaBullishOrderedOverPeaksGoldenZone; - bool isX3MaBearishOrderedOverPeaksGoldenZone; - bool isX3MaSwitchedToBullishOrderedOverPeaksGoldenZone; - bool isX3MaSwitchedToBearishOrderedOverPeaksGoldenZone; - - // - bool isX3MaBullishStateUnderValesGoldenZone; - bool isX3MaBearishStateUnderValesGoldenZone; - bool isX3MaSwitchedToBullishStateUnderValesGoldenZone; - bool isX3MaSwitchedToBearishStateUnderValesGoldenZone; - - // - bool isX3MaBullishOrderedUnderValesGoldenZone; - bool isX3MaBearishOrderedUnderValesGoldenZone; - bool isX3MaSwitchedToBullishOrderedUnderValesGoldenZone; - bool isX3MaSwitchedToBearishOrderedUnderValesGoldenZone; - - // - // XVWAP ... - - // - bool isVWapFastUnderValesGoldenZone; - bool isVWapFastCrossedUnderValesGoldenZone; - bool isVWapFastOverPeaksGoldenZone; - bool isVWapFastCrossedOverPeaksGoldenZone; - - // - bool isVWapInsidePeaksGoldenZone; - bool isVWapCrossedInsidePeaksGoldenZone; - bool isVWapInsideValesGoldenZone; - bool isVWapCrossedInsideValesGoldenZone; - - // - bool isVWapBullishStateOverPeaksGoldenZone; - bool isVWapBearishStateOverPeaksGoldenZone; - bool isVWapSwitchedToBullishStateOverPeaksGoldenZone; - bool isVWapSwitchedToBearishStateOverPeaksGoldenZone; - - // - bool isVWapBullishOrderedOverPeaksGoldenZone; - bool isVWapBearishOrderedOverPeaksGoldenZone; - bool isVWapSwitchedToBullishOrderedOverPeaksGoldenZone; - bool isVWapSwitchedToBearishOrderedOverPeaksGoldenZone; - - // - bool isVWapBullishStateUnderValesGoldenZone; - bool isVWapBearishStateUnderValesGoldenZone; - bool isVWapSwitchedToBullishStateUnderValesGoldenZone; - bool isVWapSwitchedToBearishStateUnderValesGoldenZone; - - // - bool isVWapBullishOrderedUnderValesGoldenZone; - bool isVWapBearishOrderedUnderValesGoldenZone; - bool isVWapSwitchedToBullishOrderedUnderValesGoldenZone; - bool isVWapSwitchedToBearishOrderedUnderValesGoldenZone; - - // - // XHK ... - - // - // XRWHK ... - - // - bool isRawHKBearishOverPeaksGoldenZone; - bool isRawHKSwitchedToBearishOverPeaksGoldenZone; - bool isRawHKBullishUnderValesGoldenZone; - bool isRawHKSwitchedToBullishUnderValesGoldenZone; - - // - // XSMHK ... - - // - bool isSMHKBearishOverPeaksGoldenZone; - bool isSMHKSwitchedToBearishOverPeaksGoldenZone; - bool isSMHKBullishUnderValesGoldenZone; - bool isSMHKSwitchedToBullishUnderValesGoldenZone; - - // - // XATR ... - - // - bool isAtrUpperOverPeaksGoldenZone; - bool isAtrLowerOverPeaksGoldenZone; - bool isAtrOverPeaksGoldenZone; - bool isAtrCrossedOverPeaksGoldenZone; - - // - bool isAtrUpperUnderValesGoldenZone; - bool isAtrLowerUnderValesGoldenZone; - bool isAtrUnderValesGoldenZone; - bool isAtrCrossedUnderValesGoldenZone; - - // - // XSTR ... - - // - bool isStrBullishOverPeaksGoldenZone; - bool isStrBearishOverPeaksGoldenZone; - bool isStrSwitchedToBullishOverPeaksGoldenZone; - bool isStrSwitchedToBearishOverPeaksGoldenZone; - - // - bool isStrBullishUnderValesGoldenZone; - bool isStrBearishUnderValesGoldenZone; - bool isStrSwitchedToBullishUnderValesGoldenZone; - bool isStrSwitchedToBearishUnderValesGoldenZone; - - // - // XCHE ... - - // - bool isCheBullishOverPeaksGoldenZone; - bool isCheBearishOverPeaksGoldenZone; - bool isCheSwitchedBullishOverPeaksGoldenZone; - bool isCheSwitchedBearishOverPeaksGoldenZone; - - // - bool isCheBullishUnderValesGoldenZone; - bool isCheBearishUnderValesGoldenZone; - bool isCheSwitchedBullishUnderValesGoldenZone; - bool isCheSwitchedBearishUnderValesGoldenZone; - - // - // Constructor ... - X121SMCStrategyConditionParser() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - // XSAR ... - - // - isSarBullishOverPeaksGoldenZone = false; - isSarSwitchedToBullishOverPeaksGoldenZone = false; - isSarBearishOverPeaksGoldenZone = false; - isSarSwitchedToBearishOverPeaksGoldenZone = false; - isSarBullishUnderValesGoldenZone = false; - isSarSwitchedToBullishUnderValesGoldenZone = false; - isSarBearishUnderValesGoldenZone = false; - isSarSwitchedToBearishUnderValesGoldenZone = false; - - // - // X3MA ... - - // - isX3MaFastUnderValesGoldenZone = false; - isX3MaFastCrossedUnderValesGoldenZone = false; - isX3MaFastOverPeaksGoldenZone = false; - isX3MaFastCrossedOverPeaksGoldenZone = false; - - // - isX3MaInsidePeaksGoldenZone = false; - isX3MaCrossedInsidePeaksGoldenZone = false; - isX3MaInsideValesGoldenZone = false; - isX3MaCrossedInsideValesGoldenZone = false; - - // - isX3MaBullishStateOverPeaksGoldenZone = false; - isX3MaBearishStateOverPeaksGoldenZone = false; - isX3MaSwitchedToBullishStateOverPeaksGoldenZone = false; - isX3MaSwitchedToBearishStateOverPeaksGoldenZone = false; - - // - isX3MaBullishOrderedOverPeaksGoldenZone = false; - isX3MaBearishOrderedOverPeaksGoldenZone = false; - isX3MaSwitchedToBullishOrderedOverPeaksGoldenZone = false; - isX3MaSwitchedToBearishOrderedOverPeaksGoldenZone = false; - - // - isX3MaBullishStateUnderValesGoldenZone = false; - isX3MaBearishStateUnderValesGoldenZone = false; - isX3MaSwitchedToBullishStateUnderValesGoldenZone = false; - isX3MaSwitchedToBearishStateUnderValesGoldenZone = false; - - // - isX3MaBullishOrderedUnderValesGoldenZone = false; - isX3MaBearishOrderedUnderValesGoldenZone = false; - isX3MaSwitchedToBullishOrderedUnderValesGoldenZone = false; - isX3MaSwitchedToBearishOrderedUnderValesGoldenZone = false; - - // - // XVWAP ... - - // - isVWapFastUnderValesGoldenZone = false; - isVWapFastCrossedUnderValesGoldenZone = false; - isVWapFastOverPeaksGoldenZone = false; - isVWapFastCrossedOverPeaksGoldenZone = false; - - // - isVWapInsidePeaksGoldenZone = false; - isVWapCrossedInsidePeaksGoldenZone = false; - isVWapInsideValesGoldenZone = false; - isVWapCrossedInsideValesGoldenZone = false; - - // - isVWapBullishStateOverPeaksGoldenZone = false; - isVWapBearishStateOverPeaksGoldenZone = false; - isVWapSwitchedToBullishStateOverPeaksGoldenZone = false; - isVWapSwitchedToBearishStateOverPeaksGoldenZone = false; - - // - isVWapBullishOrderedOverPeaksGoldenZone = false; - isVWapBearishOrderedOverPeaksGoldenZone = false; - isVWapSwitchedToBullishOrderedOverPeaksGoldenZone = false; - isVWapSwitchedToBearishOrderedOverPeaksGoldenZone = false; - - // - isVWapBullishStateUnderValesGoldenZone = false; - isVWapBearishStateUnderValesGoldenZone = false; - isVWapSwitchedToBullishStateUnderValesGoldenZone = false; - isVWapSwitchedToBearishStateUnderValesGoldenZone = false; - - // - isVWapBullishOrderedUnderValesGoldenZone = false; - isVWapBearishOrderedUnderValesGoldenZone = false; - isVWapSwitchedToBullishOrderedUnderValesGoldenZone = false; - isVWapSwitchedToBearishOrderedUnderValesGoldenZone = false; - - // - // XHK ... - - // - // XRWHK ... - - // - isRawHKBearishOverPeaksGoldenZone = false; - isRawHKSwitchedToBearishOverPeaksGoldenZone = false; - isRawHKBullishUnderValesGoldenZone = false; - isRawHKSwitchedToBullishUnderValesGoldenZone = false; - - // - // XSMHK ... - - // - isSMHKBearishOverPeaksGoldenZone = false; - isSMHKSwitchedToBearishOverPeaksGoldenZone = false; - isSMHKBullishUnderValesGoldenZone = false; - isSMHKSwitchedToBullishUnderValesGoldenZone = false; - - // - // XATR ... - - // - isAtrUpperOverPeaksGoldenZone = false; - isAtrLowerOverPeaksGoldenZone = false; - isAtrOverPeaksGoldenZone = false; - isAtrCrossedOverPeaksGoldenZone = false; - - // - isAtrUpperUnderValesGoldenZone = false; - isAtrLowerUnderValesGoldenZone = false; - isAtrUnderValesGoldenZone = false; - isAtrCrossedUnderValesGoldenZone = false; - - // - // XSTR ... - - // - isStrBullishOverPeaksGoldenZone = false; - isStrBearishOverPeaksGoldenZone = false; - isStrSwitchedToBullishOverPeaksGoldenZone = false; - isStrSwitchedToBearishOverPeaksGoldenZone = false; - - // - isStrBullishUnderValesGoldenZone = false; - isStrBearishUnderValesGoldenZone = false; - isStrSwitchedToBullishUnderValesGoldenZone = false; - isStrSwitchedToBearishUnderValesGoldenZone = false; - - // - // XCHE ... - - // - isCheBullishOverPeaksGoldenZone = false; - isCheBearishOverPeaksGoldenZone = false; - isCheSwitchedBullishOverPeaksGoldenZone = false; - isCheSwitchedBearishOverPeaksGoldenZone = false; - - // - isCheBullishUnderValesGoldenZone = false; - isCheBearishUnderValesGoldenZone = false; - isCheSwitchedBullishUnderValesGoldenZone = false; - isCheSwitchedBearishUnderValesGoldenZone = false; - - // - ZeroMemory(this); - } - - // - void Parse( - X121Conditions &conditions // - ) - { - // - Clean(); - - // - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - // XSAR ... - - // - isSarBullishOverPeaksGoldenZone = - conditions.isSarBullish && - conditions.sarBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isSarSwitchedToBullishOverPeaksGoldenZone = - conditions.isSarSwitchedToBullish && - conditions.sarBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isSarBearishOverPeaksGoldenZone = - conditions.isSarBearish && - conditions.sarBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isSarSwitchedToBearishOverPeaksGoldenZone = - conditions.isSarSwitchedToBearish && - conditions.sarBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isSarBullishUnderValesGoldenZone = - conditions.isSarBullish && - conditions.sarBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isSarSwitchedToBullishUnderValesGoldenZone = - conditions.isSarSwitchedToBullish && - conditions.sarBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isSarBearishUnderValesGoldenZone = - conditions.isSarBearish && - conditions.sarBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isSarSwitchedToBearishUnderValesGoldenZone = - conditions.isSarSwitchedToBearish && - conditions.sarBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - // X3MA ... - - // - isX3MaFastUnderValesGoldenZone = - conditions.x3maFastBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isX3MaFastCrossedUnderValesGoldenZone = - isX3MaFastUnderValesGoldenZone && - conditions.x3maFastBuffer[pIDX] >= conditions.valesGoldenBuffer[pIDX]; - - // - isX3MaFastOverPeaksGoldenZone = - conditions.x3maFastBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isX3MaFastCrossedOverPeaksGoldenZone = - isX3MaFastOverPeaksGoldenZone && - conditions.x3maFastBuffer[pIDX] <= conditions.peaksGoldenBuffer[pIDX]; - - // - isX3MaInsidePeaksGoldenZone = - // - conditions.x3maMin < conditions.peaksBuffer[cIDX] && - conditions.x3maMin > conditions.peaksGoldenBuffer[cIDX] && - // - conditions.x3maMax < conditions.peaksBuffer[cIDX] && - conditions.x3maMax > conditions.peaksGoldenBuffer[cIDX] - // - ; - - // - isX3MaCrossedInsidePeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - !( - // - conditions.x3maMin < conditions.peaksBuffer[pIDX] && - conditions.x3maMin > conditions.peaksGoldenBuffer[pIDX] && - // - conditions.x3maMax < conditions.peaksBuffer[pIDX] && - conditions.x3maMax > conditions.peaksGoldenBuffer[pIDX] - // - ); - - // - isX3MaInsideValesGoldenZone = - // - conditions.x3maMin > conditions.valesBuffer[cIDX] && - conditions.x3maMin < conditions.valesGoldenBuffer[cIDX] && - // - conditions.x3maMax > conditions.valesBuffer[cIDX] && - conditions.x3maMax < conditions.valesGoldenBuffer[cIDX] - // - ; - - isX3MaCrossedInsideValesGoldenZone = - isX3MaInsideValesGoldenZone && - !( - // - conditions.x3maMin > conditions.valesBuffer[pIDX] && - conditions.x3maMin < conditions.valesGoldenBuffer[pIDX] && - // - conditions.x3maMax > conditions.valesBuffer[pIDX] && - conditions.x3maMax < conditions.valesGoldenBuffer[pIDX] - // - ); - - // - isX3MaBullishStateOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaBullishState; - - // - isX3MaBearishStateOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaBearishState; - - // - isX3MaSwitchedToBullishStateOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaSwitchedToBullishState; - - // - isX3MaSwitchedToBearishStateOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaSwitchedToBearishState; - - // - isX3MaBullishOrderedOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaBullishOrdered; - - // - isX3MaBearishOrderedOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaBearishOrdered; - - // - isX3MaSwitchedToBullishOrderedOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaSwitchedToBullishOrdered; - - // - isX3MaSwitchedToBearishOrderedOverPeaksGoldenZone = - isX3MaInsidePeaksGoldenZone && - conditions.isX3MaSwitchedToBearishOrdered; - - // - isX3MaBullishStateUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaBullishState; - - // - isX3MaBearishStateUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaBearishState; - - // - isX3MaSwitchedToBullishStateUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaSwitchedToBullishState; - - // - isX3MaSwitchedToBearishStateUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaSwitchedToBearishState; - - // - isX3MaBullishOrderedUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaBullishOrdered; - - // - isX3MaBearishOrderedUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaBearishOrdered; - - // - isX3MaSwitchedToBullishOrderedUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaSwitchedToBullishOrdered; - - // - isX3MaSwitchedToBearishOrderedUnderValesGoldenZone = - isX3MaInsideValesGoldenZone && - conditions.isX3MaSwitchedToBearishOrdered; - - // - // XVWAP ... - - // - isVWapFastUnderValesGoldenZone = - conditions.vwapFastBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isVWapFastCrossedUnderValesGoldenZone = - isVWapFastUnderValesGoldenZone && - conditions.vwapFastBuffer[pIDX] >= conditions.valesGoldenBuffer[pIDX]; - - // - isVWapFastOverPeaksGoldenZone = - conditions.vwapFastBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isVWapFastCrossedOverPeaksGoldenZone = - isVWapFastOverPeaksGoldenZone && - conditions.vwapFastBuffer[pIDX] <= conditions.peaksGoldenBuffer[pIDX]; - - // - isVWapInsidePeaksGoldenZone = - // - conditions.vwapMin < conditions.peaksBuffer[cIDX] && - conditions.vwapMin > conditions.peaksGoldenBuffer[cIDX] && - // - conditions.vwapMax < conditions.peaksBuffer[cIDX] && - conditions.vwapMax > conditions.peaksGoldenBuffer[cIDX] - // - ; - - // - isVWapCrossedInsidePeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - !( - // - conditions.vwapMin < conditions.peaksBuffer[pIDX] && - conditions.vwapMin > conditions.peaksGoldenBuffer[pIDX] && - // - conditions.vwapMax < conditions.peaksBuffer[pIDX] && - conditions.vwapMax > conditions.peaksGoldenBuffer[pIDX] - // - ); - - // - isVWapInsideValesGoldenZone = - // - conditions.vwapMin > conditions.valesBuffer[cIDX] && - conditions.vwapMin < conditions.valesGoldenBuffer[cIDX] && - // - conditions.vwapMax > conditions.valesBuffer[cIDX] && - conditions.vwapMax < conditions.valesGoldenBuffer[cIDX] - // - ; - - // - isVWapCrossedInsideValesGoldenZone = - isVWapInsideValesGoldenZone && - !( - // - conditions.vwapMin > conditions.valesBuffer[pIDX] && - conditions.vwapMin < conditions.valesGoldenBuffer[pIDX] && - // - conditions.vwapMax > conditions.valesBuffer[pIDX] && - conditions.vwapMax < conditions.valesGoldenBuffer[pIDX] - // - ); - - // - isVWapBullishStateOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapBullishState; - - // - isVWapBearishStateOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapBearishState; - - // - isVWapSwitchedToBullishStateOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapSwitchedToBullishState; - - // - isVWapSwitchedToBearishStateOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapSwitchedToBearishState; - - // - isVWapBullishOrderedOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapBullishOrdered; - - // - isVWapBearishOrderedOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapBearishOrdered; - - // - isVWapSwitchedToBullishOrderedOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapSwitchedToBullishOrdered; - - // - isVWapSwitchedToBearishOrderedOverPeaksGoldenZone = - isVWapInsidePeaksGoldenZone && - conditions.isVWapSwitchedToBearishOrdered; - - // - isVWapBullishStateUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapBullishState; - - // - isVWapBearishStateUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapBearishState; - - // - isVWapSwitchedToBullishStateUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapSwitchedToBullishState; - - // - isVWapSwitchedToBearishStateUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapSwitchedToBearishState; - - // - isVWapBullishOrderedUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapBullishOrdered; - - // - isVWapBearishOrderedUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapBearishOrdered; - - // - isVWapSwitchedToBullishOrderedUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapSwitchedToBullishOrdered; - - // - isVWapSwitchedToBearishOrderedUnderValesGoldenZone = - isVWapInsideValesGoldenZone && - conditions.isVWapSwitchedToBearishOrdered; - - // - // XHK ... - - // - // XRWHK ... - - // - isRawHKBearishOverPeaksGoldenZone = - conditions.isRawHKBearish && - conditions.xhkRawHighBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isRawHKSwitchedToBearishOverPeaksGoldenZone = - conditions.isRawHKSwitchedToBearish && - conditions.xhkRawHighBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isRawHKBullishUnderValesGoldenZone = - conditions.isRawHKBullish && - conditions.xhkRawLowBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isRawHKSwitchedToBullishUnderValesGoldenZone = - conditions.isRawHKSwitchedToBullish && - conditions.xhkRawLowBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - // XSMHK ... - - // - isSMHKBearishOverPeaksGoldenZone = - conditions.isSMHKBearish && - conditions.xhkSMHighBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isSMHKSwitchedToBearishOverPeaksGoldenZone = - conditions.isSMHKSwitchedToBearish && - conditions.xhkSMHighBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isSMHKBullishUnderValesGoldenZone = - conditions.isSMHKBullish && - conditions.xhkSMLowBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isSMHKSwitchedToBullishUnderValesGoldenZone = - conditions.isSMHKSwitchedToBullish && - conditions.xhkSMLowBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - // XATR ... - - // - isAtrUpperOverPeaksGoldenZone = - conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.atrUpperBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isAtrLowerOverPeaksGoldenZone = - conditions.atrLowerBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.atrLowerBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isAtrOverPeaksGoldenZone = - isAtrUpperOverPeaksGoldenZone && - isAtrLowerOverPeaksGoldenZone; - - // - isAtrCrossedOverPeaksGoldenZone = - isAtrOverPeaksGoldenZone && - !( - // - conditions.atrUpperBuffer[pIDX] < conditions.peaksBuffer[pIDX] && - conditions.atrUpperBuffer[pIDX] > conditions.peaksGoldenBuffer[pIDX] - // - && - // - conditions.atrLowerBuffer[pIDX] < conditions.peaksBuffer[pIDX] && - conditions.atrLowerBuffer[pIDX] > conditions.peaksGoldenBuffer[pIDX] - // - ); - - // - isAtrUpperUnderValesGoldenZone = - conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX] && - conditions.atrUpperBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isAtrLowerUnderValesGoldenZone = - conditions.atrLowerBuffer[cIDX] > conditions.valesBuffer[cIDX] && - conditions.atrLowerBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isAtrUnderValesGoldenZone = - isAtrUpperUnderValesGoldenZone && - isAtrLowerUnderValesGoldenZone; - - // - isAtrCrossedUnderValesGoldenZone = - isAtrUnderValesGoldenZone && - !( - // - conditions.atrUpperBuffer[pIDX] > conditions.valesBuffer[pIDX] && - conditions.atrUpperBuffer[pIDX] < conditions.valesGoldenBuffer[pIDX] - // - && - // - conditions.atrLowerBuffer[pIDX] > conditions.valesBuffer[pIDX] && - conditions.atrLowerBuffer[pIDX] < conditions.valesGoldenBuffer[pIDX] - // - ); - - // - // XSTR ... - - // - isStrBullishOverPeaksGoldenZone = - conditions.isStrBullish && - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.strBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isStrBearishOverPeaksGoldenZone = - conditions.isStrBearish && - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.strBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isStrSwitchedToBullishOverPeaksGoldenZone = - conditions.isStrSwitchedToBullish && - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.strBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isStrSwitchedToBearishOverPeaksGoldenZone = - conditions.isStrSwitchedToBearish && - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.strBuffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isStrBullishUnderValesGoldenZone = - conditions.isStrBullish && - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && - conditions.strBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isStrBearishUnderValesGoldenZone = - conditions.isStrBearish && - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && - conditions.strBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isStrSwitchedToBullishUnderValesGoldenZone = - conditions.isStrSwitchedToBullish && - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && - conditions.strBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - isStrSwitchedToBearishUnderValesGoldenZone = - conditions.isStrSwitchedToBearish && - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && - conditions.strBuffer[cIDX] < conditions.valesGoldenBuffer[cIDX]; - - // - // XCHE ... - - // - isCheBullishOverPeaksGoldenZone = - conditions.isCheBullish && - conditions.le1Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.le1Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX] && - conditions.le2Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.le2Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isCheBearishOverPeaksGoldenZone = - conditions.isCheSwitchedToBullish && - conditions.se1Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.se1Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX] && - conditions.se2Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.se2Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isCheSwitchedBullishOverPeaksGoldenZone = - conditions.isCheSwitchedToBullish && - conditions.le1Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.le1Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX] && - conditions.le2Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.le2Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isCheSwitchedBearishOverPeaksGoldenZone = - conditions.isCheSwitchedToBearish && - conditions.se1Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.se1Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX] && - conditions.se2Buffer[cIDX] < conditions.peaksBuffer[cIDX] && - conditions.se2Buffer[cIDX] > conditions.peaksGoldenBuffer[cIDX]; - - // - isCheBullishUnderValesGoldenZone = - conditions.isCheBullish && - conditions.cheMin > conditions.valesBuffer[cIDX] && - conditions.cheMin < conditions.valesGoldenBuffer[cIDX] && - conditions.cheMax > conditions.valesBuffer[cIDX] && - conditions.cheMax < conditions.valesGoldenBuffer[cIDX]; - - // - isCheBearishUnderValesGoldenZone = - conditions.isCheBearish && - conditions.cheMin > conditions.valesBuffer[cIDX] && - conditions.cheMin < conditions.valesGoldenBuffer[cIDX] && - conditions.cheMax > conditions.valesBuffer[cIDX] && - conditions.cheMax < conditions.valesGoldenBuffer[cIDX]; - - // - isCheSwitchedBullishUnderValesGoldenZone = - conditions.isCheSwitchedToBullish && - conditions.cheMin > conditions.valesBuffer[cIDX] && - conditions.cheMin < conditions.valesGoldenBuffer[cIDX] && - conditions.cheMax > conditions.valesBuffer[cIDX] && - conditions.cheMax < conditions.valesGoldenBuffer[cIDX]; - - // - isCheSwitchedBearishUnderValesGoldenZone = - conditions.isCheSwitchedToBearish && - conditions.cheMin > conditions.valesBuffer[cIDX] && - conditions.cheMin < conditions.valesGoldenBuffer[cIDX] && - conditions.cheMax > conditions.valesBuffer[cIDX] && - conditions.cheMax < conditions.valesGoldenBuffer[cIDX]; - } - - // - bool HasSenario1Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - cXConditions.supportsBuffer[cIDX] == cXConditions.valesBuffer[zIDX] - // - // cXConditions.isSarSwitchedToBullish && - // cXConditions.isSMHKSwitchedToBullish && - // cBar.low < cXConditions.masLowerBuffer[cIDX] && - // cBar.low < cXConditions.valesGoldenBuffer[cIDX] && - // zBar.close < cXConditions.valesGoldenBuffer[cIDX] && - // cXConditions.xhkSMCloseBuffer[cIDX] < cXConditions.valesGoldenBuffer[cIDX] - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - false - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Fix Box Upper and Lower based on Strategy ... - - // - double points = GetPoints(box.symbol); - double minPointsDiff = points * 20; - - // - double prefferSL = 0; - - // - // Other SL Conditions ... - if (prefferSL <= 0) - { - // - if (isBullish) - { - // - if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesBuffer[cIDX]; - } - else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX] && - zBar.open < cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - else if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - // - if (cXConditions.sarBuffer[cIDX] > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.sarBuffer[cIDX]; - } - else - { - prefferSL = zBar.open > cXConditions.peaksGoldenBuffer[cIDX]; - } - } - } - else - { - // - if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksBuffer[cIDX]; - } - else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX] && - zBar.open > cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksGoldenBuffer[cIDX]; - } - else if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - // - if (cXConditions.sarBuffer[cIDX] < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.sarBuffer[cIDX]; - } - else - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - } - } - } - - // - if (prefferSL > 0) - { - // - box.upper = - isBullish - ? zBar.open - : prefferSL; - - // - box.lower = - isBullish - ? prefferSL - : zBar.open; - } - - // - // Validate Conditions to Force Has Holder Box ... - - result = - result && - holderBox.IsValid() && - dir == holderBox.dir; - - // - if (!result) - { - // - isBullish = false; - isBearish = false; - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - bool HasSenario2Conditions( - ENUM_X_CYCLES ttfCycle, - XBoxZone &breakedBoxes[], - XBoxZone &box, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0, - bool forceBarType = false, - bool forceFiboPressure = false // - ) - { - // - bool result = false; - - // - // Validate Args ... - result = - IsValid(ttfCycle) && - HasChild(breakedBoxes); - if (!result) - { - return result; - } - - // - // TODO: Add support for Extracting Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // TTF Cycle Extract ... - XPOIState ttfState; - X121Conditions ttfXConditions; - XC121SMCCycleHelper *ttfHelper; - X121SMCCycleConditions ttfConditions; - result = provider.SelectCycle( - ttfCycle, - ttfState, - ttfXConditions, - ttfHelper, - ttfConditions // - ); - if (!result) - { - // - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - Parse(ttfXConditions); - - // - // Normalize Args ... - - // - box.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Define Resources ... - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - double ask = GetAsk(ttfState.symbol); - double bid = GetBid(ttfState.symbol); - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - ttfState.symbol, - ttfState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - - // - // Conditions ... - - // - // First we Have to Detect Inside Box ... - XBoxZone insideBox; - count = ArraySize(breakedBoxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = breakedBoxes[i]; - - // - bool isInside = - IsInsideBox( - zBar, - iBox // - ); - if (isInside) - { - // - // Since we have to Follow Trend based on Breaked Boxes ... - // we have to use: - // - Breaked Bullish Boxes on Bearish Trend ... - // - Breaked Bearish Boxes on Bullish Trend ... - isInside = - hasBullishTrend - ? iBox.IsBearish() - : hasBearishTrend - ? iBox.IsBullish() - : false; - - // - // Check Inside ... - if (isInside) - { - // - insideBox = iBox; - iBox.Clean(); - - // - break; - } - } - - // - iBox.Clean(); - } - - // - // Check Inside Box is Valid or not ... - result = insideBox.IsValid(); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ttfState.Clean(); - insideBox.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - } - - // - // Update Inside Box From and To ... - // Based on Breaked ... - insideBox.from = insideBox.to; - insideBox.to = TimeCurrent(); - - // - // Detect Breaked Box Direction ... - bool isInsideBoxBullish = insideBox.IsBullish(); - bool isInsideBoxBearish = insideBox.IsBearish(); - - // - // Detect Inside Box Rejection ... - - // - bool isUpperBearishReject = - cBar.high >= insideBox.upper && - cBar.GetUp() < insideBox.upper; - - // - bool isUpperBullishReject = - cBar.low <= insideBox.upper && - cBar.GetDown() > insideBox.upper; - - // - bool isLowerBearishReject = - cBar.high >= insideBox.lower && - cBar.GetUp() < insideBox.lower; - - // - bool isLowerBullishReject = - cBar.low <= insideBox.lower && - cBar.GetDown() > insideBox.lower; - - // - // Apply Force Bar Type ... - if (forceBarType) - { - // - isUpperBearishReject = - isUpperBearishReject && - cBar.IsBearish(); - - // - isUpperBullishReject = - isUpperBullishReject && - cBar.IsBullish(); - - // - isLowerBearishReject = - isLowerBearishReject && - cBar.IsBearish(); - - // - isLowerBullishReject = - isLowerBullishReject && - cBar.IsBullish(); - } - - // - // Apply Force Fibo Pressure ... - if (forceBarType) - { - // - isUpperBearishReject = - isUpperBearishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - isUpperBullishReject = - isUpperBullishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - isLowerBearishReject = - isLowerBearishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - isLowerBullishReject = - isLowerBullishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - } - - // - // Bullish Conditions ... - isBullish = ( - // - hasBullishTrend && - isInsideBoxBearish && - isLowerBullishReject - // - ); - - // - // Bearish Conditions ... - isBearish = ( - // - hasBearishTrend && - isInsideBoxBullish && - isUpperBearishReject - // - ); - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - box = insideBox; - - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish // - ); - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - ttfState.Clean(); - insideBox.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - - // - bool HasSenario4Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - cBar.IsBullish() && - zBar.open >= cBar.close && - ( - // - // Regular Reject ... - (pBar.low > cBar.low && - cBar.low < cXConditions.valesGoldenBuffer[cIDX] && - cBar.GetDown() > cXConditions.valesGoldenBuffer[cIDX]) - // - || - // - // Regular Exit ... - (pBar.low < cXConditions.valesGoldenBuffer[cIDX] && - (cBar.low > cXConditions.valesGoldenBuffer[cIDX] || - cBar.GetUp() > cXConditions.valesGoldenBuffer[cIDX])) - // - || - // - IsBarBreak( - cXConditions.valesGoldenBuffer[cIDX], - X_DIRECTION_BULLISH, - cBar // - ) - // - || - // - IsBarReject( - cXConditions.valesGoldenBuffer[cIDX], - X_DIRECTION_BULLISH, - cBar // - ) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSAR ... - cXConditions.isSarBullish && - // - // XSTR ... - cXConditions.isStrSwitchedToBullish && - // - // // X3MA ... - // // XVWAP ... - // (cXConditions.isX3MaFastOverMid || - // cXConditions.isVWapFastOverMid) && - // - // XHK ... - cXConditions.isSMHKBullish && - cXConditions.isRawHKBullish && - // - // XCHE ... - cXConditions.isCheBullish && - cXConditions.le1Buffer[cIDX] < cBar.low && - cXConditions.le2Buffer[cIDX] < cBar.low - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - cBar.IsBearish() && - zBar.open <= cBar.close && - ( - // - // Regular Reject ... - (pBar.high < cBar.high && - cBar.high > cXConditions.peaksGoldenBuffer[cIDX] && - cBar.GetUp() < cXConditions.peaksGoldenBuffer[cIDX]) - // - || - // - // Regular Exit ... - (pBar.high > cXConditions.peaksGoldenBuffer[cIDX] && - (cBar.high < cXConditions.peaksGoldenBuffer[cIDX] || - cBar.GetDown() < cXConditions.peaksGoldenBuffer[cIDX])) - // - || - // - IsBarBreak( - cXConditions.peaksGoldenBuffer[cIDX], - X_DIRECTION_BEARISH, - cBar // - ) - // - || - // - IsBarReject( - cXConditions.peaksGoldenBuffer[cIDX], - X_DIRECTION_BEARISH, - cBar // - ) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSAR ... - cXConditions.isSarBearish && - // - // XSTR ... - cXConditions.isStrSwitchedToBearish && - // - // // X3MA ... - // // XVWAP ... - // (cXConditions.isX3MaFastUnderMid || - // cXConditions.isVWapFastUnderMid) && - // - // XHK ... - cXConditions.isSMHKBearish && - cXConditions.isRawHKBearish && - // - // XCHE ... - cXConditions.isCheBearish && - cXConditions.se1Buffer[cIDX] > cBar.high && - cXConditions.se2Buffer[cIDX] > cBar.high - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Validate Conditions to Force Has Holder Box ... - result = - result && - holderBox.IsValid(); - if (!result) - { - // - isBullish = false; - isBearish = false; - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // -}; diff --git a/Documents/BKP/x-cmn.tmp.codes.mq5 b/Documents/BKP/x-cmn.tmp.codes.mq5 deleted file mode 100644 index 3363ee05..00000000 --- a/Documents/BKP/x-cmn.tmp.codes.mq5 +++ /dev/null @@ -1,1413 +0,0 @@ - -// -// Calculate TP/SL for Specified Type of Positions ... -void CalculateTPSL( - double &mSL, // Hold SL - double &mTP, // Hold TP - ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) - double mEntry, // Entry Price - double mR2R = 1, // Provided Risk To Reward Ratio - double slPrice = 0, // Provided SL Price - double tpPrice = 0, // Provided TP Price - double priceToRisk = 0, // If Entry equal to Provided SL Price Risk Point - double priceToReward = 0 // If Entry equal to Provided TP Price Reward Point -) -{ - // - // if Both TP and SL Provided, ignore R2R and Calculate direct ... - // if SL provided, Calculate TP based on Provided R2R ... - // if TP provided, Calculate SL based on Provided R2R ... - // default R2R is set to 1 ... - - // - mSL = 0; - mTP = 0; - - // - bool isLong = IsLong(mType); - - // - // Set Default R2R ... - if (mR2R < 1) - { - mR2R = 1; - } - - // - if (mEntry <= 0 || - (tpPrice <= 0 && slPrice <= 0)) - { - return; - } - - // - double risk = 0; - double reward = 0; - - // - bool canCalculateBasedOnSL = slPrice > 0 && - (isLong - ? slPrice <= mEntry - : slPrice >= mEntry); - - // - bool canCalculateBasedOnTP = tpPrice > 0 && - (isLong - ? tpPrice >= mEntry - : tpPrice <= mEntry); - - // - if (canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - risk = MathAbs(mEntry - slPrice); - if (risk == 0) - { - risk = priceToRisk; - } - reward = risk * mR2R; - } - else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = MathAbs(mEntry - tpPrice); - if (reward == 0) - { - reward = priceToReward; - } - risk = reward / mR2R; - } - else if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - bool canSetTPPrice = isLong - ? tpPrice > mEntry - : tpPrice < mEntry; - if (canSetTPPrice) - { - mTP = tpPrice; - } - - // - bool canSetSLPrice = isLong - ? slPrice < mEntry - : slPrice > mEntry; - if (canSetSLPrice) - { - mSL = slPrice; - } - - // - return; - } - else if (canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - bool canSetTPPrice = isLong - ? tpPrice > mEntry - : tpPrice < mEntry; - if (canSetTPPrice) - { - mTP = tpPrice; - } - - // - bool canSetSLPrice = isLong - ? slPrice < mEntry - : slPrice > mEntry; - if (canSetSLPrice) - { - mSL = slPrice; - } - - // - return; - } - - // - mTP = isLong - ? mEntry + reward - : mEntry - reward; - - // - mSL = isLong - ? mEntry - risk - : mEntry + risk; -} - -// -bool CalculateTPSLByPoint( - double &mSL, // Hold SL - double &mTP, // Hold TP - ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) - double mEntry, // Entry Price - double mPointValue, // Point Value - double mR2R = 1, // Provided Risk To Reward Ratio - double slPoint = 0, // Provided SL Point - double tpPoint = 0 // Provided TP Point -) -{ - // - bool result = false; - - // - mSL = 0; - mTP = 0; - - // - bool isLong = IsLong(mType); - - // - // Set Default R2R ... - if (mR2R < 1) - { - mR2R = 1; - } - - // - if (mEntry <= 0 || - mPointValue <= 0 || - (slPoint <= 0 && tpPoint <= 0)) - { - return result; - } - - // - double risk = 0; - double reward = 0; - - // - bool canCalculateBasedOnSL = slPoint > 0; - - // - bool canCalculateBasedOnTP = tpPoint > 0; - - // - if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - return result; - } - - // - if (canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = tpPoint * mPointValue; - risk = slPoint * mPointValue; - } - else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = tpPoint * mPointValue; - risk = reward / mR2R; - } - else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - risk = slPoint * mPointValue; - reward = risk * mR2R; - } - - // - result = risk > 0 && reward > 0; - if (!result) - { - return result; - } - - // - mTP = isLong - ? mEntry + reward - : mEntry - reward; - - // - mSL = isLong - ? mEntry - risk - : mEntry + risk; - - // - return result; -} - -// -bool CalculateTPSLByPrice( - double &mSL, // Hold SL - double &mTP, // Hold TP - ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) - double mEntry, // Entry Price - double mR2R = 1 // Provided Risk To Reward Ratio -) -{ - // - bool result = false; - - // - bool isLong = IsLong(mType); - - // - // Set Default R2R ... - if (mR2R < 1) - { - mR2R = 1; - } - - // - if (mEntry <= 0 || - (mSL <= 0 && mTP <= 0)) - { - return result; - } - - // - double risk = 0; - double reward = 0; - - // - bool canCalculateBasedOnSL = mSL > 0; - bool canCalculateBasedOnTP = mTP > 0; - - // - if ( - !canCalculateBasedOnSL && - !canCalculateBasedOnTP) - { - return result; - } - - // - if (!canCalculateBasedOnSL && canCalculateBasedOnTP) - { - // - reward = MathAbs(mTP - mEntry); - risk = reward / mR2R; - } - else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) - { - // - risk = MathAbs(mEntry - mSL); - reward = risk * mR2R; - } - - // - result = risk > 0 && reward > 0; - if (!result) - { - return result; - } - - // - mTP = isLong - ? mEntry + reward - : mEntry - reward; - - // - mSL = isLong - ? mEntry - risk - : mEntry + risk; - - // - return result; -} - -/** - * Calculate Momentum Changes based on Given Price - */ -double CalculateMomentum( - double currentPrice, - double previousPrice // -) -{ - // - double result = 0; - - // - return result; -} - -/** - * Detect Possible Momentum Changes - * Using MqlTick ... - */ -bool DetectMomentumChange( - ENUM_POSITION_TYPE type, - string mSymbol = NULL, - int mLength = 14 // -) -{ - // - bool result = false; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - MqlTick ticks[]; - int copied = CopyTicks( - mSymbol, - ticks, - COPY_TICKS_ALL, - 0, - mLength + 1 // - ); - - // - result = copied > mLength; - if (!result) - { - return result; - } - - // - double previousPrice = GetTickExit( - ticks[mLength], - type, - mSymbol // - ); - for (int i = mLength - 1; i >= 0; i--) - { - // - double currentPrice = GetTickExit( - ticks[i], - type, - mSymbol // - ); - - // - double momentum = CalculateMomentum( - currentPrice, - previousPrice // - ); - - // - if (fabs(momentum) > 1.0) - { - // - result = true; - break; - } - } - - // - return result; -} - - -// -// -// - -// -// Extension Methods ... - -// -// Find Swing Points ... -int FindSwing( - string mSymbol, // Trading Symbol ... - ENUM_TIMEFRAMES mPeriod, // Trading Period ... - ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ... - int mLength, // Loopback ... - int bar_index // BarIndex ... -) -{ - // - int result = -1; - - // - if (StringLen(mSymbol) == 0 || (mMode != X_SWING_HIGH && mMode != X_SWING_LOW)) - { - return result; - } - - // - int current = bar_index; - int founded = FindNextSwing( - mSymbol, - mPeriod, - mMode, - (mLength * 2) + 1, - current - mLength); - - // - while (founded != current) - { - // - current = FindNextSwing( - mSymbol, - mPeriod, - mMode, - mLength, - current + 1); - - // - founded = FindNextSwing( - mSymbol, - mPeriod, - mMode, - (mLength * 2) + 1, - current - mLength); - } - - // - result = current; - - // - return result; -} - -// -// Find Next Swing ... -int FindNextSwing( - string mSymbol, // Trading Symbol ... - ENUM_TIMEFRAMES mPeriod, // Trading Period ... - ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ... - int mLength, // Loopback ... - int bar_index // BarIndex ... -) -{ - // - int result = -1; - - // - if (bar_index < 0) - { - mLength += bar_index; - bar_index = 0; - } - - // - ENUM_SERIESMODE mSeriesMode = ToSeriesMode(mMode); - - // - result = mMode == X_SWING_HIGH - ? iHighest( - mSymbol, - mPeriod, - mSeriesMode, - mLength, - bar_index) - : iLowest( - mSymbol, - mPeriod, - mSeriesMode, - mLength, - bar_index); - - // - return result; -} - -/** - * Extract values of swings from specified Collection ... - * - * @param swings: XSwingPoint instance Collection ... - * @param values: double Collection ... - * - * @return ( int ) - */ -int ExtractSwings( - XSwingPoint &swings[], - double &values[] // -) -{ - // - int result = 0; - - // - Clean(values); - - // - int count = ArraySize(swings); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - Add( - swings[i].swing, - values // - ); - } - - // - result = ArraySize(values); - - // - return result; -} - -// -// Functions ... - -// -// Validators ... - -// -// Validate an String has length and not NULL ... - -// -// Validate a Date ... - -// -// Validate a Period Param ... - - -// -// Validate Specific Period Mode ... - - -// -// As IS ... - -// -// Normalizers ... - - -// -// Prices ... - - - - -/** - * Calculates Price Change Percentage based on - * Several Params ... - * - * @param _symbol: Symbol ... - * @param _period: Time Frame ... - * @param _from: start Bar Index ... - * @param _length: Length of Bars ... - * - * @return ( double ) - */ -double GetPriceChanged( - string _symbol = NULL, - ENUM_TIMEFRAMES _period = NULL, - int _from = 0, - int _length = 3 // -) -{ - // - double result = 0; - - // - NormalizeSymbol(_symbol); - NormalizePeriod(_period); - - // - if (_from < 0) - { - _from = 0; - } - - // - if (_length < 2) - { - _length = 2; - } - - // - double closes[]; - int copiedCloses = CopyClose( - _symbol, - _period, - _from, - _length, - closes // - ); - if (copiedCloses < _length) - { - return result; - } - ArrayReverse(closes); - - // - double change = (closes[0] - closes[_length - 1]) / closes[_length - 1] * 100; - result = change; - - // - return result; -} - -/** - * Retrieve Current Tick ... - */ -bool GetTick( - string mSymbol, - MqlTick &tick // -) -{ - return SymbolInfoTick(mSymbol, tick); -} - -/** - * Retrieve Tick Entry ... - */ -double GetTickEntry( - MqlTick &mTick, - ENUM_POSITION_TYPE type, - string mSymbol = NULL // -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsLong(type) - ? mTick.ask - : mTick.bid; - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -/** - * Retrieve Tick Exit ... - */ -double GetTickExit( - MqlTick &mTick, - ENUM_POSITION_TYPE type, - string mSymbol = NULL // -) -{ - // - double result = 0; - - // - mSymbol = NormalizeSymbol(mSymbol); - - // - result = - IsLong(type) - ? mTick.bid - : mTick.ask; - result = NormalizePrice(result, mSymbol); - - // - return result; -} - -// -// Fill Specified Applied Prices ... -int FillPrice( - double &buffer[], - ENUM_APPLIED_PRICE _mAppliedTo = PRICE_CLOSE, - string _mSymbol = NULL, - ENUM_TIMEFRAMES _mPeriod = NULL, - int _mStart = 0, - int _mLoopback = 10 // -) -{ - // - int result = 0; - - // - if (_mStart < 0) - { - _mStart = 0; - } - - // - if (_mLoopback < 1) - { - _mLoopback = 1; - } - - // - _mSymbol = NormalizeSymbol(_mSymbol); - _mPeriod = NormalizePeriod(_mPeriod); - - // - Clean(buffer); - ArraySetAsSeries(buffer, true); - - // - double open[]; - result = CopyOpen( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - open // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - double high[]; - result = CopyHigh( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - high // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - double low[]; - result = CopyLow( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - low // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - double close[]; - result = CopyClose( - _mSymbol, - _mPeriod, - _mStart, - _mLoopback, - close // - ); - if (!IsValidSize(result)) - { - return result; - } - - // - for (int i = 0; i < result; i++) - { - // - double iPrice = GetAppliedPrice( - _mAppliedTo, - open, - high, - low, - close, - i // - ); - - // - Add( - iPrice, - buffer // - ); - } - - // - result = ArraySize(buffer); - - // - return result; -} - -// -// Symbols ... - - -// -// Time / Date ... - - -// -// Retrieve Day of Week ... -ENUM_X_WEEK_DAYS GetDayOfWeek( - datetime time = NULL // -) -{ - // - ENUM_X_WEEK_DAYS result = X_WEEK_DAY_NONE; - - // - time = NormalizeTime(time); - MqlDateTime timeStruct; - bool hasDate = TimeToStruct( - time, - timeStruct // - ); - if (!hasDate) - { - return result; - } - - // - result = (ENUM_X_WEEK_DAYS)timeStruct.day_of_week; - - // - return result; -} - -// -// Representation of Time Struct ... -// struct MqlDateTime -// { -// int year; // Year -// int mon; // Month -// int day; // Day -// int hour; // Hour -// int min; // Minutes -// int sec; // Seconds -// int day_of_week; // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) -// int day_of_year; // Day number of the year (January 1st is assigned the number value of zero) -// }; - - -// -// Bar Times ... - -// -// Retrieve Specified Bar Time ... -ulong GetBarTimeAsSeconds( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - // Retrieve Bar Time ... - datetime time = GetBarTime( - mSymbol, - mPeriod, - barIndex); - - // - ulong result = TimeToSeconds(time); - - // - return result; -} - -// -// Retrieve Specified Bar Time ... -ulong GetBarTimeAsMilliSeconds( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - // Retrieve Bar Time ... - datetime time = GetBarTime( - mSymbol, - mPeriod, - barIndex); - - // - ulong result = TimeToMilliSeconds(time); - - // - return result; -} - -// -// Retrieve a Bar Time Structure ... -MqlDateTime GetBarTimeStruct( - string mSymbol = "", // Specify Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Specify TimeFrame - int barIndex = 0 // Specify Bar Index -) -{ - // - MqlDateTime result = {}; - - // - // Retrieve Bar Time ... - datetime barTime = GetBarTime( - mSymbol, - mPeriod, - barIndex); - - // - // Convert to Structure ... - TimeToStruct(barTime, result); - - // - return result; -} - -// -// Retrieve Last Available Bar Time of -// Dest Period inside Source Period ... -datetime GetLastBarTime( - ENUM_TIMEFRAMES sourcePeriod, - ENUM_TIMEFRAMES destPeriod // -) -{ - // - datetime result = NULL; - - // - if (!IsValid(sourcePeriod) || - !IsValid(destPeriod)) - { - return result; - } - - // - int sourceSeconds = PeriodSeconds(sourcePeriod); - int destSeconds = PeriodSeconds(destPeriod); - if (sourceSeconds < destSeconds) - { - return result; - } - - // - XOHCL sourceBar; - bool isInited = sourceBar.Init( - _Symbol, - sourcePeriod, - 0 // - ); - if (!isInited) - { - return result; - } - - // - result = (datetime)((((int)sourceBar.time) + sourceSeconds) - destSeconds); - - // - return result; -} - -// -// Other Tools ... - - -// -// Check Bar Reject Specified Value ... -bool IsBarReject( - double value, - ENUM_X_DIRECTION dir, - XOHCL &bar // -) -{ - // - bool result = false; - - // - result = value > 0 && - bar.IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - bool isUp = IsBullish(dir); - bool isDown = IsBearish(dir); - - // - result = - // - isUp - ? bar.IsBullish() && - bar.low < value && - bar.GetDown() > value - : isDown - ? bar.IsBearish() && - bar.high > value && - bar.GetUp() < value - : false - // - ; - - // - return result; -} - -// -// Check Bar Break Specified Value ... -bool IsBarBreak( - double value, - ENUM_X_DIRECTION dir, - XOHCL &bar // -) -{ - // - bool result = false; - - // - result = value > 0 && - bar.IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - bool isUp = IsBullish(dir); - bool isDown = IsBearish(dir); - - // - result = - isUp - ? bar.IsBullish() && - ((bar.GetDown() < value && - bar.GetUp() > value) || - (bar.close > value && - pBar.close < value)) - : isDown - ? bar.IsBearish() && - ((bar.GetUp() > value && - bar.GetDown() < value) || - (bar.close < value && - pBar.close > value)) - : false; - - // - return result; -} - -// -// Calculate Fib Level ... -double GetFibonacciLevel( - double upPrice, // Upper Bound - double downPrice, // Downer Bound - double level, // Level Multiplier Factor - int direction // From Down to Up < 0, other wise Vice Versa - // -) -{ - // - double ling = upPrice - downPrice; - double pLevel = (ling / 100) * (level * 100); - - // - double result = direction > 0 ? upPrice - pLevel : downPrice + pLevel; - - // - return result; -} - -// -double GetFibonacciLevel( - double mUp, - double mDown, - ENUM_X_FIBO_LEVELS mLevel, - ENUM_X_DIRECTION mForDir // -) -{ - // - double result = 0; - - // - double levelValue = GetFiboLevelValue(mLevel); - - // - bool isValid = - // - mUp > 0 && - mDown > 0 && - levelValue > 0 && - mUp > mDown && - HasDirection(mForDir) - // - ; - if (!isValid) - { - return result; - } - - // - bool isBullish = IsBullish(mForDir); - - // - double ling = mUp - mDown; - double pLevel = (ling / 100) * (levelValue * 100); - - // - result = - isBullish - ? mUp - pLevel - : mDown + pLevel; - - // - return result; -} - -// -// Method 1 -// Normalize between 1 and 0 ... -template -double GetNormalizedValueMethod1( - T &buffer[], // Array which required to Normalize - int mLength, // Length of Normalization - int mStart = 0, // start index - int digits = 5 // Normalization Digits -) -{ - // - double result = 0; - - // - if (digits <= 5) - { - digits = 5; - } - - // - int bufferSize = ArraySize(buffer); - if (!IsValidSize(bufferSize)) - { - return result; - } - - // - // Normalize Count ... - NormalizeCount( - mStart, - mLength, - buffer // - ); - - // - T max = 0; - T min = 0; - - // - if (bufferSize != mLength) - { - // - T tmp[]; - Copy( - mStart, - mLength, - buffer, - tmp // - ); - - // - max = GetMax(tmp); - min = GetMin(tmp); - } - - // - if (bufferSize == mLength) - { - // - max = GetMax(buffer); - min = GetMin(buffer); - } - - // - T iValue = buffer[mStart]; - - // - double minMaxDiff = (max - min); - if (minMaxDiff <= 0) - { - return result; - } - - // - result = (iValue - min) / minMaxDiff; - - // - result = NormalizeDouble(result, digits); - - // - return result; -} - -// -// Method 2 -// Normalize Between Specified Upper and Lower ... -template -double GetNormalizedValueMethod2( - T &buffer[], // Array which required to Normalize - int mLength, // Length of Normalization - int mUpper, // Specified Upper Value - int mLower, // Specified Lower Value - int mStart = 0, // start index - int digits = 5 // Normalization Digits -) -{ - // - double result = 0; - - // - if (digits <= 5) - { - digits = 5; - } - - // - int bufferSize = ArraySize(buffer); - if (!IsValidSize(bufferSize)) - { - return result; - } - - // - // Normalize Count ... - NormalizeCount( - mStart, - mLength, - buffer // - ); - - // - T max = 0; - T min = 0; - - // - if (bufferSize != mLength) - { - // - T tmp[]; - Copy( - mStart, - mLength, - buffer, - tmp // - ); - - // - max = GetMax(tmp); - min = GetMin(tmp); - } - - // - if (bufferSize == mLength) - { - // - max = GetMax(buffer); - min = GetMin(buffer); - } - - // - T iValue = buffer[mStart]; - - // - double minMaxDiff = (max - min); - double boundaryDiff = (mUpper - mLower); - if (minMaxDiff <= 0 || boundaryDiff <= 0) - { - return result; - } - - // - result = boundaryDiff / (minMaxDiff * (iValue - max) + max); - - // - result = NormalizeDouble(result, digits); - - // - return result; -} - -// -void NormalizeBuffer( - double &source[], // Source Buffer - double &dest[], // Result Buffer - double upper = 100, // Upper Value to Normalize - double lower = -100, // Lower Value to Normalize - int size = -1, // Size Of Normalization - int digits = 5 // Digits for Result -) -{ - // - if (size <= 0) - { - size = ArraySize(source); - } - - // - bool asSeriesFlag = ArrayGetAsSeries(source); - - // - ArraySetAsSeries(source, false); - ArraySetAsSeries(dest, false); - - // - double min = ArrayMinimum(source, 0, size); - double max = ArrayMaximum(source, 0, size); - - // - for (int i = 0; i < size; i++) - { - // - double iNormal = lower + ((source[i] - min) / (max - min)) * (upper - lower); - - // - if (digits > 0) - { - iNormal = NormalizeDouble(iNormal, digits); - } - - // - dest[i] = iNormal; - } - - // - ArraySetAsSeries(source, asSeriesFlag); - ArraySetAsSeries(dest, asSeriesFlag); -} - -// -// Templates ... - -// -// Bar XOHCL ... - -// -// String ... - -// -// Periods / Cycles ... - - -// -// Moving Average ... - - - -//////////////////////////////////////////////////////////// - - - // // - // double ranges[]; - // int rangesCount = GetPriceRange( - // ranges, - // bar, - // forcBodyInRange, - // loopback // - // ); - // result = IsValidSize(rangesCount); - // if (!result) - // { - // // - // Clean(ranges); - - // // - // return result; - // } - - // - // Calculate Ranges ... - // double rangeMax = GetMax(ranges); - // double rangeMin = GetMin(ranges); - // double rangeAverage = GetAverage(ranges); - diff --git a/Documents/BKP/x-ob.fvg.tmp.mq5 b/Documents/BKP/x-ob.fvg.tmp.mq5 deleted file mode 100644 index 50186129..00000000 --- a/Documents/BKP/x-ob.fvg.tmp.mq5 +++ /dev/null @@ -1,1386 +0,0 @@ - -// -struct XOBFVGPivot -{ - // - // Props ... - double value; - datetime at; - - // - // Constructor ... - XOBFVGPivot() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - value = 0; - at = NULL; - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - value > 0 && - IsValid(at); - - // - return result; - } -}; - -// -struct XOBFVG -{ - // - // Props ... - XCFVG *fvgs[]; - XCOrderBlock *ob; - - // - // Constructor ... - XOBFVG() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - Clean(fvgs); - ZeroMemory(ob); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = HasOB() && - HasFVGs(); - if (!result) - { - return result; - } - - // - XOHCL passedBar; - bool isBodyOut; - bool isOBStarted = ob.IsStarted( - ob.GetDirection(), - passedBar, - isBodyOut // - ); - - // - int idx = GetOldest(fvgs); - result = IsValidIndex(idx); - if (!result) - { - // - passedBar.Clean(); - return result; - } - - // - bool isFVGStarted = fvgs[idx].IsStarted( - ob.GetDirection(), - passedBar, - isBodyOut // - ); - - // - result = isOBStarted && - isFVGStarted; - - // - passedBar.Clean(); - - // - return result; - } - - // - bool HasOB() - { - return ob != NULL && - ob.IsValid(); - } - - // - bool HasFVGs() - { - return HasChild(fvgs); - } - - // - int CountFVGs() - { - return ArraySize(fvgs); - } - - // - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool isValid = IsValid(); - if (!isValid) - { - return result; - } - - // - result = ob.GetDirection(); - - // - return result; - } - - // - bool IsBullish() - { - return IsBullish(GetDirection()); - } - - // - bool IsBearish() - { - return IsBearish(GetDirection()); - } - - // - int GetSwings( - XOBFVGPivot &pivots[] // - ) - { - // - int result = 0; - - // - Clean(pivots); - - // - if (!IsValid()) - { - return result; - } - - // - ENUM_X_DIRECTION forDir = GetDirection(); - bool isBullish = IsBullish(forDir); - - // - XOHCL passedBar; - XOBFVGPivot iPivot; - bool isPassed = false; - double appliedPrice = 0; - bool isBodyState = false; - - // - // Start ... - isPassed = ob.IsStarted( - forDir, - passedBar, - isBodyState // - ); - if (isPassed) - { - // - appliedPrice = - isBullish - ? passedBar.low - : passedBar.high; - - // - iPivot.Clean(); - iPivot.value = appliedPrice; - iPivot.at = passedBar.time; - - // - AddRef( - iPivot, - pivots // - ); - - // - iPivot.Clean(); - } - - // - // Activation ... - isPassed = ob.IsActivated( - forDir, - passedBar, - isBodyState // - ); - if (isPassed) - { - // - appliedPrice = - isBullish - ? passedBar.low - : passedBar.high; - - // - iPivot.Clean(); - iPivot.value = appliedPrice; - iPivot.at = passedBar.time; - - // - AddRef( - iPivot, - pivots // - ); - - // - iPivot.Clean(); - } - - // - // Worked ... - isPassed = ob.IsWorked( - forDir, - passedBar, - isBodyState // - ); - if (isPassed) - { - // - appliedPrice = - isBullish - ? passedBar.low - : passedBar.high; - - // - iPivot.Clean(); - iPivot.value = appliedPrice; - iPivot.at = passedBar.time; - - // - AddRef( - iPivot, - pivots // - ); - - // - iPivot.Clean(); - } - - // - passedBar.Clean(); - - // - result = ArraySize(pivots); - - // - return result; - } - - // - bool GetMainFVG( - XCFVG *&fvg // - ) - { - // - bool result = false; - - // - fvg = NULL; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = GetOldest(fvgs); - result = IsValidIndex(idx); - if (!result) - { - // - ZeroMemory(fvg); - return result; - } - - // - fvg = fvgs[idx]; - result = fvg != NULL && - fvg.IsValid(); - - // - return result; - } - - // - bool IsValidZone( - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XCFVG *tmpFVGs[]; - Copy( - fvgs, - tmpFVGs // - ); - int count = CountFVGs(); - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = tmpFVGs[i]; - - // - XOHCL startedBar; - bool isBodyOut = false; - result = iFVG.IsStarted( - iFVG.GetDirection(), - startedBar, - isBodyOut // - ); - if (!result) - { - // - ZeroMemory(iFVG); - startedBar.Clean(); - ArrayRemove( - fvgs, - i, - 1 // - ); - - // - continue; - } - - // - XOHCL bar; - bool isBullish = iFVG.IsBullish(); - datetime fromTime = startedBar.NextAt(); - - // - int fromIndex = iBarShift( - iFVG.GetSymbol(), - iFVG.GetPeriod(), - fromTime // - ); - result = IsValidIndex(fromIndex); - if (!result) - { - // - bar.Clean(); - ZeroMemory(iFVG); - startedBar.Clean(); - ArrayRemove( - fvgs, - i, - 1 // - ); - - // - continue; - } - - // - bool isInited = false; - bool isValidFVG = false; - for (int j = barIndex; j < fromIndex; j++) - { - // - isInited = bar.Init( - iFVG.GetSymbol(), - iFVG.GetPeriod(), - j // - ); - if (!isInited) - { - // - bar.Clean(); - continue; - } - - // - // bool isBarAbove = - // bar.low > iFVG.Upper(); - // bool isBarBelow = - // bar.high < iFVG.Lower(); - - // - bool isBarAbove = - bar.GetDown() > iFVG.Upper(); - bool isBarBelow = - bar.GetUp() < iFVG.Lower(); - - // - isValidFVG = - isBullish - ? isBarAbove - : isBarBelow; - if (!isValidFVG) - { - // - bar.Clean(); - - // - break; - } - - // - bar.Clean(); - } - - // - if (!isValidFVG) - { - // - ArrayRemove( - fvgs, - i, - 1 // - ); - } - - // - bar.Clean(); - ZeroMemory(iFVG); - startedBar.Clean(); - } - - // - Clean(tmpFVGs); - - // - result = HasFVGs(); - - // - return result; - } - - // - bool ToZone(XBoxZone &box) - { - // - bool result = false; - - // - result = ToZoneBox( - box, - this // - ); - - // - return result; - } - - // - void AddFVG(XCFVG *fvg) - { - // - int idx = -1; - bool has = false; - - // - has = - HasOB() && - fvg != NULL && - fvg.IsValid() && - ob.GetDirection() == fvg.GetDirection(); - if (!has) - { - return; - } - - // - idx = FindIndex( - fvg, - fvgs // - ); - has = !IsValidIndex(idx); - if (!has) - { - return; - } - - // - Add( - fvg, - fvgs // - ); - } - - // - bool IsSameAs(XOBFVG &item) - { - // - bool result = false; - - // - result = IsValid() && - IsSame(ob, item.ob); - - // - return result; - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - - // - has = HasOB(); - if (has) - { - ob.To(value); - } - - // - has = HasFVGs(); - if (has) - { - // - count = CountFVGs(); - for (int i = 0; i < count; i++) - { - fvgs[i].To(value); - } - } - } -}; - -/** - * Update to Time of Specifiex Collection ... - * - * @param items: XOBFVG instance Collection ... - * @param value: datetime ... - */ -void SpecifiedUpdateTo( - XOBFVG &items[], - datetime value = NULL // -) -{ - // - value = NormalizeTime(value); - - // - int count = ArraySize(items); - bool has = HasChild(items); - if (!has) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - items[i].UpdateTo(value); - } -} - -/** - * Extract Box Zone's of Specified OBFVG ... - * - * @param box: XBoxZone instance, represent result ... - * @param obfvg: XOBFVG instance, specified Model ... - * - * @return ( bool ) - */ -bool ToZoneBox( - XBoxZone &box, - XOBFVG &obfvg // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - // Check Model Validation ... - result = obfvg.IsValid(); - if (!result) - { - return result; - } - - // - // Retrieve Model Main Fair Value Gap ... - XCFVG *fvg; - result = obfvg.GetMainFVG(fvg); - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - - // - return result; - } - - // - bool isBullish = fvg.IsBullish(); - - // - // Retrieve Main Fair Value Gap's Started Bar ... - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = fvg.IsStarted( - fvg.GetDirection(), - startedBar, - isBodyOut // - ); - result = isStarted; - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - // Converts Main Fair Value Gaps to Box ... - result = ToBox( - box, - fvg // - ); - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - // Validate Start Bar ... - result = - isBullish - ? startedBar.high >= fvg.Upper() && - startedBar.low < fvg.Upper() - : startedBar.low <= fvg.Lower() && - startedBar.high > fvg.Lower(); - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - // Update Box using Started Bar ... - box.lower = isBullish - ? box.lower - : startedBar.low; - box.upper = - isBullish - ? startedBar.high - : box.upper; - - // - box.from = startedBar.NextAt(); - - // - // Check Box Validation ... - result = box.IsValid(); - if (!result) - { - box.Clean(); - } - - // - // Cleanup Resources ... - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XOBFVG &item // -) -{ - // - bool result = false; - - // - result = ToBox( - box, - item.ob // - ); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -int ToBox( - XOBFVG &source[], - XBoxZone &dest[] // -) -{ - // - int result = 0; - - // - Clean(dest); - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XOBFVG iZone = source[i]; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - - // - if (hasBox) - { - // - AddRef( - iBox, - dest // - ); - } - - // - iBox.Clean(); - iZone.Clean(); - } - - // - result = ArraySize(dest); - - // - return result; -} - -/** - * Get Oldest Index ... - * - * @param source: XOBFVG instance Reference Collection ... - * - * @return ( int ) - */ -int GetOldest( - XOBFVG &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.from > iBox.from; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -/** - * Get Youngest Index ... - * - * @param source: XOBFVG instance Reference Collection ... - * - * @return ( int ) - */ -int GetYoungest( - XOBFVG &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.from < iBox.from; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -/** - * Get Highest Index ... - * - * @param source: XOBFVG instance Reference Collection ... - * - * @return ( int ) - */ -int GetHighest( - XOBFVG &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.upper < iBox.upper; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -/** - * Get Lowest Index ... - * - * @param source: XOBFVG instance Reference Collection ... - * - * @return ( int ) - */ -int GetLowest( - XOBFVG &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.lower > iBox.lower; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -bool AddIfNotExists( - XOBFVG &item, - XOBFVG &items[] // -) -{ - // - bool result = false; - - // - result = item.IsValid(); - if (!result) - { - return result; - } - - // - int before = ArraySize(items); - - // - int idx = FindIndex( - item, - items // - ); - bool has = IsValidIndex(idx); - result = !has; - if (!result) - { - return result; - } - - // - AddRef( - item, - items // - ); - - // - int after = ArraySize(items); - - // - result = after > before; - - // - return result; -} - -int AddIfNotExists( - XOBFVG &items[], - XOBFVG &sources[] // -) -{ - // - int result = 0; - - // - bool has = HasChild(items); - if (!has) - { - return result; - } - - // - int before = ArraySize(sources); - - // - int count = ArraySize(items); - for (int i = 0; i < count; i++) - { - // - has = AddIfNotExists( - items[i], - sources // - ); - } - - // - int after = ArraySize(sources); - - // - result = after > before; - - // - return result; -} - -// -int DrawOBFVG( - // - XOBFVG &item, - XCBaseObject *&objects[], - // - bool drawOrderBlock = true, - bool drawFairValueGaps = true, - bool drawAllFVGs = true, - // - bool drawOBStartedBar = true, - bool drawOBActivatedBar = true, - bool drawOBBreakedBar = true, - bool drawOBWorkedBar = true, - // - bool drawFVGStartedBar = true, - bool drawFVGActivatedBar = true, - bool drawFVGBreakedBar = true, - bool drawFVGWorkedBar = true, - // - // Order Block Specs ... - // - int widthOBStartedBar = 1, - color clrOBStartedBar = clrYellow, - ENUM_LINE_STYLE styleOBStartedBar = STYLE_SOLID, - // - int widthOBActivatedBar = 1, - color clrOBActivatedBar = clrLime, - ENUM_LINE_STYLE styleOBActivatedBar = STYLE_SOLID, - // - int widthOBBreakedBar = 1, - color clrOBBreakedBar = clrRed, - ENUM_LINE_STYLE styleOBBreakedBar = STYLE_SOLID, - // - int widthOBWorkedBar = 1, - color clrOBWorkedBar = clrAqua, - ENUM_LINE_STYLE styleOBWorkedBar = STYLE_SOLID, - // - // Fair Value Gap Specs ... - // - int widthFVGStartedBar = 1, - color clrFVGStartedBar = clrYellow, - ENUM_LINE_STYLE styleFVGStartedBar = STYLE_SOLID, - // - int widthFVGActivatedBar = 1, - color clrFVGActivatedBar = clrLime, - ENUM_LINE_STYLE styleFVGActivatedBar = STYLE_SOLID, - // - int widthFVGBreakedBar = 1, - color clrFVGBreakedBar = clrRed, - ENUM_LINE_STYLE styleFVGBreakedBar = STYLE_SOLID, - // - int widthFVGWorkedBar = 1, - color clrFVGWorkedBar = clrAqua, - ENUM_LINE_STYLE styleFVGWorkedBar = STYLE_SOLID - // -) -{ - // - int result = 0; - - // - Clean(objects); - - // - bool isValid = item.IsValid(); - if (!isValid) - { - return result; - } - - // - int count = 0; - bool has = false; - bool isCreated = false; - XCBaseObject *tmpObjects[]; - - // - // Order Block ... - has = item.HasOB(); - if (has && - drawOrderBlock) - { - // - Clean(tmpObjects); - count = DrawOrderBlock( - item.ob, - tmpObjects, - drawOBStartedBar, - drawOBActivatedBar, - drawOBBreakedBar, - drawOBWorkedBar, - widthOBStartedBar, - clrOBStartedBar, - styleOBStartedBar, - widthOBActivatedBar, - clrOBActivatedBar, - styleOBActivatedBar, - widthOBBreakedBar, - clrOBBreakedBar, - styleOBBreakedBar, - widthOBWorkedBar, - clrOBWorkedBar, - styleOBWorkedBar // - ); - has = IsValidSize(count); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } - } - - // - // Fair Value Gap ... - if (!drawAllFVGs) - { - XCFVG *fvg; - has = item.GetMainFVG(fvg); - if (has && - drawFairValueGaps) - { - // - Clean(tmpObjects); - int fvgsCount = DrawFairValueGap( - fvg, - tmpObjects, - drawFVGStartedBar, - drawFVGActivatedBar, - drawFVGBreakedBar, - drawFVGWorkedBar, - widthFVGStartedBar, - clrFVGStartedBar, - styleFVGStartedBar, - widthFVGActivatedBar, - clrFVGActivatedBar, - styleFVGActivatedBar, - widthFVGBreakedBar, - clrFVGBreakedBar, - styleFVGBreakedBar, - widthFVGWorkedBar, - clrFVGWorkedBar, - styleFVGWorkedBar // - ); - has = IsValidSize(fvgsCount); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } - } - } - else - { - // - has = item.HasFVGs(); - if (has && - drawFairValueGaps) - { - // - count = item.CountFVGs(); - for (int i = 0; i < count; i++) - { - // - Clean(tmpObjects); - int fvgsCount = DrawFairValueGap( - item.fvgs[i], - tmpObjects, - drawFVGStartedBar, - drawFVGActivatedBar, - drawFVGBreakedBar, - drawFVGWorkedBar, - widthFVGStartedBar, - clrFVGStartedBar, - styleFVGStartedBar, - widthFVGActivatedBar, - clrFVGActivatedBar, - styleFVGActivatedBar, - widthFVGBreakedBar, - clrFVGBreakedBar, - styleFVGBreakedBar, - widthFVGWorkedBar, - clrFVGWorkedBar, - styleFVGWorkedBar // - ); - has = IsValidSize(fvgsCount); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } - } - } - } - - // - Clean(tmpObjects); - - // - result = ArraySize(objects); - - // - return result; -} diff --git a/Documents/BKP/x-omid.signalling.mq5 b/Documents/BKP/x-omid.signalling.mq5 deleted file mode 100644 index 3b820c33..00000000 --- a/Documents/BKP/x-omid.signalling.mq5 +++ /dev/null @@ -1,543 +0,0 @@ - // - bool HasSenario1Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) - { - // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - Parse(chXConditions); - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - // Detecting Signal Conditions ... - - // - bool isX3MAFastRejectUp = - // - cBar.low < cXConditions.x3maFastBuffer[cIDX] && - cBar.GetDown() > cXConditions.x3maFastBuffer[cIDX] - // - ; - - // - bool isX3MAFastRejectDown = - // - cBar.high > cXConditions.x3maFastBuffer[cIDX] && - cBar.GetUp() < cXConditions.x3maFastBuffer[cIDX] - // - ; - - // - // Find Breaker Bar ... - datetime nearCloseOverX3MAFast = cHelper.GetNearestCloseOverX3MAFast(cBar); - datetime nearCloseUnderX3MAFast = cHelper.GetNearestCloseUnderX3MAFast(cBar); - bool hasNearestCloseOverX3MAFast = - IsValid(nearCloseOverX3MAFast) && - IsValid(nearCloseUnderX3MAFast) - ? nearCloseOverX3MAFast > nearCloseUnderX3MAFast - : IsValid(nearCloseOverX3MAFast) - ? true - : false; - bool hasNearestCloseUnderX3MAFast = - IsValid(nearCloseOverX3MAFast) && - IsValid(nearCloseUnderX3MAFast) - ? nearCloseUnderX3MAFast > nearCloseOverX3MAFast - : IsValid(nearCloseUnderX3MAFast) - ? true - : false; - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - cBar.IsBullish() && - isX3MAFastRejectUp && - cXConditions.isSMHKBullish && - hasNearestCloseOverX3MAFast && - cXConditions.xhkSMOpenBuffer[cIDX] < cXConditions.x3maMidBuffer[cIDX] - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - cBar.IsBearish() && - isX3MAFastRejectDown && - cXConditions.isSMHKBearish && - hasNearestCloseUnderX3MAFast && - cXConditions.xhkSMOpenBuffer[cIDX] > cXConditions.x3maMidBuffer[cIDX] - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - fromIDX = GetBarIndex( - cBar.symbol, - cBar.period, - nearCloseOverX3MAFast // - ); - } - else - { - // - fromIDX = GetBarIndex( - cBar.symbol, - cBar.period, - nearCloseUnderX3MAFast // - ); - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Fix Box Upper and Lower based on Strategy ... - - // - double points = GetPoints(box.symbol); - double minPointsDiff = points * 20; - - // - double prefferSL = 0; - - // - // Other SL Conditions ... - if (prefferSL <= 0) - { - // - prefferSL = cHelper - .mX121Helper - .xhkHelper - .GetSMHKOpen(fromIDX); - } - - // - if (prefferSL > 0) - { - // - box.upper = - isBullish - ? zBar.open - : prefferSL; - - // - box.lower = - isBullish - ? prefferSL - : zBar.open; - } - - // - if (box.IsValid()) - { - // - XCBoxObject *iObj; - bool isCreated = cHelper.mPOIDrawer.DrawBox( - box, - iObj // - ); - if (isCreated) - { - // - iObj.BoxWidth(2); - iObj.BoxFill(true); - iObj.BoxStyle(STYLE_DOT); - - // - Print("Signal ..."); - } - } - - // - // Validate Conditions to Force Has Holder Box ... - - // // - // result = - // result && - // holderBox.IsValid() && - // dir == holderBox.dir; - - // // - // if (!result) - // { - // // - // isBullish = false; - // isBearish = false; - // } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - /////////////////////////////////////////////////////////////// - - // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - provider.visionXConditions.isSMHKBullish && - provider.decisionXConditions.isSarBullish && - provider.decisionXConditions.isVWapFastBullish && - provider.decisionXConditions.isX3MaFastBullish && - provider.consolidationXConditions.isSMHKBullish && - provider.decisionXConditions.isSMHKSwitchedToBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - provider.visionXConditions.isSMHKBearish && - provider.decisionXConditions.isSarBearish && - provider.decisionXConditions.isVWapFastBearish && - provider.decisionXConditions.isX3MaFastBearish && - provider.consolidationXConditions.isSMHKBearish && - provider.decisionXConditions.isSMHKSwitchedToBearish - // - ) - // - ; diff --git a/Documents/BKP/x-saherelm.x-bar.analyser.class.mq5 b/Documents/BKP/x-saherelm.x-bar.analyser.class.mq5 deleted file mode 100644 index 2b4b613f..00000000 --- a/Documents/BKP/x-saherelm.x-bar.analyser.class.mq5 +++ /dev/null @@ -1,6043 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XPOI -// Description: Bar Analysing ... -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.base.class.mq5" -#include "../Libraries/x-saherelm.x-poi.lib.mq5" - -// -// Definitions ... - -// -// Implementations ... -class XCBarAnalyser : public XCBase -{ - // - public: - // - - // - // Constructor(s) ... - void XCBarAnalyser() - { - } - - // - // Deconstructor ... - void ~XCBarAnalyser() - { - } - - // - // Getter(s) / Setter(s) ... - - // - // Providers ... - - // - // Actions ... - - /** - * Calculate Loopback Data for Specific Bar ... - * - * @param index: Integer, Bar Current Index ... - * @param start: Integer, Start of Loopback ... - * @param end: Integer, End of Loopback ... - * @param count: Integer, Number of Calculating Bars ... - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * @return ( bool ) - */ - bool CalculateLoopBackData( - int &index, - int &start, - int &end, - int &count, - XOHCL &bar, - int loopback = 1 // - ) - { - // - bool result = false; - - // - if (loopback < 1) - { - loopback = 1; - } - - // - index = -1; - start = -1; - end = -1; - count = -1; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - index = bar.Index(); - start = index + 1; - end = start + loopback; - count = end - start; - result = count >= 1; - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Retrieve Loopback HH & LL Data ... - * - * @param hhIDX: Integer, HH Index ... - * @param hh: Double, HH Value ... - * @param llIDX: Integer, LL Index ... - * @param ll: Double, LL Value ... - * @param bar: XOHCL instance ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool CalculateLoopbackHLData( - int &hhIDX, - double &hh, - int &llIDX, - double &ll, - XOHCL &bar, - int loopback // - ) - { - // - bool result = false; - - // - if (loopback < 1) - { - loopback = 1; - } - - // - int index = -1; - int start = -1; - int end = -1; - int count = -1; - result = CalculateLoopBackData( - index, - start, - end, - count, - bar, - loopback // - ); - if (!result) - { - return result; - } - - // - hhIDX = iHighest( - bar.symbol, - bar.period, - MODE_HIGH, - count, - start // - ); - result = IsValidIndex(hhIDX); - if (!result) - { - return result; - } - - // - llIDX = iLowest( - bar.symbol, - bar.period, - MODE_LOW, - count, - start // - ); - result = IsValidIndex(llIDX); - if (!result) - { - return result; - } - - // - hh = iHigh( - bar.symbol, - bar.period, - hhIDX // - ); - ll = iLow( - bar.symbol, - bar.period, - llIDX // - ); - - // - return result; - } - - /** - * Calculate Bar Range ... - * - * @param bar: XOHCL instance ... - * - * @return ( double ) - */ - double GetBarRangePercent(XOHCL &bar) - { - // - double result = 0; - - // - result = bar.GetRange() / 100; - - // - return result; - } - - /** - * Detect Same Bars ... - * - * @param bar: XOHCL instance, Start Bar ... - * @param dir: ENUM_X_DIRECTION member, Holds Result Direction ... - * @param index: Integer, Holds Result Index ... - * @param sameBars: Iteger, Required Same Bar ... - * - * @return ( bool ) - */ - bool HasSameBars( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int &index, - int sameBars = 3 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - if (sameBars < 1) - { - sameBars = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - index = bar.Index() + 1; - bool canContinue = true; - int sameBullishBarsFounded = 0; - int sameBearishBarsFounded = 0; - bool canContinueForBullish = true; - bool canContinueForBearish = true; - while (canContinue) - { - // - XOHCL iBar; - result = iBar.Init( - bar.symbol, - bar.period, - index // - ); - if (!result) - { - break; - } - - // - bool isBullish = iBar.IsBullish(); - bool isBearish = iBar.IsBearish(); - result = isBullish || - isBearish; - if (!result) - { - break; - } - - // - if (isBullish) - { - // - sameBullishBarsFounded++; - canContinueForBearish = false; - } - else if (isBearish) - { - // - sameBearishBarsFounded++; - canContinueForBullish = false; - } - else - { - // - sameBullishBarsFounded = 0; - sameBearishBarsFounded = 0; - canContinueForBullish = false; - canContinueForBearish = false; - } - - // - result = canContinueForBullish || - canContinueForBearish; - if (!result) - { - break; - } - - // - canContinueForBullish = - canContinueForBullish && - sameBullishBarsFounded > 0; - - // - canContinueForBearish = - canContinueForBearish && - sameBearishBarsFounded > 0; - - // - canContinue = - canContinueForBullish || - canContinueForBearish; - if (canContinue) - { - index++; - } - } - - // - bool hasBullishSameBars = - sameBullishBarsFounded >= sameBars; - - // - bool hasBearishSameBars = - sameBearishBarsFounded >= sameBars; - - // - result = hasBullishSameBars || - hasBearishSameBars; - if (!result) - { - return result; - } - - // - index--; - - // - dir = - hasBullishSameBars - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Detect Price Consolidation ... - * - * @param bar: XOHCL instance Reference, Start Bar ... - * @param loopback: Integer, Consolidation Length Finder ... - * @param consolidationRange: Integer, Consolidation Range Finder ... - * @param upper: Double Reference ... - * @param lower: Double Reference ... - * @param upperAppliedTo: ENUM_APPLIED_PRICE member, Upper Price ... - * @param lowerAppliedTo: ENUM_APPLIED_PRICE member, Lower Price ... - * - * @return ( bool ) - */ - bool IsConsolidate( - XOHCL &bar, - double &upper, - double &lower, - int loopback = 30, - int consolidationRange = 50, - ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH, - ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW // - ) - { - // - bool result = false; - - // - upper = 0; - lower = 0; - - // - if (loopback < 7) - { - loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double points = GetPoints(bar.symbol); - int index = bar.Index(); - - // - double upperPrice[]; - int upperPriceCount = FillPrice( - upperPrice, - upperAppliedTo, - bar.symbol, - bar.period, - index, - loopback // - ); - - // - double lowerPrice[]; - int lowerPriceCount = FillPrice( - lowerPrice, - lowerAppliedTo, - bar.symbol, - bar.period, - index, - loopback // - ); - - // - result = upperPriceCount == lowerPriceCount && - lowerPriceCount == loopback; - if (!result) - { - return result; - } - - // - upper = upperPrice[ArrayMaximum(upperPrice)]; - lower = lowerPrice[ArrayMinimum(lowerPrice)]; - - // - double range = upper - lower; - result = range <= consolidationRange * points; - - // - return result; - } - - bool HasConsolidationZone( - XOHCL &bar, - XConsolidationZone &zone, - int minLoopback = 3, - double range = 50, - ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH, - ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW // - ) - { - // - bool result = false; - - // - zone.Clean(); - - // - result = bar.IsValid() && - minLoopback > 0 && - range > 0; - if (!result) - { - return result; - } - - // - double points = GetPoints(bar.symbol); - int index = bar.Index() + 1; - int length = minLoopback; - - // - double upperPrice[]; - int upperPriceCount = FillPrice( - upperPrice, - upperAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - double lowerPrice[]; - int lowerPriceCount = FillPrice( - lowerPrice, - lowerAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - result = upperPriceCount == lowerPriceCount && - lowerPriceCount == length; - if (!result) - { - // - Clean(upperPrice); - Clean(lowerPrice); - - // - return result; - } - - // - double upper = upperPrice[ArrayMaximum(upperPrice)]; - double lower = lowerPrice[ArrayMinimum(lowerPrice)]; - - // - bool isBullishBreake = - bar.low > lower && - bar.high > upper && - bar.GetUp() > upper; - bool isBearishBreake = - bar.high < upper && - bar.low < lower && - bar.GetDown() < lower; - result = isBullishBreake || - isBearishBreake; - if (!result) - { - // - Clean(upperPrice); - Clean(lowerPrice); - - // - return result; - } - - // - double delta = upper - lower; - result = delta <= range * points; - if (!result) - { - // - Clean(upperPrice); - Clean(lowerPrice); - - // - return result; - } - - // - while (delta <= range * points) - { - // - length++; - - // - upperPriceCount = FillPrice( - upperPrice, - upperAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - lowerPriceCount = FillPrice( - lowerPrice, - lowerAppliedTo, - bar.symbol, - bar.period, - index, - length // - ); - - // - bool isValid = upperPriceCount == lowerPriceCount && - lowerPriceCount == length; - if (!isValid) - { - break; - } - - // - double iUpper = upperPrice[ArrayMaximum(upperPrice)]; - double iLower = lowerPrice[ArrayMinimum(lowerPrice)]; - - // - delta = iUpper - iLower; - if (delta <= range * points) - { - // - upper = iUpper; - lower = iLower; - } - } - - // - Clean(upperPrice); - Clean(lowerPrice); - - // - // Filling Zone ... - zone.upper = upper; - zone.lower = lower; - zone.symbol = bar.symbol; - zone.period = bar.period; - zone.to = iTime( - bar.symbol, - bar.period, - bar.Index() + 1 // - ); - zone.from = iTime( - bar.symbol, - bar.period, - bar.Index() + length // - ); - zone.dir = isBullishBreake - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - result = zone.IsValid(); - if (!result) - { - zone.Clean(); - } - - // - return result; - } - - /** - * Check Bar Has Bullish Trend or not ... - * - * @param bar: XOHCL instance ... - * @param forceAll: Boolean ... - * - * @return ( bool ) - */ - bool HasBullishTrend( - XOHCL &bar, - bool forceAll = false // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL tmpHSW[]; - XOHCL tmpLSW[]; - - // - bool trend1 = HasBullishTrend( - bar, - tmpHSW, - tmpLSW, - true // - ); - - // - bool trend2 = HasBullishTrend( - bar, - tmpHSW, - tmpLSW, - false // - ); - - // - if (!forceAll) - { - // - result = trend1; - if (!result) - { - return result; - } - } - - // - result = - trend1 || - trend2; - - // - return result; - } - - /** - * Check Bar Has Bearish Trend or not ... - * - * @param bar: XOHCL instance ... - * @param forceAll: Boolean ... - * - * @return ( bool ) - */ - bool HasBearishTrend( - XOHCL &bar, - bool forceAll = false // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL tmpHSW[]; - XOHCL tmpLSW[]; - - // - bool trend1 = HasBearishTrend( - bar, - tmpHSW, - tmpLSW, - true // - ); - - // - bool trend2 = HasBearishTrend( - bar, - tmpHSW, - tmpLSW, - false // - ); - - // - if (!forceAll) - { - // - result = trend1; - if (!result) - { - return result; - } - } - - // - result = - trend1 || - trend2; - - // - return result; - } - - /** - * Check Specified Bar Has Bullish Pattern or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length for Patterns ... - * @param verifications: Integer, Number of Given Verifications ... - * @param checkHammer: Boolean, Specified Check Hammer Pattern ... - * @param checkMorningStar: Boolean, Specified Check Morning Star Pattern ... - * @param checkBullishMarubozu: Boolean, Specified Check Marubozu Pattern ... - * @param checkBullishEngulfing: Boolean, Specified Check Engulfing Pattern ... - * - * @return ( bool ) - */ - bool HasBullishPattern( - XOHCL &bar, - int loopback = 0, - int verifications = 1, - bool checkHammer = true, - bool checkMorningStar = true, - bool checkBullishMarubozu = true, - bool checkBullishEngulfing = true // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (verifications <= 0) - { - verifications = 1; - } - - // - int founded = 0; - - // - int idx = bar.Index(); - for (int i = idx; i <= idx + loopback; i++) - { - // - XOHCL iBar; - result = iBar.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - break; - } - - // - bool isHammer = - !checkHammer - ? false - : IsHammer(iBar); - if (isHammer) - { - founded++; - } - - // - bool isMorningStar = - !checkMorningStar - ? false - : IsMorningStar(iBar); - if (isMorningStar) - { - founded++; - } - - // - bool isBullishMarubozu = - !checkBullishMarubozu - ? false - : IsBullishMarubozu(iBar); - if (isBullishMarubozu) - { - founded++; - } - - // - bool isBullishEngulfing = - !checkBullishEngulfing - ? false - : IsBullishEngulfing(iBar); - if (isBullishEngulfing) - { - founded++; - } - - // - } - - // - result = - result && - founded >= verifications; - - // - return result; - } - - /** - * Check Specified Bar Has Bearish Pattern or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length for Patterns ... - * @param verifications: Integer, Number of Given Verifications ... - * @param checkShootingStar: Boolean, Specified Check Shooting Star Pattern ... - * @param checkEveningStar: Boolean, Specified Check Evening Star Pattern ... - * @param checkBearishMarubozu: Boolean, Specified Check Marubozu Pattern ... - * @param checkBearishEngulfing: Boolean, Specified Check Engulfing Pattern ... - * - * @return ( bool ) - */ - bool HasBearishPattern( - XOHCL &bar, - int loopback = 0, - int verifications = 1, - bool checkShootingStar = true, - bool checkEveningStar = true, - bool checkBearishMarubozu = true, - bool checkBearishEngulfing = true // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (verifications <= 0) - { - verifications = 1; - } - - // - int founded = 0; - - // - int idx = bar.Index(); - for (int i = idx - 1; i <= idx + loopback; i++) - { - // - XOHCL iBar; - result = iBar.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - break; - } - - // - bool isShootingStar = - !checkShootingStar - ? false - : IsShootingStar(iBar); - if (isShootingStar) - { - founded++; - } - - // - bool isEveningStar = - !checkEveningStar - ? false - : IsEveningStar(iBar); - if (isEveningStar) - { - founded++; - } - - // - bool isBearishMarubozu = - !checkBearishMarubozu - ? false - : IsBearishMarubozu(iBar); - if (isBearishMarubozu) - { - founded++; - } - - // - bool isBearishEngulfing = - !checkBearishEngulfing - ? false - : IsBearishEngulfing(iBar); - if (isBearishEngulfing) - { - founded++; - } - - // - } - - // - result = - result && - founded >= verifications; - - // - return result; - } - - // - // Commons ... - - /** - * Check Specified Bar's Range is Extended or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool HasExtendedRange( - XOHCL &bar, - int loopback = 3 // - ) - { - // - bool result = false; - - // - if (loopback < 3) - { - loopback = 3; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - int start = index + 1; - int end = start + loopback; - int count = end - start; - result = count >= 1; - if (!result) - { - return result; - } - - // - double sum = 0; - XOHCL iBar = bar; - for (int i = start; i < end; i++) - { - // - bool isRetrieved = iBar.GetPreviousBar(iBar); - if (!isRetrieved) - { - continue; - } - - // - sum += iBar.GetRange(); - } - - // - result = sum > 0; - if (!result) - { - return result; - } - - // - double avg = sum / count; - - // - result = bar.GetRange() >= avg; - - // - return result; - } - - /** - * Check Specified Bar's Body is Extended or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool HasExtendedBody( - XOHCL &bar, - int loopback = 3 // - ) - { - // - bool result = false; - - // - if (loopback < 3) - { - loopback = 3; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - int start = index + 1; - int end = start + loopback; - int count = end - start; - result = count >= 1; - if (!result) - { - return result; - } - - // - double sum = 0; - XOHCL iBar = bar; - for (int i = start; i < end; i++) - { - // - bool isRetrieved = iBar.GetPreviousBar(iBar); - if (!isRetrieved) - { - continue; - } - - // - sum += iBar.GetBody(); - } - - // - result = sum > 0; - if (!result) - { - return result; - } - - // - double avg = sum / count; - - // - result = bar.GetBody() >= avg; - - // - return result; - } - - /** - * Check Specified Bar's Body and Range is Extended or not ... - * - * @param bar: XOHCL instance, Specified Bar ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool IsExtended( - XOHCL &bar, - int loopback = 3 // - ) - { - // - bool result = false; - - // - bool hasExtendedBody = HasExtendedBody(bar, loopback); - bool hasExtendedRange = HasExtendedRange(bar, loopback); - result = hasExtendedBody && - hasExtendedRange; - - // - return result; - } - - /** - * Check Specified Bar is Swing High or not ... - * - * @param bar: XOHCL instnce ... - * @param range: Integer, Specified Range ... - * - * @return ( bool ) - */ - bool IsSwingHigh( - XOHCL &bar, - int range = 2 // - ) - { - // - bool result = false; - - // - if (range < 1) - { - range = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - index + i // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - index - i // - ); - if (!result) - { - break; - } - - // - result = bar.high >= iPrevBar.high && - bar.high >= iNextBar.high; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check Specified Bar is Swing Low or not ... - * - * @param bar: XOHCL instnce ... - * @param range: Integer, Specified Range ... - * - * @return ( bool ) - */ - bool IsSwingLow( - XOHCL &bar, - int range = 2 // - ) - { - // - bool result = false; - - // - if (range < 1) - { - range = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - index + i // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - index - i // - ); - if (!result) - { - break; - } - - // - result = bar.low <= iPrevBar.low && - bar.low <= iNextBar.low; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check Specified Bar is Swing or not ... - * - * @param bar: XOHCL instnce ... - * @param dir: ENUM_X_DIRECTION member ... - * @param range: Integer, Specified Range ... - * - * @return ( bool ) - */ - bool IsSwing( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int range = 2 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - bool isSwingLow = IsSwingLow(bar, range); - bool isSwingHigh = IsSwingHigh(bar, range); - - // - result = isSwingLow || - isSwingHigh; - if (result) - { - // - if (isSwingLow) - { - dir = X_DIRECTION_BULLISH; - } - else - { - dir = X_DIRECTION_BEARISH; - } - } - - // - return result; - } - - /** - * Check a Bar is Momentum Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param bodyPercent: Double ... - * - * @return ( bool ) - */ - bool IsMomentumBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double bodyPercent = 70 // - ) - { - // - bool result = false; - - // - if (extend < 0) - { - extend = 0; - } - - // - if (bodyPercent < 50) - { - bodyPercent = 50; - } - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (extend > 0) - { - // - result = IsExtended( - bar, - extend // - ); - - // - if (!result) - { - return result; - } - } - - // - double body = bar.GetBody(); - double rp = GetBarRangePercent(bar); - - // - result = body >= rp * bodyPercent; - - // - if (result) - { - // - dir = - bar.IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - /** - * Check a Bar is Rejection Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param shadowPercent: Double ... - * - * @return ( bool ) - */ - bool IsRejectionBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double shadowPercent = 60 // - ) - { - // - bool result = false; - - // - if (extend < 0) - { - extend = 0; - } - - // - if (shadowPercent < 50) - { - shadowPercent = 50; - } - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (extend > 0) - { - // - result = IsExtended( - bar, - extend // - ); - - // - if (!result) - { - return result; - } - } - - // - double body = bar.GetBody(); - double range = bar.GetRange(); - double shadows = bar.GetShadows(); - double lowShadow = bar.GetLowShadow(); - double highShadow = bar.GetHighShadow(); - double rp = GetBarRangePercent(bar); - - // - result = shadows >= rp * shadowPercent; - - // - if (result) - { - // - dir = - lowShadow > highShadow - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - /** - * Check Specified Bar is Engulfing Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param bodyPercent: Double ... - * - * @return ( bool ) - */ - bool IsEngulfBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double bodyPercent = 60 // - ) - { - // - bool result = false; - - // - if (extend < 0) - { - extend = 0; - } - - // - if (bodyPercent < 50) - { - bodyPercent = 50; - } - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - if (extend > 0) - { - // - result = IsExtended( - pBar, - extend // - ); - - // - if (!result) - { - return result; - } - } - - // - // Check Engulfig ... - result = - bar.GetUp() > pBar.GetUp() && - bar.GetDown() < pBar.GetDown(); - if (!result) - { - return result; - } - - // - // Check Engulfing Direction ... - bool isBullishEngulfed = - pBar.IsBearish() && - bar.IsBullish(); - bool isBearishEngulfed = - pBar.IsBullish() && - bar.IsBearish(); - - // - result = isBullishEngulfed || - isBearishEngulfed; - if (!result) - { - return result; - } - - // - dir = isBullishEngulfed - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Check Specified Bar is Pin Bar or not ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param shadowPercent: Double ... - * @param bodyPercent: Double ... - * - * @return ( bool ) - */ - bool IsPinBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double shadowPercent = 65, - double bodyPercent = 25 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0 && - bodyPercent > 0 && - shadowPercent > 0 && - bodyPercent < shadowPercent; - if (!result) - { - return result; - } - - // - // Chack Range Extends ... - if (extend > 0) - { - // - result = HasExtendedRange( - bar, - extend // - ); - if (!result) - { - return result; - } - } - - // - // Check Body ... - double rangePercent = GetBarRangePercent(bar); - result = rangePercent > 0; - if (!result) - { - return result; - } - - // - double body = bar.GetBody(); - double highShadow = bar.GetHighShadow(); - double lowShadow = bar.GetLowShadow(); - - // - // Check Body ... - result = body / rangePercent >= bodyPercent; - if (!result) - { - return result; - } - - // - bool isPassedHighShadow = - highShadow / rangePercent >= shadowPercent; - bool isPassedLowShadow = - lowShadow / rangePercent >= shadowPercent; - result = - isPassedLowShadow || - isPassedHighShadow; - if (!result) - { - return result; - } - - // - dir = isPassedLowShadow - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - /** - * Decision Bar (Pin, Momentum or Rejection) ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * @param extend: Integer ... - * @param shadowForPinAndRejectionBarPercent: Double ... - * @param bodyForPinBarPercent: Double ... - * @param bodyForEngulfBarPercent: Double ... - * @param bodyForMomentumBarPercent: Double ... - * - * @return ( bool ) - */ - bool IsDecisionBar( - XOHCL &bar, - ENUM_X_DIRECTION &dir, - int extend = 1, - double shadowForPinAndRejectionBarPercent = 65, - double bodyForPinBarPercent = 25, - double bodyForEngulfBarPercent = 65, - double bodyForMomentumBarPercent = 70 // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Pin Bar ... - ENUM_X_DIRECTION pinDir; - bool isPiBar = IsPinBar( - bar, - pinDir, - extend, - shadowForPinAndRejectionBarPercent, - bodyForPinBarPercent // - ); - - // - // Engulfing Bar ... - ENUM_X_DIRECTION engulfDir; - bool isEngulfBar = IsEngulfBar( - bar, - engulfDir, - extend, - bodyForEngulfBarPercent // - ); - - // - // Momentum Bar ... - ENUM_X_DIRECTION momentumDir; - bool isMomentumBar = IsMomentumBar( - bar, - momentumDir, - extend, - bodyForMomentumBarPercent // - ); - - // - // Rejection Bar ... - ENUM_X_DIRECTION rejectionDir; - bool isRejectionBar = IsRejectionBar( - bar, - rejectionDir, - extend, - shadowForPinAndRejectionBarPercent // - ); - - // - result = isPiBar || - isEngulfBar || - isMomentumBar || - isRejectionBar; - if (result) - { - // - if (isPiBar) - { - dir = pinDir; - } - else if (isEngulfBar) - { - dir = engulfDir; - } - else if (isMomentumBar) - { - dir = momentumDir; - } - else - { - dir = rejectionDir; - } - } - - // - result = IsBullish(dir) || - IsBearish(dir); - - // - return result; - } - - /** - * Check Fibonacci Level 382 Pressure ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * - * @return ( bool ) - */ - bool HasFiboPressure( - XOHCL &bar, - ENUM_X_DIRECTION forDir, - ENUM_X_FIBO_LEVELS level // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - bool isBearish = IsBearish(forDir); - - // - double fiboLevelValue = GetFibonacciLevel( - bar.high, - bar.low, - level, - forDir // - ); - - // - bool isBullishPressured = - isBullish && - bar.GetDown() > fiboLevelValue; - bool isBearishPressured = - isBearish && - bar.GetUp() < fiboLevelValue; - - // - result = isBullishPressured || - isBearishPressured; - - // - return result; - } - - // - // Support and Resistance Zones ... - - /** - * Check a Bar is Support Bar or not ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Specified Verifiation Range ... - * - * @return ( bool ) - */ - bool IsSupport( - XOHCL &bar, - int range = 21 // - ) - { - // - bool result = false; - - // - if (range < 2) - { - range = 2; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - int prevIDX = index + i; - int nextIDX = index - 1; - - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - prevIDX // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - nextIDX // - ); - if (!result) - { - break; - } - - // - result = bar.low <= iPrevBar.low && - bar.low <= iNextBar.low; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check a Bar Has Support or not ... - * - * @param bar: XOHCL instance ... - * @param supportBar: XOHCL instance Specified Support Bar ... - * @param rage: int, - * @return ( bool ) - */ - bool HasSupport( - XOHCL &bar, - XOHCL &supportBar, - int range = 21 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int barIndex = bar.Index() + range; - result = IsValidIndex(barIndex); - if (!result) - { - // - supportBar.Clean(); - return result; - } - result = supportBar.Init( - bar.symbol, - bar.period, - barIndex // - ); - - // - result = supportBar.low < supportBar.GetDown(); - if (!result) - { - // - supportBar.Clean(); - return result; - } - - // - double selectedValue = supportBar.GetDown(); - - // - int llIDX = bar.FindLowestIndex(range - 1, MODE_LOW); - result = IsValidIndex(llIDX); - if (!result) - { - // - supportBar.Clean(); - return result; - } - - // - double llValue = iLow( - bar.symbol, - bar.period, - llIDX // - ); - - // - result = llValue >= selectedValue; - if (!result) - { - // - supportBar.Clean(); - return result; - } - - // - result = supportBar.IsValid(); - - // - return result; - } - - /** - * Check a Bar is Resistance Bar or not ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Specified Verifiation Range ... - * - * @return ( bool ) - */ - bool IsResistance( - XOHCL &bar, - int range = 21 // - ) - { - // - bool result = false; - - // - if (range < 2) - { - range = 2; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = bar.Index(); - result = range > 0 && - index >= range; - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - for (int i = 1; i <= range; i++) - { - // - int prevIDX = index + i; - int nextIDX = index - 1; - - // - // Prev Bar ... - XOHCL iPrevBar; - result = iPrevBar.Init( - symbol, - period, - prevIDX // - ); - if (!result) - { - break; - } - - // - // Next Bar ... - XOHCL iNextBar; - result = iNextBar.Init( - symbol, - period, - nextIDX // - ); - if (!result) - { - break; - } - - // - result = bar.high >= iPrevBar.high && - bar.high >= iNextBar.high; - if (!result) - { - break; - } - } - - // - return result; - } - - /** - * Check a Bar Has Resistance or not ... - * - * @param bar: XOHCL instance ... - * @param resistanceBar: XOHCL instance Specified Resistance Bar ... - * @param rage: int, - * @return ( bool ) - */ - bool HasResistance( - XOHCL &bar, - XOHCL &resistanceBar, - int range = 21 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int barIndex = bar.Index() + range; - result = IsValidIndex(barIndex); - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - result = resistanceBar.Init( - bar.symbol, - bar.period, - barIndex // - ); - - // - result = resistanceBar.low < resistanceBar.GetDown(); - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - - // - double selectedValue = resistanceBar.GetUp(); - - // - int hhIDX = bar.FindHighestIndex(range - 1, MODE_HIGH); - result = IsValidIndex(hhIDX); - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - - // - double hhValue = iHigh( - bar.symbol, - bar.period, - hhIDX // - ); - - // - result = hhValue >= selectedValue; - if (!result) - { - // - resistanceBar.Clean(); - return result; - } - - // - result = resistanceBar.IsValid(); - - // - return result; - } - - // - // Order Blocks ... - - /** - * Detect an Order Block Based on Given Bar ... - * - * @param bar: XOHCL instance, Specified Start Bar ... - * @param ob: XOHCL instance, Fill it if Order Block Found ... - * @param dir: ENUM_X_DIRECTION member, Specified Founded Order Block Direction ... - * @param sameBars: Integer, Specified Min Same Bars for Detecting Order Block ... - * - * @return ( bool ) - */ - bool HasOrderBlock( - XOHCL &bar, - XOHCL &ob, - ENUM_X_DIRECTION &dir, - int sameBars = 3 // - ) - { - // - bool result = false; - - // - ob.Clean(); - dir = X_DIRECTION_NONE; - - // - if (sameBars < 1) - { - sameBars = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = 0; - result = HasSameBars( - bar, - dir, - index, - sameBars // - ); - if (!result) - { - return result; - } - - // - int obIndex = index + 1; - result = ob.Init( - bar.symbol, - bar.period, - obIndex // - ); - if (!result) - { - return result; - } - - // - return result; - } - - // - // Fair Value Gaps ... - - /** - * Detect a Fair Value Gap Based on Given Bar ... - * - * @param bar: XOHCL instance, Specified Start Bar ... - * @param dir: ENUM_X_DIRECTION member, Specified Founded Order Block Direction ... - * @param sameBars: Integer, Specified Min Same Bars for Detecting Order Block ... - * - * @return ( bool ) - */ - bool HasFairValueGap( - XOHCL &bar, - XOHCL &prevBar, - XOHCL &nextBar, - ENUM_X_DIRECTION &dir, - int sameBars = 3 // - ) - { - // - bool result = false; - - // - prevBar.Clean(); - nextBar.Clean(); - dir = X_DIRECTION_NONE; - - // - if (sameBars < 1) - { - sameBars = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int index = 0; - result = HasSameBars( - bar, - dir, - index, - sameBars // - ); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(dir); - - // - int to = bar.Index(); - int from = - index > (to + sameBars) - ? to + sameBars - : index; - for (int i = from; i > to; i--) - { - // - result = prevBar.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - break; - } - - // - result = nextBar.Init( - bar.symbol, - bar.period, - i - 2 // - ); - if (!result) - { - break; - } - - // - result = isBullish - ? prevBar.high < nextBar.low - : prevBar.low > nextBar.high; - if (result) - { - break; - } - } - - // - if (!result) - { - // - prevBar.Clean(); - nextBar.Clean(); - dir = X_DIRECTION_NONE; - } - - // - return result; - } - - // - // Bar CHOCH ... - - /** - * Check Specified Bar Has PullBack or not ... - * - * @param dir: ENUM_X_DIRECTION member, Specified Direction ... - * @param bar: XOHCL instance, Speciied Bar ... - * @param loopback: Integer, loopback Length ... - * @param forceBody: Boolean, Specified Choch Happens only by Bar's Body ... - * - * @return ( bool ) - */ - bool HasPullBack( - ENUM_X_DIRECTION &dir, - XOHCL &bar, - int loopback = 3, - bool forceBody = false // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - if (loopback < 1) - { - loopback = 1; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - string symbol = bar.symbol; - ENUM_TIMEFRAMES period = bar.period; - - // - // Calculate Loopback Data ... - int index = -1; - int start = -1; - int end = -1; - int count = -1; - result = CalculateLoopBackData( - index, - start, - end, - count, - bar, - loopback // - ); - if (!result) - { - return result; - } - - // - // Calculate Loopback HH and LL Data ... - int hhIDX = -1; - double hh = -1; - int llIDX = -1; - double ll = -1; - result = CalculateLoopbackHLData( - hhIDX, - hh, - llIDX, - ll, - bar, - loopback // - ); - if (!result) - { - return result; - } - - // - bool isBullishDirection = - bar.high > hh && - bar.low > ll; - bool isBearishDirection = - bar.high < hh && - bar.low < ll; - result = isBullishDirection || - isBearishDirection; - if (!result) - { - return result; - } - - // - if (forceBody) - { - // - isBullishDirection = - bar.GetUp() > hh && - bar.GetDown() > ll; - isBearishDirection = - bar.GetUp() < hh && - bar.GetDown() < ll; - result = isBullishDirection || - isBearishDirection; - if (!result) - { - return result; - } - } - - // - // Check Bar's Direction in related to CHOCH Direction ... - result = - isBullishDirection - ? bar.IsBullish() - : bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Set Direction ... - dir = - isBullishDirection - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - // Check Loopback End Bar ... - XOHCL endBar; - result = endBar.Init( - symbol, - period, - end - 1 // - ); - if (!result) - { - return result; - } - - // - // End Bar Must be InDirect by Specified Bar ... - result = - isBullishDirection - ? endBar.IsBearish() - : endBar.IsBullish(); - - // - // Check Loopback for Directional Bars ... - - // - return result; - } - - // - // Tools ... - - // - bool IsStrong( - XOHCL &bar, - double percent = 50 // Percent of Body - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = - (bar.GetRange() * percent) / 100 <= bar.GetBody(); - - // - return result; - } - - // - bool HasStrongLowShadow( - XOHCL &bar, - double percent = 50, // Percent of Body - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = - (bar.GetRange() * percent) / 100 <= bar.GetLowShadow(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - result = bar.Index() > __loopback; - if (!result) - { - return result; - } - - // - // Get Highest High and Lowest Low in loopback Range ... - int startIndex = bar.Index() - __loopback; - int endIndex = bar.Index() + __loopback; - int requiredBars = MathAbs(endIndex - startIndex); - - // - // Highs ... - double highs[]; - int copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - - // - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - int highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - double highestHigh = highs[highestHighIDX]; - - // - // Lows ... - double lows[]; - int copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - - // - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - int lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - double lowestLow = lows[lowestLowIDX]; - - // - result = bar.low == lowestLow && - highestHigh > bar.high; - if (!result) - { - return result; - } - - // - // Try to Validate Sharp Ratio ... - - // - Clean(highs); - Clean(lows); - - // - // Left Side ... - startIndex = bar.Index() + 1; - endIndex = startIndex + (__loopback / 2) - 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double leftDiff = highestHigh - lowestLow; - - // - Clean(highs); - Clean(lows); - - // - // Right Side ... - startIndex = bar.Index() - 1; - endIndex = startIndex - (__loopback / 2) + 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double rightDiff = highestHigh - lowestLow; - double diff = MathMax(leftDiff, rightDiff); - result = bar.GetLowShadow() >= (diff / 100) * _sharpRatio; - - // - return result; - } - - // - bool HasStrongHighShadow( - XOHCL &bar, - double percent = 50, // Percent of Body - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = - (bar.GetRange() * percent) / 100 <= bar.GetHighShadow(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - result = bar.Index() > __loopback; - if (!result) - { - return result; - } - - // - // Get Highest High and Lowest Low in loopback Range ... - int startIndex = bar.Index() - __loopback; - int endIndex = bar.Index() + __loopback; - int requiredBars = MathAbs(endIndex - startIndex); - - // - // Highs ... - double highs[]; - int copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - - // - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - int highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - double highestHigh = highs[highestHighIDX]; - - // - // Lows ... - double lows[]; - int copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - - // - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - int lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - double lowestLow = lows[lowestLowIDX]; - - // - result = bar.high == highestHigh && - lowestLow < bar.low; - if (!result) - { - return result; - } - - // - // Try to Validate Sharp Ratio ... - - // - Clean(highs); - Clean(lows); - - // - // Left Side ... - startIndex = bar.Index() + 1; - endIndex = startIndex + (__loopback / 2) - 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double leftDiff = highestHigh - lowestLow; - - // - Clean(highs); - Clean(lows); - - // - // Right Side ... - startIndex = bar.Index() - 1; - endIndex = startIndex - (__loopback / 2) + 1; - requiredBars = MathAbs(endIndex - startIndex); - - // - copiedHighs = CopyHigh( - bar.symbol, - bar.period, - startIndex, - requiredBars, - highs // - ); - result = copiedHighs == requiredBars; - if (!result) - { - return result; - } - - // - highestHighIDX = ArrayMaximum(highs); - result = IsValidIndex(highestHighIDX); - if (!result) - { - return result; - } - - // - highestHigh = highs[highestHighIDX]; - - // - copiedLows = CopyLow( - bar.symbol, - bar.period, - startIndex, - requiredBars, - lows // - ); - result = copiedLows == requiredBars; - if (!result) - { - return result; - } - - // - lowestLowIDX = ArrayMinimum(lows); - result = IsValidIndex(lowestLowIDX); - if (!result) - { - return result; - } - - // - lowestLow = lows[lowestLowIDX]; - - // - double rightDiff = highestHigh - lowestLow; - double diff = MathMax(leftDiff, rightDiff); - result = bar.GetHighShadow() >= (diff / 100) * _sharpRatio; - - // - return result; - } - - // - bool IsStrongBullish( - XOHCL &bar, - double percent = 50 // Percent of Body - ) - { - // - bool result = false; - - // - result = - bar.IsValid() && - bar.IsBullish() && - IsStrong(bar, percent); - - // - return result; - } - - // - bool IsStrongBearish( - XOHCL &bar, - double percent = 50 // Percent of Body - ) - { - // - bool result = false; - - // - result = - bar.IsValid() && - bar.IsBearish() && - IsStrong(bar, percent); - - // - return result; - } - - // - bool IsSharpBullish( - XOHCL &bar, - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - int hIDX = bar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - int lIDX = bar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - result = - // - hIDX >= 0 && - lIDX >= 0 && - MathAbs(hIDX - bar.Index()) < 2 - // - ; - - // - if (!result) - { - return result; - } - - // - XOHCL hBar; - result = hBar.Init( - bar.symbol, - bar.period, - hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL lBar; - result = lBar.Init( - bar.symbol, - bar.period, - lIDX // - ); - if (!result) - { - return result; - } - - // - double lhDif = hBar.high - lBar.low; - - // - int hhIDX = hBar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - - // - int llIDX = lBar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - XOHCL hhBar; - result = hhBar.Init( - bar.symbol, - bar.period, - hhIDX + hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL llBar; - result = llBar.Init( - bar.symbol, - bar.period, - llIDX + lIDX // - ); - if (!result) - { - return result; - } - - // - double llhhDif = hhBar.high - llBar.low; - - // - result = - // - lBar.low > llBar.low && - hBar.high > hhBar.high && - lhDif >= llhhDif * _sharpRatio - // - ; - - // - return result; - } - - // - bool IsSharpBearish( - XOHCL &bar, - int __loopback = 2, - double _sharpRatio = 2.5 // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (__loopback < 0) - { - __loopback = 2; - } - - // - if (_sharpRatio < 0) - { - _sharpRatio = 2.5; - } - - // - int hIDX = bar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - int lIDX = bar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - result = - // - hIDX >= 0 && - lIDX >= 0 && - MathAbs(hIDX - bar.Index()) < 2 - // - ; - - // - if (!result) - { - return result; - } - - // - XOHCL hBar; - result = hBar.Init( - bar.symbol, - bar.period, - hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL lBar; - result = lBar.Init( - bar.symbol, - bar.period, - lIDX // - ); - if (!result) - { - return result; - } - - // - double lhDif = hBar.high - lBar.low; - - // - int hhIDX = hBar.FindHighestIndex( - __loopback, - MODE_HIGH // - ); - - // - int llIDX = lBar.FindLowestIndex( - __loopback, - MODE_LOW // - ); - - // - XOHCL hhBar; - result = hhBar.Init( - bar.symbol, - bar.period, - hhIDX + hIDX // - ); - if (!result) - { - return result; - } - - // - XOHCL llBar; - result = llBar.Init( - bar.symbol, - bar.period, - llIDX + lIDX // - ); - if (!result) - { - return result; - } - - // - double llhhDif = hhBar.high - llBar.low; - - // - result = - // - lBar.low < llBar.low && - hBar.high < hhBar.high && - lhDif >= llhhDif * _sharpRatio - // - ; - - // - return result; - } - - // - // - // - - // - // Retrieve Bullish Pressure ... - double GetBullishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - result += bars[i].GetLowShadow(); - } - - // - return result; - } - - // - // Retrieve Bearish Pressure ... - double GetBearishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - result += bars[i].GetHighShadow(); - } - - // - return result; - } - - // - bool HasBullishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPressure(bar, __loopback); - double bearishPressure = GetBearishPressure(bar, __loopback); - - // - result = - // - bullishPressure > 0 && - bearishPressure >= 0 && - bullishPressure > bearishPressure - // - ; - - // - return result; - } - - // - bool HasBearishPressure( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPressure(bar, __loopback); - double bearishPressure = GetBearishPressure(bar, __loopback); - - // - result = - // - bearishPressure > 0 && - bullishPressure >= 0 && - bearishPressure > bullishPressure - // - ; - - // - return result; - } - - // - // Retrieve Bullish Power ... - double GetBullishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - // - if (bars[i].IsBullish()) - { - result += bars[i].GetBody(); - } - } - - // - return result; - } - - // - // Retrieve Bearish Pressure ... - double GetBearishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - double result = 0; - - // - if (!bar.IsValid()) - { - return result; - } - - // - XOHCL bars[]; - int barsCount = GetBars( - bars, - bar.symbol, - bar.period, - bar.Index(), - __loopback // - ); - if (!IsValidSize(barsCount)) - { - return result; - } - - // - for (int i = 0; i < barsCount; i++) - { - // - if (bars[i].IsBearish()) - { - result += bars[i].GetBody(); - } - } - - // - return result; - } - - // - bool HasBullishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPower(bar, __loopback); - double bearishPressure = GetBearishPower(bar, __loopback); - - // - result = - // - bullishPressure > 0 && - bearishPressure >= 0 && - bullishPressure > bearishPressure - // - ; - - // - return result; - } - - // - bool HasBearishPower( - XOHCL &bar, - int __loopback = 7 // - ) - { - // - bool result = false; - - // - if (__loopback < 0) - { - __loopback = 7; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double bullishPressure = GetBullishPower(bar, __loopback); - double bearishPressure = GetBearishPower(bar, __loopback); - - // - result = - // - bearishPressure > 0 && - bullishPressure >= 0 && - bearishPressure > bullishPressure - // - ; - - // - return result; - } - - // - // Decisions ... - - // - bool IsBullishDecision( - XOHCL &bar, - double percent = 70 // Percent of Body - ) - { - // - bool result = false; - - // - result = - // - bar.IsValid() && - bar.Index() > 0 && - bar.IsBullish() && - (bar.GetRange() * percent) / 100 <= bar.GetBody() - // - ; - - // - return result; - } - - // - bool IsBearishDecision( - XOHCL &bar, - double percent = 70 // Percent of Body - ) - { - // - bool result = false; - - // - result = - // - bar.IsValid() && - bar.Index() > 0 && - bar.IsBearish() && - (bar.GetRange() * percent) / 100 <= bar.GetBody() - // - ; - - // - return result; - } - - // - // Candlestic Patterns ... - - // - // Check Doji ... - bool IsDoji( - XOHCL &bar // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = bar.open == bar.close; - - // - return result; - } - - // - // Check Hammer ... - bool IsHammer( - XOHCL &bar, - double _upShadowFactor = 0.1, - double _downShadowFactor = 0.6, - bool applyFib382Check = true, - bool applyPrevShadowCheck = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_upShadowFactor < 0) - { - _upShadowFactor = 0.1; - } - - // - if (_downShadowFactor < 0) - { - _upShadowFactor = 0.6; - } - - // - double range = bar.GetRange(); - - // - // Check Upper Shadow Must be 0 or Under 10% ... - double upShadow = bar.GetHighShadow(); - result = upShadow < range * _upShadowFactor; - if (!result) - { - return result; - } - - // - // Check Down Shadow Must at least 60% ... - double downShadow = bar.GetLowShadow(); - result = downShadow > range * _downShadowFactor; - if (!result) - { - return result; - } - - // - // Check Fib 382 ... - if (result && applyFib382Check) - { - // - double fib382 = GetFibonacciLevel( - bar.high, - bar.low, - 0.382, - -1 // - ); - result = bar.GetDown() > fib382; - } - - // - // Check Shadow Based on Prev Bar ... - if (result && applyPrevShadowCheck) - { - // - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - result = bar.low < pBar.low; - } - - // - return result; - } - - // - // Check Sgooting Star ... - // Reversal Hammer ... - bool IsShootingStar( - XOHCL &bar, - double _upShadowFactor = 0.6, - double _downShadowFactor = 0.1, - bool applyFib382Check = true, - bool applyPrevShadowCheck = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_upShadowFactor < 0) - { - _upShadowFactor = 0.6; - } - - // - if (_downShadowFactor < 0) - { - _upShadowFactor = 0.1; - } - - // - double range = bar.GetRange(); - - // - // Check Upper Shadow Must be 0 or Under 10% ... - double upShadow = bar.GetHighShadow(); - result = upShadow > range * _upShadowFactor; - if (!result) - { - return result; - } - - // - // Check Down Shadow Must at least 60% ... - double downShadow = bar.GetLowShadow(); - result = downShadow < range * _downShadowFactor; - if (!result) - { - return result; - } - - // - // Check Fib 382 ... - if (result && applyFib382Check) - { - // - double fib382 = GetFibonacciLevel( - bar.high, - bar.low, - 0.382, - 1 // - ); - result = bar.GetUp() < fib382; - } - - // - // Check Shadow Based on Prev Bar ... - if (result && applyPrevShadowCheck) - { - // - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - result = bar.high > pBar.high; - } - - // - return result; - } - - // - // Check Bullish Engulfing ... - bool IsBullishEngulfing( - XOHCL &bar, - double _engulfBarBodyFactor = 0.7 // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_engulfBarBodyFactor < 0) - { - _engulfBarBodyFactor = 0.7; - } - - // - // Check Bar Is Bullish ... - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double body = bar.GetBody(); - - // - // Check Prev Bar Must Bearish ... - result = pBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Check Shadows Engulf Prev Bar ... - result = - // - bar.high > pBar.high && - bar.low <= pBar.low - // - ; - if (!result) - { - return result; - } - - // - // Check Engulfed Bar Must Inside Engulfer Body ... - result = - // - bar.GetUp() > pBar.GetUp() && - bar.GetDown() < pBar.GetDown() - // - ; - if (!result) - { - return result; - } - - // - // Check Body of Engulfing Bar ... - if (result && _engulfBarBodyFactor > 0) - { - result = body >= range * _engulfBarBodyFactor; - } - - // - return result; - } - - // - // Check Bearish Engulfing ... - bool IsBearishEngulfing( - XOHCL &bar, - double _engulfBarBodyFactor = 0.7 // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_engulfBarBodyFactor < 0) - { - _engulfBarBodyFactor = 0.7; - } - - // - // Check Bar Is Bearish ... - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double body = bar.GetBody(); - - // - // Check Prev Bar Must Bullish ... - result = pBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Check Shadows Engulf Prev Bar ... - result = bar.high >= pBar.high && - bar.low < pBar.low; - if (!result) - { - return result; - } - - // - // Check Engulfed Bar Must Inside Engulfer Body ... - result = - // - bar.GetUp() > pBar.GetUp() && - bar.GetDown() < pBar.GetDown() - // - ; - if (!result) - { - return result; - } - - // - // Check Body of Engulfing Bar ... - if (result && _engulfBarBodyFactor > 0) - { - result = body >= range * _engulfBarBodyFactor; - } - - // - return result; - } - - // - // Check Morning Star Pattern ... - bool IsMorningStar( - XOHCL &bar, - double _middleRangeFactor = 0.3, - double _startBodyFactor = 0.6, - bool forceCheckMiddleBarDirection = true, - bool forceCheckStartBody = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_middleRangeFactor < 0) - { - _middleRangeFactor = 0.3; - } - - // - if (_startBodyFactor < 0) - { - _startBodyFactor = 0.6; - } - - // - // Current Bar Must be Bullish ... - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar must be Bearish ... - if (result && forceCheckMiddleBarDirection) - { - // - result = pBar.IsBearish(); - if (!result) - { - return result; - } - } - - // - // Retrieve Previous Bar of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev Of Prev Bar Must be Bearish ... - result = ppBar.IsBearish(); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double pRange = pBar.GetRange(); - double ppRange = ppBar.GetRange(); - - // - // Middle Bar must be Smaller than Ratio of other ... - result = - // - pRange < range * _middleRangeFactor && - pRange < ppRange * _middleRangeFactor - // - ; - if (!result) - { - return result; - } - - // - if (result && forceCheckStartBody) - { - // - result = ppBar.GetBody() > ppRange * _startBodyFactor; - if (!result) - { - return result; - } - } - - // - return result; - } - - // - // Check Evening Star Pattern ... - bool IsEveningStar( - XOHCL &bar, - double _middleRangeFactor = 0.3, - double _startBodyFactor = 0.6, - bool forceCheckMiddleBarDirection = true, - bool forceCheckStartBody = true // - ) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - if (_middleRangeFactor < 0) - { - _middleRangeFactor = 0.3; - } - - // - if (_startBodyFactor < 0) - { - _startBodyFactor = 0.6; - } - - // - // Current Bar Must be Bearish ... - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Previous Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar must be Bullish ... - if (result && forceCheckMiddleBarDirection) - { - // - result = pBar.IsBullish(); - if (!result) - { - return result; - } - } - - // - // Retrieve Previous Bar of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev Of Prev Bar Must be Bullish ... - result = ppBar.IsBullish(); - if (!result) - { - return result; - } - - // - double range = bar.GetRange(); - double pRange = pBar.GetRange(); - double ppRange = ppBar.GetRange(); - - // - // Middle Bar must be Smaller than Ratio of other ... - result = - // - pRange < range * _middleRangeFactor && - pRange < ppRange * _middleRangeFactor - // - ; - if (!result) - { - return result; - } - - // - if (result && forceCheckStartBody) - { - // - result = ppBar.GetBody() > ppRange * _startBodyFactor; - if (!result) - { - return result; - } - } - - // - return result; - } - - // - // Bullish Marubozu ... - bool IsBullishMarubozu(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - result = - // - bar.GetUp() == bar.high && - bar.GetDown() == bar.low - // - ; - - // - return result; - } - - // - // Bearish Marubozu ... - bool IsBearishMarubozu(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - result = - // - bar.GetUp() == bar.high && - bar.GetDown() == bar.low - // - ; - - // - return result; - } - - // - // Contextual Patterns ... - - // - // Check Swing High ... - bool IsBarSwingHigh(XOHCL &bar) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bearish ... - result = bar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bullish ... - result = pBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bullish ... - result = ppBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Check All Highs ... - result = - // - bar.high < pBar.high && - pBar.high > ppBar.high - // - ; - - // - return result; - } - - // - // Find Simple 3 Candle Based Swing High ... - bool IsSimpleSwingHigh( - XOHCL &bar, - double thresholdInPoint = 1 // - ) - { - // - bool result = false; - - // - int index = bar.Index(); - result = index > 0; - if (!result) - { - return result; - } - - // - XOHCL nextBar; - result = bar.GetNextBar(nextBar); - if (!result) - { - return result; - } - - // - XOHCL prevBar; - result = bar.GetPreviousBar(prevBar); - if (!result) - { - return result; - } - - // - double point = GetPoints(bar.symbol); - double requiredOffset = point * thresholdInPoint; - - // - result = - bar.high > nextBar.high && - bar.high > prevBar.high && - (thresholdInPoint <= 0 - ? true - : MathAbs( - MathMax( - nextBar.high, - prevBar.high) - - bar.high) >= requiredOffset); - - // - return result; - } - - // - // Find Last Swing High ... - bool FindLastSwingHigh( - XOHCL &bar, - XOHCL &swing // - ) - { - // - bool result = false; - - // - swing.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = iBars( - bar.symbol, - bar.period // - ); - int maxAllowed = MathMin(100, (totalBars / 100)); - - // - int idx = bar.Index(); - for (int i = idx; i <= idx + maxAllowed; i++) - { - // - swing.Clean(); - result = swing.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - // - swing.Clean(); - break; - } - - // - result = IsBarSwingHigh(swing); - if (result) - { - break; - } - } - - // - return result; - } - - // - // Check Swing Low ... - bool IsBarSwingLow(XOHCL &bar) - { - // - bool result = false; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bullish ... - result = bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bearish ... - result = pBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bearish ... - result = ppBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Check All Lows ... - result = - // - bar.low > pBar.low && - pBar.low < ppBar.low - // - ; - - // - return result; - } - - // - // Find Simple 3 Candle Based Swing Low ... - bool IsSimpleSwingLow( - XOHCL &bar, - double thresholdInPoint = 1 // - ) - { - // - bool result = false; - - // - int index = bar.Index(); - result = index > 0; - if (!result) - { - return result; - } - - // - XOHCL nextBar; - result = bar.GetNextBar(nextBar); - if (!result) - { - return result; - } - - // - XOHCL prevBar; - result = bar.GetPreviousBar(prevBar); - if (!result) - { - return result; - } - - // - double point = GetPoints(bar.symbol); - double requiredOffset = point * thresholdInPoint; - - // - result = - bar.low < nextBar.low && - bar.low < prevBar.low && - (thresholdInPoint <= 0 - ? true - : MathAbs( - MathMax( - nextBar.low, - prevBar.low) - - bar.low) >= requiredOffset); - - // - return result; - } - - // - // Find Last Swing Low ... - bool FindLastSwingLow( - XOHCL &bar, - XOHCL &swing // - ) - { - // - bool result = false; - - // - swing.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = iBars( - bar.symbol, - bar.period // - ); - int maxAllowed = MathMin(100, (totalBars / 100)); - - // - int idx = bar.Index(); - for (int i = idx; i <= idx + maxAllowed; i++) - { - // - swing.Clean(); - result = swing.Init( - bar.symbol, - bar.period, - i // - ); - if (!result) - { - // - swing.Clean(); - break; - } - - // - result = IsBarSwingLow(swing); - if (result) - { - break; - } - } - - // - return result; - } - - // - // Check Bullish FVG ... - bool HasBullishFVG( - XOHCL &bar, - double &upper, - double &lower, - datetime &start, - datetime &end, - bool forceMiddleBarCheck = true, - bool forceCheckLastBarDirection = false // - ) - { - // - bool result = false; - - // - upper = 0; - lower = 0; - - // - end = NULL; - start = NULL; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bullish ... - result = - !forceCheckLastBarDirection - ? true - : bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bullish ... - result = pBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bullish ... - result = ppBar.IsBullish(); - if (!result) - { - return result; - } - - // - // Other Conditions ... - result = - // - bar.low > ppBar.high - // - ; - - // - // Check Middle Bar Range ... - if (result && forceMiddleBarCheck) - { - // - result = - // - pBar.high > bar.low && - pBar.low < ppBar.high - // - ; - - // - if (!result) - { - return result; - } - } - - // - if (result) - { - // - end = bar.time; - upper = bar.low; - lower = ppBar.high; - start = ppBar.time; - } - - // - return result; - } - - // - // Check Bearish FVG ... - bool HasBearishFVG( - XOHCL &bar, - double &upper, - double &lower, - datetime &start, - datetime &end, - bool forceMiddleBarCheck = true, - bool forceCheckLastBarDirection = false // - ) - { - // - bool result = false; - - // - upper = 0; - lower = 0; - - // - end = NULL; - start = NULL; - - // - // Validate Content and Ignore 0 Bar - // since it is not Completed ... - result = bar.IsValid() && bar.Index() > 0; - if (!result) - { - return result; - } - - // - // Current Bar Must be Bearish ... - result = - !forceCheckLastBarDirection - ? true - : bar.IsBullish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev Bar ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - // Prev Bar Must be Bearish ... - result = pBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Retrieve Prev of Prev Bar ... - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Prev of Prev Bar Must be Bearish ... - result = ppBar.IsBearish(); - if (!result) - { - return result; - } - - // - // Other Conditions ... - result = - // - bar.high < ppBar.low - // - ; - - // - // Check Middle Bar Range ... - if (result && forceMiddleBarCheck) - { - // - result = - // - pBar.high > bar.low && - pBar.low < ppBar.high - // - ; - - // - if (!result) - { - return result; - } - } - - // - if (result) - { - // - end = bar.time; - lower = bar.high; - upper = ppBar.low; - start = ppBar.time; - } - - // - return result; - } - - // - // Find Support ... - bool HasSupport( - XOHCL &bar, - XOHCL &dest, - ENUM_X_PRICE type = X_PRICE_CLOSE, - int _loopback = 21, - int tries = 100 // - ) - { - // - bool result = false; - - // - dest.Clean(); - - // - if (_loopback < 0) - { - _loopback = 21; - } - - // - if (tries < 0) - { - tries = 100; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - for (int i = 1; i < tries; i++) - { - // - int _length = _loopback * i; - - // - int lowestIDX = bar.FindLowestIndex( - _length, - MODE_LOW // - ); - result = IsValidIndex(lowestIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - lowestIDX // - ); - if (!result) - { - break; - } - - // - result = - // - price > iLBar.high - // - ; - if (result) - { - // - dest = iLBar; - break; - } - } - - // - result = dest.IsValid(); - - // - return result; - } - - // - // Find Resistance ... - bool HasResistance( - XOHCL &bar, - XOHCL &dest, - ENUM_X_PRICE type = X_PRICE_CLOSE, - int _loopback = 21, - int tries = 100 // - ) - { - // - bool result = false; - - // - dest.Clean(); - - // - if (_loopback < 0) - { - _loopback = 21; - } - - // - if (tries < 0) - { - tries = 100; - } - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - for (int i = 1; i < tries; i++) - { - // - int _length = _loopback * i; - - // - int highestIDX = bar.FindHighestIndex( - _length, - MODE_LOW // - ); - result = IsValidIndex(highestIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - highestIDX // - ); - if (!result) - { - break; - } - - // - result = - // - price < iHBar.high - // - ; - if (result) - { - // - dest = iHBar; - break; - } - } - - // - result = dest.IsValid(); - - // - return result; - } - - // - // Trend Detection ... - - // - // Find Bullish Trend ... - bool HasBullishTrend( - XOHCL &bar, - XOHCL &highSwingBars[], - XOHCL &lowSwingBars[], - bool forceMethod2 = false, - int _loopback = 3, - int tries = 3, - ENUM_X_PRICE type = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - Clean(lowSwingBars); - Clean(highSwingBars); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - int lastIDX = bar.Index(); - double lastH = 0; - double lastL = 0; - for (int i = 1; i < tries + 1; i++) - { - // - // Use Regular Method ... - if (!forceMethod2) - { - // - int iHIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_HIGH, - _loopback, - lastIDX // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH < lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_LOW, - _loopback, - lastIDX // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL < lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - // - // Use Other MEthod ... - else - { - // - int _length = i * _loopback; - int start = - // - i == 1 - ? 1 - : _length - _loopback - // - ; - - // - int iHIDX = iHighest( - bar.symbol, - bar.period, - MODE_HIGH, - _loopback, - start // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH < lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = iLowest( - bar.symbol, - bar.period, - MODE_LOW, - _loopback, - start // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL < lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - } - - // - if (result) - { - // - result = - // - ArraySize(lowSwingBars) == tries && - ArraySize(highSwingBars) == tries - // - ; - } - - // - if (!result) - { - // - Clean(lowSwingBars); - Clean(highSwingBars); - } - - // - return result; - } - - // - // Find Bearish Trend ... - bool HasBearishTrend( - XOHCL &bar, - XOHCL &highSwingBars[], - XOHCL &lowSwingBars[], - bool forceMethod2 = false, - int _loopback = 3, - int tries = 3, - ENUM_X_PRICE type = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - Clean(lowSwingBars); - Clean(highSwingBars); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - double price = bar.GetPrice(type); - - // - int lastIDX = bar.Index(); - double lastH = 0; - double lastL = 0; - for (int i = 1; i < tries + 1; i++) - { - // - // Use Regular Method ... - if (!forceMethod2) - { - // - int iHIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_HIGH, - _loopback, - lastIDX // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH > lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = FindSwing( - bar.symbol, - bar.period, - X_SWING_LOW, - _loopback, - lastIDX // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL > lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - // - // Use Other MEthod ... - else - { - // - int _length = i * _loopback; - int start = - // - i == 1 - ? 1 - : _length - _loopback - // - ; - - // - int iHIDX = iHighest( - bar.symbol, - bar.period, - MODE_HIGH, - _loopback, - start // - ); - result = IsValidIndex(iHIDX); - if (!result) - { - break; - } - - // - XOHCL iHBar; - result = iHBar.Init( - bar.symbol, - bar.period, - iHIDX // - ); - if (!result) - { - break; - } - - // - double iH = iHBar.high; - bool isIHAccepted = - // - iH > 0 && - ( - // - lastH == 0 - ? true - : iH > lastH - // - ) - // - ; - if (isIHAccepted) - { - // - AddRef( - iHBar, - highSwingBars // - ); - - // - lastH = iH; - lastIDX = iHIDX; - } - - // - int iLIDX = iLowest( - bar.symbol, - bar.period, - MODE_LOW, - _loopback, - start // - ); - result = IsValidIndex(iLIDX); - if (!result) - { - break; - } - - // - XOHCL iLBar; - result = iLBar.Init( - bar.symbol, - bar.period, - iLIDX // - ); - if (!result) - { - break; - } - - // - double iL = iLBar.low; - bool isILAccepted = - // - iL > 0 && - ( - // - lastL == 0 - ? true - : iL > lastL - // - ) - // - ; - if (isILAccepted) - { - // - AddRef( - iLBar, - lowSwingBars // - ); - - // - lastL = iL; - lastIDX = iLIDX; - } - } - } - - // - if (result) - { - // - result = - // - ArraySize(lowSwingBars) == tries && - ArraySize(highSwingBars) == tries - // - ; - } - - // - if (!result) - { - // - Clean(lowSwingBars); - Clean(highSwingBars); - } - - // - return result; - } - - // - // Order Blocks ... - - // - // Find Bullish Order Block ... - bool HasBullishOrderBlock( - XOHCL &bar, - XOHCL &orderBlock, - int _minimumSameBars = 4 // - ) - { - // - bool result = false; - - // - orderBlock.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (_minimumSameBars < 0) - { - _minimumSameBars = 4; - } - - // - XOHCL cBar; - int founded = 0; - int cIDX = bar.Index(); - bool isEnough = false; - while (!isEnough) - { - // - result = cBar.Init( - bar.symbol, - bar.period, - cIDX // - ); - if (!result) - { - break; - } - - // - result = cBar.IsBullish(); - if (!result && cBar.IsBearish()) - { - break; - } - - // - cIDX++; - founded++; - } - - // - // Here we have to check founded and if it's fill - // our requirements ... - // cIDX is Order Block Index ... - result = - // - cBar.IsValid() && - bar.high > cBar.high && - founded >= _minimumSameBars - // - ; - if (!result) - { - return result; - } - - // - result = orderBlock.Init( - bar.symbol, - bar.period, - cIDX // - ); - if (!result) - { - // - orderBlock.Clean(); - return result; - } - - // - return result; - } - - // - // Find Bearish Order Block ... - bool HasBearishOrderBlock( - XOHCL &bar, - XOHCL &orderBlock, - int _minimumSameBars = 4 // - ) - { - // - bool result = false; - - // - orderBlock.Clean(); - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - if (_minimumSameBars < 0) - { - _minimumSameBars = 4; - } - - // - XOHCL cBar; - int founded = 0; - int cIDX = bar.Index(); - bool isEnough = false; - while (!isEnough) - { - // - bool isInited = cBar.Init( - bar.symbol, - bar.period, - cIDX // - ); - - // - result = cBar.IsBearish(); - if (!result && cBar.IsBullish()) - { - break; - } - - // - cIDX++; - founded++; - } - - // - // Here we have to check founded and if it's fill - // our requirements ... - // cIDX is Order Block Index ... - result = - // - cBar.IsValid() && - bar.high < cBar.low && - founded >= _minimumSameBars - // - ; - if (!result) - { - return result; - } - - // - result = orderBlock.Init( - bar.symbol, - bar.period, - cIDX // - ); - if (!result) - { - // - orderBlock.Clean(); - return result; - } - - // - return result; - } - - // - protected: - // - - // - private: - // - - // - // Props ... - - // - // Actions ... - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x-poi.class copy.mq5 b/Documents/BKP/x-saherelm.x-poi.class copy.mq5 deleted file mode 100644 index 19f644d8..00000000 --- a/Documents/BKP/x-saherelm.x-poi.class copy.mq5 +++ /dev/null @@ -1,3334 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XPOI -// Description: Provides Point of Interests ... -// - Swing Highs; -// - Swing Lows; -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... - -// -#include "../Classes/x-saherelm.x-alert.class.mq5" -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Libraries/x-saherelm.x-poi.state.lib.mq5" - -// -#include - -// -// Implementation ... - -// -// POI Detector Class ... -class XCPOIDetector : public XCBaseAlert -{ - // - public: - // - - // - // Constructors ... - /** - * Create an Instance ... - * - * @param symbol: String ... - * @param period: ENUM_TIMEFRAMES member ... - */ - void XCPOIDetector( - string symbol, - ENUM_TIMEFRAMES period) - { - // - // Attach Required Properties ... - mSymbol = symbol; - mPeriod = period; - - // - // Initialize Bar Tracker ... - mBarTracker.Init( - mSymbol, - mPeriod // - ); - - // - mBarAnalyser = new XCBarAnalyser(); - - // - // Apply Default Configurations ... - Default(); - } - - // - // Deconstructor ... - void ~XCPOIDetector() - { - Destroy(); - } - - // - // Getter(s) / Setter(s) ... - - /** - * Retrieve Detector Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - return mSymbol; - } - - /** - * Retrieve Detector Period ... - * - * @return ( ENUM_TIMEFRAMES ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - return mPeriod; - } - - /** - * Get Max Required POI(s) allowed to Holds ... - * - * @return ( int ) - */ - int MaxRequiredPOIs() - { - return mMaxRequiredPOIs; - } - - /** - * Set Max Required POI(s) allowed to Holds ... - * - * @param value: int ... - */ - void MaxRequiredPOIs(int value) - { - // - if (value < 0) - { - value = 5; - } - - // - mMaxRequiredPOIs = value; - } - - /** - * Get Max Allowed Loopback for POI(s) Detection on Initialization Process ... - * - * @return ( int ) - */ - int MaxAllowedLoopbackForInit() - { - return maxAllowedLoopbackForInit; - } - - /** - * Set Max Allowed Loopback for POI(s) Detection on Initialization Process ... - * - * @param value: int ... - */ - void MaxAllowedLoopbackForInit(int value) - { - // - if (value < 0) - { - value = 578; - } - - // - maxAllowedLoopbackForInit = value; - } - - /** - * Get Swing Range Validation ... - * - * @return ( int ) - */ - int SwingRange() - { - return mSwingRange; - } - - /** - * Set Swing Range Validation ... - * - * @param value: int ... - */ - void SwingRange(int value) - { - // - if (value < 1) - { - value = 1; - } - - // - mSwingRange = value; - } - - /** - * Get Momentum Bar Detection Extends Range ... - * - * @return ( int ) - */ - int MomentumExtend() - { - return mMomentumExtend; - } - - /** - * Set Momentum Bar Detection Extends Range ... - * - * @param value: int ... - */ - void MomentumExtend(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMomentumExtend = value; - } - - /** - * Get Momentum Bar Detection Body Percent ... - * - * @return ( double ) - */ - double MomentumBodyPercent() - { - return mMomentumBodyPercent; - } - - /** - * Set Momentum Bar Detection Body Percent ... - * - * @param value: double ... - */ - void MomentumBodyPercent(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - if (value > 100) - { - value = 100; - } - - // - mMomentumBodyPercent = value; - } - - /** - * Get Rejection Bar Detection Extends Range ... - * - * @return ( int ) - */ - int RejectionExtend() - { - return mRejectionExtend; - } - - /** - * Set Rejection Bar Detection Extends Range ... - * - * @param value: int ... - */ - void RejectionExtend(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRejectionExtend = value; - } - - /** - * Get Rejection Bar Detection Shadow Percent ... - * - * @return ( double ) - */ - double RejectionShadowPercent() - { - return mRejectionShadowPercent; - } - - /** - * Set Rejection Bar Detection Shadow Percent ... - * - * @param value: double ... - */ - void RejectionShadowPercent(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - if (value > 100) - { - value = 100; - } - - // - mRejectionShadowPercent = value; - } - - /** - * Get Support and Resistance Detection Range ... - * - * @return ( int ) - */ - int SupResRange() - { - return mSupResRange; - } - - /** - * Set Support and Resistance Detection Range ... - * - * @param value: int ... - */ - void SupResRange(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mSupResRange = value; - } - - /** - * Get use Support and Resistance Range as Start ... - * - * @return ( bool ) - */ - bool SupResRangeAsStart() - { - return mSupResRangeAsStart; - } - - /** - * Set use Support and Resistance Range as Start ... - * @param value: bool ... - */ - void SupResRangeAsStart(bool value) - { - mSupResRangeAsStart = value; - } - - /** - * Get OrderBlock Detection Same Bars ... - * - * @return ( int ) - */ - int OrderBlockSameBars() - { - return mOrderBlockSameBars; - } - - /** - * Set OrderBlock Detection Same Bars ... - * - * @param value: int ... - */ - void OrderBlockSameBars(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mOrderBlockSameBars = value; - } - - /** - * Get FairValueGap Detection Same Bars ... - * - * @return ( int ) - */ - int FairValueGapSameBars() - { - return mFairValueGapSameBars; - } - - /** - * Set FairValueGap Detection Same Bars ... - * - * @param value: int ... - */ - void FairValueGapSameBars(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mFairValueGapSameBars = value; - } - - /** - * Get Minimum Length of Cnsolidation Zone ... - * - * @return ( int ) - */ - int ConsolidationZoneMinLoopback() - { - return mConsolidationZoneMinLoopback; - } - - /** - * Set Minimum Length of Cnsolidation Zone ... - * - * @param value: int ... - */ - void ConsolidationZoneMinLoopback(int value) - { - // - if (value < 1) - { - value = 1; - } - - // - mConsolidationZoneMinLoopback = value; - } - - /** - * Get Consolidation Zone Range in Point ... - * - * @return ( double ) - */ - double ConsolidationZoneRangeInPoint() - { - return mConsolidationZoneRangeInPoint; - } - - /** - * Set Consolidation Zone Range in Point ... - * - * @param value: double - */ - void ConsolidationZoneRangeInPoint(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - mConsolidationZoneRangeInPoint = value; - } - - /** - * Get Consolidation Zone Upper Applied To ... - * - * @return ( ENUM_APPLIED_PRICE ) - */ - ENUM_APPLIED_PRICE ConsolidationZonesLowerAppliedTo() - { - return mConsolidationZonesLowerAppliedTo; - } - - /** - * Set Consolidation Zone Upper Applied To ... - * - * @param value: ENUM_APPLIED_PRICE - */ - void ConsolidationZonesLowerAppliedTo(ENUM_APPLIED_PRICE value = PRICE_LOW) - { - mConsolidationZonesLowerAppliedTo = value; - } - - /** - * Get Consolidation Zone Lower Applied To ... - * - * @return ( ENUM_APPLIED_PRICE ) - */ - ENUM_APPLIED_PRICE ConsolidationZonesUpperAppliedTo() - { - return mConsolidationZonesUpperAppliedTo; - } - - /** - * Set Consolidation Zone Lower Applied To ... - * - * @param value: ENUM_APPLIED_PRICE - */ - void ConsolidationZonesUpperAppliedTo(ENUM_APPLIED_PRICE value = PRICE_HIGH) - { - mConsolidationZonesUpperAppliedTo = value; - } - - // - // Actions ... - - /** - * Apply Default Configurations ... - */ - virtual void Default() - { - // - // Default Props ... - SwingRange(3); - SupResRange(21); - MomentumExtend(1); - RejectionExtend(1); - MaxRequiredPOIs(100); - OrderBlockSameBars(3); - FairValueGapSameBars(3); - MomentumBodyPercent(70); - SupResRangeAsStart(true); - RejectionShadowPercent(70); - MaxAllowedLoopbackForInit(578); - ConsolidationZoneMinLoopback(5); - ConsolidationZoneRangeInPoint(50); - ConsolidationZonesLowerAppliedTo(PRICE_LOW); - ConsolidationZonesUpperAppliedTo(PRICE_HIGH); - } - - /** - * Add Event Listener ... - * - * @param listener: TOnPOIEvent instance ... - */ - void AddEventListener(TOnPOIEvent listener) - { - // - Add( - listener, - mEventListeners // - ); - } - - /** - * Initialize Instance ... - */ - void Init( - int barIndex = 0, - bool ignoreMaxAllowed = true // - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (maxAllowedLoopbackForInit <= 0) - { - return; - } - - // - mLock = true; - bool canContinue = true; - int index = barIndex + maxAllowedLoopbackForInit; - if (!IsValidIndex(index)) - { - // - mLock = false; - return; - } - - // - while (canContinue) - { - // - XOHCL iBar; - bool has = iBar.Init( - mSymbol, - mPeriod, - index // - ); - index--; - - // - int count = 0; - ENUM_XPOI_EVENTS iEvent = X_POI_EVENT_NONE; - - // - // Swings ... - DetectSwing( - iBar, - iEvent, - false // - ); - - // - // Rejection Bar ... - DetectRejection( - iBar, - iEvent, - false // - ); - // - // Momentum Bar ... - DetectMomentum( - iBar, - iEvent, - false // - ); - - // - // Support ... - DetectSupportZone( - iBar, - iEvent, - false // - ); - - // - // Demand ... - DetectDemandZone( - iBar, - iEvent, - false // - ); - - // - // Resistance ... - DetectResistanceZone( - iBar, - iEvent, - false // - ); - - // - // Supply ... - DetectSupplyZone( - iBar, - iEvent, - false // - ); - - // - // OrderBlock ... - DetectOrderBlock( - iBar, - iEvent, - false // - ); - - // - // FairValueGap ... - DetectFairValueGap( - iBar, - iEvent, - false // - ); - - // - // Consolidation Zone ... - DetectConsolidationZone( - iBar, - iEvent, - false // - ); - - // - canContinue = - has && - index >= 0; - - // - iBar.Clean(); - } - - // - ReverseCollections(); - - // - mLock = false; - } - - /** - * Update POI(s) ... - * @param events: ENUM_XPOI_EVENTS member Collection ... - */ - void Update( - ENUM_XPOI_EVENTS &events[], - int barIndex = 0 // - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Clean(events); - - // - if (mLock) - { - return; - } - - // - // Check Bar Tracker if Waits ... - if (!mBarTracker.IsNewBar()) - { - return; - } - - // - mLock = true; - - // - XOHCL iBar; - bool has = iBar.Init( - mSymbol, - mPeriod, - barIndex // - ); - - // - if (!has) - { - // - iBar.Clean(); - - // - return; - } - - // - int count = 0; - ENUM_XPOI_EVENTS iEvent = X_POI_EVENT_NONE; - - // - // Swings ... - has = DetectSwing( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCSwing *iSwing = NULL; - if (iEvent == X_SWING_LOW_DETECTED) - { - // - has = GetLastItem( - iSwing, - mSwingLows // - ); - } - else if (iEvent == X_SWING_HIGH_DETECTED) - { - // - has = GetLastItem( - iSwing, - mSwingHighs // - ); - } - if (has) - { - item = (XCBasePOI *)iSwing; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Momentum Bar ... - has = DetectMomentum( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCMomentumBar *iMomentum = NULL; - if (iEvent == X_BULLISH_MOMENTUM_BAR_DETECTED) - { - // - has = GetLastItem( - iMomentum, - mBullishMomentumBars // - ); - } - else if (iEvent == X_BEARISH_MOMENTUM_BAR_DETECTED) - { - // - has = GetLastItem( - iMomentum, - mBearishMomentumBars // - ); - } - if (has) - { - item = (XCBasePOI *)iMomentum; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Rejection Bar ... - has = DetectRejection( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCRejectionBar *iRejection = NULL; - if (iEvent == X_BULLISH_REJECTION_BAR_DETECTED) - { - // - has = GetLastItem( - iRejection, - mBullishRejectionBars // - ); - } - else if (iEvent == X_BEARISH_REJECTION_BAR_DETECTED) - { - // - has = GetLastItem( - iRejection, - mBearishRejectionBars // - ); - } - if (has) - { - item = (XCBasePOI *)iRejection; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Support ... - has = DetectSupportZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCSupportZone *iZone = NULL; - has = GetLastItem( - iZone, - mSupportZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Demand ... - has = DetectDemandZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCDemandZone *iZone = NULL; - has = GetLastItem( - iZone, - mDemandZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Resistance ... - has = DetectResistanceZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCResistanceZone *iZone = NULL; - has = GetLastItem( - iZone, - mResistanceZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Supply ... - has = DetectSupplyZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCSupplyZone *iZone = NULL; - has = GetLastItem( - iZone, - mSupplyZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // OrderBlock ... - has = DetectOrderBlock( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCOrderBlock *iZone = NULL; - if (iEvent == X_BULLISH_ORDERBLOCK_DETECTED) - { - // - has = GetLastItem( - iZone, - mBullishOrderBlocks // - ); - } - else if (iEvent == X_BEARISH_ORDERBLOCK_DETECTED) - { - // - has = GetLastItem( - iZone, - mBearishOrderBlocks // - ); - } - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // FairValueGap ... - has = DetectFairValueGap( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCFVG *iZone = NULL; - if (iEvent == X_BULLISH_FVG_DETECTED) - { - // - has = GetLastItem( - iZone, - mBullishFairValueGaps // - ); - } - else if (iEvent == X_BEARISH_FVG_DETECTED) - { - // - has = GetLastItem( - iZone, - mBearishFairValueGaps // - ); - } - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - has = DetectConsolidationZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - } - - // - iBar.Clean(); - mLock = false; - // mBarTracker.Waits(); - - // - if (HasChild(events)) - { - CleanupUnusedCollections(); - } - } - - /** - * Get Current State of POIs ... - * - * @param state: XPOIState instance ... - */ - void GetState( - XPOIState &state // - ) - { - // - state.Clean(); - - // - state.symbol = mSymbol; - state.period = mPeriod; - state.time = TimeCurrent(); - - // - Copy( - mSwings, - state.swings // - ); - - // - Copy( - mSwingHighs, - state.swingHighs // - ); - - // - Copy( - mSwingLows, - state.swingLows // - ); - - // - Copy( - mMomentumBars, - state.momentumBars // - ); - - // - Copy( - mBullishMomentumBars, - state.bullishMomentumBars // - ); - - // - Copy( - mBearishMomentumBars, - state.bearishMomentumBars // - ); - - // - Copy( - mRejectionBars, - state.rejectionBars // - ); - - // - Copy( - mBullishRejectionBars, - state.bullishRejectionBars // - ); - - // - Copy( - mBearishRejectionBars, - state.bearishRejectionBars // - ); - - // - Copy( - mSupportZones, - state.supportZones // - ); - - // - Copy( - mResistanceZones, - state.resistanceZones // - ); - - // - Copy( - mSupplyZones, - state.supplyZones // - ); - - // - Copy( - mDemandZones, - state.demandZones // - ); - - // - Copy( - mOrderBlocks, - state.orderBlocks // - ); - - // - Copy( - mBullishOrderBlocks, - state.bullishOrderBlocks // - ); - - // - Copy( - mBearishOrderBlocks, - state.bearishOrderBlocks // - ); - - // - Copy( - mFairValueGaps, - state.fairValueGaps // - ); - - // - Copy( - mBullishFairValueGaps, - state.bullishFairValueGaps // - ); - - // - Copy( - mBearishFairValueGaps, - state.bearishFairValueGaps // - ); - - // - Copy( - mConsolidationZones, - state.consolidationZones // - ); - - // - Copy( - mBullishConsolidationZones, - state.bullishConsolidationZones // - ); - - // - Copy( - mBearishConsolidationZones, - state.bearishConsolidationZones // - ); - - // - } - - /** - * Destroy Instance ... - */ - void Destroy() - { - // - mBarTracker.Clean(); - ZeroMemory(mBarAnalyser); - - // - CleanCollections(); - } - - // - // - // - // - // - // - - /** - * Detect Swing Bars ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectSwing( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir; - result = mBarAnalyser.IsSwing( - bar, - iDir, - mSwingRange // - ); - - // - result = result && - HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - ENUM_XPOIS type = - isBullish - ? X_POI_SWING_LOW - : X_POI_SWING_HIGH; - - // - // Swing Object ... - XCSwing *swing; - swing = new XCSwing(); - result = swing.Init( - bar, - type // - ); - if (!result) - { - return result; - } - - // - // Add ... - - // - int idx = FindIndex( - swing, - mSwings // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mSwings); - - // - Add( - swing, - mSwings // - ); - - // - ArrayReverse(mSwings); - } - else - { - // - Add( - swing, - mSwings // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mSwings); - - // - Add( - swing, - mSwings // - ); - - // - ArrayReverse(mSwings); - } - else - { - // - Add( - swing, - mSwingLows // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mSwingHighs); - - // - Add( - swing, - mSwingHighs // - ); - - // - ArrayReverse(mSwingHighs); - } - else - { - // - Add( - swing, - mSwingHighs // - ); - } - } - - // - state = - isBullish - ? X_SWING_LOW_DETECTED - : X_SWING_HIGH_DETECTED; - - // - return result; - } - - /** - * Detect Momentum Bars ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectMomentum( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir; - result = mBarAnalyser.IsMomentumBar( - bar, - iDir, - mMomentumExtend, // Extends ... - mMomentumBodyPercent // Body Percent ... - ); - - // - result = result && - HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - ENUM_XPOIS type = - isBullish - ? X_POI_MOMENTUM_BAR - : X_POI_MOMENTUM_BAR; - - // - // Swing Object ... - XCMomentumBar *momentum; - momentum = new XCMomentumBar(); - result = momentum.Init( - bar // - ); - if (!result) - { - return result; - } - - // - int idx = FindIndex( - momentum, - mMomentumBars // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mMomentumBars); - - // - Add( - momentum, - mMomentumBars // - ); - - // - ArrayReverse(mMomentumBars); - } - else - { - // - Add( - momentum, - mMomentumBars // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishMomentumBars); - - // - Add( - momentum, - mBullishMomentumBars // - ); - - // - ArrayReverse(mBullishMomentumBars); - } - else - { - // - Add( - momentum, - mBullishMomentumBars // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishMomentumBars); - - // - Add( - momentum, - mBearishMomentumBars // - ); - - // - ArrayReverse(mBearishMomentumBars); - } - else - { - // - Add( - momentum, - mBearishMomentumBars // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_MOMENTUM_BAR_DETECTED - : X_BEARISH_MOMENTUM_BAR_DETECTED; - - // - return result; - } - - /** - * Detect Rejection Bars ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectRejection( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir; - result = mBarAnalyser.IsRejectionBar( - bar, - iDir, - mRejectionExtend, // Extends ... - mRejectionShadowPercent // Shadow Percent ... - ); - - // - result = result && - HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - ENUM_XPOIS type = - isBullish - ? X_POI_MOMENTUM_BAR - : X_POI_MOMENTUM_BAR; - - // - // Swing Object ... - XCRejectionBar *rejection; - rejection = new XCRejectionBar(); - result = rejection.Init( - bar // - ); - if (!result) - { - return result; - } - - // - int idx = FindIndex( - rejection, - mRejectionBars // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mRejectionBars); - - // - Add( - rejection, - mRejectionBars // - ); - - // - ArrayReverse(mRejectionBars); - } - else - { - // - Add( - rejection, - mRejectionBars // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishRejectionBars); - - // - Add( - rejection, - mBullishRejectionBars // - ); - - // - ArrayReverse(mBullishRejectionBars); - } - else - { - // - Add( - rejection, - mBullishRejectionBars // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishRejectionBars); - - // - Add( - rejection, - mBearishRejectionBars // - ); - - // - ArrayReverse(mBearishRejectionBars); - } - else - { - // - Add( - rejection, - mBearishRejectionBars // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_REJECTION_BAR_DETECTED - : X_BEARISH_REJECTION_BAR_DETECTED; - - // - return result; - } - - /** - * Detect Support Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectSupportZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL supportBar; - result = mBarAnalyser - .HasSupport( - bar, - supportBar, - mSupResRange // - ); - if (!result) - { - // - supportBar.Clean(); - - // - return result; - } - - // - XCSupportZone *supportZone; - supportZone = new XCSupportZone(); - result = supportZone.Init( - supportBar, - mSupResRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - supportBar.Clean(); - ZeroMemory(supportZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supportZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - supportBar.Clean(); - activationBar.Clean(); - ZeroMemory(supportZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - supportZone, - mSupportZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - supportBar.Clean(); - ZeroMemory(supportZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mSupportZones); - - // - Add( - supportZone, - mSupportZones // - ); - - // - ArrayReverse(mSupportZones); - } - else - { - // - Add( - supportZone, - mSupportZones // - ); - } - - // - state = X_SUPPORT_ZONE_DETECTED; - - // - supportBar.Clean(); - - // - return result; - } - - /** - * Detect Resistance Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectResistanceZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL resistanceBar; - result = mBarAnalyser - .HasResistance( - bar, - resistanceBar, - mSupResRange // - ); - if (!result) - { - // - resistanceBar.Clean(); - - // - return result; - } - - // - XCResistanceZone *resistanceZone; - resistanceZone = new XCResistanceZone(); - result = resistanceZone.Init( - resistanceBar, - mSupResRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - resistanceBar.Clean(); - ZeroMemory(resistanceZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = resistanceZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - resistanceBar.Clean(); - activationBar.Clean(); - ZeroMemory(resistanceZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - resistanceZone, - mResistanceZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - resistanceBar.Clean(); - ZeroMemory(resistanceZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mResistanceZones); - - // - Add( - resistanceZone, - mResistanceZones // - ); - - // - ArrayReverse(mResistanceZones); - } - else - { - // - Add( - resistanceZone, - mResistanceZones // - ); - } - - // - state = X_RESISTANCE_ZONE_DETECTED; - - // - resistanceBar.Clean(); - - // - return result; - } - - /** - * Detect Supply Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectSupplyZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int mSupDemRange = mSupResRange * 2; - - // - XOHCL supplyBar; - result = mBarAnalyser - .HasResistance( - bar, - supplyBar, - mSupDemRange // - ); - if (!result) - { - // - supplyBar.Clean(); - - // - return result; - } - - // - XCSupplyZone *supplyZone; - supplyZone = new XCSupplyZone(); - result = supplyZone.Init( - supplyBar, - mSupDemRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - supplyBar.Clean(); - ZeroMemory(supplyZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supplyZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - supplyBar.Clean(); - activationBar.Clean(); - ZeroMemory(supplyZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - supplyZone, - mSupplyZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - supplyBar.Clean(); - ZeroMemory(supplyZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mSupplyZones); - - // - Add( - supplyZone, - mSupplyZones // - ); - - // - ArrayReverse(mSupplyZones); - } - else - { - // - Add( - supplyZone, - mSupplyZones // - ); - } - - // - state = X_SUPPLY_ZONE_DETECTED; - - // - supplyBar.Clean(); - - // - return result; - } - - /** - * Detect Demand Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectDemandZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int mSupDemRange = mSupResRange * 2; - - // - XOHCL demandBar; - result = mBarAnalyser - .HasSupport( - bar, - demandBar, - mSupDemRange // - ); - if (!result) - { - // - demandBar.Clean(); - - // - return result; - } - - // - XCDemandZone *demandZone; - demandZone = new XCDemandZone(); - result = demandZone.Init( - demandBar, - mSupDemRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - demandBar.Clean(); - ZeroMemory(demandZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = demandZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - demandBar.Clean(); - activationBar.Clean(); - ZeroMemory(demandZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - demandZone, - mDemandZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - demandBar.Clean(); - ZeroMemory(demandZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mDemandZones); - - // - Add( - demandZone, - mDemandZones // - ); - - // - ArrayReverse(mDemandZones); - } - else - { - // - Add( - demandZone, - mDemandZones // - ); - } - - // - state = X_DEMAND_ZONE_DETECTED; - - // - demandBar.Clean(); - - // - return result; - } - - /** - * Detect Order Blocks ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectOrderBlock( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION obDir; - result = mBarAnalyser.HasOrderBlock( - bar, - obBar, - obDir, - mOrderBlockSameBars // - ); - if (!result) - { - // - obBar.Clean(); - - // - return result; - } - - // - XCOrderBlock *ob; - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - obDir // - ); - if (!result) - { - // - obBar.Clean(); - ZeroMemory(ob); - - // - return result; - } - - // - bool isBullish = IsBullish(obDir); - bool isBearish = IsBearish(obDir); - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = ob.IsActivated( - obDir, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - obBar.Clean(); - activationBar.Clean(); - ZeroMemory(ob); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - int idx = FindIndex( - ob, - mOrderBlocks // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - obBar.Clean(); - ZeroMemory(ob); - - // - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mOrderBlocks); - - // - Add( - ob, - mOrderBlocks // - ); - - // - ArrayReverse(mOrderBlocks); - } - else - { - // - Add( - ob, - mOrderBlocks // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishOrderBlocks); - - // - Add( - ob, - mBullishOrderBlocks // - ); - - // - ArrayReverse(mBullishOrderBlocks); - } - else - { - // - Add( - ob, - mBullishOrderBlocks // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishOrderBlocks); - - // - Add( - ob, - mBearishOrderBlocks // - ); - - // - ArrayReverse(mBearishOrderBlocks); - } - else - { - // - Add( - ob, - mBearishOrderBlocks // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_ORDERBLOCK_DETECTED - : X_BEARISH_ORDERBLOCK_DETECTED; - - // - obBar.Clean(); - - // - return result; - } - - /** - * Detect Fair Value Gaps ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectFairValueGap( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL fvgStartBar; - XOHCL fvgEndBar; - ENUM_X_DIRECTION fvgDir; - result = mBarAnalyser.HasFairValueGap( - bar, - fvgStartBar, - fvgEndBar, - fvgDir, - mFairValueGapSameBars // - ); - if (!result) - { - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - // - XCFVG *fvg; - fvg = new XCFVG(); - result = fvg.Init( - fvgStartBar, - fvgEndBar, - fvgDir // - ); - if (!result) - { - // - ZeroMemory(fvg); - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - // - bool isBullish = IsBullish(fvgDir); - bool isBearish = IsBearish(fvgDir); - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = fvg.IsActivated( - fvgDir, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - ZeroMemory(fvg); - fvgEndBar.Clean(); - fvgStartBar.Clean(); - activationBar.Clean(); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - int idx = FindIndex( - fvg, - mFairValueGaps // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - ZeroMemory(fvg); - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mFairValueGaps); - - // - Add( - fvg, - mFairValueGaps // - ); - - // - ArrayReverse(mFairValueGaps); - } - else - { - // - Add( - fvg, - mFairValueGaps // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishFairValueGaps); - - // - Add( - fvg, - mBullishFairValueGaps // - ); - - // - ArrayReverse(mBullishFairValueGaps); - } - else - { - // - Add( - fvg, - mBullishFairValueGaps // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishFairValueGaps); - - // - Add( - fvg, - mBearishFairValueGaps // - ); - - // - ArrayReverse(mBearishFairValueGaps); - } - else - { - // - Add( - fvg, - mBearishFairValueGaps // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_FVG_DETECTED - : X_BEARISH_FVG_DETECTED; - - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - /** - * Detect Consolidation Zones ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectConsolidationZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - XConsolidationZone cZone; - result = mBarAnalyser.HasConsolidationZone( - bar, - cZone, - mConsolidationZoneMinLoopback, - mConsolidationZoneRangeInPoint, - mConsolidationZonesUpperAppliedTo, - mConsolidationZonesLowerAppliedTo // - ); - if (!result) - { - // - cZone.Clean(); - - // - return result; - } - - // - // Add ... - - // - bool isBullish = IsBullish(cZone.dir); - bool isBearish = IsBearish(cZone.dir); - - // - int idx = FindIndex( - cZone, - mConsolidationZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - cZone.Clean(); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mConsolidationZones); - - // - AddRef( - cZone, - mConsolidationZones // - ); - - // - ArrayReverse(mConsolidationZones); - } - else - { - // - AddRef( - cZone, - mConsolidationZones // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishConsolidationZones); - - // - AddRef( - cZone, - mBullishConsolidationZones // - ); - - // - ArrayReverse(mBullishConsolidationZones); - } - else - { - // - AddRef( - cZone, - mBullishConsolidationZones // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishConsolidationZones); - - // - AddRef( - cZone, - mBearishConsolidationZones // - ); - - // - ArrayReverse(mBearishConsolidationZones); - } - else - { - // - AddRef( - cZone, - mBearishConsolidationZones // - ); - } - } - - // - state = - IsBullish(cZone.dir) - ? X_BULLISH_CONSOLIDATION_ZONE_DETECTED - : X_BEARISH_CONSOLIDATION_ZONE_DETECTED; - - // - cZone.Clean(); - - // - return result; - } - - // - protected: - // - - // - void CleanCollections() - { - // - Clean(mSwings); - Clean(mSwingLows); - Clean(mSwingHighs); - Clean(mDemandZones); - Clean(mSupplyZones); - Clean(mOrderBlocks); - Clean(mMomentumBars); - Clean(mSupportZones); - Clean(mRejectionBars); - Clean(mFairValueGaps); - Clean(mEventListeners); - Clean(mResistanceZones); - Clean(mBullishOrderBlocks); - Clean(mBearishOrderBlocks); - Clean(mConsolidationZones); - Clean(mBullishMomentumBars); - Clean(mBearishMomentumBars); - Clean(mBullishRejectionBars); - Clean(mBearishRejectionBars); - Clean(mBullishFairValueGaps); - Clean(mBearishFairValueGaps); - Clean(mBullishConsolidationZones); - Clean(mBearishConsolidationZones); - } - - // - void ReverseCollections() - { - // - ArrayReverse(mSwings); - ArrayReverse(mSwingLows); - ArrayReverse(mSwingHighs); - ArrayReverse(mDemandZones); - ArrayReverse(mSupplyZones); - ArrayReverse(mOrderBlocks); - ArrayReverse(mMomentumBars); - ArrayReverse(mSupportZones); - ArrayReverse(mRejectionBars); - ArrayReverse(mFairValueGaps); - ArrayReverse(mEventListeners); - ArrayReverse(mResistanceZones); - ArrayReverse(mBullishOrderBlocks); - ArrayReverse(mBearishOrderBlocks); - ArrayReverse(mConsolidationZones); - ArrayReverse(mBullishMomentumBars); - ArrayReverse(mBearishMomentumBars); - ArrayReverse(mBullishRejectionBars); - ArrayReverse(mBearishRejectionBars); - ArrayReverse(mBullishFairValueGaps); - ArrayReverse(mBearishFairValueGaps); - ArrayReverse(mBullishConsolidationZones); - ArrayReverse(mBearishConsolidationZones); - } - - // - void CleanupUnusedCollections( - int maxAllowed = 0 // - ) - { - // - maxAllowed = MaxRequiredPOIs(); - - // - if (maxAllowed <= 0) - { - return; - } - - // - CleanupArray( - mEventListeners, - maxAllowed // - ); - - // - CleanupArray( - mSwings, - maxAllowed // - ); - - // - CleanupArray( - mSwingLows, - maxAllowed // - ); - - // - CleanupArray( - mSwingHighs, - maxAllowed // - ); - - // - CleanupArray( - mMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mBullishMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mBearishMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mBullishRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mBearishRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mSupportZones, - maxAllowed // - ); - - // - CleanupArray( - mDemandZones, - maxAllowed // - ); - - // - CleanupArray( - mSupplyZones, - maxAllowed // - ); - - // - CleanupArray( - mResistanceZones, - maxAllowed // - ); - - // - CleanupArray( - mFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mBullishFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mBearishFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mBullishOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mBearishOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mConsolidationZones, - maxAllowed // - ); - - // - CleanupArray( - mBullishConsolidationZones, - maxAllowed // - ); - - // - CleanupArray( - mBearishConsolidationZones, - maxAllowed // - ); - - // - } - - /** - * Notify Event Listeners ... - * - * @param event: ENUM_XPOI_EVENTS member, Specified Occured Event ... - * @param param: XCBasePOI implementation, Specified Event Object ... - */ - void NotifyEventListeners( - ENUM_XPOI_EVENTS event, - XCBasePOI *param // - ) - { - // - int count = ArraySize(mEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - mEventListeners[i]( - event, - param // - ); - } - } - - // - private: - // - - // - // Props ... - string mSymbol; // Market Symbol ... - ENUM_TIMEFRAMES mPeriod; // Market Period ... - XBarTracker mBarTracker; // Market Bar Tracker ... - XCBarAnalyser *mBarAnalyser; // Bar Analyser ... - - // - bool mLock; - - // - int mMaxRequiredPOIs; // Max Allowed Holds POI(s) ... - int maxAllowedLoopbackForInit; // Max Allowed Loopback for POI(s) Detection on Initialization Process ... - - // - TOnPOIEvent mEventListeners[]; // Event Listeners ... - - // - XCSwing *mSwings[]; // Holds Founded Swing ... - XCSwing *mSwingLows[]; // Holds Founded Swing Lows ... - XCSwing *mSwingHighs[]; // Holds Founded Swing Highs ... - int mSwingRange; // Swing Detection Range ... - - // - XCMomentumBar *mMomentumBars[]; // Holds Founded Momentum Bars ... - XCMomentumBar *mBullishMomentumBars[]; // Holds Founded Bullish Momentum Bars ... - XCMomentumBar *mBearishMomentumBars[]; // Holds Founded Bearish Momentum Bars ... - int mMomentumExtend; // Momentum Bar Detection Extends Range ... - double mMomentumBodyPercent; // Momentum Bar Detection Body Percent ... - - // - XCRejectionBar *mRejectionBars[]; // Holds Founded Rejection Bars ... - XCRejectionBar *mBullishRejectionBars[]; // Holds Founded Bullish Rejection Bars ... - XCRejectionBar *mBearishRejectionBars[]; // Holds Founded Bearish Rejection Bars ... - int mRejectionExtend; // Rejection Bar Detection Extends Range ... - double mRejectionShadowPercent; // Rejection Bar Detection Body Percent ... - - // - XCSupplyZone *mSupplyZones[]; // Holds Detected Supply Zones ... - XCDemandZone *mDemandZones[]; // Holds Detected Demand Zones ... - - // - int mSupResRange; // Support and Resistance Detection Range ... - bool mSupResRangeAsStart; // use Support and Resistance Range as Start ... - XCSupportZone *mSupportZones[]; // Holds Detected Support Zones ... - XCResistanceZone *mResistanceZones[]; // Holds Detected Resistance Zones ... - - // - XCFVG *mFairValueGaps[]; // Holds Founded FairValueGaps ... - XCFVG *mBullishFairValueGaps[]; // Holds Founded Bullish FairValueGaps ... - XCFVG *mBearishFairValueGaps[]; // Holds Founded Bearish FairValueGaps ... - int mFairValueGapSameBars; // FairValueGap Detection Same Bars ... - - // - XCOrderBlock *mOrderBlocks[]; // Holds Founded OrderBlocks ... - XCOrderBlock *mBullishOrderBlocks[]; // Holds Founded Bullish OrderBlocks ... - XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish OrderBlocks ... - int mOrderBlockSameBars; // OrderBlock Detection Same Bars ... - - // - int mConsolidationZoneMinLoopback; // Minimum Length of Cnsolidation Zone ... - double mConsolidationZoneRangeInPoint; // Consolidation Zone Range in Point ... - XConsolidationZone mConsolidationZones[]; // Holds Founded Consolidation Zones ... - XConsolidationZone mBullishConsolidationZones[]; // Holds Founded Bullish Consolidation Zones ... - XConsolidationZone mBearishConsolidationZones[]; // Holds Founded Bearish Consolidation Zones ... - ENUM_APPLIED_PRICE mConsolidationZonesLowerAppliedTo; // Consolidation Zone Upper Applied To ... - ENUM_APPLIED_PRICE mConsolidationZonesUpperAppliedTo; // Consolidation Zone Lower Applied To ... - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x-poi.class.mq5 b/Documents/BKP/x-saherelm.x-poi.class.mq5 deleted file mode 100644 index 5fdbd4db..00000000 --- a/Documents/BKP/x-saherelm.x-poi.class.mq5 +++ /dev/null @@ -1,3334 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XPOI -// Description: Provides Point of Interests ... -// - Swing Highs; -// - Swing Lows; -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... - -// -#include "../Classes/x-saherelm.x-alert.class.mq5" -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Libraries/x-saherelm.x-poi.state.lib.mq5" - -// -#include - -// -// Implementation ... - -// -// POI Detector Class ... -class XCPOIDetector : public XCBaseAlert -{ - // - public: - // - - // - // Constructors ... - /** - * Create an Instance ... - * - * @param symbol: String ... - * @param period: ENUM_TIMEFRAMES member ... - */ - void XCPOIDetector( - string symbol, - ENUM_TIMEFRAMES period) - { - // - // Attach Required Properties ... - mSymbol = symbol; - mPeriod = period; - - // - // Initialize Bar Tracker ... - mBarTracker.Init( - mSymbol, - mPeriod // - ); - - // - mBarAnalyser = new XCBarAnalyser(); - - // - // Apply Default Configurations ... - Default(); - } - - // - // Deconstructor ... - void ~XCPOIDetector() - { - Destroy(); - } - - // - // Getter(s) / Setter(s) ... - - /** - * Retrieve Detector Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - return mSymbol; - } - - /** - * Retrieve Detector Period ... - * - * @return ( ENUM_TIMEFRAMES ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - return mPeriod; - } - - /** - * Get Max Required POI(s) allowed to Holds ... - * - * @return ( int ) - */ - int MaxRequiredPOIs() - { - return mMaxRequiredPOIs; - } - - /** - * Set Max Required POI(s) allowed to Holds ... - * - * @param value: int ... - */ - void MaxRequiredPOIs(int value) - { - // - if (value < 0) - { - value = 5; - } - - // - mMaxRequiredPOIs = value; - } - - /** - * Get Max Allowed Loopback for POI(s) Detection on Initialization Process ... - * - * @return ( int ) - */ - int MaxAllowedLoopbackForInit() - { - return maxAllowedLoopbackForInit; - } - - /** - * Set Max Allowed Loopback for POI(s) Detection on Initialization Process ... - * - * @param value: int ... - */ - void MaxAllowedLoopbackForInit(int value) - { - // - if (value < 0) - { - value = 578; - } - - // - maxAllowedLoopbackForInit = value; - } - - /** - * Get Swing Range Validation ... - * - * @return ( int ) - */ - int SwingRange() - { - return mSwingRange; - } - - /** - * Set Swing Range Validation ... - * - * @param value: int ... - */ - void SwingRange(int value) - { - // - if (value < 1) - { - value = 1; - } - - // - mSwingRange = value; - } - - /** - * Get Momentum Bar Detection Extends Range ... - * - * @return ( int ) - */ - int MomentumExtend() - { - return mMomentumExtend; - } - - /** - * Set Momentum Bar Detection Extends Range ... - * - * @param value: int ... - */ - void MomentumExtend(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMomentumExtend = value; - } - - /** - * Get Momentum Bar Detection Body Percent ... - * - * @return ( double ) - */ - double MomentumBodyPercent() - { - return mMomentumBodyPercent; - } - - /** - * Set Momentum Bar Detection Body Percent ... - * - * @param value: double ... - */ - void MomentumBodyPercent(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - if (value > 100) - { - value = 100; - } - - // - mMomentumBodyPercent = value; - } - - /** - * Get Rejection Bar Detection Extends Range ... - * - * @return ( int ) - */ - int RejectionExtend() - { - return mRejectionExtend; - } - - /** - * Set Rejection Bar Detection Extends Range ... - * - * @param value: int ... - */ - void RejectionExtend(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRejectionExtend = value; - } - - /** - * Get Rejection Bar Detection Shadow Percent ... - * - * @return ( double ) - */ - double RejectionShadowPercent() - { - return mRejectionShadowPercent; - } - - /** - * Set Rejection Bar Detection Shadow Percent ... - * - * @param value: double ... - */ - void RejectionShadowPercent(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - if (value > 100) - { - value = 100; - } - - // - mRejectionShadowPercent = value; - } - - /** - * Get Support and Resistance Detection Range ... - * - * @return ( int ) - */ - int SupResRange() - { - return mSupResRange; - } - - /** - * Set Support and Resistance Detection Range ... - * - * @param value: int ... - */ - void SupResRange(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mSupResRange = value; - } - - /** - * Get use Support and Resistance Range as Start ... - * - * @return ( bool ) - */ - bool SupResRangeAsStart() - { - return mSupResRangeAsStart; - } - - /** - * Set use Support and Resistance Range as Start ... - * @param value: bool ... - */ - void SupResRangeAsStart(bool value) - { - mSupResRangeAsStart = value; - } - - /** - * Get OrderBlock Detection Same Bars ... - * - * @return ( int ) - */ - int OrderBlockSameBars() - { - return mOrderBlockSameBars; - } - - /** - * Set OrderBlock Detection Same Bars ... - * - * @param value: int ... - */ - void OrderBlockSameBars(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mOrderBlockSameBars = value; - } - - /** - * Get FairValueGap Detection Same Bars ... - * - * @return ( int ) - */ - int FairValueGapSameBars() - { - return mFairValueGapSameBars; - } - - /** - * Set FairValueGap Detection Same Bars ... - * - * @param value: int ... - */ - void FairValueGapSameBars(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mFairValueGapSameBars = value; - } - - /** - * Get Minimum Length of Cnsolidation Zone ... - * - * @return ( int ) - */ - int ConsolidationZoneMinLoopback() - { - return mConsolidationZoneMinLoopback; - } - - /** - * Set Minimum Length of Cnsolidation Zone ... - * - * @param value: int ... - */ - void ConsolidationZoneMinLoopback(int value) - { - // - if (value < 1) - { - value = 1; - } - - // - mConsolidationZoneMinLoopback = value; - } - - /** - * Get Consolidation Zone Range in Point ... - * - * @return ( double ) - */ - double ConsolidationZoneRangeInPoint() - { - return mConsolidationZoneRangeInPoint; - } - - /** - * Set Consolidation Zone Range in Point ... - * - * @param value: double - */ - void ConsolidationZoneRangeInPoint(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - mConsolidationZoneRangeInPoint = value; - } - - /** - * Get Consolidation Zone Upper Applied To ... - * - * @return ( ENUM_APPLIED_PRICE ) - */ - ENUM_APPLIED_PRICE ConsolidationZonesLowerAppliedTo() - { - return mConsolidationZonesLowerAppliedTo; - } - - /** - * Set Consolidation Zone Upper Applied To ... - * - * @param value: ENUM_APPLIED_PRICE - */ - void ConsolidationZonesLowerAppliedTo(ENUM_APPLIED_PRICE value = PRICE_LOW) - { - mConsolidationZonesLowerAppliedTo = value; - } - - /** - * Get Consolidation Zone Lower Applied To ... - * - * @return ( ENUM_APPLIED_PRICE ) - */ - ENUM_APPLIED_PRICE ConsolidationZonesUpperAppliedTo() - { - return mConsolidationZonesUpperAppliedTo; - } - - /** - * Set Consolidation Zone Lower Applied To ... - * - * @param value: ENUM_APPLIED_PRICE - */ - void ConsolidationZonesUpperAppliedTo(ENUM_APPLIED_PRICE value = PRICE_HIGH) - { - mConsolidationZonesUpperAppliedTo = value; - } - - // - // Actions ... - - /** - * Apply Default Configurations ... - */ - virtual void Default() - { - // - // Default Props ... - SwingRange(3); - SupResRange(21); - MomentumExtend(1); - RejectionExtend(1); - MaxRequiredPOIs(100); - OrderBlockSameBars(3); - FairValueGapSameBars(3); - MomentumBodyPercent(70); - SupResRangeAsStart(true); - RejectionShadowPercent(70); - MaxAllowedLoopbackForInit(578); - ConsolidationZoneMinLoopback(5); - ConsolidationZoneRangeInPoint(50); - ConsolidationZonesLowerAppliedTo(PRICE_LOW); - ConsolidationZonesUpperAppliedTo(PRICE_HIGH); - } - - /** - * Add Event Listener ... - * - * @param listener: TOnPOIEvent instance ... - */ - void AddEventListener(TOnPOIEvent listener) - { - // - Add( - listener, - mEventListeners // - ); - } - - /** - * Initialize Instance ... - */ - void Init( - int barIndex = 0, - bool ignoreMaxAllowed = true // - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (maxAllowedLoopbackForInit <= 0) - { - return; - } - - // - mLock = true; - bool canContinue = true; - int index = barIndex + maxAllowedLoopbackForInit; - if (!IsValidIndex(index)) - { - // - mLock = false; - return; - } - - // - while (canContinue) - { - // - XOHCL iBar; - bool has = iBar.Init( - mSymbol, - mPeriod, - index // - ); - index--; - - // - int count = 0; - ENUM_XPOI_EVENTS iEvent = X_POI_EVENT_NONE; - - // - // Swings ... - DetectSwing( - iBar, - iEvent, - false // - ); - - // - // Rejection Bar ... - DetectRejectionBar( - iBar, - iEvent, - false // - ); - // - // Momentum Bar ... - DetectMomentumBar( - iBar, - iEvent, - false // - ); - - // - // Support ... - DetectSupportZone( - iBar, - iEvent, - false // - ); - - // - // Demand ... - DetectDemandZone( - iBar, - iEvent, - false // - ); - - // - // Resistance ... - DetectResistanceZone( - iBar, - iEvent, - false // - ); - - // - // Supply ... - DetectSupplyZone( - iBar, - iEvent, - false // - ); - - // - // OrderBlock ... - DetectOrderBlock( - iBar, - iEvent, - false // - ); - - // - // FairValueGap ... - DetectFairValueGap( - iBar, - iEvent, - false // - ); - - // - // Consolidation Zone ... - DetectConsolidationZone( - iBar, - iEvent, - false // - ); - - // - canContinue = - has && - index >= 0; - - // - iBar.Clean(); - } - - // - ReverseCollections(); - - // - mLock = false; - } - - /** - * Update POI(s) ... - * @param events: ENUM_XPOI_EVENTS member Collection ... - */ - void Update( - ENUM_XPOI_EVENTS &events[], - int barIndex = 0 // - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Clean(events); - - // - if (mLock) - { - return; - } - - // - // Check Bar Tracker if Waits ... - if (!mBarTracker.IsNewBar()) - { - return; - } - - // - mLock = true; - - // - XOHCL iBar; - bool has = iBar.Init( - mSymbol, - mPeriod, - barIndex // - ); - - // - if (!has) - { - // - iBar.Clean(); - - // - return; - } - - // - int count = 0; - ENUM_XPOI_EVENTS iEvent = X_POI_EVENT_NONE; - - // - // Swings ... - has = DetectSwing( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCSwing *iSwing = NULL; - if (iEvent == X_SWING_LOW_DETECTED) - { - // - has = GetLastItem( - iSwing, - mSwingLows // - ); - } - else if (iEvent == X_SWING_HIGH_DETECTED) - { - // - has = GetLastItem( - iSwing, - mSwingHighs // - ); - } - if (has) - { - item = (XCBasePOI *)iSwing; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Momentum Bar ... - has = DetectMomentumBar( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCMomentumBar *iMomentum = NULL; - if (iEvent == X_BULLISH_MOMENTUM_BAR_DETECTED) - { - // - has = GetLastItem( - iMomentum, - mBullishMomentumBars // - ); - } - else if (iEvent == X_BEARISH_MOMENTUM_BAR_DETECTED) - { - // - has = GetLastItem( - iMomentum, - mBearishMomentumBars // - ); - } - if (has) - { - item = (XCBasePOI *)iMomentum; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Rejection Bar ... - has = DetectRejectionBar( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCRejectionBar *iRejection = NULL; - if (iEvent == X_BULLISH_REJECTION_BAR_DETECTED) - { - // - has = GetLastItem( - iRejection, - mBullishRejectionBars // - ); - } - else if (iEvent == X_BEARISH_REJECTION_BAR_DETECTED) - { - // - has = GetLastItem( - iRejection, - mBearishRejectionBars // - ); - } - if (has) - { - item = (XCBasePOI *)iRejection; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Support ... - has = DetectSupportZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCSupportZone *iZone = NULL; - has = GetLastItem( - iZone, - mSupportZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Demand ... - has = DetectDemandZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCDemandZone *iZone = NULL; - has = GetLastItem( - iZone, - mDemandZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Resistance ... - has = DetectResistanceZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCResistanceZone *iZone = NULL; - has = GetLastItem( - iZone, - mResistanceZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // Supply ... - has = DetectSupplyZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCSupplyZone *iZone = NULL; - has = GetLastItem( - iZone, - mSupplyZones // - ); - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // OrderBlock ... - has = DetectOrderBlock( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCOrderBlock *iZone = NULL; - if (iEvent == X_BULLISH_ORDERBLOCK_DETECTED) - { - // - has = GetLastItem( - iZone, - mBullishOrderBlocks // - ); - } - else if (iEvent == X_BEARISH_ORDERBLOCK_DETECTED) - { - // - has = GetLastItem( - iZone, - mBearishOrderBlocks // - ); - } - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - // FairValueGap ... - has = DetectFairValueGap( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - - // - XCBasePOI *item = NULL; - XCFVG *iZone = NULL; - if (iEvent == X_BULLISH_FVG_DETECTED) - { - // - has = GetLastItem( - iZone, - mBullishFairValueGaps // - ); - } - else if (iEvent == X_BEARISH_FVG_DETECTED) - { - // - has = GetLastItem( - iZone, - mBearishFairValueGaps // - ); - } - if (has) - { - item = (XCBasePOI *)iZone; - } - - // - has = item != NULL; - if (has) - { - // - NotifyEventListeners( - iEvent, - item // - ); - } - } - - // - has = DetectConsolidationZone( - iBar, - iEvent // - ); - if (has) - { - // - Add( - iEvent, - events // - ); - } - - // - iBar.Clean(); - mLock = false; - // mBarTracker.Waits(); - - // - if (HasChild(events)) - { - CleanupUnusedCollections(); - } - } - - /** - * Get Current State of POIs ... - * - * @param state: XPOIState instance ... - */ - void GetState( - XPOIState &state // - ) - { - // - state.Clean(); - - // - state.symbol = mSymbol; - state.period = mPeriod; - state.time = TimeCurrent(); - - // - Copy( - mSwings, - state.swings // - ); - - // - Copy( - mSwingHighs, - state.swingHighs // - ); - - // - Copy( - mSwingLows, - state.swingLows // - ); - - // - Copy( - mMomentumBars, - state.momentumBars // - ); - - // - Copy( - mBullishMomentumBars, - state.bullishMomentumBars // - ); - - // - Copy( - mBearishMomentumBars, - state.bearishMomentumBars // - ); - - // - Copy( - mRejectionBars, - state.rejectionBars // - ); - - // - Copy( - mBullishRejectionBars, - state.bullishRejectionBars // - ); - - // - Copy( - mBearishRejectionBars, - state.bearishRejectionBars // - ); - - // - Copy( - mSupportZones, - state.supportZones // - ); - - // - Copy( - mResistanceZones, - state.resistanceZones // - ); - - // - Copy( - mSupplyZones, - state.supplyZones // - ); - - // - Copy( - mDemandZones, - state.demandZones // - ); - - // - Copy( - mOrderBlocks, - state.orderBlocks // - ); - - // - Copy( - mBullishOrderBlocks, - state.bullishOrderBlocks // - ); - - // - Copy( - mBearishOrderBlocks, - state.bearishOrderBlocks // - ); - - // - Copy( - mFairValueGaps, - state.fairValueGaps // - ); - - // - Copy( - mBullishFairValueGaps, - state.bullishFairValueGaps // - ); - - // - Copy( - mBearishFairValueGaps, - state.bearishFairValueGaps // - ); - - // - Copy( - mConsolidationZones, - state.consolidationZones // - ); - - // - Copy( - mBullishConsolidationZones, - state.bullishConsolidationZones // - ); - - // - Copy( - mBearishConsolidationZones, - state.bearishConsolidationZones // - ); - - // - } - - /** - * Destroy Instance ... - */ - void Destroy() - { - // - mBarTracker.Clean(); - ZeroMemory(mBarAnalyser); - - // - CleanCollections(); - } - - // - // - // - // - // - // - - /** - * Detect Swing Bars ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectSwing( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir; - result = mBarAnalyser.IsSwing( - bar, - iDir, - mSwingRange // - ); - - // - result = result && - HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - ENUM_XPOIS type = - isBullish - ? X_POI_SWING_LOW - : X_POI_SWING_HIGH; - - // - // Swing Object ... - XCSwing *swing; - swing = new XCSwing(); - result = swing.Init( - bar, - type // - ); - if (!result) - { - return result; - } - - // - // Add ... - - // - int idx = FindIndex( - swing, - mSwings // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mSwings); - - // - Add( - swing, - mSwings // - ); - - // - ArrayReverse(mSwings); - } - else - { - // - Add( - swing, - mSwings // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mSwings); - - // - Add( - swing, - mSwings // - ); - - // - ArrayReverse(mSwings); - } - else - { - // - Add( - swing, - mSwingLows // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mSwingHighs); - - // - Add( - swing, - mSwingHighs // - ); - - // - ArrayReverse(mSwingHighs); - } - else - { - // - Add( - swing, - mSwingHighs // - ); - } - } - - // - state = - isBullish - ? X_SWING_LOW_DETECTED - : X_SWING_HIGH_DETECTED; - - // - return result; - } - - /** - * Detect Momentum Bars ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectMomentumBar( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir; - result = mBarAnalyser.IsMomentumBar( - bar, - iDir, - mMomentumExtend, // Extends ... - mMomentumBodyPercent // Body Percent ... - ); - - // - result = result && - HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - ENUM_XPOIS type = - isBullish - ? X_POI_MOMENTUM_BAR - : X_POI_MOMENTUM_BAR; - - // - // Swing Object ... - XCMomentumBar *momentum; - momentum = new XCMomentumBar(); - result = momentum.Init( - bar // - ); - if (!result) - { - return result; - } - - // - int idx = FindIndex( - momentum, - mMomentumBars // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mMomentumBars); - - // - Add( - momentum, - mMomentumBars // - ); - - // - ArrayReverse(mMomentumBars); - } - else - { - // - Add( - momentum, - mMomentumBars // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishMomentumBars); - - // - Add( - momentum, - mBullishMomentumBars // - ); - - // - ArrayReverse(mBullishMomentumBars); - } - else - { - // - Add( - momentum, - mBullishMomentumBars // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishMomentumBars); - - // - Add( - momentum, - mBearishMomentumBars // - ); - - // - ArrayReverse(mBearishMomentumBars); - } - else - { - // - Add( - momentum, - mBearishMomentumBars // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_MOMENTUM_BAR_DETECTED - : X_BEARISH_MOMENTUM_BAR_DETECTED; - - // - return result; - } - - /** - * Detect Rejection Bars ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectRejectionBar( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir; - result = mBarAnalyser.IsRejectionBar( - bar, - iDir, - mRejectionExtend, // Extends ... - mRejectionShadowPercent // Shadow Percent ... - ); - - // - result = result && - HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - ENUM_XPOIS type = - isBullish - ? X_POI_MOMENTUM_BAR - : X_POI_MOMENTUM_BAR; - - // - // Swing Object ... - XCRejectionBar *rejection; - rejection = new XCRejectionBar(); - result = rejection.Init( - bar // - ); - if (!result) - { - return result; - } - - // - int idx = FindIndex( - rejection, - mRejectionBars // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mRejectionBars); - - // - Add( - rejection, - mRejectionBars // - ); - - // - ArrayReverse(mRejectionBars); - } - else - { - // - Add( - rejection, - mRejectionBars // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishRejectionBars); - - // - Add( - rejection, - mBullishRejectionBars // - ); - - // - ArrayReverse(mBullishRejectionBars); - } - else - { - // - Add( - rejection, - mBullishRejectionBars // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishRejectionBars); - - // - Add( - rejection, - mBearishRejectionBars // - ); - - // - ArrayReverse(mBearishRejectionBars); - } - else - { - // - Add( - rejection, - mBearishRejectionBars // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_REJECTION_BAR_DETECTED - : X_BEARISH_REJECTION_BAR_DETECTED; - - // - return result; - } - - /** - * Detect Support Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectSupportZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL supportBar; - result = mBarAnalyser - .HasSupport( - bar, - supportBar, - mSupResRange // - ); - if (!result) - { - // - supportBar.Clean(); - - // - return result; - } - - // - XCSupportZone *supportZone; - supportZone = new XCSupportZone(); - result = supportZone.Init( - supportBar, - mSupResRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - supportBar.Clean(); - ZeroMemory(supportZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supportZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - supportBar.Clean(); - activationBar.Clean(); - ZeroMemory(supportZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - supportZone, - mSupportZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - supportBar.Clean(); - ZeroMemory(supportZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mSupportZones); - - // - Add( - supportZone, - mSupportZones // - ); - - // - ArrayReverse(mSupportZones); - } - else - { - // - Add( - supportZone, - mSupportZones // - ); - } - - // - state = X_SUPPORT_ZONE_DETECTED; - - // - supportBar.Clean(); - - // - return result; - } - - /** - * Detect Resistance Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectResistanceZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL resistanceBar; - result = mBarAnalyser - .HasResistance( - bar, - resistanceBar, - mSupResRange // - ); - if (!result) - { - // - resistanceBar.Clean(); - - // - return result; - } - - // - XCResistanceZone *resistanceZone; - resistanceZone = new XCResistanceZone(); - result = resistanceZone.Init( - resistanceBar, - mSupResRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - resistanceBar.Clean(); - ZeroMemory(resistanceZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = resistanceZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - resistanceBar.Clean(); - activationBar.Clean(); - ZeroMemory(resistanceZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - resistanceZone, - mResistanceZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - resistanceBar.Clean(); - ZeroMemory(resistanceZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mResistanceZones); - - // - Add( - resistanceZone, - mResistanceZones // - ); - - // - ArrayReverse(mResistanceZones); - } - else - { - // - Add( - resistanceZone, - mResistanceZones // - ); - } - - // - state = X_RESISTANCE_ZONE_DETECTED; - - // - resistanceBar.Clean(); - - // - return result; - } - - /** - * Detect Supply Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectSupplyZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int mSupDemRange = mSupResRange * 2; - - // - XOHCL supplyBar; - result = mBarAnalyser - .HasResistance( - bar, - supplyBar, - mSupDemRange // - ); - if (!result) - { - // - supplyBar.Clean(); - - // - return result; - } - - // - XCSupplyZone *supplyZone; - supplyZone = new XCSupplyZone(); - result = supplyZone.Init( - supplyBar, - mSupDemRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - supplyBar.Clean(); - ZeroMemory(supplyZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supplyZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - supplyBar.Clean(); - activationBar.Clean(); - ZeroMemory(supplyZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - supplyZone, - mSupplyZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - supplyBar.Clean(); - ZeroMemory(supplyZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mSupplyZones); - - // - Add( - supplyZone, - mSupplyZones // - ); - - // - ArrayReverse(mSupplyZones); - } - else - { - // - Add( - supplyZone, - mSupplyZones // - ); - } - - // - state = X_SUPPLY_ZONE_DETECTED; - - // - supplyBar.Clean(); - - // - return result; - } - - /** - * Detect Demand Zone ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectDemandZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int mSupDemRange = mSupResRange * 2; - - // - XOHCL demandBar; - result = mBarAnalyser - .HasSupport( - bar, - demandBar, - mSupDemRange // - ); - if (!result) - { - // - demandBar.Clean(); - - // - return result; - } - - // - XCDemandZone *demandZone; - demandZone = new XCDemandZone(); - result = demandZone.Init( - demandBar, - mSupDemRange, - mSupResRangeAsStart // Use Range As Start ... - ); - if (!result) - { - // - demandBar.Clean(); - ZeroMemory(demandZone); - - // - return result; - } - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = demandZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - demandBar.Clean(); - activationBar.Clean(); - ZeroMemory(demandZone); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - // Add ... - - // - int idx = FindIndex( - demandZone, - mDemandZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - demandBar.Clean(); - ZeroMemory(demandZone); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mDemandZones); - - // - Add( - demandZone, - mDemandZones // - ); - - // - ArrayReverse(mDemandZones); - } - else - { - // - Add( - demandZone, - mDemandZones // - ); - } - - // - state = X_DEMAND_ZONE_DETECTED; - - // - demandBar.Clean(); - - // - return result; - } - - /** - * Detect Order Blocks ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectOrderBlock( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION obDir; - result = mBarAnalyser.HasOrderBlock( - bar, - obBar, - obDir, - mOrderBlockSameBars // - ); - if (!result) - { - // - obBar.Clean(); - - // - return result; - } - - // - XCOrderBlock *ob; - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - obDir // - ); - if (!result) - { - // - obBar.Clean(); - ZeroMemory(ob); - - // - return result; - } - - // - bool isBullish = IsBullish(obDir); - bool isBearish = IsBearish(obDir); - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = ob.IsActivated( - obDir, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - obBar.Clean(); - activationBar.Clean(); - ZeroMemory(ob); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - int idx = FindIndex( - ob, - mOrderBlocks // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - obBar.Clean(); - ZeroMemory(ob); - - // - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mOrderBlocks); - - // - Add( - ob, - mOrderBlocks // - ); - - // - ArrayReverse(mOrderBlocks); - } - else - { - // - Add( - ob, - mOrderBlocks // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishOrderBlocks); - - // - Add( - ob, - mBullishOrderBlocks // - ); - - // - ArrayReverse(mBullishOrderBlocks); - } - else - { - // - Add( - ob, - mBullishOrderBlocks // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishOrderBlocks); - - // - Add( - ob, - mBearishOrderBlocks // - ); - - // - ArrayReverse(mBearishOrderBlocks); - } - else - { - // - Add( - ob, - mBearishOrderBlocks // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_ORDERBLOCK_DETECTED - : X_BEARISH_ORDERBLOCK_DETECTED; - - // - obBar.Clean(); - - // - return result; - } - - /** - * Detect Fair Value Gaps ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectFairValueGap( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false, - bool forceActivation = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - XOHCL fvgStartBar; - XOHCL fvgEndBar; - ENUM_X_DIRECTION fvgDir; - result = mBarAnalyser.HasFairValueGap( - bar, - fvgStartBar, - fvgEndBar, - fvgDir, - mFairValueGapSameBars // - ); - if (!result) - { - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - // - XCFVG *fvg; - fvg = new XCFVG(); - result = fvg.Init( - fvgStartBar, - fvgEndBar, - fvgDir // - ); - if (!result) - { - // - ZeroMemory(fvg); - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - // - bool isBullish = IsBullish(fvgDir); - bool isBearish = IsBearish(fvgDir); - - // - // Check Zone Not Activated ... - if (forceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = fvg.IsActivated( - fvgDir, - activationBar, - isActivationBarBodyIn, - false, - bar.period // - ); - result = !isActivated; - if (!result) - { - // - ZeroMemory(fvg); - fvgEndBar.Clean(); - fvgStartBar.Clean(); - activationBar.Clean(); - - // - return result; - } - - // - activationBar.Clean(); - } - - // - int idx = FindIndex( - fvg, - mFairValueGaps // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - ZeroMemory(fvg); - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - // - // Add ... - if (reversal) - { - // - ArrayReverse(mFairValueGaps); - - // - Add( - fvg, - mFairValueGaps // - ); - - // - ArrayReverse(mFairValueGaps); - } - else - { - // - Add( - fvg, - mFairValueGaps // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishFairValueGaps); - - // - Add( - fvg, - mBullishFairValueGaps // - ); - - // - ArrayReverse(mBullishFairValueGaps); - } - else - { - // - Add( - fvg, - mBullishFairValueGaps // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishFairValueGaps); - - // - Add( - fvg, - mBearishFairValueGaps // - ); - - // - ArrayReverse(mBearishFairValueGaps); - } - else - { - // - Add( - fvg, - mBearishFairValueGaps // - ); - } - } - - // - state = - isBullish - ? X_BULLISH_FVG_DETECTED - : X_BEARISH_FVG_DETECTED; - - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - return result; - } - - /** - * Detect Consolidation Zones ... - * - * @param bar: XOHCL instance ... - * @param reversal: boolean reversal add to collection ... - * - * @return ( bool ) - */ - bool DetectConsolidationZone( - XOHCL &bar, - ENUM_XPOI_EVENTS &state, - bool reversal = false // - ) - { - // - bool result = false; - - // - state = X_POI_EVENT_NONE; - - // - XConsolidationZone cZone; - result = mBarAnalyser.HasConsolidationZone( - bar, - cZone, - mConsolidationZoneMinLoopback, - mConsolidationZoneRangeInPoint, - mConsolidationZonesUpperAppliedTo, - mConsolidationZonesLowerAppliedTo // - ); - if (!result) - { - // - cZone.Clean(); - - // - return result; - } - - // - // Add ... - - // - bool isBullish = IsBullish(cZone.dir); - bool isBearish = IsBearish(cZone.dir); - - // - int idx = FindIndex( - cZone, - mConsolidationZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - cZone.Clean(); - - // - return result; - } - - // - if (reversal) - { - // - ArrayReverse(mConsolidationZones); - - // - AddRef( - cZone, - mConsolidationZones // - ); - - // - ArrayReverse(mConsolidationZones); - } - else - { - // - AddRef( - cZone, - mConsolidationZones // - ); - } - - // - if (isBullish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBullishConsolidationZones); - - // - AddRef( - cZone, - mBullishConsolidationZones // - ); - - // - ArrayReverse(mBullishConsolidationZones); - } - else - { - // - AddRef( - cZone, - mBullishConsolidationZones // - ); - } - } - else if (isBearish) - { - // - // Add Swings ... - if (reversal) - { - // - ArrayReverse(mBearishConsolidationZones); - - // - AddRef( - cZone, - mBearishConsolidationZones // - ); - - // - ArrayReverse(mBearishConsolidationZones); - } - else - { - // - AddRef( - cZone, - mBearishConsolidationZones // - ); - } - } - - // - state = - IsBullish(cZone.dir) - ? X_BULLISH_CONSOLIDATION_ZONE_DETECTED - : X_BEARISH_CONSOLIDATION_ZONE_DETECTED; - - // - cZone.Clean(); - - // - return result; - } - - // - protected: - // - - // - void CleanCollections() - { - // - Clean(mSwings); - Clean(mSwingLows); - Clean(mSwingHighs); - Clean(mDemandZones); - Clean(mSupplyZones); - Clean(mOrderBlocks); - Clean(mMomentumBars); - Clean(mSupportZones); - Clean(mRejectionBars); - Clean(mFairValueGaps); - Clean(mEventListeners); - Clean(mResistanceZones); - Clean(mBullishOrderBlocks); - Clean(mBearishOrderBlocks); - Clean(mConsolidationZones); - Clean(mBullishMomentumBars); - Clean(mBearishMomentumBars); - Clean(mBullishRejectionBars); - Clean(mBearishRejectionBars); - Clean(mBullishFairValueGaps); - Clean(mBearishFairValueGaps); - Clean(mBullishConsolidationZones); - Clean(mBearishConsolidationZones); - } - - // - void ReverseCollections() - { - // - ArrayReverse(mSwings); - ArrayReverse(mSwingLows); - ArrayReverse(mSwingHighs); - ArrayReverse(mDemandZones); - ArrayReverse(mSupplyZones); - ArrayReverse(mOrderBlocks); - ArrayReverse(mMomentumBars); - ArrayReverse(mSupportZones); - ArrayReverse(mRejectionBars); - ArrayReverse(mFairValueGaps); - ArrayReverse(mEventListeners); - ArrayReverse(mResistanceZones); - ArrayReverse(mBullishOrderBlocks); - ArrayReverse(mBearishOrderBlocks); - ArrayReverse(mConsolidationZones); - ArrayReverse(mBullishMomentumBars); - ArrayReverse(mBearishMomentumBars); - ArrayReverse(mBullishRejectionBars); - ArrayReverse(mBearishRejectionBars); - ArrayReverse(mBullishFairValueGaps); - ArrayReverse(mBearishFairValueGaps); - ArrayReverse(mBullishConsolidationZones); - ArrayReverse(mBearishConsolidationZones); - } - - // - void CleanupUnusedCollections( - int maxAllowed = 0 // - ) - { - // - maxAllowed = MaxRequiredPOIs(); - - // - if (maxAllowed <= 0) - { - return; - } - - // - CleanupArray( - mEventListeners, - maxAllowed // - ); - - // - CleanupArray( - mSwings, - maxAllowed // - ); - - // - CleanupArray( - mSwingLows, - maxAllowed // - ); - - // - CleanupArray( - mSwingHighs, - maxAllowed // - ); - - // - CleanupArray( - mMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mBullishMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mBearishMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mBullishRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mBearishRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mSupportZones, - maxAllowed // - ); - - // - CleanupArray( - mDemandZones, - maxAllowed // - ); - - // - CleanupArray( - mSupplyZones, - maxAllowed // - ); - - // - CleanupArray( - mResistanceZones, - maxAllowed // - ); - - // - CleanupArray( - mFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mBullishFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mBearishFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mBullishOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mBearishOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mConsolidationZones, - maxAllowed // - ); - - // - CleanupArray( - mBullishConsolidationZones, - maxAllowed // - ); - - // - CleanupArray( - mBearishConsolidationZones, - maxAllowed // - ); - - // - } - - /** - * Notify Event Listeners ... - * - * @param event: ENUM_XPOI_EVENTS member, Specified Occured Event ... - * @param param: XCBasePOI implementation, Specified Event Object ... - */ - void NotifyEventListeners( - ENUM_XPOI_EVENTS event, - XCBasePOI *param // - ) - { - // - int count = ArraySize(mEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - mEventListeners[i]( - event, - param // - ); - } - } - - // - private: - // - - // - // Props ... - string mSymbol; // Market Symbol ... - ENUM_TIMEFRAMES mPeriod; // Market Period ... - XBarTracker mBarTracker; // Market Bar Tracker ... - XCBarAnalyser *mBarAnalyser; // Bar Analyser ... - - // - bool mLock; - - // - int mMaxRequiredPOIs; // Max Allowed Holds POI(s) ... - int maxAllowedLoopbackForInit; // Max Allowed Loopback for POI(s) Detection on Initialization Process ... - - // - TOnPOIEvent mEventListeners[]; // Event Listeners ... - - // - XCSwing *mSwings[]; // Holds Founded Swing ... - XCSwing *mSwingLows[]; // Holds Founded Swing Lows ... - XCSwing *mSwingHighs[]; // Holds Founded Swing Highs ... - int mSwingRange; // Swing Detection Range ... - - // - XCMomentumBar *mMomentumBars[]; // Holds Founded Momentum Bars ... - XCMomentumBar *mBullishMomentumBars[]; // Holds Founded Bullish Momentum Bars ... - XCMomentumBar *mBearishMomentumBars[]; // Holds Founded Bearish Momentum Bars ... - int mMomentumExtend; // Momentum Bar Detection Extends Range ... - double mMomentumBodyPercent; // Momentum Bar Detection Body Percent ... - - // - XCRejectionBar *mRejectionBars[]; // Holds Founded Rejection Bars ... - XCRejectionBar *mBullishRejectionBars[]; // Holds Founded Bullish Rejection Bars ... - XCRejectionBar *mBearishRejectionBars[]; // Holds Founded Bearish Rejection Bars ... - int mRejectionExtend; // Rejection Bar Detection Extends Range ... - double mRejectionShadowPercent; // Rejection Bar Detection Body Percent ... - - // - XCSupplyZone *mSupplyZones[]; // Holds Detected Supply Zones ... - XCDemandZone *mDemandZones[]; // Holds Detected Demand Zones ... - - // - int mSupResRange; // Support and Resistance Detection Range ... - bool mSupResRangeAsStart; // use Support and Resistance Range as Start ... - XCSupportZone *mSupportZones[]; // Holds Detected Support Zones ... - XCResistanceZone *mResistanceZones[]; // Holds Detected Resistance Zones ... - - // - XCFVG *mFairValueGaps[]; // Holds Founded FairValueGaps ... - XCFVG *mBullishFairValueGaps[]; // Holds Founded Bullish FairValueGaps ... - XCFVG *mBearishFairValueGaps[]; // Holds Founded Bearish FairValueGaps ... - int mFairValueGapSameBars; // FairValueGap Detection Same Bars ... - - // - XCOrderBlock *mOrderBlocks[]; // Holds Founded OrderBlocks ... - XCOrderBlock *mBullishOrderBlocks[]; // Holds Founded Bullish OrderBlocks ... - XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish OrderBlocks ... - int mOrderBlockSameBars; // OrderBlock Detection Same Bars ... - - // - int mConsolidationZoneMinLoopback; // Minimum Length of Cnsolidation Zone ... - double mConsolidationZoneRangeInPoint; // Consolidation Zone Range in Point ... - XConsolidationZone mConsolidationZones[]; // Holds Founded Consolidation Zones ... - XConsolidationZone mBullishConsolidationZones[]; // Holds Founded Bullish Consolidation Zones ... - XConsolidationZone mBearishConsolidationZones[]; // Holds Founded Bearish Consolidation Zones ... - ENUM_APPLIED_PRICE mConsolidationZonesLowerAppliedTo; // Consolidation Zone Upper Applied To ... - ENUM_APPLIED_PRICE mConsolidationZonesUpperAppliedTo; // Consolidation Zone Lower Applied To ... - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x121.xsessions.mq5 b/Documents/BKP/x-saherelm.x121.xsessions.mq5 deleted file mode 100644 index c2660db9..00000000 --- a/Documents/BKP/x-saherelm.x121.xsessions.mq5 +++ /dev/null @@ -1,197 +0,0 @@ -//+------------------------------------------------------------------+ -//| Forex Sessions and Day Range Indicator | -//+------------------------------------------------------------------+ -#property copyright "Your Name" -#property link "https://www.example.com" -#property version "1.00" -#property indicator_chart_window - -#include - -struct SessionInfo { - string name; - int startHour; // Standard start hour (GMT) - int startMinute; - int endHour; // Standard end hour (GMT) - int endMinute; - bool *isDST(datetime); // DST check function - int dstAdjustment; // Hours to add during DST -}; - -SessionInfo sessions[] = { - {"Sydney", 21, 0, 5, 0, IsSydneyDST, 1}, - {"Tokyo", 23, 0, 8, 0, IsTokyoDST, 0}, - {"London", 7, 0, 15, 0, IsLondonDST, 1}, - {"New York", 12, 0, 17, 0, IsNewYorkDST, 1} -}; - -bool sessionActive[]; -double sessionHigh[]; -double sessionLow[]; -datetime sessionStartTime[]; -datetime sessionEndTime[]; - -double dayHigh = 0; -double dayLow = 0; -datetime dayStartTime; - -//+------------------------------------------------------------------+ -//| Custom indicator initialization function | -//+------------------------------------------------------------------+ -int OnInit() { - ArrayResize(sessionActive, ArraySize(sessions)); - ArrayResize(sessionHigh, ArraySize(sessions)); - ArrayResize(sessionLow, ArraySize(sessions)); - ArrayResize(sessionStartTime, ArraySize(sessions)); - ArrayResize(sessionEndTime, ArraySize(sessions)); - - for(int i=0; i= todayStart && currentTime < todayEnd) { - if(!sessionActive[i]) { - sessionActive[i] = true; - sessionStartTime[i] = todayStart; - sessionEndTime[i] = todayEnd; - sessionHigh[i] = Bid; - sessionLow[i] = Ask; - } else { - if(Bid > sessionHigh[i]) sessionHigh[i] = Bid; - if(Ask < sessionLow[i]) sessionLow[i] = Ask; - } - } else { - sessionActive[i] = false; - } - } - - // Check day range - bool dstActiveNY = IsNewYorkDST(currentTime); - int dayStartHour = dstActiveNY ? 21 : 22; - datetime todayDayStart = StringToTime(TimeToString(currentTime, TIME_DATE) + " " + - IntegerToString(dayStartHour) + ":00"); - - if(currentTime < todayDayStart) { - todayDayStart -= 24 * 3600; - } - - if(dayStartTime != todayDayStart) { - dayStartTime = todayDayStart; - dayHigh = Bid; - dayLow = Ask; - } else { - if(Bid > dayHigh) dayHigh = Bid; - if(Ask < dayLow) dayLow = Ask; - } - - // Display information on chart - string comment = "Active Forex Sessions:\n"; - for(int i=0; i= dstStart && time < dstEnd; -} - -bool IsNewYorkDST(datetime time) { - int year = TimeYear(time); - datetime march1 = StringToTime(year + ".03.01 00:00"); - int dayOfWeekMarch1 = TimeDayOfWeek(march1); - int secondSundayMarch = 1 + (7 - dayOfWeekMarch1) % 7 + 7; - datetime dstStart = StringToTime(year + ".03." + IntegerToString(secondSundayMarch) + " 07:00"); - - datetime nov1 = StringToTime(year + ".11.01 00:00"); - int dayOfWeekNov1 = TimeDayOfWeek(nov1); - int firstSundayNov = 1 + (7 - dayOfWeekNov1) % 7; - datetime dstEnd = StringToTime(year + ".11." + IntegerToString(firstSundayNov) + " 06:00"); - - return time >= dstStart && time < dstEnd; -} - -bool IsSydneyDST(datetime time) { - int year = TimeYear(time); - datetime oct1 = StringToTime(year + ".10.01 00:00"); - int dayOfWeekOct1 = TimeDayOfWeek(oct1); - int firstSundayOct = 1 + (7 - dayOfWeekOct1) % 7; - datetime dstStart = StringToTime(year + ".10." + IntegerToString(firstSundayOct) + " 13:00"); - - datetime apr1 = StringToTime(year + ".04.01 00:00"); - int dayOfWeekApr1 = TimeDayOfWeek(apr1); - int firstSundayApr = 1 + (7 - dayOfWeekApr1) % 7; - datetime dstEnd = StringToTime(year + ".04." + IntegerToString(firstSundayApr) + " 15:00"); - - return time >= dstStart && time < dstEnd; -} - -bool IsTokyoDST(datetime time) { - return false; -} \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x121.xwz.mq5 b/Documents/BKP/x-saherelm.x121.xwz.mq5 deleted file mode 100644 index 626ee8e9..00000000 --- a/Documents/BKP/x-saherelm.x121.xwz.mq5 +++ /dev/null @@ -1,2780 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 XWZ -// Description: XWZ ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Glzoneal Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 XWZ Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121_XWZ" - -// -// Includes Common Library ... -#include "../Classes/x-saherelm.x-alert.class.mq5" -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Classes/x-saherelm.x-poi.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Libraries/x-saherelm.common.lib.mq5" -#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" - -// -// Inputs ... - -// -// Market ... -input group "Market"; - -// -input group "Calculation"; -input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Detect Price Type - -// -input group "MA Detection"; -input int maLength = 20; // MA Length -input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method - -// -input group "ATR StopLoss"; -input int atrLength = 14; // ATR Length -input double atrMultiplier = 2; // ATR Multiplier - -// -input group "ADX Detection"; -input int adxLength = 14; // ADX Length -input double adxThreshold = 25; // ADX Threshold for Strong Trends - -// -input group "POI Detection"; -input ENUM_TIMEFRAMES orderBlockTF = PERIOD_H1; // Order Block Detection Time Frame -input ENUM_TIMEFRAMES fairValueGapTF = PERIOD_M15; // Fair Value Gap Detection Time Frame -input ENUM_TIMEFRAMES supDemTF = PERIOD_H4; // Supply and Demand Detection Time Frame - -// -input group "Alert"; -input bool mXWZEnableAlerts = true; // Enable Alerts -input bool mXWZPushAlerts = false; // Push Alerts -input bool mXWZMailAlerts = false; // Mail Alerts -input bool mXWZTerminalAlerts = false; // Terminal Alerts - -// -// Presentation ... -input group "Presentation"; - -// -input group "Buffer Presentation"; -input bool showMA = true; // Show Moving Average -input bool showPin = true; // Show Pin Bars -input bool showSwing = true; // Show Swing Bars -input bool showTrend = true; // Show Trend -input bool showEngulf = true; // Show Engulf Bars -input bool showLongSL = true; // Show Long SL -input bool showShortSL = true; // Show Short SL -input bool showMomentum = true; // Show Momentum Bars -input bool showRejection = true; // Show Rejection Bars - -// -input group "POI Presentation"; -input bool showPOIs = true; // Show POI(s) -input bool showOrderBlocks = true; // Show Order Blocks -input bool showFairValueGaps = true; // Show Fair Value Gaps -input bool showSupplyZones = true; // Show Supply Zones -input bool showDemandZones = true; // Show Demand Zones - -// -input group "Presentation Config"; -input int startCalculationForLastBars = 1000; // Calculate Last n Bars -input int upTrendArrowCode = 236; // Up Trend Arrow Code -input int downTrendArrowCode = 238; // Down Trend Arrow Code -input int swingLowArrowCode = 108; // Swing Low Arrow Code -input int swingHighArrowCode = 108; // Swing High Arrow Code -input int bullishPinArrowCode = 246; // Bullish Pin Arrow Code -input int bearishPinArrowCode = 248; // Bearish Pin Arrow Code -input int bullishEngulfArrowCode = 200; // Bullish Engulf Arrow Code -input int bearishEngulfArrowCode = 202; // Bearish Engulf Arrow Code -input int bullishMomentumArrowCode = 233; // Bullish Momentum Arrow Code -input int bearishMomentumArrowCode = 234; // Bearish Momentum Arrow Code -input int bullishRejectionArrowCode = 241; // Bullish Rejection Arrow Code -input int bearishRejectionArrowCode = 242; // Bearish Rejection Arrow Code - -// -#property indicator_chart_window - -// -#property indicator_buffers 17 -#property indicator_plots 15 - -// -// Plot Buffers ... - -// -#define maBufferIndex 0 -double maBuffer[]; - -// -#property indicator_label1 "X121-XWZ MA" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrLightSkyBlue -#property indicator_style1 STYLE_SOLID -#property indicator_width1 2 - -// -#define longSLBufferIndex 1 -double longSLBuffer[]; - -// -#property indicator_label2 "X121-XWZ Long SL" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrOrange -#property indicator_style2 STYLE_SOLID -#property indicator_width2 1 - -// -#define shortSLBufferIndex 2 -double shortSLBuffer[]; - -// -#property indicator_label3 "X121-XWZ Short SL" -#property indicator_type3 DRAW_LINE -#property indicator_color3 clrOrange -#property indicator_style3 STYLE_SOLID -#property indicator_width3 1 - -// -#define upTrendBufferIndex 3 -double upTrendBuffer[]; - -// -#property indicator_label4 "X121-XWZ Trend Up" -#property indicator_type4 DRAW_ARROW -#property indicator_color4 clrAqua -#property indicator_width4 3 - -// -#define downTrendBufferIndex 4 -double downTrendBuffer[]; - -// -#property indicator_label5 "X121-XWZ Trend Down" -#property indicator_type5 DRAW_ARROW -#property indicator_color5 clrMagenta -#property indicator_width5 3 - -// -#define bullishMomentumBufferIndex 5 -double bullishMomentumBuffer[]; - -// -#property indicator_label6 "X121-XWZ Bull Momentum" -#property indicator_type6 DRAW_ARROW -#property indicator_color6 clrAqua -#property indicator_width6 3 - -// -#define bearishMomentumBufferIndex 6 -double bearishMomentumBuffer[]; - -// -#property indicator_label7 "X121-XWZ Bear Momentum" -#property indicator_type7 DRAW_ARROW -#property indicator_color7 clrMagenta -#property indicator_width7 3 - -// -#define bullishRejectionBufferIndex 7 -double bullishRejectionBuffer[]; - -// -#property indicator_label8 "X121-XWZ Bull Rejection" -#property indicator_type8 DRAW_ARROW -#property indicator_color8 clrAqua -#property indicator_width8 3 - -// -#define bearishRejectionBufferIndex 8 -double bearishRejectionBuffer[]; - -// -#property indicator_label9 "X121-XWZ Bear Rejection" -#property indicator_type9 DRAW_ARROW -#property indicator_color9 clrMagenta -#property indicator_width9 3 - -// -#define bullishPinBufferIndex 9 -double bullishPinBuffer[]; - -// -#property indicator_label10 "X121-XWZ Bull Pin" -#property indicator_type10 DRAW_ARROW -#property indicator_color10 clrAqua -#property indicator_width10 3 - -// -#define bearishPinBufferIndex 10 -double bearishPinBuffer[]; - -// -#property indicator_label11 "X121-XWZ Bear Pin" -#property indicator_type11 DRAW_ARROW -#property indicator_color11 clrMagenta -#property indicator_width11 3 - -// -#define bullishEngulfBufferIndex 11 -double bullishEngulfBuffer[]; - -// -#property indicator_label12 "X121-XWZ Bull Engulf" -#property indicator_type12 DRAW_ARROW -#property indicator_color12 clrAqua -#property indicator_width12 3 - -// -#define bearishEngulfBufferIndex 12 -double bearishEngulfBuffer[]; - -// -#property indicator_label13 "X121-XWZ Bear Engulf" -#property indicator_type13 DRAW_ARROW -#property indicator_color13 clrMagenta -#property indicator_width13 3 - -// -#define swingLowBufferIndex 13 -double swingLowBuffer[]; - -// -#property indicator_label14 "X121-XWZ Swing Low" -#property indicator_type14 DRAW_ARROW -#property indicator_color14 clrAqua -#property indicator_width14 3 - -// -#define swingHighBufferIndex 14 -double swingHighBuffer[]; - -// -#property indicator_label15 "X121-XWZ Swing High" -#property indicator_type15 DRAW_ARROW -#property indicator_color15 clrMagenta -#property indicator_width15 3 - -// -// Data Buffers ... - -// -int mLastBufferIndex = 14; - -// -#define atrBufferIndex mLastBufferIndex + 1 -double atrBuffer[]; - -// -#define adxBufferIndex mLastBufferIndex + 2 -double adxBuffer[]; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int maxLength; - -// -// MA Handler ... -int maHandler = INVALID_HANDLE; - -// -// ATR Handler ... -int atrHandler = INVALID_HANDLE; - -// -// ADX Handler ... -int adxHandler = INVALID_HANDLE; - -// -XCAlert *mXWZAlert; -XBarTracker mXWZBarTracker; -CArrayObj mXWZDrawnObjects; -XCPOIDrawer *mXWZPOIDrawer; -XCBarAnalyser *mXWZBarAnalyser; - -// -// POI(s) ... - -// -bool mXWZDetectOrderBlocks = true; -bool mXWZDetectFairValueGaps = true; -bool mXWZDetectSupplyZones = true; -bool mXWZDetectDemandZones = true; - -// -bool mXWZIgnoreUnActivateds = true; - -// -bool mXWZForceStarteds = true; -bool mXWZForceUnBreaked = true; -bool mXWZForceActivation = true; - -// -int mXWZSuResRange = 21; -int mXWZOBFVGSameBars = 3; - -// -// Un Activated POI(s) ... -XCFVG *mXWZUnActivatedFVGs[]; -XCOrderBlock *mXWZUnActivatedOBs[]; -XCSupplyZone *mXWZUnActivatedSupplyZones[]; -XCDemandZone *mXWZUnActivatedDemandZones[]; - -// -// Activated POI(s) ... -XCFVG *mXWZActivatedFVGs[]; -XCOrderBlock *mXWZActivatedOBs[]; -XCSupplyZone *mXWZActivatedSupplyZones[]; -XCDemandZone *mXWZActivatedDemandZones[]; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - mXWZDrawnObjects.Clear(); - - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // MA ... - maHandler = iMA( - _Symbol, - _Period, - maLength, - 0, - maMethod, - appliedTo // - ); - bool isInited = maHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ATR ... - atrHandler = iATR( - _Symbol, - _Period, - atrLength // - ); - isInited = maHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ADX ... - adxHandler = iADX( - _Symbol, - _Period, - adxLength // - ); - isInited = maHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - IndicatorSetInteger(INDICATOR_DIGITS, 2); - - // - // Initialize Bar Tracker ... - mXWZBarTracker.Init( - _Symbol, - _Period // - ); - - // - mXWZPOIDrawer = new XCPOIDrawer(); - ConfigurePOIDrawer(); - - // - mXWZAlert = new XCAlert(); - ConfigureAlert(); - - // - mXWZBarAnalyser = new XCBarAnalyser(); - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -/** - * De Initialize Indicator ... - * - * @param reason: Integer, De Initialization Reason ... - */ -void OnDeinit(const int reason) -{ - // - // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart - // REASON_RECOMPILE 2 Program recompiled - // REASON_CHARTCHANGE 3 A symbol or a chart period is changed - // REASON_CHARTCLOSE 4 Chart closed - // REASON_PARAMETERS 5 Inputs changed by a user - // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings - // REASON_TEMPLATE 7 Another chart template applied - // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value - // REASON_CLOSE 9 Terminal closed - - // - IndicatorRelease(maHandler); - IndicatorRelease(atrHandler); - IndicatorRelease(adxHandler); - - // - mXWZDrawnObjects.Clear(); - - // - ZeroMemory(mXWZAlert); - ZeroMemory(mXWZPOIDrawer); - ZeroMemory(mXWZBarAnalyser); - - // - Clean(mXWZActivatedOBs); - Clean(mXWZActivatedFVGs); - Clean(mXWZActivatedSupplyZones); - Clean(mXWZActivatedDemandZones); - - // - Clean(mXWZUnActivatedOBs); - Clean(mXWZUnActivatedFVGs); - Clean(mXWZUnActivatedSupplyZones); - Clean(mXWZUnActivatedDemandZones); -} - -/** - * Calculate Bars ... - * - * @param rates_total: Integer, Total Bars on Chart ... - * @param prev_calculated: Integer, Total Calculated Bars on Charts ... - * @param time: DateTime Array, History of Open Time ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param low: Double Array, History of Low Prices ... - * @param close: Double Array, History of Close Prices ... - * @param tick_volume: Long, History of Tick Volumes on Bar ... - * @param volume: Long, History of Trade Volumes ... - * @param spread: Double, History of Spread Price ... - * - * @return ( int ) - */ -int OnCalculate( - const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[] // -) -{ - // - // Prepare Buffers ... - ArraySetAsSeries(time, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(low, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - ArraySetAsSeries(volume, true); - ArraySetAsSeries(spread, true); - - // - // Validate Calculated Bars ... - - // - // MA ... - int maCalculatedBars = BarsCalculated(maHandler); - - // - // ATR ... - int atrCalculatedBars = BarsCalculated(atrHandler); - - // - // ADX ... - int adxCalculatedBars = BarsCalculated(adxHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // MA ... - maCalculatedBars >= maxLength && - // - // ATR ... - atrCalculatedBars >= maxLength && - // - // ADX ... - adxCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - // MA ... - int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer); - - // - // ATR ... - int copiedAtr = CopyBuffer(atrHandler, MAIN_LINE, 0, limit, atrBuffer); - - // - // ADX ... - int copiedAdxs = CopyBuffer(adxHandler, MAIN_LINE, 0, limit, adxBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // MA ... - copiedMas > 0 && - // - // ATR ... - copiedAtr > 0 && - // - // ADX ... - copiedAdxs > 0 - // - ; - if (!isPassedRequiredCopiedItems) - { - return prev_calculated; - } - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - CalculateBuffers( - // - i, - prev_calculated, - rates_total, - // - open, - high, - close, - low, - tick_volume // - ); - } - - // - return rates_total; -} - -// -// Functions ... - -/** - * Validate Input Args for Initialization ... - * - * @return ( bool ) - */ -bool ValidateInputs() -{ - // - bool result = false; - - // - result = - // - // MA ... - maLength > 0 && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 && - // - // ADX ... - adxLength > 0 && - adxThreshold > 0 - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - result = MathMax(maLength, atrLength); - result = MathMax(result, adxLength); - - // - return result; -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // Plot Buffers ... - - // - // MA Buffer ... - - // - ENUM_DRAW_TYPE maDrawType = showMA ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(maBuffer, true); - SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showMA); - PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, maDrawType); - - // - PlotIndexSetDouble(maBufferIndex, PLOT_EMPTY_VALUE, 0); - - // - // LONG SL Buffer ... - - // - ENUM_DRAW_TYPE longSLDrawType = showLongSL ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(longSLBuffer, true); - SetIndexBuffer(longSLBufferIndex, longSLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(longSLBufferIndex, PLOT_SHOW_DATA, showLongSL); - PlotIndexSetInteger(longSLBufferIndex, PLOT_DRAW_TYPE, longSLDrawType); - - // - PlotIndexSetDouble(longSLBufferIndex, PLOT_EMPTY_VALUE, 0); - - // - // SHORT SL Buffer ... - - // - ENUM_DRAW_TYPE shortSLDrawType = showShortSL ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(shortSLBuffer, true); - SetIndexBuffer(shortSLBufferIndex, shortSLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(shortSLBufferIndex, PLOT_SHOW_DATA, showShortSL); - PlotIndexSetInteger(shortSLBufferIndex, PLOT_DRAW_TYPE, shortSLDrawType); - - // - PlotIndexSetDouble(shortSLBufferIndex, PLOT_EMPTY_VALUE, 0); - - // - // UP Trend ... - - // - ENUM_DRAW_TYPE upTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(upTrendBuffer, true); - SetIndexBuffer(upTrendBufferIndex, upTrendBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showTrend); - PlotIndexSetInteger(upTrendBufferIndex, PLOT_DRAW_TYPE, upTrendDrawType); - - // - PlotIndexSetDouble(upTrendBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(upTrendBufferIndex, PLOT_ARROW, upTrendArrowCode); - - // - // DOWN Trend ... - - // - ENUM_DRAW_TYPE downTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(downTrendBuffer, true); - SetIndexBuffer(downTrendBufferIndex, downTrendBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showTrend); - PlotIndexSetInteger(downTrendBufferIndex, PLOT_DRAW_TYPE, downTrendDrawType); - - // - PlotIndexSetDouble(downTrendBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(downTrendBufferIndex, PLOT_ARROW, downTrendArrowCode); - - // - // Bullish Momentum ... - - // - ENUM_DRAW_TYPE bullishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishMomentumBuffer, true); - SetIndexBuffer(bullishMomentumBufferIndex, bullishMomentumBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); - PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_DRAW_TYPE, bullishMomentumDrawType); - - // - PlotIndexSetDouble(bullishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_ARROW, bullishMomentumArrowCode); - - // - // Bearish Momentum ... - - // - ENUM_DRAW_TYPE bearishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishMomentumBuffer, true); - SetIndexBuffer(bearishMomentumBufferIndex, bearishMomentumBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); - PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_DRAW_TYPE, bearishMomentumDrawType); - - // - PlotIndexSetDouble(bearishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_ARROW, bearishMomentumArrowCode); - - // - // Bullish Rejection ... - - // - ENUM_DRAW_TYPE bullishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishRejectionBuffer, true); - SetIndexBuffer(bullishRejectionBufferIndex, bullishRejectionBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); - PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_DRAW_TYPE, bullishRejectionDrawType); - - // - PlotIndexSetDouble(bullishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_ARROW, bullishRejectionArrowCode); - - // - // Bearish Rejection ... - - // - ENUM_DRAW_TYPE bearishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishRejectionBuffer, true); - SetIndexBuffer(bearishRejectionBufferIndex, bearishRejectionBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); - PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_DRAW_TYPE, bearishRejectionDrawType); - - // - PlotIndexSetDouble(bearishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_ARROW, bearishRejectionArrowCode); - - // - // Bullish Pin ... - - // - ENUM_DRAW_TYPE bullishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishPinBuffer, true); - SetIndexBuffer(bullishPinBufferIndex, bullishPinBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishPinBufferIndex, PLOT_SHOW_DATA, showPin); - PlotIndexSetInteger(bullishPinBufferIndex, PLOT_DRAW_TYPE, bullishPinDrawType); - - // - PlotIndexSetDouble(bullishPinBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishPinBufferIndex, PLOT_ARROW, bullishPinArrowCode); - - // - // Bearish Pin ... - - // - ENUM_DRAW_TYPE bearishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishPinBuffer, true); - SetIndexBuffer(bearishPinBufferIndex, bearishPinBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishPinBufferIndex, PLOT_SHOW_DATA, showPin); - PlotIndexSetInteger(bearishPinBufferIndex, PLOT_DRAW_TYPE, bearishPinDrawType); - - // - PlotIndexSetDouble(bearishPinBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishPinBufferIndex, PLOT_ARROW, bearishPinArrowCode); - - // - // Bullish Engulf ... - - // - ENUM_DRAW_TYPE bullishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishEngulfBuffer, true); - SetIndexBuffer(bullishEngulfBufferIndex, bullishEngulfBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); - PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_DRAW_TYPE, bullishEngulfDrawType); - - // - PlotIndexSetDouble(bullishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_ARROW, bullishEngulfArrowCode); - - // - // Bearish Engulf ... - - // - ENUM_DRAW_TYPE bearishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishEngulfBuffer, true); - SetIndexBuffer(bearishEngulfBufferIndex, bearishEngulfBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); - PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_DRAW_TYPE, bearishEngulfDrawType); - - // - PlotIndexSetDouble(bearishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_ARROW, bearishEngulfArrowCode); - - // - // Swing Low ... - - // - ENUM_DRAW_TYPE swingLowDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(swingLowBuffer, true); - SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingLowBufferIndex, PLOT_SHOW_DATA, showSwing); - PlotIndexSetInteger(swingLowBufferIndex, PLOT_DRAW_TYPE, swingLowDrawType); - - // - PlotIndexSetDouble(swingLowBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(swingLowBufferIndex, PLOT_ARROW, swingLowArrowCode); - - // - // Swing High ... - - // - ENUM_DRAW_TYPE swingHighDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(swingHighBuffer, true); - SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingHighBufferIndex, PLOT_SHOW_DATA, showSwing); - PlotIndexSetInteger(swingHighBufferIndex, PLOT_DRAW_TYPE, swingHighDrawType); - - // - PlotIndexSetDouble(swingHighBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(swingHighBufferIndex, PLOT_ARROW, swingHighArrowCode); - - // - // DATA Buffers ... - - // - ArraySetAsSeries(atrBuffer, true); - SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(adxBuffer, true); - SetIndexBuffer(adxBufferIndex, adxBuffer, INDICATOR_CALCULATIONS); -} - -/** - * Calculate Custom Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int barsLimit = startCalculationForLastBars > 0 - ? startCalculationForLastBars - : 0; - // - // bool canCalculate = true; - bool canCalculate = - barsLimit == 0 || - bar_index <= barsLimit; - if (canCalculate) - { - // - CalculatedPOIs( - // - bar_index, - prevCalculated, - ratesTotal, - // - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateValues( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - else - { - FillBuffersZero(bar_index); - } -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - maBuffer[barIndex] = 0; - atrBuffer[barIndex] = 0; - adxBuffer[barIndex] = 0; - longSLBuffer[barIndex] = 0; - shortSLBuffer[barIndex] = 0; - upTrendBuffer[barIndex] = 0; - swingLowBuffer[barIndex] = 0; - swingHighBuffer[barIndex] = 0; - downTrendBuffer[barIndex] = 0; - bullishPinBuffer[barIndex] = 0; - bearishPinBuffer[barIndex] = 0; - bullishEngulfBuffer[barIndex] = 0; - bearishEngulfBuffer[barIndex] = 0; - bullishMomentumBuffer[barIndex] = 0; - bearishMomentumBuffer[barIndex] = 0; - bullishRejectionBuffer[barIndex] = 0; - bearishRejectionBuffer[barIndex] = 0; -} - -/** - * Calculate Vales ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateValues( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Prepare Requirements ... - - // - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - bar_index // - ); - if (!isInited) - { - // - iBar.Clean(); - return; - } - - // - XOHCL pBar; - isInited = iBar.GetPreviousBar(pBar); - if (!isInited) - { - // - iBar.Clean(); - pBar.Clean(); - return; - } - int pIndex = pBar.Index(); - - // - // Calculate Applied Price ... - double iPrice = GetAppliedPrice( - appliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - double iMa = maBuffer[bar_index]; - double iMaPrev = maBuffer[pIndex]; - double iAtr = atrBuffer[bar_index]; - double iAdx = adxBuffer[bar_index]; - double iAppliedAtr = iAtr * atrMultiplier; - - // - double points = GetPoints(_Symbol); - double points10 = 10 * points; - - // - ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - - // - // SL Buffers ... - - // - double iLongSL = iPrice - iAppliedAtr; - double iShortSL = iPrice + iAppliedAtr; - - // - longSLBuffer[bar_index] = iLongSL; - shortSLBuffer[bar_index] = iShortSL; - - // - // Trend Buffers ... - - // - bool isUpTrend = - // - iPrice > iMa && - iBar.low < iMa && - iAdx > adxThreshold - // - ; - - // - bool isDownTrend = - // - iPrice < iMa && - iBar.high > iMa && - iAdx > adxThreshold - // - ; - - // - double upTrendValue = 0; - double downTrendValue = 0; - if (isUpTrend) - { - upTrendValue = iBar.low; - } - if (isDownTrend) - { - downTrendValue = iBar.high; - } - - // - upTrendBuffer[bar_index] = upTrendValue; - downTrendBuffer[bar_index] = downTrendValue; - - // - // Momentum Buffers ... - - // - bool isMomentum = mXWZBarAnalyser - .IsMomentumBar( - iBar, - iDir, - 1, // Extends ... - 70 // Body Percent ... - ); - bool isBullishMomentum = - isMomentum && - IsBullish(iDir); - bool isBearishMomentum = - isMomentum && - IsBearish(iDir); - if (isMomentum) - { - // - double iBullMomentumValue = 0; - double iBearMomentumValue = 0; - - // - if (isBullishMomentum) - { - // - double selectedValue = iBar.low; - - // - iBullMomentumValue = selectedValue; - } - - // - if (isBearishMomentum) - { - // - double selectedValue = iBar.high; - - // - iBearMomentumValue = selectedValue; - } - - // - bullishMomentumBuffer[bar_index] = iBullMomentumValue; - bearishMomentumBuffer[bar_index] = iBearMomentumValue; - } - - // - // Rejection Buffers ... - - // - bool isRejection = mXWZBarAnalyser - .IsRejectionBar( - iBar, - iDir, - 1, // Extends ... - 70 // Body Percent ... - ); - bool isBullishRejection = - isRejection && - IsBullish(iDir); - bool isBearishRejection = - isRejection && - IsBearish(iDir); - if (isRejection) - { - // - double iBullRejectionValue = 0; - double iBearRejectionValue = 0; - - // - if (isBullishRejection) - { - // - double selectedValue = iBar.low; - - // - iBullRejectionValue = selectedValue; - } - - // - if (isBearishRejection) - { - // - double selectedValue = iBar.high; - - // - iBearRejectionValue = selectedValue; - } - - // - bullishRejectionBuffer[bar_index] = iBullRejectionValue; - bearishRejectionBuffer[bar_index] = iBearRejectionValue; - } - - // - // Pin Buffers ... - - // - bool isPin = mXWZBarAnalyser - .IsPinBar( - iBar, - iDir, - 0, // Extends ... - 50, // Shadow Percent ... - 25 // Body Percent ... - ); - bool isBullishPin = - isPin && - IsBullish(iDir); - bool isBearishPin = - isPin && - IsBearish(iDir); - if (isPin) - { - // - double iBullPinValue = 0; - double iBearPinValue = 0; - - // - if (isBullishPin) - { - // - double selectedValue = iBar.low; - - // - iBullPinValue = selectedValue; - } - - // - if (isBearishPin) - { - // - double selectedValue = iBar.high; - - // - iBearPinValue = selectedValue; - } - - // - bullishPinBuffer[bar_index] = iBullPinValue; - bearishPinBuffer[bar_index] = iBearPinValue; - } - - // - // Engulf Buffers ... - - // - bool isEngulf = mXWZBarAnalyser - .IsEngulfBar( - iBar, - iDir, - 1, // Extends ... - 70 // Body Percent ... - ); - bool isBullishEngulf = - isEngulf && - IsBullish(iDir); - bool isBearishEngulf = - isEngulf && - IsBearish(iDir); - if (isEngulf) - { - // - double iBullEngulfValue = 0; - double iBearEngulfValue = 0; - - // - if (isBullishEngulf) - { - // - double selectedValue = iBar.low; - - // - iBullEngulfValue = selectedValue; - } - - // - if (isBearishEngulf) - { - // - double selectedValue = iBar.high; - - // - iBearEngulfValue = selectedValue; - } - - // - bullishEngulfBuffer[bar_index] = iBullEngulfValue; - bearishEngulfBuffer[bar_index] = iBearEngulfValue; - } - - // - // Swing Buffers ... - - // - bool isSwing = mXWZBarAnalyser - .IsSwing( - iBar, - iDir, - 2 // Range ... - ); - bool isSwingLow = - isSwing && - IsBullish(iDir); - bool isSwingHigh = - isSwing && - IsBearish(iDir); - if (isSwing) - { - // - double iSwingLowValue = 0; - double iSwingHighValue = 0; - - // - if (isSwingLow) - { - // - double selectedValue = iBar.low; - - // - iSwingLowValue = selectedValue; - } - - // - if (isSwingHigh) - { - // - double selectedValue = iBar.high; - - // - iSwingHighValue = selectedValue; - } - - // - swingLowBuffer[bar_index] = iSwingLowValue; - swingHighBuffer[bar_index] = iSwingHighValue; - } - - // - // Cleanup Resources ... - - // - iBar.Clean(); - pBar.Clean(); -} - -// -// POIS Functions ... - -// -void ConfigurePOIDrawer() -{ - // - if (mXWZPOIDrawer == NULL) - { - return; - } - - // - mXWZPOIDrawer.Prefix(ShortName); - mXWZPOIDrawer.ChartIdentification(ChartID()); - mXWZPOIDrawer.SubWindowIdentification(0); - - // - mXWZPOIDrawer.BullishFVGWidth(2); - mXWZPOIDrawer.BullishFVGStyle(STYLE_DOT); - mXWZPOIDrawer.BullishFVGColor(clrAqua); - - // - mXWZPOIDrawer.BearishFVGWidth(2); - mXWZPOIDrawer.BearishFVGStyle(STYLE_DOT); - mXWZPOIDrawer.BearishFVGColor(clrMagenta); - - // - mXWZPOIDrawer.SupportZoneWidth(1); - mXWZPOIDrawer.SupportZoneStyle(STYLE_DASHDOTDOT); - mXWZPOIDrawer.SupportZoneColor(clrLime); - - // - mXWZPOIDrawer.ResistanceZoneWidth(1); - mXWZPOIDrawer.ResistanceZoneStyle(STYLE_DASHDOTDOT); - mXWZPOIDrawer.ResistanceZoneColor(clrRed); - - // - mXWZPOIDrawer.BullishOrderBlockWidth(3); - mXWZPOIDrawer.BullishOrderBlockStyle(STYLE_DASH); - mXWZPOIDrawer.BullishOrderBlockColor(clrAqua); - - // - mXWZPOIDrawer.BearishOrderBlockWidth(3); - mXWZPOIDrawer.BearishOrderBlockStyle(STYLE_DASH); - mXWZPOIDrawer.BearishOrderBlockColor(clrMagenta); -} - -// -void ConfigureAlert() -{ - // - mXWZAlert.SetPrefix(ShortName); - - // - mXWZAlert.SetPushAlerts(mXWZPushAlerts); - mXWZAlert.SetMailAlerts(mXWZMailAlerts); - mXWZAlert.SetEnableAlerts(mXWZEnableAlerts); - mXWZAlert.SetTerminalAlerts(mXWZTerminalAlerts); -} - -// -void CalculatedPOIs( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - bar_index // - ); - if (!isInited) - { - // - iBar.Clean(); - return; - } - - // - XOHCL pBar; - isInited = iBar.GetPreviousBar(pBar); - if (!isInited) - { - // - iBar.Clean(); - pBar.Clean(); - return; - } - - // - // POI ... - DetectPOIs(iBar); - UpdatePOIs(iBar); - DrawPOIs(); - - // - iBar.Clean(); - pBar.Clean(); -} - -// -bool CanDetectPOIs() -{ - // - bool result = false; - - // - result = - // - mXWZDetectOrderBlocks || - mXWZDetectFairValueGaps || - mXWZDetectSupplyZones || - mXWZDetectDemandZones - // - ; - - // - return result; -} - -// -void DetectPOIs( - XOHCL &bar // -) -{ - // - if (!CanDetectPOIs()) - { - return; - } - - // - int barIndex = bar.Index(); - - // - if (barIndex <= 0) - { - return; - } - - // - DetectOrderBlock(bar); - DetectSupplyZone(bar); - DetectDemandZone(bar); - DetectFairValueGap(bar); - - // -} - -// -void UpdatePOIs( - XOHCL &bar // -) -{ - // - int count = 0; - bool has = false; - - // - // OrderBlock(s) ... - - // - has = HasChild(mXWZUnActivatedOBs); - if (has) - { - // - SpecifiedUpdateTo( - mXWZUnActivatedOBs, - bar.time // - ); - } - - // - // Fair Value Gaps ... - - // - has = HasChild(mXWZUnActivatedFVGs); - if (has) - { - // - SpecifiedUpdateTo( - mXWZUnActivatedFVGs, - bar.time // - ); - - // - count = ArraySize(mXWZUnActivatedFVGs); - } - - // - // Supply Zones ... - - // - has = HasChild(mXWZUnActivatedSupplyZones); - if (has) - { - // - SpecifiedUpdateTo( - mXWZUnActivatedSupplyZones, - bar.time // - ); - - // - count = ArraySize(mXWZUnActivatedSupplyZones); - } - - // - // Demand Zones ... - - // - has = HasChild(mXWZUnActivatedDemandZones); - if (has) - { - // - SpecifiedUpdateTo( - mXWZUnActivatedDemandZones, - bar.time // - ); - - // - count = ArraySize(mXWZUnActivatedDemandZones); - } -} - -// -void DrawPOIs() -{ - // - int count = 0; - bool has = false; - bool isCreated = false; - - // - if (!showPOIs) - { - return; - } - - // - // Order Blocks ... - if (showOrderBlocks) - { - // - bool showBullishOrderBlocks = true; - bool showBearishOrderBlocks = true; - - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - bool isBullish = mXWZUnActivatedOBs[i].IsBullish(); - - // - if ((isBullish && - showBullishOrderBlocks) || - (!isBullish && - showBearishOrderBlocks)) - { - // - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateOrderBlock( - mXWZUnActivatedOBs[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - } - } - - // - // Fair Value Gaps ... - if (showFairValueGaps) - { - // - bool showBullishFairValueGaps = true; - bool showBearishFairValueGaps = true; - - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedFVGs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - bool isBullish = mXWZUnActivatedFVGs[i].IsBullish(); - - // - if ((isBullish && - showBullishFairValueGaps) || - (!isBullish && - showBearishFairValueGaps)) - { - // - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateFairValueGap( - mXWZUnActivatedFVGs[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - } - } - - // - // Supply Zones ... - if (showSupplyZones) - { - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedSupplyZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateSupplyZone( - mXWZUnActivatedSupplyZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - - // - // Activated ... - count = ArraySize(mXWZActivatedSupplyZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - } - } - } - - // - // Demand Zones ... - if (showDemandZones) - { - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedDemandZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateDemandZone( - mXWZUnActivatedDemandZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - - // - // Activated ... - count = ArraySize(mXWZActivatedDemandZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - } - } - } - - // - ChartRedraw(); - - // -} - -// -// -// - -// -// Detect Order Block ... -void DetectOrderBlock(XOHCL &bar) -{ - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (!mXWZDetectOrderBlocks) - { - return; - } - - // - int iBarIndex = bar.Index(orderBlockTF); - - // - XOHCL iBar; - bool isInited = iBar.Init( - bar.symbol, - orderBlockTF, - iBarIndex // - ); - if (!isInited) - { - return; - } - - // - XOHCL zoneBar; - ENUM_X_DIRECTION zoneDir; - has = mXWZBarAnalyser.HasOrderBlock( - iBar, - zoneBar, - zoneDir, - mXWZOBFVGSameBars // - ); - - // - if (!has) - { - // - zoneBar.Clean(); - return; - } - - // - XCOrderBlock *zone; - zone = new XCOrderBlock(); - has = zone.Init( - zoneBar, - zoneDir // - ); - - // - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - // Check Start ... - if (mXWZForceStarteds) - { - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone.IsStarted( - zoneDir, - startedBar, - isBodyOut, - iBar.period // - ); - - // - has = isStarted; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - startedBar.Clean(); - - // - return; - } - - // - startedBar.Clean(); - } - - // - // Check Activation ... - if (mXWZForceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = zone.IsActivated( - zoneDir, - activationBar, - isActivationBarBodyIn, - false, - iBar.period // - ); - - // - has = !isActivated; - if (!has) - { - // - if (!mXWZIgnoreUnActivateds) - { - // - zone.To(activationBar.time); - - // - Add( - zone, - mXWZActivatedOBs // - ); - } - - // - zoneBar.Clean(); - ZeroMemory(zone); - activationBar.Clean(); - - // - return; - } - - // - activationBar.Clean(); - } - - // - // Check Breaktion ... - if (mXWZForceUnBreaked) - { - // - XOHCL breakedBar; - bool isBodyOut = false; - bool isBreaked = zone.IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, - iBar.period // - ); - - // - has = !isBreaked; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - breakedBar.Clean(); - - // - return; - } - - // - breakedBar.Clean(); - } - - // - // Check Indexes ... - - // - // UnActivateds ... - idx = FindIndex( - zone, - mXWZUnActivatedOBs // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - // Activateds ... - idx = FindIndex( - zone, - mXWZActivatedOBs // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - has = zone != NULL && - zone.IsValid(); - if (has) - { - // - zone.To(bar.time); - - // - Add( - zone, - mXWZUnActivatedOBs // - ); - } - - // - iBar.Clean(); - zoneBar.Clean(); -} - -// -// Detect Fair Value Gap ... -void DetectFairValueGap(XOHCL &bar) -{ - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (!mXWZDetectFairValueGaps) - { - return; - } - - // - int iBarIndex = bar.Index(fairValueGapTF); - - // - XOHCL iBar; - bool isInited = iBar.Init( - bar.symbol, - fairValueGapTF, - iBarIndex // - ); - if (!isInited) - { - return; - } - - // - XOHCL zoneEndBar; - XOHCL zoneStartBar; - ENUM_X_DIRECTION zoneDir; - has = mXWZBarAnalyser.HasFairValueGap( - iBar, - zoneStartBar, - zoneEndBar, - zoneDir, - mXWZOBFVGSameBars // - ); - - // - if (!has) - { - // - zoneEndBar.Clean(); - zoneStartBar.Clean(); - return; - } - - // - XCFVG *zone; - zone = new XCFVG(); - has = zone.Init( - zoneStartBar, - zoneEndBar, - zoneDir // - ); - - // - if (!has) - { - // - ZeroMemory(zone); - zoneEndBar.Clean(); - zoneStartBar.Clean(); - - // - return; - } - - // - // Check Start ... - if (mXWZForceStarteds) - { - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone.IsStarted( - zoneDir, - startedBar, - isBodyOut, - iBar.period // - ); - - // - has = isStarted; - if (!has) - { - // - ZeroMemory(zone); - startedBar.Clean(); - zoneEndBar.Clean(); - zoneStartBar.Clean(); - - // - return; - } - - // - startedBar.Clean(); - } - - // - // Check Activation ... - if (mXWZForceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = zone.IsActivated( - zoneDir, - activationBar, - isActivationBarBodyIn, - false, - iBar.period // - ); - - // - has = !isActivated; - if (!has) - { - // - ZeroMemory(zone); - zoneEndBar.Clean(); - zoneStartBar.Clean(); - activationBar.Clean(); - - // - return; - } - - // - activationBar.Clean(); - } - - // - // Check Breaktion ... - if (mXWZForceUnBreaked) - { - // - XOHCL breakedBar; - bool isBodyOut = false; - bool isBreaked = zone.IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, - iBar.period // - ); - - // - has = !isBreaked; - if (!has) - { - // - ZeroMemory(zone); - breakedBar.Clean(); - zoneEndBar.Clean(); - zoneStartBar.Clean(); - - // - return; - } - - // - breakedBar.Clean(); - } - - // - // Check Indexes ... - - // - // UnActivateds ... - idx = FindIndex( - zone, - mXWZUnActivatedFVGs // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - ZeroMemory(zone); - zoneEndBar.Clean(); - zoneStartBar.Clean(); - - // - return; - } - - // - // Activateds ... - idx = FindIndex( - zone, - mXWZActivatedFVGs // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - ZeroMemory(zone); - zoneEndBar.Clean(); - zoneStartBar.Clean(); - - // - return; - } - - // - has = zone != NULL && - zone.IsValid(); - if (has) - { - // - zone.To(bar.time); - - // - Add( - zone, - mXWZUnActivatedFVGs // - ); - } - - // - iBar.Clean(); - zoneEndBar.Clean(); - zoneStartBar.Clean(); -} - -// -// Supply Zone ... -void DetectSupplyZone(XOHCL &bar) -{ - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (!mXWZDetectSupplyZones) - { - return; - } - - // - int iBarIndex = bar.Index(supDemTF); - - // - XOHCL iBar; - bool isInited = iBar.Init( - bar.symbol, - supDemTF, - iBarIndex // - ); - if (!isInited) - { - return; - } - - // - int range = mXWZSuResRange * 2; - - // - XOHCL zoneBar; - ENUM_X_DIRECTION zoneDir = X_DIRECTION_BEARISH; - has = mXWZBarAnalyser.HasResistance( - iBar, - zoneBar, - range // - ); - - // - if (!has) - { - // - zoneBar.Clean(); - return; - } - - // - XCSupplyZone *zone; - zone = new XCSupplyZone(); - has = zone.Init( - zoneBar, - range, - true // - ); - - // - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - // Check Start ... - if (mXWZForceStarteds) - { - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone.IsStarted( - zoneDir, - startedBar, - isBodyOut, - iBar.period // - ); - - // - has = isStarted; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - startedBar.Clean(); - - // - return; - } - - // - startedBar.Clean(); - } - - // - // Check Activation ... - if (mXWZForceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = zone.IsActivated( - zoneDir, - activationBar, - isActivationBarBodyIn, - false, - iBar.period // - ); - - // - has = !isActivated; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - activationBar.Clean(); - - // - return; - } - - // - activationBar.Clean(); - } - - // - // Check Breaktion ... - if (mXWZForceUnBreaked) - { - // - XOHCL breakedBar; - bool isBodyOut = false; - bool isBreaked = zone.IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, - iBar.period // - ); - - // - has = !isBreaked; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - breakedBar.Clean(); - - // - return; - } - - // - breakedBar.Clean(); - } - - // - // Check Indexes ... - - // - // UnActivateds ... - idx = FindIndex( - zone, - mXWZUnActivatedSupplyZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - // Activateds ... - idx = FindIndex( - zone, - mXWZActivatedSupplyZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - has = zone != NULL && - zone.IsValid(); - if (has) - { - // - zone.To(bar.time); - - // - Add( - zone, - mXWZUnActivatedSupplyZones // - ); - } - - // - iBar.Clean(); - zoneBar.Clean(); -} - -// -// Demand Zone ... -void DetectDemandZone(XOHCL &bar) -{ - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (!mXWZDetectDemandZones) - { - return; - } - - // - int iBarIndex = bar.Index(supDemTF); - - // - XOHCL iBar; - bool isInited = iBar.Init( - bar.symbol, - supDemTF, - iBarIndex // - ); - if (!isInited) - { - return; - } - - // - int range = mXWZSuResRange * 2; - - // - XOHCL zoneBar; - ENUM_X_DIRECTION zoneDir = X_DIRECTION_BULLISH; - has = mXWZBarAnalyser.HasSupport( - iBar, - zoneBar, - range // - ); - - // - if (!has) - { - // - zoneBar.Clean(); - return; - } - - // - XCDemandZone *zone; - zone = new XCDemandZone(); - has = zone.Init( - zoneBar, - range, - true // - ); - - // - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - // Check Start ... - if (mXWZForceStarteds) - { - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone.IsStarted( - zoneDir, - startedBar, - isBodyOut, - iBar.period // - ); - - // - has = isStarted; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - startedBar.Clean(); - - // - return; - } - - // - startedBar.Clean(); - } - - // - // Check Activation ... - if (mXWZForceActivation) - { - // - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = zone.IsActivated( - zoneDir, - activationBar, - isActivationBarBodyIn, - false, - iBar.period // - ); - - // - has = !isActivated; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - activationBar.Clean(); - - // - return; - } - - // - activationBar.Clean(); - } - - // - // Check Breaktion ... - if (mXWZForceUnBreaked) - { - // - XOHCL breakedBar; - bool isBodyOut = false; - bool isBreaked = zone.IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, - iBar.period // - ); - - // - has = !isBreaked; - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - breakedBar.Clean(); - - // - return; - } - - // - breakedBar.Clean(); - } - - // - // Check Indexes ... - - // - // UnActivateds ... - idx = FindIndex( - zone, - mXWZUnActivatedDemandZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - // Activateds ... - idx = FindIndex( - zone, - mXWZActivatedDemandZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - zoneBar.Clean(); - ZeroMemory(zone); - - // - return; - } - - // - has = zone != NULL && - zone.IsValid(); - if (has) - { - // - zone.To(bar.time); - - // - Add( - zone, - mXWZUnActivatedDemandZones // - ); - } - - // - iBar.Clean(); - zoneBar.Clean(); -} - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.xohcl.lib.mq5 b/Documents/BKP/x-saherelm.xohcl.lib.mq5 deleted file mode 100644 index 03a6d0b2..00000000 --- a/Documents/BKP/x-saherelm.xohcl.lib.mq5 +++ /dev/null @@ -1,1352 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Common Library -// -------------------------------------- -// Name: XOHCLLib -// Description: provide all commonly used functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Describe an Specific Candle ... -struct XOHCL -{ - // - // Props ... - - // - double high; - double open; - double close; - double low; - - // - string symbol; - datetime time; - ENUM_TIMEFRAMES period; - - // - // Constructor ... - XOHCL() - { - Clean(); - } - - // - // Init a Bar ... - // Using Bar Index ... - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - int barIndex = 0 // Bar Index - ) - { - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - symbol = mSymbol; - period = mPeriod; - - // - time = iTime( - mSymbol, - mPeriod, - barIndex // - ); - - // - open = iOpen( - mSymbol, - mPeriod, - barIndex // - ); - open = NormalizePrice(open, mSymbol); - - // - close = iClose( - mSymbol, - mPeriod, - barIndex // - ); - close = NormalizePrice(close, mSymbol); - - // - high = iHigh( - mSymbol, - mPeriod, - barIndex // - ); - high = NormalizePrice(high, mSymbol); - - // - low = iLow( - mSymbol, - mPeriod, - barIndex // - ); - low = NormalizePrice(low, mSymbol); - - // - bool result = IsValid(); - - // - return result; - } - - // - // Init a Bar ... - // Using Bar Time ... - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - datetime mTime = NULL // Bar Time - ) - { - // - mTime = NormalizeTime(mTime); - - // - int barIndex = iBarShift( - mSymbol, - mPeriod, - mTime, - false // - ); - - // - bool result = Init( - mSymbol, - mPeriod, - barIndex - // - ); - - // - return result; - } - - // - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - double mOpen = 0, // Open - double mHigh = 0, // High - double mClose = 0, // Close - double mLow = 0, // Low - int barIndex = 0 // Bar Index - ) - { - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - symbol = mSymbol; - period = mPeriod; - - // - time = iTime( - mSymbol, - mPeriod, - barIndex - // - ); - - // - open = mOpen; - high = mHigh; - close = mClose; - low = mLow; - - // - return IsValid(); - } - - // - bool Init( - string mSymbol = NULL, // Trading Symbol - ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period - double mOpen = 0, // Open - double mHigh = 0, // High - double mClose = 0, // Close - double mLow = 0, // Low - datetime mTime = NULL // Bar Time - ) - { - // - mSymbol = NormalizeSymbol(mSymbol); - mPeriod = NormalizePeriod(mPeriod); - - // - symbol = mSymbol; - period = mPeriod; - - // - int barIndex = iBarShift( - symbol, - period, - mTime); - - // - time = iTime( - mSymbol, - mPeriod, - barIndex - // - ); - - // - open = mOpen; - high = mHigh; - close = mClose; - low = mLow; - - // - return IsValid(); - } - - // - // Tools ... - - // - void Clean() - { - // - high = 0; - open = 0; - close = 0; - low = 0; - - // - time = NULL; - symbol = NULL; - period = NULL; - - // - ZeroMemory(this); - } - - // - // Validate Bar ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - high > 0 && - open > 0 && - close > 0 && - low > 0 - // - ; - - // - return result; - } - - // - int TotalBars() - { - // - int result = 0; - - // - result = iBars( - symbol, - period // - ); - - // - return result; - } - - // - // Calculate X_PRICE Specified Type ... - double GetPrice(ENUM_X_PRICE mPType) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - switch (mPType) - { - // - case X_PRICE_OPEN: - result = open; - break; - // - case X_PRICE_HIGH: - result = high; - break; - // - case X_PRICE_CLOSE: - result = close; - break; - // - case X_PRICE_LOW: - result = low; - break; - // - case X_PRICE_UP: - result = GetUp(); - break; - // - case X_PRICE_DOWN: - result = GetDown(); - break; - } - // case PRICE_MEDIAN: - // return ((high[i] + low[i]) / 2.0); - // case PRICE_TYPICAL: - // return ((high[i] + low[i] + close[i]) / 3.0); - // case PRICE_WEIGHTED: - // return ((high[i] + low[i] + close[i] + close[i]) / 4.0); - - // - return result; - } - - // - // Retrieve Price base On Series Mode ... - double GetPrice(ENUM_SERIESMODE mMode) - { - // - ENUM_X_PRICE mXMode = ToPrice(mMode); - - // - return GetPrice(mXMode); - } - - // - // Calculate Applied Price ... - double GetPrice( - ENUM_APPLIED_PRICE mAppliedTo // Select Application Method - ) - { - // - double result = 0; - - // - // Calculate Applied Price ... - switch (mAppliedTo) - { - // - case PRICE_CLOSE: - result = close; - break; - - // - case PRICE_OPEN: - result = open; - break; - - // - case PRICE_HIGH: - result = high; - break; - - // - case PRICE_LOW: - result = low; - break; - - // - case PRICE_MEDIAN: - result = (high + low) / 2; - break; - - // - case PRICE_TYPICAL: - result = (high + low + close) / 3; - break; - - // - case PRICE_WEIGHTED: - result = (high + low + close + close) / 4; - break; - } - - // - return result; - } - - // - // Find Specific Price ... - bool FindHigherPriceBar( - XOHCL &bar, - double price, - ENUM_X_PRICE _type = X_PRICE_HIGH // - ) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = TotalBars(); - result = IsValidSize(totalBars); - if (!result) - { - return result; - } - - // - int start = Index(); - int maxAllowedLoopback = totalBars / 5; - for (int i = start; i < maxAllowedLoopback; i++) - { - // - result = bar.Init( - symbol, - period, - i // - ); - - // - if (!result) - { - break; - } - - // - double iPrice = bar.GetPrice(_type); - - // - result = - // - iPrice > 0 && - iPrice > price - // - ; - if (result) - { - break; - } - } - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - // Find Specific Price ... - bool FindLowerPriceBar( - XOHCL &bar, - double price, - ENUM_X_PRICE _type = X_PRICE_HIGH // - ) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int totalBars = TotalBars(); - result = IsValidSize(totalBars); - if (!result) - { - return result; - } - - // - int start = Index(); - int maxAllowedLoopback = totalBars / 5; - for (int i = start; i < maxAllowedLoopback; i++) - { - // - result = bar.Init( - symbol, - period, - i // - ); - - // - if (!result) - { - break; - } - - // - double iPrice = bar.GetPrice(_type); - - // - result = - // - iPrice > 0 && - iPrice < price - // - ; - if (result) - { - break; - } - } - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - // Calculate Bar Mid Line ... - double GetMid() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = (high + low) / 2; - - // - return result; - } - - // - // Calculate up Price ... - double GetUp() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = MathMax(open, close); - - // - return result; - } - - // - // Calculate Down Price ... - double GetDown() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = MathMin(open, close); - - // - return result; - } - - // - // Retrieve Required Price for Zone Checking ... - // For Bullish Zones => low; - // For Bearish Zones => high; - double GetZoneCheckValue(ENUM_X_DIRECTION forDir) - { - // - double result = 0; - - // - if (!IsValid() || - !HasDirection(forDir)) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - result = - isBullish - ? low - : high; - - return result; - } - - // - // Calculate Bar Body ... - double GetBody() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = GetUp() - GetDown(); - - // - return result; - } - - // - // Calculate Bar Range ... - double GetRange() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = high - low; - - // - return result; - } - - // - // Calculate Bar Shadows ... - double GetShadows() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = GetRange() - GetBody(); - - // - return result; - } - - // - // Calculate Bar High Shadow ... - double GetHighShadow() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = - // - high - GetUp() - // - ; - - // - return result; - } - - // - // Calculate Bar Low Shadow ... - double GetLowShadow() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = - // - GetDown() - low; - // - ; - - // - return result; - } - - // - // Check Bar is Bullish ... - bool IsBullish() - { - // - bool result = false; - - // - if (!IsValid()) - { - return result; - } - - // - result = open < close; - - // - return result; - } - - // - // Check Bar is Bearish ... - bool IsBearish() - { - // - bool result = false; - - // - if (!IsValid()) - { - return result; - } - - // - result = open > close; - - // - return result; - } - - // - // Get Direction of Bar ... - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool isBullish = IsBullish(); - bool isBearish = IsBearish(); - - // - result = - isBullish && isBearish - ? X_DIRECTION_ALL - : !isBullish && !isBearish - ? X_DIRECTION_NONE - : isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - // Find Next Bar Time ... - datetime NextAt() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int prSeconds = PeriodSeconds(period); - - // - result = time + prSeconds; - - // - return result; - } - - // - // Find Prev Bar Time ... - datetime BeforeOn() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int prSeconds = PeriodSeconds(period); - - // - result = time - prSeconds; - - // - return result; - } - - // - // Calculate Last Bar Open Time in Smaller Period ... - datetime GetLastBarTimeOfPeriod( - ENUM_TIMEFRAMES smallerPeriod // - ) - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int sourceSeconds = PeriodSeconds(period); - int destSeconds = PeriodSeconds(smallerPeriod); - if (destSeconds >= sourceSeconds) - { - // - result = time; - return result; - } - - // - result = (datetime)((((int)time) + sourceSeconds) - destSeconds); - - // - return result; - } - - // - // Calculate Close Time ... - datetime GetCloseTime() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - int seconds = PeriodSeconds(period); - - // - result = (datetime)(((int)time) + seconds); - - // - return result; - } - - // - bool BarAt( - int index, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - if (index < 0) - { - index = 0; - } - - // - result = bar.Init( - symbol, - period, - index // - ); - - // - return result; - } - - // - bool BarIn( - ENUM_TIMEFRAMES _period, - XOHCL &bar // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - result = IsValid() && - IsSpecifiedValid(_period); - if (!result) - { - return result; - } - - // - int index = Index(_period); - result = bar.Init( - symbol, - _period, - index // - ); - - // - return result; - } - - // - // Find Current Bar Index on Chart ... - int Index() - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - result = iBarShift( - symbol, - period, - time - // - ); - - // - return result; - } - - // - int Index(datetime value) - { - // - int result = -1; - - // - value = NormalizeTime(value); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = iBarShift( - symbol, - period, - value // - ); - - // - return result; - } - - // - int Index(ENUM_TIMEFRAMES value) - { - // - int result = -1; - - // - result = IsValid() && - IsSpecifiedValid(value); - if (!result) - { - return result; - } - - // - result = iBarShift( - symbol, - value, - time // - ); - - // - return result; - } - - // - bool GetNextBar(XOHCL &bar) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = Index(); - result = idx > 0; - if (!result) - { - return result; - } - - // - result = bar.Init( - this.symbol, - this.period, - idx - 1 // - ); - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - bool GetPreviousBar(XOHCL &bar) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = Index(); - - // - result = bar.Init( - this.symbol, - this.period, - idx + 1 // - ); - - // - if (!result) - { - bar.Clean(); - } - - // - return result; - } - - // - // Find Highest Bar Index ... - int FindHighestIndex( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (mLength < 2) - { - mLength = 2; - } - - // - result = iHighest( - symbol, - period, - mMode, - mLength, - Index()); - - // - return result; - } - - // - // Find Highest ... - double FindHighest( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - int idx = FindHighestIndex( - mLength, - mMode); - if (idx <= -1) - { - return result; - } - - // - XOHCL iH; - result = iH.Init( - symbol, - period, - idx - // - ); - if (!result) - { - return result; - } - - // - result = iH.GetPrice(mMode); - - // - return result; - } - - // - // Find Highest ... - double FindHighestUp( - int mLength // Loopback ... - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = FindHighest(mLength, MODE_OPEN); - result = MathMax(mLength, FindHighest(mLength, MODE_CLOSE)); - - // - return result; - } - - // - // Find Lowest Bar Index ... - int FindLowestIndex( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (mLength < 2) - { - mLength = 2; - } - - // - result = iLowest( - symbol, - period, - mMode, - mLength, - Index()); - - // - return result; - } - - // - // Find Lowest ... - double FindLowest( - int mLength, // Loopback ... - ENUM_SERIESMODE mMode // Calculation mode - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - int idx = FindLowestIndex( - mLength, - mMode); - if (idx <= -1) - { - return result; - } - - // - XOHCL iL; - result = iL.Init( - symbol, - period, - idx - // - ); - if (!result) - { - return result; - } - - // - result = iL.GetPrice(mMode); - - // - return result; - } - - // - // Find Lowest ... - double FindLowesttDown( - int mLength // Loopback ... - ) - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = FindLowest(mLength, MODE_OPEN); - result = MathMax(mLength, FindLowest(mLength, MODE_CLOSE)); - - // - return result; - } - - // - // Other ... - string GetTag(string prefix = "") - { - // - string result = NULL; - - // - result = - (IsValid(prefix) - ? prefix + "_" - : "") + - "XOHCL_" + symbol + "_" + ToString(period) + "_" + ToFormatString(time); - - // - return result; - } - - // - // Convert to String Representation ... - string ToString() - { - // - string result = ""; - - // - result = GetTypeName(this) + - "(O(" + ToString(open) + "),H(" + ToString(high) + "),C(" + ToString(close) + "),L(" + ToString(low) + "))"; - - // - return result; - } -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.xpoi.test.ea.mq5 b/Documents/BKP/x-saherelm.xpoi.test.ea.mq5 deleted file mode 100644 index 5da7f3dd..00000000 --- a/Documents/BKP/x-saherelm.xpoi.test.ea.mq5 +++ /dev/null @@ -1,377 +0,0 @@ -//+------------------------------------------------------------------+ -//| x-saherelm.xpoi.test.ea.mq5 | -//| SaherElm IT Center | -//| https://www.saherelm.ir | -//+------------------------------------------------------------------+ -#property copyright "SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" - -// -#include "../Classes/x-saherelm.x-poi.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" -#include "../Libraries/x-saherelm.x-poi.state.lib.mq5" - -// -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" - -// -// Global Variables ... - -// -XCPOIDrawer *mPOIDrawer; - -// -XCPOIDetector *mPOIDetector; -XBarTracker mBarTracker; -XCBarAnalyser *mBarAnalyser; - -// -bool useDetector = true; -bool useBarAnalyser = false; - -//+------------------------------------------------------------------+ -//| Expert initialization function | -//+------------------------------------------------------------------+ -int OnInit() -{ - // - mPOIDetector = new XCPOIDetector( - _Symbol, - _Period // - ); - - // - mPOIDrawer = new XCPOIDrawer(); - - // - mBarAnalyser = new XCBarAnalyser(); - - // - mBarTracker.Init( - _Symbol, - _Period // - ); - - // - return (INIT_SUCCEEDED); -} - -//+------------------------------------------------------------------+ -//| Expert deinitialization function | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) -{ - // - // ZeroMemory(mPOIDrawer); - // ZeroMemory(mPOIDetector); - ZeroMemory(mBarAnalyser); -} - -//+------------------------------------------------------------------+ -//| Expert tick function | -//+------------------------------------------------------------------+ -void OnTick() -{ - // - DetectBarAnalyser(); - - // - DetectPOIState(); -} - -//+------------------------------------------------------------------+ -//| Custom Functions | -//+------------------------------------------------------------------+ - -/** - * Detect POI(s) Using Bar Analyser Class ... - */ -void DetectBarAnalyser() -{ - // - if (!useBarAnalyser) - { - return; - } - - // - if (!mBarTracker.IsNewBar()) - { - return; - } - - // - XOHCL zBar; - bool isInited = zBar.Init( - _Symbol, - _Period, - 0 // - ); - if (!isInited) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - isInited = zBar.GetPreviousBar(cBar); - if (!isInited) - { - // - zBar.Clean(); - cBar.Clean(); - return; - } - - // - int rootIDX = -1; - XOHCL selectedBar; - ENUM_X_DIRECTION dir; - - // - // Check Big Change in Price ... - bool isBigChange = mBarAnalyser.IsSharp( - zBar, // Bar ... - dir, // Change Direction ... - rootIDX, // Change Root IDX ... - X_PRICE_CLOSE, // Price Change Type ... - true, // Force Use Body for Range Calculation ... - 1.0 // Range Extend Multiplier ... - ); - if (isBigChange) - { - Print("Big Price Change Detected: ", ToString(dir)); - } - - // - // Check Big Change in Price ... - bool isSpike = mBarAnalyser.IsSpike( - zBar, // Bar ... - dir, // Change Direction ... - rootIDX, // Root Index ... - X_PRICE_CLOSE, // Price Change Type ... - true, // Force Use Body for Range Calculation ... - 1.0, // Range Extend Multiplier ... - 3 // Same Bars ... - ); - if (isSpike) - { - Print("Spike Detected: ", ToString(dir)); - } - - // - // Check Doji Pattern ... - bool isDoji = mBarAnalyser.IsDoji( - cBar, - dir // - ); - if (isDoji) - { - Print(ToString(dir), " Doji Detected ..."); - } - - // - // Check Hammer Pattern ... - bool isHammer = mBarAnalyser.IsHammer( - cBar, - dir // - ); - if (isHammer) - { - Print(ToString(dir), " Hammer Detected ..."); - } - - // - // Check Engulf Pattern ... - bool isEngulfed = mBarAnalyser.IsEngulfed( - cBar, - dir // - ); - if (isEngulfed) - { - Print(ToString(dir), " Engulfed Detected ..."); - } - - // - // Check Momentum Pattern ... - bool isMomentum = mBarAnalyser.IsMomentum( - cBar, - dir // - ); - if (isMomentum) - { - Print(ToString(dir), " Momentum Detected ..."); - } - - // - // Check Pullback Pattern ... - bool isPullback = mBarAnalyser.IsPullback( - cBar, - dir // - ); - if (isMomentum) - { - Print(ToString(dir), " Pullback Detected ..."); - } - - // - // Check Swing Pattern ... - bool isSwing = mBarAnalyser.IsSwing( - cBar, - dir // - ); - if (isSwing) - { - Print(ToString(dir), " Swing Detected ..."); - } - - // - // Check Swing Pattern ... - bool isRejected = mBarAnalyser.IsRejected( - cBar, - dir // - ); - if (isRejected) - { - Print(ToString(dir), " Rejected Detected ..."); - } - - // - // Check Support ... - bool isSupport = mBarAnalyser.HasSupport( - cBar, - selectedBar // - ); - if (isSupport) - { - Print(ToString(dir), " Support Detected ..."); - } - - // - // Check Resistance ... - bool isResistance = mBarAnalyser.HasResistance( - cBar, - selectedBar // - ); - if (isResistance) - { - Print(ToString(dir), " Resistance Detected ..."); - } - - // - // Check Fair Value Gap ... - XOHCL toBar; - XOHCL fromBar; - bool hasFVG = mBarAnalyser.HasFairValueGap( - zBar, - fromBar, - toBar, - dir, - 3 // - ); - if (hasFVG) - { - Print(ToString(dir), " FairValueGap Detected ..."); - } - - // - // Check Order Block ... - bool hasOB = mBarAnalyser.HasOrderBlock( - zBar, - selectedBar, - dir, - true, - true, - true // - ); - if (hasOB) - { - Print(ToString(dir), " OrderBlock Detected ..."); - } - - // - // Cleanup Resources ... - - // - zBar.Clean(); - cBar.Clean(); -} - -/** - * Detect POI(s) Using POIDetector Class ... - */ -void DetectPOIState() -{ - // - if (!useDetector) - { - return; - } - - // - if (!mBarTracker.IsNewBar()) - { - return; - } - - // - ENUM_XPOI_EVENTS poiEvents[]; - XPOIStateEvents poiEventNotifier; - mPOIDetector.Update( - poiEvents, - 0 // - ); - poiEventNotifier.Init(poiEvents); - - // - XPOIState state; - mPOIDetector.GetState(state); - - // - bool showBullishPOIs = true; - bool showBearishPOIs = true; - - // - XCBaseObject *stateObjects[]; - mPOIDrawer.DrawState( - state, - stateObjects, - // - // Bullish ... - showBullishPOIs && false, // SwingLows - showBullishPOIs && false, // DemandZones - showBullishPOIs && false, // SupportZones - showBullishPOIs && false, // BullishSharps - showBullishPOIs && false, // BullishSpikes - showBullishPOIs && false, // BullishPullbacks - showBullishPOIs && false, // BullishMomentums - showBullishPOIs && false, // BullishRejections - showBullishPOIs && false, // BullishOrderBlocks - showBullishPOIs && false, // BullishFairValueGaps - showBullishPOIs && false, // BullishConsolidationZones - // - // Bearish ... - showBearishPOIs && false, // SwingHighs - showBearishPOIs && false, // SupplyZones - showBearishPOIs && false, // ResistanceZones - showBearishPOIs && false, // BearishSharps - showBearishPOIs && false, // BearishSpikes - showBearishPOIs && false, // BearishPullbacks - showBearishPOIs && false, // BearishMomentums - showBearishPOIs && false, // BearishRejections - showBearishPOIs && false, // BearishOrderBlocks - showBearishPOIs && false, // BearishFairValueGaps - showBearishPOIs && false // BearishConsolidationZones - ); - - // - Clean(poiEvents); - poiEventNotifier.Clean(); -} - -// -//+------------------------------------------------------------------+ diff --git a/Documents/BKP/x-tmp.structs.mq5 b/Documents/BKP/x-tmp.structs.mq5 deleted file mode 100644 index f5caf9b5..00000000 --- a/Documents/BKP/x-tmp.structs.mq5 +++ /dev/null @@ -1,2508 +0,0 @@ -// -// Structs ... - -// -// Model Specified Ticks Info ... -struct XTick -{ - // - string symbol; // Symbol ... - datetime time; // Time ... - double bid; // Bid ... - double ask; // Ask ... - double spread; // Spread ... - long volume; // Volume ... - - // - // Constructor ... - void XTick() - { - Clean(); - } - - // - // Tools Functions ... - - /** - * Initial ... - * - * @param _symbol: Symbol ... - * @param _time: Time ... - * @param _bid: Bid Price ... - * @param _ask: Ask Price ... - * @param _volume: Tick Volume ... - */ - bool Init( - string _symbol, - datetime _time, - double _bid, - double _ask, - double _spread, - long _volume // - ) - { - // - bool result = false; - - // - result = IsValid(_symbol) && - IsValid(_time) && - _bid > 0 && - _ask > 0; - if (!result) - { - return result; - } - - // - bid = _bid; - ask = _ask; - time = _time; - symbol = _symbol; - spread = _spread; - - // - result = IsValid(); - - // - return result; - } - - /** - * Init Tick by Symbol ... - * - * @param _symbol: String ... - * - * @return ( bool ) - */ - bool Init( - string _symbol, - ENUM_TIMEFRAMES _volumePeriod = NULL // - ) - { - // - bool result = false; - - // - result = IsValid(_symbol); - if (!result) - { - return result; - } - - // - datetime _time = TimeCurrent(); - double _bid = GetBid(_symbol); - double _ask = GetAsk(_symbol); - double _spread = GetSpread(_symbol); - - // - long _volume = 0; - if (IsValid(_volumePeriod)) - { - _volume = iTickVolume(_symbol, _volumePeriod, 0); - } - - // - result = Init( - _symbol, - _time, - _bid, - _ask, - _spread, - _volume // - ); - - // - return result; - } - - /** - * Cleanup ... - */ - void Clean() - { - // - bid = 0; - ask = 0; - volume = 0; - time = NULL; - symbol = NULL; - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = IsValid(symbol) && - IsValid(time) && - bid > 0 && - ask > 0 && - volume >= 0; - - // - return result; - } - - // -}; - -// -// Model a Market Cycle ... -struct XMarketCycle -{ - // - // Props ... - - // - string prefix; // Prefix Trag ... - - // - string symbol; // Market Symbol ... - - // - ENUM_TIMEFRAMES period; // Period of Cycle ... - ENUM_X_PERIOD_METHOD method; // Period Selection Method ... - ENUM_X_MARKET_CYCLES cycle; // Cycles of MArket ... - - // - int length; // Number Of Candles per Current Time Frame ... - ENUM_TIMEFRAMES hostPeriod; // Current Time Frame ... - - // - datetime lastStart; // Last Candle Bar Time ... - - // - XBarTracker barTracker; // Bar Tracker ... - XBarRemainsTime remains; // Current Bar Remains Model ... - - // - // Constructor ... - XMarketCycle() - { - Clean(); - } - - // - // Init Cycle ... - bool Init( - string mSymbol, // Trading Symbol - ENUM_TIMEFRAMES mHostPeriod, // Host Period - ENUM_X_MARKET_CYCLES mCycle, // Init Cycle - string mPrefix = "" // Prefix - ) - { - // - bool result = false; - - // - mSymbol = NormalizeSymbol(mSymbol); - mHostPeriod = NormalizePeriod(mHostPeriod); - - // - result = IsValid(mCycle); - if (!result) - { - return result; - } - - // - this.cycle = mCycle; - - // - // Set Automatically Prefix ... - if (StringLen(mPrefix) == 0) - { - this.prefix = ToString(cycle); - } - - // - result = IsValid( - method, - period // - ); - if (!result) - { - return result; - } - - // - this.symbol = mSymbol; - this.hostPeriod = mHostPeriod; - - // - // Find Cycle Period ... - if (method == X_PERIOD_AUTO) - { - // - // Select Period ... - this.period = GetCyclePeriod( - this.cycle, - this.hostPeriod); - } - - // - // Set Prefix if Provided ... - if (StringLen(mPrefix) > 0) - { - this.prefix = mPrefix; - } - - // - // Calculate Required Info ... - - // - // Length ... - this.length = PeriodSeconds(this.period) / PeriodSeconds(this.hostPeriod); - - // - // Update Additional Data ... - result = this.Update(0); - - // - return result; - } - - // - bool Init( - string mSymbol, // Trading Symbol - ENUM_TIMEFRAMES mHostPeriod, // Host Period - ENUM_X_MARKET_CYCLES mCycle, // Init Cycle - ENUM_X_PERIOD_METHOD mMethod, // Period Selection Method - ENUM_TIMEFRAMES mPeriod, // Provided Period - string mPrefix = "" // Prefix - ) - { - // - this.period = mPeriod; - this.method = mMethod; - - // - return Init( - mSymbol, - mHostPeriod, - mCycle, - mPrefix - // - ); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - length = 0; - lastStart = 0; - - // - cycle = NULL; - prefix = NULL; - symbol = NULL; - period = NULL; - method = NULL; - hostPeriod = NULL; - - // - remains.Clean(); - barTracker.Clean(); - - // - ZeroMemory(this); - } - - // - // Check Structure Valid ... - bool IsValid() - { - // - bool result = false; - - // - result = IsValid( - method, - period); - if (!result) - { - return result; - } - - // - result = - // - length > 0 && - symbol != NULL && - period != NULL && - method != NULL && - hostPeriod != NULL && - method != X_PERIOD_NONE - // - ; - - // - return result; - } - - // - // Update Market Cycle Additional Info ... - bool Update(int hostBarIndex) - { - // - bool result = false; - - // - result = this.IsValid(); - if (!result) - { - return result; - } - - // - // Init Remains ... - result = remains.Init( - this.symbol, - this.period); - if (!result) - { - return result; - } - - // - // Init Bar Tracker ... - result = barTracker.Init( - this.symbol, - this.period); - if (!result) - { - return result; - } - - // - return result; - } - - // - // Count Bars ... - int CountBars() - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = barTracker.CountBars(); - - // - return result; - } - - // - // Check New Bar ... - bool IsNewBar() - { - // - bool result = false; - - // - if (!IsValid()) - { - return result; - } - - // - result = barTracker.IsNewBar(); - - // - return result; - } - - // - // Retrieve Current Bar Index based on Host Period bar Index ... - int GetBarIndex(int barIndex) - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - if (barIndex < 0) - { - return result; - } - - // - int totalBars = CountBars(); - if (barIndex >= totalBars) - { - // - result = totalBars - 1; - return result; - } - - // - datetime hostBarTime = iTime( - this.symbol, - this.hostPeriod, - barIndex - // - ); - - // - result = iBarShift( - this.symbol, - this.period, - hostBarTime - // - ); - - // - return result; - } - - // - // Retrieve Current Cycles Specific Bar ... - XOHCL GetBar(int barIndex) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int totalBars = CountBars(); - if (barIndex >= totalBars) - { - barIndex = totalBars - 1; - } - - // - XOHCL result; - result.Init( - this.symbol, - this.period, - barIndex - // - ); - - // - return result; - } - - // - // Extract Specific Range of Bars ... - // using Start Bar Index ... - int GetBars( - XOHCL &result[], // Hold Result - int from = 0, // Start Bar Index - int count = 1, // Number of Bars - bool forceClean = true // Clean Result Array - ) - { - // - int mResult = 0; - - // - if (from < 0) - { - from = 0; - } - - // - int total = Bars( - symbol, - period); - if (from > total - 2) - { - from = total - 2; - } - - // - if (count < 0) - { - count = 1; - } - - // - int start = from; - int end = start + count; - if (end > total - 1) - { - end = total - 1; - } - - // - if (forceClean) - { - Clean(result); - } - - // - int beforeSize = ArraySize(result); - - // - for (int i = start; i < end; i++) - { - // - XOHCL iBar; - bool isValid = iBar.Init( - symbol, - period, - i - // - ); - - // - if (isValid) - { - // - AddRef( - iBar, - result - // - ); - } - } - - // - int afterSize = ArraySize(result); - - // - mResult = afterSize - beforeSize; - - // - return mResult; - } - - // - // Extract Specific Range of Bars ... - // using Start Bar Time ... - int GetBars( - XOHCL &bars[], // Hold Result - datetime from = NULL, // Start Bar Time - int count = 1 // Number of Bars - ) - { - // - from = NormalizeTime(from); - - // - return GetBars( - bars, - symbol, - period, - from, - count // - ); - } - - // - // Retrieve Bar Time ... - datetime GetBarTime(int barIndex) - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int totalBars = CountBars(); - if (barIndex >= totalBars) - { - barIndex = totalBars - 1; - } - - // - result = iTime( - this.symbol, - this.period, - barIndex - // - ); - - // - return result; - } - - // - // Find Chart ID ... - ulong GetChartID() - { - // - ulong result = 0; - - // - long firstChart = ChartFirst(); - result = firstChart; - - // - while (result >= 0) - { - // - string chSymbol = ChartSymbol(result); - ENUM_TIMEFRAMES chPeriod = ChartPeriod(result); - - // - bool isOwnChart = - // - symbol == chSymbol && - period == chPeriod - // - ; - if (isOwnChart) - { - break; - } - - // - result = ChartNext(result); - if (result < 0) - { - break; - } - } - - // - return result; - } - - // - // Create and String Representation for Unique Taging ... - string ToString() - { - // - string result = ""; - - // - if (!IsValid()) - { - return result; - } - - // - result = - GetTypeName(this) + "(" + - "PRFX(" + this.prefix + ")" + - "SMBL(" + this.symbol + ")" + - "CYC(" + ToString(this.cycle) + ")" + - "PRD(" + ToString(this.period) + ")" + - "PRDHST(" + ToString(this.hostPeriod) + ")" + - "MTH(" + EnumToString(this.method) + ")" + - ")"; - - // - return result; - } - - // - // Here we Produce a Summary brief of - // state of Cycle ... - string GenerateSummary() - { - // - string result = ""; - - // - bool hasPrefix = - StringLen(this.prefix) > 0 && - this.prefix != ToString(this.cycle); - result += (hasPrefix ? this.prefix + "[" : "") + - ToString(this.cycle) + - (hasPrefix ? "]" : "") + "\n"; - - // - result += " - PR: " + ToString(this.period) + "\n"; - - // - XOHCL cBar = GetBar(0); - - // - result += " - State: " + (cBar.IsBullish() ? "Bullish" : cBar.IsBearish() ? "Bearish" - : "Neutural"); - - // - return result; - } -}; - -// -// Linear Regression ... - -// -struct XLinearRegressionWorkStruct -{ - // - struct sDataStruct - { - // - double value; - double sumY; - double sumXY; - }; - - // - sDataStruct data[]; - - // - int dataSize; - int period; - double sumX; - double sumXX; - double divisor; - - // - // Constructor ... - XLinearRegressionWorkStruct() - : dataSize(-1), period(-1) - { - } -}; - -// -struct XLinearRegression -{ - // - XLinearRegressionWorkStruct m_work; - - // - // Calculate Linear Regression ... - double Calculate( - double value, - int period, - double &_slope, - double &_intercept, - int r, - int bars // - ) - { - // - if (m_work.dataSize <= bars) - { - m_work.dataSize = ArrayResize(m_work.data, bars + 500, 2000); - } - - // - if (period < 1) - { - period = 1; - } - - // - if (m_work.period != (int)period) - { - // - m_work.period = (int)period; - m_work.sumX = m_work.period * (m_work.period - 1.0) / 2.0; - m_work.sumXX = m_work.period * (m_work.period - 1.0) * (2.0 * m_work.period - 1.0) / 6.0; - m_work.divisor = m_work.sumX * m_work.sumX - m_work.period * m_work.sumXX; - - // - if (m_work.divisor) - { - m_work.divisor = 1.0 / m_work.divisor; - } - } - - // - m_work.data[r].value = value; - - // - if (r >= m_work.period) - { - // - m_work.data[r].sumY = m_work.data[r - 1].sumY + value - m_work.data[r - m_work.period].value; - m_work.data[r].sumXY = m_work.data[r - 1].sumXY + m_work.data[r].sumY - m_work.data[r - m_work.period].value * (m_work.period - 1.0) - value; - } - else - { - // - m_work.data[r].sumY = value; - m_work.data[r].sumXY = 0; - - // - for (int _k = 1; _k < m_work.period && r >= _k; _k++) - { - // - m_work.data[r].sumY += m_work.data[r - _k].value; - m_work.data[r].sumXY += _k * m_work.data[r - _k].value; - } - } - - // - _slope = (m_work.period * m_work.data[r].sumXY - m_work.sumX * m_work.data[r].sumY) * m_work.divisor; - _intercept = (m_work.data[r].sumY - _slope * m_work.sumX) / (double)m_work.period; - - // - double result = (_intercept + _slope * (m_work.period - 1.0)); - - // - return result; - } - - // -}; - -// -// Use To Parse Symbols for -// Ignore Brokers Additional Suffixes ... -struct XSymbolParser -{ - // - string version; // Temp ... - - // - // Symbol Parsing ... - - // - // Forext ... - - // - bool IsEURUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsUSDJPY(string symbol) - { - // - string symbolIdentifiers[] = { - "USD", - "JPY" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURJPY(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "JPY" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsUSDCHF(string symbol) - { - // - string symbolIdentifiers[] = { - "USD", - "CHF" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURCHF(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "CHF" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsGBPUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "GBP", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURGBP(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "GBP" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsAUDUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "AUD", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURAUD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "AUD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsUSDCAD(string symbol) - { - // - string symbolIdentifiers[] = { - "USD", - "CAD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURCAD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "CAD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsNZDUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "NZD", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsEURNZD(string symbol) - { - // - string symbolIdentifiers[] = { - "EUR", - "NZD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - // Metals ... - - // - bool IsXAUUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "XAU", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - bool IsXAGUSD(string symbol) - { - // - string symbolIdentifiers[] = { - "XAG", - "USD" // - }; - - // - bool result = Contains( - symbolIdentifiers, - symbol // - ); - - // - return result; - } - - // - // Indexes ... - - // - bool IsDowJones(string symbol) - { - // - bool result = Contains( - "DowJones30", - symbol // - ); - - // - return result; - } - - // - // Oil ... - - // - bool IsBrent(string symbol) - { - // - bool result = Contains( - "BRENT", - symbol // - ); - - // - return result; - } - - // - // Symbol Finder ... - string GetEURUSDSymbol() - { - // - string result = NULL; - - // - string symbols[]; - int symbolsCount = GetAllSymbols( - symbols // - ); - if (!IsValidSize(symbolsCount)) - { - return result; - } - - // - for (int i = 0; i < symbolsCount; i++) - { - // - string iSymbol = symbols[i]; - if (IsEURUSD(iSymbol)) - { - // - result = iSymbol; - break; - } - } - - // - return result; - } -}; - -// -struct XSymbolSessionParser -{ - // - string version; // Temp ... - - // - // Check Market Is Open for Specific Symbol - // in Current Time ... - bool CanTrade( - string symbol // Trading Symbol - ) - { - // - bool result = false; - - // - result = IsValid(symbol); - if (!result) - { - return result; - } - - // - MqlDateTime timeStruct; - result = TimeCurrent(timeStruct); - if (!result) - { - return result; - } - - // - ENUM_DAY_OF_WEEK dayOfWeek = (ENUM_DAY_OF_WEEK)timeStruct.day_of_week; - - // - datetime cTime = TimeCurrent(); - - // - datetime from; - datetime to; - result = SymbolInfoSessionTrade( - symbol, - dayOfWeek, - 0, // Session Index ... - from, - to // - ); - if (!result) - { - return result; - } - - // - result = cTime > from && cTime < to; - - // - return result; - } -}; - -// -// Parsing Market Names ... -struct XMarketParser -{ - // - string _version; // Temp ... - - // - bool IsIngot(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // - bool IsErrante(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // - bool IsAMarkets(string market) - { - // - bool result = false; - - // - result = IsValid(market) && - market == "AMarkets LLC"; - - // - return result; - } - - // - bool IsIFCMarkets(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // - bool IsOtetMarkets(string market) - { - // - bool result = false; - - // - // result = IsValid(market) && - // market == ""; - - // - return result; - } - - // -}; - -// -struct XPoint -{ - // - // Props ... - double value; - datetime at; - - // - XPoint() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - value = 0; - at = NULL; - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - return value > 0 && - IsValid(at); - } - - // -}; - -// -// Specified Swing Point ... -struct XSwingPoint -{ - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - - // - double swing; - datetime time; - ENUM_X_SWING_TYPE type; - - // - // Constructor ... - XSwingPoint() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup Model ... - */ - void Clean() - { - // - swing = 0; - time = NULL; - - // - symbol = NULL; - period = NULL; - - // - type = X_NO_SWING; - } - - /** - * Validate Model ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - swing > 0 && - IsValid(time) && - IsValid(symbol) && - IsValid(period) && - type != X_NO_SWING; - - // - return result; - } - - /** - * Check Swing is Low or not ... - * - * @return ( bool ) - */ - bool IsSwingLow() - { - return type == X_SWING_LOW; - } - - /** - * Check Swing is High or not ... - * - * @return ( bool ) - */ - bool IsSwingHigh() - { - return type == X_SWING_HIGH; - } -}; - -// -// Consolidation Zone ... -struct XConsolidationZone -{ - // - // Props ... - - // - string symbol; // Symbol ... - ENUM_TIMEFRAMES period; // Period ... - - // - double upper; // Upper ... - double lower; // Lower ... - - // - datetime from; // Start Date - datetime to; // Breake Date - - // - ENUM_X_DIRECTION dir; // Break Direction ... - - // - // Constructor ... - XConsolidationZone() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - upper = 0; - lower = 0; - - // - to = NULL; - from = NULL; - symbol = NULL; - period = NULL; - dir = X_DIRECTION_NONE; - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - upper > 0 && - lower > 0 && - IsValid(to) && - IsValid(from) && - IsValid(symbol) && - IsValid(period) && - HasDirection(dir) - // - ; - - // - return result; - } - - bool IsSameAs( - XConsolidationZone &item // - ) - { - // - bool result = false; - - // - result = IsValid() && - item.IsValid() && - dir == item.dir && - from == item.from && - upper == item.upper && - lower == item.lower && - symbol == item.symbol && - period == item.period; - - // - return result; - } - - /** - * Retrieve Unique Identifier ... - * - * @return ( string ) - */ - string GetTag() - { - // - string result = - // - "XCZONE" + "_" + - ToString(dir) + "_" + - symbol + "_" + - ToString(period) + "_" + - ToString(upper) + "_" + - ToString(lower) - // - ; - - // - return result; - } - - // -}; - -// -// -// - -class XCRRObject : public XCBaseObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param rr: XRR instance Reference ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XRR &rr, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = rr.IsValid(); - if (!result) - { - return result; - } - - // - string name = rr.GetTag(); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - string nameMD5 = ToMD5(name); - - // - bool isLong = IsLong(rr.type); - - // - double price1 = rr.entry; - double price2 = rr.sl; - - // - datetime time1 = rr.time; - datetime time2 = (datetime)((int)rr.time + 5 * PeriodSeconds(rr.period)); - - // - result = mFibo.Create( - chart_id, - name, - window, - time1, - price1, - time2, - price2 // - ); - if (!result) - { - return result; - } - - // - mRR = rr; - ObjName(name); - - // - int tpsCount = ArraySize(rr.tps); - int levels = tpsCount + 2; - result = mFibo.LevelsCount(levels); - if (!result) - { - return result; - } - - // - // Set Fibo Levels ... - - // - result = mFibo.LevelValue(0, 0); - if (!result) - { - return result; - } - result = mFibo.LevelDescription(0, "SL"); - if (!result) - { - return result; - } - - // - result = mFibo.LevelValue(1, 1.0); - if (!result) - { - return result; - } - result = mFibo.LevelDescription(1, "Entry"); - if (!result) - { - return result; - } - - // - for (int i = 0; i < tpsCount; i++) - { - // - int idx = i + 2; - double level = 1.0 + rr.tps[i]; - string description = "TP " + ToString(rr.tps[i]); - - // - result = mFibo.LevelValue( - idx, - level // - ); - if (!result) - { - break; - } - - // - result = mFibo.LevelDescription( - idx, - description // - ); - if (!result) - { - break; - } - } - if (!result) - { - return result; - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_RR_OBJ; - } - - // - private: - // - - // - // Props ... - XRR mRR; - CChartObjectFibo mFibo; - - // - bool SetSLProps( - int width = 1, - color clr = clrRed, - ENUM_LINE_STYLE style = STYLE_SOLID, - string description = "" // - ) - { - // - bool result = false; - - // - result = SetLevelProps( - 0, - width, - clr, - style, - description // - ); - - // - return result; - } - - // - bool SetEntryProps( - int width = 1, - color clr = clrOrange, - ENUM_LINE_STYLE style = STYLE_SOLID, - string description = "" // - ) - { - // - bool result = false; - - // - result = SetLevelProps( - 0, - width, - clr, - style, - description // - ); - - // - return result; - } - - // - bool SetTPProps( - double tpValue, - int width = 1, - color clr = clrLime, - ENUM_LINE_STYLE style = STYLE_SOLID, - string description = "" // - ) - { - // - bool result = false; - - // - int tpIDX = FindIndex( - tpValue, - mRR.tps // - ); - result = IsValidIndex(tpIDX); - if (!result) - { - return result; - } - - // - tpIDX += 2; - - // - result = SetLevelProps( - tpIDX, - width, - clr, - style, - description // - ); - - // - return result; - } - - // - bool SetLevelProps( - int id, - int width = 1, - color clr = clrYellow, - ENUM_LINE_STYLE style = STYLE_SOLID, - string description = "" // - ) - { - // - bool result = false; - - // - // Color ... - result = mFibo.LevelColor( - id, - clr // - ); - if (!result) - { - return result; - } - - // - // Style ... - result = mFibo.LevelStyle( - id, - style // - ); - if (!result) - { - return result; - } - - // - // Width ... - if (width > 0) - { - // - result = mFibo.LevelWidth( - id, - width // - ); - if (!result) - { - return result; - } - } - - // - // Description ... - if (IsValid(description)) - { - // - result = mFibo.LevelDescription( - id, - description // - ); - if (!result) - { - return result; - } - } - - // - return result; - } -}; - -class XCTrendObject : public XCBaseObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param rr: XRR instance Reference ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XPoint &swings[], - bool useMinAsStart = true, - string prefix = NULL // - ) - { - // - bool result = false; - - // - int count = ArraySize(swings); - result = - count >= 2 && - IsValidSize(count); - if (!result) - { - return result; - } - - // - double min = 0; - datetime minAt = NULL; - - // - double max = 0; - datetime maxAt = NULL; - - // - // Etract Min/Max ... - for (int i = 0; i < count; i++) - { - // - XPoint iPoint = swings[i]; - - // - if (!iPoint.IsValid()) - { - // - iPoint.Clean(); - continue; - } - - // - bool canSetMin = - min == 0 - ? true - : min > iPoint.value; - if (canSetMin) - { - // - minAt = iPoint.at; - min = iPoint.value; - } - - // - bool canSetMax = - max == 0 - ? true - : max < iPoint.value; - if (canSetMax) - { - // - maxAt = iPoint.at; - max = iPoint.value; - } - - // - iPoint.Clean(); - } - - // - double first = - useMinAsStart - ? min - : max; - datetime firstTime = - useMinAsStart - ? minAt - : maxAt; - - // - double second = - useMinAsStart - ? max - : min; - datetime secondTime = - useMinAsStart - ? maxAt - : minAt; - - // - // Validate Points ... - result = - // - first > 0 && - second > 0 && - (useMinAsStart - ? first <= second - : first >= second) && - IsSpecifiedValid(firstTime) && - IsSpecifiedValid(secondTime) - // - ; - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION dir = - useMinAsStart - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - string name = "XTRND" + ToString(dir) + "_" + ToString(first) + "_" + ToString(second); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - string nameMD5 = ToMD5(name); - - // - result = mTrend.Create( - chart_id, - name, - window, - firstTime, - first, - secondTime, - second // - ); - if (!result) - { - return result; - } - - // - ObjName(name); - - // - return result; - } - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param rr: XRR instance Reference ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XSwingPoint &swings[], - string prefix = NULL // - ) - { - // - bool result = false; - - // - int count = ArraySize(swings); - result = - count >= 2 && - IsValidSize(count); - if (!result) - { - return result; - } - - // - ENUM_X_SWING_TYPE type = swings[0].type; - bool isSwingLows = type == X_SWING_LOW; - - // - double values[]; - int valuesCount = ExtractSwings( - swings, - values // - ); - result = valuesCount == count; - if (!result) - { - return result; - } - - // - int firstIDX = -1; - double first = 0; - datetime firstTime = NULL; - - // - int secondIDX = -1; - double second = 0; - datetime secondTime = NULL; - - // - if (isSwingLows) - { - // - first = GetMin( - values, - firstIDX, - 0, - 0 // - ); - if (IsValidIndex(firstIDX)) - { - // - firstTime = swings[firstIDX].time; - - // - second = FindBiggerThan( - first, - values, - true // - ); - secondIDX = FindIndex( - second, - values // - ); - if (IsValidIndex(secondIDX)) - { - secondTime = swings[secondIDX].time; - } - } - } - else - { - // - first = GetMax( - values, - firstIDX, - 0, - 0 // - ); - if (IsValidIndex(firstIDX)) - { - // - firstTime = swings[firstIDX].time; - - // - second = FindLesserThan( - first, - values, - true // - ); - secondIDX = FindIndex( - second, - values // - ); - if (IsValidIndex(secondIDX)) - { - secondTime = swings[secondIDX].time; - } - } - } - - // - // Validate Points ... - result = - // - IsValidIndex(firstIDX) && - IsValidIndex(secondIDX) && - // - IsSpecifiedValid(firstTime) && - IsSpecifiedValid(secondTime) && - // - (isSwingLows - ? first < second - : first > second) - // - ; - if (!result) - { - return result; - } - - // - string name = ToString(type) + "_" + ToString(first) + "_" + ToString(second); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - string nameMD5 = ToMD5(name); - - // - result = mTrend.Create( - chart_id, - name, - window, - firstTime, - first, - secondTime, - second // - ); - if (!result) - { - return result; - } - - // - ObjName(name); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Set Trend Color ... - * - * @param value: Color ... - */ - void TrendColor(color value) - { - mTrend.Color(value); - } - - void TrendRayLeft(bool value) - { - mTrend.RayLeft(value); - } - - void TrendRayRight(bool value) - { - mTrend.RayRight(value); - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_TREND_OBJ; - } - - // - private: - // - - // - // Props ... - CChartObjectTrend mTrend; -}; - -// -// -// - -/** - * Create Trend Line Object ... - * - * @param swings: XSwingPoint instance Collection ... - * - * @return ( bool ) - */ -bool CreateTrend( - XSwingPoint &swings[], - XCTrendObject *&object // -) -{ - // - bool result = false; - - // - object = NULL; - - // - result = ArraySize(swings) >= 2 && - IsValidSize(ArraySize(swings)); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - object = new XCTrendObject(); - result = object.Create( - chartID, - window, - swings, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - color clrTrend = swings[0].type == X_SWING_LOW - ? SwingLowColor() - : SwingHighColor(); - object.TrendColor(clrTrend); - object.TrendRayRight(true); - - // - return result; -} - -/** - * Create Trend Line Object ... - * - * @param swings: XSwingPoint instance Collection ... - * @param useMinAsStart: Specified Min Value as Start ... - * - * @return ( bool ) - */ -bool CreateTrend( - XPoint &swings[], - XCTrendObject *&object, - bool useMinAsStart = true // -) -{ - // - bool result = false; - - // - object = NULL; - - // - result = ArraySize(swings) >= 2 && - IsValidSize(ArraySize(swings)); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - object = new XCTrendObject(); - result = object.Create( - chartID, - window, - swings, - useMinAsStart, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - color clrTrend = useMinAsStart - ? SwingLowColor() - : SwingHighColor(); - object.TrendColor(clrTrend); - object.TrendRayRight(true); - - // - return result; -} - -/** - * Create Specific Risk Reward (RR) on Chart ... - * - * @param rr: XRR instance Reference ... - * - * @return ( bool ) - */ -bool CreateRR( - XRR &rr, - XCRRObject *&object // -) -{ - // - bool result = false; - - // - object = NULL; - - // - result = rr.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - object = new XCRRObject(); - result = object.Create( - chartID, - window, - rr, - prefix // - ); - if (!result) - { - return result; - } - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 b/Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 deleted file mode 100644 index ec14a0d5..00000000 --- a/Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 +++ /dev/null @@ -1,2621 +0,0 @@ -// -// Provided Signals Enumeration ... -enum ENUM_X121SMC_XWZ_PROVIDERS -{ - X121SMC_XWZ_PROVIDER_NONE, - X121SMC_XWZ_PROVIDER_XHKMA, - X121SMC_XWZ_PROVIDER_XSHCNZ, - X121SMC_XWZ_PROVIDER_XBREAKED_BOX, - X121SMC_XWZ_PROVIDER_XREJECTED_BOX, - X121SMC_XWZ_PROVIDER_XACTIVATED_BOX, -}; - -///////////////////////////////////////////////////////////////////// - -// -// Rejected Box ... -bool HasRejectedBoxConditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - // Configure ... - bool forceRetestBox = false; - bool forceHolderBox = false; - bool forceConsolidationZone = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XPOIStateEvents cStateEvents; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int ppIDX = pIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - ENUM_X_DIRECTION iBarPosDir; - bool isBarValidForDir = cHelper - .mBarAnalyser - .IsValidForPosition( - cBar, - iBarPosDir // - ); - bool isBarValidForBullish = - isBarValidForDir && - IsBullish(iBarPosDir); - bool isBarValidForBearish = - isBarValidForDir && - IsBearish(iBarPosDir); - - // - XBoxZone selectedBox; - XSignalBox iSignalBox; - count = ArraySize(waitingBoxes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XSignalBox iBox = waitingBoxes[i]; - - // - bool isBullish = iBox.ob.IsBullish(); - bool hasFVG = iBox.fvg.IsValid(); - - // - bool isFVGBullishRejected = - // - hasFVG && - cBar.low < iBox.fvg.upper && - cBar.GetDown() > iBox.fvg.upper - // - ; - - // - bool isFVGBearishRejected = - // - hasFVG && - cBar.high > iBox.fvg.lower && - cBar.GetUp() < iBox.fvg.lower - // - ; - - // - bool isOBBullishRejected = - // - cBar.low < iBox.ob.upper && - cBar.GetDown() > iBox.ob.upper - // - ; - - // - bool isOBBearishRejected = - // - cBar.high > iBox.ob.lower && - cBar.GetUp() < iBox.ob.lower - // - ; - - // - has = - isBullish - ? (hasFVG - ? isFVGBullishRejected - : isOBBullishRejected) - : (hasFVG - ? isFVGBearishRejected - : isOBBearishRejected); - - // - // Force Using OB ... - if (!has && hasFVG) - { - // - has = isBullish - ? isOBBullishRejected - : isOBBearishRejected; - - // - selectedBox = iBox.ob; - } - if (has) - { - // - iSignalBox = iBox; - if (!selectedBox.IsValid()) - { - // - if (hasFVG) - { - selectedBox = iBox.fvg; - } - else - { - selectedBox = iBox.ob; - } - } - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - has = - iSignalBox.IsValid() && - selectedBox.IsValid(); - - // - // Retest Signal ... - int retests = 0; - if (has) - { - // - int iFromIDX = GetBarIndex( - cBar.symbol, - cBar.period, - selectedBox.from // - ); - has = IsValidIndex(iFromIDX); - if (has) - { - // - // Counting Retests ... - for (int i = iFromIDX; i >= barIndex; i--) - { - // - XOHCL iBar; - has = iBar.Init( - cBar.symbol, - cBar.period, - i // - ); - - // - bool isBullishRetested = - // - iBar.low < selectedBox.upper && - iBar.GetDown() > selectedBox.upper - // - ; - - // - bool isBearishRetested = - // - iBar.high > selectedBox.lower && - iBar.GetUp() < selectedBox.lower - // - ; - - // - has = selectedBox.IsBullish() - ? isBullishRetested - : isBearishRetested; - if (has) - { - retests++; - } - - // - iBar.Clean(); - } - } - } - - // - bool isSignalBoxRetested = - !forceRetestBox - ? retests >= 1 - : retests >= 2; - bool hasSignalBox = iSignalBox.IsValid(); - bool isSignalBoxBullish = IsBullish(iSignalBox.ob.dir); - - // - // Check Consolidation Zone ... - bool hasBullishCZone = true; - bool hasBearishCZone = true; - if (forceConsolidationZone) - { - // - XBoxZone cZone; - XBoxZone tmpBoxes[]; - if (isSignalBoxBullish) - { - // - ToBox( - cState.bullishConsolidationZones, - tmpBoxes // - ); - } - else - { - // - ToBox( - cState.bearishConsolidationZones, - tmpBoxes // - ); - } - has = HasChild(tmpBoxes); - if (has) - { - // - XBoxZone selectedBox; - if (iSignalBox.fvg.IsValid()) - { - selectedBox = iSignalBox.fvg; - } - else - { - selectedBox = iSignalBox.ob; - } - - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (has) - { - // - cZone = tmpBoxes[idx]; - - // - // Check Consolidation Zone Place ... - has = - // - ( - // - IsBoxInsideOr( - cZone, - selectedBox // - ) - // - && - // - cZone.from >= selectedBox.from - // - ) - // - || - // - ( - // - IsBoxInsideOr( - selectedBox, - cZone // - ) - // - && - // - selectedBox.from >= cZone.from - // - ) - // - ; - if (!has) - { - cZone.Clean(); - } - } - - // - selectedBox.Clean(); - } - Clean(tmpBoxes); - - // - hasBullishCZone = cZone.IsValid() && - cZone.IsBullish(); - - // - hasBearishCZone = cZone.IsValid() && - cZone.IsBearish(); - - // - cZone.Clean(); - } - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - hasSignalBox && - hasBullishCZone && - isSignalBoxBullish && - isSignalBoxRetested && - isBarValidForBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - hasSignalBox && - hasBearishCZone && - !isSignalBoxBullish && - isSignalBoxRetested && - isBarValidForBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box = selectedBox; - box.to = TimeCurrent(); - - // - // Detect Holder Box ... - if (forceHolderBox) - { - // - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Support Zones ... - ToBox( - cState.supportZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Resistance Zones ... - ToBox( - cState.resistanceZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - - // - count = ArraySize(tmpBoxes); - has = IsValidSize(count); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - iBox, - box // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - result = - result && - holderBox.IsValid() && - holderBox.dir == dir; - if (!result) - { - // - box.Clean(); - isBullish = false; - isBearish = false; - holderBox.Clean(); - } - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - iSignalBox.Clean(); - selectedBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; -} - -// -// Activated Box -bool HasActivatedBoxConditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XPOIStateEvents cStateEvents; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int ppIDX = pIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL pPBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(pPBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - ENUM_X_DIRECTION iBarPosDir; - bool isBarValidForDir = cHelper - .mBarAnalyser - .IsValidForPosition( - cBar, - iBarPosDir // - ); - bool isBarValidForBullish = - isBarValidForDir && - IsBullish(iBarPosDir); - bool isBarValidForBearish = - isBarValidForDir && - IsBearish(iBarPosDir); - - // - XSignalBox iSignalBox; - count = ArraySize(waitingBoxes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XSignalBox iBox = waitingBoxes[i]; - - // - bool isBullish = iBox.ob.IsBullish(); - bool hasFVG = iBox.fvg.IsValid(); - - // - // Checking Inside ... - - // - bool isBullishInsideFVG = - // - hasFVG && - pBar.high < iBox.fvg.upper && - pPBar.high < iBox.fvg.upper - // - ; - - // - bool isBearishInsideFVG = - // - hasFVG && - pBar.low > iBox.fvg.lower && - pPBar.low > iBox.fvg.lower - // - ; - - // - bool isBullishInsideOB = - // - pBar.high < iBox.ob.upper && - pPBar.high < iBox.ob.upper - // - ; - - // - bool isBearishInsideOB = - // - pBar.low > iBox.ob.lower && - pPBar.low > iBox.ob.lower - // - ; - - // - // Checking Breakes Box ... - - // - bool isFVGBullishBreaked = - // - hasFVG && - isBullishInsideFVG && - // - cBar.high > iBox.fvg.upper && - cBar.close > iBox.fvg.upper && - // - zBar.open > iBox.fvg.upper - // - ; - - // - bool isFVGBearishBreaked = - // - hasFVG && - isBearishInsideFVG && - // - cBar.low < iBox.fvg.lower && - cBar.close < iBox.fvg.lower && - // - zBar.open > iBox.fvg.lower - // - ; - - // - bool isOBBullishBreaked = - // - isBullishInsideOB && - // - cBar.high > iBox.ob.upper && - cBar.close > iBox.ob.upper && - // - zBar.open > iBox.ob.upper - // - ; - - // - bool isOBBearishBreaked = - // - isBearishInsideOB && - // - cBar.low < iBox.ob.lower && - cBar.close < iBox.ob.lower && - // - zBar.open > iBox.ob.lower - // - ; - - // - // Summarise ... - - // - bool isBullishBreaked = - isBarValidForBullish && - (hasFVG - ? isFVGBullishBreaked - : isOBBullishBreaked); - - // - bool isBearishBreaked = - isBarValidForBearish && - (hasFVG - ? isFVGBearishBreaked - : isOBBearishBreaked); - - // - has = isBullishBreaked || - isBearishBreaked; - // - if (has) - { - // - iSignalBox = iBox; - iBox.Clean(); - - // - dir = - isBullishBreaked - ? X_DIRECTION_BULLISH - : isBearishBreaked - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - break; - } - - // - iBox.Clean(); - } - } - - // - bool hasSignalBox = HasDirection(dir) && - iSignalBox.IsValid(); - bool isSignalBoxBullish = IsBullish(dir); - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - hasSignalBox && - isSignalBoxBullish && - isBarValidForBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - hasSignalBox && - !isSignalBoxBullish && - isBarValidForBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - if (iSignalBox.fvg.IsValid()) - { - box = iSignalBox.fvg; - } - else - { - box = iSignalBox.ob; - } - - // - box.to = TimeCurrent(); - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Support Zones ... - ToBox( - cState.supportZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Resistance Zones ... - ToBox( - cState.resistanceZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - - // - count = ArraySize(tmpBoxes); - has = IsValidSize(count); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - iBox, - box // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - result = - result && - holderBox.IsValid() && - holderBox.dir == dir; - if (!result) - { - // - box.Clean(); - isBullish = false; - isBearish = false; - holderBox.Clean(); - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - iSignalBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; -} - -// -// Breaked Box -bool HasBreakedBoxConditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XPOIStateEvents cStateEvents; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int ppIDX = pIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL pPBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(pPBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - ENUM_X_DIRECTION iBarPosDir; - bool isBarValidForDir = cHelper - .mBarAnalyser - .IsValidForPosition( - cBar, - iBarPosDir // - ); - bool isBarValidForBullish = - isBarValidForDir && - IsBullish(iBarPosDir); - bool isBarValidForBearish = - isBarValidForDir && - IsBearish(iBarPosDir); - - // - XSignalBox iSignalBox; - count = ArraySize(waitingBoxes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XSignalBox iBox = waitingBoxes[i]; - - // - bool isBullish = iBox.ob.IsBullish(); - bool hasFVG = iBox.fvg.IsValid(); - - // - // Checking Breakes Box ... - - // - bool isFVGBullishBreaked = - // - hasFVG && - // - pBar.low < iBox.fvg.upper && - // - cBar.high > iBox.fvg.upper && - cBar.close > iBox.fvg.upper && - // - zBar.open > iBox.fvg.upper - // - ; - - // - bool isFVGBearishBreaked = - // - hasFVG && - // - pBar.high > iBox.fvg.lower && - // - cBar.low < iBox.fvg.lower && - cBar.close < iBox.fvg.lower && - // - zBar.open > iBox.fvg.lower - // - ; - - // - bool isOBBullishBreaked = - // - pBar.low < iBox.ob.upper && - // - cBar.high > iBox.ob.upper && - cBar.close > iBox.ob.upper && - // - zBar.open > iBox.ob.upper - // - ; - - // - bool isOBBearishBreaked = - // - pBar.high > iBox.ob.lower && - // - cBar.low < iBox.ob.lower && - cBar.close < iBox.ob.lower && - // - zBar.open > iBox.ob.lower - // - ; - - // - // Summarise ... - - // - bool isBullishBreaked = - isBarValidForBullish && - (hasFVG - ? isFVGBullishBreaked - : isOBBullishBreaked); - - // - bool isBearishBreaked = - isBarValidForBearish && - (hasFVG - ? isFVGBearishBreaked - : isOBBearishBreaked); - - // - has = isBullishBreaked || - isBearishBreaked; - // - if (has) - { - // - iSignalBox = iBox; - iBox.Clean(); - - // - dir = - isBullishBreaked - ? X_DIRECTION_BULLISH - : isBearishBreaked - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - break; - } - - // - iBox.Clean(); - } - } - - // - bool hasSignalBox = HasDirection(dir) && - iSignalBox.IsValid(); - bool isSignalBoxBullish = IsBullish(dir); - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - hasSignalBox && - isSignalBoxBullish && - isBarValidForBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - hasSignalBox && - !isSignalBoxBullish && - isBarValidForBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - if (iSignalBox.fvg.IsValid()) - { - box = iSignalBox.fvg; - } - else - { - box = iSignalBox.ob; - } - - // - box.to = TimeCurrent(); - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Support Zones ... - ToBox( - cState.supportZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Resistance Zones ... - ToBox( - cState.resistanceZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - - // - count = ArraySize(tmpBoxes); - has = IsValidSize(count); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - iBox, - box // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - result = - result && - holderBox.IsValid() && - holderBox.dir == dir; - if (!result) - { - // - box.Clean(); - isBullish = false; - isBearish = false; - holderBox.Clean(); - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - iSignalBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; -} - -// -// XHKMA ... -bool HasXHKMAConditions( - ENUM_X_CYCLES cycle, - ENUM_X_DIRECTION trend, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Check Trend Exists ... - result = HasDirection(trend); - if (!result) - { - return result; - } - - // - // Extrand Trend Direction ... - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Check Current Waiting Box is Directional To Trend ... - XSignalBox iSignalBox; - idx = GetYoungest(waitingBoxes); - result = IsValidIndex(idx); - if (!result) - { - // - iSignalBox.Clean(); - return result; - } - iSignalBox = waitingBoxes[idx]; - result = iSignalBox.IsValid() && - iSignalBox.ob.dir == trend; - if (!result) - { - // - iSignalBox.Clean(); - return result; - } - - // - bool hasBullishSignalBox = iSignalBox.IsValid() && - iSignalBox.ob.IsBullish(); - - // - bool hasBearishSignalBox = iSignalBox.IsValid() && - iSignalBox.ob.IsBearish(); - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XPOIStateEvents cStateEvents; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int ppIDX = pIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL pPBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(pPBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - ENUM_X_DIRECTION iBarPosDir; - bool isBarValidForDir = cHelper - .mBarAnalyser - .IsValidForPosition( - cBar, - iBarPosDir // - ); - bool isBarValidForBullish = - isBarValidForDir && - IsBullish(iBarPosDir); - bool isBarValidForBearish = - isBarValidForDir && - IsBearish(iBarPosDir); - - // - // Check Bar Validation for Trend Based Directions ... - result = - isBarValidForDir && - iBarPosDir == trend && - HasDirection(iBarPosDir); - if (!result) - { - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - iSignalBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - // Here we Have to Check Other Consitions Based On Current - // Stuffs ... - XBoxZone zoneBox; - - // - // Select Boxes for Zones ... - XBoxZone tmpBoxes[]; - if (hasBullishTrend) - { - // - XBoxZone tmp[]; - - // - // Order Blocks ... - // ToBox( - // cState.bullishOrderBlocks, - // tmp // - // ); - // Copy( - // tmp, - // tmpBoxes // - // ); - // Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else if (hasBearishTrend) - { - // - XBoxZone tmp[]; - - // - // Order Blocks ... - // ToBox( - // cState.bearishOrderBlocks, - // tmp // - // ); - // Copy( - // tmp, - // tmpBoxes // - // ); - // Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - // Select Box based on Trend ... - idx = hasBullishTrend - ? GetLowest(tmpBoxes) - : hasBearishTrend - ? GetHighest(tmpBoxes) - : -1; - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - // Validate Selected Box ... - bool isDirPassed = iBox.dir == trend; - bool isFromPassed = - iSignalBox.fvg.IsValid() - ? iBox.from > iSignalBox.fvg.from - : iBox.from > iSignalBox.ob.from; - bool isPriceInsidePassed = - hasBullishTrend - ? cBar.low < iBox.upper && - cBar.low > iBox.lower - : hasBearishTrend - ? cBar.high > iBox.lower && - cBar.high < iBox.upper - : false; - has = isDirPassed && - isFromPassed && - isPriceInsidePassed; - if (has) - { - // - zoneBox = iBox; - iBox.Clean(); - break; - } - } - } - Clean(tmpBoxes); - - // - bool hasBullishZoneBox = zoneBox.IsValid() && - zoneBox.IsBullish(); - - // - bool hasBearishZoneBox = zoneBox.IsValid() && - zoneBox.IsBearish(); - - // - // Detecting Consolidation Zone ... - XBoxZone cZone; - if (hasBullishTrend) - { - // - ToBox( - cState.bullishConsolidationZones, - tmpBoxes // - ); - } - else if (hasBearishTrend) - { - // - ToBox( - cState.bearishConsolidationZones, - tmpBoxes // - ); - } - has = HasChild(tmpBoxes); - if (has) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (has) - { - // - cZone = tmpBoxes[idx]; - - // - // Check Consolidation Zone Place ... - has = - // - ( - // - IsBoxInsideOr( - cZone, - zoneBox // - ) - // - && - // - cZone.from >= zoneBox.from - // - ) - // - || - // - ( - // - IsBoxInsideOr( - zoneBox, - cZone // - ) - // - && - // - zoneBox.from >= cZone.from - // - ) - // - ; - if (!has) - { - cZone.Clean(); - } - } - } - Clean(tmpBoxes); - - // - bool hasBullishCZone = cZone.IsValid() && - cZone.IsBullish(); - - // - bool hasBearishCZone = cZone.IsValid() && - cZone.IsBearish(); - - // - // Summarize Conditions ... - - // - // Bullish ... - isBullish = - // - // Base Bullish Conditions ... - hasBullishTrend && - hasBullishCZone && - hasBullishZoneBox && - hasBullishSignalBox && - isBarValidForBullish && - // - // Other Additional Conditions ... - true - // - ; - - // - // Bearish ... - isBearish = - // - // Base Bearish Conditions ... - hasBearishTrend && - hasBearishCZone && - hasBearishZoneBox && - hasBearishSignalBox && - isBarValidForBearish && - // - // Other Additional Conditions ... - true - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box = zoneBox; - - // - box.to = TimeCurrent(); - cZone.to = TimeCurrent(); - - // - if (result) - { - // - XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - box, - iObj // - ); - - // - XCBoxObject *iCObject; - has = drawer.DrawBox( - cZone, - iCObject // - ); - if (has) - { - // - iCObject.BoxColor(clrLime); - iCObject.BoxStyle(STYLE_SOLID); - } - - // - Print("Found ..."); - - // - ZeroMemory(drawer); - } - } - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cZone.Clean(); - cState.Clean(); - zoneBox.Clean(); - iSignalBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; -} - -// -// XSHCNZ ... -bool HasXSHCNZConditions( - ENUM_X_CYCLES cycle, - ENUM_X_DIRECTION trend, - XBoxZone &box, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - box.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Validate Args ... - result = IsValid(cycle) && - HasDirection(trend) && - HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XPOIStateEvents cStateEvents; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int ppIDX = pIDX + 1; - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - cState.symbol, - cState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - // Extract XSHCNZ Boxes ... - XBoxZone sharpBox; - XBoxZone sharpBoxes[]; - count = ArraySize(waitingBoxes); - for (int i = 0; i < count; i++) - { - // - has = waitingBoxes[i].ob.type == "XSHCNZ"; - if (has) - { - // - AddRef( - waitingBoxes[i].ob, - sharpBoxes // - ); - } - } - count = ArraySize(sharpBoxes); - has = IsValidSize(count); - result = has; - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - Clean(sharpBoxes); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - - // - // Detect Price Inside Sharp Box ... - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = sharpBoxes[i]; - - // - bool isInside = cBar.close > iBox.lower && - cBar.close < iBox.upper; - if (isInside) - { - // - sharpBox = iBox; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - // Validate Sharp Box Exists ... - has = sharpBox.IsValid(); - result = has; - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - sharpBox.Clean(); - Clean(sharpBoxes); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; - } - - // - XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; - XCBoxObject *iSharpObj; - has = drawer.DrawBox( - sharpBox, - iSharpObj // - ); - if (has) - { - // - iSharpObj.BoxColor(clrYellow); - - // - Print("Sharp Box Selected ..."); - } - - // - // Validate Bar for Specified Position Type ... - ENUM_X_DIRECTION iBarPosDir; - bool isBarValidForDir = cHelper - .mBarAnalyser - .IsValidForPosition( - cBar, - iBarPosDir // - ); - bool isBarValidForBullish = - isBarValidForDir && - IsBullish(iBarPosDir); - bool isBarValidForBearish = - isBarValidForDir && - IsBearish(iBarPosDir); - - // - // Cleanup Resources ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - sharpBox.Clean(); - Clean(sharpBoxes); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); - - // - return result; -} - -/////////////////////////////////////////////////////////////// - -// -// Senario 1: -// --------------------------------------------- -// Rejected Box ... -// --------------------------------------------- -bool useSenario1 = false; -bool isSenario1Happend = false; -bool isSenario1Bullish = false; -bool isSenario1Bearish = false; -if (useSenario1) -{ - // - isSenario1Happend = cParser.HasRejectedBoxConditions( - X_CYCLE_DECISION, - box, - holderBox, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario1Bullish = - isSenario1Happend && - IsBullish(dir); - - // - isSenario1Bearish = - isSenario1Happend && - IsBearish(dir); - - // - if (isSenario1Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XREJECTED_BOX; - } -} - -// -// Senario 2: -// --------------------------------------------------- -// Activated Box ... -// --------------------------------------------------- -bool useSenario2 = false; -bool isSenario2Happend = false; -bool isSenario2Bullish = false; -bool isSenario2Bearish = false; -if (!isSenario1Happend && - useSenario2) -{ - // - isSenario2Happend = cParser.HasActivatedBoxConditions( - X_CYCLE_DECISION, - box, - holderBox, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario2Bullish = - isSenario2Happend && - IsBullish(dir); - - // - isSenario2Bearish = - isSenario2Happend && - IsBearish(dir); - - // - if (isSenario2Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XACTIVATED_BOX; - } -} - -// -// Senario 3: -// --------------------------------------------------- -// Breaked Box ... -// --------------------------------------------------- -bool useSenario3 = false; -bool isSenario3Happend = false; -bool isSenario3Bullish = false; -bool isSenario3Bearish = false; -if (!isSenario1Happend && - !isSenario2Happend && - useSenario3) -{ - // - isSenario3Happend = cParser.HasBreakedBoxConditions( - X_CYCLE_DECISION, - box, - holderBox, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario3Bullish = - isSenario3Happend && - IsBullish(dir); - - // - isSenario3Bearish = - isSenario3Happend && - IsBearish(dir); - - // - if (isSenario3Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XBREAKED_BOX; - } -} - -// -// Senario 4: -// ----------------------------------------------- -// Detect Signal Box Based On XHKMA Conditions ... -// ----------------------------------------------- -bool useSenario4 = false; -bool isSenario4Happend = false; -bool isSenario4Bullish = false; -bool isSenario4Bearish = false; -if (!isSenario1Happend && - !isSenario2Happend && - !isSenario3Happend && - useSenario4) -{ - // - isSenario4Happend = cParser.HasXHKMAConditions( - X_CYCLE_DECISION, - trend, - box, - holderBox, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario4Bullish = - isSenario4Happend && - IsBullish(dir); - - // - isSenario4Bearish = - isSenario4Happend && - IsBearish(dir); - - // - if (isSenario4Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XHKMA; - } -} - -// -// Senario 5: -// --------------------------------------------- -// XSHCNZ Signal Box Detection Conditions ... -// --------------------------------------------- -bool useSenario5 = true; -bool isSenario5Happend = false; -bool isSenario5Bullish = false; -bool isSenario5Bearish = false; -if (!isSenario1Happend && - !isSenario2Happend && - !isSenario3Happend && - !isSenario4Happend && - useSenario5) -{ - // - isSenario5Happend = cParser.HasXSHCNZConditions( - X_CYCLE_DECISION, - trend, - box, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario5Bullish = - isSenario5Happend && - IsBullish(dir); - - // - isSenario5Bearish = - isSenario5Happend && - IsBearish(dir); - - // - if (isSenario5Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XSHCNZ; - } -} diff --git a/Documents/BKP/x121.usin-xtrend.mq5 b/Documents/BKP/x121.usin-xtrend.mq5 deleted file mode 100644 index ec2b5cae..00000000 --- a/Documents/BKP/x121.usin-xtrend.mq5 +++ /dev/null @@ -1,4637 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XCX121Helper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Helpers/x-saherelm.x121.x3ma.helper.mq5" -#include "../Helpers/x-saherelm.x121.xatr.helper.mq5" -#include "../Helpers/x-saherelm.x121.xcc.helper.mq5" -#include "../Helpers/x-saherelm.x121.xche.helper.mq5" -#include "../Helpers/x-saherelm.x121.xdon.helper.mq5" -#include "../Helpers/x-saherelm.x121.xhk.helper.mq5" -#include "../Helpers/x-saherelm.x121.xmas.helper.mq5" -#include "../Helpers/x-saherelm.x121.xpv.helper.mq5" -#include "../Helpers/x-saherelm.x121.xstr.helper.mq5" -#include "../Helpers/x-saherelm.x121.xtrend.helper.mq5" -#include "../Helpers/x-saherelm.x121.xvwap.helper.mq5" - -// -// Inputs ... -struct X121Inputs -{ - // - // Props ... - bool showRSI; - X121XCCInputs xccInputs; - X121XPVInputs xpvInputs; - X121XHKInputs xhkInputs; - X121XMASInputs xmasInputs; - X121XATRInputs xatrInputs; - X121XSTRInputs xstrInputs; - X121XCHEInputs xcheInputs; - X121XDONInputs xdonInputs; - X121X3MAInputs x3maInputs; - X121XVWAPInputs xvwapInputs; - X121XTRENDInputs xtrendInputs; - - // - // Constructor ... - X121Inputs() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - xccInputs.Clean(); - xpvInputs.Clean(); - xhkInputs.Clean(); - xmasInputs.Clean(); - xatrInputs.Clean(); - xstrInputs.Clean(); - xcheInputs.Clean(); - xdonInputs.Clean(); - xvwapInputs.Clean(); - xtrendInputs.Clean(); - - // - ZeroMemory(this); - } - - /** - * Set Default Values ... - */ - void Default() - { - // - xccInputs.Default(); - xpvInputs.Default(); - xhkInputs.Default(); - xmasInputs.Default(); - xatrInputs.Default(); - xstrInputs.Default(); - xcheInputs.Default(); - xdonInputs.Default(); - x3maInputs.Default(); - xvwapInputs.Default(); - xtrendInputs.Default(); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - xccInputs.IsValid() && - xpvInputs.IsValid() && - xhkInputs.IsValid() && - xmasInputs.IsValid() && - xatrInputs.IsValid() && - xstrInputs.IsValid() && - xcheInputs.IsValid() && - xdonInputs.IsValid() && - xvwapInputs.IsValid() && - xtrendInputs.IsValid() - // - ; - - // - return result; - } - - /** - * Extract Max Input Length ... - * - * @return ( int ) - */ - int Max() - { - // - int result = 0; - - // - int xpvMax = xpvInputs.Max(); - int xhkMax = xpvInputs.Max(); - int xmasMax = xpvInputs.Max(); - int xatrMax = xatrInputs.Max(); - int xstrMax = xstrInputs.Max(); - int xcheMax = xcheInputs.Max(); - int xdonMax = xdonInputs.Max(); - int xvwapMax = xvwapInputs.Max(); - int xtrendMax = xtrendInputs.Max(); - - // - result = MathMax(xpvMax, xhkMax); - result = MathMax(result, xmasMax); - result = MathMax(result, xatrMax); - result = MathMax(result, xstrMax); - result = MathMax(result, xcheMax); - result = MathMax(result, xdonMax); - result = MathMax(result, xvwapMax); - result = MathMax(result, xtrendMax); - - // - return result; - } -}; - -// -// Conditions ... -struct X121Conditions -{ - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Buffers ... - double maBuffer[]; - double rsiBuffer[]; - double atrBuffer[]; - double strBuffer[]; - double le1Buffer[]; - double se1Buffer[]; - double le2Buffer[]; - double se2Buffer[]; - double sarBuffer[]; - double cHHBuffer[]; - double cLLBuffer[]; - double sHHBuffer[]; - double sLLBuffer[]; - double mHHBuffer[]; - double mLLBuffer[]; - double lHHBuffer[]; - double lLLBuffer[]; - double hHHBuffer[]; - double hLLBuffer[]; - double upTBuffer[]; - double adxBuffer[]; - double adxPBuffer[]; - double adxMBuffer[]; - long volumeBuffer[]; - double peaksBuffer[]; - double valesBuffer[]; - double strUpBuffer[]; - double downTBuffer[]; - double masMidBuffer[]; - double masUpperBuffer[]; - double masLowerBuffer[]; - double strDownBuffer[]; - double vwapMidBuffer[]; - double upTrendBuffer[]; - double x3maMidBuffer[]; - double le1StartBuffer[]; - double se1StartBuffer[]; - double le2StartBuffer[]; - double se2StartBuffer[]; - double strPriceBuffer[]; - double atrUpperBuffer[]; - double atrLowerBuffer[]; - double strStateBuffer[]; - double vwapFastBuffer[]; - double vwapSlowBuffer[]; - double xhkSMLowBuffer[]; - double x3maFastBuffer[]; - double x3maSlowBuffer[]; - double supportsBuffer[]; - double downTrendBuffer[]; - double vwapPriceBuffer[]; - double xhkRawLowBuffer[]; - double xhkSMOpenBuffer[]; - double xhkSMHighBuffer[]; - double xhkRawOpenBuffer[]; - double xhkRawHighBuffer[]; - double xhkSMCloseBuffer[]; - double vwapVolumeBuffer[]; - double peaksGoldenBuffer[]; - double valesGoldenBuffer[]; - double xhkRawCloseBuffer[]; - double atrUpperRawBuffer[]; - double atrLowerRawBuffer[]; - double donLowUpperBuffer[]; - double donLowLowerBuffer[]; - double resistancesBuffer[]; - double vwapMidStateBuffer[]; - double donOpenUpperBuffer[]; - double donOpenLowerBuffer[]; - double donHighUpperBuffer[]; - double donHighLowerBuffer[]; - double x3maMidStateBuffer[]; - double fractalsUpperBuffer[]; - double fractalsLowerBuffer[]; - double vwapFastStateBuffer[]; - double vwapSlowStateBuffer[]; - double donCloseUpperBuffer[]; - double donCloseLowerBuffer[]; - double x3maFastStateBuffer[]; - double x3maSlowStateBuffer[]; - - // - double rsiSlope; - double strSlope; - double atrUpperSlope; - double atrLowerSlope; - double vwapFastSlope; - double vwapMidSlope; - double vwapSlowSlope; - - // - // Conditions ... - - // - // XTrend ... - - // - bool isTrendBullish; - bool isTrendBearish; - bool isTrendSwitchedToBullish; - bool isTrendSwitchedToBearish; - - // - bool isRsiSlopeBullish; - bool isStrSlopeBullish; - bool isAtrUpperSlopeBullish; - bool isAtrLowerSlopeBullish; - bool isVwapFastSlopeBullish; - bool isVwapMidSlopeBullish; - bool isVwapSlowSlopeBullish; - - // - bool isRsiSlopeBearish; - bool isStrSlopeBearish; - bool isAtrUpperSlopeBearish; - bool isAtrLowerSlopeBearish; - bool isVwapFastSlopeBearish; - bool isVwapMidSlopeBearish; - bool isVwapSlowSlopeBearish; - - // - bool isRsiOverSold; - bool isRsiOverBought; - bool isRsiCrossedOverOverSold; - bool isRsiCrossedUnderOverSold; - bool isRsiCrossedOverOverBought; - bool isRsiCrossedUnderOverBought; - - // - bool isClosedOverAtrUpper; - bool isClosedOverAtrLower; - bool isClosedUnderAtrUpper; - bool isClosedUnderAtrLower; - - // - bool isRejectedUpAtrUpper; - bool isRejectedDownAtrUpper; - - // - bool isRejectedUpAtrLower; - bool isRejectedDownAtrLower; - - // - bool isBreakedUpAtrUpper; - bool isBreakedDownAtrUpper; - - // - bool isBreakedUpAtrLower; - bool isBreakedDownAtrLower; - - // - bool isRejectedDonOpenUpper; - bool isRejectedDonHighUpper; - bool isRejectedDonLowUpper; - bool isRejectedDonCloseUpper; - - // - bool isRejectedDonOpenLower; - bool isRejectedDonHighLower; - bool isRejectedDonLowLower; - bool isRejectedDonCloseLower; - - // - bool isBreakedDonOpenUpper; - bool isBreakedDonHighUpper; - bool isBreakedDonLowUpper; - bool isBreakedDonCloseUpper; - - // - bool isBreakedDonOpenLower; - bool isBreakedDonHighLower; - bool isBreakedDonLowLower; - bool isBreakedDonCloseLower; - - // - bool isSarBullish; - bool isSarBearish; - bool isSarSwitchedToBullish; - bool isSarSwitchedToBearish; - - // - bool isNewPeak; - bool isNewPeakOverLast; - bool isNewPeakUnderLast; - bool isRejectedPrevPeak; - bool isBreakedUpPrevPeak; - - // - bool isNewVale; - bool isNewValeOverLast; - bool isNewValeUnderLast; - bool isRejectedPrevVale; - bool isBreakedDownPrevVale; - - // - bool isStrBullish; - bool isStrBearish; - bool isStrSwitchedToBullish; - bool isStrSwitchedToBearish; - - // - bool isChe1Bullish; - bool isChe1Bearish; - bool isChe1SwitchedToBullish; - bool isChe1SwitchedToBearish; - - // - bool isChe2Bullish; - bool isChe2Bearish; - bool isChe2SwitchedToBullish; - bool isChe2SwitchedToBearish; - - // - bool isCheBullish; - bool isCheBearish; - bool isCheSwitchedToBullish; - bool isCheSwitchedToBearish; - - // - bool isVWapMidBullish; - bool isVWapMidBearish; - bool isVWapFastBullish; - bool isVWapFastBearish; - bool isVWapMidNeutural; - bool isVWapSlowBullish; - bool isVWapSlowBearish; - bool isVWapFastOverMid; - bool isVWapMidOverSlow; - bool isVWapFastNeutural; - bool isVWapSlowNeutural; - bool isVWapFastUnderMid; - bool isVWapMidUnderSlow; - bool isVWapBullishState; - bool isVWapBearishState; - bool isVWapNeuturalState; - bool isVWapBullishOrdered; - bool isVWapBearishOrdered; - bool isVWapSwitchedToBullishState; - bool isVWapSwitchedToBearishState; - bool isVWapSwitchedToNeuturalState; - bool isVWapSwitchedToBullishOrdered; - bool isVWapSwitchedToBearishOrdered; - - // - bool isX3MaMidBullish; - bool isX3MaMidBearish; - bool isX3MaFastBullish; - bool isX3MaFastBearish; - bool isX3MaMidNeutural; - bool isX3MaSlowBullish; - bool isX3MaSlowBearish; - bool isX3MaFastOverMid; - bool isX3MaMidOverSlow; - bool isX3MaFastNeutural; - bool isX3MaSlowNeutural; - bool isX3MaFastUnderMid; - bool isX3MaMidUnderSlow; - bool isX3MaBullishState; - bool isX3MaBearishState; - bool isX3MaNeuturalState; - bool isX3MaBullishOrdered; - bool isX3MaBearishOrdered; - bool isX3MaSwitchedToBullishState; - bool isX3MaSwitchedToBearishState; - bool isX3MaSwitchedToNeuturalState; - bool isX3MaSwitchedToBullishOrdered; - bool isX3MaSwitchedToBearishOrdered; - - // - bool isSMHKBullish; - bool isRawHKBullish; - bool isSMHKBearish; - bool isRawHKBearish; - bool isBreakedUpSMHK; - bool isBreakedUpRawHK; - bool isRejectedUpSMHK; - bool isClosedOverSMHK; - bool isRejectedUpRawHK; - bool isBreakedDownSMHK; - bool isClosedUnderSMHK; - bool isClosedOverRawHK; - bool isClosedUnderRawHK; - bool isBreakedDownRawHK; - bool isRejectedDownSMHK; - bool isRejectedDownRawHK; - bool isRawHKBreakedUpSMHK; - bool isRawHKClosedOverSMHK; - bool isRawHKClosedUnderSMHK; - bool isRawHKBreakedDownSMHK; - bool isSMHKSwitchedToBullish; - bool isSMHKSwitchedToBearish; - bool isRawHKSwitchedToBearish; - bool isRawHKSwitchedToBullish; - - // - // Complex Conditions ... - - // - double cheMin; - double cheMax; - double x3maMin; - double x3maMax; - double vwapMin; - double vwapMax; - - // - bool isSarIncreased; - bool isSarDecreased; - bool isX3MaFatsOverMid; - bool isSarEqualsToPeak; - bool isSarEqualsToVale; - bool isStrEqualsToPeak; - bool isStrEqualsToVale; - bool isX3MaMinBreakedUp; - bool isX3MaMaxBreakedUp; - bool isX3MaFatsUnderMid; - bool isX3MaFatsOverSlow; - bool isAtrUpperOverPeak; - bool isPeakOverAtrUpper; - bool isStrUpperOverPeak; - bool isStrLowerOverVale; - bool isBreakedUpPrevSar; - bool isBreakedUpPrevStr; - bool isVWapMinBreakedUp; - bool isVWapMaxBreakedUp; - bool isClosedOverCheMin; - bool isClosedOverCheMax; - bool isX3MaFatsUnderSlow; - bool isAtrLowerUnderVale; - bool isClosedOverX3MaMin; - bool isClosedOverX3MaMax; - bool isValeUnderAtrLower; - bool isStrUpperUnderPeak; - bool isStrLowerUnderVale; - bool isClosedUnderCheMin; - bool isClosedUnderCheMax; - bool isClosedOverVWapMin; - bool isClosedOverVWapMax; - bool isX3MaMinBreakedDown; - bool isX3MaMaxBreakedDown; - bool isClosedUnderX3MaMin; - bool isClosedUnderX3MaMax; - bool isBreakedDownPrevSar; - bool isBreakedDownPrevStr; - bool isStrCrossedOverVale; - bool isSarCrossedOverVale; - bool isClosedUnderVWapMin; - bool isClosedUnderVWapMax; - bool isVWapMinBreakedDown; - bool isVWapMaxBreakedDown; - bool isX3MaFatsOverMidPrev; - bool isSarCrossedUnderPeak; - bool isStrCrossedUnderPeak; - bool isNewPeakOverAtrUpper; - bool isBreakedUpPrevCheMin; - bool isBreakedUpPrevCheMax; - bool isBreakedUpPrevCheLE1; - bool isBreakedUpPrevCheLE2; - bool isBreakedUpPrevCheSE1; - bool isBreakedUpPrevCheSE2; - bool isX3MaFatsUnderMidPrev; - bool isX3MaFatsOverSlowPrev; - bool isAtrUpperEqualsToPeak; - bool isAtrLowerEqualsToVale; - bool isStrUpperOverAtrUpper; - bool isStrLowerOverAtrLower; - bool isNewValeUnderAtrLower; - bool isAtrUpperCrossedUpPeak; - bool isAtrLowerCrossedUpVale; - bool isStrUpperUnderAtrUpper; - bool isStrLowerUnderAtrLower; - bool isX3MaFatsUnderSlowPrev; - bool isBreakedUpPrevAtrUpper; - bool isBreakedUpPrevAtrLower; - bool isBreakedDownPrevCheMin; - bool isBreakedDownPrevCheMax; - bool isBreakedDownPrevCheLE1; - bool isBreakedDownPrevCheLE2; - bool isBreakedDownPrevCheSE1; - bool isBreakedDownPrevCheSE2; - bool isX3MaFastCrossedOverMid; - bool isRejectedUpPrevAtrUpper; - bool isRejectedUpPrevAtrLower; - bool isVWapFastCrossedOverMid; - bool isX3MaFastCrossedUnderMid; - bool isX3MaFastCrossedOverSlow; - bool isAtrUpperCrossedDownPeak; - bool isAtrLowerCrossedDownVale; - bool isStrLowerOverDonLowLower; - bool isVWapFastCrossedUnderMid; - bool isBreakedDownPrevAtrUpper; - bool isBreakedDownPrevAtrLower; - bool isStrUpperCrossedOverPeak; - bool isStrLowerCrossedOverVale; - bool isDonLowLowerEqualsToVale; - bool isVWapFastCrossedOverSlow; - bool isX3MaFastCrossedUnderSlow; - bool isStrUpperOverDonHighUpper; - bool isStrLowerUnderDonLowLower; - bool isVWapFastCrossedUnderSlow; - bool isStrUpperCrossedUnderPeak; - bool isStrLowerCrossedUnderVale; - bool isDonHighUpperEqualsToPeak; - bool isRejectedDownPrevAtrUpper; - bool isRejectedDownPrevAtrLower; - bool isStrUpperUnderDonHighUpper; - bool isStrUpperCrossedOverAtrUpper; - bool isStrLowerCrossedOverAtrLower; - bool isStrUpperCrossedUnderAtrUpper; - bool isStrLowerCrossedUnderAtrLower; - bool isStrLowerCrossedOverDonLowLower; - bool isStrUpperCrossedOverDonHighUpper; - bool isStrLowerCrossedUnderDonLowLower; - bool isStrUpperCrossedUnderDonHighUpper; - - // - // Constructor ... - X121Conditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - // Commons ... - symbol = NULL; - period = NULL; - time = NULL; - - // - // Buffers ... - - // - Clean(maBuffer); - Clean(rsiBuffer); - Clean(atrBuffer); - Clean(strBuffer); - Clean(le1Buffer); - Clean(se1Buffer); - Clean(le2Buffer); - Clean(se2Buffer); - Clean(sarBuffer); - Clean(cHHBuffer); - Clean(cLLBuffer); - Clean(sHHBuffer); - Clean(sLLBuffer); - Clean(mHHBuffer); - Clean(mLLBuffer); - Clean(lHHBuffer); - Clean(lLLBuffer); - Clean(hHHBuffer); - Clean(hLLBuffer); - Clean(upTBuffer); - Clean(adxBuffer); - Clean(adxPBuffer); - Clean(adxMBuffer); - Clean(peaksBuffer); - Clean(valesBuffer); - Clean(strUpBuffer); - Clean(downTBuffer); - Clean(volumeBuffer); - Clean(masMidBuffer); - Clean(strDownBuffer); - Clean(vwapMidBuffer); - Clean(upTrendBuffer); - Clean(x3maMidBuffer); - Clean(masUpperBuffer); - Clean(masLowerBuffer); - Clean(le1StartBuffer); - Clean(se1StartBuffer); - Clean(le2StartBuffer); - Clean(se2StartBuffer); - Clean(strPriceBuffer); - Clean(atrUpperBuffer); - Clean(atrLowerBuffer); - Clean(strStateBuffer); - Clean(vwapFastBuffer); - Clean(vwapSlowBuffer); - Clean(xhkSMLowBuffer); - Clean(x3maFastBuffer); - Clean(x3maSlowBuffer); - Clean(supportsBuffer); - Clean(downTrendBuffer); - Clean(vwapPriceBuffer); - Clean(xhkRawLowBuffer); - Clean(xhkSMOpenBuffer); - Clean(xhkSMHighBuffer); - Clean(xhkRawOpenBuffer); - Clean(xhkRawHighBuffer); - Clean(xhkSMCloseBuffer); - Clean(vwapVolumeBuffer); - Clean(peaksGoldenBuffer); - Clean(valesGoldenBuffer); - Clean(xhkRawCloseBuffer); - Clean(atrUpperRawBuffer); - Clean(atrLowerRawBuffer); - Clean(donLowUpperBuffer); - Clean(donLowLowerBuffer); - Clean(resistancesBuffer); - Clean(vwapMidStateBuffer); - Clean(donOpenUpperBuffer); - Clean(donOpenLowerBuffer); - Clean(donHighUpperBuffer); - Clean(donHighLowerBuffer); - Clean(x3maMidStateBuffer); - Clean(fractalsUpperBuffer); - Clean(fractalsLowerBuffer); - Clean(vwapFastStateBuffer); - Clean(vwapSlowStateBuffer); - Clean(donCloseUpperBuffer); - Clean(donCloseLowerBuffer); - Clean(x3maFastStateBuffer); - Clean(x3maSlowStateBuffer); - // - ArraySetAsSeries(maBuffer, true); - ArraySetAsSeries(rsiBuffer, true); - ArraySetAsSeries(atrBuffer, true); - ArraySetAsSeries(strBuffer, true); - ArraySetAsSeries(le1Buffer, true); - ArraySetAsSeries(se1Buffer, true); - ArraySetAsSeries(le2Buffer, true); - ArraySetAsSeries(se2Buffer, true); - ArraySetAsSeries(sarBuffer, true); - ArraySetAsSeries(cHHBuffer, true); - ArraySetAsSeries(cLLBuffer, true); - ArraySetAsSeries(sHHBuffer, true); - ArraySetAsSeries(sLLBuffer, true); - ArraySetAsSeries(mHHBuffer, true); - ArraySetAsSeries(mLLBuffer, true); - ArraySetAsSeries(lHHBuffer, true); - ArraySetAsSeries(lLLBuffer, true); - ArraySetAsSeries(hHHBuffer, true); - ArraySetAsSeries(hLLBuffer, true); - ArraySetAsSeries(upTBuffer, true); - ArraySetAsSeries(adxBuffer, true); - ArraySetAsSeries(adxPBuffer, true); - ArraySetAsSeries(adxMBuffer, true); - ArraySetAsSeries(peaksBuffer, true); - ArraySetAsSeries(valesBuffer, true); - ArraySetAsSeries(strUpBuffer, true); - ArraySetAsSeries(downTBuffer, true); - ArraySetAsSeries(volumeBuffer, true); - ArraySetAsSeries(masMidBuffer, true); - ArraySetAsSeries(strDownBuffer, true); - ArraySetAsSeries(vwapMidBuffer, true); - ArraySetAsSeries(upTrendBuffer, true); - ArraySetAsSeries(x3maMidBuffer, true); - ArraySetAsSeries(masUpperBuffer, true); - ArraySetAsSeries(masLowerBuffer, true); - ArraySetAsSeries(le1StartBuffer, true); - ArraySetAsSeries(se1StartBuffer, true); - ArraySetAsSeries(le2StartBuffer, true); - ArraySetAsSeries(se2StartBuffer, true); - ArraySetAsSeries(strPriceBuffer, true); - ArraySetAsSeries(atrUpperBuffer, true); - ArraySetAsSeries(atrLowerBuffer, true); - ArraySetAsSeries(strStateBuffer, true); - ArraySetAsSeries(vwapFastBuffer, true); - ArraySetAsSeries(vwapSlowBuffer, true); - ArraySetAsSeries(xhkSMLowBuffer, true); - ArraySetAsSeries(x3maFastBuffer, true); - ArraySetAsSeries(x3maSlowBuffer, true); - ArraySetAsSeries(supportsBuffer, true); - ArraySetAsSeries(downTrendBuffer, true); - ArraySetAsSeries(vwapPriceBuffer, true); - ArraySetAsSeries(xhkRawLowBuffer, true); - ArraySetAsSeries(xhkSMOpenBuffer, true); - ArraySetAsSeries(xhkSMHighBuffer, true); - ArraySetAsSeries(xhkRawOpenBuffer, true); - ArraySetAsSeries(xhkRawHighBuffer, true); - ArraySetAsSeries(xhkSMCloseBuffer, true); - ArraySetAsSeries(vwapVolumeBuffer, true); - ArraySetAsSeries(peaksGoldenBuffer, true); - ArraySetAsSeries(valesGoldenBuffer, true); - ArraySetAsSeries(xhkRawCloseBuffer, true); - ArraySetAsSeries(atrUpperRawBuffer, true); - ArraySetAsSeries(atrLowerRawBuffer, true); - ArraySetAsSeries(donLowUpperBuffer, true); - ArraySetAsSeries(donLowLowerBuffer, true); - ArraySetAsSeries(resistancesBuffer, true); - ArraySetAsSeries(vwapMidStateBuffer, true); - ArraySetAsSeries(donOpenUpperBuffer, true); - ArraySetAsSeries(donOpenLowerBuffer, true); - ArraySetAsSeries(donHighUpperBuffer, true); - ArraySetAsSeries(donHighLowerBuffer, true); - ArraySetAsSeries(x3maMidStateBuffer, true); - ArraySetAsSeries(fractalsUpperBuffer, true); - ArraySetAsSeries(fractalsLowerBuffer, true); - ArraySetAsSeries(vwapFastStateBuffer, true); - ArraySetAsSeries(vwapSlowStateBuffer, true); - ArraySetAsSeries(donCloseUpperBuffer, true); - ArraySetAsSeries(donCloseLowerBuffer, true); - ArraySetAsSeries(x3maFastStateBuffer, true); - ArraySetAsSeries(x3maSlowStateBuffer, true); - - // - cheMin = 0; - cheMax = 0; - vwapMin = 0; - vwapMax = 0; - x3maMin = 0; - x3maMax = 0; - - // - // Slopes ... - - rsiSlope = 0; - strSlope = 0; - atrUpperSlope = 0; - atrLowerSlope = 0; - vwapFastSlope = 0; - vwapMidSlope = 0; - vwapSlowSlope = 0; - - // - // Conditions ... - - // - isRsiSlopeBullish = false; - isStrSlopeBullish = false; - isAtrUpperSlopeBullish = false; - isAtrLowerSlopeBullish = false; - isVwapFastSlopeBullish = false; - isVwapMidSlopeBullish = false; - isVwapSlowSlopeBullish = false; - - // - isRsiSlopeBearish = false; - isStrSlopeBearish = false; - isAtrUpperSlopeBearish = false; - isAtrLowerSlopeBearish = false; - isVwapFastSlopeBearish = false; - isVwapMidSlopeBearish = false; - isVwapSlowSlopeBearish = false; - - // - // RSI ... - - // - isRsiOverBought = false; - isRsiCrossedOverOverBought = false; - isRsiCrossedUnderOverBought = false; - - // - isRsiOverSold = false; - isRsiCrossedUnderOverSold = false; - isRsiCrossedOverOverSold = false; - - // - // ATR ... - - // - isBreakedUpAtrUpper = false; - isBreakedUpAtrLower = false; - isClosedOverAtrUpper = false; - isClosedOverAtrLower = false; - isRejectedUpAtrUpper = false; - isRejectedUpAtrLower = false; - isClosedUnderAtrUpper = false; - isClosedUnderAtrLower = false; - isBreakedDownAtrUpper = false; - isBreakedDownAtrLower = false; - isRejectedDownAtrUpper = false; - isRejectedDownAtrLower = false; - - // - // DON ... - - // - isRejectedDonOpenUpper = false; - isRejectedDonHighUpper = false; - isRejectedDonLowUpper = false; - isRejectedDonCloseUpper = false; - isRejectedDonOpenLower = false; - isRejectedDonHighLower = false; - isRejectedDonLowLower = false; - isRejectedDonCloseLower = false; - isBreakedDonOpenUpper = false; - isBreakedDonHighUpper = false; - isBreakedDonLowUpper = false; - isBreakedDonCloseUpper = false; - isBreakedDonOpenLower = false; - isBreakedDonHighLower = false; - isBreakedDonLowLower = false; - isBreakedDonCloseLower = false; - - // - // SAR ... - - // - isSarBullish = false; - isSarBearish = false; - isSarSwitchedToBullish = false; - isSarSwitchedToBearish = false; - - // - // PV ... - - // - isNewPeak = false; - isNewPeakOverLast = false; - isNewPeakUnderLast = false; - isRejectedPrevPeak = false; - isBreakedUpPrevPeak = false; - - // - isNewVale = false; - isNewValeOverLast = false; - isNewValeUnderLast = false; - isRejectedPrevVale = false; - isBreakedDownPrevVale = false; - - // - // STR ... - - // - isStrBullish = false; - isStrBearish = false; - isStrSwitchedToBullish = false; - isStrSwitchedToBearish = false; - - // - // VWAP ... - isVWapMidBullish = false; - isVWapMidBearish = false; - isVWapMidNeutural = false; - isVWapSlowBullish = false; - isVWapSlowBearish = false; - isVWapFastBullish = false; - isVWapFastBearish = false; - isVWapFastOverMid = false; - isVWapMidOverSlow = false; - isVWapFastNeutural = false; - isVWapSlowNeutural = false; - isVWapFastUnderMid = false; - isVWapMidUnderSlow = false; - isVWapBullishState = false; - isVWapBearishState = false; - isVWapNeuturalState = false; - isVWapBullishOrdered = false; - isVWapBearishOrdered = false; - isVWapSwitchedToBullishState = false; - isVWapSwitchedToBearishState = false; - isVWapSwitchedToNeuturalState = false; - isVWapSwitchedToBullishOrdered = false; - isVWapSwitchedToBearishOrdered = false; - - // - // X3MA ... - isX3MaMidBullish = false; - isX3MaMidBearish = false; - isX3MaFastBullish = false; - isX3MaFastBearish = false; - isX3MaMidNeutural = false; - isX3MaSlowBullish = false; - isX3MaSlowBearish = false; - isX3MaFastOverMid = false; - isX3MaMidOverSlow = false; - isX3MaFastNeutural = false; - isX3MaSlowNeutural = false; - isX3MaFastUnderMid = false; - isX3MaMidUnderSlow = false; - isX3MaBullishState = false; - isX3MaBearishState = false; - isX3MaNeuturalState = false; - isX3MaBullishOrdered = false; - isX3MaBearishOrdered = false; - isX3MaSwitchedToBullishState = false; - isX3MaSwitchedToBearishState = false; - isX3MaSwitchedToNeuturalState = false; - isX3MaSwitchedToBullishOrdered = false; - isX3MaSwitchedToBearishOrdered = false; - - // - // CHE ... - - // - isCheBullish = false; - isCheBearish = false; - isChe1Bullish = false; - isChe1Bearish = false; - isChe2Bullish = false; - isChe2Bearish = false; - isClosedOverCheMin = false; - isClosedOverCheMax = false; - isClosedUnderCheMin = false; - isClosedUnderCheMax = false; - isCheSwitchedToBullish = false; - isCheSwitchedToBearish = false; - isChe1SwitchedToBullish = false; - isChe1SwitchedToBearish = false; - isChe2SwitchedToBullish = false; - isChe2SwitchedToBearish = false; - - // - // XHK ... - isSMHKBullish = false; - isRawHKBullish = false; - isSMHKBearish = false; - isRawHKBearish = false; - isBreakedUpSMHK = false; - isBreakedUpRawHK = false; - isRejectedUpSMHK = false; - isClosedOverSMHK = false; - isRejectedUpRawHK = false; - isBreakedDownSMHK = false; - isClosedUnderSMHK = false; - isClosedOverRawHK = false; - isClosedUnderRawHK = false; - isBreakedDownRawHK = false; - isRejectedDownSMHK = false; - isRejectedDownRawHK = false; - isRawHKBreakedUpSMHK = false; - isRawHKClosedOverSMHK = false; - isSMHKSwitchedToBearish = false; - isRawHKSwitchedToBearish = false; - isRawHKClosedUnderSMHK = false; - isRawHKBreakedDownSMHK = false; - isSMHKSwitchedToBullish = false; - isRawHKSwitchedToBullish = false; - - // - // Complex Conditions ... - - // - isSarIncreased = false; - isSarDecreased = false; - isX3MaFatsOverMid = false; - isSarEqualsToPeak = false; - isSarEqualsToVale = false; - isStrEqualsToPeak = false; - isStrEqualsToVale = false; - isX3MaMinBreakedUp = false; - isX3MaMaxBreakedUp = false; - isX3MaFatsUnderMid = false; - isX3MaFatsOverSlow = false; - isAtrUpperOverPeak = false; - isPeakOverAtrUpper = false; - isStrUpperOverPeak = false; - isStrLowerOverVale = false; - isBreakedUpPrevSar = false; - isBreakedUpPrevStr = false; - isVWapMinBreakedUp = false; - isVWapMaxBreakedUp = false; - isClosedOverCheMin = false; - isClosedOverCheMax = false; - isX3MaFatsUnderSlow = false; - isAtrLowerUnderVale = false; - isClosedOverX3MaMin = false; - isClosedOverX3MaMax = false; - isValeUnderAtrLower = false; - isStrUpperUnderPeak = false; - isStrLowerUnderVale = false; - isClosedUnderCheMin = false; - isClosedUnderCheMax = false; - isClosedOverVWapMin = false; - isClosedOverVWapMax = false; - isX3MaMinBreakedDown = false; - isX3MaMaxBreakedDown = false; - isClosedUnderX3MaMin = false; - isClosedUnderX3MaMax = false; - isBreakedDownPrevSar = false; - isBreakedDownPrevStr = false; - isStrCrossedOverVale = false; - isSarCrossedOverVale = false; - isClosedUnderVWapMin = false; - isClosedUnderVWapMax = false; - isVWapMinBreakedDown = false; - isVWapMaxBreakedDown = false; - isX3MaFatsOverMidPrev = false; - isSarCrossedUnderPeak = false; - isStrCrossedUnderPeak = false; - isNewPeakOverAtrUpper = false; - isBreakedUpPrevCheMin = false; - isBreakedUpPrevCheMax = false; - isBreakedUpPrevCheLE1 = false; - isBreakedUpPrevCheLE2 = false; - isBreakedUpPrevCheSE1 = false; - isBreakedUpPrevCheSE2 = false; - isX3MaFatsUnderMidPrev = false; - isX3MaFatsOverSlowPrev = false; - isAtrUpperEqualsToPeak = false; - isAtrLowerEqualsToVale = false; - isStrUpperOverAtrUpper = false; - isStrLowerOverAtrLower = false; - isNewValeUnderAtrLower = false; - isAtrUpperCrossedUpPeak = false; - isAtrLowerCrossedUpVale = false; - isStrUpperUnderAtrUpper = false; - isStrLowerUnderAtrLower = false; - isX3MaFatsUnderSlowPrev = false; - isBreakedUpPrevAtrUpper = false; - isBreakedUpPrevAtrLower = false; - isBreakedDownPrevCheMin = false; - isBreakedDownPrevCheMax = false; - isBreakedDownPrevCheLE1 = false; - isBreakedDownPrevCheLE2 = false; - isBreakedDownPrevCheSE1 = false; - isBreakedDownPrevCheSE2 = false; - isX3MaFastCrossedOverMid = false; - isRejectedUpPrevAtrUpper = false; - isRejectedUpPrevAtrLower = false; - isVWapFastCrossedOverMid = false; - isX3MaFastCrossedUnderMid = false; - isX3MaFastCrossedOverSlow = false; - isAtrUpperCrossedDownPeak = false; - isAtrLowerCrossedDownVale = false; - isStrLowerOverDonLowLower = false; - isVWapFastCrossedUnderMid = false; - isBreakedDownPrevAtrUpper = false; - isBreakedDownPrevAtrLower = false; - isStrUpperCrossedOverPeak = false; - isStrLowerCrossedOverVale = false; - isDonLowLowerEqualsToVale = false; - isVWapFastCrossedOverSlow = false; - isX3MaFastCrossedUnderSlow = false; - isStrUpperOverDonHighUpper = false; - isStrLowerUnderDonLowLower = false; - isVWapFastCrossedUnderSlow = false; - isStrUpperCrossedUnderPeak = false; - isStrLowerCrossedUnderVale = false; - isDonHighUpperEqualsToPeak = false; - isRejectedDownPrevAtrUpper = false; - isRejectedDownPrevAtrLower = false; - isStrUpperUnderDonHighUpper = false; - isStrUpperCrossedOverAtrUpper = false; - isStrLowerCrossedOverAtrLower = false; - isStrUpperCrossedUnderAtrUpper = false; - isStrLowerCrossedUnderAtrLower = false; - isStrLowerCrossedOverDonLowLower = false; - isStrUpperCrossedOverDonHighUpper = false; - isStrLowerCrossedUnderDonLowLower = false; - isStrUpperCrossedUnderDonHighUpper = false; - - // - ZeroMemory(this); - } - - /** - * Generate Conditions Scores ... - * - * @param bullishScore: Double, Directional Scores Reference ... - * @param bearishScore: Double, Directional Scores Reference ... - */ - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - double score = 1; - double minScore = 0.5; - double highScore = 1.5; - - // - // SLOPES ... - - // - if (isRsiSlopeBullish) - { - bullishScore += minScore; - } - if (isStrSlopeBullish) - { - bullishScore += minScore; - } - if (isAtrUpperSlopeBullish) - { - bullishScore += minScore; - } - if (isAtrLowerSlopeBullish) - { - bullishScore += minScore; - } - if (isVwapFastSlopeBullish) - { - bullishScore += minScore; - } - if (isVwapMidSlopeBullish) - { - bullishScore += minScore; - } - if (isVwapSlowSlopeBullish) - { - bullishScore += minScore; - } - - // - if (isRsiSlopeBearish) - { - bearishScore += minScore; - } - if (isStrSlopeBearish) - { - bearishScore += minScore; - } - if (isAtrUpperSlopeBearish) - { - bearishScore += minScore; - } - if (isAtrLowerSlopeBearish) - { - bearishScore += minScore; - } - if (isVwapFastSlopeBearish) - { - bearishScore += minScore; - } - if (isVwapMidSlopeBearish) - { - bearishScore += minScore; - } - if (isVwapSlowSlopeBearish) - { - bearishScore += minScore; - } - - // - // COMPLEX ... - - // - if (isRsiOverSold) - { - bullishScore += score; - } - if (isRsiCrossedUnderOverSold) - { - bullishScore += highScore; - } - - // - if (isRsiOverBought) - { - bearishScore += score; - } - if (isRsiCrossedOverOverBought) - { - bearishScore += highScore; - } - - // - // XTREND ... - - // - if (isTrendBullish) - { - bullishScore += minScore; - } - if (isTrendSwitchedToBullish) - { - bullishScore += score; - } - - // - if (isTrendBearish) - { - bearishScore += minScore; - } - if (isTrendSwitchedToBearish) - { - bearishScore += score; - } - - // - // XSAR ... - - // - if (isSarBullish) - { - bullishScore += minScore; - } - if (isSarSwitchedToBullish) - { - bullishScore += score; - } - - // - if (isSarBearish) - { - bearishScore += minScore; - } - if (isSarSwitchedToBearish) - { - bearishScore += score; - } - - // - // XSTR ... - - // - if (isStrBullish) - { - bullishScore += minScore; - } - if (isStrSwitchedToBullish) - { - bullishScore += score; - } - - // - if (isStrBearish) - { - bearishScore += minScore; - } - if (isStrSwitchedToBearish) - { - bearishScore += score; - } - - // - // XCHE ... - - // - if (isCheBullish) - { - bullishScore += score; - } - if (isCheSwitchedToBullish) - { - bullishScore += highScore; - } - if (isChe1Bullish && - !isCheBullish && - !isCheSwitchedToBullish) - { - bullishScore += minScore; - } - if (isChe1SwitchedToBullish && - !isCheBullish && - !isCheSwitchedToBullish) - { - bullishScore += minScore; - } - - // - if (isCheBearish) - { - bearishScore += score; - } - if (isCheSwitchedToBearish) - { - bearishScore += highScore; - } - if (isChe1Bearish && - !isCheBearish && - !isCheSwitchedToBearish) - { - bearishScore += minScore; - } - if (isChe1SwitchedToBearish && - !isCheBearish && - !isCheSwitchedToBearish) - { - bearishScore += minScore; - } - - // - // XVWAP ... - - // - if (isVWapBullishState) - { - bullishScore += score; - } - if (isVWapBullishOrdered) - { - bullishScore += score; - } - if (isVWapSwitchedToBullishState) - { - bullishScore += highScore; - } - if (isVWapSwitchedToBullishOrdered) - { - bullishScore += highScore; - } - if (!isVWapBullishState && - !isVWapSwitchedToBullishState) - { - // - if (isVWapFastBullish) - { - bullishScore += minScore; - } - if (isVWapSlowBullish) - { - bullishScore += minScore; - } - } - if (!isVWapBullishOrdered && - !isVWapSwitchedToBullishOrdered) - { - // - if (isVWapFastOverMid) - { - bullishScore += minScore; - } - if (isVWapMidOverSlow) - { - bullishScore += minScore; - } - } - - // - if (isVWapBearishState) - { - bearishScore += score; - } - if (isVWapBearishOrdered) - { - bearishScore += score; - } - if (isVWapSwitchedToBearishState) - { - bearishScore += highScore; - } - if (isVWapSwitchedToBearishOrdered) - { - bearishScore += highScore; - } - if (!isVWapBearishState && - !isVWapSwitchedToBearishState) - { - // - if (isVWapFastBearish) - { - bearishScore += minScore; - } - if (isVWapSlowBearish) - { - bearishScore += minScore; - } - } - if (!isVWapBearishOrdered && - !isVWapSwitchedToBearishOrdered) - { - // - if (isVWapFastUnderMid) - { - bearishScore += minScore; - } - if (isVWapMidUnderSlow) - { - bearishScore += minScore; - } - } - - // - // X3MA ... - - // - if (isX3MaBullishState) - { - bullishScore += score; - } - if (isX3MaBullishOrdered) - { - bullishScore += score; - } - if (isX3MaSwitchedToBullishState) - { - bullishScore += highScore; - } - if (isX3MaSwitchedToBullishOrdered) - { - bullishScore += highScore; - } - if (!isX3MaBullishState && - !isX3MaSwitchedToBullishState) - { - // - if (isX3MaFastBullish) - { - bullishScore += minScore; - } - if (isX3MaSlowBullish) - { - bullishScore += minScore; - } - } - if (!isX3MaBullishOrdered && - !isX3MaSwitchedToBullishOrdered) - { - // - if (isX3MaFastOverMid) - { - bullishScore += minScore; - } - if (isX3MaMidOverSlow) - { - bullishScore += minScore; - } - } - - // - if (isX3MaBearishState) - { - bearishScore += score; - } - if (isX3MaBearishOrdered) - { - bearishScore += score; - } - if (isX3MaSwitchedToBearishState) - { - bearishScore += highScore; - } - if (isX3MaSwitchedToBearishOrdered) - { - bearishScore += highScore; - } - if (!isX3MaBearishState && - !isX3MaSwitchedToBearishState) - { - // - if (isX3MaFastBearish) - { - bearishScore += minScore; - } - if (isX3MaSlowBearish) - { - bearishScore += minScore; - } - } - if (!isX3MaBearishOrdered && - !isX3MaSwitchedToBearishOrdered) - { - // - if (isX3MaFastUnderMid) - { - bearishScore += minScore; - } - if (isX3MaMidUnderSlow) - { - bearishScore += minScore; - } - } - - // - // XSMHK ... - - // - if (isSMHKBullish) - { - bullishScore += minScore; - } - if (isRawHKBullish) - { - bullishScore += minScore; - } - if (isClosedOverSMHK) - { - bullishScore += minScore; - } - if (isClosedOverRawHK) - { - bullishScore += minScore; - } - if (isRawHKClosedOverSMHK) - { - bullishScore += minScore; - } - if (isSMHKSwitchedToBullish) - { - bullishScore += highScore; - } - if (isRawHKSwitchedToBullish) - { - bullishScore += highScore; - } - - // - if (isSMHKBearish) - { - bearishScore += minScore; - } - if (isRawHKBearish) - { - bearishScore += minScore; - } - if (isClosedUnderSMHK) - { - bearishScore += minScore; - } - if (isClosedUnderRawHK) - { - bearishScore += minScore; - } - if (isRawHKClosedUnderSMHK) - { - bearishScore += minScore; - } - if (isSMHKSwitchedToBearish) - { - bearishScore += highScore; - } - if (isRawHKSwitchedToBullish) - { - bearishScore += highScore; - } - - // - // Complex Conditions ... - - // - if (isSarIncreased) - { - bullishScore += minScore; - } - if (isSarEqualsToVale) - { - bullishScore += minScore; - } - if (isBreakedUpPrevSar) - { - bullishScore += minScore; - } - if (isSarCrossedOverVale) - { - bullishScore += score; - } - - // - if (isAtrLowerUnderVale) - { - bullishScore += minScore; - } - if (isValeUnderAtrLower) - { - bullishScore += minScore; - } - if (isNewValeUnderAtrLower) - { - bullishScore += minScore; - } - if (isAtrLowerEqualsToVale) - { - bullishScore += minScore; - } - if (isStrLowerOverAtrLower) - { - bullishScore += minScore; - } - if (isStrUpperOverAtrUpper) - { - bullishScore += minScore; - } - if (isAtrLowerCrossedUpVale) - { - bullishScore += score; - } - if (isAtrUpperCrossedUpPeak) - { - bullishScore += score; - } - if (isBreakedUpPrevAtrLower) - { - bullishScore += minScore; - } - if (isBreakedUpPrevAtrUpper) - { - bullishScore += minScore; - } - if (isRejectedUpPrevAtrUpper) - { - bullishScore += minScore; - } - if (isRejectedUpPrevAtrLower) - { - bullishScore += minScore; - } - if (isStrLowerCrossedOverAtrLower) - { - bullishScore += score; - } - if (isStrUpperCrossedOverAtrUpper) - { - bullishScore += score; - } - - // - if (isBreakedUpPrevStr) - { - bullishScore += minScore; - } - if (isStrEqualsToVale) - { - bullishScore += minScore; - } - if (isStrLowerOverVale) - { - bullishScore += minScore; - } - if (isStrLowerUnderVale) - { - bullishScore += minScore; - } - if (isStrCrossedOverVale) - { - bullishScore += score; - } - if (isStrUpperCrossedOverPeak) - { - bullishScore += score; - } - if (isStrLowerCrossedOverVale) - { - bullishScore += score; - } - if (isStrLowerUnderDonLowLower) - { - bullishScore += minScore; - } - if (isStrLowerCrossedOverDonLowLower) - { - bullishScore += score; - } - if (isStrUpperCrossedOverDonHighUpper) - { - bullishScore += score; - } - - // - if (isVWapMinBreakedUp) - { - bullishScore += minScore; - } - if (isVWapMaxBreakedUp) - { - bullishScore += minScore; - } - if (isClosedOverVWapMin) - { - bullishScore += minScore; - } - if (isClosedOverVWapMax) - { - bullishScore += minScore; - } - if (isVWapFastCrossedOverMid) - { - bullishScore += score; - } - if (isVWapFastCrossedOverSlow) - { - bullishScore += score; - } - - // - if (isX3MaMinBreakedUp) - { - bullishScore += minScore; - } - if (isX3MaMaxBreakedUp) - { - bullishScore += minScore; - } - if (isClosedOverX3MaMin) - { - bullishScore += minScore; - } - if (isClosedOverX3MaMax) - { - bullishScore += minScore; - } - if (isX3MaFastCrossedOverMid) - { - bullishScore += score; - } - if (isX3MaFastCrossedOverSlow) - { - bullishScore += score; - } - - // - if (isClosedOverCheMin) - { - bullishScore += minScore; - } - if (isClosedOverCheMax) - { - bullishScore += minScore; - } - if (isBreakedUpPrevCheMin) - { - bullishScore += minScore; - } - if (isBreakedUpPrevCheMax) - { - bullishScore += minScore; - } - if (isBreakedUpPrevCheLE1) - { - bullishScore += minScore; - } - if (isBreakedUpPrevCheLE2) - { - bullishScore += minScore; - } - if (isBreakedUpPrevCheSE1) - { - bullishScore += minScore; - } - if (isBreakedUpPrevCheSE2) - { - bullishScore += minScore; - } - if (isDonLowLowerEqualsToVale) - { - bullishScore += minScore; - } - - // - // - // - - // - if (isSarDecreased) - { - bearishScore += minScore; - } - if (isSarEqualsToPeak) - { - bearishScore += minScore; - } - if (isBreakedDownPrevSar) - { - bearishScore += minScore; - } - if (isSarCrossedUnderPeak) - { - bearishScore += score; - } - - // - if (isAtrUpperOverPeak) - { - bearishScore += minScore; - } - if (isPeakOverAtrUpper) - { - bearishScore += minScore; - } - if (isNewPeakOverAtrUpper) - { - bearishScore += minScore; - } - if (isAtrUpperEqualsToPeak) - { - bearishScore += minScore; - } - if (isStrLowerUnderAtrLower) - { - bearishScore += minScore; - } - if (isStrUpperUnderAtrUpper) - { - bearishScore += minScore; - } - if (isAtrLowerCrossedDownVale) - { - bearishScore += score; - } - if (isAtrUpperCrossedDownPeak) - { - bearishScore += score; - } - if (isBreakedDownPrevAtrUpper) - { - bearishScore += minScore; - } - if (isBreakedDownPrevAtrLower) - { - bearishScore += minScore; - } - if (isRejectedDownPrevAtrUpper) - { - bearishScore += minScore; - } - if (isRejectedDownPrevAtrLower) - { - bearishScore += minScore; - } - if (isStrLowerCrossedUnderAtrLower) - { - bearishScore += score; - } - if (isStrUpperCrossedUnderAtrUpper) - { - bearishScore += score; - } - - // - if (isStrEqualsToPeak) - { - bearishScore += minScore; - } - if (isStrUpperOverPeak) - { - bearishScore += minScore; - } - if (isStrUpperUnderPeak) - { - bearishScore += minScore; - } - if (isBreakedDownPrevStr) - { - bearishScore += minScore; - } - if (isStrCrossedUnderPeak) - { - bearishScore += score; - } - if (isStrLowerOverDonLowLower) - { - bearishScore += minScore; - } - if (isStrUpperOverDonHighUpper) - { - bearishScore += minScore; - } - if (isStrUpperCrossedUnderPeak) - { - bearishScore += score; - } - if (isStrLowerCrossedUnderVale) - { - bearishScore += score; - } - if (isStrUpperUnderDonHighUpper) - { - bearishScore += minScore; - } - if (isStrLowerCrossedUnderDonLowLower) - { - bearishScore += score; - } - if (isStrUpperCrossedUnderDonHighUpper) - { - bearishScore += score; - } - - // - if (isClosedUnderVWapMin) - { - bearishScore += minScore; - } - if (isClosedUnderVWapMax) - { - bearishScore += minScore; - } - if (isVWapMinBreakedDown) - { - bearishScore += minScore; - } - if (isVWapMaxBreakedDown) - { - bearishScore += minScore; - } - if (isVWapFastCrossedUnderMid) - { - bearishScore += score; - } - if (isVWapFastCrossedUnderSlow) - { - bearishScore += score; - } - - // - if (isX3MaMinBreakedDown) - { - bearishScore += minScore; - } - if (isX3MaMaxBreakedDown) - { - bearishScore += minScore; - } - if (isClosedUnderX3MaMin) - { - bearishScore += minScore; - } - if (isClosedUnderX3MaMax) - { - bearishScore += minScore; - } - if (isX3MaFastCrossedUnderMid) - { - bearishScore += score; - } - if (isX3MaFastCrossedUnderSlow) - { - bearishScore += score; - } - - // - if (isClosedUnderCheMin) - { - bearishScore += minScore; - } - if (isClosedUnderCheMax) - { - bearishScore += minScore; - } - if (isBreakedDownPrevCheMin) - { - bearishScore += minScore; - } - if (isBreakedDownPrevCheMax) - { - bearishScore += minScore; - } - if (isBreakedDownPrevCheLE1) - { - bearishScore += minScore; - } - if (isBreakedDownPrevCheLE2) - { - bearishScore += minScore; - } - if (isBreakedDownPrevCheSE1) - { - bearishScore += minScore; - } - if (isBreakedDownPrevCheSE2) - { - bearishScore += minScore; - } - if (isDonHighUpperEqualsToPeak) - { - bearishScore += minScore; - } - - // - // - // - } - - /** - * Generate Summary String for Represent Conditions State ... - * - * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... - * @param onlyConditions: Boolean, Just Generate Only Conditions ... - * @param includeScores: Boolean, Attach Scores Representations on Result ... - * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... - * @param separator: String, Separate Lines ... - * - * @return ( string ) - */ - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string scoresStr = - // - "Scores: " + separator + - "---------------" + separator + - "Bullish: " + ToString(bullishScore) + separator + - "Bearish: " + ToString(bearishScore) + separator + - "" - // - ; - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores // - ); - - // - string conditionsStr = - // - "-----------------------" + separator + - "SAR ..." + separator + - "-----------------------" + separator + - ToString("isSarBullish", isSarBullish, ignoreFalseConditions, separator) + - ToString("isSarBearish", isSarBearish, ignoreFalseConditions, separator) + - ToString("isSarSwitchedToBullish", isSarSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isSarSwitchedToBearish", isSarSwitchedToBearish, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "Trend ..." + separator + - "-----------------------" + separator + - ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) + - ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) + - ToString("isTrendSwitchedToBullish", isTrendSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isTrendSwitchedToBearish", isTrendSwitchedToBearish, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "STR ..." + separator + - "-----------------------" + separator + - ToString("isStrBullish", isStrBullish, ignoreFalseConditions, separator) + - ToString("isStrBearish", isStrBearish, ignoreFalseConditions, separator) + - ToString("isStrSwitchedToBullish", isStrSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isStrSwitchedToBearish", isStrSwitchedToBearish, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "PV ..." + separator + - "-----------------------" + separator + - 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 + - "-----------------------" + separator + - ToString("isRsiOverBought", isRsiOverBought, ignoreFalseConditions, separator) + - ToString("isRsiCrossedOverOverBought", isRsiCrossedOverOverBought, ignoreFalseConditions, separator) + - ToString("isRsiCrossedUnderOverBought", isRsiCrossedUnderOverBought, ignoreFalseConditions, separator) + - ToString("isRsiOverSold", isRsiOverSold, ignoreFalseConditions, separator) + - ToString("isRsiCrossedUnderOverSold", isRsiCrossedUnderOverSold, ignoreFalseConditions, separator) + - ToString("isRsiCrossedOverOverSold", isRsiCrossedOverOverSold, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "ATR ..." + separator + - "-----------------------" + separator + - ToString("isClosedOverAtrUpper", isClosedOverAtrUpper, ignoreFalseConditions, separator) + - ToString("isClosedOverAtrLower", isClosedOverAtrLower, ignoreFalseConditions, separator) + - ToString("isClosedUnderAtrUpper", isClosedUnderAtrUpper, ignoreFalseConditions, separator) + - ToString("isClosedUnderAtrLower", isClosedUnderAtrLower, ignoreFalseConditions, separator) + - ToString("isRejectedUpAtrUpper", isRejectedUpAtrUpper, ignoreFalseConditions, separator) + - ToString("isRejectedDownAtrUpper", isRejectedDownAtrUpper, ignoreFalseConditions, separator) + - ToString("isRejectedUpAtrLower", isRejectedUpAtrLower, ignoreFalseConditions, separator) + - ToString("isRejectedDownAtrLower", isRejectedDownAtrLower, ignoreFalseConditions, separator) + - ToString("isBreakedUpAtrUpper", isBreakedUpAtrUpper, ignoreFalseConditions, separator) + - ToString("isBreakedDownAtrUpper", isBreakedDownAtrUpper, ignoreFalseConditions, separator) + - ToString("isBreakedUpAtrLower", isBreakedUpAtrLower, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "DON ..." + separator + - "-----------------------" + separator + - ToString("isBreakedDownAtrLower", isBreakedDownAtrLower, ignoreFalseConditions, separator) + - ToString("isRejectedDonOpenUpper", isRejectedDonOpenUpper, ignoreFalseConditions, separator) + - ToString("isRejectedDonHighUpper", isRejectedDonHighUpper, ignoreFalseConditions, separator) + - ToString("isRejectedDonLowUpper", isRejectedDonLowUpper, ignoreFalseConditions, separator) + - ToString("isRejectedDonCloseUpper", isRejectedDonCloseUpper, ignoreFalseConditions, separator) + - ToString("isRejectedDonOpenLower", isRejectedDonOpenLower, ignoreFalseConditions, separator) + - ToString("isRejectedDonHighLower", isRejectedDonHighLower, ignoreFalseConditions, separator) + - ToString("isRejectedDonLowLower", isRejectedDonLowLower, ignoreFalseConditions, separator) + - ToString("isRejectedDonCloseLower", isRejectedDonCloseLower, ignoreFalseConditions, separator) + - ToString("isBreakedDonOpenUpper", isBreakedDonOpenUpper, ignoreFalseConditions, separator) + - ToString("isBreakedDonHighUpper", isBreakedDonHighUpper, ignoreFalseConditions, separator) + - ToString("isBreakedDonLowUpper", isBreakedDonLowUpper, ignoreFalseConditions, separator) + - ToString("isBreakedDonCloseUpper", isBreakedDonCloseUpper, ignoreFalseConditions, separator) + - ToString("isBreakedDonOpenLower", isBreakedDonOpenLower, ignoreFalseConditions, separator) + - ToString("isBreakedDonHighLower", isBreakedDonHighLower, ignoreFalseConditions, separator) + - ToString("isBreakedDonLowLower", isBreakedDonLowLower, ignoreFalseConditions, separator) + - ToString("isBreakedDonCloseLower", isBreakedDonCloseLower, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "VWAP ..." + separator + - "-----------------------" + separator + - ToString("isVWapFastBullish", isVWapFastBullish, ignoreFalseConditions, separator) + - ToString("isVWapFastBearish", isVWapFastBearish, ignoreFalseConditions, separator) + - ToString("isVWapFastNeutural", isVWapFastNeutural, ignoreFalseConditions, separator) + - ToString("isVWapMidBullish", isVWapMidBullish, ignoreFalseConditions, separator) + - ToString("isVWapMidBearish", isVWapMidBearish, ignoreFalseConditions, separator) + - ToString("isVWapMidNeutural", isVWapMidNeutural, ignoreFalseConditions, separator) + - ToString("isVWapSlowBullish", isVWapSlowBullish, ignoreFalseConditions, separator) + - ToString("isVWapSlowBearish", isVWapSlowBearish, ignoreFalseConditions, separator) + - ToString("isVWapSlowNeutural", isVWapSlowNeutural, ignoreFalseConditions, separator) + - ToString("isVWapFastOverMid", isVWapFastOverMid, ignoreFalseConditions, separator) + - ToString("isVWapMidOverSlow", isVWapMidOverSlow, ignoreFalseConditions, separator) + - ToString("isVWapFastUnderMid", isVWapFastUnderMid, ignoreFalseConditions, separator) + - ToString("isVWapMidUnderSlow", isVWapMidUnderSlow, ignoreFalseConditions, separator) + - ToString("isVWapBullishState", isVWapBullishState, ignoreFalseConditions, separator) + - ToString("isVWapBearishState", isVWapBearishState, ignoreFalseConditions, separator) + - ToString("isVWapNeuturalState", isVWapNeuturalState, ignoreFalseConditions, separator) + - ToString("isVWapBullishOrdered", isVWapBullishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapBearishOrdered", isVWapBearishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBullishOrdered", isVWapSwitchedToBullishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBearishOrdered", isVWapSwitchedToBearishOrdered, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBullishState", isVWapSwitchedToBullishState, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToBearishState", isVWapSwitchedToBearishState, ignoreFalseConditions, separator) + - ToString("isVWapSwitchedToNeuturalState", isVWapSwitchedToNeuturalState, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "X3MA ..." + separator + - "-----------------------" + separator + - ToString("isX3MaMidBullish", isX3MaMidBullish, ignoreFalseConditions, separator) + - ToString("isX3MaMidBearish", isX3MaMidBearish, ignoreFalseConditions, separator) + - ToString("isX3MaFastBullish", isX3MaFastBullish, ignoreFalseConditions, separator) + - ToString("isX3MaFastBearish", isX3MaFastBearish, ignoreFalseConditions, separator) + - ToString("isX3MaMidNeutural", isX3MaMidNeutural, ignoreFalseConditions, separator) + - ToString("isX3MaSlowBullish", isX3MaSlowBullish, ignoreFalseConditions, separator) + - ToString("isX3MaSlowBearish", isX3MaSlowBearish, ignoreFalseConditions, separator) + - ToString("isX3MaFastOverMid", isX3MaFastOverMid, ignoreFalseConditions, separator) + - ToString("isX3MaMidOverSlow", isX3MaMidOverSlow, ignoreFalseConditions, separator) + - ToString("isX3MaFastNeutural", isX3MaFastNeutural, ignoreFalseConditions, separator) + - ToString("isX3MaSlowNeutural", isX3MaSlowNeutural, ignoreFalseConditions, separator) + - ToString("isX3MaFastUnderMid", isX3MaFastUnderMid, ignoreFalseConditions, separator) + - ToString("isX3MaMidUnderSlow", isX3MaMidUnderSlow, ignoreFalseConditions, separator) + - ToString("isX3MaBullishState", isX3MaBullishState, ignoreFalseConditions, separator) + - ToString("isX3MaBearishState", isX3MaBearishState, ignoreFalseConditions, separator) + - ToString("isX3MaNeuturalState", isX3MaNeuturalState, ignoreFalseConditions, separator) + - ToString("isX3MaBullishOrdered", isX3MaBullishOrdered, ignoreFalseConditions, separator) + - ToString("isX3MaBearishOrdered", isX3MaBearishOrdered, ignoreFalseConditions, separator) + - ToString("isX3MaSwitchedToBullishState", isX3MaSwitchedToBullishState, ignoreFalseConditions, separator) + - ToString("isX3MaSwitchedToBearishState", isX3MaSwitchedToBearishState, ignoreFalseConditions, separator) + - ToString("isX3MaSwitchedToNeuturalState", isX3MaSwitchedToNeuturalState, ignoreFalseConditions, separator) + - ToString("isX3MaSwitchedToBullishOrdered", isX3MaSwitchedToBullishOrdered, ignoreFalseConditions, separator) + - ToString("isX3MaSwitchedToBearishOrdered", isX3MaSwitchedToBearishOrdered, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "CHE ..." + separator + - "-----------------------" + separator + - ToString("isChe1Bullish", isChe1Bullish, ignoreFalseConditions, separator) + - ToString("isChe1Bearish", isChe1Bearish, ignoreFalseConditions, separator) + - ToString("isChe1SwitchedToBullish", isChe1SwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isChe1SwitchedToBearish", isChe1SwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isChe2Bullish", isChe2Bullish, ignoreFalseConditions, separator) + - ToString("isChe2Bearish", isChe2Bearish, ignoreFalseConditions, separator) + - ToString("isChe2SwitchedToBullish", isChe2SwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isChe2SwitchedToBearish", isChe2SwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isCheBullish", isCheBullish, ignoreFalseConditions, separator) + - ToString("isCheBearish", isCheBearish, ignoreFalseConditions, separator) + - ToString("isCheSwitchedToBullish", isCheSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isCheSwitchedToBearish", isCheSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isClosedOverCheMin", isClosedOverCheMin, ignoreFalseConditions, separator) + - ToString("isClosedOverCheMax", isClosedOverCheMax, ignoreFalseConditions, separator) + - ToString("isClosedUnderCheMin", isClosedUnderCheMin, ignoreFalseConditions, separator) + - ToString("isClosedUnderCheMax", isClosedUnderCheMax, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "HK ..." + separator + - "-----------------------" + separator + - ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) + - ToString("isRawHKBullish", isRawHKBullish, ignoreFalseConditions, separator) + - ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) + - ToString("isRawHKBearish", isRawHKBearish, ignoreFalseConditions, separator) + - ToString("isBreakedUpSMHK", isBreakedUpSMHK, ignoreFalseConditions, separator) + - ToString("isBreakedUpRawHK", isBreakedUpRawHK, ignoreFalseConditions, separator) + - ToString("isRejectedUpSMHK", isRejectedUpSMHK, ignoreFalseConditions, separator) + - ToString("isClosedOverSMHK", isClosedOverSMHK, ignoreFalseConditions, separator) + - ToString("isRejectedUpRawHK", isRejectedUpRawHK, ignoreFalseConditions, separator) + - ToString("isBreakedDownSMHK", isBreakedDownSMHK, ignoreFalseConditions, separator) + - ToString("isClosedUnderSMHK", isClosedUnderSMHK, ignoreFalseConditions, separator) + - ToString("isClosedOverRawHK", isClosedOverRawHK, ignoreFalseConditions, separator) + - ToString("isClosedUnderRawHK", isClosedUnderRawHK, ignoreFalseConditions, separator) + - ToString("isBreakedDownRawHK", isBreakedDownRawHK, ignoreFalseConditions, separator) + - ToString("isRejectedDownSMHK", isRejectedDownSMHK, ignoreFalseConditions, separator) + - ToString("isRejectedDownRawHK", isRejectedDownRawHK, ignoreFalseConditions, separator) + - ToString("isRawHKBreakedUpSMHK", isRawHKBreakedUpSMHK, ignoreFalseConditions, separator) + - ToString("isRawHKClosedOverSMHK", isRawHKClosedOverSMHK, ignoreFalseConditions, separator) + - ToString("isSMHKSwitchedToBearish", isSMHKSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isRawHKSwitchedToBearish", isRawHKSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isRawHKClosedUnderSMHK", isRawHKClosedUnderSMHK, ignoreFalseConditions, separator) + - ToString("isRawHKBreakedDownSMHK", isRawHKBreakedDownSMHK, ignoreFalseConditions, separator) + - ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) + - ToString("isRawHKSwitchedToBullish", isRawHKSwitchedToBullish, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "Slopes ..." + separator + - "-----------------------" + separator + - ToString("isRsiSlopeBullish", isRsiSlopeBullish, ignoreFalseConditions, separator) + - ToString("isStrSlopeBullish", isStrSlopeBullish, ignoreFalseConditions, separator) + - ToString("isAtrUpperSlopeBullish", isAtrUpperSlopeBullish, ignoreFalseConditions, separator) + - ToString("isAtrLowerSlopeBullish", isAtrLowerSlopeBullish, ignoreFalseConditions, separator) + - ToString("isVwapFastSlopeBullish", isVwapFastSlopeBullish, ignoreFalseConditions, separator) + - ToString("isVwapMidSlopeBullish", isVwapMidSlopeBullish, ignoreFalseConditions, separator) + - ToString("isVwapSlowSlopeBullish", isVwapSlowSlopeBullish, ignoreFalseConditions, separator) + - ToString("isRsiSlopeBearish", isRsiSlopeBearish, ignoreFalseConditions, separator) + - ToString("isStrSlopeBearish", isStrSlopeBearish, ignoreFalseConditions, separator) + - ToString("isAtrUpperSlopeBearish", isAtrUpperSlopeBearish, ignoreFalseConditions, separator) + - ToString("isAtrLowerSlopeBearish", isAtrLowerSlopeBearish, ignoreFalseConditions, separator) + - ToString("isVwapFastSlopeBearish", isVwapFastSlopeBearish, ignoreFalseConditions, separator) + - ToString("isVwapMidSlopeBearish", isVwapMidSlopeBearish, ignoreFalseConditions, separator) + - ToString("isVwapSlowSlopeBearish", isVwapSlowSlopeBearish, ignoreFalseConditions, separator) + - // - "-----------------------" + separator + - "Coplex ..." + separator + - "-----------------------" + separator + - ToString("isSarIncreased", isSarIncreased, ignoreFalseConditions, separator) + - ToString("isSarDecreased", isSarDecreased, ignoreFalseConditions, separator) + - ToString("isSarEqualsToPeak", isSarEqualsToPeak, ignoreFalseConditions, separator) + - - ToString("isStrEqualsToPeak", isStrEqualsToPeak, ignoreFalseConditions, separator) + - ToString("isStrEqualsToVale", isStrEqualsToVale, ignoreFalseConditions, separator) + - ToString("isPeakOverAtrUpper", isPeakOverAtrUpper, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevSar", isBreakedUpPrevSar, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevStr", isBreakedUpPrevStr, ignoreFalseConditions, separator) + - ToString("isVWapMinBreakedUp", isVWapMinBreakedUp, ignoreFalseConditions, separator) + - ToString("isVWapMaxBreakedUp", isVWapMaxBreakedUp, ignoreFalseConditions, separator) + - ToString("isStrUpperOverPeak", isStrUpperOverPeak, ignoreFalseConditions, separator) + - ToString("isStrLowerOverVale", isStrLowerOverVale, ignoreFalseConditions, separator) + - ToString("isAtrUpperOverPeak", isAtrUpperOverPeak, ignoreFalseConditions, separator) + - ToString("isAtrLowerUnderVale", isAtrLowerUnderVale, ignoreFalseConditions, separator) + - ToString("isClosedOverVWapMin", isClosedOverVWapMin, ignoreFalseConditions, separator) + - ToString("isClosedOverVWapMax", isClosedOverVWapMax, ignoreFalseConditions, separator) + - ToString("isStrUpperUnderPeak", isStrUpperUnderPeak, ignoreFalseConditions, separator) + - ToString("isValeUnderAtrLower", isValeUnderAtrLower, ignoreFalseConditions, separator) + - ToString("isStrLowerUnderVale", isStrLowerUnderVale, ignoreFalseConditions, separator) + - ToString("isVWapMinBreakedDown", isVWapMinBreakedDown, ignoreFalseConditions, separator) + - ToString("isVWapMaxBreakedDown", isVWapMaxBreakedDown, ignoreFalseConditions, separator) + - ToString("isClosedUnderVWapMin", isClosedUnderVWapMin, ignoreFalseConditions, separator) + - ToString("isClosedUnderVWapMax", isClosedUnderVWapMax, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevSar", isBreakedDownPrevSar, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevStr", isBreakedDownPrevStr, ignoreFalseConditions, separator) + - ToString("isSarCrossedOverVale", isSarCrossedOverVale, ignoreFalseConditions, separator) + - ToString("isStrCrossedOverVale", isStrCrossedOverVale, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevCheLE1", isBreakedUpPrevCheLE1, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevCheLE2", isBreakedUpPrevCheLE2, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevCheSE1", isBreakedUpPrevCheSE1, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevCheSE2", isBreakedUpPrevCheSE2, ignoreFalseConditions, separator) + - ToString("isSarCrossedUnderPeak", isSarCrossedUnderPeak, ignoreFalseConditions, separator) + - ToString("isStrCrossedUnderPeak", isStrCrossedUnderPeak, ignoreFalseConditions, separator) + - ToString("isNewPeakOverAtrUpper", isNewPeakOverAtrUpper, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevCheMin", isBreakedUpPrevCheMin, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevCheMax", isBreakedUpPrevCheMax, ignoreFalseConditions, separator) + - ToString("isNewValeUnderAtrLower", isNewValeUnderAtrLower, ignoreFalseConditions, separator) + - ToString("isStrUpperOverAtrUpper", isStrUpperOverAtrUpper, ignoreFalseConditions, separator) + - ToString("isStrLowerOverAtrLower", isStrLowerOverAtrLower, ignoreFalseConditions, separator) + - ToString("isAtrUpperEqualsToPeak", isAtrUpperEqualsToPeak, ignoreFalseConditions, separator) + - ToString("isAtrLowerEqualsToVale", isAtrLowerEqualsToVale, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevCheMin", isBreakedDownPrevCheMin, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevCheMax", isBreakedDownPrevCheMax, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevCheLE1", isBreakedDownPrevCheLE1, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevCheLE2", isBreakedDownPrevCheLE2, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevCheSE1", isBreakedDownPrevCheSE1, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevCheSE2", isBreakedDownPrevCheSE2, ignoreFalseConditions, separator) + - ToString("isAtrUpperCrossedUpPeak", isAtrUpperCrossedUpPeak, ignoreFalseConditions, separator) + - ToString("isAtrLowerCrossedUpVale", isAtrLowerCrossedUpVale, ignoreFalseConditions, separator) + - ToString("isStrUpperUnderAtrUpper", isStrUpperUnderAtrUpper, ignoreFalseConditions, separator) + - ToString("isStrLowerUnderAtrLower", isStrLowerUnderAtrLower, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevAtrUpper", isBreakedUpPrevAtrUpper, ignoreFalseConditions, separator) + - ToString("isBreakedUpPrevAtrLower", isBreakedUpPrevAtrLower, ignoreFalseConditions, separator) + - ToString("isVWapFastCrossedOverMid", isVWapFastCrossedOverMid, ignoreFalseConditions, separator) + - ToString("isRejectedUpPrevAtrUpper", isRejectedUpPrevAtrUpper, ignoreFalseConditions, separator) + - ToString("isRejectedUpPrevAtrLower", isRejectedUpPrevAtrLower, ignoreFalseConditions, separator) + - ToString("isAtrUpperCrossedDownPeak", isAtrUpperCrossedDownPeak, ignoreFalseConditions, separator) + - ToString("isAtrLowerCrossedDownVale", isAtrLowerCrossedDownVale, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevAtrUpper", isBreakedDownPrevAtrUpper, ignoreFalseConditions, separator) + - ToString("isBreakedDownPrevAtrLower", isBreakedDownPrevAtrLower, ignoreFalseConditions, separator) + - ToString("isVWapFastCrossedUnderMid", isVWapFastCrossedUnderMid, ignoreFalseConditions, separator) + - ToString("isVWapFastCrossedOverSlow", isVWapFastCrossedOverSlow, ignoreFalseConditions, separator) + - ToString("isStrUpperCrossedOverPeak", isStrUpperCrossedOverPeak, ignoreFalseConditions, separator) + - ToString("isStrLowerOverDonLowLower", isStrLowerOverDonLowLower, ignoreFalseConditions, separator) + - ToString("isStrLowerCrossedOverVale", isStrLowerCrossedOverVale, ignoreFalseConditions, separator) + - ToString("isDonLowLowerEqualsToVale", isDonLowLowerEqualsToVale, ignoreFalseConditions, separator) + - ToString("isRejectedDownPrevAtrUpper", isRejectedDownPrevAtrUpper, ignoreFalseConditions, separator) + - ToString("isRejectedDownPrevAtrLower", isRejectedDownPrevAtrLower, ignoreFalseConditions, separator) + - ToString("isVWapFastCrossedUnderSlow", isVWapFastCrossedUnderSlow, ignoreFalseConditions, separator) + - ToString("isStrUpperCrossedUnderPeak", isStrUpperCrossedUnderPeak, ignoreFalseConditions, separator) + - ToString("isStrLowerCrossedUnderVale", isStrLowerCrossedUnderVale, ignoreFalseConditions, separator) + - ToString("isDonHighUpperEqualsToPeak", isDonHighUpperEqualsToPeak, ignoreFalseConditions, separator) + - ToString("isStrUpperOverDonHighUpper", isStrUpperOverDonHighUpper, ignoreFalseConditions, separator) + - ToString("isStrLowerUnderDonLowLower", isStrLowerUnderDonLowLower, ignoreFalseConditions, separator) + - ToString("isStrUpperUnderDonHighUpper", isStrUpperUnderDonHighUpper, ignoreFalseConditions, separator) + - ToString("isStrUpperCrossedOverAtrUpper", isStrUpperCrossedOverAtrUpper, ignoreFalseConditions, separator) + - ToString("isStrLowerCrossedOverAtrLower", isStrLowerCrossedOverAtrLower, ignoreFalseConditions, separator) + - ToString("isStrUpperCrossedUnderAtrUpper", isStrUpperCrossedUnderAtrUpper, ignoreFalseConditions, separator) + - ToString("isStrLowerCrossedUnderAtrLower", isStrLowerCrossedUnderAtrLower, ignoreFalseConditions, separator) + - ToString("isStrLowerCrossedOverDonLowLower", isStrLowerCrossedOverDonLowLower, ignoreFalseConditions, separator) + - ToString("isStrUpperCrossedOverDonHighUpper", isStrUpperCrossedOverDonHighUpper, ignoreFalseConditions, separator) + - ToString("isStrLowerCrossedUnderDonLowLower", isStrLowerCrossedUnderDonLowLower, ignoreFalseConditions, separator) + - ToString("isStrUpperCrossedUnderDonHighUpper", isStrUpperCrossedUnderDonHighUpper, ignoreFalseConditions, separator) + - // - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - (onlyConditions - ? "" - : commonStr) + - (!includeScores - ? "" - : scoresStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - /** - * Retrieve nique Tag Identifier ... - * - * @return ( string ) - */ - string GetTag() - { - return GetTypeName(this); - } - - // -}; - -// -// Implementation ... -class XCX121Helper : public XCBase -{ - // - public: - // - - // - // Helpers ... - XCX121XCCHelper *xccHelper; - XCX121XPVHelper *xpvHelper; - XCX121XHKHelper *xhkHelper; - XCX121XMASHelper *xmasHelper; - XCX121XATRHelper *xatrHelper; - XCX121XSTRHelper *xstrHelper; - XCX121XCHEHelper *xcheHelper; - XCX121XDONHelper *xdonHelper; - XCX121X3MAHelper *x3maHelper; - XCX121XVWAPHelper *xvwapHelper; - XCX121XTRENDHelper *xtrendHelper; - - // - // Constructors ... - XCX121Helper() - { - } - - // - // Deconstructor ... - ~XCX121Helper() - { - // - mInputs.Clean(); - xccInputs.Clean(); - xpvInputs.Clean(); - xhkInputs.Clean(); - xmasInputs.Clean(); - xatrInputs.Clean(); - xdonInputs.Clean(); - xstrInputs.Clean(); - xcheInputs.Clean(); - x3maInputs.Clean(); - xvwapInputs.Clean(); - xtrendInputs.Clean(); - - // - delete xccHelper; - delete xpvHelper; - delete xhkHelper; - delete xmasHelper; - delete xatrHelper; - delete xstrHelper; - delete xcheHelper; - delete xdonHelper; - delete x3maHelper; - delete xvwapHelper; - delete xtrendHelper; - - // - ZeroMemory(xccHelper); - ZeroMemory(xpvHelper); - ZeroMemory(xhkHelper); - ZeroMemory(xmasHelper); - ZeroMemory(xatrHelper); - ZeroMemory(xstrHelper); - ZeroMemory(xcheHelper); - ZeroMemory(xdonHelper); - ZeroMemory(x3maHelper); - ZeroMemory(xvwapHelper); - ZeroMemory(xtrendHelper); - } - - // - string GetSymbol() - { - return mSymbol; - } - - // - ENUM_TIMEFRAMES GetPeriod() - { - return mPeriod; - } - - // - // Tools ... - - /** - * Initialize Indicator Helper ... - * - * @param symbol: String, Symbol ... - * @param period: ENUM_TIMEFRAMES member, Period ... - * @param inputs: X121Inputs instance, Indicator Inputs ... - * - * @return ( bool ) - */ - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - X121Inputs &inputs // Inputs - ) - { - // - bool result = false; - - // - result = - IsValid(symbol) && - IsValid(period) && - inputs.IsValid(); - if (!result) - { - return result; - } - - // - mSymbol = symbol; - mPeriod = period; - - // - // Setting Inputs ... - - // - mInputs = inputs; - xccInputs = inputs.xccInputs; - xpvInputs = inputs.xpvInputs; - xhkInputs = inputs.xhkInputs; - xmasInputs = inputs.xmasInputs; - xatrInputs = inputs.xatrInputs; - xstrInputs = inputs.xstrInputs; - xcheInputs = inputs.xcheInputs; - xdonInputs = inputs.xdonInputs; - x3maInputs = inputs.x3maInputs; - xvwapInputs = inputs.xvwapInputs; - xtrendInputs = inputs.xtrendInputs; - - // - // Initial Helpers ... - - // - // XCC ... - xccHelper = new XCX121XCCHelper(); - result = xccHelper.Init( - symbol, - period, - xccInputs // - ); - if (!result) - { - return result; - } - - // - // XPV ... - xpvHelper = new XCX121XPVHelper(); - result = xpvHelper.Init( - symbol, - period, - xpvInputs // - ); - if (!result) - { - return result; - } - - // - // XHK ... - xhkHelper = new XCX121XHKHelper(); - result = xhkHelper.Init( - symbol, - period, - xhkInputs // - ); - if (!result) - { - return result; - } - - // - // XMAS ... - xmasHelper = new XCX121XMASHelper(); - result = xmasHelper.Init( - symbol, - period, - xmasInputs // - ); - if (!result) - { - return result; - } - - // - // XATR ... - xatrHelper = new XCX121XATRHelper(); - result = xatrHelper.Init( - symbol, - period, - xatrInputs // - ); - if (!result) - { - return result; - } - - // - // XSTR ... - xstrHelper = new XCX121XSTRHelper(); - result = xstrHelper.Init( - symbol, - period, - xstrInputs // - ); - if (!result) - { - return result; - } - - // - // XCHE ... - xcheHelper = new XCX121XCHEHelper(); - result = xcheHelper.Init( - symbol, - period, - xcheInputs // - ); - if (!result) - { - return result; - } - - // - // XDON ... - xdonHelper = new XCX121XDONHelper(); - result = xdonHelper.Init( - symbol, - period, - xdonInputs // - ); - if (!result) - { - return result; - } - - // - // X3MA ... - x3maHelper = new XCX121X3MAHelper(); - result = x3maHelper.Init( - symbol, - period, - x3maInputs // - ); - if (!result) - { - return result; - } - - // - // XVWAP ... - xvwapHelper = new XCX121XVWAPHelper(); - result = xvwapHelper.Init( - symbol, - period, - xvwapInputs // - ); - if (!result) - { - return result; - } - - // - // XTREND ... - xtrendHelper = new XCX121XTRENDHelper(); - result = xtrendHelper.Init( - symbol, - period, - xtrendInputs // - ); - if (!result) - { - return result; - } - - // - if (inputs.showRSI) - { - // - mRSIHandler = iRSI( - symbol, - period, - xatrInputs.rsiLength, - xatrInputs.rsiAppliedTo // - ); - - // - result = mRSIHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - } - - // - return result; - } - - // - // Conditions Readers ... - - // - // XPV ... - bool GetPVConditions( - X121XPVConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xpvHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XHK ... - bool GetHKConditions( - X121XHKConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xhkHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XMAS ... - bool GetMASConditions( - X121XMASConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xmasHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XATR ... - bool GetATRConditions( - X121XATRConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xatrHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XSTR ... - bool GetSTRConditions( - X121XSTRConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xstrHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XCHE ... - bool GetCHEConditions( - X121XCHEConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xcheHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XDON ... - bool GetDONConditions( - X121XDONConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xdonHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // X3MA ... - bool Get3MAConditions( - X121X3MAConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = x3maHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XVWAP ... - bool GetVWAPConditions( - X121XVWAPConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xvwapHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - // XTREND ... - bool GetTrendConditions( - X121XTRENDConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = false; - - // - result = xtrendHelper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - return result; - } - - // - void Free() - { - // - xpvHelper.Free(); - xhkHelper.Free(); - xmasHelper.Free(); - xatrHelper.Free(); - xstrHelper.Free(); - xcheHelper.Free(); - xdonHelper.Free(); - xvwapHelper.Free(); - xtrendHelper.Free(); - } - - // - bool GetConditions( - X121Conditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = true; - - // - if (loopback < 5) - { - loopback = 5; - } - - // - conditions.Clean(); - - // - conditions.symbol = mSymbol; - conditions.period = mPeriod; - conditions.time = TimeCurrent(); - - // - int zIndex = barIndex; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - XOHCL zBar; - result = zBar.Init( - mSymbol, - mPeriod, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - mSymbol, - mPeriod, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - mSymbol, - mPeriod, - pIndex // - ); - if (!result) - { - return result; - } - - // - // XPV ... - X121XPVConditions xpvConditions; - result = GetPVConditions( - xpvConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XHK ... - X121XHKConditions xhkConditions; - result = GetHKConditions( - xhkConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XMAS ... - X121XMASConditions xmasConditions; - result = GetMASConditions( - xmasConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XATR ... - X121XATRConditions xatrConditions; - result = GetATRConditions( - xatrConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XSTR ... - X121XSTRConditions xstrConditions; - result = GetSTRConditions( - xstrConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XCHE ... - X121XCHEConditions xcheConditions; - result = GetCHEConditions( - xcheConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XDON ... - X121XDONConditions xdonConditions; - result = GetDONConditions( - xdonConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // X3MA ... - X121X3MAConditions x3maConditions; - result = Get3MAConditions( - x3maConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XVWAP ... - X121XVWAPConditions xvwapConditions; - result = GetVWAPConditions( - xvwapConditions, - barIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // XTREND ... - X121XTRENDConditions xtrendConditions; - result = GetTrendConditions( - xtrendConditions, - barIndex, - loopback // - ); - if (!result) - { - 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 ... - - // - int cIDX = 1; - int pIDX = cIDX + 1; - - // - // XPV ... - - // - // Buffers ... - - // - Copy( - xpvConditions.peaksBuffer, - conditions.peaksBuffer // - ); - - // - Copy( - xpvConditions.valesBuffer, - conditions.valesBuffer // - ); - - // - Copy( - xpvConditions.supportsBuffer, - conditions.supportsBuffer // - ); - - // - Copy( - xpvConditions.resistancesBuffer, - conditions.resistancesBuffer // - ); - - // - Copy( - xpvConditions.peaksGoldenBuffer, - conditions.peaksGoldenBuffer // - ); - - // - Copy( - xpvConditions.valesGoldenBuffer, - conditions.valesGoldenBuffer // - ); - - // - Copy( - xpvConditions.sarBuffer, - conditions.sarBuffer // - ); - - // - Copy( - xpvConditions.cHHBuffer, - conditions.cHHBuffer // - ); - - // - Copy( - xpvConditions.cLLBuffer, - conditions.cLLBuffer // - ); - - // - Copy( - xpvConditions.sHHBuffer, - conditions.sHHBuffer // - ); - - // - Copy( - xpvConditions.sLLBuffer, - conditions.sLLBuffer // - ); - - // - Copy( - xpvConditions.mHHBuffer, - conditions.mHHBuffer // - ); - - // - Copy( - xpvConditions.mLLBuffer, - conditions.mLLBuffer // - ); - - // - Copy( - xpvConditions.lHHBuffer, - conditions.lHHBuffer // - ); - - // - Copy( - xpvConditions.lLLBuffer, - conditions.lLLBuffer // - ); - - // - Copy( - xpvConditions.hHHBuffer, - conditions.hHHBuffer // - ); - - // - Copy( - xpvConditions.hLLBuffer, - conditions.hLLBuffer // - ); - - // - Copy( - xpvConditions.fractalsUpperBuffer, - conditions.fractalsUpperBuffer // - ); - - // - Copy( - xpvConditions.fractalsLowerBuffer, - conditions.fractalsLowerBuffer // - ); - - // - // Conditions ... - - // - conditions.isNewPeak = xpvConditions.isNewPeak; - conditions.isNewVale = xpvConditions.isNewVale; - conditions.isSarBullish = xpvConditions.isSarBullish; - conditions.isSarBearish = xpvConditions.isSarBearish; - conditions.isNewPeakOverLast = xpvConditions.isNewPeakOverLast; - 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; - - // - // XHK ... - - // - // Buffers ... - - // - Copy( - xhkConditions.xhkRawOpenBuffer, - conditions.xhkRawOpenBuffer // - ); - - // - Copy( - xhkConditions.xhkRawHighBuffer, - conditions.xhkRawHighBuffer // - ); - - // - Copy( - xhkConditions.xhkRawLowBuffer, - conditions.xhkRawLowBuffer // - ); - - // - Copy( - xhkConditions.xhkRawCloseBuffer, - conditions.xhkRawCloseBuffer // - ); - - // - Copy( - xhkConditions.xhkSMOpenBuffer, - conditions.xhkSMOpenBuffer // - ); - - // - Copy( - xhkConditions.xhkSMHighBuffer, - conditions.xhkSMHighBuffer // - ); - - // - Copy( - xhkConditions.xhkSMLowBuffer, - conditions.xhkSMLowBuffer // - ); - - // - Copy( - xhkConditions.xhkSMCloseBuffer, - conditions.xhkSMCloseBuffer // - ); - - // - // Conditions ... - conditions.isSMHKBullish = xhkConditions.isSMHKBullish; - conditions.isRawHKBullish = xhkConditions.isRawHKBullish; - conditions.isSMHKBearish = xhkConditions.isSMHKBearish; - conditions.isRawHKBearish = xhkConditions.isRawHKBearish; - conditions.isBreakedUpSMHK = xhkConditions.isBreakedUpSMHK; - conditions.isBreakedUpRawHK = xhkConditions.isBreakedUpRawHK; - conditions.isRejectedUpSMHK = xhkConditions.isRejectedUpSMHK; - conditions.isClosedOverSMHK = xhkConditions.isClosedOverSMHK; - conditions.isRejectedUpRawHK = xhkConditions.isRejectedUpRawHK; - conditions.isBreakedDownSMHK = xhkConditions.isBreakedDownSMHK; - conditions.isClosedUnderSMHK = xhkConditions.isClosedUnderSMHK; - conditions.isClosedOverRawHK = xhkConditions.isClosedOverRawHK; - conditions.isClosedUnderRawHK = xhkConditions.isClosedUnderRawHK; - conditions.isBreakedDownRawHK = xhkConditions.isBreakedDownRawHK; - conditions.isRejectedDownSMHK = xhkConditions.isRejectedDownSMHK; - conditions.isRejectedDownRawHK = xhkConditions.isRejectedDownRawHK; - conditions.isRawHKBreakedUpSMHK = xhkConditions.isRawHKBreakedUpSMHK; - conditions.isRawHKClosedOverSMHK = xhkConditions.isRawHKClosedOverSMHK; - conditions.isSMHKSwitchedToBearish = xhkConditions.isSMHKSwitchedToBearish; - conditions.isRawHKSwitchedToBearish = xhkConditions.isRawHKSwitchedToBearish; - conditions.isRawHKClosedUnderSMHK = xhkConditions.isRawHKClosedUnderSMHK; - conditions.isRawHKBreakedDownSMHK = xhkConditions.isRawHKBreakedDownSMHK; - conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish; - conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish; - - // - // XMAS ... - - // - // Buffers ... - - // - Copy( - xmasConditions.upperBuffer, - conditions.masUpperBuffer // - ); - - // - Copy( - xmasConditions.midBuffer, - conditions.masMidBuffer // - ); - - // - Copy( - xmasConditions.lowerBuffer, - conditions.masLowerBuffer // - ); - - // - // XTREND ... - - // - // Buffers ... - - // - Copy( - xtrendConditions.upTrendBuffer, - conditions.upTrendBuffer // - ); - - // - Copy( - xtrendConditions.downTrendBuffer, - conditions.downTrendBuffer // - ); - - // - Copy( - xtrendConditions.maBuffer, - conditions.maBuffer // - ); - - // - Copy( - xtrendConditions.adxBuffer, - conditions.adxBuffer // - ); - - // - Copy( - xtrendConditions.adxPBuffer, - conditions.adxPBuffer // - ); - - // - Copy( - xtrendConditions.adxMBuffer, - conditions.adxMBuffer // - ); - - // - Copy( - xtrendConditions.upTBuffer, - conditions.upTBuffer // - ); - - // - Copy( - xtrendConditions.downTBuffer, - conditions.downTBuffer // - ); - - // - conditions.isTrendBullish = xtrendConditions.isTrendBullish; - conditions.isTrendBearish = xtrendConditions.isTrendBearish; - conditions.isTrendSwitchedToBullish = xtrendConditions.isTrendSwitchedToBullish; - conditions.isTrendSwitchedToBearish = xtrendConditions.isTrendSwitchedToBearish; - - // - // XATR ... - - // - // Buffers ... - - // - Copy( - xatrConditions.atrUpperBuffer, - conditions.atrUpperBuffer // - ); - - // - Copy( - xatrConditions.atrLowerBuffer, - conditions.atrLowerBuffer // - ); - - // - Copy( - xatrConditions.atrUpperRawBuffer, - conditions.atrUpperRawBuffer // - ); - - // - Copy( - xatrConditions.atrLowerRawBuffer, - conditions.atrLowerRawBuffer // - ); - - // - Copy( - xatrConditions.atrBuffer, - conditions.atrBuffer // - ); - - // - Copy( - xatrConditions.rsiBuffer, - conditions.rsiBuffer // - ); - - // - // Conditions ... - - // - conditions.isRsiOverSold = xatrConditions.isRsiOverSold; - conditions.isRsiOverBought = xatrConditions.isRsiOverBought; - conditions.isBreakedUpAtrUpper = xatrConditions.isBreakedUpAtrUpper; - conditions.isBreakedUpAtrLower = xatrConditions.isBreakedUpAtrLower; - conditions.isClosedOverAtrUpper = xatrConditions.isClosedOverAtrUpper; - conditions.isRejectedUpAtrUpper = xatrConditions.isRejectedUpAtrUpper; - conditions.isRejectedUpAtrLower = xatrConditions.isRejectedUpAtrLower; - conditions.isClosedOverAtrLower = xatrConditions.isClosedOverAtrLower; - conditions.isBreakedDownAtrUpper = xatrConditions.isBreakedDownAtrUpper; - conditions.isBreakedDownAtrLower = xatrConditions.isBreakedDownAtrLower; - conditions.isClosedUnderAtrUpper = xatrConditions.isClosedUnderAtrUpper; - conditions.isClosedUnderAtrLower = xatrConditions.isClosedUnderAtrLower; - conditions.isRejectedDownAtrUpper = xatrConditions.isRejectedDownAtrUpper; - conditions.isRejectedDownAtrLower = xatrConditions.isRejectedDownAtrLower; - conditions.isRsiCrossedOverOverSold = xatrConditions.isRsiCrossedOverOverSold; - conditions.isRsiCrossedUnderOverSold = xatrConditions.isRsiCrossedUnderOverSold; - conditions.isRsiCrossedOverOverBought = xatrConditions.isRsiCrossedOverOverBought; - conditions.isRsiCrossedUnderOverBought = xatrConditions.isRsiCrossedUnderOverBought; - - // - // XSTR ... - - // - // Buffers ... - - // - Copy( - xstrConditions.strBuffer, - conditions.strBuffer // - ); - - // - Copy( - xstrConditions.strPriceBuffer, - conditions.strPriceBuffer // - ); - - // - Copy( - xstrConditions.strUpBuffer, - conditions.strUpBuffer // - ); - - // - Copy( - xstrConditions.strDownBuffer, - conditions.strDownBuffer // - ); - - // - Copy( - xstrConditions.strStateBuffer, - conditions.strStateBuffer // - ); - - // - // Conditions ... - - // - conditions.isStrBullish = xstrConditions.isStrBullish; - conditions.isStrBearish = xstrConditions.isStrBearish; - conditions.isStrSwitchedToBullish = xstrConditions.isStrSwitchedToBullish; - conditions.isStrSwitchedToBearish = xstrConditions.isStrSwitchedToBearish; - - // - // XCHE ... - - // - // Buffers ... - - // - Copy( - xcheConditions.le1Buffer, - conditions.le1Buffer // - ); - - // - Copy( - xcheConditions.se1Buffer, - conditions.se1Buffer // - ); - - // - Copy( - xcheConditions.le2Buffer, - conditions.le2Buffer // - ); - - // - Copy( - xcheConditions.se2Buffer, - conditions.se2Buffer // - ); - - // - Copy( - xcheConditions.le1StartBuffer, - conditions.le1StartBuffer // - ); - - // - Copy( - xcheConditions.se1StartBuffer, - conditions.se1StartBuffer // - ); - - // - Copy( - xcheConditions.le2StartBuffer, - conditions.le2StartBuffer // - ); - - // - Copy( - xcheConditions.se2StartBuffer, - conditions.se2StartBuffer // - ); - - // - // Conditions ... - - conditions.isCheBullish = xcheConditions.isCheBullish; - conditions.isCheBearish = xcheConditions.isCheBearish; - conditions.isChe1Bullish = xcheConditions.isChe1Bullish; - conditions.isChe1Bearish = xcheConditions.isChe1Bearish; - conditions.isChe2Bullish = xcheConditions.isChe2Bullish; - conditions.isChe2Bearish = xcheConditions.isChe2Bearish; - conditions.isClosedOverCheMin = xcheConditions.isClosedOverCheMin; - conditions.isClosedOverCheMax = xcheConditions.isClosedOverCheMax; - conditions.isClosedUnderCheMin = xcheConditions.isClosedUnderCheMin; - conditions.isClosedUnderCheMax = xcheConditions.isClosedUnderCheMax; - conditions.isCheSwitchedToBullish = xcheConditions.isCheSwitchedToBullish; - conditions.isCheSwitchedToBearish = xcheConditions.isCheSwitchedToBearish; - conditions.isChe1SwitchedToBullish = xcheConditions.isChe1SwitchedToBullish; - conditions.isChe1SwitchedToBearish = xcheConditions.isChe1SwitchedToBearish; - conditions.isChe2SwitchedToBullish = xcheConditions.isChe2SwitchedToBullish; - conditions.isChe2SwitchedToBearish = xcheConditions.isChe2SwitchedToBearish; - - // - // XDON ... - - // - // Buffers ... - - // - Copy( - xdonConditions.donOpenUpperBuffer, - conditions.donOpenUpperBuffer // - ); - - // - Copy( - xdonConditions.donOpenLowerBuffer, - conditions.donOpenLowerBuffer // - ); - - // - Copy( - xdonConditions.donHighUpperBuffer, - conditions.donHighUpperBuffer // - ); - - // - Copy( - xdonConditions.donHighLowerBuffer, - conditions.donHighLowerBuffer // - ); - - // - Copy( - xdonConditions.donLowUpperBuffer, - conditions.donLowUpperBuffer // - ); - - // - Copy( - xdonConditions.donLowLowerBuffer, - conditions.donLowLowerBuffer // - ); - - // - Copy( - xdonConditions.donCloseUpperBuffer, - conditions.donCloseUpperBuffer // - ); - - // - Copy( - xdonConditions.donCloseLowerBuffer, - conditions.donCloseLowerBuffer // - ); - - // - // Conditions ... - - // - conditions.isBreakedDonLowUpper = xdonConditions.isBreakedDonLowUpper; - conditions.isBreakedDonLowLower = xdonConditions.isBreakedDonLowLower; - conditions.isRejectedDonLowUpper = xdonConditions.isRejectedDonLowUpper; - conditions.isRejectedDonLowLower = xdonConditions.isRejectedDonLowLower; - conditions.isBreakedDonOpenUpper = xdonConditions.isBreakedDonOpenUpper; - conditions.isBreakedDonHighUpper = xdonConditions.isBreakedDonHighUpper; - conditions.isBreakedDonOpenLower = xdonConditions.isBreakedDonOpenLower; - conditions.isBreakedDonHighLower = xdonConditions.isBreakedDonHighLower; - conditions.isRejectedDonOpenUpper = xdonConditions.isRejectedDonOpenUpper; - conditions.isRejectedDonHighUpper = xdonConditions.isRejectedDonHighUpper; - conditions.isRejectedDonOpenLower = xdonConditions.isRejectedDonOpenLower; - conditions.isRejectedDonHighLower = xdonConditions.isRejectedDonHighLower; - conditions.isBreakedDonCloseUpper = xdonConditions.isBreakedDonCloseUpper; - conditions.isBreakedDonCloseLower = xdonConditions.isBreakedDonCloseLower; - conditions.isRejectedDonCloseUpper = xdonConditions.isRejectedDonCloseUpper; - conditions.isRejectedDonCloseLower = xdonConditions.isRejectedDonCloseLower; - - // - // X3MA ... - - // - // Buffers ... - - // - Copy( - x3maConditions.x3maFastBuffer, - conditions.x3maFastBuffer // - ); - - // - Copy( - x3maConditions.x3maMidBuffer, - conditions.x3maMidBuffer // - ); - - // - Copy( - x3maConditions.x3maSlowBuffer, - conditions.x3maSlowBuffer // - ); - - // - Copy( - x3maConditions.x3maFastStateBuffer, - conditions.x3maFastStateBuffer // - ); - - // - Copy( - x3maConditions.x3maMidStateBuffer, - conditions.x3maMidStateBuffer // - ); - - // - Copy( - x3maConditions.x3maSlowStateBuffer, - conditions.x3maSlowStateBuffer // - ); - - // - // Conditions ... - - // - conditions.isX3MaMidBullish = x3maConditions.isX3MaMidBullish; - conditions.isX3MaMidBearish = x3maConditions.isX3MaMidBearish; - conditions.isX3MaFastBullish = x3maConditions.isX3MaFastBullish; - conditions.isX3MaFastBearish = x3maConditions.isX3MaFastBearish; - conditions.isX3MaMidNeutural = x3maConditions.isX3MaMidNeutural; - conditions.isX3MaSlowBullish = x3maConditions.isX3MaSlowBullish; - conditions.isX3MaSlowBearish = x3maConditions.isX3MaSlowBearish; - conditions.isX3MaFastOverMid = x3maConditions.isX3MaFastOverMid; - conditions.isX3MaMidOverSlow = x3maConditions.isX3MaMidOverSlow; - conditions.isX3MaFastNeutural = x3maConditions.isX3MaFastNeutural; - conditions.isX3MaSlowNeutural = x3maConditions.isX3MaSlowNeutural; - conditions.isX3MaFastUnderMid = x3maConditions.isX3MaFastUnderMid; - conditions.isX3MaMidUnderSlow = x3maConditions.isX3MaMidUnderSlow; - conditions.isX3MaBullishState = x3maConditions.isX3MaBullishState; - conditions.isX3MaBearishState = x3maConditions.isX3MaBearishState; - conditions.isX3MaNeuturalState = x3maConditions.isX3MaNeuturalState; - conditions.isX3MaBullishOrdered = x3maConditions.isX3MaBullishOrdered; - conditions.isX3MaBearishOrdered = x3maConditions.isX3MaBearishOrdered; - conditions.isX3MaSwitchedToBullishState = x3maConditions.isX3MaSwitchedToBullishState; - conditions.isX3MaSwitchedToBearishState = x3maConditions.isX3MaSwitchedToBearishState; - conditions.isX3MaSwitchedToNeuturalState = x3maConditions.isX3MaSwitchedToNeuturalState; - conditions.isX3MaSwitchedToBullishOrdered = x3maConditions.isX3MaSwitchedToBullishOrdered; - conditions.isX3MaSwitchedToBearishOrdered = x3maConditions.isX3MaSwitchedToBearishOrdered; - - // - // XVWAP ... - - // - // Buffers ... - - // - Copy( - xvwapConditions.vwapFastBuffer, - conditions.vwapFastBuffer // - ); - - // - Copy( - xvwapConditions.vwapMidBuffer, - conditions.vwapMidBuffer // - ); - - // - Copy( - xvwapConditions.vwapSlowBuffer, - conditions.vwapSlowBuffer // - ); - - // - Copy( - xvwapConditions.vwapVolumeBuffer, - conditions.vwapVolumeBuffer // - ); - - // - Copy( - xvwapConditions.vwapPriceBuffer, - conditions.vwapPriceBuffer // - ); - - // - Copy( - xvwapConditions.vwapFastStateBuffer, - conditions.vwapFastStateBuffer // - ); - - // - Copy( - xvwapConditions.vwapMidStateBuffer, - conditions.vwapMidStateBuffer // - ); - - // - Copy( - xvwapConditions.vwapSlowStateBuffer, - conditions.vwapSlowStateBuffer // - ); - - // - // Conditions ... - - // - conditions.isVWapMidBullish = xvwapConditions.isVWapMidBullish; - conditions.isVWapMidBearish = xvwapConditions.isVWapMidBearish; - conditions.isVWapFastBullish = xvwapConditions.isVWapFastBullish; - conditions.isVWapFastBearish = xvwapConditions.isVWapFastBearish; - conditions.isVWapMidNeutural = xvwapConditions.isVWapMidNeutural; - conditions.isVWapSlowBullish = xvwapConditions.isVWapSlowBullish; - conditions.isVWapSlowBearish = xvwapConditions.isVWapSlowBearish; - conditions.isVWapFastOverMid = xvwapConditions.isVWapFastOverMid; - conditions.isVWapMidOverSlow = xvwapConditions.isVWapMidOverSlow; - conditions.isVWapFastNeutural = xvwapConditions.isVWapFastNeutural; - conditions.isVWapSlowNeutural = xvwapConditions.isVWapSlowNeutural; - conditions.isVWapFastUnderMid = xvwapConditions.isVWapFastUnderMid; - conditions.isVWapMidUnderSlow = xvwapConditions.isVWapMidUnderSlow; - conditions.isVWapBullishState = xvwapConditions.isVWapBullishState; - conditions.isVWapBearishState = xvwapConditions.isVWapBearishState; - conditions.isVWapNeuturalState = xvwapConditions.isVWapNeuturalState; - conditions.isVWapBullishOrdered = xvwapConditions.isVWapBullishOrdered; - conditions.isVWapBearishOrdered = xvwapConditions.isVWapBearishOrdered; - conditions.isVWapSwitchedToBullishState = xvwapConditions.isVWapSwitchedToBullishState; - conditions.isVWapSwitchedToBearishState = xvwapConditions.isVWapSwitchedToBearishState; - conditions.isVWapSwitchedToNeuturalState = xvwapConditions.isVWapSwitchedToNeuturalState; - conditions.isVWapSwitchedToBullishOrdered = xvwapConditions.isVWapSwitchedToBullishOrdered; - conditions.isVWapSwitchedToBearishOrdered = xvwapConditions.isVWapSwitchedToBearishOrdered; - - // - // Slopes ... - - // - double rsiSlope = GetSlope(conditions.rsiBuffer, pIDX, cIDX); - double strSlope = GetSlope(conditions.strBuffer, pIDX, cIDX); - double atrUpperSlope = GetSlope(conditions.atrUpperBuffer, pIDX, cIDX); - double atrLowerSlope = GetSlope(conditions.atrLowerBuffer, pIDX, cIDX); - double vwapFastSlope = GetSlope(conditions.vwapFastBuffer, pIDX, cIDX); - double vwapMidSlope = GetSlope(conditions.vwapMidBuffer, pIDX, cIDX); - double vwapSlowSlope = GetSlope(conditions.vwapSlowBuffer, pIDX, cIDX); - - // - bool isRsiSlopeBullish = rsiSlope > 0; - bool isStrSlopeBullish = strSlope > 0; - bool isAtrUpperSlopeBullish = atrUpperSlope > 0; - bool isAtrLowerSlopeBullish = atrLowerSlope > 0; - bool isVwapFastSlopeBullish = vwapFastSlope > 0; - bool isVwapMidSlopeBullish = vwapMidSlope > 0; - bool isVwapSlowSlopeBullish = vwapSlowSlope > 0; - - // - bool isRsiSlopeBearish = rsiSlope < 0; - bool isStrSlopeBearish = strSlope < 0; - bool isAtrUpperSlopeBearish = atrUpperSlope < 0; - bool isAtrLowerSlopeBearish = atrLowerSlope < 0; - bool isVwapFastSlopeBearish = vwapFastSlope < 0; - bool isVwapMidSlopeBearish = vwapMidSlope < 0; - bool isVwapSlowSlopeBearish = vwapSlowSlope < 0; - - // - conditions.rsiSlope = rsiSlope; - conditions.strSlope = strSlope; - conditions.vwapMidSlope = vwapMidSlope; - conditions.vwapSlowSlope = vwapSlowSlope; - conditions.atrUpperSlope = atrUpperSlope; - conditions.atrLowerSlope = atrLowerSlope; - conditions.vwapFastSlope = vwapFastSlope; - conditions.isRsiSlopeBearish = isRsiSlopeBearish; - conditions.isStrSlopeBearish = isStrSlopeBearish; - conditions.isRsiSlopeBullish = isRsiSlopeBullish; - conditions.isStrSlopeBullish = isStrSlopeBullish; - conditions.isVwapMidSlopeBearish = isVwapMidSlopeBearish; - conditions.isVwapMidSlopeBullish = isVwapMidSlopeBullish; - conditions.isAtrUpperSlopeBearish = isAtrUpperSlopeBearish; - conditions.isAtrLowerSlopeBearish = isAtrLowerSlopeBearish; - conditions.isVwapFastSlopeBearish = isVwapFastSlopeBearish; - conditions.isVwapSlowSlopeBearish = isVwapSlowSlopeBearish; - conditions.isAtrUpperSlopeBullish = isAtrUpperSlopeBullish; - conditions.isAtrLowerSlopeBullish = isAtrLowerSlopeBullish; - conditions.isVwapFastSlopeBullish = isVwapFastSlopeBullish; - conditions.isVwapSlowSlopeBullish = isVwapSlowSlopeBullish; - - // - // Complex Conditions ... - - // - double x3maFast = conditions.x3maFastBuffer[cIDX]; - double x3maMid = conditions.x3maMidBuffer[cIDX]; - double x3maSlow = conditions.x3maSlowBuffer[cIDX]; - - // - double x3mas[3] = { - x3maFast, - x3maMid, - x3maSlow // - }; - - // - double x3maMin = GetMin(x3mas); - double x3maMax = GetMax(x3mas); - - // - bool isX3MaMinBreakedUp = IsBarBreak( - x3maMin, - X_DIRECTION_BULLISH, - cBar // - ); - bool isX3MaMinBreakedDown = IsBarBreak( - x3maMin, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isX3MaMaxBreakedUp = IsBarBreak( - x3maMax, - X_DIRECTION_BULLISH, - cBar // - ); - bool isX3MaMaxBreakedDown = IsBarBreak( - x3maMax, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isX3MaFatsOverMid = conditions.x3maFastBuffer[cIDX] > conditions.x3maMidBuffer[cIDX]; - bool isX3MaFatsOverMidPrev = conditions.x3maFastBuffer[pIDX] > conditions.x3maMidBuffer[pIDX]; - - // - bool isX3MaFatsUnderMid = conditions.x3maFastBuffer[cIDX] < conditions.x3maMidBuffer[cIDX]; - bool isX3MaFatsUnderMidPrev = conditions.x3maFastBuffer[pIDX] < conditions.x3maMidBuffer[pIDX]; - - // - bool isX3MaFatsOverSlow = conditions.x3maFastBuffer[cIDX] > conditions.x3maSlowBuffer[cIDX]; - bool isX3MaFatsOverSlowPrev = conditions.x3maFastBuffer[pIDX] > conditions.x3maSlowBuffer[pIDX]; - - // - bool isX3MaFatsUnderSlow = conditions.x3maFastBuffer[cIDX] < conditions.x3maSlowBuffer[cIDX]; - bool isX3MaFatsUnderSlowPrev = conditions.x3maFastBuffer[pIDX] < conditions.x3maSlowBuffer[pIDX]; - - // - bool isX3MaFastCrossedOverMid = isX3MaFatsOverMid && - !isX3MaFatsOverMidPrev; - bool isX3MaFastCrossedUnderMid = isX3MaFatsUnderMid && - !isX3MaFatsUnderMidPrev; - - // - bool isX3MaFastCrossedOverSlow = isX3MaFatsOverSlow && - !isX3MaFatsOverSlowPrev; - bool isX3MaFastCrossedUnderSlow = isX3MaFatsUnderSlow && - !isX3MaFatsUnderSlowPrev; - - // - bool isClosedOverX3MaMin = cBar.close > x3maMin; - bool isClosedUnderX3MaMin = cBar.close < x3maMin; - - // - bool isClosedOverX3MaMax = cBar.close > x3maMax; - bool isClosedUnderX3MaMax = cBar.close < x3maMax; - - // - // - // - - // - double vwapFast = conditions.vwapFastBuffer[cIDX]; - double vwapMid = conditions.vwapMidBuffer[cIDX]; - double vwapSlow = conditions.vwapSlowBuffer[cIDX]; - - // - double vwaps[3] = { - vwapFast, - vwapMid, - vwapSlow // - }; - - // - double vwapMin = GetMin(vwaps); - double vwapMax = GetMax(vwaps); - - // - bool isVWapMinBreakedUp = IsBarBreak( - vwapMin, - X_DIRECTION_BULLISH, - cBar // - ); - bool isVWapMinBreakedDown = IsBarBreak( - vwapMin, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isVWapMaxBreakedUp = IsBarBreak( - vwapMax, - X_DIRECTION_BULLISH, - cBar // - ); - bool isVWapMaxBreakedDown = IsBarBreak( - vwapMax, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isVWapFatsOverMid = conditions.vwapFastBuffer[cIDX] > conditions.vwapMidBuffer[cIDX]; - bool isVWapFatsOverMidPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapFatsUnderMid = conditions.vwapFastBuffer[cIDX] < conditions.vwapMidBuffer[cIDX]; - bool isVWapFatsUnderMidPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapMidBuffer[pIDX]; - - // - bool isVWapFatsOverSlow = conditions.vwapFastBuffer[cIDX] > conditions.vwapSlowBuffer[cIDX]; - bool isVWapFatsOverSlowPrev = conditions.vwapFastBuffer[pIDX] > conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapFatsUnderSlow = conditions.vwapFastBuffer[cIDX] < conditions.vwapSlowBuffer[cIDX]; - bool isVWapFatsUnderSlowPrev = conditions.vwapFastBuffer[pIDX] < conditions.vwapSlowBuffer[pIDX]; - - // - bool isVWapFastCrossedOverMid = isVWapFatsOverMid && - !isVWapFatsOverMidPrev; - bool isVWapFastCrossedUnderMid = isVWapFatsUnderMid && - !isVWapFatsUnderMidPrev; - - // - bool isVWapFastCrossedOverSlow = isVWapFatsOverSlow && - !isVWapFatsOverSlowPrev; - bool isVWapFastCrossedUnderSlow = isVWapFatsUnderSlow && - !isVWapFatsUnderSlowPrev; - - // - bool isClosedOverVWapMin = cBar.close > vwapMin; - bool isClosedUnderVWapMin = cBar.close < vwapMin; - - // - bool isClosedOverVWapMax = cBar.close > vwapMax; - bool isClosedUnderVWapMax = cBar.close < vwapMax; - - // - bool isSarEqualsToPeak = - conditions.sarBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - bool isSarEqualsToVale = - conditions.sarBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isSarIncreased = conditions.sarBuffer[cIDX] > conditions.sarBuffer[pIDX]; - bool isSarDecreased = conditions.sarBuffer[cIDX] < conditions.sarBuffer[pIDX]; - - // - double prevSar = conditions.sarBuffer[pIDX]; - double prevStr = conditions.strBuffer[pIDX]; - double prevCheLE1 = conditions.le1Buffer[pIDX]; - double prevCheLE2 = conditions.le2Buffer[pIDX]; - double prevCheSE1 = conditions.se1Buffer[pIDX]; - double prevCheSE2 = conditions.se2Buffer[pIDX]; - double prevAtrUpper = conditions.atrUpperBuffer[pIDX]; - double prevAtrLower = conditions.atrLowerBuffer[pIDX]; - - // - double ches[]; - if (prevCheLE1 != EMPTY_VALUE) - { - // - Add( - prevCheLE1, - ches // - ); - } - if (prevCheLE2 != EMPTY_VALUE) - { - // - Add( - prevCheLE2, - ches // - ); - } - if (prevCheSE1 != EMPTY_VALUE) - { - // - Add( - prevCheSE1, - ches // - ); - } - if (prevCheSE2 != EMPTY_VALUE) - { - // - Add( - prevCheSE2, - ches // - ); - } - - // - double cheMin = GetMin(ches); - double cheMax = GetMax(ches); - - // - bool isBreakedUpPrevSar = IsBarBreak( - prevSar, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevSar = IsBarBreak( - prevSar, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevStr = IsBarBreak( - prevStr, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevStr = IsBarBreak( - prevStr, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isRejectedUpPrevAtrUpper = IsBarReject( - prevAtrUpper, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isRejectedDownPrevAtrUpper = IsBarReject( - prevAtrUpper, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isRejectedUpPrevAtrLower = IsBarReject( - prevAtrLower, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isRejectedDownPrevAtrLower = IsBarReject( - prevAtrLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevAtrUpper = IsBarBreak( - prevAtrUpper, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevAtrUpper = IsBarBreak( - prevAtrUpper, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevAtrLower = IsBarBreak( - prevAtrLower, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevAtrLower = IsBarBreak( - prevAtrLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevCheLE1 = IsBarBreak( - prevCheLE1, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedUpPrevCheLE2 = IsBarBreak( - prevCheLE2, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedUpPrevCheSE1 = IsBarBreak( - prevCheSE1, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedUpPrevCheSE2 = IsBarBreak( - prevCheSE2, - X_DIRECTION_BULLISH, - cBar // - ); - - // - bool isBreakedDownPrevCheLE1 = IsBarBreak( - prevCheLE1, - X_DIRECTION_BEARISH, - cBar // - ); - bool isBreakedDownPrevCheLE2 = IsBarBreak( - prevCheLE2, - X_DIRECTION_BEARISH, - cBar // - ); - bool isBreakedDownPrevCheSE1 = IsBarBreak( - prevCheSE1, - X_DIRECTION_BEARISH, - cBar // - ); - bool isBreakedDownPrevCheSE2 = IsBarBreak( - prevCheSE2, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevCheMin = IsBarBreak( - cheMin, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevCheMin = IsBarBreak( - cheMin, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isBreakedUpPrevCheMax = IsBarBreak( - cheMax, - X_DIRECTION_BULLISH, - cBar // - ); - bool isBreakedDownPrevCheMax = IsBarBreak( - cheMax, - X_DIRECTION_BEARISH, - cBar // - ); - - // - bool isSarCrossedUnderPeak = - conditions.sarBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - !(conditions.sarBuffer[pIDX] < conditions.peaksBuffer[pIDX]); - bool isSarCrossedOverVale = - conditions.sarBuffer[cIDX] > conditions.valesBuffer[cIDX] && - !(conditions.sarBuffer[pIDX] > conditions.valesBuffer[pIDX]); - - // - bool isStrEqualsToPeak = - conditions.strBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - bool isStrEqualsToVale = - conditions.strBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isStrCrossedUnderPeak = - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - !(conditions.strBuffer[pIDX] < conditions.peaksBuffer[pIDX]); - bool isStrCrossedOverVale = - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX] && - !(conditions.strBuffer[pIDX] > conditions.valesBuffer[pIDX]); - - // - bool isPeakOverAtrUpper = - conditions.peaksBuffer[cIDX] > conditions.atrUpperBuffer[cIDX]; - bool isValeUnderAtrLower = - conditions.valesBuffer[cIDX] > conditions.atrLowerBuffer[cIDX]; - - // - bool isNewPeakOverAtrUpper = - isPeakOverAtrUpper && - conditions.isNewPeak; - bool isNewValeUnderAtrLower = - isValeUnderAtrLower && - conditions.isNewVale; - - // - bool isStrUpperOverPeak = - conditions.strBuffer[cIDX] > conditions.peaksBuffer[cIDX]; - bool isStrUpperOverPeakPrev = - conditions.strBuffer[pIDX] > conditions.peaksBuffer[pIDX]; - - // - bool isStrUpperUnderPeak = - conditions.strBuffer[cIDX] < conditions.peaksBuffer[cIDX]; - bool isStrUpperUnderPeakPrev = - conditions.strBuffer[pIDX] < conditions.peaksBuffer[pIDX]; - - // - bool isStrUpperCrossedOverPeak = isStrUpperOverPeak && - !isStrUpperOverPeakPrev; - bool isStrUpperCrossedUnderPeak = isStrUpperUnderPeak && - !isStrUpperUnderPeakPrev; - - // - bool isStrLowerOverVale = - conditions.strBuffer[cIDX] > conditions.valesBuffer[cIDX]; - bool isStrLowerOverValePrev = - conditions.strBuffer[pIDX] > conditions.valesBuffer[pIDX]; - - // - bool isStrLowerUnderVale = - conditions.strBuffer[cIDX] < conditions.valesBuffer[cIDX]; - bool isStrLowerUnderValePrev = - conditions.strBuffer[pIDX] < conditions.valesBuffer[pIDX]; - - // - bool isStrLowerCrossedOverVale = isStrLowerOverVale && - !isStrLowerOverValePrev; - bool isStrLowerCrossedUnderVale = isStrLowerUnderVale && - !isStrLowerUnderValePrev; - - // - bool isDonHighUpperEqualsToPeak = - conditions.donHighUpperBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - bool isDonLowLowerEqualsToVale = - conditions.donLowLowerBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isStrUpperOverAtrUpper = - conditions.strUpBuffer[cIDX] > conditions.atrUpperBuffer[cIDX]; - bool isStrUpperOverAtrUpperPrev = - conditions.strUpBuffer[pIDX] > conditions.atrUpperBuffer[pIDX]; - bool isStrUpperCrossedOverAtrUpper = isStrUpperOverAtrUpper && - !isStrUpperOverAtrUpperPrev; - - // - bool isStrUpperUnderAtrUpper = - conditions.strUpBuffer[cIDX] < conditions.atrUpperBuffer[cIDX]; - bool isStrUpperUnderAtrUpperPrev = - conditions.strUpBuffer[pIDX] < conditions.atrUpperBuffer[pIDX]; - bool isStrUpperCrossedUnderAtrUpper = isStrUpperUnderAtrUpper && - !isStrUpperUnderAtrUpperPrev; - - // - bool isStrLowerOverAtrLower = - conditions.strDownBuffer[cIDX] > conditions.atrLowerBuffer[cIDX]; - bool isStrLowerOverAtrLowerPrev = - conditions.strDownBuffer[pIDX] > conditions.atrLowerBuffer[pIDX]; - bool isStrLowerCrossedOverAtrLower = isStrLowerOverAtrLower && - !isStrLowerOverAtrLowerPrev; - - // - bool isStrLowerUnderAtrLower = - conditions.strDownBuffer[cIDX] < conditions.atrLowerBuffer[cIDX]; - bool isStrLowerUnderAtrLowerPrev = - conditions.strDownBuffer[pIDX] < conditions.atrLowerBuffer[pIDX]; - bool isStrLowerCrossedUnderAtrLower = isStrLowerUnderAtrLower && - !isStrLowerUnderAtrLowerPrev; - - // - bool isStrUpperOverDonHighUpper = - conditions.strUpBuffer[cIDX] > conditions.donHighUpperBuffer[cIDX]; - bool isStrUpperOverDonHighUpperPrev = - conditions.strUpBuffer[pIDX] > conditions.donHighUpperBuffer[pIDX]; - bool isStrUpperCrossedOverDonHighUpper = isStrUpperOverDonHighUpper && - !isStrUpperOverDonHighUpperPrev; - - // - bool isStrUpperUnderDonHighUpper = - conditions.strUpBuffer[cIDX] < conditions.donHighUpperBuffer[cIDX]; - bool isStrUpperUnderDonHighUpperPrev = - conditions.strUpBuffer[pIDX] < conditions.donHighUpperBuffer[pIDX]; - bool isStrUpperCrossedUnderDonHighUpper = isStrUpperUnderDonHighUpper && - !isStrUpperUnderDonHighUpperPrev; - - // - bool isStrLowerOverDonLowLower = - conditions.strDownBuffer[cIDX] > conditions.donLowLowerBuffer[cIDX]; - bool isStrLowerOverDonLowLowerPrev = - conditions.strDownBuffer[pIDX] > conditions.donLowLowerBuffer[pIDX]; - bool isStrLowerCrossedOverDonLowLower = isStrLowerOverDonLowLower && - !isStrLowerOverDonLowLowerPrev; - - // - bool isStrLowerUnderDonLowLower = - conditions.strDownBuffer[cIDX] < conditions.donLowLowerBuffer[cIDX]; - bool isStrLowerUnderDonLowLowerPrev = - conditions.strDownBuffer[pIDX] < conditions.donLowLowerBuffer[pIDX]; - bool isStrLowerCrossedUnderDonLowLower = isStrLowerUnderDonLowLower && - !isStrLowerUnderDonLowLowerPrev; - - // - bool isAtrUpperOverPeak = conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX]; - bool isAtrUpperEqualsToPeak = conditions.atrUpperBuffer[cIDX] == conditions.peaksBuffer[cIDX]; - - // - bool isAtrUpperCrossedUpPeak = conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] > conditions.peaksBuffer[cIDX]); - bool isAtrUpperCrossedDownPeak = conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] < conditions.peaksBuffer[cIDX]); - - // - bool isAtrLowerUnderVale = conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX]; - bool isAtrLowerEqualsToVale = conditions.atrUpperBuffer[cIDX] == conditions.valesBuffer[cIDX]; - - // - bool isAtrLowerCrossedUpVale = conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] > conditions.valesBuffer[cIDX]); - bool isAtrLowerCrossedDownVale = conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX] && - !(conditions.atrUpperBuffer[cIDX] < conditions.valesBuffer[cIDX]); - - // - conditions.cheMin = cheMin; - conditions.cheMax = cheMax; - conditions.x3maMin = x3maMin; - conditions.x3maMax = x3maMax; - conditions.vwapMin = vwapMin; - conditions.vwapMax = vwapMax; - - // - conditions.isSarIncreased = isSarIncreased; - conditions.isSarDecreased = isSarDecreased; - conditions.isSarEqualsToPeak = isSarEqualsToPeak; - conditions.isSarEqualsToVale = isSarEqualsToVale; - conditions.isStrEqualsToPeak = isStrEqualsToPeak; - conditions.isStrEqualsToVale = isStrEqualsToVale; - conditions.isX3MaFatsOverMid = isX3MaFatsOverMid; - conditions.isX3MaMinBreakedUp = isX3MaMinBreakedUp; - conditions.isX3MaMaxBreakedUp = isX3MaMaxBreakedUp; - conditions.isX3MaFatsUnderMid = isX3MaFatsUnderMid; - conditions.isX3MaFatsOverSlow = isX3MaFatsOverSlow; - conditions.isStrUpperOverPeak = isStrUpperOverPeak; - conditions.isPeakOverAtrUpper = isPeakOverAtrUpper; - conditions.isStrLowerOverVale = isStrLowerOverVale; - conditions.isVWapMinBreakedUp = isVWapMinBreakedUp; - conditions.isVWapMaxBreakedUp = isVWapMaxBreakedUp; - conditions.isBreakedUpPrevSar = isBreakedUpPrevSar; - conditions.isBreakedUpPrevStr = isBreakedUpPrevStr; - conditions.isAtrUpperOverPeak = isAtrUpperOverPeak; - conditions.isClosedOverX3MaMin = isClosedOverX3MaMin; - conditions.isClosedOverX3MaMax = isClosedOverX3MaMax; - conditions.isX3MaFatsUnderSlow = isX3MaFatsUnderSlow; - conditions.isAtrLowerUnderVale = isAtrLowerUnderVale; - conditions.isStrLowerUnderVale = isStrLowerUnderVale; - conditions.isStrUpperUnderPeak = isStrUpperUnderPeak; - conditions.isValeUnderAtrLower = isValeUnderAtrLower; - conditions.isClosedOverVWapMin = isClosedOverVWapMin; - conditions.isClosedOverVWapMax = isClosedOverVWapMax; - conditions.isClosedUnderX3MaMin = isClosedUnderX3MaMin; - conditions.isClosedUnderX3MaMax = isClosedUnderX3MaMax; - conditions.isX3MaMinBreakedDown = isX3MaMinBreakedDown; - conditions.isX3MaMaxBreakedDown = isX3MaMaxBreakedDown; - conditions.isClosedUnderVWapMin = isClosedUnderVWapMin; - conditions.isClosedUnderVWapMax = isClosedUnderVWapMax; - conditions.isVWapMinBreakedDown = isVWapMinBreakedDown; - conditions.isVWapMaxBreakedDown = isVWapMaxBreakedDown; - conditions.isSarCrossedOverVale = isSarCrossedOverVale; - conditions.isStrCrossedOverVale = isStrCrossedOverVale; - conditions.isBreakedDownPrevStr = isBreakedDownPrevStr; - conditions.isBreakedDownPrevSar = isBreakedDownPrevSar; - conditions.isX3MaFatsOverMidPrev = isX3MaFatsOverMidPrev; - conditions.isSarCrossedUnderPeak = isSarCrossedUnderPeak; - conditions.isStrCrossedUnderPeak = isStrCrossedUnderPeak; - conditions.isNewPeakOverAtrUpper = isNewPeakOverAtrUpper; - conditions.isBreakedUpPrevCheLE1 = isBreakedUpPrevCheLE1; - conditions.isBreakedUpPrevCheLE2 = isBreakedUpPrevCheLE2; - conditions.isBreakedUpPrevCheSE1 = isBreakedUpPrevCheSE1; - conditions.isBreakedUpPrevCheSE2 = isBreakedUpPrevCheSE2; - conditions.isBreakedUpPrevCheMin = isBreakedUpPrevCheMin; - conditions.isBreakedUpPrevCheMax = isBreakedUpPrevCheMax; - conditions.isX3MaFatsUnderMidPrev = isX3MaFatsUnderMidPrev; - conditions.isX3MaFatsOverSlowPrev = isX3MaFatsOverSlowPrev; - conditions.isAtrUpperEqualsToPeak = isAtrUpperEqualsToPeak; - conditions.isAtrLowerEqualsToVale = isAtrLowerEqualsToVale; - conditions.isNewValeUnderAtrLower = isNewValeUnderAtrLower; - conditions.isStrUpperOverAtrUpper = isStrUpperOverAtrUpper; - conditions.isStrLowerOverAtrLower = isStrLowerOverAtrLower; - conditions.isX3MaFatsUnderSlowPrev = isX3MaFatsUnderSlowPrev; - conditions.isBreakedDownPrevCheMin = isBreakedDownPrevCheMin; - conditions.isBreakedDownPrevCheMax = isBreakedDownPrevCheMax; - conditions.isBreakedDownPrevCheLE1 = isBreakedDownPrevCheLE1; - conditions.isBreakedDownPrevCheLE2 = isBreakedDownPrevCheLE2; - conditions.isBreakedDownPrevCheSE1 = isBreakedDownPrevCheSE1; - conditions.isBreakedDownPrevCheSE2 = isBreakedDownPrevCheSE2; - conditions.isStrUpperUnderAtrUpper = isStrUpperUnderAtrUpper; - conditions.isStrLowerUnderAtrLower = isStrLowerUnderAtrLower; - conditions.isBreakedUpPrevAtrUpper = isBreakedUpPrevAtrUpper; - conditions.isBreakedUpPrevAtrLower = isBreakedUpPrevAtrLower; - conditions.isAtrUpperCrossedUpPeak = isAtrUpperCrossedUpPeak; - conditions.isAtrLowerCrossedUpVale = isAtrLowerCrossedUpVale; - conditions.isX3MaFastCrossedOverMid = isX3MaFastCrossedOverMid; - conditions.isVWapFastCrossedOverMid = isVWapFastCrossedOverMid; - conditions.isRejectedUpPrevAtrUpper = isRejectedUpPrevAtrUpper; - conditions.isRejectedUpPrevAtrLower = isRejectedUpPrevAtrLower; - conditions.isX3MaFastCrossedUnderMid = isX3MaFastCrossedUnderMid; - conditions.isX3MaFastCrossedOverSlow = isX3MaFastCrossedOverSlow; - conditions.isAtrUpperCrossedDownPeak = isAtrUpperCrossedDownPeak; - conditions.isAtrLowerCrossedDownVale = isAtrLowerCrossedDownVale; - conditions.isBreakedDownPrevAtrUpper = isBreakedDownPrevAtrUpper; - conditions.isBreakedDownPrevAtrLower = isBreakedDownPrevAtrLower; - conditions.isVWapFastCrossedUnderMid = isVWapFastCrossedUnderMid; - conditions.isDonLowLowerEqualsToVale = isDonLowLowerEqualsToVale; - conditions.isStrUpperCrossedOverPeak = isStrUpperCrossedOverPeak; - conditions.isStrLowerCrossedOverVale = isStrLowerCrossedOverVale; - conditions.isStrLowerOverDonLowLower = isStrLowerOverDonLowLower; - conditions.isVWapFastCrossedOverSlow = isVWapFastCrossedOverSlow; - conditions.isX3MaFastCrossedUnderSlow = isX3MaFastCrossedUnderSlow; - conditions.isRejectedDownPrevAtrUpper = isRejectedDownPrevAtrUpper; - conditions.isRejectedDownPrevAtrLower = isRejectedDownPrevAtrLower; - conditions.isVWapFastCrossedUnderSlow = isVWapFastCrossedUnderSlow; - conditions.isStrUpperOverDonHighUpper = isStrUpperOverDonHighUpper; - conditions.isStrLowerUnderDonLowLower = isStrLowerUnderDonLowLower; - conditions.isDonHighUpperEqualsToPeak = isDonHighUpperEqualsToPeak; - conditions.isStrUpperCrossedUnderPeak = isStrUpperCrossedUnderPeak; - conditions.isStrLowerCrossedUnderVale = isStrLowerCrossedUnderVale; - conditions.isStrUpperUnderDonHighUpper = isStrUpperUnderDonHighUpper; - conditions.isStrLowerCrossedOverAtrLower = isStrLowerCrossedOverAtrLower; - conditions.isStrUpperCrossedOverAtrUpper = isStrUpperCrossedOverAtrUpper; - conditions.isStrUpperCrossedUnderAtrUpper = isStrUpperCrossedUnderAtrUpper; - conditions.isStrLowerCrossedUnderAtrLower = isStrLowerCrossedUnderAtrLower; - conditions.isStrLowerCrossedOverDonLowLower = isStrLowerCrossedOverDonLowLower; - conditions.isStrUpperCrossedOverDonHighUpper = isStrUpperCrossedOverDonHighUpper; - conditions.isStrLowerCrossedUnderDonLowLower = isStrLowerCrossedUnderDonLowLower; - conditions.isStrUpperCrossedUnderDonHighUpper = isStrUpperCrossedUnderDonHighUpper; - - // - xpvConditions.Clean(); - xhkConditions.Clean(); - xmasConditions.Clean(); - xatrConditions.Clean(); - xstrConditions.Clean(); - xcheConditions.Clean(); - xdonConditions.Clean(); - x3maConditions.Clean(); - xvwapConditions.Clean(); - xtrendConditions.Clean(); - - // - Free(); - - // - return result; - } - - // - protected: - // - - // - private: - // - - // - string mSymbol; // Trading Symbol - ENUM_TIMEFRAMES mPeriod; // Trading Period - - // - // Inputs ... - X121Inputs mInputs; - X121XCCInputs xccInputs; - X121XPVInputs xpvInputs; - X121XHKInputs xhkInputs; - X121XMASInputs xmasInputs; - X121XATRInputs xatrInputs; - X121XDONInputs xdonInputs; - X121XSTRInputs xstrInputs; - X121XCHEInputs xcheInputs; - X121X3MAInputs x3maInputs; - X121XVWAPInputs xvwapInputs; - X121XTRENDInputs xtrendInputs; - - // - int mRSIHandler; -}; - -// \ No newline at end of file