From 60980ff036c2fbf1013cabe9ecf345733f8cb241 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 22 Feb 2025 14:28:59 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-bar.analyser.class.mq5 | 133 +- Documents/BKP/xsupdem/plib.tmp.codes.mq5 | 304 +++ Indicators/x-saherelm.x121.xwz.mq5 | 2164 +++++++++++++------ Libraries/x-saherelm.x-poi.lib.mq5 | 8 +- 4 files changed, 1998 insertions(+), 611 deletions(-) diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 6eaacbff..d2b906dd 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -1136,6 +1136,51 @@ class XCBarAnalyser : public XCBase return result; } + /** + * Check Specified Bar is Swing or not ... + * + * @param bar: XOHCL instnce ... + * @param dir: ENUM_X_DIRECTION member ... + * @param range: Integer, Specified Range ... + * + * @return ( bool ) + */ + bool IsSwing( + XOHCL &bar, + ENUM_X_DIRECTION &dir, + int range = 2 // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + bool isSwingLow = IsSwingLow(bar, range); + bool isSwingHigh = IsSwingHigh(bar, range); + + // + result = isSwingLow || + isSwingHigh; + if (result) + { + // + if (isSwingLow) + { + dir = X_DIRECTION_BULLISH; + } + else + { + dir = X_DIRECTION_BEARISH; + } + } + + // + return result; + } + /** * Check a Bar is Momentum Bar or not ... * @@ -1765,10 +1810,10 @@ class XCBarAnalyser : public XCBase /** * Check a Bar Has Support or not ... - * + * * @param bar: XOHCL instance ... * @param supportBar: XOHCL instance Specified Support Bar ... - * @param rage: int, + * @param rage: int, * @return ( bool ) */ bool HasSupport( @@ -1935,6 +1980,90 @@ class XCBarAnalyser : public XCBase return result; } + /** + * Check a Bar Has Resistance or not ... + * + * @param bar: XOHCL instance ... + * @param resistanceBar: XOHCL instance Specified Resistance Bar ... + * @param rage: int, + * @return ( bool ) + */ + bool HasResistance( + XOHCL &bar, + XOHCL &resistanceBar, + int range = 21 // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int barIndex = bar.Index() + range; + result = IsValidIndex(barIndex); + if (!result) + { + // + resistanceBar.Clean(); + return result; + } + result = resistanceBar.Init( + bar.symbol, + bar.period, + barIndex // + ); + + // + result = resistanceBar.low < resistanceBar.GetDown(); + if (!result) + { + // + resistanceBar.Clean(); + return result; + } + + // + double selectedValue = resistanceBar.GetUp(); + + // + int hhIDX = bar.FindHighestIndex(range - 1, MODE_HIGH); + result = IsValidIndex(hhIDX); + if (!result) + { + // + resistanceBar.Clean(); + return result; + } + + // + double hhValue = iHigh( + bar.symbol, + bar.period, + hhIDX // + ); + + // + result = hhValue >= selectedValue; + if (!result) + { + // + resistanceBar.Clean(); + return result; + } + + // + result = resistanceBar.IsValid(); + + // + return result; + } + // // Order Blocks ... diff --git a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 index 679b8500..255d6b67 100644 --- a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 +++ b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 @@ -2364,3 +2364,307 @@ bool IsReject( // Clean(tmps); } + + + ////////////////////////////////////////////////////////// + + + // // + // // Calculate Rejection Values ... + + // // + // double fiboUpDown = GetFibonacciLevel( + // iBar.high, + // iBar.low, + // X_FIBO_LEVEL_382, + // X_DIRECTION_BEARISH // + // ); + // double fiboDownUp = GetFibonacciLevel( + // iBar.high, + // iBar.low, + // X_FIBO_LEVEL_382, + // X_DIRECTION_BULLISH // + // ); + + // // + // bool hasFiboToUpPressure = + // fiboDownUp > 0 && + // fiboDownUp <= iBar.GetDown(); + // bool hasFiboToDownPressure = + // fiboUpDown > 0 && + // fiboUpDown >= iBar.GetUp(); + + // // + // bool isLongReject = + // // + // iBar.low < iMa && + // iBar.high >= iMa && + // iBar.GetDown() >= iMa + // // + // ; + // bool isStrongLongReject = + // iBar.IsBullish() && + // isLongReject; + // bool isPressuredLongReject = + // isLongReject && + // hasFiboToUpPressure; + // bool isPressuredStrongLongReject = + // isStrongLongReject && + // isPressuredLongReject; + + // // + // bool isShortReject = + // // + // iBar.high > iMa && + // iBar.low <= iMa && + // iBar.GetUp() <= iMa + // // + // ; + // bool isStrongShortReject = + // iBar.IsBearish() && + // isShortReject; + // bool isPressuredShortReject = + // isShortReject && + // hasFiboToDownPressure; + // bool isPressuredStrongShortReject = + // isStrongShortReject && + // isPressuredShortReject; + + // // + // double iLongRejectValue = 0; + // double iShortRejectValue = 0; + + // // + // bool isAppliedLongReject = false; + // bool isAppliedShortReject = false; + // switch (rejectionType) + // { + // // + // case XWZ_REJECTION_BAR: + // isAppliedLongReject = isLongReject; + // isAppliedShortReject = isShortReject; + // break; + + // // + // case XWZ_REJECTION_STRONG_BAR: + // isAppliedLongReject = isStrongLongReject; + // isAppliedShortReject = isStrongShortReject; + // break; + + // // + // case XWZ_REJECTION_PRESSURED_BAR: + // isAppliedLongReject = isPressuredLongReject; + // isAppliedShortReject = isPressuredShortReject; + // break; + + // // + // case XWZ_REJECTION_STRONG_PRESSURED_BAR: + // isAppliedLongReject = isPressuredStrongLongReject; + // isAppliedShortReject = isPressuredStrongShortReject; + // break; + // } + + // // + // // Calculate Rejection Verification Values ... + + // // + // int iLLIDX = pBar + // .FindLowestIndex( + // rejectionVerificationLength, + // MODE_LOW // + // ); + // datetime iLLTime = iTime( + // _Symbol, + // _Period, + // iLLIDX // + // ); + // double iLL = iLow( + // _Symbol, + // _Period, + // iLLIDX // + // ); + + // // + // int iHHIDX = pBar + // .FindHighestIndex( + // rejectionVerificationLength, + // MODE_HIGH // + // ); + // datetime iHHTime = iTime( + // _Symbol, + // _Period, + // iHHIDX // + // ); + // double iHH = iHigh( + // _Symbol, + // _Period, + // iHHIDX // + // ); + + // // + // bool isLLBreaked = false; + // bool isHHBreaked = false; + // if (rejectionVerificationLength > 0) + // { + // // + // for (int i = bar_index + 1; i < bar_index + rejectionVerificationLength; i++) + // { + // // + // double iMaValue = maBuffer[i]; + + // // + // XOHCL iBar; + // bool isInited = iBar.Init( + // _Symbol, + // _Period, + // i // + // ); + // if (!isInited) + // { + // // + // iBar.Clean(); + // isLLBreaked = true; + // isHHBreaked = true; + // break; + // } + + // // + // if (!isLLBreaked) + // { + // isLLBreaked = iBar.low < iMaValue; + // } + + // // + // if (!isHHBreaked) + // { + // isHHBreaked = iBar.high > iMaValue; + // } + + // // + // if (isLLBreaked && + // isHHBreaked) + // { + // break; + // } + // } + // } + + // // + // // Validate Rejections ... + + // // + // // -[] Before Reject Long, price + // // must not touch Ma from Up for at least 3 Bar ... + // bool isValidAppliedLongReject = + // !isLLBreaked && + // isAppliedLongReject; + + // // + // // -[] Before Reject Short Price + // // must no touch Ma from down at least 3 Bar ... + // bool isValidAppliedShortReject = + // !isHHBreaked && + // isAppliedShortReject; + + // // + // if (isValidAppliedLongReject) + // { + // iLongRejectValue = iBar.low - points10; + // } + // else + // { + // iLongRejectValue = 0; + // } + + // // + // if (isValidAppliedShortReject) + // { + // iShortRejectValue = iBar.high + points10; + // } + // else + // { + // iShortRejectValue = 0; + // } + + // // + // // Draw Verification Box ... + // if (isValidAppliedLongReject || + // isValidAppliedShortReject) + // { + // // + // datetime time1 = iTime( + // _Symbol, + // _Period, + // iBar.Index() + rejectionVerificationLength // + // ); + // datetime time2 = iTime( + // _Symbol, + // _Period, + // iBar.Index() + 0 // + // ); + // string llName = ToString(iLLIDX) + "_" + + // ToString(iLL) + "_" + + // ToMD5(iLLTime); + // CChartObjectTrend *llTrend; + // llTrend = new CChartObjectTrend(); + // bool isCreated = llTrend.Create( + // 0, + // llName, + // 0, + // time1, + // iLL, + // time2, + // iLL // + // ); + // if (isCreated) + // { + // mXWZDrawnObjects.Add(llTrend); + // } + + // // + // string hhName = ToString(iHHIDX) + "_" + + // ToString(iHH) + "_" + + // ToMD5(iHHTime); + // CChartObjectTrend *hhTrend; + // hhTrend = new CChartObjectTrend(); + // isCreated = hhTrend.Create( + // 0, + // hhName, + // 0, + // time1, + // iHH, + // time2, + // iHH // + // ); + // if (isCreated) + // { + // mXWZDrawnObjects.Add(hhTrend); + // } + // } + + // // + // int idx = -1; + // int count = 0; + // bool has = false; + + // // + // ENUM_X_DIRECTION trend = + // IsValid(lastBullishTrend) && + // lastBullishTrend > lastBearishTrend + // ? X_DIRECTION_BULLISH + // : IsValid(lastBearishTrend) && + // lastBearishTrend > lastBullishTrend + // ? X_DIRECTION_BEARISH + // : X_DIRECTION_NONE; + // bool hasTrend = HasDirection(trend); + // bool hasBullishTrend = hasTrend && + // IsBullish(trend); + // bool hasBearishTrend = hasTrend && + // IsBearish(trend); + + // // + // // Filling Buffers ... + + // // + // longSLBuffer[bar_index] = iLongSL; + // shortSLBuffer[bar_index] = iShortSL; diff --git a/Indicators/x-saherelm.x121.xwz.mq5 b/Indicators/x-saherelm.x121.xwz.mq5 index 780dac6d..e36232c7 100644 --- a/Indicators/x-saherelm.x121.xwz.mq5 +++ b/Indicators/x-saherelm.x121.xwz.mq5 @@ -39,6 +39,7 @@ enum ENUM_XWZ_REJECTION_TYPES #include "../Classes/x-saherelm.x-bar.analyser.class.mq5" #include "../Classes/x-saherelm.x-poi.drawer.class.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" +#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" // // Inputs ... @@ -49,9 +50,7 @@ input group "Market"; // input group "Calculation"; -input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Detect Price Type -input ENUM_XWZ_REJECTION_TYPES rejectionType = XWZ_REJECTION_STRONG_BAR; // Rejection Type -input int rejectionVerificationLength = 3; // Rejection Verification Length +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Detect Price Type // input group "MA Detection"; @@ -73,39 +72,48 @@ input double adxThreshold = 25; // ADX Threshold for Strong Trends input group "Presentation"; // +input group "Buffer Presentation"; +input bool showMA = true; // Show Moving Average +input bool showPin = true; // Show Pin Bars +input bool showSwing = true; // Show Swing Bars +input bool showTrend = true; // Show Trend +input bool showEngulf = true; // Show Engulf Bars +input bool showLongSL = true; // Show Long SL +input bool showShortSL = true; // Show Short SL +input bool showMomentum = true; // Show Momentum Bars +input bool showRejection = true; // Show Rejection Bars + +// +input group "POI Presentation"; +input bool showPOIs = true; // Show POI(s) +input bool showActivatedPOIs = true; // Show Activated POI(s) +input bool showOrderBlocks = true; // Show Order Blocks +input bool showFairValueGaps = true; // Show Fair Value Gaps +input bool showSupportZones = false; // Show Support Zones +input bool showResistanceZones = false; // Show Resistance Zones + +// +input group "Presentation Config"; input int startCalculationForLastBars = 1000; // Calculate Last n Bars -input int upTrendArrowCode = 233; // Up Trend Arrow Code -input int downTrendArrowCode = 234; // Down Trend Arrow Code -input int longRejectArrowCode = 225; // Long Reject Arrow Code -input int shortRejectArrowCode = 226; // Short Reject Arrow Code - -// -input bool showMA = true; // Show Moving Average -input bool showLongSL = true; // Show Long SL -input bool showShortSL = true; // Show Short SL -input bool showUpTrend = true; // Show Up Trend -input bool showDownTrend = true; // Show Down Trend -input bool showLongReject = true; // Show Long Reject -input bool showShortReject = true; // Show Short Reject - -// -input bool showPOIs = false; // Draw POI(s) ... -input bool showActivatedPOIs = false; // Draw Activated POI(s) ... -input bool showBullishOrderBlocks = true; // Draw Bullish Order Blocks ... -input bool showBearishOrderBlocks = true; // Draw Bearish Order Blocks ... -input bool showBullishFairValueGaps = true; // Draw Bullish Fair Value Gaps ... -input bool showBearishFairValueGaps = true; // Draw Bearish Fair Value Gaps ... -input bool showSupplyZones = true; // Draw Supply Zones ... -input bool showDemandZones = true; // Draw Demand Zones ... -input bool showSupportZones = true; // Draw Support Zones ... -input bool showResistanceZones = true; // Draw Resistance Zones ... +input int upTrendArrowCode = 236; // Up Trend Arrow Code +input int downTrendArrowCode = 238; // Down Trend Arrow Code +input int swingLowArrowCode = 108; // Swing Low Arrow Code +input int swingHighArrowCode = 108; // Swing High Arrow Code +input int bullishPinArrowCode = 246; // Bullish Pin Arrow Code +input int bearishPinArrowCode = 248; // Bearish Pin Arrow Code +input int bullishEngulfArrowCode = 200; // Bullish Engulf Arrow Code +input int bearishEngulfArrowCode = 202; // Bearish Engulf Arrow Code +input int bullishMomentumArrowCode = 233; // Bullish Momentum Arrow Code +input int bearishMomentumArrowCode = 234; // Bearish Momentum Arrow Code +input int bullishRejectionArrowCode = 241; // Bullish Rejection Arrow Code +input int bearishRejectionArrowCode = 242; // Bearish Rejection Arrow Code // #property indicator_chart_window // -#property indicator_buffers 8 -#property indicator_plots 7 +#property indicator_buffers 17 +#property indicator_plots 15 // // Plot Buffers ... @@ -115,7 +123,7 @@ input bool showResistanceZones = true; // Draw Resistance Zones ... double maBuffer[]; // -#property indicator_label1 "X121 XWZ MA" +#property indicator_label1 "X121-XWZ MA" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLightSkyBlue #property indicator_style1 STYLE_SOLID @@ -126,7 +134,7 @@ double maBuffer[]; double longSLBuffer[]; // -#property indicator_label2 "X121 XWZ Long SL" +#property indicator_label2 "X121-XWZ Long SL" #property indicator_type2 DRAW_LINE #property indicator_color2 clrOrange #property indicator_style2 STYLE_SOLID @@ -137,59 +145,137 @@ double longSLBuffer[]; double shortSLBuffer[]; // -#property indicator_label3 "X121 XWZ Short SL" +#property indicator_label3 "X121-XWZ Short SL" #property indicator_type3 DRAW_LINE #property indicator_color3 clrOrange #property indicator_style3 STYLE_SOLID #property indicator_width3 1 // -#define longRejectBufferIndex 3 -double longRejectBuffer[]; - -// -#property indicator_label4 "X121 XWZ Long Reject" -#property indicator_type4 DRAW_ARROW -#property indicator_color4 clrLime -#property indicator_style4 STYLE_SOLID -#property indicator_width4 1 - -// -#define shortRejectBufferIndex 4 -double shortRejectBuffer[]; - -// -#property indicator_label5 "X121 XWZ Short Reject" -#property indicator_type5 DRAW_ARROW -#property indicator_color5 clrRed -#property indicator_style5 STYLE_SOLID -#property indicator_width5 1 - -// -#define upTrendBufferIndex 5 +#define upTrendBufferIndex 3 double upTrendBuffer[]; // -#property indicator_label6 "X121 XTREND Up" -#property indicator_type6 DRAW_ARROW -#property indicator_color6 clrAqua -#property indicator_width6 1 +#property indicator_label4 "X121-XWZ Trend Up" +#property indicator_type4 DRAW_ARROW +#property indicator_color4 clrAqua +#property indicator_width4 3 // -#define downTrendBufferIndex 6 +#define downTrendBufferIndex 4 double downTrendBuffer[]; // -#property indicator_label7 "X121 XTREND Down" +#property indicator_label5 "X121-XWZ Trend Down" +#property indicator_type5 DRAW_ARROW +#property indicator_color5 clrMagenta +#property indicator_width5 3 + +// +#define bullishMomentumBufferIndex 5 +double bullishMomentumBuffer[]; + +// +#property indicator_label6 "X121-XWZ Bull Momentum" +#property indicator_type6 DRAW_ARROW +#property indicator_color6 clrAqua +#property indicator_width6 3 + +// +#define bearishMomentumBufferIndex 6 +double bearishMomentumBuffer[]; + +// +#property indicator_label7 "X121-XWZ Bear Momentum" #property indicator_type7 DRAW_ARROW #property indicator_color7 clrMagenta -#property indicator_width7 1 +#property indicator_width7 3 + +// +#define bullishRejectionBufferIndex 7 +double bullishRejectionBuffer[]; + +// +#property indicator_label8 "X121-XWZ Bull Rejection" +#property indicator_type8 DRAW_ARROW +#property indicator_color8 clrAqua +#property indicator_width8 3 + +// +#define bearishRejectionBufferIndex 8 +double bearishRejectionBuffer[]; + +// +#property indicator_label9 "X121-XWZ Bear Rejection" +#property indicator_type9 DRAW_ARROW +#property indicator_color9 clrMagenta +#property indicator_width9 3 + +// +#define bullishPinBufferIndex 9 +double bullishPinBuffer[]; + +// +#property indicator_label10 "X121-XWZ Bull Pin" +#property indicator_type10 DRAW_ARROW +#property indicator_color10 clrAqua +#property indicator_width10 3 + +// +#define bearishPinBufferIndex 10 +double bearishPinBuffer[]; + +// +#property indicator_label11 "X121-XWZ Bear Pin" +#property indicator_type11 DRAW_ARROW +#property indicator_color11 clrMagenta +#property indicator_width11 3 + +// +#define bullishEngulfBufferIndex 11 +double bullishEngulfBuffer[]; + +// +#property indicator_label12 "X121-XWZ Bull Engulf" +#property indicator_type12 DRAW_ARROW +#property indicator_color12 clrAqua +#property indicator_width12 3 + +// +#define bearishEngulfBufferIndex 12 +double bearishEngulfBuffer[]; + +// +#property indicator_label13 "X121-XWZ Bear Engulf" +#property indicator_type13 DRAW_ARROW +#property indicator_color13 clrMagenta +#property indicator_width13 3 + +// +#define swingLowBufferIndex 13 +double swingLowBuffer[]; + +// +#property indicator_label14 "X121-XWZ Swing Low" +#property indicator_type14 DRAW_ARROW +#property indicator_color14 clrAqua +#property indicator_width14 3 + +// +#define swingHighBufferIndex 14 +double swingHighBuffer[]; + +// +#property indicator_label15 "X121-XWZ Swing High" +#property indicator_type15 DRAW_ARROW +#property indicator_color15 clrMagenta +#property indicator_width15 3 // // Data Buffers ... // -int mLastBufferIndex = 6; +int mLastBufferIndex = 14; // #define atrBufferIndex mLastBufferIndex + 1 @@ -230,12 +316,30 @@ XCBarAnalyser *mXWZBarAnalyser; datetime lastBullishTrend = NULL; datetime lastBearishTrend = NULL; +// +// POI(s) ... + +// +bool mXWZDetectOrderBlocks = true; +bool mXWZDetectFairValueGaps = true; +bool mXWZDetectSupportZones = true; +bool mXWZDetectResistanceZones = true; + +// +bool filterPOIsUsingZones = false; // Filter POI(s) Using Zones + +// +XCFVG *lastBullFVG; +XCFVG *lastBearFVG; +XCOrderBlock *lastBullOB; +XCOrderBlock *lastBearOB; +XCSupportZone *lastSupport; +XCResistanceZone *lastResistance; + // // Un Activated POI(s) ... XCFVG *mXWZUnActivatedFVGs[]; XCOrderBlock *mXWZUnActivatedOBs[]; -XCSupplyZone *mXWZUnActivatedSupplyZones[]; -XCDemandZone *mXWZUnActivatedDemandZones[]; XCSupportZone *mXWZUnActivatedSupportZones[]; XCResistanceZone *mXWZUnActivatedResistanceZones[]; @@ -243,8 +347,6 @@ XCResistanceZone *mXWZUnActivatedResistanceZones[]; // Activated POI(s) ... XCFVG *mXWZActivatedFVGs[]; XCOrderBlock *mXWZActivatedOBs[]; -XCSupplyZone *mXWZActivatedSupplyZones[]; -XCDemandZone *mXWZActivatedDemandZones[]; XCSupportZone *mXWZActivatedSupportZones[]; XCResistanceZone *mXWZActivatedResistanceZones[]; @@ -331,6 +433,9 @@ int OnInit() // mXWZPOIDrawer = new XCPOIDrawer(); + ConfigurePOIDrawer(); + + // mXWZBarAnalyser = new XCBarAnalyser(); // @@ -370,18 +475,14 @@ void OnDeinit(const int reason) ZeroMemory(mXWZBarAnalyser); // - Clean(mXWZActivatedFVGs); Clean(mXWZActivatedOBs); - Clean(mXWZActivatedSupplyZones); - Clean(mXWZActivatedDemandZones); + Clean(mXWZActivatedFVGs); Clean(mXWZActivatedSupportZones); Clean(mXWZActivatedResistanceZones); // Clean(mXWZUnActivatedOBs); Clean(mXWZUnActivatedFVGs); - Clean(mXWZUnActivatedSupplyZones); - Clean(mXWZUnActivatedDemandZones); Clean(mXWZUnActivatedSupportZones); Clean(mXWZUnActivatedResistanceZones); } @@ -639,54 +740,18 @@ void DefineBuffers() // PlotIndexSetDouble(shortSLBufferIndex, PLOT_EMPTY_VALUE, 0); - // - // LONG Reject ... - - // - ENUM_DRAW_TYPE longRejectDrawType = showLongReject ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(longRejectBuffer, true); - SetIndexBuffer(longRejectBufferIndex, longRejectBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(longRejectBufferIndex, PLOT_SHOW_DATA, showLongReject); - PlotIndexSetInteger(longRejectBufferIndex, PLOT_DRAW_TYPE, longRejectDrawType); - - // - PlotIndexSetDouble(longRejectBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(longRejectBufferIndex, PLOT_ARROW, longRejectArrowCode); - - // - // SHORT Reject ... - - // - ENUM_DRAW_TYPE shortRejectDrawType = showShortReject ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(shortRejectBuffer, true); - SetIndexBuffer(shortRejectBufferIndex, shortRejectBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(shortRejectBufferIndex, PLOT_SHOW_DATA, showShortReject); - PlotIndexSetInteger(shortRejectBufferIndex, PLOT_DRAW_TYPE, shortRejectDrawType); - - // - PlotIndexSetDouble(shortRejectBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(shortRejectBufferIndex, PLOT_ARROW, shortRejectArrowCode); - // // UP Trend ... // - ENUM_DRAW_TYPE upTrendDrawType = showUpTrend ? DRAW_ARROW : DRAW_NONE; + ENUM_DRAW_TYPE upTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; // ArraySetAsSeries(upTrendBuffer, true); SetIndexBuffer(upTrendBufferIndex, upTrendBuffer, INDICATOR_DATA); // - PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showUpTrend); + PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showTrend); PlotIndexSetInteger(upTrendBufferIndex, PLOT_DRAW_TYPE, upTrendDrawType); // @@ -697,20 +762,200 @@ void DefineBuffers() // DOWN Trend ... // - ENUM_DRAW_TYPE downTrendDrawType = showDownTrend ? DRAW_ARROW : DRAW_NONE; + ENUM_DRAW_TYPE downTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; // ArraySetAsSeries(downTrendBuffer, true); SetIndexBuffer(downTrendBufferIndex, downTrendBuffer, INDICATOR_DATA); // - PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showDownTrend); + PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showTrend); PlotIndexSetInteger(downTrendBufferIndex, PLOT_DRAW_TYPE, downTrendDrawType); // PlotIndexSetDouble(downTrendBufferIndex, PLOT_EMPTY_VALUE, 0); PlotIndexSetInteger(downTrendBufferIndex, PLOT_ARROW, downTrendArrowCode); + // + // Bullish Momentum ... + + // + ENUM_DRAW_TYPE bullishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishMomentumBuffer, true); + SetIndexBuffer(bullishMomentumBufferIndex, bullishMomentumBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); + PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_DRAW_TYPE, bullishMomentumDrawType); + + // + PlotIndexSetDouble(bullishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_ARROW, bullishMomentumArrowCode); + + // + // Bearish Momentum ... + + // + ENUM_DRAW_TYPE bearishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishMomentumBuffer, true); + SetIndexBuffer(bearishMomentumBufferIndex, bearishMomentumBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); + PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_DRAW_TYPE, bearishMomentumDrawType); + + // + PlotIndexSetDouble(bearishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_ARROW, bearishMomentumArrowCode); + + // + // Bullish Rejection ... + + // + ENUM_DRAW_TYPE bullishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishRejectionBuffer, true); + SetIndexBuffer(bullishRejectionBufferIndex, bullishRejectionBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); + PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_DRAW_TYPE, bullishRejectionDrawType); + + // + PlotIndexSetDouble(bullishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_ARROW, bullishRejectionArrowCode); + + // + // Bearish Rejection ... + + // + ENUM_DRAW_TYPE bearishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishRejectionBuffer, true); + SetIndexBuffer(bearishRejectionBufferIndex, bearishRejectionBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); + PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_DRAW_TYPE, bearishRejectionDrawType); + + // + PlotIndexSetDouble(bearishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_ARROW, bearishRejectionArrowCode); + + // + // Bullish Pin ... + + // + ENUM_DRAW_TYPE bullishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishPinBuffer, true); + SetIndexBuffer(bullishPinBufferIndex, bullishPinBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishPinBufferIndex, PLOT_SHOW_DATA, showPin); + PlotIndexSetInteger(bullishPinBufferIndex, PLOT_DRAW_TYPE, bullishPinDrawType); + + // + PlotIndexSetDouble(bullishPinBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishPinBufferIndex, PLOT_ARROW, bullishPinArrowCode); + + // + // Bearish Pin ... + + // + ENUM_DRAW_TYPE bearishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishPinBuffer, true); + SetIndexBuffer(bearishPinBufferIndex, bearishPinBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishPinBufferIndex, PLOT_SHOW_DATA, showPin); + PlotIndexSetInteger(bearishPinBufferIndex, PLOT_DRAW_TYPE, bearishPinDrawType); + + // + PlotIndexSetDouble(bearishPinBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishPinBufferIndex, PLOT_ARROW, bearishPinArrowCode); + + // + // Bullish Engulf ... + + // + ENUM_DRAW_TYPE bullishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishEngulfBuffer, true); + SetIndexBuffer(bullishEngulfBufferIndex, bullishEngulfBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); + PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_DRAW_TYPE, bullishEngulfDrawType); + + // + PlotIndexSetDouble(bullishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_ARROW, bullishEngulfArrowCode); + + // + // Bearish Engulf ... + + // + ENUM_DRAW_TYPE bearishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishEngulfBuffer, true); + SetIndexBuffer(bearishEngulfBufferIndex, bearishEngulfBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); + PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_DRAW_TYPE, bearishEngulfDrawType); + + // + PlotIndexSetDouble(bearishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_ARROW, bearishEngulfArrowCode); + + // + // Swing Low ... + + // + ENUM_DRAW_TYPE swingLowDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(swingLowBuffer, true); + SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(swingLowBufferIndex, PLOT_SHOW_DATA, showSwing); + PlotIndexSetInteger(swingLowBufferIndex, PLOT_DRAW_TYPE, swingLowDrawType); + + // + PlotIndexSetDouble(swingLowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(swingLowBufferIndex, PLOT_ARROW, swingLowArrowCode); + + // + // Swing High ... + + // + ENUM_DRAW_TYPE swingHighDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(swingHighBuffer, true); + SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(swingHighBufferIndex, PLOT_SHOW_DATA, showSwing); + PlotIndexSetInteger(swingHighBufferIndex, PLOT_DRAW_TYPE, swingHighDrawType); + + // + PlotIndexSetDouble(swingHighBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(swingHighBufferIndex, PLOT_ARROW, swingHighArrowCode); + // // DATA Buffers ... @@ -803,9 +1048,17 @@ void FillBuffersZero(int barIndex) longSLBuffer[barIndex] = 0; shortSLBuffer[barIndex] = 0; upTrendBuffer[barIndex] = 0; + swingLowBuffer[barIndex] = 0; + swingHighBuffer[barIndex] = 0; downTrendBuffer[barIndex] = 0; - longRejectBuffer[barIndex] = 0; - shortRejectBuffer[barIndex] = 0; + bullishPinBuffer[barIndex] = 0; + bearishPinBuffer[barIndex] = 0; + bullishEngulfBuffer[barIndex] = 0; + bearishEngulfBuffer[barIndex] = 0; + bullishMomentumBuffer[barIndex] = 0; + bearishMomentumBuffer[barIndex] = 0; + bullishRejectionBuffer[barIndex] = 0; + bearishRejectionBuffer[barIndex] = 0; } /** @@ -831,6 +1084,9 @@ void CalculateValues( const long &tickVolume[] // ) { + // + // Prepare Requirements ... + // XOHCL iBar; bool isInited = iBar.Init( @@ -857,6 +1113,7 @@ void CalculateValues( } // + // Calculate Applied Price ... double iPrice = GetAppliedPrice( appliedTo, open, @@ -877,20 +1134,47 @@ void CalculateValues( double points10 = 10 * points; // - // Calculate SL Values ... + ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + + // + bool hasLastBullOB = lastBullOB != NULL && + lastBullOB.IsValid(); + bool hasLastBearOB = lastBearOB != NULL && + lastBearOB.IsValid(); + + // + bool hasLastBullFVG = lastBullFVG != NULL && + lastBullFVG.IsValid(); + bool hasLastBearFVG = lastBearFVG != NULL && + lastBearFVG.IsValid(); + + // + bool hasLastSupport = lastSupport != NULL && + lastSupport.IsValid(); + + // + bool hasLastResistance = lastResistance != NULL && + lastResistance.IsValid(); + + // + // SL Buffers ... // double iLongSL = iPrice - iAppliedAtr; double iShortSL = iPrice + iAppliedAtr; // - // Calculate Trend Values ... + longSLBuffer[bar_index] = iLongSL; + shortSLBuffer[bar_index] = iShortSL; + + // + // Trend Buffers ... // bool isUpTrend = // iPrice > iMa && - iBar.open < iMa && + iBar.low < iMa && iAdx > adxThreshold // ; @@ -899,7 +1183,7 @@ void CalculateValues( bool isDownTrend = // iPrice < iMa && - iBar.open > iMa && + iBar.high > iMa && iAdx > adxThreshold // ; @@ -911,322 +1195,358 @@ void CalculateValues( { // lastBullishTrend = iBar.time; - upTrendValue = iBar.low - points10; + upTrendValue = iBar.low; } if (isDownTrend) { // lastBearishTrend = iBar.time; - downTrendValue = iBar.high + points10; + downTrendValue = iBar.high; } - // - // Calculate Rejection Values ... - - // - double fiboUpDown = GetFibonacciLevel( - iBar.high, - iBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - iBar.high, - iBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= iBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= iBar.GetUp(); - - // - bool isLongReject = - // - iBar.low < iMa && - iBar.high >= iMa && - iBar.GetDown() >= iMa - // - ; - bool isStrongLongReject = - iBar.IsBullish() && - isLongReject; - bool isPressuredLongReject = - isLongReject && - hasFiboToUpPressure; - bool isPressuredStrongLongReject = - isStrongLongReject && - isPressuredLongReject; - - // - bool isShortReject = - // - iBar.high > iMa && - iBar.low <= iMa && - iBar.GetUp() <= iMa - // - ; - bool isStrongShortReject = - iBar.IsBearish() && - isShortReject; - bool isPressuredShortReject = - isShortReject && - hasFiboToDownPressure; - bool isPressuredStrongShortReject = - isStrongShortReject && - isPressuredShortReject; - - // - double iLongRejectValue = 0; - double iShortRejectValue = 0; - - // - bool isAppliedLongReject = false; - bool isAppliedShortReject = false; - switch (rejectionType) - { - // - case XWZ_REJECTION_BAR: - isAppliedLongReject = isLongReject; - isAppliedShortReject = isShortReject; - break; - - // - case XWZ_REJECTION_STRONG_BAR: - isAppliedLongReject = isStrongLongReject; - isAppliedShortReject = isStrongShortReject; - break; - - // - case XWZ_REJECTION_PRESSURED_BAR: - isAppliedLongReject = isPressuredLongReject; - isAppliedShortReject = isPressuredShortReject; - break; - - // - case XWZ_REJECTION_STRONG_PRESSURED_BAR: - isAppliedLongReject = isPressuredStrongLongReject; - isAppliedShortReject = isPressuredStrongShortReject; - break; - } - - // - // Calculate Rejection Verification Values ... - - // - int iLLIDX = pBar - .FindLowestIndex( - rejectionVerificationLength, - MODE_LOW // - ); - datetime iLLTime = iTime( - _Symbol, - _Period, - iLLIDX // - ); - double iLL = iLow( - _Symbol, - _Period, - iLLIDX // - ); - - // - int iHHIDX = pBar - .FindHighestIndex( - rejectionVerificationLength, - MODE_HIGH // - ); - datetime iHHTime = iTime( - _Symbol, - _Period, - iHHIDX // - ); - double iHH = iHigh( - _Symbol, - _Period, - iHHIDX // - ); - - // - bool isLLBreaked = false; - bool isHHBreaked = false; - if (rejectionVerificationLength > 0) - { - // - for (int i = bar_index + 1; i < bar_index + rejectionVerificationLength; i++) - { - // - double iMaValue = maBuffer[i]; - - // - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - i // - ); - if (!isInited) - { - // - iBar.Clean(); - isLLBreaked = true; - isHHBreaked = true; - break; - } - - // - if (!isLLBreaked) - { - isLLBreaked = iBar.low < iMaValue; - } - - // - if (!isHHBreaked) - { - isHHBreaked = iBar.high > iMaValue; - } - - // - if (isLLBreaked && - isHHBreaked) - { - break; - } - } - } - - // - // Validate Rejections ... - - // - // -[] Before Reject Long, price - // must not touch Ma from Up for at least 3 Bar ... - bool isValidAppliedLongReject = - !isLLBreaked && - isAppliedLongReject; - - // - // -[] Before Reject Short Price - // must no touch Ma from down at least 3 Bar ... - bool isValidAppliedShortReject = - !isHHBreaked && - isAppliedShortReject; - - // - if (isValidAppliedLongReject) - { - iLongRejectValue = iBar.low - points10; - } - else - { - iLongRejectValue = 0; - } - - // - if (isValidAppliedShortReject) - { - iShortRejectValue = iBar.high + points10; - } - else - { - iShortRejectValue = 0; - } - - // - // Draw Verification Box ... - if (isValidAppliedLongReject || - isValidAppliedShortReject) - { - // - datetime time1 = iTime( - _Symbol, - _Period, - iBar.Index() + rejectionVerificationLength // - ); - datetime time2 = iTime( - _Symbol, - _Period, - iBar.Index() + 0 // - ); - string llName = ToString(iLLIDX) + "_" + - ToString(iLL) + "_" + - ToMD5(iLLTime); - CChartObjectTrend *llTrend; - llTrend = new CChartObjectTrend(); - bool isCreated = llTrend.Create( - 0, - llName, - 0, - time1, - iLL, - time2, - iLL // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(llTrend); - } - - // - string hhName = ToString(iHHIDX) + "_" + - ToString(iHH) + "_" + - ToMD5(iHHTime); - CChartObjectTrend *hhTrend; - hhTrend = new CChartObjectTrend(); - isCreated = hhTrend.Create( - 0, - hhName, - 0, - time1, - iHH, - time2, - iHH // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(hhTrend); - } - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - ENUM_X_DIRECTION trend = - IsValid(lastBullishTrend) && - lastBullishTrend > lastBearishTrend - ? X_DIRECTION_BULLISH - : IsValid(lastBearishTrend) && - lastBearishTrend > lastBullishTrend - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - bool hasTrend = HasDirection(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - - // - // Filling Buffers ... - - // - longSLBuffer[bar_index] = iLongSL; - shortSLBuffer[bar_index] = iShortSL; - // upTrendBuffer[bar_index] = upTrendValue; downTrendBuffer[bar_index] = downTrendValue; // - longRejectBuffer[bar_index] = iLongRejectValue; - shortRejectBuffer[bar_index] = iShortRejectValue; + // Momentum Buffers ... + + // + bool isMomentum = mXWZBarAnalyser + .IsMomentumBar( + iBar, + iDir, + 1, // Extends ... + 70 // Body Percent ... + ); + bool isBullishMomentum = + isMomentum && + IsBullish(iDir); + bool isBearishMomentum = + isMomentum && + IsBearish(iDir); + if (isMomentum) + { + // + double iBullMomentumValue = 0; + double iBearMomentumValue = 0; + + // + if (isBullishMomentum) + { + // + double selectedValue = iBar.low; + + // + iBullMomentumValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + } + + // + if (isBearishMomentum) + { + // + double selectedValue = iBar.high; + + // + iBearMomentumValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + } + + // + bullishMomentumBuffer[bar_index] = iBullMomentumValue; + bearishMomentumBuffer[bar_index] = iBearMomentumValue; + } + + // + // Rejection Buffers ... + + // + bool isRejection = mXWZBarAnalyser + .IsRejectionBar( + iBar, + iDir, + 1, // Extends ... + 70 // Body Percent ... + ); + bool isBullishRejection = + isRejection && + IsBullish(iDir); + bool isBearishRejection = + isRejection && + IsBearish(iDir); + if (isRejection) + { + // + double iBullRejectionValue = 0; + double iBearRejectionValue = 0; + + // + if (isBullishRejection) + { + // + double selectedValue = iBar.low; + + // + iBullRejectionValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + } + + // + if (isBearishRejection) + { + // + double selectedValue = iBar.high; + + // + iBearRejectionValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + } + + // + bullishRejectionBuffer[bar_index] = iBullRejectionValue; + bearishRejectionBuffer[bar_index] = iBearRejectionValue; + } + + // + // Pin Buffers ... + + // + bool isPin = mXWZBarAnalyser + .IsPinBar( + iBar, + iDir, + 0, // Extends ... + 50, // Shadow Percent ... + 25 // Body Percent ... + ); + bool isBullishPin = + isPin && + IsBullish(iDir); + bool isBearishPin = + isPin && + IsBearish(iDir); + if (isPin) + { + // + double iBullPinValue = 0; + double iBearPinValue = 0; + + // + if (isBullishPin) + { + // + double selectedValue = iBar.low; + + // + iBullPinValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + } + + // + if (isBearishPin) + { + // + double selectedValue = iBar.high; + + // + iBearPinValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + } + + // + bullishPinBuffer[bar_index] = iBullPinValue; + bearishPinBuffer[bar_index] = iBearPinValue; + } + + // + // Engulf Buffers ... + + // + bool isEngulf = mXWZBarAnalyser + .IsEngulfBar( + iBar, + iDir, + 1, // Extends ... + 70 // Body Percent ... + ); + bool isBullishEngulf = + isEngulf && + IsBullish(iDir); + bool isBearishEngulf = + isEngulf && + IsBearish(iDir); + if (isEngulf) + { + // + double iBullEngulfValue = 0; + double iBearEngulfValue = 0; + + // + if (isBullishEngulf) + { + // + double selectedValue = iBar.low; + + // + iBullEngulfValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + } + + // + if (isBearishEngulf) + { + // + double selectedValue = iBar.high; + + // + iBearEngulfValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + } + + // + bullishEngulfBuffer[bar_index] = iBullEngulfValue; + bearishEngulfBuffer[bar_index] = iBearEngulfValue; + } + + // + // Swing Buffers ... + + // + bool isSwing = mXWZBarAnalyser + .IsSwing( + iBar, + iDir, + 2 // Range ... + ); + bool isSwingLow = + isSwing && + IsBullish(iDir); + bool isSwingHigh = + isSwing && + IsBearish(iDir); + if (isSwing) + { + // + double iSwingLowValue = 0; + double iSwingHighValue = 0; + + // + if (isSwingLow) + { + // + double selectedValue = iBar.low; + + // + iSwingLowValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsBelow( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + } + + // + if (isSwingHigh) + { + // + double selectedValue = iBar.high; + + // + iSwingHighValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsAbove( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + } + + // + swingLowBuffer[bar_index] = iSwingLowValue; + swingHighBuffer[bar_index] = iSwingHighValue; + } // // Cleanup Resources ... @@ -1238,6 +1558,53 @@ void CalculateValues( // // POIS Functions ... + +// +void ConfigurePOIDrawer() +{ + // + if (mXWZPOIDrawer == NULL) + { + return; + } + + // + mXWZPOIDrawer.Prefix(ShortName); + mXWZPOIDrawer.ChartIdentification(ChartID()); + mXWZPOIDrawer.SubWindowIdentification(0); + + // + mXWZPOIDrawer.BullishFVGWidth(1); + mXWZPOIDrawer.BullishFVGStyle(STYLE_DOT); + mXWZPOIDrawer.BullishFVGColor(clrAqua); + + // + mXWZPOIDrawer.BearishFVGWidth(1); + mXWZPOIDrawer.BearishFVGStyle(STYLE_DOT); + mXWZPOIDrawer.BearishFVGColor(clrMagenta); + + // + mXWZPOIDrawer.SupportZoneWidth(1); + mXWZPOIDrawer.SupportZoneStyle(STYLE_DASHDOTDOT); + mXWZPOIDrawer.SupportZoneColor(clrLime); + + // + mXWZPOIDrawer.ResistanceZoneWidth(1); + mXWZPOIDrawer.ResistanceZoneStyle(STYLE_DASHDOTDOT); + mXWZPOIDrawer.ResistanceZoneColor(clrRed); + + // + mXWZPOIDrawer.BullishOrderBlockWidth(4); + mXWZPOIDrawer.BullishOrderBlockStyle(STYLE_DASH); + mXWZPOIDrawer.BullishOrderBlockColor(clrAqua); + + // + mXWZPOIDrawer.BearishOrderBlockWidth(4); + mXWZPOIDrawer.BearishOrderBlockStyle(STYLE_DASH); + mXWZPOIDrawer.BearishOrderBlockColor(clrMagenta); +} + +// void CalculatedPOIs( int bar_index, // Selected Bar Index const int prevCalculated, @@ -1285,11 +1652,37 @@ void CalculatedPOIs( pBar.Clean(); } +// +bool CanDetectPOIs() +{ + // + bool result = false; + + // + result = + // + mXWZDetectOrderBlocks || + mXWZDetectFairValueGaps || + mXWZDetectSupportZones || + mXWZDetectResistanceZones + // + ; + + // + return result; +} + // void DetectPOIs( XOHCL &bar // ) { + // + if (!CanDetectPOIs()) + { + return; + } + // int idx = -1; int range = 21; @@ -1298,271 +1691,390 @@ void DetectPOIs( // Detect Order Block ... // - XOHCL obBar; - XCOrderBlock *ob; - ENUM_X_DIRECTION obDir; - bool hasOB = mXWZBarAnalyser.HasOrderBlock( - bar, - obBar, - obDir // - ); - bool hasBullishOB = - hasOB && - IsBullish(obDir); - bool hasBearishOB = - hasOB && - IsBearish(obDir); - if (hasOB) + if (mXWZDetectOrderBlocks) { // - ob = new XCOrderBlock(); - bool isInited = ob.Init(obBar, obDir); - if (isInited) + XOHCL obBar; + XCOrderBlock *ob; + ENUM_X_DIRECTION obDir; + bool hasOB = mXWZBarAnalyser.HasOrderBlock( + bar, + obBar, + obDir // + ); + bool hasBullishOB = + hasOB && + IsBullish(obDir); + bool hasBearishOB = + hasOB && + IsBearish(obDir); + if (hasOB) { // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = ob.IsActivated( - forDir, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) + ob = new XCOrderBlock(); + bool isInited = ob.Init(obBar, obDir); + if (isInited) { // - idx = FindIndex( - ob, - mXWZUnActivatedOBs // + ENUM_X_DIRECTION iForDir = ob.GetDirection(); + bool isBullish = IsBullish(iForDir); + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = ob.IsActivated( + iForDir, + activationBar, + isActivationBarBodyIn, + false, + _Period // ); - if (!IsValidIndex(idx)) + + // + if (!isActivated) { // - Add( + idx = FindIndex( ob, mXWZUnActivatedOBs // ); + if (!IsValidIndex(idx)) + { + // + if (isBullish) + { + lastBullOB = ob; + } + else + { + lastBearOB = ob; + } + + // + Add( + ob, + mXWZUnActivatedOBs // + ); + } } - } - else - { - // - idx = FindIndex( - ob, - mXWZActivatedOBs // - ); - if (!IsValidIndex(idx)) + else { // - ob.To(activationBar.time); - - // - Add( + idx = FindIndex( ob, mXWZActivatedOBs // ); + if (!IsValidIndex(idx)) + { + // + ob.To(activationBar.time); + + // + Add( + ob, + mXWZActivatedOBs // + ); + } } + + // + activationBar.Clean(); } - - // - activationBar.Clean(); } - } - // - obBar.Clean(); + // + obBar.Clean(); + } // // Detect Fair Value Gap ... // - XOHCL fvgStartBar; - XOHCL fvgEndBar; - XCFVG *fvg; - ENUM_X_DIRECTION fvgDir; - bool hasFVG = mXWZBarAnalyser.HasFairValueGap( - bar, - fvgStartBar, - fvgEndBar, - fvgDir // - ); - bool hasBullishFVG = - hasFVG && - IsBullish(fvgDir); - bool hasBearishFVG = - hasFVG && - IsBearish(fvgDir); - if (hasFVG) + if (mXWZDetectFairValueGaps) { // - fvg = new XCFVG(); - bool isInited = fvg.Init( + XOHCL fvgStartBar; + XOHCL fvgEndBar; + XCFVG *fvg; + ENUM_X_DIRECTION fvgDir; + bool hasFVG = mXWZBarAnalyser.HasFairValueGap( + bar, fvgStartBar, fvgEndBar, fvgDir // ); - if (isInited) + bool hasBullishFVG = + hasFVG && + IsBullish(fvgDir); + bool hasBearishFVG = + hasFVG && + IsBearish(fvgDir); + if (hasFVG) { // - ENUM_X_DIRECTION forDir = fvg.GetDirection(); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = fvg.IsActivated( - forDir, - activationBar, - isActivationBarBodyIn, - false, - _Period // + fvg = new XCFVG(); + bool isInited = fvg.Init( + fvgStartBar, + fvgEndBar, + fvgDir // ); - - // - if (!isActivated) + if (isInited) { // - idx = FindIndex( - fvg, - mXWZUnActivatedFVGs // + ENUM_X_DIRECTION iForDir = fvg.GetDirection(); + bool isBullish = IsBullish(iForDir); + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = fvg.IsActivated( + iForDir, + activationBar, + isActivationBarBodyIn, + false, + _Period // ); - if (!IsValidIndex(idx)) + + // + if (!isActivated) { // - Add( + idx = FindIndex( fvg, mXWZUnActivatedFVGs // ); + if (!IsValidIndex(idx)) + { + // + if (isBullish) + { + lastBullFVG = fvg; + } + else + { + lastBearFVG = fvg; + } + + // + Add( + fvg, + mXWZUnActivatedFVGs // + ); + } } - } - else - { - // - idx = FindIndex( - fvg, - mXWZActivatedFVGs // - ); - if (!IsValidIndex(idx)) + else { // - fvg.To(activationBar.time); - - // - Add( + idx = FindIndex( fvg, mXWZActivatedFVGs // ); + if (!IsValidIndex(idx)) + { + // + fvg.To(activationBar.time); + + // + Add( + fvg, + mXWZActivatedFVGs // + ); + } } + + // + activationBar.Clean(); } - - // - activationBar.Clean(); } + + // + fvgEndBar.Clean(); + fvgStartBar.Clean(); } - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - - // - // Detect Supply Zone ... - - // - // Detect Deman Zone ... - // // Detect Support Zone ... // - XOHCL supportBar; - XCSupportZone *supportZone; - bool hasSupport = mXWZBarAnalyser - .HasSupport( - bar, - supportBar, - range // - ); - if (hasSupport) + if (mXWZDetectSupportZones) { // - supportZone = new XCSupportZone(); - hasSupport = supportZone.Init( - supportBar, - range, - true // Use Range As Start ... - ); - - // + XOHCL supportBar; + XCSupportZone *supportZone; + bool hasSupport = mXWZBarAnalyser + .HasSupport( + bar, + supportBar, + range // + ); if (hasSupport) { // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supportZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // + supportZone = new XCSupportZone(); + hasSupport = supportZone.Init( + supportBar, + range, + true // Use Range As Start ... ); // - if (!isActivated) + if (hasSupport) { // - idx = FindIndex( - supportZone, - mXWZUnActivatedSupportZones // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = supportZone.IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // ); - hasSupport = !IsValidIndex(idx); - if (hasSupport) + + // + if (!isActivated) { // - Add( + idx = FindIndex( supportZone, mXWZUnActivatedSupportZones // ); + hasSupport = !IsValidIndex(idx); + if (hasSupport) + { + // + lastSupport = supportZone; + + // + Add( + supportZone, + mXWZUnActivatedSupportZones // + ); + } } - } - else - { - // - idx = FindIndex( - supportZone, - mXWZActivatedSupportZones // - ); - hasSupport = !IsValidIndex(idx); - if (hasSupport) + else { // - supportZone.To(activationBar.time); - - // - Add( + idx = FindIndex( supportZone, mXWZActivatedSupportZones // ); - } - } + hasSupport = !IsValidIndex(idx); + if (hasSupport) + { + // + supportZone.To(activationBar.time); - // - activationBar.Clean(); + // + Add( + supportZone, + mXWZActivatedSupportZones // + ); + } + } + + // + activationBar.Clean(); + } } + + // + supportBar.Clean(); } // - supportBar.Clean(); + // Detect Resistance Zone ... // - // Detect Resistance Zone ... + if (mXWZDetectResistanceZones) + { + // + XOHCL resistaneBar; + XCResistanceZone *resistanceZone; + bool hasResistance = mXWZBarAnalyser + .HasResistance( + bar, + resistaneBar, + range // + ); + if (hasResistance) + { + // + resistanceZone = new XCResistanceZone(); + hasResistance = resistanceZone.Init( + resistaneBar, + range, + true // Use Range As Start ... + ); + + // + if (hasResistance) + { + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = resistanceZone.IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + idx = FindIndex( + resistanceZone, + mXWZUnActivatedResistanceZones // + ); + hasResistance = !IsValidIndex(idx); + if (hasResistance) + { + // + lastResistance = resistanceZone; + + // + Add( + resistanceZone, + mXWZUnActivatedResistanceZones // + ); + } + } + else + { + // + idx = FindIndex( + resistanceZone, + mXWZActivatedResistanceZones // + ); + hasResistance = !IsValidIndex(idx); + if (hasResistance) + { + // + resistanceZone.To(activationBar.time); + + // + Add( + resistanceZone, + mXWZActivatedResistanceZones // + ); + } + } + + // + activationBar.Clean(); + } + } + + // + resistaneBar.Clean(); + } // } @@ -1575,6 +2087,7 @@ void UpdatePOIs( // int count = -1; bool has = false; + bool resetDraws = false; // if (!bar.IsValid()) @@ -1587,6 +2100,8 @@ void UpdatePOIs( // // Order Blocks ... + + // count = ArraySize(mXWZUnActivatedOBs); has = IsValidSize(count); if (has) @@ -1644,8 +2159,79 @@ void UpdatePOIs( ); } + // + count = ArraySize(mXWZActivatedOBs); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iZone = mXWZActivatedOBs[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + ENUM_X_DIRECTION iForDir = iZone.GetDirection(); + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedOBs, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + // // Fair Value Gaps ... + + // count = ArraySize(mXWZUnActivatedFVGs); has = IsValidSize(count); if (has) @@ -1703,8 +2289,79 @@ void UpdatePOIs( ); } + // + count = ArraySize(mXWZActivatedFVGs); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + for (int i = 0; i < count; i++) + { + // + XCFVG *iZone = mXWZActivatedFVGs[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + ENUM_X_DIRECTION iForDir = iZone.GetDirection(); + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedFVGs, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + // // Support Zones ... + + // count = ArraySize(mXWZUnActivatedSupportZones); has = IsValidSize(count); if (has) @@ -1765,6 +2422,242 @@ void UpdatePOIs( ); } + // + count = ArraySize(mXWZActivatedSupportZones); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + ENUM_X_DIRECTION iForDir = X_DIRECTION_BULLISH; + for (int i = 0; i < count; i++) + { + // + XCSupportZone *iZone = mXWZActivatedSupportZones[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedSupportZones, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + + // + // Resistance Zones ... + + // + count = ArraySize(mXWZUnActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + XCResistanceZone *tmps[]; + for (int i = 0; i < count; i++) + { + // + // Update To ... + mXWZUnActivatedResistanceZones[i].To(to); + + // + // Check Activation ... + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = mXWZUnActivatedResistanceZones[i] + .IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + Add( + mXWZUnActivatedResistanceZones[i], + tmps // + ); + } + else + { + // + mXWZUnActivatedResistanceZones[i].To(activationBar.time); + + // + Add( + mXWZUnActivatedResistanceZones[i], + mXWZActivatedResistanceZones // + ); + } + + // + activationBar.Clean(); + } + + // + Copy( + tmps, + mXWZUnActivatedResistanceZones // + ); + } + + // + count = ArraySize(mXWZActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + ENUM_X_DIRECTION iForDir = X_DIRECTION_BEARISH; + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *iZone = mXWZActivatedResistanceZones[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + + // + // Check Breake ... + bool isBreaked = iZone.IsBreaked( + iForDir, + passedBar, + isBodyOut, + true, + false, + _Period // + ); + if (isBreaked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedResistanceZones, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + + // + // + // + + // + // Clean Draws if has to ... + if (resetDraws) + { + mXWZDrawnObjects.Clear(); + } + // } @@ -1784,11 +2677,12 @@ void DrawPOIs() // // Order Blocks ... - bool showOrderBlocks = - showBullishOrderBlocks || - showBearishOrderBlocks; if (showOrderBlocks) { + // + bool showBullishOrderBlocks = true; + bool showBearishOrderBlocks = true; + // // UnActivated ... count = ArraySize(mXWZUnActivatedOBs); @@ -1873,11 +2767,12 @@ void DrawPOIs() // // Fair Value Gaps ... - bool showOrderFairValueGaps = - showBullishFairValueGaps || - showBearishFairValueGaps; - if (showOrderFairValueGaps) + if (showFairValueGaps) { + // + bool showBullishFairValueGaps = true; + bool showBearishFairValueGaps = true; + // // UnActivated ... count = ArraySize(mXWZUnActivatedFVGs); @@ -2014,6 +2909,61 @@ void DrawPOIs() } } + // + // Resistance Zones ... + if (showResistanceZones) + { + // + // UnActivated ... + count = ArraySize(mXWZUnActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = mXWZPOIDrawer + .CreateResistanceZone( + mXWZUnActivatedResistanceZones[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + + // + // Activated ... + if (showActivatedPOIs) + { + // + count = ArraySize(mXWZActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = mXWZPOIDrawer + .CreateResistanceZone( + mXWZActivatedResistanceZones[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + } + } + // } diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 89b3e285..c9d0680f 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -3726,7 +3726,8 @@ class XCResistanceZone : public XCBarZone */ bool Init( XOHCL &bar, - int range = 0 // + int range = 0, + bool useRangeAsStart = false // ) { // @@ -3761,7 +3762,10 @@ class XCResistanceZone : public XCBarZone int periodSeconds = PeriodSeconds(bar.period); // - datetime from = (datetime)((int)time - (range * periodSeconds)); + datetime from = + !useRangeAsStart + ? (datetime)((int)time - (range * periodSeconds)) + : time; datetime to = (datetime)((int)time + (range * periodSeconds)); //