/////////////////////////////////////////////////////// // // SaherElm IT Center MQL4 Global Library // --------------------------------------------- // saherelm useful tools and definitions ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Includes Logger library ... #include "../Libraries/x-saherelm.log.lib.mq4" // // Includes Drawing library ... #include "../Libraries/x-saherelm.draw.lib.mq4" // // START Functions ... // // // Determines current working is New Bar or not ... bool IsNewBar() { // static datetime lastbar; datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE); // if(lastbar != curbar) { // lastbar = curbar; return true; } // return false; } // // Retrieve RMA on Specific Candle ... double GetRMA( int bar_index, int length ) { // double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index); double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index); double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index); // double result = longSMA - mediumSMA + shortSMA; // return result; } // // this function check crossing up two Buffers ... bool IsCrossedOver( double &arr1[], double &arr2[], int index1, int index2 = -1 ) { // // Normalize Index 2 Value ... if (index2 < 0) { index2 = index1 + 1; } // bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]); // return result; } // // this function check crossing down two Buffers ... bool IsCrossedUnder( double &arr1[], double &arr2[], int index1, int index2 = -1 ) { // // Normalize Index 2 Value ... if (index2 < 0) { index2 = index1 + 1; } // bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]); // return result; } // // Convert points to Actual Point ... double PointsToDouble(int points) { // double result = points * _Point; return result; } // // Converts Pips to Points ... int PipsToPoints(int pips) { // int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1); return result; } // // Converts Pips to Double ... double PipsToDouble(int pips) { // double result = PointsToDouble(PipsToPoints(pips)); return result; } // // Converts Double Value to Pips ... int PriceToPips(double value) { // if (value <= 0) { return 0; } // double pipValue = _Point * MathPow(10, _Digits); int result = (int)(value / pipValue); // return result; } // // Converts Pips to Double ... double PipsToPrice(int pips) { // if (pips <= 0) { return 0; } // double pipValue = _Point * MathPow(10, _Digits); double result = pipValue * pips; // return result; } // // Generate ATR StopLoss Value ... double CalculateATRSL( int period, double multiplier ) { // if (period <= 0 || multiplier <= 0) { return 0; } // double atrValue = iATR( _Symbol, _Period, period, 0 ); // double result = atrValue * multiplier; // return result; } // // Detect Candle Type ... // Bullish => means close > open ... bool isBullishCandle( const int bar_index ) { // // Temp Result ... bool result = false; // if (bar_index < 0) { return result; } // double open = iOpen( _Symbol, _Period, bar_index ); // double close = iClose( _Symbol, _Period, bar_index ); // result = isBullishCandle( open, close ); // return result; } bool isBullishCandle( const double open, const double close ) { // // Temp Result ... bool result = false; // result = open < close; // return result; } // // Detect Candle Type ... // Bearish => means close < open ... bool isBearishCandle( const int bar_index ) { // // Temp Result ... bool result = false; // if (bar_index < 0) { return result; } // double open = iOpen( _Symbol, _Period, bar_index ); // double close = iClose( _Symbol, _Period, bar_index ); // result = isBearishCandle( open, close ); // return result; } bool isBearishCandle( const double open, const double close ) { // // Temp Result ... bool result = false; // result = open > close; // return result; } // // Retrieve Highest High Value based on Given Market ... double GetMarketHighestHigh( // const int bar_index, // Bar Index ... const int marketLen // Market Length ... ) { // // Empty Result ... double result = 0.0; // // Retrieve Desired Bar Index ... int foundedBarIndex = iHighest( _Symbol, _Period, MODE_HIGH, marketLen, bar_index ); // // Retrieve Price ... result = iHigh( _Symbol, _Period, foundedBarIndex ); // return result; } // // Retrieve Highest High Value based on Given Market ... double GetMarketLowestLow( // const int bar_index, // Bar Index ... const int marketLen // Market Length ... ) { // // Empty Result ... double result = 0.0; // // Retrieve Desired Bar Index ... int foundedBarIndex = iLowest( _Symbol, _Period, MODE_LOW, marketLen, bar_index ); // // Retrieve Price ... result = iLow( _Symbol, _Period, foundedBarIndex ); // return result; } // // Retrieve Highest High Value based on Given Market ... double GetMarketHighestOpen( // const int bar_index, // Bar Index ... const int marketLen // Market Length ... ) { // // Empty Result ... double result = 0.0; // // Retrieve Desired Bar Index ... int foundedBarIndex = iHighest( _Symbol, _Period, MODE_OPEN, marketLen, bar_index ); // // Retrieve Price ... result = iOpen( _Symbol, _Period, foundedBarIndex ); // return result; } // // Retrieve Highest High Value based on Given Market ... double GetMarketLowestClose( // const int bar_index, // Bar Index ... const int marketLen // Market Length ... ) { // // Empty Result ... double result = 0.0; // // Retrieve Desired Bar Index ... int foundedBarIndex = iLowest( _Symbol, _Period, MODE_CLOSE, marketLen, bar_index ); // // Retrieve Price ... result = iClose( _Symbol, _Period, foundedBarIndex ); // return result; } // // Find last Candle which it's Low Price is // less than given price ... double GetLowLessCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iLow( _Symbol, _Period, index ); // while (result >= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetLowLessCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iLow( _Symbol, _Period, result ); // while (cP >= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's Low Price is // great than given price ... double GetLowGreatCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iLow( _Symbol, _Period, index ); // while (result >= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetLowGreatCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iLow( _Symbol, _Period, result ); // while (cP >= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's High Price is // less than given price ... double GetHighLessCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iHigh( _Symbol, _Period, index ); // while (result >= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetHighLessCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iHigh( _Symbol, _Period, result ); // while (cP >= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's High Price is // great than given price ... double GetHighGreatCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iHigh( _Symbol, _Period, index ); // while (result <= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetHighGreatCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iHigh( _Symbol, _Period, result ); // while (cP <= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's Open Price is // less than given price ... double GetOpenLessCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iOpen( _Symbol, _Period, index ); // while (result >= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetOpenLessCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iOpen( _Symbol, _Period, result ); // while (cP >= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's Open Price is // less than given price ... double GetOpenGreatCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iOpen( _Symbol, _Period, index ); // while (result <= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetOpenGreatCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iOpen( _Symbol, _Period, result ); // while (cP <= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's Close Price is // less than given price ... double GetCloseLessCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iClose( _Symbol, _Period, index ); // while (result >= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetCloseLessCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iClose( _Symbol, _Period, result ); // while (cP >= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // // Find last Candle which it's Close Price is // great than given price ... double GetCloseGreatCandlePrice( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int index = bar_index + 1; double result = iClose( _Symbol, _Period, index ); // while (result <= price) { // index++; // result = iLow( _Symbol, _Period, index ); } // return result; } int GetCloseGreatCandleIndex( // const int bar_index, // Bar Index ... const double price // Position Open Price ... ) { // int result = bar_index + 1; double cP = iClose( _Symbol, _Period, result ); // while (cP <= price) { // result++; // cP = iLow( _Symbol, _Period, result ); } // return result; } // struct XMinMax { double min; double max; }; // // Find Min and Max Value of specific Buffer ... XMinMax GetBufferMinMax(const double &buffer[]) { // XMinMax result = {}; // int bufferSize = ArraySize(buffer); if (bufferSize < 1) { return result; } // double min = buffer[0]; double max = buffer[0]; // for (int i = 1; i < bufferSize; i++) { // if (buffer[i] < min) { min = buffer[i]; } else if (buffer[i] > max) { max = buffer[i]; } } // result.min = min; result.max = max; // return result; } // // END Functions ... //