From d50bee9f963a50e2267627c4edd5384d753093c1 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 8 May 2025 14:17:32 +0330 Subject: [PATCH] remove backups ... --- Documents/BKP/1/signallers.tmp.mq5 | 124 - Documents/BKP/1/xcaea.signaller.class.mq5 | 853 -- Documents/BKP/1/xcaea.signaller.lib.mq5 | 1334 --- Documents/BKP/2.mq5 | 1087 --- .../BKP/Indicators/x-saherelm.x121.xca.v1.mq5 | 2452 ------ .../BKP/Indicators/x-saherelm.x121.xca.v2.mq5 | 2487 ------ .../BKP/Indicators/x-saherelm.x121.xswlh.mq5 | 573 -- .../BKP/signallers1/xcaea.signaller.class.mq5 | 1070 --- .../BKP/signallers1/xcaea.signaller.lib.mq5 | 2810 ------ Documents/BKP/test.tmp.mq5 | 273 - Documents/BKP/xcaea.signaller.class.mq5 | 878 -- .../BKP/xcaea.x-poi.detector.class.bkp.mq5 | 4936 ----------- Documents/BKP/xcaea.x-poi.detector.class.mq5 | 7731 ----------------- .../BKP/xcaea.x-poi.drawer.class.bkp.mq5 | 2329 ----- Documents/BKP/xcaea.x-poi.drawer.class.mq5 | 2424 ------ 15 files changed, 31361 deletions(-) delete mode 100644 Documents/BKP/1/signallers.tmp.mq5 delete mode 100644 Documents/BKP/1/xcaea.signaller.class.mq5 delete mode 100644 Documents/BKP/1/xcaea.signaller.lib.mq5 delete mode 100644 Documents/BKP/2.mq5 delete mode 100644 Documents/BKP/Indicators/x-saherelm.x121.xca.v1.mq5 delete mode 100644 Documents/BKP/Indicators/x-saherelm.x121.xca.v2.mq5 delete mode 100644 Documents/BKP/Indicators/x-saherelm.x121.xswlh.mq5 delete mode 100644 Documents/BKP/signallers1/xcaea.signaller.class.mq5 delete mode 100644 Documents/BKP/signallers1/xcaea.signaller.lib.mq5 delete mode 100644 Documents/BKP/test.tmp.mq5 delete mode 100644 Documents/BKP/xcaea.signaller.class.mq5 delete mode 100644 Documents/BKP/xcaea.x-poi.detector.class.bkp.mq5 delete mode 100644 Documents/BKP/xcaea.x-poi.detector.class.mq5 delete mode 100644 Documents/BKP/xcaea.x-poi.drawer.class.bkp.mq5 delete mode 100644 Documents/BKP/xcaea.x-poi.drawer.class.mq5 diff --git a/Documents/BKP/1/signallers.tmp.mq5 b/Documents/BKP/1/signallers.tmp.mq5 deleted file mode 100644 index f0300681..00000000 --- a/Documents/BKP/1/signallers.tmp.mq5 +++ /dev/null @@ -1,124 +0,0 @@ - // - // Parsing Pivots ... - - // - // Detect Selected Pivot ... - XBoxZone lastOSCPivot; - double providedSL = 0; - bool hasNewOSC = false; - bool hasPivots = HasChild(pivots); - if (hasPivots) - { - // - // Detect Selected Pivots ... - count = ArraySize(pivots); - for (int i = 0; i < count; i++) - { - // - XBoxZone iPivot = pivots[i]; - - // - // Detect Selected Last OSC Pivots ... - bool isOSC = - Contains( - "XCA_RSI", - iPivot.type // - ) || - Contains( - "XCA_CCI", - iPivot.type // - ); - bool canSetOSC = - !isOSC - ? false - : !lastOSCPivot.IsValid() - ? true - : lastOSCPivot.from < iPivot.from; - if (canSetOSC) - { - // - lastOSCPivot = iPivot; - - // - // Detect New OSC Pivot Happens ... - hasNewOSC = lastOSCPivot.IsValid() && - cBar.time == lastOSCPivot.to; - } - - // - // Check Pivot Box Type ... - bool isPVPivot = - Contains( - "XCA_PEAKSWHRES", - iPivot.type // - ) || - Contains( - "XCA_VALESWLSUP", - iPivot.type // - ); - if (isPVPivot) - { - // - // Select Box for OSC ... - if (hasNewOSC) - { - // - bool canSelectBox = - pivotBox.IsValid() - ? false - : lastOSCPivot.dir == iPivot.dir && - (IsBullish(iPivot.dir) - ? lastOSCPivot.upper > iPivot.upper && - lastOSCPivot.lower < iPivot.upper && - lastOSCPivot.lower <= iPivot.lower - : lastOSCPivot.lower < iPivot.lower && - lastOSCPivot.upper > iPivot.lower && - lastOSCPivot.upper >= iPivot.upper); - if (canSelectBox) - { - pivotBox = iPivot; - } - } - } - - // - iPivot.Clean(); - - // - } - } - - // - // Signaller Summarization ... - - // - // Cond1 Act Using PEAK VALE Box Activation or Rejection ... - - // - bool isCond1Bullish = - // - hasNewOSC && - (cVale < pVale || - pVale < p2Vale) && - pivotBox.IsValid() && - pivotBox.IsBullish() && - lastOSCPivot.IsBullish() && - conditions.isValeIsPivot - // - ; - - // - bool isCond1Bearish = - // - hasNewOSC && - (cPeak > pPeak || - pPeak > p2Peak) && - pivotBox.IsValid() && - pivotBox.IsBearish() && - lastOSCPivot.IsBearish() && - conditions.isPeakIsPivot - // - ; - -//////////////////////////////////////////////////////////////////// - diff --git a/Documents/BKP/1/xcaea.signaller.class.mq5 b/Documents/BKP/1/xcaea.signaller.class.mq5 deleted file mode 100644 index 71f8c5f1..00000000 --- a/Documents/BKP/1/xcaea.signaller.class.mq5 +++ /dev/null @@ -1,853 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEASignaller ... -// Description: Class for XCAEA Signaller ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA Signaller" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.base.class.mq5" -#include "../../Classes/x-saherelm.x-cobject.class.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" -#include "../Classes/xcaea.x-poi.drawer.class.mq5" -#include "../Helpers/xcaea.helper.mq5" -#include "../Libraries/xcaea.signaller.lib.mq5" - -// -// Definitions ... - -class XCXCAEASignaller : XCBase -{ - // - // Public ... - public: - // - // Props ... - bool useGuards; - XCAEAInputs inputs; - XBarTracker barTraker; - XCXCAEAHelper *helper; - XCXCAEAPOIDrawer *drawer; - bool continuesRFTillTarget; - XBoxZone unAvailableBoxes[]; - XCXCAEAPOIDetector *detector; - XCAEAStrategyConditions mConditions; - XCAEAStrategyConditions mConditionsCollection[]; - - // - // Constructor ... - XCXCAEASignaller( - string _symbol, - ENUM_TIMEFRAMES _period // - ) - { - // - symbol = _symbol; - period = _period; - - // - Init(); - } - - // - // Deconstructor ... - ~XCXCAEASignaller() - { - DeInit(); - } - - // - // Properties ... - - string GetSymbol() - { - return symbol; - } - - ENUM_TIMEFRAMES GetPeriod() - { - return period; - } - - // - // Signaller Tools ... - - /** - * Detect Setup Conditions based on Signalling ... - * - * @param maxAllowedSLDistanceInPoint: int, Max Allowed SL Distance in Points (if Bigger thn Zero Provided) ... - * - * @return ( bool ) - */ - bool DetectSignalSetup( - double tpReward = 3, - double maxAllowedSLDistanceInPoint = 100 // - ) - { - // - bool result = false; - - // - // Check Bar Processing ... - if (!barTraker.CanProcessBar()) - { - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL pPBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - 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(); - - // - return result; - } - - // - // Setup Conditions ... - XBoxZone boxes[]; - XBoxZone pivotBox; - XBoxZone signalBox; - double additionalSL = 0; - XBoxZone bullishBoxes[]; - XBoxZone bearishBoxes[]; - bool hasSignalBox = false; - XCAEAConditions conditions; - ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; - - // - // Detecting Pivots ... - detector.Update( - zIndex // - ); - - // - // Validate Pivots ... - detector.Validate( - unAvailableBoxes, - zIndex // - ); - - // - // Draw Founded Pivots ... - drawer.Draw(cTime); - - // - // Retrieve Valid Boxes ... - - // // - // // Bullish ... - // int bullishBoxesCount = - // detector - // .FillBullishBoxes(bullishBoxes); - - // // - // // Bearish ... - // int bearishBoxesCount = - // detector - // .FillBearishBoxes(bearishBoxes); - - // // - // Copy( - // bullishBoxes, - // boxes, - // false // - // ); - // Copy( - // bearishBoxes, - // boxes, - // false // - // ); - int boxesCount = ArraySize(boxes); - bool hasBoxes = IsValidSize(boxesCount); - - // - // Filter UnAvailable Boxes ... - if (hasBoxes) - { - // - // Remove UnAvailable Boxes ... - has = HasChild(unAvailableBoxes); - if (has) - { - // - count = ArraySize(unAvailableBoxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = unAvailableBoxes[i]; - - // - has = FindBoxIndex( - idx, - iBox, - boxes // - ); - if (has) - { - // - ArrayRemove( - boxes, - idx, - 1 // - ); - } - } - } - - // - hasBoxes = HasChild(boxes); - boxesCount = ArraySize(boxes); - } - - // - // - // - - // - // if (hasBoxes) - // { - // } - - // - // Detect Sinal Box ... - hasSignalBox = DetectXCAEAConditions( - boxes, - conditions, - pivotBox, - signalBox, - additionalSL, - signalBoxDir, - helper, - zIndex, - loopback // - ); - - // - // Make Pivot Box UnAvailable ... - if (pivotBox.IsValid()) - { - // - AddRef( - pivotBox, - unAvailableBoxes // - ); - } - - // - isBullish = hasSignalBox && - IsBullish(signalBoxDir); - - // - isBearish = hasSignalBox && - IsBearish(signalBoxDir); - - // - result = isBullish || - isBearish; - if (result) - { - // - // Do What we Want ... - barTraker.Waits(); - - // - // Draw Signal Box ... - XCBoxObject *iObj; - bool isCreated = helper.poiDrawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - mObjects.Add(iObj); - ZeroMemory(iObj); - - // - Print("Signal Box ..."); - } - - // - // Prepare Conditions ... - mConditions.symbol = symbol; - mConditions.period = period; - - // - double spread = GetSpread(symbol); - - // - double entry = - isBullish - ? signalBox.upper - : signalBox.lower; - - // - double sl = - isBullish - ? signalBox.lower - : signalBox.upper; - if (additionalSL > 0) - { - // - sl = - isBullish - ? sl - additionalSL - : sl + additionalSL; - } - - // - double risk = - isBullish - ? entry - sl - : sl - entry; - risk += spread; - if (risk >= maxAllowedSLDistanceInPoint * points) - { - // - // Fix Risk in Big Distances ... - double hh5 = zBar.FindHighest(5, MODE_HIGH); - double ll5 = zBar.FindLowest(5, MODE_LOW); - - // - double hhll5Delta = hh5 - ll5; - double riskDelta = hhll5Delta / 2; - risk = riskDelta; - } - - // - double rewardTP = risk * tpReward; - - // - double tp = - isBullish - ? entry + rewardTP - : entry - rewardTP; - - // - // Filling ... - mConditions.sl = sl; - mConditions.tp = tp; - mConditions.pivot = - isBullish - ? sl - : entry; - mConditions.point = - isBullish - ? entry - : sl; - mConditions.dir = signalBoxDir; - mConditions.provider = "XCAEA"; - mConditions.signalBox = signalBox; - mConditions.setupTime = zBar.time; - mConditions.conditions = conditions; - - // - // Select RF Rewards ... - if (continuesRFTillTarget) - { - // - double rfReward = 1; - while (rfReward < tpReward) - { - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - - // - rfReward++; - } - } - else - { - // - double rfReward = 1; - - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - } - } - - // - // Cleanup Resource ... - - // - Clean(boxes); - Clean(bullishBoxes); - Clean(bearishBoxes); - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - - // - pivotBox.Clean(); - signalBox.Clean(); - conditions.Clean(); - - // - return result; - } - - /** - * Detect Trigger Conditions for Specified Signal ... - * - * @param conditions: XCAEAStrategyConditions instance Reference, Specified Signal Conditions ... - * @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ... - * - * @return ( bool ) - */ - bool DetectSignalTrigger( - XCAEAStrategyConditions &conditions, - int maxAllowedSetupAge = 60 // - ) - { - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Check Signal Validation ... - // IMPORTANT: since all Validations done in SetUp Process ... - // here we only Execute Signal ... - - // - result = isBullish || - isBearish; - - // - if (result) - { - // - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - } - - // - // Cleanup ... - - // - return result; - } - - /** - * Detect Guards bsed on Signalling Class ... - * - * @param guards: XCAEAGuard instance Collection, Holds Provided Guards ... - * @param positions: XPosition instance Collection, Provides Signalling Based Positions for Apply Guards on them ... - * @param provider: X121SMCStrategySignalProviderData instance Reference, Specified Data for Cycles ... - * - * @return ( bool ) - */ - bool DetectGuards( - XCAEAGuard &guards[], - const XPosition &positions[] // - ) - { - // - bool result = false; - - // - return result; - } - - /** - * Add Conditions to Conditions Collection if not Exists ... - * - * @param maxAllowed: int, Specified Max Allowed Holding Conditions ... - * - * @return ( int ) - */ - int AddConditionsIfNotExists( - int maxAllowed = 10 // - ) - { - // - int result = 0; - - // - bool isSetuped = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(mConditionsCollection); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - XCAEAStrategyConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - XCAEAStrategyConditions iItem = tmpItems[i]; - - // - bool canRemove = mConditions.dir == iItem.dir && - mConditions.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - mConditionsCollection, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - mConditions, - mConditionsCollection // - ); - - // - // Remove Olds ... - CleanupArray( - mConditionsCollection, - maxAllowed // - ); - - // - result = ArraySize(mConditionsCollection); - - // - return result; - } - - // - // Protected ... - protected: - // - - // - // Private ... - private: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - CArrayObj mObjects; - CArrayObj mBarObjects; - - /** - * Initialize ... - */ - void Init() - { - // - useGuards = false; - continuesRFTillTarget = true; - - // - barTraker.Init( - symbol, - period // - ); - - // - inputs.Default(); - - // - // Configure Indicators ... - - // - // XCC ... - inputs.ccInputs.showCandles = true; - - // - // XCT ... - inputs.ctInputs.showCandleTime = true; - - // - // XCA ... - - // - inputs.caInputs.supResSmoothingLength = 7; - inputs.caInputs.supResSmoothingMode = X_MA_MODE_NONE; - - // - inputs.caInputs.showKI = true; - inputs.caInputs.showTKI = false; - inputs.caInputs.showSar = false; - inputs.caInputs.showVidya = true; - inputs.caInputs.showTrend = false; - inputs.caInputs.showSwings = false; - inputs.caInputs.showLongCycle = false; - inputs.caInputs.showHindCycle = false; - inputs.caInputs.showFiboLevel1 = false; - inputs.caInputs.showFiboLevel2 = false; - inputs.caInputs.showFiboLevel3 = false; - inputs.caInputs.showShortCycle = false; - inputs.caInputs.showMediumCycle = false; - inputs.caInputs.showPeaksAndVales = true; - inputs.caInputs.showPeakAndValeGolden = false; - inputs.caInputs.showSupportAndResistance = false; - - // - // XOSCS ... - // inputs.oscsInputs.rsiLength = 5; - // inputs.oscsInputs.cciLength = 5; - // inputs.oscsInputs.mfiLength = 5; - // inputs.oscsInputs.rviLength = 5; - - // - // Oscillators Views ... - inputs.showCCI = false; - inputs.showRSI = false; - inputs.showMFI = false; - inputs.showRVI = false; - inputs.showADX = false; - inputs.showMACD = false; - - // - // XCAEA Helper ... - helper = new XCXCAEAHelper(); - helper.Init( - symbol, - period, - inputs // - ); - - // - // Initialize and Configure Detector ... - detector = new XCXCAEAPOIDetector(helper); - - // - // Configure Detector ... - detector.detectRSIPeakPivots = true; - detector.detectRSIValePivots = true; - detector.detectCCIPeakPivots = true; - detector.detectCCIValePivots = true; - detector.detectFVGBullishPivots = true; - detector.detectFVGBearishPivots = true; - detector.detectValeSupSWLPivots = true; - detector.detectPeakResSWHPivots = true; - detector.detectPVFVGBullishPivots = true; - detector.detectPVFVGBearishPivots = true; - - // - // Initialize and Configure Drawer ... - drawer = new XCXCAEAPOIDrawer(detector); - - // - drawer.ignoreUpdateOSCTos = true; - - // - // Configure Drawer ... - drawer.drawRSIPeakPivots = true; - drawer.drawRSIValePivots = true; - drawer.drawCCIPeakPivots = true; - drawer.drawCCIValePivots = true; - drawer.drawFVGBullishPivots = false; - drawer.drawFVGBearishPivots = false; - drawer.drawValeSupSWLPivots = true; - drawer.drawPeakResSWHPivots = true; - drawer.drawPVFVGBullishPivots = true; - drawer.drawPVFVGBearishPivots = true; - - // - // Configure Widths ... - drawer.rsiPeakPivotsWidth = 4; - drawer.rsiValePivotsWidth = 4; - drawer.cciPeakPivotsWidth = 4; - drawer.cciValePivotsWidth = 4; - drawer.fvgBullishPivotsWidth = 2; - drawer.fvgBearishPivotsWidth = 2; - drawer.valeSupSWLPivotsWidth = 1; - drawer.peakResSWHPivotsWidth = 1; - drawer.pvFVGBullishPivotsWidth = 1; - drawer.pvFVGBearishPivotsWidth = 1; - - // - // Configure Colors ... - drawer.rsiPeakPivotsColor = clrMagenta; - drawer.rsiValePivotsColor = clrAqua; - drawer.cciPeakPivotsColor = clrMagenta; - drawer.cciValePivotsColor = clrAqua; - drawer.fvgBullishPivotsColor = clrLime; - drawer.fvgBearishPivotsColor = clrRed; - drawer.valeSupSWLPivotsColor = clrAqua; - drawer.peakResSWHPivotsColor = clrMagenta; - drawer.pvFVGBullishPivotsColor = clrLime; - drawer.pvFVGBearishPivotsColor = clrRed; - - // - // Configures Styles ... - drawer.rsiPeakPivotsStyle = STYLE_DASH; - drawer.rsiValePivotsStyle = STYLE_DASH; - drawer.cciPeakPivotsStyle = STYLE_DASH; - drawer.cciValePivotsStyle = STYLE_DASH; - drawer.fvgBullishPivotsStyle = STYLE_DASHDOTDOT; - drawer.fvgBearishPivotsStyle = STYLE_DASHDOTDOT; - drawer.valeSupSWLPivotsStyle = STYLE_SOLID; - drawer.peakResSWHPivotsStyle = STYLE_SOLID; - drawer.pvFVGBullishPivotsStyle = STYLE_DASHDOTDOT; - drawer.pvFVGBearishPivotsStyle = STYLE_DASHDOTDOT; - - // - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - inputs.Clean(); - - // - ZeroMemory(drawer); - ZeroMemory(helper); - ZeroMemory(detector); - - // - mConditions.Clean(); - Clean(mConditionsCollection); - - // - mObjects.Clear(); - mBarObjects.Clear(); - - // - barTraker.Clean(); - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/1/xcaea.signaller.lib.mq5 b/Documents/BKP/1/xcaea.signaller.lib.mq5 deleted file mode 100644 index cd29c16b..00000000 --- a/Documents/BKP/1/xcaea.signaller.lib.mq5 +++ /dev/null @@ -1,1334 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCAEASignaller Lib -// Description: Library for XCAEA Signaller ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Library for XCAEA Signaller" -#property strict - -// -// Imports ... -#include "../../Libraries/x-saherelm.common.lib.mq5" -#include "../../Libraries/x-saherelm.x-poi.lib.mq5" -#include "../../Libraries/x-saherelm.x-trade.lib.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" -#include "../Helpers/xcaea.helper.mq5" - -// -// Enumeration ... - -// -// Guard Actions ... -enum ENUM_GUARD_ACTIONS -{ - X_GUARD_ACTION_NONE, // Nothing to Do - X_GUARD_ACTION_CLOSE, // Close Specified Position - X_GUARD_ACTION_CLOSE_ALL, // Close All Positions - X_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions - X_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position - X_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position - X_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position - X_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position - X_GUARD_ACTION_HEDGE, // Hedge Specified Positions -}; - -// -// Definitions ... - -// -// Conditions Struct ... -struct XCAEAStrategyConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - // Setup Props ... - - // - double sl; - double tp; - double pivot; - double point; - string provider; - double targets[]; - - // - datetime time; - datetime setupTime; - datetime triggerTime; - - // - XBoxZone signalBox; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - XCAEAConditions conditions; - - // - // Constructor ... - XCAEAStrategyConditions() - { - Default(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - tp = 0; - pivot = 0; - point = 0; - - // - symbol = NULL; - period = NULL; - provider = NULL; - - // - time = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - Clean(targets); - - // - signalBox.Clean(); - conditions.Clean(); - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - ZeroMemory(this); - } - - /** - * Default ... - */ - void Default() - { - // - sl = 0; - tp = 0; - pivot = 0; - point = 0; - - // - symbol = NULL; - period = NULL; - provider = NULL; - - // - time = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - Clean(targets); - - // - signalBox.Clean(); - conditions.Clean(); - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - } - - // - // Signalling ... - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = IsSpecifiedValid(symbol) && - IsSpecifiedValid(period) && - IsSpecifiedValid(time); - - // - return result; - } - - /** - * Check Conditions Has Valid Bullish Signal ... - * - * @return ( bool ) - */ - bool HasBullishSignal() - { - // - bool result = false; - - // - result = - (sl > 0 || - tp > 0) && - IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - result = - IsBullish(dir); - - // - return result; - } - - /** - * Check Conditions Has Valid Bearish Signal ... - * - * @return ( bool ) - */ - bool HasBearishSignal() - { - // - bool result = false; - - // - result = - (sl > 0 || - tp > 0) && - IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - result = - IsBearish(dir); - - // - return result; - } - - // - // Setting Up and Triggering Up ... - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // -}; - -// -// Model a Guard Action ... -struct XCAEAGuard -{ - // - // Props ... - ENUM_GUARD_ACTIONS action; - datetime time; - - // - string symbol; - string provider; - - // - // Specified Position ... - ulong ticket; - - // - // Partial Close ... - double volumeMultiplier; - - // - // SL Trial ... - double sl; - - // - // TP Trial ... - double tp; - - // - // Constructor ... - XCAEAGuard() - { - Default(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - time = NULL; - action = X_GUARD_ACTION_NONE; - - // - symbol = NULL; - provider = NULL; - - // - ticket = 0; - - // - volumeMultiplier = 0; - - // - sl = 0; - tp = 0; - - // - ZeroMemory(this); - } - - /** - * Default ... - */ - void Default() { - // - time = NULL; - action = X_GUARD_ACTION_NONE; - - // - symbol = NULL; - provider = NULL; - - // - ticket = 0; - - // - volumeMultiplier = 0; - - // - sl = 0; - tp = 0; - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(time) && - IsValid(symbol) && - IsValid(provider) && - action != X_GUARD_ACTION_NONE - // - ; - if (!result) - { - return result; - } - - // - // Validate Model Based On Specified Guard Actions ... - - // - return result; - } -}; - -/** - * Add Guard to Collection ... - * - * @param guard: XCAEAGuard instance ... - * @param guards: XCAEAGuard instance Collection ... - * - * @return ( int ) - */ -int AddGuard( - XCAEAGuard &guard, - XCAEAGuard &guards[] // -) -{ - // - int result = 0; - - // - if (!guard.IsValid()) - { - return result; - } - - // - AddRef( - guard, - guards // - ); - - // - result = ArraySize(guards); - - // - return result; -} - -// -bool DetectXCAEAConditions( - XBoxZone &boxes[], - XCAEAConditions &conditions, - XBoxZone &pivotBox, - XBoxZone &box, - double &additionalSL, - ENUM_X_DIRECTION &dir, - XCXCAEAHelper *helper, - int barIndex = 0, - int loopback = 10 // -) -{ - // - bool result = false; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - box.Clean(); - additionalSL = 0; - conditions.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - loopback = NormalizeInt(loopback, 5); - - // - string symbol = helper.GetSymbol(); - ENUM_TIMEFRAMES period = helper.GetPeriod(); - double points = GetPoints(symbol); - - // - XCAEAConditions pConditions; - result = helper.GetConditions( - conditions, - barIndex, - loopback // - ); - result = result && - helper.GetConditions( - pConditions, - barIndex + 1, - loopback // - ); - if (!result) - { - // - conditions.Clean(); - pConditions.Clean(); - - // - return result; - } - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - int p4IDX = p3IDX + 1; - - // - // Reading Parameters ... - - // - // KI ... - - // - double cKI = conditions.kiBuffer[cIDX]; - double pKI = conditions.kiBuffer[pIDX]; - double p2KI = conditions.kiBuffer[p2IDX]; - - // - double cKIState = conditions.kiStateBuffer[cIDX]; - double pKIState = conditions.kiStateBuffer[pIDX]; - double p2KIState = conditions.kiStateBuffer[p2IDX]; - - // - // TKI ... - - // - double cTKI = conditions.tkiBuffer[cIDX]; - double pTKI = conditions.tkiBuffer[pIDX]; - double p2TKI = conditions.tkiBuffer[p2IDX]; - - // - double cTKIState = conditions.tkiStateBuffer[cIDX]; - double pTKIState = conditions.tkiStateBuffer[pIDX]; - double p2TKIState = conditions.tkiStateBuffer[p2IDX]; - - // - // TREND ... - - // - double cTrend = conditions.trendBuffer[cIDX]; - double pTrend = conditions.trendBuffer[pIDX]; - double p2Trend = conditions.trendBuffer[p2IDX]; - - // - double ctrendState = conditions.trendStateBuffer[cIDX]; - double ptrendState = conditions.trendStateBuffer[pIDX]; - double p2trendState = conditions.trendStateBuffer[p2IDX]; - - // - // SWING Low ... - double cSWL = conditions.swingLowBuffer[cIDX]; - double pSWL = conditions.swingLowBuffer[pIDX]; - double p2SWL = conditions.swingLowBuffer[p2IDX]; - - // - // SWING High ... - double cSWH = conditions.swingHighBuffer[cIDX]; - double pSWH = conditions.swingHighBuffer[pIDX]; - double p2SWH = conditions.swingHighBuffer[p2IDX]; - - // - // PEAK ... - double zPeak = conditions.peakBuffer[zIDX]; - double cPeak = conditions.peakBuffer[cIDX]; - double pPeak = conditions.peakBuffer[pIDX]; - double p2Peak = conditions.peakBuffer[p2IDX]; - double p3Peak = conditions.peakBuffer[p3IDX]; - - // - // VALE ... - double zVale = conditions.valeBuffer[zIDX]; - double cVale = conditions.valeBuffer[cIDX]; - double pVale = conditions.valeBuffer[pIDX]; - double p2Vale = conditions.valeBuffer[p2IDX]; - double p3Vale = conditions.valeBuffer[p3IDX]; - - // - // VIDYA ... - double zVidya = conditions.vidyaBuffer[zIDX]; - double cVidya = conditions.vidyaBuffer[cIDX]; - double pVidya = conditions.vidyaBuffer[pIDX]; - double p2Vidya = conditions.vidyaBuffer[p2IDX]; - double p3Vidya = conditions.vidyaBuffer[p3IDX]; - - // - double zVidyaState = conditions.vidyaStateBuffer[zIDX]; - double cVidyaState = conditions.vidyaStateBuffer[cIDX]; - double pVidyaState = conditions.vidyaStateBuffer[pIDX]; - double p2VidyaState = conditions.vidyaStateBuffer[p2IDX]; - double p3VidyaState = conditions.vidyaStateBuffer[p3IDX]; - - // - // RSI ... - double zRSI = conditions.rsiBuffer[zIDX]; - double cRSI = conditions.rsiBuffer[cIDX]; - double pRSI = conditions.rsiBuffer[pIDX]; - double p2RSI = conditions.rsiBuffer[p2IDX]; - double p3RSI = conditions.rsiBuffer[p3IDX]; - - // - // CCI ... - double zCCI = conditions.cciBuffer[zIDX]; - double cCCI = conditions.cciBuffer[cIDX]; - double pCCI = conditions.cciBuffer[pIDX]; - double p2CCI = conditions.cciBuffer[p2IDX]; - double p3CCI = conditions.cciBuffer[p3IDX]; - - // - // RVI ... - - // - double zRVI = conditions.rviBuffer[zIDX]; - double cRVI = conditions.rviBuffer[cIDX]; - double pRVI = conditions.rviBuffer[pIDX]; - double p2RVI = conditions.rviBuffer[p2IDX]; - double p3RVI = conditions.rviBuffer[p3IDX]; - - // - double zRVISignal = conditions.rviSignalBuffer[zIDX]; - double cRVISignal = conditions.rviSignalBuffer[cIDX]; - double pRVISignal = conditions.rviSignalBuffer[pIDX]; - double p2RVISignal = conditions.rviSignalBuffer[p2IDX]; - double p3RVISignal = conditions.rviSignalBuffer[p3IDX]; - - // - // Reading Bars ... - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - XOHCL p3Bar; - XOHCL p4Bar; - result = zBar.Init( - symbol, - period, - zIDX // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(p2Bar); - result = - result && - p2Bar.GetPreviousBar(p3Bar); - result = - result && - p3Bar.GetPreviousBar(p4Bar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - p3Bar.Clean(); - p4Bar.Clean(); - - // - box.Clean(); - conditions.Clean(); - pConditions.Clean(); - - // - return result; - } - - // - // Bars Conditions ... - - // - ENUM_X_DIRECTION cBarDir; - - // - // Hammer ... - bool isCBarHammer = helper - .barAnalyser - .IsHammer( - cBar, - cBarDir // - ); - bool isCBarBullishHammer = - isCBarHammer && - IsBullish(cBarDir); - bool isCBarBearishHammer = - isCBarHammer && - IsBearish(cBarDir); - - // - // Rejected ... - bool isCBarRejected = helper - .barAnalyser - .IsRejected( - cBar, - cBarDir, - false, // Force Type ... - true // Force Fibo Pressure ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarDir); - - // - // Engulfed ... - bool isCBarEngulfed = helper - .barAnalyser - .IsEngulfed( - cBar, - cBarDir // - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarDir); - - // - // Momentum ... - bool isCBarMomentum = helper - .barAnalyser - .IsMomentum( - cBar, - cBarDir, - 1 // - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarDir); - - // - // Bar Sumarise ... - - // - bool isCBarValidForBullish = - (isCBarBullishHammer || - isCBarBullishRejected || - isCBarBullishMomentum || - isCBarBullishEngulfed); - - // - bool isCBarValidForBearish = - (isCBarBearishHammer || - isCBarBearishRejected || - isCBarBearishMomentum || - isCBarBearishEngulfed); - - // - // Score ... - - // - double bullishScore = 0; - double bearishScore = 0; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isScoreBullish = - bullishScore > bearishScore; - - // - bool isScoreBearish = - bearishScore > bullishScore; - - // - string summary = - conditions - .GenerateSummary(); - - // - // Conditions ... - - // - bool isRSIBullish = - zRSI >= cRSI && - cRSI > pRSI; - bool isRSIBearish = - zRSI <= cRSI && - cRSI < pRSI; - - // - bool isCCIBullish = - zCCI >= cCCI && - cCCI > pCCI && - (zCCI > conditions.cciOSLevel || - cCCI > conditions.cciOSLevel); - bool isCCIBearish = - zCCI >= cCCI && - cCCI > pCCI && - (zCCI < conditions.cciOBLevel || - cCCI < conditions.cciOBLevel); - - // - // Detect Selected Box ... - XBoxZone oscBoxes[]; - XBoxZone lastOSCBox; - double providedSL = 0; - bool isBoxFVG = false; - bool hasOSCBox = false; - bool hasPivotBox = false; - bool isBoxPeakVale = false; - bool isBoxRejected = false; - bool isBoxActivated = false; - bool isBoxFullSifeRejected = false; - bool hasBoxes = HasChild(boxes); - if (hasBoxes) - { - // - // Detect Selected Boxes ... - XBoxZone tmp[]; - Copy( - boxes, - tmp // - ); - while (HasChild(tmp)) - { - // - idx = GetYoungest(tmp); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox; - iBox = tmp[idx]; - ArrayRemove( - tmp, - idx, - 1 // - ); - - // - // Check Selected Box not RSI or CCI ... - isBoxFVG = Contains( - "XCA_FVG", - iBox.type // - ); - isBoxPeakVale = - Contains( - "XCA_PEAKSWHRES", - iBox.type // - ) || - Contains( - "XCA_VALESWLSUP", - iBox.type // - ); - has = isBoxFVG || - isBoxPeakVale; - if (!has) - { - // - bool isOSC = Contains( - "XCA_CCI_VALE", - iBox.type // - ) || - Contains( - "XCA_CCI_PEAK", - iBox.type // - ) || - Contains( - "XCA_RSI_VALE", - iBox.type // - ) || - Contains( - "XCA_RSI_PEAK", - iBox.type // - ); - if (isOSC) - { - // - AddRef( - iBox, - oscBoxes // - ); - } - - // - iBox.Clean(); - - // - continue; - } - - // - bool isBullish = iBox.IsBullish(); - bool isBearish = iBox.IsBearish(); - - // - double rejectedCheckPrice = - isBullish - ? iBox.upper - : iBox.lower; - double rejectedFullCheckPrice = - isBullish - ? iBox.lower - : iBox.upper; - - // - // Check Box Selecting Senarios ... - - // - // Selecting Rejected Boxes ... - isBoxRejected = cBar.IsRejected( - rejectedCheckPrice, - iBox.dir, - false, - false // - ); - - // - // Selecting Rejected Boxes ... - isBoxFullSifeRejected = cBar.IsRejected( - rejectedFullCheckPrice, - iBox.dir, - false, - false // - ); - - // - // Selecting Activation Boxes ... - - // - bool isBullishActivated = - isBullish && - cBar.IsBullish() && - cBar.GetUp() > rejectedCheckPrice && - cBar.GetDown() < rejectedCheckPrice; - - // - bool isBearishActivated = - isBearish && - cBar.IsBearish() && - cBar.GetUp() > rejectedCheckPrice && - cBar.GetDown() < rejectedCheckPrice; - - // - isBoxActivated = isBullishActivated || - isBearishActivated; - - // - // Detect Box is Selected or not ... - has = - isBoxRejected || - isBoxActivated || - isBoxFullSifeRejected; - if (has) - { - // - pivotBox = iBox; - - // - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - - // - Clean(tmp); - } - - // - // Check OSC Boxes ... - bool hasOSCBoxes = HasChild(oscBoxes); - if (hasOSCBoxes) - { - // - // Detect Newest OSC Box ... - idx = GetYoungest(oscBoxes); - has = IsValidIndex(idx); - if (has) - { - lastOSCBox = oscBoxes[idx]; - } - - // - // Validate OSC Box is Valid or not ... - has = lastOSCBox.IsValid(); - if (has) - { - // - // Check Bar is Inside OSC Box or not ... - has = cBar.time > lastOSCBox.from && - cBar.time <= lastOSCBox.to; - if (!has) - { - lastOSCBox.Clean(); - } - } - - // - hasOSCBox = lastOSCBox.IsValid(); - if (hasOSCBox) - { - // // - // XCBoxObject *iObj; - // has = helper.poiDrawer.DrawBox( - // lastOSCBox, - // iObj // - // ); - // if (has) { - // iObj.BoxWidth(4); - // } - } - } - - // - // Force Conditions to Have Selected Box ... - hasPivotBox = hasBoxes && - pivotBox.IsValid(); - if (hasPivotBox) - { - // // - // pivotBox.to = TimeCurrent(); - - // // - // // Draw Pivot Box Here ... - // if (isBoxPeakVale) - // { - // // - // XCBoxObject *iObj; - // has = helper.poiDrawer.DrawBox( - // pivotBox, - // iObj // - // ); - // if (has) - // { - // // - // iObj.BoxWidth(5); - // iObj.BoxColor(clrDodgerBlue); - // Print("Draw Pivot Box ..."); - // } - // } - } - - // - // If all Conditions required Boxes ... - // if (!result) - // { - // // - // zBar.Clean(); - // cBar.Clean(); - // pBar.Clean(); - // p2Bar.Clean(); - // p3Bar.Clean(); - // p4Bar.Clean(); - - // // - // box.Clean(); - // pivotBox.Clean(); - // conditions.Clean(); - - // // - // return result; - // } - - // - // Signaller Summarization ... - - // - // Cond1 Act Using PEAK VALE Box Activation or Rejection ... - - // - bool isCond1Bullish = - // - false && - hasPivotBox && - isBoxPeakVale && - isScoreBullish && - pivotBox.IsBullish() && - (conditions.isValeUnderLast || - (conditions.isValeSameLast && - pConditions.isValeUnderLast)) && - conditions.isRSICrossedOverOS && - conditions.isCCICrossedOverOS - // - ; - - // - bool isCond1Bearish = - // - false && - hasPivotBox && - isBoxPeakVale && - isScoreBearish && - pivotBox.IsBearish() && - (conditions.isPeakOverLast || - (conditions.isPeakSameLast && - pConditions.isPeakOverLast)) && - conditions.isRSICrossedUnderOB && - conditions.isCCICrossedUnderOB - // - ; - - // - bool isCond1 = isCond1Bullish || - isCond1Bearish; - if (isCond1) - { - // - providedSL = - isCond1Bullish - ? MathMin(pBar.low, pivotBox.lower) - : MathMax(pBar.high, pivotBox.upper); - - // - additionalSL = 0.5 * conditions.atrBuffer[cIDX]; - - // - Print("Cond1"); - } - - // - // Cond2 Act Using OSC Box and Vydia ... - - // - bool isCond2Bullish = - // - hasOSCBox && - // cVidyaState < 0 && - lastOSCBox.IsBullish() // && - // lastOSCBox.upper < cVidya - // - ; - - // - bool isCond2Bearish = - // - hasOSCBox && - // cVidyaState > 0 && - lastOSCBox.IsBearish() // && - // lastOSCBox.lower > cVidya - // - ; - - // - bool isCond2 = isCond2Bullish || - isCond2Bearish; - if (isCond2) - { - // - providedSL = - isCond1Bullish - ? MathMin(pBar.low, pivotBox.lower) - : MathMax(pBar.high, pivotBox.upper); - - // - Print("Cond2"); - isCond2Bullish = false; - isCond2Bearish = false; - } - - // - // Cond3 Act Using CCi Peaks and Vales ... - - // - bool isCond3Bullish = false; - - // - bool isCond3Bearish = false; - - // - bool isCond3 = isCond3Bullish || - isCond3Bearish; - if (isCond3) - { - // - - // - Print("Cond3"); - } - - // - // Summarise Conditions ... - - // - bool isBullish = - // - isCond1Bullish || - isCond2Bullish || - isCond3Bullish; - // - ; - - // - bool isBearish = - // - isCond1Bearish || - isCond2Bearish || - isCond3Bearish - // - ; - - // - result = isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double entry = GetEntry( - conditions.symbol, - dir // - ); - - // - double sl = - providedSL > 0 - ? providedSL - : isBullish - ? pivotBox.lower - : pivotBox.upper; - - // - box.dir = dir; - box.symbol = conditions.symbol; - box.period = conditions.period; - - // - box.upper = - isBullish - ? entry - : sl; - - // - box.lower = - isBullish - ? sl - : entry; - - // - box.to = zBar.time; - box.from = p4Bar.time; - - // - box.type = "XCASignal"; - } - - // - result = box.IsValid() && - HasDirection(dir); - - // - // Cleanup Resources ... - - // - if (!result) - { - // - box.Clean(); - pivotBox.Clean(); - conditions.Clean(); - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - p3Bar.Clean(); - p4Bar.Clean(); - Clean(oscBoxes); - pConditions.Clean(); - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/2.mq5 b/Documents/BKP/2.mq5 deleted file mode 100644 index db7e47c9..00000000 --- a/Documents/BKP/2.mq5 +++ /dev/null @@ -1,1087 +0,0 @@ - // - void ApplyManalyswerValidation( - XBoxZone &pivots[], - int barIndex = 0 // - ) - { - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - - // - barIndex = NormalizeInt(barIndex, 0); - - // - bool has = HasChild(pivots); - if (!has) - { - return; - } - - // - XBoxZone tmp[]; - Copy( - pivots, - tmp // - ); - Clean(pivots); - while (HasChild(tmp)) - { - // - XBoxZone iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - // Retrieve Pivot info ... - // int toIDX = iPivot.ToIndex(); - // int fromIDX = iPivot.FromIndex(); - // bool isBullish = iPivot.IsBullish(); - - // - // Retrieve Conditions ... - // XCAEAConditions conditions; - // has = helper.GetConditions( - // conditions, - // toIDX, - // 5 // - // ); - - // - // Retrieve Bars ... - - // - // XOHCL cBar; - // XOHCL pBar; - // XOHCL p2Bar; - - // // - // has = - // has && - // cBar.Init( - // conditions.symbol, - // conditions.period, - // toIDX // - // ); - // has = has && - // cBar.GetPreviousBar(pBar); - // has = has && - // pBar.GetPreviousBar(p2Bar); - // if (!has) - // { - // // - // cBar.Clean(); - // pBar.Clean(); - // p2Bar.Clean(); - // iPivot.Clean(); - // conditions.Clean(); - - // // - // continue; - // } - - // - // Reading Conditions ... - - // // - // // MAL ... - // double zMAL = conditions.malBuffer[zIDX]; - // double cMAL = conditions.malBuffer[cIDX]; - // double pMAL = conditions.malBuffer[pIDX]; - // double p2MAL = conditions.malBuffer[p2IDX]; - - // // - // // MAC ... - // double zMAC = conditions.macBuffer[zIDX]; - // double cMAC = conditions.macBuffer[cIDX]; - // double pMAC = conditions.macBuffer[pIDX]; - // double p2MAC = conditions.macBuffer[p2IDX]; - - // // - // // MAH ... - // double zMAH = conditions.mahBuffer[zIDX]; - // double cMAH = conditions.mahBuffer[cIDX]; - // double pMAH = conditions.mahBuffer[pIDX]; - // double p2MAH = conditions.mahBuffer[p2IDX]; - - // - // Checking Conditions ... - // has = isBullish - // ? cBar.high < cMAL || - // pBar.high < pMAL - // : cBar.low < cMAH || - // pBar.low < pMAL; - - // - has = - isBullish - ? iPivot. - if (has) - { - // - AddRef( - iPivot, - pivots // - ); - } - - // - // Cleanup Resources ... - // cBar.Clean(); - // pBar.Clean(); - // p2Bar.Clean(); - iPivot.Clean(); - // conditions.Clean(); - } - - // - Clean(tmp); - } - - -////////////////////////////////////////////////////////////// - - - // - // Parsing Pivots ... - XBoxZone rciPivot; - double providedSL = 0; - XBoxZone rejectedPivot; - XBoxZone insidePivots[]; - XBoxZone rciContainers[]; - int insidePivotsCount = 0; - bool isRejectedOnMid = false; - bool hasInsidePivots = false; - bool hasRCIContainers = false; - bool hasPivots = HasChild(pivots); - if (hasPivots) - { - // - // drawer.DrawBoxes( - // pivots, - // TimeCurrent() // - // ); - - // - // Select Inside Boxes ... - - // - ENUM_XCA_PIVOTS allowedInsidePivots[] = { - XCA_FVG_BULL, - XCA_FVG_BEAR, - XCA_PEAKSWHRES, - XCA_VALESWLSUP, - XCA_TREND_BULL, - XCA_TREND_BEAR, - }; - insidePivotsCount = SelectInsideBoxes( - allowedInsidePivots, - insidePivots, - pivots, - zBar, - cBar, - pBar, - p2Bar // - ); - hasInsidePivots = IsValidSize(insidePivotsCount); - if (hasInsidePivots) - { - // - // drawer.DrawBoxes( - // insidePivots, - // zBar.time // - // ); - } - - // - // Detect Rejected Pivot ... - ENUM_XCA_PIVOTS allowedRejectedPivots[] = { - XCA_FVG_BULL, - XCA_FVG_BEAR, - // XCA_PEAKSWHRES, - // XCA_VALESWLSUP, - // XCA_TREND_BULL, - // XCA_TREND_BEAR, - }; - has = SelectRejectedBox( - allowedRejectedPivots, - rejectedPivot, - isRejectedOnMid, - pivots, - zBar, - cBar, - pBar, - p2Bar, - false, // Ignore Mid Rejection ... - true, - true // - ); - - // - // Select CCI/RSI Cross Object ... - count = ArraySize(pivots); - for (int i = 0; i < count; i++) - { - // - XBoxZone iPivot = pivots[i]; - - // - ENUM_XCA_PIVOTS iType = GetPivotType(iPivot); - - // - // Checking Type is Passed ... - has = - // - iType == XCA_RSI_COOS || - iType == XCA_CCI_COOS || - iType == XCA_RSI_CUOB || - iType == XCA_CCI_CUOB - // - ; - - // - // Checking cBar is Pivots' Last Bar ... - has = - has && - cBar.time <= iPivot.to && - cBar.time > iPivot.from; - if (has) - { - // - rciPivot = iPivot; - - // - iPivot.Clean(); - - // - break; - } - - // - iPivot.Clean(); - } - - // - // Detect RCI Pivot Containers Pivots ... - count = ArraySize(pivots); - has = rciPivot.IsValid(); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iPivot = pivots[i]; - - // - ENUM_XCA_PIVOTS iType = GetPivotType(iPivot); - - // - // Checking Type is Passed ... - has = - // - IsValid(iType) && - (iType == XCA_PEAKSWHRES || - iType == XCA_VALESWLSUP) - // - ; - - // - // Check Dir is Passed ... - has = - has && - rciPivot.dir == iPivot.dir; - - // - // Check RCI Pivot is Inside Pivot ... - has = - has && - // - ( - // - (rciPivot.lower >= iPivot.lower && - rciPivot.lower < iPivot.upper) - // - || - // - (rciPivot.upper <= iPivot.upper && - rciPivot.upper > iPivot.lower) - // - || - // - (rciPivot.upper > iPivot.upper && - rciPivot.lower < iPivot.lower) - // - ) - // - ; - - // - if (has) - { - // - AddRef( - iPivot, - rciContainers // - ); - } - - // - iPivot.Clean(); - } - - // - hasRCIContainers = HasChild(rciContainers); - } - } - -///////////////////////////////////////////////////////////////////// - - - // - // Box Based Conditions ... - - // - // if (isCBarHasStrongATR) - // { - // // - // Print(ToString(cBar.GetDirection()), " ATR Growing ..."); - // } - - // - // bool isZeroVScore = isScoreNeutural || - // isVolumeNeutural; - - // // - // bool isBullishTested = - // isZeroVScore && - // isCBarValidForBullish // && - // // rejectedPivot.IsValid() && - // // rejectedPivot.IsBullish() - // ; - // bool isBearishTested = - // isZeroVScore && - // isCBarValidForBearish // && - // // rejectedPivot.IsValid() && - // // rejectedPivot.IsBearish() - // ; - - // // - // bool isTested = - // // - // isBullishTested || - // isBearishTested - // // - // ; - // if (isTested) - // { - // // - // Print("Zero Volume ..."); - // } - - -///////////////////////////////////////////////////////////////////// - - - // - bool isCond2Bullish = - // - false // && - // - // conditions. - // - // zPeak > cPeak && - // zBar.close > cPeak && - // ((zPeak - cPeak) > 2 * points) && - // - // z3MAFastState > 0 && - // isValeGoldenRejected && - // isCBarBullishRejected && - // conditions.isValeIsPivot - // - // isPCCIOS && - // isRSIBullish && - // conditions.isCloseUnderMal - // rciPivot.IsValid() && - // rciPivot.IsBullish() && - // isCCIBullish && - // cBar.close > c3MAFast - // isADXBullish && - // hasRCIContainers && - // conditions.isValeIsPivot && - // (conditions.isRSICrossedOverOS || - // conditions.isCCICrossedOverOS) // && - // conditions.swingLowBuffer[cIDX] < conditions.fiboLevel3Buffer[cIDX] - // // - ; - - // - bool isCond2Bearish = - // - false // && - // - // z3MAFastState < 0 && - // isPeakGoldenRejected && - // isCBarBullishRejected && - // conditions.isPeakIsPivot - // - // isPCCIOB && - // isRSIBearish && - // c3MAFastState < 0 && - // conditions.isCloseOverMah - // rciPivot.IsValid() && - // rciPivot.IsBearish() && - // conditions.isRSIOB && - // isCCIBearish && - // cBar.close < c3MAFast - // isADXBearish && - // hasRCIContainers && - // conditions.isPeakIsPivot && - // (conditions.isRSICrossedUnderOB || - // conditions.isCCICrossedUnderOB) // && - // conditions.swingHighBuffer[cIDX] > conditions.fiboLevel1Buffer[cIDX] - // // - ; - - - /////////////////////////////////////////////////////////////////////////////////// - - - // - // bool DetectPeakPivot( - // int barIndex, - // XOHCL &zBar, - // XOHCL &cBar, - // XOHCL &pBar, - // XOHCL &p2Bar, - // XCAEAConditions &conditions // - // ) - // { - // // - // bool result = false; - - // // - // // Validate Args ... - // result = - // // - // barIndex >= 0 && - // zBar.IsValid() && - // cBar.IsValid() && - // pBar.IsValid() && - // p2Bar.IsValid() && - // detectPeakPivots - // // - // ; - // if (!result) - // { - // return result; - // } - - // // - // // Define Requirements ... - - // // - // int zIDX = 0; - // int cIDX = zIDX + 1; - // int pIDX = cIDX + 1; - // int p2IDX = pIDX + 1; - - // // - // datetime cTime = zBar.time; - // string symbol = zBar.symbol; - // ENUM_TIMEFRAMES period = zBar.period; - // double points = GetPoints(symbol); - - // // - // // Reading Conditional Values ... - - // // - // // PEAK ... - // double zPeak = conditions.peakBuffer[zIDX]; - // double cPeak = conditions.peakBuffer[cIDX]; - // double pPeak = conditions.peakBuffer[pIDX]; - // double p2Peak = conditions.peakBuffer[p2IDX]; - - // // - // // PEAK Golden ... - // double zPeakGolden = conditions.peakGoldenBuffer[zIDX]; - // double cPeakGolden = conditions.peakGoldenBuffer[cIDX]; - // double pPeakGolden = conditions.peakGoldenBuffer[pIDX]; - // double p2PeakGolden = conditions.peakGoldenBuffer[p2IDX]; - - // // - // // VALE ... - // double zVale = conditions.valeBuffer[zIDX]; - // double cVale = conditions.valeBuffer[cIDX]; - // double pVale = conditions.valeBuffer[pIDX]; - // double p2Vale = conditions.valeBuffer[p2IDX]; - - // // - // // VALE Golden ... - // double zValeGolden = conditions.valeGoldenBuffer[zIDX]; - // double cValeGolden = conditions.valeGoldenBuffer[cIDX]; - // double pValeGolden = conditions.valeGoldenBuffer[pIDX]; - // double p2ValeGolden = conditions.valeGoldenBuffer[p2IDX]; - - // // - // // SWING High .. - // double zSwingHigh = conditions.swingHighBuffer[zIDX]; - // double cSwingHigh = conditions.swingHighBuffer[cIDX]; - // double pSwingHigh = conditions.swingHighBuffer[pIDX]; - // double p2SwingHigh = conditions.swingHighBuffer[p2IDX]; - - // // - // // SWING Low ... - // double zSwingLow = conditions.swingLowBuffer[zIDX]; - // double cSwingLow = conditions.swingLowBuffer[cIDX]; - // double pSwingLow = conditions.swingLowBuffer[pIDX]; - // double p2SwingLow = conditions.swingLowBuffer[p2IDX]; - - // // - // // SUPPORT ... - // double zSupport = conditions.supportBuffer[zIDX]; - // double cSupport = conditions.supportBuffer[cIDX]; - // double pSupport = conditions.supportBuffer[pIDX]; - // double p2Support = conditions.supportBuffer[p2IDX]; - - // // - // // RESISTANCE ... - // double zResistance = conditions.resistanceBuffer[zIDX]; - // double cResistance = conditions.resistanceBuffer[cIDX]; - // double pResistance = conditions.resistanceBuffer[pIDX]; - // double p2Resistance = conditions.resistanceBuffer[p2IDX]; - - // // - // // Detecting Bar Conditions ... - - // // - // ENUM_X_DIRECTION cBarDir; - - // // - // // Rejected ... - // bool isCBarRejected = helper - // .barAnalyser - // .IsRejected( - // cBar, - // cBarDir, - // false, // Force Type ... - // true // Force Fibo Pressure ... - // ); - // bool isCBarBullishRejected = - // isCBarRejected && - // IsBullish(cBarDir); - // bool isCBarBearishRejected = - // isCBarRejected && - // IsBearish(cBarDir); - - // // - // // Engulfed ... - // bool isCBarEngulfed = helper - // .barAnalyser - // .IsEngulfed( - // cBar, - // cBarDir // - // ); - // bool isCBarBullishEngulfed = - // isCBarEngulfed && - // IsBullish(cBarDir); - // bool isCBarBearishEngulfed = - // isCBarEngulfed && - // IsBearish(cBarDir); - - // // - // // Prepare Conditinal Conditions ... - - // // - // bool isPeakSameLast = cPeak == pPeak; - // bool isPeakSameLastPrev = pPeak == p2Peak; - - // // - // if (applySwingsOnPVPivots) - // { - // // - // isPeakSameLast = - // isPeakSameLast && - // cSwingHigh == cPeak && - // cSwingHigh == pSwingHigh; - - // // - // isPeakSameLastPrev = - // isPeakSameLastPrev && - // pSwingHigh == pPeak && - // pSwingHigh == p2SwingHigh; - // } - - // // - // if (applySupportAndResistanceOnPVPivots) - // { - // // - // isPeakSameLast = - // isPeakSameLast && - // cResistance == cPeak && - // cResistance == pResistance; - - // // - // isPeakSameLastPrev = - // isPeakSameLastPrev && - // pResistance == pPeak && - // pResistance == p2Resistance; - // } - - // // - // bool isPeakSwitchedToSameLast = isPeakSameLast && - // !isPeakSameLastPrev; - // bool isPeakFinishedFromSameLast = !isPeakSameLast && - // isPeakSameLastPrev; - - // // - // // ZERO ... - // // Default Peak and Vale Selection ... - // bool isTypeZeroStart = isPeakFinishedFromSameLast; - // bool isTypeZeroContinue = isPeakSameLast; - // bool isTypeZeroFinished = isPeakSwitchedToSameLast; - // if (isTypeZeroFinished) - // { - // // - // bool hasSelectionType = selectRejectedPVPivots || - // selectEngulfedPVPivots; - - // // - // bool isPVRejected = - // isCBarBearishRejected && - // selectRejectedPVPivots; - - // // - // bool isPVEngulfed = - // isCBarBearishEngulfed && - // selectEngulfedPVPivots; - - // // - // bool isBarPassed = - // !hasSelectionType - // ? true - // : isPVRejected || - // isPVEngulfed; - - // // - // isTypeZeroFinished = - // isBarPassed && - // isTypeZeroFinished; - // if (!isTypeZeroFinished) - // { - // peakPivot.Clean(); - // } - // } - - // // - // // Summarizing Conditions ... - - // // - // result = false; - - // // - // bool hasStartCondition = - // // - // isTypeZeroStart - // // - // ; - // bool hasContinuationCondition = - // // - // isTypeZeroContinue - // // - // ; - // bool hasEndCondition = - // // - // isTypeZeroFinished - // // - // ; - - // // - // // ReInstance Pivot ... - // if (hasStartCondition) - // { - // // - // peakPivot.Clean(); - - // // - // peakPivot.type = XCA_PEAK; - // peakPivot.symbol = symbol; - // peakPivot.period = period; - - // // - // peakPivot.to = pBar.time; - // peakPivot.from = pBar.time; - // peakPivot.value = pPeak; - // peakPivot.reserve = pPeakGolden; - // } - - // // - // // Calculate and Fill Pivot Requirements ... - // if (hasContinuationCondition) - // { - // // - // peakPivot.from = pBar.time; - - // // - // peakPivot.reserve = - // peakPivot.reserve == 0 - // ? pPeakGolden - // : MathMax(peakPivot.reserve, pPeakGolden); - // } - - // // - // // End up Pivot and Store it ... - // if (hasEndCondition) - // { - // // - // result = - // peakPivot.IsValid() && - // peakPivot.GetAge() >= pivotVerifications; - // if (result) - // { - // // - // XBoxZone iBox; - // result = peakPivot.AsBox(iBox); - // if (result) - // { - // // - // newPeakPivotDetected = AddBox( - // iBox, - // peakPivots // - // ); - // } - - // // - // iBox.Clean(); - // } - - // // - // peakPivot.Clean(); - // } - - // // - // return result; - // } - - - - // // - // bool DetectValePivot( - // int barIndex, - // XOHCL &zBar, - // XOHCL &cBar, - // XOHCL &pBar, - // XOHCL &p2Bar, - // XCAEAConditions &conditions // - // ) - // { - // // - // bool result = false; - - // // - // // Validate Args ... - // result = - // // - // barIndex >= 0 && - // zBar.IsValid() && - // cBar.IsValid() && - // pBar.IsValid() && - // p2Bar.IsValid() && - // detectValePivots - // // - // ; - // if (!result) - // { - // return result; - // } - - // // - // // Define Requirements ... - - // // - // int zIDX = 0; - // int cIDX = zIDX + 1; - // int pIDX = cIDX + 1; - // int p2IDX = pIDX + 1; - - // // - // datetime cTime = zBar.time; - // string symbol = zBar.symbol; - // ENUM_TIMEFRAMES period = zBar.period; - // double points = GetPoints(symbol); - - // // - // // Reading Conditional Values ... - - // // - // // PEAK ... - // double zPeak = conditions.peakBuffer[zIDX]; - // double cPeak = conditions.peakBuffer[cIDX]; - // double pPeak = conditions.peakBuffer[pIDX]; - // double p2Peak = conditions.peakBuffer[p2IDX]; - - // // - // // PEAK Golden ... - // double zPeakGolden = conditions.peakGoldenBuffer[zIDX]; - // double cPeakGolden = conditions.peakGoldenBuffer[cIDX]; - // double pPeakGolden = conditions.peakGoldenBuffer[pIDX]; - // double p2PeakGolden = conditions.peakGoldenBuffer[p2IDX]; - - // // - // // VALE ... - // double zVale = conditions.valeBuffer[zIDX]; - // double cVale = conditions.valeBuffer[cIDX]; - // double pVale = conditions.valeBuffer[pIDX]; - // double p2Vale = conditions.valeBuffer[p2IDX]; - - // // - // // VALE Golden ... - // double zValeGolden = conditions.valeGoldenBuffer[zIDX]; - // double cValeGolden = conditions.valeGoldenBuffer[cIDX]; - // double pValeGolden = conditions.valeGoldenBuffer[pIDX]; - // double p2ValeGolden = conditions.valeGoldenBuffer[p2IDX]; - - // // - // // SWING High .. - // double zSwingHigh = conditions.swingHighBuffer[zIDX]; - // double cSwingHigh = conditions.swingHighBuffer[cIDX]; - // double pSwingHigh = conditions.swingHighBuffer[pIDX]; - // double p2SwingHigh = conditions.swingHighBuffer[p2IDX]; - - // // - // // SWING Low ... - // double zSwingLow = conditions.swingLowBuffer[zIDX]; - // double cSwingLow = conditions.swingLowBuffer[cIDX]; - // double pSwingLow = conditions.swingLowBuffer[pIDX]; - // double p2SwingLow = conditions.swingLowBuffer[p2IDX]; - - // // - // // SUPPORT ... - // double zSupport = conditions.supportBuffer[zIDX]; - // double cSupport = conditions.supportBuffer[cIDX]; - // double pSupport = conditions.supportBuffer[pIDX]; - // double p2Support = conditions.supportBuffer[p2IDX]; - - // // - // // RESISTANCE ... - // double zResistance = conditions.resistanceBuffer[zIDX]; - // double cResistance = conditions.resistanceBuffer[cIDX]; - // double pResistance = conditions.resistanceBuffer[pIDX]; - // double p2Resistance = conditions.resistanceBuffer[p2IDX]; - - // // - // // Detecting Bar Conditions ... - - // // - // ENUM_X_DIRECTION cBarDir; - - // // - // // Rejected ... - // bool isCBarRejected = helper - // .barAnalyser - // .IsRejected( - // cBar, - // cBarDir, - // false, // Force Type ... - // true // Force Fibo Pressure ... - // ); - // bool isCBarBullishRejected = - // isCBarRejected && - // IsBullish(cBarDir); - // bool isCBarBearishRejected = - // isCBarRejected && - // IsBearish(cBarDir); - - // // - // // Engulfed ... - // bool isCBarEngulfed = helper - // .barAnalyser - // .IsEngulfed( - // cBar, - // cBarDir // - // ); - // bool isCBarBullishEngulfed = - // isCBarEngulfed && - // IsBullish(cBarDir); - // bool isCBarBearishEngulfed = - // isCBarEngulfed && - // IsBearish(cBarDir); - - // // - // // Prepare Conditinal Conditions ... - - // // - // bool isValeSameLast = cVale == pVale; - // bool isValeSameLastPrev = pVale == p2Vale; - - // // - // if (applySwingsOnPVPivots) - // { - // // - // isValeSameLast = - // isValeSameLast && - // cSwingLow == cVale && - // cSwingLow == pSwingLow; - - // // - // isValeSameLastPrev = - // isValeSameLastPrev && - // pSwingLow == pVale && - // pSwingLow == p2SwingLow; - // } - - // // - // if (applySupportAndResistanceOnPVPivots) - // { - // // - // isValeSameLast = - // isValeSameLast && - // cSupport == cVale && - // cSupport == pSupport; - - // // - // isValeSameLastPrev = - // isValeSameLastPrev && - // pSupport == pVale && - // pSupport == p2Support; - // } - - // // - // bool isValeSwitchedToSameLast = isValeSameLast && - // !isValeSameLastPrev; - // bool isValeFinishedFromSameLast = !isValeSameLast && - // isValeSameLastPrev; - - // // - // // ZERO ... - // // Default Peak and Vale Selection ... - // bool isTypeZeroStart = isValeFinishedFromSameLast; - // bool isTypeZeroContinue = isValeSameLast; - // bool isTypeZeroFinished = isValeSwitchedToSameLast; - // if (isTypeZeroFinished) - // { - // // - // bool hasSelectionType = selectRejectedPVPivots || - // selectEngulfedPVPivots; - - // // - // bool isPVRejected = - // isCBarBullishRejected && - // selectRejectedPVPivots; - - // // - // bool isPVEngulfed = - // isCBarBullishEngulfed && - // selectEngulfedPVPivots; - - // // - // bool isBarPassed = - // !hasSelectionType - // ? true - // : isPVRejected || - // isPVEngulfed; - - // // - // isTypeZeroFinished = - // isBarPassed && - // isTypeZeroFinished; - // if (!isTypeZeroFinished) - // { - // valePivot.Clean(); - // } - // } - - // // - // // Summarizing Conditions ... - - // // - // result = false; - - // // - // bool hasStartCondition = - // // - // isTypeZeroStart - // // - // ; - // bool hasContinuationCondition = - // // - // isTypeZeroContinue - // // - // ; - // bool hasEndCondition = - // // - // isTypeZeroFinished - // // - // ; - - // // - // // ReInstance Pivot ... - // if (hasStartCondition) - // { - // // - // valePivot.Clean(); - - // // - // valePivot.type = XCA_VALE; - // valePivot.symbol = symbol; - // valePivot.period = period; - - // // - // valePivot.to = pBar.time; - // valePivot.from = pBar.time; - // valePivot.value = pVale; - // valePivot.reserve = pValeGolden; - // } - - // // - // // Calculate and Fill Pivot Requirements ... - // if (hasContinuationCondition) - // { - // // - // valePivot.from = pBar.time; - - // // - // valePivot.reserve = - // valePivot.reserve == 0 - // ? pValeGolden - // : MathMin(valePivot.reserve, pValeGolden); - // } - - // // - // // End up Pivot and Store it ... - // if (hasEndCondition) - // { - // // - // result = - // valePivot.IsValid() && - // valePivot.GetAge() >= pivotVerifications; - // if (result) - // { - // // - // XBoxZone iBox; - // result = valePivot.AsBox(iBox); - // if (result) - // { - // // - // newPeakPivotDetected = AddBox( - // iBox, - // valePivots // - // ); - // } - - // // - // iBox.Clean(); - // } - - // // - // valePivot.Clean(); - // } - - // // - // return result; - // } diff --git a/Documents/BKP/Indicators/x-saherelm.x121.xca.v1.mq5 b/Documents/BKP/Indicators/x-saherelm.x121.xca.v1.mq5 deleted file mode 100644 index 4169373c..00000000 --- a/Documents/BKP/Indicators/x-saherelm.x121.xca.v1.mq5 +++ /dev/null @@ -1,2452 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 XCA -// Description: XCA ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 XCA Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121 XCA" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -input group "Market"; - -// -input group "Short"; -input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period - -// -input group "Medium"; -input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period - -// -input group "Long"; -input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period - -// -input group "Hind"; -input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period - -// -input group "Boundary Detection"; -input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method -input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method - -// -input group "Fibo Levels"; -input ENUM_X_FIBO_LEVELS fiboLevel1 = X_FIBO_LEVEL_236; // Fibo Level 1 -input ENUM_X_FIBO_LEVELS fiboLevel2 = X_FIBO_LEVEL_500; // Fibo Level 2 -input ENUM_X_FIBO_LEVELS fiboLevel3 = X_FIBO_LEVEL_764; // Fibo Level 3 - -// -input group "Sar Detection"; -input double sarStep = 0.02; // Step -input double sarMax = 0.2; // Maximum - -// -// KI ... -input group "KI"; -input int kiLength = 26; // KI Length - -// -// VIDYA ... -// Variable Index Dynamic Average ... -input group "VIDYA"; -input int vidyaCMOLength = 20; // CMO (Candle Momentum) Length -input int vidyaEMALength = 14; // EMA Length -input ENUM_APPLIED_PRICE vidyaAppliedTo = PRICE_CLOSE; // Applied To - -// -// Manalyser ... -input group "Manalyser"; -input int manalyserLength = 14; // Length -input ENUM_MA_METHOD manalyserMethod = MODE_SMA; // Method - -// -input group "Swing Detection"; -input int swingLength = 5; // Length - -// -input group "Support and Resistance"; -input int supResSmoothingLength = 7; // Smoothing Length -input ENUM_X_MA_METHOD supResSmoothingMode = X_MA_MODE_SMA; // Smoothing Method - -// -// Presentation ... -input group "Presentation"; - -// -input int startCalculationForLastBars = 1000; // Calculate Last n Bars - -// -input bool showSar = true; // Show Sar -input bool showKI = true; // Show KI -input bool showTKI = true; // Show KI Trend -input bool showMAH = true; // Show MAH -input bool showMAL = true; // Show MAL -input bool showMAC = true; // Show MAC -input bool showVidya = true; // Show Vidya -input bool showTrend = true; // Show Trend -input bool showSwings = true; // Show Swings -input bool showFiboLevel1 = true; // Show Fibo Level 1 -input bool showFiboLevel2 = true; // Show Fibo Level 2 -input bool showFiboLevel3 = true; // Show Fibo Level 3 -input bool showPeaksAndVales = true; // Show Peaks And Vales -input bool showPeakAndValeGolden = true; // Show Peak and Vale Golden -input bool showSupportAndResistance = true; // Show Support and Resistance -input bool showShortCycle = true; // Show Short Cycle -input bool showMediumCycle = true; // Show Medium Cycle -input bool showLongCycle = true; // Show Long Cycle -input bool showHindCycle = true; // Show Hind Cycle - -// -int sarArrowCode = 159; // Parabolic Sar Arrow Code -int peakArrowCode = 159; // Peaks Arrow Code -int valeArrowCode = 159; // Vales Arrow Code -int swingLowArrowCode = 225; // Swing Low Arrow Code -int swingHighArrowCode = 226; // Swing High Arrow Code - -// -// Buffers ... - -// -#define hideColorIDX 0 -#define bullishColorIDX 1 -#define bearishColorIDX 2 -#define neuturalColorIDX 3 - -// -#define bullishState 1 -#define neuturalState 0 -#define bearishState -1 - -// -#define emptyValue 0.0 - -// -#property indicator_chart_window - -// -#property indicator_buffers 37 -#property indicator_plots 27 - -// -// Plot Buffers ... - -// -// SHORT ... - -// -#define sHHBufferIndex 0 -double sHHBuffer[]; - -// -#property indicator_label1 "SH" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrGray -#property indicator_style1 STYLE_DOT -#property indicator_width1 1 - -// -#define sLLBufferIndex 1 -double sLLBuffer[]; - -// -#property indicator_label2 "SL" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrGray -#property indicator_style2 STYLE_DOT -#property indicator_width2 1 - -// -// MEDIUM ... - -// -#define mHHBufferIndex 2 -double mHHBuffer[]; - -// -#property indicator_label3 "MH" -#property indicator_type3 DRAW_LINE -#property indicator_color3 clrIndigo -#property indicator_style3 STYLE_DOT -#property indicator_width3 1 - -// -#define mLLBufferIndex 3 -double mLLBuffer[]; - -// -#property indicator_label4 "ML" -#property indicator_type4 DRAW_LINE -#property indicator_color4 clrIndigo -#property indicator_style4 STYLE_DOT -#property indicator_width4 1 - -// -// LONG ... - -// -#define lHHBufferIndex 4 -double lHHBuffer[]; - -// -#property indicator_label5 "LH" -#property indicator_type5 DRAW_LINE -#property indicator_color5 clrGoldenrod -#property indicator_style5 STYLE_DOT -#property indicator_width5 1 - -// -#define lLLBufferIndex 5 -double lLLBuffer[]; - -// -#property indicator_label6 "LL" -#property indicator_type6 DRAW_LINE -#property indicator_color6 clrGoldenrod -#property indicator_style6 STYLE_DOT -#property indicator_width6 1 - -// -// HIND ... - -// -#define hHHBufferIndex 6 -double hHHBuffer[]; - -// -#property indicator_label7 "HH" -#property indicator_type7 DRAW_LINE -#property indicator_color7 clrBrown -#property indicator_style7 STYLE_DOT -#property indicator_width7 1 - -// -#define hLLBufferIndex 7 -double hLLBuffer[]; - -// -#property indicator_label8 "HL" -#property indicator_type8 DRAW_LINE -#property indicator_color8 clrBrown -#property indicator_style8 STYLE_DOT -#property indicator_width8 1 - -// -// SUPPORT ... - -// -#define supportBufferIndex 8 -double supportBuffer[]; - -// -#property indicator_label9 "SUPPORT" -#property indicator_type9 DRAW_LINE -#property indicator_color9 clrLime -#property indicator_style9 STYLE_SOLID -#property indicator_width9 1 - -// -// RESISTANCE ... - -// -#define resistanceBufferIndex 9 -double resistanceBuffer[]; - -// -#property indicator_label10 "RESISTANCE" -#property indicator_type10 DRAW_LINE -#property indicator_color10 clrRed -#property indicator_style10 STYLE_SOLID -#property indicator_width10 1 - -// -// PEAKS ... - -// -#define peakBufferIndex 10 -double peakBuffer[]; - -// -#property indicator_label11 "PEAK" -#property indicator_type11 DRAW_ARROW -#property indicator_color11 clrMagenta -#property indicator_width11 1 - -// -// PEAKS Golden ... - -// -#define peakGoldenBufferIndex 11 -double peakGoldenBuffer[]; - -// -#property indicator_label12 "PEAK Golden" -#property indicator_type12 DRAW_LINE -#property indicator_color12 clrMagenta -#property indicator_style2 STYLE_DOT -#property indicator_width12 1 - -// -// VALES ... - -// -#define valeBufferIndex 12 -double valeBuffer[]; - -// -#property indicator_label13 "VALE" -#property indicator_type13 DRAW_ARROW -#property indicator_color13 clrAqua -#property indicator_width13 1 - -// -// VALE Golden ... - -// -#define valeGoldenBufferIndex 13 -double valeGoldenBuffer[]; - -// -#property indicator_label14 "VALES Golden" -#property indicator_type14 DRAW_LINE -#property indicator_color14 clrAqua -#property indicator_style4 STYLE_DOT -#property indicator_width14 1 - -// -// FIBO Level 1 - -// -#define fiboLevel1BufferIndex 14 -double fiboLevel1Buffer[]; - -// -#property indicator_label15 "Fibo L1" -#property indicator_type15 DRAW_LINE -#property indicator_color15 clrGold -#property indicator_style15 STYLE_DOT -#property indicator_width15 1 - -// -// FIBO Level 2 - -// -#define fiboLevel2BufferIndex 15 -double fiboLevel2Buffer[]; - -// -#property indicator_label16 "Fibo L2" -#property indicator_type16 DRAW_LINE -#property indicator_color16 clrYellow -#property indicator_style16 STYLE_DASH -#property indicator_width16 1 - -// -// FIBO Level 3 - -// -#define fiboLevel3BufferIndex 16 -double fiboLevel3Buffer[]; - -// -#property indicator_label17 "Fibo L3" -#property indicator_type17 DRAW_LINE -#property indicator_color17 clrGold -#property indicator_style17 STYLE_DOT -#property indicator_width17 1 - -// -// SAR ... - -// -#define sarBufferIndex 17 -double sarBuffer[]; - -// -#property indicator_label18 "SAR" -#property indicator_type18 DRAW_ARROW -#property indicator_color18 clrYellow -#property indicator_width18 1 - -// -// TREND ... - -// -#define trendBufferIndex 18 -#define trendBufferPlotIndex 18 -double trendBuffer[]; - -// -#define trendColorBufferIndex 19 -double trendColorBuffer[]; - -// -#property indicator_label19 "TRND" -#property indicator_type19 DRAW_COLOR_LINE -#property indicator_color19 CLR_NONE, clrAqua, clrMagenta, clrGray -#property indicator_style19 STYLE_DASH -#property indicator_width19 2 - -// -// KI ... - -// -#define kiBufferIndex 20 -#define kiBufferPlotIndex 19 -double kiBuffer[]; - -// -#define kiColorBufferIndex 21 -double kiColorBuffer[]; - -// -#property indicator_label20 "KI" -#property indicator_type20 DRAW_COLOR_LINE -#property indicator_color20 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style20 STYLE_DASHDOTDOT -#property indicator_width20 2 - -// -// SWING Low ... - -// -#define swingLowBufferIndex 22 -#define swingLowBufferPlotIndex 20 -double swingLowBuffer[]; - -// -#property indicator_label21 "SWL" -#property indicator_type21 DRAW_ARROW -#property indicator_color21 clrGreen -#property indicator_width21 1 - -// -// SWING High ... - -// -#define swingHighBufferIndex 23 -#define swingHighBufferPlotIndex 21 -double swingHighBuffer[]; - -// -#property indicator_label22 "SWH" -#property indicator_type22 DRAW_ARROW -#property indicator_color22 clrRed -#property indicator_width22 1 - -// -// TKI ... - -// -#define tkiBufferIndex 24 -#define tkiBufferPlotIndex 22 -double tkiBuffer[]; - -// -#define tkiColorBufferIndex 25 -double tkiColorBuffer[]; - -// -#property indicator_label23 "TKI" -#property indicator_type23 DRAW_COLOR_LINE -#property indicator_color23 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style23 STYLE_DASHDOTDOT -#property indicator_width23 2 - -// -// VIDYA ... - -// -#define vidyaBufferIndex 26 -#define vidyaBufferPlotIndex 23 -double vidyaBuffer[]; - -// -#define vidyaColorBufferIndex 27 -double vidyaColorBuffer[]; - -// -#property indicator_label24 "VIDYA" -#property indicator_type24 DRAW_COLOR_LINE -#property indicator_color24 CLR_NONE, clrAqua, clrMagenta, clrGray -#property indicator_style24 STYLE_SOLID -#property indicator_width24 1 - -// -// MAH ... - -// -#define mahBufferIndex 28 -#define mahBufferPlotIndex 24 -double mahBuffer[]; - -// -#property indicator_label25 "MAH" -#property indicator_type25 DRAW_LINE -#property indicator_color25 clrMagenta -#property indicator_style25 STYLE_SOLID -#property indicator_width25 1 - -// -// MAL ... - -// -#define malBufferIndex 29 -#define malBufferPlotIndex 25 -double malBuffer[]; - -// -#property indicator_label26 "MAL" -#property indicator_type26 DRAW_LINE -#property indicator_color26 clrAqua -#property indicator_style26 STYLE_SOLID -#property indicator_width26 1 - -// -// MAC ... - -// -#define macBufferIndex 30 -#define macBufferPlotIndex 26 -double macBuffer[]; - -// -#property indicator_label27 "MAC" -#property indicator_type27 DRAW_LINE -#property indicator_color27 clrYellow -#property indicator_style27 STYLE_SOLID -#property indicator_width27 1 - -// -// Data Buffers ... - -#define mLastBufferIndex 30 - -// -#define trendStateBufferIndex mLastBufferIndex + 1 -double trendStateBuffer[]; - -// -#define kiStateBufferIndex mLastBufferIndex + 2 -double kiStateBuffer[]; - -// -#define tkiStateBufferIndex mLastBufferIndex + 3 -double tkiStateBuffer[]; - -// -#define vidyaStateBufferIndex mLastBufferIndex + 4 -double vidyaStateBuffer[]; - -// -#define supBufferIndex mLastBufferIndex + 5 -double supBuffer[]; - -// -#define resBufferIndex mLastBufferIndex + 6 -double resBuffer[]; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int firstBarIndex; - -// -int maxLength; - -// -// SAR Handler ... -int sarHandler = INVALID_HANDLE; - -// -// TREND Handler ... -int tkiHandler = INVALID_HANDLE; -int vidyaHandler = INVALID_HANDLE; -int trendHandler = INVALID_HANDLE; - -// -// Manalyser Handlers ... -int mahHandler = INVALID_HANDLE; -int malHandler = INVALID_HANDLE; -int macHandler = INVALID_HANDLE; - -// -// XMarketCycle sc; -int mSCLength = 0; -ENUM_TIMEFRAMES mSCPeriod = NULL; - -// -// XMarketCycle mc; -int mMCLength = 0; -ENUM_TIMEFRAMES mMCPeriod = NULL; - -// -// XMarketCycle lc; -int mLCLength = 0; -ENUM_TIMEFRAMES mLCPeriod = NULL; - -// -// XMarketCycle hc; -int mHCLength = 0; -ENUM_TIMEFRAMES mHCPeriod = NULL; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - if (!InitMarketCycles()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // SAR ... - sarHandler = iSAR( - _Symbol, - _Period, - sarStep, - sarMax // - ); - bool isInited = sarHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // TKI ... - tkiHandler = iMA( - _Symbol, - _Period, - kiLength, - 0, - MODE_SMA, - PRICE_MEDIAN // - ); - isInited = tkiHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // VIDYA ... - vidyaHandler = iVIDyA( - _Symbol, - _Period, - vidyaCMOLength, - vidyaEMALength, - 0, - vidyaAppliedTo // - ); - isInited = vidyaHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // TREND ... - trendHandler = iMA( - _Symbol, - _Period, - mHCLength, - 0, - MODE_SMA, - PRICE_CLOSE // - ); - isInited = trendHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // MANALYSE ... - - // - // MAH ... - mahHandler = iMA( - _Symbol, - _Period, - manalyserLength, - 0, - manalyserMethod, - PRICE_HIGH // - ); - isInited = mahHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // MAL ... - malHandler = iMA( - _Symbol, - _Period, - manalyserLength, - 0, - manalyserMethod, - PRICE_LOW // - ); - isInited = malHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // MAC ... - macHandler = iMA( - _Symbol, - _Period, - manalyserLength, - 0, - manalyserMethod, - PRICE_CLOSE // - ); - isInited = macHandler != 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(); - - // - // 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(sarHandler); - IndicatorRelease(tkiHandler); - IndicatorRelease(vidyaHandler); - IndicatorRelease(trendHandler); -} - -/** - * 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 ... - - // - // SAR ... - int sarCalculatedBars = BarsCalculated(sarHandler); - - // - // TKI ... - int tkiCalculatedBars = BarsCalculated(tkiHandler); - - // - // VIDYA ... - int vidyaCalculatedBars = BarsCalculated(vidyaHandler); - - // - // TREND ... - int trendCalculatedBars = BarsCalculated(trendHandler); - - // - // MANALYSER ... - - // - // MAH ... - int mahCalculatedBars = BarsCalculated(mahHandler); - - // - // MAL ... - int malCalculatedBars = BarsCalculated(malHandler); - - // - // MAC ... - int macCalculatedBars = BarsCalculated(macHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // SAR ... - sarCalculatedBars >= maxLength && - // - // TKI ... - tkiCalculatedBars >= maxLength && - // - // VIDYA ... - vidyaCalculatedBars >= maxLength && - // - // TREND ... - trendCalculatedBars >= maxLength && - // - // MANALYSER ... - // MAH ... - mahCalculatedBars >= maxLength && - // MAL ... - malCalculatedBars >= maxLength && - // MAC ... - macCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - // SAR ... - int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); - - // - // TKI ... - int copiedTKIs = CopyBuffer(tkiHandler, 0, 0, limit, tkiBuffer); - - // - // TKI ... - int copiedVidyas = CopyBuffer(vidyaHandler, 0, 0, limit, vidyaBuffer); - - // - // TREND ... - int copiedTrends = CopyBuffer(trendHandler, MAIN_LINE, 0, limit + 1, trendBuffer); - - // - // MANALYSER ... - - // - // MAH ... - int copiedMahs = CopyBuffer(mahHandler, 0, 0, limit, mahBuffer); - - // - // MAL ... - int copiedMals = CopyBuffer(malHandler, 0, 0, limit, malBuffer); - - // - // MAC ... - int copiedMacs = CopyBuffer(macHandler, 0, 0, limit, macBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // SAR ... - copiedSars >= limit && - // - // TKI ... - copiedTKIs >= limit && - // - // VIDYA ... - copiedVidyas >= limit && - // - // TREND ... - copiedTrends >= limit && - // - // MANALYSER ... - // MAH ... - copiedMahs >= limit && - // MAL ... - copiedMals >= limit && - // MAC ... - copiedMacs >= limit - // - ; - 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 = - // - // SAR ... - sarMax > 0 && - sarStep > 0 && - kiLength > 0 && - swingLength > 0 && - sarMax > sarStep && - vidyaEMALength > 0 && - vidyaCMOLength > 0 && - manalyserLength > 0 && - // - // XCA ... - (IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod)) - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - result = MathMax(kiLength, swingLength); - result = MathMax(result, vidyaCMOLength); - result = MathMax(result, vidyaEMALength); - result = MathMax(result, manalyserLength); - - // - return result; -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // Plot Buffers ... - - // - // SHORT ... - - // - ENUM_DRAW_TYPE sDrawType = showShortCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(sHHBuffer, true); - SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sHHBufferIndex, PLOT_SHOW_DATA, showShortCycle); - PlotIndexSetInteger(sHHBufferIndex, PLOT_DRAW_TYPE, sDrawType); - - // - PlotIndexSetDouble(sHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(sLLBuffer, true); - SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sLLBufferIndex, PLOT_SHOW_DATA, showShortCycle); - PlotIndexSetInteger(sLLBufferIndex, PLOT_DRAW_TYPE, sDrawType); - - // - PlotIndexSetDouble(sLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // MEDIUM ... - - // - ENUM_DRAW_TYPE mDrawType = showMediumCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(mHHBuffer, true); - SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(mHHBufferIndex, PLOT_SHOW_DATA, showMediumCycle); - PlotIndexSetInteger(mHHBufferIndex, PLOT_DRAW_TYPE, mDrawType); - - // - PlotIndexSetDouble(mHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(mLLBuffer, true); - SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(mLLBufferIndex, PLOT_SHOW_DATA, showMediumCycle); - PlotIndexSetInteger(mLLBufferIndex, PLOT_DRAW_TYPE, mDrawType); - - // - PlotIndexSetDouble(mLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LONG ... - - // - ENUM_DRAW_TYPE lDrawType = showLongCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(lHHBuffer, true); - SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(lHHBufferIndex, PLOT_SHOW_DATA, showLongCycle); - PlotIndexSetInteger(lHHBufferIndex, PLOT_DRAW_TYPE, lDrawType); - - // - PlotIndexSetDouble(lHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(lLLBuffer, true); - SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(lLLBufferIndex, PLOT_SHOW_DATA, showLongCycle); - PlotIndexSetInteger(lLLBufferIndex, PLOT_DRAW_TYPE, lDrawType); - - // - PlotIndexSetDouble(lLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // HIND ... - - // - ENUM_DRAW_TYPE hDrawType = showHindCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(hHHBuffer, true); - SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(hHHBufferIndex, PLOT_SHOW_DATA, showHindCycle); - PlotIndexSetInteger(hHHBufferIndex, PLOT_DRAW_TYPE, hDrawType); - - // - PlotIndexSetDouble(hHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(hLLBuffer, true); - SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(hLLBufferIndex, PLOT_SHOW_DATA, showHindCycle); - PlotIndexSetInteger(hLLBufferIndex, PLOT_DRAW_TYPE, hDrawType); - - // - PlotIndexSetDouble(hLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // SUPPORT / RESISTANCE ... - - // - ENUM_DRAW_TYPE supResDrawType = showSupportAndResistance ? DRAW_LINE : DRAW_NONE; - - // - // SUPPORT ... - - // - ArraySetAsSeries(supportBuffer, true); - SetIndexBuffer(supportBufferIndex, supportBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(supportBufferIndex, PLOT_SHOW_DATA, showSupportAndResistance); - PlotIndexSetInteger(supportBufferIndex, PLOT_DRAW_TYPE, supResDrawType); - - // - PlotIndexSetDouble(supportBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // RESISTANCE ... - - // - ArraySetAsSeries(resistanceBuffer, true); - SetIndexBuffer(resistanceBufferIndex, resistanceBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(resistanceBufferIndex, PLOT_SHOW_DATA, showSupportAndResistance); - PlotIndexSetInteger(resistanceBufferIndex, PLOT_DRAW_TYPE, supResDrawType); - - // - PlotIndexSetDouble(resistanceBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // PEAK / VALE ... - - // - ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; - - // - // PEAK ... - - // - ArraySetAsSeries(peakBuffer, true); - SetIndexBuffer(peakBufferIndex, peakBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(peakBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); - PlotIndexSetInteger(peakBufferIndex, PLOT_DRAW_TYPE, pvDrawType); - - // - PlotIndexSetDouble(peakBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(peakBufferIndex, PLOT_ARROW, peakArrowCode); - - // - // VALE ... - - // - ArraySetAsSeries(valeBuffer, true); - SetIndexBuffer(valeBufferIndex, valeBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(valeBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); - PlotIndexSetInteger(valeBufferIndex, PLOT_DRAW_TYPE, pvDrawType); - - // - PlotIndexSetDouble(valeBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(valeBufferIndex, PLOT_ARROW, valeArrowCode); - - // - // PV GOLDEN ... - - // - ENUM_DRAW_TYPE pvGoldenDrawType = showPeakAndValeGolden ? DRAW_LINE : DRAW_NONE; - - // - // PEAK Golden ... - - // - ArraySetAsSeries(peakGoldenBuffer, true); - SetIndexBuffer(peakGoldenBufferIndex, peakGoldenBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(peakGoldenBufferIndex, PLOT_SHOW_DATA, showPeakAndValeGolden); - PlotIndexSetInteger(peakGoldenBufferIndex, PLOT_DRAW_TYPE, pvGoldenDrawType); - - // - PlotIndexSetDouble(peakGoldenBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // VALE Golden ... - - // - ArraySetAsSeries(valeGoldenBuffer, true); - SetIndexBuffer(valeGoldenBufferIndex, valeGoldenBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(valeGoldenBufferIndex, PLOT_SHOW_DATA, showPeakAndValeGolden); - PlotIndexSetInteger(valeGoldenBufferIndex, PLOT_DRAW_TYPE, pvGoldenDrawType); - - // - PlotIndexSetDouble(valeGoldenBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // FIBO L1 ... - - // - ENUM_DRAW_TYPE fiboL1DrawType = showFiboLevel1 ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(fiboLevel1Buffer, true); - SetIndexBuffer(fiboLevel1BufferIndex, fiboLevel1Buffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(fiboLevel1BufferIndex, PLOT_SHOW_DATA, showFiboLevel1); - PlotIndexSetInteger(fiboLevel1BufferIndex, PLOT_DRAW_TYPE, fiboL1DrawType); - - // - PlotIndexSetDouble(fiboLevel1BufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // FIBO L2 ... - - // - ENUM_DRAW_TYPE fiboL2DrawType = showFiboLevel2 ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(fiboLevel2Buffer, true); - SetIndexBuffer(fiboLevel2BufferIndex, fiboLevel2Buffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(fiboLevel2BufferIndex, PLOT_SHOW_DATA, showFiboLevel2); - PlotIndexSetInteger(fiboLevel2BufferIndex, PLOT_DRAW_TYPE, fiboL2DrawType); - - // - PlotIndexSetDouble(fiboLevel2BufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // FIBO L3 ... - - // - ENUM_DRAW_TYPE fiboL3DrawType = showFiboLevel3 ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(fiboLevel3Buffer, true); - SetIndexBuffer(fiboLevel3BufferIndex, fiboLevel3Buffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(fiboLevel3BufferIndex, PLOT_SHOW_DATA, showFiboLevel3); - PlotIndexSetInteger(fiboLevel3BufferIndex, PLOT_DRAW_TYPE, fiboL3DrawType); - - // - PlotIndexSetDouble(fiboLevel3BufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // SAR ... - - // - ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(sarBuffer, true); - SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar); - PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType); - - // - PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); - - // - // TREND ... - - // - ENUM_DRAW_TYPE trendDrawType = showTrend ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(trendBuffer, true); - SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(trendBufferPlotIndex, PLOT_SHOW_DATA, showTrend); - // PlotIndexSetInteger(trendBufferPlotIndex, PLOT_DRAW_TYPE, trendDrawType); - - // - PlotIndexSetDouble(trendBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(trendColorBuffer, true); - SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX); - - // - // KI ... - - // - ENUM_DRAW_TYPE kiDrawType = showKI ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(kiBuffer, true); - SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKI); - // PlotIndexSetInteger(kiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType); - - // - PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(kiColorBuffer, true); - SetIndexBuffer(kiColorBufferIndex, kiColorBuffer, INDICATOR_COLOR_INDEX); - - // - // TKI ... - - // - ENUM_DRAW_TYPE tkiDrawType = showTKI ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(tkiBuffer, true); - SetIndexBuffer(tkiBufferIndex, tkiBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_SHOW_DATA, showKI); - // PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType); - - // - PlotIndexSetDouble(tkiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(tkiColorBuffer, true); - SetIndexBuffer(tkiColorBufferIndex, tkiColorBuffer, INDICATOR_COLOR_INDEX); - - // - // VIDYA ... - - // - ENUM_DRAW_TYPE vidyaDrawType = showVidya ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(vidyaBuffer, true); - SetIndexBuffer(vidyaBufferIndex, vidyaBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(vidyaBufferPlotIndex, PLOT_SHOW_DATA, showKI); - // PlotIndexSetInteger(vidyaBufferPlotIndex, PLOT_DRAW_TYPE, vidyaDrawType); - - // - PlotIndexSetDouble(vidyaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(vidyaColorBuffer, true); - SetIndexBuffer(vidyaColorBufferIndex, vidyaColorBuffer, INDICATOR_COLOR_INDEX); - - // - // SWINGS ... - - // - ENUM_DRAW_TYPE swingDrawType = showSwings ? DRAW_ARROW : DRAW_NONE; - - // - // SWING Low ... - - // - ArraySetAsSeries(swingLowBuffer, true); - SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_SHOW_DATA, showSwings); - PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_DRAW_TYPE, swingDrawType); - - // - PlotIndexSetDouble(swingLowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_ARROW, swingLowArrowCode); - - // - // SWING High ... - - // - ArraySetAsSeries(swingHighBuffer, true); - SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_SHOW_DATA, showSwings); - PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_DRAW_TYPE, swingDrawType); - - // - PlotIndexSetDouble(swingHighBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_ARROW, swingHighArrowCode); - - // - // MANALYSER ... - - // - // MAH ... - - // - ENUM_DRAW_TYPE mahDrawType = showMAH ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(mahBuffer, true); - SetIndexBuffer(mahBufferIndex, mahBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(mahBufferPlotIndex, PLOT_SHOW_DATA, showMAH); - PlotIndexSetInteger(mahBufferPlotIndex, PLOT_DRAW_TYPE, mahDrawType); - - // - PlotIndexSetDouble(mahBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // MAL ... - - // - ENUM_DRAW_TYPE malDrawType = showMAL ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(malBuffer, true); - SetIndexBuffer(malBufferIndex, malBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(malBufferPlotIndex, PLOT_SHOW_DATA, showMAL); - PlotIndexSetInteger(malBufferPlotIndex, PLOT_DRAW_TYPE, malDrawType); - - // - PlotIndexSetDouble(malBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // MAC ... - - // - ENUM_DRAW_TYPE macDrawType = showMAC ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(macBuffer, true); - SetIndexBuffer(macBufferIndex, macBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(macBufferPlotIndex, PLOT_SHOW_DATA, showMAC); - PlotIndexSetInteger(macBufferPlotIndex, PLOT_DRAW_TYPE, mahDrawType); - - // - PlotIndexSetDouble(macBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // Data Buffers ... - - // - ArraySetAsSeries(trendStateBuffer, true); - SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(kiStateBuffer, true); - SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(tkiStateBuffer, true); - SetIndexBuffer(tkiStateBufferIndex, tkiStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(vidyaStateBuffer, true); - SetIndexBuffer(vidyaStateBufferIndex, vidyaStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(supBuffer, true); - SetIndexBuffer(supBufferIndex, supBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(resBuffer, true); - SetIndexBuffer(resBufferIndex, resBuffer, INDICATOR_CALCULATIONS); - - // -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - // - IndicatorSetInteger(INDICATOR_DIGITS, _Digits); - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * 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; - if (barsLimit == 0) - { - // - barsLimit = ratesTotal; - firstBarIndex = barsLimit - 1; - } - else - { - // - firstBarIndex = startCalculationForLastBars; - } - - // - // bool canCalculate = true; - bool canCalculate = - bar_index <= barsLimit; - if (canCalculate) - { - // - // Calculate Cycles ... - CalculateCycles(bar_index); - - // - // Calculate Support nad Resistance ... - CalculateValues( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - else - { - FillBuffersZero(bar_index); - } -} - -// -// Custom ... - -/** - * Initial Market Cycles ... - * - * @return ( bool ) - */ -bool InitMarketCycles() -{ - // - bool result = false; - - // - int cPeriodSeconds = PeriodSeconds(_Period); - - // - // Find Cycle Period ... - if (scMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mSCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_SHORT, - _Period // - ); - } - else - { - mSCPeriod = scPeriod; - } - - // - if (IsValid(mSCPeriod)) - { - mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (mcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mMCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_MEDIUM, - _Period // - ); - } - else - { - mMCPeriod = mcPeriod; - } - - // - if (IsValid(mMCPeriod)) - { - mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (lcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mLCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_LONG, - _Period // - ); - } - else - { - mLCPeriod = lcPeriod; - } - - // - if (IsValid(mLCPeriod)) - { - mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (hcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mHCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_HIND, - _Period // - ); - } - else - { - mHCPeriod = hcPeriod; - } - - // - if (IsValid(mHCPeriod)) - { - mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; - } - - // - result = mSCLength > 0 && - mMCLength > mSCLength && - mLCLength > mMCLength && - mHCLength > mLCLength; - - // - return result; -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - // SHORT ... - sHHBuffer[barIndex] = emptyValue; - sLLBuffer[barIndex] = emptyValue; - - // - // MEDIUM ... - mHHBuffer[barIndex] = emptyValue; - mLLBuffer[barIndex] = emptyValue; - - // - // LONG ... - lHHBuffer[barIndex] = emptyValue; - lLLBuffer[barIndex] = emptyValue; - - // - // HIND ... - hHHBuffer[barIndex] = emptyValue; - hLLBuffer[barIndex] = emptyValue; - - // - // SUPPORT / RESISTANCE ... - supBuffer[barIndex] = emptyValue; - resBuffer[barIndex] = emptyValue; - supportBuffer[barIndex] = emptyValue; - resistanceBuffer[barIndex] = emptyValue; - - // - // PEAKS ... - peakBuffer[barIndex] = emptyValue; - peakGoldenBuffer[barIndex] = emptyValue; - - // - // VALES ... - valeBuffer[barIndex] = emptyValue; - valeGoldenBuffer[barIndex] = emptyValue; - - // - // SAR ... - sarBuffer[barIndex] = emptyValue; - - // - // TREND ... - trendBuffer[barIndex] = emptyValue; - trendColorBuffer[barIndex] = hideColorIDX; - trendStateBuffer[barIndex] = neuturalState; - - // - // KI ... - kiBuffer[barIndex] = emptyValue; - kiColorBuffer[barIndex] = hideColorIDX; - kiStateBuffer[barIndex] = neuturalState; - - // - // TKI ... - tkiBuffer[barIndex] = emptyValue; - tkiColorBuffer[barIndex] = hideColorIDX; - tkiStateBuffer[barIndex] = neuturalState; - - // - // VIDYA ... - vidyaBuffer[barIndex] = emptyValue; - vidyaColorBuffer[barIndex] = hideColorIDX; - vidyaStateBuffer[barIndex] = neuturalState; - - // - // SWINGS ... - swingLowBuffer[barIndex] = emptyValue; - swingHighBuffer[barIndex] = emptyValue; -} - -/** - * Calculate Specified Market Cycle Info ... - * - * @param barIndex: Integer, Bar Index ... - * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... - * @param hhBuffer: Highest High Buffer Reference ... - * @param llBuffer: Lowest Low Buffer Reference ... - */ -void CalculateCycle( - int barIndex, - ENUM_X_MARKET_CYCLES cycle, - double &hhBuffer[], - double &llBuffer[] // -) -{ - // - XOHCL bar; - bool isBarInited = bar.Init( - _Symbol, - _Period, - barIndex - // - ); - if (!isBarInited) - { - return; - } - - // - int mLength = 0; - switch (cycle) - { - // - case X_MARKET_CYCLE_SHORT: - mLength = mSCLength; - break; - - // - case X_MARKET_CYCLE_MEDIUM: - mLength = mMCLength; - break; - - // - case X_MARKET_CYCLE_LONG: - mLength = mLCLength; - break; - - // - case X_MARKET_CYCLE_HIND: - mLength = mHCLength; - break; - } - - // - if (mLength == 0) - { - return; - } - - // - // Find Highest High ... - double hhValue = bar.FindHighest( - mLength, - hhMode - // - ); - hhBuffer[barIndex] = hhValue; - - // - // Find Lowest Low ... - double llValue = bar.FindLowest( - mLength, - llMode - // - ); - llBuffer[barIndex] = llValue; -} - -/** - * Claculate Cycles ... - * - * @param barIndex: Integer, Bar Index ... - */ -void CalculateCycles(int barIndex) -{ - // - // SHORT ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_SHORT, - sHHBuffer, - sLLBuffer // - ); - - // - // MEDIUM ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_MEDIUM, - mHHBuffer, - mLLBuffer // - ); - - // - // LONG ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_LONG, - lHHBuffer, - lLLBuffer // - ); - - // - // HIND ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_HIND, - hHHBuffer, - hLLBuffer // - ); -} - -/** - * Calculate Values ... - * - * @param bar_index: int, Specified Bar Index ... - * @param prevCalculated: int, Provides Previous Calculated Bars ... - * @param ratesTotal: int, Provides All Availabled Bars ... - * @param open: double Collection, Provides Open Prices Time Series ... - * @param high: double Collection, Provides High Prices Time Series ... - * @param close: double Collection, Provides Close Prices Time Series ... - * @param low: double Collection, Provides Low Prices Time Series ... - * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... - */ -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[] // -) -{ - // - // Check Prev Bar ... - // - int lastBarIndex = bar_index + 1; - bool isFirstBar = - startCalculationForLastBars > 0 - ? bar_index == startCalculationForLastBars - : bar_index == firstBarIndex; - - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - bar_index // - ); - - // - double iSHH = sHHBuffer[bar_index]; - double iSLL = sLLBuffer[bar_index]; - - // - double iMHH = mHHBuffer[bar_index]; - double iMLL = mLLBuffer[bar_index]; - - // - double iLHH = lHHBuffer[bar_index]; - double iLLL = lLLBuffer[bar_index]; - - // - double iHHH = hHHBuffer[bar_index]; - double iHLL = hLLBuffer[bar_index]; - - // - // Calculate BOS ... - - // - // Calculate CHOCH ... - - // - // Calculate Support ... - double lastSupport = - isFirstBar - ? emptyValue - : supBuffer[lastBarIndex]; - bool isSupport = iSLL == iMLL; - double iSupport = - isSupport - ? iSLL - : lastSupport; - supBuffer[bar_index] = iSupport; - - // - // Calculate Vale ... - double lastVale = - isFirstBar - ? emptyValue - : valeBuffer[lastBarIndex]; - bool isVale = - isSupport && - iMLL == iLLL && - iLLL == iHLL; - double iVale = - isVale - ? iMLL - : lastVale; - valeBuffer[bar_index] = iVale; - - // - // Calculate Resistance ... - double lastResistance = - isFirstBar - ? emptyValue - : resBuffer[lastBarIndex]; - bool isResistance = iSHH == iMHH; - double iResistance = - isResistance - ? iSHH - : lastResistance; - resBuffer[bar_index] = iResistance; - - // - // Calculate Peak ... - double lastPeak = - isFirstBar - ? emptyValue - : peakBuffer[lastBarIndex]; - bool isPeak = - isResistance && - iMHH == iLHH && - iLHH == iHHH; - double iPeak = - isPeak - ? iMHH - : lastPeak; - peakBuffer[bar_index] = iPeak; - - // - bool canSmooth = - supResSmoothingLength > 0 && - supResSmoothingMode != X_MA_MODE_NONE; - if (!canSmooth) - { - // - supportBuffer[bar_index] = iSupport; - resistanceBuffer[bar_index] = iResistance; - } - else - { - // - // Support ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - supResSmoothingLength, - supBuffer, - supportBuffer, - supResSmoothingMode // - ); - - // - // Resistance ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - supResSmoothingLength, - resBuffer, - resistanceBuffer, - supResSmoothingMode // - ); - } - - // - // Calculate Fibo Levels ... - - // - double iFiboUpper = peakBuffer[bar_index]; - double iFiboLower = valeBuffer[bar_index]; - - // - double iFiboLevel1 = GetFibonacciLevel( - iFiboUpper, - iFiboLower, - fiboLevel1, - X_DIRECTION_BEARISH // - ); - fiboLevel1Buffer[bar_index] = iFiboLevel1; - - // - double iFiboLevel2 = GetFibonacciLevel( - iFiboUpper, - iFiboLower, - fiboLevel2, - X_DIRECTION_BEARISH // - ); - fiboLevel2Buffer[bar_index] = iFiboLevel2; - - // - double iFiboLevel3 = GetFibonacciLevel( - iFiboUpper, - iFiboLower, - fiboLevel3, - X_DIRECTION_BEARISH // - ); - fiboLevel3Buffer[bar_index] = iFiboLevel3; - - // - // Calculate Trend Color Buffer ... - double iClose = close[bar_index]; - double iTrend = trendBuffer[bar_index]; - - // - double iTrendState = neuturalState; - double iTrendColor = neuturalColorIDX; - if (iClose > iTrend) - { - // - iTrendState = bullishState; - iTrendColor = !showTrend - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iTrend) - { - // - iTrendState = bearishState; - iTrendColor = !showTrend - ? hideColorIDX - : bearishColorIDX; - } - trendStateBuffer[bar_index] = iTrendState; - trendColorBuffer[bar_index] = iTrendColor; - - // - // Calculate KI / Color ... - double lastKI = - isFirstBar - ? emptyValue - : kiBuffer[lastBarIndex]; - double iKI = lastKI; - if (isInited) - { - // - double iLLKI = iBar.FindLowest(kiLength, MODE_LOW); - double iHHKI = iBar.FindHighest(kiLength, MODE_HIGH); - - // - iKI = (iHHKI + iLLKI) / 2; - if (iLLKI == 0 || iHHKI == 0) - { - iKI = lastKI; - } - } - else - { - iKI = lastKI; - } - kiBuffer[bar_index] = iKI; - - // - double iKIState = neuturalState; - double iKIColor = neuturalColorIDX; - if (iClose > iKI) - { - // - iKIState = bullishState; - iKIColor = - !showKI - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iKI) - { - // - iKIState = bearishState; - iKIColor = - !showKI - ? hideColorIDX - : bearishColorIDX; - } - kiStateBuffer[bar_index] = iKIState; - kiColorBuffer[bar_index] = iKIColor; - - // - // Calculate PV Gold ... - double lastPeakGold = - isFirstBar - ? emptyValue - : peakGoldenBuffer[lastBarIndex]; - double lastValeGold = - isFirstBar - ? emptyValue - : valeGoldenBuffer[lastBarIndex]; - double iPeakGold = lastPeakGold; - double iValeGold = lastValeGold; - if (isInited) - { - // - iPeakGold = iBar.FindHighest(mHCLength, MODE_CLOSE); - if (iPeakGold == 0) - { - iPeakGold = lastPeakGold; - } - - // - iValeGold = iBar.FindLowest(mHCLength, MODE_CLOSE); - if (iValeGold == 0) - { - iValeGold = lastValeGold; - } - } - else - { - // - iPeakGold = lastPeakGold; - iValeGold = lastValeGold; - } - peakGoldenBuffer[bar_index] = iPeakGold; - valeGoldenBuffer[bar_index] = iValeGold; - - // - // Calculate Swings ... - - // - double lastSwingLow = - isFirstBar - ? emptyValue - : swingLowBuffer[lastBarIndex]; - bool isSwingLow = IsSwingLow( - high, - low, - bar_index, - swingLength // - ); - double iSwingLow = - isSwingLow - ? low[bar_index] - : lastSwingLow; - swingLowBuffer[bar_index] = iSwingLow; - - // - double lastSwingHigh = - isFirstBar - ? emptyValue - : swingHighBuffer[lastBarIndex]; - bool isSwingHigh = IsSwingHigh( - high, - low, - bar_index, - swingLength // - ); - double iSwingHigh = - isSwingHigh - ? high[bar_index] - : lastSwingHigh; - swingHighBuffer[bar_index] = iSwingHigh; - - // - // TKI State and Color ... - - // - double iTKI = tkiBuffer[bar_index]; - - // - double iTKIState = neuturalState; - double iTKIColor = neuturalColorIDX; - if (iClose > iTKI) - { - // - iTKIState = bullishState; - iTKIColor = - !showTKI - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iTKI) - { - // - iTKIState = bearishState; - iTKIColor = - !showTKI - ? hideColorIDX - : bearishColorIDX; - } - tkiStateBuffer[bar_index] = iTKIState; - tkiColorBuffer[bar_index] = iTKIColor; - - // - // VIDYA Color ... - - // - double iVIDYA = vidyaBuffer[bar_index]; - - // - double iVIDYAState = neuturalState; - double iVIDYAColor = neuturalColorIDX; - if (iClose > iVIDYA) - { - // - iVIDYAState = bullishState; - iVIDYAColor = - !showVidya - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iVIDYA) - { - // - iVIDYAState = bearishState; - iVIDYAColor = - !showVidya - ? hideColorIDX - : bearishColorIDX; - } - vidyaStateBuffer[bar_index] = iVIDYAState; - vidyaColorBuffer[bar_index] = iVIDYAColor; - - // - // Cleanup Resources ... - - // - iBar.Clean(); -} - -// -bool IsSwingLow( - const double &high[], - const double &low[], - int index, - int length // -) -{ - // - bool result = false; - - // - result = index + 1 + length <= firstBarIndex; - if (!result) - { - return result; - } - - // - for (int i = index + 1; i <= index + length; i++) - { - // - result = low[index] < low[i]; - if (!result) - { - break; - } - } - - // - return result; -} - -// -bool IsSwingHigh( - const double &high[], - const double &low[], - int index, - int length // -) -{ - // - bool result = false; - - // - result = index + 1 + length <= firstBarIndex; - if (!result) - { - return result; - } - - // - for (int i = index + 1; i <= index + length; i++) - { - // - result = high[index] > high[i]; - if (!result) - { - break; - } - } - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.x121.xca.v2.mq5 b/Documents/BKP/Indicators/x-saherelm.x121.xca.v2.mq5 deleted file mode 100644 index bfa86fcf..00000000 --- a/Documents/BKP/Indicators/x-saherelm.x121.xca.v2.mq5 +++ /dev/null @@ -1,2487 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 XCA -// Description: XCA ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 XCA Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121 XCA" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -input group "Market"; - -// -input group "Short"; -input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period - -// -input group "Medium"; -input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period - -// -input group "Long"; -input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period - -// -input group "Hind"; -input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period -input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period - -// -input group "Boundary Detection"; -input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method -input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method - -// -input group "Fibo Levels"; -input ENUM_X_FIBO_LEVELS fiboLevel1 = X_FIBO_LEVEL_236; // Fibo Level 1 -input ENUM_X_FIBO_LEVELS fiboLevel2 = X_FIBO_LEVEL_500; // Fibo Level 2 -input ENUM_X_FIBO_LEVELS fiboLevel3 = X_FIBO_LEVEL_764; // Fibo Level 3 - -// -input group "Sar Detection"; -input double sarStep = 0.02; // Step -input double sarMax = 0.2; // Maximum - -// -// KI ... -input group "KI"; -input int kiLength = 26; // KI Length - -// -// VIDYA ... -// Variable Index Dynamic Average ... -input group "VIDYA"; -input int vidyaCMOLength = 20; // CMO (Candle Momentum) Length -input int vidyaEMALength = 14; // EMA Length -input ENUM_APPLIED_PRICE vidyaAppliedTo = PRICE_CLOSE; // Applied To - -// -// Manalyser ... -input group "Manalyser"; -input int manalyserLength = 14; // Length -input ENUM_MA_METHOD manalyserMethod = MODE_SMA; // Method - -// -input group "Swing Detection"; -input int swingLength = 5; // Length - -// -input group "Support and Resistance"; -input int supResSmoothingLength = 7; // Smoothing Length -input ENUM_X_MA_METHOD supResSmoothingMode = X_MA_MODE_SMA; // Smoothing Method - -// -// Presentation ... -input group "Presentation"; - -// -input int startCalculationForLastBars = 1000; // Calculate Last n Bars - -// -input bool showSar = true; // Show Sar -input bool showKI = true; // Show KI -input bool showTKI = true; // Show KI Trend -input bool showMAH = true; // Show MAH -input bool showMAL = true; // Show MAL -input bool showMAC = true; // Show MAC -input bool showVidya = true; // Show Vidya -input bool showTrend = true; // Show Trend -input bool showSwings = true; // Show Swings -input bool showFiboLevel1 = true; // Show Fibo Level 1 -input bool showFiboLevel2 = true; // Show Fibo Level 2 -input bool showFiboLevel3 = true; // Show Fibo Level 3 -input bool showPeaksAndVales = true; // Show Peaks And Vales -input bool showPeakAndValeGolden = true; // Show Peak and Vale Golden -input bool showSupportAndResistance = true; // Show Support and Resistance -input bool showShortCycle = true; // Show Short Cycle -input bool showMediumCycle = true; // Show Medium Cycle -input bool showLongCycle = true; // Show Long Cycle -input bool showHindCycle = true; // Show Hind Cycle - -// -int sarArrowCode = 159; // Parabolic Sar Arrow Code -int peakArrowCode = 159; // Peaks Arrow Code -int valeArrowCode = 159; // Vales Arrow Code -int swingLowArrowCode = 225; // Swing Low Arrow Code -int swingHighArrowCode = 226; // Swing High Arrow Code - -// -// Buffers ... - -// -#define hideColorIDX 0 -#define bullishColorIDX 1 -#define bearishColorIDX 2 -#define neuturalColorIDX 3 - -// -#define bullishState 1 -#define neuturalState 0 -#define bearishState -1 - -// -#define emptyValue 0.0 - -// -#property indicator_chart_window - -// -#property indicator_buffers 37 -#property indicator_plots 27 - -// -// Plot Buffers ... - -// -// SHORT ... - -// -#define sHHBufferIndex 0 -double sHHBuffer[]; - -// -#property indicator_label1 "SH" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrGray -#property indicator_style1 STYLE_DOT -#property indicator_width1 1 - -// -#define sLLBufferIndex 1 -double sLLBuffer[]; - -// -#property indicator_label2 "SL" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrGray -#property indicator_style2 STYLE_DOT -#property indicator_width2 1 - -// -// MEDIUM ... - -// -#define mHHBufferIndex 2 -double mHHBuffer[]; - -// -#property indicator_label3 "MH" -#property indicator_type3 DRAW_LINE -#property indicator_color3 clrIndigo -#property indicator_style3 STYLE_DOT -#property indicator_width3 1 - -// -#define mLLBufferIndex 3 -double mLLBuffer[]; - -// -#property indicator_label4 "ML" -#property indicator_type4 DRAW_LINE -#property indicator_color4 clrIndigo -#property indicator_style4 STYLE_DOT -#property indicator_width4 1 - -// -// LONG ... - -// -#define lHHBufferIndex 4 -double lHHBuffer[]; - -// -#property indicator_label5 "LH" -#property indicator_type5 DRAW_LINE -#property indicator_color5 clrGoldenrod -#property indicator_style5 STYLE_DOT -#property indicator_width5 1 - -// -#define lLLBufferIndex 5 -double lLLBuffer[]; - -// -#property indicator_label6 "LL" -#property indicator_type6 DRAW_LINE -#property indicator_color6 clrGoldenrod -#property indicator_style6 STYLE_DOT -#property indicator_width6 1 - -// -// HIND ... - -// -#define hHHBufferIndex 6 -double hHHBuffer[]; - -// -#property indicator_label7 "HH" -#property indicator_type7 DRAW_LINE -#property indicator_color7 clrBrown -#property indicator_style7 STYLE_DOT -#property indicator_width7 1 - -// -#define hLLBufferIndex 7 -double hLLBuffer[]; - -// -#property indicator_label8 "HL" -#property indicator_type8 DRAW_LINE -#property indicator_color8 clrBrown -#property indicator_style8 STYLE_DOT -#property indicator_width8 1 - -// -// SUPPORT ... - -// -#define supportBufferIndex 8 -double supportBuffer[]; - -// -#property indicator_label9 "SUPPORT" -#property indicator_type9 DRAW_LINE -#property indicator_color9 clrLime -#property indicator_style9 STYLE_SOLID -#property indicator_width9 1 - -// -// RESISTANCE ... - -// -#define resistanceBufferIndex 9 -double resistanceBuffer[]; - -// -#property indicator_label10 "RESISTANCE" -#property indicator_type10 DRAW_LINE -#property indicator_color10 clrRed -#property indicator_style10 STYLE_SOLID -#property indicator_width10 1 - -// -// PEAKS ... - -// -#define peakBufferIndex 10 -double peakBuffer[]; - -// -#property indicator_label11 "PEAK" -#property indicator_type11 DRAW_ARROW -#property indicator_color11 clrMagenta -#property indicator_width11 1 - -// -// PEAKS Golden ... - -// -#define peakGoldenBufferIndex 11 -double peakGoldenBuffer[]; - -// -#property indicator_label12 "PEAK Golden" -#property indicator_type12 DRAW_LINE -#property indicator_color12 clrMagenta -#property indicator_style2 STYLE_DOT -#property indicator_width12 1 - -// -// VALES ... - -// -#define valeBufferIndex 12 -double valeBuffer[]; - -// -#property indicator_label13 "VALE" -#property indicator_type13 DRAW_ARROW -#property indicator_color13 clrAqua -#property indicator_width13 1 - -// -// VALE Golden ... - -// -#define valeGoldenBufferIndex 13 -double valeGoldenBuffer[]; - -// -#property indicator_label14 "VALES Golden" -#property indicator_type14 DRAW_LINE -#property indicator_color14 clrAqua -#property indicator_style4 STYLE_DOT -#property indicator_width14 1 - -// -// FIBO Level 1 - -// -#define fiboLevel1BufferIndex 14 -double fiboLevel1Buffer[]; - -// -#property indicator_label15 "Fibo L1" -#property indicator_type15 DRAW_LINE -#property indicator_color15 clrGold -#property indicator_style15 STYLE_DOT -#property indicator_width15 1 - -// -// FIBO Level 2 - -// -#define fiboLevel2BufferIndex 15 -double fiboLevel2Buffer[]; - -// -#property indicator_label16 "Fibo L2" -#property indicator_type16 DRAW_LINE -#property indicator_color16 clrYellow -#property indicator_style16 STYLE_DASH -#property indicator_width16 1 - -// -// FIBO Level 3 - -// -#define fiboLevel3BufferIndex 16 -double fiboLevel3Buffer[]; - -// -#property indicator_label17 "Fibo L3" -#property indicator_type17 DRAW_LINE -#property indicator_color17 clrGold -#property indicator_style17 STYLE_DOT -#property indicator_width17 1 - -// -// SAR ... - -// -#define sarBufferIndex 17 -double sarBuffer[]; - -// -#property indicator_label18 "SAR" -#property indicator_type18 DRAW_ARROW -#property indicator_color18 clrYellow -#property indicator_width18 1 - -// -// TREND ... - -// -#define trendBufferIndex 18 -#define trendBufferPlotIndex 18 -double trendBuffer[]; - -// -#define trendColorBufferIndex 19 -double trendColorBuffer[]; - -// -#property indicator_label19 "TRND" -#property indicator_type19 DRAW_COLOR_LINE -#property indicator_color19 CLR_NONE, clrAqua, clrMagenta, clrGray -#property indicator_style19 STYLE_DASH -#property indicator_width19 2 - -// -// KI ... - -// -#define kiBufferIndex 20 -#define kiBufferPlotIndex 19 -double kiBuffer[]; - -// -#define kiColorBufferIndex 21 -double kiColorBuffer[]; - -// -#property indicator_label20 "KI" -#property indicator_type20 DRAW_COLOR_LINE -#property indicator_color20 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style20 STYLE_DASHDOTDOT -#property indicator_width20 2 - -// -// SWING Low ... - -// -#define swingLowBufferIndex 22 -#define swingLowBufferPlotIndex 20 -double swingLowBuffer[]; - -// -#property indicator_label21 "SWL" -#property indicator_type21 DRAW_ARROW -#property indicator_color21 clrGreen -#property indicator_width21 1 - -// -// SWING High ... - -// -#define swingHighBufferIndex 23 -#define swingHighBufferPlotIndex 21 -double swingHighBuffer[]; - -// -#property indicator_label22 "SWH" -#property indicator_type22 DRAW_ARROW -#property indicator_color22 clrRed -#property indicator_width22 1 - -// -// TKI ... - -// -#define tkiBufferIndex 24 -#define tkiBufferPlotIndex 22 -double tkiBuffer[]; - -// -#define tkiColorBufferIndex 25 -double tkiColorBuffer[]; - -// -#property indicator_label23 "TKI" -#property indicator_type23 DRAW_COLOR_LINE -#property indicator_color23 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style23 STYLE_DASHDOTDOT -#property indicator_width23 2 - -// -// VIDYA ... - -// -#define vidyaBufferIndex 26 -#define vidyaBufferPlotIndex 23 -double vidyaBuffer[]; - -// -#define vidyaColorBufferIndex 27 -double vidyaColorBuffer[]; - -// -#property indicator_label24 "VIDYA" -#property indicator_type24 DRAW_COLOR_LINE -#property indicator_color24 CLR_NONE, clrAqua, clrMagenta, clrGray -#property indicator_style24 STYLE_SOLID -#property indicator_width24 1 - -// -// MAH ... - -// -#define mahBufferIndex 28 -#define mahBufferPlotIndex 24 -double mahBuffer[]; - -// -#property indicator_label25 "MAH" -#property indicator_type25 DRAW_LINE -#property indicator_color25 clrMagenta -#property indicator_style25 STYLE_SOLID -#property indicator_width25 1 - -// -// MAL ... - -// -#define malBufferIndex 29 -#define malBufferPlotIndex 25 -double malBuffer[]; - -// -#property indicator_label26 "MAL" -#property indicator_type26 DRAW_LINE -#property indicator_color26 clrAqua -#property indicator_style26 STYLE_SOLID -#property indicator_width26 1 - -// -// MAC ... - -// -#define macBufferIndex 30 -#define macBufferPlotIndex 26 -double macBuffer[]; - -// -#property indicator_label27 "MAC" -#property indicator_type27 DRAW_LINE -#property indicator_color27 clrYellow -#property indicator_style27 STYLE_SOLID -#property indicator_width27 1 - -// -// Data Buffers ... - -#define mLastBufferIndex 30 - -// -#define trendStateBufferIndex mLastBufferIndex + 1 -double trendStateBuffer[]; - -// -#define kiStateBufferIndex mLastBufferIndex + 2 -double kiStateBuffer[]; - -// -#define tkiStateBufferIndex mLastBufferIndex + 3 -double tkiStateBuffer[]; - -// -#define vidyaStateBufferIndex mLastBufferIndex + 4 -double vidyaStateBuffer[]; - -// -#define supBufferIndex mLastBufferIndex + 5 -double supBuffer[]; - -// -#define resBufferIndex mLastBufferIndex + 6 -double resBuffer[]; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int firstBarIndex; - -// -int maxLength; - -// -// SAR Handler ... -int sarHandler = INVALID_HANDLE; - -// -// TREND Handler ... -int tkiHandler = INVALID_HANDLE; -int vidyaHandler = INVALID_HANDLE; -int trendHandler = INVALID_HANDLE; - -// -// Manalyser Handlers ... -int mahHandler = INVALID_HANDLE; -int malHandler = INVALID_HANDLE; -int macHandler = INVALID_HANDLE; - -// -// XMarketCycle sc; -int mSCLength = 0; -ENUM_TIMEFRAMES mSCPeriod = NULL; - -// -// XMarketCycle mc; -int mMCLength = 0; -ENUM_TIMEFRAMES mMCPeriod = NULL; - -// -// XMarketCycle lc; -int mLCLength = 0; -ENUM_TIMEFRAMES mLCPeriod = NULL; - -// -// XMarketCycle hc; -int mHCLength = 0; -ENUM_TIMEFRAMES mHCPeriod = NULL; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - if (!InitMarketCycles()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // SAR ... - sarHandler = iSAR( - _Symbol, - _Period, - sarStep, - sarMax // - ); - bool isInited = sarHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // TKI ... - tkiHandler = iMA( - _Symbol, - _Period, - kiLength, - 0, - MODE_SMA, - PRICE_MEDIAN // - ); - isInited = tkiHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // VIDYA ... - vidyaHandler = iVIDyA( - _Symbol, - _Period, - vidyaCMOLength, - vidyaEMALength, - 0, - vidyaAppliedTo // - ); - isInited = vidyaHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // TREND ... - trendHandler = iMA( - _Symbol, - _Period, - mHCLength, - 0, - MODE_SMA, - PRICE_CLOSE // - ); - isInited = trendHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // MANALYSE ... - - // - // MAH ... - mahHandler = iMA( - _Symbol, - _Period, - manalyserLength, - 0, - manalyserMethod, - PRICE_HIGH // - ); - isInited = mahHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // MAL ... - malHandler = iMA( - _Symbol, - _Period, - manalyserLength, - 0, - manalyserMethod, - PRICE_LOW // - ); - isInited = malHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // MAC ... - macHandler = iMA( - _Symbol, - _Period, - manalyserLength, - 0, - manalyserMethod, - PRICE_CLOSE // - ); - isInited = macHandler != 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(); - - // - // 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(sarHandler); - IndicatorRelease(tkiHandler); - IndicatorRelease(vidyaHandler); - IndicatorRelease(trendHandler); -} - -/** - * 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 ... - - // - // SAR ... - int sarCalculatedBars = BarsCalculated(sarHandler); - - // - // TKI ... - int tkiCalculatedBars = BarsCalculated(tkiHandler); - - // - // VIDYA ... - int vidyaCalculatedBars = BarsCalculated(vidyaHandler); - - // - // TREND ... - int trendCalculatedBars = BarsCalculated(trendHandler); - - // - // MANALYSER ... - - // - // MAH ... - int mahCalculatedBars = BarsCalculated(mahHandler); - - // - // MAL ... - int malCalculatedBars = BarsCalculated(malHandler); - - // - // MAC ... - int macCalculatedBars = BarsCalculated(macHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // SAR ... - sarCalculatedBars >= maxLength && - // - // TKI ... - tkiCalculatedBars >= maxLength && - // - // VIDYA ... - vidyaCalculatedBars >= maxLength && - // - // TREND ... - trendCalculatedBars >= maxLength && - // - // MANALYSER ... - // MAH ... - mahCalculatedBars >= maxLength && - // MAL ... - malCalculatedBars >= maxLength && - // MAC ... - macCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - // SAR ... - int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); - - // - // TKI ... - int copiedTKIs = CopyBuffer(tkiHandler, 0, 0, limit, tkiBuffer); - - // - // TKI ... - int copiedVidyas = CopyBuffer(vidyaHandler, 0, 0, limit, vidyaBuffer); - - // - // TREND ... - int copiedTrends = CopyBuffer(trendHandler, MAIN_LINE, 0, limit + 1, trendBuffer); - - // - // MANALYSER ... - - // - // MAH ... - int copiedMahs = CopyBuffer(mahHandler, 0, 0, limit, mahBuffer); - - // - // MAL ... - int copiedMals = CopyBuffer(malHandler, 0, 0, limit, malBuffer); - - // - // MAC ... - int copiedMacs = CopyBuffer(macHandler, 0, 0, limit, macBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // SAR ... - copiedSars >= limit && - // - // TKI ... - copiedTKIs >= limit && - // - // VIDYA ... - copiedVidyas >= limit && - // - // TREND ... - copiedTrends >= limit && - // - // MANALYSER ... - // MAH ... - copiedMahs >= limit && - // MAL ... - copiedMals >= limit && - // MAC ... - copiedMacs >= limit - // - ; - 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 = - // - // SAR ... - sarMax > 0 && - sarStep > 0 && - kiLength > 0 && - swingLength > 0 && - sarMax > sarStep && - vidyaEMALength > 0 && - vidyaCMOLength > 0 && - manalyserLength > 0 && - // - // XCA ... - (IsValid(scMethod, scPeriod) && - IsValid(mcMethod, mcPeriod) && - IsValid(lcMethod, lcPeriod) && - IsValid(hcMethod, hcPeriod)) - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - result = MathMax(kiLength, swingLength); - result = MathMax(result, vidyaCMOLength); - result = MathMax(result, vidyaEMALength); - result = MathMax(result, manalyserLength); - - // - return result; -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // Plot Buffers ... - - // - // SHORT ... - - // - ENUM_DRAW_TYPE sDrawType = showShortCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(sHHBuffer, true); - SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sHHBufferIndex, PLOT_SHOW_DATA, showShortCycle); - PlotIndexSetInteger(sHHBufferIndex, PLOT_DRAW_TYPE, sDrawType); - - // - PlotIndexSetDouble(sHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(sLLBuffer, true); - SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sLLBufferIndex, PLOT_SHOW_DATA, showShortCycle); - PlotIndexSetInteger(sLLBufferIndex, PLOT_DRAW_TYPE, sDrawType); - - // - PlotIndexSetDouble(sLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // MEDIUM ... - - // - ENUM_DRAW_TYPE mDrawType = showMediumCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(mHHBuffer, true); - SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(mHHBufferIndex, PLOT_SHOW_DATA, showMediumCycle); - PlotIndexSetInteger(mHHBufferIndex, PLOT_DRAW_TYPE, mDrawType); - - // - PlotIndexSetDouble(mHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(mLLBuffer, true); - SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(mLLBufferIndex, PLOT_SHOW_DATA, showMediumCycle); - PlotIndexSetInteger(mLLBufferIndex, PLOT_DRAW_TYPE, mDrawType); - - // - PlotIndexSetDouble(mLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LONG ... - - // - ENUM_DRAW_TYPE lDrawType = showLongCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(lHHBuffer, true); - SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(lHHBufferIndex, PLOT_SHOW_DATA, showLongCycle); - PlotIndexSetInteger(lHHBufferIndex, PLOT_DRAW_TYPE, lDrawType); - - // - PlotIndexSetDouble(lHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(lLLBuffer, true); - SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(lLLBufferIndex, PLOT_SHOW_DATA, showLongCycle); - PlotIndexSetInteger(lLLBufferIndex, PLOT_DRAW_TYPE, lDrawType); - - // - PlotIndexSetDouble(lLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // HIND ... - - // - ENUM_DRAW_TYPE hDrawType = showHindCycle ? DRAW_LINE : DRAW_NONE; - - // - // HH ... - - // - ArraySetAsSeries(hHHBuffer, true); - SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(hHHBufferIndex, PLOT_SHOW_DATA, showHindCycle); - PlotIndexSetInteger(hHHBufferIndex, PLOT_DRAW_TYPE, hDrawType); - - // - PlotIndexSetDouble(hHHBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // LL ... - - // - ArraySetAsSeries(hLLBuffer, true); - SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(hLLBufferIndex, PLOT_SHOW_DATA, showHindCycle); - PlotIndexSetInteger(hLLBufferIndex, PLOT_DRAW_TYPE, hDrawType); - - // - PlotIndexSetDouble(hLLBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // SUPPORT / RESISTANCE ... - - // - ENUM_DRAW_TYPE supResDrawType = showSupportAndResistance ? DRAW_LINE : DRAW_NONE; - - // - // SUPPORT ... - - // - ArraySetAsSeries(supportBuffer, true); - SetIndexBuffer(supportBufferIndex, supportBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(supportBufferIndex, PLOT_SHOW_DATA, showSupportAndResistance); - PlotIndexSetInteger(supportBufferIndex, PLOT_DRAW_TYPE, supResDrawType); - - // - PlotIndexSetDouble(supportBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // RESISTANCE ... - - // - ArraySetAsSeries(resistanceBuffer, true); - SetIndexBuffer(resistanceBufferIndex, resistanceBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(resistanceBufferIndex, PLOT_SHOW_DATA, showSupportAndResistance); - PlotIndexSetInteger(resistanceBufferIndex, PLOT_DRAW_TYPE, supResDrawType); - - // - PlotIndexSetDouble(resistanceBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // PEAK / VALE ... - - // - ENUM_DRAW_TYPE pvDrawType = showPeaksAndVales ? DRAW_ARROW : DRAW_NONE; - - // - // PEAK ... - - // - ArraySetAsSeries(peakBuffer, true); - SetIndexBuffer(peakBufferIndex, peakBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(peakBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); - PlotIndexSetInteger(peakBufferIndex, PLOT_DRAW_TYPE, pvDrawType); - - // - PlotIndexSetDouble(peakBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(peakBufferIndex, PLOT_ARROW, peakArrowCode); - - // - // VALE ... - - // - ArraySetAsSeries(valeBuffer, true); - SetIndexBuffer(valeBufferIndex, valeBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(valeBufferIndex, PLOT_SHOW_DATA, showPeaksAndVales); - PlotIndexSetInteger(valeBufferIndex, PLOT_DRAW_TYPE, pvDrawType); - - // - PlotIndexSetDouble(valeBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(valeBufferIndex, PLOT_ARROW, valeArrowCode); - - // - // PV GOLDEN ... - - // - ENUM_DRAW_TYPE pvGoldenDrawType = showPeakAndValeGolden ? DRAW_LINE : DRAW_NONE; - - // - // PEAK Golden ... - - // - ArraySetAsSeries(peakGoldenBuffer, true); - SetIndexBuffer(peakGoldenBufferIndex, peakGoldenBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(peakGoldenBufferIndex, PLOT_SHOW_DATA, showPeakAndValeGolden); - PlotIndexSetInteger(peakGoldenBufferIndex, PLOT_DRAW_TYPE, pvGoldenDrawType); - - // - PlotIndexSetDouble(peakGoldenBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // VALE Golden ... - - // - ArraySetAsSeries(valeGoldenBuffer, true); - SetIndexBuffer(valeGoldenBufferIndex, valeGoldenBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(valeGoldenBufferIndex, PLOT_SHOW_DATA, showPeakAndValeGolden); - PlotIndexSetInteger(valeGoldenBufferIndex, PLOT_DRAW_TYPE, pvGoldenDrawType); - - // - PlotIndexSetDouble(valeGoldenBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // FIBO L1 ... - - // - ENUM_DRAW_TYPE fiboL1DrawType = showFiboLevel1 ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(fiboLevel1Buffer, true); - SetIndexBuffer(fiboLevel1BufferIndex, fiboLevel1Buffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(fiboLevel1BufferIndex, PLOT_SHOW_DATA, showFiboLevel1); - PlotIndexSetInteger(fiboLevel1BufferIndex, PLOT_DRAW_TYPE, fiboL1DrawType); - - // - PlotIndexSetDouble(fiboLevel1BufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // FIBO L2 ... - - // - ENUM_DRAW_TYPE fiboL2DrawType = showFiboLevel2 ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(fiboLevel2Buffer, true); - SetIndexBuffer(fiboLevel2BufferIndex, fiboLevel2Buffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(fiboLevel2BufferIndex, PLOT_SHOW_DATA, showFiboLevel2); - PlotIndexSetInteger(fiboLevel2BufferIndex, PLOT_DRAW_TYPE, fiboL2DrawType); - - // - PlotIndexSetDouble(fiboLevel2BufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // FIBO L3 ... - - // - ENUM_DRAW_TYPE fiboL3DrawType = showFiboLevel3 ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(fiboLevel3Buffer, true); - SetIndexBuffer(fiboLevel3BufferIndex, fiboLevel3Buffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(fiboLevel3BufferIndex, PLOT_SHOW_DATA, showFiboLevel3); - PlotIndexSetInteger(fiboLevel3BufferIndex, PLOT_DRAW_TYPE, fiboL3DrawType); - - // - PlotIndexSetDouble(fiboLevel3BufferIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // SAR ... - - // - ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(sarBuffer, true); - SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar); - PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType); - - // - PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); - - // - // TREND ... - - // - ENUM_DRAW_TYPE trendDrawType = showTrend ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(trendBuffer, true); - SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(trendBufferPlotIndex, PLOT_SHOW_DATA, showTrend); - // PlotIndexSetInteger(trendBufferPlotIndex, PLOT_DRAW_TYPE, trendDrawType); - - // - PlotIndexSetDouble(trendBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(trendColorBuffer, true); - SetIndexBuffer(trendColorBufferIndex, trendColorBuffer, INDICATOR_COLOR_INDEX); - - // - // KI ... - - // - ENUM_DRAW_TYPE kiDrawType = showKI ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(kiBuffer, true); - SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKI); - // PlotIndexSetInteger(kiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType); - - // - PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(kiColorBuffer, true); - SetIndexBuffer(kiColorBufferIndex, kiColorBuffer, INDICATOR_COLOR_INDEX); - - // - // TKI ... - - // - ENUM_DRAW_TYPE tkiDrawType = showTKI ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(tkiBuffer, true); - SetIndexBuffer(tkiBufferIndex, tkiBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_SHOW_DATA, showKI); - // PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType); - - // - PlotIndexSetDouble(tkiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(tkiColorBuffer, true); - SetIndexBuffer(tkiColorBufferIndex, tkiColorBuffer, INDICATOR_COLOR_INDEX); - - // - // VIDYA ... - - // - ENUM_DRAW_TYPE vidyaDrawType = showVidya ? DRAW_COLOR_LINE : DRAW_NONE; - - // - ArraySetAsSeries(vidyaBuffer, true); - SetIndexBuffer(vidyaBufferIndex, vidyaBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(vidyaBufferPlotIndex, PLOT_SHOW_DATA, showKI); - // PlotIndexSetInteger(vidyaBufferPlotIndex, PLOT_DRAW_TYPE, vidyaDrawType); - - // - PlotIndexSetDouble(vidyaBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - ArraySetAsSeries(vidyaColorBuffer, true); - SetIndexBuffer(vidyaColorBufferIndex, vidyaColorBuffer, INDICATOR_COLOR_INDEX); - - // - // SWINGS ... - - // - ENUM_DRAW_TYPE swingDrawType = showSwings ? DRAW_ARROW : DRAW_NONE; - - // - // SWING Low ... - - // - ArraySetAsSeries(swingLowBuffer, true); - SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_SHOW_DATA, showSwings); - PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_DRAW_TYPE, swingDrawType); - - // - PlotIndexSetDouble(swingLowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(swingLowBufferPlotIndex, PLOT_ARROW, swingLowArrowCode); - - // - // SWING High ... - - // - ArraySetAsSeries(swingHighBuffer, true); - SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_SHOW_DATA, showSwings); - PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_DRAW_TYPE, swingDrawType); - - // - PlotIndexSetDouble(swingHighBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(swingHighBufferPlotIndex, PLOT_ARROW, swingHighArrowCode); - - // - // MANALYSER ... - - // - // MAH ... - - // - ENUM_DRAW_TYPE mahDrawType = showMAH ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(mahBuffer, true); - SetIndexBuffer(mahBufferIndex, mahBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(mahBufferPlotIndex, PLOT_SHOW_DATA, showMAH); - PlotIndexSetInteger(mahBufferPlotIndex, PLOT_DRAW_TYPE, mahDrawType); - - // - PlotIndexSetDouble(mahBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // MAL ... - - // - ENUM_DRAW_TYPE malDrawType = showMAL ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(malBuffer, true); - SetIndexBuffer(malBufferIndex, malBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(malBufferPlotIndex, PLOT_SHOW_DATA, showMAL); - PlotIndexSetInteger(malBufferPlotIndex, PLOT_DRAW_TYPE, malDrawType); - - // - PlotIndexSetDouble(malBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // MAC ... - - // - ENUM_DRAW_TYPE macDrawType = showMAC ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(macBuffer, true); - SetIndexBuffer(macBufferIndex, macBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(macBufferPlotIndex, PLOT_SHOW_DATA, showMAC); - PlotIndexSetInteger(macBufferPlotIndex, PLOT_DRAW_TYPE, mahDrawType); - - // - PlotIndexSetDouble(macBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); - - // - // Data Buffers ... - - // - ArraySetAsSeries(trendStateBuffer, true); - SetIndexBuffer(trendStateBufferIndex, trendStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(kiStateBuffer, true); - SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(tkiStateBuffer, true); - SetIndexBuffer(tkiStateBufferIndex, tkiStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(vidyaStateBuffer, true); - SetIndexBuffer(vidyaStateBufferIndex, vidyaStateBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(supBuffer, true); - SetIndexBuffer(supBufferIndex, supBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(resBuffer, true); - SetIndexBuffer(resBufferIndex, resBuffer, INDICATOR_CALCULATIONS); - - // -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - // - IndicatorSetInteger(INDICATOR_DIGITS, _Digits); - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * 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; - if (barsLimit == 0) - { - // - barsLimit = ratesTotal; - firstBarIndex = barsLimit - 1; - } - else - { - // - firstBarIndex = startCalculationForLastBars; - } - - // - // bool canCalculate = true; - bool canCalculate = - bar_index <= barsLimit; - if (canCalculate) - { - // - // Calculate Cycles ... - CalculateCycles(bar_index); - - // - // Calculate Support nad Resistance ... - CalculateValues( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - else - { - FillBuffersZero(bar_index); - } -} - -// -// Custom ... - -/** - * Initial Market Cycles ... - * - * @return ( bool ) - */ -bool InitMarketCycles() -{ - // - bool result = false; - - // - int cPeriodSeconds = PeriodSeconds(_Period); - - // - // Find Cycle Period ... - if (scMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mSCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_SHORT, - _Period // - ); - } - else - { - mSCPeriod = scPeriod; - } - - // - if (IsValid(mSCPeriod)) - { - mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (mcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mMCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_MEDIUM, - _Period // - ); - } - else - { - mMCPeriod = mcPeriod; - } - - // - if (IsValid(mMCPeriod)) - { - mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (lcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mLCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_LONG, - _Period // - ); - } - else - { - mLCPeriod = lcPeriod; - } - - // - if (IsValid(mLCPeriod)) - { - mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; - } - - // - // Find Cycle Period ... - if (hcMethod == X_PERIOD_AUTO) - { - // - // Select Period ... - mHCPeriod = GetCyclePeriod( - X_MARKET_CYCLE_HIND, - _Period // - ); - } - else - { - mHCPeriod = hcPeriod; - } - - // - if (IsValid(mHCPeriod)) - { - mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; - } - - // - result = mSCLength > 0 && - mMCLength > mSCLength && - mLCLength > mMCLength && - mHCLength > mLCLength; - - // - return result; -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - // SHORT ... - sHHBuffer[barIndex] = emptyValue; - sLLBuffer[barIndex] = emptyValue; - - // - // MEDIUM ... - mHHBuffer[barIndex] = emptyValue; - mLLBuffer[barIndex] = emptyValue; - - // - // LONG ... - lHHBuffer[barIndex] = emptyValue; - lLLBuffer[barIndex] = emptyValue; - - // - // HIND ... - hHHBuffer[barIndex] = emptyValue; - hLLBuffer[barIndex] = emptyValue; - - // - // SUPPORT / RESISTANCE ... - supBuffer[barIndex] = emptyValue; - resBuffer[barIndex] = emptyValue; - supportBuffer[barIndex] = emptyValue; - resistanceBuffer[barIndex] = emptyValue; - - // - // PEAKS ... - peakBuffer[barIndex] = emptyValue; - peakGoldenBuffer[barIndex] = emptyValue; - - // - // VALES ... - valeBuffer[barIndex] = emptyValue; - valeGoldenBuffer[barIndex] = emptyValue; - - // - // SAR ... - sarBuffer[barIndex] = emptyValue; - - // - // TREND ... - trendBuffer[barIndex] = emptyValue; - trendColorBuffer[barIndex] = hideColorIDX; - trendStateBuffer[barIndex] = neuturalState; - - // - // KI ... - kiBuffer[barIndex] = emptyValue; - kiColorBuffer[barIndex] = hideColorIDX; - kiStateBuffer[barIndex] = neuturalState; - - // - // TKI ... - tkiBuffer[barIndex] = emptyValue; - tkiColorBuffer[barIndex] = hideColorIDX; - tkiStateBuffer[barIndex] = neuturalState; - - // - // VIDYA ... - vidyaBuffer[barIndex] = emptyValue; - vidyaColorBuffer[barIndex] = hideColorIDX; - vidyaStateBuffer[barIndex] = neuturalState; - - // - // SWINGS ... - swingLowBuffer[barIndex] = emptyValue; - swingHighBuffer[barIndex] = emptyValue; -} - -/** - * Calculate Specified Market Cycle Info ... - * - * @param barIndex: Integer, Bar Index ... - * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... - * @param hhBuffer: Highest High Buffer Reference ... - * @param llBuffer: Lowest Low Buffer Reference ... - */ -void CalculateCycle( - int barIndex, - ENUM_X_MARKET_CYCLES cycle, - double &hhBuffer[], - double &llBuffer[] // -) -{ - // - XOHCL bar; - bool isBarInited = bar.Init( - _Symbol, - _Period, - barIndex - // - ); - if (!isBarInited) - { - return; - } - - // - int mLength = 0; - switch (cycle) - { - // - case X_MARKET_CYCLE_SHORT: - mLength = mSCLength; - break; - - // - case X_MARKET_CYCLE_MEDIUM: - mLength = mMCLength; - break; - - // - case X_MARKET_CYCLE_LONG: - mLength = mLCLength; - break; - - // - case X_MARKET_CYCLE_HIND: - mLength = mHCLength; - break; - } - - // - if (mLength == 0) - { - return; - } - - // - // Find Highest High ... - double hhValue = bar.FindHighest( - mLength, - hhMode - // - ); - hhBuffer[barIndex] = hhValue; - - // - // Find Lowest Low ... - double llValue = bar.FindLowest( - mLength, - llMode - // - ); - llBuffer[barIndex] = llValue; -} - -/** - * Claculate Cycles ... - * - * @param barIndex: Integer, Bar Index ... - */ -void CalculateCycles(int barIndex) -{ - // - // SHORT ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_SHORT, - sHHBuffer, - sLLBuffer // - ); - - // - // MEDIUM ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_MEDIUM, - mHHBuffer, - mLLBuffer // - ); - - // - // LONG ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_LONG, - lHHBuffer, - lLLBuffer // - ); - - // - // HIND ... - CalculateCycle( - barIndex, - X_MARKET_CYCLE_HIND, - hHHBuffer, - hLLBuffer // - ); -} - -/** - * Calculate Values ... - * - * @param bar_index: int, Specified Bar Index ... - * @param prevCalculated: int, Provides Previous Calculated Bars ... - * @param ratesTotal: int, Provides All Availabled Bars ... - * @param open: double Collection, Provides Open Prices Time Series ... - * @param high: double Collection, Provides High Prices Time Series ... - * @param close: double Collection, Provides Close Prices Time Series ... - * @param low: double Collection, Provides Low Prices Time Series ... - * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... - */ -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[] // -) -{ - // - // Check Prev Bar ... - // - int lastBarIndex = bar_index + 1; - bool isFirstBar = - startCalculationForLastBars > 0 - ? bar_index == startCalculationForLastBars - : bar_index == firstBarIndex; - - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - bar_index // - ); - - // - double iSHH = sHHBuffer[bar_index]; - double iSLL = sLLBuffer[bar_index]; - - // - double iMHH = mHHBuffer[bar_index]; - double iMLL = mLLBuffer[bar_index]; - - // - double iLHH = lHHBuffer[bar_index]; - double iLLL = lLLBuffer[bar_index]; - - // - double iHHH = hHHBuffer[bar_index]; - double iHLL = hLLBuffer[bar_index]; - - // - // Calculate BOS ... - - // - // Calculate CHOCH ... - - // - // Calculate Support ... - double lastSupport = - isFirstBar - ? emptyValue - : supBuffer[lastBarIndex]; - bool isSupport = iSLL == iMLL; - double iSupport = - isSupport - ? iSLL - : lastSupport; - supBuffer[bar_index] = iSupport; - - // - // Calculate Vale ... - double lastVale = - isFirstBar - ? emptyValue - : valeBuffer[lastBarIndex]; - bool isVale = - isSupport && - iMLL == iLLL && - iLLL == iHLL; - double iVale = - isVale - ? iMLL - : lastVale; - valeBuffer[bar_index] = iVale; - - // - // Calculate Resistance ... - double lastResistance = - isFirstBar - ? emptyValue - : resBuffer[lastBarIndex]; - bool isResistance = iSHH == iMHH; - double iResistance = - isResistance - ? iSHH - : lastResistance; - resBuffer[bar_index] = iResistance; - - // - // Calculate Peak ... - double lastPeak = - isFirstBar - ? emptyValue - : peakBuffer[lastBarIndex]; - bool isPeak = - isResistance && - iMHH == iLHH && - iLHH == iHHH; - double iPeak = - isPeak - ? iMHH - : lastPeak; - peakBuffer[bar_index] = iPeak; - - // - bool canSmooth = - supResSmoothingLength > 0 && - supResSmoothingMode != X_MA_MODE_NONE; - if (!canSmooth) - { - // - supportBuffer[bar_index] = iSupport; - resistanceBuffer[bar_index] = iResistance; - } - else - { - // - // Support ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - supResSmoothingLength, - supBuffer, - supportBuffer, - supResSmoothingMode // - ); - - // - // Resistance ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - supResSmoothingLength, - resBuffer, - resistanceBuffer, - supResSmoothingMode // - ); - } - - // - // Calculate Fibo Levels ... - - // - double iFiboUpper = peakBuffer[bar_index]; - double iFiboLower = valeBuffer[bar_index]; - - // - double iFiboLevel1 = GetFibonacciLevel( - iFiboUpper, - iFiboLower, - fiboLevel1, - X_DIRECTION_BEARISH // - ); - fiboLevel1Buffer[bar_index] = iFiboLevel1; - - // - double iFiboLevel2 = GetFibonacciLevel( - iFiboUpper, - iFiboLower, - fiboLevel2, - X_DIRECTION_BEARISH // - ); - fiboLevel2Buffer[bar_index] = iFiboLevel2; - - // - double iFiboLevel3 = GetFibonacciLevel( - iFiboUpper, - iFiboLower, - fiboLevel3, - X_DIRECTION_BEARISH // - ); - fiboLevel3Buffer[bar_index] = iFiboLevel3; - - // - // Calculate Trend Color Buffer ... - double iClose = close[bar_index]; - double iTrend = trendBuffer[bar_index]; - - // - double iTrendState = neuturalState; - double iTrendColor = neuturalColorIDX; - if (iClose > iTrend) - { - // - iTrendState = bullishState; - iTrendColor = !showTrend - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iTrend) - { - // - iTrendState = bearishState; - iTrendColor = !showTrend - ? hideColorIDX - : bearishColorIDX; - } - trendStateBuffer[bar_index] = iTrendState; - trendColorBuffer[bar_index] = iTrendColor; - - // - // Calculate KI / Color ... - double lastKI = - isFirstBar - ? emptyValue - : kiBuffer[lastBarIndex]; - double iKI = lastKI; - if (isInited) - { - // - double iLLKI = iBar.FindLowest(kiLength, MODE_LOW); - double iHHKI = iBar.FindHighest(kiLength, MODE_HIGH); - - // - iKI = (iHHKI + iLLKI) / 2; - if (iLLKI == 0 || iHHKI == 0) - { - iKI = lastKI; - } - } - else - { - iKI = lastKI; - } - kiBuffer[bar_index] = iKI; - - // - double iKIState = neuturalState; - double iKIColor = neuturalColorIDX; - if (iClose > iKI) - { - // - iKIState = bullishState; - iKIColor = - !showKI - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iKI) - { - // - iKIState = bearishState; - iKIColor = - !showKI - ? hideColorIDX - : bearishColorIDX; - } - kiStateBuffer[bar_index] = iKIState; - kiColorBuffer[bar_index] = iKIColor; - - // - // Calculate PV Gold ... - double lastPeakGold = - isFirstBar - ? emptyValue - : peakGoldenBuffer[lastBarIndex]; - double lastValeGold = - isFirstBar - ? emptyValue - : valeGoldenBuffer[lastBarIndex]; - double iPeakGold = lastPeakGold; - double iValeGold = lastValeGold; - if (isInited) - { - // - iPeakGold = iBar.FindHighest(mHCLength, MODE_CLOSE); - if (iPeakGold == 0) - { - iPeakGold = lastPeakGold; - } - - // - iValeGold = iBar.FindLowest(mHCLength, MODE_CLOSE); - if (iValeGold == 0) - { - iValeGold = lastValeGold; - } - } - else - { - // - iPeakGold = lastPeakGold; - iValeGold = lastValeGold; - } - peakGoldenBuffer[bar_index] = iPeakGold; - valeGoldenBuffer[bar_index] = iValeGold; - - // - // Calculate Swings ... - - // - double lastSwingLow = - isFirstBar - ? emptyValue - : swingLowBuffer[lastBarIndex]; - double lastSwingHigh = - isFirstBar - ? emptyValue - : swingHighBuffer[lastBarIndex]; - - // - bool isSwingLow = IsSwingLow( - high, - low, - bar_index, - swingLength // - ); - bool isSwingHigh = IsSwingHigh( - high, - low, - bar_index, - swingLength // - ); - bool hasSwing = isSwingLow || - isSwingHigh; - if (!hasSwing) - { - // - // FillBuffersZero(bar_index); - - // - swingLowBuffer[bar_index] = lastSwingLow; - swingHighBuffer[bar_index] = lastSwingHigh; - } - else - { - // - double iSwingLow = low[bar_index]; - double iSwingHigh = high[bar_index]; - - // - if (isSwingLow && !isSwingHigh) - { - iSwingHigh = lastSwingHigh; - } - else if (isSwingHigh && !isSwingLow) - { - iSwingLow = lastSwingLow; - } - - // - if (iSwingLow > lastSwingLow && - iSwingHigh == lastSwingHigh) - { - iSwingLow = lastSwingLow; - } - - // - if (iSwingHigh < lastSwingHigh && - iSwingLow == lastSwingLow) - { - iSwingHigh = lastSwingHigh; - } - - // - swingLowBuffer[bar_index] = iSwingLow; - swingHighBuffer[bar_index] = iSwingHigh; - } - - // - // TKI State and Color ... - - // - double iTKI = tkiBuffer[bar_index]; - - // - double iTKIState = neuturalState; - double iTKIColor = neuturalColorIDX; - if (iClose > iTKI) - { - // - iTKIState = bullishState; - iTKIColor = - !showTKI - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iTKI) - { - // - iTKIState = bearishState; - iTKIColor = - !showTKI - ? hideColorIDX - : bearishColorIDX; - } - tkiStateBuffer[bar_index] = iTKIState; - tkiColorBuffer[bar_index] = iTKIColor; - - // - // VIDYA Color ... - - // - double iVIDYA = vidyaBuffer[bar_index]; - - // - double iVIDYAState = neuturalState; - double iVIDYAColor = neuturalColorIDX; - if (iClose > iVIDYA) - { - // - iVIDYAState = bullishState; - iVIDYAColor = - !showVidya - ? hideColorIDX - : bullishColorIDX; - } - else if (iClose < iVIDYA) - { - // - iVIDYAState = bearishState; - iVIDYAColor = - !showVidya - ? hideColorIDX - : bearishColorIDX; - } - vidyaStateBuffer[bar_index] = iVIDYAState; - vidyaColorBuffer[bar_index] = iVIDYAColor; - - // - // Cleanup Resources ... - - // - iBar.Clean(); -} - -// -bool IsSwingLow( - const double &high[], - const double &low[], - int index, - int length // -) -{ - // - bool result = false; - - // - result = index + 1 + length <= firstBarIndex; - if (!result) - { - return result; - } - - // - for (int i = index + 1; i <= index + length; i++) - { - // - result = low[index] < low[i]; - if (!result) - { - break; - } - } - - // - return result; -} - -// -bool IsSwingHigh( - const double &high[], - const double &low[], - int index, - int length // -) -{ - // - bool result = false; - - // - result = index + 1 + length <= firstBarIndex; - if (!result) - { - return result; - } - - // - for (int i = index + 1; i <= index + length; i++) - { - // - result = high[index] > high[i]; - if (!result) - { - break; - } - } - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/Indicators/x-saherelm.x121.xswlh.mq5 b/Documents/BKP/Indicators/x-saherelm.x121.xswlh.mq5 deleted file mode 100644 index 75640001..00000000 --- a/Documents/BKP/Indicators/x-saherelm.x121.xswlh.mq5 +++ /dev/null @@ -1,573 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 XSWLH -// Description: XSWLH ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 XSWLH Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121 XSWLH" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -input int swingLength; // Swing Length - -// -input int startCalculationForLastBars = 1000; // Calculate Last n Bars - -// -input bool showSwingLow; // Show Swing Low -input bool showSwingHigh; // Show Swing High - -// -input int swingLowArrowCode = 225; // Swing Low Arrow Code -input int swingHighArrowCode = 226; // Swing High Arrow Code - -// -#define emptyValue 0.0 - -// -// Buffers ... - -// -#property indicator_chart_window - -// -#property indicator_buffers 2 -#property indicator_plots 2 - -// -// SWING LOW ... - -// -#define swingLowBufferIndex 0 -double swingLowBuffer[]; - -// -#property indicator_label1 "SWL" -#property indicator_type1 DRAW_ARROW -#property indicator_color1 clrGreen -#property indicator_width1 1 - -// -// SWING HIGH ... - -// -#define swingHighBufferIndex 1 -double swingHighBuffer[]; - -// -#property indicator_label2 "SWH" -#property indicator_type2 DRAW_ARROW -#property indicator_color2 clrRed -#property indicator_width2 1 - -// -// Data Buffers ... - -// -#define lastBufferIndex 1 - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int firstBarIndex; - -// -int maxLength; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // 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(); - - // - // 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 -} - -/** - * 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); - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // 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 = - // - swingLength > 0 - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - result = MathMax(result, swingLength); - - // - return result; -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // Plot Buffers ... - - // - // SWING Low ... - - // - ENUM_DRAW_TYPE swingLowDrawType = showSwingLow ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(swingLowBuffer, true); - SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingLowBufferIndex, PLOT_SHOW_DATA, showSwingLow); - PlotIndexSetInteger(swingLowBufferIndex, PLOT_DRAW_TYPE, swingLowDrawType); - - // - PlotIndexSetDouble(swingLowBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(swingLowBufferIndex, PLOT_ARROW, swingLowArrowCode); - - // - // SWING High ... - - // - ENUM_DRAW_TYPE swingHighDrawType = showSwingHigh ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(swingHighBuffer, true); - SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingHighBufferIndex, PLOT_SHOW_DATA, showSwingHigh); - PlotIndexSetInteger(swingHighBufferIndex, PLOT_DRAW_TYPE, swingHighDrawType); - - // - PlotIndexSetDouble(swingHighBufferIndex, PLOT_EMPTY_VALUE, emptyValue); - PlotIndexSetInteger(swingHighBufferIndex, PLOT_ARROW, swingHighArrowCode); -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - // - IndicatorSetInteger(INDICATOR_DIGITS, _Digits); - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - swingLowBuffer[barIndex] = emptyValue; - swingHighBuffer[barIndex] = emptyValue; -} - -/** - * 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; - if (barsLimit == 0) - { - // - barsLimit = ratesTotal; - firstBarIndex = barsLimit - 1; - } - else - { - // - firstBarIndex = startCalculationForLastBars; - } - - // - // bool canCalculate = true; - bool canCalculate = - bar_index <= barsLimit; - if (canCalculate) - { - // - // Calculate Support nad Resistance ... - CalculateValues( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - else - { - FillBuffersZero(bar_index); - } -} - -/** - * Calculate Values ... - * - * @param bar_index: int, Specified Bar Index ... - * @param prevCalculated: int, Provides Previous Calculated Bars ... - * @param ratesTotal: int, Provides All Availabled Bars ... - * @param open: double Collection, Provides Open Prices Time Series ... - * @param high: double Collection, Provides High Prices Time Series ... - * @param close: double Collection, Provides Close Prices Time Series ... - * @param low: double Collection, Provides Low Prices Time Series ... - * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... - */ -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[] // -) -{ - // - // Check Prev Bar ... - // - int lastBarIndex = bar_index + 1; - bool isFirstBar = - startCalculationForLastBars > 0 - ? bar_index == startCalculationForLastBars - : bar_index == firstBarIndex; - - // - // Reading Last Values ... - - // - double iSWLPrev = - isFirstBar - ? emptyValue - : swingLowBuffer[lastBarIndex]; - - // - double iSWHPrev = - isFirstBar - ? emptyValue - : swingHighBuffer[lastBarIndex]; - - // - // Checking Swings ... - bool isSwingLow = IsSwingLow(high, low, bar_index, swingLength); - bool isSwingHigh = IsSwingHigh(high, low, bar_index, swingLength); - bool hasSwing = isSwingLow || - isSwingHigh; - if (!hasSwing) - { - // - // FillBuffersZero(bar_index); - - // - swingLowBuffer[bar_index] = iSWLPrev; - swingHighBuffer[bar_index] = iSWHPrev; - return; - } - - // - double iSWL = low[bar_index]; - double iSWH = high[bar_index]; - - // - // Act Based on Swing High or Swing Low Detection ... - if (isSwingLow && !isSwingHigh) - { - // - // Detect Swing High based On swing Low ... - iSWH = iSWHPrev; - } - else if (isSwingHigh && !isSwingLow) - { - // - // Detect Swing Low Based On Swing High ... - iSWL = iSWLPrev; - } - - // - if (iSWL > iSWLPrev && iSWH == iSWHPrev) - { - iSWL = iSWLPrev; - } - - // - if (iSWH < iSWHPrev && iSWL == iSWLPrev) - { - iSWH = iSWHPrev; - } - - // - swingLowBuffer[bar_index] = iSWL; - swingHighBuffer[bar_index] = iSWH; -} - -// -// Helpers ... - -// -bool IsSwingLow( - const double &high[], - const double &low[], - int index, - int length // -) -{ - // - bool result = false; - - // - result = index + 1 + length <= firstBarIndex; - if (!result) - { - return result; - } - - // - for (int i = index + 1; i <= index + length; i++) - { - // - result = low[index] < low[i]; - if (!result) - { - break; - } - } - - // - return result; -} - -// -bool IsSwingHigh( - const double &high[], - const double &low[], - int index, - int length // -) -{ - // - bool result = false; - - // - result = index + 1 + length <= firstBarIndex; - if (!result) - { - return result; - } - - // - for (int i = index + 1; i <= index + length; i++) - { - // - result = high[index] > high[i]; - if (!result) - { - break; - } - } - - // - return result; -} diff --git a/Documents/BKP/signallers1/xcaea.signaller.class.mq5 b/Documents/BKP/signallers1/xcaea.signaller.class.mq5 deleted file mode 100644 index 9c4b1140..00000000 --- a/Documents/BKP/signallers1/xcaea.signaller.class.mq5 +++ /dev/null @@ -1,1070 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEASignaller ... -// Description: Class for XCAEA Signaller ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA Signaller" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.base.class.mq5" -#include "../../Classes/x-saherelm.x-cobject.class.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" -#include "../Classes/xcaea.x-poi.drawer.class.mq5" -#include "../Helpers/xcaea.helper.mq5" -#include "../Libraries/xcaea.signaller.lib.mq5" - -// -// Definitions ... - -class XCXCAEASignaller : XCBase -{ - // - // Public ... - public: - // - // Props ... - bool useGuards; - bool useTargets; - int poiLoopback; - XCAEAInputs inputs; - XBarTracker barTraker; - XCXCAEAHelper *helper; - bool rfOnInvalidPivots; - XCXCAEAPOIDrawer *drawer; - bool continuesRFTillTarget; - XBoxZone unAvailableBoxes[]; - XCXCAEAPOIDetector *detector; - XCAEAStrategyConditions mConditions; - XCAEAStrategyConditions mConditionsCollection[]; - - // - // Constructor ... - XCXCAEASignaller( - string _symbol, - ENUM_TIMEFRAMES _period // - ) - { - // - symbol = _symbol; - period = _period; - - // - Init(); - } - - // - // Deconstructor ... - ~XCXCAEASignaller() - { - DeInit(); - } - - // - // Properties ... - - /** - * Initialize ... - */ - void Init() - { - // - useGuards = false; - useTargets = true; - rfOnInvalidPivots = false; - continuesRFTillTarget = false; - - // - barTraker.Init( - symbol, - period // - ); - - // - inputs.Default(); - - // - // Configure Indicators ... - - // - // XCC ... - inputs.ccInputs.showCandles = true; - - // - // XCT ... - inputs.ctInputs.showCandleTime = true; - - // - // XCA ... - - // - inputs.caInputs.supResSmoothingLength = 7; - inputs.caInputs.supResSmoothingMode = X_MA_MODE_NONE; - - // - inputs.x3maInputs.applyColor = true; - - // - inputs.x3maInputs.fastLength = 5; - - // - inputs.x3maInputs.showFast = true; - inputs.x3maInputs.showSlow = false; - inputs.x3maInputs.showMedium = false; - - // - inputs.caInputs.showMAH = true; - inputs.caInputs.showMAL = true; - inputs.caInputs.showMAC = true; - inputs.caInputs.showSar = true; - inputs.caInputs.showSwings = true; - inputs.caInputs.showFiboLevel1 = true; - inputs.caInputs.showFiboLevel2 = true; - inputs.caInputs.showFiboLevel3 = true; - inputs.caInputs.showFiboLevel4 = true; - inputs.caInputs.showFiboLevel5 = true; - inputs.caInputs.showPeaksAndVales = true; - - // - inputs.caInputs.showKI = false; - inputs.caInputs.showTKI = false; - inputs.caInputs.showVidya = false; - inputs.caInputs.showTrend = false; - inputs.caInputs.showPeakAndValeGolden = false; - inputs.caInputs.showSupportAndResistance = false; - - // - // XOSCS ... - // inputs.oscsInputs.rsiLength = 5; - // inputs.oscsInputs.rsiOBLevel = 90; - // inputs.oscsInputs.rsiOSLevel = 10; - // inputs.oscsInputs.cciLength = 7; - // inputs.oscsInputs.cciOBLevel = 130; - // inputs.oscsInputs.cciOSLevel = -130; - // inputs.oscsInputs.mfiLength = 5; - // inputs.oscsInputs.rviLength = 5; - - // - // Oscillators Views ... - inputs.showRSI = false; - inputs.showCCI = false; - inputs.showMFI = false; - inputs.showRVI = false; - inputs.showADX = false; - inputs.showMACD = false; - - // - // XCAEA Helper ... - helper = new XCXCAEAHelper(); - helper.Init( - symbol, - period, - inputs // - ); - - // - // Initialize and Configure Detector ... - detector = new XCXCAEAPOIDetector(helper); - - // - // Common Configurations ... - detector.maxAllowedPivots = 0; - detector.pivotVerifications = 5; - detector.ticksDividerInPoints = 15; - detector.pivotDetectionLoopbac = 1000; - - // - // Configure Detector ... - - // - // PV ... - - // - detector.maxAllowedPVLifetime = 0; - detector.applySwingsOnPVPivots = true; - detector.selectRejectedPVPivots = true; - detector.selectEngulfedPVPivots = true; - detector.applySupportAndResistanceOnPVPivots = true; - - // - // PEAK ... - detector.detectPeakPivots = true; - - // - // VALE ... - detector.detectValePivots = true; - - // - // FVG ... - - // - detector.selectSameBarFVGs = false; - detector.maxAllowedFVGLifetime = 0; - detector.validateFVGUsingPV = false; - detector.applyPVToFVGBoundary = false; - detector.selectRejectedFVGPivots = false; - detector.selectEngulfedFVGPivots = false; - detector.validateFVGUsingManalyser = true; - detector.applyLastBarToFVGBoundary = false; - detector.selectOnlyFVGWhichHasIndirectionalLastBar = true; - - // - // Bullish ... - detector.detectFVGBullishPivots = true; - - // - // Bearish ... - detector.detectFVGBearishPivots = true; - - // - // TREND ... - - // - detector.maxAllowedTrendLifetime = 0; - - // - // Bullish ... - detector.detectTrendBullishPivots = true; - - // - // Bearish ... - detector.detectTrendBearishPivots = true; - - // - // DRAWER ... - - // - // Initialize and Configure Drawer ... - drawer = new XCXCAEAPOIDrawer(detector); - - // - drawer.ignoreUpdateOSCTos = true; - - // - // Configure Drawer ... - drawer.drawPeakPivots = true; - drawer.drawValePivots = true; - drawer.drawFVGBullishPivots = true; - drawer.drawFVGBearishPivots = true; - drawer.drawTrendBullishPivots = true; - drawer.drawTrendBearishPivots = true; - - // - // Configure Styles ... - - // - // PV ... - - // - // PEAK ... - XCAPivotStyle peakStyle; - peakStyle.width = 2; - peakStyle.clr = clrMagenta; - peakStyle.style = STYLE_SOLID; - drawer.peakPivotStyle = peakStyle; - peakStyle.Clean(); - - // - // VALE ... - XCAPivotStyle valeStyle; - valeStyle.width = 2; - valeStyle.clr = clrAqua; - valeStyle.style = STYLE_SOLID; - drawer.valePivotStyle = valeStyle; - valeStyle.Clean(); - - // - // FVG ... - - // - // Bullish ... - XCAPivotStyle fvgBullishStyle; - fvgBullishStyle.width = 2; - fvgBullishStyle.clr = clrLime; - fvgBullishStyle.style = STYLE_DASH; - drawer.fvgBullishPivotStyle = fvgBullishStyle; - fvgBullishStyle.Clean(); - - // - // Bearish ... - XCAPivotStyle fvgBearishStyle; - fvgBearishStyle.width = 2; - fvgBearishStyle.clr = clrRed; - fvgBearishStyle.style = STYLE_DASH; - drawer.fvgBearishPivotStyle = fvgBearishStyle; - fvgBearishStyle.Clean(); - - // - // TREND ... - - // - // Bullish ... - XCAPivotStyle trendBullishStyle; - trendBullishStyle.width = 2; - trendBullishStyle.clr = clrLime; - trendBullishStyle.style = STYLE_DOT; - drawer.trendBullishPivotStyle = trendBullishStyle; - trendBullishStyle.Clean(); - - // - // Bearish ... - XCAPivotStyle trendBearishStyle; - trendBearishStyle.width = 2; - trendBearishStyle.clr = clrRed; - trendBearishStyle.style = STYLE_DOT; - drawer.trendBearishPivotStyle = trendBearishStyle; - trendBearishStyle.Clean(); - - // - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - inputs.Clean(); - - // - // Cleaning Draws ... - drawer.Clear(); - - // - ZeroMemory(drawer); - ZeroMemory(helper); - ZeroMemory(detector); - - // - mConditions.Clean(); - Clean(mConditionsCollection); - - // - mObjects.Clear(); - mBarObjects.Clear(); - - // - barTraker.Clean(); - } - - // - string GetSymbol() - { - return symbol; - } - - // - ENUM_TIMEFRAMES GetPeriod() - { - return period; - } - - // - // Signaller Tools ... - - /** - * Detect Setup Conditions based on Signalling ... - * - * @param maxAllowedSLDistanceInPoint: int, Max Allowed SL Distance in Points (if Bigger thn Zero Provided) ... - * - * @return ( bool ) - */ - bool DetectSignalSetup( - double tpReward = 3, - double maxAllowedSLDistanceInPoint = 100 // - ) - { - // - bool result = false; - - // - // Check Bar Processing ... - if (!barTraker.CanProcessBar()) - { - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL pPBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - 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(); - - // - return result; - } - - // - // Setup Conditions ... - double targets[]; - XBoxZone pivots[]; - XBoxZone pivotBox; - XBoxZone signalBox; - int pivotsCount = 0; - bool hasTrend = false; - bool hasPivots = false; - double additionalSL = 0; - bool hasSignalBox = false; - XCAEAConditions conditions; - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; - - // - // Detecting Pivots ... - // detector.Detect( - // zIndex // - // ); - - // - // Validate Pivots ... - // detector.Validate( - // unAvailableBoxes, - // zIndex // - // ); - - // - // if (detector.pivotDetectionLoopbac > 100) - // { - // detector.pivotDetectionLoopbac = 100; - // } - - // - // Draw Founded Pivots ... - // drawer.Draw(cTime); - - // - // drawer.DrawPeakPivots(cTime); - // drawer.DrawValePivots(cTime); - // drawer.DrawFVGBullishPivots(cTime); - // drawer.DrawFVGBearishPivots(cTime); - // drawer.DrawTrendBullishPivots(cTime); - // drawer.DrawTrendBearishPivots(cTime); - - // - // Retrieve Valid Pviots ... - // pivotsCount = detector.FillPivots(pivots); - // hasPivots = IsValidSize(pivotsCount); - - // - // Filter UnAvailable Boxes ... - // if (hasPivots) - // { - // // - // // Remove UnAvailable Boxes ... - // has = HasChild(unAvailableBoxes); - // if (has) - // { - // // - // count = ArraySize(unAvailableBoxes); - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox = unAvailableBoxes[i]; - - // // - // has = FindBoxIndex( - // idx, - // iBox, - // pivots // - // ); - // if (has) - // { - // // - // ArrayRemove( - // pivots, - // idx, - // 1 // - // ); - // } - // } - // } - - // // - // hasPivots = HasChild(pivots); - // pivotsCount = ArraySize(pivots); - // } - - // - // - // - - // - TestDetectSignal( - helper, - drawer, - signalBox, - signalBoxDir, - conditions, - zIndex, - loopback // - ); - - // // - // // Detect Sinal Box ... - // hasSignalBox = DetectXCAEAConditions( - // drawer, - // trend, - // pivots, - // conditions, - // pivotBox, - // signalBox, - // targets, - // additionalSL, - // signalBoxDir, - // helper, - // zIndex, - // loopback // - // ); - - // - // Make Pivot Box UnAvailable ... - if (pivotBox.IsValid()) - { - // - AddRef( - pivotBox, - unAvailableBoxes // - ); - } - - // - // Make Signal Box UnAvailable ... - if (signalBox.IsValid()) - { - // - AddRef( - signalBox, - unAvailableBoxes // - ); - } - - // - isBullish = hasSignalBox && - IsBullish(signalBoxDir); - - // - isBearish = hasSignalBox && - IsBearish(signalBoxDir); - - // - result = isBullish || - isBearish; - if (result) - { - // - // Do What we Want ... - barTraker.Waits(); - - // - // Draw Signal Box ... - XCBoxObject *iObj; - bool isCreated = helper.poiDrawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - mObjects.Add(iObj); - ZeroMemory(iObj); - - // - // Print("Signal Box ..."); - } - - // - // Prepare Conditions ... - mConditions.symbol = symbol; - mConditions.period = period; - - // - double spread = GetSpread(symbol); - - // - double entry = - isBullish - ? signalBox.upper - : signalBox.lower; - - // - double sl = - isBullish - ? signalBox.lower - : signalBox.upper; - if (additionalSL > 0) - { - // - sl = - isBullish - ? sl - additionalSL - : sl + additionalSL; - } - - // - double risk = - isBullish - ? entry - sl - : sl - entry; - risk += spread; - if (risk >= maxAllowedSLDistanceInPoint * points) - { - // - // Fix Risk in Big Distances ... - double hh5 = zBar.FindHighest(5, MODE_HIGH); - double ll5 = zBar.FindLowest(5, MODE_LOW); - - // - double hhll5Delta = hh5 - ll5; - double riskDelta = hhll5Delta / 2; - risk = riskDelta; - } - - // - double rewardTP = risk * tpReward; - - // - double tp = - isBullish - ? entry + rewardTP - : entry - rewardTP; - - // - // Filling ... - mConditions.sl = sl; - mConditions.tp = tp; - mConditions.pivot = - isBullish - ? sl - : entry; - mConditions.point = - isBullish - ? entry - : sl; - mConditions.dir = signalBoxDir; - mConditions.provider = "XCAEA"; - mConditions.signalBox = signalBox; - mConditions.setupTime = zBar.time; - mConditions.conditions = conditions; - - // - // Targets Preparing ... - if (useTargets) - { - // - Copy( - targets, - mConditions.targets // - ); - - // - // Select RF Rewards ... - if (continuesRFTillTarget) - { - // - double rfReward = 1; - while (rfReward < tpReward) - { - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - - // - rfReward++; - } - } - else - { - // - double rfReward = 2; - - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - } - - // - // Detect Rf on Invalid Pivots ... - if (rfOnInvalidPivots) - { - // - has = detector.HasInvalidPivots(); - if (has) - { - // - XBoxZone targetBox; - double targetBoxPrice = 0; - count = detector.CountInvalidPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iPivot = detector.invalidPivots[i]; - - // - bool isValidPivot = - Contains( - "XCA_PEAKSWHRES", - iPivot.type // - ) || - Contains( - "XCA_VALESWLSUP", - iPivot.type // - ) || - Contains( - "XCA_FVG", - iPivot.type // - ); - if (!isValidPivot) - { - // - iPivot.Clean(); - continue; - } - - // - double selectedPrice = - isBullish - ? iPivot.lower - (5 * points) - : iPivot.upper + (5 * points); - - // - double targetBoxSelectedPrice = - isBullish - ? targetBox.lower - (5 * points) - : targetBox.upper + (5 * points); - - // - bool isDirPassed = iPivot.dir = signalBoxDir; - bool isPricePassed = - isBullish - ? entry < selectedPrice - : entry > selectedPrice; - bool canSetTarget = - !targetBox.IsValid() - ? true - : isBullish - ? targetBoxSelectedPrice > selectedPrice - : targetBoxSelectedPrice < selectedPrice; - if (canSetTarget) - { - // - targetBox = iPivot; - targetBoxPrice = targetBoxSelectedPrice; - } - - // - iPivot.Clean(); - } - - // - if (targetBox.IsValid() && - targetBoxPrice > 0) - { - // - Add( - targetBoxPrice, - mConditions.targets // - ); - } - - // - targetBox.Clean(); - } - } - } - } - - // - // Cleanup Resource ... - - // - Clean(pivots); - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - - // - pivotBox.Clean(); - signalBox.Clean(); - conditions.Clean(); - - // - return result; - } - - /** - * Detect Trigger Conditions for Specified Signal ... - * - * @param conditions: XCAEAStrategyConditions instance Reference, Specified Signal Conditions ... - * @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ... - * - * @return ( bool ) - */ - bool DetectSignalTrigger( - XCAEAStrategyConditions &conditions, - int maxAllowedSetupAge = 60 // - ) - { - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Check Signal Validation ... - // IMPORTANT: since all Validations done in SetUp Process ... - // here we only Execute Signal ... - - // - result = isBullish || - isBearish; - - // - if (result) - { - // - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - } - - // - // Cleanup ... - - // - return result; - } - - /** - * Detect Guards bsed on Signalling Class ... - * - * @param guards: XCAEAGuard instance Collection, Holds Provided Guards ... - * @param positions: XPosition instance Collection, Provides Signalling Based Positions for Apply Guards on them ... - * @param provider: X121SMCStrategySignalProviderData instance Reference, Specified Data for Cycles ... - * - * @return ( bool ) - */ - bool DetectGuards( - XCAEAGuard &guards[], - const XPosition &positions[] // - ) - { - // - bool result = false; - - // - return result; - } - - /** - * Add Conditions to Conditions Collection if not Exists ... - * - * @param maxAllowed: int, Specified Max Allowed Holding Conditions ... - * - * @return ( int ) - */ - int AddConditionsIfNotExists( - int maxAllowed = 10 // - ) - { - // - int result = 0; - - // - bool isSetuped = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(mConditionsCollection); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - XCAEAStrategyConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - XCAEAStrategyConditions iItem = tmpItems[i]; - - // - bool canRemove = mConditions.dir == iItem.dir && - mConditions.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - mConditionsCollection, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - mConditions, - mConditionsCollection // - ); - - // - // Remove Olds ... - CleanupArray( - mConditionsCollection, - maxAllowed // - ); - - // - result = ArraySize(mConditionsCollection); - - // - return result; - } - - // - // Protected ... - protected: - // - - // - // Private ... - private: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - CArrayObj mObjects; - CArrayObj mBarObjects; - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/signallers1/xcaea.signaller.lib.mq5 b/Documents/BKP/signallers1/xcaea.signaller.lib.mq5 deleted file mode 100644 index 91ae70d1..00000000 --- a/Documents/BKP/signallers1/xcaea.signaller.lib.mq5 +++ /dev/null @@ -1,2810 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCAEASignaller Lib -// Description: Library for XCAEA Signaller ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Library for XCAEA Signaller" -#property strict - -// -// Imports ... -#include "../../Libraries/x-saherelm.common.lib.mq5" -#include "../../Libraries/x-saherelm.x-poi.lib.mq5" -#include "../../Libraries/x-saherelm.x-trade.lib.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" -#include "../Classes/xcaea.x-poi.drawer.class.mq5" -#include "../Helpers/xcaea.helper.mq5" - -// -// Enumeration ... - -// -// Guard Actions ... -enum ENUM_GUARD_ACTIONS -{ - X_GUARD_ACTION_NONE, // Nothing to Do - X_GUARD_ACTION_CLOSE, // Close Specified Position - X_GUARD_ACTION_CLOSE_ALL, // Close All Positions - X_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions - X_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position - X_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position - X_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position - X_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position - X_GUARD_ACTION_HEDGE, // Hedge Specified Positions -}; - -// -// Definitions ... - -// -// Conditions Struct ... -struct XCAEAStrategyConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - // Setup Props ... - - // - double sl; - double tp; - double pivot; - double point; - string provider; - double targets[]; - - // - datetime time; - datetime setupTime; - datetime triggerTime; - - // - XBoxZone signalBox; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - XCAEAConditions conditions; - - // - // Constructor ... - XCAEAStrategyConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - tp = 0; - pivot = 0; - point = 0; - - // - symbol = NULL; - period = NULL; - provider = NULL; - - // - time = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - Clean(targets); - - // - signalBox.Clean(); - conditions.Clean(); - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - ZeroMemory(this); - } - - // - // Signalling ... - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = IsSpecifiedValid(symbol) && - IsSpecifiedValid(period) && - IsSpecifiedValid(time); - - // - return result; - } - - /** - * Check Conditions Has Valid Bullish Signal ... - * - * @return ( bool ) - */ - bool HasBullishSignal() - { - // - bool result = false; - - // - result = - (sl > 0 || - tp > 0) && - IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - result = - IsBullish(dir); - - // - return result; - } - - /** - * Check Conditions Has Valid Bearish Signal ... - * - * @return ( bool ) - */ - bool HasBearishSignal() - { - // - bool result = false; - - // - result = - (sl > 0 || - tp > 0) && - IsValid() && - HasDirection(dir); - if (!result) - { - return result; - } - - // - result = - IsBearish(dir); - - // - return result; - } - - // - // Setting Up and Triggering Up ... - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // -}; - -// -// Model a Guard Action ... -struct XCAEAGuard -{ - // - // Props ... - ENUM_GUARD_ACTIONS action; - datetime time; - - // - string symbol; - string provider; - - // - // Specified Position ... - ulong ticket; - - // - // Partial Close ... - double volumeMultiplier; - - // - // SL Trial ... - double sl; - - // - // TP Trial ... - double tp; - - // - // Constructor ... - XCAEAGuard() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - time = NULL; - action = X_GUARD_ACTION_NONE; - - // - symbol = NULL; - provider = NULL; - - // - ticket = 0; - - // - volumeMultiplier = 0; - - // - sl = 0; - tp = 0; - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(time) && - IsValid(symbol) && - IsValid(provider) && - action != X_GUARD_ACTION_NONE - // - ; - if (!result) - { - return result; - } - - // - // Validate Model Based On Specified Guard Actions ... - - // - return result; - } -}; - -/** - * Add Guard to Collection ... - * - * @param guard: XCAEAGuard instance ... - * @param guards: XCAEAGuard instance Collection ... - * - * @return ( int ) - */ -int AddGuard( - XCAEAGuard &guard, - XCAEAGuard &guards[] // -) -{ - // - int result = 0; - - // - if (!guard.IsValid()) - { - return result; - } - - // - AddRef( - guard, - guards // - ); - - // - result = ArraySize(guards); - - // - return result; -} - -// -bool TestDetectSignal( - XCXCAEAHelper *helper, - XCXCAEAPOIDrawer *drawer, - XBoxZone &box, - ENUM_X_DIRECTION &dir, - XCAEAConditions &conditions, - int barIndex = 0, - int loopback = 10 // -) -{ - // - bool result = false; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - box.Clean(); - conditions.Clean(); - dir = X_DIRECTION_NONE; - barIndex = NormalizeInt(barIndex, 0); - loopback = NormalizeInt(loopback, 5); - - // - // Retrieve Some Requirements ... - string symbol = helper.GetSymbol(); - ENUM_TIMEFRAMES period = helper.GetPeriod(); - double points = GetPoints(symbol); - - // - // Retrieve Conditions for Processing ... - result = helper.GetConditions( - conditions, - barIndex, - loopback // - ); - if (!result) - { - // - box.Clean(); - conditions.Clean(); - - // - return result; - } - - // - // Define IDXses ... - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - int p4IDX = p3IDX + 1; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - XOHCL p3Bar; - XOHCL p4Bar; - result = zBar.Init( - symbol, - period, - zIDX // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(p2Bar); - result = - result && - p2Bar.GetPreviousBar(p3Bar); - result = - result && - p3Bar.GetPreviousBar(p4Bar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - p3Bar.Clean(); - p4Bar.Clean(); - - // - box.Clean(); - conditions.Clean(); - - // - return result; - } - - // - // Bars Conditions ... - - // - // Score ... - - // - double bullishScore = 0; - double bearishScore = 0; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isScoreBullish = - bullishScore > bearishScore; - - // - bool isScoreBearish = - bearishScore > bullishScore; - - // - bool isScoreNeutural = MathAbs(bullishScore - bearishScore) == 0; - - // - // Calculating Range Volumes ... - - // - double bullishVolume = 0; - double bearishVolume = 0; - helper.barAnalyser.CalculateRangeVolume( - cBar, - bullishVolume, - bearishVolume, - loopback // - ); - - // - bool isVolumeNeutural = MathAbs(bullishVolume - bearishVolume) == 0; - - // - // Reading Values ... - - // - // SAR ... - double zSar = conditions.sarBuffer[zIDX]; - double cSar = conditions.sarBuffer[cIDX]; - double pSar = conditions.sarBuffer[pIDX]; - double p2Sar = conditions.sarBuffer[p2IDX]; - double p3Sar = conditions.sarBuffer[p3IDX]; - - // - // PEAK ... - double zPeak = conditions.peakBuffer[zIDX]; - double cPeak = conditions.peakBuffer[cIDX]; - double pPeak = conditions.peakBuffer[pIDX]; - double p2Peak = conditions.peakBuffer[p2IDX]; - double p3Peak = conditions.peakBuffer[p3IDX]; - double p4Peak = conditions.peakBuffer[p4IDX]; - - // - // VALE ... - double zVale = conditions.valeBuffer[zIDX]; - double cVale = conditions.valeBuffer[cIDX]; - double pVale = conditions.valeBuffer[pIDX]; - double p2Vale = conditions.valeBuffer[p2IDX]; - double p3Vale = conditions.valeBuffer[p3IDX]; - double p4Vale = conditions.valeBuffer[p4IDX]; - - // - // SWING Low ... - double zSWL = conditions.swingLowBuffer[zIDX]; - double cSWL = conditions.swingLowBuffer[cIDX]; - double pSWL = conditions.swingLowBuffer[pIDX]; - double p2SWL = conditions.swingLowBuffer[p2IDX]; - double p3SWL = conditions.swingLowBuffer[p3IDX]; - - // - // SWING High ... - double zSWH = conditions.swingHighBuffer[zIDX]; - double cSWH = conditions.swingHighBuffer[cIDX]; - double pSWH = conditions.swingHighBuffer[pIDX]; - double p2SWH = conditions.swingHighBuffer[p2IDX]; - double p3SWH = conditions.swingHighBuffer[p3IDX]; - - // - // SUPPORT ... - double zSupport = conditions.supportBuffer[zIDX]; - double cSupport = conditions.supportBuffer[cIDX]; - double pSupport = conditions.supportBuffer[pIDX]; - double p2Support = conditions.supportBuffer[p2IDX]; - double p3Support = conditions.supportBuffer[p3IDX]; - - // - // RESISTANCE ... - double zResistance = conditions.resistanceBuffer[zIDX]; - double cResistance = conditions.resistanceBuffer[cIDX]; - double pResistance = conditions.resistanceBuffer[pIDX]; - double p2Resistance = conditions.resistanceBuffer[p2IDX]; - double p3Resistance = conditions.resistanceBuffer[p3IDX]; - - // - // MAH ... - double zMAH = conditions.mahBuffer[zIDX]; - double cMAH = conditions.mahBuffer[cIDX]; - double pMAH = conditions.mahBuffer[pIDX]; - double p2MAH = conditions.mahBuffer[p2IDX]; - double p3MAH = conditions.mahBuffer[p3IDX]; - - // - // MAL ... - double zMAL = conditions.malBuffer[zIDX]; - double cMAL = conditions.malBuffer[cIDX]; - double pMAL = conditions.malBuffer[pIDX]; - double p2MAL = conditions.malBuffer[p2IDX]; - double p3MAL = conditions.malBuffer[p3IDX]; - - // - // MAC ... - double zMAC = conditions.macBuffer[zIDX]; - double cMAC = conditions.macBuffer[cIDX]; - double pMAC = conditions.macBuffer[pIDX]; - double p2MAC = conditions.macBuffer[p2IDX]; - double p3MAC = conditions.macBuffer[p3IDX]; - - // - // FIBO Level 1 ... - double zFib1 = conditions.fiboLevel1Buffer[zIDX]; - double cFib1 = conditions.fiboLevel1Buffer[cIDX]; - double pFib1 = conditions.fiboLevel1Buffer[pIDX]; - double p2Fib1 = conditions.fiboLevel1Buffer[p2IDX]; - double p3Fib1 = conditions.fiboLevel1Buffer[p3IDX]; - - // - // FIBO Level 2 ... - double zFib2 = conditions.fiboLevel2Buffer[zIDX]; - double cFib2 = conditions.fiboLevel2Buffer[cIDX]; - double pFib2 = conditions.fiboLevel2Buffer[pIDX]; - double p2Fib2 = conditions.fiboLevel2Buffer[p2IDX]; - double p3Fib2 = conditions.fiboLevel2Buffer[p3IDX]; - - // - // FIBO Level 3 ... - double zFib3 = conditions.fiboLevel3Buffer[zIDX]; - double cFib3 = conditions.fiboLevel3Buffer[cIDX]; - double pFib3 = conditions.fiboLevel3Buffer[pIDX]; - double p2Fib3 = conditions.fiboLevel3Buffer[p2IDX]; - double p3Fib3 = conditions.fiboLevel3Buffer[p3IDX]; - - // - // FIBO Level 4 ... - double zFib4 = conditions.fiboLevel4Buffer[zIDX]; - double cFib4 = conditions.fiboLevel4Buffer[cIDX]; - double pFib4 = conditions.fiboLevel4Buffer[pIDX]; - double p2Fib4 = conditions.fiboLevel4Buffer[p2IDX]; - double p3Fib4 = conditions.fiboLevel4Buffer[p3IDX]; - - // - // FIBO Level 5 ... - double zFib5 = conditions.fiboLevel5Buffer[zIDX]; - double cFib5 = conditions.fiboLevel5Buffer[cIDX]; - double pFib5 = conditions.fiboLevel5Buffer[pIDX]; - double p2Fib5 = conditions.fiboLevel5Buffer[p2IDX]; - double p3Fib5 = conditions.fiboLevel5Buffer[p3IDX]; - - // - // FAST ... - double zFast = conditions.fastBuffer[zIDX]; - double cFast = conditions.fastBuffer[cIDX]; - double pFast = conditions.fastBuffer[pIDX]; - double p2Fast = conditions.fastBuffer[p2IDX]; - double p3Fast = conditions.fastBuffer[p3IDX]; - - // - // FAST State ... - double zFastState = conditions.fastStateBuffer[zIDX]; - double cFastState = conditions.fastStateBuffer[cIDX]; - double pFastState = conditions.fastStateBuffer[pIDX]; - double p2FastState = conditions.fastStateBuffer[p2IDX]; - double p3FastState = conditions.fastStateBuffer[p3IDX]; - - // - // Create Custom Conditions ... - - // - // Bar and Fibo Conditions ... - - // - // Bearish ... - - // - // Strong Reversal ... - bool isZBarOnFiboStrongBearish = zBar.low > zFib5; - bool isCBarOnFiboStrongBearish = cBar.low > cFib5; - bool isPBarOnFiboStrongBearish = pBar.low > pFib5; - bool isP2BarOnFiboStrongBearish = p2Bar.low > p2Fib5; - bool isP3BarOnFiboStrongBearish = p3Bar.low > p3Fib5; - - // - // Golden Zone Reversal ... - bool isZBarOnFiboGoldenBearish = zBar.low > zFib3 && - zBar.high < zFib4; - bool isCBarOnFiboGoldenBearish = cBar.low > cFib3 && - cBar.high < cFib4; - bool isPBarOnFiboGoldenBearish = pBar.low > pFib3 && - pBar.high < pFib4; - bool isP2BarOnFiboGoldenBearish = p2Bar.low > p2Fib3 && - p2Bar.high < p2Fib4; - bool isP3BarOnFiboGoldenBearish = p3Bar.low > p3Fib3 && - p3Bar.high < p3Fib4; - - // - // Bullish ... - - // - // Strong Reversal ... - bool isZBarOnFiboStrongBullish = zBar.high < zFib1; - bool isCBarOnFiboStrongBullish = cBar.high < cFib1; - bool isPBarOnFiboStrongBullish = pBar.high < pFib1; - bool isP2BarOnFiboStrongBullish = p2Bar.high < p2Fib1; - bool isP3BarOnFiboStrongBullish = p3Bar.high < p3Fib1; - - // - // Golden Zone Reversal ... - bool isZBarOnFiboGoldenBullish = zBar.low > zFib2 && - zBar.high < zFib3; - bool isCBarOnFiboGoldenBullish = cBar.low > cFib2 && - cBar.high < cFib3; - bool isPBarOnFiboGoldenBullish = pBar.low > pFib2 && - pBar.high < pFib3; - bool isP2BarOnFiboGoldenBullish = p2Bar.low > p2Fib2 && - p2Bar.high < p2Fib3; - bool isP3BarOnFiboGoldenBullish = p3Bar.low > p3Fib2 && - p3Bar.high < p3Fib3; - - // - // Score and Volume Conditions ... - - // - bool isScoreVolumeNeutural = isScoreNeutural || - isVolumeNeutural; - - // - bool isScoreVolumeNeuturalInFiboStrongBullish = - isScoreNeutural && - isCBarOnFiboStrongBullish; - - // - bool isScoreVolumeNeuturalInFiboGoldenBullish = - isScoreNeutural && - isCBarOnFiboGoldenBullish; - - // - bool isScoreVolumeNeuturalInFiboStrongBearish = - isScoreNeutural && - isCBarOnFiboStrongBearish; - - // - bool isScoreVolumeNeuturalInFiboGoldenBearish = - isScoreNeutural && - isCBarOnFiboGoldenBearish; - - // - bool isScoreVolumeNeuturalBullishPowered = - isScoreVolumeNeuturalInFiboStrongBullish || - isScoreVolumeNeuturalInFiboGoldenBullish; - - // - bool isScoreVolumeNeuturalBearishPowered = - isScoreVolumeNeuturalInFiboStrongBearish || - isScoreVolumeNeuturalInFiboGoldenBearish; - - // - // PEAK and VALES ... - - // - // PEAK Pivot ... - bool isZIsPeakPivot = - zPeak == cPeak && - zPeak == zSWH && - zPeak == zResistance && - isZBarOnFiboStrongBearish; - bool isCIsPeakPivot = - cPeak == pPeak && - cPeak == cSWH && - cPeak == cResistance && - isCBarOnFiboStrongBearish; - bool isPIsPeakPivot = - pPeak == p2Peak && - pPeak == pSWH && - pPeak == pResistance && - isPBarOnFiboStrongBearish; - bool isP2IsPeakPivot = - p2Peak == p3Peak && - p2Peak == p2SWH && - p2Peak == p2Resistance && - isP2BarOnFiboStrongBearish; - bool isP3IsPeakPivot = - p3Peak == p4Peak && - p3Peak == p3SWH && - p3Peak == p3Resistance && - isP3BarOnFiboStrongBearish; - - // - // VALE Pivot ... - bool isZIsValePivot = - zVale == cVale && - zVale == zSWL && - zVale == zSupport && - isZBarOnFiboStrongBullish; - bool isCIsValePivot = - cVale == pVale && - cVale == cSWL && - cVale == cSupport && - isCBarOnFiboStrongBullish; - bool isPIsValePivot = - pVale == p2Vale && - pVale == pSWL && - pVale == pSupport && - isPBarOnFiboStrongBullish; - bool isP2IsValePivot = - p2Vale == p3Vale && - p2Vale == p2SWL && - p2Vale == p2Support && - isP2BarOnFiboStrongBullish; - bool isP3IsValePivot = - p3Vale == p4Vale && - p3Vale == p3SWL && - p3Vale == p3Support && - isP3BarOnFiboStrongBullish; - - // - // FIBO Section Change Detection ... - bool isFiboSectionChanged = - // - (cFib1 != pFib1 && - cFib2 != pFib2 && - cFib3 != pFib3 && - cFib4 != pFib4 && - cFib5 != pFib5) - // - && - // - (conditions.isPeakUnderLast || - conditions.isValeOverLast || - conditions.isSwingLowOverLast || - conditions.isSwingHighUnderLast) - // - ; - - // - // SAR Change ... - - // - bool isSarSwitchedInFiboStrongBullish = - isCBarOnFiboStrongBullish && - conditions.isSarSwitchedToBullish; - - // - bool isSarSwitchedInFiboGoldenBullish = - isCBarOnFiboGoldenBullish && - conditions.isSarSwitchedToBullish; - - // - bool isSarSwitchedInFiboStrongBearish = - isCBarOnFiboStrongBearish && - conditions.isSarSwitchedToBearish; - - // - bool isSarSwitchedInFiboGoldenBearish = - isCBarOnFiboGoldenBearish && - conditions.isSarSwitchedToBearish; - - // - bool isSarSwitchedToBullish = - cFastState > 0 && - isSarSwitchedInFiboStrongBullish; - - // - bool isSarSwitchedToBearish = - cFastState < 0 && - isSarSwitchedInFiboStrongBearish; - ; - - // - // Testing Conditions ... - - // - // Detect Fibo Section Changed ... - if (isFiboSectionChanged) - { - // Print("Fibo Section Changed ..."); - } - - // - // PVPivot Conditions ... - if (isCIsPeakPivot || - isCIsValePivot) - { - // // - // ENUM_X_DIRECTION iPVPivotDir = - // isCIsValePivot - // ? X_DIRECTION_BULLISH - // : X_DIRECTION_BEARISH; - - // // - // int timeOffset = (int)cBar.time; - // string iName = ToString(iPVPivotDir) + "_PVPVT_" + ToString(timeOffset); - // color iColor = isCIsValePivot - // ? clrAqua - // : clrMagenta; - // ENUM_LINE_STYLE iStyle = STYLE_DOT; - - // // - // CChartObjectVLine *iObj; - // iObj = new CChartObjectVLine(); - // has = iObj.Create( - // 0, - // iName, - // 0, - // cBar.time // - // ); - // if (has) - // { - // // - // iObj.Color(iColor); - // iObj.Style(iStyle); - // } - - // // - // Print("Conditions Finder ..."); - } - - // - // Testing Sar Changes ... - if (isSarSwitchedToBullish || - isSarSwitchedToBearish) - { - // - // ENUM_X_DIRECTION iSarChangeDir = - // isSarSwitchedToBullish - // ? X_DIRECTION_BULLISH - // : X_DIRECTION_BEARISH; - - // // - // int timeOffset = (int)cBar.time; - // string iName = ToString(iSarChangeDir) + "_SAR_" + ToString(timeOffset); - // color iColor = isSarSwitchedToBullish - // ? clrAqua - // : clrMagenta; - // ENUM_LINE_STYLE iStyle = STYLE_DOT; - - // // - // CChartObjectVLine *iObj; - // iObj = new CChartObjectVLine(); - // has = iObj.Create( - // 0, - // iName, - // 0, - // cBar.time // - // ); - // if (has) - // { - // // - // iObj.Color(iColor); - // iObj.Style(iStyle); - // } - - // - // Print("Conditions Finder ..."); - } - - // - // Score and Volume Conditions ... - if (isScoreVolumeNeuturalBullishPowered || - isScoreVolumeNeuturalBearishPowered) - { - // - // ENUM_X_DIRECTION iScoreVolumeDir = - // isScoreVolumeNeuturalBullishPowered - // ? X_DIRECTION_BULLISH - // : X_DIRECTION_BEARISH; - - // // - // int timeOffset = (int)cBar.time; - // string iName = ToString(iScoreVolumeDir) + "_SCVM_" + ToString(timeOffset); - // color iColor = isScoreVolumeNeuturalBullishPowered - // ? clrAqua - // : clrMagenta; - // ENUM_LINE_STYLE iStyle = STYLE_DOT; - - // - // CChartObjectVLine *iObj; - // iObj = new CChartObjectVLine(); - // has = iObj.Create( - // 0, - // iName, - // 0, - // cBar.time // - // ); - // if (has) - // { - // // - // iObj.Color(iColor); - // iObj.Style(iStyle); - // } - - // // - // Print("Conditions Finder ..."); - } - - // - // Custom Senarios ... - - // - bool isCond1Bullish = - isCIsValePivot && - !isFiboSectionChanged && - isSarSwitchedToBullish; - - // - bool isCond1Bearish = - isCIsPeakPivot && - !isFiboSectionChanged && - isSarSwitchedToBearish; - - // - bool isCond1 = - isCond1Bullish || - isCond1Bearish; - if (isCond1) - { - // - ENUM_X_DIRECTION iCond1Dir = - isCond1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - int timeOffset = (int)cBar.time; - string iName = ToString(iCond1Dir) + "_COND1_" + ToString(timeOffset); - color iColor = isCond1Bullish - ? clrAqua - : clrMagenta; - ENUM_LINE_STYLE iStyle = STYLE_DOT; - - // - CChartObjectVLine *iObj; - iObj = new CChartObjectVLine(); - has = iObj.Create( - 0, - iName, - 0, - cBar.time // - ); - if (has) - { - // - iObj.Color(iColor); - iObj.Style(iStyle); - } - - // - // Create Signal Box Based on Cond1 ... - - // - double upper = - isCond1Bullish - ? cBar.FindHighest(5, MODE_HIGH) - : MathMax(cPeak, cSWH); - - // - double lower = - isCond1Bullish - ? MathMin(cVale, cSWL) - : cBar.FindLowest(5, MODE_LOW); - - // - int toIDX = cBar.Index(); - int fromIDX = cBar.Index() + 5; - - // - datetime toTime = GetBarTime( - symbol, - period, - toIDX // - ); - datetime fromTime = GetBarTime( - symbol, - period, - fromIDX // - ); - - // - XBoxZone iBox; - - // - iBox.to = toTime; - iBox.upper = upper; - iBox.lower = lower; - iBox.type = "COND1"; - iBox.symbol = symbol; - iBox.period = period; - iBox.dir = iCond1Dir; - iBox.from = fromTime; - - // - has = iBox.IsValid(); - if (has) - { - // - XCBoxObject *iObj; - has = helper - .poiDrawer - .DrawBox( - iBox, - iObj // - ); - if (has) - { - // - // Style Object ... - } - } - - // - iBox.Clean(); - - // - // Print("Conditions Finder ..."); - } - - // - // Summarise Result ... - - // - bool isBullish = false; - bool isBearish = false; - - // - result = isBullish || - isBearish; - if (result) - { - // - // Do Signal Preparing ... - - // - // Check Box is Prepared or Not ... - result = box.IsValid(); - } - - // - // Cleaning Up ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - p3Bar.Clean(); - p4Bar.Clean(); - - // - if (!result) - { - // - box.Clean(); - conditions.Clean(); - } - - // - return result; -} - -// -// Cond 2 ... -// - a PV Box is Sweep Liquidity; -// - a Directional FVg Occures Exactly after Liquidity Sweep; -// - Price Action Go Inside FVG; -// - SL behind FVG; - -// -bool DetectXCAEAConditions( - XCXCAEAPOIDrawer *drawer, - XBoxZone &pivots[], - XCAEAConditions &conditions, - XBoxZone &pivotBox, - XBoxZone &box, - double &targets[], - double &additionalSL, - ENUM_X_DIRECTION &dir, - XCXCAEAHelper *helper, - int barIndex = 0, - int loopback = 10 // -) -{ - // - bool result = false; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - box.Clean(); - additionalSL = 0; - conditions.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - loopback = NormalizeInt(loopback, 5); - - // - // Retrieve Some Requirements ... - string symbol = helper.GetSymbol(); - ENUM_TIMEFRAMES period = helper.GetPeriod(); - double points = GetPoints(symbol); - - // - // Trend Parsing ... - // bool hasTrend = HasDirection(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - - // - // Retrieve Previous and Current Bar Conditions ... - XCAEAConditions pConditions; - result = helper.GetConditions( - conditions, - barIndex, - loopback // - ); - result = result && - helper.GetConditions( - pConditions, - barIndex + 1, - loopback // - ); - if (!result) - { - // - conditions.Clean(); - pConditions.Clean(); - - // - return result; - } - - // - // Define IDXses ... - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - int p4IDX = p3IDX + 1; - - // - // Reading Bars ... - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - XOHCL p3Bar; - XOHCL p4Bar; - result = zBar.Init( - symbol, - period, - zIDX // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(p2Bar); - result = - result && - p2Bar.GetPreviousBar(p3Bar); - result = - result && - p3Bar.GetPreviousBar(p4Bar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - p3Bar.Clean(); - p4Bar.Clean(); - - // - box.Clean(); - conditions.Clean(); - pConditions.Clean(); - - // - return result; - } - - // - // Bars Conditions ... - - // - // Temparory Bar Direction ... - ENUM_X_DIRECTION cBarDir; - - // - // Hammer ... - bool isCBarHammer = helper - .barAnalyser - .IsHammer( - cBar, - cBarDir // - ); - bool isCBarBullishHammer = - isCBarHammer && - IsBullish(cBarDir); - bool isCBarBearishHammer = - isCBarHammer && - IsBearish(cBarDir); - - // - // Rejected ... - bool isCBarRejected = helper - .barAnalyser - .IsRejected( - cBar, - cBarDir, - false, // Force Type ... - true // Force Fibo Pressure ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarDir); - - // - // Engulfed ... - bool isCBarEngulfed = helper - .barAnalyser - .IsEngulfed( - cBar, - cBarDir // - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarDir); - - // - // Momentum ... - bool isCBarMomentum = helper - .barAnalyser - .IsMomentum( - cBar, - cBarDir, - 1 // - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarDir); - - // - // Bar Sumarise ... - - // - bool isCBarValidForBullish = - (isCBarBullishHammer || - isCBarBullishRejected || - isCBarBullishMomentum || - isCBarBullishEngulfed); - - // - bool isCBarValidForBearish = - (isCBarBearishHammer || - isCBarBearishRejected || - isCBarBearishMomentum || - isCBarBearishEngulfed); - - // - // Score ... - - // - double bullishScore = 0; - double bearishScore = 0; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isScoreBullish = - bullishScore > bearishScore; - - // - bool isScoreBearish = - bearishScore > bullishScore; - - // - bool isScoreNeutural = MathAbs(bullishScore - bearishScore) == 0; - - // - // Calculating Range Volumes ... - - // - double bullishVolume = 0; - double bearishVolume = 0; - int volumeRangeLoopback = loopback; - helper.barAnalyser.CalculateRangeVolume( - cBar, - bullishVolume, - bearishVolume, - volumeRangeLoopback // - ); - - // - bool isVolumeNeutural = MathAbs(bullishVolume - bearishVolume) == 0; - - // - double rangeVolume = bullishVolume == bearishVolume; - double rangeVolumeAvg = rangeVolume / volumeRangeLoopback; - - // - bool isVolumeBullish = bullishVolume > bearishVolume; - bool isVolumeBearish = bullishVolume < bearishVolume; - bool isVolumeOverLast = cBar.volume > pBar.volume; - bool isVolumeOverAvg = cBar.volume > rangeVolumeAvg; - - // - // Conditions ... - - // - // SAR ... - double zSar = conditions.sarBuffer[zIDX]; - double cSar = conditions.sarBuffer[cIDX]; - double pSar = conditions.sarBuffer[pIDX]; - double p2Sar = conditions.sarBuffer[p2IDX]; - - // - // PEAK ... - double zPeak = conditions.peakBuffer[zIDX]; - double cPeak = conditions.peakBuffer[cIDX]; - double pPeak = conditions.peakBuffer[pIDX]; - double p2Peak = conditions.peakBuffer[p2IDX]; - - // - // VALE ... - double zVale = conditions.valeBuffer[zIDX]; - double cVale = conditions.valeBuffer[cIDX]; - double pVale = conditions.valeBuffer[pIDX]; - double p2Vale = conditions.valeBuffer[p2IDX]; - - // - // PEAKGOLDEN ... - double zPeakGolden = conditions.peakGoldenBuffer[zIDX]; - double cPeakGolden = conditions.peakGoldenBuffer[cIDX]; - double pPeakGolden = conditions.peakGoldenBuffer[pIDX]; - double p2PeakGolden = conditions.peakGoldenBuffer[p2IDX]; - - // - // VALEGOLDEN ... - double zValeGolden = conditions.valeGoldenBuffer[zIDX]; - double cValeGolden = conditions.valeGoldenBuffer[cIDX]; - double pValeGolden = conditions.valeGoldenBuffer[pIDX]; - double p2ValeGolden = conditions.valeGoldenBuffer[p2IDX]; - - // - // SUPPORT ... - double zSupport = conditions.supportBuffer[zIDX]; - double cSupport = conditions.supportBuffer[cIDX]; - double pSupport = conditions.supportBuffer[pIDX]; - double p2Support = conditions.supportBuffer[p2IDX]; - - // - // RESISTANCE ... - double zResistance = conditions.resistanceBuffer[zIDX]; - double cResistance = conditions.resistanceBuffer[cIDX]; - double pResistance = conditions.resistanceBuffer[pIDX]; - double p2Resistance = conditions.resistanceBuffer[p2IDX]; - - // - // SWING LOW ... - double zSwingLow = conditions.swingLowBuffer[zIDX]; - double cSwingLow = conditions.swingLowBuffer[cIDX]; - double pSwingLow = conditions.swingLowBuffer[pIDX]; - double p2SwingLow = conditions.swingLowBuffer[p2IDX]; - - // - // SWING HIGH ... - double zSwingHigh = conditions.swingHighBuffer[zIDX]; - double cSwingHigh = conditions.swingHighBuffer[cIDX]; - double pSwingHigh = conditions.swingHighBuffer[pIDX]; - double p2SwingHigh = conditions.swingHighBuffer[p2IDX]; - - // - // TREND ... - double zTrend = conditions.trendBuffer[zIDX]; - double cTrend = conditions.trendBuffer[cIDX]; - double pTrend = conditions.trendBuffer[pIDX]; - double p2Trend = conditions.trendBuffer[p2IDX]; - - // - // KI ... - double zKI = conditions.kiBuffer[zIDX]; - double cKI = conditions.kiBuffer[cIDX]; - double pKI = conditions.kiBuffer[pIDX]; - double p2KI = conditions.kiBuffer[p2IDX]; - - // - // TKI ... - double zTKI = conditions.tkiBuffer[zIDX]; - double cTKI = conditions.tkiBuffer[cIDX]; - double pTKI = conditions.tkiBuffer[pIDX]; - double p2TKI = conditions.tkiBuffer[p2IDX]; - - // - // VIDYA ... - double zVIDYA = conditions.vidyaBuffer[zIDX]; - double cVIDYA = conditions.vidyaBuffer[cIDX]; - double pVIDYA = conditions.vidyaBuffer[pIDX]; - double p2VIDYA = conditions.vidyaBuffer[p2IDX]; - - // - // RSI ... - double zRSI = conditions.rsiBuffer[zIDX]; - double cRSI = conditions.rsiBuffer[cIDX]; - double pRSI = conditions.rsiBuffer[pIDX]; - double p2RSI = conditions.rsiBuffer[p2IDX]; - - // - // CCI ... - double zCCI = conditions.cciBuffer[zIDX]; - double cCCI = conditions.cciBuffer[cIDX]; - double pCCI = conditions.cciBuffer[pIDX]; - double p2CCI = conditions.cciBuffer[p2IDX]; - - // - // ATR ... - double zATR = conditions.atrBuffer[zIDX]; - double cATR = conditions.atrBuffer[cIDX]; - double pATR = conditions.atrBuffer[pIDX]; - double p2ATR = conditions.atrBuffer[p2IDX]; - - // - // ADX ... - double zADX = conditions.adxBuffer[zIDX]; - double cADX = conditions.adxBuffer[cIDX]; - double pADX = conditions.adxBuffer[pIDX]; - double p2ADX = conditions.adxBuffer[p2IDX]; - - // - // ADX P ... - double zADXP = conditions.adxpBuffer[zIDX]; - double cADXP = conditions.adxpBuffer[cIDX]; - double pADXP = conditions.adxpBuffer[pIDX]; - double p2ADXP = conditions.adxpBuffer[p2IDX]; - - // - // ADX N ... - double zADXN = conditions.adxnBuffer[zIDX]; - double cADXN = conditions.adxnBuffer[cIDX]; - double pADXN = conditions.adxnBuffer[pIDX]; - double p2ADXN = conditions.adxnBuffer[p2IDX]; - - // - // X3MA ... - - // - // FAST ... - - // - double z3MAFast = conditions.fastBuffer[zIDX]; - double c3MAFast = conditions.fastBuffer[cIDX]; - double p3MAFast = conditions.fastBuffer[pIDX]; - double p23MAFast = conditions.fastBuffer[p2IDX]; - - // - double z3MAFastState = conditions.fastStateBuffer[zIDX]; - double c3MAFastState = conditions.fastStateBuffer[cIDX]; - double p3MAFastState = conditions.fastStateBuffer[pIDX]; - double p23MAFastState = conditions.fastStateBuffer[p2IDX]; - - // - // MEDIUM ... - - // - double z3MAMedium = conditions.mediumBuffer[zIDX]; - double c3MAMedium = conditions.mediumBuffer[cIDX]; - double p3MAMedium = conditions.mediumBuffer[pIDX]; - double p23MAMedium = conditions.mediumBuffer[p2IDX]; - - // - double z3MAMediumState = conditions.mediumStateBuffer[zIDX]; - double c3MAMediumState = conditions.mediumStateBuffer[cIDX]; - double p3MAMediumState = conditions.mediumStateBuffer[pIDX]; - double p23MAMediumState = conditions.mediumStateBuffer[p2IDX]; - - // - // SLOW ... - - // - double z3MASlow = conditions.slowBuffer[zIDX]; - double c3MASlow = conditions.slowBuffer[cIDX]; - double p3MASlow = conditions.slowBuffer[pIDX]; - double p23MASlow = conditions.slowBuffer[p2IDX]; - - // - double z3MASlowState = conditions.slowStateBuffer[zIDX]; - double c3MASlowState = conditions.slowStateBuffer[cIDX]; - double p3MASlowState = conditions.slowStateBuffer[pIDX]; - double p23MASlowState = conditions.slowStateBuffer[p2IDX]; - - // - double x3maBullishGapUpper = c3MAMedium; - double x3maBullishGapLower = c3MASlow; - - // - double x3maBearishGapUpper = c3MASlow; - double x3maBearishGapLower = c3MAMedium; - - // - double cTrendValues[7] = { - cKI, - cTKI, - cTrend, - cVIDYA, - c3MAFast, - c3MASlow, - c3MAMedium, - }; - double pTrendValues[7] = { - pKI, - pTKI, - pTrend, - pVIDYA, - p3MAFast, - p3MASlow, - p3MAMedium, - }; - - // - double minCTrendValue = GetMin(cTrendValues); - double maxCTrendValue = GetMax(cTrendValues); - - // - double minPTrendValue = GetMin(pTrendValues); - double maxPTrendValue = GetMax(pTrendValues); - - // - double cTrendValuesRange = (maxCTrendValue - minCTrendValue); - double cTrendValuesRangePoint = (cTrendValuesRange / points); - - // - double pTrendValuesRange = (maxPTrendValue - minPTrendValue); - double pTrendValuesRangePoint = (pTrendValuesRange / points); - - // - // Create Conditions ... - - // - bool isPRSIOB = - pRSI > conditions.rsiOBLevel; - - // - bool isPRSIOS = - pRSI < conditions.rsiOSLevel; - - // - bool isRSIBullish = - cRSI > pRSI && - !conditions.isRSIOB; - - // - bool isRSIBearish = - cRSI < pRSI && - !conditions.isRSIOS; - - // - bool isPCCIOB = - pCCI > conditions.cciOBLevel; - - // - bool isPCCIOS = - pCCI < conditions.cciOSLevel; - - // - bool isCCIBullish = - cCCI > pCCI && - !conditions.isCCIOB; - - // - bool isCCIBearish = - cCCI < pCCI && - !conditions.isCCIOS; - - // - bool isADXBullish = - cADX > cADXN; - bool isADXBullishPrev = - pADX > pADXN; - - // - bool isADXSwitchedToBullish = isADXBullish && - !isADXBullishPrev; - - // - bool isADXBearish = - cADX > cADXN; - bool isADXBearishPrev = - pADX > pADXN; - - // - bool isADXSwitchedToBearish = isADXBearish && - !isADXBearishPrev; - - // - double barStrongAtrMult = 1.5; - - // - bool isCBarRangeHasStrongATR = - cBar.GetRange() > cATR * barStrongAtrMult; - - // - bool isCBarBodyHasStrongATR = - cBar.GetBody() > cATR * barStrongAtrMult; - - // - bool isCBarHasStrongATR = isCBarRangeHasStrongATR && - isCBarBodyHasStrongATR; - - // - bool isCBarIsStrongBullish = - isCBarHasStrongATR && - cBar.IsBullish(); - - // - bool isCBarIsStrongBearish = - isCBarHasStrongATR && - cBar.IsBearish(); - - // - bool isLowOverMax = cBar.low > maxCTrendValue; - bool isHighUnderMin = cBar.high < minCTrendValue; - bool isCloseOverMax = cBar.close > maxCTrendValue; - bool isCloseUnderMin = cBar.close < minCTrendValue; - - // - bool isCTrendRangeValid = cTrendValuesRangePoint <= 50; - bool isPTrendRangeValid = pTrendValuesRangePoint <= 50; - - // - bool isTrendRangeSwitchedToValid = isCTrendRangeValid && - !isPTrendRangeValid; - bool isTrendRangeFinishedFromValid = !isCTrendRangeValid && - isPTrendRangeValid; - - // - bool isPeakGoldenRejected = - cBar.high > cPeakGolden && - cBar.GetUp() <= cPeakGolden; - - // - bool isValeGoldenRejected = - cBar.low < cValeGolden && - cBar.GetDown() >= cValeGolden; - - // - bool isX3MaBullishState = - // - z3MAFast > z3MAMedium && - c3MAFast > c3MAMedium && - z3MAMedium > z3MASlow && - c3MAMedium > c3MASlow - // - ; - - // - bool isX3MaBearishState = - // - z3MAFast < z3MAMedium && - c3MAFast < c3MAMedium && - z3MAMedium < z3MASlow && - c3MAMedium < c3MASlow - // - ; - - // - bool isX3MaValidForBullishRejection = - // - c3MASlowState > 0 && - z3MASlowState > 0 && - z3MAMediumState > 0 && - c3MAMediumState > 0 && - z3MAMedium > z3MASlow && - c3MAMedium > c3MASlow && - conditions.isVidyaBullish - // - ; - - // - bool isX3MaValidForBearishRejection = - // - c3MASlowState < 0 && - z3MASlowState < 0 && - z3MAMediumState < 0 && - c3MAMediumState < 0 && - z3MAMedium < z3MASlow && - c3MAMedium < c3MASlow && - conditions.isVidyaBearish - // - ; - - // - // Parsing Pivots ... - XBoxZone upperPivot; - XBoxZone lowerPivot; - double providedSL = 0; - XBoxZone rejectedPivot; - XBoxZone insidePivots[]; - int insidePivotsCount = 0; - XBoxZone fakeBreakedPivot; - bool isRejectedOnMid = false; - bool hasInsidePivots = false; - bool hasPivots = HasChild(pivots); - if (hasPivots) - { - // - // Select Inside Boxes ... - ENUM_XCA_PIVOTS allowedInsidePivots[] = { - XCA_FVG_BULL, - XCA_FVG_BEAR, - }; - insidePivotsCount = SelectInsideBoxes( - allowedInsidePivots, - insidePivots, - pivots, - zBar, - cBar, - pBar, - p2Bar // - ); - Clean(allowedInsidePivots); - hasInsidePivots = IsValidSize(insidePivotsCount); - - // - // Detect Rejected Pivot ... - ENUM_XCA_PIVOTS allowedRejectedPivots[] = { - XCA_FVG_BULL, - XCA_FVG_BEAR, - }; - has = SelectRejectedBox( - allowedRejectedPivots, - rejectedPivot, - isRejectedOnMid, - pivots, - zBar, - cBar, - pBar, - p2Bar, - false, // Ignore Mid Rejection ... - true, - true // - ); - Clean(allowedRejectedPivots); - - // - // Select Fake Breakout Box ... - ENUM_XCA_PIVOTS allowedFakeBreakedPivots[] = { - XCA_PEAK, - XCA_VALE, - }; - has = SelectFakeBreakedBox( - allowedFakeBreakedPivots, - fakeBreakedPivot, - pivots, - helper, - zBar, - cBar, - pBar, - p2Bar // - ); - Clean(allowedFakeBreakedPivots); - - // - // Select Boundary Boxes ... - ENUM_XCA_PIVOTS allowedBoundarydPivots[] = { - XCA_PEAK, - XCA_VALE, - }; - has = SelectBoundaryBoxes( - allowedBoundarydPivots, - upperPivot, - lowerPivot, - pivots, - helper, - zBar, - cBar, - pBar, - p2Bar // - ); - Clean(allowedBoundarydPivots); - } - - // - // Signaller Summarization ... - - // - // Cond1 Act Using FVG Rejections ... - - // - bool isCond1Bullish = - // - false && // TODO: Remove this ... - isRSIBullish && - isVolumeOverAvg && - isVolumeOverLast && - conditions.isSarBullish && - rejectedPivot.IsValid() && - rejectedPivot.IsBullish() && - isX3MaValidForBullishRejection - // - ; - - // - bool isCond1Bearish = - // - false && // TODO: Remove this ... - isRSIBearish && - isVolumeOverAvg && - isVolumeOverLast && - conditions.isSarBearish && - rejectedPivot.IsValid() && - rejectedPivot.IsBearish() && - isX3MaValidForBearishRejection - // - ; - - // - bool isCond1 = isCond1Bullish || - isCond1Bearish; - if (isCond1) - { - pivotBox = rejectedPivot; - } - - // - // Cond2 Act Using OSC Box and Vydia ... - - // - bool isCond2Bullish = - // - upperPivot.IsValid() && - lowerPivot.IsValid() && - fakeBreakedPivot.IsValid() && - fakeBreakedPivot.IsBullish() - // - ; - - // - bool isCond2Bearish = - // - upperPivot.IsValid() && - lowerPivot.IsValid() && - fakeBreakedPivot.IsValid() && - fakeBreakedPivot.IsBearish() - // - ; - - // - bool isCond2 = isCond2Bullish || - isCond2Bearish; - if (isCond2) - { - Print("Cond2 ..."); - } - - // - // Cond3 Act Using CCi Peaks and Vales ... - - // - bool isCond3Bullish = - // - false - // - ; - - // - bool isCond3Bearish = - // - false - // - ; - - // - bool isCond3 = isCond3Bullish || - isCond3Bearish; - if (isCond3) - { - } - - // - // Summarise Conditions ... - - // - bool isBullish = - // - isCond1Bullish || - isCond2Bullish || - isCond3Bullish; - // - ; - - // - bool isBearish = - // - isCond1Bearish || - isCond2Bearish || - isCond3Bearish - // - ; - - // - result = isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double entry = GetEntry( - conditions.symbol, - dir // - ); - - // - double sls[]; - - // - // Preparing SLs ... - - // - // For Cond 1 ... - // For Cond 2 ... - if (isCond1 || - isCond2) - { - // - if (isCond1Bullish) - { - // - // Rejected Pivot ... - Add( - rejectedPivot.lower, - sls // - ); - - // - if (!isRejectedOnMid) - { - // - Add( - rejectedPivot.GetMid(), - sls // - ); - } - } - else - { - // - // Rejected Pivot ... - Add( - rejectedPivot.upper, - sls // - ); - - // - if (!isRejectedOnMid) - { - // - Add( - rejectedPivot.GetMid(), - sls // - ); - } - } - - // - providedSL = - isCond1Bullish - ? GetMax(sls) - : GetMin(sls); - // - } - - // - double risk = MathAbs(providedSL - entry); - double riskPoint = risk / points; - - // - double sl = - providedSL > 0 - ? providedSL - : isBullish - ? pivotBox.lower - : pivotBox.upper; - - // - box.dir = dir; - box.symbol = conditions.symbol; - box.period = conditions.period; - - // - box.upper = - isBullish - ? entry - : sl; - - // - box.lower = - isBullish - ? sl - : entry; - - // - box.to = zBar.time; - box.from = p4Bar.time; - - // - box.type = "XCASignal"; - - // - // Preparing Targets ... - if (isCond1 || - isCond2) - { - // - // Add Reward 1 ... - - // - double rewardPrice = 1 * risk; - double rewardTP = - isBullish - ? entry + rewardPrice - : entry - rewardPrice; - - // - Add( - rewardTP, - targets // - ); - } - - // - Clean(sls); - } - - // - result = box.IsValid() && - HasDirection(dir); - - // - // Cleanup Resources ... - - // - if (!result) - { - // - box.Clean(); - pivotBox.Clean(); - conditions.Clean(); - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - p3Bar.Clean(); - p4Bar.Clean(); - upperPivot.Clean(); - lowerPivot.Clean(); - Clean(cTrendValues); - Clean(pTrendValues); - Clean(insidePivots); - pConditions.Clean(); - rejectedPivot.Clean(); - fakeBreakedPivot.Clean(); - - // - return result; -} - -// -// Select Inside Boxes ... -int SelectInsideBoxes( - ENUM_XCA_PIVOTS &allowedTypes[], - XBoxZone &insideBoxes[], - XBoxZone &boxes[], - XOHCL &zBar, - XOHCL &cBar, - XOHCL &pBar, - XOHCL &p2Bar // -) -{ - // - int result = 0; - - // - Clean(insideBoxes); - - // - bool has = - zBar.IsValid() && - cBar.IsValid() && - pBar.IsValid() && - p2Bar.IsValid() && - HasChild(boxes); - if (!has) - { - return result; - } - - // - int count = ArraySize(boxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = boxes[i]; - - // - ENUM_XCA_PIVOTS iType = GetPivotType(iBox); - bool isAllowedType = IsValid(iType) && - !HasChild(allowedTypes) - ? true - : Contains( - iType, - allowedTypes // - ); - if (!isAllowedType) - { - // - iBox.Clean(); - - // - continue; - } - - // - bool isBullish = iBox.IsBullish(); - bool isBearish = iBox.IsBearish(); - - // - // Check Inside Conditions ... - - // - bool isBullishInside = - // - isBullish && - // - ((cBar.low < iBox.upper && - cBar.low > iBox.lower) || - (cBar.GetDown() < iBox.upper && - cBar.GetDown() > iBox.lower)) - // - ; - - // - bool isBearishInside = - // - isBearish && - // - ((cBar.high > iBox.lower && - cBar.high < iBox.upper) || - (cBar.GetUp() > iBox.lower && - cBar.GetUp() < iBox.upper)) - // - ; - - // - has = isBullishInside || - isBearishInside; - if (has) - { - // - AddRef( - iBox, - insideBoxes // - ); - } - - // - iBox.Clean(); - } - - // - result = ArraySize(insideBoxes); - - // - return result; -} - -// -bool SelectRejectedBox( - ENUM_XCA_PIVOTS &allowedTypes[], - XBoxZone &box, - bool &rejectOnMid, - XBoxZone &boxes[], - XOHCL &zBar, - XOHCL &cBar, - XOHCL &pBar, - XOHCL &p2Bar, - bool ignoreMidRejection = true, - bool forceBarType = false, - bool forcePressure = false // -) -{ - // - bool result = false; - - // - box.Clean(); - rejectOnMid = false; - - // - // Validate ... - result = HasChild(boxes) && - zBar.IsValid() && - cBar.IsValid() && - pBar.IsValid() && - p2Bar.IsValid(); - if (!result) - { - return result; - } - - // - int count = ArraySize(boxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = boxes[i]; - - // - ENUM_XCA_PIVOTS iType = GetPivotType(iBox); - bool isAllowedType = IsValid(iType) && - !HasChild(allowedTypes) - ? true - : Contains( - iType, - allowedTypes // - ); - if (!isAllowedType) - { - // - iBox.Clean(); - - // - continue; - } - - // - bool isBullish = iBox.IsBullish(); - bool isBearish = iBox.IsBearish(); - - // - double boundaryPrice = iBox.GetRejection(); - - // - double midPrice = iBox.GetMid(); - - // - bool isMidBullishRejected = cBar.IsRejected( - midPrice, - X_DIRECTION_BULLISH, - forceBarType, - forcePressure // - ); - - // - bool isBoundaryBullishRejected = cBar.IsRejected( - boundaryPrice, - X_DIRECTION_BULLISH, - forceBarType, - forcePressure // - ); - - // - bool isMidBearishRejected = cBar.IsRejected( - midPrice, - X_DIRECTION_BEARISH, - forceBarType, - forcePressure // - ); - - // - bool isBoundaryBearishRejected = cBar.IsRejected( - boundaryPrice, - X_DIRECTION_BEARISH, - forceBarType, - forcePressure // - ); - - // - if (ignoreMidRejection) - { - // - isMidBullishRejected = false; - isMidBearishRejected = false; - } - - // - bool isBullishRejected = - isBullish && - (isMidBullishRejected || - isBoundaryBullishRejected); - - // - bool isBearishRejected = - isBearish && - (isMidBearishRejected || - isBoundaryBearishRejected); - - // - bool isRejected = - isBullishRejected || - isBearishRejected; - if (isRejected) - { - // - box = iBox; - rejectOnMid = isBullishRejected - ? isMidBullishRejected - : isMidBearishRejected; - break; - } - - // - iBox.Clean(); - } - - // - result = box.IsValid(); - - // - return result; -} - -// -bool SelectFakeBreakedBox( - ENUM_XCA_PIVOTS &allowedTypes[], - XBoxZone &box, - XBoxZone &boxes[], - XCXCAEAHelper *helper, - XOHCL &zBar, - XOHCL &cBar, - XOHCL &pBar, - XOHCL &p2Bar // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - // Validate ... - result = - zBar.IsValid() && - cBar.IsValid() && - pBar.IsValid() && - p2Bar.IsValid() && - HasChild(boxes); - if (!result) - { - return result; - } - - // - XBoxZone tmp[]; - Copy( - boxes, - tmp // - ); - - // - int idx = -1; - XBoxZone iBox; - while (HasChild(tmp)) - { - // - idx = GetYoungest(tmp); - result = IsValidIndex(idx); - if (!result) - { - break; - } - - // - iBox = tmp[idx]; - ArrayRemove( - tmp, - idx, - 1 // - ); - - // - // Checking Box Type Allowed ... - ENUM_XCA_PIVOTS iType = GetPivotType(iBox); - result = IsValid(iType) && - (!HasChild(allowedTypes) - ? true - : Contains( - iType, - allowedTypes // - )); - if (!result) - { - // - iBox.Clean(); - continue; - } - - // - // Check Box Fake Breakeout ... - result = IsFakeBreakeout( - iBox, - helper, - cBar.Index() // - ); - if (result) - { - // - box = iBox; - break; - } - - // - iBox.Clean(); - } - - // - Clean(tmp); - iBox.Clean(); - - // - result = box.IsValid(); - - // - return result; -} - -// -bool SelectBoundaryBoxes( - ENUM_XCA_PIVOTS &allowedTypes[], - XBoxZone &upperBox, - XBoxZone &lowerBox, - XBoxZone &boxes[], - XCXCAEAHelper *helper, - XOHCL &zBar, - XOHCL &cBar, - XOHCL &pBar, - XOHCL &p2Bar // -) -{ - // - bool result = false; - - // - upperBox.Clean(); - lowerBox.Clean(); - - // - // Validate ... - result = - zBar.IsValid() && - cBar.IsValid() && - pBar.IsValid() && - p2Bar.IsValid() && - HasChild(boxes); - if (!result) - { - return result; - } - - // - XBoxZone tmp[]; - Copy( - boxes, - tmp // - ); - - // - int idx = -1; - XBoxZone iBox; - while (HasChild(tmp)) - { - // - idx = GetYoungest(tmp); - result = IsValidIndex(idx); - if (!result) - { - break; - } - - // - iBox = tmp[idx]; - ArrayRemove( - tmp, - idx, - 1 // - ); - - // - // Checking Box Type Allowed ... - ENUM_XCA_PIVOTS iType = GetPivotType(iBox); - result = IsValid(iType) && - (!HasChild(allowedTypes) - ? true - : Contains( - iType, - allowedTypes // - )); - if (!result) - { - // - iBox.Clean(); - continue; - } - - // - // Upper ... - bool canSetUpper = - iType == XCA_PEAK && - (!upperBox.IsValid() - ? true - : upperBox.lower > iBox.lower); - if (canSetUpper) - { - upperBox = iBox; - } - - // - // Lower ... - bool canSetLower = - iType == XCA_VALE && - (!lowerBox.IsValid() - ? true - : lowerBox.upper < iBox.upper); - if (canSetLower) - { - lowerBox = iBox; - } - - // - iBox.Clean(); - } - - // - Clean(tmp); - iBox.Clean(); - - // - result = upperBox.IsValid() && - lowerBox.IsValid(); - - // - return result; -} - -// -int ExtractValues( - double &values[], - XBoxZone &pivots[], - bool forceClean = true // -) -{ - // - int result = 0; - - // - if (forceClean) - { - Clean(values); - } - - // - int count = ArraySize(pivots); - for (int i = 0; i < count; i++) - { - // - XBoxZone iPivot = pivots[i]; - - // - Add( - iPivot.upper, - values // - ); - - // - Add( - iPivot.lower, - values // - ); - - // - iPivot.Clean(); - } - - // - result = ArraySize(values); - - // - return result; -} - -// -double GetMax(XBoxZone &pivots[]) -{ - // - double values[]; - ExtractValues( - values, - pivots // - ); - - // - double result = GetMax(values); - - // - Clean(values); - - // - return result; -} - -// -double GetMin(XBoxZone &pivots[]) -{ - // - double values[]; - ExtractValues( - values, - pivots // - ); - - // - double result = GetMin(values); - - // - Clean(values); - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/test.tmp.mq5 b/Documents/BKP/test.tmp.mq5 deleted file mode 100644 index 295565c4..00000000 --- a/Documents/BKP/test.tmp.mq5 +++ /dev/null @@ -1,273 +0,0 @@ -// -// Detect SignalBox Trigger ... -// Cond1: -// - Close Under Min / Max ... -// - All Trendings in Direction ... -// - Consolidating Trendings ... -// - ... -bool CanTriggerCond1( - XCXCAEAHelper *helper, - XBoxZone &box, - ENUM_X_DIRECTION &dir, - double &sls[], - int barIndex = 0, - int loopback = 10 // -) -{ - // - bool result = false; - - // - // Normalize Args ... - Clean(sls); - dir = X_DIRECTION_NONE; - loopback = NormalizeInt(loopback, 5); - barIndex = NormalizeInt(barIndex, 0); - - // - // Validate Decision Box ... - result = box.IsValid(); - if (!result) - { - return result; - } - - // - // Retrieve Market Conditions ... - XCAEAConditions conditions; - result = helper.GetConditions( - conditions, - barIndex, - loopback // - ); - - // - // Extract CBar ... - XOHCL cBar; - result = cBar.Init( - conditions.symbol, - conditions.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - conditions.Clean(); - - // - return result; - } - - // - // Bar Conditions ... - - // - ENUM_X_DIRECTION barDir; - - // - // ENGULF ... - - // - bool isCBarEngulfed = helper - .barAnalyser - .IsEngulfed( - cBar, - barDir // - ); - - // - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(barDir); - - // - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(barDir); - - // - bool isBullish = box.IsBullish(); - bool isBearish = box.IsBearish(); - - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - int p4IDX = p3IDX + 1; - - // - // Reading Values ... - - // - // SAR ... - double cSAR = conditions.sarBuffer[cIDX]; - - // - // SWH ... - double cSWH = conditions.swingHighBuffer[cIDX]; - - // - // SWL ... - double cSWL = conditions.swingLowBuffer[cIDX]; - - // - // PEAK ... - double cPeak = conditions.peakBuffer[cIDX]; - - // - // VALE ... - double cVale = conditions.valeBuffer[cIDX]; - - // - // MAH ... - double cMAH = conditions.mahBuffer[cIDX]; - - // - // MAC ... - double cMAC = conditions.macBuffer[cIDX]; - - // - // MAL ... - double cMAL = conditions.malBuffer[cIDX]; - - // - // KI ... - double cKI = conditions.kiBuffer[cIDX]; - double cKIState = conditions.kiStateBuffer[cIDX]; - - // - // TKI ... - double cTKI = conditions.tkiBuffer[cIDX]; - double cTKIState = conditions.tkiStateBuffer[cIDX]; - - // - // FAST ... - double cFast = conditions.fastBuffer[cIDX]; - double cFastState = conditions.fastStateBuffer[cIDX]; - - // - // VIDYA ... - double cVidya = conditions.vidyaBuffer[cIDX]; - double cVidyaState = conditions.vidyaStateBuffer[cIDX]; - - // - // TREND ... - double cTrend = conditions.trendBuffer[cIDX]; - double cTrendState = conditions.trendStateBuffer[cIDX]; - - // - // Generating Conditions ... - - // - bool isSWLOverBox = cSWL > box.lower; - bool isSWHUnderBox = cSWH < box.upper; - - // - bool isValeOverBox = cVale > box.lower; - bool isPeakUnderBox = cPeak < box.upper; - - // - bool hasBullishPress = - // isBullish && - (isSWLOverBox || - isValeOverBox); - - // - bool hasBearishPress = - // isBearish && - (isSWHUnderBox || - isPeakUnderBox); - - // - double trends[] = { - cMAH, - cMAC, - cMAL, - cKI, - cTKI, - cFast, - cVidya, - cTrend // - }; - double trendMax = GetMax(trends); - double trendMin = GetMin(trends); - Copy( - trends, - sls // - ); - - // - bool isCloseOverMax = cBar.close > trendMax; - bool isCloseUnderMin = cBar.close < trendMin; - - // - bool isStateBullish = - cKIState > 0 && - cTKIState > 0 && - cFastState > 0 && - cTrendState > 0 && - cVidyaState > 0; - - // - bool isStateBearish = - cKIState < 0 && - cTKIState < 0 && - cFastState < 0 && - cTrendState < 0 && - cVidyaState < 0; - - // - bool hasBullishTrend = - // isBullish && - isStateBullish && - isCloseOverMax; - - // - bool hasBearishTrend = - // isBearish && - isStateBearish && - isCloseUnderMin; - - // - // Summarizing ... - - // - bool canTriggerLong = - // isBullish && - hasBullishPress && - hasBullishTrend; - - // - bool canTriggerShort = - // isBearish && - hasBearishPress && - hasBearishTrend; - - // - result = canTriggerLong || - canTriggerShort; - if (result) - { - // - dir = canTriggerLong - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - Print("Triggered ..."); - } - - // - // Cleanup Resources ... - - // - cBar.Clean(); - Clean(trends); - conditions.Clean(); - - // - return result; -} diff --git a/Documents/BKP/xcaea.signaller.class.mq5 b/Documents/BKP/xcaea.signaller.class.mq5 deleted file mode 100644 index e240ea00..00000000 --- a/Documents/BKP/xcaea.signaller.class.mq5 +++ /dev/null @@ -1,878 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEASignaller ... -// Description: Class for XCAEA Signaller ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA Signaller" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.base.class.mq5" -#include "../../Classes/x-saherelm.x-cobject.class.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" -#include "../Classes/xcaea.x-poi.drawer.class.mq5" -#include "../Helpers/xcaea.helper.mq5" -#include "../Libraries/xcaea.signaller.lib.mq5" - -// -// Definitions ... - -class XCXCAEASignaller : XCBase -{ - // - // Public ... - public: - // - // Props ... - bool useGuards; - XCAEAInputs inputs; - XBarTracker barTraker; - XCXCAEAHelper *helper; - XCXCAEAPOIDrawer *drawer; - bool continuesRFTillTarget; - XBoxZone unAvailableBoxes[]; - XCXCAEAPOIDetector *detector; - XCAEAStrategyConditions mConditions; - XCAEAStrategyConditions mConditionsCollection[]; - - // - // Constructor ... - XCXCAEASignaller( - string _symbol, - ENUM_TIMEFRAMES _period // - ) - { - // - symbol = _symbol; - period = _period; - - // - Init(); - } - - // - // Deconstructor ... - ~XCXCAEASignaller() - { - DeInit(); - } - - // - // Properties ... - - string GetSymbol() - { - return symbol; - } - - ENUM_TIMEFRAMES GetPeriod() - { - return period; - } - - // - // Signaller Tools ... - - /** - * Detect Setup Conditions based on Signalling ... - * - * @param maxAllowedSLDistanceInPoint: int, Max Allowed SL Distance in Points (if Bigger thn Zero Provided) ... - * - * @return ( bool ) - */ - bool DetectSignalSetup( - double tpReward = 3, - double maxAllowedSLDistanceInPoint = 100 // - ) - { - // - bool result = false; - - // - // Check Bar Processing ... - if (!barTraker.CanProcessBar()) - { - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL pPBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - 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(); - - // - return result; - } - - // - // Setup Conditions ... - XBoxZone boxes[]; - XBoxZone pivotBox; - XBoxZone signalBox; - double additionalSL = 0; - XBoxZone bullishBoxes[]; - XBoxZone bearishBoxes[]; - bool hasSignalBox = false; - XCAEAConditions conditions; - ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; - - // - // Detecting Pivots ... - detector.Update( - zIndex // - ); - - // - // Validate Pivots ... - detector.Validate( - unAvailableBoxes, - zIndex // - ); - - // - // Draw Founded Pivots ... - drawer.Draw(cTime); - - // - // Retrieve Valid Boxes ... - - // - // Bullish ... - int bullishBoxesCount = - detector - .FillBullishBoxes(bullishBoxes); - - // - // Bearish ... - int bearishBoxesCount = - detector - .FillBearishBoxes(bearishBoxes); - - // - Copy( - bullishBoxes, - boxes, - false // - ); - Copy( - bearishBoxes, - boxes, - false // - ); - int boxesCount = ArraySize(boxes); - bool hasBoxes = IsValidSize(boxesCount); - - // - // Filter UnAvailable Boxes ... - if (hasBoxes) - { - // - // Remove UnAvailable Boxes ... - has = HasChild(unAvailableBoxes); - if (has) - { - // - count = ArraySize(unAvailableBoxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = unAvailableBoxes[i]; - - // - has = FindBoxIndex( - idx, - iBox, - boxes // - ); - if (has) - { - // - ArrayRemove( - boxes, - idx, - 1 // - ); - } - } - } - - // - hasBoxes = HasChild(boxes); - boxesCount = ArraySize(boxes); - } - - // - // - // - - // - // if (hasBoxes) - // { - // } - - // - // Detect Sinal Box ... - hasSignalBox = DetectXCAEAConditions( - boxes, - conditions, - pivotBox, - signalBox, - additionalSL, - signalBoxDir, - helper, - zIndex, - loopback // - ); - - // - // Make Pivot Box UnAvailable ... - if (pivotBox.IsValid()) - { - // - AddRef( - pivotBox, - unAvailableBoxes // - ); - } - - // - isBullish = hasSignalBox && - IsBullish(signalBoxDir); - - // - isBearish = hasSignalBox && - IsBearish(signalBoxDir); - - // - result = isBullish || - isBearish; - if (result) - { - // - // Do What we Want ... - barTraker.Waits(); - - // - // Draw Signal Box ... - XCBoxObject *iObj; - bool isCreated = helper.poiDrawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - mObjects.Add(iObj); - ZeroMemory(iObj); - - // - Print("Signal Box ..."); - } - - // - // Prepare Conditions ... - mConditions.symbol = symbol; - mConditions.period = period; - - // - double spread = GetSpread(symbol); - - // - double entry = - isBullish - ? signalBox.upper - : signalBox.lower; - - // - double sl = - isBullish - ? signalBox.lower - : signalBox.upper; - if (additionalSL > 0) - { - // - sl = - isBullish - ? sl - additionalSL - : sl + additionalSL; - } - - // - double risk = - isBullish - ? entry - sl - : sl - entry; - risk += spread; - if (risk >= maxAllowedSLDistanceInPoint * points) - { - // - // Fix Risk in Big Distances ... - double hh5 = zBar.FindHighest(5, MODE_HIGH); - double ll5 = zBar.FindLowest(5, MODE_LOW); - - // - double hhll5Delta = hh5 - ll5; - double riskDelta = hhll5Delta / 2; - risk = riskDelta; - } - - // - double rewardTP = risk * tpReward; - - // - double tp = - isBullish - ? entry + rewardTP - : entry - rewardTP; - - // - // Filling ... - mConditions.sl = sl; - mConditions.tp = tp; - mConditions.pivot = - isBullish - ? sl - : entry; - mConditions.point = - isBullish - ? entry - : sl; - mConditions.dir = signalBoxDir; - mConditions.provider = "XCAEA"; - mConditions.signalBox = signalBox; - mConditions.setupTime = zBar.time; - mConditions.conditions = conditions; - - // - // Select RF Rewards ... - if (continuesRFTillTarget) - { - // - double rfReward = 1; - while (rfReward < tpReward) - { - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - - // - rfReward++; - } - } - else - { - // - double rfReward = 1; - - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - } - } - - // - // Cleanup Resource ... - - // - Clean(boxes); - Clean(bullishBoxes); - Clean(bearishBoxes); - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - - // - pivotBox.Clean(); - signalBox.Clean(); - conditions.Clean(); - - // - return result; - } - - /** - * Detect Trigger Conditions for Specified Signal ... - * - * @param conditions: XCAEAStrategyConditions instance Reference, Specified Signal Conditions ... - * @param maxAllowedSetupAge: specified Setup Age for Expiration (if bigger than Zero) ... - * - * @return ( bool ) - */ - bool DetectSignalTrigger( - XCAEAStrategyConditions &conditions, - int maxAllowedSetupAge = 60 // - ) - { - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Check Signal Validation ... - // IMPORTANT: since all Validations done in SetUp Process ... - // here we only Execute Signal ... - - // - result = isBullish || - isBearish; - - // - if (result) - { - // - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - } - - // - // Cleanup ... - - // - return result; - } - - /** - * Detect Guards bsed on Signalling Class ... - * - * @param guards: XCAEAGuard instance Collection, Holds Provided Guards ... - * @param positions: XPosition instance Collection, Provides Signalling Based Positions for Apply Guards on them ... - * @param provider: X121SMCStrategySignalProviderData instance Reference, Specified Data for Cycles ... - * - * @return ( bool ) - */ - bool DetectGuards( - XCAEAGuard &guards[], - const XPosition &positions[] // - ) - { - // - bool result = false; - - // - return result; - } - - /** - * Add Conditions to Conditions Collection if not Exists ... - * - * @param maxAllowed: int, Specified Max Allowed Holding Conditions ... - * - * @return ( int ) - */ - int AddConditionsIfNotExists( - int maxAllowed = 10 // - ) - { - // - int result = 0; - - // - bool isSetuped = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(mConditionsCollection); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - XCAEAStrategyConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - XCAEAStrategyConditions iItem = tmpItems[i]; - - // - bool canRemove = mConditions.dir == iItem.dir && - mConditions.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - mConditionsCollection, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - mConditions, - mConditionsCollection // - ); - - // - // Remove Olds ... - CleanupArray( - mConditionsCollection, - maxAllowed // - ); - - // - result = ArraySize(mConditionsCollection); - - // - return result; - } - - // - // Protected ... - protected: - // - - // - // Private ... - private: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - CArrayObj mObjects; - CArrayObj mBarObjects; - - /** - * Initialize ... - */ - void Init() - { - // - useGuards = false; - continuesRFTillTarget = true; - - // - barTraker.Init( - symbol, - period // - ); - - // - inputs.Default(); - - // - // Configure Indicators ... - - // - // XCC ... - inputs.ccInputs.showCandles = true; - - // - // XCT ... - inputs.ctInputs.showCandleTime = true; - - // - // XCA ... - - // - inputs.caInputs.supResSmoothingLength = 7; - inputs.caInputs.supResSmoothingMode = X_MA_MODE_NONE; - - // - inputs.caInputs.showKI = true; - inputs.caInputs.showTKI = false; - inputs.caInputs.showSar = false; - inputs.caInputs.showVidya = true; - inputs.caInputs.showTrend = false; - inputs.caInputs.showSwings = false; - inputs.caInputs.showLongCycle = false; - inputs.caInputs.showHindCycle = false; - inputs.caInputs.showFiboLevel1 = false; - inputs.caInputs.showFiboLevel2 = false; - inputs.caInputs.showFiboLevel3 = false; - inputs.caInputs.showShortCycle = false; - inputs.caInputs.showMediumCycle = false; - inputs.caInputs.showPeaksAndVales = true; - inputs.caInputs.showPeakAndValeGolden = false; - inputs.caInputs.showSupportAndResistance = false; - - // - // XOSCS ... - // inputs.oscsInputs.rsiLength = 5; - // inputs.oscsInputs.cciLength = 5; - // inputs.oscsInputs.mfiLength = 5; - // inputs.oscsInputs.rviLength = 5; - - // - // Oscillators Views ... - inputs.showCCI = false; - inputs.showRSI = false; - inputs.showMFI = false; - inputs.showRVI = false; - inputs.showADX = false; - inputs.showMACD = false; - - // - // XCAEA Helper ... - helper = new XCXCAEAHelper(); - helper.Init( - symbol, - period, - inputs // - ); - - // - // Initialize and Configure Detector ... - detector = new XCXCAEAPOIDetector(helper); - - // - detector.detectSWHPivot = false; - detector.detectSWLPivot = false; - detector.detectPeakPivot = false; - detector.detectValePivot = false; - detector.detectRSIPeakPivot = true; - detector.detectRSIValePivot = true; - detector.detectCCIPeakPivot = true; - detector.detectCCIValePivot = true; - detector.detectKIBullishPivot = false; - detector.detectKIBearishPivot = false; - detector.detectFVGBullishPivot = true; - detector.detectFVGBearishPivot = true; - detector.detectPeakSWHResPivot = true; - detector.detectValeSWLSupPivot = true; - detector.detectTKIBullishPivot = false; - detector.detectCycleSameLLPivot = false; - detector.detectCycleSameHHPivot = false; - detector.detectTKIBearishPivot = false; - detector.detectTrendBullishPivot = false; - detector.detectTrendBearishPivot = false; - detector.detectTKITRNDBullishPivot = false; - detector.detectTKITRNDBearishPivot = false; - detector.detectRSICrossedOverOSPivot = false; - detector.detectRSICrossedUnderOBPivot = false; - detector.detectCCICrossedOverOSPivot = false; - detector.detectCCICrossedUnderOBPivot = false; - - // - // Initialize and Configure Drawer ... - drawer = new XCXCAEAPOIDrawer(detector); - - // - // UnActive Pivots ... - drawer.drawSWHPivots = false; - drawer.drawSWLPivots = false; - drawer.drawPeakPivots = false; - drawer.drawValePivots = false; - drawer.drawRSIPeakPivots = true; // true; - drawer.drawRSIValePivots = true; // true; - drawer.drawCCIPeakPivots = false; // true; - drawer.drawCCIValePivots = false; // true; - drawer.drawKIBullishPivots = false; - drawer.drawKIBearishPivots = false; - drawer.drawFVGBullishPivots = false; - drawer.drawFVGBearishPivots = false; - drawer.drawPeakSWHResPivots = false; // true; - drawer.drawValeSWLSupPivots = false; // true; - drawer.drawTKIBullishPivots = false; - drawer.drawTKIBearishPivots = false; - drawer.drawPVFVGBullishPivots = false; // true; - drawer.drawPVFVGBearishPivots = false; // true; - drawer.drawCycleSameLLPivots = false; - drawer.drawCycleSameHHPivots = false; - drawer.drawTrendBullishPivots = false; - drawer.drawTrendBearishPivots = false; - drawer.drawTKITRNDBullishPivots = false; - drawer.drawTKITRNDBearishPivots = false; - drawer.drawRSICrossedOverOSPivots = false; - drawer.drawRSICrossedUnderOBPivots = false; - drawer.drawCCICrossedOverOSPivots = false; - drawer.drawCCICrossedUnderOBPivots = false; - - // - drawer.drawTicks = false; - - // - // Configure Width ... - drawer.peakPivotWidth = 1; - drawer.valePivotWidth = 1; - drawer.ticksBullishWidth = 2; - drawer.ticksBearishWidth = 2; - drawer.fvgBullishPivotWidth = 1; - drawer.fvgBearishPivotWidth = 1; - drawer.oscsBullishPivotWidth = 2; - drawer.oscsBearishPivotWidth = 2; - - // - // Configure Colors ... - drawer.peakPivotColor = clrMagenta; - drawer.valePivotColor = clrAqua; - drawer.ticksBullishColor = clrYellow; - drawer.ticksBearishColor = clrOrange; - drawer.fvgBullishPivotColor = clrLime; - drawer.fvgBearishPivotColor = clrRed; - drawer.oscsBullishPivotColor = clrAqua; - drawer.oscsBearishPivotColor = clrMagenta; - - // - // Configure Style ... - drawer.peakPivotStyle = STYLE_SOLID; - drawer.valePivotStyle = STYLE_SOLID; - drawer.ticksBullishStyle = STYLE_DOT; - drawer.ticksBearishStyle = STYLE_DOT; - drawer.fvgBullishPivotStyle = STYLE_DASH; - drawer.fvgBearishPivotStyle = STYLE_DASH; - drawer.oscsBullishPivotStyle = STYLE_SOLID; - drawer.oscsBearishPivotStyle = STYLE_SOLID; - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - inputs.Clean(); - - // - ZeroMemory(drawer); - ZeroMemory(helper); - ZeroMemory(detector); - - // - mConditions.Clean(); - Clean(mConditionsCollection); - - // - mObjects.Clear(); - mBarObjects.Clear(); - - // - barTraker.Clean(); - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/xcaea.x-poi.detector.class.bkp.mq5 b/Documents/BKP/xcaea.x-poi.detector.class.bkp.mq5 deleted file mode 100644 index 7fc68ece..00000000 --- a/Documents/BKP/xcaea.x-poi.detector.class.bkp.mq5 +++ /dev/null @@ -1,4936 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEAPOIDetector ... -// Description: Class for XCAEA POI Detector ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA POI Detector" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Helpers/xcaea.helper.mq5" - -// -// Definitions ... - -// -enum ENUM_XCA_PIVOTS -{ - XCA_NONE, // None - XCA_TICK, // Tick - XCA_VOLUME, // Volume - XCA_FVG_BULL, // FVGBull - XCA_FVG_BEAR, // FVGBear - XCA_RSI_COOS, // RSICOOS - XCA_RSI_CUOB, // RSICUOB - XCA_RSI_PEAK, // RSIPeak - XCA_RSI_VALE, // RSIVale - XCA_CCI_COOS, // CCICOOS - XCA_CCI_CUOB, // CCICUOB - XCA_CCI_PEAK, // CCIPeak - XCA_CCI_VALE, // CCIVale - XCA_PEAKSWHRES, // PeakSWHRes - XCA_VALESWLSUP, // ValeSWLSup - XCA_TREND_BULL, // TrendBull - XCA_TREND_BEAR, // TrendBear -}; - -// -bool IsValid(ENUM_XCA_PIVOTS value) -{ - // - bool result = false; - - // - result = value != XCA_NONE; - - // - return result; -} - -// -string ToString(ENUM_XCA_PIVOTS value) -{ - // - string result = NULL; - - // - result = EnumToString(value); - - // - return result; -} - -// -ENUM_X_DIRECTION GetDirection(ENUM_XCA_PIVOTS value) -{ - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - switch (value) - { - // - case XCA_FVG_BULL: - case XCA_RSI_COOS: - case XCA_RSI_VALE: - case XCA_CCI_COOS: - case XCA_CCI_VALE: - case XCA_TREND_BULL: - case XCA_VALESWLSUP: - result = X_DIRECTION_BULLISH; - break; - - // - case XCA_FVG_BEAR: - case XCA_RSI_CUOB: - case XCA_RSI_PEAK: - case XCA_CCI_CUOB: - case XCA_CCI_PEAK: - case XCA_TREND_BEAR: - case XCA_PEAKSWHRES: - result = X_DIRECTION_BEARISH; - break; - } - - // - return result; -} - -// -string GetBoxType(ENUM_XCA_PIVOTS value) -{ - // - string result = NULL; - - // - switch (value) - { - // - case XCA_TICK: - case XCA_VOLUME: - case XCA_RSI_COOS: - case XCA_RSI_VALE: - case XCA_CCI_COOS: - case XCA_CCI_VALE: - case XCA_RSI_CUOB: - case XCA_RSI_PEAK: - case XCA_CCI_CUOB: - case XCA_CCI_PEAK: - case XCA_VALESWLSUP: - case XCA_PEAKSWHRES: - result = ToString(value); - break; - // - case XCA_FVG_BULL: - case XCA_FVG_BEAR: - result = "XCA_FVG"; - break; - - // - case XCA_TREND_BULL: - case XCA_TREND_BEAR: - result = "XCA_TREND"; - break; - } - - // - return result; -} - -// -ENUM_XCA_PIVOTS GetPivotType(XBoxZone &value) -{ - // - ENUM_XCA_PIVOTS result = XCA_NONE; - - // - bool has = value.IsValid(); - if (!has) - { - return result; - } - - // - bool isTick = value.type == GetBoxType(XCA_TICK); - bool isVolume = value.type == GetBoxType(XCA_VOLUME); - bool isFVGBull = value.type == GetBoxType(XCA_FVG_BULL) && - value.dir == GetDirection(XCA_FVG_BULL); - bool isFVGBear = value.type == GetBoxType(XCA_FVG_BEAR) && - value.dir == GetDirection(XCA_FVG_BEAR); - bool isRSIPeak = value.type == GetBoxType(XCA_RSI_PEAK) && - value.dir == GetDirection(XCA_RSI_PEAK); - bool isRSIVale = value.type == GetBoxType(XCA_RSI_VALE) && - value.dir == GetDirection(XCA_RSI_VALE); - bool isCCIPeak = value.type == GetBoxType(XCA_CCI_PEAK) && - value.dir == GetDirection(XCA_CCI_PEAK); - bool isCCIVale = value.type == GetBoxType(XCA_CCI_VALE) && - value.dir == GetDirection(XCA_CCI_VALE); - bool isRSICrossedOverOS = value.type == GetBoxType(XCA_RSI_COOS) && - value.dir == GetDirection(XCA_RSI_COOS); - bool isRSICrossedUnderOB = value.type == GetBoxType(XCA_RSI_CUOB) && - value.dir == GetDirection(XCA_RSI_CUOB); - bool isCCICrossedOverOS = value.type == GetBoxType(XCA_CCI_COOS) && - value.dir == GetDirection(XCA_CCI_COOS); - bool isCCICrossedUnderOB = value.type == GetBoxType(XCA_CCI_CUOB) && - value.dir == GetDirection(XCA_CCI_CUOB); - bool isTrendBullish = value.type == GetBoxType(XCA_TREND_BULL) && - value.dir == GetDirection(XCA_TREND_BULL); - bool isTrendBearish = value.type == GetBoxType(XCA_TREND_BEAR) && - value.dir == GetDirection(XCA_TREND_BEAR); - bool isPeakSWHRes = value.type == GetBoxType(XCA_PEAKSWHRES) && - value.dir == GetDirection(XCA_PEAKSWHRES); - bool isValeSWLSup = value.type == GetBoxType(XCA_VALESWLSUP) && - value.dir == GetDirection(XCA_VALESWLSUP); - - // - if (isTick) - { - result = XCA_TICK; - } - else if (isVolume) - { - result = XCA_VOLUME; - } - else if (isFVGBull) - { - result = XCA_FVG_BULL; - } - else if (isFVGBear) - { - result = XCA_FVG_BEAR; - } - else if (isRSIPeak) - { - result = XCA_RSI_PEAK; - } - else if (isRSIVale) - { - result = XCA_RSI_VALE; - } - else if (isCCIPeak) - { - result = XCA_CCI_PEAK; - } - else if (isCCIVale) - { - result = XCA_CCI_VALE; - } - else if (isRSICrossedOverOS) - { - result = XCA_RSI_COOS; - } - else if (isRSICrossedUnderOB) - { - result = XCA_RSI_CUOB; - } - else if (isCCICrossedOverOS) - { - result = XCA_CCI_COOS; - } - else if (isCCICrossedUnderOB) - { - result = XCA_CCI_CUOB; - } - else if (isTrendBullish) - { - result = XCA_TREND_BULL; - } - else if (isTrendBearish) - { - result = XCA_TREND_BEAR; - } - else if (isPeakSWHRes) - { - result = XCA_PEAKSWHRES; - } - else if (isValeSWLSup) - { - result = XCA_VALESWLSUP; - } - - // - return result; -} - -// -int ExtractPivots( - XBoxZone &extracted[], - ENUM_XCA_PIVOTS type, - XBoxZone &source[] // -) -{ - // - int result = 0; - - // - Clean(extracted); - - // - bool has = - IsValid(type) && - HasChild(source); - if (!has) - { - return result; - } - - // - int count = ArraySize(source); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = source[i]; - - // - ENUM_XCA_PIVOTS iType = GetPivotType(iBox); - - // - has = iType == type; - if (has) - { - // - AddRef( - iBox, - extracted // - ); - } - - // - iBox.Clean(); - } - - // - result = ArraySize(extracted); - - // - return result; -} - -// -struct XCAPivot -{ - // - // Props ... - datetime to; - double value; - string symbol; - datetime from; - double reserve; - ENUM_XCA_PIVOTS type; - ENUM_TIMEFRAMES period; - - // - double values[]; - - // - // Constructor ... - XCAPivot() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - value = 0; - to = NULL; - reserve = 0; - from = NULL; - symbol = NULL; - period = NULL; - type = XCA_NONE; - - // - Clean(values); - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - from < to && - value != 0 && - IsValid(to) && - IsValid(from) && - IsValid(type) && - IsValid(symbol) && - IsValid(period); - - // - return result; - } - - /** - * Check a Model is Same as this or not ... - * - * @param pivot: XCAPivot ... - * - * @return ( bool ) - */ - bool IsSameAs(XCAPivot &pivot) - { - // - bool result = false; - - // - result = - IsValid() && - pivot.IsValid(); - if (!result) - { - return result; - } - - // - result = - to == pivot.to && - from == pivot.from && - type == pivot.type && - value == pivot.value && - symbol == pivot.symbol && - period == pivot.period; - - // - return result; - } - - /** - * Retrieve To Index ... - * - * @param forPeriod: ENUM_TIMEFRAMES, Specified Period ... - * - * @return ( int ) - */ - int ToIndex( - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = GetBarIndex( - symbol, - forPeriod, - to // - ); - - // - return result; - } - - /** - * Retrieve From Index ... - * - * @param forPeriod: ENUM_TIMEFRAMES, Specified Period ... - * - * @return ( int ) - */ - int FromIndex( - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = GetBarIndex( - symbol, - forPeriod, - from // - ); - - // - return result; - } - - /** - * Retrieve Age of Pivot ... - * - * @param forPeriod: ENUM_TIMEFRAMES, Specified Period ... - * - * @return ( int ) - */ - int GetAge( - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - int toIDX = ToIndex(forPeriod); - int fromIDX = FromIndex(forPeriod); - - // - result = fromIDX - toIDX; - - // - return result; - } - - /** - * Converts Pivot to Box ... - * - * @param box: XBoxZone instance reference ... - * - * @return ( bool ) - */ - bool AsBox( - XBoxZone &box // - ) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir = GetDirection(type); - - // - result = HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = - IsBullish(iDir) && - value < reserve; - - // - bool isBearish = - IsBearish(iDir) && - value > reserve; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - box.to = to; - box.dir = iDir; - box.from = from; - box.symbol = symbol; - box.period = period; - - // - string typeStr = GetBoxType(type); - box.type = typeStr; - - // - box.upper = - isBullish - ? reserve - : value; - box.lower = - isBullish - ? value - : reserve; - - // - result = box.IsValid(); - if (!result) - { - box.Clean(); - } - - // - return result; - } - - // -}; - -// -struct XCATRENDFVG -{ - // - XBoxZone trend; - XBoxZone fvgs[]; - - // - XCATRENDFVG() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - Clean(fvgs); - trend.Clean(); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = trend.IsValid(); - - // - return result; - } - - // - void AddFVG(XBoxZone &fvg) - { - // - bool has = trend.IsValid() && - fvg.IsValid() && - fvg.dir == trend.dir; - if (!has) - { - return; - } - - // - int idx = -1; - has = FindBoxIndex( - idx, - fvg, - fvgs // - ); - if (has) - { - return; - } - - // - AddRef( - fvg, - fvgs // - ); - } - - // - bool IsBullish() - { - return IsValid() && - trend.IsBullish(); - } - - // - bool IsBearish() - { - return IsValid() && - trend.IsBearish(); - } - - // - bool GetSelectedFVG(XBoxZone &fvg) - { - // - bool result = false; - - // - fvg.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - if (IsBullish()) - { - idx = GetLowest(fvgs); - } - else if (IsBearish()) - { - idx = GetHighest(fvgs); - } - result = IsValidIndex(idx); - if (!result) - { - return result; - } - - // - fvg = fvgs[idx]; - - // - result = fvg.IsValid(); - - // - return result; - } - - // -}; - -// -int ExtractTrendFVGs( - XBoxZone &extracteds[], - XBoxZone &trend, - XBoxZone &fvgs[] // -) -{ - // - int result = 0; - - // - Clean(extracteds); - - // - bool has = HasChild(fvgs) && - trend.IsValid(); - if (!has) - { - return result; - } - - // - // Check Trend Box Pivot is Valid Trend ... - ENUM_XCA_PIVOTS iType = GetPivotType(trend); - has = iType == XCA_TREND_BULL || - iType == XCA_TREND_BEAR; - if (!has) - { - return result; - } - - // - int count = ArraySize(fvgs); - for (int i = 0; i < count; i++) - { - // - XBoxZone iFVG = fvgs[i]; - - // - bool isDirPassed = iFVG.dir == trend.dir; - bool isPricePassed = iFVG.upper <= trend.upper && - iFVG.lower >= trend.lower; - bool isFromPassed = iFVG.from > trend.from; - has = - isDirPassed && - isFromPassed && - isPricePassed; - if (has) - { - // - AddRef( - iFVG, - extracteds // - ); - } - - // - iFVG.Clean(); - } - - // - result = ArraySize(extracteds); - - // - return result; -} - -// -int ExtractTrendPivots( - XCATRENDFVG &items[], - XBoxZone &boxes[] // -) -{ - // - int result = 0; - - // - Clean(items); - - // - bool has = HasChild(boxes); - if (!has) - { - return result; - } - - // - // Extract Trend Boxes ... - XBoxZone tmp[]; - XBoxZone trendBoxes[]; - ExtractPivots( - tmp, - XCA_TREND_BULL, - boxes // - ); - Copy( - tmp, - trendBoxes, - false // - ); - Clean(tmp); - ExtractPivots( - tmp, - XCA_TREND_BEAR, - boxes // - ); - Copy( - tmp, - trendBoxes, - false // - ); - Clean(tmp); - - // - // Check Trend Boxes Exists ... - has = HasChild(trendBoxes); - if (!has) - { - // - Clean(trendBoxes); - return result; - } - - // - // Extract FVG Boxes ... - XBoxZone fvgBoxes[]; - - // - ExtractPivots( - tmp, - XCA_FVG_BULL, - boxes // - ); - Copy( - tmp, - fvgBoxes, - false // - ); - Clean(tmp); - ExtractPivots( - tmp, - XCA_FVG_BEAR, - boxes // - ); - Copy( - tmp, - fvgBoxes, - false // - ); - Clean(tmp); - bool hasFVGs = HasChild(fvgBoxes); - int fvgsCount = ArraySize(fvgBoxes); - - // - // Loop through Trend Boxes to Extract XCATRENDFVG Models ... - int count = ArraySize(trendBoxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iTrendBox = trendBoxes[i]; - - // - XCATRENDFVG iTrendFVG; - iTrendFVG.trend = iTrendBox; - - // - XBoxZone fvgs[]; - if (hasFVGs) - { - // - int fvgsCount = ExtractTrendFVGs( - fvgs, - iTrendBox, - fvgBoxes // - ); - - // - Copy( - fvgs, - iTrendFVG.fvgs // - ); - } - - // - has = iTrendFVG.IsValid(); - if (has) - { - // - AddRef( - iTrendFVG, - items // - ); - } - - // - iTrendBox.Clean(); - iTrendFVG.Clean(); - } - - // - Clean(tmp); - Clean(fvgBoxes); - Clean(trendBoxes); - - // - result = ArraySize(items); - - // - return result; -} - -// -int GetOldest(XCATRENDFVG &items[]) -{ - // - int result = -1; - - // - bool has = HasChild(items); - if (!has) - { - return result; - } - - // - XCATRENDFVG item; - int count = ArraySize(items); - for (int i = 0; i < count; i++) - { - // - XCATRENDFVG iTrendFVG = items[i]; - - // - bool canSet = - !item.IsValid() - ? true - : item.trend.from > iTrendFVG.trend.from; - if (canSet) - { - // - result = i; - item = iTrendFVG; - } - - // - iTrendFVG.Clean(); - } - - // - has = IsValidIndex(result); - item.Clean(); - - // - return result; -} - -// -// Implementations ... -class XCXCAEAPOIDetector : public XCBase -{ - // - // Public ... - public: - // - // Props ... - - // - // Pivot Verifications and Max Allowed Holding Items ... - int maxAllowedPivots; // Max Allowed Holding Pibots ... - int pivotVerifications; // Pivots Verifications ... - int pivotDetectionLoopbac; // Pivots Detection Loopback ... - double ticksDividerInPoints; // Ticks and Volume Detection Divider in Point ... - ENUM_TIMEFRAMES ticksDetectionPerid; // Ticks and Volume Detection Loopback ... - - // - // FVG Validations ... - int maxAllowedFVGsAge; - bool validateFVGsUsingPV; - bool validateFVGsUsingMANALYSER; - - // - // TREND ... - XBoxZone trendPivotP; // Prev Pivot of Market Trend ... - XBoxZone trendPivotC; // Current Pivot of Market Trend ... - ENUM_X_DIRECTION trendDir; // Trend Direction ... - - // - // Breaked Pivots ... - XBoxZone invalidPivots[]; - - // - // TICK Pivots ... - - // - bool detectTickPivots; - XBoxZone tickPivots[]; - - // - // VOLUME Pivots ... - - // - bool detectVolumePivots; - XBoxZone volumePivots[]; - - // - // RSI Peak Pivot ... - - // - bool detectRSIPeakPivots; - XBoxZone rsiPeakPivots[]; - bool newRSIPeakPivotDetected; - - // - // RSI Vale Pivot ... - - // - bool detectRSIValePivots; - XBoxZone rsiValePivots[]; - bool newRSIValePivotDetected; - - // - // CCI Peak Pivot ... - - // - bool detectCCIPeakPivots; - XBoxZone cciPeakPivots[]; - bool newCCIPeakPivotDetected; - - // - // CCI Vale Pivot ... - - // - bool detectCCIValePivots; - XBoxZone cciValePivots[]; - bool newCCIValePivotDetected; - - // - // FVG Bullish Pivots ... - - // - bool detectFVGBullishPivots; - XBoxZone fvgBullishPivots[]; - bool newFVGBullishPivotDetected; - - // - // FVG Bearish Pivots ... - - // - bool detectFVGBearishPivots; - XBoxZone fvgBearishPivots[]; - bool newFVGBearishPivotDetected; - - // - // VALE Pivot Support Swing Low ... - - // - XCAPivot valeSupSWLPivot; - bool detectValeSupSWLPivots; - XBoxZone valeSupSWLPivots[]; - bool newValeSupSWLPivotDetected; - - // - // PEAK Pivot Resistance Swing High ... - - // - XCAPivot peakResSWHPivot; - bool detectPeakResSWHPivots; - XBoxZone peakResSWHPivots[]; - bool newPeakResSWHPivotDetected; - - // - // TREND Bullish ... - - // - XCAPivot trendBullishPivot; - XBoxZone trendBullishFVGs[]; - bool detectTrendBullishPivots; - XCATRENDFVG trendBullishPivots[]; - bool newTrendBullishPivotDetected; - - // - // TREND Bearish ... - - // - XCAPivot trendBearishPivot; - XBoxZone trendBearishFVGs[]; - bool detectTrendBearishPivots; - XCATRENDFVG trendBearishPivots[]; - bool newTrendBearishPivotDetected; - - // - // RSI Crossed Over OS Pivot ... - - // - bool detectRSICrossedOverOSPivots; - XBoxZone rsiCrossedOverOSPivots[]; - bool newRSICrossedOverOSPivotDetected; - - // - // RSI Crossed Under OB Pivot ... - - // - bool detectRSICrossedUnderOBPivots; - XBoxZone rsiCrossedUnderOBPivots[]; - bool newRSICrossedUnderOBPivotDetected; - - // - // CCI Crossed Over OS Pivot ... - - // - bool detectCCICrossedOverOSPivots; - XBoxZone cciCrossedOverOSPivots[]; - bool newCCICrossedOverOSPivotDetected; - - // - // CCI Crossed Under OB Pivot ... - - // - bool detectCCICrossedUnderOBPivots; - XBoxZone cciCrossedUnderOBPivots[]; - bool newCCICrossedUnderOBPivotDetected; - - // - // Constructors ... - XCXCAEAPOIDetector( - XCXCAEAHelper *_helper // - ) - { - // - helper = _helper; - drawer = new XCPOIDrawer(); - barAnalyser = new XCBarAnalyser(); - - // - Default(); - } - - // - // De Constructors ... - ~XCXCAEAPOIDetector() - { - // - valeSupSWLPivot.Clean(); - peakResSWHPivot.Clean(); - - // - Clean(trendBullishFVGs); - trendBullishPivot.Clean(); - - // - Clean(trendBearishFVGs); - trendBearishPivot.Clean(); - - // - trendPivotP.Clean(); - trendPivotC.Clean(); - trendDir = X_DIRECTION_NONE; - - // - CleanPivots(); - - // - ZeroMemory(helper); - ZeroMemory(drawer); - ZeroMemory(barAnalyser); - } - - // - // Properties ... - - // - // Tools ... - - // - virtual void Default() - { - // - maxAllowedPivots = 50; - pivotVerifications = 5; - ticksDividerInPoints = 15; - pivotDetectionLoopbac = 100; - ticksDetectionPerid = PERIOD_D1; - - // - maxAllowedFVGsAge = 0; - validateFVGsUsingPV = false; - validateFVGsUsingMANALYSER = false; - - // - detectTickPivots = true; - detectVolumePivots = true; - detectRSIPeakPivots = true; - detectRSIValePivots = true; - detectCCIPeakPivots = true; - detectCCIValePivots = true; - detectFVGBullishPivots = true; - detectFVGBearishPivots = true; - detectValeSupSWLPivots = true; - detectPeakResSWHPivots = true; - detectTrendBullishPivots = true; - detectTrendBearishPivots = true; - detectRSICrossedOverOSPivots = true; - detectRSICrossedUnderOBPivots = true; - detectCCICrossedOverOSPivots = true; - detectCCICrossedUnderOBPivots = true; - - // - trendDir = X_DIRECTION_NONE; - } - - // - void Update( - int barIndex = 0 // - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int loopback = pivotDetectionLoopbac; - loopback = NormalizeInt(loopback, 50); - - // - int idx = -1; - int count = 0; - bool has = false; - - // - newRSIPeakPivotDetected = false; - newRSIValePivotDetected = false; - newCCIPeakPivotDetected = false; - newCCIValePivotDetected = false; - newFVGBullishPivotDetected = false; - newFVGBearishPivotDetected = false; - newValeSupSWLPivotDetected = false; - newPeakResSWHPivotDetected = false; - newTrendBullishPivotDetected = false; - newTrendBearishPivotDetected = false; - newRSICrossedOverOSPivotDetected = false; - newRSICrossedUnderOBPivotDetected = false; - newCCICrossedOverOSPivotDetected = false; - newCCICrossedUnderOBPivotDetected = false; - - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - - // - int index = barIndex; - int start = index; - int end = index + loopback; - while (start < end) - { - // - // Retrieve Conditions ... - XCAEAConditions conditions; - has = helper.GetConditions( - conditions, - start, - 10 // - ); - if (!has) - { - conditions.Clean(); - continue; - } - - // - // Retrieve Bars ... - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - has = zBar.Init( - conditions.symbol, - conditions.period, - start // - ); - has = - has && - zBar.GetPreviousBar(cBar); - has = - has && - cBar.GetPreviousBar(pBar); - has = - has && - pBar.GetPreviousBar(p2Bar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - conditions.Clean(); - - // - continue; - } - - // - // Bars Conditions ... - - // - // Bars Conditions ... - - // - ENUM_X_DIRECTION cBarDir; - - // - // Hammer ... - bool isCBarHammer = helper - .barAnalyser - .IsHammer( - cBar, - cBarDir // - ); - bool isCBarBullishHammer = - isCBarHammer && - IsBullish(cBarDir); - bool isCBarBearishHammer = - isCBarHammer && - IsBearish(cBarDir); - - // - // Rejected ... - bool isCBarRejected = helper - .barAnalyser - .IsRejected( - cBar, - cBarDir, - false, // Force Type ... - true // Force Fibo Pressure ... - ); - bool isCBarBullishRejected = - isCBarRejected && - IsBullish(cBarDir); - bool isCBarBearishRejected = - isCBarRejected && - IsBearish(cBarDir); - - // - // Engulfed ... - bool isCBarEngulfed = helper - .barAnalyser - .IsEngulfed( - cBar, - cBarDir // - ); - bool isCBarBullishEngulfed = - isCBarEngulfed && - IsBullish(cBarDir); - bool isCBarBearishEngulfed = - isCBarEngulfed && - IsBearish(cBarDir); - - // - // Momentum ... - bool isCBarMomentum = helper - .barAnalyser - .IsMomentum( - cBar, - cBarDir, - 1 // - ); - bool isCBarBullishMomentum = - isCBarMomentum && - IsBullish(cBarDir); - bool isCBarBearishMomentum = - isCBarMomentum && - IsBearish(cBarDir); - - // - // FVG ... - - // - XBoxZone fvgBox; - bool isFVG = barAnalyser.IsFVG( - cBar, - fvgBox // - ); - bool isBullishFVG = - isFVG && - fvgBox.IsBullish(); - bool isBearishFVG = - isFVG && - fvgBox.IsBearish(); - - // - bool isCBarHasBullishPower = isBullishFVG || - isCBarBullishRejected || - isCBarBullishEngulfed || - isCBarBullishMomentum; - - // - bool isCBarHasBearishPower = isBearishFVG || - isCBarBearishRejected || - isCBarBearishEngulfed || - isCBarBearishMomentum; - - // - // Reading Values from Conditions and - // Create Customized Conditions if required ... - - // - // PEAK ... - double zPeak = conditions.peakBuffer[zIDX]; - double cPeak = conditions.peakBuffer[cIDX]; - double pPeak = conditions.peakBuffer[pIDX]; - double p2Peak = conditions.peakBuffer[p2IDX]; - - // - // VALE ... - double zVale = conditions.valeBuffer[zIDX]; - double cVale = conditions.valeBuffer[cIDX]; - double pVale = conditions.valeBuffer[pIDX]; - double p2Vale = conditions.valeBuffer[p2IDX]; - - // - // MANALYSER ... - - // - // MAH ... - double zMAH = conditions.mahBuffer[zIDX]; - double cMAH = conditions.mahBuffer[cIDX]; - double pMAH = conditions.mahBuffer[pIDX]; - double p2MAH = conditions.mahBuffer[p2IDX]; - - // - // MAL ... - double zMAL = conditions.malBuffer[zIDX]; - double cMAL = conditions.malBuffer[cIDX]; - double pMAL = conditions.malBuffer[pIDX]; - double p2MAL = conditions.malBuffer[p2IDX]; - - // - // MAC ... - double zMAC = conditions.macBuffer[zIDX]; - double cMAC = conditions.macBuffer[cIDX]; - double pMAC = conditions.macBuffer[pIDX]; - double p2MAC = conditions.macBuffer[p2IDX]; - - // - // RSI ... - - // - double zRSI = conditions.rsiBuffer[zIDX]; - double cRSI = conditions.rsiBuffer[cIDX]; - double pRSI = conditions.rsiBuffer[pIDX]; - double p2RSI = conditions.rsiBuffer[p2IDX]; - - // - bool isRSIPeak = - pRSI > cRSI && - pRSI > p2RSI && - pRSI > zRSI; - - // - bool isRSIVale = - pRSI < cRSI && - pRSI < p2RSI && - pRSI < zRSI; - - // - // CCI ... - - // - double zCCI = conditions.cciBuffer[zIDX]; - double cCCI = conditions.cciBuffer[cIDX]; - double pCCI = conditions.cciBuffer[pIDX]; - double p2CCI = conditions.cciBuffer[p2IDX]; - - // - bool isCCIPeak = - pCCI > cCCI && - pCCI > p2CCI && - pCCI > zCCI; - - // - bool isCCIVale = - pCCI < cCCI && - pCCI < p2CCI && - pCCI < zCCI; - - // - // ATR ... - double zATR = conditions.atrBuffer[zIDX]; - double cATR = conditions.atrBuffer[cIDX]; - double pATR = conditions.atrBuffer[pIDX]; - double p2ATR = conditions.atrBuffer[p2IDX]; - - // - double atrSum = GetSum(conditions.atrBuffer); - double atrMax = GetMax(conditions.atrBuffer); - double atrMin = GetMin(conditions.atrBuffer); - double atrAvg = GetAverage(conditions.atrBuffer); - - // - // Extracting Required Data about Trending ... - - // - double zFast = conditions.fastBuffer[zIDX]; - double cFast = conditions.fastBuffer[cIDX]; - double pFast = conditions.fastBuffer[pIDX]; - double p2Fast = conditions.fastBuffer[p2IDX]; - - // - double zMedium = conditions.mediumBuffer[zIDX]; - double cMedium = conditions.mediumBuffer[cIDX]; - double pMedium = conditions.mediumBuffer[pIDX]; - double p2Medium = conditions.mediumBuffer[p2IDX]; - - // - double zSlow = conditions.slowBuffer[zIDX]; - double cSlow = conditions.slowBuffer[cIDX]; - double pSlow = conditions.slowBuffer[pIDX]; - double p2Slow = conditions.slowBuffer[p2IDX]; - - // - double z3Mas[] = { - zFast, - zMedium, - zSlow, - }; - double z3MasMin = GetMin(z3Mas); - double z3MasMax = GetMax(z3Mas); - - // - double c3Mas[] = { - cFast, - cMedium, - cSlow, - }; - double c3MasMin = GetMin(c3Mas); - double c3MasMax = GetMax(c3Mas); - - // - double p3Mas[] = { - pFast, - pMedium, - pSlow, - }; - double p3MasMin = GetMin(p3Mas); - double p3MasMax = GetMax(p3Mas); - - // - double p23Mas[] = { - p2Fast, - p2Medium, - p2Slow, - }; - double p23MasMin = GetMin(p23Mas); - double p23MasMax = GetMax(p23Mas); - - // - // Try to Custom Mechanism for Trend Detection ... - - // - bool is3MaBullish = - cFast > cSlow && - cMedium > cSlow; - bool is3MaBullishPrev = - pFast > pSlow && - pMedium > pSlow; - - // - bool is3MaBearish = - cFast < cSlow && - cMedium < cSlow; - bool is3MaBearishPrev = - pFast < pSlow && - pMedium < pSlow; - - // - bool is3MaSwitchedToBullish = is3MaBullish && - !is3MaBullishPrev; - bool is3MaSwitchedToBearish = is3MaBearish && - !is3MaBearishPrev; - - // - bool is3MaFinishedFromBullish = !is3MaBullish && - is3MaBullishPrev; - bool is3MaFinishedFromBearish = !is3MaBearish && - is3MaBearishPrev; - - // - // TREND BULLISH Conditions ... - - // - bool trendBullishStartPivotCondition = - // - // One ... - // conditions.is3MaFinishedFromBullish - // // - // || - // - // Two ... - is3MaFinishedFromBullish - // - ; - - // - bool trendBullishPivotContinuationCondition = - // - // One ... - // conditions.is3MaBullish - // // - // || - // - // Two ... - is3MaBullish - // - ; - - // - bool trendBullisPivothFinishedCondition = - // - // One ... - // conditions.is3MaSwitchedToBullish - // // - // || - // - // Two ... - is3MaSwitchedToBullish - // - ; - - // - // TREND BEARISH Conditions ... - - // - bool trendBearishStartPivotCondition = - // - // One ... - // conditions.is3MaFinishedFromBearish - // // - // || - // - // Two ... - is3MaFinishedFromBearish - // - ; - - // - bool trendBearishPivotContinuationCondition = - // - // One ... - // conditions.is3MaBearish - // // - // || - // - // Two ... - is3MaBearish - // - ; - - // - bool trendBearishivothFinishedCondition = - // - // One ... - // conditions.is3MaSwitchedToBearish - // // - // || - // - // Two ... - is3MaSwitchedToBearish - // - ; - - // - // Checking Pivots ... - - // - // Detect TICK and VOLUME Pivots ... - if (detectTickPivots || detectVolumePivots) - { - // - XOHCL ticksToBar; - XOHCL ticksFromBar; - XCTicksZone *ticksZone = NULL; - - // - datetime ticksTo = GetPeriodStartTime( - zBar.symbol, - ticksDetectionPerid, - zBar.time // - ); - bool isTicksBarInited = ticksToBar.Init( - zBar.symbol, - zBar.period, - ticksTo // - ); - datetime ticksFrom = ticksTo - PeriodSeconds(ticksDetectionPerid); - isTicksBarInited = isTicksBarInited && - ticksFromBar.Init( - zBar.symbol, - zBar.period, - ticksFrom // - ); - bool hasValidTicksTimeRange = IsValid(ticksTo) && - isTicksBarInited && - IsValid(ticksFrom) && - ticksFrom < ticksTo; - - // - bool isTickPivotExists = - hasValidTicksTimeRange && - IsExistsTickPivot( - ticksTo, - ticksFrom // - ); - - // - bool isVolumePivotExists = - hasValidTicksTimeRange && - IsExistsVolumePivot( - ticksTo, - ticksFrom // - ); - - // - bool isInitializedZone = !isTickPivotExists || - !isVolumePivotExists; - if (isInitializedZone) - { - // - isInitializedZone = InitializeTicksZone( - ticksZone, - ticksToBar, - ticksFromBar // - ); - } - - // - // TICK Pivots ... - if (detectTickPivots) - { - // - // Check Current Zone Exists or Not ... - if (isInitializedZone && !isTickPivotExists) - { - // - XBoxZone iBox; - XCTickZone *iZone; - has = ticksZone.GetMaxTickZone(iZone); - if (has) - { - // - // Try to Converts a Tick Zone to XBoxZone ... - iBox.to = ticksTo; - iBox.from = ticksFrom; - iBox.lower = iZone.low; - iBox.upper = iZone.high; - iBox.symbol = iZone.symbol; - iBox.period = iZone.period; - iBox.type = GetBoxType(XCA_TICK); - iBox.dir = X_DIRECTION_BULLISH; // Temparory ... - - // - has = iBox.IsValid(); - if (has) - { - // - AddBox( - iBox, - tickPivots // - ); - } - } - - // - iBox.Clean(); - ZeroMemory(iZone); - } - } - - // - // VOLUME Pivots ... - if (detectVolumePivots) - { - // - // Check Current Zone Exists or Not ... - if (isInitializedZone && !isVolumePivotExists) - { - // - XBoxZone iBox; - XCTickZone *iZone; - has = ticksZone.GetMaxVolumeZone(iZone); - if (has) - { - // - // Try to Converts a Tick Zone to XBoxZone ... - iBox.to = ticksTo; - iBox.from = ticksFrom; - iBox.lower = iZone.low; - iBox.upper = iZone.high; - iBox.symbol = iZone.symbol; - iBox.period = iZone.period; - iBox.type = GetBoxType(XCA_VOLUME); - iBox.dir = X_DIRECTION_BULLISH; // Temparory ... - - // - has = iBox.IsValid(); - if (has) - { - // - AddBox( - iBox, - volumePivots // - ); - } - } - - // - iBox.Clean(); - ZeroMemory(iZone); - } - } - - // - ticksToBar.Clean(); - ticksFromBar.Clean(); - ZeroMemory(ticksZone); - - // - } - - // - // RSI Peak Pivot ... - if (detectRSIPeakPivots) - { - // - bool checkingCondition = - isRSIPeak && - isCBarHasBearishPower // && - // conditions.isRSICrossedUnderOB - ; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_RSI_PEAK; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMin(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newRSIPeakPivotDetected = AddBox( - iBox, - rsiPeakPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // RSI Vale Pivot ... - if (detectRSIValePivots) - { - // - bool checkingCondition = - isRSIVale && - isCBarHasBullishPower // && - // conditions.isRSICrossedOverOS - ; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.low; - iPivot.type = XCA_RSI_VALE; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMax(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newRSIValePivotDetected = AddBox( - iBox, - rsiValePivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // CCI Peak Pivot ... - if (detectCCIPeakPivots) - { - // - bool checkingCondition = - isCCIPeak && - isCBarHasBearishPower // && - // conditions.isCCICrossedUnderOB - ; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_CCI_PEAK; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMin(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newCCIPeakPivotDetected = AddBox( - iBox, - cciPeakPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // CCI Vale Pivot ... - if (detectCCIValePivots) - { - // - bool checkingCondition = - isCCIVale && - isCBarHasBullishPower // && - // conditions.isCCICrossedOverOS - ; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.low; - iPivot.type = XCA_CCI_VALE; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMax(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newCCIValePivotDetected = AddBox( - iBox, - cciValePivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // FVG Bullish ... - if (detectFVGBullishPivots) - { - // - bool checkingCondition = - // - isBullishFVG && - // - fvgBox.upper < cMAL - // - // (cPeak > pPeak || - // pPeak > p2Peak) - // - ; - - // - if (checkingCondition) - { - // - XBoxZone iBox; - XCAPivot iPivot; - - // - iPivot.to = fvgBox.to; - iPivot.from = fvgBox.from; - iPivot.type = XCA_FVG_BULL; - iPivot.value = fvgBox.lower; - iPivot.reserve = fvgBox.upper; - iPivot.symbol = fvgBox.symbol; - iPivot.period = fvgBox.period; - - // - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newFVGBullishPivotDetected = AddBox( - iBox, - fvgBullishPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // FVG Bearish ... - if (detectFVGBearishPivots) - { - // - bool checkingCondition = - // - isBearishFVG && - // - fvgBox.lower > cMAH - // - // (cVale < pVale || - // pVale < p2Vale) - // - ; - - // - if (checkingCondition) - { - // - XBoxZone iBox; - XCAPivot iPivot; - - // - iPivot.to = fvgBox.to; - iPivot.from = fvgBox.from; - iPivot.type = XCA_FVG_BEAR; - iPivot.value = fvgBox.upper; - iPivot.reserve = fvgBox.lower; - iPivot.symbol = fvgBox.symbol; - iPivot.period = fvgBox.period; - - // - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newFVGBearishPivotDetected = AddBox( - iBox, - fvgBearishPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // VALE Pivot Support Swing Low ... - if (detectValeSupSWLPivots) - { - // - if (conditions.isValeFinishedFromPivot) - { - // - valeSupSWLPivot.Clean(); - - // - valeSupSWLPivot.type = XCA_VALESWLSUP; - valeSupSWLPivot.symbol = conditions.symbol; - valeSupSWLPivot.period = conditions.period; - - // - valeSupSWLPivot.to = pBar.time; - valeSupSWLPivot.from = pBar.time; - valeSupSWLPivot.value = conditions.valeBuffer[pIDX]; - valeSupSWLPivot.reserve = conditions.valeGoldenBuffer[pIDX]; - } - - // - if (conditions.isValeIsPivot) - { - // - valeSupSWLPivot.from = pBar.time; - - // - valeSupSWLPivot.reserve = - valeSupSWLPivot.reserve == 0 - ? conditions.valeGoldenBuffer[cIDX] - : MathMin(valeSupSWLPivot.reserve, conditions.valeGoldenBuffer[cIDX]); - } - - // - if (conditions.isValeSwitchedToPivot) - { - // - has = - valeSupSWLPivot.IsValid() && - valeSupSWLPivot.GetAge() >= pivotVerifications; - if (has) - { - // - XBoxZone iBox; - has = valeSupSWLPivot.AsBox(iBox); - if (has) - { - // - newValeSupSWLPivotDetected = AddBox( - iBox, - valeSupSWLPivots // - ); - } - - // - iBox.Clean(); - } - - // - valeSupSWLPivot.Clean(); - } - } - - // - // PEAK Pivot Resistance Swing High ... - if (detectPeakResSWHPivots) - { - // - if (conditions.isPeakFinishedFromPivot) - { - // - peakResSWHPivot.Clean(); - - // - peakResSWHPivot.type = XCA_PEAKSWHRES; - peakResSWHPivot.symbol = conditions.symbol; - peakResSWHPivot.period = conditions.period; - - // - peakResSWHPivot.to = pBar.time; - peakResSWHPivot.from = pBar.time; - peakResSWHPivot.value = conditions.peakBuffer[pIDX]; - peakResSWHPivot.reserve = conditions.peakGoldenBuffer[pIDX]; - } - - // - if (conditions.isPeakIsPivot) - { - // - peakResSWHPivot.from = pBar.time; - - // - peakResSWHPivot.reserve = - peakResSWHPivot.reserve == 0 - ? conditions.peakGoldenBuffer[cIDX] - : MathMax(peakResSWHPivot.reserve, conditions.peakGoldenBuffer[cIDX]); - } - - // - if (conditions.isPeakSwitchedToPivot) - { - // - has = - peakResSWHPivot.IsValid() && - peakResSWHPivot.GetAge() >= pivotVerifications; - if (has) - { - // - XBoxZone iBox; - has = peakResSWHPivot.AsBox(iBox); - if (has) - { - // - newPeakResSWHPivotDetected = AddBox( - iBox, - peakResSWHPivots // - ); - } - - // - iBox.Clean(); - } - - // - peakResSWHPivot.Clean(); - } - } - - // - // TREND Bullish ... - if (detectTrendBullishPivots) - { - // - if (trendBullishStartPivotCondition) - { - // - Clean(trendBullishFVGs); - trendBullishPivot.Clean(); - - // - trendBullishPivot.type = XCA_TREND_BULL; - trendBullishPivot.symbol = conditions.symbol; - trendBullishPivot.period = conditions.period; - - // - trendBullishPivot.to = pBar.time; - trendBullishPivot.from = pBar.time; - trendBullishPivot.value = p3MasMin; - trendBullishPivot.reserve = p3MasMax; - } - - // - if (trendBullishPivotContinuationCondition) - { - // - trendBullishPivot.from = pBar.time; - - // - Add( - p3MasMin, - trendBullishPivot.values // - ); - Add( - p3MasMax, - trendBullishPivot.values // - ); - - // - trendBullishPivot.reserve = - trendBullishPivot.reserve == 0 - ? p3MasMax - : MathMax(trendBullishPivot.reserve, p3MasMax); - - // - // Handling FVGs Here ... - if (isBullishFVG) - { - // - fvgBox.type = GetBoxType(XCA_FVG_BULL); - - // - AddBox( - fvgBox, - trendBullishFVGs // - ); - } - } - - // - if (trendBullisPivothFinishedCondition) - { - // - // Update Values ... - trendBullishPivot.value = GetMin(trendBullishPivot.values); - trendBullishPivot.reserve = GetMax(trendBullishPivot.values); - - // - has = - trendBullishPivot.IsValid() && - trendBullishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - XBoxZone iBox; - has = trendBullishPivot.AsBox(iBox); - if (has) - { - // - XCATRENDFVG iTrendFVG; - - // - iTrendFVG.trend = iBox; - Copy( - trendBullishFVGs, - iTrendFVG.fvgs // - ); - - // - newTrendBullishPivotDetected = iTrendFVG.IsValid(); - if (newTrendBullishPivotDetected) - { - // - AddRef( - iTrendFVG, - trendBullishPivots // - ); - } - - // - iTrendFVG.Clean(); - } - - // - iBox.Clean(); - } - - // - Clean(trendBullishFVGs); - trendBullishPivot.Clean(); - } - } - - // - // TREND Bearish ... - if (detectTrendBearishPivots) - { - // - if (trendBearishStartPivotCondition) - { - // - Clean(trendBearishFVGs); - trendBearishPivot.Clean(); - - // - trendBearishPivot.type = XCA_TREND_BEAR; - trendBearishPivot.symbol = conditions.symbol; - trendBearishPivot.period = conditions.period; - - // - trendBearishPivot.to = pBar.time; - trendBearishPivot.from = pBar.time; - trendBearishPivot.value = p3MasMax; - trendBearishPivot.reserve = p3MasMin; - } - - // - if (trendBearishPivotContinuationCondition) - { - // - trendBearishPivot.from = pBar.time; - - // - Add( - p3MasMin, - trendBearishPivot.values // - ); - Add( - p3MasMax, - trendBearishPivot.values // - ); - - // - trendBearishPivot.reserve = - trendBearishPivot.reserve == 0 - ? p3MasMin - : MathMin(trendBearishPivot.reserve, p3MasMin); - - // - // Handling FVGs Here ... - if (isBearishFVG) - { - // - fvgBox.type = GetBoxType(XCA_FVG_BEAR); - - // - AddBox( - fvgBox, - trendBearishFVGs // - ); - } - } - - // - if (trendBearishivothFinishedCondition) - { - // - // Update Values ... - trendBearishPivot.value = GetMax(trendBearishPivot.values); - trendBearishPivot.reserve = GetMin(trendBearishPivot.values); - - // - has = - trendBearishPivot.IsValid() && - trendBearishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - XBoxZone iBox; - has = trendBearishPivot.AsBox(iBox); - if (has) - { - // - XCATRENDFVG iTrendFVG; - - // - iTrendFVG.trend = iBox; - Copy( - trendBearishFVGs, - iTrendFVG.fvgs // - ); - - // - newTrendBearishPivotDetected = iTrendFVG.IsValid(); - if (newTrendBearishPivotDetected) - { - // - AddRef( - iTrendFVG, - trendBearishPivots // - ); - } - - // - iTrendFVG.Clean(); - } - - // - iBox.Clean(); - } - - // - Clean(trendBearishFVGs); - trendBearishPivot.Clean(); - } - } - - // - // RSI Crossed Over OS ... - if (detectRSICrossedOverOSPivots) - { - // - bool checkingCondition = - // isRSIVale && - // isCBarHasBullishPower && - conditions.isRSICrossedOverOS; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.value = pBar.low; - iPivot.from = p2Bar.time; - iPivot.type = XCA_RSI_COOS; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - - // - iPivot.value = GetMin(iPivot.values); - iPivot.reserve = GetMax(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newRSICrossedOverOSPivotDetected = AddBox( - iBox, - rsiCrossedOverOSPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // RSI Crossed Under OB ... - if (detectRSICrossedUnderOBPivots) - { - // - bool checkingCondition = - // isRSIPeak && - // isCBarHasBearishPower && - conditions.isRSICrossedUnderOB; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_RSI_CUOB; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - - // - iPivot.value = GetMax(iPivot.values); - iPivot.reserve = GetMin(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newRSICrossedUnderOBPivotDetected = AddBox( - iBox, - rsiCrossedUnderOBPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // CCI Crossed Over OS ... - if (detectCCICrossedOverOSPivots) - { - // - bool checkingCondition = - isCCIVale && - // isCBarHasBullishPower && - conditions.isCCICrossedOverOS; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.value = pBar.low; - iPivot.from = p2Bar.time; - iPivot.type = XCA_CCI_COOS; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - - // - iPivot.value = GetMin(iPivot.values); - iPivot.reserve = GetMax(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newCCICrossedOverOSPivotDetected = AddBox( - iBox, - cciCrossedOverOSPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // CCI Crossed Under OB ... - if (detectCCICrossedUnderOBPivots) - { - // - bool checkingCondition = - isCCIPeak && - // isCBarHasBearishPower && - conditions.isCCICrossedUnderOB; - - // - if (checkingCondition) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_CCI_CUOB; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - - // - iPivot.value = GetMax(iPivot.values); - iPivot.reserve = GetMin(iPivot.values); - - // - XBoxZone iBox; - has = iPivot.IsValid(); - if (has) - { - // - has = iPivot.AsBox(iBox); - if (has) - { - // - newCCICrossedUnderOBPivotDetected = AddBox( - iBox, - cciCrossedUnderOBPivots // - ); - } - } - - // - iBox.Clean(); - iPivot.Clean(); - } - } - - // - // SPIKE Bullish ... - - // - bool detectSpikeBullisPivots = true; - if (detectSpikeBullisPivots) - { - // - // For Spike Detection ... - // [] 80% of Bars Must be Same as Direction ... - // [] Price Range of Bars Must be Passed of atr mult ... - // [] Required Volume Processing if Neccessary ... - - // - bool startCondition = false; - bool continuationCondition = false; - bool endCondition = false; - - // - // TODO: Complete this ... - } - - // - start++; - - // - Clean(z3Mas); - Clean(c3Mas); - Clean(p3Mas); - Clean(p23Mas); - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - fvgBox.Clean(); - conditions.Clean(); - } - - // - SortPivots(); - } - - // - void Validate( - XBoxZone &unAvailableBoxes[], - int barIndex = 0 // - ) - { - // - // Do All Pivots Validation ... - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - bool has = false; - - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - - // - // Retrieve Conditions ... - XCAEAConditions conditions; - has = helper.GetConditions( - conditions, - barIndex, - 5 // - ); - if (!has) - { - conditions.Clean(); - return; - } - - // - // Implement Validation Senarios ... - - // - // TICK Pivots ... - - // - // TODO: Complete this ... - has = HasTickPivots(); - if (has) - { - // - } - - // - // VOLUME Pivots ... - - // - // TODO: Complete this ... - has = HasVolumePivots(); - if (has) - { - // - } - - // - // RSI Peak Pivot ... - - // - has = HasRSIPeakPivots(); - if (has) - { - // - ApplyValidationOnBox( - rsiPeakPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // RSI Vale Pivot ... - - // - has = HasRSIValePivots(); - if (has) - { - // - ApplyValidationOnBox( - rsiValePivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // CCI Peak Pivot ... - - // - has = HasCCIPeakPivots(); - if (has) - { - // - ApplyValidationOnBox( - cciPeakPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // CCI Vale Pivot ... - - // - has = HasCCIValePivots(); - if (has) - { - // - ApplyValidationOnBox( - cciValePivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // FVG Bullish ... - - // - has = HasFVGBullishPivots(); - if (has) - { - // - ApplyValidationOnBox( - fvgBullishPivots, - unAvailableBoxes, - barIndex // - ); - - // - // Validate FVG Ages ... - if (maxAllowedFVGsAge > 0) - { - // - ApplyAgeVerification( - fvgBullishPivots, - maxAllowedFVGsAge // - ); - } - - // - // Validate FVG using PV ... - if (validateFVGsUsingPV) - { - // - ApplyFVGPVValidation( - fvgBullishPivots, - conditions // - ); - } - - // - // Validating FVGs using MANALYSER ... - // if (validateFVGsUsingMANALYSER) - // { - // // - // ApplyManalyswerValidation( - // fvgBullishPivots, - // barIndex // - // ); - // } - } - - // - // FVG Bearish ... - - // - has = HasFVGBearishPivots(); - if (has) - { - // - ApplyValidationOnBox( - fvgBearishPivots, - unAvailableBoxes, - barIndex // - ); - - // - // Validate FVG Ages ... - if (maxAllowedFVGsAge > 0) - { - // - ApplyAgeVerification( - fvgBearishPivots, - maxAllowedFVGsAge // - ); - } - - // - // Validate FVG using PV ... - if (validateFVGsUsingPV) - { - // - ApplyFVGPVValidation( - fvgBearishPivots, - conditions // - ); - } - - // - // Validating FVGs using MANALYSER ... - // if (validateFVGsUsingMANALYSER) - // { - // // - // ApplyManalyswerValidation( - // fvgBearishPivots, - // barIndex // - // ); - // } - } - - // - // VALE Pivot Support Swing Low ... - - // - has = HasValeSupSWLPivots(); - if (has) - { - // - ApplyValidationOnBox( - valeSupSWLPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // PEAK Pivot Resistance Swing High ... - - // - has = HasPeakResSWHPivots(); - if (has) - { - // - ApplyValidationOnBox( - peakResSWHPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // TREND Bullish ... - - // - has = HasTrendBullishPivots(); - if (has) - { - // - ApplyValidationOnTrendFVG( - trendBullishPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // TREND Bearish ... - - // - has = HasTrendBearishPivots(); - if (has) - { - // - ApplyValidationOnTrendFVG( - trendBearishPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // RSI Crossed Over OS ... - - // - has = HasRSICrossedOverOSPivots(); - if (has) - { - // - ApplyValidationOnBox( - rsiCrossedOverOSPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // RSI Crossed Under OB ... - - // - has = HasRSICrossedUnderOBPivots(); - if (has) - { - // - ApplyValidationOnBox( - rsiCrossedUnderOBPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // CCI Crossed Over OS ... - - // - has = HasCCICrossedOverOSPivots(); - if (has) - { - // - ApplyValidationOnBox( - cciCrossedOverOSPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - // CCI Crossed Under OB ... - - // - has = HasCCICrossedUnderOBPivots(); - if (has) - { - // - ApplyValidationOnBox( - cciCrossedUnderOBPivots, - unAvailableBoxes, - barIndex // - ); - } - - // - conditions.Clean(); - - // - SortPivots(); - } - - // - int FillPivots( - XBoxZone &pivots[], - ENUM_X_DIRECTION forDir = X_DIRECTION_ALL // - ) - { - // - int result = 0; - - // - Clean(pivots); - - // - if (forDir == X_DIRECTION_NONE) - { - return result; - } - - // - int count = 0; - bool has = false; - - // - bool canFillBullish = - forDir == X_DIRECTION_ALL || - forDir == X_DIRECTION_BULLISH; - - // - bool canFillBearish = - forDir == X_DIRECTION_ALL || - forDir == X_DIRECTION_BEARISH; - - // - // Bullish ... - if (canFillBullish) - { - // - Copy( - rsiValePivots, - pivots, - false // - ); - - // - Copy( - cciValePivots, - pivots, - false // - ); - - // - Copy( - fvgBullishPivots, - pivots, - false // - ); - - // - Copy( - valeSupSWLPivots, - pivots, - false // - ); - - // - Copy( - rsiCrossedOverOSPivots, - pivots, - false // - ); - - // - Copy( - cciCrossedOverOSPivots, - pivots, - false // - ); - - // - has = HasTrendBullishPivots(); - if (has) - { - // - count = CountTrendBullishPivots(); - for (int i = 0; i < count; i++) - { - // - AddRef( - trendBullishPivots[i].trend, - pivots // - ); - - // - XBoxZone iBox; - has = trendBullishPivots[i].GetSelectedFVG(iBox); - if (has) - { - // - AddRef( - iBox, - pivots // - ); - } - - // - iBox.Clean(); - } - } - } - - // - // Bearish ... - if (canFillBearish) - { - // - Copy( - rsiPeakPivots, - pivots, - false // - ); - - // - Copy( - cciPeakPivots, - pivots, - false // - ); - - // - Copy( - fvgBearishPivots, - pivots, - false // - ); - - // - Copy( - peakResSWHPivots, - pivots, - false // - ); - - // - Copy( - rsiCrossedUnderOBPivots, - pivots, - false // - ); - - // - Copy( - cciCrossedUnderOBPivots, - pivots, - false // - ); - - // - has = HasTrendBearishPivots(); - if (has) - { - // - count = CountTrendBearishPivots(); - for (int i = 0; i < count; i++) - { - // - AddRef( - trendBearishPivots[i].trend, - pivots // - ); - - // - XBoxZone iBox; - has = trendBearishPivots[i].GetSelectedFVG(iBox); - if (has) - { - // - AddRef( - iBox, - pivots // - ); - } - - // - iBox.Clean(); - } - } - } - - // - result = ArraySize(pivots); - - // - return result; - } - - // - bool MarketTrend(ENUM_X_DIRECTION &trend) - { - // - bool result = false; - - // - // Update Market Trend ... - DetectMarketTrend(); - - // - trend = trendDir; - result = HasDirection(trend); - - // - return result; - } - - // - // Counters ... - - // - // INVALID Pivots ... - - // - bool HasInvalidPivots() - { - return HasChild(invalidPivots); - } - - // - int CountInvalidPivots() - { - return ArraySize(invalidPivots); - } - - // - // TICK Pivot ... - - // - bool HasTickPivots() - { - return HasChild(tickPivots); - } - - // - int CountTickPivots() - { - return ArraySize(tickPivots); - } - - // - // VOLUME Pivots ... - - // - bool HasVolumePivots() - { - return HasChild(volumePivots); - } - - // - int CountVolumePivots() - { - return ArraySize(volumePivots); - } - - // - // RSI Peak Pivot ... - - // - bool HasRSIPeakPivots() - { - return HasChild(rsiPeakPivots); - } - - // - int CountRSIPeakPivots() - { - return ArraySize(rsiPeakPivots); - } - - // - // RSI Vale Pivot ... - - // - bool HasRSIValePivots() - { - return HasChild(rsiValePivots); - } - - // - int CountRSIValePivots() - { - return ArraySize(rsiValePivots); - } - - // - // CCI Peak Pivot ... - - // - bool HasCCIPeakPivots() - { - return HasChild(cciPeakPivots); - } - - // - int CountCCIPeakPivots() - { - return ArraySize(cciPeakPivots); - } - - // - // CCI Vale Pivot ... - - // - bool HasCCIValePivots() - { - return HasChild(cciValePivots); - } - - // - int CountCCIValePivots() - { - return ArraySize(cciValePivots); - } - - // - // FVG Bullish ... - - // - bool HasFVGBullishPivots() - { - return HasChild(fvgBullishPivots); - } - - // - int CountFVGBullishPivots() - { - return ArraySize(fvgBullishPivots); - } - - // - // FVG Bearish ... - - // - bool HasFVGBearishPivots() - { - return HasChild(fvgBearishPivots); - } - - // - int CountFVGBearishPivots() - { - return ArraySize(fvgBearishPivots); - } - - // - // VALE Pivot Support Swing Low ... - - // - bool HasValeSupSWLPivots() - { - return HasChild(valeSupSWLPivots); - } - - // - int CountValeSupSWLPivots() - { - return ArraySize(valeSupSWLPivots); - } - - // - // PEAK Pivot Resistance Swing High ... - - // - bool HasPeakResSWHPivots() - { - return HasChild(peakResSWHPivots); - } - - // - int CountPeakResSWHPivots() - { - return ArraySize(peakResSWHPivots); - } - - // - // TREND Bullish ... - - // - bool HasTrendBullishPivots() - { - return HasChild(trendBullishPivots); - } - - // - int CountTrendBullishPivots() - { - return ArraySize(trendBullishPivots); - } - - // - // TREND Bearish ... - - // - bool HasTrendBearishPivots() - { - return HasChild(trendBearishPivots); - } - - // - int CountTrendBearishPivots() - { - return ArraySize(trendBearishPivots); - } - - // - // RSI Crossed Over OS Pivots ... - - // - bool HasRSICrossedOverOSPivots() - { - return HasChild(rsiCrossedOverOSPivots); - } - - // - int CountRSICrossedOverOSPivots() - { - return ArraySize(rsiCrossedOverOSPivots); - } - - // - // RSI Crossed Under OB Pivots ... - - // - bool HasRSICrossedUnderOBPivots() - { - return HasChild(rsiCrossedUnderOBPivots); - } - - // - int CountRSICrossedUnderOBPivots() - { - return ArraySize(rsiCrossedUnderOBPivots); - } - - // - // CCI Crossed Over OS Pivots ... - - // - bool HasCCICrossedOverOSPivots() - { - return HasChild(cciCrossedOverOSPivots); - } - - // - int CountCCICrossedOverOSPivots() - { - return ArraySize(rsiCrossedOverOSPivots); - } - - // - // CCI Crossed Under OB Pivots ... - - // - bool HasCCICrossedUnderOBPivots() - { - return HasChild(cciCrossedUnderOBPivots); - } - - // - int CountCCICrossedUnderOBPivots() - { - return ArraySize(cciCrossedUnderOBPivots); - } - - // - // Protected ... - protected: - // - // Props ... - - // - // Prrivate ... - private: - // - // Props ... - - // - XCPOIDrawer *drawer; - XCXCAEAHelper *helper; - XCBarAnalyser *barAnalyser; - - // - bool AddBox( - XBoxZone &box, - XBoxZone &boxes[] // - ) - { - // - bool result = false; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - bool isExists = FindBoxIndex( - idx, - box, - boxes // - ); - result = !isExists; - if (!result) - { - return result; - } - - // - int before = ArraySize(boxes); - - // - AddRef( - box, - boxes // - ); - - // - int after = ArraySize(boxes); - - // - result = after > before; - - // - return result; - } - - // - bool ValidateBox( - XBoxZone &box, - XBoxZone &unAvailableBoxes[], - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Normalize Bar Index ... - barIndex = NormalizeInt(barIndex, 0); - - // - // Ceck Input Box is Valid ... - result = box.IsValid(); - if (!result) - { - return result; - } - - // - // Check Input Box is Available ... - bool canCheckUnAvailableBoxes = HasChild(unAvailableBoxes); - if (canCheckUnAvailableBoxes) - { - // - int idx = -1; - bool isUnAvailable = FindBoxIndex( - idx, - box, - unAvailableBoxes // - ); - result = !isUnAvailable; - if (!result) - { - return result; - } - } - - // - // Check Input Box is Breaked or not ... - - // - // Check Bar Index must after Box To Index ... - int toIDX = box.ToIndex(); - int fromIDX = box.FromIndex(); - result = toIDX > barIndex && - fromIDX > barIndex && - fromIDX > toIDX; - if (!result) - { - return result; - } - - // - // Detect Box Applied Boundary Price ... - // For Checking Break of Box ... - bool isBullish = box.IsBullish(); - double boundary = - isBullish - ? box.lower - : box.upper; - - // - // for validating Box Break we have to wait At Least 3 Bars Close - // out of Box Boundary ... - int barsLength = 3; - - // - // Calculate Start Checking Bar Index ... - int startCheckBreaktionBarIndex = toIDX - barsLength; - bool isBarIndexValid = startCheckBreaktionBarIndex > 0 && - barIndex < startCheckBreaktionBarIndex; - result = isBarIndexValid; - if (!result) - { - // - // Assume Box is Valid if Bar Index not Valid for Checking ... - result = true; - return result; - } - - // - // Try to Check Box Validation if Everything is OK ... - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - bool isValid = false; - bool isBreaked = false; - for (int i = barIndex; i < startCheckBreaktionBarIndex; i++) - { - // - // Initialize Bars ... - isValid = cBar.Init( - box.symbol, - box.period, - i + 1 // - ); - isValid = - result && - cBar.GetPreviousBar(pBar); - isValid = - result && - pBar.GetPreviousBar(p2Bar); - if (!isValid) - { - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - result = false; - - // - break; - } - - // - // Preparing Conditions ... - - // - bool isBullishBreaked = - isBullish && - cBar.close < boundary && - pBar.close < boundary && - p2Bar.close < boundary; - - // - bool isBearishBreaked = - !isBullish && - cBar.close > boundary && - pBar.close > boundary && - p2Bar.close > boundary; - - // - // Calculate Result ... - isBreaked = isBullishBreaked || - isBearishBreaked; - if (isBreaked) - { - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - result = false; - - // - break; - } - - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - } - - // - result = isValid && - !isBreaked; - - // - // Cleanup Resource ... - - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - return result; - } - - // - void CleanPivots() - { - // - Clean(invalidPivots); - - // - Clean(tickPivots); - Clean(volumePivots); - Clean(rsiPeakPivots); - Clean(rsiValePivots); - Clean(cciPeakPivots); - Clean(cciValePivots); - Clean(fvgBullishPivots); - Clean(fvgBearishPivots); - Clean(valeSupSWLPivots); - Clean(peakResSWHPivots); - Clean(trendBullishPivots); - Clean(trendBearishPivots); - Clean(rsiCrossedOverOSPivots); - Clean(rsiCrossedUnderOBPivots); - Clean(cciCrossedOverOSPivots); - Clean(cciCrossedUnderOBPivots); - } - - // - void SortPivots() - { - // - bool has = false; - - // - // RSI Peak ... - has = HasRSIPeakPivots(); - if (has) - { - ApplySortOnBox(rsiPeakPivots); - } - - // - // RSI Vale ... - has = HasRSIValePivots(); - if (has) - { - ApplySortOnBox(rsiValePivots); - } - - // - // CCI Peak ... - has = HasCCIPeakPivots(); - if (has) - { - ApplySortOnBox(cciPeakPivots); - } - - // - // CCI Vale ... - has = HasCCIValePivots(); - if (has) - { - ApplySortOnBox(cciValePivots); - } - - // - // FVG Bullish ... - has = HasFVGBullishPivots(); - if (has) - { - ApplySortOnBox(fvgBullishPivots); - } - - // - // FVG Bearish ... - has = HasFVGBearishPivots(); - if (has) - { - ApplySortOnBox(fvgBearishPivots); - } - - // - // VALE SUP SWL ... - has = HasValeSupSWLPivots(); - if (has) - { - ApplySortOnBox(valeSupSWLPivots); - } - - // - // PEAK REs SWH ... - has = HasPeakResSWHPivots(); - if (has) - { - ApplySortOnBox(peakResSWHPivots); - } - - // - // PVFVG Bullish ... - has = HasTrendBullishPivots(); - if (has) - { - ApplySortOnTrendFVG(trendBullishPivots); - } - - // - // PVFVG Bearish ... - has = HasTrendBearishPivots(); - if (has) - { - ApplySortOnTrendFVG(trendBearishPivots); - } - - // - // RSI Crossed Over OS ... - has = HasRSICrossedOverOSPivots(); - if (has) - { - ApplySortOnBox(rsiCrossedOverOSPivots); - } - - // - // RSI Crossed Under OB ... - has = HasRSICrossedUnderOBPivots(); - if (has) - { - ApplySortOnBox(rsiCrossedUnderOBPivots); - } - - // - // CCI Crossed Over OS ... - has = HasCCICrossedOverOSPivots(); - if (has) - { - ApplySortOnBox(cciCrossedOverOSPivots); - } - - // - // CCI Crossed Under OB ... - has = HasCCICrossedUnderOBPivots(); - if (has) - { - ApplySortOnBox(cciCrossedUnderOBPivots); - } - - // - // INVALID Pivots ... - has = HasInvalidPivots(); - if (has) - { - ApplySortOnBox(invalidPivots); - } - } - - // - // Sorting ... - - // - void ApplySortOnBox( - XBoxZone &items[] // - ) - { - // - int idx = -1; - bool has = false; - - // - has = HasChild(items); - if (!has) - { - return; - } - - // - XBoxZone tmp[]; - Copy( - items, - tmp // - ); - Clean(items); - - // - while (HasChild(tmp)) - { - // - idx = GetOldest(tmp); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmp[idx]; - ArrayRemove( - tmp, - idx, - 1 // - ); - - // - AddRef( - iBox, - items // - ); - } - - // - CleanupArray( - items, - maxAllowedPivots // - ); - - // - Clean(tmp); - } - - // - void ApplySortOnTrendFVG( - XCATRENDFVG &items[] // - ) - { - // - int idx = -1; - bool has = false; - - // - has = HasChild(items); - if (!has) - { - return; - } - - // - XCATRENDFVG tmp[]; - Copy( - items, - tmp // - ); - Clean(items); - - // - while (HasChild(tmp)) - { - // - idx = GetOldest(tmp); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCATRENDFVG iTrendFVG = tmp[idx]; - ArrayRemove( - tmp, - idx, - 1 // - ); - - // - AddRef( - iTrendFVG, - items // - ); - } - - // - CleanupArray( - items, - maxAllowedPivots // - ); - - // - Clean(tmp); - } - - // - // Validators ... - - // - void ApplyValidationOnBox( - XBoxZone &items[], - XBoxZone &unAvailableItems[], - int barIndex = 0 // - ) - { - // - bool has = false; - - // - has = HasChild(items); - if (!has) - { - return; - } - - // - XBoxZone tmp[]; - Copy( - items, - tmp // - ); - Clean(items); - while (HasChild(tmp)) - { - // - XBoxZone iBox = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = ValidateBox( - iBox, - unAvailableItems, - barIndex // - ); - if (has) - { - // - AddRef( - iBox, - items // - ); - } - - // - iBox.Clean(); - // - } - - // - Clean(tmp); - } - - // - void ApplyAgeVerification( - XBoxZone &pivots[], - int maxAllowedAge // - ) - { - // - bool has = HasChild(pivots) && - maxAllowedAge > 0; - if (!has) - { - return; - } - - // - XBoxZone tmp[]; - Copy( - pivots, - tmp // - ); - Clean(pivots); - - // - while (HasChild(tmp)) - { - // - XBoxZone iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - iPivot.to = TimeCurrent(); - - // - int iAge = iPivot.GetAge(); - has = iAge <= maxAllowedAge; - if (has) - { - // - AddRef( - iPivot, - pivots // - ); - } - - // - iPivot.Clean(); - } - - // - Clean(tmp); - } - - // - void ApplyFVGPVValidation( - XBoxZone &fvgs[], - XCAEAConditions &conditions // - ) - { - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - - // - bool has = HasChild(fvgs); - if (!has) - { - return; - } - - // - // Reading Values ... - - // - // PEAK ... - double zPeak = conditions.peakBuffer[zIDX]; - double cPeak = conditions.peakBuffer[cIDX]; - double pPeak = conditions.peakBuffer[pIDX]; - double p2Peak = conditions.peakBuffer[p2IDX]; - - // - // VALE ... - double zVale = conditions.valeBuffer[zIDX]; - double cVale = conditions.valeBuffer[cIDX]; - double pVale = conditions.valeBuffer[pIDX]; - double p2Vale = conditions.valeBuffer[p2IDX]; - - // - XBoxZone tmp[]; - Copy( - fvgs, - tmp // - ); - Clean(fvgs); - while (HasChild(tmp)) - { - // - XBoxZone iBox = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - bool isBullish = iBox.IsBullish(); - - // - bool isPVBreaked = - isBullish - ? cVale > iBox.upper - : cPeak < iBox.lower; - - // - has = !isPVBreaked; - if (has) - { - // - AddRef( - iBox, - fvgs // - ); - } - - // - iBox.Clean(); - } - - // - Clean(tmp); - } - - // - void ApplyValidationOnTrendFVG( - XCATRENDFVG &items[], - XBoxZone &unAvailableItems[], - int barIndex = 0 // - ) - { - // - bool has = false; - - // - has = HasChild(items); - if (!has) - { - return; - } - - // - XCATRENDFVG tmp[]; - Copy( - items, - tmp // - ); - Clean(items); - while (HasChild(tmp)) - { - // - XCATRENDFVG iTrendFVG = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - // Validate TMP Trend Box ... - has = ValidateBox( - iTrendFVG.trend, - unAvailableItems, - barIndex // - ); - if (has) - { - // - // Now we Have to Validate FVGS ... - ApplyValidationOnBox( - iTrendFVG.fvgs, - unAvailableItems, - barIndex // - ); - - // - has = iTrendFVG.IsValid(); - if (has) - { - // - AddRef( - iTrendFVG, - items // - ); - } - } - - // - iTrendFVG.Clean(); - } - - // - Clean(tmp); - } - - // - // - // - - // - bool IsExistsTickPivot( - datetime to, - datetime from // - ) - { - // - bool result = false; - - // - // Validate Args ... - result = IsValid(to) && - IsValid(from) && - to > from; - if (!result) - { - return result; - } - - // - result = HasTickPivots(); - if (!result) - { - return result; - } - - // - int idx = -1; - int count = CountTickPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tickPivots[i]; - - // - result = iBox.to == to && - iBox.from == from; - if (result) - { - // - idx = i; - iBox.Clean(); - - // - break; - } - - // - iBox.Clean(); - } - - // - result = IsValidIndex(idx); - - // - return result; - } - - // - bool IsExistsVolumePivot( - datetime to, - datetime from // - ) - { - // - bool result = false; - - // - // Validate Args ... - result = IsValid(to) && - IsValid(from) && - to > from; - if (!result) - { - return result; - } - - // - result = HasVolumePivots(); - if (!result) - { - return result; - } - - // - int idx = -1; - int count = CountVolumePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = volumePivots[i]; - - // - result = iBox.to == to && - iBox.from == from; - if (result) - { - // - idx = i; - iBox.Clean(); - - // - break; - } - - // - iBox.Clean(); - } - - // - result = IsValidIndex(idx); - - // - return result; - } - - // - bool InitializeTicksZone( - XCTicksZone *&zone, - XOHCL &toBar, - XOHCL &fromBar // - ) - { - // - bool result = false; - - // - result = zone == NULL; - if (!result) - { - return result; - } - - // - int toIDX = toBar.Index(); - int fromIDX = fromBar.Index(); - int rangeLength = fromIDX - toIDX; - double rangeDivider = ticksDividerInPoints * GetPoints(toBar.symbol); - double rangeL = toBar.FindLowest(rangeLength, MODE_LOW); - double rangeH = toBar.FindHighest(rangeLength, MODE_HIGH); - double rangeDiff = (rangeH - rangeL); - int zoneLevels = (int)(rangeDiff / rangeDivider); - - // - zone = new XCTicksZone(); - zone.Levels(zoneLevels); - - // - result = zone.Init( - fromBar, - toBar // - ); - if (!result) - { - ZeroMemory(zone); - } - - // - return result; - } - - // - void DetectMarketTrend() - { - // - int idx = -1; - int count = 0; - bool has = false; - - // - XBoxZone tmp[]; - has = HasPeakResSWHPivots(); - if (has) - { - // - Copy( - peakResSWHPivots, - tmp, - false // - ); - } - has = HasValeSupSWLPivots(); - if (has) - { - // - Copy( - valeSupSWLPivots, - tmp, - false // - ); - } - count = ArraySize(tmp); - has = HasChild(tmp); - if (!has) - { - return; - } - - // - has = HasDirection(trendDir); - if (!has) - { - // - trendPivotC.Clean(); - trendPivotP.Clean(); - } - - // - XBoxZone cPivot; - XBoxZone pPivot; - ENUM_X_DIRECTION dir = X_DIRECTION_NONE; - while (HasChild(tmp)) - { - // - XBoxZone iPivot; - idx = GetYoungest(tmp); - has = IsValidIndex(idx); - if (!has) - { - // - iPivot.Clean(); - break; - } - - // - iPivot = tmp[idx]; - ArrayRemove( - tmp, - idx, - 1 // - ); - - // - // Check Can Set CPivot ... - bool canSetCPivot = - !cPivot.IsValid() - ? true - : iPivot.from > cPivot.from; - if (canSetCPivot) - { - // - if (cPivot.IsValid()) - { - pPivot = cPivot; - } - - // - cPivot = iPivot; - } - - // - // Check Can Set PPivot ... - bool canSetPPivot = - !cPivot.IsValid() - ? false - : iPivot.from < cPivot.from - ? !pPivot.IsValid() - ? true - : iPivot.from > pPivot.from - : false; - if (canSetPPivot) - { - pPivot = iPivot; - } - - // - has = cPivot.IsValid() && - pPivot.IsValid(); - if (has) - { - // - iPivot.Clean(); - break; - } - - // - iPivot.Clean(); - } - - // - // Check Resources for Detecting Conditions ... - bool hasTrend = - // - cPivot.IsValid() && - pPivot.IsValid() && - cPivot.dir == pPivot.dir && - cPivot.from > pPivot.from && - (IsBullish(cPivot.dir) - ? cPivot.lower > pPivot.lower - : cPivot.upper < pPivot.upper); - // - ; - if (hasTrend) - { - // - trendPivotC = cPivot; - trendPivotP = pPivot; - trendDir = cPivot.dir; - } - - // - Clean(tmp); - cPivot.Clean(); - pPivot.Clean(); - - // - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/xcaea.x-poi.detector.class.mq5 b/Documents/BKP/xcaea.x-poi.detector.class.mq5 deleted file mode 100644 index 97cb01e5..00000000 --- a/Documents/BKP/xcaea.x-poi.detector.class.mq5 +++ /dev/null @@ -1,7731 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEAPOIDetector ... -// Description: Class for XCAEA POI Detector ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA POI Detector" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Helpers/xcaea.helper.mq5" - -// -// Definitions ... - -// -enum ENUM_XCA_PIVOTS -{ - XCA_NONE, // None - XCA_LL, // LowestLow - XCA_HH, // HighestHigh - XCA_KI, // KI - XCA_SWL, // SWL - XCA_SWH, // SWH - XCA_VALE, // VALE - XCA_PEAK, // PEAK - XCA_FVG_BULL, // FVGBull - XCA_FVG_BEAR, // FVGBear - XCA_RSI_COOS, // RSICOOS - XCA_RSI_CUOB, // RSICUOB - XCA_RSI_PEAK, // RSIPeak - XCA_RSI_VALE, // RSIVale - XCA_CCI_COOS, // CCICOOS - XCA_CCI_CUOB, // CCICUOB - XCA_CCI_PEAK, // CCIPeak - XCA_CCI_VALE, // CCIVale - XCA_KI_BULL, // KIBull - XCA_KI_BEAR, // KIBear - XCA_TKI_BULL, // TKIBull - XCA_TKI_BEAR, // TKIBear - XCA_PEAKSWHRES, // PeakSWHRes - XCA_VALESWLSUP, // ValeSWLSup - XCA_TREND_BULL, // TrendBull - XCA_TREND_BEAR, // TrendBear - XCA_TKITRND_BULL, // TKITRNDBull - XCA_TKITRND_BEAR, // TKITRNDBear -}; - -// -bool IsValid(ENUM_XCA_PIVOTS value) -{ - // - bool result = false; - - // - result = value != XCA_NONE; - - // - return result; -} - -// -string ToString(ENUM_XCA_PIVOTS value) -{ - // - string result = NULL; - - // - result = EnumToString(value); - - // - return result; -} - -// -struct XCAPivot -{ - // - // Props ... - datetime to; - double value; - string symbol; - datetime from; - double reserve; - ENUM_XCA_PIVOTS type; - ENUM_TIMEFRAMES period; - - // - double values[]; - - // - // Constructor ... - XCAPivot() - { - Default(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - value = 0; - to = NULL; - reserve = 0; - from = NULL; - symbol = NULL; - period = NULL; - type = XCA_NONE; - - // - Clean(values); - - // - ZeroMemory(this); - } - - /** - * Default ... - */ - void Default() - { - // - value = 0; - to = NULL; - reserve = 0; - from = NULL; - symbol = NULL; - period = NULL; - type = XCA_NONE; - - // - Clean(values); - - // - ZeroMemory(this); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - from < to && - value != 0 && - IsValid(to) && - IsValid(from) && - IsValid(type) && - IsValid(symbol) && - IsValid(period); - - // - return result; - } - - /** - * Check a Model is Same as this or not ... - * - * @param pivot: XCAPivot ... - * - * @return ( bool ) - */ - bool IsSameAs(XCAPivot &pivot) - { - // - bool result = false; - - // - result = - IsValid() && - pivot.IsValid(); - if (!result) - { - return result; - } - - // - result = - to == pivot.to && - from == pivot.from && - type == pivot.type && - value == pivot.value && - symbol == pivot.symbol && - period == pivot.period; - - // - return result; - } - - /** - * Retrieve To Index ... - * - * @param forPeriod: ENUM_TIMEFRAMES, Specified Period ... - * - * @return ( int ) - */ - int ToIndex( - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = GetBarIndex( - symbol, - forPeriod, - to // - ); - - // - return result; - } - - /** - * Retrieve From Index ... - * - * @param forPeriod: ENUM_TIMEFRAMES, Specified Period ... - * - * @return ( int ) - */ - int FromIndex( - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - int result = -1; - - // - if (!IsValid()) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = GetBarIndex( - symbol, - forPeriod, - from // - ); - - // - return result; - } - - /** - * Retrieve Age of Pivot ... - * - * @param forPeriod: ENUM_TIMEFRAMES, Specified Period ... - * - * @return ( int ) - */ - int GetAge( - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - int toIDX = ToIndex(forPeriod); - int fromIDX = FromIndex(forPeriod); - - // - result = fromIDX - toIDX; - - // - return result; - } - - /** - * Converts Pivot to Box ... - * - * @param box: XBoxZone instance reference ... - * - * @return ( bool ) - */ - bool AsBox( - XBoxZone &box // - ) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - switch (type) - { - // - case XCA_LL: - case XCA_SWL: - case XCA_VALE: - case XCA_KI_BULL: - case XCA_FVG_BULL: - case XCA_RSI_COOS: - case XCA_RSI_VALE: - case XCA_CCI_COOS: - case XCA_CCI_VALE: - case XCA_TKI_BULL: - case XCA_TREND_BULL: - case XCA_VALESWLSUP: - case XCA_TKITRND_BULL: - iDir = X_DIRECTION_BULLISH; - break; - - // - case XCA_HH: - case XCA_SWH: - case XCA_PEAK: - case XCA_KI_BEAR: - case XCA_FVG_BEAR: - case XCA_RSI_CUOB: - case XCA_RSI_PEAK: - case XCA_CCI_CUOB: - case XCA_CCI_PEAK: - case XCA_TKI_BEAR: - case XCA_TREND_BEAR: - case XCA_PEAKSWHRES: - case XCA_TKITRND_BEAR: - iDir = X_DIRECTION_BEARISH; - break; - } - - // - result = HasDirection(iDir); - if (!result) - { - return result; - } - - // - bool isBullish = - IsBullish(iDir) && - value < reserve; - - // - bool isBearish = - IsBearish(iDir) && - value > reserve; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - box.to = to; - box.dir = iDir; - box.from = from; - box.symbol = symbol; - box.period = period; - - // - string typeStr = ToString(type); - if (type == XCA_KI_BULL || - type == XCA_KI_BEAR) - { - // - typeStr = "XCA_KI"; - } - else if (type == XCA_FVG_BULL || - type == XCA_FVG_BEAR) - { - // - typeStr = "XCA_FVG"; - } - else if (type == XCA_RSI_COOS || - type == XCA_RSI_CUOB) - { - // - typeStr = "XCA_RSI"; - } - else if (type == XCA_CCI_COOS || - type == XCA_CCI_CUOB) - { - // - typeStr = "XCA_CCI"; - } - else if (type == XCA_TKI_BULL || - type == XCA_TKI_BEAR) - { - // - typeStr = "XCA_TKI"; - } - else if (type == XCA_TREND_BULL || - type == XCA_TREND_BEAR) - { - // - typeStr = "XCA_TREND"; - } - else if (type == XCA_TKITRND_BULL || - type == XCA_TKITRND_BEAR) - { - // - typeStr = "XCA_TKITRND"; - } - box.type = typeStr; - - // - box.upper = - isBullish - ? reserve - : value; - box.lower = - isBullish - ? value - : reserve; - - // - result = box.IsValid(); - if (!result) - { - box.Clean(); - } - - // - return result; - } - - // -}; - -// -struct XCAPVPivot -{ - // - // Props ... - double value; - XCAPivot pivots[]; - ENUM_X_DIRECTION dir; - - // - // Constructor ... - XCAPVPivot() - { - Default(); - } - - // - // Tools ... - - // - void Clean() - { - // - value = 0; - Clean(pivots); - dir = X_DIRECTION_NONE; - - // - ZeroMemory(this); - } - - // - void Default() - { - // - value = 0; - Clean(pivots); - dir = X_DIRECTION_NONE; - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = value != 0 && - HasDirection(dir); - - // - return result; - } - - // - void AddPivot(XCAPivot &pivot) - { - // - if (!IsValid() || - !pivot.IsValid()) - { - return; - } - - // - int idx = -1; - bool has = FindPivotIndex( - idx, - pivot, - pivots // - ); - if (has) - { - return; - } - - // - AddRef( - pivot, - pivots // - ); - } - - // - int GetPivots(XBoxZone &pivotBoxes[]) - { - // - int result = 0; - - // - Clean(pivotBoxes); - - // - bool has = false; - - // - has = IsValid() && - HasChild(pivots); - if (!has) - { - return result; - } - - // - int count = ArraySize(pivots); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = pivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - pivotBoxes // - ); - } - - // - iBox.Clean(); - } - - // - result = ArraySize(pivotBoxes); - - // - return result; - } -}; - -// -struct XCAPVTick -{ - // - XCAPivot pivot; - XCTicksZone *zone; - - // - XCAPVTick() - { - Default(); - } - - // - // Tools ... - - // - void Clean() - { - // - pivot.Clean(); - - // - ZeroMemory(zone); - ZeroMemory(this); - } - - // - void Default() - { - // - pivot.Clean(); - - // - ZeroMemory(zone); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = pivot.IsValid() && - zone != NULL; - - // - return result; - } - - // - bool Init(XCAPivot &_pivot) - { - // - bool result = false; - - // - result = _pivot.IsValid(); - if (!result) - { - return result; - } - - // - int toIDX = _pivot.ToIndex(); - int fromIDX = _pivot.FromIndex(); - int rangeLength = fromIDX - toIDX; - result = IsValidIndex(fromIDX) && - IsValidIndex(toIDX); - if (!result) - { - // - Clean(); - return result; - } - - // - XOHCL toBar; - XOHCL fromBar; - result = toBar.Init( - _pivot.symbol, - _pivot.period, - toIDX // - ); - result = result && - fromBar.Init( - _pivot.symbol, - _pivot.period, - fromIDX // - ); - if (!result) - { - // - toBar.Clean(); - fromBar.Clean(); - - // - Clean(); - - // - return result; - } - - // - double rangeDivider = 10 * GetPoints(_pivot.symbol); - double rangeL = toBar.FindLowest(rangeLength, MODE_LOW); - double rangeH = toBar.FindHighest(rangeLength, MODE_HIGH); - double rangeDiff = (rangeH - rangeL); - int zoneLevels = (int)(rangeDiff / rangeDivider); - - // - XCTicksZone *_zone; - _zone = new XCTicksZone(); - _zone.Levels(zoneLevels); - result = _zone.Init( - fromBar, - toBar // - ); - if (!result) - { - // - toBar.Clean(); - fromBar.Clean(); - ZeroMemory(_zone); - - // - Clean(); - - // - return result; - } - - // - pivot = _pivot; - zone = _zone; - - // - result = IsValid(); - if (!result) - { - Clean(); - } - - // - toBar.Clean(); - fromBar.Clean(); - ZeroMemory(_zone); - - // - return result; - } - - // - bool GetMaxVolumeBox(XBoxZone &box) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - // Select MAX Volume Zone ... - XCTickZone *selectedZone = NULL; - int zonesCount = zone.Count(); - for (int j = 0; j < zonesCount; j++) - { - // - XCTickZone *jZone = zone.GetZone(j); - - // - bool canSet = - selectedZone == NULL - ? true - : selectedZone.volume < jZone.volume; - if (canSet) - { - selectedZone = jZone; - } - - // - ZeroMemory(jZone); - } - - // - result = selectedZone != NULL; - if (!result) - { - // - box.Clean(); - ZeroMemory(selectedZone); - - // - return result; - } - - // - result = pivot.AsBox(box); - if (!result) - { - // - box.Clean(); - - // - return result; - } - box.upper = selectedZone.high; - box.lower = selectedZone.low; - box.type = - pivot.type == XCA_PEAKSWHRES - ? "PEAKTICK" - : pivot.type == XCA_VALESWLSUP - ? "VALETICK" - : box.type; - - // - return result; - } - - // -}; - -/** - * Find Specified Pivot Index inside a Collection of Pivots ... - * - * @param pivot: XCAPivot instance Reference ... - * @param pivots: XCAPivot instance Reference Collection ... - * - * @return ( int ) - */ -bool FindPivotIndex( - int &index, - XCAPivot &pivot, - XCAPivot &pivots[] // -) -{ - // - bool result = false; - - // - index = -1; - - // - int count = ArraySize(pivots); - result = pivot.IsValid() && - IsValidSize(count); - if (!result) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XCAPivot iPivot = pivots[i]; - - // - bool isSame = pivot.IsSameAs(iPivot); - if (isSame) - { - // - index = i; - break; - } - } - - // - result = IsValidIndex(index); - - // - return result; -} - -/** - * Add or Update Specified Pivot to Specified Collection ... - * - * @param pivot: XCAPivot instance reference, Specified Item ... - * @param pivots: XCAPivot instance reference Collection ... - * @param maxAllowedPivots: int, Max Allowed Pivots number of Collection ... - */ -void AddPivot( - XCAPivot &pivot, - XCAPivot &pivots[], - int maxAllowedPivots = 50 // -) -{ - // - bool has = pivot.IsValid(); - if (!has) - { - return; - } - - // - int idx = -1; - has = FindPivotIndex( - idx, - pivot, - pivots // - ); - if (has) - { - return; - } - - // - int updateIDX = -1; - int count = ArraySize(pivots); - for (int i = 0; i < count; i++) - { - // - XCAPivot iPivot = pivots[i]; - - // - has = - iPivot.to > pivot.to && - iPivot.from == pivot.from && - iPivot.value == pivot.value && - iPivot.symbol == pivot.symbol && - iPivot.period == pivot.period; - if (has) - { - // - updateIDX = i; - break; - } - } - - // - has = IsValidIndex(updateIDX); - if (!has) - { - // - AddRef( - pivot, - pivots // - ); - } - else - { - pivots[updateIDX].to = pivot.to; - } - - // - // Apply Max Allowed ... - CleanupArray( - pivots, - maxAllowedPivots // - ); -} - -/** - * Add or Update PV FVG item to Specified Collection ... - * - * @param value: double, Peak or Vale Value ... - * @param fvg: XCAPivot instance reference, Specified Pivot ... - * @param collection: XCAPVPivot instance Collection ... - */ -void AddOrUpdatePVFVG( - double value, - XCAPivot &fvg, - XCAPVPivot &collection[] // -) -{ - // - // Validate Args ... - if (value < 0 && - !fvg.IsValid() && - (fvg.type == XCA_FVG_BULL || - fvg.type == XCA_FVG_BEAR)) - { - return; - } - - // - // Check Pivot is Exists or not ... - ENUM_X_DIRECTION dir = - fvg.type == XCA_FVG_BULL - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - bool isBullish = IsBullish(dir); - bool isBearish = IsBearish(dir); - - // - // Try to Findout Pivot Value in Collection ... - int idx = -1; - int count = ArraySize(collection); - for (int i = 0; i < count; i++) - { - // - XCAPVPivot iTem = collection[i]; - - // - bool isSameValue = iTem.value == value; - bool isSameDirection = iTem.dir == dir; - - // - bool isValid = isSameValue && - isSameDirection; - if (isValid) - { - // - idx = i; - iTem.Clean(); - break; - } - - // - iTem.Clean(); - } - - // - // Try to Add Or Update Pivots ... - bool hasIndex = IsValidIndex(idx); - if (!hasIndex) - { - // - // New Item ... - XCAPVPivot iPVFVG; - - // - iPVFVG.dir = dir; - iPVFVG.value = value; - - // - AddRef( - fvg, - iPVFVG.pivots // - ); - - // - AddRef( - iPVFVG, - collection // - ); - } - else - { - // - // Add Pivot to Existing Item ... - collection[idx].AddPivot(fvg); - } - - // -} - -/** - * Add Specified PVTick to Collection ... - * - * @param pvTick: XCAPVTick instance Reference ... - * @param pvTicks: XCAPVTickinstance Reference Collection ... - */ -void AddPVTick( - XCAPVTick &pvTick, - XCAPVTick &pvTicks[] // -) -{ - // - bool has = pvTick.IsValid(); - if (!has) - { - return; - } - - // - has = false; - int count = ArraySize(pvTicks); - for (int i = 0; i < count; i++) - { - // - has = pvTicks[i].pivot.IsSameAs(pvTick.pivot); - if (has) - { - break; - } - } - - // - if (has) - { - return; - } - - // - AddRef( - pvTick, - pvTicks // - ); -} - -// -// Implementations ... -class XCXCAEAPOIDetector : public XCBase -{ - // - // Public ... - public: - // - // Props ... - - // - // Pivot Verifications and Max Allowed Holding Items ... - int pivotVerifications; // Pivots Verifications ... - int maxAllowedPivots; // Max Allowed Holding Pibots ... - - // - // Detector Pivots State Properties ... - - // - // PEAK / VALES ... - bool detectPeakPivot; - bool detectValePivot; - - // - // PEAK SWH RES / VALE SWL SUP ... - bool detectPeakSWHResPivot; - bool detectValeSWLSupPivot; - - // - // SWING HIGH / LOW ... - bool detectSWHPivot; - bool detectSWLPivot; - - // - // KI ... - bool detectKIBullishPivot; - bool detectKIBearishPivot; - - // - // TKI ... - bool detectTKIBullishPivot; - bool detectTKIBearishPivot; - - // - // FVG ... - bool detectFVGBullishPivot; - bool detectFVGBearishPivot; - - // - // SAME Cycles HH / LL ... - bool detectCycleSameLLPivot; - bool detectCycleSameHHPivot; - - // - // TREND ... - bool detectTrendBullishPivot; - bool detectTrendBearishPivot; - - // - // TKITRND ... - bool detectTKITRNDBullishPivot; - bool detectTKITRNDBearishPivot; - - // - // OSCS ... - - // - // RSI ... - bool detectRSIPeakPivot; - bool detectRSIValePivot; - bool detectRSICrossedOverOSPivot; - bool detectRSICrossedUnderOBPivot; - - // - // CCI ... - bool detectCCIPeakPivot; - bool detectCCIValePivot; - bool detectCCICrossedOverOSPivot; - bool detectCCICrossedUnderOBPivot; - - // - // Active Pivots ... - XCAPivot swhPivot; - XCAPivot swlPivot; - XCAPivot peakPivot; - XCAPivot valePivot; - XCAPivot sSameHHPivot; - XCAPivot mSameHHPivot; - XCAPivot lSameHHPivot; - XCAPivot hSameHHPivot; - XCAPivot sSameLLPivot; - XCAPivot mSameLLPivot; - XCAPivot lSameLLPivot; - XCAPivot hSameLLPivot; - XCAPivot kiBullishPivot; - XCAPivot kiBearishPivot; - XCAPivot tkiBullishPivot; - XCAPivot tkiBearishPivot; - XCAPivot peakSWHResPivot; - XCAPivot valeSWLSupPivot; - XCAPivot trendBullishPivot; - XCAPivot trendBearishPivot; - XCAPivot tkitrndBullishPivot; - XCAPivot tkitrndBearishPivot; - - // - // UnActive Pivots ... - XCAPivot swhPivots[]; - XCAPivot swlPivots[]; - XCAPivot peakPivots[]; - XCAPivot valePivots[]; - XCAPivot rsiPeakPivots[]; - XCAPivot rsiValePivots[]; - XCAPivot cciPeakPivots[]; - XCAPivot cciValePivots[]; - XCAPivot sSameHHPivots[]; - XCAPivot mSameHHPivots[]; - XCAPivot lSameHHPivots[]; - XCAPivot hSameHHPivots[]; - XCAPivot sSameLLPivots[]; - XCAPivot mSameLLPivots[]; - XCAPivot lSameLLPivots[]; - XCAPivot hSameLLPivots[]; - XCAPivot kiBullishPivots[]; - XCAPivot kiBearishPivots[]; - XCAPivot fvgBullishPivots[]; - XCAPivot fvgBearishPivots[]; - XCAPivot tkiBullishPivots[]; - XCAPivot tkiBearishPivots[]; - XCAPivot peakSWHResPivots[]; - XCAPivot valeSWLSupPivots[]; - XCAPivot trendBullishPivots[]; - XCAPivot trendBearishPivots[]; - XCAPivot tkitrndBullishPivots[]; - XCAPivot tkitrndBearishPivots[]; - XCAPivot rsiCrossedOverOSPivots[]; - XCAPivot cciCrossedOverOSPivots[]; - XCAPivot rsiCrossedUnderOBPivots[]; - XCAPivot cciCrossedUnderOBPivots[]; - - // - XCAPVTick peakTicks[]; - XCAPVTick valeTicks[]; - - // - XCAPVPivot pvFVGBullishPivots[]; - XCAPVPivot pvFVGBearishPivots[]; - - // - // Constructors ... - XCXCAEAPOIDetector( - XCXCAEAHelper *_helper // - ) - { - // - helper = _helper; - drawer = new XCPOIDrawer(); - barAnalyser = new XCBarAnalyser(); - - // - Default(); - } - - // - // De Constructors ... - ~XCXCAEAPOIDetector() - { - // - swhPivot.Clean(); - swlPivot.Clean(); - peakPivot.Clean(); - valePivot.Clean(); - sSameHHPivot.Clean(); - mSameHHPivot.Clean(); - lSameHHPivot.Clean(); - hSameHHPivot.Clean(); - sSameLLPivot.Clean(); - mSameLLPivot.Clean(); - lSameLLPivot.Clean(); - hSameLLPivot.Clean(); - kiBullishPivot.Clean(); - kiBearishPivot.Clean(); - tkiBullishPivot.Clean(); - tkiBearishPivot.Clean(); - peakSWHResPivot.Clean(); - valeSWLSupPivot.Clean(); - trendBullishPivot.Clean(); - trendBearishPivot.Clean(); - tkitrndBullishPivot.Clean(); - tkitrndBearishPivot.Clean(); - - // - Clean(swhPivots); - Clean(swlPivots); - Clean(peakPivots); - Clean(valePivots); - Clean(rsiPeakPivots); - Clean(rsiValePivots); - Clean(cciPeakPivots); - Clean(cciValePivots); - Clean(sSameHHPivots); - Clean(mSameHHPivots); - Clean(lSameHHPivots); - Clean(hSameHHPivots); - Clean(sSameLLPivots); - Clean(mSameLLPivots); - Clean(lSameLLPivots); - Clean(hSameLLPivots); - Clean(kiBullishPivots); - Clean(kiBearishPivots); - Clean(fvgBullishPivots); - Clean(fvgBearishPivots); - Clean(tkiBullishPivots); - Clean(tkiBearishPivots); - Clean(peakSWHResPivots); - Clean(valeSWLSupPivots); - Clean(trendBullishPivots); - Clean(trendBearishPivots); - Clean(tkitrndBullishPivots); - Clean(tkitrndBearishPivots); - Clean(rsiCrossedOverOSPivots); - Clean(cciCrossedOverOSPivots); - Clean(rsiCrossedUnderOBPivots); - Clean(cciCrossedUnderOBPivots); - - // - ZeroMemory(helper); - ZeroMemory(drawer); - ZeroMemory(barAnalyser); - } - - // - // Properties ... - - // - // Tools ... - - // - virtual void Default() - { - // - maxAllowedPivots = 50; - pivotVerifications = 5; - - // - detectSWHPivot = true; - detectSWLPivot = true; - detectPeakPivot = true; - detectValePivot = true; - detectRSIPeakPivot = true; - detectRSIValePivot = true; - detectCCIPeakPivot = true; - detectCCIValePivot = true; - detectKIBullishPivot = true; - detectKIBearishPivot = true; - detectFVGBullishPivot = true; - detectFVGBearishPivot = true; - detectTKIBullishPivot = true; - detectTKIBearishPivot = true; - detectPeakSWHResPivot = true; - detectValeSWLSupPivot = true; - detectCycleSameLLPivot = true; - detectCycleSameHHPivot = true; - detectTrendBullishPivot = true; - detectTrendBearishPivot = true; - detectTKITRNDBullishPivot = true; - detectTKITRNDBearishPivot = true; - detectCCICrossedOverOSPivot = true; - detectCCICrossedUnderOBPivot = true; - } - - // - void Update( - int barIndex = 0, - int loopback = 400 // - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - loopback = NormalizeInt(loopback, 400); - - // - int count = 0; - bool has = false; - - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - - // - int index = barIndex; - int start = index; - int end = index + loopback; - while (start < end) - { - // - // Retrieve Conditions ... - XCAEAConditions iConditions; - has = helper.GetConditions( - iConditions, - start, - 5 // - ); - - // - // Retrieve Bars ... - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - has = zBar.Init( - iConditions.symbol, - iConditions.period, - start // - ); - has = - has && - zBar.GetPreviousBar(cBar); - has = - has && - cBar.GetPreviousBar(pBar); - has = - has && - pBar.GetPreviousBar(p2Bar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - iConditions.Clean(); - - // - continue; - } - - // - XBoxZone fvgBox; - bool isFVG = barAnalyser.IsFVG( - cBar, - fvgBox // - ); - - // - bool isBullishFVG = - isFVG && - fvgBox.IsBullish(); - - // - bool isBearishFVG = - isFVG && - fvgBox.IsBearish(); - - // - // Provide Some Conditions ... - - // - double points = GetPoints(zBar.symbol); - - // - // PEAK ... - - // - double cPeak = iConditions.peakBuffer[cIDX]; - double pPeak = iConditions.peakBuffer[pIDX]; - double p2Peak = iConditions.peakBuffer[p2IDX]; - - // - bool isPeakStartSameLast = - cPeak == pPeak && - pPeak != p2Peak; - - // - bool isPeakFinishedSameLast = - cPeak != pPeak && - pPeak == p2Peak; - - // - // VALE ... - - // - double cVale = iConditions.valeBuffer[cIDX]; - double pVale = iConditions.valeBuffer[pIDX]; - double p2Vale = iConditions.valeBuffer[p2IDX]; - - // - bool isValeStartSameLast = - cVale == pVale && - pVale != p2Vale; - - // - bool isValeFinishedSameLast = - cVale != pVale && - pVale == p2Vale; - - // - // SWH ... - - // - double cSWH = iConditions.swingHighBuffer[cIDX]; - double pSWH = iConditions.swingHighBuffer[pIDX]; - double p2SWH = iConditions.swingHighBuffer[p2IDX]; - - // - bool isSWHStartSameLast = - cSWH == pSWH && - pSWH != p2SWH; - - // - bool isSWHFinishedSameLast = - cSWH != pSWH && - pSWH == p2SWH; - - // - // SWL ... - - // - double pSWL = iConditions.swingLowBuffer[pIDX]; - double cSWL = iConditions.swingLowBuffer[cIDX]; - double p2SWL = iConditions.swingLowBuffer[p2IDX]; - - // - bool isSWLStartSameLast = - cSWL == pSWL && - pSWL != p2SWL; - - // - bool isSWLFinishedSameLast = - cSWL != pSWL && - pSWL == p2SWL; - - // - // SUPPORT ... - - // - double cSupport = iConditions.supportBuffer[cIDX]; - double pSupport = iConditions.supportBuffer[pIDX]; - double p2Support = iConditions.supportBuffer[p2IDX]; - - // - bool isSupportStartSameLast = - cSupport == pSupport && - pSupport != p2Support; - - // - bool isSupportFinishedSameLast = - cSupport != pSupport && - pSupport == p2Support; - - // - // RESISTANCE ... - - // - double pResistance = iConditions.resistanceBuffer[pIDX]; - double cResistance = iConditions.resistanceBuffer[cIDX]; - double p2Resistance = iConditions.resistanceBuffer[p2IDX]; - - // - bool isResistanceStartSameLast = - cResistance == pResistance && - pResistance != p2Resistance; - - // - bool isResistanceFinishedSameLast = - cResistance != pResistance && - pResistance == p2Resistance; - - // - // PEAK SWH RES ... - - // - bool isCPeakIsPivot = - cPeak == cSWH && - cSWH == cResistance; - - // - bool isPPeakIsPivot = - pPeak == pSWH && - pSWH == pResistance; - - // - bool isStartPeakIsPivot = - isCPeakIsPivot && - !isPPeakIsPivot; - - // - bool isFinishedPeakIsPivot = - !isCPeakIsPivot && - isPPeakIsPivot; - - // - // VALE SWL SUP ... - - // - bool isCValeIsPivot = - cVale == cSWL && - cSWL == cSupport; - - // - bool isPValeIsPivot = - pVale == pSWL && - pSWL == pSupport; - - // - bool isStartValeIsPivot = - isCValeIsPivot && - !isPValeIsPivot; - - // - bool isFinishedValeIsPivot = - !isCValeIsPivot && - isPValeIsPivot; - - // - // TKITRND ... - - // - double cKI = iConditions.kiBuffer[cIDX]; - double pKI = iConditions.kiBuffer[pIDX]; - double p2KI = iConditions.kiBuffer[p2IDX]; - - // - double cKIState = iConditions.kiStateBuffer[cIDX]; - double pKIState = iConditions.kiStateBuffer[pIDX]; - double p2KIState = iConditions.kiStateBuffer[p2IDX]; - - // - double cTKI = iConditions.tkiBuffer[cIDX]; - double pTKI = iConditions.tkiBuffer[pIDX]; - double p2TKI = iConditions.tkiBuffer[p2IDX]; - - // - double cTKIState = iConditions.tkiStateBuffer[cIDX]; - double pTKIState = iConditions.tkiStateBuffer[pIDX]; - double p2TKIState = iConditions.tkiStateBuffer[p2IDX]; - - // - double cTrend = iConditions.trendBuffer[cIDX]; - double pTrend = iConditions.trendBuffer[pIDX]; - double p2Trend = iConditions.trendBuffer[p2IDX]; - - // - double cTrendState = iConditions.trendStateBuffer[cIDX]; - double pTrendState = iConditions.trendStateBuffer[pIDX]; - double p2TrendState = iConditions.trendStateBuffer[p2IDX]; - - // - double cTKITRNDs[] = { - cKI, - cTKI, - cTrend // - }; - - // - double cTKITRNDMin = GetMin(cTKITRNDs); - double cTKITRNDMax = GetMax(cTKITRNDs); - - // - double pTKITRNDs[] = { - pKI, - pTKI, - pTrend // - }; - - // - double pTKITRNDMin = GetMin(pTKITRNDs); - double pTKITRNDMax = GetMax(pTKITRNDs); - - // - bool isCTKITRNDBullish = - cKIState > 0 && - cTKIState > 0 && - cTrendState > 0; - - // - bool isPTKITRNDBullish = - pKIState > 0 && - pTKIState > 0 && - pTrendState > 0; - - // - bool isTKITRNDSwitchedBullish = - isCTKITRNDBullish && - !isPTKITRNDBullish; - - // - bool isCTKITRNDBearish = - cKIState < 0 && - cTKIState < 0 && - cTrendState < 0; - - // - bool isPTKITRNDBearish = - pKIState < 0 && - pTKIState < 0 && - pTrendState < 0; - - // - bool isTKITRNDSwitchedBearish = - isCTKITRNDBearish && - !isPTKITRNDBearish; - - // - // CYCLES ... - - // - double cSLL = iConditions.sLLBuffer[cIDX]; - double pSLL = iConditions.sLLBuffer[pIDX]; - double p2SLL = iConditions.sLLBuffer[p2IDX]; - - // - double cSHH = iConditions.sHHBuffer[cIDX]; - double pSHH = iConditions.sHHBuffer[pIDX]; - double p2SHH = iConditions.sHHBuffer[p2IDX]; - - // - double cMLL = iConditions.mLLBuffer[cIDX]; - double pMLL = iConditions.mLLBuffer[pIDX]; - double p2MLL = iConditions.mLLBuffer[p2IDX]; - - // - double cMHH = iConditions.mHHBuffer[cIDX]; - double pMHH = iConditions.mHHBuffer[pIDX]; - double p2MHH = iConditions.mHHBuffer[p2IDX]; - - // - double cLLL = iConditions.lLLBuffer[cIDX]; - double pLLL = iConditions.lLLBuffer[pIDX]; - double p2LLL = iConditions.lLLBuffer[p2IDX]; - - // - double cLHH = iConditions.lHHBuffer[cIDX]; - double pLHH = iConditions.lHHBuffer[pIDX]; - double p2LHH = iConditions.lHHBuffer[p2IDX]; - - // - double cHLL = iConditions.hLLBuffer[cIDX]; - double pHLL = iConditions.hLLBuffer[pIDX]; - double p2HLL = iConditions.hLLBuffer[p2IDX]; - - // - double cHHH = iConditions.hHHBuffer[cIDX]; - double pHHH = iConditions.hHHBuffer[pIDX]; - double p2HHH = iConditions.hHHBuffer[p2IDX]; - - // - // Short Cycle ... - - // - // LL ... - - // - bool isCSLLSame = - cSLL == pSLL; - - // - bool isPSLLSame = - pSLL == p2SLL; - - // - bool isSLLStartSame = - isCSLLSame && - !isPSLLSame; - - // - bool isSLLFinishedSame = - !isCSLLSame && - isPSLLSame; - - // - // HH ... - - // - bool isCSHHSame = - cSHH == pSHH; - - // - bool isPSHHSame = - pSHH == p2SHH; - - // - bool isSHHStartSame = - isCSHHSame && - !isPSHHSame; - - // - bool isSHHFinishedSame = - !isCSHHSame && - isPSHHSame; - - // - // Mediu Cycle ... - - // - // LL ... - - // - bool isCMLLSame = - cMLL == pMLL; - - // - bool isPMLLSame = - pMLL == p2MLL; - - // - bool isMLLStartSame = - isCMLLSame && - !isPMLLSame; - - // - bool isMLLFinishedSame = - !isCMLLSame && - isPMLLSame; - - // - // HH ... - - // - bool isCMHHSame = - cMHH == pMHH; - - // - bool isPMHHSame = - pMHH == p2MHH; - - // - bool isMHHStartSame = - isCMHHSame && - !isPMHHSame; - - // - bool isMHHFinishedSame = - !isCMHHSame && - isPMHHSame; - - // - // Long Cycle ... - - // - // LL ... - - // - bool isCLLLSame = - cLLL == pLLL; - - // - bool isPLLLSame = - pLLL == p2LLL; - - // - bool isLLLStartSame = - isCLLLSame && - !isPLLLSame; - - // - bool isLLLFinishedSame = - !isCLLLSame && - isPLLLSame; - - // - // HH ... - - // - bool isCLHHSame = - cLHH == pLHH; - - // - bool isPLHHSame = - pLHH == p2LHH; - - // - bool isLHHStartSame = - isCLHHSame && - !isPLHHSame; - - // - bool isLHHFinishedSame = - !isCLHHSame && - isPLHHSame; - - // - // Hind Cycle ... - - // - // LL ... - - // - bool isCHLLSame = - cHLL == pHLL; - - // - bool isPHLLSame = - pHLL == p2HLL; - - // - bool isHLLStartSame = - isCHLLSame && - !isPHLLSame; - - // - bool isHLLFinishedSame = - !isCHLLSame && - isPHLLSame; - - // - // HH ... - - // - bool isCHHHSame = - cHHH == pHHH; - - // - bool isPHHHSame = - pHHH == p2HHH; - - // - bool isHHHStartSame = - isCHHHSame && - !isPHHHSame; - - // - bool isHHHFinishedSame = - !isCHHHSame && - isPHHHSame; - - // - // KI ... - - // - bool isCKISame = - cKI == pKI; - - // - bool isPKISame = - pKI == p2KI; - - // - bool isKIStartSame = - isCKISame && - !isPKISame; - - // - bool isKIFinishedSame = - !isCKISame && - isPKISame; - - // - // RSI ... - - // - double zRSI = iConditions.rsiBuffer[zIDX]; - double cRSI = iConditions.rsiBuffer[cIDX]; - double pRSI = iConditions.rsiBuffer[pIDX]; - double p2RSI = iConditions.rsiBuffer[p2IDX]; - - // - bool isRSIPeak = - pRSI > cRSI && - pRSI > p2RSI && - pRSI > zRSI; - - // - bool isRSIVale = - pRSI < cRSI && - pRSI < p2RSI && - pRSI < zRSI; - - // - bool isRSIBullishVPattern = - cRSI > pRSI && - p2RSI > pRSI && - cRSI > iConditions.rsiOSLevel && - pRSI < iConditions.rsiOSLevel; - - // - bool isRSIBearishVPattern = - cRSI < pRSI && - p2RSI < pRSI && - cRSI < iConditions.rsiOBLevel && - pRSI > iConditions.rsiOBLevel; - - // - // CCI ... - - // - double zCCI = iConditions.cciBuffer[zIDX]; - double cCCI = iConditions.cciBuffer[cIDX]; - double pCCI = iConditions.cciBuffer[pIDX]; - double p2CCI = iConditions.cciBuffer[p2IDX]; - - // - bool isCCIPeak = - pCCI > cCCI && - pCCI > p2CCI && - pCCI > zCCI; - - // - bool isCCIVale = - pCCI < cCCI && - pCCI < p2CCI && - pCCI < zCCI; - - // - bool isCCIBullishVPattern = - cCCI > pCCI && - p2CCI > pCCI && - cCCI > iConditions.cciOSLevel && - pCCI < iConditions.cciOSLevel; - - // - bool isCCIBearishVPattern = - cCCI < pCCI && - p2CCI < pCCI && - cCCI < iConditions.cciOBLevel && - pCCI > iConditions.cciOBLevel; - - // - // Checking Pivots ... - - // - // Peak Pivot ... - if (detectPeakPivot) - { - // - if (!peakPivot.IsValid()) - { - // - peakPivot.type = XCA_PEAK; - peakPivot.symbol = iConditions.symbol; - peakPivot.period = iConditions.period; - - // - if (isPeakFinishedSameLast) - { - // - peakPivot.Clean(); - - // - peakPivot.type = XCA_PEAK; - peakPivot.symbol = iConditions.symbol; - peakPivot.period = iConditions.period; - - // - peakPivot.to = pBar.time; - peakPivot.from = pBar.time; - peakPivot.value = iConditions.peakBuffer[pIDX]; - peakPivot.reserve = iConditions.peakGoldenBuffer[pIDX]; - } - } - - // - if (iConditions.isPeakSameLast) - { - // - peakPivot.from = pBar.time; - - // - peakPivot.reserve = - peakPivot.reserve == 0 - ? iConditions.peakGoldenBuffer[cIDX] - : MathMax(peakPivot.reserve, iConditions.peakGoldenBuffer[cIDX]); - } - - // - if (isPeakStartSameLast) - { - // - has = - peakPivot.IsValid() && - peakPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - peakPivot, - peakPivots, - maxAllowedPivots // - ); - } - - // - peakPivot.Clean(); - } - } - - // - // Vale Pivot ... - if (detectValePivot) - { - // - if (!valePivot.IsValid()) - { - // - valePivot.type = XCA_VALE; - valePivot.symbol = iConditions.symbol; - valePivot.period = iConditions.period; - - // - if (isValeFinishedSameLast) - { - // - valePivot.Clean(); - - // - valePivot.type = XCA_VALE; - valePivot.symbol = iConditions.symbol; - valePivot.period = iConditions.period; - - // - valePivot.to = pBar.time; - valePivot.from = pBar.time; - valePivot.value = iConditions.valeBuffer[pIDX]; - valePivot.reserve = iConditions.valeGoldenBuffer[pIDX]; - } - } - - // - if (iConditions.isValeSameLast) - { - // - valePivot.from = pBar.time; - - // - valePivot.reserve = - valePivot.reserve == 0 - ? iConditions.valeGoldenBuffer[cIDX] - : MathMin(valePivot.reserve, iConditions.valeGoldenBuffer[cIDX]); - } - - // - if (isValeStartSameLast) - { - // - has = valePivot.IsValid() && - valePivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - valePivot, - valePivots, - maxAllowedPivots // - ); - } - - // - valePivot.Clean(); - } - } - - // - // SWH Pivot ... - if (detectSWHPivot) - { - // - if (!swhPivot.IsValid()) - { - // - swhPivot.type = XCA_SWH; - swhPivot.symbol = iConditions.symbol; - swhPivot.period = iConditions.period; - - // - if (isSWHFinishedSameLast) - { - // - swhPivot.Clean(); - - // - swhPivot.type = XCA_SWH; - swhPivot.symbol = iConditions.symbol; - swhPivot.period = iConditions.period; - - // - swhPivot.to = pBar.time; - swhPivot.from = pBar.time; - swhPivot.value = iConditions.swingHighBuffer[pIDX]; - } - } - - // - if (iConditions.isSwingHighSameLast) - { - // - swhPivot.from = pBar.time; - - // - double reserve = swhPivot.reserve; - if (pBar.high == pSWH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - swhPivot.reserve = reserve; - } - - // - if (isSWHStartSameLast) - { - // - double reserve = swhPivot.reserve; - if (cBar.high == cSWH) - { - // - reserve = - reserve == 0 - ? cBar.GetUp() - : MathMin(reserve, cBar.GetUp()); - } - if (pBar.high == pSWH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - if (reserve == 0 || reserve == swhPivot.value) - { - reserve = swhPivot.value - (5 * points); - } - swhPivot.reserve = reserve; - - // - has = - swhPivot.IsValid() && - swhPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - swhPivot, - swhPivots, - maxAllowedPivots // - ); - } - - // - swhPivot.Clean(); - } - } - - // - // SWL Pivot ... - if (detectSWLPivot) - { - // - if (!swlPivot.IsValid()) - { - // - swlPivot.type = XCA_SWL; - swlPivot.symbol = iConditions.symbol; - swlPivot.period = iConditions.period; - - // - if (isSWLFinishedSameLast) - { - // - swlPivot.Clean(); - - // - swlPivot.type = XCA_SWL; - swlPivot.symbol = iConditions.symbol; - swlPivot.period = iConditions.period; - - // - swlPivot.to = cBar.time; - swlPivot.from = pBar.time; - swlPivot.value = iConditions.swingLowBuffer[cIDX]; - } - } - - // - if (iConditions.isSwingLowSameLast) - { - // - swlPivot.from = pBar.time; - - // - double reserve = swlPivot.reserve; - if (pBar.low == pSWL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - swlPivot.reserve = reserve; - } - - // - if (isSWLStartSameLast) - { - // - double reserve = swlPivot.reserve; - if (cBar.low == cSWL) - { - // - reserve = - reserve == 0 - ? cBar.GetDown() - : MathMax(reserve, cBar.GetDown()); - } - if (pBar.low == pSWL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - if (reserve == 0 || reserve == swlPivot.value) - { - reserve = swlPivot.value + (5 * points); - } - swlPivot.reserve = reserve; - - // - has = - swlPivot.IsValid() && - swlPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - swlPivot, - swlPivots, - maxAllowedPivots // - ); - } - - // - swlPivot.Clean(); - } - } - - // - // Peak SWH Res Pivot ... - if (detectPeakSWHResPivot) - { - // - if (!peakSWHResPivot.IsValid()) - { - // - peakSWHResPivot.type = XCA_PEAKSWHRES; - peakSWHResPivot.symbol = iConditions.symbol; - peakSWHResPivot.period = iConditions.period; - - // - if (isFinishedPeakIsPivot) - { - // - peakSWHResPivot.Clean(); - - // - peakSWHResPivot.type = XCA_PEAKSWHRES; - peakSWHResPivot.symbol = iConditions.symbol; - peakSWHResPivot.period = iConditions.period; - - // - peakSWHResPivot.to = pBar.time; - peakSWHResPivot.from = pBar.time; - peakSWHResPivot.value = iConditions.peakBuffer[pIDX]; - peakSWHResPivot.reserve = iConditions.peakGoldenBuffer[pIDX]; - } - } - - // - if (iConditions.isPeakIsPivot) - { - // - peakSWHResPivot.from = pBar.time; - - // - peakSWHResPivot.reserve = - peakSWHResPivot.reserve == 0 - ? iConditions.peakGoldenBuffer[pIDX] - : MathMax(peakSWHResPivot.reserve, iConditions.peakGoldenBuffer[pIDX]); - } - - // - if (isStartPeakIsPivot) - { - // - has = peakSWHResPivot.IsValid() && - peakSWHResPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - peakSWHResPivot, - peakSWHResPivots, - maxAllowedPivots // - ); - - // - XCAPVTick peakTick; - has = peakTick.Init(peakSWHResPivot); - if (has) - { - // - AddPVTick( - peakTick, - peakTicks // - ); - } - - // - peakTick.Clean(); - } - - // - peakSWHResPivot.Clean(); - } - } - - // - // Vale SWL Sup Pivot ... - if (detectValeSWLSupPivot) - { - // - if (!valeSWLSupPivot.IsValid()) - { - // - valeSWLSupPivot.type = XCA_VALESWLSUP; - valeSWLSupPivot.symbol = iConditions.symbol; - valeSWLSupPivot.period = iConditions.period; - - // - if (isFinishedValeIsPivot) - { - // - valeSWLSupPivot.Clean(); - - // - valeSWLSupPivot.type = XCA_VALESWLSUP; - valeSWLSupPivot.symbol = iConditions.symbol; - valeSWLSupPivot.period = iConditions.period; - - // - valeSWLSupPivot.to = pBar.time; - valeSWLSupPivot.from = pBar.time; - valeSWLSupPivot.value = iConditions.valeBuffer[pIDX]; - valeSWLSupPivot.reserve = iConditions.valeGoldenBuffer[pIDX]; - } - } - - // - if (iConditions.isValeIsPivot) - { - // - valeSWLSupPivot.from = pBar.time; - - // - valeSWLSupPivot.reserve = - valeSWLSupPivot.reserve == 0 - ? iConditions.valeGoldenBuffer[pIDX] - : MathMin(valeSWLSupPivot.reserve, iConditions.valeGoldenBuffer[pIDX]); - } - - // - if (isStartValeIsPivot) - { - // - has = valeSWLSupPivot.IsValid() && - valeSWLSupPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - valeSWLSupPivot, - valeSWLSupPivots, - maxAllowedPivots // - ); - - // - XCAPVTick valeTick; - has = valeTick.Init(valeSWLSupPivot); - if (has) - { - // - AddPVTick( - valeTick, - valeTicks // - ); - } - - // - valeTick.Clean(); - } - - // - valeSWLSupPivot.Clean(); - } - } - - // - // KI Bullish ... - if (detectKIBullishPivot) - { - // - if (!kiBullishPivot.IsValid()) - { - // - kiBullishPivot.type = XCA_KI_BULL; - kiBullishPivot.symbol = iConditions.symbol; - kiBullishPivot.period = iConditions.period; - - // - if (iConditions.isKISwitchedToBearish) - { - // - kiBullishPivot.Clean(); - - // - kiBullishPivot.type = XCA_KI_BULL; - kiBullishPivot.symbol = iConditions.symbol; - kiBullishPivot.period = iConditions.period; - - // - kiBullishPivot.to = pBar.time; - kiBullishPivot.from = pBar.time; - kiBullishPivot.value = iConditions.kiBuffer[pIDX]; - kiBullishPivot.reserve = iConditions.kiBuffer[pIDX]; - } - } - - // - if (iConditions.isKIBullish) - { - // - kiBullishPivot.from = cBar.time; - - // - Add( - iConditions.kiBuffer[cIDX], - kiBullishPivot.values // - ); - - // - kiBullishPivot.value = - kiBullishPivot.value == 0 - ? iConditions.kiBuffer[cIDX] - : MathMin(iConditions.kiBuffer[cIDX], kiBullishPivot.value); - - // - kiBullishPivot.reserve = - kiBullishPivot.reserve == 0 - ? iConditions.kiBuffer[cIDX] - : MathMax(iConditions.kiBuffer[cIDX], kiBullishPivot.reserve); - } - - // - if (iConditions.isKISwitchedToBullish) - { - // - has = - kiBullishPivot.IsValid() && - kiBullishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - kiBullishPivot, - kiBullishPivots, - maxAllowedPivots // - ); - } - - // - kiBullishPivot.Clean(); - } - } - - // - // KI Bearish ... - if (detectKIBearishPivot) - { - // - if (!kiBearishPivot.IsValid()) - { - // - kiBearishPivot.type = XCA_KI_BEAR; - kiBearishPivot.symbol = iConditions.symbol; - kiBearishPivot.period = iConditions.period; - - // - if (iConditions.isKISwitchedToBullish) - { - // - kiBearishPivot.Clean(); - - // - kiBearishPivot.type = XCA_KI_BEAR; - kiBearishPivot.symbol = iConditions.symbol; - kiBearishPivot.period = iConditions.period; - - // - kiBearishPivot.to = pBar.time; - kiBearishPivot.from = pBar.time; - kiBearishPivot.value = iConditions.kiBuffer[pIDX]; - kiBearishPivot.reserve = iConditions.kiBuffer[pIDX]; - } - } - - // - if (iConditions.isKIBearish) - { - // - kiBearishPivot.from = cBar.time; - - // - Add( - iConditions.kiBuffer[cIDX], - kiBearishPivot.values // - ); - - // - kiBearishPivot.value = - kiBearishPivot.value == 0 - ? iConditions.kiBuffer[cIDX] - : MathMax(iConditions.kiBuffer[cIDX], kiBearishPivot.value); - - // - kiBearishPivot.reserve = - kiBearishPivot.reserve == 0 - ? iConditions.kiBuffer[cIDX] - : MathMin(iConditions.kiBuffer[cIDX], kiBearishPivot.reserve); - } - - // - if (iConditions.isKISwitchedToBearish) - { - // - has = - kiBearishPivot.IsValid() && - kiBearishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - kiBearishPivot, - kiBearishPivots, - maxAllowedPivots // - ); - } - - // - kiBearishPivot.Clean(); - } - } - - // - // FVG Bullish ... - if (detectFVGBullishPivot) - { - // - if (isBullishFVG) - { - // - XCAPivot iPivot; - - // - iPivot.to = fvgBox.to; - iPivot.from = fvgBox.from; - iPivot.type = XCA_FVG_BULL; - iPivot.value = fvgBox.lower; - iPivot.reserve = fvgBox.upper; - iPivot.symbol = fvgBox.symbol; - iPivot.period = fvgBox.period; - - // - AddPivot( - iPivot, - fvgBullishPivots, - maxAllowedPivots // - ); - - // - double fValue = - fvgBox.IsBullish() - ? cVale - : cPeak; - - // - // XPVFVG Handling ... - AddOrUpdatePVFVG( - fValue, - iPivot, - pvFVGBullishPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // FVG Bearish ... - if (detectFVGBearishPivot) - { - // - if (isBearishFVG) - { - // - XCAPivot iPivot; - - // - iPivot.to = fvgBox.to; - iPivot.from = fvgBox.from; - iPivot.type = XCA_FVG_BEAR; - iPivot.value = fvgBox.upper; - iPivot.reserve = fvgBox.lower; - iPivot.symbol = fvgBox.symbol; - iPivot.period = fvgBox.period; - - // - AddPivot( - iPivot, - fvgBearishPivots, - maxAllowedPivots // - ); - - // - double fValue = - fvgBox.IsBullish() - ? cVale - : cPeak; - - // - // XPVFVG Handling ... - AddOrUpdatePVFVG( - fValue, - iPivot, - pvFVGBearishPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // TKI Bullish ... - if (detectTKIBullishPivot) - { - // - if (!tkiBullishPivot.IsValid()) - { - // - tkiBullishPivot.type = XCA_TKI_BULL; - tkiBullishPivot.symbol = iConditions.symbol; - tkiBullishPivot.period = iConditions.period; - - // - if (iConditions.isTKISwitchedToBearish) - { - // - tkiBullishPivot.Clean(); - - // - tkiBullishPivot.type = XCA_TKI_BULL; - tkiBullishPivot.symbol = iConditions.symbol; - tkiBullishPivot.period = iConditions.period; - - // - tkiBullishPivot.to = pBar.time; - tkiBullishPivot.from = pBar.time; - tkiBullishPivot.value = iConditions.tkiBuffer[pIDX]; - tkiBullishPivot.reserve = iConditions.tkiBuffer[pIDX]; - } - } - - // - if (iConditions.isTKIBullish) - { - // - tkiBullishPivot.from = cBar.time; - - // - Add( - iConditions.tkiBuffer[cIDX], - tkiBullishPivot.values // - ); - - // - tkiBullishPivot.value = - tkiBullishPivot.value == 0 - ? iConditions.tkiBuffer[cIDX] - : MathMin(iConditions.tkiBuffer[cIDX], tkiBullishPivot.value); - - // - tkiBullishPivot.reserve = - tkiBullishPivot.reserve == 0 - ? iConditions.tkiBuffer[cIDX] - : MathMax(iConditions.tkiBuffer[cIDX], tkiBullishPivot.reserve); - } - - // - if (iConditions.isTKISwitchedToBullish) - { - // - has = - tkiBullishPivot.IsValid() && - tkiBullishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - tkiBullishPivot, - tkiBullishPivots, - maxAllowedPivots // - ); - } - - // - tkiBullishPivot.Clean(); - } - } - - // - // TKI Bearish ... - if (detectTKIBearishPivot) - { - // - if (!tkiBearishPivot.IsValid()) - { - // - tkiBearishPivot.type = XCA_TKI_BEAR; - tkiBearishPivot.symbol = iConditions.symbol; - tkiBearishPivot.period = iConditions.period; - - // - if (iConditions.isTKISwitchedToBullish) - { - // - tkiBearishPivot.Clean(); - - // - tkiBearishPivot.type = XCA_TKI_BEAR; - tkiBearishPivot.symbol = iConditions.symbol; - tkiBearishPivot.period = iConditions.period; - - // - tkiBearishPivot.to = pBar.time; - tkiBearishPivot.from = pBar.time; - tkiBearishPivot.value = iConditions.tkiBuffer[pIDX]; - tkiBearishPivot.reserve = iConditions.tkiBuffer[pIDX]; - } - } - - // - if (iConditions.isTKIBearish) - { - // - tkiBearishPivot.from = cBar.time; - - // - Add( - iConditions.tkiBuffer[cIDX], - tkiBearishPivot.values // - ); - - // - tkiBearishPivot.value = - tkiBearishPivot.value == 0 - ? iConditions.tkiBuffer[cIDX] - : MathMax(iConditions.tkiBuffer[cIDX], tkiBearishPivot.value); - - // - tkiBearishPivot.reserve = - tkiBearishPivot.reserve == 0 - ? iConditions.tkiBuffer[cIDX] - : MathMin(iConditions.tkiBuffer[cIDX], tkiBearishPivot.reserve); - } - - // - if (iConditions.isTKISwitchedToBearish) - { - // - has = - tkiBearishPivot.IsValid() && - tkiBearishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - tkiBearishPivot, - tkiBearishPivots, - maxAllowedPivots // - ); - } - - // - tkiBearishPivot.Clean(); - } - } - - // - // TREND Bullish ... - if (detectTrendBullishPivot) - { - // - if (!trendBullishPivot.IsValid()) - { - // - trendBullishPivot.type = XCA_TREND_BULL; - trendBullishPivot.symbol = iConditions.symbol; - trendBullishPivot.period = iConditions.period; - - // - if (iConditions.isTrendSwitchedToBearish) - { - // - trendBullishPivot.Clean(); - - // - trendBullishPivot.type = XCA_TREND_BULL; - trendBullishPivot.symbol = iConditions.symbol; - trendBullishPivot.period = iConditions.period; - - // - trendBullishPivot.to = pBar.time; - trendBullishPivot.from = pBar.time; - trendBullishPivot.value = iConditions.trendBuffer[pIDX]; - trendBullishPivot.reserve = iConditions.trendBuffer[pIDX]; - } - } - - // - if (iConditions.isTrendBullish) - { - // - trendBullishPivot.from = cBar.time; - - // - Add( - iConditions.trendBuffer[cIDX], - trendBullishPivot.values // - ); - - // - trendBullishPivot.value = - trendBullishPivot.value == 0 - ? iConditions.trendBuffer[cIDX] - : MathMin(iConditions.trendBuffer[cIDX], trendBullishPivot.value); - - // - trendBullishPivot.reserve = - trendBullishPivot.reserve == 0 - ? iConditions.trendBuffer[cIDX] - : MathMax(iConditions.trendBuffer[cIDX], trendBullishPivot.reserve); - } - - // - if (iConditions.isTrendSwitchedToBullish) - { - // - has = - trendBullishPivot.IsValid() && - trendBullishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - trendBullishPivot, - trendBullishPivots, - maxAllowedPivots // - ); - } - - // - trendBullishPivot.Clean(); - } - } - - // - // TREND Bearish ... - if (detectTrendBearishPivot) - { - // - if (!trendBearishPivot.IsValid()) - { - // - trendBearishPivot.type = XCA_TREND_BEAR; - trendBearishPivot.symbol = iConditions.symbol; - trendBearishPivot.period = iConditions.period; - - // - if (iConditions.isTrendSwitchedToBullish) - { - // - trendBearishPivot.Clean(); - - // - trendBearishPivot.type = XCA_TREND_BEAR; - trendBearishPivot.symbol = iConditions.symbol; - trendBearishPivot.period = iConditions.period; - - // - trendBearishPivot.to = pBar.time; - trendBearishPivot.from = pBar.time; - trendBearishPivot.value = iConditions.trendBuffer[pIDX]; - trendBearishPivot.reserve = iConditions.trendBuffer[pIDX]; - } - } - - // - if (iConditions.isTrendBearish) - { - // - trendBearishPivot.from = cBar.time; - - // - Add( - iConditions.trendBuffer[cIDX], - trendBearishPivot.values // - ); - - // - trendBearishPivot.value = - trendBearishPivot.value == 0 - ? iConditions.trendBuffer[cIDX] - : MathMax(iConditions.trendBuffer[cIDX], trendBearishPivot.value); - - // - trendBearishPivot.reserve = - trendBearishPivot.reserve == 0 - ? iConditions.trendBuffer[cIDX] - : MathMin(iConditions.trendBuffer[cIDX], trendBearishPivot.reserve); - } - - // - if (iConditions.isTrendSwitchedToBearish) - { - // - has = - trendBearishPivot.IsValid() && - trendBearishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - trendBearishPivot, - trendBearishPivots, - maxAllowedPivots // - ); - } - - // - trendBearishPivot.Clean(); - } - } - - // - // TKITRND Bullish ... - if (detectTKITRNDBullishPivot) - { - // - if (!tkitrndBullishPivot.IsValid()) - { - // - tkitrndBullishPivot.type = XCA_TKITRND_BULL; - tkitrndBullishPivot.symbol = iConditions.symbol; - tkitrndBullishPivot.period = iConditions.period; - - // - if (!isCTKITRNDBullish && isPTKITRNDBullish) - { - // - tkitrndBullishPivot.Clean(); - - // - tkitrndBullishPivot.type = XCA_TKITRND_BULL; - tkitrndBullishPivot.symbol = iConditions.symbol; - tkitrndBullishPivot.period = iConditions.period; - - // - tkitrndBullishPivot.to = pBar.time; - tkitrndBullishPivot.from = pBar.time; - tkitrndBullishPivot.value = pTKITRNDMin; - tkitrndBullishPivot.reserve = pTKITRNDMax; - } - } - - // - if (isCTKITRNDBullish) - { - // - tkitrndBullishPivot.from = cBar.time; - - // - Add( - cTKITRNDMin, - tkitrndBullishPivot.values // - ); - - // - Add( - cTKITRNDMax, - tkitrndBullishPivot.values // - ); - - // - tkitrndBullishPivot.value = - tkitrndBullishPivot.value == 0 - ? cTKITRNDMin - : MathMin(cTKITRNDMin, tkitrndBullishPivot.value); - - // - tkitrndBullishPivot.reserve = - tkitrndBullishPivot.reserve == 0 - ? cTKITRNDMax - : MathMax(cTKITRNDMax, tkitrndBullishPivot.reserve); - } - - // - if (!isCTKITRNDBullish) - { - // - has = - tkitrndBullishPivot.IsValid() && - tkitrndBullishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - tkitrndBullishPivot, - tkitrndBullishPivots, - maxAllowedPivots // - ); - } - - // - trendBullishPivot.Clean(); - } - } - - // - // TKITRND Bearish ... - if (detectTKITRNDBearishPivot) - { - // - if (!tkitrndBearishPivot.IsValid()) - { - // - tkitrndBearishPivot.type = XCA_TKITRND_BEAR; - tkitrndBearishPivot.symbol = iConditions.symbol; - tkitrndBearishPivot.period = iConditions.period; - - // - if (!isCTKITRNDBearish && isPTKITRNDBearish) - { - // - tkitrndBearishPivot.Clean(); - - // - tkitrndBearishPivot.type = XCA_TKITRND_BEAR; - tkitrndBearishPivot.symbol = iConditions.symbol; - tkitrndBearishPivot.period = iConditions.period; - - // - tkitrndBearishPivot.to = pBar.time; - tkitrndBearishPivot.from = pBar.time; - tkitrndBearishPivot.value = pTKITRNDMax; - tkitrndBearishPivot.reserve = pTKITRNDMin; - } - } - - // - if (isCTKITRNDBearish) - { - // - tkitrndBearishPivot.from = cBar.time; - - // - Add( - cTKITRNDMin, - tkitrndBearishPivot.values // - ); - - // - Add( - cTKITRNDMax, - tkitrndBearishPivot.values // - ); - - // - tkitrndBearishPivot.value = - tkitrndBearishPivot.value == 0 - ? cTKITRNDMax - : MathMax(cTKITRNDMax, tkitrndBearishPivot.value); - - // - tkitrndBearishPivot.reserve = - tkitrndBearishPivot.reserve == 0 - ? cTKITRNDMin - : MathMin(cTKITRNDMin, tkitrndBearishPivot.reserve); - } - - // - if (!isCTKITRNDBearish) - { - // - has = - tkitrndBearishPivot.IsValid() && - tkitrndBearishPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - tkitrndBearishPivot, - tkitrndBearishPivots, - maxAllowedPivots // - ); - } - - // - trendBearishPivot.Clean(); - } - } - - // - // Cycles LL ... - if (detectCycleSameLLPivot) - { - // - // Short Cycle ... - if (!sSameLLPivot.IsValid()) - { - // - sSameLLPivot.type = XCA_LL; - sSameLLPivot.symbol = iConditions.symbol; - sSameLLPivot.period = iConditions.period; - - // - if (isSLLFinishedSame) - { - // - sSameLLPivot.Clean(); - - // - sSameLLPivot.type = XCA_LL; - sSameLLPivot.symbol = iConditions.symbol; - sSameLLPivot.period = iConditions.period; - - // - sSameLLPivot.to = pBar.time; - sSameLLPivot.from = pBar.time; - sSameLLPivot.value = pSLL; - sSameLLPivot.reserve = pSLL; - } - } - - // - if (isCSLLSame) - { - // - sSameLLPivot.from = pBar.time; - - // - double reserve = sSameLLPivot.reserve; - if (pBar.low == pSLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - sSameLLPivot.reserve = reserve; - } - - // - if (isSLLStartSame) - { - // - double reserve = sSameLLPivot.reserve; - if (cBar.low == cSLL) - { - // - reserve = - reserve == 0 - ? cBar.GetDown() - : MathMax(reserve, cBar.GetDown()); - } - if (pBar.low == pSLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - if (reserve == 0 || reserve == sSameLLPivot.value) - { - reserve = sSameLLPivot.value + (5 * points); - } - sSameLLPivot.reserve = reserve; - - // - has = - sSameLLPivot.IsValid() && - sSameLLPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - sSameLLPivot, - sSameLLPivots, - maxAllowedPivots // - ); - } - - // - sSameLLPivot.Clean(); - } - - // - // Medium Cycle ... - if (!mSameLLPivot.IsValid()) - { - // - mSameLLPivot.type = XCA_LL; - mSameLLPivot.symbol = iConditions.symbol; - mSameLLPivot.period = iConditions.period; - - // - if (isMLLFinishedSame) - { - // - mSameLLPivot.Clean(); - - // - mSameLLPivot.type = XCA_LL; - mSameLLPivot.symbol = iConditions.symbol; - mSameLLPivot.period = iConditions.period; - - // - mSameLLPivot.to = pBar.time; - mSameLLPivot.from = pBar.time; - mSameLLPivot.value = pMLL; - mSameLLPivot.reserve = pMLL; - } - } - - // - if (isCMLLSame) - { - // - mSameLLPivot.from = pBar.time; - - // - double reserve = mSameLLPivot.reserve; - if (pBar.low == pMLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - mSameLLPivot.reserve = reserve; - } - - // - if (isMLLStartSame) - { - // - double reserve = mSameLLPivot.reserve; - if (cBar.low == cMLL) - { - // - reserve = - reserve == 0 - ? cBar.GetDown() - : MathMax(reserve, cBar.GetDown()); - } - if (pBar.low == pMLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - if (reserve == 0 || reserve == mSameLLPivot.value) - { - reserve = mSameLLPivot.value + (5 * points); - } - mSameLLPivot.reserve = reserve; - - // - has = - mSameLLPivot.IsValid() && - mSameLLPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - mSameLLPivot, - mSameLLPivots, - maxAllowedPivots // - ); - } - - // - mSameLLPivot.Clean(); - } - - // - // Long Cycle ... - if (!lSameLLPivot.IsValid()) - { - // - lSameLLPivot.type = XCA_LL; - lSameLLPivot.symbol = iConditions.symbol; - lSameLLPivot.period = iConditions.period; - - // - if (isLLLFinishedSame) - { - // - lSameLLPivot.Clean(); - - // - lSameLLPivot.type = XCA_LL; - lSameLLPivot.symbol = iConditions.symbol; - lSameLLPivot.period = iConditions.period; - - // - lSameLLPivot.to = pBar.time; - lSameLLPivot.from = pBar.time; - lSameLLPivot.value = pLLL; - lSameLLPivot.reserve = pLLL; - } - } - - // - if (isCLLLSame) - { - // - lSameLLPivot.from = pBar.time; - - // - double reserve = lSameLLPivot.reserve; - if (pBar.low == pLLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - lSameLLPivot.reserve = reserve; - } - - // - if (isLLLStartSame) - { - // - double reserve = lSameLLPivot.reserve; - if (cBar.low == cLLL) - { - // - reserve = - reserve == 0 - ? cBar.GetDown() - : MathMax(reserve, cBar.GetDown()); - } - if (pBar.low == pLLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - if (reserve == 0 || reserve == lSameLLPivot.value) - { - reserve = lSameLLPivot.value + (5 * points); - } - lSameLLPivot.reserve = reserve; - - // - has = - lSameLLPivot.IsValid() && - lSameLLPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - lSameLLPivot, - lSameLLPivots, - maxAllowedPivots // - ); - } - - // - lSameLLPivot.Clean(); - } - - // - // Hind Cycle ... - if (!hSameLLPivot.IsValid()) - { - // - hSameLLPivot.type = XCA_LL; - hSameLLPivot.symbol = iConditions.symbol; - hSameLLPivot.period = iConditions.period; - - // - if (isHLLFinishedSame) - { - // - hSameLLPivot.Clean(); - - // - hSameLLPivot.type = XCA_LL; - hSameLLPivot.symbol = iConditions.symbol; - hSameLLPivot.period = iConditions.period; - - // - hSameLLPivot.to = pBar.time; - hSameLLPivot.from = pBar.time; - hSameLLPivot.value = pHLL; - hSameLLPivot.reserve = pHLL; - } - } - - // - if (isCHLLSame) - { - // - hSameLLPivot.from = pBar.time; - - // - double reserve = hSameLLPivot.reserve; - if (pBar.low == pHLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - hSameLLPivot.reserve = reserve; - } - - // - if (isHLLStartSame) - { - // - double reserve = hSameLLPivot.reserve; - if (cBar.low == cHLL) - { - // - reserve = - reserve == 0 - ? cBar.GetDown() - : MathMax(reserve, cBar.GetDown()); - } - if (pBar.low == pHLL) - { - // - reserve = - reserve == 0 - ? pBar.GetDown() - : MathMax(reserve, pBar.GetDown()); - } - if (reserve == 0 || reserve == hSameLLPivot.value) - { - reserve = hSameLLPivot.value + (5 * points); - } - hSameLLPivot.reserve = reserve; - - // - has = - hSameLLPivot.IsValid() && - hSameLLPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - hSameLLPivot, - hSameLLPivots, - maxAllowedPivots // - ); - } - - // - hSameLLPivot.Clean(); - } - } - - // - // Cycles HH ... - if (detectCycleSameHHPivot) - { - // - // Short Cycle ... - if (!sSameHHPivot.IsValid()) - { - // - sSameHHPivot.type = XCA_HH; - sSameHHPivot.symbol = iConditions.symbol; - sSameHHPivot.period = iConditions.period; - - // - if (isSHHFinishedSame) - { - // - sSameHHPivot.Clean(); - - // - sSameHHPivot.type = XCA_HH; - sSameHHPivot.symbol = iConditions.symbol; - sSameHHPivot.period = iConditions.period; - - // - sSameHHPivot.to = pBar.time; - sSameHHPivot.from = pBar.time; - sSameHHPivot.value = pSHH; - sSameHHPivot.reserve = pSHH; - } - } - - // - if (isCSHHSame) - { - // - sSameHHPivot.from = pBar.time; - - // - double reserve = sSameHHPivot.reserve; - if (pBar.high == pSHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - sSameHHPivot.reserve = reserve; - } - - // - if (isSHHStartSame) - { - // - double reserve = sSameHHPivot.reserve; - if (cBar.high == cSHH) - { - // - reserve = - reserve == 0 - ? cBar.GetUp() - : MathMin(reserve, cBar.GetUp()); - } - if (pBar.high == pSHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - if (reserve == 0 || reserve == sSameHHPivot.value) - { - reserve = sSameHHPivot.value + (5 * points); - } - sSameHHPivot.reserve = reserve; - - // - has = - sSameHHPivot.IsValid() && - sSameHHPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - sSameHHPivot, - sSameHHPivots, - maxAllowedPivots // - ); - } - - // - sSameHHPivot.Clean(); - } - - // - // Medium Cycle ... - if (!mSameHHPivot.IsValid()) - { - // - mSameHHPivot.type = XCA_HH; - mSameHHPivot.symbol = iConditions.symbol; - mSameHHPivot.period = iConditions.period; - - // - if (isMHHFinishedSame) - { - // - mSameHHPivot.Clean(); - - // - mSameHHPivot.type = XCA_HH; - mSameHHPivot.symbol = iConditions.symbol; - mSameHHPivot.period = iConditions.period; - - // - mSameHHPivot.to = pBar.time; - mSameHHPivot.from = pBar.time; - mSameHHPivot.value = pMHH; - mSameHHPivot.reserve = pMHH; - } - } - - // - if (isCMHHSame) - { - // - mSameHHPivot.from = pBar.time; - - // - double reserve = mSameHHPivot.reserve; - if (pBar.high == pMHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - mSameHHPivot.reserve = reserve; - } - - // - if (isMHHStartSame) - { - // - double reserve = mSameHHPivot.reserve; - if (cBar.high == cMHH) - { - // - reserve = - reserve == 0 - ? cBar.GetUp() - : MathMin(reserve, cBar.GetUp()); - } - if (pBar.high == pMHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - if (reserve == 0 || reserve == mSameHHPivot.value) - { - reserve = mSameHHPivot.value + (5 * points); - } - mSameHHPivot.reserve = reserve; - - // - has = - mSameHHPivot.IsValid() && - mSameHHPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - mSameHHPivot, - mSameHHPivots, - maxAllowedPivots // - ); - } - - // - mSameHHPivot.Clean(); - } - - // - // Long Cycle ... - if (!lSameHHPivot.IsValid()) - { - // - lSameHHPivot.type = XCA_HH; - lSameHHPivot.symbol = iConditions.symbol; - lSameHHPivot.period = iConditions.period; - - // - if (isLHHFinishedSame) - { - // - lSameHHPivot.Clean(); - - // - lSameHHPivot.type = XCA_HH; - lSameHHPivot.symbol = iConditions.symbol; - lSameHHPivot.period = iConditions.period; - - // - lSameHHPivot.to = pBar.time; - lSameHHPivot.from = pBar.time; - lSameHHPivot.value = pLHH; - lSameHHPivot.reserve = pLHH; - } - } - - // - if (isCLHHSame) - { - // - lSameHHPivot.from = pBar.time; - - // - double reserve = lSameHHPivot.reserve; - if (pBar.high == pLHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - lSameHHPivot.reserve = reserve; - } - - // - if (isLHHStartSame) - { - // - double reserve = lSameHHPivot.reserve; - if (cBar.high == cLHH) - { - // - reserve = - reserve == 0 - ? cBar.GetUp() - : MathMin(reserve, cBar.GetUp()); - } - if (pBar.high == pLHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - if (reserve == 0 || reserve == lSameHHPivot.value) - { - reserve = lSameHHPivot.value + (5 * points); - } - lSameHHPivot.reserve = reserve; - - // - has = - lSameHHPivot.IsValid() && - lSameHHPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - lSameHHPivot, - lSameHHPivots, - maxAllowedPivots // - ); - } - - // - lSameHHPivot.Clean(); - } - - // - // Hind Cycle ... - if (!hSameHHPivot.IsValid()) - { - // - hSameHHPivot.type = XCA_HH; - hSameHHPivot.symbol = iConditions.symbol; - hSameHHPivot.period = iConditions.period; - - // - if (isHHHFinishedSame) - { - // - hSameHHPivot.Clean(); - - // - hSameHHPivot.type = XCA_HH; - hSameHHPivot.symbol = iConditions.symbol; - hSameHHPivot.period = iConditions.period; - - // - hSameHHPivot.to = pBar.time; - hSameHHPivot.from = pBar.time; - hSameHHPivot.value = pHHH; - hSameHHPivot.reserve = pHHH; - } - } - - // - if (isCHHHSame) - { - // - hSameHHPivot.from = pBar.time; - - // - double reserve = hSameHHPivot.reserve; - if (pBar.high == pHHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - hSameHHPivot.reserve = reserve; - } - - // - if (isHHHStartSame) - { - // - double reserve = hSameHHPivot.reserve; - if (cBar.high == cHHH) - { - // - reserve = - reserve == 0 - ? cBar.GetUp() - : MathMin(reserve, cBar.GetUp()); - } - if (pBar.high == pHHH) - { - // - reserve = - reserve == 0 - ? pBar.GetUp() - : MathMin(reserve, pBar.GetUp()); - } - if (reserve == 0 || reserve == hSameHHPivot.value) - { - reserve = hSameHHPivot.value + (5 * points); - } - hSameHHPivot.reserve = reserve; - - // - has = - hSameHHPivot.IsValid() && - hSameHHPivot.GetAge() >= pivotVerifications; - if (has) - { - // - AddPivot( - hSameHHPivot, - hSameHHPivots, - maxAllowedPivots // - ); - } - - // - hSameHHPivot.Clean(); - } - } - - // - // RSI Peak ... - if (detectRSIPeakPivot) - { - // - if (isRSIPeak) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_RSI_PEAK; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMin(iPivot.values); - - // - AddPivot( - iPivot, - rsiPeakPivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // RSI Vale ... - if (detectRSIValePivot) - { - // - if (isRSIVale) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.low; - iPivot.type = XCA_RSI_VALE; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMax(iPivot.values); - - // - AddPivot( - iPivot, - rsiValePivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // RSI Crossed Over OS ... - if (detectRSICrossedOverOSPivot) - { - // - if (isRSIBullishVPattern) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.low; - iPivot.type = XCA_RSI_COOS; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMax(iPivot.values); - - // - AddPivot( - iPivot, - rsiCrossedOverOSPivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // RSI Crossed Under OS ... - if (detectRSICrossedUnderOBPivot) - { - // - if (isRSIBearishVPattern) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_RSI_CUOB; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMin(iPivot.values); - - // - AddPivot( - iPivot, - rsiCrossedUnderOBPivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // CCI Peak ... - if (detectCCIPeakPivot) - { - // - if (isCCIPeak) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_CCI_PEAK; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMin(iPivot.values); - - // - AddPivot( - iPivot, - cciPeakPivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // CCI Vale ... - if (detectCCIValePivot) - { - // - if (isCCIVale) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.low; - iPivot.type = XCA_CCI_VALE; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMax(iPivot.values); - - // - AddPivot( - iPivot, - cciValePivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // CCI Crossed Over OS ... - if (detectCCICrossedOverOSPivot) - { - // - if (isCCIBullishVPattern) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.low; - iPivot.type = XCA_CCI_COOS; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.low, - iPivot.values // - ); - Add( - pBar.low, - iPivot.values // - ); - Add( - p2Bar.low, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMax(iPivot.values); - - // - AddPivot( - iPivot, - cciCrossedOverOSPivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - // CCI Crossed Under OS ... - if (detectCCICrossedUnderOBPivot) - { - // - if (isCCIBearishVPattern) - { - // - XCAPivot iPivot; - - // - iPivot.to = cBar.time; - iPivot.from = p2Bar.time; - iPivot.value = pBar.high; - iPivot.type = XCA_CCI_CUOB; - iPivot.symbol = cBar.symbol; - iPivot.period = cBar.period; - - // - Add( - cBar.high, - iPivot.values // - ); - Add( - pBar.high, - iPivot.values // - ); - Add( - p2Bar.high, - iPivot.values // - ); - Add( - cBar.close, - iPivot.values // - ); - Add( - pBar.close, - iPivot.values // - ); - Add( - p2Bar.close, - iPivot.values // - ); - - // - iPivot.reserve = GetMin(iPivot.values); - - // - AddPivot( - iPivot, - cciCrossedUnderOBPivots, - maxAllowedPivots // - ); - - // - iPivot.Clean(); - } - } - - // - start++; - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - fvgBox.Clean(); - iConditions.Clean(); - } - - // - } - - // - void Validate( - XBoxZone &unAvailableBoxes[], - int barIndex = 0 // - ) - { - // - // Do All Pivots Validation ... - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - XCAPivot tmp[]; - bool has = false; - - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - - // - // Implement Validation Senarios ... - - // - // PEAKS ... - - // - has = HasPeakPivots(); - if (has) - { - // - Copy( - peakPivots, - tmp // - ); - Clean(peakPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - peakPivots // - ); - } - } - Clean(tmp); - } - - // - // VALES ... - - // - has = HasValePivots(); - if (has) - { - // - Copy( - valePivots, - tmp // - ); - Clean(valePivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - valePivots // - ); - } - } - Clean(tmp); - } - - // - // PEAK SWH RES ... - - // - has = HasPeakSWHResPivots(); - if (has) - { - // - Copy( - peakSWHResPivots, - tmp // - ); - Clean(peakSWHResPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - peakSWHResPivots // - ); - } - } - Clean(tmp); - } - - // - // VALE SWL SUP ... - - // - has = HasValeSWLSupPivots(); - if (has) - { - // - Copy( - valeSWLSupPivots, - tmp // - ); - Clean(valeSWLSupPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - valeSWLSupPivots // - ); - } - } - Clean(tmp); - } - - // - // SWING HIGH ... - - // - has = HasSWHPivots(); - if (has) - { - // - Copy( - swhPivots, - tmp // - ); - Clean(swhPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - swhPivots // - ); - } - } - Clean(tmp); - } - - // - // SWING LOW ... - - // - has = HasSWLPivots(); - if (has) - { - // - Copy( - swlPivots, - tmp // - ); - Clean(swlPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - swlPivots // - ); - } - } - Clean(tmp); - } - - // - // KI ... - - // - has = HasKIBullishPivots(); - if (has) - { - // - Copy( - kiBullishPivots, - tmp // - ); - Clean(kiBullishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - kiBullishPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasKIBearishPivots(); - if (has) - { - // - Copy( - kiBearishPivots, - tmp // - ); - Clean(kiBearishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - kiBearishPivots // - ); - } - } - Clean(tmp); - } - - // - // TKI ... - - // - has = HasTKIBullishPivots(); - if (has) - { - // - Copy( - tkiBullishPivots, - tmp // - ); - Clean(tkiBullishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - tkiBullishPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasTKIBearishPivots(); - if (has) - { - // - Copy( - tkiBearishPivots, - tmp // - ); - Clean(tkiBearishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - tkiBearishPivots // - ); - } - } - Clean(tmp); - } - - // - // FVG ... - - // - has = HasFVGBullishPivots(); - if (has) - { - // - Copy( - fvgBullishPivots, - tmp // - ); - Clean(fvgBullishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - fvgBullishPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasFVGBearishPivots(); - if (has) - { - // - Copy( - fvgBearishPivots, - tmp // - ); - Clean(fvgBearishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - fvgBearishPivots // - ); - } - } - Clean(tmp); - } - - // - // PVFVG ... - XCAPVPivot tmpPVFVG[]; - - // - has = HasPVFVGBullishPivots(); - if (has) - { - // - Copy( - pvFVGBullishPivots, - tmpPVFVG // - ); - Clean(pvFVGBullishPivots); - while (HasChild(tmpPVFVG)) - { - // - XCAPVPivot iPVFVG = tmpPVFVG[0]; - ArrayRemove( - tmpPVFVG, - 0, - 1 // - ); - - // - XCAPivot tmpFVGs[]; - Copy( - iPVFVG.pivots, - tmpFVGs // - ); - Clean(iPVFVG.pivots); - while (HasChild(tmpFVGs)) - { - // - XCAPivot iPivot = tmpFVGs[0]; - ArrayRemove( - tmpFVGs, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - iPVFVG.pivots // - ); - } - } - Clean(tmpFVGs); - - // - if (HasChild(iPVFVG.pivots)) - { - // - AddRef( - iPVFVG, - pvFVGBullishPivots // - ); - } - } - Clean(tmp); - Clean(tmpPVFVG); - } - - // - has = HasPVFVGBearishPivots(); - if (has) - { - // - Copy( - pvFVGBearishPivots, - tmpPVFVG // - ); - Clean(pvFVGBearishPivots); - while (HasChild(tmpPVFVG)) - { - // - XCAPVPivot iPVFVG = tmpPVFVG[0]; - ArrayRemove( - tmpPVFVG, - 0, - 1 // - ); - - // - XCAPivot tmpFVGs[]; - Copy( - iPVFVG.pivots, - tmpFVGs // - ); - Clean(iPVFVG.pivots); - while (HasChild(tmpFVGs)) - { - // - XCAPivot iPivot = tmpFVGs[0]; - ArrayRemove( - tmpFVGs, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - iPVFVG.pivots // - ); - } - } - Clean(tmpFVGs); - - // - if (HasChild(iPVFVG.pivots)) - { - // - AddRef( - iPVFVG, - pvFVGBearishPivots // - ); - } - } - Clean(tmp); - Clean(tmpPVFVG); - } - - // - // TREND ... - - // - has = HasTrendBullishPivots(); - if (has) - { - // - Copy( - trendBullishPivots, - tmp // - ); - Clean(trendBullishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - trendBullishPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasTrendBearishPivots(); - if (has) - { - // - Copy( - trendBearishPivots, - tmp // - ); - Clean(trendBearishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - trendBearishPivots // - ); - } - } - Clean(tmp); - } - - // - // TKITRND ... - - // - has = HasTKITRNDBullishPivots(); - if (has) - { - // - Copy( - tkitrndBullishPivots, - tmp // - ); - Clean(tkitrndBullishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - tkitrndBullishPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasTKITRNDBearishPivots(); - if (has) - { - // - Copy( - tkitrndBearishPivots, - tmp // - ); - Clean(tkitrndBearishPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - tkitrndBearishPivots // - ); - } - } - Clean(tmp); - } - - // - // SAME CYCLES HH / LL ... - - // - has = HasSSameLLPivots(); - if (has) - { - // - Copy( - sSameLLPivots, - tmp // - ); - Clean(sSameLLPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - sSameLLPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasSSameHHPivots(); - if (has) - { - // - Copy( - sSameHHPivots, - tmp // - ); - Clean(sSameHHPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - sSameHHPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasMSameLLPivots(); - if (has) - { - // - Copy( - mSameLLPivots, - tmp // - ); - Clean(mSameLLPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - mSameLLPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasMSameHHPivots(); - if (has) - { - // - Copy( - mSameHHPivots, - tmp // - ); - Clean(mSameHHPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - mSameHHPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasLSameLLPivots(); - if (has) - { - // - Copy( - lSameLLPivots, - tmp // - ); - Clean(lSameLLPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - lSameLLPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasLSameHHPivots(); - if (has) - { - // - Copy( - lSameHHPivots, - tmp // - ); - Clean(lSameHHPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - lSameHHPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasHSameLLPivots(); - if (has) - { - // - Copy( - hSameLLPivots, - tmp // - ); - Clean(hSameLLPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - hSameLLPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasHSameHHPivots(); - if (has) - { - // - Copy( - hSameHHPivots, - tmp // - ); - Clean(hSameHHPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - hSameHHPivots // - ); - } - } - Clean(tmp); - } - - // - // OSCS ... - - // - // RSI ... - - // - has = HasRSIPeakPivots(); - if (has) - { - // - Copy( - rsiPeakPivots, - tmp // - ); - Clean(rsiPeakPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - rsiPeakPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasRSIValePivots(); - if (has) - { - // - Copy( - rsiValePivots, - tmp // - ); - Clean(rsiValePivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - rsiValePivots // - ); - } - } - Clean(tmp); - } - - // - has = HasRSICrossedOverOSPivots(); - if (has) - { - // - Copy( - rsiCrossedOverOSPivots, - tmp // - ); - Clean(rsiCrossedOverOSPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - rsiCrossedOverOSPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasRSICrossedUnderOBPivots(); - if (has) - { - // - Copy( - rsiCrossedUnderOBPivots, - tmp // - ); - Clean(rsiCrossedUnderOBPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - rsiCrossedUnderOBPivots // - ); - } - } - Clean(tmp); - } - - // - // CCI ... - - // - has = HasCCIPeakPivots(); - if (has) - { - // - Copy( - cciPeakPivots, - tmp // - ); - Clean(cciPeakPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - cciPeakPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasCCIValePivots(); - if (has) - { - // - Copy( - cciValePivots, - tmp // - ); - Clean(cciValePivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - cciValePivots // - ); - } - } - Clean(tmp); - } - - // - has = HasCCICrossedOverOSPivots(); - if (has) - { - // - Copy( - cciCrossedOverOSPivots, - tmp // - ); - Clean(cciCrossedOverOSPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - cciCrossedOverOSPivots // - ); - } - } - Clean(tmp); - } - - // - has = HasCCICrossedUnderOBPivots(); - if (has) - { - // - Copy( - cciCrossedUnderOBPivots, - tmp // - ); - Clean(cciCrossedUnderOBPivots); - while (HasChild(tmp)) - { - // - XCAPivot iPivot = tmp[0]; - ArrayRemove( - tmp, - 0, - 1 // - ); - - // - has = IsPivotBreaked( - iPivot, - unAvailableBoxes, - barIndex // - ); - if (!has) - { - // - AddRef( - iPivot, - cciCrossedUnderOBPivots // - ); - } - } - Clean(tmp); - } - - // - // PVTICKS ... - - // - XCAPVTick tmpTicks[]; - - // - has = HasPeakTicks(); - if (has) - { - // - Copy( - peakTicks, - tmpTicks // - ); - Clean(peakTicks); - while (HasChild(tmpTicks)) - { - // - XCAPVTick iPVTick = tmpTicks[0]; - ArrayRemove( - tmpTicks, - 0, - 1 // - ); - - // - XBoxZone iBox; - bool isBoxBreaked = false; - has = iPVTick.GetMaxVolumeBox(iBox); - if (has) - { - // - isBoxBreaked = IsBoxBreaked( - iBox, - unAvailableBoxes, - barIndex // - ); - } - - // - has = IsPivotBreaked( - iPVTick.pivot, - unAvailableBoxes, - barIndex // - ); - if (!has && !isBoxBreaked) - { - // - AddRef( - iPVTick, - peakTicks // - ); - } - } - Clean(tmpTicks); - } - - // - has = HasValeTicks(); - if (has) - { - // - Copy( - valeTicks, - tmpTicks // - ); - Clean(valeTicks); - while (HasChild(tmpTicks)) - { - // - XCAPVTick iPVTick = tmpTicks[0]; - ArrayRemove( - tmpTicks, - 0, - 1 // - ); - - // - XBoxZone iBox; - bool isBoxBreaked = false; - has = iPVTick.GetMaxVolumeBox(iBox); - if (has) - { - // - isBoxBreaked = IsBoxBreaked( - iBox, - unAvailableBoxes, - barIndex // - ); - } - - // - has = IsPivotBreaked( - iPVTick.pivot, - unAvailableBoxes, - barIndex // - ); - if (!has && !isBoxBreaked) - { - // - AddRef( - iPVTick, - valeTicks // - ); - } - } - Clean(tmpTicks); - } - - // - Clean(tmp); - Clean(tmpPVFVG); - Clean(tmpTicks); - } - - // - int FillBullishBoxes( - XBoxZone &boxes[] // - ) - { - // - int result = 0; - - // - int count = 0; - bool has = false; - - // - Clean(boxes); - - // - has = HasSWLPivots(); - if (has) - { - // - count = CountSWLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = swlPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasValePivots(); - if (has) - { - // - count = CountValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = valePivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasSSameLLPivots(); - if (has) - { - // - count = CountSSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = sSameLLPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasMSameLLPivots(); - if (has) - { - // - count = CountMSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = mSameLLPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasLSameLLPivots(); - if (has) - { - // - count = CountLSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = lSameLLPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasHSameLLPivots(); - if (has) - { - // - count = CountHSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = hSameLLPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasKIBullishPivots(); - if (has) - { - // - count = CountKIBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = kiBullishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasFVGBullishPivots(); - if (has) - { - // - count = CountFVGBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = fvgBullishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasValeSWLSupPivots(); - if (has) - { - // - count = CountValeSWLSupPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = valeSWLSupPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasTKIBullishPivots(); - if (has) - { - // - count = CountTKIBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = tkiBullishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasTrendBullishPivots(); - if (has) - { - // - count = CountTrendBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = trendBullishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasTKITRNDBullishPivots(); - if (has) - { - // - count = CountTKITRNDBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = tkitrndBullishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasRSIValePivots(); - if (has) - { - // - count = CountRSIValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = rsiValePivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasRSICrossedOverOSPivots(); - if (has) - { - // - count = CountRSICrossedOverOSPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = rsiCrossedOverOSPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasCCIValePivots(); - if (has) - { - // - count = CountCCIValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = cciValePivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasCCICrossedOverOSPivots(); - if (has) - { - // - count = CountCCICrossedOverOSPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = cciCrossedOverOSPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - result = ArraySize(boxes); - - // - return result; - } - - // - int FillBearishBoxes( - XBoxZone &boxes[] // - ) - { - // - int result = 0; - - // - int count = 0; - bool has = false; - - // - Clean(boxes); - - // - has = HasSWHPivots(); - if (has) - { - // - count = CountSWHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = swhPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasPeakPivots(); - if (has) - { - // - count = CountPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = peakPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasSSameHHPivots(); - if (has) - { - // - count = CountSSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = sSameHHPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasMSameHHPivots(); - if (has) - { - // - count = CountMSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = mSameHHPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasLSameHHPivots(); - if (has) - { - // - count = CountLSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = lSameHHPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasHSameHHPivots(); - if (has) - { - // - count = CountHSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = hSameHHPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasKIBearishPivots(); - if (has) - { - // - count = CountKIBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = kiBearishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasFVGBearishPivots(); - if (has) - { - // - count = CountFVGBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = fvgBearishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasPeakSWHResPivots(); - if (has) - { - // - count = CountPeakSWHResPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = peakSWHResPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasTKIBearishPivots(); - if (has) - { - // - count = CountTKIBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = tkiBearishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasTrendBearishPivots(); - if (has) - { - // - count = CountTrendBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = trendBearishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasTKITRNDBearishPivots(); - if (has) - { - // - count = CountTKITRNDBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = tkitrndBearishPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasRSIPeakPivots(); - if (has) - { - // - count = CountRSIPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = rsiPeakPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasRSICrossedUnderOBPivots(); - if (has) - { - // - count = CountRSICrossedUnderOBPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = rsiCrossedUnderOBPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasCCIPeakPivots(); - if (has) - { - // - count = CountCCIPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = cciPeakPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - has = HasCCICrossedUnderOBPivots(); - if (has) - { - // - count = CountCCICrossedUnderOBPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = cciCrossedUnderOBPivots[i].AsBox(iBox); - if (has) - { - // - AddRef( - iBox, - boxes // - ); - } - - // - iBox.Clean(); - } - } - - // - result = ArraySize(boxes); - - // - return result; - } - - // - // POI Handlers ... - - // - // PEAK ... - - // - bool HasPeakPivots() - { - return HasChild(peakPivots); - } - - // - int CountPeakPivots() - { - return ArraySize(peakPivots); - } - - // - // VALE ... - - // - bool HasValePivots() - { - return HasChild(valePivots); - } - - // - int CountValePivots() - { - return ArraySize(valePivots); - } - - // - // PEAK SWH Res ... - - // - bool HasPeakSWHResPivots() - { - return HasChild(peakSWHResPivots); - } - - // - int CountPeakSWHResPivots() - { - return ArraySize(peakSWHResPivots); - } - - // - // VALE SWL Sup ... - - // - bool HasValeSWLSupPivots() - { - return HasChild(valeSWLSupPivots); - } - - // - int CountValeSWLSupPivots() - { - return ArraySize(valeSWLSupPivots); - } - - // - // SWING High ... - - // - bool HasSWHPivots() - { - return HasChild(swhPivots); - } - - // - int CountSWHPivots() - { - return ArraySize(swhPivots); - } - - // - // SWING Low ... - - // - bool HasSWLPivots() - { - return HasChild(swlPivots); - } - - // - int CountSWLPivots() - { - return ArraySize(swlPivots); - } - - // - // KI ... - - // - bool HasKIBullishPivots() - { - return HasChild(kiBullishPivots); - } - - // - int CountKIBullishPivots() - { - return ArraySize(kiBullishPivots); - } - - // - bool HasKIBearishPivots() - { - return HasChild(kiBearishPivots); - } - - // - int CountKIBearishPivots() - { - return ArraySize(kiBearishPivots); - } - - // - // TKI ... - - // - bool HasTKIBullishPivots() - { - return HasChild(tkiBullishPivots); - } - - // - int CountTKIBullishPivots() - { - return ArraySize(tkiBullishPivots); - } - - // - bool HasTKIBearishPivots() - { - return HasChild(tkiBearishPivots); - } - - // - int CountTKIBearishPivots() - { - return ArraySize(tkiBearishPivots); - } - - // - // FVG ... - - // - bool HasFVGBullishPivots() - { - return HasChild(fvgBullishPivots); - } - - // - int CountFVGBullishPivots() - { - return ArraySize(fvgBullishPivots); - } - - // - bool HasFVGBearishPivots() - { - return HasChild(fvgBearishPivots); - } - - // - int CountFVGBearishPivots() - { - return ArraySize(fvgBearishPivots); - } - - // - // PVFVG ... - - // - bool HasPVFVGBullishPivots() - { - return HasChild(pvFVGBullishPivots); - } - - // - int CountPVFVGBullishPivots() - { - return ArraySize(pvFVGBullishPivots); - } - - // - bool HasPVFVGBearishPivots() - { - return HasChild(pvFVGBearishPivots); - } - - // - int CountPVFVGBearishPivots() - { - return ArraySize(pvFVGBearishPivots); - } - - // - // TREND ... - - // - bool HasTrendBullishPivots() - { - return HasChild(trendBullishPivots); - } - - // - int CountTrendBullishPivots() - { - return ArraySize(trendBullishPivots); - } - - // - bool HasTrendBearishPivots() - { - return HasChild(trendBearishPivots); - } - - // - int CountTrendBearishPivots() - { - return ArraySize(trendBearishPivots); - } - - // - // TKITRND ... - - // - bool HasTKITRNDBullishPivots() - { - return HasChild(tkitrndBullishPivots); - } - - // - int CountTKITRNDBullishPivots() - { - return ArraySize(tkitrndBullishPivots); - } - - // - bool HasTKITRNDBearishPivots() - { - return HasChild(tkitrndBearishPivots); - } - - // - int CountTKITRNDBearishPivots() - { - return ArraySize(tkitrndBearishPivots); - } - - // - // SAME CYCLES HH / LL ... - - // - bool HasSSameLLPivots() - { - return HasChild(sSameLLPivots); - } - - // - int CountSSameLLPivots() - { - return ArraySize(sSameLLPivots); - } - - // - bool HasMSameLLPivots() - { - return HasChild(mSameLLPivots); - } - - // - int CountMSameLLPivots() - { - return ArraySize(mSameLLPivots); - } - - // - bool HasLSameLLPivots() - { - return HasChild(lSameLLPivots); - } - - // - int CountLSameLLPivots() - { - return ArraySize(lSameLLPivots); - } - - // - bool HasHSameLLPivots() - { - return HasChild(hSameLLPivots); - } - - // - int CountHSameLLPivots() - { - return ArraySize(hSameLLPivots); - } - - // - bool HasSSameHHPivots() - { - return HasChild(sSameHHPivots); - } - - // - int CountSSameHHPivots() - { - return ArraySize(sSameHHPivots); - } - - // - bool HasMSameHHPivots() - { - return HasChild(mSameHHPivots); - } - - // - int CountMSameHHPivots() - { - return ArraySize(mSameHHPivots); - } - - // - bool HasLSameHHPivots() - { - return HasChild(lSameHHPivots); - } - - // - int CountLSameHHPivots() - { - return ArraySize(lSameHHPivots); - } - - // - bool HasHSameHHPivots() - { - return HasChild(hSameHHPivots); - } - - // - int CountHSameHHPivots() - { - return ArraySize(hSameHHPivots); - } - - // - // OSCS ... - - // - // RSI ... - - // - bool HasRSIPeakPivots() - { - return HasChild(rsiPeakPivots); - } - - // - int CountRSIPeakPivots() - { - return ArraySize(rsiPeakPivots); - } - - // - bool HasRSIValePivots() - { - return HasChild(rsiValePivots); - } - - // - int CountRSIValePivots() - { - return ArraySize(rsiValePivots); - } - - // - bool HasRSICrossedOverOSPivots() - { - return HasChild(rsiCrossedOverOSPivots); - } - - // - int CountRSICrossedOverOSPivots() - { - return ArraySize(rsiCrossedOverOSPivots); - } - - // - bool HasRSICrossedUnderOBPivots() - { - return HasChild(rsiCrossedUnderOBPivots); - } - - // - int CountRSICrossedUnderOBPivots() - { - return ArraySize(rsiCrossedUnderOBPivots); - } - - // - // CCI ... - - // - bool HasCCIPeakPivots() - { - return HasChild(cciPeakPivots); - } - - // - int CountCCIPeakPivots() - { - return ArraySize(cciPeakPivots); - } - - // - bool HasCCIValePivots() - { - return HasChild(cciValePivots); - } - - // - int CountCCIValePivots() - { - return ArraySize(cciValePivots); - } - - // - bool HasCCICrossedOverOSPivots() - { - return HasChild(cciCrossedOverOSPivots); - } - - // - int CountCCICrossedOverOSPivots() - { - return ArraySize(cciCrossedOverOSPivots); - } - - // - bool HasCCICrossedUnderOBPivots() - { - return HasChild(cciCrossedUnderOBPivots); - } - - // - int CountCCICrossedUnderOBPivots() - { - return ArraySize(cciCrossedUnderOBPivots); - } - - // - // PVTICKS ... - - // - bool HasPeakTicks() - { - return HasChild(peakTicks); - } - - // - int CountPeakTicks() - { - return ArraySize(peakTicks); - } - - // - bool HasValeTicks() - { - return HasChild(valeTicks); - } - - // - int CountValeTicks() - { - return ArraySize(valeTicks); - } - - // - // Protected ... - protected: - // - // Props ... - - // - // Prrivate ... - private: - // - // Props ... - - // - XCPOIDrawer *drawer; - XCXCAEAHelper *helper; - XCBarAnalyser *barAnalyser; - - // - bool CheckPivotCommons( - XCAPivot &pivot, - XBoxZone &box, - XBoxZone &unAvailableBoxes[], - int barIndex = 0 // - ) - { - // - bool result = false; - - // - box.Clean(); - - // - barIndex = NormalizeInt(barIndex, 0); - - // - result = pivot.IsValid(); - if (!result) - { - return result; - } - - // - int pivotToIDX = pivot.ToIndex(); - - // - result = pivotToIDX > barIndex; - if (!result) - { - return result; - } - - // - result = pivot.AsBox(box); - if (!result) - { - // - box.Clean(); - return result; - } - - // - return result; - } - - // - bool CheckPivotIsAvailable( - XBoxZone &pivotBox, - XBoxZone &unAvailableBoxes[] // - ) - { - // - bool result = false; - - // - result = pivotBox.IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - bool isExists = FindBoxIndex( - idx, - pivotBox, - unAvailableBoxes // - ); - result = !isExists; - - // - return result; - } - - // - bool IsPivotBreaked( - XCAPivot &pivot, - XBoxZone &unAvailableBoxes[], - int barIndex = 0 // - ) - { - // - bool result = false; - - // - XBoxZone iBox; - result = CheckPivotCommons( - pivot, - iBox, - unAvailableBoxes, - barIndex // - ); - if (!result) - { - // - iBox.Clean(); - return result; - } - - // - // Check Box is Available Or Not ... - bool isAvailable = CheckPivotIsAvailable( - iBox, - unAvailableBoxes // - ); - if (!isAvailable) - { - // - iBox.Clean(); - - // - // Assume UnAvailable Boes as Breaked ... - result = true; - return result; - } - - // - bool isBullish = iBox.IsBullish(); - double boundary = - isBullish - ? iBox.lower - : iBox.upper; - - // - int toIDX = iBox.ToIndex(); - - // - // for validating Box Break we have to wait At Least 3 Bars Close - // out of Box Boundary ... - int barsLength = 3; - - // - int startCheckBreaktionBarIndex = toIDX - barsLength; - result = startCheckBreaktionBarIndex > 0 && - barIndex < startCheckBreaktionBarIndex; - if (!result) - { - // - iBox.Clean(); - return result; - } - - // - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - for (int i = barIndex; i < startCheckBreaktionBarIndex; i++) - { - // - result = cBar.Init( - iBox.symbol, - iBox.period, - i + 1 // - ); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(p2Bar); - if (!result) - { - // - iBox.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - break; - } - - // - bool isBullishBreaked = - isBullish && - cBar.close < boundary && - pBar.close < boundary && - p2Bar.close < boundary; - - // - bool isBearishBreaked = - !isBullish && - cBar.close > boundary && - pBar.close > boundary && - p2Bar.close > boundary; - - // - result = isBullishBreaked || - isBearishBreaked; - if (result) - { - break; - } - - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - } - - // - iBox.Clean(); - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - return result; - } - - // - bool IsBoxBreaked( - XBoxZone &box, - XBoxZone &unAvailableBoxes[], - int barIndex = 0 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeInt(barIndex, 0); - - // - result = box.IsValid(); - if (!result) - { - // - // Assume Invalid Boxes as Broken ... - return true; - } - - // - int idx = -1; - result = FindBoxIndex( - idx, - box, - unAvailableBoxes // - ); - if (result) - { - // - // Assume UnAvailable Boxes as Broken ... - return result; - } - - // - int toIDX = box.ToIndex(); - result = toIDX > barIndex; - if (!result) - { - return result; - } - - // - bool isBullish = box.IsBullish(); - double boundary = - isBullish - ? box.lower - : box.upper; - - // - // for validating Box Break we have to wait At Least 3 Bars Close - // out of Box Boundary ... - int barsLength = 3; - - // - int startCheckBreaktionBarIndex = toIDX - barsLength; - result = startCheckBreaktionBarIndex > 0 && - barIndex < startCheckBreaktionBarIndex; - if (!result) - { - return result; - } - - // - XOHCL cBar; - XOHCL pBar; - XOHCL p2Bar; - for (int i = barIndex; i < startCheckBreaktionBarIndex; i++) - { - // - result = cBar.Init( - box.symbol, - box.period, - i + 1 // - ); - result = - result && - cBar.GetPreviousBar(pBar); - result = - result && - pBar.GetPreviousBar(p2Bar); - if (!result) - { - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - break; - } - - // - bool isBullishBreaked = - isBullish && - cBar.close < boundary && - pBar.close < boundary && - p2Bar.close < boundary; - - // - bool isBearishBreaked = - !isBullish && - cBar.close > boundary && - pBar.close > boundary && - p2Bar.close > boundary; - - // - result = isBullishBreaked || - isBearishBreaked; - if (result) - { - break; - } - - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - } - - // - cBar.Clean(); - pBar.Clean(); - p2Bar.Clean(); - - // - return result; - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/xcaea.x-poi.drawer.class.bkp.mq5 b/Documents/BKP/xcaea.x-poi.drawer.class.bkp.mq5 deleted file mode 100644 index f0f59a75..00000000 --- a/Documents/BKP/xcaea.x-poi.drawer.class.bkp.mq5 +++ /dev/null @@ -1,2329 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEAPOIDrawer ... -// Description: Class for XCAEA POI Drawer ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA POI Drawer" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" - -// -// Definitions ... - -// -// Implementations ... -class XCXCAEAPOIDrawer : public XCBase -{ - // - // Public ... - public: - // - // Props ... - - // - bool ignoreUpdateOSCTos; - bool drawTrendPivotsOnlySelectedFVG; - - // - // Drawers ... - bool drawTrendLine; - bool drawTickPivots; - bool drawVolumePivots; - bool drawRSIPeakPivots; - bool drawRSIValePivots; - bool drawCCIPeakPivots; - bool drawCCIValePivots; - bool drawFVGBullishPivots; - bool drawFVGBearishPivots; - bool drawValeSupSWLPivots; - bool drawPeakResSWHPivots; - bool drawTrendBullishPivots; - bool drawTrendBearishPivots; - bool drawRSICrossedOverOSPivots; - bool drawRSICrossedUnderOBPivots; - bool drawCCICrossedOverOSPivots; - bool drawCCICrossedUnderOBPivots; - - // - // Colors ... - - // - color defaultBullishColor; - color defaultBearishColor; - - // - color tickPivotsColor; - color volumePivotsColor; - color rsiPeakPivotsColor; - color rsiValePivotsColor; - color cciPeakPivotsColor; - color cciValePivotsColor; - color fvgBullishPivotsColor; - color fvgBearishPivotsColor; - color valeSupSWLPivotsColor; - color peakResSWHPivotsColor; - color trendLineBullishColor; - color trendLineBearishColor; - color trendBullishPivotsColor; - color trendBearishPivotsColor; - color rsiCrossedOverOSPivotsColor; - color rsiCrossedUnderOBPivotsColor; - color cciCrossedOverOSPivotsColor; - color cciCrossedUnderOBPivotsColor; - - // - // Width ... - - // - int defaultBullishWidth; - int defaultBearishWidth; - - // - int tickPivotsWidth; - int volumePivotsWidth; - int rsiPeakPivotsWidth; - int rsiValePivotsWidth; - int cciPeakPivotsWidth; - int cciValePivotsWidth; - int fvgBullishPivotsWidth; - int fvgBearishPivotsWidth; - int valeSupSWLPivotsWidth; - int peakResSWHPivotsWidth; - int trendLineBullishWidth; - int trendLineBearishWidth; - int trendBullishPivotsWidth; - int trendBearishPivotsWidth; - int rsiCrossedOverOSPivotsWidth; - int rsiCrossedUnderOBPivotsWidth; - int cciCrossedOverOSPivotsWidth; - int cciCrossedUnderOBPivotsWidth; - - // - // Style ... - - // - ENUM_LINE_STYLE defaultBullishStyle; - ENUM_LINE_STYLE defaultBearishStyle; - - // - ENUM_LINE_STYLE tickPivotsStyle; - ENUM_LINE_STYLE volumePivotsStyle; - ENUM_LINE_STYLE rsiPeakPivotsStyle; - ENUM_LINE_STYLE rsiValePivotsStyle; - ENUM_LINE_STYLE cciPeakPivotsStyle; - ENUM_LINE_STYLE cciValePivotsStyle; - ENUM_LINE_STYLE fvgBullishPivotsStyle; - ENUM_LINE_STYLE fvgBearishPivotsStyle; - ENUM_LINE_STYLE valeSupSWLPivotsStyle; - ENUM_LINE_STYLE peakResSWHPivotsStyle; - ENUM_LINE_STYLE trendLineBullishStyle; - ENUM_LINE_STYLE trendLineBearishStyle; - ENUM_LINE_STYLE trendBullishPivotsStyle; - ENUM_LINE_STYLE trendBearishPivotsStyle; - ENUM_LINE_STYLE rsiCrossedOverOSPivotsStyle; - ENUM_LINE_STYLE rsiCrossedUnderOBPivotsStyle; - ENUM_LINE_STYLE cciCrossedOverOSPivotsStyle; - ENUM_LINE_STYLE cciCrossedUnderOBPivotsStyle; - - // - // Colorize Props ... - - // - // Width Props ... - - // - // Style Props ... - - // - // Constructors ... - XCXCAEAPOIDrawer( - XCXCAEAPOIDetector *_detector // - ) - { - // - detector = _detector; - drawer = new XCPOIDrawer(); - - // - Default(); - } - - // - // De Constructors ... - ~XCXCAEAPOIDrawer() - { - // - Clear(); - - // - ZeroMemory(drawer); - ZeroMemory(detector); - } - - // - // Properties ... - - // - // Tools ... - - // - virtual void Default() - { - // - ignoreUpdateOSCTos = true; - drawTrendPivotsOnlySelectedFVG = true; - - // - drawTrendLine = false; - drawTickPivots = false; - drawVolumePivots = false; - drawRSIPeakPivots = false; - drawRSIValePivots = false; - drawCCIPeakPivots = false; - drawCCIValePivots = false; - drawFVGBullishPivots = false; - drawFVGBearishPivots = false; - drawValeSupSWLPivots = false; - drawPeakResSWHPivots = false; - drawTrendBullishPivots = false; - drawTrendBearishPivots = false; - drawRSICrossedOverOSPivots = false; - drawRSICrossedUnderOBPivots = false; - drawCCICrossedOverOSPivots = false; - drawCCICrossedUnderOBPivots = false; - - // - defaultBullishColor = clrLime; - defaultBearishColor = clrRed; - - // - tickPivotsColor = defaultBullishColor; - volumePivotsColor = defaultBearishColor; - - // - rsiValePivotsColor = defaultBullishColor; - cciValePivotsColor = defaultBullishColor; - fvgBullishPivotsColor = defaultBullishColor; - valeSupSWLPivotsColor = defaultBullishColor; - trendLineBullishColor = defaultBullishColor; - trendBullishPivotsColor = defaultBullishColor; - rsiCrossedOverOSPivotsColor = defaultBullishColor; - cciCrossedOverOSPivotsColor = defaultBullishColor; - - // - rsiPeakPivotsColor = defaultBearishColor; - cciPeakPivotsColor = defaultBearishColor; - fvgBearishPivotsColor = defaultBearishColor; - peakResSWHPivotsColor = defaultBearishColor; - trendLineBearishColor = defaultBearishColor; - trendBearishPivotsColor = defaultBearishColor; - rsiCrossedUnderOBPivotsColor = defaultBearishColor; - cciCrossedUnderOBPivotsColor = defaultBearishColor; - - // - defaultBullishWidth = 1; - defaultBearishWidth = 1; - - // - tickPivotsWidth = defaultBullishWidth; - volumePivotsWidth = defaultBearishWidth; - - // - rsiValePivotsWidth = defaultBullishWidth; - cciValePivotsWidth = defaultBullishWidth; - fvgBullishPivotsWidth = defaultBullishWidth; - valeSupSWLPivotsWidth = defaultBullishWidth; - trendLineBullishWidth = defaultBullishWidth; - trendBullishPivotsWidth = defaultBullishWidth; - rsiCrossedOverOSPivotsWidth = defaultBullishWidth; - cciCrossedOverOSPivotsWidth = defaultBullishWidth; - - // - rsiPeakPivotsWidth = defaultBearishWidth; - cciPeakPivotsWidth = defaultBearishWidth; - fvgBearishPivotsWidth = defaultBearishWidth; - peakResSWHPivotsWidth = defaultBearishWidth; - trendLineBearishWidth = defaultBearishWidth; - trendBearishPivotsWidth = defaultBearishWidth; - rsiCrossedUnderOBPivotsWidth = defaultBearishWidth; - cciCrossedUnderOBPivotsWidth = defaultBearishWidth; - - // - defaultBullishStyle = STYLE_SOLID; - defaultBearishStyle = STYLE_SOLID; - - // - tickPivotsStyle = defaultBullishStyle; - volumePivotsStyle = defaultBearishStyle; - - // - rsiValePivotsStyle = defaultBullishStyle; - cciValePivotsStyle = defaultBullishStyle; - fvgBullishPivotsStyle = defaultBullishStyle; - valeSupSWLPivotsStyle = defaultBullishStyle; - trendLineBullishStyle = defaultBullishStyle; - trendBullishPivotsStyle = defaultBullishStyle; - rsiCrossedOverOSPivotsStyle = defaultBullishStyle; - cciCrossedOverOSPivotsStyle = defaultBullishStyle; - - // - rsiPeakPivotsStyle = defaultBearishStyle; - cciPeakPivotsStyle = defaultBearishStyle; - fvgBearishPivotsStyle = defaultBearishStyle; - peakResSWHPivotsStyle = defaultBearishStyle; - trendLineBearishStyle = defaultBearishStyle; - trendBearishPivotsStyle = defaultBearishStyle; - rsiCrossedUnderOBPivotsStyle = defaultBearishStyle; - cciCrossedUnderOBPivotsStyle = defaultBearishStyle; - } - - // - void Draw(datetime to = NULL) - { - // - DrawTrendLine(); - DrawTickPivots(to); - DrawVolumePivots(to); - DrawRSIPeakPivots(to); - DrawRSIValePivots(to); - DrawCCIPeakPivots(to); - DrawCCIValePivots(to); - DrawFVGBullishPivots(to); - DrawFVGBearishPivots(to); - DrawValeSupSWLPivots(to); - DrawPeakResSWHPivots(to); - DrawTrendBullishPivots(to); - DrawTrendBearishPivots(to); - DrawRSICrossedOverOSPivots(to); - DrawRSICrossedUnderOBPivots(to); - DrawCCICrossedOverOSPivots(to); - DrawCCICrossedUnderOBPivots(to); - } - - // - void DrawBox( - XBoxZone &box, - datetime to = NULL // - ) - { - // - bool has = box.IsValid(); - if (!has) - { - return; - } - // - // Detect Pivot Type ... - ENUM_XCA_PIVOTS iType = GetPivotType(box); - has = IsValid(iType); - if (!has) - { - return; - } - - // - switch (iType) - { - // - case XCA_TICK: - // - DrawTickPivot( - box, - to // - ); - break; - - // - case XCA_VOLUME: - // - DrawVolumePivot( - box, - to // - ); - break; - - // - case XCA_FVG_BULL: - // - DrawFVGBullishPivot( - box, - to // - ); - break; - - // - case XCA_FVG_BEAR: - // - DrawFVGBearishPivot( - box, - to // - ); - break; - - // - case XCA_RSI_COOS: - // - DrawRSICrossedOverOSPivot( - box, - to // - ); - break; - - // - case XCA_RSI_CUOB: - // - DrawRSICrossedUnderOBPivot( - box, - to // - ); - break; - - // - case XCA_RSI_PEAK: - // - DrawRSIPeakPivot( - box, - to // - ); - break; - - // - case XCA_RSI_VALE: - // - DrawRSIValePivot( - box, - to // - ); - break; - - // - case XCA_CCI_COOS: - // - DrawCCICrossedOverOSPivot( - box, - to // - ); - break; - - // - case XCA_CCI_CUOB: - // - DrawCCICrossedUnderOBPivot( - box, - to // - ); - break; - - // - case XCA_CCI_PEAK: - // - DrawCCIPeakPivot( - box, - to // - ); - break; - - // - case XCA_CCI_VALE: - // - DrawCCIValePivot( - box, - to // - ); - break; - - // - case XCA_PEAKSWHRES: - // - DrawPeakResSWHPivot( - box, - to // - ); - break; - - // - case XCA_VALESWLSUP: - // - DrawValeSupSWLPivot( - box, - to // - ); - break; - } - } - - // - void DrawBoxes( - XBoxZone &boxes[], - datetime to = NULL // - ) - { - // - bool has = HasChild(boxes); - if (!has) - { - return; - } - - // - int count = ArraySize(boxes); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = boxes[i]; - - // - // Detect Pivot Type ... - DrawBox( - iBox, - to // - ); - - // - iBox.Clean(); - }; - - // - // Trend Items ... - XCATRENDFVG trendFVGs[]; - count = ExtractTrendPivots( - trendFVGs, - boxes // - ); - has = IsValidSize(count); - if (!has) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XCATRENDFVG iTrendFVG = trendFVGs[i]; - - // - bool isBullish = iTrendFVG.IsBullish(); - if (isBullish) - { - // - DrawTrendBullishPivot( - iTrendFVG, - to // - ); - } - else - { - // - DrawTrendBearishPivot( - iTrendFVG, - to // - ); - } - - // - iTrendFVG.Clean(); - } - - // - Clean(trendFVGs); - } - - // - void Clear() - { - // - mTrendLineObjects.Clear(); - mTickPivotObjects.Clear(); - mVolumePivotObjects.Clear(); - mRSIPeakPivotObjects.Clear(); - mRSIValePivotObjects.Clear(); - mCCIPeakPivotObjects.Clear(); - mCCIValePivotObjects.Clear(); - mFVGBullishPivotObjects.Clear(); - mFVGBearishPivotObjects.Clear(); - mValeSupSWLPivotObjects.Clear(); - mPeakResSWHPivotObjects.Clear(); - mTrendBullishPivotObjects.Clear(); - mTrendBearishPivotObjects.Clear(); - mRSICrossedOverOSPivotObjects.Clear(); - mRSICrossedUnderOBPivotObjects.Clear(); - mCCICrossedOverOSPivotObjects.Clear(); - mCCICrossedUnderOBPivotObjects.Clear(); - } - - // - // Collection Drawers ... - - // - void DrawTrendLine() - { - // - if (!drawTrendLine) - { - return; - } - - // - mTrendLineObjects.Clear(); - - // - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - bool has = detector.MarketTrend(trend); - if (!has) - { - return; - } - - // - long chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - bool hasBullishTrend = IsBullish(trend); - - // - double pPrice = hasBullishTrend - ? detector.trendPivotP.lower - : detector.trendPivotP.upper; - - // - datetime pTime = detector.trendPivotP.from; - - // - double cPrice = hasBullishTrend - ? detector.trendPivotC.lower - : detector.trendPivotC.upper; - - // - datetime cTime = detector.trendPivotC.from; - - // - string tlName = ToString(trend) + - "_TL_" + - ToString(pPrice) + - "_" + - ToString(cPrice); - - // - int tlWidth = hasBullishTrend - ? trendLineBullishWidth - : trendLineBearishWidth; - - // - color tlColor = hasBullishTrend - ? trendLineBullishColor - : trendLineBearishColor; - - // - ENUM_LINE_STYLE tlStyle = hasBullishTrend - ? trendLineBullishStyle - : trendLineBearishStyle; - - // - CChartObjectTrend *iObj; - iObj = new CChartObjectTrend(); - has = iObj.Create( - chartID, - tlName, - subWindow, - pTime, - pPrice, - cTime, - cPrice // - ); - if (has) - { - // - // Style Object ... - iObj.Color(tlColor); - iObj.Width(tlWidth); - iObj.Style(tlStyle); - iObj.RayRight(true); - - // - // Store Object ... - mTrendLineObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawTickPivots(datetime to = NULL) - { - // - bool has = drawTickPivots; - if (!has) - { - return; - } - - // - has = detector.HasTickPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTickPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.tickPivots[i]; - - // - DrawTickPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawVolumePivots(datetime to = NULL) - { - // - bool has = drawVolumePivots; - if (!has) - { - return; - } - - // - has = detector.HasVolumePivots(); - if (!has) - { - return; - } - - // - int count = detector.CountVolumePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.volumePivots[i]; - - // - DrawVolumePivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawRSIPeakPivots(datetime to = NULL) - { - // - bool has = drawRSIPeakPivots; - if (!has) - { - return; - } - - // - has = detector.HasRSIPeakPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountRSIPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.rsiPeakPivots[i]; - - // - DrawRSIPeakPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawRSIValePivots(datetime to = NULL) - { - // - bool has = drawRSIValePivots; - if (!has) - { - return; - } - - // - has = detector.HasRSIValePivots(); - if (!has) - { - return; - } - - // - int count = detector.CountRSIValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.rsiValePivots[i]; - - // - DrawRSIValePivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawCCIPeakPivots(datetime to = NULL) - { - // - bool has = drawCCIPeakPivots; - if (!has) - { - return; - } - - // - has = detector.HasCCIPeakPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountCCIPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.cciPeakPivots[i]; - - // - DrawCCIPeakPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawCCIValePivots(datetime to = NULL) - { - // - bool has = drawCCIValePivots; - if (!has) - { - return; - } - - // - has = detector.HasCCIValePivots(); - if (!has) - { - return; - } - - // - int count = detector.CountCCIValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.cciValePivots[i]; - - // - DrawCCIValePivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawFVGBullishPivots(datetime to = NULL) - { - // - bool has = drawFVGBullishPivots; - if (!has) - { - return; - } - - // - has = detector.HasFVGBullishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountFVGBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.fvgBullishPivots[i]; - - // - DrawFVGBullishPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawFVGBearishPivots(datetime to = NULL) - { - // - bool has = drawFVGBearishPivots; - if (!has) - { - return; - } - - // - has = detector.HasFVGBearishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountFVGBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.fvgBearishPivots[i]; - - // - DrawFVGBearishPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawValeSupSWLPivots(datetime to = NULL) - { - // - bool has = drawValeSupSWLPivots; - if (!has) - { - return; - } - - // - has = detector.HasValeSupSWLPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountValeSupSWLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.valeSupSWLPivots[i]; - - // - DrawValeSupSWLPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawPeakResSWHPivots(datetime to = NULL) - { - // - bool has = drawPeakResSWHPivots; - if (!has) - { - return; - } - - // - has = detector.HasPeakResSWHPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountPeakResSWHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.peakResSWHPivots[i]; - - // - DrawPeakResSWHPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawTrendBullishPivots(datetime to = NULL) - { - // - bool has = drawTrendBullishPivots; - if (!has) - { - return; - } - - // - has = detector.HasTrendBullishPivots(); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - int count = detector.CountTrendBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XCATRENDFVG iTrendFVG = detector.trendBullishPivots[i]; - - // - DrawTrendBullishPivot( - iTrendFVG, - to // - ); - - // - iTrendFVG.Clean(); - } - } - - // - void DrawTrendBearishPivots(datetime to = NULL) - { - // - bool has = drawTrendBearishPivots; - if (!has) - { - return; - } - - // - has = detector.HasTrendBearishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTrendBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XCATRENDFVG iTrendFVG = detector.trendBearishPivots[i]; - - // - DrawTrendBearishPivot( - iTrendFVG, - to // - ); - - // - iTrendFVG.Clean(); - } - } - - // - void DrawRSICrossedOverOSPivots(datetime to = NULL) - { - // - bool has = drawRSICrossedOverOSPivots; - if (!has) - { - return; - } - - // - has = detector.HasRSICrossedOverOSPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountRSICrossedOverOSPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.rsiCrossedOverOSPivots[i]; - - // - DrawRSICrossedOverOSPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawRSICrossedUnderOBPivots(datetime to = NULL) - { - // - bool has = drawRSICrossedUnderOBPivots; - if (!has) - { - return; - } - - // - has = detector.HasRSICrossedUnderOBPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountRSICrossedUnderOBPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.rsiCrossedUnderOBPivots[i]; - - // - DrawRSICrossedUnderOBPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawCCICrossedOverOSPivots(datetime to = NULL) - { - // - bool has = drawCCICrossedOverOSPivots; - if (!has) - { - return; - } - - // - has = detector.HasCCICrossedOverOSPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountCCICrossedOverOSPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.cciCrossedOverOSPivots[i]; - - // - DrawCCICrossedOverOSPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - void DrawCCICrossedUnderOBPivots(datetime to = NULL) - { - // - bool has = drawCCICrossedUnderOBPivots; - if (!has) - { - return; - } - - // - has = detector.HasCCICrossedUnderOBPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountCCICrossedUnderOBPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = detector.cciCrossedUnderOBPivots[i]; - - // - DrawCCICrossedUnderOBPivot( - iBox, - to // - ); - - // - iBox.Clean(); - } - } - - // - // One Item Drawers ... - - // - void DrawTickPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawTickPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_TICK); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Pivot ... - iObj.BoxColor(tickPivotsColor); - iObj.BoxWidth(tickPivotsWidth); - iObj.BoxStyle(tickPivotsStyle); - - // - // Store Pivot ... - mTickPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawVolumePivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawVolumePivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_VOLUME); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Pivot ... - iObj.BoxColor(volumePivotsColor); - iObj.BoxWidth(volumePivotsWidth); - iObj.BoxStyle(volumePivotsStyle); - - // - // Store Pivot ... - mVolumePivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawRSIPeakPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawRSIPeakPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_RSI_PEAK) && - item.dir == GetDirection(XCA_RSI_PEAK); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(rsiPeakPivotsColor); - iObj.BoxWidth(rsiPeakPivotsWidth); - iObj.BoxStyle(rsiPeakPivotsStyle); - - // - // Store Object ... - mRSIPeakPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawRSIValePivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawRSIValePivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_RSI_VALE) && - item.dir == GetDirection(XCA_RSI_VALE); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(rsiValePivotsColor); - iObj.BoxWidth(rsiValePivotsWidth); - iObj.BoxStyle(rsiValePivotsStyle); - - // - // Store Object ... - mRSIValePivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawCCIPeakPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawCCIPeakPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_CCI_PEAK) && - item.dir == GetDirection(XCA_CCI_PEAK); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(cciPeakPivotsColor); - iObj.BoxWidth(cciPeakPivotsWidth); - iObj.BoxStyle(cciPeakPivotsStyle); - - // - // Store Object ... - mCCIPeakPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawCCIValePivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawCCIValePivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_CCI_VALE) && - item.dir == GetDirection(XCA_CCI_VALE); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(cciValePivotsColor); - iObj.BoxWidth(cciValePivotsWidth); - iObj.BoxStyle(cciValePivotsStyle); - - // - // Store Object ... - mCCIValePivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawFVGBullishPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawFVGBullishPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_FVG_BULL) && - item.dir == GetDirection(XCA_FVG_BULL); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(fvgBullishPivotsColor); - iObj.BoxWidth(fvgBullishPivotsWidth); - iObj.BoxStyle(fvgBullishPivotsStyle); - - // - // Store Object ... - mFVGBullishPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawFVGBearishPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawFVGBearishPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_FVG_BEAR) && - item.dir == GetDirection(XCA_FVG_BEAR); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(fvgBearishPivotsColor); - iObj.BoxWidth(fvgBearishPivotsWidth); - iObj.BoxStyle(fvgBearishPivotsStyle); - - // - // Store Object ... - mFVGBearishPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawValeSupSWLPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawValeSupSWLPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_VALESWLSUP) && - item.dir == GetDirection(XCA_VALESWLSUP); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(valeSupSWLPivotsColor); - iObj.BoxWidth(valeSupSWLPivotsWidth); - iObj.BoxStyle(valeSupSWLPivotsStyle); - - // - // Store Object ... - mValeSupSWLPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawPeakResSWHPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawPeakResSWHPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_PEAKSWHRES) && - item.dir == GetDirection(XCA_PEAKSWHRES); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(peakResSWHPivotsColor); - iObj.BoxWidth(peakResSWHPivotsWidth); - iObj.BoxStyle(peakResSWHPivotsStyle); - - // - // Store Object ... - mPeakResSWHPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawTrendBullishPivot( - XCATRENDFVG &item, - datetime to = NULL // - ) - { - // - bool has = drawTrendBullishPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.trend.type == GetBoxType(XCA_TREND_BULL) && - item.trend.dir == GetDirection(XCA_TREND_BULL); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - // Draw Trend Box ... - - // - if (canUpdateTo) - { - item.trend.to = to; - } - - // - XCBoxObject *iTrendBoxObj; - has = drawer.DrawBox( - item.trend, - iTrendBoxObj // - ); - if (has) - { - // - // Style Object ... - iTrendBoxObj.BoxColor(trendBullishPivotsColor); - iTrendBoxObj.BoxWidth(trendBullishPivotsWidth); - iTrendBoxObj.BoxStyle(trendBullishPivotsStyle); - - // - // Store Object ... - mTrendBullishPivotObjects.Add(iTrendBoxObj); - } - - // - // Draw ITrendFVG FVGS ... - if (drawTrendPivotsOnlySelectedFVG) - { - // - XBoxZone iBox; - has = item.GetSelectedFVG(iBox); - if (!has) - { - // - iBox.Clean(); - return; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - - // - if (has) - { - // - // Style Object ... - iObj.BoxColor(fvgBullishPivotsColor); - iObj.BoxWidth(fvgBullishPivotsWidth); - iObj.BoxStyle(fvgBullishPivotsStyle); - - // - // Store Object ... - mTrendBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - ZeroMemory(iObj); - } - else - { - // - // Draw All FVGs ... - has = HasChild(item.fvgs); - if (has) - { - // - int jCount = ArraySize(item.fvgs); - for (int j = 0; j < jCount; j++) - { - // - XBoxZone iBox = item.fvgs[j]; - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(fvgBullishPivotsColor); - iObj.BoxWidth(fvgBullishPivotsWidth); - iObj.BoxStyle(fvgBullishPivotsStyle); - - // - // Store Object ... - mTrendBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - ZeroMemory(iObj); - } - } - } - - // - ZeroMemory(iTrendBoxObj); - } - - // - void DrawTrendBearishPivot( - XCATRENDFVG &item, - datetime to = NULL // - ) - { - // - bool has = drawTrendBearishPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.trend.type == GetBoxType(XCA_TREND_BEAR) && - item.trend.dir == GetDirection(XCA_TREND_BEAR); - if (!has) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - // Draw Trend Box ... - - // - if (canUpdateTo) - { - item.trend.to = to; - } - - // - XCBoxObject *iTrendBoxObj; - has = drawer.DrawBox( - item.trend, - iTrendBoxObj // - ); - if (has) - { - // - // Style Object ... - iTrendBoxObj.BoxColor(trendBearishPivotsColor); - iTrendBoxObj.BoxWidth(trendBearishPivotsWidth); - iTrendBoxObj.BoxStyle(trendBearishPivotsStyle); - - // - // Store Object ... - mTrendBearishPivotObjects.Add(iTrendBoxObj); - } - - // - // Draw ITrendFVG FVGS ... - if (drawTrendPivotsOnlySelectedFVG) - { - // - XBoxZone iBox; - has = item.GetSelectedFVG(iBox); - if (!has) - { - // - iBox.Clean(); - return; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - - // - if (has) - { - // - // Style Object ... - iObj.BoxColor(fvgBearishPivotsColor); - iObj.BoxWidth(fvgBearishPivotsWidth); - iObj.BoxStyle(fvgBearishPivotsStyle); - - // - // Store Object ... - mTrendBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - ZeroMemory(iObj); - } - else - { - // - // Draw All FVGs ... - has = HasChild(item.fvgs); - if (has) - { - // - int jCount = ArraySize(item.fvgs); - for (int j = 0; j < jCount; j++) - { - // - XBoxZone iBox = item.fvgs[j]; - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(fvgBearishPivotsColor); - iObj.BoxWidth(fvgBearishPivotsWidth); - iObj.BoxStyle(fvgBearishPivotsStyle); - - // - // Store Object ... - mTrendBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - ZeroMemory(iObj); - } - } - } - - // - ZeroMemory(iTrendBoxObj); - } - - // - void DrawRSICrossedOverOSPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawRSICrossedOverOSPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_RSI_COOS) && - item.dir == GetDirection(XCA_RSI_COOS); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(rsiCrossedOverOSPivotsColor); - iObj.BoxWidth(rsiCrossedOverOSPivotsWidth); - iObj.BoxStyle(rsiCrossedOverOSPivotsStyle); - - // - // Store Object ... - mRSICrossedOverOSPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawRSICrossedUnderOBPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawRSICrossedUnderOBPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_RSI_CUOB) && - item.dir == GetDirection(XCA_RSI_CUOB); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(rsiCrossedUnderOBPivotsColor); - iObj.BoxWidth(rsiCrossedUnderOBPivotsWidth); - iObj.BoxStyle(rsiCrossedUnderOBPivotsStyle); - - // - // Store Object ... - mRSICrossedUnderOBPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawCCICrossedOverOSPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawCCICrossedOverOSPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_CCI_COOS) && - item.dir == GetDirection(XCA_CCI_COOS); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(cciCrossedOverOSPivotsColor); - iObj.BoxWidth(cciCrossedOverOSPivotsWidth); - iObj.BoxStyle(cciCrossedOverOSPivotsStyle); - - // - // Store Object ... - mCCICrossedOverOSPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - void DrawCCICrossedUnderOBPivot( - XBoxZone &item, - datetime to = NULL // - ) - { - // - bool has = drawCCICrossedUnderOBPivots; - if (!has) - { - return; - } - - // - has = item.IsValid() && - item.type == GetBoxType(XCA_CCI_CUOB) && - item.dir == GetDirection(XCA_CCI_CUOB); - if (!has) - { - return; - } - - // - if (ignoreUpdateOSCTos) - { - to = NULL; - } - bool canUpdateTo = IsValid(to); - if (canUpdateTo) - { - item.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - item, - iObj // - ); - if (has) - { - // - // Style Object ... - iObj.BoxColor(cciCrossedUnderOBPivotsColor); - iObj.BoxWidth(cciCrossedUnderOBPivotsWidth); - iObj.BoxStyle(cciCrossedUnderOBPivotsStyle); - - // - // Store Object ... - mCCICrossedUnderOBPivotObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - // Protected ... - protected: - // - // Props ... - - // - // Prrivate ... - private: - // - // Props ... - - // - XCPOIDrawer *drawer; - XCXCAEAPOIDetector *detector; - - // - CArrayObj mTickPivotObjects; - CArrayObj mTrendLineObjects; - CArrayObj mVolumePivotObjects; - CArrayObj mRSIPeakPivotObjects; - CArrayObj mRSIValePivotObjects; - CArrayObj mCCIPeakPivotObjects; - CArrayObj mCCIValePivotObjects; - CArrayObj mFVGBullishPivotObjects; - CArrayObj mFVGBearishPivotObjects; - CArrayObj mValeSupSWLPivotObjects; - CArrayObj mPeakResSWHPivotObjects; - CArrayObj mTrendBullishPivotObjects; - CArrayObj mTrendBearishPivotObjects; - CArrayObj mRSICrossedOverOSPivotObjects; - CArrayObj mRSICrossedUnderOBPivotObjects; - CArrayObj mCCICrossedOverOSPivotObjects; - CArrayObj mCCICrossedUnderOBPivotObjects; - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/xcaea.x-poi.drawer.class.mq5 b/Documents/BKP/xcaea.x-poi.drawer.class.mq5 deleted file mode 100644 index 14d0bfd0..00000000 --- a/Documents/BKP/xcaea.x-poi.drawer.class.mq5 +++ /dev/null @@ -1,2424 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: XCXCAEAPOIDrawer ... -// Description: Class for XCAEA POI Drawer ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm Class for XCAEA POI Drawer" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Classes/xcaea.x-poi.detector.class.mq5" - -// -// Definitions ... - -// -// Implementations ... -class XCXCAEAPOIDrawer : public XCBase -{ - // - // Public ... - public: - // - // Props ... - bool drawSWHPivots; - bool drawSWLPivots; - bool drawPeakPivots; - bool drawValePivots; - bool drawRSIPeakPivots; - bool drawRSIValePivots; - bool drawCCIPeakPivots; - bool drawCCIValePivots; - bool drawKIBullishPivots; - bool drawKIBearishPivots; - bool drawFVGBullishPivots; - bool drawFVGBearishPivots; - bool drawPeakSWHResPivots; - bool drawValeSWLSupPivots; - bool drawTKIBullishPivots; - bool drawTKIBearishPivots; - bool drawCycleSameLLPivots; - bool drawCycleSameHHPivots; - bool drawTrendBullishPivots; - bool drawTrendBearishPivots; - bool drawPVFVGBullishPivots; - bool drawPVFVGBearishPivots; - bool drawTKITRNDBullishPivots; - bool drawTKITRNDBearishPivots; - bool drawRSICrossedOverOSPivots; - bool drawRSICrossedUnderOBPivots; - bool drawCCICrossedOverOSPivots; - bool drawCCICrossedUnderOBPivots; - - // - bool drawTicks; - - // - // Colorize Props ... - - // - color peakPivotColor; - color valePivotColor; - color sameHHPivotColor; - color sameLLPivotColor; - color ticksBullishColor; - color ticksBearishColor; - color kiBullishPivotColor; - color kiBearishPivotColor; - color fvgBullishPivotColor; - color fvgBearishPivotColor; - color defBullishPivotColor; - color defBearishPivotColor; - color oscsBullishPivotColor; - color oscsBearishPivotColor; - color trendBullishPivotColor; - color trendBearishPivotColor; - - // - // Width Props ... - - // - int peakPivotWidth; - int valePivotWidth; - int sameHHPivotWidth; - int sameLLPivotWidth; - int ticksBullishWidth; - int ticksBearishWidth; - int kiBullishPivotWidth; - int kiBearishPivotWidth; - int fvgBullishPivotWidth; - int fvgBearishPivotWidth; - int defBullishPivotWidth; - int defBearishPivotWidth; - int oscsBullishPivotWidth; - int oscsBearishPivotWidth; - int trendBullishPivotWidth; - int trendBearishPivotWidth; - - // - // Style Props ... - - // - ENUM_LINE_STYLE peakPivotStyle; - ENUM_LINE_STYLE valePivotStyle; - ENUM_LINE_STYLE sameHHPivotStyle; - ENUM_LINE_STYLE sameLLPivotStyle; - ENUM_LINE_STYLE ticksBullishStyle; - ENUM_LINE_STYLE ticksBearishStyle; - ENUM_LINE_STYLE kiBullishPivotStyle; - ENUM_LINE_STYLE kiBearishPivotStyle; - ENUM_LINE_STYLE fvgBullishPivotStyle; - ENUM_LINE_STYLE fvgBearishPivotStyle; - ENUM_LINE_STYLE defBullishPivotStyle; - ENUM_LINE_STYLE defBearishPivotStyle; - ENUM_LINE_STYLE oscsBullishPivotStyle; - ENUM_LINE_STYLE oscsBearishPivotStyle; - ENUM_LINE_STYLE trendBullishPivotStyle; - ENUM_LINE_STYLE trendBearishPivotStyle; - // - // Constructors ... - XCXCAEAPOIDrawer( - XCXCAEAPOIDetector *_detector // - ) - { - // - detector = _detector; - drawer = new XCPOIDrawer(); - - // - Default(); - } - - // - // De Constructors ... - ~XCXCAEAPOIDrawer() - { - // - mSWHPivotObjects.Clear(); - mSWLPivotObjects.Clear(); - mPeakPivotObjects.Clear(); - mValePivotObjects.Clear(); - mRSIPeakPivotObjects.Clear(); - mRSIValePivotObjects.Clear(); - mCCIPeakPivotObjects.Clear(); - mCCIValePivotObjects.Clear(); - mKIBullishPivotObjects.Clear(); - mKIBearishPivotObjects.Clear(); - mFVGBullishPivotObjects.Clear(); - mFVGBearishPivotObjects.Clear(); - mPeakSWHResPivotObjects.Clear(); - mValeSWLSupPivotObjects.Clear(); - mTKIBullishPivotObjects.Clear(); - mTKIBearishPivotObjects.Clear(); - mTrendBullishPivotObjects.Clear(); - mTrendBearishPivotObjects.Clear(); - mCycleSameLLPivotObjects.Clear(); - mCycleSameHHPivotObjects.Clear(); - mTKITRNDBullishPivotObjects.Clear(); - mTKITRNDBearishPivotObjects.Clear(); - mRSICrossedOverOSPivotObjects.Clear(); - mRSICrossedUnderOBPivotObjects.Clear(); - mCCICrossedOverOSPivotObjects.Clear(); - mCCICrossedUnderOBPivotObjects.Clear(); - - // - ZeroMemory(drawer); - ZeroMemory(detector); - } - - // - // Properties ... - - // - // Tools ... - - // - virtual void Default() - { - // - drawSWHPivots = false; - drawSWLPivots = false; - drawPeakPivots = false; - drawValePivots = false; - drawRSIPeakPivots = false; - drawRSIValePivots = false; - drawCCIPeakPivots = false; - drawCCIValePivots = false; - drawKIBullishPivots = false; - drawKIBearishPivots = false; - drawFVGBullishPivots = false; - drawFVGBearishPivots = false; - drawPeakSWHResPivots = false; - drawValeSWLSupPivots = false; - drawTKIBullishPivots = false; - drawTKIBearishPivots = false; - drawCycleSameLLPivots = false; - drawCycleSameHHPivots = false; - drawPVFVGBullishPivots = false; - drawPVFVGBearishPivots = false; - drawTrendBullishPivots = false; - drawTrendBearishPivots = false; - drawTKITRNDBullishPivots = false; - drawTKITRNDBearishPivots = false; - drawRSICrossedOverOSPivots = false; - drawRSICrossedUnderOBPivots = false; - drawCCICrossedOverOSPivots = false; - drawCCICrossedUnderOBPivots = false; - - // - drawTicks = false; - - // - // Color ... - defBullishPivotColor = clrLime; - defBearishPivotColor = clrRed; - - // - peakPivotColor = defBearishPivotColor; - valePivotColor = defBullishPivotColor; - sameHHPivotColor = defBearishPivotColor; - sameLLPivotColor = defBullishPivotColor; - ticksBullishColor = defBearishPivotColor; - ticksBearishColor = defBullishPivotColor; - kiBullishPivotColor = defBullishPivotColor; - kiBearishPivotColor = defBearishPivotColor; - fvgBullishPivotColor = defBullishPivotColor; - fvgBearishPivotColor = defBearishPivotColor; - oscsBullishPivotColor = defBullishPivotColor; - oscsBearishPivotColor = defBearishPivotColor; - trendBullishPivotColor = defBullishPivotColor; - trendBearishPivotColor = defBearishPivotColor; - - // - // Width ... - defBullishPivotWidth = 1; - defBearishPivotWidth = 1; - - // - peakPivotWidth = defBearishPivotWidth; - valePivotWidth = defBullishPivotWidth; - sameHHPivotWidth = defBearishPivotWidth; - sameLLPivotWidth = defBullishPivotWidth; - ticksBullishWidth = defBearishPivotWidth; - ticksBearishWidth = defBullishPivotWidth; - kiBullishPivotWidth = defBullishPivotWidth; - kiBearishPivotWidth = defBearishPivotWidth; - fvgBullishPivotWidth = defBullishPivotWidth; - fvgBearishPivotWidth = defBearishPivotWidth; - oscsBullishPivotWidth = defBullishPivotWidth; - oscsBearishPivotWidth = defBearishPivotWidth; - trendBullishPivotWidth = defBullishPivotWidth; - trendBearishPivotWidth = defBearishPivotWidth; - - // - // Style ... - defBullishPivotStyle = STYLE_DOT; - defBearishPivotStyle = STYLE_DOT; - - // - peakPivotStyle = defBearishPivotStyle; - valePivotStyle = defBullishPivotStyle; - sameHHPivotStyle = defBearishPivotStyle; - sameLLPivotStyle = defBullishPivotStyle; - ticksBullishStyle = defBearishPivotStyle; - ticksBearishStyle = defBullishPivotStyle; - kiBullishPivotStyle = defBullishPivotStyle; - kiBearishPivotStyle = defBearishPivotStyle; - fvgBullishPivotStyle = defBullishPivotStyle; - fvgBearishPivotStyle = defBearishPivotStyle; - oscsBullishPivotStyle = defBullishPivotStyle; - oscsBearishPivotStyle = defBearishPivotStyle; - trendBullishPivotStyle = defBullishPivotStyle; - trendBearishPivotStyle = defBearishPivotStyle; - } - - // - void Draw(datetime to = NULL) - { - // - DrawTicks(to); - DrawSWHPivots(to); - DrawSWLPivots(to); - DrawPeakPivots(to); - DrawValePivots(to); - DrawRSIPeakPivots(to); - DrawRSIValePivots(to); - DrawCCIPeakPivots(to); - DrawCCIValePivots(to); - DrawKIBullishPivots(to); - DrawKIBearishPivots(to); - DrawFVGBullishPivots(to); - DrawFVGBearishPivots(to); - DrawPeakSWHResPivots(to); - DrawValeSWLSupPivots(to); - DrawTKIBullishPivots(to); - DrawTKIBearishPivots(to); - DrawCycleSameLLPivots(to); - DrawCycleSameHHPivots(to); - DrawTrendBullishPivots(to); - DrawTrendBearishPivots(to); - DrawTKITRNDBullishPivots(to); - DrawTKITRNDBearishPivots(to); - DrawRSICrossedOverOSPivots(to); - DrawRSICrossedUnderOBPivots(to); - DrawCCICrossedOverOSPivots(to); - DrawCCICrossedUnderOBPivots(to); - } - - // - // - // - - // - void DrawTicks(datetime to = NULL) - { - // - if (!drawTicks) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - // PEAK TICKS ... - bool has = detector.HasPeakTicks(); - if (has) - { - // - int count = detector.CountPeakTicks(); - for (int i = 0; i < count; i++) - { - // - XCAPVTick iPVTick = detector.peakTicks[i]; - - // - // Converts Zone to Box ... - XBoxZone iBox; - has = iPVTick.GetMaxVolumeBox(iBox); - if (!has) - { - // - iBox.Clean(); - iPVTick.Clean(); - - // - continue; - } - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(ticksBearishColor); - iObj.BoxWidth(ticksBearishWidth); - iObj.BoxStyle(ticksBearishStyle); - - // - mPeakSWHResPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - iPVTick.Clean(); - ZeroMemory(iObj); - } - } - - // - // VALE TICKS ... - has = detector.HasValeTicks(); - if (has) - { - // - int count = detector.CountValeTicks(); - for (int i = 0; i < count; i++) - { - // - XCAPVTick iPVTick = detector.valeTicks[i]; - - // - // Converts Zone to Box ... - XBoxZone iBox; - has = iPVTick.GetMaxVolumeBox(iBox); - if (!has) - { - // - iBox.Clean(); - iPVTick.Clean(); - - // - continue; - } - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(ticksBullishColor); - iObj.BoxWidth(ticksBullishWidth); - iObj.BoxStyle(ticksBullishStyle); - - // - mValeSWLSupPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - iPVTick.Clean(); - ZeroMemory(iObj); - } - } - } - - // - void DrawSWHPivots(datetime to = NULL) - { - // - if (!drawSWHPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasSWHPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountSWHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.swhPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(peakPivotColor); - iObj.BoxWidth(peakPivotWidth); - iObj.BoxStyle(peakPivotStyle); - - // - mSWHPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawSWLPivots(datetime to = NULL) - { - // - if (!drawSWLPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasSWLPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountSWLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.swlPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(valePivotColor); - iObj.BoxWidth(valePivotWidth); - iObj.BoxStyle(valePivotStyle); - - // - mSWLPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawPeakPivots(datetime to = NULL) - { - // - if (!drawPeakPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasPeakPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.peakPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(peakPivotColor); - iObj.BoxWidth(peakPivotWidth); - iObj.BoxStyle(peakPivotStyle); - - // - mPeakPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawValePivots(datetime to = NULL) - { - // - if (!drawValePivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasValePivots(); - if (!has) - { - return; - } - - // - int count = detector.CountValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.valePivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(valePivotColor); - iObj.BoxWidth(valePivotWidth); - iObj.BoxStyle(valePivotStyle); - - // - mValePivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawKIBullishPivots(datetime to = NULL) - { - // - if (!drawKIBullishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasKIBullishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountKIBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.kiBullishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(kiBullishPivotColor); - iObj.BoxWidth(kiBullishPivotWidth); - iObj.BoxStyle(kiBullishPivotStyle); - - // - mKIBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawKIBearishPivots(datetime to = NULL) - { - // - if (!drawKIBearishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasKIBearishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountKIBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.kiBearishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(kiBearishPivotColor); - iObj.BoxWidth(kiBearishPivotWidth); - iObj.BoxStyle(kiBearishPivotStyle); - - // - mKIBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawFVGBullishPivots(datetime to = NULL) - { - // - bool canUpdateTo = IsValid(to); - - // - if (drawFVGBullishPivots) - { - // - bool has = detector.HasFVGBullishPivots(); - if (has) - { - // - int count = detector.CountFVGBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.fvgBullishPivots[i].AsBox(iBox); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(fvgBullishPivotColor); - iObj.BoxWidth(fvgBullishPivotWidth); - iObj.BoxStyle(fvgBullishPivotStyle); - - // - mFVGBullishPivotObjects.Add(iObj); - } - } - } - } - - // - if (drawPVFVGBullishPivots) - { - // - bool has = detector.HasPVFVGBullishPivots(); - if (has) - { - // - int count = detector.CountPVFVGBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XCAPVPivot iPVFVG = detector.pvFVGBullishPivots[i]; - - // - XBoxZone fvgBoxes[]; - int fvgBoxesCount = iPVFVG.GetPivots(fvgBoxes); - has = IsValidSize(fvgBoxesCount); - if (has) - { - // - int idx = GetLowest(fvgBoxes); - if (IsValidIndex(idx)) - { - // - XBoxZone iBox = fvgBoxes[idx]; - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - - // - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(fvgBullishPivotColor); - iObj.BoxWidth(fvgBullishPivotWidth); - iObj.BoxStyle(fvgBullishPivotStyle); - - // - mFVGBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - ZeroMemory(iObj); - } - } - } - } - } - } - - // - void DrawFVGBearishPivots(datetime to = NULL) - { - // - bool canUpdateTo = IsValid(to); - - // - if (drawFVGBearishPivots) - { - // - bool has = detector.HasFVGBearishPivots(); - if (has) - { - // - int count = detector.CountFVGBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.fvgBearishPivots[i].AsBox(iBox); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(fvgBearishPivotColor); - iObj.BoxWidth(fvgBearishPivotWidth); - iObj.BoxStyle(fvgBearishPivotStyle); - - // - mFVGBearishPivotObjects.Add(iObj); - } - } - } - } - - // - if (drawPVFVGBullishPivots) - { - // - bool has = detector.HasPVFVGBearishPivots(); - if (has) - { - // - int count = detector.CountPVFVGBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XCAPVPivot iPVFVG = detector.pvFVGBearishPivots[i]; - - // - XBoxZone fvgBoxes[]; - int fvgBoxesCount = iPVFVG.GetPivots(fvgBoxes); - has = IsValidSize(fvgBoxesCount); - if (has) - { - // - int idx = GetHighest(fvgBoxes); - if (IsValidIndex(idx)) - { - // - XBoxZone iBox = fvgBoxes[idx]; - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - - // - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(fvgBearishPivotColor); - iObj.BoxWidth(fvgBearishPivotWidth); - iObj.BoxStyle(fvgBearishPivotStyle); - - // - mFVGBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - ZeroMemory(iObj); - } - } - } - } - } - } - - // - void DrawPeakSWHResPivots(datetime to = NULL) - { - // - if (!drawPeakSWHResPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasPeakSWHResPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountPeakSWHResPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.peakSWHResPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(peakPivotColor); - iObj.BoxWidth(peakPivotWidth); - iObj.BoxStyle(peakPivotStyle); - - // - mPeakSWHResPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawValeSWLSupPivots(datetime to = NULL) - { - // - if (!drawValeSWLSupPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasValeSWLSupPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountValeSWLSupPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.valeSWLSupPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(valePivotColor); - iObj.BoxWidth(valePivotWidth); - iObj.BoxStyle(valePivotStyle); - - // - mValeSWLSupPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawTKIBullishPivots(datetime to = NULL) - { - // - if (!drawTKIBullishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasTKIBullishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTKIBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.tkiBullishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(kiBullishPivotColor); - iObj.BoxWidth(kiBullishPivotWidth); - iObj.BoxStyle(kiBullishPivotStyle); - - // - mTKIBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawTKIBearishPivots(datetime to = NULL) - { - // - if (!drawTKIBearishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasTKIBearishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTKIBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.tkiBearishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(kiBearishPivotColor); - iObj.BoxWidth(kiBearishPivotWidth); - iObj.BoxStyle(kiBearishPivotStyle); - - // - mTKIBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawTrendBullishPivots(datetime to = NULL) - { - // - if (!drawTrendBullishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasTrendBullishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTrendBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.trendBullishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(trendBullishPivotColor); - iObj.BoxWidth(trendBullishPivotWidth); - iObj.BoxStyle(trendBullishPivotStyle); - - // - mTrendBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawTrendBearishPivots(datetime to = NULL) - { - // - if (!drawTrendBearishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasTrendBearishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTrendBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.trendBearishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(trendBearishPivotColor); - iObj.BoxWidth(trendBearishPivotWidth); - iObj.BoxStyle(trendBearishPivotStyle); - - // - mTrendBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawTKITRNDBullishPivots(datetime to = NULL) - { - // - if (!drawTKITRNDBullishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasTKITRNDBullishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTKITRNDBullishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.tkitrndBullishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(trendBullishPivotColor); - iObj.BoxWidth(trendBullishPivotWidth); - iObj.BoxStyle(trendBullishPivotStyle); - - // - mTKITRNDBullishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawTKITRNDBearishPivots(datetime to = NULL) - { - // - if (!drawTKITRNDBearishPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - bool has = detector.HasTKITRNDBearishPivots(); - if (!has) - { - return; - } - - // - int count = detector.CountTKITRNDBearishPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.tkitrndBearishPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(trendBearishPivotColor); - iObj.BoxWidth(trendBearishPivotWidth); - iObj.BoxStyle(trendBearishPivotStyle); - - // - mTKITRNDBearishPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - void DrawCycleSameLLPivots(datetime to = NULL) - { - // - if (!drawCycleSameLLPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - int count = 0; - - // - // SHORT ... - bool has = detector.HasSSameLLPivots(); - if (has) - { - // - count = detector.CountSSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.sSameLLPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameLLPivotColor); - iObj.BoxWidth(sameLLPivotWidth); - iObj.BoxStyle(sameLLPivotStyle); - - // - mCycleSameLLPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // MEDIUM ... - has = detector.HasMSameLLPivots(); - if (has) - { - // - count = detector.CountMSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.mSameLLPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameLLPivotColor); - iObj.BoxWidth(sameLLPivotWidth); - iObj.BoxStyle(sameLLPivotStyle); - - // - mCycleSameLLPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // LONG ... - has = detector.HasLSameLLPivots(); - if (has) - { - // - count = detector.CountLSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.lSameLLPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameLLPivotColor); - iObj.BoxWidth(sameLLPivotWidth); - iObj.BoxStyle(sameLLPivotStyle); - - // - mCycleSameLLPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // HIND ... - has = detector.HasHSameLLPivots(); - if (has) - { - // - count = detector.CountHSameLLPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.hSameLLPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameLLPivotColor); - iObj.BoxWidth(sameLLPivotWidth); - iObj.BoxStyle(sameLLPivotStyle); - - // - mCycleSameLLPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawCycleSameHHPivots(datetime to = NULL) - { - // - if (!drawCycleSameHHPivots) - { - return; - } - - // - bool canUpdateTo = IsValid(to); - - // - int count = 0; - - // - // SHORT ... - bool has = detector.HasSSameHHPivots(); - if (has) - { - // - count = detector.CountSSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.sSameHHPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameHHPivotColor); - iObj.BoxWidth(sameHHPivotWidth); - iObj.BoxStyle(sameHHPivotStyle); - - // - mCycleSameHHPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // MEDIUM ... - has = detector.HasMSameHHPivots(); - if (has) - { - // - count = detector.CountMSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.mSameHHPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameHHPivotColor); - iObj.BoxWidth(sameHHPivotWidth); - iObj.BoxStyle(sameHHPivotStyle); - - // - mCycleSameHHPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // LONG ... - has = detector.HasLSameHHPivots(); - if (has) - { - // - count = detector.CountLSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.lSameHHPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameHHPivotColor); - iObj.BoxWidth(sameHHPivotWidth); - iObj.BoxStyle(sameHHPivotStyle); - - // - mCycleSameHHPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // HIND ... - has = detector.HasHSameHHPivots(); - if (has) - { - // - count = detector.CountHSameHHPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.hSameHHPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(sameHHPivotColor); - iObj.BoxWidth(sameHHPivotWidth); - iObj.BoxStyle(sameHHPivotStyle); - - // - mCycleSameHHPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawRSIPeakPivots(datetime to = NULL) - { - // - if (!drawRSIPeakPivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasRSIPeakPivots(); - if (has) - { - // - count = detector.CountRSIPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.rsiPeakPivots[i].AsBox(iBox); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBearishPivotColor); - iObj.BoxWidth(oscsBearishPivotWidth); - iObj.BoxStyle(oscsBearishPivotStyle); - - // - mRSIPeakPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawRSIValePivots(datetime to = NULL) - { - // - if (!drawRSIValePivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasRSIValePivots(); - if (has) - { - // - count = detector.CountRSIValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.rsiValePivots[i].AsBox(iBox); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBullishPivotColor); - iObj.BoxWidth(oscsBullishPivotWidth); - iObj.BoxStyle(oscsBullishPivotStyle); - - // - mRSIValePivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawRSICrossedOverOSPivots(datetime to = NULL) - { - // - if (!drawRSICrossedOverOSPivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasRSICrossedOverOSPivots(); - if (has) - { - // - count = detector.CountRSICrossedOverOSPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.rsiCrossedOverOSPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBullishPivotColor); - iObj.BoxWidth(oscsBullishPivotWidth); - iObj.BoxStyle(oscsBullishPivotStyle); - - // - mRSICrossedOverOSPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawRSICrossedUnderOBPivots(datetime to = NULL) - { - // - if (!drawRSICrossedUnderOBPivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasRSICrossedUnderOBPivots(); - if (has) - { - // - count = detector.CountRSICrossedUnderOBPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.rsiCrossedUnderOBPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBearishPivotColor); - iObj.BoxWidth(oscsBearishPivotWidth); - iObj.BoxStyle(oscsBearishPivotStyle); - - // - mRSICrossedUnderOBPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawCCIPeakPivots(datetime to = NULL) - { - // - if (!drawCCIPeakPivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasCCIPeakPivots(); - if (has) - { - // - count = detector.CountCCIPeakPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.cciPeakPivots[i].AsBox(iBox); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBearishPivotColor); - iObj.BoxWidth(oscsBearishPivotWidth); - iObj.BoxStyle(oscsBearishPivotStyle); - - // - mCCIPeakPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawCCIValePivots(datetime to = NULL) - { - // - if (!drawCCIValePivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasCCIValePivots(); - if (has) - { - // - count = detector.CountCCIValePivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.cciValePivots[i].AsBox(iBox); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBullishPivotColor); - iObj.BoxWidth(oscsBullishPivotWidth); - iObj.BoxStyle(oscsBullishPivotStyle); - - // - mCCIValePivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawCCICrossedOverOSPivots(datetime to = NULL) - { - // - if (!drawCCICrossedOverOSPivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasCCICrossedOverOSPivots(); - if (has) - { - // - count = detector.CountCCICrossedOverOSPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.cciCrossedOverOSPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBullishPivotColor); - iObj.BoxWidth(oscsBullishPivotWidth); - iObj.BoxStyle(oscsBullishPivotStyle); - - // - mCCICrossedOverOSPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - void DrawCCICrossedUnderOBPivots(datetime to = NULL) - { - // - if (!drawCCICrossedUnderOBPivots) - { - return; - } - - // - to = NULL; - bool canUpdateTo = IsValid(to); - - // - int count = 0; - bool has = detector.HasCCICrossedUnderOBPivots(); - if (has) - { - // - count = detector.CountCCICrossedUnderOBPivots(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = detector.cciCrossedUnderOBPivots[i].AsBox(iBox); - if (!has) - { - continue; - } - - // - if (canUpdateTo) - { - iBox.to = to; - } - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxColor(oscsBearishPivotColor); - iObj.BoxWidth(oscsBearishPivotWidth); - iObj.BoxStyle(oscsBearishPivotStyle); - - // - mCCICrossedUnderOBPivotObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - // Protected ... - protected: - // - // Props ... - - // - // Prrivate ... - private: - // - // Props ... - - // - XCPOIDrawer *drawer; - XCXCAEAPOIDetector *detector; - - // - CArrayObj mSWHPivotObjects; - CArrayObj mSWLPivotObjects; - CArrayObj mPeakPivotObjects; - CArrayObj mValePivotObjects; - CArrayObj mRSIPeakPivotObjects; - CArrayObj mRSIValePivotObjects; - CArrayObj mCCIPeakPivotObjects; - CArrayObj mCCIValePivotObjects; - CArrayObj mKIBullishPivotObjects; - CArrayObj mKIBearishPivotObjects; - CArrayObj mFVGBullishPivotObjects; - CArrayObj mFVGBearishPivotObjects; - CArrayObj mPeakSWHResPivotObjects; - CArrayObj mValeSWLSupPivotObjects; - CArrayObj mTKIBullishPivotObjects; - CArrayObj mTKIBearishPivotObjects; - CArrayObj mCycleSameLLPivotObjects; - CArrayObj mCycleSameHHPivotObjects; - CArrayObj mTrendBullishPivotObjects; - CArrayObj mTrendBearishPivotObjects; - CArrayObj mTKITRNDBullishPivotObjects; - CArrayObj mTKITRNDBearishPivotObjects; - CArrayObj mRSICrossedOverOSPivotObjects; - CArrayObj mRSICrossedUnderOBPivotObjects; - CArrayObj mCCICrossedOverOSPivotObjects; - CArrayObj mCCICrossedUnderOBPivotObjects; - - // -}; - -// \ No newline at end of file