/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Parser Class Library // ---------------------------------------------------- // Name: XCX121XKIHelperParser // Description: provides all Indicator // Helper Parse 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 "../../Helpers/x-saherelm.x121.xki.helper.mq5" // // Definitions ... // // Implementation ... class XCX121XKIHelperParser : XCBase { // // Public ... public: // string symbol; ENUM_TIMEFRAMES period; // // Constructor ... XCX121XKIHelperParser(XCX121XKIHelper *_helper) { // helper = _helper; symbol = _helper.GetSymbol(); period = _helper.GetPeriod(); } // // Deconstructor ... ~XCX121XKIHelperParser() { ZeroMemory(helper); } // // Tools ... /** * Validate ... * * @return ( bool ) */ bool IsValid() { // bool result = false; // result = helper != NULL && helper.IsValid() && IsXValid(symbol) && IsXValid(period); // return result; } /** * Normalize Bar Index ... * * @param barIndex: int, Provided Bar Index ... * * @return ( int ) */ int NormalizeBarIndex(int barIndex = 0) { // int result = -1; // if (!IsValid()) { return result; } // result = helper.NormalizeBarIndex(barIndex); // return result; } double GetPoints() { return GetXPoints(symbol); } XOHCL GetBar(int barIndex = 0) { // barIndex = NormalizeBarIndex(barIndex); XOHCL result; result.Init(symbol, period, barIndex); return result; } double GetPrice( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) { // XOHCL bar = GetBar(barIndex); double result = EMPTY_VALUE; if (bar.IsValid()) { result = bar.GetPrice(priceType); } bar.Clean(); // return result; } // // Parsers ... // Indicators Base Conditions ... // DECLARE_STATE_FUNCTIONS("KIFast", helper.GetKIFastState, NormalizeBarIndex); DECLARE_VALUE_COMPARATOR_FUNCTIONS("KIFast", helper.GetKIFast, NormalizeBarIndex, GetPoints); // DECLARE_STATE_FUNCTIONS("KISlow", helper.GetKISlowState, NormalizeBarIndex); DECLARE_VALUE_COMPARATOR_FUNCTIONS("KISlow", helper.GetKISlow, NormalizeBarIndex, GetPoints); // DECLARE_STATE_FUNCTIONS("KISuperSlow", helper.GetKISlowState, NormalizeBarIndex); DECLARE_VALUE_COMPARATOR_FUNCTIONS("KISuperSlow", helper.GetKISlow, NormalizeBarIndex, GetPoints); // DECLARE_STATE_FUNCTIONS("KIWave", helper.GetKIWaveState, NormalizeBarIndex); DECLARE_VALUE_COMPARATOR_FUNCTIONS("KIWave", helper.GetKIWave, NormalizeBarIndex, GetPoints); // DECLARE_PRICE_COMPARATOR_FUNCTIONS("KIUpper", helper.GetKIUpper, NormalizeBarIndex, GetPrice); DECLARE_PRICE_COMPARATOR_FUNCTIONS("KILower", helper.GetKILower, NormalizeBarIndex, GetPrice); // DECLARE_PRICE_BASED_STATE_FUNCTIONS("MAFast", helper.GetMAFast, NormalizeBarIndex, GetPoints, GetPrice); DECLARE_PRICE_BASED_STATE_FUNCTIONS("MASlow", helper.GetMASlow, NormalizeBarIndex, GetPoints, GetPrice); DECLARE_PRICE_BASED_STATE_FUNCTIONS("MASuperSlow", helper.GetMASuperSlow, NormalizeBarIndex, GetPoints, GetPrice); // DECLARE_CROSSING_COMPARATOR_FUNCTIONS("KI", "Fast", "Slow", helper.GetKIFast, helper.GetKISlow, NormalizeBarIndex, GetPoints); DECLARE_CROSSING_COMPARATOR_FUNCTIONS("MA", "Fast", "Slow", helper.GetMAFast, helper.GetMASlow, NormalizeBarIndex, GetPoints); DECLARE_CROSSING_COMPARATOR_FUNCTIONS("KI", "Slow", "SuperSlow", helper.GetKISlow, helper.GetKISuperSlow, NormalizeBarIndex, GetPoints); DECLARE_CROSSING_COMPARATOR_FUNCTIONS("MA", "Slow", "SuperSlow", helper.GetMASlow, helper.GetMASuperSlow, NormalizeBarIndex, GetPoints); // DECLARE_VALUE_COMPARATOR_FUNCTIONS("Peak", helper.GetPeak, NormalizeBarIndex, GetPoints); DECLARE_VALUE_COMPARATOR_FUNCTIONS("Vale", helper.GetVale, NormalizeBarIndex, GetPoints); // DECLARE_VALUE_COMPARATOR_FUNCTIONS("ATR", helper.GetATR, NormalizeBarIndex, GetPoints); DECLARE_VALUE_COMPARATOR_FUNCTIONS("ATRSmoothed", helper.GetATRSmoothed, NormalizeBarIndex, GetPoints); // DECLARE_VALUE_COMPARATOR_FUNCTIONS("RSI", helper.GetRSI, NormalizeBarIndex, GetPoints); DECLARE_VALUE_COMPARATOR_FUNCTIONS("RSISmoothed", helper.GetRSISmoothed, NormalizeBarIndex, GetPoints); // // // bool IsATRBreakoutUp( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid() && IsXValid(priceType); if (!result) { return result; } // XOHCL bar; result = bar.Init(symbol, period, barIndex); if (!result) { return result; } // double price = bar.GetPrice(priceType); result = price > helper.GetATRRawUpper(barIndex); bar.Clean(); // return result; } bool IsATRBreakoutDown( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid() && IsXValid(priceType); if (!result) { return result; } // XOHCL bar; result = bar.Init(symbol, period, barIndex); if (!result) { return result; } // double price = bar.GetPrice(priceType); result = price < helper.GetATRRawLower(barIndex); bar.Clean(); // return result; } bool IsVolatilityHigh(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double atr = helper.GetATR(barIndex); double atrMa = helper.GetATRSmoothed(barIndex); result = atr > atrMa; // return result; } bool IsVolatilityLow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double atr = helper.GetATR(barIndex); double atrMa = helper.GetATRSmoothed(barIndex); result = atr < atrMa; // return result; } bool IsVolatilitySwitchdToHigh(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double atr = helper.GetATR(barIndex); double atrPrev = helper.GetATR(barIndex + 1); double atrMa = helper.GetATRSmoothed(barIndex); double atrMaPrev = helper.GetATRSmoothed(barIndex + 1); // result = atr > atrMa && atrPrev <= atrMaPrev; // return result; } bool IsVolatilitySwitchdToLow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double atr = helper.GetATR(barIndex); double atrPrev = helper.GetATR(barIndex + 1); double atrMa = helper.GetATRSmoothed(barIndex); double atrMaPrev = helper.GetATRSmoothed(barIndex + 1); // result = atr < atrMa && atrPrev >= atrMaPrev; // return result; } bool IsRSIBullish( int barIndex = 0, double threshold = 55, double tolerance = 2 // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // result = helper.GetRSI(barIndex) > threshold + (GetXPoints(symbol) * tolerance) || helper.GetRSI(barIndex) > threshold - (GetXPoints(symbol) * tolerance); // return result; } bool IsRSISwitchedToBullish( int barIndex = 0, double threshold = 55, double tolerance = 2 // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // result = IsRSIBullish(barIndex, threshold, tolerance) && !IsRSIBullish(barIndex + 1, threshold, tolerance); // return result; } bool IsRSIBearish( int barIndex = 0, double threshold = 45, double tolerance = 2 // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // result = helper.GetRSI(barIndex) < threshold + (GetXPoints(symbol) * tolerance) || helper.GetRSI(barIndex) < threshold - (GetXPoints(symbol) * tolerance); // return result; } bool IsRSISwitchedToBearish( int barIndex = 0, double threshold = 45, double tolerance = 2 // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // result = IsRSIBearish(barIndex, threshold, tolerance) && !IsRSIBearish(barIndex + 1, threshold, tolerance); // return result; } bool IsRSIRising(int barIndex = 0) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && helper.GetRSI(barIndex) > helper.GetRSISmoothed(barIndex); // return result; } bool IsRSISwitchedToRising(int barIndex = 0) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && IsRSIRising(barIndex) && !IsRSIRising(barIndex + 1); // return result; } bool IsRSIFalling(int barIndex = 0) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && helper.GetRSI(barIndex) < helper.GetRSISmoothed(barIndex); // return result; } bool IsRSISwitchedToFalling(int barIndex = 0) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && IsRSIFalling(barIndex) && !IsRSIFalling(barIndex + 1); // return result; } bool IsRSIOverbought( int barIndex = 0, double threshold = 70, double tolerance = 2 // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // result = helper.GetRSI(barIndex) > threshold + (GetXPoints(symbol) * tolerance) || helper.GetRSI(barIndex) > threshold - (GetXPoints(symbol) * tolerance); // return result; } bool IsRSIOversold( int barIndex = 0, double threshold = 30, double tolerance = 2 // ) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // result = helper.GetRSI(barIndex) < threshold + (GetXPoints(symbol) * tolerance) || helper.GetRSI(barIndex) < threshold - (GetXPoints(symbol) * tolerance); // return result; } bool IsRSISwitchedToOversold( int barIndex = 0, double threshold = 30, double tolerance = 2 // ) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && IsRSIOversold(barIndex, threshold, tolerance) && !IsRSIOversold(barIndex + 1, threshold, tolerance); // return result; } bool IsRSISwitchedFromOversold( int barIndex = 0, double threshold = 30, double tolerance = 2 // ) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && !IsRSIOversold(barIndex, threshold, tolerance) && IsRSIOversold(barIndex + 1, threshold, tolerance); // return result; } bool IsRSISwitchedToOverbought( int barIndex = 0, double threshold = 70, double tolerance = 2 // ) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && IsRSIOverbought(barIndex, threshold, tolerance) && !IsRSIOverbought(barIndex + 1, threshold, tolerance); // return result; } bool IsRSISwitchedFromOverbought( int barIndex = 0, double threshold = 70, double tolerance = 2 // ) { // bool result = false; // barIndex = NormalizeBarIndex(barIndex); // result = IsValid() && !IsRSIOverbought(barIndex, threshold, tolerance) && IsRSIOverbought(barIndex + 1, threshold, tolerance); // return result; } // // Protected ... protected: // // // Private ... private: // XCX121XKIHelper *helper; // }; //