From b77771b2fc6caf355177b02e0fa00c5063775203 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 2 Oct 2025 20:23:31 +0330 Subject: [PATCH] last works ... --- Classes/x-saherelm.x-helper.class.mq5 | 26 + Documents/BKP/test.fima.ind.mq5 | 2523 +++++++++++++++++ Experts/x-saherelm.xfima.backtester.ea.mq5 | 10 +- Helpers/x-saherelm.xfima.helper.mq5 | 764 ++++- Indicators/x-saherelm.xfima.mq5 | 70 +- Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 22 + .../x-saherelm.xfima.signaller.class.mq5 | 73 +- .../x-saherelm.xfima.x-poi.detector.class.mq5 | 136 + 8 files changed, 3537 insertions(+), 87 deletions(-) create mode 100644 Documents/BKP/test.fima.ind.mq5 diff --git a/Classes/x-saherelm.x-helper.class.mq5 b/Classes/x-saherelm.x-helper.class.mq5 index e5a35e1b..021966ae 100644 --- a/Classes/x-saherelm.x-helper.class.mq5 +++ b/Classes/x-saherelm.x-helper.class.mq5 @@ -635,6 +635,32 @@ class XCBaseHelper : public XCBase return result; } + /** + * Normalizing Bar Index ... + * + * @param barIndex: int, Provided Bar Index ... + * + * @return ( int ) + */ + int NormalizeBarIndex(int barIndex) + { + // + int result = barIndex; + + // + if (!IsValid()) + { + return result; + } + + // + int count = CountBars() - 1; + result = NormalizeInt(result, 0, count - 1); + + // + return result; + } + // // Private ... private: diff --git a/Documents/BKP/test.fima.ind.mq5 b/Documents/BKP/test.fima.ind.mq5 new file mode 100644 index 00000000..0f1cd20a --- /dev/null +++ b/Documents/BKP/test.fima.ind.mq5 @@ -0,0 +1,2523 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XFIMA +// Description: Integrates All Requirements inside +// this indicator for analyse Markets Based on OM1 ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XFIMA Indicator" +#property icon "../Images/SaherElm_Logo_Color.ico" +#property strict + +// +// Definitions ... + +// +// Definitions ... +enum ENUM_X_ZG_SEARCH_MODE +{ + X_ZG_SEARCH_EXTREMUM = 0, // searching for the first extremum + X_ZG_SEARCH_PEAK = 1, // searching for the next ZigZag peak + X_ZG_SEARCH_VALE = -1 // searching for the next ZigZag vale +}; + +// +#define ShortName "XFIMA" + +// +// Imports ... +#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Calculation"; + +// +// Short ... +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Short Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Short Period + +// +// Medium ... +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Medium Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Medium Period + +// +// Long ... +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Long Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Long Period + +// +// Hind ... +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Hind Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Hind Period + +// +// PV ... +input ENUM_SERIESMODE upperMode = MODE_HIGH; // Peak Method +input ENUM_SERIESMODE lowerMode = MODE_LOW; // Vale Method + +// +// Others ... +input ENUM_X_FIBO_LEVELS fiboUpperZoneLevel = X_FIBO_LEVEL_382; // Upper Zone Level +input ENUM_X_FIBO_LEVELS fiboMiddleZoneLevel = X_FIBO_LEVEL_500; // Upper Zone Level +input ENUM_X_FIBO_LEVELS fiboLowerZoneLevel = X_FIBO_LEVEL_618; // Lower Zone Level +input double sarStep = 0.02; // SAR Step +input double sarMax = 0.2; // SAR Maximum +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method +input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To +input int maFastLength = 7; // Fast MA Length +input int maSlowLength = 21; // Slow MA Length +input int maBandLength = 21; // MA Bond Length +input int zigzagDepth = 12; // ZigZag Depth +input int zigzagDeviation = 5; // ZigZag Deviation +input int zigzagBackStep = 3; // ZigZag Back Step +input ENUM_X_PRICE zigzagUppersMode = X_PRICE_HIGH; // ZigZag High Detect Mode +input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low Detect Mode +input bool hkIgnoreShadows = true; // HK Remove noises +input int hkSmoothingLength = 21; // HK Smoothing Length +input ENUM_X_MA_METHOD hkSmoothingMode = X_MA_MODE_EMA; // HK Smoothing Method + +// +// Presentation ... +input group "Presentation"; +input bool showPV = true; // Show PV +input bool showHK = true; // Show HK +input bool showSAR = true; // Show Sar +input bool showHKBond = true; // Show HK Bond +input bool showMAFast = true; // Show MA Fast +input bool showMASlow = true; // Show MA Slow +input bool showMABand = true; // Show MA Bond +input bool showZigZag = true; // Show ZigZag +input bool showFiboZone = true; // Show Fibo Zone + +// +input int startCalculationForLastBars = 1500; // Calculate Last n Bars + +// +input int sarArrowCode = 159; // Parabolic Sar Arrow Code +input int peakArrowCode = 159; // Peaks Arrow Code +input int valeArrowCode = 159; // Vales Arrow Code + +// +// Non Inputs ... + +// +#define hideColorIDX 0 +#define bullishColorIDX 1 +#define bearishColorIDX 2 +#define neuturalColorIDX 3 + +// +#define bullishState 1 +#define neuturalState 0 +#define bearishState -1 + +// +#define emptyValue 0.0 + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 40 +#property indicator_plots 14 + +// +// Plot Buffers ... + +// +// Fast MA ... + +// +#define maFastBufferIndex 0 +#define maFastBufferPlotIndex 0 +double maFastBuffer[]; + +// +#define maFastColorBufferIndex 1 +double maFastColorBuffer[]; + +// +#property indicator_label1 "FastMA" +#property indicator_type1 DRAW_COLOR_LINE +#property indicator_color1 CLR_NONE, clrLime, clrLime, clrLime // clrYellow, clrOrangeRed, clrGray +#property indicator_width1 3 + +// +// Slow MA ... + +// +#define maSlowBufferIndex 2 +#define maSlowBufferPlotIndex 1 +double maSlowBuffer[]; + +// +#define maSlowColorBufferIndex 3 +double maSlowColorBuffer[]; + +// +#property indicator_label2 "SlowMA" +#property indicator_type2 DRAW_COLOR_LINE +#property indicator_color2 CLR_NONE, clrRed, clrRed, clrRed // clrLime, clrRed, clrGray +#property indicator_width2 3 + +// +// SAR ... + +// +#define sarBufferIndex 4 +#define sarBufferPlotIndex 2 +double sarBuffer[]; + +// +#define sarColorBufferIndex 5 +double sarColorBuffer[]; + +// +#property indicator_label3 "SAR" +#property indicator_type3 DRAW_COLOR_ARROW +#property indicator_color3 CLR_NONE, clrLime, clrRed, clrGray +#property indicator_width3 2 + +// +// PEAKS ... + +// +#define peakBufferIndex 6 +#define peakBufferPlotIndex 3 +double peakBuffer[]; + +// +#property indicator_label4 "PEAK" +#property indicator_type4 DRAW_ARROW +#property indicator_color4 clrMagenta +#property indicator_width4 3 + +// +// VALES ... + +// +#define valeBufferIndex 7 +#define valeBufferPlotIndex 4 +double valeBuffer[]; + +// +#property indicator_label5 "VALE" +#property indicator_type5 DRAW_ARROW +#property indicator_color5 clrAqua +#property indicator_width5 3 + +// +// FIBO Upper ... + +// +#define fiboUpperBufferIndex 8 +#define fiboUpperBufferPlotIndex 5 +double fiboUpperBuffer[]; + +// +#property indicator_label6 "FIBUP" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrAqua +#property indicator_width6 2 + +// +// FIBO Middle ... + +// +#define fiboMiddleBufferIndex 9 +#define fiboMiddleBufferPlotIndex 6 +double fiboMiddleBuffer[]; + +// +#property indicator_label7 "FIBMID" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrBrown +#property indicator_width7 2 + +// +// FIBO Lower ... + +// +#define fiboLowerBufferIndex 10 +#define fiboLowerBufferPlotIndex 7 +double fiboLowerBuffer[]; + +// +#property indicator_label8 "FIBLO" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrMagenta +#property indicator_width8 2 + +// +// ZigZag ... + +// +#define zigzagBufferIndex 11 +#define zigzagBufferPlotIndex 8 +double zigzagBuffer[]; + +// +#property indicator_label9 "XZG" +#property indicator_type9 DRAW_SECTION +#property indicator_color9 clrYellow +#property indicator_width9 2 + +// +// MA Upper Boundary ... + +// +#define maUpperBufferIndex 12 +#define maUpperBufferPlotIndex 9 +double maUpperBuffer[]; + +// +#property indicator_label10 "UpperMA" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrAqua +#property indicator_width10 3 + +// +// MA Lower Boundary ... + +// +#define maLowerBufferIndex 13 +#define maLowerBufferPlotIndex 10 +double maLowerBuffer[]; + +// +#property indicator_label11 "LowerMA" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrMagenta +#property indicator_width11 3 + +// +// XHK ... + +// +#define hkOpenBufferIndex 14 +double hkOpenBuffer[]; + +// +#define hkHighBufferIndex 15 +double hkHighBuffer[]; + +// +#define hkLowBufferIndex 16 +double hkLowBuffer[]; + +// +#define hkCloseBufferIndex 17 +double hkCloseBuffer[]; + +// +#define hkColorBufferIndex 18 +double hkColorBuffer[]; + +// +#define hkBufferPlotIndex 11 +#property indicator_label12 "XHK Open;XHK High;XHK Low;XHK Close" +#property indicator_type12 DRAW_COLOR_CANDLES +#property indicator_color12 CLR_NONE, clrAqua, clrMagenta, clrGray + +// +#define hkBondUpperBufferIndex 19 +double hkBondUpperBuffer[]; + +// +#define hkBondUpperBufferPlotIndex 12 +#property indicator_label13 "UpperHK" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrAqua +#property indicator_width13 3 + +// +#define hkBondLowerBufferIndex 20 +double hkBondLowerBuffer[]; + +// +#define hkBondLowerBufferPlotIndex 13 +#property indicator_label14 "LowerHK" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrMagenta +#property indicator_width14 3 + +// +// Data Buffers ... + +// +#define mLastBufferIndex 20 + +// +// MA ... + +// +#define maFastStateBufferIndex mLastBufferIndex + 1 +double maFastStateBuffer[]; + +// +#define maSlowStateBufferIndex mLastBufferIndex + 2 +double maSlowStateBuffer[]; + +// +// SAR ... + +// +#define sarStateBufferIndex mLastBufferIndex + 3 +double sarStateBuffer[]; + +// +// CYCLES ... + +// +// SC ... + +// +#define sHHBufferIndex mLastBufferIndex + 4 +double sHHBuffer[]; + +// +#define sLLBufferIndex mLastBufferIndex + 5 +double sLLBuffer[]; + +// +// MC ... + +// +#define mHHBufferIndex mLastBufferIndex + 6 +double mHHBuffer[]; + +// +#define mLLBufferIndex mLastBufferIndex + 7 +double mLLBuffer[]; + +// +// LC ... + +// +#define lHHBufferIndex mLastBufferIndex + 8 +double lHHBuffer[]; + +// +#define lLLBufferIndex mLastBufferIndex + 9 +double lLLBuffer[]; + +// +// HC ... + +// +#define hHHBufferIndex mLastBufferIndex + 10 +double hHHBuffer[]; + +// +#define hLLBufferIndex mLastBufferIndex + 11 +double hLLBuffer[]; + +// +// ZigZag ... + +// +#define highsBufferIndex mLastBufferIndex + 12 +double highsBuffer[]; + +// +#define highsTimeBufferIndex mLastBufferIndex + 13 +double highsTimeBuffer[]; + +// +#define lowsBufferIndex mLastBufferIndex + 14 +double lowsBuffer[]; + +// +#define lowsTimeBufferIndex mLastBufferIndex + 15 +double lowsTimeBuffer[]; + +// +// XHK Data ... + +// +#define hkRawHighBufferIndex mLastBufferIndex + 16 +double hkRawHighBuffer[]; + +// +#define hkRawOpenBufferIndex mLastBufferIndex + 17 +double hkRawOpenBuffer[]; + +// +#define hkRawLowBufferIndex mLastBufferIndex + 18 +double hkRawLowBuffer[]; + +// +#define hkRawCloseBufferIndex mLastBufferIndex + 19 +double hkRawCloseBuffer[]; + +// +// Variables, Properties and etc ... + +// +// XMarketCycle sc; +int mSCLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// XMarketCycle mc; +int mMCLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// XMarketCycle lc; +int mLCLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// XMarketCycle hc; +int mHCLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +int sarHandler = INVALID_HANDLE; +int maFastHandler = INVALID_HANDLE; +int maSlowHandler = INVALID_HANDLE; +int maUpperHandler = INVALID_HANDLE; +int maLowerHandler = INVALID_HANDLE; + +// +int limit; + +// +int maxLength; + +// +int firstBarIndex; + +// +// Requirements ... +CArrayObj mObjects; +XCPOIDrawer *mDrawer; + +// +double zigzagUppers[]; +double zigzagLowers[]; +int zigzagLowersCount = 0; +int zigzagUppersCount = 0; +int zigzagRecalc = 3; // Number of last extremes for recalculation + +// +double lastZigZagPeak = 0; +datetime lastZigZagPeakTime = NULL; + +// +double lastZigZagVale = 0; +datetime lastZigZagValeTime = NULL; + +// +// Event Handlers ... + +/** + * Initialize Indicator ... + * + * @return ( int ) + */ +int OnInit() +{ + // + bool has = false; + + // + // Validate Inputs ... + has = ValidateInputs(); + if (!has) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + has = InitCycles(); + if (!has) + { + return INIT_FAILED; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Initial Requirements ... + has = InitRequirements(); + if (!has) + { + return INIT_FAILED; + } + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; + + // +} + +/** + * De Initialize Indicator ... + * + * @param reason: Integer, De Initialization Reason ... + */ +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + delete mDrawer; + ZeroMemory(mDrawer); + + // + mObjects.Clear(); + + // + // De Initialize all Handlers and etc ... + IndicatorRelease(sarHandler); + IndicatorRelease(maFastHandler); + IndicatorRelease(maSlowHandler); + IndicatorRelease(maUpperHandler); + IndicatorRelease(maLowerHandler); +} + +/** + * Calculate Bars ... + * + * @param rates_total: Integer, Total Bars on Chart ... + * @param prev_calculated: Integer, Total Calculated Bars on Charts ... + * @param time: DateTime Array, History of Open Time ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param low: Double Array, History of Low Prices ... + * @param close: Double Array, History of Close Prices ... + * @param tick_volume: Long, History of Tick Volumes on Bar ... + * @param volume: Long, History of Trade Volumes ... + * @param spread: Double, History of Spread Price ... + * + * @return ( int ) + */ +int OnCalculate( + const int rates_total, + const int prev_calculated, + const datetime &time[], + const double &open[], + const double &high[], + const double &low[], + const double &close[], + const long &tick_volume[], + const long &volume[], + const int &spread[] // +) +{ + // + // Do ZigZag Calculations Before ArraySet As Series ... + int calculatedZigZags = CalculateZigZag( + 0, + prev_calculated, + rates_total, + open, + high, + close, + low, + tick_volume // + ); + if (calculatedZigZags != rates_total) + { + return prev_calculated; + } + + // + // Prepare Buffers ... + ArraySetAsSeries(time, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(low, true); + ArraySetAsSeries(close, true); + ArraySetAsSeries(tick_volume, true); + ArraySetAsSeries(volume, true); + ArraySetAsSeries(spread, true); + + // + // Validate Calculated Bars ... + + // + // MA ... + int maFastCalculatedBars = BarsCalculated(maFastHandler); + int maSlowCalculatedBars = BarsCalculated(maSlowHandler); + int maUpperCalculatedBars = BarsCalculated(maUpperHandler); + int maLowerCalculatedBars = BarsCalculated(maLowerHandler); + + // + // SAR ... + int sarCalculatedBars = BarsCalculated(sarHandler); + + // + bool isPassedRequiredCalculatedBars = + // + // MA ... + maFastCalculatedBars >= maxLength && + maSlowCalculatedBars >= maxLength && + maUpperCalculatedBars >= maxLength && + maLowerCalculatedBars >= maxLength && + // + // SAR ... + sarCalculatedBars >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + // MA ... + int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer); + int copiedMASlows = CopyBuffer(maSlowHandler, MAIN_LINE, 0, limit, maSlowBuffer); + int copiedMAUppers = CopyBuffer(maUpperHandler, MAIN_LINE, 0, limit, maUpperBuffer); + int copiedMALowers = CopyBuffer(maLowerHandler, MAIN_LINE, 0, limit, maLowerBuffer); + + // + // SAR ... + int copiedSARs = CopyBuffer(sarHandler, MAIN_LINE, 0, limit, sarBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // MA ... + copiedMAFasts >= limit && + copiedMASlows >= limit && + copiedMAUppers >= limit && + copiedMALowers >= limit && + // + // SAR ... + copiedSARs >= limit + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + // + CalculateBuffers( + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume // + ); + } + + // + return rates_total; +} + +// +// Custom Functions ... + +/** + * Set Indicator Short Name and also we can define Buffers Labels ... + */ +void SetIndicatorName() +{ + // + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +/** + * Validate Input Args for Initialization ... + * + * @return ( bool ) + */ +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + // MA ... + maFastLength >= 2 && + maSlowLength >= 2 && + maBandLength >= 2 && + maSlowLength > maFastLength && + // + // SAR ... + sarMax > 0 && + sarStep > 0 && + sarMax > sarStep && + // + // CYCLES ... + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) && + // + // ZIGZAG ... + zigzagDepth > 0 && + zigzagDeviation > 0 && + zigzagBackStep > 0 && + // + // Validate Upper Mode Detection ... + IsXValid(zigzagUppersMode) && + // + // Validate Lower Mode Detection ... + IsXValid(zigzagLowersMode) + // + ; + + // + return result; +} + +/** + * Extract Max Length of Inputs ... + * + * @return ( int ) + */ +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(mSCLength, mMCLength); + result = MathMax(result, mLCLength); + result = MathMax(result, mHCLength); + result = MathMax(result, maFastLength); + result = MathMax(result, maSlowLength); + result = MathMax(result, maBandLength); + + // + return result; +} + +/** + * Define Required Buffers ... + */ +void DefineBuffers() +{ + // + // Fast MA ... + + // + ArraySetAsSeries(maFastBuffer, true); + SetIndexBuffer(maFastBufferIndex, maFastBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(maFastBufferPlotIndex, PLOT_SHOW_DATA, showMAFast); + PlotIndexSetDouble(maFastBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(maFastColorBuffer, true); + SetIndexBuffer(maFastColorBufferIndex, maFastColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(maFastStateBuffer, true); + SetIndexBuffer(maFastStateBufferIndex, maFastStateBuffer, INDICATOR_CALCULATIONS); + + // + // Slow MA ... + + // + ArraySetAsSeries(maSlowBuffer, true); + SetIndexBuffer(maSlowBufferIndex, maSlowBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(maSlowBufferPlotIndex, PLOT_SHOW_DATA, showMASlow); + PlotIndexSetDouble(maSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + ArraySetAsSeries(maSlowColorBuffer, true); + SetIndexBuffer(maSlowColorBufferIndex, maSlowColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(maSlowStateBuffer, true); + SetIndexBuffer(maSlowStateBufferIndex, maSlowStateBuffer, INDICATOR_CALCULATIONS); + + // + // SAR ... + + // + ArraySetAsSeries(sarBuffer, true); + SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(sarBufferPlotIndex, PLOT_SHOW_DATA, showSAR); + PlotIndexSetDouble(sarBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + PlotIndexSetInteger(sarBufferPlotIndex, PLOT_ARROW, sarArrowCode); + + // + ArraySetAsSeries(sarColorBuffer, true); + SetIndexBuffer(sarColorBufferIndex, sarColorBuffer, INDICATOR_COLOR_INDEX); + + // + ArraySetAsSeries(sarStateBuffer, true); + SetIndexBuffer(sarStateBufferIndex, sarStateBuffer, INDICATOR_CALCULATIONS); + + // + // PEAK / VALE ... + + // + ENUM_DRAW_TYPE pvDrawType = showPV ? DRAW_ARROW : DRAW_NONE; + + // + // PEAK ... + + // + ArraySetAsSeries(peakBuffer, true); + SetIndexBuffer(peakBufferIndex, peakBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(peakBufferPlotIndex, PLOT_SHOW_DATA, showPV); + PlotIndexSetInteger(peakBufferPlotIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + PlotIndexSetDouble(peakBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + PlotIndexSetInteger(peakBufferPlotIndex, PLOT_ARROW, peakArrowCode); + + // + // VALE ... + + // + ArraySetAsSeries(valeBuffer, true); + SetIndexBuffer(valeBufferIndex, valeBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(valeBufferPlotIndex, PLOT_SHOW_DATA, showPV); + PlotIndexSetInteger(valeBufferPlotIndex, PLOT_DRAW_TYPE, pvDrawType); + + // + PlotIndexSetDouble(valeBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + PlotIndexSetInteger(valeBufferPlotIndex, PLOT_ARROW, valeArrowCode); + + // + // FIBO Zone ... + + // + ENUM_DRAW_TYPE fiboZoneDrawType = showFiboZone ? DRAW_LINE : DRAW_NONE; + + // + // Upper ... + ArraySetAsSeries(fiboUpperBuffer, true); + SetIndexBuffer(fiboUpperBufferIndex, fiboUpperBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(fiboUpperBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone); + PlotIndexSetInteger(fiboUpperBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType); + PlotIndexSetDouble(fiboUpperBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // Middle ... + ArraySetAsSeries(fiboMiddleBuffer, true); + SetIndexBuffer(fiboMiddleBufferIndex, fiboMiddleBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(fiboMiddleBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone); + PlotIndexSetInteger(fiboMiddleBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType); + PlotIndexSetDouble(fiboMiddleBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // Lower ... + ArraySetAsSeries(fiboLowerBuffer, true); + SetIndexBuffer(fiboLowerBufferIndex, fiboLowerBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(fiboLowerBufferPlotIndex, PLOT_SHOW_DATA, showFiboZone); + PlotIndexSetInteger(fiboLowerBufferPlotIndex, PLOT_DRAW_TYPE, fiboZoneDrawType); + PlotIndexSetDouble(fiboLowerBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + + // + // ZigZag ... + + // + ENUM_DRAW_TYPE zigzagDrawType = showZigZag ? DRAW_SECTION : DRAW_NONE; + + // + SetIndexBuffer(zigzagBufferIndex, zigzagBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(zigzagBufferPlotIndex, PLOT_SHOW_DATA, showZigZag); + PlotIndexSetInteger(zigzagBufferPlotIndex, PLOT_DRAW_TYPE, zigzagDrawType); + + PlotIndexSetInteger(zigzagBufferPlotIndex, PLOT_DRAW_BEGIN, 0); + PlotIndexSetDouble(zigzagBufferPlotIndex, PLOT_EMPTY_VALUE, 0); + + // + // MA Bond ... + + // + ENUM_DRAW_TYPE maBandDrawType = showMABand ? DRAW_LINE : DRAW_NONE; + + // + // MA Upper Bond ... + + // + ArraySetAsSeries(maUpperBuffer, true); + SetIndexBuffer(maUpperBufferIndex, maUpperBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(maUpperBufferPlotIndex, PLOT_SHOW_DATA, showMABand); + PlotIndexSetInteger(maUpperBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType); + + PlotIndexSetInteger(maUpperBufferPlotIndex, PLOT_DRAW_BEGIN, 0); + PlotIndexSetDouble(maUpperBufferPlotIndex, PLOT_EMPTY_VALUE, 0); + + // + // MA Lower Bond ... + + // + ArraySetAsSeries(maLowerBuffer, true); + SetIndexBuffer(maLowerBufferIndex, maLowerBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_SHOW_DATA, showMABand); + PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_TYPE, maBandDrawType); + + PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0); + PlotIndexSetDouble(maLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0); + + // + // XHK ... + + // + // XHK Color ... + ArraySetAsSeries(hkColorBuffer, true); + SetIndexBuffer(hkColorBufferIndex, hkColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on XHK Bar Buffer ... + PlotIndexSetDouble(hkBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue); + PlotIndexSetInteger(hkBufferPlotIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(hkOpenBuffer, true); + SetIndexBuffer(hkOpenBufferIndex, hkOpenBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(hkHighBuffer, true); + SetIndexBuffer(hkHighBufferIndex, hkHighBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(hkLowBuffer, true); + SetIndexBuffer(hkLowBufferIndex, hkLowBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(hkCloseBuffer, true); + SetIndexBuffer(hkCloseBufferIndex, hkCloseBuffer, INDICATOR_DATA); + + // + // XHK Bond ... + + // + // Upper ... + ArraySetAsSeries(hkBondUpperBuffer, true); + SetIndexBuffer(hkBondUpperBufferIndex, hkBondUpperBuffer, INDICATOR_DATA); + + // + // Lower ... + ArraySetAsSeries(hkBondLowerBuffer, true); + SetIndexBuffer(hkBondLowerBufferIndex, hkBondLowerBuffer, INDICATOR_DATA); + + // + // Data Buffers ... + + // + // CYCLES ... + + // + // SC ... + + // + ArraySetAsSeries(sHHBuffer, true); + SetIndexBuffer(sHHBufferIndex, sHHBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(sLLBuffer, true); + SetIndexBuffer(sLLBufferIndex, sLLBuffer, INDICATOR_DATA); + + // + // MC ... + + // + ArraySetAsSeries(mHHBuffer, true); + SetIndexBuffer(mHHBufferIndex, mHHBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(mLLBuffer, true); + SetIndexBuffer(mLLBufferIndex, mLLBuffer, INDICATOR_DATA); + + // + // LC ... + + // + ArraySetAsSeries(lHHBuffer, true); + SetIndexBuffer(lHHBufferIndex, lHHBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(lLLBuffer, true); + SetIndexBuffer(lLLBufferIndex, lLLBuffer, INDICATOR_DATA); + + // + // HC ... + + // + ArraySetAsSeries(hHHBuffer, true); + SetIndexBuffer(hHHBufferIndex, hHHBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(hLLBuffer, true); + SetIndexBuffer(hLLBufferIndex, hLLBuffer, INDICATOR_DATA); + + // + // Highs ... + SetIndexBuffer(highsBufferIndex, highsBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(highsTimeBufferIndex, highsTimeBuffer, INDICATOR_CALCULATIONS); + + // + // Lows ... + SetIndexBuffer(lowsBufferIndex, lowsBuffer, INDICATOR_CALCULATIONS); + SetIndexBuffer(lowsTimeBufferIndex, lowsTimeBuffer, INDICATOR_CALCULATIONS); + + // + // XHK Data ... + + // + ArraySetAsSeries(hkRawHighBuffer, true); + SetIndexBuffer(hkRawHighBufferIndex, hkRawHighBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(hkRawOpenBuffer, true); + SetIndexBuffer(hkRawOpenBufferIndex, hkRawOpenBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(hkRawLowBuffer, true); + SetIndexBuffer(hkRawLowBufferIndex, hkRawLowBuffer, INDICATOR_DATA); + + // + ArraySetAsSeries(hkRawCloseBuffer, true); + SetIndexBuffer(hkRawCloseBufferIndex, hkRawCloseBuffer, INDICATOR_DATA); + + // +} + +/** + * Initial Market Cycles ... + * + * @return ( bool ) + */ +bool InitCycles() +{ + // + bool result = false; + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + if (IsValid(mSCPeriod)) + { + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + if (IsValid(mMCPeriod)) + { + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + if (IsValid(mLCPeriod)) + { + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + } + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + if (IsValid(mHCPeriod)) + { + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + } + + // + result = mSCLength > 0 && + mMCLength > mSCLength && + mLCLength > mMCLength && + mHCLength > mLCLength; + + // + return result; +} + +/** + * Initial all Indicator Requirements ... + * + * @return ( false ) + * + */ +bool InitRequirements() +{ + // + bool result = false; + + // + // Handlers ... + + // + // Fast MA ... + maFastHandler = iMA( + _Symbol, + _Period, + maFastLength, + 0, + maMethod, + maAppliedTo // + ); + result = maFastHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // Slow MA ... + maSlowHandler = iMA( + _Symbol, + _Period, + maSlowLength, + 0, + maMethod, + maAppliedTo // + ); + result = maSlowHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // MA Bond Upper ... + maUpperHandler = iMA( + _Symbol, + _Period, + maBandLength, + 0, + maMethod, + PRICE_HIGH // + ); + result = maUpperHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // MA Bond Lower ... + maLowerHandler = iMA( + _Symbol, + _Period, + maBandLength, + 0, + maMethod, + PRICE_LOW // + ); + result = maLowerHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + // SAR ... + sarHandler = iSAR( + _Symbol, + _Period, + sarStep, + sarMax // + ); + result = sarHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + mDrawer = new XCPOIDrawer(); + + // + return result; +} + +/** + * Calculate Custom Buffers ... + * + * @param barIndex: Integer, Represent Current Bar ... + * @param prevCalculated: Integer, Represent Previous Calculated Bars ... + * @param ratesTotal: Integer, Represents All Available Bars ... + * @param open: Double Array, History of Open Prices ... + * @param high: Double Array, History of High Prices ... + * @param close: Double Array, History of Close Prices ... + * @param low: Double Array, History of Low Prices ... + * @param tickVolume: Long, History of Tick Volumes on Bar ... + */ +void CalculateBuffers( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // Calculate Bars Limit and First Bar Index ... + int barsLimit = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : 0; + if (barsLimit == 0) + { + // + barsLimit = ratesTotal; + firstBarIndex = barsLimit - 1; + } + else + { + firstBarIndex = startCalculationForLastBars; + } + + // + // bool canCalculate = true; + bool canCalculate = + barIndex <= barsLimit; + if (canCalculate) + { + // + // Calculate Values ... + CalculateValues( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + } + else + { + FillBuffersZero(barIndex); + } +} + +/** + * Fill All Bufers to Zero Vlue for Specified Bar Index ... + * + * @param barIndex: Integer ... + */ +void FillBuffersZero(int barIndex) +{ + // + // TODO: Fill Buffers as Empty ... +} + +/** + * Calculate Values ... + * + * @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 CalculateValues( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int lastBarIndex = barIndex + 1; + int maxBarIndex = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : ratesTotal; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + // Common Requirements ... + + // + // CYCLES Ranges ... + CalculateCycleRanges( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // PV ... + CalculatePV( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // XHK ... + CalculateHKBar( + barIndex, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // Fast MA ... + double iFastMa = maFastBuffer[barIndex]; + double maFastState = close[barIndex] > iFastMa + ? bullishState + : close[barIndex] < iFastMa + ? bearishState + : neuturalState; + double maFastColor = close[barIndex] > iFastMa + ? bullishColorIDX + : close[barIndex] < iFastMa + ? bearishColorIDX + : neuturalColorIDX; + maFastStateBuffer[barIndex] = maFastState; + maFastColorBuffer[barIndex] = showMAFast + ? maFastColor + : hideColorIDX; + + // + // Slow MA ... + double iSlowMa = maSlowBuffer[barIndex]; + double maSlowState = close[barIndex] > iSlowMa + ? bullishState + : close[barIndex] < iSlowMa + ? bearishState + : neuturalState; + double maSlowColor = close[barIndex] > iSlowMa + ? bullishColorIDX + : close[barIndex] < iSlowMa + ? bearishColorIDX + : neuturalColorIDX; + maSlowStateBuffer[barIndex] = maSlowState; + maSlowColorBuffer[barIndex] = showMASlow + ? maSlowColor + : hideColorIDX; + + // + // SAR ... + double iSar = sarBuffer[barIndex]; + double sarState = low[barIndex] > iSar + ? bullishState + : high[barIndex] < iSar + ? bearishState + : neuturalState; + double sarColor = low[barIndex] > iSar + ? bullishColorIDX + : high[barIndex] < iSar + ? bearishColorIDX + : neuturalColorIDX; + sarStateBuffer[barIndex] = sarState; + sarColorBuffer[barIndex] = showSAR + ? sarColor + : hideColorIDX; + + // + // FIBO Zone ... + + // + double iPeak = peakBuffer[barIndex]; + double iVale = valeBuffer[barIndex]; + + // + double iFiboUp = GetFibonacciLevel( + iPeak, + iVale, + fiboUpperZoneLevel, + X_DIRECTION_BULLISH // + ); + + // + double iFiboMid = GetFibonacciLevel( + iPeak, + iVale, + fiboMiddleZoneLevel, + X_DIRECTION_BULLISH // + ); + + // + double iFiboLo = GetFibonacciLevel( + iPeak, + iVale, + fiboLowerZoneLevel, + X_DIRECTION_BULLISH // + ); + + // + fiboUpperBuffer[barIndex] = iFiboUp; + fiboMiddleBuffer[barIndex] = iFiboMid; + fiboLowerBuffer[barIndex] = iFiboLo; +} + +// +void CalculatePV( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int lastBarIndex = barIndex + 1; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + double iSHH = sHHBuffer[barIndex]; + double iSLL = sLLBuffer[barIndex]; + + // + double iMHH = mHHBuffer[barIndex]; + double iMLL = mLLBuffer[barIndex]; + + // + double iLHH = lHHBuffer[barIndex]; + double iLLL = lLLBuffer[barIndex]; + + // + double iHHH = hHHBuffer[barIndex]; + double iHLL = hLLBuffer[barIndex]; + + // + // Calculate VALE ... + bool isVale = iSLL == iMLL && + iMLL == iLLL && + iLLL == iHLL; + double iPVale = + isFirstBar + ? emptyValue + : valeBuffer[lastBarIndex]; + double iVale = + isVale + ? iSLL + : iPVale; + valeBuffer[barIndex] = iVale; + + // + // Calculate PEAK ... + bool isPeak = iSHH == iMHH && + iMHH == iLHH && + iLHH == iHHH; + double iPPeak = + isFirstBar + ? emptyValue + : peakBuffer[lastBarIndex]; + double iPeak = + isPeak + ? iSHH + : iPPeak; + peakBuffer[barIndex] = iPeak; +} + +/** + * Calculate Values ... + * + * @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 ... + * + * @return ( int ) + */ +int CalculateZigZag( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int result = 0; + + // + // Define Variables ... + int i = 0; + + // + int start = 0; + int extreme_counter = 0; + int extreme_search = X_ZG_SEARCH_EXTREMUM; + int shift = 0; + int back = 0; + int last_high_pos = 0; + int last_low_pos = 0; + + // + double val = 0; + double res = 0; + double curlow = 0; + double curhigh = 0; + double last_high = 0; + double last_low = 0; + + // + // Initializing ... + if (prevCalculated == 0) + { + // + ArrayInitialize(lowsBuffer, 0); + ArrayInitialize(highsBuffer, 0); + ArrayInitialize(zigzagBuffer, 0); + ArrayInitialize(lowsTimeBuffer, 0); + ArrayInitialize(highsTimeBuffer, 0); + + // + start = zigzagDepth; + } + + // + // Preparing ZigZag Calculation High and Lows ... + + // + if (zigzagLowersCount != zigzagUppersCount || zigzagLowersCount != ratesTotal) + { + // + // Filling Upper ... + zigzagUppersCount = FillPrice( + zigzagUppersMode, + zigzagUppers, + open, + high, + close, + low // + ); + + // + // Filling Lower ... + zigzagLowersCount = FillPrice( + zigzagLowersMode, + zigzagLowers, + open, + high, + close, + low // + ); + } + + // + // Already Calculated Before ... + if (prevCalculated > 0) + { + // + i = ratesTotal - 1; + + // + // Searching for the third X_ZG_SEARCH_EXTREMUM from the last UnComplete Bar ... + while (extreme_counter < zigzagRecalc && i > ratesTotal - 100) + { + // + res = zigzagBuffer[i]; + if (res != 0) + { + extreme_counter++; + } + + // + i--; + } + + // + i++; + start = i; + + // + // What type of X_ZG_SEARCH_EXTREMUM we Search for ... + if (lowsBuffer[i] != 0) + { + // + curlow = lowsBuffer[i]; + extreme_search = X_ZG_SEARCH_PEAK; + } + else + { + // + curhigh = highsBuffer[i]; + extreme_search = X_ZG_SEARCH_VALE; + } + + // + // Clear Values ... + for (i = start + 1; i < ratesTotal && !IsStopped(); i++) + { + // + lowsBuffer[i] = 0; + highsBuffer[i] = 0; + zigzagBuffer[i] = 0; + lowsTimeBuffer[i] = 0; + highsTimeBuffer[i] = 0; + } + } + + // + // Search for High and Low Extremes ... + for (shift = start; shift < ratesTotal && !IsStopped(); shift++) + { + // + // Low ... + val = zigzagLowers[Lowest(zigzagLowers, zigzagDepth, shift)]; + if (val == last_low) + { + val = 0; + } + else + { + // + last_low = val; + + // + if ((zigzagLowers[shift] - val) > zigzagDeviation * _Point) + { + val = 0; + } + else + { + // + for (back = 1; back <= zigzagBackStep; back++) + { + // + res = lowsBuffer[shift - back]; + if ((res != 0) && (res > val)) + { + // + lowsBuffer[shift - back] = 0; + lowsTimeBuffer[shift - back] = 0; + } + } + } + } + + // + if (zigzagLowers[shift] == val) + { + // + lowsBuffer[shift] = val; + lowsTimeBuffer[shift] = GetZigZagBarTime(shift); + } + else + { + // + lowsBuffer[shift] = 0; + lowsTimeBuffer[shift] = 0; + } + + // + // High ... + val = zigzagUppers[Highest(zigzagUppers, zigzagDepth, shift)]; + if (val == last_high) + { + val = 0; + } + else + { + // + last_high = val; + + // + if ((val - zigzagUppers[shift]) > zigzagDeviation * _Point) + { + val = 0; + } + else + { + // + for (back = 1; back <= zigzagBackStep; back++) + { + // + res = highsBuffer[shift - back]; + if ((res != 0) && (res < val)) + { + // + highsBuffer[shift - back] = 0; + highsTimeBuffer[shift - back] = 0; + } + } + } + } + + // + if (zigzagUppers[shift] == val) + { + // + highsBuffer[shift] = val; + highsTimeBuffer[shift] = GetZigZagBarTime(shift); + } + else + { + highsBuffer[shift] = 0; + highsTimeBuffer[shift] = 0; + } + } + + // + // Set Last Value ... + if (extreme_search == 0) // Undefined Values ... + { + // + last_low = 0; + last_high = 0; + } + else + { + // + last_low = curlow; + last_high = curhigh; + } + + // + // Final Selection of Extreme Points for ZigZag ... + for (shift = start; shift < ratesTotal && !IsStopped(); shift++) + { + // + res = 0; + + // + switch (extreme_search) + { + // + case X_ZG_SEARCH_EXTREMUM: + // + if (last_low == 0 && last_high == 0) + { + // + if (highsBuffer[shift] != 0) + { + // + last_high_pos = shift; + last_high = zigzagUppers[shift]; + + // + extreme_search = X_ZG_SEARCH_VALE; + + // + zigzagBuffer[shift] = last_high; + + // + res = 1; + } + + // + if (lowsBuffer[shift] != 0) + { + // + last_low_pos = shift; + last_low = zigzagLowers[shift]; + + // + extreme_search = X_ZG_SEARCH_PEAK; + + // + zigzagBuffer[shift] = last_low; + + // + res = 1; + } + } + break; + + // + case X_ZG_SEARCH_PEAK: + // + if (lowsBuffer[shift] != 0 && lowsBuffer[shift] < last_low && highsBuffer[shift] == 0) + { + // + zigzagBuffer[last_low_pos] = 0; + + // + last_low_pos = shift; + last_low = lowsBuffer[shift]; + + // + zigzagBuffer[shift] = last_low; + + // + res = 1; + } + + // + if (highsBuffer[shift] != 0 && lowsBuffer[shift] == 0) + { + // + last_high_pos = shift; + last_high = highsBuffer[shift]; + + // + zigzagBuffer[shift] = last_high; + + // + extreme_search = X_ZG_SEARCH_VALE; + + // + res = 1; + } + break; + + // + case X_ZG_SEARCH_VALE: + // + if (highsBuffer[shift] != 0 && highsBuffer[shift] > last_high && lowsBuffer[shift] == 0) + { + // + zigzagBuffer[last_high_pos] = 0; + + // + last_high_pos = shift; + last_high = highsBuffer[shift]; + + // + zigzagBuffer[shift] = last_high; + } + + // + if (lowsBuffer[shift] != 0 && highsBuffer[shift] == 0) + { + // + last_low_pos = shift; + last_low = lowsBuffer[shift]; + + // + zigzagBuffer[shift] = last_low; + + // + extreme_search = X_ZG_SEARCH_PEAK; + } + break; + } + } + + // + result = ratesTotal; + + // + return result; +} + +// +void CalculateHKBar( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int lastBarIndex = barIndex + 1; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + double lastHKOpen = + isFirstBar + ? emptyValue + : hkOpenBuffer[lastBarIndex]; + double lastHKClose = + isFirstBar + ? emptyValue + : hkCloseBuffer[lastBarIndex]; + + // + double iHKOpenValue = (lastHKOpen + lastHKClose) / 2; + double iHKCloseValue = (open[barIndex] + high[barIndex] + close[barIndex] + low[barIndex]) / 4; + double iHKHighValue = MathMax(high[barIndex], MathMax(iHKOpenValue, iHKCloseValue)); + double iHKLowValue = MathMin(low[barIndex], MathMin(iHKOpenValue, iHKCloseValue)); + + // + bool isBullish = iHKOpenValue < iHKCloseValue; + bool isBearish = iHKOpenValue > iHKCloseValue; + + // + if (hkIgnoreShadows) + { + // + iHKHighValue = isBullish + ? iHKCloseValue + : iHKOpenValue; + + // + iHKLowValue = isBullish + ? iHKOpenValue + : iHKCloseValue; + } + + // + // XHK Buffers ... + hkOpenBuffer[barIndex] = iHKOpenValue; + hkHighBuffer[barIndex] = iHKHighValue; + hkLowBuffer[barIndex] = iHKLowValue; + hkCloseBuffer[barIndex] = iHKCloseValue; + + // + // XHK Raw Bufferss ... + hkRawOpenBuffer[barIndex] = iHKOpenValue; + hkRawHighBuffer[barIndex] = iHKHighValue; + hkRawLowBuffer[barIndex] = iHKLowValue; + hkRawCloseBuffer[barIndex] = iHKCloseValue; + + // + // Smoothing ... + if (IsXValid(hkSmoothingMode) && hkSmoothingLength > 0) + { + // + // XHK Signal ... + + // + // High ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + barIndex, + hkSmoothingLength, + hkRawHighBuffer, + hkHighBuffer, + hkSmoothingMode // + ); + + // + // Open ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + barIndex, + hkSmoothingLength, + hkRawOpenBuffer, + hkOpenBuffer, + hkSmoothingMode // + ); + + // + // Close ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + barIndex, + hkSmoothingLength, + hkRawLowBuffer, + hkLowBuffer, + hkSmoothingMode // + ); + + // + // Close ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + barIndex, + hkSmoothingLength, + hkRawCloseBuffer, + hkCloseBuffer, + hkSmoothingMode // + ); + } + + // + hkBondUpperBuffer[barIndex] = hkHighBuffer[barIndex]; + hkBondLowerBuffer[barIndex] = hkLowBuffer[barIndex]; + + // + // Calculate HK Color ... + double iHKColorValue = + isBullish + ? bullishColorIDX + : isBearish + ? bearishColorIDX + : neuturalColorIDX; + hkColorBuffer[barIndex] = + showHK + ? iHKColorValue + : hideColorIDX; +} + +// +void CalculateCycleRanges( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // SHORT ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_SHORT, + sHHBuffer, + sLLBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_MEDIUM, + mHHBuffer, + mLLBuffer // + ); + + // + // LONG ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_LONG, + lHHBuffer, + lLLBuffer // + ); + + // + // HIND ... + CalculateCycle( + barIndex, + X_MARKET_CYCLE_HIND, + hHHBuffer, + hLLBuffer // + ); +} + +/** + * Calculate Specified Market Cycle Info ... + * + * @param barIndex: Integer, Bar Index ... + * @param cycle: ENUM_X_MARKET_CYCLES member, Specified Cycle ... + * @param hhBuffer: Highest High Buffer Reference ... + * @param llBuffer: Lowest Low Buffer Reference ... + */ +void CalculateCycle( + int barIndex, + ENUM_X_MARKET_CYCLES cycle, + double &hhBuffer[], + double &llBuffer[] // +) +{ + // + XOHCL bar; + bool isBarInited = bar.Init( + _Symbol, + _Period, + barIndex + // + ); + if (!isBarInited) + { + return; + } + + // + int mLength = 0; + switch (cycle) + { + // + case X_MARKET_CYCLE_SHORT: + mLength = mSCLength; + break; + + // + case X_MARKET_CYCLE_MEDIUM: + mLength = mMCLength; + break; + + // + case X_MARKET_CYCLE_LONG: + mLength = mLCLength; + break; + + // + case X_MARKET_CYCLE_HIND: + mLength = mHCLength; + break; + } + + // + if (mLength == 0) + { + return; + } + + // + // Find Highest High ... + double hhValue = bar.FindHighest( + mLength, + upperMode // + ); + hhBuffer[barIndex] = hhValue; + + // + // Find Lowest Low ... + double llValue = bar.FindLowest( + mLength, + lowerMode // + ); + llBuffer[barIndex] = llValue; + + // + bar.Clean(); +} + +// +// +// + +// +// Get Specified Bar Time as Double ... +double GetZigZagBarTime(int barIndex) +{ + // + if (barIndex <= 0) + { + barIndex = 0; + } + + // + datetime time = iTime(_Symbol, _Period, barIndex); + + // + double result = (double)((int)time); + + // + return result; +} + +// +// Filling Required Prices Based on MODE ... +int FillPrice( + ENUM_X_PRICE mode, + double &dest[], + const double &open[], + const double &high[], + const double &close[], + const double &low[] // +) +{ + // + int result = 0; + + // + SpecifiedClean(dest); + + // + if (!IsXValid(mode)) + { + return result; + } + + // + switch (mode) + { + // + case X_PRICE_HIGH: + // + result = ArrayCopy( + dest, + high // + ); + break; + + // + case X_PRICE_LOW: + // + result = ArrayCopy( + dest, + low // + ); + break; + + // + case X_PRICE_OPEN: + // + result = ArrayCopy( + dest, + open // + ); + break; + + // + case X_PRICE_CLOSE: + // + result = ArrayCopy( + dest, + close // + ); + break; + + // + default: + // + result = ArrayCopy( + dest, + close // + ); + break; + } + + // + return result; +} + +// +// Search for the index of the highest bar ... +int Highest( + const double &mArray[], + const int mDepth, + const int mStart // +) +{ + // + int result = 0; + + // + if (mStart < 0) + { + return result; + } + + // + double max = mArray[mStart]; + result = mStart; + + // + // Start searching ... + for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--) + { + // + if (mArray[i] > max) + { + // + result = i; + max = mArray[i]; + } + } + + // + // Return index of the highest bar + return result; +} + +// +// Search for the index of the lowest bar ... +int Lowest( + const double &mArray[], + const int mDepth, + const int mStart // +) +{ + // + int result = 0; + + // + if (mStart < 0) + { + return result; + } + + // + double min = mArray[mStart]; + result = mStart; + + // + // Start searching ... + for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--) + { + // + if (mArray[i] < min) + { + // + result = i; + min = mArray[i]; + } + } + + // + // Return index of the lowest bar + return result; +} + +// \ No newline at end of file diff --git a/Experts/x-saherelm.xfima.backtester.ea.mq5 b/Experts/x-saherelm.xfima.backtester.ea.mq5 index fb78395e..75512225 100644 --- a/Experts/x-saherelm.xfima.backtester.ea.mq5 +++ b/Experts/x-saherelm.xfima.backtester.ea.mq5 @@ -100,7 +100,7 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To input int maFastLength = 7; // Fast MA Length input int maSlowLength = 20; // Slow MA Length -input int maBandLength = 7; // MA Band Length +input int maBondLength = 7; // MA Bond Length input int zigzagDepth = 12; // ZigZag Depth input int zigzagDeviation = 5; // ZigZag Deviation input int zigzagBackStep = 3; // ZigZag Back Step @@ -126,7 +126,8 @@ input bool showSAR = true; // Show Sar input bool showBars = true; // Show Bars input bool showMAFast = true; // Show MA Fast input bool showMASlow = true; // Show MA Slow -input bool showMABand = true; // Show MA Band +input bool showMABond = true; // Show MA Bond +input bool showHKBond = true; // Show HK Bond input bool showBarTime = true; // Show Bar Time input bool showZigZag = true; // Show ZigZag input bool showFiboZone = true; // Show Fibo Zone @@ -303,7 +304,7 @@ int OnInit() fimaInputs.maAppliedTo = maAppliedTo; fimaInputs.maFastLength = maFastLength; fimaInputs.maSlowLength = maSlowLength; - fimaInputs.maBandLength = maBandLength; + fimaInputs.maBondLength = maBondLength; fimaInputs.zigzagDepth = zigzagDepth; fimaInputs.zigzagDeviation = zigzagDeviation; fimaInputs.zigzagBackStep = zigzagBackStep; @@ -317,7 +318,8 @@ int OnInit() fimaInputs.showSAR = showSAR; fimaInputs.showMAFast = showMAFast; fimaInputs.showMASlow = showMASlow; - fimaInputs.showMABand = showMABand; + fimaInputs.showMABond = showMABond; + fimaInputs.showHKBond = showHKBond; fimaInputs.showZigZag = showZigZag; fimaInputs.showFiboZone = showFiboZone; fimaInputs.startCalculationForLastBars = startCalculationForLastBars; diff --git a/Helpers/x-saherelm.xfima.helper.mq5 b/Helpers/x-saherelm.xfima.helper.mq5 index b4934f30..73bb99a4 100644 --- a/Helpers/x-saherelm.xfima.helper.mq5 +++ b/Helpers/x-saherelm.xfima.helper.mq5 @@ -35,54 +35,56 @@ enum ENUM_XFIMA_BUFFERS { XFIMA_MA_FAST_LINE = 0, XFIMA_MA_FAST_COLOR_LINE = 1, - XFIMA_MA_FAST_STATE_LINE = 19, + XFIMA_MA_FAST_STATE_LINE = 21, XFIMA_MA_SLOW_LINE = 2, XFIMA_MA_SLOW_COLOR_LINE = 3, - XFIMA_MA_SLOW_STATE_LINE = 20, + XFIMA_MA_SLOW_STATE_LINE = 22, XFIMA_SAR_LINE = 4, XFIMA_SAR_COLOR_LINE = 5, - XFIMA_SAR_STATE_LINE = 21, + XFIMA_SAR_STATE_LINE = 23, XFIMA_PEAK_LINE = 6, XFIMA_VALE_LINE = 7, XFIMA_FIBO_UPPER_LINE = 8, XFIMA_FIBO_MIDDLE_LINE = 9, XFIMA_FIBO_LOWER_LINE = 10, XFIMA_ZIGZAG_LINE = 11, - XFIMA_MA_BAND_UPPER_LINE = 12, - XFIMA_MA_BAND_LOWER_LINE = 13, - XFIMA_ZIGZAG_HIGHS_LINE = 30, - XFIMA_ZIGZAG_HIGHS_TIME_LINE = 31, - XFIMA_ZIGZAG_LOWS_LINE = 32, - XFIMA_ZIGZAG_LOWS_TIME_LINE = 33, + XFIMA_MA_BOND_UPPER_LINE = 12, + XFIMA_MA_BOND_LOWER_LINE = 13, + XFIMA_ZIGZAG_HIGHS_LINE = 32, + XFIMA_ZIGZAG_HIGHS_TIME_LINE = 33, + XFIMA_ZIGZAG_LOWS_LINE = 34, + XFIMA_ZIGZAG_LOWS_TIME_LINE = 35, // XFIMA_HK_OPEN_LINE = 14, XFIMA_HK_HIGH_LINE = 15, XFIMA_HK_LOW_LINE = 16, XFIMA_HK_CLOSE_LINE = 17, XFIMA_HK_COLOR_LINE = 18, - XFIMA_HK_RAW_OPEN_LINE = 34, - XFIMA_HK_RAW_HIGH_LINE = 35, - XFIMA_HK_RAW_LOW_LINE = 36, - XFIMA_HK_RAW_CLOSE_LINE = 37, - // 19 Ma Fast State - // 20 Ma Slow State - // 21 Sar State - XFIMA_SC_HH_LINE = 22, - XFIMA_SC_LL_LINE = 23, - XFIMA_MC_HH_LINE = 24, - XFIMA_MC_LL_LINE = 25, - XFIMA_LC_HH_LINE = 26, - XFIMA_LC_LL_LINE = 27, - XFIMA_HC_HH_LINE = 28, - XFIMA_HC_LL_LINE = 29, - // 30 ZigZag Highs - // 31 ZigZag Highs Time - // 32 ZigZag Lows - // 33 ZigZag Lows Time - // 34 HK Raw Open - // 35 HK Raw High - // 36 HK Raw Low - // 37 HK Raw Close + XFIMA_HK_BOND_UPPER_LINE = 19, + XFIMA_HK_BOND_LOWER_LINE = 20, + XFIMA_HK_RAW_OPEN_LINE = 36, + XFIMA_HK_RAW_HIGH_LINE = 37, + XFIMA_HK_RAW_LOW_LINE = 38, + XFIMA_HK_RAW_CLOSE_LINE = 39, + // 21 Ma Fast State + // 22 Ma Slow State + // 23 Sar State + XFIMA_SC_HH_LINE = 24, + XFIMA_SC_LL_LINE = 25, + XFIMA_MC_HH_LINE = 26, + XFIMA_MC_LL_LINE = 27, + XFIMA_LC_HH_LINE = 28, + XFIMA_LC_LL_LINE = 29, + XFIMA_HC_HH_LINE = 30, + XFIMA_HC_LL_LINE = 31, + // 32 ZigZag Highs + // 33 ZigZag Highs Time + // 34 ZigZag Lows + // 35 ZigZag Lows Time + // 36 HK Raw Open + // 37 HK Raw High + // 38 HK Raw Low + // 39 HK Raw Close }; // @@ -113,7 +115,7 @@ struct XFIMAInputs ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To int maFastLength; // Fast MA Length int maSlowLength; // Slow MA Length - int maBandLength; // MA Band Length + int maBondLength; // MA Bond Length int zigzagDepth; // ZigZag Depth int zigzagDeviation; // ZigZag Deviation int zigzagBackStep; // ZigZag Back Step @@ -130,7 +132,8 @@ struct XFIMAInputs bool showSAR; // Show Sar bool showMAFast; // Show MA Fast bool showMASlow; // Show MA Slow - bool showMABand; // Show MA Band + bool showMABond; // Show MA Bond + bool showHKBond; // Show HK Bond bool showZigZag; // Show ZigZag bool showFiboZone; // Show Fibo Zone int startCalculationForLastBars; // Calculate Last n Bars @@ -180,7 +183,7 @@ struct XFIMAInputs maAppliedTo = PRICE_CLOSE; // MA Applied To maFastLength = 7; // Fast MA Length maSlowLength = 20; // Slow MA Length - maBandLength = 7; // MA Band Length + maBondLength = 7; // MA Bond Length zigzagDepth = 12; // ZigZag Depth zigzagDeviation = 5; // ZigZag Deviation zigzagBackStep = 3; // ZigZag Back Step @@ -197,7 +200,8 @@ struct XFIMAInputs showSAR = true; // Show Sar showMAFast = true; // Show MA Fast showMASlow = true; // Show MA Slow - showMABand = true; // Show MA Band + showMABond = true; // Show MA Bond + showHKBond = true; // Show HK Bond showZigZag = true; // Show ZigZag showFiboZone = true; // Show Fibo Zone startCalculationForLastBars = 1500; // Calculate Last n Bars @@ -216,7 +220,8 @@ struct XFIMAInputs showSAR = false; showMAFast = false; showMASlow = false; - showMABand = false; + showMABond = false; + showHKBond = false; showZigZag = false; showFiboZone = false; } @@ -234,7 +239,7 @@ struct XFIMAInputs // MA ... maFastLength >= 2 && maSlowLength >= 2 && - maBandLength >= 2 && + maBondLength >= 2 && maSlowLength > maFastLength && // // SAR ... @@ -289,8 +294,8 @@ struct XFIMAConditions double maSlowBuffer[]; double maSlowColorBuffer[]; double maSlowStateBuffer[]; - double maBandUpperBuffer[]; - double maBandLowerBuffer[]; + double maBondUpperBuffer[]; + double maBondLowerBuffer[]; double sarBuffer[]; double sarColorBuffer[]; double sarStateBuffer[]; @@ -357,8 +362,8 @@ struct XFIMAConditions SpecifiedClean(maSlowBuffer); SpecifiedClean(maSlowColorBuffer); SpecifiedClean(maSlowStateBuffer); - SpecifiedClean(maBandUpperBuffer); - SpecifiedClean(maBandLowerBuffer); + SpecifiedClean(maBondUpperBuffer); + SpecifiedClean(maBondLowerBuffer); SpecifiedClean(sarBuffer); SpecifiedClean(sarColorBuffer); SpecifiedClean(sarStateBuffer); @@ -399,8 +404,8 @@ struct XFIMAConditions ArraySetAsSeries(maSlowBuffer, true); ArraySetAsSeries(maSlowColorBuffer, true); ArraySetAsSeries(maSlowStateBuffer, true); - ArraySetAsSeries(maBandUpperBuffer, true); - ArraySetAsSeries(maBandLowerBuffer, true); + ArraySetAsSeries(maBondUpperBuffer, true); + ArraySetAsSeries(maBondLowerBuffer, true); ArraySetAsSeries(sarBuffer, true); ArraySetAsSeries(sarColorBuffer, true); ArraySetAsSeries(sarStateBuffer, true); @@ -554,7 +559,7 @@ class XCXFIMAHelper : public XCBaseHelper mInputs.maAppliedTo, mInputs.maFastLength, mInputs.maSlowLength, - mInputs.maBandLength, + mInputs.maBondLength, mInputs.zigzagDepth, mInputs.zigzagDeviation, mInputs.zigzagBackStep, @@ -569,7 +574,8 @@ class XCXFIMAHelper : public XCBaseHelper mInputs.showSAR, mInputs.showMAFast, mInputs.showMASlow, - mInputs.showMABand, + mInputs.showMABond, + mInputs.showHKBond, mInputs.showZigZag, mInputs.showFiboZone, mInputs.startCalculationForLastBars, @@ -703,17 +709,17 @@ class XCXFIMAHelper : public XCBaseHelper ); // - CopyMABandUpper( + CopyMABondUpper( zIndex, loopback, - conditions.maBandUpperBuffer // + conditions.maBondUpperBuffer // ); // - CopyMABandLower( + CopyMABondLower( zIndex, loopback, - conditions.maBandLowerBuffer // + conditions.maBondLowerBuffer // ); // @@ -1158,6 +1164,444 @@ class XCXFIMAHelper : public XCBaseHelper return result; } + /** + * Check Peak Happens over Last ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsPeakOverLast(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Reading Values ... + + // + double iPeak = GetPeak(barIndex); + double pPeak = GetPeak(barIndex + 1); + + // + result = NotEmptyZero(iPeak) && + iPeak > pPeak; + + // + return result; + } + + /** + * Check Vale Happens over Last ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsValeOverLast(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Reading Values ... + + // + double iVale = GetVale(barIndex); + double pVale = GetVale(barIndex + 1); + + // + result = NotEmptyZero(iVale) && + iVale > pVale; + + // + return result; + } + + /** + * Check Peak Happens under Last ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsPeakUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Reading Values ... + + // + double iPeak = GetPeak(barIndex); + double pPeak = GetPeak(barIndex + 1); + + // + result = NotEmptyZero(iPeak) && + iPeak < pPeak; + + // + return result; + } + + /** + * Check Vale Happens under Last ... + * + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsValeUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Reading Values ... + + // + double iVale = GetVale(barIndex); + double pVale = GetVale(barIndex + 1); + + // + result = NotEmptyZero(iVale) && + iVale < pVale; + + // + return result; + } + + /** + * Check Fibo Section is Changed or not ... + * + * @param dir: reference to hold section change direction ... + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool IsFiboSectionChanged( + ENUM_X_DIRECTION &dir, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = false; + bool isBearish = false; + + // + // Reading Values ... + + // + double iFiboUpper = GetFiboUpper(barIndex); + double pFiboUpper = GetFiboUpper(barIndex + 1); + + // + double iFiboMiddle = GetFiboMiddle(barIndex); + double pFiboMiddle = GetFiboMiddle(barIndex + 1); + + // + double iFiboLower = GetFiboLower(barIndex); + double pFiboLower = GetFiboLower(barIndex + 1); + + // + isBullish = iFiboLower >= pFiboMiddle && + iFiboMiddle >= pFiboUpper; + isBearish = iFiboUpper <= pFiboMiddle && + iFiboMiddle <= pFiboLower; + result = (isBullish && !isBearish) || + (isBearish && !isBullish); + if (!result) + { + return result; + } + + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + + bool HasFiboPush( + ENUM_X_DIRECTION &dir, + int barIndex = 0, + int validationLength = 5 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + validationLength = NormalizeInt(validationLength, 3); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Define Requirements ... + + // + XOHCL iBar; + bool isBullish = false; + bool isBearish = false; + + // + double iFiboUpper = EMPTY_VALUE; + double pFiboUpper = EMPTY_VALUE; + + // + double iFiboMiddle = EMPTY_VALUE; + double pFiboMiddle = EMPTY_VALUE; + + // + double iFiboLower = EMPTY_VALUE; + double pFiboLower = EMPTY_VALUE; + + // + // Check Zone Validation ... + int start = barIndex; + int end = start + validationLength; + for (int i = start; i < end; i++) + { + // + // Reading Values ... + + // + iFiboUpper = GetFiboUpper(i); + pFiboUpper = GetFiboUpper(i + 1); + + // + iFiboMiddle = GetFiboMiddle(i); + pFiboMiddle = GetFiboMiddle(i + 1); + + // + iFiboLower = GetFiboLower(i); + pFiboLower = GetFiboLower(i + 1); + + // + result = iFiboUpper == pFiboUpper; + if (!result) + { + break; + } + } + + // + if (result) + { + // + result = iBar.Init( + mSymbol, + mPeriod, + barIndex // + ); + + // + if (result) + { + // + iFiboUpper = GetFiboUpper(barIndex); + iFiboMiddle = GetFiboMiddle(barIndex); + iFiboLower = GetFiboLower(barIndex); + + // + isBullish = iBar.IsBullish() && + iBar.close > iFiboLower && + iBar.low < iFiboLower; + isBearish = iBar.IsBearish() && + iBar.close < iFiboUpper && + iBar.high > iFiboUpper; + result = (isBullish && !isBearish) || + (isBearish && !isBullish); + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + } + } + + // + // Cleanup Resources ... + iBar.Clean(); + + // + return result; + } + + // + // Tools ... + + /** + * Detect Last Fibo Section Changed till Loopback Length ... + * + * @param lastBarIndex: int, reference to hold Detected Bar Index ... + * @param dir: ENUM_X_DIRECTION, reference to detected Direction ... + * @param barIndex: int, Specified Bar Index ... + * @param maxAllowedLoopbackLength: int, Max Allowed Loopback Bars ... + * @param forDir: ENUM_X_DIRECTION, Specified Section Change Direction Looking for ... + * + * @return ( bool ) + */ + bool GetLastFiboSectionChanged( + int &lastBarIndex, + ENUM_X_DIRECTION &dir, + int barIndex = 0, + int maxAllowedLoopbackLength = 100, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + bool result = false; + + // + // Prepare ... + lastBarIndex = -1; + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + int start = barIndex + 1; + int end = start + maxAllowedLoopbackLength; + for (int i = start; i < end; i++) + { + // + result = IsFiboSectionChanged(dir, i); + if (result) + { + // + // Validate By forDir ... + if (HasDirection(forDir)) + { + result = dir == forDir; + } + + // + if (!result) + { + // + lastBarIndex = -1; + dir = X_DIRECTION_NONE; + } + + // + if (result) + { + // + lastBarIndex = i; + break; + } + } + } + + // + result = HasDirection(dir) && + IsValidIndex(lastBarIndex); + + // + return result; + } + + // + // Extractions ... + /** * Extract Specified Kind of Pivots ... * @@ -2641,19 +3085,19 @@ class XCXFIMAHelper : public XCBaseHelper // Upper MA ... // - double GetMABandUpper( + double GetMABondUpper( int barIndex // Bar Index ) { // return ReadValue( - (int)XFIMA_MA_BAND_UPPER_LINE, + (int)XFIMA_MA_BOND_UPPER_LINE, barIndex // ); } // - int CopyMABandUpper( + int CopyMABondUpper( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -2663,7 +3107,7 @@ class XCXFIMAHelper : public XCBaseHelper // return ReadValues( buffer, - (int)XFIMA_MA_BAND_UPPER_LINE, + (int)XFIMA_MA_BOND_UPPER_LINE, start, count, asSeries // @@ -2674,19 +3118,19 @@ class XCXFIMAHelper : public XCBaseHelper // Lower MA ... // - double GetMABandLower( + double GetMABondLower( int barIndex // Bar Index ) { // return ReadValue( - (int)XFIMA_MA_BAND_LOWER_LINE, + (int)XFIMA_MA_BOND_LOWER_LINE, barIndex // ); } // - int CopyMABandLower( + int CopyMABondLower( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -2696,7 +3140,7 @@ class XCXFIMAHelper : public XCBaseHelper // return ReadValues( buffer, - (int)XFIMA_MA_BAND_LOWER_LINE, + (int)XFIMA_MA_BOND_LOWER_LINE, start, count, asSeries // @@ -3417,6 +3861,210 @@ class XCXFIMAHelper : public XCBaseHelper ); } + // + // XHK Raw ... + + // + // XHK Raw Open ... + + // + double GetHKRawOpen( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HK_RAW_OPEN_LINE, + barIndex // + ); + } + + // + int CopyHKRawOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HK_RAW_OPEN_LINE, + start, + count, + asSeries // + ); + } + + // + // XHK Raw High ... + + // + double GetHKRawHigh( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HK_RAW_HIGH_LINE, + barIndex // + ); + } + + // + int CopyHKRawHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HK_RAW_HIGH_LINE, + start, + count, + asSeries // + ); + } + + // + // XHK Raw Low ... + + // + double GetHKRawLow( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HK_RAW_LOW_LINE, + barIndex // + ); + } + + // + int CopyHKRawLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HK_RAW_LOW_LINE, + start, + count, + asSeries // + ); + } + + // + // XHK Raw Close ... + + // + double GetHKRawClose( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HK_RAW_CLOSE_LINE, + barIndex // + ); + } + + // + int CopyHKRawClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HK_RAW_CLOSE_LINE, + start, + count, + asSeries // + ); + } + + // + // XHK Bond ... + + // + // XHK Bond Upper ... + + // + double GetHKBondUpper( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HK_BOND_UPPER_LINE, + barIndex // + ); + } + + // + int CopyHKBondUpper( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HK_BOND_UPPER_LINE, + start, + count, + asSeries // + ); + } + + // + // XHK Bond Lower ... + + // + double GetHKBondLower( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)XFIMA_HK_BOND_LOWER_LINE, + barIndex // + ); + } + + // + int CopyHKBondLower( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)XFIMA_HK_BOND_LOWER_LINE, + start, + count, + asSeries // + ); + } + // // Protected ... protected: diff --git a/Indicators/x-saherelm.xfima.mq5 b/Indicators/x-saherelm.xfima.mq5 index a93db0b4..217d07dc 100644 --- a/Indicators/x-saherelm.xfima.mq5 +++ b/Indicators/x-saherelm.xfima.mq5 @@ -82,8 +82,8 @@ input double sarMax = 0.2; // SAR Maximum input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To input int maFastLength = 7; // Fast MA Length -input int maSlowLength = 20; // Slow MA Length -input int maBandLength = 7; // MA Band Length +input int maSlowLength = 21; // Slow MA Length +input int maBandLength = 21; // MA Bond Length input int zigzagDepth = 12; // ZigZag Depth input int zigzagDeviation = 5; // ZigZag Deviation input int zigzagBackStep = 3; // ZigZag Back Step @@ -101,7 +101,8 @@ input bool showHK = true; // Show HK input bool showSAR = true; // Show Sar input bool showMAFast = true; // Show MA Fast input bool showMASlow = true; // Show MA Slow -input bool showMABand = true; // Show MA Band +input bool showMABand = true; // Show MA Bond +input bool showHKBond = true; // Show HK Bond input bool showZigZag = true; // Show ZigZag input bool showFiboZone = true; // Show Fibo Zone @@ -137,8 +138,8 @@ input int valeArrowCode = 159; // Vales Arrow Code #property indicator_chart_window // -#property indicator_buffers 38 -#property indicator_plots 12 +#property indicator_buffers 40 +#property indicator_plots 14 // // Plot Buffers ... @@ -282,7 +283,7 @@ double zigzagBuffer[]; #property indicator_width9 2 // -// MA Upper Boundary ... +// MA Upper ... // #define maUpperBufferIndex 12 @@ -292,11 +293,11 @@ double maUpperBuffer[]; // #property indicator_label10 "UpperMA" #property indicator_type10 DRAW_LINE -#property indicator_color10 clrAqua +#property indicator_color10 clrLime #property indicator_width10 3 // -// MA Lower Boundary ... +// MA Lower ... // #define maLowerBufferIndex 13 @@ -306,7 +307,7 @@ double maLowerBuffer[]; // #property indicator_label11 "LowerMA" #property indicator_type11 DRAW_LINE -#property indicator_color11 clrMagenta +#property indicator_color11 clrRed #property indicator_width11 3 // @@ -338,11 +339,33 @@ double hkColorBuffer[]; #property indicator_type12 DRAW_COLOR_CANDLES #property indicator_color12 CLR_NONE, clrAqua, clrMagenta, clrGray +// +#define hkBondUpperBufferIndex 19 +double hkBondUpperBuffer[]; + +// +#define hkBondUpperBufferPlotIndex 12 +#property indicator_label13 "UpperHK" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrAqua +#property indicator_width13 3 + +// +#define hkBondLowerBufferIndex 20 +double hkBondLowerBuffer[]; + +// +#define hkBondLowerBufferPlotIndex 13 +#property indicator_label14 "LowerHK" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrMagenta +#property indicator_width14 3 + // // Data Buffers ... // -#define mLastBufferIndex 18 +#define mLastBufferIndex 20 // // MA ... @@ -982,13 +1005,13 @@ void DefineBuffers() PlotIndexSetDouble(zigzagBufferPlotIndex, PLOT_EMPTY_VALUE, 0); // - // MA Band ... + // MA Bond ... // ENUM_DRAW_TYPE maBandDrawType = showMABand ? DRAW_LINE : DRAW_NONE; // - // MA Upper Band ... + // MA Upper Bond ... // ArraySetAsSeries(maUpperBuffer, true); @@ -1002,7 +1025,7 @@ void DefineBuffers() PlotIndexSetDouble(maUpperBufferPlotIndex, PLOT_EMPTY_VALUE, 0); // - // MA Lower Band ... + // MA Lower Bond ... // ArraySetAsSeries(maLowerBuffer, true); @@ -1048,6 +1071,19 @@ void DefineBuffers() ArraySetAsSeries(hkCloseBuffer, true); SetIndexBuffer(hkCloseBufferIndex, hkCloseBuffer, INDICATOR_DATA); + // + // XHK Bond ... + + // + // Upper ... + ArraySetAsSeries(hkBondUpperBuffer, true); + SetIndexBuffer(hkBondUpperBufferIndex, hkBondUpperBuffer, INDICATOR_DATA); + + // + // Lower ... + ArraySetAsSeries(hkBondLowerBuffer, true); + SetIndexBuffer(hkBondLowerBufferIndex, hkBondLowerBuffer, INDICATOR_DATA); + // // Data Buffers ... @@ -1288,7 +1324,7 @@ bool InitRequirements() } // - // MA Band Upper ... + // MA Bond Upper ... maUpperHandler = iMA( _Symbol, _Period, @@ -1304,7 +1340,7 @@ bool InitRequirements() } // - // MA Band Lower ... + // MA Bond Lower ... maLowerHandler = iMA( _Symbol, _Period, @@ -2160,6 +2196,10 @@ void CalculateHKBar( ); } + // + hkBondUpperBuffer[barIndex] = hkHighBuffer[barIndex]; + hkBondLowerBuffer[barIndex] = hkLowBuffer[barIndex]; + // // Calculate HK Color ... double iHKColorValue = diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 57987aeb..e9b84969 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -3850,6 +3850,28 @@ void ValidateBoxes( // } +void UpdateToTime( + XBoxZone &zones[], + datetime toTime = NULL// +) { + // + // Normalize ... + toTime = NormalizeTime(toTime); + + // + // Validate ... + bool has = HasChild(zones); + if (!has) { + return; + } + + // + int count = ArraySize(zones); + for (int i = 0; i < count; i++) { + zones[i].to = toTime; + } +} + /** * Converts a Bar to Pivot ... * diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index 5f3dba76..991c0342 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -415,8 +415,8 @@ class XCXFIMABaseSignaller : public XCBaseSignaller // // Retrieve MA Band for Validation ... - double iMABandUpper = fimaConditions.maBandUpperBuffer[0]; - double iMABandLower = fimaConditions.maBandLowerBuffer[0]; + double iMABandUpper = fimaConditions.maBondUpperBuffer[0]; + double iMABandLower = fimaConditions.maBondLowerBuffer[0]; // // Validate by Edge Price ... @@ -578,6 +578,9 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // XBoxZone iBox; // XCBoxObject *iBoxObj; + // + // poiDrawer.RemoveDraws(); + // // // has = iStructure.pvAnalysis.HasSupportBox(iBox); // if (has) @@ -608,21 +611,71 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // } // } + // // + // // Draw Zones ... + // has = HasChild(iStructure.supports); + // if (has) { + // // + // CArrayObj *iSupportObjs; + // poiDrawer.DrawBoxes( + // iStructure.supports, + // iSupportObjs, + // true // + // ); + // } + + // // + // has = HasChild(iStructure.resistances); + // if (has) { + // // + // CArrayObj *iResistanceObjs; + // poiDrawer.DrawBoxes( + // iStructure.resistances, + // iResistanceObjs, + // true // + // ); + // } + + // + // Detecte Fibo Section Changes ... + + // + has = fimaHelper.IsFiboSectionChanged(iDir, iBar.Index()); + has = has && + IsXBullish(iDir) && + fimaHelper.IsValeOverLast(iBar.Index()); + + // + has = fimaHelper.IsFiboSectionChanged(iDir, iBar.Index()); + has = has && + IsXBearish(iDir) && + fimaHelper.IsPeakUnderLast(iBar.Index()); + + // + has = fimaHelper.HasFiboPush(iDir, iBar.Index(), 5); + + // + if (has) + { + Print("Draw Zones ..."); + } + // // Disable Signallers ... has = false; + iDir = X_DIRECTION_NONE; // // Strategy 1 ... // Works on Support or Resistances Areas ... - has = Strategy1HasSignal( - iBar, - iZone, - iTargets, - iDir, - iFIMAConditions, - iStructure // - ); + // has = Strategy1HasSignal( + // iBar, + // iZone, + // iTargets, + // iDir, + // iFIMAConditions, + // iStructure // + // ); // // Strategy 2 ... diff --git a/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 index ca3cf83d..7f596944 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 @@ -476,6 +476,138 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector return result; } + int ExtractXFIMAZones( + XBoxZone &zones[], + int barIndex = 0, + int requiredNumberOfZones = 50, + double shadowMultiplier = 4, + int maxAllowedLoopbackLength = 1500 // + ) + { + // + int result = 0; + + // + // Prepare ... + XClean(zones); + + // + // Normalize ... + barIndex = NormalizeInt(barIndex, 0); + shadowMultiplier = NormalizeDouble(shadowMultiplier, 2); + requiredNumberOfZones = NormalizeInt(requiredNumberOfZones, 5); + maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50); + + // + // Validate ... + bool has = + fimaHelper != NULL && + fimaHelper.IsValid(); + if (!has) + { + return result; + } + + // + // Create a Loop ... + XOHCL iBar; + XBoxZone iBox; + bool isBullish = false; + bool isBearish = false; + double iUpper = EMPTY_VALUE; + double iLower = EMPTY_VALUE; + double iHKUpper = EMPTY_VALUE; + double iHKLower = EMPTY_VALUE; + double iMAUpper = EMPTY_VALUE; + double iMALower = EMPTY_VALUE; + string symbol = fimaHelper.GetSymbol(); + ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + ENUM_TIMEFRAMES period = fimaHelper.GetPeriod(); + + // + int start = barIndex; + int idx = start - 1; + int end = start + maxAllowedLoopbackLength; + while (ArraySize(zones) < requiredNumberOfZones && idx < end) + { + // + idx++; + + // + // Initialize Indexed Bar ... + has = iBar.Init( + symbol, + period, + idx // + ); + if (!has) + { + continue; + } + + // + // Reading Bars ... + iMAUpper = fimaHelper.GetMABondUpper(idx); + iMALower = fimaHelper.GetMABondLower(idx); + iHKUpper = fimaHelper.GetHKBondUpper(idx); + iHKLower = fimaHelper.GetHKBondLower(idx); + + // + iUpper = MathMax(iMAUpper, iHKUpper); + iLower = MathMin(iMALower, iHKLower); + + // + // Check Bar State ... + has = + NotEmptyZero(iUpper) && + NotEmptyZero(iLower); + if (!has) + { + continue; + } + + // + // Check Direction of Zone ... + isBullish = iBar.low < iLower; + isBearish = iBar.high > iUpper; + has = (isBullish && !isBearish) || + (isBearish && !isBullish); + if (!has) + { + continue; + } + + // + // Validate Shadow Multiplier ... + has = + isBullish + ? iBar.GetLowShadow() > iBar.GetHighShadow() * shadowMultiplier + : iBar.GetHighShadow() > iBar.GetLowShadow() * shadowMultiplier; + if (!has) + { + continue; + } + + // + iDir = isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + + // + // Cleanup Resources ... + iBar.Clean(); + iBox.Clean(); + } + + // + result = ArraySize(zones); + + // + return result; + } + /** * Destroy ... */ @@ -1434,6 +1566,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // OBS ... CheckZones(forBar, obs); + UpdateToTime(obs, forBar.time); Copy( obs, structure.obs // @@ -1442,6 +1575,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // FVGS ... CheckZones(forBar, fvgs); + UpdateToTime(fvgs, forBar.time); Copy( fvgs, structure.fvgs // @@ -1450,6 +1584,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // SUPPORTS ... CheckZones(forBar, supports); + UpdateToTime(supports, forBar.time); Copy( supports, structure.supports // @@ -1458,6 +1593,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // RESISTANCES ... CheckZones(forBar, resistances); + UpdateToTime(resistances, forBar.time); Copy( resistances, structure.resistances //