From e604865ee1e6d1fc52988515e6f0d3a37a6d4532 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 7 Aug 2024 05:15:11 +0330 Subject: [PATCH] develop xchdon indicator and it's relate Helper class ... --- Helpers/x-saherelm.xchdon.helper.mq5 | 3887 ++++++++++++++++++++++++++ Indicators/x-saherelm.xchdon.mq5 | 1603 +++++++++++ 2 files changed, 5490 insertions(+) create mode 100644 Helpers/x-saherelm.xchdon.helper.mq5 create mode 100644 Indicators/x-saherelm.xchdon.mq5 diff --git a/Helpers/x-saherelm.xchdon.helper.mq5 b/Helpers/x-saherelm.xchdon.helper.mq5 new file mode 100644 index 00000000..2b054736 --- /dev/null +++ b/Helpers/x-saherelm.xchdon.helper.mq5 @@ -0,0 +1,3887 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHDONHelper +// 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" + +// +enum ENUM_XCHDON_BUFFERS +{ + // + // Current ... + // + XCHDON_C_OPEN_UPPER_LINE = 0, + XCHDON_C_OPEN_LOWER_LINE = 1, + // + XCHDON_C_HIGH_UPPER_LINE = 2, + XCHDON_C_HIGH_LOWER_LINE = 3, + // + XCHDON_C_LOW_UPPER_LINE = 4, + XCHDON_C_LOW_LOWER_LINE = 5, + // + XCHDON_C_CLOSE_UPPER_LINE = 6, + XCHDON_C_CLOSE_LOWER_LINE = 7, + // + // Short ... + // + XCHDON_S_OPEN_UPPER_LINE = 8, + XCHDON_S_OPEN_LOWER_LINE = 9, + // + XCHDON_S_HIGH_UPPER_LINE = 10, + XCHDON_S_HIGH_LOWER_LINE = 11, + // + XCHDON_S_LOW_UPPER_LINE = 12, + XCHDON_S_LOW_LOWER_LINE = 13, + // + XCHDON_S_CLOSE_UPPER_LINE = 14, + XCHDON_S_CLOSE_LOWER_LINE = 15, + // + // Medium ... + // + XCHDON_M_OPEN_UPPER_LINE = 16, + XCHDON_M_OPEN_LOWER_LINE = 17, + // + XCHDON_M_HIGH_UPPER_LINE = 18, + XCHDON_M_HIGH_LOWER_LINE = 19, + // + XCHDON_M_LOW_UPPER_LINE = 20, + XCHDON_M_LOW_LOWER_LINE = 21, + // + XCHDON_M_CLOSE_UPPER_LINE = 22, + XCHDON_M_CLOSE_LOWER_LINE = 23, + // + // Long ... + // + XCHDON_L_OPEN_UPPER_LINE = 24, + XCHDON_L_OPEN_LOWER_LINE = 25, + // + XCHDON_L_HIGH_UPPER_LINE = 26, + XCHDON_L_HIGH_LOWER_LINE = 27, + // + XCHDON_L_LOW_UPPER_LINE = 28, + XCHDON_L_LOW_LOWER_LINE = 29, + // + XCHDON_L_CLOSE_UPPER_LINE = 30, + XCHDON_L_CLOSE_LOWER_LINE = 31, + // + // Hind ... + // + XCHDON_H_OPEN_UPPER_LINE = 32, + XCHDON_H_OPEN_LOWER_LINE = 33, + // + XCHDON_H_HIGH_UPPER_LINE = 34, + XCHDON_H_HIGH_LOWER_LINE = 35, + // + XCHDON_H_LOW_UPPER_LINE = 36, + XCHDON_H_LOW_LOWER_LINE = 37, + // + XCHDON_H_CLOSE_UPPER_LINE = 38, + XCHDON_H_CLOSE_LOWER_LINE = 39, +}; + +// +// Input Models ... +struct XCHDONInputs +{ + // + // Props ... + + // + // Market ... + int length; // Market Length + + // + // 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 + + // + // Presentation ... + + // + bool showUpper; // Show Upper Band + bool showLower; // Show Lower Band + + // + bool showOpen; // Show Open + bool showHigh; // Show High + bool showClose; // Show Close + bool showLow; // Show Low + + // + bool showCurrent; // Show Current Cycle + bool showShort; // Show Short Cycle + bool showMedium; // Show Medium Cycle + bool showLong; // Show Long Cycle + bool showHind; // Show Hind Cycle + + // + // Constructor(s) ... + XCHDONInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + length = 0; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showUpper = false; + showLower = false; + + // + showOpen = false; + showHigh = false; + showClose = false; + showLow = false; + + // + showCurrent = false; + showShort = false; + showMedium = false; + showLong = false; + showHind = false; + } + + // + // Default ... + void Default() + { + // + length = 52; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showUpper = true; + showLower = true; + + // + showOpen = true; + showHigh = true; + showClose = true; + showLow = true; + + // + showCurrent = true; + showShort = true; + showMedium = true; + showLong = true; + showHind = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 2 + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(result, length); + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHDONConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + // Current ... + double cOpenUpper[]; + double cOpenLower[]; + double cHighUpper[]; + double cHighLower[]; + double cLowUpper[]; + double cLowLower[]; + double cCloseUpper[]; + double cCloseLower[]; + + // + // Short ... + double sOpenUpper[]; + double sOpenLower[]; + double sHighUpper[]; + double sHighLower[]; + double sLowUpper[]; + double sLowLower[]; + double sCloseUpper[]; + double sCloseLower[]; + + // + // Medium ... + double mOpenUpper[]; + double mOpenLower[]; + double mHighUpper[]; + double mHighLower[]; + double mLowUpper[]; + double mLowLower[]; + double mCloseUpper[]; + double mCloseLower[]; + + // + // Long ... + double lOpenUpper[]; + double lOpenLower[]; + double lHighUpper[]; + double lHighLower[]; + double lLowUpper[]; + double lLowLower[]; + double lCloseUpper[]; + double lCloseLower[]; + + // + // Hind ... + double hOpenUpper[]; + double hOpenLower[]; + double hHighUpper[]; + double hHighLower[]; + double hLowUpper[]; + double hLowLower[]; + double hCloseUpper[]; + double hCloseLower[]; + + // + // Conditions ... + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + + // + void Clean() + { + // + // Buffers ... + + // + Clean(cOpenUpper); + Clean(cOpenLower); + Clean(cHighUpper); + Clean(cHighLower); + Clean(cLowUpper); + Clean(cLowLower); + Clean(cCloseUpper); + Clean(cCloseLower); + Clean(sOpenUpper); + Clean(sOpenLower); + Clean(sHighUpper); + Clean(sHighLower); + Clean(sLowUpper); + Clean(sLowLower); + Clean(sCloseUpper); + Clean(sCloseLower); + Clean(mOpenUpper); + Clean(mOpenLower); + Clean(mHighUpper); + Clean(mHighLower); + Clean(mLowUpper); + Clean(mLowLower); + Clean(mCloseUpper); + Clean(mCloseLower); + Clean(lOpenUpper); + Clean(lOpenLower); + Clean(lHighUpper); + Clean(lHighLower); + Clean(lLowUpper); + Clean(lLowLower); + Clean(lCloseUpper); + Clean(lCloseLower); + Clean(hOpenUpper); + Clean(hOpenLower); + Clean(hHighUpper); + Clean(hHighLower); + Clean(hLowUpper); + Clean(hLowLower); + Clean(hCloseUpper); + Clean(hCloseLower); + + // + ArraySetAsSeries(cOpenUpper, true); + ArraySetAsSeries(cOpenLower, true); + ArraySetAsSeries(cHighUpper, true); + ArraySetAsSeries(cHighLower, true); + ArraySetAsSeries(cLowUpper, true); + ArraySetAsSeries(cLowLower, true); + ArraySetAsSeries(cCloseUpper, true); + ArraySetAsSeries(cCloseLower, true); + ArraySetAsSeries(sOpenUpper, true); + ArraySetAsSeries(sOpenLower, true); + ArraySetAsSeries(sHighUpper, true); + ArraySetAsSeries(sHighLower, true); + ArraySetAsSeries(sLowUpper, true); + ArraySetAsSeries(sLowLower, true); + ArraySetAsSeries(sCloseUpper, true); + ArraySetAsSeries(sCloseLower, true); + ArraySetAsSeries(mOpenUpper, true); + ArraySetAsSeries(mOpenLower, true); + ArraySetAsSeries(mHighUpper, true); + ArraySetAsSeries(mHighLower, true); + ArraySetAsSeries(mLowUpper, true); + ArraySetAsSeries(mLowLower, true); + ArraySetAsSeries(mCloseUpper, true); + ArraySetAsSeries(mCloseLower, true); + ArraySetAsSeries(lOpenUpper, true); + ArraySetAsSeries(lOpenLower, true); + ArraySetAsSeries(lHighUpper, true); + ArraySetAsSeries(lHighLower, true); + ArraySetAsSeries(lLowUpper, true); + ArraySetAsSeries(lLowLower, true); + ArraySetAsSeries(lCloseUpper, true); + ArraySetAsSeries(lCloseLower, true); + ArraySetAsSeries(hOpenUpper, true); + ArraySetAsSeries(hOpenLower, true); + ArraySetAsSeries(hHighUpper, true); + ArraySetAsSeries(hHighLower, true); + ArraySetAsSeries(hLowUpper, true); + ArraySetAsSeries(hLowLower, true); + ArraySetAsSeries(hCloseUpper, true); + ArraySetAsSeries(hCloseLower, true); + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Current ... + // + // Short ... + // + // Medium ... + // + // Long ... + // + // Hind ... + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHDON"; + } +}; + +// +// Class ... +class XSCXCHDONHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHDONHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHDONHelper() + { + // + Clean(cOpenUpperBuffer); + Clean(cOpenLowerBuffer); + Clean(cHighUpperBuffer); + Clean(cHighLowerBuffer); + Clean(cLowUpperBuffer); + Clean(cLowLowerBuffer); + Clean(cCloseUpperBuffer); + Clean(cCloseLowerBuffer); + Clean(sOpenUpperBuffer); + Clean(sOpenLowerBuffer); + Clean(sHighUpperBuffer); + Clean(sHighLowerBuffer); + Clean(sLowUpperBuffer); + Clean(sLowLowerBuffer); + Clean(sCloseUpperBuffer); + Clean(sCloseLowerBuffer); + Clean(mOpenUpperBuffer); + Clean(mOpenLowerBuffer); + Clean(mHighUpperBuffer); + Clean(mHighLowerBuffer); + Clean(mLowUpperBuffer); + Clean(mLowLowerBuffer); + Clean(mCloseUpperBuffer); + Clean(mCloseLowerBuffer); + Clean(lOpenUpperBuffer); + Clean(lOpenLowerBuffer); + Clean(lHighUpperBuffer); + Clean(lHighLowerBuffer); + Clean(lLowUpperBuffer); + Clean(lLowLowerBuffer); + Clean(lCloseUpperBuffer); + Clean(lCloseLowerBuffer); + Clean(hOpenUpperBuffer); + Clean(hOpenLowerBuffer); + Clean(hHighUpperBuffer); + Clean(hHighLowerBuffer); + Clean(hLowUpperBuffer); + Clean(hLowLowerBuffer); + Clean(hCloseUpperBuffer); + Clean(hCloseLowerBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHDONInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(cOpenUpperBuffer, true); + ArraySetAsSeries(cOpenLowerBuffer, true); + ArraySetAsSeries(cHighUpperBuffer, true); + ArraySetAsSeries(cHighLowerBuffer, true); + ArraySetAsSeries(cLowUpperBuffer, true); + ArraySetAsSeries(cLowLowerBuffer, true); + ArraySetAsSeries(cCloseUpperBuffer, true); + ArraySetAsSeries(cCloseLowerBuffer, true); + ArraySetAsSeries(sOpenUpperBuffer, true); + ArraySetAsSeries(sOpenLowerBuffer, true); + ArraySetAsSeries(sHighUpperBuffer, true); + ArraySetAsSeries(sHighLowerBuffer, true); + ArraySetAsSeries(sLowUpperBuffer, true); + ArraySetAsSeries(sLowLowerBuffer, true); + ArraySetAsSeries(sCloseUpperBuffer, true); + ArraySetAsSeries(sCloseLowerBuffer, true); + ArraySetAsSeries(mOpenUpperBuffer, true); + ArraySetAsSeries(mOpenLowerBuffer, true); + ArraySetAsSeries(mHighUpperBuffer, true); + ArraySetAsSeries(mHighLowerBuffer, true); + ArraySetAsSeries(mLowUpperBuffer, true); + ArraySetAsSeries(mLowLowerBuffer, true); + ArraySetAsSeries(mCloseUpperBuffer, true); + ArraySetAsSeries(mCloseLowerBuffer, true); + ArraySetAsSeries(lOpenUpperBuffer, true); + ArraySetAsSeries(lOpenLowerBuffer, true); + ArraySetAsSeries(lHighUpperBuffer, true); + ArraySetAsSeries(lHighLowerBuffer, true); + ArraySetAsSeries(lLowUpperBuffer, true); + ArraySetAsSeries(lLowLowerBuffer, true); + ArraySetAsSeries(lCloseUpperBuffer, true); + ArraySetAsSeries(lCloseLowerBuffer, true); + ArraySetAsSeries(hOpenUpperBuffer, true); + ArraySetAsSeries(hOpenLowerBuffer, true); + ArraySetAsSeries(hHighUpperBuffer, true); + ArraySetAsSeries(hHighLowerBuffer, true); + ArraySetAsSeries(hLowUpperBuffer, true); + ArraySetAsSeries(hLowLowerBuffer, true); + ArraySetAsSeries(hCloseUpperBuffer, true); + ArraySetAsSeries(hCloseLowerBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchdon", + // + // Inputs ... + // + // Market ... + "", + mInputs.length, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + // + mInputs.showUpper, // Show Upper Band + mInputs.showLower, // Show Lower Band + // + mInputs.showOpen, // Show Open + mInputs.showHigh, // Show High + mInputs.showClose, // Show Close + mInputs.showLow, // Show Low + // + // Cycles ... + mInputs.showCurrent, // Show Current Cycle + mInputs.showShort, // Show Short Cycle + mInputs.showMedium, // Show Medium Cycle + mInputs.showLong, // Show Long Cycle + mInputs.showHind // Show Hind Cycle + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Buffers ... + + // + // Current ... + + // + // Open ... + + // + double GetCOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCOpenUpper( + 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, + cOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCOpenLower( + 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, + cOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetCHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCHighUpper( + 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, + cHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCHighLower( + 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, + cHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetCLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCLowUpper( + 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, + cLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCLowLower( + 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, + cLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetCCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCCloseUpper( + 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, + cCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return cCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyCCloseLower( + 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, + cCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + // Open ... + + // + double GetSOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySOpenUpper( + 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, + sOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySOpenLower( + 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, + sOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetSHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySHighUpper( + 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, + sHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySHighLower( + 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, + sHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetSLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySLowUpper( + 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, + sLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySLowLower( + 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, + sLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetSCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySCloseUpper( + 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, + sCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return sCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopySCloseLower( + 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, + sCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + // Open ... + + // + double GetMOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMOpenUpper( + 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, + mOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMOpenLower( + 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, + mOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetMHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMHighUpper( + 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, + mHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMHighLower( + 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, + mHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetMLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMLowUpper( + 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, + mLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMLowLower( + 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, + mLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetMCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMCloseUpper( + 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, + mCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return mCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyMCloseLower( + 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, + mCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + // Open ... + + // + double GetLOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLOpenUpper( + 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, + lOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLOpenLower( + 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, + lOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetLHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLHighUpper( + 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, + lHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLHighLower( + 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, + lHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetLLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLLowUpper( + 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, + lLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLLowLower( + 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, + lLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetLCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLCloseUpper( + 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, + lCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return lCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyLCloseLower( + 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, + lCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + // Open ... + + // + double GetHOpenUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hOpenUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHOpenUpper( + 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, + hOpenUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHOpenLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hOpenLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHOpenLower( + 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, + hOpenLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // High ... + + // + double GetHHighUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hHighUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHHighUpper( + 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, + hHighUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHHighLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hHighLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHHighLower( + 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, + hHighLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Low ... + + // + double GetHLowUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hLowUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHLowUpper( + 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, + hLowUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHLowLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hLowLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHLowLower( + 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, + hLowLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Close ... + + // + double GetHCloseUpper( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hCloseUpperBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHCloseUpper( + 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, + hCloseUpperBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHCloseLower( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + return hCloseLowerBuffer[barIndex]; + } + + // + // Copy Required Buffer ... + int CopyHCloseLower( + 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, + hCloseLowerBuffer, + buffer, + forceClean + // + ); + } + + // + // Tools ... + + // + void GetCycleValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES cycle, // Cycle + // + double &openUpper, + double &openLower, + double &highUpper, + double &highLower, + double &lowUpper, + double &lowLower, + double &closeUpper, + double &closeLower // + ) + { + // + openUpper = 0; + openLower = 0; + highUpper = 0; + highLower = 0; + lowUpper = 0; + lowLower = 0; + closeUpper = 0; + closeLower = 0; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + switch (cycle) + { + // + // Current ... + case X_MARKET_CYCLE_UNKNOWN: + // + openUpper = GetCOpenUpper(barIndex); + openLower = GetCOpenLower(barIndex); + highUpper = GetCHighUpper(barIndex); + highLower = GetCHighLower(barIndex); + lowUpper = GetCLowUpper(barIndex); + lowLower = GetCLowLower(barIndex); + closeUpper = GetCCloseUpper(barIndex); + closeLower = GetCCloseLower(barIndex); + break; + + // + // Short ... + case X_MARKET_CYCLE_SHORT: + // + openUpper = GetSOpenUpper(barIndex); + openLower = GetSOpenLower(barIndex); + highUpper = GetSHighUpper(barIndex); + highLower = GetSHighLower(barIndex); + lowUpper = GetSLowUpper(barIndex); + lowLower = GetSLowLower(barIndex); + closeUpper = GetSCloseUpper(barIndex); + closeLower = GetSCloseLower(barIndex); + break; + + // + // Medium ... + case X_MARKET_CYCLE_MEDIUM: + // + openUpper = GetMOpenUpper(barIndex); + openLower = GetMOpenLower(barIndex); + highUpper = GetMHighUpper(barIndex); + highLower = GetMHighLower(barIndex); + lowUpper = GetMLowUpper(barIndex); + lowLower = GetMLowLower(barIndex); + closeUpper = GetMCloseUpper(barIndex); + closeLower = GetMCloseLower(barIndex); + break; + + // + // Long ... + case X_MARKET_CYCLE_LONG: + // + openUpper = GetLOpenUpper(barIndex); + openLower = GetLOpenLower(barIndex); + highUpper = GetLHighUpper(barIndex); + highLower = GetLHighLower(barIndex); + lowUpper = GetLLowUpper(barIndex); + lowLower = GetLLowLower(barIndex); + closeUpper = GetLCloseUpper(barIndex); + closeLower = GetLCloseLower(barIndex); + break; + + // + // Hind ... + case X_MARKET_CYCLE_HIND: + // + openUpper = GetHOpenUpper(barIndex); + openLower = GetHOpenLower(barIndex); + highUpper = GetHHighUpper(barIndex); + highLower = GetHHighLower(barIndex); + lowUpper = GetHLowUpper(barIndex); + lowLower = GetHLowLower(barIndex); + closeUpper = GetHCloseUpper(barIndex); + closeLower = GetHCloseLower(barIndex); + break; + } + } + + // + int GetCyclesUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenUpper, + values // + ); + + // + Add( + iHighUpper, + values // + ); + + // + Add( + iLowUpper, + values // + ); + + // + Add( + iCloseUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesOpenUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesOpenLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesHighUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iHighUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesHighLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iHighLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesLowUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iLowUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesLowLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iLowLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesCloseUpperValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iCloseUpper, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesCloseLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iCloseLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + int GetCyclesLowerValues( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + int result = 0; + + // + double values[]; + + // + int count = ArraySize(cycles); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + double iOpenUpper = 0; + double iOpenLower = 0; + double iHighUpper = 0; + double iHighLower = 0; + double iLowUpper = 0; + double iLowLower = 0; + double iCloseUpper = 0; + double iCloseLower = 0; + GetCycleValues( + barIndex, + cycles[i], + iOpenUpper, + iOpenLower, + iHighUpper, + iHighLower, + iLowUpper, + iLowLower, + iCloseUpper, + iCloseLower // + ); + + // + Add( + iOpenLower, + values // + ); + + // + Add( + iHighLower, + values // + ); + + // + Add( + iLowLower, + values // + ); + + // + Add( + iCloseLower, + values // + ); + } + + // + result = ArraySize(values); + + // + return result; + } + + // + double GetCyclesUpperMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesUpperValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesUpperMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesUpperValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + double GetCyclesLowerMax( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesLowerValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMax(values); + + // + return result; + } + + // + double GetCyclesLowerMin( + int barIndex, // Bar Index + ENUM_X_MARKET_CYCLES &cycles[] // Cycles + ) + { + // + double result = 0; + + // + double values[]; + int count = GetCyclesLowerValues( + barIndex, + cycles // + ); + if (!IsValidSize(count)) + { + return result; + } + + // + result = GetSpecifiedMin(values); + + // + return result; + } + + // + // Conditions ... + + // + bool GetConditions( + XCHDONConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // Current ... + // CopyCTenkanSen( + // zIndex, + // loopback, + // conditions.cTK // + // ); + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Conditions ... + + // + // Current ... + + // + // Short ... + + // + // Medium ... + + // + // Long ... + + // + // Hind ... + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHDONInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // Current ... + double cOpenUpperBuffer[]; + double cOpenLowerBuffer[]; + double cHighUpperBuffer[]; + double cHighLowerBuffer[]; + double cLowUpperBuffer[]; + double cLowLowerBuffer[]; + double cCloseUpperBuffer[]; + double cCloseLowerBuffer[]; + + // + // Short ... + double sOpenUpperBuffer[]; + double sOpenLowerBuffer[]; + double sHighUpperBuffer[]; + double sHighLowerBuffer[]; + double sLowUpperBuffer[]; + double sLowLowerBuffer[]; + double sCloseUpperBuffer[]; + double sCloseLowerBuffer[]; + + // + // Medium ... + double mOpenUpperBuffer[]; + double mOpenLowerBuffer[]; + double mHighUpperBuffer[]; + double mHighLowerBuffer[]; + double mLowUpperBuffer[]; + double mLowLowerBuffer[]; + double mCloseUpperBuffer[]; + double mCloseLowerBuffer[]; + + // + // Long ... + double lOpenUpperBuffer[]; + double lOpenLowerBuffer[]; + double lHighUpperBuffer[]; + double lHighLowerBuffer[]; + double lLowUpperBuffer[]; + double lLowLowerBuffer[]; + double lCloseUpperBuffer[]; + double lCloseLowerBuffer[]; + + // + // Hind ... + double hOpenUpperBuffer[]; + double hOpenLowerBuffer[]; + double hHighUpperBuffer[]; + double hHighLowerBuffer[]; + double hLowUpperBuffer[]; + double hLowLowerBuffer[]; + double hCloseUpperBuffer[]; + double hCloseLowerBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Current ... + CopyBuffer( + mHandler, + XCHDON_C_OPEN_UPPER_LINE, + 0, + totalBars, + cOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_OPEN_LOWER_LINE, + 0, + totalBars, + cOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_HIGH_UPPER_LINE, + 0, + totalBars, + cHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_HIGH_LOWER_LINE, + 0, + totalBars, + cHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_LOW_UPPER_LINE, + 0, + totalBars, + cLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_LOW_LOWER_LINE, + 0, + totalBars, + cLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_CLOSE_UPPER_LINE, + 0, + totalBars, + cCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_C_CLOSE_LOWER_LINE, + 0, + totalBars, + cCloseLowerBuffer // + ); + + // + // Short ... + CopyBuffer( + mHandler, + XCHDON_S_OPEN_UPPER_LINE, + 0, + totalBars, + sOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_OPEN_LOWER_LINE, + 0, + totalBars, + sOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_HIGH_UPPER_LINE, + 0, + totalBars, + sHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_HIGH_LOWER_LINE, + 0, + totalBars, + sHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_LOW_UPPER_LINE, + 0, + totalBars, + sLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_LOW_LOWER_LINE, + 0, + totalBars, + sLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_CLOSE_UPPER_LINE, + 0, + totalBars, + sCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_S_CLOSE_LOWER_LINE, + 0, + totalBars, + sCloseLowerBuffer // + ); + + // + // Medium ... + CopyBuffer( + mHandler, + XCHDON_M_OPEN_UPPER_LINE, + 0, + totalBars, + mOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_OPEN_LOWER_LINE, + 0, + totalBars, + mOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_HIGH_UPPER_LINE, + 0, + totalBars, + mHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_HIGH_LOWER_LINE, + 0, + totalBars, + mHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_LOW_UPPER_LINE, + 0, + totalBars, + mLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_LOW_LOWER_LINE, + 0, + totalBars, + mLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_CLOSE_UPPER_LINE, + 0, + totalBars, + mCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_M_CLOSE_LOWER_LINE, + 0, + totalBars, + mCloseLowerBuffer // + ); + + // + // Long ... + CopyBuffer( + mHandler, + XCHDON_L_OPEN_UPPER_LINE, + 0, + totalBars, + lOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_OPEN_LOWER_LINE, + 0, + totalBars, + lOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_HIGH_UPPER_LINE, + 0, + totalBars, + lHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_HIGH_LOWER_LINE, + 0, + totalBars, + lHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_LOW_UPPER_LINE, + 0, + totalBars, + lLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_LOW_LOWER_LINE, + 0, + totalBars, + lLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_CLOSE_UPPER_LINE, + 0, + totalBars, + lCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_L_CLOSE_LOWER_LINE, + 0, + totalBars, + lCloseLowerBuffer // + ); + + // + // Hind ... + CopyBuffer( + mHandler, + XCHDON_H_OPEN_UPPER_LINE, + 0, + totalBars, + hOpenUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_OPEN_LOWER_LINE, + 0, + totalBars, + hOpenLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_HIGH_UPPER_LINE, + 0, + totalBars, + hHighUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_HIGH_LOWER_LINE, + 0, + totalBars, + hHighLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_LOW_UPPER_LINE, + 0, + totalBars, + hLowUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_LOW_LOWER_LINE, + 0, + totalBars, + hLowLowerBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_CLOSE_UPPER_LINE, + 0, + totalBars, + hCloseUpperBuffer // + ); + CopyBuffer( + mHandler, + XCHDON_H_CLOSE_LOWER_LINE, + 0, + totalBars, + hCloseLowerBuffer // + ); + }; +}; + +// \ No newline at end of file diff --git a/Indicators/x-saherelm.xchdon.mq5 b/Indicators/x-saherelm.xchdon.mq5 new file mode 100644 index 00000000..64f53ece --- /dev/null +++ b/Indicators/x-saherelm.xchdon.mq5 @@ -0,0 +1,1603 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------------- +// Name: XCHDON +// Description: Donchain on Cycles ... +// +// +// 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 XCHDON Indicator" +#property strict + +// +#define ShortName "XCHDON" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +input group "Market"; +input int length = 52; // Market Length + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +input group "Presentation"; + +// +input bool showUpper = true; // Show Upper Band +input bool showLower = true; // Show Lower Band + +// +input bool showOpen = true; // Show Open +input bool showHigh = true; // Show High +input bool showClose = true; // Show Close +input bool showLow = true; // Show Low + +// +input bool showCurrent = true; // Show Current Cycle +input bool showShort = true; // Show Short Cycle +input bool showMedium = true; // Show Medium Cycle +input bool showLong = true; // Show Long Cycle +input bool showHind = true; // Show Hind Cycle + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 40 +#property indicator_plots 40 + +// +// Current ... + +// +// Open ... + +// +#define cOpenUpperBufferIndex 0 +double cOpenUpperBuffer[]; + +// +#property indicator_label1 "XCHDON C O U" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrCornflowerBlue +#property indicator_width1 1 + +// +#define cOpenLowerBufferIndex 1 +double cOpenLowerBuffer[]; + +// +#property indicator_label2 "XCHDON C O L" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrCornflowerBlue +#property indicator_width2 1 + +// +// High ... + +// +#define cHighUpperBufferIndex 2 +double cHighUpperBuffer[]; + +// +#property indicator_label3 "XCHDON C H U" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAquamarine +#property indicator_width3 1 + +// +#define cHighLowerBufferIndex 3 +double cHighLowerBuffer[]; + +// +#property indicator_label4 "XCHDON C H L" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrAquamarine +#property indicator_width4 1 + +// +// Low ... + +// +#define cLowUpperBufferIndex 4 +double cLowUpperBuffer[]; + +// +#property indicator_label5 "XCHDON C L U" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrDarkOrchid +#property indicator_width5 1 + +// +#define cLowLowerBufferIndex 5 +double cLowLowerBuffer[]; + +// +#property indicator_label6 "XCHDON C L L" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrDarkOrchid +#property indicator_width6 1 + +// +// Close ... + +// +#define cCloseUpperBufferIndex 6 +double cCloseUpperBuffer[]; + +// +#property indicator_label7 "XCHDON C C U" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrCoral +#property indicator_width7 1 + +// +#define cCloseLowerBufferIndex 7 +double cCloseLowerBuffer[]; + +// +#property indicator_label8 "XCHDON C C L" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrCoral +#property indicator_width8 1 + +// +// Short ... + +// +// Open ... + +// +#define sOpenUpperBufferIndex 8 +double sOpenUpperBuffer[]; + +// +#property indicator_label9 "XCHDON S O U" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrCornflowerBlue +#property indicator_width9 1 + +// +#define sOpenLowerBufferIndex 9 +double sOpenLowerBuffer[]; + +// +#property indicator_label10 "XCHDON S O L" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrCornflowerBlue +#property indicator_width10 1 + +// +// High ... + +// +#define sHighUpperBufferIndex 10 +double sHighUpperBuffer[]; + +// +#property indicator_label11 "XCHDON S H U" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAquamarine +#property indicator_width11 1 + +// +#define sHighLowerBufferIndex 11 +double sHighLowerBuffer[]; + +// +#property indicator_label12 "XCHDON S H L" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrAquamarine +#property indicator_width12 1 + +// +// Low ... + +// +#define sLowUpperBufferIndex 12 +double sLowUpperBuffer[]; + +// +#property indicator_label13 "XCHDON S L U" +#property indicator_type13 DRAW_LINE +#property indicator_color13 clrDarkOrchid +#property indicator_width13 1 + +// +#define sLowLowerBufferIndex 13 +double sLowLowerBuffer[]; + +// +#property indicator_label14 "XCHDON S L L" +#property indicator_type14 DRAW_LINE +#property indicator_color14 clrDarkOrchid +#property indicator_width14 1 + +// +// Close ... + +// +#define sCloseUpperBufferIndex 14 +double sCloseUpperBuffer[]; + +// +#property indicator_label15 "XCHDON S C U" +#property indicator_type15 DRAW_LINE +#property indicator_color15 clrCoral +#property indicator_width15 1 + +// +#define sCloseLowerBufferIndex 15 +double sCloseLowerBuffer[]; + +// +#property indicator_label16 "XCHDON S C L" +#property indicator_type16 DRAW_LINE +#property indicator_color16 clrCoral +#property indicator_width16 1 + +// +// Medium ... + +// +// Open ... + +// +#define mOpenUpperBufferIndex 16 +double mOpenUpperBuffer[]; + +// +#property indicator_label17 "XCHDON M O U" +#property indicator_type17 DRAW_LINE +#property indicator_color17 clrCornflowerBlue +#property indicator_width17 1 + +// +#define mOpenLowerBufferIndex 17 +double mOpenLowerBuffer[]; + +// +#property indicator_label18 "XCHDON M O L" +#property indicator_type18 DRAW_LINE +#property indicator_color18 clrCornflowerBlue +#property indicator_width18 1 + +// +// High ... + +// +#define mHighUpperBufferIndex 18 +double mHighUpperBuffer[]; + +// +#property indicator_label19 "XCHDON M H U" +#property indicator_type19 DRAW_LINE +#property indicator_color19 clrAquamarine +#property indicator_width19 1 + +// +#define mHighLowerBufferIndex 19 +double mHighLowerBuffer[]; + +// +#property indicator_label20 "XCHDON M H L" +#property indicator_type20 DRAW_LINE +#property indicator_color20 clrAquamarine +#property indicator_width20 1 + +// +// Low ... + +// +#define mLowUpperBufferIndex 20 +double mLowUpperBuffer[]; + +// +#property indicator_label21 "XCHDON M L U" +#property indicator_type21 DRAW_LINE +#property indicator_color21 clrDarkOrchid +#property indicator_width21 1 + +// +#define mLowLowerBufferIndex 21 +double mLowLowerBuffer[]; + +// +#property indicator_label22 "XCHDON M L L" +#property indicator_type22 DRAW_LINE +#property indicator_color22 clrDarkOrchid +#property indicator_width22 1 + +// +// Close ... + +// +#define mCloseUpperBufferIndex 22 +double mCloseUpperBuffer[]; + +// +#property indicator_label23 "XCHDON M C U" +#property indicator_type23 DRAW_LINE +#property indicator_color23 clrCoral +#property indicator_width23 1 + +// +#define mCloseLowerBufferIndex 23 +double mCloseLowerBuffer[]; + +// +#property indicator_label24 "XCHDON M C L" +#property indicator_type24 DRAW_LINE +#property indicator_color24 clrCoral +#property indicator_width24 1 + +// +// Long ... + +// +// Open ... + +// +#define lOpenUpperBufferIndex 24 +double lOpenUpperBuffer[]; + +// +#property indicator_label25 "XCHDON L O U" +#property indicator_type25 DRAW_LINE +#property indicator_color25 clrCornflowerBlue +#property indicator_width25 1 + +// +#define lOpenLowerBufferIndex 25 +double lOpenLowerBuffer[]; + +// +#property indicator_label26 "XCHDON L O L" +#property indicator_type26 DRAW_LINE +#property indicator_color26 clrCornflowerBlue +#property indicator_width26 1 + +// +// High ... + +// +#define lHighUpperBufferIndex 26 +double lHighUpperBuffer[]; + +// +#property indicator_label27 "XCHDON L H U" +#property indicator_type27 DRAW_LINE +#property indicator_color27 clrAquamarine +#property indicator_width27 1 + +// +#define lHighLowerBufferIndex 27 +double lHighLowerBuffer[]; + +// +#property indicator_label28 "XCHDON L H L" +#property indicator_type28 DRAW_LINE +#property indicator_color28 clrAquamarine +#property indicator_width28 1 + +// +// Low ... + +// +#define lLowUpperBufferIndex 28 +double lLowUpperBuffer[]; + +// +#property indicator_label29 "XCHDON L L U" +#property indicator_type29 DRAW_LINE +#property indicator_color29 clrDarkOrchid +#property indicator_width29 1 + +// +#define lLowLowerBufferIndex 29 +double lLowLowerBuffer[]; + +// +#property indicator_label30 "XCHDON L L L" +#property indicator_type30 DRAW_LINE +#property indicator_color30 clrDarkOrchid +#property indicator_width30 1 + +// +// Close ... + +// +#define lCloseUpperBufferIndex 30 +double lCloseUpperBuffer[]; + +// +#property indicator_label31 "XCHDON L C U" +#property indicator_type31 DRAW_LINE +#property indicator_color31 clrCoral +#property indicator_width31 1 + +// +#define lCloseLowerBufferIndex 31 +double lCloseLowerBuffer[]; + +// +#property indicator_label32 "XCHDON L C L" +#property indicator_type32 DRAW_LINE +#property indicator_color32 clrCoral +#property indicator_width32 1 + +// +// Hind ... + +// +// Open ... + +// +#define hOpenUpperBufferIndex 32 +double hOpenUpperBuffer[]; + +// +#property indicator_label33 "XCHDON H O U" +#property indicator_type33 DRAW_LINE +#property indicator_color33 clrCornflowerBlue +#property indicator_width33 1 + +// +#define hOpenLowerBufferIndex 33 +double hOpenLowerBuffer[]; + +// +#property indicator_label34 "XCHDON H O L" +#property indicator_type34 DRAW_LINE +#property indicator_color34 clrCornflowerBlue +#property indicator_width34 1 + +// +// High ... + +// +#define hHighUpperBufferIndex 34 +double hHighUpperBuffer[]; + +// +#property indicator_label35 "XCHDON H H U" +#property indicator_type35 DRAW_LINE +#property indicator_color35 clrAquamarine +#property indicator_width35 1 + +// +#define hHighLowerBufferIndex 35 +double hHighLowerBuffer[]; + +// +#property indicator_label36 "XCHDON H H L" +#property indicator_type36 DRAW_LINE +#property indicator_color36 clrAquamarine +#property indicator_width36 1 + +// +// Low ... + +// +#define hLowUpperBufferIndex 36 +double hLowUpperBuffer[]; + +// +#property indicator_label37 "XCHDON H L U" +#property indicator_type37 DRAW_LINE +#property indicator_color37 clrDarkOrchid +#property indicator_width37 1 + +// +#define hLowLowerBufferIndex 37 +double hLowLowerBuffer[]; + +// +#property indicator_label38 "XCHDON H L L" +#property indicator_type38 DRAW_LINE +#property indicator_color38 clrDarkOrchid +#property indicator_width38 1 + +// +// Close ... + +// +#define hCloseUpperBufferIndex 38 +double hCloseUpperBuffer[]; + +// +#property indicator_label39 "XCHDON H C U" +#property indicator_type39 DRAW_LINE +#property indicator_color39 clrCoral +#property indicator_width39 1 + +// +#define hCloseLowerBufferIndex 39 +double hCloseLowerBuffer[]; + +// +#property indicator_label40 "XCHDON H C L" +#property indicator_type40 DRAW_LINE +#property indicator_color40 clrCoral +#property indicator_width40 1 + +// +// Variables, Properties and etc ... + +// +int maxLength; + +// +// Current ... +int mCMarketLength = length; + +// +// Short ... +int mSCycleLength = 0; +int mSMarketLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; + +// +// Medium ... +int mMCycleLength = 0; +int mMMarketLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; + +// +// Long ... +int mLCycleLength = 0; +int mLMarketLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; + +// +// Hind ... +int mHCycleLength = 0; +int mHMarketLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // 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(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +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 +} + +// +// Calculating what we want ... +int OnCalculate( + 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 ... +) +{ + // + if (rates_total < maxLength - 1) + { + return prev_calculated; + } + + // + int start = prev_calculated == 0 + ? maxLength + : prev_calculated - 1; + + // + // Main Loop ... + for (int i = start; i < rates_total; i++) + { + // + CalculateBuffers( + // + i, + prev_calculated, + rates_total, + // + open, + high, + close, + low, + tick_volume + // + ); + } + + // + return rates_total; +} + +// +// Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = false; + + // + result = + // + length > 2 + // + && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Initialize Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCycleLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSMarketLength = mSCycleLength * mCMarketLength; + result = mSCycleLength > 0; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCycleLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMMarketLength = mMCycleLength * mCMarketLength; + result = mMCycleLength > 0; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCycleLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLMarketLength = mLCycleLength * mCMarketLength; + result = mLCycleLength > 0; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCycleLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHMarketLength = mHCycleLength * mCMarketLength; + result = mHCycleLength > 0; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(mCMarketLength, mSMarketLength); + result = MathMax(result, mMMarketLength); + result = MathMax(result, mLMarketLength); + result = MathMax(result, mHMarketLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // CURRENT ... + + // + // Open ... + + // + // UPPER ... + bool canShowCOpenUpper = showUpper && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenUpperDrawType = canShowCOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenUpperBufferIndex, cOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowCOpenUpper); + PlotIndexSetInteger(cOpenUpperBufferIndex, PLOT_DRAW_TYPE, cOpenUpperDrawType); + + // + // LOWER ... + bool canShowCOpenLower = showLower && showOpen && showCurrent; + ENUM_DRAW_TYPE cOpenLowerDrawType = canShowCOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cOpenLowerBufferIndex, cOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowCOpenLower); + PlotIndexSetInteger(cOpenLowerBufferIndex, PLOT_DRAW_TYPE, cOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowCCloseUpper = showUpper && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseUpperDrawType = canShowCCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseUpperBufferIndex, cCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowCCloseUpper); + PlotIndexSetInteger(cCloseUpperBufferIndex, PLOT_DRAW_TYPE, cCloseUpperDrawType); + + // + // LOWER ... + bool canShowCCloseLower = showLower && showClose && showCurrent; + ENUM_DRAW_TYPE cCloseLowerDrawType = canShowCCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cCloseLowerBufferIndex, cCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowCCloseLower); + PlotIndexSetInteger(cCloseLowerBufferIndex, PLOT_DRAW_TYPE, cCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowCHighUpper = showUpper && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighUpperDrawType = canShowCHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighUpperBufferIndex, cHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_SHOW_DATA, canShowCHighUpper); + PlotIndexSetInteger(cHighUpperBufferIndex, PLOT_DRAW_TYPE, cHighUpperDrawType); + + // + // LOWER ... + bool canShowCHighLower = showLower && showHigh && showCurrent; + ENUM_DRAW_TYPE cHighLowerDrawType = canShowCHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cHighLowerBufferIndex, cHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_SHOW_DATA, canShowCHighLower); + PlotIndexSetInteger(cHighLowerBufferIndex, PLOT_DRAW_TYPE, cHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowCLowUpper = showUpper && showLow && showCurrent; + ENUM_DRAW_TYPE cLowUpperDrawType = canShowCLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowUpperBufferIndex, cLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_SHOW_DATA, canShowCLowUpper); + PlotIndexSetInteger(cLowUpperBufferIndex, PLOT_DRAW_TYPE, cLowUpperDrawType); + + // + // LOWER ... + bool canShowCLowLower = showLower && showLow && showCurrent; + ENUM_DRAW_TYPE cLowLowerDrawType = canShowCLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(cLowLowerBufferIndex, cLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_SHOW_DATA, canShowCLowLower); + PlotIndexSetInteger(cLowLowerBufferIndex, PLOT_DRAW_TYPE, cLowLowerDrawType); + + // + // SHORT ... + + // + // Open ... + + // + // UPPER ... + bool canShowSOpenUpper = showUpper && showOpen && showShort; + ENUM_DRAW_TYPE sOpenUpperDrawType = canShowSOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenUpperBufferIndex, sOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowSOpenUpper); + PlotIndexSetInteger(sOpenUpperBufferIndex, PLOT_DRAW_TYPE, sOpenUpperDrawType); + + // + // LOWER ... + bool canShowSOpenLower = showLower && showOpen && showShort; + ENUM_DRAW_TYPE sOpenLowerDrawType = canShowSOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sOpenLowerBufferIndex, sOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowSOpenLower); + PlotIndexSetInteger(sOpenLowerBufferIndex, PLOT_DRAW_TYPE, sOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowSCloseUpper = showUpper && showClose && showShort; + ENUM_DRAW_TYPE sCloseUpperDrawType = canShowSCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseUpperBufferIndex, sCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowSCloseUpper); + PlotIndexSetInteger(sCloseUpperBufferIndex, PLOT_DRAW_TYPE, sCloseUpperDrawType); + + // + // LOWER ... + bool canShowSCloseLower = showLower && showClose && showShort; + ENUM_DRAW_TYPE sCloseLowerDrawType = canShowSCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sCloseLowerBufferIndex, sCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowSCloseLower); + PlotIndexSetInteger(sCloseLowerBufferIndex, PLOT_DRAW_TYPE, sCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowSHighUpper = showUpper && showHigh && showShort; + ENUM_DRAW_TYPE sHighUpperDrawType = canShowSHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighUpperBufferIndex, sHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_SHOW_DATA, canShowSHighUpper); + PlotIndexSetInteger(sHighUpperBufferIndex, PLOT_DRAW_TYPE, sHighUpperDrawType); + + // + // LOWER ... + bool canShowSHighLower = showLower && showHigh && showShort; + ENUM_DRAW_TYPE sHighLowerDrawType = canShowSHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sHighLowerBufferIndex, sHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_SHOW_DATA, canShowSHighLower); + PlotIndexSetInteger(sHighLowerBufferIndex, PLOT_DRAW_TYPE, sHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowSLowUpper = showUpper && showLow && showShort; + ENUM_DRAW_TYPE sLowUpperDrawType = canShowSLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowUpperBufferIndex, sLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_SHOW_DATA, canShowSLowUpper); + PlotIndexSetInteger(sLowUpperBufferIndex, PLOT_DRAW_TYPE, sLowUpperDrawType); + + // + // LOWER ... + bool canShowSLowLower = showLower && showLow && showShort; + ENUM_DRAW_TYPE sLowLowerDrawType = canShowSLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(sLowLowerBufferIndex, sLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_SHOW_DATA, canShowSLowLower); + PlotIndexSetInteger(sLowLowerBufferIndex, PLOT_DRAW_TYPE, sLowLowerDrawType); + + // + // MEDIUM ... + + // + // Open ... + + // + // UPPER ... + bool canShowMOpenUpper = showUpper && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenUpperDrawType = canShowMOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenUpperBufferIndex, mOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowMOpenUpper); + PlotIndexSetInteger(mOpenUpperBufferIndex, PLOT_DRAW_TYPE, mOpenUpperDrawType); + + // + // LOWER ... + bool canShowMOpenLower = showLower && showOpen && showMedium; + ENUM_DRAW_TYPE mOpenLowerDrawType = canShowMOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mOpenLowerBufferIndex, mOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowMOpenLower); + PlotIndexSetInteger(mOpenLowerBufferIndex, PLOT_DRAW_TYPE, mOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowMCloseUpper = showUpper && showClose && showMedium; + ENUM_DRAW_TYPE mCloseUpperDrawType = canShowMCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseUpperBufferIndex, mCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowMCloseUpper); + PlotIndexSetInteger(mCloseUpperBufferIndex, PLOT_DRAW_TYPE, mCloseUpperDrawType); + + // + // LOWER ... + bool canShowMCloseLower = showLower && showClose && showMedium; + ENUM_DRAW_TYPE mCloseLowerDrawType = canShowMCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mCloseLowerBufferIndex, mCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowMCloseLower); + PlotIndexSetInteger(mCloseLowerBufferIndex, PLOT_DRAW_TYPE, mCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowMHighUpper = showUpper && showHigh && showMedium; + ENUM_DRAW_TYPE mHighUpperDrawType = canShowMHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighUpperBufferIndex, mHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_SHOW_DATA, canShowMHighUpper); + PlotIndexSetInteger(mHighUpperBufferIndex, PLOT_DRAW_TYPE, mHighUpperDrawType); + + // + // LOWER ... + bool canShowMHighLower = showLower && showHigh && showMedium; + ENUM_DRAW_TYPE mHighLowerDrawType = canShowMHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mHighLowerBufferIndex, mHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_SHOW_DATA, canShowMHighLower); + PlotIndexSetInteger(mHighLowerBufferIndex, PLOT_DRAW_TYPE, mHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowMLowUpper = showUpper && showLow && showMedium; + ENUM_DRAW_TYPE mLowUpperDrawType = canShowMLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowUpperBufferIndex, mLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_SHOW_DATA, canShowMLowUpper); + PlotIndexSetInteger(mLowUpperBufferIndex, PLOT_DRAW_TYPE, mLowUpperDrawType); + + // + // LOWER ... + bool canShowMLowLower = showLower && showLow && showMedium; + ENUM_DRAW_TYPE mLowLowerDrawType = canShowMLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(mLowLowerBufferIndex, mLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_SHOW_DATA, canShowMLowLower); + PlotIndexSetInteger(mLowLowerBufferIndex, PLOT_DRAW_TYPE, mLowLowerDrawType); + + // + // LONG ... + + // + // Open ... + + // + // UPPER ... + bool canShowLOpenUpper = showUpper && showOpen && showLong; + ENUM_DRAW_TYPE lOpenUpperDrawType = canShowLOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenUpperBufferIndex, lOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowLOpenUpper); + PlotIndexSetInteger(lOpenUpperBufferIndex, PLOT_DRAW_TYPE, lOpenUpperDrawType); + + // + // LOWER ... + bool canShowLOpenLower = showLower && showOpen && showLong; + ENUM_DRAW_TYPE lOpenLowerDrawType = canShowLOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lOpenLowerBufferIndex, lOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowLOpenLower); + PlotIndexSetInteger(lOpenLowerBufferIndex, PLOT_DRAW_TYPE, lOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowLCloseUpper = showUpper && showClose && showLong; + ENUM_DRAW_TYPE lCloseUpperDrawType = canShowLCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseUpperBufferIndex, lCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowLCloseUpper); + PlotIndexSetInteger(lCloseUpperBufferIndex, PLOT_DRAW_TYPE, lCloseUpperDrawType); + + // + // LOWER ... + bool canShowLCloseLower = showLower && showClose && showLong; + ENUM_DRAW_TYPE lCloseLowerDrawType = canShowLCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lCloseLowerBufferIndex, lCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowLCloseLower); + PlotIndexSetInteger(lCloseLowerBufferIndex, PLOT_DRAW_TYPE, lCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowLHighUpper = showUpper && showHigh && showLong; + ENUM_DRAW_TYPE lHighUpperDrawType = canShowLHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighUpperBufferIndex, lHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_SHOW_DATA, canShowLHighUpper); + PlotIndexSetInteger(lHighUpperBufferIndex, PLOT_DRAW_TYPE, lHighUpperDrawType); + + // + // LOWER ... + bool canShowLHighLower = showLower && showHigh && showLong; + ENUM_DRAW_TYPE lHighLowerDrawType = canShowLHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lHighLowerBufferIndex, lHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_SHOW_DATA, canShowLHighLower); + PlotIndexSetInteger(lHighLowerBufferIndex, PLOT_DRAW_TYPE, lHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowLLowUpper = showUpper && showLow && showLong; + ENUM_DRAW_TYPE lLowUpperDrawType = canShowLLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowUpperBufferIndex, lLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_SHOW_DATA, canShowLLowUpper); + PlotIndexSetInteger(lLowUpperBufferIndex, PLOT_DRAW_TYPE, lLowUpperDrawType); + + // + // LOWER ... + bool canShowLLowLower = showLower && showLow && showLong; + ENUM_DRAW_TYPE lLowLowerDrawType = canShowLLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(lLowLowerBufferIndex, lLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_SHOW_DATA, canShowLLowLower); + PlotIndexSetInteger(lLowLowerBufferIndex, PLOT_DRAW_TYPE, lLowLowerDrawType); + + // + // HIND ... + + // + // Open ... + + // + // UPPER ... + bool canShowHOpenUpper = showUpper && showOpen && showHind; + ENUM_DRAW_TYPE hOpenUpperDrawType = canShowHOpenUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenUpperBufferIndex, hOpenUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_SHOW_DATA, canShowHOpenUpper); + PlotIndexSetInteger(hOpenUpperBufferIndex, PLOT_DRAW_TYPE, hOpenUpperDrawType); + + // + // LOWER ... + bool canShowHOpenLower = showLower && showOpen && showHind; + ENUM_DRAW_TYPE hOpenLowerDrawType = canShowHOpenLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hOpenLowerBufferIndex, hOpenLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hOpenLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_SHOW_DATA, canShowHOpenLower); + PlotIndexSetInteger(hOpenLowerBufferIndex, PLOT_DRAW_TYPE, hOpenLowerDrawType); + + // + // Close ... + + // + // UPPER ... + bool canShowHCloseUpper = showUpper && showClose && showHind; + ENUM_DRAW_TYPE hCloseUpperDrawType = canShowHCloseUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseUpperBufferIndex, hCloseUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_SHOW_DATA, canShowHCloseUpper); + PlotIndexSetInteger(hCloseUpperBufferIndex, PLOT_DRAW_TYPE, hCloseUpperDrawType); + + // + // LOWER ... + bool canShowHCloseLower = showLower && showClose && showHind; + ENUM_DRAW_TYPE hCloseLowerDrawType = canShowHCloseLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hCloseLowerBufferIndex, hCloseLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hCloseLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_SHOW_DATA, canShowHCloseLower); + PlotIndexSetInteger(hCloseLowerBufferIndex, PLOT_DRAW_TYPE, hCloseLowerDrawType); + + // + // High ... + + // + // UPPER ... + bool canShowHHighUpper = showUpper && showHigh && showHind; + ENUM_DRAW_TYPE hHighUpperDrawType = canShowHHighUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighUpperBufferIndex, hHighUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_SHOW_DATA, canShowHHighUpper); + PlotIndexSetInteger(hHighUpperBufferIndex, PLOT_DRAW_TYPE, hHighUpperDrawType); + + // + // LOWER ... + bool canShowHHighLower = showLower && showHigh && showHind; + ENUM_DRAW_TYPE hHighLowerDrawType = canShowHHighLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hHighLowerBufferIndex, hHighLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hHighLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_SHOW_DATA, canShowHHighLower); + PlotIndexSetInteger(hHighLowerBufferIndex, PLOT_DRAW_TYPE, hHighLowerDrawType); + + // + // Low ... + + // + // UPPER ... + bool canShowHLowUpper = showUpper && showLow && showHind; + ENUM_DRAW_TYPE hLowUpperDrawType = canShowHLowUpper ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowUpperBufferIndex, hLowUpperBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_SHOW_DATA, canShowHLowUpper); + PlotIndexSetInteger(hLowUpperBufferIndex, PLOT_DRAW_TYPE, hLowUpperDrawType); + + // + // LOWER ... + bool canShowHLowLower = showLower && showLow && showHind; + ENUM_DRAW_TYPE hLowLowerDrawType = canShowHLowLower ? DRAW_LINE : DRAW_NONE; + SetIndexBuffer(hLowLowerBufferIndex, hLowLowerBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hLowLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_SHOW_DATA, canShowHLowLower); + PlotIndexSetInteger(hLowLowerBufferIndex, PLOT_DRAW_TYPE, hLowLowerDrawType); +} + +// +// Calculations ... + +// +// Calculate Buffers ... +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[] // +) +{ + // + CalculateCycles( + bar_index, + prevCalculated, + ratesTotal, + open, + high, + close, + low, + tickVolume // + ); +} + +// +void CalculateCycles( + 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[] // +) +{ + // + // CURRENT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mCMarketLength, + // + cOpenUpperBuffer, + cOpenLowerBuffer, + cHighUpperBuffer, + cHighLowerBuffer, + cLowUpperBuffer, + cLowLowerBuffer, + cCloseUpperBuffer, + cCloseLowerBuffer // + ); + + // + // SHORT ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mSMarketLength, + // + sOpenUpperBuffer, + sOpenLowerBuffer, + sHighUpperBuffer, + sHighLowerBuffer, + sLowUpperBuffer, + sLowLowerBuffer, + sCloseUpperBuffer, + sCloseLowerBuffer // + ); + + // + // MEDIUM ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mMMarketLength, + // + mOpenUpperBuffer, + mOpenLowerBuffer, + mHighUpperBuffer, + mHighLowerBuffer, + mLowUpperBuffer, + mLowLowerBuffer, + mCloseUpperBuffer, + mCloseLowerBuffer // + ); + + // + // LONG ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mLMarketLength, + // + lOpenUpperBuffer, + lOpenLowerBuffer, + lHighUpperBuffer, + lHighLowerBuffer, + lLowUpperBuffer, + lLowLowerBuffer, + lCloseUpperBuffer, + lCloseLowerBuffer // + ); + + // + // HIND ... + CalculateCycle( + // + bar_index, + prevCalculated, + ratesTotal, + // + open, + high, + close, + low, + tickVolume, + // + mHMarketLength, + // + hOpenUpperBuffer, + hOpenLowerBuffer, + hHighUpperBuffer, + hHighLowerBuffer, + hLowUpperBuffer, + hLowLowerBuffer, + hCloseUpperBuffer, + hCloseLowerBuffer // + ); +} + +// +void CalculateCycle( + 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 _length, + // + double &_ouBuffer[], + double &_olBuffer[], + double &_huBuffer[], + double &_hlBuffer[], + double &_luBuffer[], + double &_llBuffer[], + double &_cuBuffer[], + double &_clBuffer[] // +) +{ + // + double iUpper = 0; + double iLower = 0; + + // + // OPEN ... + + // + iUpper = open[ArrayMaximum(open, bar_index - _length + 1, _length)]; + iLower = open[ArrayMinimum(open, bar_index - _length + 1, _length)]; + + // + _ouBuffer[bar_index] = iUpper; + _olBuffer[bar_index] = iLower; + + // + // HIGH ... + + // + iUpper = high[ArrayMaximum(high, bar_index - _length + 1, _length)]; + iLower = high[ArrayMinimum(high, bar_index - _length + 1, _length)]; + + // + _huBuffer[bar_index] = iUpper; + _hlBuffer[bar_index] = iLower; + + // + // LOW ... + + // + iUpper = low[ArrayMaximum(low, bar_index - _length + 1, _length)]; + iLower = low[ArrayMinimum(low, bar_index - _length + 1, _length)]; + + // + _luBuffer[bar_index] = iUpper; + _llBuffer[bar_index] = iLower; + + // + // CLOSE ... + + // + iUpper = close[ArrayMaximum(close, bar_index - _length + 1, _length)]; + iLower = close[ArrayMinimum(close, bar_index - _length + 1, _length)]; + + // + _cuBuffer[bar_index] = iUpper; + _clBuffer[bar_index] = iLower; +} + +// \ No newline at end of file