/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXDONHelper // Description: provides all Indicator // Helper requirements ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Imports ... #include "../Classes/x-saherelm.xhelper.class.mq5" // // Definitions ... // enum ENUM_XDON_BUFFERS { // // Open ... XDON_UPPER_O_LINE = 0, XDON_LOWER_O_LINE = 1, // // Close ... XDON_UPPER_C_LINE = 2, XDON_LOWER_C_LINE = 3, // // High ... XDON_UPPER_H_LINE = 4, XDON_LOWER_H_LINE = 5, // // Low ... XDON_UPPER_L_LINE = 6, XDON_LOWER_L_LINE = 7, }; // // Input Models ... struct XDONInputs { // // Props ... // // Market ... int length; // Market Length double offset; // Offset // // Presentation ... bool showOpen; // Show Open bool showHigh; // Show High bool showClose; // Show Close bool showLow; // Show Low // // Constructor(s) ... XDONInputs() { // Clean(); } // // Tools ... // // Clean ... void Clean() { // // Market ... length = 0; offset = 0; // // Presentation ... showOpen = false; showHigh = false; showClose = false; showLow = false; } // // Default ... void Default() { // // Market ... length = 52; offset = 0; // // Presentation ... showOpen = true; showHigh = true; showClose = true; showLow = true; } // // Validate ... bool IsValid() { // bool result = false; // result = // length >= 5 && offset >= 0 // ; // return result; } // // Retrieve MAx Length ... int Max() { // int result = 0; // result = MathMax(0, length); // return result; } }; // // Class ... class XSCXDONHelper : public XSCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XSCXDONHelper() : XSCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XSCXDONHelper() { // Clean(upperOBuffer); Clean(lowerOBuffer); Clean(upperCBuffer); Clean(lowerCBuffer); Clean(upperHBuffer); Clean(lowerHBuffer); Clean(upperLBuffer); Clean(lowerLBuffer); } // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period XDONInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // mInputs = inputs; // ArraySetAsSeries(upperOBuffer, true); ArraySetAsSeries(lowerOBuffer, true); ArraySetAsSeries(upperCBuffer, true); ArraySetAsSeries(lowerCBuffer, true); ArraySetAsSeries(upperHBuffer, true); ArraySetAsSeries(lowerHBuffer, true); ArraySetAsSeries(upperLBuffer, true); ArraySetAsSeries(lowerLBuffer, true); // mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.xdon", // // Inputs ... // // Market ... "", mInputs.length, // Market Length mInputs.offset, // Offset // // Presentation ... "", mInputs.showOpen, // Show Open mInputs.showHigh, // Show High mInputs.showClose, // Show Close mInputs.showLow // Show Low // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // XDONInputs GetInputs() { return mInputs; } // bool SetInputs( XDONInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Buffers ... // // Open ... // // Upper ... // double GetUpperO( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(upperOBuffer); if (barIndex >= count) { barIndex = count - 1; } // return upperOBuffer[barIndex]; } // // Copy Required Items ... int CopyUpperO( 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, upperOBuffer, buffer, forceClean // ); } // bool IsSameUpperO( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( upperOBuffer, verifier, barIndex // ); } // // Lower ... // double GetLowerO( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(lowerOBuffer); if (barIndex >= count) { barIndex = count - 1; } // return lowerOBuffer[barIndex]; } // // Copy Required Items ... int CopyLowerO( 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, lowerOBuffer, buffer, forceClean // ); } // bool IsSameLowerO( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( lowerOBuffer, verifier, barIndex // ); } // // Close ... // // Upper ... // double GetUpperC( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(upperCBuffer); if (barIndex >= count) { barIndex = count - 1; } // return upperCBuffer[barIndex]; } // // Copy Required Items ... int CopyUpperC( 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, upperCBuffer, buffer, forceClean // ); } // bool IsSameUpperC( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( upperCBuffer, verifier, barIndex // ); } // // Lower ... // double GetLowerC( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(lowerCBuffer); if (barIndex >= count) { barIndex = count - 1; } // return lowerCBuffer[barIndex]; } // // Copy Required Items ... int CopyLowerC( 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, lowerCBuffer, buffer, forceClean // ); } // bool IsSameLowerC( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( lowerCBuffer, verifier, barIndex // ); } // // High ... // // Upper ... // double GetUpperH( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(upperHBuffer); if (barIndex >= count) { barIndex = count - 1; } // return upperHBuffer[barIndex]; } // // Copy Required Items ... int CopyUpperH( 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, upperHBuffer, buffer, forceClean // ); } // bool IsSameUpperH( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( upperHBuffer, verifier, barIndex // ); } // // Lower ... // double GetLowerH( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(lowerHBuffer); if (barIndex >= count) { barIndex = count - 1; } // return lowerHBuffer[barIndex]; } // // Copy Required Items ... int CopyLowerH( 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, lowerHBuffer, buffer, forceClean // ); } // bool IsSameLowerH( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( lowerHBuffer, verifier, barIndex // ); } // // Low ... // // Upper ... // double GetUpperL( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(upperLBuffer); if (barIndex >= count) { barIndex = count - 1; } // return upperLBuffer[barIndex]; } // // Copy Required Items ... int CopyUpperL( 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, upperLBuffer, buffer, forceClean // ); } // bool IsSameUpperL( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( upperLBuffer, verifier, barIndex // ); } // // Lower ... // double GetLowerL( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(lowerLBuffer); if (barIndex >= count) { barIndex = count - 1; } // return lowerLBuffer[barIndex]; } // // Copy Required Items ... int CopyLowerL( 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, lowerLBuffer, buffer, forceClean // ); } // bool IsSameLowerL( int barIndex, // Start Bar Index int verifier = 71 // Number of Verifiers ) { // // Update Calculations ... Calculate(); // return IsSame( lowerLBuffer, verifier, barIndex // ); } // void GetUppers( double &result[], int barIndex = 0 // ) { // Clean(result); // double uo = GetUpperO(barIndex); double uc = GetUpperC(barIndex); double uh = GetUpperH(barIndex); double ul = GetUpperL(barIndex); // Add(uo, result); Add(uc, result); Add(uh, result); Add(ul, result); } double GetMinUpper( int barIndex = 0 // ) { // double values[]; GetUppers(values); // double result = GetMin(values); // return result; } double GetMaxUpper( int barIndex = 0 // ) { // double values[]; GetUppers(values); // double result = GetMax(values); // return result; } // void GetLowers( double &result[], int barIndex = 0 // ) { // Clean(result); // double lo = GetLowerO(barIndex); double lc = GetLowerC(barIndex); double lh = GetLowerH(barIndex); double ll = GetLowerL(barIndex); // Add(lo, result); Add(lc, result); Add(lh, result); Add(ll, result); } double GetMinLower( int barIndex = 0 // ) { // double values[]; GetLowers(values); // double result = GetMin(values); // return result; } double GetMaxLower( int barIndex = 0 // ) { // double values[]; GetLowers(values); // double result = GetMin(values); // return result; } // // Protected ... protected: // // Private ... private: // // Props ... XDONInputs mInputs; // Inputs ... // // Buffers ... double upperOBuffer[]; double lowerOBuffer[]; double upperCBuffer[]; double lowerCBuffer[]; double upperHBuffer[]; double lowerHBuffer[]; double upperLBuffer[]; double lowerLBuffer[]; // // Tools ... // // Calculate Values Until Now ... void Calculate() { // int totalBars = CountBars(); if (totalBars > 1000) { totalBars = 1000; } // // Open ... // // Upper Buffer ... CopyBuffer( mHandler, XDON_UPPER_O_LINE, 0, totalBars, upperOBuffer // ); // // Lower Buffer ... CopyBuffer( mHandler, XDON_LOWER_O_LINE, 0, totalBars, lowerOBuffer // ); // // Close ... // // Upper Buffer ... CopyBuffer( mHandler, XDON_UPPER_C_LINE, 0, totalBars, upperCBuffer // ); // // Lower Buffer ... CopyBuffer( mHandler, XDON_LOWER_C_LINE, 0, totalBars, lowerCBuffer // ); // // High ... // // Upper Buffer ... CopyBuffer( mHandler, XDON_UPPER_H_LINE, 0, totalBars, upperHBuffer // ); // // Lower Buffer ... CopyBuffer( mHandler, XDON_LOWER_H_LINE, 0, totalBars, lowerHBuffer // ); // // Low ... // // Upper Buffer ... CopyBuffer( mHandler, XDON_UPPER_L_LINE, 0, totalBars, upperLBuffer // ); // // Lower Buffer ... CopyBuffer( mHandler, XDON_LOWER_L_LINE, 0, totalBars, lowerLBuffer // ); } }; // // Tools ...