diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 05e6267f..2b4b613f 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -260,7 +260,7 @@ class XCBarAnalyser : public XCBase } // - index = bar.Index(); + index = bar.Index() + 1; bool canContinue = true; int sameBullishBarsFounded = 0; int sameBearishBarsFounded = 0; @@ -297,12 +297,20 @@ class XCBarAnalyser : public XCBase sameBullishBarsFounded++; canContinueForBearish = false; } - else + else if (isBearish) { // sameBearishBarsFounded++; canContinueForBullish = false; } + else + { + // + sameBullishBarsFounded = 0; + sameBearishBarsFounded = 0; + canContinueForBullish = false; + canContinueForBearish = false; + } // result = canContinueForBullish || @@ -348,6 +356,9 @@ class XCBarAnalyser : public XCBase return result; } + // + index--; + // dir = hasBullishSameBars @@ -2295,7 +2306,7 @@ class XCBarAnalyser : public XCBase } // - int obIndex = index; + int obIndex = index + 1; result = ob.Init( bar.symbol, bar.period, @@ -2368,8 +2379,11 @@ class XCBarAnalyser : public XCBase bool isBullish = IsBullish(dir); // - int to = bar.Index() + 1; - int from = index + 1; + int to = bar.Index(); + int from = + index > (to + sameBars) + ? to + sameBars + : index; for (int i = from; i > to; i--) { // diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index c7ac30e0..5fdbd4db 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -1157,7 +1157,7 @@ class XCPOIDetector : public XCBaseAlert // iBar.Clean(); mLock = false; - mBarTracker.Waits(); + // mBarTracker.Waits(); // if (HasChild(events)) @@ -1332,251 +1332,8 @@ class XCPOIDetector : public XCBaseAlert } // - protected: // - // - void CleanCollections() - { - // - Clean(mSwings); - Clean(mSwingLows); - Clean(mSwingHighs); - Clean(mDemandZones); - Clean(mSupplyZones); - Clean(mOrderBlocks); - Clean(mMomentumBars); - Clean(mSupportZones); - Clean(mRejectionBars); - Clean(mFairValueGaps); - Clean(mEventListeners); - Clean(mResistanceZones); - Clean(mBullishOrderBlocks); - Clean(mBearishOrderBlocks); - Clean(mConsolidationZones); - Clean(mBullishMomentumBars); - Clean(mBearishMomentumBars); - Clean(mBullishRejectionBars); - Clean(mBearishRejectionBars); - Clean(mBullishFairValueGaps); - Clean(mBearishFairValueGaps); - Clean(mBullishConsolidationZones); - Clean(mBearishConsolidationZones); - } - - // - void ReverseCollections() - { - // - ArrayReverse(mSwings); - ArrayReverse(mSwingLows); - ArrayReverse(mSwingHighs); - ArrayReverse(mDemandZones); - ArrayReverse(mSupplyZones); - ArrayReverse(mOrderBlocks); - ArrayReverse(mMomentumBars); - ArrayReverse(mSupportZones); - ArrayReverse(mRejectionBars); - ArrayReverse(mFairValueGaps); - ArrayReverse(mEventListeners); - ArrayReverse(mResistanceZones); - ArrayReverse(mBullishOrderBlocks); - ArrayReverse(mBearishOrderBlocks); - ArrayReverse(mConsolidationZones); - ArrayReverse(mBullishMomentumBars); - ArrayReverse(mBearishMomentumBars); - ArrayReverse(mBullishRejectionBars); - ArrayReverse(mBearishRejectionBars); - ArrayReverse(mBullishFairValueGaps); - ArrayReverse(mBearishFairValueGaps); - ArrayReverse(mBullishConsolidationZones); - ArrayReverse(mBearishConsolidationZones); - } - - // - void CleanupUnusedCollections( - int maxAllowed = 0 // - ) - { - // - maxAllowed = MaxRequiredPOIs(); - - // - if (maxAllowed <= 0) - { - return; - } - - // - CleanupArray( - mEventListeners, - maxAllowed // - ); - - // - CleanupArray( - mSwings, - maxAllowed // - ); - - // - CleanupArray( - mSwingLows, - maxAllowed // - ); - - // - CleanupArray( - mSwingHighs, - maxAllowed // - ); - - // - CleanupArray( - mMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mBullishMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mBearishMomentumBars, - maxAllowed // - ); - - // - CleanupArray( - mRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mBullishRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mBearishRejectionBars, - maxAllowed // - ); - - // - CleanupArray( - mSupportZones, - maxAllowed // - ); - - // - CleanupArray( - mDemandZones, - maxAllowed // - ); - - // - CleanupArray( - mSupplyZones, - maxAllowed // - ); - - // - CleanupArray( - mResistanceZones, - maxAllowed // - ); - - // - CleanupArray( - mFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mBullishFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mBearishFairValueGaps, - maxAllowed // - ); - - // - CleanupArray( - mOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mBullishOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mBearishOrderBlocks, - maxAllowed // - ); - - // - CleanupArray( - mConsolidationZones, - maxAllowed // - ); - - // - CleanupArray( - mBullishConsolidationZones, - maxAllowed // - ); - - // - CleanupArray( - mBearishConsolidationZones, - maxAllowed // - ); - - // - } - - /** - * Notify Event Listeners ... - * - * @param event: ENUM_XPOI_EVENTS member, Specified Occured Event ... - * @param param: XCBasePOI implementation, Specified Event Object ... - */ - void NotifyEventListeners( - ENUM_XPOI_EVENTS event, - XCBasePOI *param // - ) - { - // - int count = ArraySize(mEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - mEventListeners[i]( - event, - param // - ); - } - } - // // // @@ -3253,6 +3010,252 @@ class XCPOIDetector : public XCBaseAlert return result; } + // + protected: + // + + // + void CleanCollections() + { + // + Clean(mSwings); + Clean(mSwingLows); + Clean(mSwingHighs); + Clean(mDemandZones); + Clean(mSupplyZones); + Clean(mOrderBlocks); + Clean(mMomentumBars); + Clean(mSupportZones); + Clean(mRejectionBars); + Clean(mFairValueGaps); + Clean(mEventListeners); + Clean(mResistanceZones); + Clean(mBullishOrderBlocks); + Clean(mBearishOrderBlocks); + Clean(mConsolidationZones); + Clean(mBullishMomentumBars); + Clean(mBearishMomentumBars); + Clean(mBullishRejectionBars); + Clean(mBearishRejectionBars); + Clean(mBullishFairValueGaps); + Clean(mBearishFairValueGaps); + Clean(mBullishConsolidationZones); + Clean(mBearishConsolidationZones); + } + + // + void ReverseCollections() + { + // + ArrayReverse(mSwings); + ArrayReverse(mSwingLows); + ArrayReverse(mSwingHighs); + ArrayReverse(mDemandZones); + ArrayReverse(mSupplyZones); + ArrayReverse(mOrderBlocks); + ArrayReverse(mMomentumBars); + ArrayReverse(mSupportZones); + ArrayReverse(mRejectionBars); + ArrayReverse(mFairValueGaps); + ArrayReverse(mEventListeners); + ArrayReverse(mResistanceZones); + ArrayReverse(mBullishOrderBlocks); + ArrayReverse(mBearishOrderBlocks); + ArrayReverse(mConsolidationZones); + ArrayReverse(mBullishMomentumBars); + ArrayReverse(mBearishMomentumBars); + ArrayReverse(mBullishRejectionBars); + ArrayReverse(mBearishRejectionBars); + ArrayReverse(mBullishFairValueGaps); + ArrayReverse(mBearishFairValueGaps); + ArrayReverse(mBullishConsolidationZones); + ArrayReverse(mBearishConsolidationZones); + } + + // + void CleanupUnusedCollections( + int maxAllowed = 0 // + ) + { + // + maxAllowed = MaxRequiredPOIs(); + + // + if (maxAllowed <= 0) + { + return; + } + + // + CleanupArray( + mEventListeners, + maxAllowed // + ); + + // + CleanupArray( + mSwings, + maxAllowed // + ); + + // + CleanupArray( + mSwingLows, + maxAllowed // + ); + + // + CleanupArray( + mSwingHighs, + maxAllowed // + ); + + // + CleanupArray( + mMomentumBars, + maxAllowed // + ); + + // + CleanupArray( + mBullishMomentumBars, + maxAllowed // + ); + + // + CleanupArray( + mBearishMomentumBars, + maxAllowed // + ); + + // + CleanupArray( + mRejectionBars, + maxAllowed // + ); + + // + CleanupArray( + mBullishRejectionBars, + maxAllowed // + ); + + // + CleanupArray( + mBearishRejectionBars, + maxAllowed // + ); + + // + CleanupArray( + mSupportZones, + maxAllowed // + ); + + // + CleanupArray( + mDemandZones, + maxAllowed // + ); + + // + CleanupArray( + mSupplyZones, + maxAllowed // + ); + + // + CleanupArray( + mResistanceZones, + maxAllowed // + ); + + // + CleanupArray( + mFairValueGaps, + maxAllowed // + ); + + // + CleanupArray( + mBullishFairValueGaps, + maxAllowed // + ); + + // + CleanupArray( + mBearishFairValueGaps, + maxAllowed // + ); + + // + CleanupArray( + mOrderBlocks, + maxAllowed // + ); + + // + CleanupArray( + mBullishOrderBlocks, + maxAllowed // + ); + + // + CleanupArray( + mBearishOrderBlocks, + maxAllowed // + ); + + // + CleanupArray( + mConsolidationZones, + maxAllowed // + ); + + // + CleanupArray( + mBullishConsolidationZones, + maxAllowed // + ); + + // + CleanupArray( + mBearishConsolidationZones, + maxAllowed // + ); + + // + } + + /** + * Notify Event Listeners ... + * + * @param event: ENUM_XPOI_EVENTS member, Specified Occured Event ... + * @param param: XCBasePOI implementation, Specified Event Object ... + */ + void NotifyEventListeners( + ENUM_XPOI_EVENTS event, + XCBasePOI *param // + ) + { + // + int count = ArraySize(mEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + mEventListeners[i]( + event, + param // + ); + } + } + // private: // diff --git a/Documents/BKP/x-saherelm.x121.xwz.mq5 b/Documents/BKP/x-saherelm.x121.xwz.mq5 new file mode 100644 index 00000000..8828b358 --- /dev/null +++ b/Documents/BKP/x-saherelm.x121.xwz.mq5 @@ -0,0 +1,3438 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: X121 XWZ +// Description: XWZ ... +// +// +// 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 X121 XWZ Indicator" +#property strict + +// +// Definitions ... + +// +#define ShortName "X121_XWZ" + +// +// Includes Common Library ... +#include "../Classes/x-saherelm.x-alert.class.mq5" +#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" +#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" +#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; + +// +input group "Calculation"; +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Detect Price Type + +// +input group "MA Detection"; +input int maLength = 20; // MA Length +input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method + +// +input group "ATR StopLoss"; +input int atrLength = 14; // ATR Length +input double atrMultiplier = 2; // ATR Multiplier + +// +input group "ADX Detection"; +input int adxLength = 14; // ADX Length +input double adxThreshold = 25; // ADX Threshold for Strong Trends + +// +input group "Alert"; +input bool mXWZEnableAlerts = true; // Enable Alerts +input bool mXWZPushAlerts = false; // Push Alerts +input bool mXWZMailAlerts = false; // Mail Alerts +input bool mXWZTerminalAlerts = false; // Terminal Alerts + +// +// Presentation ... +input group "Presentation"; + +// +input group "Buffer Presentation"; +input bool showMA = true; // Show Moving Average +input bool showPin = true; // Show Pin Bars +input bool showSwing = true; // Show Swing Bars +input bool showTrend = true; // Show Trend +input bool showEngulf = true; // Show Engulf Bars +input bool showLongSL = true; // Show Long SL +input bool showShortSL = true; // Show Short SL +input bool showMomentum = true; // Show Momentum Bars +input bool showRejection = true; // Show Rejection Bars + +// +input group "POI Presentation"; +input bool showPOIs = false; // Show POI(s) +input bool showActivatedPOIs = true; // Show Activated POI(s) +input bool showOrderBlocks = true; // Show Order Blocks +input bool showFairValueGaps = true; // Show Fair Value Gaps +input bool showSupportZones = false; // Show Support Zones +input bool showResistanceZones = false; // Show Resistance Zones + +// +input group "Presentation Config"; +input int startCalculationForLastBars = 1000; // Calculate Last n Bars +input int upTrendArrowCode = 236; // Up Trend Arrow Code +input int downTrendArrowCode = 238; // Down Trend Arrow Code +input int swingLowArrowCode = 108; // Swing Low Arrow Code +input int swingHighArrowCode = 108; // Swing High Arrow Code +input int bullishPinArrowCode = 246; // Bullish Pin Arrow Code +input int bearishPinArrowCode = 248; // Bearish Pin Arrow Code +input int bullishEngulfArrowCode = 200; // Bullish Engulf Arrow Code +input int bearishEngulfArrowCode = 202; // Bearish Engulf Arrow Code +input int bullishMomentumArrowCode = 233; // Bullish Momentum Arrow Code +input int bearishMomentumArrowCode = 234; // Bearish Momentum Arrow Code +input int bullishRejectionArrowCode = 241; // Bullish Rejection Arrow Code +input int bearishRejectionArrowCode = 242; // Bearish Rejection Arrow Code + +// +#property indicator_chart_window + +// +#property indicator_buffers 17 +#property indicator_plots 15 + +// +// Plot Buffers ... + +// +#define maBufferIndex 0 +double maBuffer[]; + +// +#property indicator_label1 "X121-XWZ MA" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrLightSkyBlue +#property indicator_style1 STYLE_SOLID +#property indicator_width1 2 + +// +#define longSLBufferIndex 1 +double longSLBuffer[]; + +// +#property indicator_label2 "X121-XWZ Long SL" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrOrange +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +#define shortSLBufferIndex 2 +double shortSLBuffer[]; + +// +#property indicator_label3 "X121-XWZ Short SL" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrOrange +#property indicator_style3 STYLE_SOLID +#property indicator_width3 1 + +// +#define upTrendBufferIndex 3 +double upTrendBuffer[]; + +// +#property indicator_label4 "X121-XWZ Trend Up" +#property indicator_type4 DRAW_ARROW +#property indicator_color4 clrAqua +#property indicator_width4 3 + +// +#define downTrendBufferIndex 4 +double downTrendBuffer[]; + +// +#property indicator_label5 "X121-XWZ Trend Down" +#property indicator_type5 DRAW_ARROW +#property indicator_color5 clrMagenta +#property indicator_width5 3 + +// +#define bullishMomentumBufferIndex 5 +double bullishMomentumBuffer[]; + +// +#property indicator_label6 "X121-XWZ Bull Momentum" +#property indicator_type6 DRAW_ARROW +#property indicator_color6 clrAqua +#property indicator_width6 3 + +// +#define bearishMomentumBufferIndex 6 +double bearishMomentumBuffer[]; + +// +#property indicator_label7 "X121-XWZ Bear Momentum" +#property indicator_type7 DRAW_ARROW +#property indicator_color7 clrMagenta +#property indicator_width7 3 + +// +#define bullishRejectionBufferIndex 7 +double bullishRejectionBuffer[]; + +// +#property indicator_label8 "X121-XWZ Bull Rejection" +#property indicator_type8 DRAW_ARROW +#property indicator_color8 clrAqua +#property indicator_width8 3 + +// +#define bearishRejectionBufferIndex 8 +double bearishRejectionBuffer[]; + +// +#property indicator_label9 "X121-XWZ Bear Rejection" +#property indicator_type9 DRAW_ARROW +#property indicator_color9 clrMagenta +#property indicator_width9 3 + +// +#define bullishPinBufferIndex 9 +double bullishPinBuffer[]; + +// +#property indicator_label10 "X121-XWZ Bull Pin" +#property indicator_type10 DRAW_ARROW +#property indicator_color10 clrAqua +#property indicator_width10 3 + +// +#define bearishPinBufferIndex 10 +double bearishPinBuffer[]; + +// +#property indicator_label11 "X121-XWZ Bear Pin" +#property indicator_type11 DRAW_ARROW +#property indicator_color11 clrMagenta +#property indicator_width11 3 + +// +#define bullishEngulfBufferIndex 11 +double bullishEngulfBuffer[]; + +// +#property indicator_label12 "X121-XWZ Bull Engulf" +#property indicator_type12 DRAW_ARROW +#property indicator_color12 clrAqua +#property indicator_width12 3 + +// +#define bearishEngulfBufferIndex 12 +double bearishEngulfBuffer[]; + +// +#property indicator_label13 "X121-XWZ Bear Engulf" +#property indicator_type13 DRAW_ARROW +#property indicator_color13 clrMagenta +#property indicator_width13 3 + +// +#define swingLowBufferIndex 13 +double swingLowBuffer[]; + +// +#property indicator_label14 "X121-XWZ Swing Low" +#property indicator_type14 DRAW_ARROW +#property indicator_color14 clrAqua +#property indicator_width14 3 + +// +#define swingHighBufferIndex 14 +double swingHighBuffer[]; + +// +#property indicator_label15 "X121-XWZ Swing High" +#property indicator_type15 DRAW_ARROW +#property indicator_color15 clrMagenta +#property indicator_width15 3 + +// +// Data Buffers ... + +// +int mLastBufferIndex = 14; + +// +#define atrBufferIndex mLastBufferIndex + 1 +double atrBuffer[]; + +// +#define adxBufferIndex mLastBufferIndex + 2 +double adxBuffer[]; + +// +// Variables, Properties and etc ... + +// +// this counts Available Bars ... +int limit; + +// +int maxLength; + +// +// MA Handler ... +int maHandler = INVALID_HANDLE; + +// +// ATR Handler ... +int atrHandler = INVALID_HANDLE; + +// +// ADX Handler ... +int adxHandler = INVALID_HANDLE; + +// +XCAlert *mXWZAlert; +CArrayObj mXWZDrawnObjects; +XCPOIDrawer *mXWZPOIDrawer; +XCBarAnalyser *mXWZBarAnalyser; + +// +datetime lastBullishTrend = NULL; +datetime lastBearishTrend = NULL; + +// +datetime lastCrossedOverMA = NULL; +datetime lastCrossedUnderMA = NULL; + +// +// POI(s) ... + +// +bool mXWZDetectOrderBlocks = true; +bool mXWZDetectFairValueGaps = false; +bool mXWZDetectSupportZones = false; +bool mXWZDetectResistanceZones = false; + +// +bool filterPOIsUsingMa = false; // Filter POI(s) Using MA +bool filterPOIsUsingZones = false; // Filter POI(s) Using Zones + +// +XCFVG *lastBullFVG; +XCFVG *lastBearFVG; +XCOrderBlock *lastBullOB; +XCOrderBlock *lastBearOB; +XCSupportZone *lastSupport; +XCResistanceZone *lastResistance; + +// +// Un Activated POI(s) ... +XCFVG *mXWZUnActivatedFVGs[]; +XCOrderBlock *mXWZUnActivatedOBs[]; +XCSupportZone *mXWZUnActivatedSupportZones[]; +XCResistanceZone *mXWZUnActivatedResistanceZones[]; + +// +// Activated POI(s) ... +XCFVG *mXWZActivatedFVGs[]; +XCOrderBlock *mXWZActivatedOBs[]; +XCSupportZone *mXWZActivatedSupportZones[]; +XCResistanceZone *mXWZActivatedResistanceZones[]; + +// +// Event Handlers ... + +/** + * Initialize Indicator ... + * + * @return ( int ) + */ +int OnInit() +{ + // + mXWZDrawnObjects.Clear(); + + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Initialize Indicator Handlers ... + + // + // MA ... + maHandler = iMA( + _Symbol, + _Period, + maLength, + 0, + maMethod, + appliedTo // + ); + bool isInited = maHandler != INVALID_HANDLE; + if (!isInited) + { + return INIT_FAILED; + } + + // + // ATR ... + atrHandler = iATR( + _Symbol, + _Period, + atrLength // + ); + isInited = maHandler != INVALID_HANDLE; + if (!isInited) + { + return INIT_FAILED; + } + + // + // ADX ... + adxHandler = iADX( + _Symbol, + _Period, + adxLength // + ); + isInited = maHandler != INVALID_HANDLE; + if (!isInited) + { + 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(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + IndicatorSetInteger(INDICATOR_DIGITS, 2); + + // + mXWZPOIDrawer = new XCPOIDrawer(); + ConfigurePOIDrawer(); + + // + mXWZAlert = new XCAlert(); + ConfigureAlert(); + + // + mXWZBarAnalyser = new XCBarAnalyser(); + + // + // 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 + + // + IndicatorRelease(maHandler); + IndicatorRelease(atrHandler); + IndicatorRelease(adxHandler); + + // + mXWZDrawnObjects.Clear(); + + // + ZeroMemory(mXWZAlert); + ZeroMemory(mXWZPOIDrawer); + ZeroMemory(mXWZBarAnalyser); + + // + Clean(mXWZActivatedOBs); + Clean(mXWZActivatedFVGs); + Clean(mXWZActivatedSupportZones); + Clean(mXWZActivatedResistanceZones); + + // + Clean(mXWZUnActivatedOBs); + Clean(mXWZUnActivatedFVGs); + Clean(mXWZUnActivatedSupportZones); + Clean(mXWZUnActivatedResistanceZones); +} + +/** + * 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[] // +) +{ + // + // 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 maCalculatedBars = BarsCalculated(maHandler); + + // + // ATR ... + int atrCalculatedBars = BarsCalculated(atrHandler); + + // + // ADX ... + int adxCalculatedBars = BarsCalculated(adxHandler); + + // + bool isPassedRequiredCalculatedBars = + // + // MA ... + maCalculatedBars >= maxLength && + // + // ATR ... + atrCalculatedBars >= maxLength && + // + // ADX ... + adxCalculatedBars >= 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 copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer); + + // + // ATR ... + int copiedAtr = CopyBuffer(atrHandler, MAIN_LINE, 0, limit, atrBuffer); + + // + // ADX ... + int copiedAdxs = CopyBuffer(adxHandler, MAIN_LINE, 0, limit, adxBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // MA ... + copiedMas > 0 && + // + // ATR ... + copiedAtr > 0 && + // + // ADX ... + copiedAdxs > 0 + // + ; + 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; +} + +// +// Functions ... + +/** + * Validate Input Args for Initialization ... + * + * @return ( bool ) + */ +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + // MA ... + maLength > 0 && + // + // ATR ... + atrLength > 0 && + atrMultiplier > 0 && + // + // ADX ... + adxLength > 0 && + adxThreshold > 0 + // + ; + + // + return result; +} + +/** + * Extract Max Length of Inputs ... + * + * @return ( int ) + */ +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + result = MathMax(maLength, atrLength); + result = MathMax(result, adxLength); + + // + return result; +} + +/** + * Set Indicator Short Name and also we can define Buffers Labels ... + */ +void SetIndicatorName() +{ + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +/** + * Define Required Buffers ... + */ +void DefineBuffers() +{ + // + // Plot Buffers ... + + // + // MA Buffer ... + + // + ENUM_DRAW_TYPE maDrawType = showMA ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(maBuffer, true); + SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showMA); + PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, maDrawType); + + // + PlotIndexSetDouble(maBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + // LONG SL Buffer ... + + // + ENUM_DRAW_TYPE longSLDrawType = showLongSL ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(longSLBuffer, true); + SetIndexBuffer(longSLBufferIndex, longSLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(longSLBufferIndex, PLOT_SHOW_DATA, showLongSL); + PlotIndexSetInteger(longSLBufferIndex, PLOT_DRAW_TYPE, longSLDrawType); + + // + PlotIndexSetDouble(longSLBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + // SHORT SL Buffer ... + + // + ENUM_DRAW_TYPE shortSLDrawType = showShortSL ? DRAW_LINE : DRAW_NONE; + + // + ArraySetAsSeries(shortSLBuffer, true); + SetIndexBuffer(shortSLBufferIndex, shortSLBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(shortSLBufferIndex, PLOT_SHOW_DATA, showShortSL); + PlotIndexSetInteger(shortSLBufferIndex, PLOT_DRAW_TYPE, shortSLDrawType); + + // + PlotIndexSetDouble(shortSLBufferIndex, PLOT_EMPTY_VALUE, 0); + + // + // UP Trend ... + + // + ENUM_DRAW_TYPE upTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(upTrendBuffer, true); + SetIndexBuffer(upTrendBufferIndex, upTrendBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showTrend); + PlotIndexSetInteger(upTrendBufferIndex, PLOT_DRAW_TYPE, upTrendDrawType); + + // + PlotIndexSetDouble(upTrendBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(upTrendBufferIndex, PLOT_ARROW, upTrendArrowCode); + + // + // DOWN Trend ... + + // + ENUM_DRAW_TYPE downTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(downTrendBuffer, true); + SetIndexBuffer(downTrendBufferIndex, downTrendBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showTrend); + PlotIndexSetInteger(downTrendBufferIndex, PLOT_DRAW_TYPE, downTrendDrawType); + + // + PlotIndexSetDouble(downTrendBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(downTrendBufferIndex, PLOT_ARROW, downTrendArrowCode); + + // + // Bullish Momentum ... + + // + ENUM_DRAW_TYPE bullishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishMomentumBuffer, true); + SetIndexBuffer(bullishMomentumBufferIndex, bullishMomentumBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); + PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_DRAW_TYPE, bullishMomentumDrawType); + + // + PlotIndexSetDouble(bullishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_ARROW, bullishMomentumArrowCode); + + // + // Bearish Momentum ... + + // + ENUM_DRAW_TYPE bearishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishMomentumBuffer, true); + SetIndexBuffer(bearishMomentumBufferIndex, bearishMomentumBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); + PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_DRAW_TYPE, bearishMomentumDrawType); + + // + PlotIndexSetDouble(bearishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_ARROW, bearishMomentumArrowCode); + + // + // Bullish Rejection ... + + // + ENUM_DRAW_TYPE bullishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishRejectionBuffer, true); + SetIndexBuffer(bullishRejectionBufferIndex, bullishRejectionBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); + PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_DRAW_TYPE, bullishRejectionDrawType); + + // + PlotIndexSetDouble(bullishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_ARROW, bullishRejectionArrowCode); + + // + // Bearish Rejection ... + + // + ENUM_DRAW_TYPE bearishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishRejectionBuffer, true); + SetIndexBuffer(bearishRejectionBufferIndex, bearishRejectionBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); + PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_DRAW_TYPE, bearishRejectionDrawType); + + // + PlotIndexSetDouble(bearishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_ARROW, bearishRejectionArrowCode); + + // + // Bullish Pin ... + + // + ENUM_DRAW_TYPE bullishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishPinBuffer, true); + SetIndexBuffer(bullishPinBufferIndex, bullishPinBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishPinBufferIndex, PLOT_SHOW_DATA, showPin); + PlotIndexSetInteger(bullishPinBufferIndex, PLOT_DRAW_TYPE, bullishPinDrawType); + + // + PlotIndexSetDouble(bullishPinBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishPinBufferIndex, PLOT_ARROW, bullishPinArrowCode); + + // + // Bearish Pin ... + + // + ENUM_DRAW_TYPE bearishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishPinBuffer, true); + SetIndexBuffer(bearishPinBufferIndex, bearishPinBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishPinBufferIndex, PLOT_SHOW_DATA, showPin); + PlotIndexSetInteger(bearishPinBufferIndex, PLOT_DRAW_TYPE, bearishPinDrawType); + + // + PlotIndexSetDouble(bearishPinBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishPinBufferIndex, PLOT_ARROW, bearishPinArrowCode); + + // + // Bullish Engulf ... + + // + ENUM_DRAW_TYPE bullishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bullishEngulfBuffer, true); + SetIndexBuffer(bullishEngulfBufferIndex, bullishEngulfBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); + PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_DRAW_TYPE, bullishEngulfDrawType); + + // + PlotIndexSetDouble(bullishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_ARROW, bullishEngulfArrowCode); + + // + // Bearish Engulf ... + + // + ENUM_DRAW_TYPE bearishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(bearishEngulfBuffer, true); + SetIndexBuffer(bearishEngulfBufferIndex, bearishEngulfBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); + PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_DRAW_TYPE, bearishEngulfDrawType); + + // + PlotIndexSetDouble(bearishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_ARROW, bearishEngulfArrowCode); + + // + // Swing Low ... + + // + ENUM_DRAW_TYPE swingLowDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(swingLowBuffer, true); + SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(swingLowBufferIndex, PLOT_SHOW_DATA, showSwing); + PlotIndexSetInteger(swingLowBufferIndex, PLOT_DRAW_TYPE, swingLowDrawType); + + // + PlotIndexSetDouble(swingLowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(swingLowBufferIndex, PLOT_ARROW, swingLowArrowCode); + + // + // Swing High ... + + // + ENUM_DRAW_TYPE swingHighDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; + + // + ArraySetAsSeries(swingHighBuffer, true); + SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); + + // + PlotIndexSetInteger(swingHighBufferIndex, PLOT_SHOW_DATA, showSwing); + PlotIndexSetInteger(swingHighBufferIndex, PLOT_DRAW_TYPE, swingHighDrawType); + + // + PlotIndexSetDouble(swingHighBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(swingHighBufferIndex, PLOT_ARROW, swingHighArrowCode); + + // + // DATA Buffers ... + + // + ArraySetAsSeries(atrBuffer, true); + SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); + + // + ArraySetAsSeries(adxBuffer, true); + SetIndexBuffer(adxBufferIndex, adxBuffer, INDICATOR_CALCULATIONS); +} + +/** + * Calculate Custom Buffers ... + * + * @param bar_index: 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 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[] // +) +{ + // + int barsLimit = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : 0; + // + // bool canCalculate = true; + bool canCalculate = + barsLimit == 0 || + bar_index <= barsLimit; + if (canCalculate) + { + // + CalculatedPOIs( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume // + ); + + // + CalculateValues( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + } + else + { + FillBuffersZero(bar_index); + } +} + +/** + * Fill All Bufers to Zero Vlue for Specified Bar Index ... + * + * @param barIndex: Integer ... + */ +void FillBuffersZero(int barIndex) +{ + // + maBuffer[barIndex] = 0; + atrBuffer[barIndex] = 0; + adxBuffer[barIndex] = 0; + longSLBuffer[barIndex] = 0; + shortSLBuffer[barIndex] = 0; + upTrendBuffer[barIndex] = 0; + swingLowBuffer[barIndex] = 0; + swingHighBuffer[barIndex] = 0; + downTrendBuffer[barIndex] = 0; + bullishPinBuffer[barIndex] = 0; + bearishPinBuffer[barIndex] = 0; + bullishEngulfBuffer[barIndex] = 0; + bearishEngulfBuffer[barIndex] = 0; + bullishMomentumBuffer[barIndex] = 0; + bearishMomentumBuffer[barIndex] = 0; + bullishRejectionBuffer[barIndex] = 0; + bearishRejectionBuffer[barIndex] = 0; +} + +/** + * Calculate Vales ... + * + * @param bar_index: 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 CalculateValues( + 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[] // +) +{ + // + // Prepare Requirements ... + + // + XOHCL iBar; + bool isInited = iBar.Init( + _Symbol, + _Period, + bar_index // + ); + if (!isInited) + { + // + iBar.Clean(); + return; + } + + // + XOHCL pBar; + isInited = iBar.GetPreviousBar(pBar); + if (!isInited) + { + // + iBar.Clean(); + pBar.Clean(); + return; + } + int pIndex = pBar.Index(); + + // + // Calculate Applied Price ... + double iPrice = GetAppliedPrice( + appliedTo, + open, + high, + low, + close, + bar_index // + ); + + // + double iMa = maBuffer[bar_index]; + double iMaPrev = maBuffer[pIndex]; + double iAtr = atrBuffer[bar_index]; + double iAdx = adxBuffer[bar_index]; + double iAppliedAtr = iAtr * atrMultiplier; + + // + double points = GetPoints(_Symbol); + double points10 = 10 * points; + + // + ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + + // + bool hasLastBullOB = lastBullOB != NULL && + lastBullOB.IsValid(); + bool hasLastBearOB = lastBearOB != NULL && + lastBearOB.IsValid(); + + // + bool hasLastBullFVG = lastBullFVG != NULL && + lastBullFVG.IsValid(); + bool hasLastBearFVG = lastBearFVG != NULL && + lastBearFVG.IsValid(); + + // + bool hasLastSupport = lastSupport != NULL && + lastSupport.IsValid(); + + // + bool hasLastResistance = lastResistance != NULL && + lastResistance.IsValid(); + + // + // Calculate Crossing Over / Under Ma ... + bool isCrossedOverMA = + // + iBar.low > iMa && + (pBar.low <= iMaPrev && + (pBar.GetUp() <= iMaPrev || + pBar.GetDown() <= iMaPrev)) + // + ; + bool isCrossedUnderMA = + // + iBar.high < iMa && + (pBar.high >= iMaPrev && + (pBar.GetUp() >= iMaPrev || + pBar.GetDown() >= iMaPrev)) + // + ; + lastCrossedOverMA = + isCrossedOverMA + ? iBar.time + : lastCrossedOverMA; + lastCrossedUnderMA = + isCrossedUnderMA + ? iBar.time + : lastCrossedUnderMA; + + // + // SL Buffers ... + + // + double iLongSL = iPrice - iAppliedAtr; + double iShortSL = iPrice + iAppliedAtr; + + // + longSLBuffer[bar_index] = iLongSL; + shortSLBuffer[bar_index] = iShortSL; + + // + // Trend Buffers ... + + // + bool isUpTrend = + // + iPrice > iMa && + iBar.low < iMa && + iAdx > adxThreshold + // + ; + + // + bool isDownTrend = + // + iPrice < iMa && + iBar.high > iMa && + iAdx > adxThreshold + // + ; + + // + double upTrendValue = 0; + double downTrendValue = 0; + if (isUpTrend) + { + // + lastBullishTrend = iBar.time; + upTrendValue = iBar.low; + } + if (isDownTrend) + { + // + lastBearishTrend = iBar.time; + downTrendValue = iBar.high; + } + + // + upTrendBuffer[bar_index] = upTrendValue; + downTrendBuffer[bar_index] = downTrendValue; + + // + // Momentum Buffers ... + + // + bool isMomentum = mXWZBarAnalyser + .IsMomentumBar( + iBar, + iDir, + 1, // Extends ... + 70 // Body Percent ... + ); + bool isBullishMomentum = + isMomentum && + IsBullish(iDir); + bool isBearishMomentum = + isMomentum && + IsBearish(iDir); + if (isMomentum) + { + // + double iBullMomentumValue = 0; + double iBearMomentumValue = 0; + + // + if (isBullishMomentum) + { + // + double selectedValue = iBar.low; + + // + iBullMomentumValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + + // + iBullMomentumValue = + !filterPOIsUsingMa + ? iBullMomentumValue + : iBullMomentumValue < iMa + ? iBullMomentumValue + : 0; + } + + // + if (isBearishMomentum) + { + // + double selectedValue = iBar.high; + + // + iBearMomentumValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + + // + iBearMomentumValue = + !filterPOIsUsingMa + ? iBearMomentumValue + : iBearMomentumValue > iMa + ? iBearMomentumValue + : 0; + } + + // + bullishMomentumBuffer[bar_index] = iBullMomentumValue; + bearishMomentumBuffer[bar_index] = iBearMomentumValue; + } + + // + // Rejection Buffers ... + + // + bool isRejection = mXWZBarAnalyser + .IsRejectionBar( + iBar, + iDir, + 1, // Extends ... + 70 // Body Percent ... + ); + bool isBullishRejection = + isRejection && + IsBullish(iDir); + bool isBearishRejection = + isRejection && + IsBearish(iDir); + if (isRejection) + { + // + double iBullRejectionValue = 0; + double iBearRejectionValue = 0; + + // + if (isBullishRejection) + { + // + double selectedValue = iBar.low; + + // + iBullRejectionValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + + // + iBullRejectionValue = + !filterPOIsUsingMa + ? iBullRejectionValue + : iBullRejectionValue < iMa + ? iBullRejectionValue + : 0; + } + + // + if (isBearishRejection) + { + // + double selectedValue = iBar.high; + + // + iBearRejectionValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + + // + iBearRejectionValue = + !filterPOIsUsingMa + ? iBearRejectionValue + : iBearRejectionValue > iMa + ? iBearRejectionValue + : 0; + } + + // + bullishRejectionBuffer[bar_index] = iBullRejectionValue; + bearishRejectionBuffer[bar_index] = iBearRejectionValue; + } + + // + // Pin Buffers ... + + // + bool isPin = mXWZBarAnalyser + .IsPinBar( + iBar, + iDir, + 0, // Extends ... + 50, // Shadow Percent ... + 25 // Body Percent ... + ); + bool isBullishPin = + isPin && + IsBullish(iDir); + bool isBearishPin = + isPin && + IsBearish(iDir); + if (isPin) + { + // + double iBullPinValue = 0; + double iBearPinValue = 0; + + // + if (isBullishPin) + { + // + double selectedValue = iBar.low; + + // + iBullPinValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + + // + iBullPinValue = + !filterPOIsUsingMa + ? iBullPinValue + : iBullPinValue < iMa + ? iBullPinValue + : 0; + } + + // + if (isBearishPin) + { + // + double selectedValue = iBar.high; + + // + iBearPinValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + + // + iBearPinValue = + !filterPOIsUsingMa + ? iBearPinValue + : iBearPinValue > iMa + ? iBearPinValue + : 0; + } + + // + bullishPinBuffer[bar_index] = iBullPinValue; + bearishPinBuffer[bar_index] = iBearPinValue; + } + + // + // Engulf Buffers ... + + // + bool isEngulf = mXWZBarAnalyser + .IsEngulfBar( + iBar, + iDir, + 1, // Extends ... + 70 // Body Percent ... + ); + bool isBullishEngulf = + isEngulf && + IsBullish(iDir); + bool isBearishEngulf = + isEngulf && + IsBearish(iDir); + if (isEngulf) + { + // + double iBullEngulfValue = 0; + double iBearEngulfValue = 0; + + // + if (isBullishEngulf) + { + // + double selectedValue = iBar.low; + + // + iBullEngulfValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsInside( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + + // + iBullEngulfValue = + !filterPOIsUsingMa + ? iBullEngulfValue + : iBullEngulfValue < iMa + ? iBullEngulfValue + : 0; + } + + // + if (isBearishEngulf) + { + // + double selectedValue = iBar.high; + + // + iBearEngulfValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsInside( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + + // + iBearEngulfValue = + !filterPOIsUsingMa + ? iBearEngulfValue + : iBearEngulfValue > iMa + ? iBearEngulfValue + : 0; + } + + // + bullishEngulfBuffer[bar_index] = iBullEngulfValue; + bearishEngulfBuffer[bar_index] = iBearEngulfValue; + } + + // + // Swing Buffers ... + + // + bool isSwing = mXWZBarAnalyser + .IsSwing( + iBar, + iDir, + 2 // Range ... + ); + bool isSwingLow = + isSwing && + IsBullish(iDir); + bool isSwingHigh = + isSwing && + IsBearish(iDir); + if (isSwing) + { + // + double iSwingLowValue = 0; + double iSwingHighValue = 0; + + // + if (isSwingLow) + { + // + double selectedValue = iBar.low; + + // + iSwingLowValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBullOB + ? 0 + : IsBelow( + selectedValue, + lastBullOB // + ) + ? selectedValue + : 0; + + // + iSwingLowValue = + !filterPOIsUsingMa + ? iSwingLowValue + : iSwingLowValue < iMa + ? iSwingLowValue + : 0; + } + + // + if (isSwingHigh) + { + // + double selectedValue = iBar.high; + + // + iSwingHighValue = + !filterPOIsUsingZones + ? selectedValue + : !hasLastBearOB + ? 0 + : IsAbove( + selectedValue, + lastBearOB // + ) + ? selectedValue + : 0; + + // + iSwingHighValue = + !filterPOIsUsingMa + ? iSwingHighValue + : iSwingHighValue > iMa + ? iSwingHighValue + : 0; + } + + // + swingLowBuffer[bar_index] = iSwingLowValue; + swingHighBuffer[bar_index] = iSwingHighValue; + } + + // + // + // + + // + DetectSignals( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); + + // + // Cleanup Resources ... + + // + iBar.Clean(); + pBar.Clean(); +} + +// +void ConfigureAlert() +{ + // + mXWZAlert.SetPrefix(ShortName); + + // + mXWZAlert.SetPushAlerts(mXWZPushAlerts); + mXWZAlert.SetMailAlerts(mXWZMailAlerts); + mXWZAlert.SetEnableAlerts(mXWZEnableAlerts); + mXWZAlert.SetTerminalAlerts(mXWZTerminalAlerts); +} + +// +void DetectSignals( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // Calculate Signals ... + + // + XOHCL bar; + XOHCL pBar; + XOHCL ppBar; + bool isInited = bar.Init( + _Symbol, + _Period, + barIndex // + ); + if (!isInited) + { + return; + } + + // + isInited = bar.GetPreviousBar(pBar); + if (!isInited) + { + return; + } + + // + isInited = pBar.GetPreviousBar(ppBar); + if (!isInited) + { + return; + } + + // + int pIDX = pBar.Index(); + int ppIDX = ppBar.Index(); + + // + // Reading Buffers ... + + // + double ma = maBuffer[barIndex]; + double maPrev = maBuffer[pIDX]; + double maPPrev = maBuffer[ppIDX]; + + // + // Pin Bar ... + bool isBullisPinned = bullishPinBuffer[pIDX] > 0; + bool isBearisPinned = bearishPinBuffer[pIDX] > 0; + + // + // Engulf Bar ... + bool isBullisEngulfed = bullishEngulfBuffer[pIDX] > 0; + bool isBearisEngulfed = bearishEngulfBuffer[pIDX] > 0; + + // + // Rejection Bar ... + bool isBullishRejected = bullishRejectionBuffer[pIDX] > 0; + bool isBearishRejected = bearishRejectionBuffer[pIDX] > 0; + + // + // Momentum Bar ... + bool isBullishMomentum = bullishMomentumBuffer[pIDX] > 0; + bool isBearishMomentum = bearishMomentumBuffer[pIDX] > 0; + + // + // Checking Pullback ... + ENUM_X_DIRECTION pullbackDir; + bool hasPullback = mXWZBarAnalyser.HasPullBack( + pullbackDir, + bar // + ); + bool hasBullishPullback = + hasPullback && + IsBullish(pullbackDir); + bool hasBearishPullback = + hasPullback && + IsBearish(pullbackDir); + + // + // Order Block Parsing ... + + // // + // bool isMACrossedOverBullishOB = + // // + // lastBullOB != NULL && + // lastBullOB.IsValid() && + // // + // IsInside( + // maPPrev, + // lastBullOB // + // ) && + // // + // IsAbove( + // maPrev, + // lastBullOB // + // ) + // // + // ; + + // // + // bool isMACrossedUnderBearishOB = + // // + // lastBearOB != NULL && + // lastBearOB.IsValid() && + // // + // IsInside( + // maPPrev, + // lastBearOB // + // ) && + // // + // IsBelow( + // maPrev, + // lastBearOB // + // ) + // // + // ; + + // + // Bullish ... + // -------------- + // -[] a Bullish Wave Which Crossed Over MA ... + // -[] Trend is Bullish ... + // -[] PullBack to MA ... + // -[] Has a Bllish Rejection ... + bool hasBullishSignal = + // + pBar.IsBullish() && + pBar.low < maPrev && + pBar.GetDown() >= maPrev && + // + bar.open >= ma && + // + hasBearishPullback && + // + false + // + ; + + // + // Bearish ... + // -------------- + // -[] a Bearish Wave Which Crossed Under MA ... + // -[] Trend is Bearish ... + // -[] PullBack to MA ... + // -[] Has a Bearish Rejection ... + bool hasBearishSignal = + // + false + // pBar.IsBearish() && + // pBar.high > maPrev && + // pBar.GetUp() <= maPrev && + // // + // bar.open <= ma && + // // + // true + // + ; + + // + // Draw ... + // + + // + long chartID = mXWZPOIDrawer.ChartIdentification(); + int window = mXWZPOIDrawer.SubWindowIdentification(); + + // // + // if (isMACrossedOverBullishOB) + // { + // // + // string name = + // "Bullish_" + + // ToMD5(ToFormatString(pBar.time)); + + // // + // CChartObjectVLine *iLine; + // iLine = new CChartObjectVLine(); + // bool isCreated = iLine.Create( + // chartID, + // name, + // window, + // pBar.time // + // ); + // if (isCreated) + // { + // // + // iLine.Color(clrAqua); + + // // + // mXWZDrawnObjects.Add(iLine); + // } + // } + + // // + // if (isMACrossedUnderBearishOB) + // { + // // + // string name = + // "Bearish_" + + // ToMD5(ToFormatString(pBar.time)); + + // // + // CChartObjectVLine *iLine; + // iLine = new CChartObjectVLine(); + // bool isCreated = iLine.Create( + // chartID, + // name, + // window, + // pBar.time // + // ); + // if (isCreated) + // { + // // + // iLine.Color(clrMagenta); + + // // + // mXWZDrawnObjects.Add(iLine); + // } + // } + + // + bool hasSignal = + (hasBullishSignal || + hasBearishSignal); + if (hasSignal) + { + // + long chartID = mXWZPOIDrawer.ChartIdentification(); + int window = mXWZPOIDrawer.SubWindowIdentification(); + string name = + (hasBullishSignal + ? "Bullish_" + : "Bearish_") + + "Signal_" + ToMD5(ToFormatString(bar.time)); + color signalColor = + hasBullishSignal + ? clrYellow + : clrOrange; + + // + CChartObjectVLine *iSignal; + iSignal = new CChartObjectVLine(); + bool isCreated = iSignal.Create( + chartID, + name, + window, + bar.time // + ); + if (isCreated) + { + // + iSignal.Color(signalColor); + + // + mXWZDrawnObjects.Add(iSignal); + } + + // + bool drawRR = false; + if (drawRR) + { + // + XRR iSigRR; + ENUM_X_POSITION_TYPES type = + hasBullishSignal + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + double sl = hasBullishSignal + ? longSLBuffer[barIndex] + : shortSLBuffer[barIndex]; + + // + isCreated = iSigRR.Init( + _Symbol, + _Period, + sl, + bar.open, + type, + ShortName // + ); + if (!isCreated) + { + return; + } + + // + iSigRR.time = pBar.NextAt(); + + // + XCRRObject *iObj; + isCreated = mXWZPOIDrawer.CreateRR( + iSigRR, + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + + // + iSigRR.Clean(); + } + } + + // + bar.Clean(); + pBar.Clean(); +} + +// +// POIS Functions ... + +// +void ConfigurePOIDrawer() +{ + // + if (mXWZPOIDrawer == NULL) + { + return; + } + + // + mXWZPOIDrawer.Prefix(ShortName); + mXWZPOIDrawer.ChartIdentification(ChartID()); + mXWZPOIDrawer.SubWindowIdentification(0); + + // + mXWZPOIDrawer.BullishFVGWidth(1); + mXWZPOIDrawer.BullishFVGStyle(STYLE_DOT); + mXWZPOIDrawer.BullishFVGColor(clrAqua); + + // + mXWZPOIDrawer.BearishFVGWidth(1); + mXWZPOIDrawer.BearishFVGStyle(STYLE_DOT); + mXWZPOIDrawer.BearishFVGColor(clrMagenta); + + // + mXWZPOIDrawer.SupportZoneWidth(1); + mXWZPOIDrawer.SupportZoneStyle(STYLE_DASHDOTDOT); + mXWZPOIDrawer.SupportZoneColor(clrLime); + + // + mXWZPOIDrawer.ResistanceZoneWidth(1); + mXWZPOIDrawer.ResistanceZoneStyle(STYLE_DASHDOTDOT); + mXWZPOIDrawer.ResistanceZoneColor(clrRed); + + // + mXWZPOIDrawer.BullishOrderBlockWidth(4); + mXWZPOIDrawer.BullishOrderBlockStyle(STYLE_DASH); + mXWZPOIDrawer.BullishOrderBlockColor(clrAqua); + + // + mXWZPOIDrawer.BearishOrderBlockWidth(4); + mXWZPOIDrawer.BearishOrderBlockStyle(STYLE_DASH); + mXWZPOIDrawer.BearishOrderBlockColor(clrMagenta); +} + +// +void CalculatedPOIs( + int bar_index, // Selected Bar Index + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + XOHCL iBar; + bool isInited = iBar.Init( + _Symbol, + _Period, + bar_index // + ); + if (!isInited) + { + // + iBar.Clean(); + return; + } + + // + XOHCL pBar; + isInited = iBar.GetPreviousBar(pBar); + if (!isInited) + { + // + iBar.Clean(); + pBar.Clean(); + return; + } + + // + // POI ... + DetectPOIs(iBar); + UpdatePOIs(iBar); + DrawPOIs(); + + // + iBar.Clean(); + pBar.Clean(); +} + +// +bool CanDetectPOIs() +{ + // + bool result = false; + + // + result = + // + mXWZDetectOrderBlocks || + mXWZDetectFairValueGaps || + mXWZDetectSupportZones || + mXWZDetectResistanceZones + // + ; + + // + return result; +} + +// +void DetectPOIs( + XOHCL &bar // +) +{ + // + if (!CanDetectPOIs()) + { + return; + } + + // + int idx = -1; + int range = 21; + + // + // Detect Order Block ... + + // + if (mXWZDetectOrderBlocks) + { + // + XOHCL obBar; + XCOrderBlock *ob; + ENUM_X_DIRECTION obDir; + bool hasOB = mXWZBarAnalyser.HasOrderBlock( + bar, + obBar, + obDir // + ); + bool hasBullishOB = + hasOB && + IsBullish(obDir); + bool hasBearishOB = + hasOB && + IsBearish(obDir); + if (hasOB) + { + // + ob = new XCOrderBlock(); + bool isInited = ob.Init(obBar, obDir); + if (isInited) + { + // + ENUM_X_DIRECTION iForDir = ob.GetDirection(); + bool isBullish = IsBullish(iForDir); + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = ob.IsActivated( + iForDir, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + idx = FindIndex( + ob, + mXWZUnActivatedOBs // + ); + if (!IsValidIndex(idx)) + { + // + if (isBullish) + { + lastBullOB = ob; + } + else + { + lastBearOB = ob; + } + + // + Add( + ob, + mXWZUnActivatedOBs // + ); + } + } + else + { + // + idx = FindIndex( + ob, + mXWZActivatedOBs // + ); + if (!IsValidIndex(idx)) + { + // + ob.To(activationBar.time); + + // + Add( + ob, + mXWZActivatedOBs // + ); + } + } + + // + activationBar.Clean(); + } + } + + // + obBar.Clean(); + } + + // + // Detect Fair Value Gap ... + + // + if (mXWZDetectFairValueGaps) + { + // + XOHCL fvgStartBar; + XOHCL fvgEndBar; + XCFVG *fvg; + ENUM_X_DIRECTION fvgDir; + bool hasFVG = mXWZBarAnalyser.HasFairValueGap( + bar, + fvgStartBar, + fvgEndBar, + fvgDir // + ); + bool hasBullishFVG = + hasFVG && + IsBullish(fvgDir); + bool hasBearishFVG = + hasFVG && + IsBearish(fvgDir); + if (hasFVG) + { + // + fvg = new XCFVG(); + bool isInited = fvg.Init( + fvgStartBar, + fvgEndBar, + fvgDir // + ); + if (isInited) + { + // + ENUM_X_DIRECTION iForDir = fvg.GetDirection(); + bool isBullish = IsBullish(iForDir); + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = fvg.IsActivated( + iForDir, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + idx = FindIndex( + fvg, + mXWZUnActivatedFVGs // + ); + if (!IsValidIndex(idx)) + { + // + if (isBullish) + { + lastBullFVG = fvg; + } + else + { + lastBearFVG = fvg; + } + + // + Add( + fvg, + mXWZUnActivatedFVGs // + ); + } + } + else + { + // + idx = FindIndex( + fvg, + mXWZActivatedFVGs // + ); + if (!IsValidIndex(idx)) + { + // + fvg.To(activationBar.time); + + // + Add( + fvg, + mXWZActivatedFVGs // + ); + } + } + + // + activationBar.Clean(); + } + } + + // + fvgEndBar.Clean(); + fvgStartBar.Clean(); + } + + // + // Detect Support Zone ... + + // + if (mXWZDetectSupportZones) + { + // + XOHCL supportBar; + XCSupportZone *supportZone; + bool hasSupport = mXWZBarAnalyser + .HasSupport( + bar, + supportBar, + range // + ); + if (hasSupport) + { + // + supportZone = new XCSupportZone(); + hasSupport = supportZone.Init( + supportBar, + range, + true // Use Range As Start ... + ); + + // + if (hasSupport) + { + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = supportZone.IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + idx = FindIndex( + supportZone, + mXWZUnActivatedSupportZones // + ); + hasSupport = !IsValidIndex(idx); + if (hasSupport) + { + // + lastSupport = supportZone; + + // + Add( + supportZone, + mXWZUnActivatedSupportZones // + ); + } + } + else + { + // + idx = FindIndex( + supportZone, + mXWZActivatedSupportZones // + ); + hasSupport = !IsValidIndex(idx); + if (hasSupport) + { + // + supportZone.To(activationBar.time); + + // + Add( + supportZone, + mXWZActivatedSupportZones // + ); + } + } + + // + activationBar.Clean(); + } + } + + // + supportBar.Clean(); + } + + // + // Detect Resistance Zone ... + + // + if (mXWZDetectResistanceZones) + { + // + XOHCL resistaneBar; + XCResistanceZone *resistanceZone; + bool hasResistance = mXWZBarAnalyser + .HasResistance( + bar, + resistaneBar, + range // + ); + if (hasResistance) + { + // + resistanceZone = new XCResistanceZone(); + hasResistance = resistanceZone.Init( + resistaneBar, + range, + true // Use Range As Start ... + ); + + // + if (hasResistance) + { + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = resistanceZone.IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + idx = FindIndex( + resistanceZone, + mXWZUnActivatedResistanceZones // + ); + hasResistance = !IsValidIndex(idx); + if (hasResistance) + { + // + lastResistance = resistanceZone; + + // + Add( + resistanceZone, + mXWZUnActivatedResistanceZones // + ); + } + } + else + { + // + idx = FindIndex( + resistanceZone, + mXWZActivatedResistanceZones // + ); + hasResistance = !IsValidIndex(idx); + if (hasResistance) + { + // + resistanceZone.To(activationBar.time); + + // + Add( + resistanceZone, + mXWZActivatedResistanceZones // + ); + } + } + + // + activationBar.Clean(); + } + } + + // + resistaneBar.Clean(); + } + + // +} + +// +void UpdatePOIs( + XOHCL &bar // +) +{ + // + int count = -1; + bool has = false; + bool resetDraws = false; + + // + if (!bar.IsValid()) + { + return; + } + + // + datetime to = bar.time; + + // + // Order Blocks ... + + // + count = ArraySize(mXWZUnActivatedOBs); + has = IsValidSize(count); + if (has) + { + // + XCOrderBlock *tmps[]; + for (int i = 0; i < count; i++) + { + // + // Update To ... + mXWZUnActivatedOBs[i].To(to); + + // + // Check Activation ... + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = mXWZUnActivatedOBs[i] + .IsActivated( + mXWZUnActivatedOBs[i].GetDirection(), + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + activationBar.Clean(); + + // + if (!isActivated) + { + // + Add( + mXWZUnActivatedOBs[i], + tmps // + ); + } + else + { + // + Add( + mXWZUnActivatedOBs[i], + mXWZActivatedOBs // + ); + } + } + + // + Copy( + tmps, + mXWZUnActivatedOBs // + ); + } + + // + count = ArraySize(mXWZActivatedOBs); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iZone = mXWZActivatedOBs[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + ENUM_X_DIRECTION iForDir = iZone.GetDirection(); + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedOBs, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + + // + // Fair Value Gaps ... + + // + count = ArraySize(mXWZUnActivatedFVGs); + has = IsValidSize(count); + if (has) + { + // + XCFVG *tmps[]; + for (int i = 0; i < count; i++) + { + // + // Update To ... + mXWZUnActivatedFVGs[i].To(to); + + // + // Check Activation ... + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = mXWZUnActivatedFVGs[i] + .IsActivated( + mXWZUnActivatedFVGs[i].GetDirection(), + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + activationBar.Clean(); + + // + if (!isActivated) + { + // + Add( + mXWZUnActivatedFVGs[i], + tmps // + ); + } + else + { + // + Add( + mXWZUnActivatedFVGs[i], + mXWZActivatedFVGs // + ); + } + } + + // + Copy( + tmps, + mXWZUnActivatedFVGs // + ); + } + + // + count = ArraySize(mXWZActivatedFVGs); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + for (int i = 0; i < count; i++) + { + // + XCFVG *iZone = mXWZActivatedFVGs[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + ENUM_X_DIRECTION iForDir = iZone.GetDirection(); + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedFVGs, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + + // + // Support Zones ... + + // + count = ArraySize(mXWZUnActivatedSupportZones); + has = IsValidSize(count); + if (has) + { + // + XCSupportZone *tmps[]; + for (int i = 0; i < count; i++) + { + // + // Update To ... + mXWZUnActivatedSupportZones[i].To(to); + + // + // Check Activation ... + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = mXWZUnActivatedSupportZones[i] + .IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + Add( + mXWZUnActivatedSupportZones[i], + tmps // + ); + } + else + { + // + mXWZUnActivatedSupportZones[i].To(activationBar.time); + + // + Add( + mXWZUnActivatedSupportZones[i], + mXWZActivatedSupportZones // + ); + } + + // + activationBar.Clean(); + } + + // + Copy( + tmps, + mXWZUnActivatedSupportZones // + ); + } + + // + count = ArraySize(mXWZActivatedSupportZones); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + ENUM_X_DIRECTION iForDir = X_DIRECTION_BULLISH; + for (int i = 0; i < count; i++) + { + // + XCSupportZone *iZone = mXWZActivatedSupportZones[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedSupportZones, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + + // + // Resistance Zones ... + + // + count = ArraySize(mXWZUnActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + XCResistanceZone *tmps[]; + for (int i = 0; i < count; i++) + { + // + // Update To ... + mXWZUnActivatedResistanceZones[i].To(to); + + // + // Check Activation ... + + // + // Check OB Not Activated ... + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = mXWZUnActivatedResistanceZones[i] + .IsActivated( + X_DIRECTION_BULLISH, + activationBar, + isActivationBarBodyIn, + false, + _Period // + ); + + // + if (!isActivated) + { + // + Add( + mXWZUnActivatedResistanceZones[i], + tmps // + ); + } + else + { + // + mXWZUnActivatedResistanceZones[i].To(activationBar.time); + + // + Add( + mXWZUnActivatedResistanceZones[i], + mXWZActivatedResistanceZones // + ); + } + + // + activationBar.Clean(); + } + + // + Copy( + tmps, + mXWZUnActivatedResistanceZones // + ); + } + + // + count = ArraySize(mXWZActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + // Remove UnWorks / Breaked Zones ... + int removeIDX[]; + ENUM_X_DIRECTION iForDir = X_DIRECTION_BEARISH; + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *iZone = mXWZActivatedResistanceZones[i]; + + // + XOHCL passedBar; + bool isBodyOut = false; + + // + // Check Breake ... + bool isBreaked = iZone.IsBreaked( + iForDir, + passedBar, + isBodyOut, + true, + false, + _Period // + ); + if (isBreaked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + // Check Works ... + bool isWorked = iZone.IsWorked( + iForDir, + passedBar, + isBodyOut, + true, + false, + false, + _Period // + ); + if (!isWorked) + { + // + Add( + i, + removeIDX // + ); + + // + passedBar.Clean(); + break; + } + + // + passedBar.Clean(); + } + + // + if (HasChild(removeIDX)) + { + // + resetDraws = true; + + // + count = ArraySize(removeIDX); + for (int i = 0; i < count; i++) + { + // + ArrayRemove( + mXWZActivatedResistanceZones, + removeIDX[i], + 1 // + ); + } + } + + // + Clean(removeIDX); + } + + // + // + // + + // + // Clean Draws if has to ... + if (resetDraws) + { + mXWZDrawnObjects.Clear(); + } + + // +} + +// +void DrawPOIs() +{ + // + int count = 0; + bool has = false; + bool isCreated = false; + + // + if (!showPOIs) + { + return; + } + + // + // Order Blocks ... + if (showOrderBlocks) + { + // + bool showBullishOrderBlocks = true; + bool showBearishOrderBlocks = true; + + // + // UnActivated ... + count = ArraySize(mXWZUnActivatedOBs); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + bool isBullish = mXWZUnActivatedOBs[i].IsBullish(); + + // + if ((isBullish && + showBullishOrderBlocks) || + (!isBullish && + showBearishOrderBlocks)) + { + // + XCBaseObject *iObj; + isCreated = mXWZPOIDrawer + .CreateOrderBlock( + mXWZUnActivatedOBs[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + } + + // + // Activated ... + count = ArraySize(mXWZActivatedOBs); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iOB = mXWZActivatedOBs[i]; + + // + bool isBullish = iOB.IsBullish(); + + // + if (showActivatedPOIs && + ((isBullish && + showBullishOrderBlocks) || + (!isBullish && + showBearishOrderBlocks))) + { + // + XCBaseObject *iObj; + isCreated = mXWZPOIDrawer + .CreateOrderBlock( + iOB, + iObj // + ); + if (isCreated) + { + // + // if (isBullish) + // { + // ((XCBullishOrderBlockObject *)iObj).ZoneFill(true); + // } + // else + // { + // ((XCBearishOrderBlockObject *)iObj).ZoneFill(true); + // } + + // + mXWZDrawnObjects.Add(iObj); + } + } + } + } + } + + // + // Fair Value Gaps ... + if (showFairValueGaps) + { + // + bool showBullishFairValueGaps = true; + bool showBearishFairValueGaps = true; + + // + // UnActivated ... + count = ArraySize(mXWZUnActivatedFVGs); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + bool isBullish = mXWZUnActivatedFVGs[i].IsBullish(); + + // + if ((isBullish && + showBullishFairValueGaps) || + (!isBullish && + showBearishFairValueGaps)) + { + // + XCBaseObject *iObj; + isCreated = mXWZPOIDrawer + .CreateFairValueGap( + mXWZUnActivatedFVGs[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + } + + // + // Activated ... + count = ArraySize(mXWZActivatedFVGs); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCFVG *iFVG = mXWZActivatedFVGs[i]; + + // + bool isBullish = iFVG.IsBullish(); + + // + if (showActivatedPOIs && + ((isBullish && + showBullishFairValueGaps) || + (!isBullish && + showBearishFairValueGaps))) + { + XCBaseObject *iObj; + isCreated = mXWZPOIDrawer + .CreateFairValueGap( + iFVG, + iObj // + ); + if (isCreated) + { + // + // if (isBullish) + // { + // ((XCBullishOrderBlockObject *)iObj).ZoneFill(true); + // } + // else + // { + // ((XCBearishOrderBlockObject *)iObj).ZoneFill(true); + // } + + // + mXWZDrawnObjects.Add(iObj); + } + } + } + } + } + + // + // Support Zones ... + if (showSupportZones) + { + // + // UnActivated ... + count = ArraySize(mXWZUnActivatedSupportZones); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupportZoneObject *iObj; + isCreated = mXWZPOIDrawer + .CreateSupportZone( + mXWZUnActivatedSupportZones[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + + // + // Activated ... + if (showActivatedPOIs) + { + // + count = ArraySize(mXWZActivatedSupportZones); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupportZoneObject *iObj; + isCreated = mXWZPOIDrawer + .CreateSupportZone( + mXWZActivatedSupportZones[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + } + } + + // + // Resistance Zones ... + if (showResistanceZones) + { + // + // UnActivated ... + count = ArraySize(mXWZUnActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = mXWZPOIDrawer + .CreateResistanceZone( + mXWZUnActivatedResistanceZones[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + + // + // Activated ... + if (showActivatedPOIs) + { + // + count = ArraySize(mXWZActivatedResistanceZones); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = mXWZPOIDrawer + .CreateResistanceZone( + mXWZActivatedResistanceZones[i], + iObj // + ); + if (isCreated) + { + mXWZDrawnObjects.Add(iObj); + } + } + } + } + } + + // +} + +// \ No newline at end of file diff --git a/Experts/Test.mq5 b/Experts/Test.mq5 new file mode 100644 index 00000000..bc4ba882 --- /dev/null +++ b/Experts/Test.mq5 @@ -0,0 +1,208 @@ +//+------------------------------------------------------------------+ +//| Test.mq5 | +//| Copyright 2025, MetaQuotes Ltd. | +//| https://www.mql5.com | +//+------------------------------------------------------------------+ +#property copyright "Copyright 2025, MetaQuotes Ltd." +#property link "https://www.mql5.com" +#property version "1.00" + +// +#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" +#include "../Classes/x-saherelm.x-poi.class.mq5" +#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" + +// +XCPOIDrawer *mPOIDrawer; +XCPOIDetector *mPOIDetector; +XCBarAnalyser *mBarAnalyser; + +// +XBarTracker mBarTracker; + +//+------------------------------------------------------------------+ +//| Expert initialization function | +//+------------------------------------------------------------------+ +int OnInit() +{ + //--- + mPOIDetector = new XCPOIDetector( + _Symbol, + _Period // + ); + // mPOIDetector.Init(); + + //--- + mPOIDrawer = new XCPOIDrawer(); + + //--- + mBarAnalyser = new XCBarAnalyser(); + + //--- + mBarTracker.Init( + _Symbol, + _Period // + ); + + //--- + return (INIT_SUCCEEDED); +} +//+------------------------------------------------------------------+ +//| Expert deinitialization function | +//+------------------------------------------------------------------+ +void OnDeinit(const int reason) +{ + //--- + ZeroMemory(mPOIDrawer); + ZeroMemory(mBarAnalyser); + ZeroMemory(mPOIDetector); +} +//+------------------------------------------------------------------+ +//| Expert tick function | +//+------------------------------------------------------------------+ +void OnTick() +{ + + // + bool isNewBar = mBarTracker.IsNewBar(); + if (!isNewBar) + { + return; + } + + // + ENUM_XPOI_EVENTS mPOIEvents[]; + mPOIDetector.Update(mPOIEvents); + + // + XPOIState mPOIState; + mPOIDetector.GetState(mPOIState); + + // + bool has = mPOIState.HasFairValueGaps(); + if (has) + { + // + int count = mPOIState.CountFairValueGaps(); + for (int i = 0; i < count; i++) + { + // + mPOIState.fairValueGaps[i].To(TimeCurrent()); + + // + XCBaseObject *iObj; + bool isCreated = mPOIDrawer.CreateFairValueGap( + mPOIState.fairValueGaps[i], + iObj // + ); + } + + // + Print("Salam"); + } + + // + return; + + // + XOHCL bar; + bool isInited = bar.Init( + _Symbol, + _Period, + 0 // + ); + if (!isInited) + { + return; + } + + // + int index = 0; + ENUM_X_DIRECTION sameBarDir; + bool hasSameBars = mBarAnalyser.HasSameBars( + bar, + sameBarDir, + index, + 3 // + ); + if (hasSameBars) + { + } + + // + // Detect Fair Value Gap ... + XOHCL fvgEndBar; + XOHCL fvgStartBar; + ENUM_X_DIRECTION fvgDir; + bool hasFVG = mBarAnalyser.HasFairValueGap( + bar, + fvgStartBar, + fvgEndBar, + fvgDir, + 3 // + ); + if (hasFVG) + { + // + XCFVG *fvg; + fvg = new XCFVG(); + bool isInit = fvg.Init( + fvgStartBar, + fvgEndBar, + fvgDir // + ); + // if (isInit) + // { + // // + // XCBaseObject *iObj; + // bool isCreated = mPOIDrawer.CreateFairValueGap( + // fvg, + // iObj // + // ); + // + // // + // if (isCreated) + // { + // } + // } + } + + // + XOHCL obBar; + ENUM_X_DIRECTION obDir; + bool hasOB = mBarAnalyser.HasOrderBlock( + bar, + obBar, + obDir, + 3 // + ); + if (hasOB) + { + // + XCOrderBlock *ob; + ob = new XCOrderBlock(); + bool isInit = ob.Init( + obBar, + obDir // + ); + if (isInit) + { + // // + // XCBaseObject *iObj; + // bool isCreated = mPOIDrawer.CreateOrderBlock( + // ob, + // iObj // + // ); + + // // + // if (isCreated) + // { + // Print("Order Block ..."); + // } + // } + } + + // + } +} +//+------------------------------------------------------------------+ diff --git a/Indicators/x-saherelm.x121.xwz.mq5 b/Indicators/x-saherelm.x121.xwz.mq5 index 8828b358..44bec6c9 100644 --- a/Indicators/x-saherelm.x121.xwz.mq5 +++ b/Indicators/x-saherelm.x121.xwz.mq5 @@ -12,7 +12,7 @@ // ////////////////////////////////////////////////////// // -// Global Properties ... +// Glzoneal Properties ... #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" @@ -29,6 +29,7 @@ // Includes Common Library ... #include "../Classes/x-saherelm.x-alert.class.mq5" #include "../Classes/x-saherelm.x-bar.analyser.class.mq5" +#include "../Classes/x-saherelm.x-poi.class.mq5" #include "../Classes/x-saherelm.x-poi.drawer.class.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" #include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" @@ -84,12 +85,11 @@ input bool showRejection = true; // Show Rejection Bars // input group "POI Presentation"; -input bool showPOIs = false; // Show POI(s) -input bool showActivatedPOIs = true; // Show Activated POI(s) -input bool showOrderBlocks = true; // Show Order Blocks -input bool showFairValueGaps = true; // Show Fair Value Gaps -input bool showSupportZones = false; // Show Support Zones -input bool showResistanceZones = false; // Show Resistance Zones +input bool showPOIs = true; // Show POI(s) +input bool showOrderBlocks = true; // Show Order Blocks +input bool showFairValueGaps = true; // Show Fair Value Gaps +input bool showSupplyZones = true; // Show Supply Zones +input bool showDemandZones = true; // Show Demand Zones // input group "Presentation Config"; @@ -308,52 +308,45 @@ int adxHandler = INVALID_HANDLE; // XCAlert *mXWZAlert; +XBarTracker mXWZBarTracker; CArrayObj mXWZDrawnObjects; XCPOIDrawer *mXWZPOIDrawer; XCBarAnalyser *mXWZBarAnalyser; -// -datetime lastBullishTrend = NULL; -datetime lastBearishTrend = NULL; - -// -datetime lastCrossedOverMA = NULL; -datetime lastCrossedUnderMA = NULL; - // // POI(s) ... // bool mXWZDetectOrderBlocks = true; -bool mXWZDetectFairValueGaps = false; -bool mXWZDetectSupportZones = false; -bool mXWZDetectResistanceZones = false; +bool mXWZDetectFairValueGaps = true; +bool mXWZDetectSupplyZones = true; +bool mXWZDetectDemandZones = true; // -bool filterPOIsUsingMa = false; // Filter POI(s) Using MA -bool filterPOIsUsingZones = false; // Filter POI(s) Using Zones +bool mXWZIgnoreUnActivateds = true; // -XCFVG *lastBullFVG; -XCFVG *lastBearFVG; -XCOrderBlock *lastBullOB; -XCOrderBlock *lastBearOB; -XCSupportZone *lastSupport; -XCResistanceZone *lastResistance; +bool mXWZForceStarteds = true; +bool mXWZForceUnBreaked = true; +bool mXWZForceActivation = true; + +// +int mXWZSuResRange = 21; +int mXWZOBFVGSameBars = 3; // // Un Activated POI(s) ... XCFVG *mXWZUnActivatedFVGs[]; XCOrderBlock *mXWZUnActivatedOBs[]; -XCSupportZone *mXWZUnActivatedSupportZones[]; -XCResistanceZone *mXWZUnActivatedResistanceZones[]; +XCSupplyZone *mXWZUnActivatedSupplyZones[]; +XCDemandZone *mXWZUnActivatedDemandZones[]; // // Activated POI(s) ... XCFVG *mXWZActivatedFVGs[]; XCOrderBlock *mXWZActivatedOBs[]; -XCSupportZone *mXWZActivatedSupportZones[]; -XCResistanceZone *mXWZActivatedResistanceZones[]; +XCSupplyZone *mXWZActivatedSupplyZones[]; +XCDemandZone *mXWZActivatedDemandZones[]; // // Event Handlers ... @@ -436,6 +429,13 @@ int OnInit() SetIndicatorName(); IndicatorSetInteger(INDICATOR_DIGITS, 2); + // + // Initialize Bar Tracker ... + mXWZBarTracker.Init( + _Symbol, + _Period // + ); + // mXWZPOIDrawer = new XCPOIDrawer(); ConfigurePOIDrawer(); @@ -487,14 +487,14 @@ void OnDeinit(const int reason) // Clean(mXWZActivatedOBs); Clean(mXWZActivatedFVGs); - Clean(mXWZActivatedSupportZones); - Clean(mXWZActivatedResistanceZones); + Clean(mXWZActivatedSupplyZones); + Clean(mXWZActivatedDemandZones); // Clean(mXWZUnActivatedOBs); Clean(mXWZUnActivatedFVGs); - Clean(mXWZUnActivatedSupportZones); - Clean(mXWZUnActivatedResistanceZones); + Clean(mXWZUnActivatedSupplyZones); + Clean(mXWZUnActivatedDemandZones); } /** @@ -1148,53 +1148,6 @@ void CalculateValues( // ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - // - bool hasLastBullOB = lastBullOB != NULL && - lastBullOB.IsValid(); - bool hasLastBearOB = lastBearOB != NULL && - lastBearOB.IsValid(); - - // - bool hasLastBullFVG = lastBullFVG != NULL && - lastBullFVG.IsValid(); - bool hasLastBearFVG = lastBearFVG != NULL && - lastBearFVG.IsValid(); - - // - bool hasLastSupport = lastSupport != NULL && - lastSupport.IsValid(); - - // - bool hasLastResistance = lastResistance != NULL && - lastResistance.IsValid(); - - // - // Calculate Crossing Over / Under Ma ... - bool isCrossedOverMA = - // - iBar.low > iMa && - (pBar.low <= iMaPrev && - (pBar.GetUp() <= iMaPrev || - pBar.GetDown() <= iMaPrev)) - // - ; - bool isCrossedUnderMA = - // - iBar.high < iMa && - (pBar.high >= iMaPrev && - (pBar.GetUp() >= iMaPrev || - pBar.GetDown() >= iMaPrev)) - // - ; - lastCrossedOverMA = - isCrossedOverMA - ? iBar.time - : lastCrossedOverMA; - lastCrossedUnderMA = - isCrossedUnderMA - ? iBar.time - : lastCrossedUnderMA; - // // SL Buffers ... @@ -1232,14 +1185,10 @@ void CalculateValues( double downTrendValue = 0; if (isUpTrend) { - // - lastBullishTrend = iBar.time; upTrendValue = iBar.low; } if (isDownTrend) { - // - lastBearishTrend = iBar.time; downTrendValue = iBar.high; } @@ -1277,25 +1226,7 @@ void CalculateValues( double selectedValue = iBar.low; // - iBullMomentumValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullMomentumValue = - !filterPOIsUsingMa - ? iBullMomentumValue - : iBullMomentumValue < iMa - ? iBullMomentumValue - : 0; + iBullMomentumValue = selectedValue; } // @@ -1305,25 +1236,7 @@ void CalculateValues( double selectedValue = iBar.high; // - iBearMomentumValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearMomentumValue = - !filterPOIsUsingMa - ? iBearMomentumValue - : iBearMomentumValue > iMa - ? iBearMomentumValue - : 0; + iBearMomentumValue = selectedValue; } // @@ -1361,25 +1274,7 @@ void CalculateValues( double selectedValue = iBar.low; // - iBullRejectionValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullRejectionValue = - !filterPOIsUsingMa - ? iBullRejectionValue - : iBullRejectionValue < iMa - ? iBullRejectionValue - : 0; + iBullRejectionValue = selectedValue; } // @@ -1389,25 +1284,7 @@ void CalculateValues( double selectedValue = iBar.high; // - iBearRejectionValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearRejectionValue = - !filterPOIsUsingMa - ? iBearRejectionValue - : iBearRejectionValue > iMa - ? iBearRejectionValue - : 0; + iBearRejectionValue = selectedValue; } // @@ -1446,25 +1323,7 @@ void CalculateValues( double selectedValue = iBar.low; // - iBullPinValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullPinValue = - !filterPOIsUsingMa - ? iBullPinValue - : iBullPinValue < iMa - ? iBullPinValue - : 0; + iBullPinValue = selectedValue; } // @@ -1474,25 +1333,7 @@ void CalculateValues( double selectedValue = iBar.high; // - iBearPinValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearPinValue = - !filterPOIsUsingMa - ? iBearPinValue - : iBearPinValue > iMa - ? iBearPinValue - : 0; + iBearPinValue = selectedValue; } // @@ -1530,25 +1371,7 @@ void CalculateValues( double selectedValue = iBar.low; // - iBullEngulfValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullEngulfValue = - !filterPOIsUsingMa - ? iBullEngulfValue - : iBullEngulfValue < iMa - ? iBullEngulfValue - : 0; + iBullEngulfValue = selectedValue; } // @@ -1558,25 +1381,7 @@ void CalculateValues( double selectedValue = iBar.high; // - iBearEngulfValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearEngulfValue = - !filterPOIsUsingMa - ? iBearEngulfValue - : iBearEngulfValue > iMa - ? iBearEngulfValue - : 0; + iBearEngulfValue = selectedValue; } // @@ -1613,25 +1418,7 @@ void CalculateValues( double selectedValue = iBar.low; // - iSwingLowValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsBelow( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iSwingLowValue = - !filterPOIsUsingMa - ? iSwingLowValue - : iSwingLowValue < iMa - ? iSwingLowValue - : 0; + iSwingLowValue = selectedValue; } // @@ -1641,25 +1428,7 @@ void CalculateValues( double selectedValue = iBar.high; // - iSwingHighValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsAbove( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iSwingHighValue = - !filterPOIsUsingMa - ? iSwingHighValue - : iSwingHighValue > iMa - ? iSwingHighValue - : 0; + iSwingHighValue = selectedValue; } // @@ -1667,22 +1436,6 @@ void CalculateValues( swingHighBuffer[bar_index] = iSwingHighValue; } - // - // - // - - // - DetectSignals( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - // // Cleanup Resources ... @@ -1691,339 +1444,6 @@ void CalculateValues( pBar.Clean(); } -// -void ConfigureAlert() -{ - // - mXWZAlert.SetPrefix(ShortName); - - // - mXWZAlert.SetPushAlerts(mXWZPushAlerts); - mXWZAlert.SetMailAlerts(mXWZMailAlerts); - mXWZAlert.SetEnableAlerts(mXWZEnableAlerts); - mXWZAlert.SetTerminalAlerts(mXWZTerminalAlerts); -} - -// -void DetectSignals( - int barIndex, - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Calculate Signals ... - - // - XOHCL bar; - XOHCL pBar; - XOHCL ppBar; - bool isInited = bar.Init( - _Symbol, - _Period, - barIndex // - ); - if (!isInited) - { - return; - } - - // - isInited = bar.GetPreviousBar(pBar); - if (!isInited) - { - return; - } - - // - isInited = pBar.GetPreviousBar(ppBar); - if (!isInited) - { - return; - } - - // - int pIDX = pBar.Index(); - int ppIDX = ppBar.Index(); - - // - // Reading Buffers ... - - // - double ma = maBuffer[barIndex]; - double maPrev = maBuffer[pIDX]; - double maPPrev = maBuffer[ppIDX]; - - // - // Pin Bar ... - bool isBullisPinned = bullishPinBuffer[pIDX] > 0; - bool isBearisPinned = bearishPinBuffer[pIDX] > 0; - - // - // Engulf Bar ... - bool isBullisEngulfed = bullishEngulfBuffer[pIDX] > 0; - bool isBearisEngulfed = bearishEngulfBuffer[pIDX] > 0; - - // - // Rejection Bar ... - bool isBullishRejected = bullishRejectionBuffer[pIDX] > 0; - bool isBearishRejected = bearishRejectionBuffer[pIDX] > 0; - - // - // Momentum Bar ... - bool isBullishMomentum = bullishMomentumBuffer[pIDX] > 0; - bool isBearishMomentum = bearishMomentumBuffer[pIDX] > 0; - - // - // Checking Pullback ... - ENUM_X_DIRECTION pullbackDir; - bool hasPullback = mXWZBarAnalyser.HasPullBack( - pullbackDir, - bar // - ); - bool hasBullishPullback = - hasPullback && - IsBullish(pullbackDir); - bool hasBearishPullback = - hasPullback && - IsBearish(pullbackDir); - - // - // Order Block Parsing ... - - // // - // bool isMACrossedOverBullishOB = - // // - // lastBullOB != NULL && - // lastBullOB.IsValid() && - // // - // IsInside( - // maPPrev, - // lastBullOB // - // ) && - // // - // IsAbove( - // maPrev, - // lastBullOB // - // ) - // // - // ; - - // // - // bool isMACrossedUnderBearishOB = - // // - // lastBearOB != NULL && - // lastBearOB.IsValid() && - // // - // IsInside( - // maPPrev, - // lastBearOB // - // ) && - // // - // IsBelow( - // maPrev, - // lastBearOB // - // ) - // // - // ; - - // - // Bullish ... - // -------------- - // -[] a Bullish Wave Which Crossed Over MA ... - // -[] Trend is Bullish ... - // -[] PullBack to MA ... - // -[] Has a Bllish Rejection ... - bool hasBullishSignal = - // - pBar.IsBullish() && - pBar.low < maPrev && - pBar.GetDown() >= maPrev && - // - bar.open >= ma && - // - hasBearishPullback && - // - false - // - ; - - // - // Bearish ... - // -------------- - // -[] a Bearish Wave Which Crossed Under MA ... - // -[] Trend is Bearish ... - // -[] PullBack to MA ... - // -[] Has a Bearish Rejection ... - bool hasBearishSignal = - // - false - // pBar.IsBearish() && - // pBar.high > maPrev && - // pBar.GetUp() <= maPrev && - // // - // bar.open <= ma && - // // - // true - // - ; - - // - // Draw ... - // - - // - long chartID = mXWZPOIDrawer.ChartIdentification(); - int window = mXWZPOIDrawer.SubWindowIdentification(); - - // // - // if (isMACrossedOverBullishOB) - // { - // // - // string name = - // "Bullish_" + - // ToMD5(ToFormatString(pBar.time)); - - // // - // CChartObjectVLine *iLine; - // iLine = new CChartObjectVLine(); - // bool isCreated = iLine.Create( - // chartID, - // name, - // window, - // pBar.time // - // ); - // if (isCreated) - // { - // // - // iLine.Color(clrAqua); - - // // - // mXWZDrawnObjects.Add(iLine); - // } - // } - - // // - // if (isMACrossedUnderBearishOB) - // { - // // - // string name = - // "Bearish_" + - // ToMD5(ToFormatString(pBar.time)); - - // // - // CChartObjectVLine *iLine; - // iLine = new CChartObjectVLine(); - // bool isCreated = iLine.Create( - // chartID, - // name, - // window, - // pBar.time // - // ); - // if (isCreated) - // { - // // - // iLine.Color(clrMagenta); - - // // - // mXWZDrawnObjects.Add(iLine); - // } - // } - - // - bool hasSignal = - (hasBullishSignal || - hasBearishSignal); - if (hasSignal) - { - // - long chartID = mXWZPOIDrawer.ChartIdentification(); - int window = mXWZPOIDrawer.SubWindowIdentification(); - string name = - (hasBullishSignal - ? "Bullish_" - : "Bearish_") + - "Signal_" + ToMD5(ToFormatString(bar.time)); - color signalColor = - hasBullishSignal - ? clrYellow - : clrOrange; - - // - CChartObjectVLine *iSignal; - iSignal = new CChartObjectVLine(); - bool isCreated = iSignal.Create( - chartID, - name, - window, - bar.time // - ); - if (isCreated) - { - // - iSignal.Color(signalColor); - - // - mXWZDrawnObjects.Add(iSignal); - } - - // - bool drawRR = false; - if (drawRR) - { - // - XRR iSigRR; - ENUM_X_POSITION_TYPES type = - hasBullishSignal - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - double sl = hasBullishSignal - ? longSLBuffer[barIndex] - : shortSLBuffer[barIndex]; - - // - isCreated = iSigRR.Init( - _Symbol, - _Period, - sl, - bar.open, - type, - ShortName // - ); - if (!isCreated) - { - return; - } - - // - iSigRR.time = pBar.NextAt(); - - // - XCRRObject *iObj; - isCreated = mXWZPOIDrawer.CreateRR( - iSigRR, - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - - // - iSigRR.Clean(); - } - } - - // - bar.Clean(); - pBar.Clean(); -} - // // POIS Functions ... @@ -2042,12 +1462,12 @@ void ConfigurePOIDrawer() mXWZPOIDrawer.SubWindowIdentification(0); // - mXWZPOIDrawer.BullishFVGWidth(1); + mXWZPOIDrawer.BullishFVGWidth(2); mXWZPOIDrawer.BullishFVGStyle(STYLE_DOT); mXWZPOIDrawer.BullishFVGColor(clrAqua); // - mXWZPOIDrawer.BearishFVGWidth(1); + mXWZPOIDrawer.BearishFVGWidth(2); mXWZPOIDrawer.BearishFVGStyle(STYLE_DOT); mXWZPOIDrawer.BearishFVGColor(clrMagenta); @@ -2062,16 +1482,29 @@ void ConfigurePOIDrawer() mXWZPOIDrawer.ResistanceZoneColor(clrRed); // - mXWZPOIDrawer.BullishOrderBlockWidth(4); + mXWZPOIDrawer.BullishOrderBlockWidth(3); mXWZPOIDrawer.BullishOrderBlockStyle(STYLE_DASH); mXWZPOIDrawer.BullishOrderBlockColor(clrAqua); // - mXWZPOIDrawer.BearishOrderBlockWidth(4); + mXWZPOIDrawer.BearishOrderBlockWidth(3); mXWZPOIDrawer.BearishOrderBlockStyle(STYLE_DASH); mXWZPOIDrawer.BearishOrderBlockColor(clrMagenta); } +// +void ConfigureAlert() +{ + // + mXWZAlert.SetPrefix(ShortName); + + // + mXWZAlert.SetPushAlerts(mXWZPushAlerts); + mXWZAlert.SetMailAlerts(mXWZMailAlerts); + mXWZAlert.SetEnableAlerts(mXWZEnableAlerts); + mXWZAlert.SetTerminalAlerts(mXWZTerminalAlerts); +} + // void CalculatedPOIs( int bar_index, // Selected Bar Index @@ -2131,8 +1564,8 @@ bool CanDetectPOIs() // mXWZDetectOrderBlocks || mXWZDetectFairValueGaps || - mXWZDetectSupportZones || - mXWZDetectResistanceZones + mXWZDetectSupplyZones || + mXWZDetectDemandZones // ; @@ -2152,397 +1585,19 @@ void DetectPOIs( } // - int idx = -1; - int range = 21; + int barIndex = bar.Index(); // - // Detect Order Block ... - - // - if (mXWZDetectOrderBlocks) + if (barIndex <= 0) { - // - XOHCL obBar; - XCOrderBlock *ob; - ENUM_X_DIRECTION obDir; - bool hasOB = mXWZBarAnalyser.HasOrderBlock( - bar, - obBar, - obDir // - ); - bool hasBullishOB = - hasOB && - IsBullish(obDir); - bool hasBearishOB = - hasOB && - IsBearish(obDir); - if (hasOB) - { - // - ob = new XCOrderBlock(); - bool isInited = ob.Init(obBar, obDir); - if (isInited) - { - // - ENUM_X_DIRECTION iForDir = ob.GetDirection(); - bool isBullish = IsBullish(iForDir); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = ob.IsActivated( - iForDir, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - ob, - mXWZUnActivatedOBs // - ); - if (!IsValidIndex(idx)) - { - // - if (isBullish) - { - lastBullOB = ob; - } - else - { - lastBearOB = ob; - } - - // - Add( - ob, - mXWZUnActivatedOBs // - ); - } - } - else - { - // - idx = FindIndex( - ob, - mXWZActivatedOBs // - ); - if (!IsValidIndex(idx)) - { - // - ob.To(activationBar.time); - - // - Add( - ob, - mXWZActivatedOBs // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - obBar.Clean(); + return; } // - // Detect Fair Value Gap ... - - // - if (mXWZDetectFairValueGaps) - { - // - XOHCL fvgStartBar; - XOHCL fvgEndBar; - XCFVG *fvg; - ENUM_X_DIRECTION fvgDir; - bool hasFVG = mXWZBarAnalyser.HasFairValueGap( - bar, - fvgStartBar, - fvgEndBar, - fvgDir // - ); - bool hasBullishFVG = - hasFVG && - IsBullish(fvgDir); - bool hasBearishFVG = - hasFVG && - IsBearish(fvgDir); - if (hasFVG) - { - // - fvg = new XCFVG(); - bool isInited = fvg.Init( - fvgStartBar, - fvgEndBar, - fvgDir // - ); - if (isInited) - { - // - ENUM_X_DIRECTION iForDir = fvg.GetDirection(); - bool isBullish = IsBullish(iForDir); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = fvg.IsActivated( - iForDir, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - fvg, - mXWZUnActivatedFVGs // - ); - if (!IsValidIndex(idx)) - { - // - if (isBullish) - { - lastBullFVG = fvg; - } - else - { - lastBearFVG = fvg; - } - - // - Add( - fvg, - mXWZUnActivatedFVGs // - ); - } - } - else - { - // - idx = FindIndex( - fvg, - mXWZActivatedFVGs // - ); - if (!IsValidIndex(idx)) - { - // - fvg.To(activationBar.time); - - // - Add( - fvg, - mXWZActivatedFVGs // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - } - - // - // Detect Support Zone ... - - // - if (mXWZDetectSupportZones) - { - // - XOHCL supportBar; - XCSupportZone *supportZone; - bool hasSupport = mXWZBarAnalyser - .HasSupport( - bar, - supportBar, - range // - ); - if (hasSupport) - { - // - supportZone = new XCSupportZone(); - hasSupport = supportZone.Init( - supportBar, - range, - true // Use Range As Start ... - ); - - // - if (hasSupport) - { - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supportZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - supportZone, - mXWZUnActivatedSupportZones // - ); - hasSupport = !IsValidIndex(idx); - if (hasSupport) - { - // - lastSupport = supportZone; - - // - Add( - supportZone, - mXWZUnActivatedSupportZones // - ); - } - } - else - { - // - idx = FindIndex( - supportZone, - mXWZActivatedSupportZones // - ); - hasSupport = !IsValidIndex(idx); - if (hasSupport) - { - // - supportZone.To(activationBar.time); - - // - Add( - supportZone, - mXWZActivatedSupportZones // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - supportBar.Clean(); - } - - // - // Detect Resistance Zone ... - - // - if (mXWZDetectResistanceZones) - { - // - XOHCL resistaneBar; - XCResistanceZone *resistanceZone; - bool hasResistance = mXWZBarAnalyser - .HasResistance( - bar, - resistaneBar, - range // - ); - if (hasResistance) - { - // - resistanceZone = new XCResistanceZone(); - hasResistance = resistanceZone.Init( - resistaneBar, - range, - true // Use Range As Start ... - ); - - // - if (hasResistance) - { - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = resistanceZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - resistanceZone, - mXWZUnActivatedResistanceZones // - ); - hasResistance = !IsValidIndex(idx); - if (hasResistance) - { - // - lastResistance = resistanceZone; - - // - Add( - resistanceZone, - mXWZUnActivatedResistanceZones // - ); - } - } - else - { - // - idx = FindIndex( - resistanceZone, - mXWZActivatedResistanceZones // - ); - hasResistance = !IsValidIndex(idx); - if (hasResistance) - { - // - resistanceZone.To(activationBar.time); - - // - Add( - resistanceZone, - mXWZActivatedResistanceZones // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - resistaneBar.Clean(); - } + DetectOrderBlock(bar); + DetectSupplyZone(bar); + DetectDemandZone(bar); + DetectFairValueGap(bar); // } @@ -2553,580 +1608,73 @@ void UpdatePOIs( ) { // - int count = -1; + int count = 0; bool has = false; - bool resetDraws = false; // - if (!bar.IsValid()) - { - return; - } + // OrderBlock(s) ... // - datetime to = bar.time; - - // - // Order Blocks ... - - // - count = ArraySize(mXWZUnActivatedOBs); - has = IsValidSize(count); + has = HasChild(mXWZUnActivatedOBs); if (has) { // - XCOrderBlock *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedOBs[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedOBs[i] - .IsActivated( - mXWZUnActivatedOBs[i].GetDirection(), - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - activationBar.Clean(); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedOBs[i], - tmps // - ); - } - else - { - // - Add( - mXWZUnActivatedOBs[i], - mXWZActivatedOBs // - ); - } - } - - // - Copy( - tmps, - mXWZUnActivatedOBs // + SpecifiedUpdateTo( + mXWZUnActivatedOBs, + bar.time // ); } - // - count = ArraySize(mXWZActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iZone = mXWZActivatedOBs[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - ENUM_X_DIRECTION iForDir = iZone.GetDirection(); - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedOBs, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - // // Fair Value Gaps ... // - count = ArraySize(mXWZUnActivatedFVGs); - has = IsValidSize(count); + has = HasChild(mXWZUnActivatedFVGs); if (has) { // - XCFVG *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedFVGs[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedFVGs[i] - .IsActivated( - mXWZUnActivatedFVGs[i].GetDirection(), - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - activationBar.Clean(); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedFVGs[i], - tmps // - ); - } - else - { - // - Add( - mXWZUnActivatedFVGs[i], - mXWZActivatedFVGs // - ); - } - } - - // - Copy( - tmps, - mXWZUnActivatedFVGs // + SpecifiedUpdateTo( + mXWZUnActivatedFVGs, + bar.time // ); + + // + count = ArraySize(mXWZUnActivatedFVGs); } // - count = ArraySize(mXWZActivatedFVGs); - has = IsValidSize(count); + // Supply Zones ... + + // + has = HasChild(mXWZUnActivatedSupplyZones); if (has) { // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - for (int i = 0; i < count; i++) - { - // - XCFVG *iZone = mXWZActivatedFVGs[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - ENUM_X_DIRECTION iForDir = iZone.GetDirection(); - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedFVGs, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - - // - // Support Zones ... - - // - count = ArraySize(mXWZUnActivatedSupportZones); - has = IsValidSize(count); - if (has) - { - // - XCSupportZone *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedSupportZones[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedSupportZones[i] - .IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedSupportZones[i], - tmps // - ); - } - else - { - // - mXWZUnActivatedSupportZones[i].To(activationBar.time); - - // - Add( - mXWZUnActivatedSupportZones[i], - mXWZActivatedSupportZones // - ); - } - - // - activationBar.Clean(); - } - - // - Copy( - tmps, - mXWZUnActivatedSupportZones // + SpecifiedUpdateTo( + mXWZUnActivatedSupplyZones, + bar.time // ); + + // + count = ArraySize(mXWZUnActivatedSupplyZones); } // - count = ArraySize(mXWZActivatedSupportZones); - has = IsValidSize(count); + // Demand Zones ... + + // + has = HasChild(mXWZUnActivatedDemandZones); if (has) { // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - ENUM_X_DIRECTION iForDir = X_DIRECTION_BULLISH; - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = mXWZActivatedSupportZones[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedSupportZones, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - - // - // Resistance Zones ... - - // - count = ArraySize(mXWZUnActivatedResistanceZones); - has = IsValidSize(count); - if (has) - { - // - XCResistanceZone *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedResistanceZones[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedResistanceZones[i] - .IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedResistanceZones[i], - tmps // - ); - } - else - { - // - mXWZUnActivatedResistanceZones[i].To(activationBar.time); - - // - Add( - mXWZUnActivatedResistanceZones[i], - mXWZActivatedResistanceZones // - ); - } - - // - activationBar.Clean(); - } - - // - Copy( - tmps, - mXWZUnActivatedResistanceZones // + SpecifiedUpdateTo( + mXWZUnActivatedDemandZones, + bar.time // ); - } - - // - count = ArraySize(mXWZActivatedResistanceZones); - has = IsValidSize(count); - if (has) - { - // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - ENUM_X_DIRECTION iForDir = X_DIRECTION_BEARISH; - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = mXWZActivatedResistanceZones[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - - // - // Check Breake ... - bool isBreaked = iZone.IsBreaked( - iForDir, - passedBar, - isBodyOut, - true, - false, - _Period // - ); - if (isBreaked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedResistanceZones, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); + count = ArraySize(mXWZUnActivatedDemandZones); } - - // - // - // - - // - // Clean Draws if has to ... - if (resetDraws) - { - mXWZDrawnObjects.Clear(); - } - - // } // @@ -3183,54 +1731,6 @@ void DrawPOIs() } } } - - // - // Activated ... - count = ArraySize(mXWZActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mXWZActivatedOBs[i]; - - // - bool isBullish = iOB.IsBullish(); - - // - if (showActivatedPOIs && - ((isBullish && - showBullishOrderBlocks) || - (!isBullish && - showBearishOrderBlocks))) - { - // - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateOrderBlock( - iOB, - iObj // - ); - if (isCreated) - { - // - // if (isBullish) - // { - // ((XCBullishOrderBlockObject *)iObj).ZoneFill(true); - // } - // else - // { - // ((XCBearishOrderBlockObject *)iObj).ZoneFill(true); - // } - - // - mXWZDrawnObjects.Add(iObj); - } - } - } - } } // @@ -3273,62 +1773,15 @@ void DrawPOIs() } } } - - // - // Activated ... - count = ArraySize(mXWZActivatedFVGs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = mXWZActivatedFVGs[i]; - - // - bool isBullish = iFVG.IsBullish(); - - // - if (showActivatedPOIs && - ((isBullish && - showBullishFairValueGaps) || - (!isBullish && - showBearishFairValueGaps))) - { - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateFairValueGap( - iFVG, - iObj // - ); - if (isCreated) - { - // - // if (isBullish) - // { - // ((XCBullishOrderBlockObject *)iObj).ZoneFill(true); - // } - // else - // { - // ((XCBearishOrderBlockObject *)iObj).ZoneFill(true); - // } - - // - mXWZDrawnObjects.Add(iObj); - } - } - } - } } // - // Support Zones ... - if (showSupportZones) + // Supply Zones ... + if (showSupplyZones) { // // UnActivated ... - count = ArraySize(mXWZUnActivatedSupportZones); + count = ArraySize(mXWZUnActivatedSupplyZones); has = IsValidSize(count); if (has) { @@ -3336,10 +1789,10 @@ void DrawPOIs() for (int i = 0; i < count; i++) { // - XCSupportZoneObject *iObj; + XCSupplyZoneObject *iObj; isCreated = mXWZPOIDrawer - .CreateSupportZone( - mXWZUnActivatedSupportZones[i], + .CreateSupplyZone( + mXWZUnActivatedSupplyZones[i], iObj // ); if (isCreated) @@ -3351,39 +1804,24 @@ void DrawPOIs() // // Activated ... - if (showActivatedPOIs) + count = ArraySize(mXWZActivatedSupplyZones); + has = IsValidSize(count); + if (has) { // - count = ArraySize(mXWZActivatedSupportZones); - has = IsValidSize(count); - if (has) + for (int i = 0; i < count; i++) { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateSupportZone( - mXWZActivatedSupportZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } } } } // - // Resistance Zones ... - if (showResistanceZones) + // Demand Zones ... + if (showDemandZones) { // // UnActivated ... - count = ArraySize(mXWZUnActivatedResistanceZones); + count = ArraySize(mXWZUnActivatedDemandZones); has = IsValidSize(count); if (has) { @@ -3391,10 +1829,10 @@ void DrawPOIs() for (int i = 0; i < count; i++) { // - XCResistanceZoneObject *iObj; + XCDemandZoneObject *iObj; isCreated = mXWZPOIDrawer - .CreateResistanceZone( - mXWZUnActivatedResistanceZones[i], + .CreateDemandZone( + mXWZUnActivatedDemandZones[i], iObj // ); if (isCreated) @@ -3406,33 +1844,867 @@ void DrawPOIs() // // Activated ... - if (showActivatedPOIs) + count = ArraySize(mXWZActivatedDemandZones); + has = IsValidSize(count); + if (has) { // - count = ArraySize(mXWZActivatedResistanceZones); - has = IsValidSize(count); - if (has) + for (int i = 0; i < count; i++) { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateResistanceZone( - mXWZActivatedResistanceZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } } } } + // + ChartRedraw(); + // } +// +// +// + +// +// Detect Order Block ... +void DetectOrderBlock(XOHCL &bar) +{ + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (!mXWZDetectOrderBlocks) + { + return; + } + + // + XOHCL zoneBar; + ENUM_X_DIRECTION zoneDir; + has = mXWZBarAnalyser.HasOrderBlock( + bar, + zoneBar, + zoneDir, + mXWZOBFVGSameBars // + ); + + // + if (!has) + { + // + zoneBar.Clean(); + return; + } + + // + XCOrderBlock *zone; + zone = new XCOrderBlock(); + has = zone.Init( + zoneBar, + zoneDir // + ); + + // + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + // Check Start ... + if (mXWZForceStarteds) + { + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = zone.IsStarted( + zoneDir, + startedBar, + isBodyOut, + bar.period // + ); + + // + has = isStarted; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + startedBar.Clean(); + + // + return; + } + + // + startedBar.Clean(); + } + + // + // Check Activation ... + if (mXWZForceActivation) + { + // + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = zone.IsActivated( + zoneDir, + activationBar, + isActivationBarBodyIn, + false, + bar.period // + ); + + // + has = !isActivated; + if (!has) + { + // + if (!mXWZIgnoreUnActivateds) + { + // + zone.To(activationBar.time); + + // + Add( + zone, + mXWZActivatedOBs // + ); + } + + // + zoneBar.Clean(); + ZeroMemory(zone); + activationBar.Clean(); + + // + return; + } + + // + activationBar.Clean(); + } + + // + // Check Breaktion ... + if (mXWZForceUnBreaked) + { + // + XOHCL breakedBar; + bool isBodyOut = false; + bool isBreaked = zone.IsBreaked( + zoneDir, + breakedBar, + isBodyOut, + false, + bar.period // + ); + + // + has = !isBreaked; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + breakedBar.Clean(); + + // + return; + } + + // + breakedBar.Clean(); + } + + // + // Check Indexes ... + + // + // UnActivateds ... + idx = FindIndex( + zone, + mXWZUnActivatedOBs // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + // Activateds ... + idx = FindIndex( + zone, + mXWZActivatedOBs // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + has = zone != NULL && + zone.IsValid(); + if (has) + { + // + zone.To(bar.time); + + // + Add( + zone, + mXWZUnActivatedOBs // + ); + } + + // + zoneBar.Clean(); +} + +// +// Detect Fair Value Gap ... +void DetectFairValueGap(XOHCL &bar) +{ + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (!mXWZDetectFairValueGaps) + { + return; + } + + // + XOHCL zoneEndBar; + XOHCL zoneStartBar; + ENUM_X_DIRECTION zoneDir; + has = mXWZBarAnalyser.HasFairValueGap( + bar, + zoneStartBar, + zoneEndBar, + zoneDir, + mXWZOBFVGSameBars // + ); + + // + if (!has) + { + // + zoneEndBar.Clean(); + zoneStartBar.Clean(); + return; + } + + // + XCFVG *zone; + zone = new XCFVG(); + has = zone.Init( + zoneStartBar, + zoneEndBar, + zoneDir // + ); + + // + if (!has) + { + // + ZeroMemory(zone); + zoneEndBar.Clean(); + zoneStartBar.Clean(); + + // + return; + } + + // + // Check Start ... + if (mXWZForceStarteds) + { + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = zone.IsStarted( + zoneDir, + startedBar, + isBodyOut, + bar.period // + ); + + // + has = isStarted; + if (!has) + { + // + ZeroMemory(zone); + startedBar.Clean(); + zoneEndBar.Clean(); + zoneStartBar.Clean(); + + // + return; + } + + // + startedBar.Clean(); + } + + // + // Check Activation ... + if (mXWZForceActivation) + { + // + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = zone.IsActivated( + zoneDir, + activationBar, + isActivationBarBodyIn, + false, + bar.period // + ); + + // + has = !isActivated; + if (!has) + { + // + ZeroMemory(zone); + zoneEndBar.Clean(); + zoneStartBar.Clean(); + activationBar.Clean(); + + // + return; + } + + // + activationBar.Clean(); + } + + // + // Check Breaktion ... + if (mXWZForceUnBreaked) + { + // + XOHCL breakedBar; + bool isBodyOut = false; + bool isBreaked = zone.IsBreaked( + zoneDir, + breakedBar, + isBodyOut, + false, + bar.period // + ); + + // + has = !isBreaked; + if (!has) + { + // + ZeroMemory(zone); + breakedBar.Clean(); + zoneEndBar.Clean(); + zoneStartBar.Clean(); + + // + return; + } + + // + breakedBar.Clean(); + } + + // + // Check Indexes ... + + // + // UnActivateds ... + idx = FindIndex( + zone, + mXWZUnActivatedFVGs // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + ZeroMemory(zone); + zoneEndBar.Clean(); + zoneStartBar.Clean(); + + // + return; + } + + // + // Activateds ... + idx = FindIndex( + zone, + mXWZActivatedFVGs // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + ZeroMemory(zone); + zoneEndBar.Clean(); + zoneStartBar.Clean(); + + // + return; + } + + // + has = zone != NULL && + zone.IsValid(); + if (has) + { + // + zone.To(bar.time); + + // + Add( + zone, + mXWZUnActivatedFVGs // + ); + } + + // + zoneEndBar.Clean(); + zoneStartBar.Clean(); +} + +// +// Supply Zone ... +void DetectSupplyZone(XOHCL &bar) +{ + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (!mXWZDetectSupplyZones) + { + return; + } + + // + int range = mXWZSuResRange * 2; + + // + XOHCL zoneBar; + ENUM_X_DIRECTION zoneDir = X_DIRECTION_BEARISH; + has = mXWZBarAnalyser.HasResistance( + bar, + zoneBar, + range // + ); + + // + if (!has) + { + // + zoneBar.Clean(); + return; + } + + // + XCSupplyZone *zone; + zone = new XCSupplyZone(); + has = zone.Init( + zoneBar, + range, + true // + ); + + // + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + // Check Start ... + if (mXWZForceStarteds) + { + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = zone.IsStarted( + zoneDir, + startedBar, + isBodyOut, + bar.period // + ); + + // + has = isStarted; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + startedBar.Clean(); + + // + return; + } + + // + startedBar.Clean(); + } + + // + // Check Activation ... + if (mXWZForceActivation) + { + // + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = zone.IsActivated( + zoneDir, + activationBar, + isActivationBarBodyIn, + false, + bar.period // + ); + + // + has = !isActivated; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + activationBar.Clean(); + + // + return; + } + + // + activationBar.Clean(); + } + + // + // Check Breaktion ... + if (mXWZForceUnBreaked) + { + // + XOHCL breakedBar; + bool isBodyOut = false; + bool isBreaked = zone.IsBreaked( + zoneDir, + breakedBar, + isBodyOut, + false, + bar.period // + ); + + // + has = !isBreaked; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + breakedBar.Clean(); + + // + return; + } + + // + breakedBar.Clean(); + } + + // + // Check Indexes ... + + // + // UnActivateds ... + idx = FindIndex( + zone, + mXWZUnActivatedSupplyZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + // Activateds ... + idx = FindIndex( + zone, + mXWZActivatedSupplyZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + has = zone != NULL && + zone.IsValid(); + if (has) + { + // + zone.To(bar.time); + + // + Add( + zone, + mXWZUnActivatedSupplyZones // + ); + } + + // + zoneBar.Clean(); +} + +// +// Demand Zone ... +void DetectDemandZone(XOHCL &bar) +{ + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (!mXWZDetectDemandZones) + { + return; + } + + // + int range = mXWZSuResRange * 2; + + // + XOHCL zoneBar; + ENUM_X_DIRECTION zoneDir = X_DIRECTION_BULLISH; + has = mXWZBarAnalyser.HasSupport( + bar, + zoneBar, + range // + ); + + // + if (!has) + { + // + zoneBar.Clean(); + return; + } + + // + XCDemandZone *zone; + zone = new XCDemandZone(); + has = zone.Init( + zoneBar, + range, + true // + ); + + // + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + // Check Start ... + if (mXWZForceStarteds) + { + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = zone.IsStarted( + zoneDir, + startedBar, + isBodyOut, + bar.period // + ); + + // + has = isStarted; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + startedBar.Clean(); + + // + return; + } + + // + startedBar.Clean(); + } + + // + // Check Activation ... + if (mXWZForceActivation) + { + // + XOHCL activationBar; + bool isActivationBarBodyIn = false; + bool isActivated = zone.IsActivated( + zoneDir, + activationBar, + isActivationBarBodyIn, + false, + bar.period // + ); + + // + has = !isActivated; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + activationBar.Clean(); + + // + return; + } + + // + activationBar.Clean(); + } + + // + // Check Breaktion ... + if (mXWZForceUnBreaked) + { + // + XOHCL breakedBar; + bool isBodyOut = false; + bool isBreaked = zone.IsBreaked( + zoneDir, + breakedBar, + isBodyOut, + false, + bar.period // + ); + + // + has = !isBreaked; + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + breakedBar.Clean(); + + // + return; + } + + // + breakedBar.Clean(); + } + + // + // Check Indexes ... + + // + // UnActivateds ... + idx = FindIndex( + zone, + mXWZUnActivatedDemandZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + // Activateds ... + idx = FindIndex( + zone, + mXWZActivatedDemandZones // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + zoneBar.Clean(); + ZeroMemory(zone); + + // + return; + } + + // + has = zone != NULL && + zone.IsValid(); + if (has) + { + // + zone.To(bar.time); + + // + Add( + zone, + mXWZUnActivatedDemandZones // + ); + } + + // + zoneBar.Clean(); +} + // \ No newline at end of file diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 1b68dabc..900e34f9 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -7793,6 +7793,57 @@ int FindIndex( // return result; } +// +// Find Specific Item Index inside a Collection ... +template +int FindIndex( + T &item, // Item to Find + const T &items[] // Items for Search +) +{ + // + int result = -1; + + // + // Check Item Validation ... + if (!item.IsValid()) + { + return result; + } + + // + int itemsCount = ArraySize(items); + if (itemsCount <= 0) + { + return result; + } + + // + for (int i = 0; i < itemsCount; i++) + { + // + T iItem = items[i]; + + // + // Validate Item ... + if (!iItem.IsValid()) + { + continue; + } + + // + bool isSame = item.IsSameAs(iItem); + if (isSame && result <= -1) + { + // + result = i; + break; + } + } + + // + return result; +} // // Check an Array Contains Specified Value ... diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index b56d9704..bbcf0fd1 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -2450,6 +2450,36 @@ int AddIfNotExists( return result; } +/** + * Update to Time of Specifiex Collection ... + * + * @param items: XOBFVG instance Collection ... + * @param value: datetime ... + */ +template +void SpecifiedUpdateTo( + T *&items[], + datetime value = NULL // +) +{ + // + value = NormalizeTime(value); + + // + int count = ArraySize(items); + bool has = HasChild(items); + if (!has) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + items[i].To(value); + } +} + // template int FilterZones( diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 16fc0947..def6c2c3 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -2018,9 +2018,8 @@ class XCTwoBarZone : public XCZone XOHCL &startBar, XOHCL &endBar, ENUM_XPOIS type, - bool useStartBarForUpper, - ENUM_X_PRICE upperPrice, - ENUM_X_PRICE lowerPrice // + ENUM_X_PRICE startPrice, + ENUM_X_PRICE endPrice // ) { // @@ -2042,18 +2041,33 @@ class XCTwoBarZone : public XCZone mType = type; mEndBar = endBar; mStartBar = startBar; - mUpperPrice = upperPrice; - mLowerPrice = lowerPrice; - mUseStartBarForUpper = useStartBarForUpper; + + // + int startIndex = startBar.Index(); + int endIndex = endBar.Index(); - mUpper = - useStartBarForUpper - ? startBar.GetPrice(upperPrice) - : endBar.GetPrice(upperPrice); - mLower = - useStartBarForUpper - ? endBar.GetPrice(lowerPrice) - : startBar.GetPrice(lowerPrice); + // + double mStartPrice = startBar.GetPrice(startPrice); + double mEndPrice = endBar.GetPrice(endPrice); + bool isStartOverEnd = mStartPrice > mEndPrice; + + // + if (isStartOverEnd) + { + // + mUpperPrice = startPrice; + mLowerPrice = endPrice; + } + else + { + // + mUpperPrice = endPrice; + mLowerPrice = startPrice; + } + + // + mUpper = MathMax(mStartPrice, mEndPrice); + mLower = MathMin(mStartPrice, mEndPrice); // result = IsValidTwoBarZone(); @@ -4342,24 +4356,20 @@ class XCFVG : public XCTwoBarZone : X_POI_BEARISH_FVG; // - bool useFistForUpper = isDirBullish - ? false - : true; - ENUM_X_PRICE upPrice = isDirBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - ENUM_X_PRICE loPrice = isDirBullish - ? X_PRICE_HIGH - : X_PRICE_LOW; + ENUM_X_PRICE startPrice = isDirBullish + ? X_PRICE_HIGH + : X_PRICE_LOW; + ENUM_X_PRICE endPrice = isDirBullish + ? X_PRICE_LOW + : X_PRICE_HIGH; // result = InitTwoBarZone( startBar, endBar, mTT, - useFistForUpper, - upPrice, - loPrice // + startPrice, + endPrice // ); if (!result) { diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index 076d446c..0c515c8b 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -5165,57 +5165,6 @@ bool IsStateFilterPassed( // -// -// Find Specific Item Index inside a Collection ... -template -int FindIndex( - T &item, // Item to Find - const T &items[] // Items for Search -) -{ - // - int result = -1; - - // - // Check Item Validation ... - if (!item.IsValid()) - { - return result; - } - - // - int itemsCount = ArraySize(items); - if (itemsCount <= 0) - { - return result; - } - - // - for (int i = 0; i < itemsCount; i++) - { - // - T iItem = items[i]; - - // - // Validate Item ... - if (!iItem.IsValid()) - { - continue; - } - - // - bool isSame = item.IsSameAs(iItem); - if (isSame && result <= -1) - { - // - result = i; - break; - } - } - - // - return result; -} // //