/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXATSLHelper // 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_XATSL_BUFFERS { XATSL_MAIN_LINE = 0, }; // // Input Models ... struct XATSLInputs { // // Props ... // // Market ... int length; // Length double coeff; // Coefficient // // Presentation ... bool show; // Show // // Constructor(s) ... XATSLInputs() { // Clean(); } // // Tools ... // // Clean ... void Clean() { // length = 0; coeff = 0; // show = false; } // // Default ... void Default() { // length = 14; coeff = 2.0; // show = true; } // // Validate ... bool IsValid() { // bool result = false; // result = // length >= 2 && coeff > 0 // ; // return result; } // // Retrieve MAx Length ... int Max() { // int result = 0; // result = MathMax(result, length); // return result; } }; // // Define Conditions ... struct XATSLConditions { // // Common ... string symbol; ENUM_TIMEFRAMES period; datetime time; // // Buffers ... double atsl[]; // // Conditions ... // bool isBullish; bool isBearish; // bool isSwitchedToBullish; bool isSwitchedToBearish; // void Clean() { // Clean(atsl); // ArraySetAsSeries(atsl, 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 "XATSL"; } }; // // Class ... class XSCXATSLHelper : public XSCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XSCXATSLHelper() : XSCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XSCXATSLHelper() { Clean(atslBuffer); } // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period XATSLInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // mInputs = inputs; // ArraySetAsSeries(atslBuffer, true); mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.xatsl", // // Inputs ... // // Market ... "", mInputs.length, mInputs.coeff, // // Presentation ... "", mInputs.show // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // XATSLInputs GetInputs() { return mInputs; } // bool SetInputs( XATSLInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Buffers ... // double GetATSL( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(atslBuffer); if (barIndex >= count) { barIndex = count - 1; } // return atslBuffer[barIndex]; } // // Copy Required Items ... int CopyATSL( 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, atslBuffer, buffer, forceClean // ); } // bool GetConditions( XATSLConditions &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; // // Buffers ... // CopyATSL( zIndex, loopback, conditions.atsl // ); // // 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; } // bool isBullish = conditions.atsl[cIndex] < cBar.close; bool isBullishPrev = conditions.atsl[pIndex] < pBar.close; // bool isBearish = conditions.atsl[cIndex] > cBar.close; bool isBearishPrev = conditions.atsl[pIndex] > pBar.close; // 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 ... XATSLInputs mInputs; // Inputs ... // // Buffers ... double atslBuffer[]; // // Tools ... // // Calculate Values Until Now ... void Calculate() { // int totalBars = CountBars(); if (totalBars > 1000) { totalBars = 1000; } // // Longs Buffer ... CopyBuffer( mHandler, XATSL_MAIN_LINE, 0, totalBars, atslBuffer // ); } }; //