/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXTDHelper // 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_XTD_BUFFERS { XTD_BULLISH_LINE = 0, XTD_BEARISH_LINE = 1, XTD_SIGNAL_LINE = 2, }; // // Input Models ... struct XTDInputs { // // Props ... // int length; // Market Length bool drawCrosses; // Draw Cross Arrows // // Bullish ... uchar bullishArrowCode; // Cross Over Arrow Code color bullishArrowColor; // Cross Over Arrow Color // // Bearish ... uchar bearishArrowCode; // Cross Under Arrow Code color bearishArrowColor; // Cross Under Arrow Color // // Constructor(s) ... XTDInputs() { // Clean(); } // // Tools ... // // Clean ... void Clean() { // length = 0; drawCrosses = false; // // Bullish ... bullishArrowCode = 228; bullishArrowColor = CLR_NONE; // // Bearish ... bearishArrowCode = 230; bearishArrowColor = CLR_NONE; } // // Default ... void Default() { // length = 14; drawCrosses = false; // // Bullish ... bullishArrowCode = 228; bullishArrowColor = CLR_NONE; // // Bearish ... bearishArrowCode = 230; bearishArrowColor = CLR_NONE; } // // Validate ... bool IsValid() { // bool result = false; // result = // length >= 2 // ; // return result; } // // Retrieve MAx Length ... int Max() { // int result = 0; // result = MathMax(result, length); // return result; } }; // // Define Conditions ... struct XTDConditions { // // Common ... string symbol; ENUM_TIMEFRAMES period; datetime time; // // Buffers ... double bullish[]; double bearish[]; // // Conditions ... // bool isBullish; bool isBearish; bool isSwitchedToBullish; bool isSwitchedToBearish; // void Clean() { // Clean(bullish); Clean(bearish); // ArraySetAsSeries(bullish, true); ArraySetAsSeries(bearish, true); // isBullish = false; isBearish = false; isSwitchedToBullish = false; isSwitchedToBearish = false; } // void GenerateScore( double &bullishScore, double &bearishScore // ) { // bullishScore = 0; bearishScore = 0; // if (isBullish) { bullishScore++; } if (isSwitchedToBullish) { bullishScore++; } // if (isBearish) { bearishScore++; } if (isSwitchedToBearish) { bearishScore++; } } // 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 = // ToString("isBullish", isBullish, ignoreFalseConditions, separator) + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + "" // ; // result = // "[" + GetTag() + "]" + separator + (onlyConditions ? "" : commonStr) + (!includeScores ? "" : scoresStr) + " " + separator + (onlyCommons ? "" : conditionsStr) + "" // ; // return result; } // string GetTag() { return "XTD"; } }; // // Class ... class XSCXTDHelper : public XSCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XSCXTDHelper() : XSCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XSCXTDHelper() { // Clean(signalBuffer); Clean(bullishBuffer); Clean(bearishBuffer); } // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period XTDInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // mInputs = inputs; // ArraySetAsSeries(bullishBuffer, true); ArraySetAsSeries(bearishBuffer, true); ArraySetAsSeries(signalBuffer, true); // mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.xtd", // // Inputs ... // mInputs.length, // Market Length mInputs.drawCrosses, // Draw Cross Arrows // // Bullish ... mInputs.bullishArrowCode, // Cross Over Arrow Code mInputs.bullishArrowColor, // Cross Over Arrow Color // // Bearish ... mInputs.bearishArrowCode, // Cross Under Arrow Code mInputs.bearishArrowColor // Cross Under Arrow Color // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // XTDInputs GetInputs() { return mInputs; } // bool SetInputs( XTDInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Buffers ... // double GetBullish( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(bullishBuffer); if (barIndex >= count) { barIndex = count - 1; } // return bullishBuffer[barIndex]; } // // Copy Required Items ... int CopyBullish( 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, bullishBuffer, buffer, forceClean // ); } // double GetBearish( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(bearishBuffer); if (barIndex >= count) { barIndex = count - 1; } // return bearishBuffer[barIndex]; } // // Copy Required Items ... int CopyBearish( 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, bearishBuffer, buffer, forceClean // ); } // double GetSignal( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(signalBuffer); if (barIndex >= count) { barIndex = count - 1; } // return signalBuffer[barIndex]; } // // Copy Required Items ... int CopySignal( 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, signalBuffer, buffer, forceClean // ); } // bool GetConditions( XTDConditions &conditions, // int barIndex = 0, // int loopback = 3 // ) { // bool result = true; // if (loopback < 3) { loopback = 3; } // 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; // CopyBullish( zIndex, loopback, conditions.bullish // ); CopyBearish( zIndex, loopback, conditions.bearish // ); // // Calculate Conditions ... // bool isBullish = conditions.bullish[cIndex] > conditions.bearish[cIndex]; bool isBearish = conditions.bullish[cIndex] < conditions.bearish[cIndex]; // bool isBullishPrev = conditions.bullish[pIndex] > conditions.bearish[pIndex]; bool isBearishPrev = conditions.bullish[pIndex] < conditions.bearish[pIndex]; // bool isSwitchedToBullish = isBullish && !isBullishPrev; bool isSwitchedToBearish = isBearish && !isBearishPrev; // conditions.isBullish = isBullish; conditions.isBearish = isBearish; conditions.isSwitchedToBullish = isSwitchedToBullish; conditions.isSwitchedToBearish = isSwitchedToBearish; // return result; } // // Protected ... protected: // // Private ... private: // // Props ... XTDInputs mInputs; // Inputs ... // // Buffers ... double bullishBuffer[]; double bearishBuffer[]; double signalBuffer[]; // // Tools ... // // Calculate Values Until Now ... void Calculate() { // int totalBars = CountBars(); if (totalBars > 1000) { totalBars = 1000; } // // Bullish ... CopyBuffer( mHandler, XTD_BULLISH_LINE, 0, totalBars, bullishBuffer // ); // // Bearish ... CopyBuffer( mHandler, XTD_BEARISH_LINE, 0, totalBars, bearishBuffer // ); // // Signal ... CopyBuffer( mHandler, XTD_SIGNAL_LINE, 0, totalBars, signalBuffer // ); } }; // // Tools ...