From e69dc85eea470ebe03418021c59d04c4daa61ee2 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 18 May 2024 16:55:28 +0330 Subject: [PATCH] complete some sort of new indicators helpers classes ... --- Documents/x-saherelm.xhk.helper.mq5 | 280 +++++ Helpers/x-saherelm.xama.helper.mq5 | 4 +- Helpers/x-saherelm.xhk.helper.mq5 | 1028 +++++++++++++++++ Helpers/x-saherelm.xmrb.helper.mq5 | 1229 +++++++++++++++++++++ Helpers/x-saherelm.xpv.helper.mq5 | 1597 +++++++++++++++++++++++++++ Helpers/x-saherelm.xsslc.helper.mq5 | 408 +++++++ Helpers/x-saherelm.xtm.helper.mq5 | 4 +- Indicators/x-saherelm.xhk.mq5 | 347 +++--- Indicators/x-saherelm.xpv.mq5 | 1 + Indicators/x-saherelm.xsslc.mq5 | 15 +- Libraries/x-saherelm.common.lib.mq5 | 148 +++ 11 files changed, 4874 insertions(+), 187 deletions(-) create mode 100644 Documents/x-saherelm.xhk.helper.mq5 create mode 100644 Helpers/x-saherelm.xhk.helper.mq5 create mode 100644 Helpers/x-saherelm.xmrb.helper.mq5 create mode 100644 Helpers/x-saherelm.xpv.helper.mq5 create mode 100644 Helpers/x-saherelm.xsslc.helper.mq5 diff --git a/Documents/x-saherelm.xhk.helper.mq5 b/Documents/x-saherelm.xhk.helper.mq5 new file mode 100644 index 00000000..aad34a49 --- /dev/null +++ b/Documents/x-saherelm.xhk.helper.mq5 @@ -0,0 +1,280 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXSSLCHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XSSLC_BUFFERS +{ + XSSLC_MAIN_LINE = 0 +}; + +// +// Input Models ... +struct XSSLCInputs +{ + // + // Props ... + + // + // Constructor(s) ... + XSSLCInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + } + + // + // Default ... + void Default() + { + // + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + false + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(0, 0); + + // + return result; + } +}; + +// +// Class ... +class XSCXSSLCHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXSSLCHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXSSLCHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XSSLCInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + // ArraySetAsSeries(mainBuffer, true); + // mHandler = iCustom( + // mSymbol, + // mPeriod, + // "x-saherelm.xsslc", + // // + // // Inputs ... + // // + // ); + // result = mHandler != INVALID_HANDLE; + // if (!result) + // { + // return result; + // } + + // + return result; + } + + // + // Inputs ... + + // + XSSLCInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XSSLCInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // // + // double GetMain( + // int barIndex // Bar Index + // ) + // { + // // + // if (barIndex < 0) + // { + // barIndex = 0; + // } + + // // + // Calculate(); + + // // + // int count = ArraySize(mainBuffer); + // if (barIndex >= count) + // { + // barIndex = count - 1; + // } + + // // + // return mainBuffer[barIndex]; + // } + + // // + // // Copy Required Items ... + // int CopyMain( + // int start, // Start + // int count, // Number of Items for read + // double &buffer[], // Dest Buffer + // bool forceClean = true // Force To Clean buffer + // ) + // { + // // + // // Update Calculations ... + // Calculate(); + + // // + // // Copy Items ... + // return Copy( + // start, + // count, + // mainBuffer, + // buffer, + // forceClean + // // + // ); + // } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XSSLCInputs mInputs; // Inputs ... + + // + // Buffers ... + // double mainBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + + // // + // // Main Buffer ... + // CopyBuffer( + // mHandler, + // XSSLC_MAIN_LINE, + // 0, + // totalBars, + // mainBuffer + // // + // ); + } +} + +// +// Tools ... \ No newline at end of file diff --git a/Helpers/x-saherelm.xama.helper.mq5 b/Helpers/x-saherelm.xama.helper.mq5 index 0e0a7add..3e8ee7ef 100644 --- a/Helpers/x-saherelm.xama.helper.mq5 +++ b/Helpers/x-saherelm.xama.helper.mq5 @@ -252,8 +252,8 @@ public: } // - // Copy Required Main Buffer ... - int CopyMainBuffer( + // Copy Required Items ... + int CopyMain( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer diff --git a/Helpers/x-saherelm.xhk.helper.mq5 b/Helpers/x-saherelm.xhk.helper.mq5 new file mode 100644 index 00000000..d1d00226 --- /dev/null +++ b/Helpers/x-saherelm.xhk.helper.mq5 @@ -0,0 +1,1028 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXHKHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XHK_BUFFERS +{ + // + // Hiken Ashi ... + XHK_OPEN_LINE = 0, + XHK_HIGHLINE = 1, + XHK_LOW_LINE = 2, + XHK_CLOSE_LINE = 3, + // + // Smoothed Hiken Ashi ... + XHK_SM_OPEN_LINE = 5, + XHK_SM_HIGHLINE = 6, + XHK_SM_LOW_LINE = 7, + XHK_SM_CLOSE_LINE = 8, +}; + +// +// Input Models ... +struct XHKInputs +{ + // + // Props ... + + // + // Market ... + int smoothingLength; // Smoothing Length + // + // Presentation ... + bool drawHikenAshi; // Draw Hiken Ashi + bool drawSmoothedHikenAshi; // Draw Smoothed Hiken Ashi + + // + // Constructor(s) ... + XHKInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + // Market ... + smoothingLength = 0; + // + // Presentation ... + drawHikenAshi = false; + drawSmoothedHikenAshi = false; + } + + // + // Default ... + void Default() + { + // + // Market ... + smoothingLength = 17; + // + // Presentation ... + drawHikenAshi = true; + drawSmoothedHikenAshi = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + smoothingLength > 2 + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(0, smoothingLength); + + // + return result; + } +}; + +// +// Class ... +class XSCXHKHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXHKHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXHKHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XHKInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(openBuffer, true); + ArraySetAsSeries(highBuffer, true); + ArraySetAsSeries(lowBuffer, true); + ArraySetAsSeries(closeBuffer, true); + ArraySetAsSeries(smOpenBuffer, true); + ArraySetAsSeries(smHighBuffer, true); + ArraySetAsSeries(smLowBuffer, true); + ArraySetAsSeries(smCloseBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xhk", + // + // Inputs ... + // + // Market ... + "", + mInputs.smoothingLength, // Smoothing Length + // + // Presentation ... + "", + mInputs.drawHikenAshi, // Draw Hiken Ashi + mInputs.drawSmoothedHikenAshi // Draw Smoothed Hiken Ashi + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XHKInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XHKInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + double GetOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(openBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return openBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + openBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(highBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return highBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + highBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(closeBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return closeBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + closeBuffer, + buffer, + forceClean + // + ); + } + + // + // Smoothed ... + + // + double GetSMOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(smOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return smOpenBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySMOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + smOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(smHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return smHighBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySMHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + smHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(smLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return smLowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySMLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + smLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(smCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return smCloseBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySMClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + smCloseBuffer, + buffer, + forceClean + // + ); + } + + // + // XOHCL ... + + // + // Retrieve Hiken Ashi Info as XOHCL model ... + bool AsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(openBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetOpen(barIndex); + double high = GetHigh(barIndex); + double close = GetClose(barIndex); + double low = GetLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopyAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(openBuffer)) + { + start = ArraySize(openBuffer) - 1; + } + + // + XOHCL tmp[]; + ArraySetAsSeries(tmp, false); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = AsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + tmp + // + ); + } + } + + // + ArraySetAsSeries(tmp, true); + + // + CopyRef( + 0, + ArraySize(tmp), + tmp, + buffer, + forceClean + // + ); + + // + result = ArraySize(tmp); + + // + Clean(tmp); + + // + return result; + } + + // + // Retrieve Smoothed Hiken Ashi Info as XOHCL model ... + bool SMAsOHCL( + XOHCL &bar, // Holds Result + int barIndex // Bar Index + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(openBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + double open = GetSMOpen(barIndex); + double high = GetSMHigh(barIndex); + double close = GetSMClose(barIndex); + double low = GetSMLow(barIndex); + + // + result = bar.Init( + mSymbol, + mPeriod, + open, + high, + close, + low, + barIndex + // + ); + + // + return result; + } + + // + // Copy Required Items ... + int CopySMAsOHCL( + int start, // Start + int count, // Number of Items for read + XOHCL &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + int result = 0; + + // + // Update Calculations ... + Calculate(); + + // + if (forceClean) + { + Clean(buffer); + } + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(openBuffer)) + { + start = ArraySize(openBuffer) - 1; + } + + // + XOHCL tmp[]; + ArraySetAsSeries(tmp, false); + + // + for (int i = start; i < start + count; i++) + { + // + XOHCL iBar; + bool isInit = SMAsOHCL(iBar, i); + + // + if (isInit) + { + // + AddRef( + iBar, + tmp + // + ); + } + } + + // + ArraySetAsSeries(tmp, true); + + // + CopyRef( + 0, + ArraySize(tmp), + tmp, + buffer, + forceClean + // + ); + + // + result = ArraySize(tmp); + + // + Clean(tmp); + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XHKInputs mInputs; // Inputs ... + + // + // Buffers ... + double openBuffer[]; + double highBuffer[]; + double lowBuffer[]; + double closeBuffer[]; + double smOpenBuffer[]; + double smHighBuffer[]; + double smLowBuffer[]; + double smCloseBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + + // + // Open Buffer ... + CopyBuffer( + mHandler, + XHK_OPEN_LINE, + 0, + totalBars, + openBuffer + // + ); + + // + // High Buffer ... + CopyBuffer( + mHandler, + XHK_HIGHLINE, + 0, + totalBars, + highBuffer + // + ); + + // + // Low Buffer ... + CopyBuffer( + mHandler, + XHK_LOW_LINE, + 0, + totalBars, + lowBuffer + // + ); + + // + // Close Buffer ... + CopyBuffer( + mHandler, + XHK_CLOSE_LINE, + 0, + totalBars, + closeBuffer + // + ); + + // + // Smoothed ... + + // + // Open Buffer ... + CopyBuffer( + mHandler, + XHK_SM_OPEN_LINE, + 0, + totalBars, + smOpenBuffer + // + ); + + // + // High Buffer ... + CopyBuffer( + mHandler, + XHK_SM_HIGHLINE, + 0, + totalBars, + smHighBuffer + // + ); + + // + // Low Buffer ... + CopyBuffer( + mHandler, + XHK_SM_LOW_LINE, + 0, + totalBars, + smLowBuffer + // + ); + + // + // Close Buffer ... + CopyBuffer( + mHandler, + XHK_SM_CLOSE_LINE, + 0, + totalBars, + smCloseBuffer + // + ); + } +} + +// +// Tools ... \ No newline at end of file diff --git a/Helpers/x-saherelm.xmrb.helper.mq5 b/Helpers/x-saherelm.xmrb.helper.mq5 new file mode 100644 index 00000000..0977effa --- /dev/null +++ b/Helpers/x-saherelm.xmrb.helper.mq5 @@ -0,0 +1,1229 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXMRBHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XMRB_BUFFERS +{ + // + // Ribbon ... + XMRB_FAST_LINE = 0, + XMRB_SLOW_LINE = 1, + // + // Ribbon 1 ... + XMRB_R1_FAST_LINE = 2, + XMRB_R1_SLOW_LINE = 3, + // + // Ribbon 2 ... + XMRB_R2_FAST_LINE = 4, + XMRB_R2_SLOW_LINE = 5, + // + // Ribbon 3 ... + XMRB_R3_FAST_LINE = 6, + XMRB_R3_SLOW_LINE = 7, + // + // Ribbon 4 ... + XMRB_R4_FAST_LINE = 8, + XMRB_R4_SLOW_LINE = 9, + // + // Ribbon 5 ... + XMRB_R5_FAST_LINE = 10, + XMRB_R5_SLOW_LINE = 11, +}; + +// +// Input Models ... +struct XMRBInputs +{ + // + // Props ... + + // + // Ribbon 1 ... + int fast1Length; // Fast + int slow1Length; // Slow + + // + // Ribbon 2 ... + int fast2Length; // Fast + int slow2Length; // Slow + + // + // Ribbon 3 ... + int fast3Length; // Fast + int slow3Length; // Slow + + // + // Ribbon 4 ... + int fast4Length; // Fast + int slow4Length; // Slow + + // + // Ribbon 5 ... + int fast5Length; // Fast + int slow5Length; // Slow + + // + // Calculation ... + ENUM_MA_METHOD ribbonMode; // Mode + ENUM_APPLIED_PRICE ribbonAppliedTo; // Applied To + + // + // Presentation ... + bool showFastMa; // Show Fast + bool showSlowMa; // Show Slow + bool showRibbon; // Show Ribbon + + // + // Constructor(s) ... + XMRBInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + // Ribbon 1 ... + fast1Length = 0; // Fast + slow1Length = 0; // Slow + + // + // Ribbon 2 ... + fast2Length = 0; // Fast + slow2Length = 0; // Slow + + // + // Ribbon 3 ... + fast3Length = 0; // Fast + slow3Length = 0; // Slow + + // + // Ribbon 4 ... + fast4Length = 0; // Fast + slow4Length = 0; // Slow + + // + // Ribbon 5 ... + fast5Length = 0; // Fast + slow5Length = 0; // Slow + + // + // Calculation ... + ribbonMode = MODE_EMA; // Mode + ribbonAppliedTo = PRICE_CLOSE; // Applied To + + // + // Presentation ... + showFastMa = false; // Show Fast + showSlowMa = false; // Show Slow + showRibbon = false; // Show Ribbon + } + + // + // Default ... + void Default() + { + // + // Ribbon 1 ... + fast1Length = 3; // Fast + slow1Length = 5; // Slow + + // + // Ribbon 2 ... + fast2Length = 8; // Fast + slow2Length = 13; // Slow + + // + // Ribbon 3 ... + fast3Length = 21; // Fast + slow3Length = 34; // Slow + + // + // Ribbon 4 ... + fast4Length = 55; // Fast + slow4Length = 89; // Slow + + // + // Ribbon 5 ... + fast5Length = 144; // Fast + slow5Length = 233; // Slow + + // + // Calculation ... + ribbonMode = MODE_EMA; // Mode + ribbonAppliedTo = PRICE_CLOSE; // Applied To + + // + // Presentation ... + showFastMa = true; // Show Fast + showSlowMa = true; // Show Slow + showRibbon = true; // Show Ribbon + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + (fast1Length > 2 && + fast2Length > fast1Length && + fast3Length > fast2Length && + fast4Length > fast3Length && + fast5Length > fast4Length && + slow1Length > fast1Length && + slow2Length > fast2Length && + slow3Length > fast3Length && + slow4Length > fast4Length && + slow5Length > fast5Length && + slow2Length > slow1Length && + slow3Length > slow2Length && + slow4Length > slow3Length && + slow5Length > slow4Length + // + ) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(fast1Length, fast2Length); + result = MathMax(result, fast3Length); + result = MathMax(result, fast4Length); + result = MathMax(result, fast5Length); + + // + result = MathMax(result, slow1Length); + result = MathMax(result, slow2Length); + result = MathMax(result, slow3Length); + result = MathMax(result, slow4Length); + result = MathMax(result, slow5Length); + + // + return result; + } +}; + +// +// Class ... +class XSCXMRBHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXMRBHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXMRBHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XMRBInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(fastBuffer, true); + ArraySetAsSeries(slowBuffer, true); + ArraySetAsSeries(r1FastBuffer, true); + ArraySetAsSeries(r1SlowBuffer, true); + ArraySetAsSeries(r2FastBuffer, true); + ArraySetAsSeries(r2SlowBuffer, true); + ArraySetAsSeries(r3FastBuffer, true); + ArraySetAsSeries(r3SlowBuffer, true); + ArraySetAsSeries(r4FastBuffer, true); + ArraySetAsSeries(r4SlowBuffer, true); + ArraySetAsSeries(r5FastBuffer, true); + ArraySetAsSeries(r5SlowBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xmrb", + // + // Inputs ... + // + // Ribbon 1 ... + "", + mInputs.fast1Length, // Fast + mInputs.slow1Length, // Slow + // + // Ribbon 2 ... + "", + mInputs.fast2Length, // Fast + mInputs.slow2Length, // Slow + // + // Ribbon 3 ... + "", + mInputs.fast3Length, // Fast + mInputs.slow3Length, // Slow + // + // Ribbon 4 ... + "", + mInputs.fast4Length, // Fast + mInputs.slow4Length, // Slow + // + // Ribbon 5 ... + "", + mInputs.fast5Length, // Fast + mInputs.slow5Length, // Slow + // + // Calculation ... + "", + mInputs.ribbonMode, // Mode + mInputs.ribbonAppliedTo, // Applied To + // + // Presentation ... + "", + mInputs.showFastMa, // Show Fast + mInputs.showSlowMa, // Show Slow + mInputs.showRibbon // Show Ribbon + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XMRBInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XMRBInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Fast ... + + // + double GetFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fastBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(slowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return slowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + slowBuffer, + buffer, + forceClean + // + ); + } + + // + // Ribbon 1 ... + + // + // Fast ... + + // + double GetR1Fast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r1FastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r1FastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR1Fast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r1FastBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetR1Slow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r1SlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r1SlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR1Slow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r1SlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Ribbon 2 ... + + // + // Fast ... + + // + double GetR2Fast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r2FastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r2FastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int Copy21Fast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r2FastBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetR2Slow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r2SlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r2SlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR2Slow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r2SlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Ribbon 3 ... + + // + // Fast ... + + // + double GetR3Fast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r3FastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r3FastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR3Fast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r3FastBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetR3Slow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r3SlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r3SlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR3Slow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r3SlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Ribbon 4 ... + + // + // Fast ... + + // + double GetR4Fast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r4FastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r4FastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR4Fast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r4FastBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetR4Slow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r4SlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r4SlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR4Slow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r4SlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Ribbon 5 ... + + // + // Fast ... + + // + double GetR5Fast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r5FastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r5FastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR5Fast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r5FastBuffer, + buffer, + forceClean + // + ); + } + + // + // Slow ... + + // + double GetR5Slow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(r5SlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return r5SlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyR5Slow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + r5SlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XMRBInputs mInputs; // Inputs ... + + // + // Buffers ... + double fastBuffer[]; + double slowBuffer[]; + double r1FastBuffer[]; + double r1SlowBuffer[]; + double r2FastBuffer[]; + double r2SlowBuffer[]; + double r3FastBuffer[]; + double r3SlowBuffer[]; + double r4FastBuffer[]; + double r4SlowBuffer[]; + double r5FastBuffer[]; + double r5SlowBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XMRB_FAST_LINE, + 0, + totalBars, + fastBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XMRB_SLOW_LINE, + 0, + totalBars, + slowBuffer + // + ); + + // + // Ribbon 1 ... + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XMRB_R1_FAST_LINE, + 0, + totalBars, + r1FastBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XMRB_R1_SLOW_LINE, + 0, + totalBars, + r1SlowBuffer + // + ); + + // + // Ribbon 2 ... + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XMRB_R2_FAST_LINE, + 0, + totalBars, + r2FastBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XMRB_R2_SLOW_LINE, + 0, + totalBars, + r2SlowBuffer + // + ); + + // + // Ribbon 3 ... + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XMRB_R3_FAST_LINE, + 0, + totalBars, + r3FastBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XMRB_R3_SLOW_LINE, + 0, + totalBars, + r3SlowBuffer + // + ); + + // + // Ribbon 4 ... + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XMRB_R4_FAST_LINE, + 0, + totalBars, + r4FastBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XMRB_R4_SLOW_LINE, + 0, + totalBars, + r4SlowBuffer + // + ); + + // + // Ribbon 5 ... + + // + // Fast Buffer ... + CopyBuffer( + mHandler, + XMRB_R5_FAST_LINE, + 0, + totalBars, + r5FastBuffer + // + ); + + // + // Slow Buffer ... + CopyBuffer( + mHandler, + XMRB_R5_SLOW_LINE, + 0, + totalBars, + r5SlowBuffer + // + ); + } +} + +// +// Tools ... \ No newline at end of file diff --git a/Helpers/x-saherelm.xpv.helper.mq5 b/Helpers/x-saherelm.xpv.helper.mq5 new file mode 100644 index 00000000..d0716eaf --- /dev/null +++ b/Helpers/x-saherelm.xpv.helper.mq5 @@ -0,0 +1,1597 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXPVHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XPV_BUFFERS +{ + // + // Peaks and Vales ... + XPV_PEAKS_LINE = 0, + XPV_VALES_LINE = 1, + // + // Support and Resistances ... + XPV_RESISTANCE_LINE = 2, + XPV_SUPPORT_LINE = 4, + // + // Fibonacci ... + XPV_FIB_1_LINE = 6, + XPV_FIB_2_LINE = 8, + XPV_FIB_3_LINE = 10, + XPV_FIB_4_LINE = 12, + XPV_FIB_5_LINE = 14, + // + // Short ... + XPV_SC_HH_LINE = 16, + XPV_SC_LL_LINE = 18, + // + // Medium ... + XPV_MC_HH_LINE = 20, + XPV_MC_LL_LINE = 22, + // + // Long ... + XPV_LC_HH_LINE = 24, + XPV_LC_LL_LINE = 26, + // + // Hind ... + XPV_HC_HH_LINE = 28, + XPV_HC_LL_LINE = 30, +}; + +// +// Input Models ... +struct XXPVInputs +{ + // + // Props ... + + // + // Makret Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Fibonacci ... + double fiboLevel1; // Fibio 1st Level + double fiboLevel2; // Fibio 2st Level + double fiboLevel3; // Fibio 3rd Level + double fiboLevel4; // Fibio 4th Level + double fiboLevel5; // Fibio 5th Level + + // + // Boundary Detection Modes ... + ENUM_SERIESMODE hhMode; // Highest High Calculation Method + ENUM_SERIESMODE llMode; // Lowest Low Calculation Method + + // + // Presentation ... + bool showPeaksAndVales; // Show Peaks and Vales + bool showLevels; // Show Levels + bool showConsolidations; // Show Consolidations + bool showFibo1Levels; // Show Fibo 1st Level + bool showFibo2Levels; // Show Fibo 2nd Level + bool showFibo3Levels; // Show Fibo 3rd Level + bool showFibo4Levels; // Show Fibo 4th Level + bool showFibo5Levels; // Show Fibo 5th Level + + // + // Constructor(s) ... + XXPVInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + // Makret Cycles ... + + // + // Short ... + scMethod = X_PERIOD_NOTHING; + scPeriod = NULL; + + // + // Medium ... + mcMethod = X_PERIOD_NOTHING; + mcPeriod = NULL; + + // + // Long ... + lcMethod = X_PERIOD_NOTHING; + lcPeriod = NULL; + + // + // Hind ... + hcMethod = X_PERIOD_NOTHING; + hcPeriod = NULL; + + // + // Fibonacci ... + fiboLevel1 = 0; + fiboLevel2 = 0; + fiboLevel3 = 0; + fiboLevel4 = 0; + fiboLevel5 = 0; + + // + // Boundary Detection Modes ... + hhMode = MODE_HIGH; + llMode = MODE_LOW; + + // + // Presentation ... + showPeaksAndVales = false; + showLevels = false; + showConsolidations = false; + showFibo1Levels = false; + showFibo2Levels = false; + showFibo3Levels = false; + showFibo4Levels = false; + showFibo5Levels = false; + } + + // + // Default ... + void Default() + { + // + // Makret Cycles ... + + // + // Short ... + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + + // + // Medium ... + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + + // + // Long ... + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + + // + // Hind ... + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + // Fibonacci ... + fiboLevel1 = 0.236; + fiboLevel2 = 0.382; + fiboLevel3 = 0.5; + fiboLevel4 = 0.618; + fiboLevel5 = 0.764; + + // + // Boundary Detection Modes ... + hhMode = MODE_HIGH; + llMode = MODE_LOW; + + // + // Presentation ... + showPeaksAndVales = true; + showLevels = false; + showConsolidations = false; + showFibo1Levels = true; + showFibo2Levels = true; + showFibo3Levels = true; + showFibo4Levels = true; + showFibo5Levels = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + false + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(result, 0); + + // + return result; + } +}; + +// +// Class ... +class XSCXPVHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXPVHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXPVHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XXPVInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(peaksBuffer, true); + ArraySetAsSeries(valesBuffer, true); + ArraySetAsSeries(resistanceBuffer, true); + ArraySetAsSeries(supportBuffer, true); + ArraySetAsSeries(fib1Buffer, true); + ArraySetAsSeries(fib2Buffer, true); + ArraySetAsSeries(fib3Buffer, true); + ArraySetAsSeries(fib4Buffer, true); + ArraySetAsSeries(fib5Buffer, true); + ArraySetAsSeries(scHHBuffer, true); + ArraySetAsSeries(scLLBuffer, true); + ArraySetAsSeries(mcHHBuffer, true); + ArraySetAsSeries(mcLLBuffer, true); + ArraySetAsSeries(lcHHBuffer, true); + ArraySetAsSeries(lcLLBuffer, true); + ArraySetAsSeries(hcHHBuffer, true); + ArraySetAsSeries(hcLLBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xpv", + // + // Inputs ... + // + // Makret Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, // How to Find Period + mInputs.scPeriod, // Time Period + // + // Medium ... + "", + mInputs.mcMethod, // How to Find Period + mInputs.mcPeriod, // Time Period + // + // Long ... + "", + mInputs.lcMethod, // How to Find Period + mInputs.lcPeriod, // Time Period + // + // Hind ... + "", + mInputs.hcMethod, // How to Find Period + mInputs.hcPeriod, // Time Period + // + // Fibonacci ... + "", + mInputs.fiboLevel1, // Fibio 1st Level + mInputs.fiboLevel2, // Fibio 2st Level + mInputs.fiboLevel3, // Fibio 3rd Level + mInputs.fiboLevel4, // Fibio 4th Level + mInputs.fiboLevel5, // Fibio 5th Level + // + // Boundary Detection Modes ... + "", + mInputs.hhMode, // Highest High Calculation Method + mInputs.llMode, // Lowest Low Calculation Method + // + // Presentation ... + "", + mInputs.showPeaksAndVales, // Show Peaks and Vales + mInputs.showLevels, // Show Levels + mInputs.showConsolidations, // Show Consolidations + mInputs.showFibo1Levels, // Show Fibo 1st Level + mInputs.showFibo2Levels, // Show Fibo 2nd Level + mInputs.showFibo3Levels, // Show Fibo 3rd Level + mInputs.showFibo4Levels, // Show Fibo 4th Level + mInputs.showFibo5Levels // Show Fibo 5th Level + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XXPVInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XXPVInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Peaks ... + + // + double GetPeak( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(peaksBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return peaksBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyPeak( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + peaksBuffer, + buffer, + forceClean + // + ); + } + + // + // Vales ... + + // + double GetVale( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(valesBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return valesBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyVale( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + valesBuffer, + buffer, + forceClean + // + ); + } + + // + // Resistance ... + + // + double GetResistance( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(resistanceBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return resistanceBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyResistance( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + resistanceBuffer, + buffer, + forceClean + // + ); + } + + // + // Support ... + + // + double GetSupport( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(supportBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return supportBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySupport( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + supportBuffer, + buffer, + forceClean + // + ); + } + + // + // Fibonacci ... + + // + // Level 1 ... + + // + double GetFib1( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib1Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib1Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib1( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib1Buffer, + buffer, + forceClean + // + ); + } + + // + // Level 2 ... + + // + double GetFib2( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib2Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib2Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib2( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib2Buffer, + buffer, + forceClean + // + ); + } + + // + // Level 3 ... + + // + double GetFib3( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib3Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib3Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib3( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib3Buffer, + buffer, + forceClean + // + ); + } + + // + // Level 4 ... + + // + double GetFib4( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib4Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib4Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib4( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib4Buffer, + buffer, + forceClean + // + ); + } + + // + // Level 5 ... + + // + double GetFib5( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fib5Buffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fib5Buffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFib5( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fib5Buffer, + buffer, + forceClean + // + ); + } + + // + // Cycles ... + + // + // Short ... + + // + // HH ... + + // + double GetSCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(scHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return scHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + scHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetSCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(scLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return scLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + scLLBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + // HH ... + + // + double GetMCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mcHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mcHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mcHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetMCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mcLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mcLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mcLLBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + // HH ... + + // + double GetLCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lcHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lcHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lcHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetLCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lcLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lcLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lcLLBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + // HH ... + + // + double GetHCHH( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hcHHBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hcHHBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHCHH( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hcHHBuffer, + buffer, + forceClean + // + ); + } + + // + // LL ... + + // + double GetHCLL( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hcLLBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hcLLBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHCLL( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hcLLBuffer, + buffer, + forceClean + // + ); + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XXPVInputs mInputs; // Inputs ... + + // + // Buffers ... + double peaksBuffer[]; + double valesBuffer[]; + double resistanceBuffer[]; + double supportBuffer[]; + double fib1Buffer[]; + double fib2Buffer[]; + double fib3Buffer[]; + double fib4Buffer[]; + double fib5Buffer[]; + double scHHBuffer[]; + double scLLBuffer[]; + double mcHHBuffer[]; + double mcLLBuffer[]; + double lcHHBuffer[]; + double lcLLBuffer[]; + double hcHHBuffer[]; + double hcLLBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + + // + // Peaks and Vales ... + + // + // Peaks Buffer ... + CopyBuffer( + mHandler, + XPV_PEAKS_LINE, + 0, + totalBars, + peaksBuffer + // + ); + + // + // Vales Buffer ... + CopyBuffer( + mHandler, + XPV_VALES_LINE, + 0, + totalBars, + valesBuffer + // + ); + + // + // Support and Resistances ... + + // + // Resistances Buffer ... + CopyBuffer( + mHandler, + XPV_RESISTANCE_LINE, + 0, + totalBars, + resistanceBuffer + // + ); + + // + // Supports Buffer ... + CopyBuffer( + mHandler, + XPV_SUPPORT_LINE, + 0, + totalBars, + supportBuffer + // + ); + + // + // Fibonacci ... + + // + // Level 1 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_1_LINE, + 0, + totalBars, + fib1Buffer + // + ); + + // + // Level 2 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_2_LINE, + 0, + totalBars, + fib2Buffer + // + ); + + // + // Level 3 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_3_LINE, + 0, + totalBars, + fib3Buffer + // + ); + + // + // Level 4 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_4_LINE, + 0, + totalBars, + fib4Buffer + // + ); + + // + // Level 5 Buffer ... + CopyBuffer( + mHandler, + XPV_FIB_5_LINE, + 0, + totalBars, + fib5Buffer + // + ); + + // + // Cycles ... + + // + // Short ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_SC_HH_LINE, + 0, + totalBars, + scHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_SC_LL_LINE, + 0, + totalBars, + scLLBuffer + // + ); + + // + // Medium ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_MC_HH_LINE, + 0, + totalBars, + mcHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_MC_LL_LINE, + 0, + totalBars, + mcLLBuffer + // + ); + + // + // Long ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_LC_HH_LINE, + 0, + totalBars, + lcHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_LC_LL_LINE, + 0, + totalBars, + lcLLBuffer + // + ); + + // + // Hind ... + + // + // HH ... + CopyBuffer( + mHandler, + XPV_HC_HH_LINE, + 0, + totalBars, + hcHHBuffer + // + ); + + // + // LL ... + CopyBuffer( + mHandler, + XPV_HC_LL_LINE, + 0, + totalBars, + hcLLBuffer + // + ); + } +} + +// +// Tools ... \ No newline at end of file diff --git a/Helpers/x-saherelm.xsslc.helper.mq5 b/Helpers/x-saherelm.xsslc.helper.mq5 new file mode 100644 index 00000000..c2c69f00 --- /dev/null +++ b/Helpers/x-saherelm.xsslc.helper.mq5 @@ -0,0 +1,408 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXSSLCHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XSSLC_BUFFERS +{ + XSSLC_UP_LINE = 0, + XSSLC_DOWN_LINE = 1, +}; + +// +// Input Models ... +struct XSSLCInputs +{ + // + // Props ... + + // + // Market ... + int length; // Length + + // + // Calculation ... + ENUM_MA_METHOD method; // Method + ENUM_APPLIED_PRICE upAppliedTo; // Up Applied To + ENUM_APPLIED_PRICE downAppliedTo; // Down Applied To + + // + // Presentation ... + bool showUp; // Show Up + bool showDown; // Show Down + + // + // Constructor(s) ... + XSSLCInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + // Market ... + length = 0; + + // + // Calculation ... + method = MODE_SMA; + upAppliedTo = PRICE_HIGH; + downAppliedTo = PRICE_LOW; + + // + // Presentation ... + showUp = false; + showDown = false; + } + + // + // Default ... + void Default() + { + // + // Market ... + length = 36; + + // + // Calculation ... + method = MODE_SMA; + upAppliedTo = PRICE_HIGH; + downAppliedTo = PRICE_LOW; + + // + // Presentation ... + showUp = true; + showDown = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + false + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(0, 0); + + // + return result; + } +}; + +// +// Class ... +class XSCXSSLCHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXSSLCHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXSSLCHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XSSLCInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(upBuffer, true); + ArraySetAsSeries(downBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xsslc", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, // Length + // + // Calculation ... + "", + mInputs.method, // Method + mInputs.upAppliedTo, // Up Applied To + mInputs.downAppliedTo, // Down Applied To + // + // Presentation ... + "", + mInputs.showUp, // Show Up + mInputs.showDown // Show Down + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XSSLCInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XSSLCInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // Up ... + + // + double GetUp( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(upBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return upBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyUp( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + upBuffer, + buffer, + forceClean + // + ); + } + + // + // Down ... + + // + double GetDown( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(downBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return downBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyDown( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + downBuffer, + buffer, + forceClean + // + ); + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XSSLCInputs mInputs; // Inputs ... + + // + // Buffers ... + double upBuffer[]; + double downBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + + // + // Up ... + CopyBuffer( + mHandler, + XSSLC_UP_LINE, + 0, + totalBars, + upBuffer + // + ); + + // + // Down ... + CopyBuffer( + mHandler, + XSSLC_DOWN_LINE, + 0, + totalBars, + downBuffer + // + ); + } +} + +// +// Tools ... \ No newline at end of file diff --git a/Helpers/x-saherelm.xtm.helper.mq5 b/Helpers/x-saherelm.xtm.helper.mq5 index c1f3a062..cbbb8e90 100644 --- a/Helpers/x-saherelm.xtm.helper.mq5 +++ b/Helpers/x-saherelm.xtm.helper.mq5 @@ -245,8 +245,8 @@ public: } // - // Copy Required Main Buffer ... - int CopyMainBuffer( + // Copy Required Items ... + int CopyMain( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer diff --git a/Indicators/x-saherelm.xhk.mq5 b/Indicators/x-saherelm.xhk.mq5 index ca4a6b33..37cf4b55 100644 --- a/Indicators/x-saherelm.xhk.mq5 +++ b/Indicators/x-saherelm.xhk.mq5 @@ -17,57 +17,44 @@ #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" -#property description "SaherElm X121_XHK Indicator" +#property description "SaherElm XHK Indicator" #property strict // -// START Constants ... -// +// Constants ... // // Indicator Short Name ... -#define ShortName "X121_XHK" +#define ShortName "XHK" // -// END Constants ... -// - -// -// START Inputs ... -// - -// -input group "Presentation"; -input bool drawCandles = true; // Draw Hiken Ashi Candle -input bool drawCandleLines = false; // Show HikenAshi Lines - -// -// END Inputs ... -// - -// -// START Includes and Imports ... -// - -// -// Includes Common Library ... +// Imports ... +#include #include "../Libraries/x-saherelm.common.lib.mq5" // -// END Includes and Imports ... -// +// Inputs ... // -// START Buffers ... +input group "Market"; +input int smoothingLength = 17; // Smoothing Length +// +input group "Presentation"; +input bool drawHikenAshi = true; // Draw Hiken Ashi +input bool drawSmoothedHikenAshi = true; // Draw Smoothed Hiken Ashi + +// +// Buffers ... + // #property indicator_chart_window // -#property indicator_buffers 13 -#property indicator_plots 5 +#property indicator_buffers 10 +#property indicator_plots 10 // -// PLOTTED Buffers ... +// Buffers ... // // Open ... @@ -98,84 +85,54 @@ double candleColorBuffer[]; #define candlesBufferIndex 0 // -#property indicator_label1 "X121_XHK Open;X121_XHK High;X121_XHK Low;X121_XHK Close" +#property indicator_label1 "XHK Open;XHK High;XHK Low;XHK Close" #property indicator_type1 DRAW_COLOR_CANDLES -#property indicator_color1 clrAqua, clrMagenta, CLR_NONE +#property indicator_color1 CLR_NONE, clrAqua, clrMagenta // -#define openHKBufferIndex 5 -#define openHKColorBufferIndex 6 -double openHKBuffer[]; -double openHKColorBuffer[]; +// SM Open ... +#define openSMBufferIndex 5 +double openSMBuffer[]; // -#define openHKBufferPlotIndex 1 -#property indicator_label2 "X121_XHK O" -#property indicator_type2 DRAW_COLOR_LINE -#property indicator_color2 clrAqua, clrMagenta, clrLightGray -#property indicator_style2 STYLE_DOT -#property indicator_width2 1 +// SM High ... +#define highSMBufferIndex 6 +double highSMBuffer[]; // -#define highHKBufferIndex 7 -#define highHKColorBufferIndex 8 -double highHKBuffer[]; -double highHKColorBuffer[]; +// SM Low ... +#define lowSMBufferIndex 7 +double lowSMBuffer[]; // -#define highHKBufferPlotIndex 2 -#property indicator_label3 "X121_XHK H" -#property indicator_type3 DRAW_COLOR_LINE -#property indicator_color3 clrAqua, clrMagenta, clrLightGray -#property indicator_style3 STYLE_DOT -#property indicator_width3 1 +// SM Close ... +#define closeSMBufferIndex 8 +double closeSMBuffer[]; // -#define lowHKBufferIndex 9 -#define lowHKColorBufferIndex 10 -double lowHKBuffer[]; -double lowHKColorBuffer[]; +// SM Candle Color ... +#define candleColorSMBufferIndex 9 +double candleColorSMBuffer[]; // -#define lowHKBufferPlotIndex 3 -#property indicator_label4 "X121_XHK L" -#property indicator_type4 DRAW_COLOR_LINE -#property indicator_color4 clrAqua, clrMagenta, clrLightGray -#property indicator_style4 STYLE_DOT -#property indicator_width4 1 +#define candlesSMBufferIndex 1 // -#define closeHKBufferIndex 11 -#define closeHKColorBufferIndex 12 -double closeHKBuffer[]; -double closeHKColorBuffer[]; +#property indicator_label2 "XSMHK Open;XSMHK High;XSMHK Low;XSMHK Close" +#property indicator_type2 DRAW_COLOR_CANDLES +#property indicator_color2 CLR_NONE, clrDarkGreen, clrDarkRed // -#define closeHKBufferPlotIndex 4 -#property indicator_label5 "X121_XHK C" -#property indicator_type5 DRAW_COLOR_LINE -#property indicator_color5 clrAqua, clrMagenta, clrLightGray -#property indicator_style5 STYLE_DOT -#property indicator_width5 1 - -// -// END Buffers ... -// - -// -// START Global Definitions: Variables, Properties and etc ... -// +// Variables, Properties and etc ... // int maxLength; // -// END Global Definitions: Variables, Properties and etc ... -// +double mHideColorIDX = 0; // -// START Event Handlers ... -// +// Event Handlers ... // // Initialization ... @@ -228,36 +185,17 @@ void OnDeinit(const int reason) // // Calculating what we want ... int OnCalculate( - // - // total Candles on chart ... - const int rates_total, - // - // total calculated Candles on charts ... - const int prev_calculated, - // - // history of Candles Open Time ... - const datetime &time[], - // - // history of Candles Open Price ... - const double &open[], - // - // history of Candles High Price ... - const double &high[], - // - // history of Candles Low Price ... - const double &low[], - // - // history of Candles Close Price ... - const double &close[], - // - // history of Tick Volumes on Candle ... - const long &tick_volume[], - // - // history of Trade Volumes ... - const long &volume[], - // - // history of Candles Spread Price ... - const int &spread[]) + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) { // // Prepare Buffers ... @@ -284,17 +222,15 @@ int OnCalculate( CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low); } + // + CalculateSM(rates_total, prev_calculated); + // return rates_total; } // -// END Event Handlers ... -// - -// -// START Functions ... -// +// Functions ... // // Validate Input Args for Initialization ... @@ -361,52 +297,41 @@ void DefineBuffers() PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false); // - // Open HK ... - ENUM_DRAW_TYPE openDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE; - ArraySetAsSeries(openHKBuffer, true); - SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA); - PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines); - PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_DRAW_TYPE, openDrawType); + // Candles Color ... + ArraySetAsSeries(candleColorSMBuffer, true); + SetIndexBuffer(candleColorSMBufferIndex, candleColorSMBuffer, INDICATOR_COLOR_INDEX); // - ArraySetAsSeries(openHKColorBuffer, true); - SetIndexBuffer(openHKColorBufferIndex, openHKColorBuffer, INDICATOR_COLOR_INDEX); + // Set EMPTY_VALUE on Candles Buffer ... + PlotIndexSetDouble(candlesSMBufferIndex, PLOT_EMPTY_VALUE, 0.0); // - // High HK ... - ENUM_DRAW_TYPE highDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE; - ArraySetAsSeries(highHKBuffer, true); - SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA); - PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines); - PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_DRAW_TYPE, highDrawType); + PlotIndexSetInteger(candlesSMBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(candleColorSMBufferIndex, PLOT_SHOW_DATA, false); // - ArraySetAsSeries(highHKColorBuffer, true); - SetIndexBuffer(highHKColorBufferIndex, highHKColorBuffer, INDICATOR_COLOR_INDEX); + // Open ... + ArraySetAsSeries(openSMBuffer, true); + PlotIndexSetInteger(openSMBufferIndex, PLOT_SHOW_DATA, false); + SetIndexBuffer(openSMBufferIndex, openSMBuffer, INDICATOR_DATA); // - // Low HK ... - ENUM_DRAW_TYPE lowDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE; - ArraySetAsSeries(lowHKBuffer, true); - SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA); - PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines); - PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_DRAW_TYPE, lowDrawType); + // High ... + ArraySetAsSeries(highSMBuffer, true); + SetIndexBuffer(highSMBufferIndex, highSMBuffer, INDICATOR_DATA); + PlotIndexSetInteger(highSMBufferIndex, PLOT_SHOW_DATA, false); // - ArraySetAsSeries(lowHKColorBuffer, true); - SetIndexBuffer(lowHKColorBufferIndex, lowHKColorBuffer, INDICATOR_COLOR_INDEX); + // Close ... + ArraySetAsSeries(closeSMBuffer, true); + SetIndexBuffer(closeSMBufferIndex, closeSMBuffer, INDICATOR_DATA); + PlotIndexSetInteger(closeSMBufferIndex, PLOT_SHOW_DATA, false); // - // Close HK ... - ENUM_DRAW_TYPE closeDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE; - ArraySetAsSeries(closeHKBuffer, true); - SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA); - PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines); - PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_DRAW_TYPE, closeDrawType); - - // - ArraySetAsSeries(closeHKColorBuffer, true); - SetIndexBuffer(closeHKColorBufferIndex, closeHKColorBuffer, INDICATOR_COLOR_INDEX); + // Low ... + ArraySetAsSeries(lowSMBuffer, true); + SetIndexBuffer(lowSMBufferIndex, lowSMBuffer, INDICATOR_DATA); + PlotIndexSetInteger(lowSMBufferIndex, PLOT_SHOW_DATA, false); } // @@ -425,7 +350,8 @@ void CalculateBuffers( const double &open[], const double &high[], const double &close[], - const double &low[]) + const double &low[] // +) { // double mPrevHKOpenValue; @@ -458,29 +384,96 @@ void CalculateBuffers( closeBuffer[bar_index] = mHKCloseValue; // - double candleColorValue = - mHKOpenValue < mHKCloseValue ? 0 : 1; - + bool isBearish = // - candleColorBuffer[bar_index] = drawCandles ? candleColorValue : 2; + openBuffer[bar_index] > closeBuffer[bar_index] + // + ; // - openHKBuffer[bar_index] = mHKOpenValue; - openHKColorBuffer[bar_index] = candleColorValue; - - // - highHKBuffer[bar_index] = mHKHighValue; - highHKColorBuffer[bar_index] = candleColorValue; - - // - lowHKBuffer[bar_index] = mHKLowValue; - lowHKColorBuffer[bar_index] = candleColorValue; - - // - closeHKBuffer[bar_index] = mHKCloseValue; - closeHKColorBuffer[bar_index] = candleColorValue; + candleColorBuffer[bar_index] = !drawHikenAshi + ? mHideColorIDX + : isBearish + ? 2 + : 1; } // -// END Functions ... -// +// Calculate Smoothed HikenAshi ... +void CalculateSM( + int ratesTotal, // Total Bars + int prevCalculated // Calculated Bars +) +{ + // + // Open ... + int calculatedSMHKOpens = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + smoothingLength, + openBuffer, + openSMBuffer); + + // + // High ... + int calculatedSMHKHighs = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + smoothingLength, + highBuffer, + highSMBuffer); + + // + // Low ... + int calculatedSMHKLows = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + smoothingLength, + lowBuffer, + lowSMBuffer); + + // + // Close ... + int calculatedSMHKCloses = ExponentialMAOnBuffer( + ratesTotal, + prevCalculated, + 0, + smoothingLength, + closeBuffer, + closeSMBuffer); + + // + // Find Calculated Items for Colors ... + int mNumberOfItems = MathMin(calculatedSMHKOpens, calculatedSMHKHighs); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKLows); + mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKCloses); + + // + // Create a Loop for Color of Candles ... + for (int i = 0; i < mNumberOfItems; i++) + { + // + bool isBearish = + // + openSMBuffer[i] > closeSMBuffer[i] + // + ; + + // + if (drawSmoothedHikenAshi) + { + // + candleColorSMBuffer[i] = isBearish + ? 2 + : 1; + } + else + { + // + candleColorSMBuffer[i] = mHideColorIDX; + } + } +} diff --git a/Indicators/x-saherelm.xpv.mq5 b/Indicators/x-saherelm.xpv.mq5 index 4e29dcc0..d724dd25 100644 --- a/Indicators/x-saherelm.xpv.mq5 +++ b/Indicators/x-saherelm.xpv.mq5 @@ -906,6 +906,7 @@ void CalculateCycle( double &llColorBuffer[] // ) { + // cycle.Update(barIndex); // diff --git a/Indicators/x-saherelm.xsslc.mq5 b/Indicators/x-saherelm.xsslc.mq5 index b94a7b41..620cb249 100644 --- a/Indicators/x-saherelm.xsslc.mq5 +++ b/Indicators/x-saherelm.xsslc.mq5 @@ -348,10 +348,9 @@ void DefineBuffers() // ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(upBuffer, true); SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA); - PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, false); + PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, showUp); PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength); PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType); @@ -361,7 +360,6 @@ void DefineBuffers() // ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(downBuffer, true); SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA); PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, showDown); @@ -412,11 +410,16 @@ void CalculateBuffers( // double kpiValue; - if (closeValue > upMaValue) { + if (closeValue > upMaValue) + { kpiValue = 1; - } else if (closeValue < downMaValue) { + } + else if (closeValue < downMaValue) + { kpiValue = -1; - } else { + } + else + { kpiValue = kpiBuffer[bar_index + 1]; } diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index beaa20fa..f0a644d4 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -353,6 +353,86 @@ struct XOHCL return result; } + // + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period + double mOpen = 0, // Open + double mHigh = 0, // High + double mClose = 0, // Close + double mLow = 0, // Low + int barIndex = 0 // Bar Index + ) + { + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + symbol = mSymbol; + period = mPeriod; + + // + time = iTime( + mSymbol, + mPeriod, + barIndex + // + ); + + // + open = mOpen; + high = mHigh; + close = mClose; + low = mLow; + + // + return IsValid(); + } + + // + bool Init( + string mSymbol = NULL, // Trading Symbol + ENUM_TIMEFRAMES mPeriod = NULL, // Trading Period + double mOpen = 0, // Open + double mHigh = 0, // High + double mClose = 0, // Close + double mLow = 0, // Low + datetime mTime = NULL // Bar Time + ) + { + // + mSymbol = NormalizeSymbol(mSymbol); + mPeriod = NormalizePeriod(mPeriod); + + // + symbol = mSymbol; + period = mPeriod; + + // + int barIndex = iBarShift( + symbol, + period, + mTime); + + // + time = iTime( + mSymbol, + mPeriod, + barIndex + // + ); + + // + open = mOpen; + high = mHigh; + close = mClose; + low = mLow; + + // + return IsValid(); + } + // // Tools ... @@ -3593,6 +3673,74 @@ int Copy( return result; } +// +// Copy Items from a Buffer ... +template +int CopyRef( + int start, // Start + int count, // Number of Items for read + T &source[], // Source Buffer + T &dest[], // Dest Buffer + bool forceClean = true // Force To Clean buffer +) +{ + // + int result = 0; + + // + if (forceClean) + { + Clean(dest); + } + + // + if (start < 0) + { + start = 0; + } + + // + if (start >= ArraySize(source)) + { + start = ArraySize(source) - 1; + } + + // + int beforeSize = ArraySize(dest); + + // + bool asSeriesDest = ArrayGetAsSeries(dest); + bool asSeriesSource = ArrayGetAsSeries(source); + + // + ArraySetAsSeries(dest, true); + ArraySetAsSeries(source, true); + + // + for (int i = start; i < start + count; i++) + { + // + AddRef( + source[i], + dest + // + ); + } + + // + int afterSize = ArraySize(dest); + + // + result = afterSize - beforeSize; + + // + ArraySetAsSeries(dest, asSeriesDest); + ArraySetAsSeries(source, asSeriesSource); + + // + return result; +} + // // Retrive Last Item of Specified Buffer ... template