// int minRequiredRange = 20; if (barIndex > maxBarIndex - minRequiredRange - 4) { return; } // double iP2SCLL = sLLBuffer[barIndex + 2]; double iP2SCHH = sHHBuffer[barIndex + 2]; // double iP3SCLL = sLLBuffer[barIndex + 3]; double iP3SCHH = sHHBuffer[barIndex + 3]; // double iP4SCLL = sLLBuffer[barIndex + 4]; double iP4SCHH = sHHBuffer[barIndex + 4]; // double iP2MCLL = mLLBuffer[barIndex + 2]; double iP2MCHH = mHHBuffer[barIndex + 2]; // double iP3MCLL = mLLBuffer[barIndex + 3]; double iP3MCHH = mHHBuffer[barIndex + 3]; // double iP4MCLL = mLLBuffer[barIndex + 4]; double iP4MCHH = mHHBuffer[barIndex + 4]; // double iP2LCLL = lLLBuffer[barIndex + 2]; double iP2LCHH = lHHBuffer[barIndex + 2]; // double iP3LCLL = lLLBuffer[barIndex + 3]; double iP3LCHH = lHHBuffer[barIndex + 3]; // double iP4LCLL = lLLBuffer[barIndex + 4]; double iP4LCHH = lHHBuffer[barIndex + 4]; // double iP2HCLL = hLLBuffer[barIndex + 2]; double iP2HCHH = hHHBuffer[barIndex + 2]; // double iP3HCLL = hLLBuffer[barIndex + 3]; double iP3HCHH = hHHBuffer[barIndex + 3]; // double iP4HCLL = hLLBuffer[barIndex + 4]; double iP4HCHH = hHHBuffer[barIndex + 4]; // // Cycle States ... // // Create Conditions ... // bool isSCMaOverMCMa = iSCMa > iMCMa; bool isPSCMaOverMCMa = iPSCMa > iPMCMa; // bool isSCMaUnderMCMa = iSCMa < iMCMa; bool isPSCMaUnderMCMa = iPSCMa < iPMCMa; // bool isSCMaCrossedOverMCMa = isSCMaOverMCMa && !isPSCMaOverMCMa; // bool isSCMaCrossedUnderMCMa = isSCMaUnderMCMa && !isPSCMaUnderMCMa; // bool isLCMaOverHCMa = iLCMa > iHCMa; bool isPLCMaOverHCMa = iPLCMa > iPHCMa; // bool isLCMaUnderHCMa = iLCMa < iHCMa; bool isPLCMaUnderHCMa = iPLCMa < iPHCMa; // bool isLCMaCrossedOverHCMa = isLCMaOverHCMa && !isPLCMaOverHCMa; // bool isLCMaCrossedUnderHCMa = isLCMaUnderHCMa && !isPLCMaUnderHCMa; // // SC State ... // bool isSCMaBullish = iSCMaState == bullishState; bool isPSCMaBullish = iPSCMaState == bullishState; // bool isSCMaBearish = iSCMaState == bearishState; bool isPSCMaBearish = iPSCMaState == bearishState; // bool isSCMaSwitchedToBullish = isSCMaBullish && !isPSCMaBullish; // bool isSCMaSwitchedToBearish = isSCMaBearish && !isPSCMaBearish; // bool isSCLLOverMCLL = iSCLL > iMCLL; bool isPSCLLOverMCLL = iPSCLL > iPMCLL; bool isP2SCLLOverMCLL = iP2SCLL > iP2MCLL; bool isP3SCLLOverMCLL = iP3SCLL > iP3MCLL; bool isP4SCLLOverMCLL = iP4SCLL > iP4MCLL; // bool isSCHHUnderMCHH = iSCHH < iMCHH; bool isPSCHHUnderMCHH = iPSCHH < iPMCHH; bool isP2SCHHUnderMCHH = iP2SCHH < iP2MCHH; bool isP3SCHHUnderMCHH = iP3SCHH < iP3MCHH; bool isP4SCHHUnderMCHH = iP4SCHH < iP4MCHH; // bool isSCLLCrossedOverMCLL = isSCLLOverMCLL && !isPSCLLOverMCLL; bool isPSCLLCrossedOverMCLL = isPSCLLOverMCLL && !isP2SCLLOverMCLL; bool isP2SCLLCrossedOverMCLL = isP2SCLLOverMCLL && !isP3SCLLOverMCLL; bool isP3SCLLCrossedOverMCLL = isP3SCLLOverMCLL && !isP4SCLLOverMCLL; // bool isSCHHCrossedUnderMCHH = isSCHHUnderMCHH && !isPSCHHUnderMCHH; bool isPSCHHCrossedUnderMCHH = isPSCHHUnderMCHH && !isP2SCHHUnderMCHH; bool isP2SCHHCrossedUnderMCHH = isP2SCHHUnderMCHH && !isP3SCHHUnderMCHH; bool isP3SCHHCrossedUnderMCHH = isP3SCHHUnderMCHH && !isP4SCHHUnderMCHH; // // MC State ... // bool isMCMaBullish = iMCMaState == bullishState; bool isPMCMaBullish = iPMCMaState == bullishState; // bool isMCMaBearish = iMCMaState == bearishState; bool isPMCMaBearish = iPMCMaState == bearishState; // bool isMCMaSwitchedToBullish = isMCMaBullish && !isPMCMaBullish; // bool isMCMaSwitchedToBearish = isMCMaBearish && !isPMCMaBearish; // bool isMCLLOverLCLL = iMCLL > iLCLL; bool isPMCLLOverLCLL = iPMCLL > iPLCLL; bool isP2MCLLOverLCLL = iP2MCLL > iP2LCLL; bool isP3MCLLOverLCLL = iP3MCLL > iP3LCLL; bool isP4MCLLOverLCLL = iP4MCLL > iP4LCLL; // bool isMCHHUnderLCHH = iMCHH < iLCHH; bool isPMCHHUnderLCHH = iPMCHH < iPLCHH; bool isP2MCHHUnderLCHH = iP2MCHH < iP2LCHH; bool isP3MCHHUnderLCHH = iP3MCHH < iP3LCHH; bool isP4MCHHUnderLCHH = iP4MCHH < iP4LCHH; // bool isMCLLCrossedOverLCLL = isMCLLOverLCLL && !isPMCLLOverLCLL; bool isPMCLLCrossedOverLCLL = isPMCLLOverLCLL && !isP2MCLLOverLCLL; bool isP2MCLLCrossedOverLCLL = isP2MCLLOverLCLL && !isP3MCLLOverLCLL; bool isP3MCLLCrossedOverLCLL = isP3MCLLOverLCLL && !isP4MCLLOverLCLL; // bool isMCHHCrossedUnderLCHH = isMCHHUnderLCHH && !isPMCHHUnderLCHH; bool isPMCHHCrossedUnderLCHH = isPMCHHUnderLCHH && !isP2MCHHUnderLCHH; bool isP2MCHHCrossedUnderLCHH = isP2MCHHUnderLCHH && !isP3MCHHUnderLCHH; bool isP3MCHHCrossedUnderLCHH = isP3MCHHUnderLCHH && !isP4MCHHUnderLCHH; // // LC State ... // bool isLCMaBullish = iLCMaState == bullishState; bool isPLCMaBullish = iPLCMaState == bullishState; // bool isLCMaBearish = iLCMaState == bearishState; bool isPLCMaBearish = iPLCMaState == bearishState; // bool isLCMaSwitchedToBullish = isLCMaBullish && !isPLCMaBullish; // bool isLCMaSwitchedToBearish = isLCMaBearish && !isPLCMaBearish; // bool isLCLLOverHCLL = iLCLL > iHCLL; bool isPLCLLOverHCLL = iPLCLL > iPHCLL; bool isP2LCLLOverHCLL = iP2LCLL > iP2HCLL; bool isP3LCLLOverHCLL = iP3LCLL > iP3HCLL; bool isP4LCLLOverHCLL = iP4LCLL > iP4HCLL; // bool isLCHHUnderHCHH = iLCHH < iHCHH; bool isPLCHHUnderHCHH = iPLCHH < iPHCHH; bool isP2LCHHUnderHCHH = iP2LCHH < iP2HCHH; bool isP3LCHHUnderHCHH = iP3LCHH < iP3HCHH; bool isP4LCHHUnderHCHH = iP4LCHH < iP4HCHH; // bool isLCLLCrossedOverHCLL = isLCLLOverHCLL && !isPLCLLOverHCLL; bool isPLCLLCrossedOverHCLL = isPLCLLOverHCLL && !isP2LCLLOverHCLL; bool isP2LCLLCrossedOverHCLL = isP2LCLLOverHCLL && !isP3LCLLOverHCLL; bool isP3LCLLCrossedOverHCLL = isP3LCLLOverHCLL && !isP4LCLLOverHCLL; // bool isLCHHCrossedUnderHCHH = isLCHHUnderHCHH && !isPLCHHUnderHCHH; bool isPLCHHCrossedUnderHCHH = isPLCHHUnderHCHH && !isP2LCHHUnderHCHH; bool isP2LCHHCrossedUnderHCHH = isP2LCHHUnderHCHH && !isP3LCHHUnderHCHH; bool isP3LCHHCrossedUnderHCHH = isP3LCHHUnderHCHH && !isP4LCHHUnderHCHH; // // HC State ... // bool isHCMaBullish = iHCMaState == bullishState; bool isPHCMaBullish = iPHCMaState == bullishState; // bool isHCMaBearish = iHCMaState == bearishState; bool isPHCMaBearish = iPHCMaState == bearishState; // bool isHCMaSwitchedToBullish = isHCMaBullish && !isPHCMaBullish; // bool isHCMaSwitchedToBearish = isHCMaBearish && !isPHCMaBearish; /////////////////////////////////////////////////////////////////////////////// // // HK Signal Bar ... // double iHKSOpen = hkSBarOpenBuffer[barIndex]; double iHKSClose = hkSBarCloseBuffer[barIndex]; // double iHKSMax = MathMax(iHKSOpen, iHKSClose); double iHKSMin = MathMin(iHKSOpen, iHKSClose); // bool isHKSBullish = hkSBarOpenBuffer[barIndex] < hkSBarCloseBuffer[barIndex]; bool isPHKSBullish = hkSBarOpenBuffer[barIndex + 1] < hkSBarCloseBuffer[barIndex + 1]; // bool isHKSBearish = hkSBarOpenBuffer[barIndex] > hkSBarCloseBuffer[barIndex]; bool isPHKSBearish = hkSBarOpenBuffer[barIndex + 1] > hkSBarCloseBuffer[barIndex + 1]; // bool isHKSSwitchedToBullish = isHKSBullish && !isPHKSBullish; // bool isHKSSwitchedToBearish = isHKSBearish && !isPHKSBearish; // // TREND ... // double iTrend = trendBuffer[barIndex]; bool isTrendBullish = trendStateBuffer[barIndex] > 0; bool isTrendBearish = trendStateBuffer[barIndex] < 0; bool isTrendSwitchedToBullish = trendStateBuffer[barIndex] > 0 && trendStateBuffer[barIndex + 1] <= 0; bool isTrendSwitchedToBearish = trendStateBuffer[barIndex] < 0 && trendStateBuffer[barIndex + 1] >= 0; // // RSI ... // bool isRSIOverOB = rsiBuffer[barIndex] > rsiOBLevel; bool isPRSIOverOB = rsiBuffer[barIndex + 1] > rsiOBLevel; // bool isRSIUnderOB = rsiBuffer[barIndex] < rsiOBLevel; bool isPRSIUnderOB = rsiBuffer[barIndex + 1] < rsiOBLevel; // bool isRSICrossedOverOB = isRSIOverOB && !isPRSIOverOB; // bool isRSICrossedUnderOB = isRSIUnderOB && !isPRSIUnderOB; // bool isRSIOverOS = rsiBuffer[barIndex] > rsiOSLevel; bool isPRSIOverOS = rsiBuffer[barIndex + 1] > rsiOSLevel; // bool isRSIUnderOS = rsiBuffer[barIndex] < rsiOSLevel; bool isPRSIUnderOS = rsiBuffer[barIndex + 1] < rsiOSLevel; // bool isRSICrossedOverOS = isRSIOverOS && !isPRSIOverOS; // bool isRSICrossedUnderOS = isRSIUnderOS && !isPRSIUnderOS; // // ADX ... // bool isADXOverThreshold = adxBuffer[barIndex] > adxThreshold; bool isPADXOverThreshold = adxBuffer[barIndex + 1] > adxThreshold; // bool isADXUnderThreshold = adxBuffer[barIndex] < adxThreshold; bool isPADXUnderThreshold = adxBuffer[barIndex + 1] < adxThreshold; // bool isADXCrossedOverThreshold = isADXOverThreshold && !isPADXOverThreshold; // bool isADXCrossedUnderThreshold = isADXUnderThreshold && !isPADXUnderThreshold; // bool isADXBullish = adxpBuffer[barIndex] > adxnBuffer[barIndex]; bool isPADXBullish = adxpBuffer[barIndex + 1] > adxnBuffer[barIndex + 1]; // bool isADXBearish = adxpBuffer[barIndex] < adxnBuffer[barIndex]; bool isPADXBearish = adxpBuffer[barIndex + 1] < adxnBuffer[barIndex + 1]; // bool isADXSwitchedToBullish = isADXBullish && !isPADXBullish; // bool isADXSwitchedToBearish = isADXBearish && !isPADXBearish; // bool isADXFullySwitchedToBullish = isADXSwitchedToBullish && isADXCrossedOverThreshold; // bool isADXFullySwitchedToBearish = isADXSwitchedToBearish && isADXCrossedUnderThreshold; // bool isTriggerBarOverHKS = iBar.low > iHKSMax; bool isTriggerBarUnderHKS = iBar.high < iHKSMin; // // KI ... // bool isKIBullish = kiStateBuffer[barIndex] > 0; bool isPKIBullish = kiStateBuffer[barIndex + 1] > 0; // bool isKIBearish = kiStateBuffer[barIndex] < 0; bool isPKIBearish = kiStateBuffer[barIndex = 1] < 0; // // // bool isKIOverHKS = // kiBuffer[barIndex] > iHKSMax; // // // bool isKIUnderHKS = // kiBuffer[barIndex] < iHKSMin; // bool isKISwitchedToBullish = isKIBullish && !isPKIBullish; // bool isKISwitchedToBearish = isKIBearish && !isPKIBearish; // // Detecting Signal ... // // Bullish ... isBullish = // false // Conditions Validation ... // isKIOverHKS && // isHKSBullish && // isKISwitchedToBullish // && // // Bar Validation ... // iBar.IsBullish() && // iBar.close > kiBuffer[barIndex] // ; // // Bearish ... isBearish = // false // Conditions Validation ... // isKIUnderHKS && // isHKSBearish && // isKISwitchedToBearish // && // // Bar Validation ... // iBar.IsBearish() && // iBar.close < kiBuffer[barIndex] // ; //////////////////////////////////////////////////////////////////// // int mSameKICount = 0; int mSameKIBullishCount = 0; int mSameKIBearishCount = 0; // int mSamePeakCount = 0; int mSameValeCount = 0; // double mSamePeaksGoldenMin = 0; double mSamePeaksGoldenMax = 0; // double mSameValesGoldenMin = 0; double mSameValesGoldenMax = 0; // int mSamePeakGoldenCount = 0; int mSameValeGoldenCount = 0; // bool mDrawLiquidities = false; bool mDrawRangeBreakes = false; // bool mDetectLiquidities = true; bool mDetectRangeBreakes = true; // XBoxZone mBullishLiquidities[]; XBoxZone mBearishLiquidities[]; XBoxZone mBullishRangeBreakes[]; XBoxZone mBearishRangeBreakes[]; // // POI(s) Handlers ... // /** * Detect POI(s) ... * * @param barIndex: 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 DetectPOIs( int barIndex, const int prevCalculated, const int ratesTotal, const double &open[], const double &high[], const double &close[], const double &low[], const long &tickVolume[] // ) { // // Check Some Requirements ... int lastBarIndex = barIndex + 1; int maxBarIndex = startCalculationForLastBars > 0 ? startCalculationForLastBars : ratesTotal; bool isFirstBar = startCalculationForLastBars > 0 ? barIndex == startCalculationForLastBars : barIndex == firstBarIndex; // // Handle Minimum Required Bars ... bool isPassedRequiredBars = barIndex < maxBarIndex - 3; if (!isPassedRequiredBars) { return; } // // Recieve Bar ... XOHCL iBar; XOHCL iPBar; bool has = iBar.Init( _Symbol, _Period, barIndex // ); has = has && iBar.GetPreviousBar(iPBar); if (!has) { return; } // bool isBullish = false; bool isBearish = false; int maxAllowedPOIs = 50; // ENUM_X_DIRECTION iDir; // // Detecting Liquidity ... if (mDetectLiquidities) { // bool isLiquidity = mBarAnalyser .IsRejected( iBar, iDir, true, true // ); bool isBullishLiquiditySweeped = isLiquidity && IsBullish(iDir); bool isBearishLiquiditySweeped = isLiquidity && IsBearish(iDir); if (isLiquidity) { // XBoxZone iLiq; // iLiq.dir = iDir; iLiq.type = "XLIQ"; iLiq.upper = isBullishLiquiditySweeped ? iBar.GetDown() : iBar.high; iLiq.lower = isBullishLiquiditySweeped ? iBar.low : iBar.GetUp(); iLiq.at = iBar.time; iLiq.from = iBar.time; iLiq.symbol = _Symbol; iLiq.period = _Period; iLiq.to = ((datetime)((int)iBar.time + (PeriodSeconds(_Period)))); // if (iLiq.IsValid()) { // if (isBullishLiquiditySweeped) { // has = AddBoxIfNotExists( iLiq, mBullishLiquidities // ); if (has) { // SortBoxes( mBullishLiquidities, maxAllowedPOIs // ); } } else { // has = AddBoxIfNotExists( iLiq, mBearishLiquidities // ); if (has) { // SortBoxes( mBearishLiquidities, maxAllowedPOIs // ); } } } // iLiq.Clean(); } } // // Detecting Bullish and Bearish Breakes ... // bool isPeakSame = peakBuffer[barIndex] == peakBuffer[barIndex + 1]; bool isPPeakSame = peakBuffer[barIndex + 1] == peakBuffer[barIndex + 2]; // bool isPeakOverLast = peakBuffer[barIndex] > peakBuffer[barIndex + 1]; bool isPPeakOverLast = peakBuffer[barIndex + 1] > peakBuffer[barIndex + 2]; // bool isPeakUnderLast = peakBuffer[barIndex] < peakBuffer[barIndex + 1]; bool isPPeakUnderLast = peakBuffer[barIndex + 1] < peakBuffer[barIndex + 2]; // bool isSamePeakOverLast = isPPeakSame && isPeakOverLast; bool isSamePeakUnderLast = isPPeakSame && isPeakUnderLast; // bool isValeSame = valeBuffer[barIndex] == valeBuffer[barIndex + 1]; bool isPValeSame = valeBuffer[barIndex + 1] == valeBuffer[barIndex + 2]; // bool isValeOverLast = valeBuffer[barIndex] > valeBuffer[barIndex + 1]; bool isPValeOverLast = valeBuffer[barIndex + 1] > valeBuffer[barIndex + 2]; // bool isValeUnderLast = valeBuffer[barIndex] < valeBuffer[barIndex + 1]; bool isPValeUnderLast = valeBuffer[barIndex + 1] < valeBuffer[barIndex + 2]; // bool isSameValeOverLast = isPValeSame && isValeOverLast; bool isSameValeUnderLast = isPValeSame && isValeUnderLast; // // Detecting Range Breakes ... if (mDetectRangeBreakes) { // isBullish = isSamePeakOverLast // || isSameValeOverLast ; isBearish = isSameValeUnderLast // || isSamePeakUnderLast ; // bool basedOnPeak = isSamePeakOverLast // || isSamePeakUnderLast ; // bool basedOnVale = isSameValeUnderLast // isSameValeOverLast || ; // has = isBullish || isBearish; // if (has) { // XBoxZone iRNGBreak; // iDir = isBullish ? X_DIRECTION_BULLISH : isBearish ? X_DIRECTION_BEARISH : X_DIRECTION_NONE; // iRNGBreak.dir = iDir; iRNGBreak.at = iBar.time; iRNGBreak.type = "XRNGB"; iRNGBreak.to = iBar.time; iRNGBreak.symbol = _Symbol; iRNGBreak.period = _Period; // int fromIDX = iBar.Index() + (basedOnPeak ? mSamePeakCount : basedOnVale ? mSameValeCount : 0); datetime from = GetBarTime( _Symbol, _Period, fromIDX // ); iRNGBreak.from = from; // double upper = isBullish ? basedOnPeak ? peakBuffer[barIndex] : basedOnVale ? mSameValeGoldenCount : 0 : isBearish ? basedOnPeak ? peakBuffer[barIndex] : basedOnVale ? mSameValeGoldenCount : 0 : 0; // double lower = isBullish ? basedOnPeak ? mSamePeakGoldenCount : basedOnVale ? valeBuffer[barIndex] : 0 : isBearish ? basedOnPeak ? mSamePeakGoldenCount : basedOnVale ? valeBuffer[barIndex] : 0 : 0; // iRNGBreak.upper = upper; iRNGBreak.lower = lower; // // Adding POI ... has = iRNGBreak.IsValid(); if (has) { // if (isBullish) { // has = AddBoxIfNotExists( iRNGBreak, mBullishRangeBreakes // ); if (has) { // SortBoxes( mBullishRangeBreakes, maxAllowedPOIs // ); } } else if (isBearish) { // has = AddBoxIfNotExists( iRNGBreak, mBearishRangeBreakes // ); if (has) { // SortBoxes( mBearishRangeBreakes, maxAllowedPOIs // ); } } } } } // if (isPeakSame) { // mSamePeakGoldenCount = mSamePeakGoldenCount == 0 ? iBar.GetUp() : MathMax(mSamePeakGoldenCount, iBar.GetUp()); mSamePeakCount++; } else { // mSamePeakCount = 0; mSamePeakGoldenCount = 0; } // if (isValeSame) { // mSameValeGoldenCount = mSameValeGoldenCount == 0 ? iBar.GetDown() : MathMin(mSameValeGoldenCount, iBar.GetDown()); mSameValeCount++; } else { // mSameValeCount = 0; mSameValeGoldenCount = 0; } // // Cleanup Resources ... // iBar.Clean(); iPBar.Clean(); } /** * Validate Detected POI(s) ... * * @param barIndex: 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 ValidatePOIs( int barIndex, const int prevCalculated, const int ratesTotal, const double &open[], const double &high[], const double &close[], const double &low[], const long &tickVolume[] // ) { // int count = 0; bool has = false; int barsLength = 3; datetime to = GetBarTime( _Symbol, _Period, barIndex // ); // // Liquidities ... // // Bullish Liquidities ... count = ArraySize(mBullishLiquidities); has = IsValidSize(count); if (has) { // ValidateBoxes( mBullishLiquidities, barIndex, barsLength // ); } // // Bearish Liquidities ... count = ArraySize(mBearishLiquidities); has = IsValidSize(count); if (has) { // ValidateBoxes( mBearishLiquidities, barIndex, barsLength // ); } // // Range Breaks ... // // Bullish ... count = ArraySize(mBullishRangeBreakes); has = IsValidSize(count); if (has) { // ValidateBoxes( mBullishRangeBreakes, barIndex, barsLength // ); } // // Bearish ... count = ArraySize(mBearishRangeBreakes); has = IsValidSize(count); if (has) { // ValidateBoxes( mBearishRangeBreakes, barIndex, barsLength // ); } // } /** * Draw Detected POI(s) ... * * @param barIndex: 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 DrawPOIs( int barIndex, const int prevCalculated, const int ratesTotal, const double &open[], const double &high[], const double &close[], const double &low[], const long &tickVolume[] // ) { // int count = 0; XBoxZone iBox; bool has = false; datetime to = GetBarTime( _Symbol, _Period, barIndex // ); // // Liquidities ... if (mDrawLiquidities) { // count = ArraySize(mBullishLiquidities); has = IsValidSize(count); if (has) { // for (int i = 0; i < count; i++) { // iBox = mBullishLiquidities[i]; iBox.to = to; // XCBoxObject *iObj; has = mDrawer.DrawBox( iBox, iObj // ); if (has) { mObjects.Add(iObj); } // iBox.Clean(); } } // count = ArraySize(mBearishLiquidities); has = IsValidSize(count); if (has) { // for (int i = 0; i < count; i++) { // iBox = mBearishLiquidities[i]; iBox.to = to; // XCBoxObject *iObj; has = mDrawer.DrawBox( iBox, iObj // ); if (has) { mObjects.Add(iObj); } // iBox.Clean(); } } } // // Range Breaks ... if (mDrawRangeBreakes) { // // Bullish ... count = ArraySize(mBullishRangeBreakes); has = IsValidSize(count); if (has) { // for (int i = 0; i < count; i++) { // iBox = mBullishRangeBreakes[i]; iBox.to = to; // XCBoxObject *iObj; has = mDrawer.DrawBox( iBox, iObj // ); if (has) { // XPOIStyle iStyle; iStyle.width = 1; iStyle.clr = clrAqua; iStyle.style = STYLE_DOT; // mDrawer.ApplyStyle( iObj, iStyle // ); // mObjects.Add(iObj); } // iBox.Clean(); } } // // Bearish ... count = ArraySize(mBearishRangeBreakes); has = IsValidSize(count); if (has) { // for (int i = 0; i < count; i++) { // iBox = mBearishRangeBreakes[i]; iBox.to = to; // XCBoxObject *iObj; has = mDrawer.DrawBox( iBox, iObj // ); if (has) { // XPOIStyle iStyle; iStyle.width = 1; iStyle.clr = clrMagenta; iStyle.style = STYLE_DOT; // mDrawer.ApplyStyle( iObj, iStyle // ); // mObjects.Add(iObj); } // iBox.Clean(); } } } // } /** * Process Custom Analysing Senarios ... * * @param barIndex: 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 DoProcess( int barIndex, const int prevCalculated, const int ratesTotal, const double &open[], const double &high[], const double &close[], const double &low[], const long &tickVolume[] // ) { // // Check Some Requirements ... int lastBarIndex = barIndex + 1; int maxBarIndex = startCalculationForLastBars > 0 ? startCalculationForLastBars : ratesTotal; bool isFirstBar = startCalculationForLastBars > 0 ? barIndex == startCalculationForLastBars : barIndex == firstBarIndex; // // Recieve Bar ... XOHCL iBar; XOHCL iPBar; bool has = iBar.Init( _Symbol, _Period, barIndex // ); has = has && iBar.GetPreviousBar(iPBar); if (!has) { return; } // // Do Process ... // // Detecting Trigger Bar ... // bool hasSignal = false; bool isBullish = false; bool isBearish = false; string namePrefix = NULL; int triggerBarPushers = 0; ENUM_X_DIRECTION triggerDir; // // Detecting Trigger Bars ... // bool isCond1Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, true, // Cond 1 ... false, // Cond 2 ... false, // Cond 3 ... false, // Cond 4 ... false, // Cond 5 ... false, // Cond 6 ... false // Cond 7 ... ); bool isCond1BullishTrigger = isCond1Trigger && IsBullish(triggerDir); bool isCond1BearishTrigger = isCond1Trigger && IsBearish(triggerDir); if (isCond1Trigger) { // triggerBarPushers++; namePrefix += "Cond1"; } // bool isCond2Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, false, // Cond 1 ... true, // Cond 2 ... false, // Cond 3 ... false, // Cond 4 ... false, // Cond 5 ... false, // Cond 6 ... false // Cond 7 ... ); bool isCond2BullishTrigger = isCond2Trigger && IsBullish(triggerDir); bool isCond2BearishTrigger = isCond2Trigger && IsBearish(triggerDir); if (isCond2Trigger) { // triggerBarPushers++; namePrefix += "Cond2"; } // bool isCond3Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... true, // Cond 3 ... false, // Cond 4 ... false, // Cond 5 ... false, // Cond 6 ... false // Cond 7 ... ); bool isCond3BullishTrigger = isCond3Trigger && IsBullish(triggerDir); bool isCond3BearishTrigger = isCond3Trigger && IsBearish(triggerDir); if (isCond3Trigger) { // triggerBarPushers++; namePrefix += "Cond3"; } // bool isCond4Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... false, // Cond 3 ... true, // Cond 4 ... false, // Cond 5 ... false, // Cond 6 ... false // Cond 7 ... ); bool isCond4BullishTrigger = isCond4Trigger && IsBullish(triggerDir); bool isCond4BearishTrigger = isCond4Trigger && IsBearish(triggerDir); if (isCond4Trigger) { // triggerBarPushers++; namePrefix += "Cond4"; } // bool isCond5Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... false, // Cond 3 ... false, // Cond 4 ... true, // Cond 5 ... false, // Cond 6 ... false // Cond 7 ... ); bool isCond5BullishTrigger = isCond5Trigger && IsBullish(triggerDir); bool isCond5BearishTrigger = isCond5Trigger && IsBearish(triggerDir); if (isCond5Trigger) { // triggerBarPushers++; namePrefix += "Cond5"; } // bool isCond6Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... false, // Cond 3 ... false, // Cond 4 ... false, // Cond 5 ... true, // Cond 6 ... false // Cond 7 ... ); bool isCond6BullishTrigger = isCond6Trigger && IsBullish(triggerDir); bool isCond6BearishTrigger = isCond6Trigger && IsBearish(triggerDir); if (isCond6Trigger) { // triggerBarPushers++; namePrefix += "Cond6"; } // bool isCond7Trigger = mBarAnalyser .IsValidForTrigger( iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... false, // Cond 3 ... false, // Cond 4 ... false, // Cond 5 ... false, // Cond 6 ... true // Cond 7 ... ); bool isCond7BullishTrigger = isCond7Trigger && IsBullish(triggerDir); bool isCond7BearishTrigger = isCond7Trigger && IsBearish(triggerDir); if (isCond7Trigger) { // triggerBarPushers++; namePrefix += "Cond7"; } // // Summarizing Trigger Bars ... // bool isBullishTriggerBar = // isCond1BullishTrigger || isCond2BullishTrigger || isCond3BullishTrigger || isCond4BullishTrigger || isCond5BullishTrigger || isCond6BullishTrigger || isCond7BullishTrigger // ; // bool isBearishTriggerBar = // isCond1BearishTrigger || isCond2BearishTrigger || isCond3BearishTrigger || isCond4BearishTrigger || isCond5BearishTrigger || isCond6BearishTrigger || isCond7BearishTrigger // ; // bool isTriggerBar = // triggerBarPushers >= 1 && (isBullishTriggerBar || isBearishTriggerBar) // ; // // Reading Required Condiions ... // int pIndex = barIndex + 1; int ppIndex = barIndex + 2; // // PV ... // bool isSamePeak = peakBuffer[pIndex] == peakBuffer[ppIndex]; bool isSameVale = valeBuffer[pIndex] == valeBuffer[ppIndex]; // bool isPeakOverLast = peakBuffer[pIndex] > peakBuffer[ppIndex]; bool isPeakUnderLast = peakBuffer[pIndex] < peakBuffer[ppIndex]; // bool isValeOverLast = valeBuffer[pIndex] > valeBuffer[ppIndex]; bool isValeUnderLast = valeBuffer[pIndex] < valeBuffer[ppIndex]; // bool isSamePeakGolden = peakGoldenBuffer[pIndex] == peakGoldenBuffer[ppIndex]; bool isSameValeGolden = valeGoldenBuffer[pIndex] == valeGoldenBuffer[ppIndex]; // bool isPeakGoldeOverLast = peakGoldenBuffer[pIndex] > peakGoldenBuffer[ppIndex]; bool isPeakGoldenUnderLast = peakGoldenBuffer[pIndex] < peakGoldenBuffer[ppIndex]; // bool isValeGoldenOverLast = valeGoldenBuffer[pIndex] > valeGoldenBuffer[ppIndex]; bool isValeGoldenUnderLast = valeGoldenBuffer[pIndex] < valeGoldenBuffer[ppIndex]; // if (isSamePeak) { mSamePeakCount++; } else { mSamePeakCount = 0; } // if (isSameVale) { mSameValeCount++; } else { mSameValeCount = 0; } // if (isSamePeakGolden) { mSamePeakGoldenCount++; } else { mSamePeakGoldenCount = 0; } // if (isSameValeGolden) { mSameValeGoldenCount++; } else { mSameValeGoldenCount = 0; } // // SAR ... // bool isSarBullish = sarStateBuffer[pIndex] > 0; bool isPSarBullish = sarStateBuffer[ppIndex] > 0; // bool isSarBearish = sarStateBuffer[pIndex] < 0; bool isPSarBearish = sarStateBuffer[ppIndex] < 0; // bool isSarSwitchedToBullish = isSarBullish && !isPSarBullish; // bool isSarSwitchedToBearish = isSarBearish && !isPSarBearish; // // HKS ... // bool isHKSBullish = hkSBarCloseBuffer[pIndex] > hkSBarOpenBuffer[pIndex]; bool isPHKSBullish = hkSBarCloseBuffer[ppIndex] > hkSBarOpenBuffer[ppIndex]; // bool isHKSBearish = hkSBarCloseBuffer[pIndex] < hkSBarOpenBuffer[pIndex]; bool isPHKSBearish = hkSBarCloseBuffer[ppIndex] < hkSBarOpenBuffer[ppIndex]; // bool isHKSSwitchedToBullish = isHKSBullish && !isPHKSBullish; // bool isHKSSwitchedToBearish = isHKSBearish && !isPHKSBearish; // // SB ... // bool isSBullish = sBarCloseBuffer[pIndex] > sBarOpenBuffer[pIndex]; bool isPSBullish = sBarCloseBuffer[ppIndex] > sBarOpenBuffer[ppIndex]; // bool isSBearish = sBarCloseBuffer[pIndex] < sBarOpenBuffer[pIndex]; bool isPSBearish = sBarCloseBuffer[ppIndex] < sBarOpenBuffer[ppIndex]; // bool isSSwitchedToBullish = isSBullish && !isPSBullish; // bool isSSwitchedToBearish = isSBearish && !isPSBearish; // // KI ... // bool isKIBullish = kiStateBuffer[pIndex] > 0; bool isPKIBullish = kiStateBuffer[ppIndex] > 0; // bool isKIBearish = kiStateBuffer[pIndex] < 0; bool isPKIBearish = kiStateBuffer[ppIndex] < 0; // bool isKISwitchedToBullish = isKIBullish && !isPKIBullish; // bool isKISwitchedToBearish = isKIBearish && !isPKIBearish; // bool isKIBullishBreaked = iPBar.IsBreaked( kiBuffer[pIndex], X_DIRECTION_BULLISH, X_FIBO_LEVEL_500, X_BOUNDARY_PRICE_UP_DOWN // ); // bool isKIBearishBreaked = iPBar.IsBreaked( kiBuffer[pIndex], X_DIRECTION_BEARISH, X_FIBO_LEVEL_500, X_BOUNDARY_PRICE_UP_DOWN // ); // bool isKISame = kiBuffer[pIndex] == kiBuffer[ppIndex]; bool isKIBullishSame = isKISame && isKIBullish; bool isKIBearishSame = isKISame && isKIBearish; // if (isKISame) { mSameKICount++; } else { mSameKICount = 0; } // if (isKIBullishSame) { mSameKIBullishCount++; } else { mSameKIBullishCount = 0; } // if (isKIBearishSame) { mSameKIBearishCount++; } else { mSameKIBearishCount = 0; } // // Validating Trigger Bar based on Conditions ... if (isTriggerBar) { // // TODO: Remove this if required ... isTriggerBar = false; isBullishTriggerBar = false; isBearishTriggerBar = false; } // // Detecting Signal ... // // Bullish ... isBullish = // // Conditions Validation ... isKIBullishBreaked // isSSwitchedToBullish // isKISwitchedToBullish // isSarSwitchedToBullish // isHKSSwitchedToBullish // // Bar Validation ... // ; // // Bearish ... isBearish = // // Conditions Validation ... isKIBearishBreaked // isSSwitchedToBearish // isKISwitchedToBearish // isSarSwitchedToBearish // isHKSSwitchedToBearish // // Bar Validation ... // ; // // Summarizing Signal ... hasSignal = isBullish || isBearish; // // Draw Requirements ... // // Draw Trigger Bar ... if (isTriggerBar) { // int triggerBullishArrowCode = 225; int triggerBearishArrowCode = 226; // color triggerBarBullishColor = clrLime; color triggerBarBearishColor = clrRed; // ENUM_ARROW_ANCHOR triggerBullishAnchor = ANCHOR_TOP; ENUM_ARROW_ANCHOR triggerBearishAnchor = ANCHOR_BOTTOM; // int arrowWidth = 3; int arrowCode = isBullishTriggerBar ? triggerBullishArrowCode : triggerBearishArrowCode; ENUM_X_PRICE arrowPriceType = isBullishTriggerBar ? X_PRICE_LOW : X_PRICE_HIGH; color arrowColor = isBullishTriggerBar ? triggerBarBullishColor : triggerBarBearishColor; ENUM_ARROW_ANCHOR arrowAnchor = isBullishTriggerBar ? triggerBullishAnchor : triggerBearishAnchor; // XCBarArrowObject *iObj; has = mDrawer.CreateBarArrow( iBar, iObj, arrowPriceType, arrowCode, arrowColor, arrowWidth, arrowAnchor, namePrefix // ); if (has) { mObjects.Add(iObj); } // // Converts to Box ... XBoxZone iBox; iBox.type = "XTRB"; iBox.to = iBar.time; iBox.symbol = _Symbol; iBox.period = _Period; iBox.lower = iPBar.low; iBox.from = iPBar.time; iBox.upper = iPBar.high; iBox.dir = isBullishTriggerBar ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH; if (iBox.IsValid()) { // // XCBoxObject *iObj; // has = mDrawer.DrawBox( // iBox, // iObj // // ); // if (has) // { // mObjects.Add(iObj); // } // XSignal iSignal; double iRewardRatios[] = { 1, 1.5, 2 // }; has = ToSignal( iBox, iSignal, iRewardRatios, 0 // Additional SL ... ); if (has) { // XCSignalObject *iObj; has = mDrawer.DrawSignal( iSignal, iObj, 4 // ); if (has) { mObjects.Add(iObj); } } } // } // // Draw Signal ... if (hasSignal) { // int bullishArrowCode = 225; int bearishArrowCode = 226; // color bullishColor = clrLime; color bearishColor = clrRed; // ENUM_ARROW_ANCHOR bullishAnchor = ANCHOR_TOP; ENUM_ARROW_ANCHOR bearishAnchor = ANCHOR_BOTTOM; // int arrowWidth = 3; int arrowCode = isBullish ? bullishArrowCode : bearishArrowCode; ENUM_X_PRICE arrowPriceType = isBullish ? X_PRICE_LOW : X_PRICE_HIGH; color arrowColor = isBullish ? bullishColor : bearishColor; ENUM_ARROW_ANCHOR arrowAnchor = isBullish ? bullishAnchor : bearishAnchor; // XCBarArrowObject *iObj; has = mDrawer.CreateBarArrow( iBar, iObj, arrowPriceType, arrowCode, arrowColor, arrowWidth, arrowAnchor, namePrefix // ); if (has) { mObjects.Add(iObj); } // // Converts to Box ... XBoxZone iBox; iBox.type = "XSG"; iBox.to = iBar.time; iBox.symbol = _Symbol; iBox.period = _Period; iBox.lower = iPBar.low; iBox.from = iPBar.time; iBox.upper = iPBar.high; iBox.dir = isBullish ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH; if (iBox.IsValid()) { // XSignal iSignal; double iRewardRatios[] = { 1, 1.5, 2 // }; has = ToSignal( iBox, iSignal, iRewardRatios, 0 // Additional SL ... ); if (has) { // XCSignalObject *iObj; has = mDrawer.DrawSignal( iSignal, iObj, 4 // ); if (has) { mObjects.Add(iObj); } } } } // // Cleanup Resources ... // iBar.Clean(); iPBar.Clean(); } ////////////////////////////////////////////////////////////////////