/////////////////////////////////////////////////////// // // 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 DetectXCAEAConditions( XCXCAEAPOIDrawer *drawer, ENUM_X_DIRECTION trend, 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; // // Generating Conditions Summary ... string summary = conditions .GenerateSummary(); // // Calculating Range Volumes ... // double bullishVolume = 0; double bearishVolume = 0; int volumeRangeLoopback = 5; helper.barAnalyser.CalculateRangeVolume( cBar, bullishVolume, bearishVolume, volumeRangeLoopback // ); // 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]; // // 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]; // // 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; // 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 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 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); } } // // 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; // // // drawer.DrawBox( // rejectedPivot, // TimeCurrent() // // ); // // Print("Cond1"); } // // Cond2 Act Using OSC Box and Vydia ... // bool isCond2Bullish = // // false && // isPRSIOS && isPCCIOS && isRSIBullish && isCCIBullish && // isADXBullish && // hasRCIContainers && rciPivot.IsValid() && rciPivot.IsBullish() && // conditions.isUnderMal && // conditions.isValeIsPivot && (conditions.isRSICrossedOverOS || conditions.isCCICrossedOverOS) // && // conditions.swingLowBuffer[cIDX] < conditions.fiboLevel3Buffer[cIDX] // ; // bool isCond2Bearish = // // false && // isPRSIOB && isPCCIOB && isRSIBearish && isCCIBearish && // isADXBearish && // hasRCIContainers && rciPivot.IsValid() && rciPivot.IsBearish() && // conditions.isOverMal && // conditions.isPeakIsPivot && (conditions.isRSICrossedUnderOB || conditions.isCCICrossedUnderOB) // && // conditions.swingHighBuffer[cIDX] > conditions.fiboLevel1Buffer[cIDX] // ; // bool isCond2 = isCond2Bullish || isCond2Bearish; if (isCond2) { pivotBox = rciPivot; } // // 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 // ); } // // // // X3MA Medium ... // if (c3MAMedium < entry) // { // // // Add( // c3MAMedium, // sls // // ); // } } else { // // Rejected Pivot ... Add( rejectedPivot.upper, sls // ); // if (!isRejectedOnMid) { // Add( rejectedPivot.GetMid(), sls // ); } // // // // X3MA Medium ... // if (c3MAMedium > entry) // { // // // Add( // c3MAMedium, // 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(); rciPivot.Clean(); Clean(cTrendValues); Clean(pTrendValues); Clean(insidePivots); pConditions.Clean(); Clean(rciContainers); rejectedPivot.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; } // 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; } //