/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXASCTHelper // 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_XASCT_BUFFERS { XASCT_LONG_LINE = 0, XASCT_SHORT_LINE = 1 }; // // Input Models ... struct XASCTInputs { // // Props ... // // Market ... int risk; // Risk // // Presentation ... bool showLongs; // Show Long Arrows bool showShorts; // Show Short Arrows uchar longArrowCode; // Long Arrow uchar shortArrowCode; // Short Arrow // // Constructor(s) ... XASCTInputs() { // Clean(); } // // Tools ... // // Clean ... void Clean() { // risk = 0; // showLongs = false; showShorts = false; longArrowCode = 0; shortArrowCode = 0; } // // Default ... void Default() { // risk = 4; // showLongs = true; showShorts = true; longArrowCode = 233; shortArrowCode = 234; } // // Validate ... bool IsValid() { // bool result = false; // result = // risk >= 1 // ; // return result; } // // Retrieve MAx Length ... int Max() { // int result = 0; // result = int(MathMax(3 + risk * 2, 4) + 1); // return result; } }; // // Define Conditions ... struct XASCTConditions { // // Common ... string symbol; ENUM_TIMEFRAMES period; datetime time; // // Buffers ... double longSignal[]; double shortSignal[]; // // Conditions ... // bool isLongSignal; bool isShortSignal; // void Clean() { // Clean(longSignal); Clean(shortSignal); // ArraySetAsSeries(longSignal, true); ArraySetAsSeries(shortSignal, true); // isLongSignal = false; isShortSignal = false; } // void GenerateScore( double &bullishScore, double &bearishScore // ) { // bullishScore = 0; bearishScore = 0; // if (isLongSignal) { bullishScore++; } // if (isShortSignal) { 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("isLongSignal", isLongSignal, ignoreFalseConditions, separator) + ToString("isShortSignal", isShortSignal, ignoreFalseConditions, separator) + "" // ; // result = // "[" + GetTag() + "]" + separator + (onlyConditions ? "" : commonStr) + (!includeScores ? "" : scoresStr) + " " + separator + (onlyCommons ? "" : conditionsStr) + "" // ; // return result; } // string GetTag() { return "XASCT"; } }; // // Class ... class XSCXASCTHelper : public XSCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XSCXASCTHelper() : XSCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XSCXASCTHelper() {} // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period XASCTInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // mInputs = inputs; // ArraySetAsSeries(longsBuffer, true); ArraySetAsSeries(shortsBuffer, true); mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.xasct", // // Inputs ... // // Market ... "", mInputs.risk, // Risk // // Presentation ... "", mInputs.showLongs, // Show Long Arrows mInputs.showShorts, // Show Short Arrows mInputs.longArrowCode, // Long Arrow mInputs.shortArrowCode // Short Arrow // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // XASCTInputs GetInputs() { return mInputs; } // bool SetInputs( XASCTInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Buffers ... // double GetLong( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(longsBuffer); if (barIndex >= count) { barIndex = count - 1; } // return longsBuffer[barIndex]; } // // Copy Required Items ... int CopyLong( 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, longsBuffer, buffer, forceClean // ); } // double GetShort( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(shortsBuffer); if (barIndex >= count) { barIndex = count - 1; } // return shortsBuffer[barIndex]; } // // Copy Required Items ... int CopyShort( 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, shortsBuffer, buffer, forceClean // ); } // bool GetConditions( XASCTConditions &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 ... // CopyLong( zIndex, loopback, conditions.longSignal // ); CopyShort( zIndex, loopback, conditions.shortSignal // ); // // Conditions ... // bool isLongSignal = NotEmptyZero(conditions.longSignal[cIndex]); bool isShortSignal = NotEmptyZero(conditions.shortSignal[cIndex]); // conditions.isLongSignal = isLongSignal; conditions.isShortSignal = isShortSignal; // return result; } // // Protected ... protected: // // Private ... private: // // Props ... XASCTInputs mInputs; // Inputs ... // // Buffers ... double longsBuffer[]; double shortsBuffer[]; // // Tools ... // // Calculate Values Until Now ... void Calculate() { // int totalBars = CountBars(); if (totalBars > 1000) { totalBars = 1000; } // // Longs Buffer ... CopyBuffer( mHandler, XASCT_LONG_LINE, 0, totalBars, longsBuffer // ); // // Shorts Buffer ... CopyBuffer( mHandler, XASCT_SHORT_LINE, 0, totalBars, shortsBuffer // ); } }; // // Tools ...