From fe7df78f5d953e14f146d44f3479dee58c79787e Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 13 Mar 2025 05:47:12 +0330 Subject: [PATCH] fix xpv and add support for providing fractals based Supports and Resistances ... --- Documents/BKP/support_and_resistance.mq5 | 121 ++++++ Helpers/x-saherelm.x121.helper.mq5 | 37 +- Helpers/x-saherelm.x121.xpv.helper.mq5 | 385 +++++++++++++++++- Indicators/x-saherelm.x121.xpv.mq5 | 211 +++++++++- Libraries/x-saherelm.x-poi.lib.mq5 | 39 +- .../Signals/x-121.smc.xwz.signal.lib.mq5 | 39 +- .../Strategy/x-121.smc.strategy.class.mq5 | 2 + 7 files changed, 799 insertions(+), 35 deletions(-) create mode 100644 Documents/BKP/support_and_resistance.mq5 diff --git a/Documents/BKP/support_and_resistance.mq5 b/Documents/BKP/support_and_resistance.mq5 new file mode 100644 index 00000000..fe5b2730 --- /dev/null +++ b/Documents/BKP/support_and_resistance.mq5 @@ -0,0 +1,121 @@ +//+------------------------------------------------------------------+ +//| Support and Resistance.mq5 | +//| https://t.me/ForexEaPremium | +//+------------------------------------------------------------------+ +#property copyright "https://t.me/ForexEaPremium" +#property version "2.02" + +#property description "Blue and red support and resistance levels displayed directly on the chart." +#property description "Alerts for close above resistance and close below support." + +#property indicator_chart_window +#property indicator_buffers 2 +#property indicator_plots 2 +#property indicator_color1 clrRed +#property indicator_type1 DRAW_ARROW +#property indicator_width1 2 +#property indicator_label1 "Resistance" +#property indicator_color2 clrBlue +#property indicator_type2 DRAW_ARROW +#property indicator_width2 2 +#property indicator_label2 "Support" + +enum enum_candle_to_check +{ + Current, + Previous +}; + +input bool EnableNativeAlerts = false; +input bool EnableEmailAlerts = false; +input bool EnablePushAlerts = false; +input enum_candle_to_check TriggerCandle = Previous; + +double Resistance[]; +double Support[]; + +int myFractal; + +datetime LastAlertTime = D'01.01.1970'; + +void OnInit() +{ + PlotIndexSetInteger(0, PLOT_ARROW, 119); + PlotIndexSetInteger(1, PLOT_ARROW, 119); + + SetIndexBuffer(0, Resistance); + SetIndexBuffer(1, Support); + + ArraySetAsSeries(Resistance, true); + ArraySetAsSeries(Support, true); + + PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 5); + PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, 5); + + myFractal = iFractals(NULL, 0); +} + +int OnCalculate(const int rates_total, + const int prev_calculated, + const datetime &Time[], + const double &open[], + const double &High[], + const double &Low[], + const double &Close[], + const long &tick_volume[], + const long &volume[], + const int &spread[]) +{ + ArraySetAsSeries(High, true); + ArraySetAsSeries(Low, true); + ArraySetAsSeries(Close, true); + ArraySetAsSeries(Time, true); + + //Get the values of the Fractals indicator before entering the cycle. + double FractalUpperBuffer[]; + double FractalLowerBuffer[]; + + CopyBuffer(myFractal, 0, 0, rates_total, FractalUpperBuffer); + CopyBuffer(myFractal, 1, 0, rates_total, FractalLowerBuffer); + + ArraySetAsSeries(FractalUpperBuffer, true); + ArraySetAsSeries(FractalLowerBuffer, true); + + for (int i = rates_total - 2; i >= 0; i--) + { + if (FractalUpperBuffer[i] != EMPTY_VALUE) Resistance[i] = High[i]; + else Resistance[i] = Resistance[i + 1]; + + if (FractalLowerBuffer[i] != EMPTY_VALUE) Support[i] = Low[i]; + else Support[i] = Support[i + 1]; + } + + // Alerts + if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0)) + { + string Text, TextNative; + // Resistance. + if ((Close[TriggerCandle] > Resistance[TriggerCandle]) && (Close[TriggerCandle + 1] <= Resistance[TriggerCandle])) + { + Text = "S&R: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - Closed above Resistance: " + DoubleToString(Resistance[TriggerCandle], _Digits) + "."; + TextNative = "S&R: Closed above Resistance: " + DoubleToString(Resistance[TriggerCandle], _Digits) + "."; + if (EnableNativeAlerts) Alert(TextNative); + if (EnableEmailAlerts) SendMail("S&R Alert", Text); + if (EnablePushAlerts) SendNotification(Text); + LastAlertTime = Time[0]; + } + // Support. + if ((Close[TriggerCandle] < Support[TriggerCandle]) && (Close[TriggerCandle + 1] >= Support[TriggerCandle])) + { + Text = "S&R: " + Symbol() + " - " + StringSubstr(EnumToString((ENUM_TIMEFRAMES)Period()), 7) + " - Closed below Support: " + DoubleToString(Support[TriggerCandle], _Digits) + "."; + TextNative = "S&R: Closed below Support: " + DoubleToString(Support[TriggerCandle], _Digits) + "."; + if (EnableNativeAlerts) Alert(TextNative); + if (EnableEmailAlerts) SendMail("S&R Alert", Text); + if (EnablePushAlerts) SendNotification(Text); + LastAlertTime = Time[0]; + } + } + + return rates_total; +} +//+------------------------------------------------------------------+ \ No newline at end of file diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index d6077469..ec2b5cae 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -229,6 +229,7 @@ struct X121Conditions double xhkSMLowBuffer[]; double x3maFastBuffer[]; double x3maSlowBuffer[]; + double supportsBuffer[]; double downTrendBuffer[]; double vwapPriceBuffer[]; double xhkRawLowBuffer[]; @@ -245,12 +246,15 @@ struct X121Conditions double atrLowerRawBuffer[]; double donLowUpperBuffer[]; double donLowLowerBuffer[]; + double resistancesBuffer[]; double vwapMidStateBuffer[]; double donOpenUpperBuffer[]; double donOpenLowerBuffer[]; double donHighUpperBuffer[]; double donHighLowerBuffer[]; double x3maMidStateBuffer[]; + double fractalsUpperBuffer[]; + double fractalsLowerBuffer[]; double vwapFastStateBuffer[]; double vwapSlowStateBuffer[]; double donCloseUpperBuffer[]; @@ -665,6 +669,7 @@ struct X121Conditions Clean(xhkSMLowBuffer); Clean(x3maFastBuffer); Clean(x3maSlowBuffer); + Clean(supportsBuffer); Clean(downTrendBuffer); Clean(vwapPriceBuffer); Clean(xhkRawLowBuffer); @@ -681,19 +686,21 @@ struct X121Conditions Clean(atrLowerRawBuffer); Clean(donLowUpperBuffer); Clean(donLowLowerBuffer); + Clean(resistancesBuffer); Clean(vwapMidStateBuffer); Clean(donOpenUpperBuffer); Clean(donOpenLowerBuffer); Clean(donHighUpperBuffer); Clean(donHighLowerBuffer); Clean(x3maMidStateBuffer); + Clean(fractalsUpperBuffer); + Clean(fractalsLowerBuffer); Clean(vwapFastStateBuffer); Clean(vwapSlowStateBuffer); Clean(donCloseUpperBuffer); Clean(donCloseLowerBuffer); Clean(x3maFastStateBuffer); Clean(x3maSlowStateBuffer); - // ArraySetAsSeries(maBuffer, true); ArraySetAsSeries(rsiBuffer, true); @@ -743,6 +750,7 @@ struct X121Conditions ArraySetAsSeries(xhkSMLowBuffer, true); ArraySetAsSeries(x3maFastBuffer, true); ArraySetAsSeries(x3maSlowBuffer, true); + ArraySetAsSeries(supportsBuffer, true); ArraySetAsSeries(downTrendBuffer, true); ArraySetAsSeries(vwapPriceBuffer, true); ArraySetAsSeries(xhkRawLowBuffer, true); @@ -759,12 +767,15 @@ struct X121Conditions ArraySetAsSeries(atrLowerRawBuffer, true); ArraySetAsSeries(donLowUpperBuffer, true); ArraySetAsSeries(donLowLowerBuffer, true); + ArraySetAsSeries(resistancesBuffer, true); ArraySetAsSeries(vwapMidStateBuffer, true); ArraySetAsSeries(donOpenUpperBuffer, true); ArraySetAsSeries(donOpenLowerBuffer, true); ArraySetAsSeries(donHighUpperBuffer, true); ArraySetAsSeries(donHighLowerBuffer, true); ArraySetAsSeries(x3maMidStateBuffer, true); + ArraySetAsSeries(fractalsUpperBuffer, true); + ArraySetAsSeries(fractalsLowerBuffer, true); ArraySetAsSeries(vwapFastStateBuffer, true); ArraySetAsSeries(vwapSlowStateBuffer, true); ArraySetAsSeries(donCloseUpperBuffer, true); @@ -3185,6 +3196,18 @@ class XCX121Helper : public XCBase conditions.valesBuffer // ); + // + Copy( + xpvConditions.supportsBuffer, + conditions.supportsBuffer // + ); + + // + Copy( + xpvConditions.resistancesBuffer, + conditions.resistancesBuffer // + ); + // Copy( xpvConditions.peaksGoldenBuffer, @@ -3263,6 +3286,18 @@ class XCX121Helper : public XCBase conditions.hLLBuffer // ); + // + Copy( + xpvConditions.fractalsUpperBuffer, + conditions.fractalsUpperBuffer // + ); + + // + Copy( + xpvConditions.fractalsLowerBuffer, + conditions.fractalsLowerBuffer // + ); + // // Conditions ... diff --git a/Helpers/x-saherelm.x121.xpv.helper.mq5 b/Helpers/x-saherelm.x121.xpv.helper.mq5 index 993a1848..5d2f2fe9 100644 --- a/Helpers/x-saherelm.x121.xpv.helper.mq5 +++ b/Helpers/x-saherelm.x121.xpv.helper.mq5 @@ -37,16 +37,20 @@ enum ENUM_X121_XPV_BUFFERS X121_XPV_SAR_LINE = 2, X121_XPV_PEAK_GOLDEN_ZONE_LINE = 3, X121_XPV_VALE_GOLDEN_ZONE_LINE = 4, - X121_XPV_C_HH_LINE = 5, - X121_XPV_C_LL_LINE = 6, - X121_XPV_S_HH_LINE = 7, - X121_XPV_S_LL_LINE = 8, - X121_XPV_M_HH_LINE = 9, - X121_XPV_M_LL_LINE = 10, - X121_XPV_L_HH_LINE = 11, - X121_XPV_L_LL_LINE = 12, - X121_XPV_H_HH_LINE = 13, - X121_XPV_H_LL_LINE = 14, + X121_XPV_SUPPORT_LINE = 5, + X121_XPV_RESISTANCE_LINE = 6, + X121_XPV_C_HH_LINE = 7, + X121_XPV_C_LL_LINE = 8, + X121_XPV_S_HH_LINE = 9, + X121_XPV_S_LL_LINE = 10, + X121_XPV_M_HH_LINE = 11, + X121_XPV_M_LL_LINE = 12, + X121_XPV_L_HH_LINE = 13, + X121_XPV_L_LL_LINE = 14, + X121_XPV_H_HH_LINE = 15, + X121_XPV_H_LL_LINE = 16, + X121_XPV_FRACTALS_UPPER_LINE = 17, + X121_XPV_FRACTALS_LOWER_LINE = 18, }; // @@ -91,15 +95,19 @@ struct X121XPVInputs int startCalculationForLastBars; // Calculate Last n Bars // - int sarArrowCode; // Parabolic Sar Arrow Code - int peaksArrowCode; // Peaks Arrow Code - int valesArrowCode; // Vales Arrow Code + int sarArrowCode; // Parabolic Sar Arrow Code + int peaksArrowCode; // Peaks Arrow Code + int valesArrowCode; // Vales Arrow Code + int supportsArrowCode; // Supports Arrow Code + int resistancesArrowCode; // Resistances Arrow Code // - bool showSar; // Show Parabolic Sar - bool showPeaks; // Show Peaks - bool showVales; // Show Vales + bool showSar; // Show Parabolic Sar + bool showPeaks; // Show Peaks + bool showVales; // Show Vales bool showGoldenZones; // Show Golden Zones + bool showSupports; // Show Supports + bool showResistances; // Show Resistances // // Constructor(s) ... @@ -153,12 +161,16 @@ struct X121XPVInputs sarArrowCode = 0; peaksArrowCode = 0; valesArrowCode = 0; + supportsArrowCode = 0; + resistancesArrowCode = 0; // showSar = false; showPeaks = false; showVales = false; - showGoldenZones = true; + showGoldenZones = false; + showSupports = false; + showResistances = false; // ZeroMemory(this); @@ -205,12 +217,16 @@ struct X121XPVInputs sarArrowCode = 159; peaksArrowCode = 159; valesArrowCode = 159; + supportsArrowCode = 159; + resistancesArrowCode = 159; // showSar = true; showPeaks = true; showVales = true; showGoldenZones = true; + showSupports = true; + showResistances = true; } // @@ -271,6 +287,8 @@ struct X121XPVConditions double valesBuffer[]; double peaksGoldenBuffer[]; double valesGoldenBuffer[]; + double supportsBuffer[]; + double resistancesBuffer[]; double sarBuffer[]; double cHHBuffer[]; double cLLBuffer[]; @@ -282,6 +300,8 @@ struct X121XPVConditions double lLLBuffer[]; double hHHBuffer[]; double hLLBuffer[]; + double fractalsUpperBuffer[]; + double fractalsLowerBuffer[]; // // Conditions ... @@ -343,6 +363,8 @@ struct X121XPVConditions Clean(valesBuffer); Clean(peaksGoldenBuffer); Clean(valesGoldenBuffer); + Clean(supportsBuffer); + Clean(resistancesBuffer); Clean(sarBuffer); Clean(cHHBuffer); Clean(cLLBuffer); @@ -354,6 +376,8 @@ struct X121XPVConditions Clean(lLLBuffer); Clean(hHHBuffer); Clean(hLLBuffer); + Clean(fractalsUpperBuffer); + Clean(fractalsLowerBuffer); // // Clean(bullishTrendBuffer); @@ -364,6 +388,8 @@ struct X121XPVConditions ArraySetAsSeries(valesBuffer, true); ArraySetAsSeries(peaksGoldenBuffer, true); ArraySetAsSeries(valesGoldenBuffer, true); + ArraySetAsSeries(supportsBuffer, true); + ArraySetAsSeries(resistancesBuffer, true); ArraySetAsSeries(sarBuffer, true); ArraySetAsSeries(cHHBuffer, true); ArraySetAsSeries(cLLBuffer, true); @@ -375,6 +401,8 @@ struct X121XPVConditions ArraySetAsSeries(lLLBuffer, true); ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(fractalsUpperBuffer, true); + ArraySetAsSeries(fractalsLowerBuffer, true); // // Conditions ... @@ -393,6 +421,7 @@ struct X121XPVConditions isNewPeakUnderLast = false; isRejectedPrevPeak = false; isBreakedUpPrevPeak = false; + // isNewVale = false; isNewValeOverLast = false; @@ -557,6 +586,8 @@ class XCX121XPVHelper : public XCBaseHelper Clean(valesBuffer); Clean(peaksGoldenBuffer); Clean(valesGoldenBuffer); + Clean(supportsBuffer); + Clean(resistancesBuffer); Clean(sarBuffer); Clean(cHHBuffer); Clean(cLLBuffer); @@ -568,6 +599,8 @@ class XCX121XPVHelper : public XCBaseHelper Clean(lLLBuffer); Clean(hHHBuffer); Clean(hLLBuffer); + Clean(fractalsUpperBuffer); + Clean(fractalsLowerBuffer); } // @@ -597,6 +630,8 @@ class XCX121XPVHelper : public XCBaseHelper ArraySetAsSeries(valesBuffer, true); ArraySetAsSeries(peaksGoldenBuffer, true); ArraySetAsSeries(valesGoldenBuffer, true); + ArraySetAsSeries(supportsBuffer, true); + ArraySetAsSeries(resistancesBuffer, true); ArraySetAsSeries(sarBuffer, true); ArraySetAsSeries(cHHBuffer, true); ArraySetAsSeries(cLLBuffer, true); @@ -608,6 +643,8 @@ class XCX121XPVHelper : public XCBaseHelper ArraySetAsSeries(lLLBuffer, true); ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(fractalsUpperBuffer, true); + ArraySetAsSeries(fractalsLowerBuffer, true); // mInputs = inputs; @@ -661,11 +698,15 @@ class XCX121XPVHelper : public XCBaseHelper mInputs.sarArrowCode, mInputs.peaksArrowCode, mInputs.valesArrowCode, + mInputs.supportsArrowCode, + mInputs.resistancesArrowCode, // mInputs.showSar, mInputs.showPeaks, mInputs.showVales, - mInputs.showGoldenZones + mInputs.showGoldenZones, + mInputs.showSupports, + mInputs.showResistances // ); result = mHandler != INVALID_HANDLE; @@ -863,6 +904,110 @@ class XCX121XPVHelper : public XCBaseHelper ); } + // + // SUPPORTS ... + + // + double GetSupport( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(supportsBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return supportsBuffer[barIndex]; + } + + // + int CopySupport( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + supportsBuffer, + buffer, + forceClean + // + ); + } + + // + // RESISTANCES ... + + // + double GetResistance( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(resistancesBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return resistancesBuffer[barIndex]; + } + + // + int CopyResistance( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + resistancesBuffer, + buffer, + forceClean + // + ); + } + // // GOLDEN PEAKS ... @@ -1734,6 +1879,110 @@ class XCX121XPVHelper : public XCBaseHelper ); } + // + // FRACTALS Upper ... + + // + double GetFractalsUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fractalsUpperBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fractalsUpperBuffer[barIndex]; + } + + // + int CopyFractalsUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fractalsUpperBuffer, + buffer, + forceClean + // + ); + } + + // + // FRACTALS Lower ... + + // + double GetFractalsLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fractalsLowerBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fractalsLowerBuffer[barIndex]; + } + + // + int CopyFractalsLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fractalsLowerBuffer, + buffer, + forceClean + // + ); + } + // // Tools Function ... @@ -2053,6 +2302,20 @@ class XCX121XPVHelper : public XCBaseHelper conditions.valesBuffer // ); + // + CopySupport( + zIndex, + loopback, + conditions.supportsBuffer // + ); + + // + CopyResistance( + zIndex, + loopback, + conditions.resistancesBuffer // + ); + // CopyPeakGoldenZone( zIndex, @@ -2137,6 +2400,20 @@ class XCX121XPVHelper : public XCBaseHelper conditions.hLLBuffer // ); + // + CopyFractalsUpper( + zIndex, + loopback, + conditions.fractalsUpperBuffer // + ); + + // + CopyFractalsLower( + zIndex, + loopback, + conditions.fractalsLowerBuffer // + ); + // // Conditions ... @@ -2240,6 +2517,8 @@ class XCX121XPVHelper : public XCBaseHelper // Buffers ... double peaksBuffer[]; double valesBuffer[]; + double supportsBuffer[]; + double resistancesBuffer[]; double peaksGoldenBuffer[]; double valesGoldenBuffer[]; double sarBuffer[]; @@ -2253,6 +2532,8 @@ class XCX121XPVHelper : public XCBaseHelper double lLLBuffer[]; double hHHBuffer[]; double hLLBuffer[]; + double fractalsUpperBuffer[]; + double fractalsLowerBuffer[]; // void Calculate( @@ -2298,6 +2579,28 @@ class XCX121XPVHelper : public XCBaseHelper // ); + // + // SUPPORTS ... + CopyBuffer( + mHandler, + X121_XPV_SUPPORT_LINE, + 0, + maxRequiredBars, + supportsBuffer + // + ); + + // + // RESISTANCES ... + CopyBuffer( + mHandler, + X121_XPV_RESISTANCE_LINE, + 0, + maxRequiredBars, + resistancesBuffer + // + ); + // // GOLDEN PEAKS ... CopyBuffer( @@ -2444,6 +2747,28 @@ class XCX121XPVHelper : public XCBaseHelper hLLBuffer // ); + + // + // FRACTALS Upper ... + CopyBuffer( + mHandler, + X121_XPV_FRACTALS_UPPER_LINE, + 0, + maxRequiredBars, + fractalsUpperBuffer + // + ); + + // + // FRACTALS Lower ... + CopyBuffer( + mHandler, + X121_XPV_FRACTALS_LOWER_LINE, + 0, + maxRequiredBars, + fractalsLowerBuffer + // + ); } // @@ -2475,6 +2800,18 @@ class XCX121XPVHelper : public XCBaseHelper maxAllowed // ); + // + CleanupArray( + supportsBuffer, + maxAllowed // + ); + + // + CleanupArray( + resistancesBuffer, + maxAllowed // + ); + // CleanupArray( sarBuffer, @@ -2541,6 +2878,18 @@ class XCX121XPVHelper : public XCBaseHelper maxAllowed // ); + // + CleanupArray( + fractalsUpperBuffer, + maxAllowed // + ); + + // + CleanupArray( + fractalsLowerBuffer, + maxAllowed // + ); + // } diff --git a/Indicators/x-saherelm.x121.xpv.mq5 b/Indicators/x-saherelm.x121.xpv.mq5 index 0af0a37e..463a093e 100644 --- a/Indicators/x-saherelm.x121.xpv.mq5 +++ b/Indicators/x-saherelm.x121.xpv.mq5 @@ -60,7 +60,7 @@ input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period input group "Boundary Detection"; input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method -input ENUM_X_FIBO_LEVELS goldenZoneLevel = X_FIBO_LEVEL_382; // Golden Zone Detection +input ENUM_X_FIBO_LEVELS goldenZoneLevel = X_FIBO_LEVEL_236; // Golden Zone Detection // input group "Sar Detection"; @@ -76,12 +76,16 @@ input int startCalculationForLastBars = 1000; // Calculate Last n Bars input int sarArrowCode = 159; // Parabolic Sar Arrow Code input int peaksArrowCode = 159; // Peaks Arrow Code input int valesArrowCode = 159; // Vales Arrow Code +input int supportsArrowCode = 159; // Supports Arrow Code +input int resistancesArrowCode = 159; // Resistances Arrow Code // -input bool showSar = true; // Show Parabolic Sar -input bool showPeaks = true; // Show Peaks -input bool showVales = true; // Show Vales +input bool showSar = true; // Show Parabolic Sar +input bool showPeaks = true; // Show Peaks +input bool showVales = true; // Show Vales input bool showGoldenZones = true; // Show Golden Zones +input bool showSupports = true; // Show Supports +input bool showResistances = true; // Show Resistances // // Buffers ... @@ -96,8 +100,8 @@ input bool showGoldenZones = true; // Show Golden Zones #property indicator_chart_window // -#property indicator_buffers 15 -#property indicator_plots 5 +#property indicator_buffers 19 +#property indicator_plots 7 // // Plot Buffers ... @@ -112,7 +116,7 @@ double peaksBuffer[]; // #property indicator_label1 "X121 PEAKS" #property indicator_type1 DRAW_ARROW -#property indicator_color1 clrAqua +#property indicator_color1 clrMagenta #property indicator_width1 1 // @@ -125,7 +129,7 @@ double valesBuffer[]; // #property indicator_label2 "X121 VALES" #property indicator_type2 DRAW_ARROW -#property indicator_color2 clrMagenta +#property indicator_color2 clrAqua #property indicator_width2 1 // @@ -160,11 +164,31 @@ double valesGoldenZoneBuffer[]; #property indicator_style5 STYLE_DOT #property indicator_width5 1 +// +#define supportsBufferIndex 5 +double supportsBuffer[]; + +// +#property indicator_label6 "X121 SUPRT" +#property indicator_type6 DRAW_ARROW +#property indicator_color6 clrLime +#property indicator_width6 1 + +// +#define resistancesBufferIndex 6 +double resistancesBuffer[]; + +// +#property indicator_label7 "X121 RESIS" +#property indicator_type7 DRAW_ARROW +#property indicator_color7 clrRed +#property indicator_width7 1 + // // Data Buffers ... // -int mLastBufferIndex = 4; +int mLastBufferIndex = 6; // // CURRENT ... @@ -221,6 +245,17 @@ double hHHBuffer[]; #define hLLBufferIndex mLastBufferIndex + 10 double hLLBuffer[]; +// +// Support and Resistances ... + +// +#define fractalsUpperBufferIndex mLastBufferIndex + 11 +double fractalsUpperBuffer[]; + +// +#define fractalsLowerBufferIndex mLastBufferIndex + 12 +double fractalsLowerBuffer[]; + // // Variables, Properties and etc ... @@ -235,6 +270,10 @@ int maxLength; // SAR Handler ... int sarHandler = INVALID_HANDLE; +// +// FRACTALS Handler ... +int fractalHandler = INVALID_HANDLE; + // // XMarketCycle sc; int mSCLength = 0; @@ -289,6 +328,18 @@ int OnInit() return INIT_FAILED; } + // + // Fractal ... + fractalHandler = iFractals( + _Symbol, + _Period // + ); + isInited = fractalHandler != INVALID_HANDLE; + if (!isInited) + { + return INIT_FAILED; + } + // if (!InitMarketCycles()) { @@ -336,6 +387,7 @@ void OnDeinit(const int reason) // IndicatorRelease(sarHandler); + IndicatorRelease(fractalHandler); } /** @@ -385,11 +437,18 @@ int OnCalculate( // SAR ... int sarCalculatedBars = BarsCalculated(sarHandler); + // + // FRACTALS ... + int fractalsCalculatedBars = BarsCalculated(fractalHandler); + // bool isPassedRequiredCalculatedBars = // // SAR ... - sarCalculatedBars >= maxLength + sarCalculatedBars >= maxLength && + // + // FRACTALS ... + fractalsCalculatedBars >= maxLength // ; if (!isPassedRequiredCalculatedBars) @@ -409,12 +468,21 @@ int OnCalculate( // SAR ... int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); + // + // FRACTALS ... + int copiedFractalsUppers = CopyBuffer(fractalHandler, UPPER_LINE, 0, limit + 1, fractalsUpperBuffer); + int copiedFractalsLowers = CopyBuffer(fractalHandler, LOWER_LINE, 0, limit + 1, fractalsLowerBuffer); + // // Validate Copied Items ... bool isPassedRequiredCopiedItems = // // SAR ... - copiedSars > 0 + copiedSars > 0 && + // + // FRACTALS ... + copiedFractalsUppers > 0 && + copiedFractalsLowers > 0 // ; if (!isPassedRequiredCopiedItems) @@ -514,7 +582,7 @@ void DefineBuffers() PlotIndexSetInteger(peaksBufferIndex, PLOT_DRAW_TYPE, peaksDrawType); // - PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetDouble(peaksBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(peaksBufferIndex, PLOT_ARROW, peaksArrowCode); // @@ -532,7 +600,7 @@ void DefineBuffers() PlotIndexSetInteger(valesBufferIndex, PLOT_DRAW_TYPE, valesDrawType); // - PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetDouble(valesBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(valesBufferIndex, PLOT_ARROW, valesArrowCode); // @@ -550,9 +618,45 @@ void DefineBuffers() PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType); // - PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode); + // + // Support ... + + // + ENUM_DRAW_TYPE supportsDrawType = showSupports ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(supportsBuffer, true); + SetIndexBuffer(supportsBufferIndex, supportsBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(supportsBufferIndex, PLOT_SHOW_DATA, showSupports); + PlotIndexSetInteger(supportsBufferIndex, PLOT_DRAW_TYPE, supportsDrawType); + + // + PlotIndexSetDouble(supportsBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(supportsBufferIndex, PLOT_ARROW, supportsArrowCode); + + // + // Resistances... + + // + ENUM_DRAW_TYPE resistancesDrawType = showResistances ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(resistancesBuffer, true); + SetIndexBuffer(resistancesBufferIndex, resistancesBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(resistancesBufferIndex, PLOT_SHOW_DATA, showResistances); + PlotIndexSetInteger(resistancesBufferIndex, PLOT_DRAW_TYPE, resistancesDrawType); + + // + PlotIndexSetDouble(resistancesBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(resistancesBufferIndex, PLOT_ARROW, resistancesArrowCode); + // // Golden Zones ... @@ -638,6 +742,17 @@ void DefineBuffers() // ArraySetAsSeries(hLLBuffer, true); SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_CALCULATIONS); + + // + // FRACTALS ... + + // + ArraySetAsSeries(fractalsUpperBuffer, true); + SetIndexBuffer(fractalsUpperBufferIndex, fractalsUpperBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(fractalsLowerBuffer, true); + SetIndexBuffer(fractalsLowerBufferIndex, fractalsLowerBuffer, INDICATOR_CALCULATIONS); } /** @@ -689,6 +804,19 @@ void CalculateBuffers( // // Calculate Peaks and Vales ... CalculatePeaksAndVales(bar_index); + + // + // Calculate Support nad Resistance ... + CalculateSupportAndResistance( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); } else { @@ -853,6 +981,16 @@ void FillBuffersZero(int barIndex) // // SARS ... sarBuffer[barIndex] = EMPTY_VALUE; + + // + // Support and Resistances ... + supportsBuffer[barIndex] = EMPTY_VALUE; + resistancesBuffer[barIndex] = EMPTY_VALUE; + + // + // Fractals ... + fractalsUpperBuffer[barIndex] = EMPTY_VALUE; + fractalsLowerBuffer[barIndex] = EMPTY_VALUE; } /** @@ -1069,6 +1207,51 @@ void CalculatePeaksAndVales(int barIndex) X_DIRECTION_BEARISH // ); valesGoldenZoneBuffer[barIndex] = iValeGoldenZone; + + // } +/** + * Calculate Support nad Resistances ... + * + * @param bar_index: int, Specified Bar Index ... + * @param prevCalculated: int, Provides Previous Calculated Bars ... + * @param ratesTotal: int, Provides All Availabled Bars ... + * @param open: double Collection, Provides Open Prices Time Series ... + * @param high: double Collection, Provides High Prices Time Series ... + * @param close: double Collection, Provides Close Prices Time Series ... + * @param low: double Collection, Provides Low Prices Time Series ... + * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... + */ +void CalculateSupportAndResistance( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + double iUpperFractalsPrev = fractalsUpperBuffer[bar_index + 1]; + double iLowerFractalsPrev = fractalsLowerBuffer[bar_index + 1]; + + // + double iHigh = high[bar_index]; + double iLow = low[bar_index]; + + // + double iSupport = iLowerFractalsPrev != EMPTY_VALUE + ? iLow + : supportsBuffer[bar_index + 1]; + double iResistance = iUpperFractalsPrev != EMPTY_VALUE + ? iHigh + : resistancesBuffer[bar_index + 1]; + + // + supportsBuffer[bar_index] = iSupport; + resistancesBuffer[bar_index] = iResistance; +} // \ No newline at end of file diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index def6c2c3..f27dcfa0 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -2041,7 +2041,7 @@ class XCTwoBarZone : public XCZone mType = type; mEndBar = endBar; mStartBar = startBar; - + // int startIndex = startBar.Index(); int endIndex = endBar.Index(); @@ -5338,6 +5338,43 @@ struct XBoxZone return result; } + /** + * Retrieve Box Age ... + * + * @param forPeriod: ENUM_TIMEFRAMES member ... + * + * @return ( int ) + */ + int GetAge( + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + int result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = iBarShift( + symbol, + forPeriod, + from // + ); + + // + return result; + } + /** * Retrieve Unique Identifier ... * diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index cd9b7cf2..f02fbae0 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -765,6 +765,42 @@ struct X121SMCStrategyXWZWorkingZone return result; } + bool DetectTreand( + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + // Overal ... + ENUM_X_DIRECTION overal; + bool hasOveral = DetectOveralDirection(overal); + + // + // Waiting Boxes ... + ENUM_X_DIRECTION boxDir = X_DIRECTION_NONE; + XBoxZone tmpBoxes[]; + Copy( + waitingBoxes, + tmpBoxes // + ); + int count = ArraySize(tmpBoxes); + bool has = IsValidSize(count); + if (has) + { + // + } + + // + + // + return result; + } + /** * Update all Collections Members To Time ... * @@ -1021,7 +1057,8 @@ struct X121SMCStrategyXWZWorkingZone { // ENUM_X_DIRECTION overalTrend; - bool hasTrend = DetectOveralTrend(overalTrend); + bool hasTrend = DetectOveralDirection(overalTrend); + if (hasTrend) { // diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 8c7aa8bd..780f2934 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -795,6 +795,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy x121Inputs.xpvInputs.showSar = showAll || true; x121Inputs.xpvInputs.showPeaks = showAll || true; x121Inputs.xpvInputs.showVales = showAll || true; + x121Inputs.xpvInputs.showSupports = showAll || true; + x121Inputs.xpvInputs.showResistances = showAll || true; x121Inputs.xpvInputs.showGoldenZones = showAll || true; //