diff --git a/Classes/x-saherelm.xmd5.class.mq5 b/Classes/x-saherelm.xmd5.class.mq5 new file mode 100644 index 00000000..3311aa5a --- /dev/null +++ b/Classes/x-saherelm.xmd5.class.mq5 @@ -0,0 +1,441 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCMD5 +// Description: Provides MD5 Hashing 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 + +// +// START Definitions ... +// + +// +static uchar _md5_PADDING[64] = + { + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +// +#define _md5_F(x, y, z) (((x) & (y)) | ((~x) & (z))) +#define _md5_G(x, y, z) (((x) & (z)) | ((y) & (~z))) +#define _md5_H(x, y, z) ((x) ^ (y) ^ (z)) +#define _md5_I(x, y, z) ((y) ^ ((x) | (~z))) +#define _md5_ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + +// +#define _md5_FF(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_F((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_GG(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_G((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_HH(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_H((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_II(a, b, c, d, x, s, ac) \ + { \ + (a) += _md5_I((b), (c), (d)) + (x) + (uint)(ac); \ + (a) = _md5_ROTATE_LEFT((a), (s)); \ + (a) += (b); \ + } + +// +#define _md5_INIT_STATE_0 0x67452301 +#define _md5_INIT_STATE_1 0xefcdab89 +#define _md5_INIT_STATE_2 0x98badcfe +#define _md5_INIT_STATE_3 0x10325476 + +// +#define _md5_S11 7 +#define _md5_S12 12 +#define _md5_S13 17 +#define _md5_S14 22 + +// +#define _md5_S21 5 +#define _md5_S22 9 +#define _md5_S23 14 +#define _md5_S24 20 + +// +#define _md5_S31 4 +#define _md5_S32 11 +#define _md5_S33 16 +#define _md5_S34 23 + +// +#define _md5_S41 6 +#define _md5_S42 10 +#define _md5_S43 15 +#define _md5_S44 21 + +// +// END Definitions ... +// + +// +// XCMD5 a library for Hashing ... +class XSCMD5 +{ + // + // Public Provides ... +public: + // + // Protected Provides ... + + // + // Constructor ... + XSCMD5(void) {} + + // + // Deconstructor ... + ~XSCMD5(void) {} + + // + // Hash Specified Char Array ... + string Hash( + uchar &mSource[], // Specify Char Array to Hash + int mLength = 0 // Specify Length of Char Array which required to hash + ) + { + // + string result = ""; + + // + int sourceCount = ArraySize(mSource); + + // + // Validate Args ... + if ( + sourceCount <= 0 || + (sourceCount > 0 && mLength > sourceCount)) + { + return result; + } + + // + // Normalize Args ... + if (mLength == 0) + { + mLength = sourceCount; + } + + // + // Init MD5 ... + MD5Init(); + + // + // Update Buffer ... + MD5Update(mSource, mLength); + + // + // Calculate Result ... + result = MD5Final(); + + // + return result; + } + + // + // Hash Specified String ... + string Hash( + string mSource // Specified String + ) + { + // + string result = ""; + + // + // Converts String to Char Array ... + uchar bytes[]; + StringToCharArray( + mSource, + bytes, + 0, + StringLen(mSource)); + + // + result = Hash( + bytes, + ArraySize(bytes)); + + // + return result; + } + +protected: + // + // Private Provides ... +private: + // + uint m_lMD5[4]; + uint m_nCount[2]; + uchar m_lpszBuffer[64]; + + // + // Convert Byte to DWord ... + void ByteToDWord(int &out[], uint &in[], uint len) + { + // + uint i = 0; + uint j = 0; + + // + for (; j < len; i++, j += 4) + { + out[i] = (int)in[j] | (int)in[j + 1] << 8 | (int)in[j + 2] << 16 | (int)in[j + 3] << 24; + } + } + + // + // Convert DWord to Byte ... + void DWordToByte(uchar &out[], int &in[], uint len) + { + // + uint i = 0; + uint j = 0; + + // + for (; j < len; i++, j += 4) + { + // + out[j] = (uchar)(in[i] & 0xff); + out[j + 1] = (uchar)((in[i] >> 8) & 0xff); + out[j + 2] = (uchar)((in[i] >> 16) & 0xff); + out[j + 3] = (uchar)((in[i] >> 24) & 0xff); + } + } + + // + // Init MD5 Array ... + void MD5Init() + { + // + ArrayInitialize(m_lpszBuffer, 64); + + // + m_nCount[0] = m_nCount[1] = 0; + m_lMD5[0] = _md5_INIT_STATE_0; + m_lMD5[1] = _md5_INIT_STATE_1; + m_lMD5[2] = _md5_INIT_STATE_2; + m_lMD5[3] = _md5_INIT_STATE_3; + } + + // + // Update MD5 ... + void MD5Update(uchar &inBuf[], uint inLen) + { + // + int i, ii; + int mdi; + + // + uint in[16]; + int i0 = 0; + + // + mdi = (int)((m_nCount[0] >> 3) & 0x3F); + + // + if ((m_nCount[0] + ((uint)inLen << 3)) < m_nCount[0]) + { + m_nCount[1]++; + } + + // + m_nCount[0] += ((uint)inLen << 3); + m_nCount[1] += ((uint)inLen >> 29); + + // + while ((inLen--) > 0) + { + // + m_lpszBuffer[mdi++] = inBuf[i0++]; + if (mdi == 0x40) + { + // + for (i = 0, ii = 0; i < 16; i++, ii += 4) + { + in[i] = (((uint)m_lpszBuffer[ii + 3]) << 24) | (((uint)m_lpszBuffer[ii + 2]) << 16) | (((uint)m_lpszBuffer[ii + 1]) << 8) | ((uint)m_lpszBuffer[ii]); + } + + // + Transform(m_lMD5, in); + + // + mdi = 0; + } + } + } + + // + // Finalize an MD5 Expression ... + string MD5Final() + { + // + uchar bits[8]; + int nIndex; + uint nPadLen; + const int nMD5Size = 16; + uchar lpszMD5[16]; + string temp; + string out = ""; + int i; + + // + DWordToByte(bits, m_nCount, 8); + nIndex = (int)((m_nCount[0] >> 3) & 0x3f); + nPadLen = (nIndex < 56) ? (56 - nIndex) : (120 - nIndex); + MD5Update(_md5_PADDING, nPadLen); + MD5Update(bits, 8); + DWordToByte(lpszMD5, m_lMD5, nMD5Size); + + // + for (i = 0; i < nMD5Size; i++) + { + // + if (lpszMD5[i] == 0) + { + temp = "00"; + } + else if (lpszMD5[i] <= 15) + { + temp = StringFormat("0%x", lpszMD5[i]); + } + else + { + temp = StringFormat("%x", lpszMD5[i]); + } + + // + out += temp; + } + + // + lpszMD5[0] = '\0'; + + // + return (out); + } + + // + // Transform Buffers ... + void Transform(uint &buf[], uint &in[]) + { + // + uint a = buf[0], b = buf[1], c = buf[2], d = buf[3]; + + // + _md5_FF(a, b, c, d, in[0], _md5_S11, 0xD76AA478); + _md5_FF(d, a, b, c, in[1], _md5_S12, 0xE8C7B756); + _md5_FF(c, d, a, b, in[2], _md5_S13, 0x242070DB); + _md5_FF(b, c, d, a, in[3], _md5_S14, 0xC1BDCEEE); + _md5_FF(a, b, c, d, in[4], _md5_S11, 0xF57C0FAF); + _md5_FF(d, a, b, c, in[5], _md5_S12, 0x4787C62A); + _md5_FF(c, d, a, b, in[6], _md5_S13, 0xA8304613); + _md5_FF(b, c, d, a, in[7], _md5_S14, 0xFD469501); + _md5_FF(a, b, c, d, in[8], _md5_S11, 0x698098D8); + _md5_FF(d, a, b, c, in[9], _md5_S12, 0x8B44F7AF); + _md5_FF(c, d, a, b, in[10], _md5_S13, 0xFFFF5BB1); + _md5_FF(b, c, d, a, in[11], _md5_S14, 0x895CD7BE); + _md5_FF(a, b, c, d, in[12], _md5_S11, 0x6B901122); + _md5_FF(d, a, b, c, in[13], _md5_S12, 0xFD987193); + _md5_FF(c, d, a, b, in[14], _md5_S13, 0xA679438E); + _md5_FF(b, c, d, a, in[15], _md5_S14, 0x49B40821); + + // + _md5_GG(a, b, c, d, in[1], _md5_S21, 0xF61E2562); + _md5_GG(d, a, b, c, in[6], _md5_S22, 0xC040B340); + _md5_GG(c, d, a, b, in[11], _md5_S23, 0x265E5A51); + _md5_GG(b, c, d, a, in[0], _md5_S24, 0xE9B6C7AA); + _md5_GG(a, b, c, d, in[5], _md5_S21, 0xD62F105D); + _md5_GG(d, a, b, c, in[10], _md5_S22, 0x02441453); + _md5_GG(c, d, a, b, in[15], _md5_S23, 0xD8A1E681); + _md5_GG(b, c, d, a, in[4], _md5_S24, 0xE7D3FBC8); + _md5_GG(a, b, c, d, in[9], _md5_S21, 0x21E1CDE6); + _md5_GG(d, a, b, c, in[14], _md5_S22, 0xC33707D6); + _md5_GG(c, d, a, b, in[3], _md5_S23, 0xF4D50D87); + _md5_GG(b, c, d, a, in[8], _md5_S24, 0x455A14ED); + _md5_GG(a, b, c, d, in[13], _md5_S21, 0xA9E3E905); + _md5_GG(d, a, b, c, in[2], _md5_S22, 0xFCEFA3F8); + _md5_GG(c, d, a, b, in[7], _md5_S23, 0x676F02D9); + _md5_GG(b, c, d, a, in[12], _md5_S24, 0x8D2A4C8A); + + // + _md5_HH(a, b, c, d, in[5], _md5_S31, 0xFFFA3942); + _md5_HH(d, a, b, c, in[8], _md5_S32, 0x8771F681); + _md5_HH(c, d, a, b, in[11], _md5_S33, 0x6D9D6122); + _md5_HH(b, c, d, a, in[14], _md5_S34, 0xFDE5380C); + _md5_HH(a, b, c, d, in[1], _md5_S31, 0xA4BEEA44); + _md5_HH(d, a, b, c, in[4], _md5_S32, 0x4BDECFA9); + _md5_HH(c, d, a, b, in[7], _md5_S33, 0xF6BB4B60); + _md5_HH(b, c, d, a, in[10], _md5_S34, 0xBEBFBC70); + _md5_HH(a, b, c, d, in[13], _md5_S31, 0x289B7EC6); + _md5_HH(d, a, b, c, in[0], _md5_S32, 0xEAA127FA); + _md5_HH(c, d, a, b, in[3], _md5_S33, 0xD4EF3085); + _md5_HH(b, c, d, a, in[6], _md5_S34, 0x04881D05); + _md5_HH(a, b, c, d, in[9], _md5_S31, 0xD9D4D039); + _md5_HH(d, a, b, c, in[12], _md5_S32, 0xE6DB99E5); + _md5_HH(c, d, a, b, in[15], _md5_S33, 0x1FA27CF8); + _md5_HH(b, c, d, a, in[2], _md5_S34, 0xC4AC5665); + + // + _md5_II(a, b, c, d, in[0], _md5_S41, 0xF4292244); + _md5_II(d, a, b, c, in[7], _md5_S42, 0x432AFF97); + _md5_II(c, d, a, b, in[14], _md5_S43, 0xAB9423A7); + _md5_II(b, c, d, a, in[5], _md5_S44, 0xFC93A039); + _md5_II(a, b, c, d, in[12], _md5_S41, 0x655B59C3); + _md5_II(d, a, b, c, in[3], _md5_S42, 0x8F0CCC92); + _md5_II(c, d, a, b, in[10], _md5_S43, 0xFFEFF47D); + _md5_II(b, c, d, a, in[1], _md5_S44, 0x85845DD1); + _md5_II(a, b, c, d, in[8], _md5_S41, 0x6FA87E4F); + _md5_II(d, a, b, c, in[15], _md5_S42, 0xFE2CE6E0); + _md5_II(c, d, a, b, in[6], _md5_S43, 0xA3014314); + _md5_II(b, c, d, a, in[13], _md5_S44, 0x4E0811A1); + _md5_II(a, b, c, d, in[4], _md5_S41, 0xF7537E82); + _md5_II(d, a, b, c, in[11], _md5_S42, 0xBD3AF235); + _md5_II(c, d, a, b, in[2], _md5_S43, 0x2AD7D2BB); + _md5_II(b, c, d, a, in[9], _md5_S44, 0xEB86D391); + + // + buf[0] += a; + buf[1] += b; + buf[2] += c; + buf[3] += d; + } +}; diff --git a/Indicators/x-saherelm.xama.indicator.mq5 b/Indicators/x-saherelm.xama.indicator.mq5 index 14d1ef70..e2df3fe5 100644 --- a/Indicators/x-saherelm.xama.indicator.mq5 +++ b/Indicators/x-saherelm.xama.indicator.mq5 @@ -48,10 +48,6 @@ input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -106,9 +102,6 @@ int OnInit() return INIT_PARAMETERS_INCORRECT; } - // - logTag = ShortName; - // // Initializing MA Handler ... maHandler = iAMA( @@ -121,10 +114,6 @@ int OnInit() appliedTo); if (maHandler == INVALID_HANDLE) { - // - string message = "Error Initializing Ma Handler ..."; - LogMessage(message); - // return INIT_FAILED; } @@ -320,7 +309,12 @@ void CalculateBuffers(int bar_index) { // // Requirements ... - XOHCL candle = GetCandle(bar_index); + XOHCL candle; + candle.Init( + _Symbol, + _Period, + bar_index + ); // double maValue = maBuffer[bar_index]; diff --git a/Indicators/x-saherelm.xchlh.oscillator.mq5 b/Indicators/x-saherelm.xchlh.oscillator.mq5 index 5c74787c..83ebacbf 100644 --- a/Indicators/x-saherelm.xchlh.oscillator.mq5 +++ b/Indicators/x-saherelm.xchlh.oscillator.mq5 @@ -33,9 +33,6 @@ enum ENUM_X_XCHLH_HOT_STATES X_XCHLH_HOT_LL = -1, }; -// -// Including Models Library ... -#include "../Libraries/x-saherelm.models.lib.mq5" // // END Constants ... // @@ -190,7 +187,6 @@ int OnInit() } // - logTag = ShortName; drawPrefix = ShortName; // @@ -229,10 +225,6 @@ void OnDeinit(const int reason) // ReDraw Chart ... ChartRedraw(); - // - // De Init Draw Library ... - OnDeinitDrawLibrary(); - // Comment(""); } @@ -529,15 +521,35 @@ void LCCalculateBuffers( ENUM_SERIESMODE hhMode = lcHHMode; ENUM_SERIESMODE llMode = lcLLMode; double threshold = PipsToPrice(lcThresholdInPips); - double hh = GetHighestHigh( + + // + int hhIdx = iHighest( + _Symbol, + _Period, + hhMode, length, - bar_index, - hhMode); + bar_index + // + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx); double hhValue = hh + threshold; - double ll = GetLowestLow( + + // + int llIdx = iLowest( + _Symbol, + _Period, + llMode, length, - bar_index, - llMode); + bar_index + // + ); + double ll = iLow( + _Symbol, + _Period, + llIdx); double llValue = ll - threshold; // @@ -557,15 +569,35 @@ void MCCalculateBuffers( ENUM_SERIESMODE hhMode = mcHHMode; ENUM_SERIESMODE llMode = mcLLMode; double threshold = PipsToPrice(mcThresholdInPips); - double hh = GetHighestHigh( + + // + int hhIdx = iHighest( + _Symbol, + _Period, + hhMode, length, - bar_index, - hhMode); + bar_index + // + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx); double hhValue = hh + threshold; - double ll = GetLowestLow( + + // + int llIdx = iLowest( + _Symbol, + _Period, + llMode, length, - bar_index, - llMode); + bar_index + // + ); + double ll = iLow( + _Symbol, + _Period, + llIdx); double llValue = ll - threshold; // @@ -585,15 +617,35 @@ void SCCalculateBuffers( ENUM_SERIESMODE hhMode = scHHMode; ENUM_SERIESMODE llMode = scLLMode; double threshold = PipsToPrice(scThresholdInPips); - double hh = GetHighestHigh( + + // + int hhIdx = iHighest( + _Symbol, + _Period, + hhMode, length, - bar_index, - hhMode); + bar_index + // + ); + double hh = iHigh( + _Symbol, + _Period, + hhIdx); double hhValue = hh + threshold; - double ll = GetLowestLow( + + // + int llIdx = iLowest( + _Symbol, + _Period, + llMode, length, - bar_index, - llMode); + bar_index + // + ); + double ll = iLow( + _Symbol, + _Period, + llIdx); double llValue = ll - threshold; // @@ -710,7 +762,13 @@ void DrawBuffers( // // Retrieve Candle Model ... - XOHCL candle = GetCandle(bar_index); + XOHCL candle; + candle.Init( + _Symbol, + _Period, + bar_index + // + ); datetime time = iTime(_Symbol, _Period, bar_index); // diff --git a/Indicators/x-saherelm.xchma.oscillator.mq5 b/Indicators/x-saherelm.xchma.oscillator.mq5 index 12d6c691..efc75247 100644 --- a/Indicators/x-saherelm.xchma.oscillator.mq5 +++ b/Indicators/x-saherelm.xchma.oscillator.mq5 @@ -110,10 +110,6 @@ input bool scDrawCrosses = false; // Draw Cross Lines // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -205,7 +201,6 @@ int OnInit() } // - logTag = ShortName; drawPrefix = ShortName; // @@ -251,10 +246,6 @@ void OnDeinit(const int reason) // ReDraw Chart ... ChartRedraw(); - // - // De Init Draw Library ... - OnDeinitDrawLibrary(); - // Comment(""); } @@ -640,10 +631,6 @@ bool LCInitHandlers() lcAppliedTo); if (lcFastHandler == INVALID_HANDLE) { - // - LogMessage("LC Fast Indicator initialization failed: " + (string)GetLastError()); - - // return false; } @@ -658,10 +645,6 @@ bool LCInitHandlers() lcAppliedTo); if (lcSlowHandler == INVALID_HANDLE) { - // - LogMessage("LC Slow Indicator initialization failed: " + (string)GetLastError()); - - // return false; } @@ -687,10 +670,6 @@ bool MCInitHandlers() mcAppliedTo); if (mcFastHandler == INVALID_HANDLE) { - // - LogMessage("MC Fast Indicator initialization failed: " + (string)GetLastError()); - - // return false; } @@ -705,10 +684,6 @@ bool MCInitHandlers() mcAppliedTo); if (mcSlowHandler == INVALID_HANDLE) { - // - LogMessage("MC Slow Indicator initialization failed: " + (string)GetLastError()); - - // return false; } @@ -734,10 +709,6 @@ bool SCInitHandlers() scAppliedTo); if (scFastHandler == INVALID_HANDLE) { - // - LogMessage("SC Fast Indicator initialization failed: " + (string)GetLastError()); - - // return false; } @@ -752,10 +723,6 @@ bool SCInitHandlers() scAppliedTo); if (scSlowHandler == INVALID_HANDLE) { - // - LogMessage("SC Slow Indicator initialization failed: " + (string)GetLastError()); - - // return false; } @@ -771,7 +738,7 @@ double GetLCState( { // // Fast Cross Over Slow Detection ... - bool isFastCrossedOverSlow = IsCrossOver( + bool isFastCrossedOverSlow = IsCrossedOver( lcFastBuffer, lcSlowBuffer, bar_index); @@ -785,7 +752,7 @@ double GetLCState( // // Fast Cross Under Slow Detection ... - bool isFastCrossedUnderSlow = IsCrossUnder( + bool isFastCrossedUnderSlow = IsCrossedUnder( lcFastBuffer, lcSlowBuffer, bar_index); @@ -833,7 +800,7 @@ double GetMCState( { // // Fast Cross Over Slow Detection ... - bool isFastCrossedOverSlow = IsCrossOver( + bool isFastCrossedOverSlow = IsCrossedOver( mcFastBuffer, mcSlowBuffer, bar_index); @@ -847,7 +814,7 @@ double GetMCState( // // Fast Cross Under Slow Detection ... - bool isFastCrossedUnderSlow = IsCrossUnder( + bool isFastCrossedUnderSlow = IsCrossedUnder( mcFastBuffer, mcSlowBuffer, bar_index); @@ -895,7 +862,7 @@ double GetSCState( { // // Fast Cross Over Slow Detection ... - bool isFastCrossedOverSlow = IsCrossOver( + bool isFastCrossedOverSlow = IsCrossedOver( scFastBuffer, scSlowBuffer, bar_index); @@ -909,7 +876,7 @@ double GetSCState( // // Fast Cross Under Slow Detection ... - bool isFastCrossedUnderSlow = IsCrossUnder( + bool isFastCrossedUnderSlow = IsCrossedUnder( scFastBuffer, scSlowBuffer, bar_index); @@ -1031,7 +998,13 @@ void DrawBuffers( // // Retrieve Candle Model ... - XOHCL candle = GetCandle(bar_index); + XOHCL candle; + candle.Init( + _Symbol, + _Period, + bar_index + // + ); datetime time = iTime(_Symbol, _Period, bar_index); // diff --git a/Indicators/x-saherelm.xctimer.indicator.mq5 b/Indicators/x-saherelm.xctimer.indicator.mq5 index 6a064212..84e7e8f3 100644 --- a/Indicators/x-saherelm.xctimer.indicator.mq5 +++ b/Indicators/x-saherelm.xctimer.indicator.mq5 @@ -39,6 +39,14 @@ input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // // START Buffers ... // + +// +#property indicator_chart_window + +// +#property indicator_buffers 0 +#property indicator_plots 0 + // // END Buffers ... // diff --git a/Indicators/x-saherelm.xfi.oscillator.mq5 b/Indicators/x-saherelm.xfi.oscillator.mq5 index cfd393ca..3f61fd7e 100644 --- a/Indicators/x-saherelm.xfi.oscillator.mq5 +++ b/Indicators/x-saherelm.xfi.oscillator.mq5 @@ -38,10 +38,6 @@ input ENUM_APPLIED_VOLUME appliedTo = VOLUME_TICK; // Applied To // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -96,9 +92,6 @@ int OnInit() return INIT_PARAMETERS_INCORRECT; } - // - logTag = ShortName; - // fiHandler = iForce( _Symbol, @@ -108,11 +101,6 @@ int OnInit() appliedTo); if (fiHandler == INVALID_HANDLE) { - // - string message = "Error Initializing Handler ..."; - LogMessage(message); - - // return INIT_FAILED; } diff --git a/Indicators/x-saherelm.xlh.indicator.mq5 b/Indicators/x-saherelm.xlh.indicator.mq5 index 4dfc64e2..16858c25 100644 --- a/Indicators/x-saherelm.xlh.indicator.mq5 +++ b/Indicators/x-saherelm.xlh.indicator.mq5 @@ -38,10 +38,6 @@ input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -121,9 +117,6 @@ int OnInit() return INIT_PARAMETERS_INCORRECT; } - // - logTag = ShortName; - // // Define Index Buffers ... DefineBuffers(); @@ -310,10 +303,17 @@ void CalculateBuffers( _Period, hhMode, length, - bar_index); - double hhValue = GetAppliedPrice( - hhIndex, - hhMode); + bar_index + // + ); + XOHCL hhBar; + hhBar.Init( + _Symbol, + _Period, + hhIndex + // + ); + double hhValue = hhBar.GetPrice(hhMode); // hhBuffer[bar_index] = hhValue; @@ -325,16 +325,22 @@ void CalculateBuffers( _Period, llMode, length, - bar_index); - double llValue = GetAppliedPrice( - llIndex, - llMode); + bar_index + // + ); + XOHCL llBar; + llBar.Init( + _Symbol, + _Period, + llIndex + // + ); + double llValue = llBar.GetPrice(llMode); // llBuffer[bar_index] = llValue; // - XOHCL c = GetCandle(bar_index); double lhDiff = hhValue - llValue; double signalValue = (lhDiff / 2); diff --git a/Indicators/x-saherelm.xobd.indicator.mq5 b/Indicators/x-saherelm.xobd.indicator.mq5 index 4ac05cf6..d1ca9ed4 100644 --- a/Indicators/x-saherelm.xobd.indicator.mq5 +++ b/Indicators/x-saherelm.xobd.indicator.mq5 @@ -44,10 +44,6 @@ input color swingLowArrowColor = clrAqua; // Swing Low Arrow Color // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Include Common and Models Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -94,7 +90,6 @@ int OnInit() } // - logTag = ShortName; drawPrefix = ShortName; // @@ -125,10 +120,6 @@ void OnDeinit(const int reason) // REASON_TEMPLATE 7 Another chart template applied // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_CLOSE 9 Terminal closed - - // - // Here we can handle De Initialization Reasons ... - OnDeinitDrawLibrary(); } // @@ -264,32 +255,30 @@ void CalculateBuffers(int bar_index) // // Reading Candles Data ... - XOHCL candles[]; - for (int i = bar_index; i < bar_index + ((length * 2) + 2); i++) - { + int start = bar_index; + int count = (length * 2) + 2; + int end = start + count; + XOHCL bars[]; + GetBars( + bars, + _Symbol, + _Period, + start, + count // - XOHCL iCandle = GetCandle( - _Symbol, - _Period, - i); - - // - Add( - iCandle, - candles); - } + ); // // Swing Low ... isSwingLow = // - candles[1].close > candles[2].close && - candles[2].close > candles[3].close && + bars[1].close > bars[2].close && + bars[2].close > bars[3].close && // - candles[3].close < candles[4].close && + bars[3].close < bars[4].close && // - candles[5].close > candles[4].close && - candles[6].close > candles[5].close + bars[5].close > bars[4].close && + bars[6].close > bars[5].close // ; @@ -306,13 +295,13 @@ void CalculateBuffers(int bar_index) // Swing High ... isSwingHigh = // - candles[1].close < candles[2].close && - candles[2].close < candles[3].close && + bars[1].close < bars[2].close && + bars[2].close < bars[3].close && // - candles[3].close > candles[4].close && + bars[3].close > bars[4].close && // - candles[5].close < candles[4].close && - candles[6].close < candles[5].close + bars[5].close < bars[4].close && + bars[6].close < bars[5].close // ; @@ -355,12 +344,17 @@ void CalculateBuffers(int bar_index) // // Draw a Swing Arrow Shape ... void DrawSwingArrow( - int type, // Swing Type: 0 - Low / 1 - High ... - int bar_index) + int type, // Swing Type: 0 - Low / 1 - High ... + int bar_index // +) { // bool isSwingHigh = type == 1; - XOHCL candle = GetCandle(bar_index + 3); + XOHCL candle; + candle.Init( + _Symbol, + _Period, + bar_index + 3); double arrowDistanceInPoint = 0; // diff --git a/Indicators/x-saherelm.xrsi.oscillator.mq5 b/Indicators/x-saherelm.xrsi.oscillator.mq5 index 5659e07d..babf20d7 100644 --- a/Indicators/x-saherelm.xrsi.oscillator.mq5 +++ b/Indicators/x-saherelm.xrsi.oscillator.mq5 @@ -66,10 +66,6 @@ input ENUM_LINE_STYLE longExitLineStyle = STYLE_DOT; // Long Exit Style // START Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Include Common and Models Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -127,9 +123,6 @@ int OnInit() return INIT_PARAMETERS_INCORRECT; } - // - logTag = ShortName; - // rsiHandler = iRSI( _Symbol, diff --git a/Indicators/x-saherelm.xtd.oscillator.mq5 b/Indicators/x-saherelm.xtd.oscillator.mq5 index 5f46d187..d762b395 100644 --- a/Indicators/x-saherelm.xtd.oscillator.mq5 +++ b/Indicators/x-saherelm.xtd.oscillator.mq5 @@ -38,10 +38,6 @@ enum ENUM_X_XTD_STATES // END Constants ... // -// -// Include Models Library ... -#include "../Libraries/x-saherelm.models.lib.mq5" - // // START Inputs ... // @@ -61,10 +57,6 @@ input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5"; - // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5"; @@ -141,7 +133,6 @@ int OnInit() } // - logTag = ShortName; drawPrefix = ShortName; // @@ -175,10 +166,6 @@ void OnDeinit(const int reason) // // Here we can handle De Initialization Reasons ... - - // - // De Init Draw Library ... - OnDeinitDrawLibrary(); } // @@ -383,11 +370,11 @@ double GetState( // bullishCrossedUnderBearish = -2; // bullishUnderBearish = -1; // OtherWise = 0; - bool isBullishCrossedOverBearish = IsCrossOver( + bool isBullishCrossedOverBearish = IsCrossedOver( bullishBuffer, bearishBuffer, bar_index); - bool isBullishCrossedUnderBearish = IsCrossUnder( + bool isBullishCrossedUnderBearish = IsCrossedUnder( bullishBuffer, bearishBuffer, bar_index); diff --git a/Indicators/x-saherelm.xtm.indicator.mq5 b/Indicators/x-saherelm.xtm.indicator.mq5 index eac88e0a..7b924fbf 100644 --- a/Indicators/x-saherelm.xtm.indicator.mq5 +++ b/Indicators/x-saherelm.xtm.indicator.mq5 @@ -47,10 +47,6 @@ input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To // END Inputs ... // -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" @@ -105,9 +101,6 @@ int OnInit() return INIT_PARAMETERS_INCORRECT; } - // - logTag = ShortName; - // // Initializing MA Handler ... maHandler = iMA( @@ -119,11 +112,6 @@ int OnInit() maAppliedTo); if (maHandler == INVALID_HANDLE) { - // - string message = "Error Initializing Ma Handler ..."; - LogMessage(message); - - // return INIT_FAILED; } @@ -316,7 +304,13 @@ void CalculateBuffers(int bar_index) { // // Requirements ... - XOHCL candle = GetCandle(bar_index); + XOHCL candle; + candle.Init( + _Symbol, + _Period, + bar_index + // + ); // double maValue = maBuffer[bar_index]; diff --git a/Indicators/x-saherelm.xts.oscillator.mq5 b/Indicators/x-saherelm.xts.oscillator.mq5 index 46e9fbf9..00afe83c 100644 --- a/Indicators/x-saherelm.xts.oscillator.mq5 +++ b/Indicators/x-saherelm.xts.oscillator.mq5 @@ -23,20 +23,16 @@ // START Constants ... // +// #define ShortName "XTS" -enum ENUM_X_PERIOD_METHOD -{ - // - X_PERIOD_NOTHING, - // - X_PERIOD_AUTO, - // - X_PERIOD_MANUALLY -}; +// +// Includes Draw Library ... +#include "../Libraries/x-saherelm.draw.lib.mq5" // -// XTS Oscillator States ... +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" // // END Constants ... @@ -63,18 +59,6 @@ input ENUM_X_PERIOD_METHOD farestMethod = X_PERIOD_AUTO; // How to Find Farest P input ENUM_TIMEFRAMES farestPeriod = NULL; // Farest Time Frame input ENUM_APPLIED_PRICE farestAppliedTo = PRICE_CLOSE; // Farest Applied To -// -// Includes Logging Library ... -#include "../Libraries/x-saherelm.log.lib.mq5" - -// -// Includes Draw Library ... -#include "../Libraries/x-saherelm.draw.lib.mq5" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - // // START Buffers ... // @@ -165,7 +149,6 @@ int OnInit() } // - logTag = ShortName; drawPrefix = ShortName; // @@ -185,10 +168,6 @@ int OnInit() // DeInitialization ... void OnDeinit(const int reason) { - // - OnDeinitDrawLibrary(); - - // Comment(""); } @@ -368,15 +347,16 @@ void CalculateCurrent(int bar_index) startTime); // - XOHCL c = GetCandle( + XOHCL c; + c.Init( _Symbol, _Period, - startBarIndex); + startBarIndex + // + ); // - double value = GetAppliedPrice( - c, - currentAppliedTo); + double value = c.GetPrice(currentAppliedTo); // currentBuffer[bar_index] = value; @@ -394,7 +374,7 @@ void CalculateNearest(int bar_index) { // case X_PERIOD_AUTO: - mNearestPeriod = GetNearestTimeFrame(_Period); + mNearestPeriod = GetNearestPeriod(_Period); break; // @@ -420,15 +400,16 @@ void CalculateNearest(int bar_index) startTime); // - XOHCL c = GetCandle( + XOHCL c; + c.Init( _Symbol, _Period, - startBarIndex); + startBarIndex + // + ); // - double value = GetAppliedPrice( - c, - nearestAppliedTo); + double value = c.GetPrice(nearestAppliedTo); // nearestBuffer[bar_index] = value; @@ -446,7 +427,7 @@ void CalculateMediest(int bar_index) { // case X_PERIOD_AUTO: - mMediestPeriod = GetMediestTimeFrame(_Period); + mMediestPeriod = GetMediestPeriod(_Period); break; // @@ -472,15 +453,16 @@ void CalculateMediest(int bar_index) startTime); // - XOHCL c = GetCandle( + XOHCL c; + c.Init( _Symbol, _Period, - startBarIndex); + startBarIndex + // + ); // - double value = GetAppliedPrice( - c, - mediestAppliedTo); + double value = c.GetPrice(mediestAppliedTo); // mediestBuffer[bar_index] = value; @@ -498,7 +480,7 @@ void CalculateFarest(int bar_index) { // case X_PERIOD_AUTO: - mFarestPeriod = GetFarestTimeFrame(_Period); + mFarestPeriod = GetLongestPeriod(_Period); break; // @@ -524,15 +506,16 @@ void CalculateFarest(int bar_index) startTime); // - XOHCL c = GetCandle( + XOHCL c; + c.Init( _Symbol, _Period, - startBarIndex); + startBarIndex + // + ); // - double value = GetAppliedPrice( - c, - farestAppliedTo); + double value = c.GetPrice(farestAppliedTo); // farestBuffer[bar_index] = value; @@ -553,6 +536,7 @@ string GenerateDescriptionComment() // return result; } + // // END Functions ... // diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 96b33e68..634b73b6 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -18,9 +18,10 @@ #property link "https://www.saherelm.ir" #property version "1.00" #property strict - +\ // // Imports ... +#include "../Classes/x-saherelm.xmd5.class.mq5" // // Models ... @@ -435,10 +436,20 @@ struct XOHCL return result; } + // + // Retrieve Price base On Series Mode ... + double GetPrice(ENUM_SERIESMODE mMode) { + // + ENUM_X_PRICE mXMode = ToPrice(mMode); + + // + return GetPrice(mXMode); + } + // // Calculate Applied Price ... double GetPrice( - ENUM_APPLIED_PRICE appliedTo // Select Application Method + ENUM_APPLIED_PRICE mAppliedTo // Select Application Method ) { // @@ -446,7 +457,7 @@ struct XOHCL // // Calculate Applied Price ... - switch (appliedTo) + switch (mAppliedTo) { // case PRICE_CLOSE: @@ -3279,6 +3290,48 @@ string GetTypeName(const T &t) return typename(T); } +// +template +string GetToken(T &item) +{ + // + string mType = GetTypeName(item); + + // + string result = mType; + + // + string parts[]; + int partsCount = SplitContent( + parts, + result, + " " + // + ); + if (partsCount <= 0) + { + // + result = mType; + return result; + } + + // + bool hasLastPart = GetLastItem( + result, + parts + // + ); + if (!hasLastPart) + { + // + result = mType; + return result; + } + + // + return result; +} + // // Generate Unique Tags ... template @@ -3704,7 +3757,7 @@ double GetMax( // // Get Min of Specific Loopback of a Buffer ... template -double GetMinValue( +double GetMin( T &buffer[], // the Buffer which required to search int start = 0, // Start Index int count = 0 // Count for Search @@ -3753,7 +3806,7 @@ double GetMinValue( // // Find a Value less than Specified ... template -T FindLesserThanValue( +T FindLesserThan( T value, // Specified Value ... const T &source[], // Source ... bool isDescend = false // Find Biggest Lesser Value ... @@ -3814,7 +3867,7 @@ T FindLesserThanValue( // // Find a Value less than Specified ... template -T FindBiggerThanValue( +T FindBiggerThan( T value, // Specified Value ... const T &source[], // Source ... bool isDescend = false // Find Smallest Bigger Value ... @@ -3875,7 +3928,7 @@ T FindBiggerThanValue( // // Find Same Values in Array ... template -void FindSameValues( +void FindSames( T &result[], // Holds Result ... T &source[], // Source ... int verifications = 3 // Number of Consequence Repeat ... @@ -4821,6 +4874,77 @@ int ParseDoubleArraySurrounded( // return count; } +int ParseTimeArraySurrounded( + datetime &result[], // Holds Result + const string surrounded, // Surrounded Content + const string mToken, // Specified Token + string separator = ",", // Separator ... + const string startString = "(", // Expression Start String must be Unique + const string endString = ")", // Where to End Extraction, usually a Sign + bool forceClean = true // Clean Result ... +) +{ + // + int count = 0; + + // + if (forceClean) + { + Clean(result); + } + + // + int before = ArraySize(result); + + // + string contentStr = ParseStringSurrounded(surrounded, mToken); + if (!IsValid(contentStr)) + { + return count; + } + + // + string tmps[]; + int tmpsCount = SplitContent( + tmps, + contentStr + // + ); + if (tmpsCount <= 0) + { + return count; + } + + // + for (int i = 0; i < tmpsCount; i++) + { + // + string iTMP = tmps[i]; + if (!IsValid(iTMP)) + { + continue; + } + + // + datetime iValue = (datetime)iTMP; + + // + Add( + iValue, + result + // + ); + } + + // + int after = ArraySize(result); + + // + count = after - before; + + // + return count; +} // // Surround an String by Specific Token ... @@ -4859,6 +4983,38 @@ string Surround( return result; } +// +template +string SurroundArray( + string mToken, + T &value[], + string startString = "(", // Token Start Content + string endString = ")" // Token End Content +) +{ + // + string result = NULL; + + // + string valueStr = ToString(value); + if (!IsValid(valueStr)) + { + return result; + } + + // + result = Surround( + mToken, + valueStr, + startString, + endString + // + ); + + // + return result; +} + // // Periods / Cycles ... diff --git a/Libraries/x-saherelm.draw.lib.mq5 b/Libraries/x-saherelm.draw.lib.mq5 index b714abaf..2bdaf10d 100644 --- a/Libraries/x-saherelm.draw.lib.mq5 +++ b/Libraries/x-saherelm.draw.lib.mq5 @@ -20,2609 +20,7 @@ #property strict // -// START Inputs ... -// -// -// END Inputs ... -// - -// -// Include Logger Library ... -#include "x-saherelm.log.lib.mq5" -#include "x-saherelm.common.lib.mq5" -#include "../Classes/x-saherelm.xmd5.class.mq5" - -// -// START Global Definitions: Variables, Properties and etc ... -// - -// -string drawPrefix = "X-OBJ"; - -// -// END Global Definitions: Variables, Properties and etc ... -// - -// -// START Provided Functions ... -// - -// -// DeInitial Library if required ... -void OnDeinitDrawLibrary() -{ - RemoveDraws(); -} - -// -// remove drawn objects ... -void RemoveDraws( - string tag = NULL, - long chartId = -1, - int subWindow = -1) -{ - // - // Normalize Args ... - // - if (tag == NULL) - { - tag = drawPrefix; - } - - // - if (chartId == -1) - { - chartId = 0; - } - - // - if (subWindow == -1) - { - subWindow = 0; - } - - // - for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) - { - // - string on = ObjectName(chartId, iObj, subWindow); - if (StringFind(on, tag) >= 0) - { - ObjectDelete(chartId, on); - } - } - - // - // Redraw Chart ... - ChartRedraw(); -} - -// -bool RemoveDraw( - string name, - long chartId = -1, - int subWindow = -1) -{ - // - bool result = false; - - // - if (chartId == -1) - { - chartId = 0; - } - - // - if (subWindow == -1) - { - subWindow = 0; - } - - // - string objName = ""; - for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) - { - // - string on = ObjectName(chartId, iObj, subWindow); - if (StringFind(on, name) >= 0) - { - // - objName = on; - break; - } - } - - // - if (StringLen(objName) > 0) - { - result = ObjectDelete(chartId, objName); - } - - // - return result; -} - -// -// Deselect All Draws ... -void DeselectAllDraws() -{ - // - int objs = ObjectsTotal(ChartID(), 0); - for (int o = 0; o < objs; o++) - { - ObjectSetInteger(ChartID(), ObjectName(ChartID(), o, 0), OBJPROP_SELECTED, false); - } - - // - ChartRedraw(); -} - -// -// Check Object Exists ... -bool IsDrawExists( - string name, - long chartId = -1, - int subWindow = -1) -{ - // - bool result = false; - - // - if (chartId == -1) - { - chartId = 0; - } - - // - if (subWindow == -1) - { - subWindow = 0; - } - - // - for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) - { - // - string on = ObjectName(chartId, iObj, subWindow); - result = StringFind(on, name) >= 0; - if (result) - { - break; - } - } - - // - return result; -} - -// -// END Provided Functions ... -// - -// -// START Regular Draws ... -// - -// -// START Arrow Functions ... -// - -// -// Draw an Arrow Object on Chart ... -bool DrawArrow( - const long chartID = 0, // chart's ID - const string name = "Arrow", // arrow name - const int subWindow = 0, // subwindow index - datetime time = 0, // anchor point time - double price = 0, // anchor point price - const uchar arrowCode = 252, // arrow code - const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position - const color clr = clrAqua, // arrow color - const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style - const int width = 3, // arrow size - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = false, // hidden in the object list - const long zOrder = 0 // Order Object ... -) -{ - // - // set anchor point coordinates if they are not set ... - ChangeArrowEmptyPoint(time, price); - - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // create an arrow ... - if (!ObjectCreate(chartID, objName, OBJ_ARROW, subWindow, time, price)) - { - // - string message = - __FUNCTION__ + - ": failed to create an arrow! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set the arrow code ... - ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, arrowCode); - - // - // set anchor type ... - ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); - - // - // set the arrow color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set the border line style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set the arrow's size ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving the arrow by mouse - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is false by default, if you want making it possible to highlight and move the object - // change it to true ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Move the anchor point of Arrow ... -bool MoveArrow( - const long chartID = 0, // chart's ID - const string name = "Arrow", // object name - datetime time = 0, // anchor point time coordinate - double price = 0 // anchor point price coordinate -) -{ - // - // if point position is not set, move it to the current bar having Bid price ... - if (!time) - { - time = TimeCurrent(); - } - - // - if (!price) - { - price = SymbolInfoDouble(_Symbol, SYMBOL_BID); - } - - // - // reset the error value - ResetLastError(); - - // - // move the anchor point ... - if (!ObjectMove(chartID, name, 0, time, price)) - { - // - string message = - __FUNCTION__ + - ": failed to move the anchor point! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Delete an arrow ... -bool DeleteArrow( - const long chartID = 0, // chart's ID - const string name = "Arrow" // arrow name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete an arrow ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete an arrow! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Change the arrow code ... -bool ArrowCodeChange( - const long chartID = 0, // chart's ID - const string name = "Arrow", // object name - const uchar code = 252 // arrow code -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // change the arrow code ... - if (!ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code)) - { - // - string message = - __FUNCTION__ + - ": failed to change the arrow code! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Change anchor type ... -bool ArrowAnchorChange( - const long chartID = 0, // chart's ID - const string name = "Arrow", // object name - const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // change anchor type ... - if (!ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor)) - { - // - string message = - __FUNCTION__ + - ": failed to change anchor type! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Check anchor point values and set default values -// for empty ones ... -void ChangeArrowEmptyPoint( - datetime &time, - double &price) -{ - // - // if the point's time is not set, it will be on the current bar ... - if (!time) - { - time = TimeCurrent(); - } - - // - // if the point's price is not set, it will have Bid value ... - if (!price) - { - price = SymbolInfoDouble(_Symbol, SYMBOL_BID); - } -} - -// -// END Arrow Functions ... -// - -// -// START Horizontal Line Functions ... -// - -// -// Create, Draw the horizontal line ... -bool DrawHorizontalLine( - const long chartID = 0, // chart's ID - const string name = "HLine", // line name - const int subWindow = 0, // subwindow index - double price = 0, // line price - const color clr = clrRed, // line color - const ENUM_LINE_STYLE style = STYLE_SOLID, // line style - const int width = 1, // line width - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = false, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // if the price is not set, set it at the current Bid price level ... - if (!price) - { - price = SymbolInfoDouble(Symbol(), SYMBOL_BID); - } - - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // create a horizontal line ... - if (!ObjectCreate(chartID, objName, OBJ_HLINE, subWindow, 0, price)) - { - // - string message = - __FUNCTION__ + - ": failed to create a horizontal line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set line color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set line display style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set line width ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving the line by mouse - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is true by default making it possible to highlight and move the object - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Move horizontal line ... -bool MoveHorizontalLine( - const long chartID = 0, // chart's ID - const string name = "HLine", // line name - double price = 0 // line price -) -{ - // - // if the line price is not set, move it to the current Bid price level ... - if (!price) - { - price = SymbolInfoDouble(Symbol(), SYMBOL_BID); - } - - // - // reset the error value ... - ResetLastError(); - - // - // move a horizontal line ... - if (!ObjectMove(chartID, name, 0, 0, price)) - { - // - string message = - __FUNCTION__ + - ": failed to move the horizontal line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Delete a horizontal line ... -bool DeleteHorizontalLine( - const long chartID = 0, // chart's ID - const string name = "HLine" // line name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete a horizontal line ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete a horizontal line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// END Horizontal Line Functions ... -// - -// -// START Vertical Line Functions ... -// - -// -// Create the vertical line ... -bool DrawVerticalLine( - const long chartID = 0, // chart's ID - const string name = "VLine", // line name - const int subWindow = 0, // subwindow index - datetime time = 0, // line time - const color clr = clrRed, // line color - const ENUM_LINE_STYLE style = STYLE_SOLID, // line style - const int width = 1, // line width - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = false, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // if the line time is not set, draw it via the last bar ... - if (!time) - { - time = TimeCurrent(); - } - - // - // reset the error value - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // create a vertical line ... - if (!ObjectCreate(chartID, objName, OBJ_VLINE, subWindow, time, 0)) - { - // - string message = - __FUNCTION__ + - ": failed to create a vertical line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set line color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set line display style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set line width ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving the line by mouse - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is true by default making it possible to highlight and move the object ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Move the vertical line ... -bool MoveVerticalLine( - const long chartID = 0, // chart's ID - const string name = "VLine", // line name - datetime time = 0 // line time -) -{ - // - // if line time is not set, move the line to the last bar ... - if (!time) - { - time = TimeCurrent(); - } - - // - // reset the error value ... - ResetLastError(); - - // - // move the vertical line ... - if (!ObjectMove(chartID, name, 0, time, 0)) - { - // - string message = - __FUNCTION__ + - ": failed to move the vertical line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Delete the vertical line ... -bool DeleteVerticalLine( - const long chartID = 0, // chart's ID - const string name = "VLine" // line name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete the vertical line ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete the vertical line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// END Vertical Line Functions ... -// - -// -// START Rectangle Functions ... -// - -// -// Create rectangle by the given coordinates ... -bool DrawRectangle( - const long chartID = 0, // chart's ID - const string name = "Rectangle", // rectangle name - const int subWindow = 0, // subwindow index - datetime time1 = 0, // first point time - double price1 = 0, // first point price - datetime time2 = 0, // second point time - double price2 = 0, // second point price - const color clr = clrRed, // rectangle color - const ENUM_LINE_STYLE style = STYLE_SOLID, // style of rectangle lines - const int width = 1, // width of rectangle lines - const bool fill = false, // filling rectangle with color - const bool back = false, // in the background - const bool selection = true, // highlight to move - const bool hidden = true, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - bool result = false; - - // - // Set anchor points' coordinates if they are not set ... - ChangeRectangleEmptyPoints(time1, price1, time2, price2); - - // - // Create a rectangle by the given coordinates ... - result = ObjectCreate(chartID, name, OBJ_RECTANGLE, subWindow, time1, price1, time2, price2); - if (!result) - { - return result; - } - - // - // Set rectangle color ... - ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); - - // - // Set the style of rectangle lines - ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); - - // - // Set width of the rectangle lines ... - ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); - - // - // Enable (true) or disable (false) the mode of filling the rectangle ... - ObjectSetInteger(chartID, name, OBJPROP_FILL, fill); - - // - // Display in the foreground (false) or background (true) ... - ObjectSetInteger(chartID, name, OBJPROP_BACK, back); - - // - // Enable (true) or disable (false) the mode of highlighting the rectangle for moving - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is true by default making it possible to highlight and move the object - ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); - - // - ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); - - // - // Hide (true) or display (false) graphical object name in the object list ... - ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); - - // - // Set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); - - // - // Successful execution - return result; -} - -// -// Move the rectangle anchor point ...s -bool RectanglePointChange( - const long chartID = 0, // chart's ID - const string name = "Rectangle", // rectangle name - const int pointIndex = 0, // anchor point index - datetime time = 0, // anchor point time coordinate - double price = 0 // anchor point price coordinate -) -{ - // - bool result = false; - - // - // if point position is not set, move it to the current bar having Bid price ... - if (!time) - { - time = TimeCurrent(); - } - - // - if (!price) - { - price = SymbolInfoDouble(Symbol(), SYMBOL_BID); - } - - // - // Move the anchor point ... - result = ObjectMove(chartID, name, pointIndex, time, price); - if (!result) - { - return result; - } - - // - // Successful execution - return result; -} - -// -// Delete the rectangle ... -bool DeleteRectangle( - const long chartID = 0, // chart's ID - const string name = "Rectangle" // rectangle name -) -{ - // - bool result = false; - - // - result = ObjectDelete(chartID, name); - - // - return result; -} - -// -// Check the values of rectangle's anchor points and set default -// values for empty ones -void ChangeRectangleEmptyPoints( - datetime &time1, double &price1, - datetime &time2, double &price2) -{ - // - // if the first point's time is not set, it will be on the current bar ... - if (!time1) - { - time1 = TimeCurrent(); - } - - // - // if the first point's price is not set, it will have Bid value ... - if (!price1) - { - price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); - } - - // - // if the second point's time is not set, it is located 9 bars left from the second one ... - if (!time2) - { - // - // array for receiving the open time of the last 10 bars ... - datetime temp[10]; - CopyTime(Symbol(), Period(), time1, 10, temp); - - // - // set the second point 9 bars left from the first one ... - time2 = temp[0]; - } - - // - // if the second point's price is not set, move it 300 points lower than the first one ... - if (!price2) - { - price2 = price1 - 300 * SymbolInfoDouble(Symbol(), SYMBOL_POINT); - } -} - -// -// END Rectangle Functions ... -// - -// -// START RectangleLabel Functions ... -// - -// -// Create Rectangle Label Object ... -bool DrawRectangleLabel( - const long chartID = 0, // chart's ID - const string name = "RectLabel", // label name - const int subWindow = 0, // subwindow index - const int x = 0, // X coordinate - const int y = 0, // Y coordinate - const int width = 50, // width - const int height = 18, // height - const color bgColor = clrWhiteSmoke, // background color - const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type - const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring - const color clr = clrRed, // flat border color (Flat) - const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style - const int lineWidth = 1, // flat border width - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = false, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // - // create a rectangle label - if (!ObjectCreate(chartID, objName, OBJ_RECTANGLE_LABEL, subWindow, 0, 0)) - { - // - string message = - __FUNCTION__ + - ": failed to create a rectangle label! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set label coordinates ... - ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); - ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); - - // - // set label size ... - ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); - ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); - - // - // set background color ... - ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor); - - // - // set border type ... - ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border); - - // - // set the chart's corner, relative to which point coordinates are defined ... - ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); - - // - // set flat border color (in Flat mode) ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set flat border line style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set flat border width ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, lineWidth); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving the label by mouse ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Move Rectangle Label .. -bool MoveRectangleLabel( - const long chartID = 0, // chart's ID - const string name = "RectLabel", // label name - const int x = 0, // X coordinate - const int y = 0 // Y coordinate -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // move the rectangle label ... - if (!ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x)) - { - // - string message = - __FUNCTION__ + - ": failed to move X coordinate of the label! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - if (!ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y)) - { - // - string message = - __FUNCTION__ + - ": failed to move Y coordinate of the label! Error code = " + - (string)GetLastError(); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Delete the rectangle label ... -bool DeleteRectangleLabel( - const long chartID = 0, // chart's ID - const string name = "RectLabel" // label name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete the label ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete a rectangle label! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Change Rectangle Label Size ... -bool ChangeSizeRectangleLabel( - const long chartID = 0, // chart's ID - const string name = "RectLabel", // label name - const int width = 50, // label width - const int height = 18 // label height -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // change label size ... - if (!ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width)) - { - // - string message = - __FUNCTION__ + - ": failed to change the label's width! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - if (!ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height)) - { - // - string message = - __FUNCTION__ + - ": failed to change the label's height! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Change rectangle label border type ... -bool RectLabelChangeBorderType( - const long chartID = 0, // chart's ID - const string name = "RectLabel", // label name - const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // change border type ... - if (!ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border)) - { - // - string message = - __FUNCTION__ + - ": failed to change the border type! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// END RectangleLabel Functions ... -// - -// -// START TrendLine Funcions ... -// - -// -// Create a trend line by the given coordinates ... -bool DrawTrendLine( - const long chartID = 0, // chart's ID - const string name = "TrendLine", // line name - const int subWindow = 0, // subwindow index - datetime time1 = 0, // first point time - double price1 = 0, // first point price - datetime time2 = 0, // second point time - double price2 = 0, // second point price - const color clr = clrYellow, // line color - const ENUM_LINE_STYLE style = STYLE_SOLID, // line style - const int width = 1, // line width - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool rayRight = false, // line's continuation to the right - const bool hidden = false, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // set anchor points' coordinates if they are not set ... - ChangeTrendLineEmptyPoints( - time1, - price1, - time2, - price2); - - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // create a trend line by the given coordinates ... - if (!ObjectCreate(chartID, objName, OBJ_TREND, subWindow, time1, price1, time2, price2)) - { - // - string message = - __FUNCTION__ + - ": failed to create a trend line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set line color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set line display style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set line width ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving the line by mouse - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is true by default making it possible to highlight and move the object ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // enable true or disable false the mode of continuation of the line's display to the right ... - ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Move trend line anchor point ... | -bool ChangeTrendLinePoint( - const long chartID = 0, // chart's ID - const string name = "TrendLine", // line name - const int pointindex = 0, // anchor point index - datetime time = 0, // anchor point time coordinate - double price = 0 // anchor point price coordinate -) -{ - // - // if point position is not set, move it to the current bar having Bid price ... - if (!time) - { - time = TimeCurrent(); - } - - // - if (!price) - { - price = SymbolInfoDouble(Symbol(), SYMBOL_BID); - } - - // - // reset the error value ... - ResetLastError(); - - // - // move trend line's anchor point ... - if (!ObjectMove(chartID, name, pointindex, time, price)) - { - // - string message = - __FUNCTION__ + - ": failed to move the anchor point! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// The function deletes the trend line from the chart ... -bool DeleteTrendLine( - const long chartID = 0, // chart's ID - const string name = "TrendLine" // line name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete a trend line ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete a trend line! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Check the values of trend line's anchor points and set default ... -// values for empty ones ... -void ChangeTrendLineEmptyPoints( - datetime &time1, - double &price1, - datetime &time2, - double &price2) -{ - // - // if the first point's time is not set, it will be on the current bar ... - if (!time1) - { - time1 = TimeCurrent(); - } - - // - // if the first point's price is not set, it will have Bid value ... - if (!price1) - { - price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); - } - - // - // if the second point's time is not set, it is located 9 bars left from the second one ... - if (!time2) - { - // - // array for receiving the open time of the last 10 bars ... - datetime temp[10]; - CopyTime(Symbol(), Period(), time1, 10, temp); - - // - // set the second point 9 bars left from the first one ... - time2 = temp[0]; - } - - // - // if the second point's price is not set, it is equal to the first point's one ... - if (!price2) - { - price2 = price1; - } -} - -// -// END TrendLine Functions ... -// - -// -// START Text Functions ... -// - -// -// Create and Draw a Text Object ... -bool DrawText( - const long chartID = 0, // chart's ID - const string name = "Text", // object name - const int subWindow = 0, // subwindow index - datetime time = 0, // anchor point time - double price = 0, // anchor point price - const string text = "Text", // the text itself - const string font = "Arial", // font - const int fontSize = 10, // font size - const color clr = clrRed, // color - const double angle = 0.0, // text slope - const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = true, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // set anchor point coordinates if they are not set ... - ChangeTextEmptyPoint(time, price); - - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // - // create Text object - if (!ObjectCreate(chartID, objName, OBJ_TEXT, subWindow, time, price)) - { - // - string message = - __FUNCTION__ + - ": failed to create \"Text\" object! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set the text ... - ObjectSetString(chartID, objName, OBJPROP_TEXT, text); - - // - // set text font ... - ObjectSetString(chartID, objName, OBJPROP_FONT, font); - - // - // set font size ... - ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize); - - // - // set the slope angle of the text ... - ObjectSetDouble(chartID, objName, OBJPROP_ANGLE, angle); - - // - // set anchor type ... - ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); - - // - // set color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving the object by mouse ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Move the anchor point ... -bool MoveText( - const long chartID = 0, // chart's ID - const string name = "Text", // object name - datetime time = 0, // anchor point time coordinate - double price = 0 // anchor point price coordinate -) -{ - // - // - // if point position is not set, move it to the current bar having Bid price - if (!time) - { - time = TimeCurrent(); - } - - // - if (!price) - { - price = SymbolInfoDouble(_Symbol, SYMBOL_BID); - } - - // - // reset the error value ... - ResetLastError(); - - // - // move the anchor point .. - if (!ObjectMove(chartID, name, 0, time, price)) - { - // - string message = - __FUNCTION__ + - ": failed to move the anchor point! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Change the object text ... -bool ChangeText( - const long chartID = 0, // chart's ID - const string name = "Text", // object name - const string text = "Text" // text -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // change object text ... - if (!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) - { - // - string message = - __FUNCTION__ + - ": failed to change the text! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Delete Text object ... -bool DeleteText( - const long chartID = 0, // chart's ID - const string name = "Text" // object name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete the object ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete \"Text\" object! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution - return true; -} - -// -// Check anchor point values and set default values -// for empty ones ... -void ChangeTextEmptyPoint( - datetime &time, - double &price) -{ - // - // if the point's time is not set, it will be on the current bar ... - if (!time) - { - time = TimeCurrent(); - } - - // - // if the point's price is not set, it will have Bid value ... - if (!price) - { - price = SymbolInfoDouble(_Symbol, SYMBOL_BID); - } -} - -// -// END Text Functions ... -// - -// -// START Fibonacchi Functions ... -// - -// -// Create Fibonacci Retracement by the given coordinates ... -bool DrawFibonacci( - const long chartID = 0, // chart's ID - const string name = "Fibonacci", // object name - const int subWindow = 0, // subwindow index - datetime time1 = 0, // first point time - double price1 = 0, // first point price - datetime time2 = 0, // second point time - double price2 = 0, // second point price - const color clr = clrRed, // object color - const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style - const int width = 1, // object line width - const bool back = false, // in the background - const bool selection = true, // highlight to move - const bool rayRight = false, // object's continuation to the right - const bool hidden = true, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // set anchor points' coordinates if they are not set ... - ChangeFibonacciEmptyPoints(time1, price1, time2, price2); - - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // Create Fibonacci Retracement by the given coordinates ... - if (!ObjectCreate(chartID, objName, OBJ_FIBO, subWindow, time1, price1, time2, price2)) - { - // - string message = - __FUNCTION__ + - ": failed to create \"Fibonacci Retracement\"! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set line style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set line width ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of highlighting the channel for moving - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is true by default making it possible to highlight and move the object ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // enable true or disable false the mode of continuation of the object's display to the right ... - ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // successful execution ... - return true; -} - -// -// Create Fibonacci Retracement by the given coordinates ... -bool DrawCustomFibonacci( - // - int levels, // number of level lines - double &values[], // values of level lines - color &colors[], // color of level lines - ENUM_LINE_STYLE &styles[], // style of level lines - int &widths[], // width of level lines - string &descriptions[], // level Descriptions - // - const long chartID = 0, // chart's ID - const string name = "Fibonacci", // object name - const int subWindow = 0, // subwindow index - datetime time1 = 0, // first point time - double price1 = 0, // first point price - datetime time2 = 0, // second point time - double price2 = 0, // second point price - const color clr = clrAqua, // object color - const ENUM_LINE_STYLE style = STYLE_DOT, // object line style - const int width = 1, // object line width - const bool back = false, // in the background - const bool selection = true, // highlight to move - const bool rayRight = false, // object's continuation to the right - const bool hidden = true, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - // set anchor points' coordinates if they are not set ... - ChangeFibonacciEmptyPoints(time1, price1, time2, price2); - - // - // reset the error value ... - ResetLastError(); - - // - // Normalize Name ... - string objName = drawPrefix + "_" + name; - - // - // Create Fibonacci Retracement by the given coordinates ... - if (!ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2)) - { - // - string message = - __FUNCTION__ + - ": failed to create \"Fibonacci Retracement\"! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set color ... - ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); - - // - // set line style ... - ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); - - // - // set line width ... - ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true ... - ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of highlighting the channel for moving - // when creating a graphical object using ObjectCreate function, the object cannot be - // highlighted and moved by default. Inside this method, selection parameter - // is true by default making it possible to highlight and move the object ... - ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); - ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); - - // - // enable true or disable false the mode of continuation of the object's display to the right ... - ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); - - // - // hide true or display false graphical object name in the object list ... - ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart ... - ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); - - // - // Change Levels Of Fibonacci ... - bool result = FibonacciLevelsSet( - levels, - values, - colors, - styles, - widths, - descriptions, - chartID, - objName); - - // - // successful execution ... - return result; -} - -// -// Set number of levels and their parameters ... -bool FibonacciLevelsSet( - int levels, // number of level lines - double &values[], // values of level lines - color &colors[], // color of level lines - ENUM_LINE_STYLE &styles[], // style of level lines - int &widths[], // width of level lines - string &descriptions[], // level Descriptions - const long chartID = 0, // chart's ID - const string name = "Fibonacci" // object name -) -{ - // - // check array sizes ... - if ( - levels != ArraySize(colors) || - levels != ArraySize(styles) || - levels != ArraySize(widths) || - levels != ArraySize(widths)) - { - // - string message = - __FUNCTION__ + - ": array length does not correspond to the number of levels, error!"; - - // - LogMessage(message); - - // - return false; - } - - // - // set the number of levels ... - ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); - - // - // set the properties of levels in the loop ... - for (int i = 0; i < levels; i++) - { - // - // level value ... - ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); - - // - // level color ... - ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); - - // - // level style ... - ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); - - // - // level width ... - ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); - - // - // level description ... - // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); - ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); - } - - // - // successful execution ... - return true; -} - -// -// Move Fibonacci Retracement anchor point ... -bool FibonacciPointChange( - const long chartID = 0, // chart's ID - const string name = "Fibonacci", // object name - const int pointIndex = 0, // anchor point index - datetime time = 0, // anchor point time coordinate - double price = 0 // anchor point price coordinate -) -{ - // - // if point position is not set, move it to the current bar having Bid price ... - if (!time) - { - time = TimeCurrent(); - } - - // - if (!price) - { - price = SymbolInfoDouble(_Symbol, SYMBOL_BID); - } - - // - // reset the error value ... - ResetLastError(); - - // - // move the anchor point ... - if (!ObjectMove(chartID, name, pointIndex, time, price)) - { - // - string message = - __FUNCTION__ + - ": failed to move the anchor point! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Delete Fibonacci Retracement ... -bool DeleteFibonachi( - const long chartID = 0, // chart's ID - const string name = "Fibonacci" // object name -) -{ - // - // reset the error value ... - ResetLastError(); - - // - // delete the object ... - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete \"Fibonacci Retracement\"! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution ... - return true; -} - -// -// Check the values of Fibonacci Retracement anchor points and set -// default values for empty ones ... -void ChangeFibonacciEmptyPoints( - datetime &time1, - double &price1, - datetime &time2, - double &price2) -{ - // - // if the second point's time is not set, it will be on the current bar ... - if (!time2) - { - time2 = TimeCurrent(); - } - - // - // if the second point's price is not set, it will have Bid value ... - if (!price2) - { - price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); - } - - // - // if the first point's time is not set, it is located 9 bars left from the second one ... - if (!time1) - { - // - // array for receiving the open time of the last 10 bars ... - datetime temp[10]; - CopyTime(Symbol(), Period(), time2, 10, temp); - - // - // set the first point 9 bars left from the second one ... - time1 = temp[0]; - } - - // - // if the first point's price is not set, move it 200 points below the second one ... - if (!price1) - { - price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); - } -} - -// -// END Fibonacci Functions ... -// - -// -// START Event Functions ... -// - -// -// Create an Event ... -bool EventCreate( - const long chartID = 0, // chart's ID - const string name = "Event", // object name - const int subWindow = 0, // subwindow index - const string text = "Content", // event text - datetime time = 0, // anchor point time - const color clr = clrRed, // color - const int width = 1, // point width when highlighted - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = true, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - if (!time) - { - time = TimeCurrent(); - } - - // - ResetLastError(); - - // - if (!ObjectCreate(chartID, name, OBJ_EVENT, subWindow, time, 0)) - { - // - string message = - __FUNCTION__ + - ": failed to create \"Event\" object! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // set event text - ObjectSetString(chartID, name, OBJPROP_TEXT, text); - - // - // set color - ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); - - // - // set anchor point width if the object is highlighted - ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); - - // - // display in the foreground false or background true - ObjectSetInteger(chartID, name, OBJPROP_BACK, back); - - // - // enable true or disable false the mode of moving event by mouse - ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); - ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list - ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart - ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); - - // - // successful execution - return true; -} - -// -// Change Event object text -bool EventTextChange( - const long chartID = 0, // chart's ID - const string name = "Event", // event name - const string text = "Content" // text -) -{ - // - // reset the error value - ResetLastError(); - - // - // change object text - if (!ObjectSetString(chartID, name, OBJPROP_TEXT, text)) - { - // - string message = - __FUNCTION__ + - ": failed to change the text! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution - return true; -} - -// -// Move Event object -bool EventMove( - const long chartID = 0, // chart's ID - const string name = "Event", // event name - datetime time = 0 // time -) -{ - // - // if time is not set, move event to the last bar - if (!time) - { - time = TimeCurrent(); - } - - // - // reset the error value - ResetLastError(); - - // - // move the object - if (!ObjectMove(chartID, name, 0, time, 0)) - { - // - string message = - __FUNCTION__ + - ": failed to move \"Event\" object! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution - return true; -} - -// -// Delete Event object -bool EventDelete( - const long chartID = 0, // chart's ID - const string name = "Event" // event name -) -{ - // - // reset the error value - ResetLastError(); - - // - // delete the object - if (!ObjectDelete(chartID, name)) - { - // - string message = - __FUNCTION__ + - ": failed to delete \"Event\" object! Error code = " + - (string)GetLastError(); - - // - LogMessage(message); - - // - return false; - } - - // - // successful execution - return true; -} - -// -// END Event Functions ... -// - -// -// START Button Functions ... -// - -// -// Create the button ... -bool ButtonCreate( - const long chartID = 0, // chart's ID - const string name = "Button", // button name - const int subWindow = 0, // subwindow index - const int x = 0, // X coordinate - const int y = 0, // Y coordinate - const int width = 50, // button width - const int height = 15, // button height - const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring - const string text = "Button", // text - const string font = "Arial", // font - const int fontSize = 8, // font size - const color clr = clrBlack, // text color - const color bgColor = clrLightGray, // background color - const color borderColor = clrNONE, // border color - const bool state = false, // pressed/released - const bool back = false, // in the background - const bool selection = false, // highlight to move - const bool hidden = true, // hidden in the object list - const long zOrder = 0 // priority for mouse click -) -{ - // - bool result = false; - - // - // create the button - result = ObjectCreate(chartID, name, OBJ_BUTTON, subWindow, 0, 0); - if (!result) - { - return result; - } - - // - // set button coordinates - ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); - ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); - - // - // set button size - ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); - ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); - - // - // set the chart's corner, relative to which point coordinates are defined - ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); - - // - // set the text - ObjectSetString(chartID, name, OBJPROP_TEXT, text); - - // - // set text font - ObjectSetString(chartID, name, OBJPROP_FONT, font); - - // - // set font size - ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); - - // - // set text color - ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); - - // - // set background color - ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, bgColor); - - // - // set border color - ObjectSetInteger(chartID, name, OBJPROP_BORDER_COLOR, borderColor); - - // - // display in the foreground false or background true - ObjectSetInteger(chartID, name, OBJPROP_BACK, back); - - // - // set button state - ObjectSetInteger(chartID, name, OBJPROP_STATE, state); - - // - // enable true or disable false the mode of moving the button by mouse - ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); - ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); - - // - // hide true or display false graphical object name in the object list - ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); - - // - // set the priority for receiving the event of a mouse click in the chart - ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); - - // - return result; -} - -// -// Move the button ... -bool ButtonMove( - const long chartID = 0, // chart's ID - const string name = "Button", // button name - const int x = 0, // X coordinate - const int y = 0 // Y coordinate -) -{ - // - bool result = false; - - // - // move the button - - // - result = ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); - if (!result) - { - return result; - } - - // - result = ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); - - // - return result; -} - -// -// Change button size ... -bool ButtonChangeSize( - const long chartID = 0, // chart's ID - const string name = "Button", // button name - const int width = 50, // button width - const int height = 18 // button height -) -{ - // - bool result = false; - - // - // change the button size - - // - result = ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); - if (!result) - { - return result; - } - - // - result = ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); - - // - return result; -} - -// -// Change corner of the chart for binding the button ... -bool ButtonChangeCorner( - const long chartID = 0, // chart's ID - const string name = "Button", // button name - const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER // chart corner for anchoring -) -{ - // - bool result = false; - - // - // change anchor corner - - // - result = ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); - - // - return result; -} - -// -// Change button text ... -bool ButtonTextChange( - const long chartID = 0, // chart's ID - const string name = "Button", // button name - const string text = "Text" // text -) -{ - // - bool result = false; - - // - // change object text - result = ObjectSetString(chartID, name, OBJPROP_TEXT, text); - - // - return result; -} - -// -// Delete the button ... -bool ButtonDelete( - const long chartID = 0, // chart's ID - const string name = "Button" // button name -) -{ - // - bool result = false; - - // - // delete the button - result = ObjectDelete(chartID, name); - - // - return result; -} - -// -// END Button Functions ... -// - -// -// END Regular Draws ... -// - -// -// START Chart Style Drawers ... -// - -// -// Apply Styles On Chart ... -void ApplyChartStyle( - long mChartId = -1, // chart's ID - ENUM_CHART_MODE mMode = CHART_CANDLES, // chart's mMode - bool mShowBidLine = true, // show bid line - bool mShowAskLine = true, // show ask line - bool mShowGrid = false, // show grids on chart - bool mShowVolumes = false, // show volumes - bool mShowTradeLevels = true, // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) - bool mAutoScroll = true, // chart autoscroll - bool mQuickNavigation = true, // chart quick navigation state - color mForeGroundColor = clrWhite, // chart's foreground color - color mBackGroundColor = clrBlack, // chart's background color - color mUpColor = clrGreen, // Up Color - color mDownColor = clrRed, // Down Color - color mBullishColor = clrGreen, // Bullish color - color mBearishColor = clrRed, // Bearish color - color mGridColor = clrGray, // grid color - color mBidLineColor = clrGray, // bid line color - color mAskLineColor = clrRed, // ask line color - color mLineColor = clrLime, // line mMode and doji candlestick color - color mStopColor = clrGold, // Color of stop order levels (Stop Loss and Take Profit) - color mVolumesColor = clrGreen // volumes color -) -{ - // - // Validate Args ... - if (mChartId == -1) - { - mChartId = 0; - } - - // - ChartSetInteger(mChartId, CHART_MODE, mMode); - ChartSetInteger(mChartId, CHART_SHOW_BID_LINE, mShowBidLine); - ChartSetInteger(mChartId, CHART_SHOW_ASK_LINE, mShowAskLine); - ChartSetInteger(mChartId, CHART_SHOW_GRID, mShowGrid); - ChartSetInteger(mChartId, CHART_SHOW_VOLUMES, mShowVolumes); - ChartSetInteger(mChartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); - ChartSetInteger(mChartId, CHART_AUTOSCROLL, mAutoScroll); - ChartSetInteger(mChartId, CHART_QUICK_NAVIGATION, mQuickNavigation); - ChartSetInteger(mChartId, CHART_COLOR_FOREGROUND, mForeGroundColor); - ChartSetInteger(mChartId, CHART_COLOR_BACKGROUND, mBackGroundColor); - ChartSetInteger(mChartId, CHART_COLOR_CHART_UP, mUpColor); - ChartSetInteger(mChartId, CHART_COLOR_CHART_DOWN, mDownColor); - ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BULL, mBullishColor); - ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); - ChartSetInteger(mChartId, CHART_COLOR_GRID, mGridColor); - ChartSetInteger(mChartId, CHART_COLOR_BID, mBidLineColor); - ChartSetInteger(mChartId, CHART_COLOR_ASK, mAskLineColor); - ChartSetInteger(mChartId, CHART_COLOR_STOP_LEVEL, mStopColor); - ChartSetInteger(mChartId, CHART_COLOR_CHART_LINE, mLineColor); - ChartSetInteger(mChartId, CHART_COLOR_VOLUME, mVolumesColor); -} +// Global Definitions: Variables, Properties and etc ... // // Retrieve Chart Size in Pixel ... @@ -2642,38 +40,6 @@ struct XSize int hStep; }; -// -// Retrieve Chart Size ... -bool GetChartSize( - XSize &result, // Holds Result ... - long chartID = 0 // Specified Chart ID ... -) -{ - // - bool mResult = false; - - // - mResult = ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0, result.width); - if (!mResult) - { - return mResult; - } - - // - mResult = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0, result.height); - - // - return mResult; -} - -// -// END Chart Style Drawers ... -// - -// -// START Custom Drawings ... -// - // // Define a Draw Specifications ... struct XDrawSpecifications @@ -2970,639 +336,2108 @@ struct XOHCLDrawSpecification }; // -bool RemoveCandle( - XOHCL &c, - long chartId = 0, - int subWindow = 0 // +string drawPrefix = "X-OBJ"; + +// +// Common Draw Functions ... + +// +// remove drawn objects ... +void RemoveDraws( + string tag = NULL, + long chartId = -1, + int subWindow = -1 // +) +{ + // + // Normalize Args ... + // + if (tag == NULL) + { + tag = drawPrefix; + } + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + if (StringFind(on, tag) >= 0) + { + ObjectDelete(chartId, on); + } + } + + // + // Redraw Chart ... + ChartRedraw(); +} + +// +bool RemoveDraw( + string name, + long chartId = -1, + int subWindow = -1 // ) { // bool result = false; // - string cTag = GenerateTag(c); - - // - result = IsDrawExists( - cTag, - chartId, - subWindow); - if (!result) + if (chartId == -1) { - return result; + chartId = 0; } // - RemoveDraws( - cTag, - chartId, - subWindow); + if (subWindow == -1) + { + subWindow = 0; + } + + // + string objName = ""; + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + if (StringFind(on, name) >= 0) + { + // + objName = on; + break; + } + } + + // + if (StringLen(objName) > 0) + { + result = ObjectDelete(chartId, objName); + } // return result; } // -// XOHCL ... -void DrawCandleAsLine( - long chartId, // Chart ID ... - int subWindow, // SubWindow ... - XOHCL &c, // the Candle Which required to Draw ... - const datetime time, // Candle Time ... - XOHCLDrawSpecification &config, // Draw Specifications ... - string tag = "", // Draw Tag ... - bool update = true, // Update Draw if Exists ... - bool drawMidLine = true // Draw Open Close Middle Line ... +// Deselect All Draws ... +void DeselectAllDraws() +{ + // + int objs = ObjectsTotal(ChartID(), 0); + for (int o = 0; o < objs; o++) + { + ObjectSetInteger(ChartID(), ObjectName(ChartID(), o, 0), OBJPROP_SELECTED, false); + } + + // + ChartRedraw(); +} + +// +// Check Object Exists ... +bool IsDrawExists( + string name, + long chartId = -1, + int subWindow = -1 // ) { // - datetime cTime = TimeCurrent(); - XDrawSpecifications specs; + bool result = false; // - string baseTag = tag + GenerateTag(c); + if (chartId == -1) + { + chartId = 0; + } // - // Open ... - specs = config.openStyle; - if (specs.draw) + if (subWindow == -1) + { + subWindow = 0; + } + + // + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) { // - double value = c.open; - string valueTag = "|O|"; - - // - string mTag = baseTag + valueTag + ToString(value); - string mLblTag = baseTag + valueTag + "_lbl"; - - // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - mTag, - chartId, - subWindow // - ); - bool canDraw = !isExists || (isExists && update); - - // - if (isExists && canDraw) + string on = ObjectName(chartId, iObj, subWindow); + result = StringFind(on, name) >= 0; + if (result) { - // - DeleteText( - chartId, - mLblTag // - ); - - // - DeleteTrendLine( - chartId, - mTag // - ); - } - - // - if (canDraw) - { - // - // Draw Label ... - if (StringLen(specs.label) > 0) - { - DrawText( - chartId, - mLblTag, - subWindow, - cTime, - value, - specs.label, - specs.labelFont, - specs.labelFontSize, - specs.labelColor, - specs.labelAngel, - specs.labelAnchor, - specs.back, - specs.selection, - specs.hidden, - specs.zOrder // - ); - } - - // - // Draw ... - DrawTrendLine( - chartId, - mTag, - subWindow, - time, - value, - cTime, - value, - specs.clr, - specs.style, - specs.width, - specs.back, - specs.selection, - specs.rayRight, - specs.hidden, - specs.zOrder // - ); + break; } } // - // High ... - specs = config.highStyle; - if (specs.draw) + return result; +} + +// +// Regular Draws ... + +// +// Arrow Functions ... + +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = 252, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) +{ + // + bool result = false; + + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create an arrow ... + result = ObjectCreate(chartID, objName, OBJ_ARROW, subWindow, time, price); + if (!result) { - // - double value = c.high; - string valueTag = "|H|"; - - // - string mTag = baseTag + valueTag + ToString(value); - string mLblTag = baseTag + valueTag + "_lbl"; - - // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - mTag, - chartId, - subWindow // - ); - bool canDraw = !isExists || (isExists && update); - - // - if (isExists && canDraw) - { - // - DeleteText( - chartId, - mLblTag // - ); - - // - DeleteTrendLine( - chartId, - mTag // - ); - } - - // - if (canDraw) - { - // - // Draw Label ... - if (StringLen(specs.label) > 0) - { - DrawText( - chartId, - mLblTag, - subWindow, - cTime, - value, - specs.label, - specs.labelFont, - specs.labelFontSize, - specs.labelColor, - specs.labelAngel, - specs.labelAnchor, - specs.back, - specs.selection, - specs.hidden, - specs.zOrder // - ); - } - - // - // Draw ... - DrawTrendLine( - chartId, - mTag, - subWindow, - time, - value, - cTime, - value, - specs.clr, - specs.style, - specs.width, - specs.back, - specs.selection, - specs.rayRight, - specs.hidden, - specs.zOrder // - ); - } + return result; } // - // Close ... - specs = config.closeStyle; - if (specs.draw) + // set the arrow code ... + ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) { - // - double value = c.close; - string valueTag = "|C|"; - - // - string mTag = baseTag + valueTag + ToString(value); - string mLblTag = baseTag + valueTag + "_lbl"; - - // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - mTag, - chartId, - subWindow // - ); - bool canDraw = !isExists || (isExists && update); - - // - if (isExists && canDraw) - { - // - DeleteText( - chartId, - mLblTag // - ); - - // - DeleteTrendLine( - chartId, - mTag); - } - - // - if (canDraw) - { - // - // Draw Label ... - if (StringLen(specs.label) > 0) - { - DrawText( - chartId, - mLblTag, - subWindow, - cTime, - value, - specs.label, - specs.labelFont, - specs.labelFontSize, - specs.labelColor, - specs.labelAngel, - specs.labelAnchor, - specs.back, - specs.selection, - specs.hidden, - specs.zOrder // - ); - } - - // - // Draw ... - DrawTrendLine( - chartId, - mTag, - subWindow, - time, - value, - cTime, - value, - specs.clr, - specs.style, - specs.width, - specs.back, - specs.selection, - specs.rayRight, - specs.hidden, - specs.zOrder // - ); - } + time = TimeCurrent(); } // - // Low ... - specs = config.lowStyle; - if (specs.draw) + if (!price) { - // - double value = c.low; - string valueTag = "|L|"; + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } - // - string mTag = baseTag + valueTag + ToString(value); - string mLblTag = baseTag + valueTag + "_lbl"; + // + // move the anchor point ... + result = ObjectMove(chartID, name, 0, time, price); - // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - mTag, - chartId, - subWindow // - ); - bool canDraw = !isExists || (isExists && update); + // + return result; +} - // - if (isExists && canDraw) - { - // - DeleteText( - chartId, - mLblTag // - ); +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) +{ + // + bool result = false; - // - DeleteTrendLine( - chartId, - mTag); - } + // + // delete an arrow ... + result = !ObjectDelete(chartID, name); - // - if (canDraw) - { - // - // Draw Label ... - if (StringLen(specs.label) > 0) - { - DrawText( - chartId, - mLblTag, - subWindow, - cTime, - value, - specs.label, - specs.labelFont, - specs.labelFontSize, - specs.labelColor, - specs.labelAngel, - specs.labelAnchor, - specs.back, - specs.selection, - specs.hidden, - specs.zOrder // - ); - } + // + return result; +} - // - // Draw ... - DrawTrendLine( - chartId, - mTag, - subWindow, - time, - value, - cTime, - value, - specs.clr, - specs.style, - specs.width, - specs.back, - specs.selection, - specs.rayRight, - specs.hidden, - specs.zOrder // - ); - } +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) +{ + // + bool result = false; + + // + // change the arrow code ... + result = ObjectSetInteger(chartID, name, OBJPROP_ARROWCODE, code); + + // + return result; +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) +{ + // + bool result = false; + + // + // change anchor type ... + result = !ObjectSetInteger(chartID, name, OBJPROP_ANCHOR, anchor); + + // + return result; +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price // +) +{ + // + // if the point's time is not set, it will be on the current bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); } } // -void DrawCandleAsBox( - long chartId, // Chart ID ... - int subWindow, // SubWindow ... - XOHCL &c, // the Candle Which required to Draw ... - const datetime time, // Candle Time ... - XOHCLDrawSpecification &config, // Draw Specifications ... - string tag = "", // Draw Tag ... - bool drawBody = true, // Draw Body ... - bool drawShadows = true, // Draw Shadows ... - bool update = true // Update Draw if Exists ... +// Horizontal Line Functions ... + +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click ) { // - datetime cTime = TimeCurrent(); + bool result = false; // - // First Check all Styles Must Be Draw true ... - bool canDraw = - // - config.openStyle.draw && - config.highStyle.draw && - config.closeStyle.draw && - config.lowStyle.draw - // - ; - - // - if (!canDraw) + // if the price is not set, set it at the current Bid price level ... + if (!price) { - return; + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); } // - // Next we have to determine Candle is Bullish or Bearish ... - // - bool isBullish = - c.open < c.close; + // Normalize Name ... + string objName = drawPrefix + "_" + name; // - bool isBearish = - c.open > c.close; - - // - XDrawSpecifications bodySpec; - if (isBullish) + // create a horizontal line ... + result = ObjectCreate(chartID, objName, OBJ_HLINE, subWindow, 0, price); + if (!result) { - bodySpec = config.openStyle; - } - else if (isBearish) - { - bodySpec = config.closeStyle; - } - else - { - // - bodySpec.clr = clrGray; + return result; } // - // Now We have to Draw 3 Rectangle ... - // 1- Up Shadow - // 2- Candle Body - // 3- Down Shadow + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); // - double upPrice = MathMax(c.open, c.close); - double downPrice = MathMin(c.open, c.close); - double upShadowSize = c.high - upPrice; - double downShadowSize = downPrice - c.low; + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); // - string mTag = GenerateTag(c); + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); // - // Draw Up Shadow ... - if (drawShadows) + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) +{ + // + bool result = false; + + // + // if the line price is not set, move it to the current Bid price level ... + if (!price) { - // - string upShadowTag = mTag + "|US|"; - - XDrawSpecifications spec = config.highStyle; - - // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - upShadowTag, - chartId, - subWindow // - ); - - // - bool canDraw = !isExists || (isExists && update); - - // - if (isExists && canDraw) - { - // - DeleteRectangle( - chartId, - upShadowTag // - ); - } - - // - if (canDraw) - { - // - // New ... - DrawRectangle( - chartId, - upShadowTag, - subWindow, - time, - c.high, - cTime, - upPrice, - spec.clr, - spec.style, - spec.width, - spec.fill, - spec.back, - spec.selection, - spec.hidden, - spec.zOrder // - ); - } + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); } // - // Draw Body ... - if (drawBody) + // move a horizontal line ... + result = ObjectMove(chartID, name, 0, 0, price); + + // + return result; +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) +{ + // + bool result = false; + + // + // delete a horizontal line ... + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Vertical Line Functions ... + +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int subWindow = 0, // subwindow index + datetime time = 0, // line time + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // if the line time is not set, draw it via the last bar ... + if (!time) { - // - string bodyTag = mTag + "|BDY|"; - - // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - bodyTag, - chartId, - subWindow // - ); - - // - bool canDraw = !isExists || (isExists && update); - - // - if (isExists && canDraw) - { - // - DeleteRectangle( - chartId, - bodyTag // - ); - } - - // - if (canDraw) - { - // - // New ... - DrawRectangle( - chartId, - bodyTag, - subWindow, - time, - upPrice, - cTime, - downPrice, - bodySpec.clr, - bodySpec.style, - bodySpec.width, - bodySpec.fill, - bodySpec.back, - bodySpec.selection, - bodySpec.hidden, - bodySpec.zOrder // - ); - } + time = TimeCurrent(); } // - // Draw Down Shadow ... - if (drawShadows) + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a vertical line ... + result = ObjectCreate(chartID, objName, OBJ_VLINE, subWindow, time, 0); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) +{ + // + bool result = false; + + // + // if line time is not set, move the line to the last bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // move the vertical line ... + result = ObjectMove(chartID, name, 0, time, 0); + + // + return result; +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) +{ + // + bool result = false; + + // + // delete the vertical line ... + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Rectangle Functions ... + +// +// Create rectangle by the given coordinates ... +bool DrawRectangle( + const long chartID = 0, // chart's ID + const string name = "Rectangle", // rectangle name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // rectangle color + const ENUM_LINE_STYLE style = STYLE_SOLID, // style of rectangle lines + const int width = 1, // width of rectangle lines + const bool fill = false, // filling rectangle with color + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Set anchor points' coordinates if they are not set ... + ChangeRectangleEmptyPoints(time1, price1, time2, price2); + + // + // Create a rectangle by the given coordinates ... + result = ObjectCreate(chartID, name, OBJ_RECTANGLE, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // Set rectangle color ... + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // Set the style of rectangle lines + ObjectSetInteger(chartID, name, OBJPROP_STYLE, style); + + // + // Set width of the rectangle lines ... + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // Enable (true) or disable (false) the mode of filling the rectangle ... + ObjectSetInteger(chartID, name, OBJPROP_FILL, fill); + + // + // Display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // Enable (true) or disable (false) the mode of highlighting the rectangle for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + + // + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // Hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // Set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // Successful execution + return result; +} + +// +// Move the rectangle anchor point ...s +bool RectanglePointChange( + const long chartID = 0, // chart's ID + const string name = "Rectangle", // rectangle name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // Move the anchor point ... + result = ObjectMove(chartID, name, pointIndex, time, price); + + // + return result; +} + +// +// Delete the rectangle ... +bool DeleteRectangle( + const long chartID = 0, // chart's ID + const string name = "Rectangle" // rectangle name +) +{ + // + bool result = false; + + // + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Check the values of rectangle's anchor points and set default +// values for empty ones +void ChangeRectangleEmptyPoints( + datetime &time1, double &price1, + datetime &time2, double &price2 // +) +{ + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) + { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) + { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) { // - string downShadowTag = mTag + "|DS|"; - - XDrawSpecifications spec = config.lowStyle; + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); // - // Check if Object Exists Delete it ... - bool isExists = IsDrawExists( - downShadowTag, - chartId, - subWindow // - ); + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } - // - bool canDraw = !isExists || (isExists && update); - - // - if (isExists && canDraw) - { - // - DeleteRectangle( - chartId, - downShadowTag // - ); - } - - // - if (canDraw) - { - // - // New ... - DrawRectangle( - chartId, - downShadowTag, - subWindow, - time, - downPrice, - cTime, - downPrice + downShadowSize, - spec.clr, - spec.style, - spec.width, - spec.fill, - spec.back, - spec.selection, - spec.hidden, - spec.zOrder // - ); - } + // + // if the second point's price is not set, move it 300 points lower than the first one ... + if (!price2) + { + price2 = price1 - 300 * SymbolInfoDouble(Symbol(), SYMBOL_POINT); } } // -// END Custom Drawings ... +// RectangleLabel Functions ... + // +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color bgColor = clrWhiteSmoke, // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a rectangle label + result = ObjectCreate(chartID, objName, OBJ_RECTANGLE_LABEL, subWindow, 0, 0); + if (!result) + { + return result; + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor); + + // + // set border type ... + ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the label by mouse ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y = 0 // Y coordinate +) +{ + // + bool result = false; + + // + // move the rectangle label ... + result = ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + return result; +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) +{ + // + bool result = false; + + // + // delete the label ... + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) +{ + // + bool result = false; + + // + // change label size ... + result = ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + return result; +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) +{ + // + bool result = false; + + // + // change border type ... + result = ObjectSetInteger(chartID, name, OBJPROP_BORDER_TYPE, border); + + // + return result; +} + +// +// TrendLine Funcions ... + +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a trend line by the given coordinates ... + result = ObjectCreate(chartID, objName, OBJ_TREND, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // move trend line's anchor point ... + result = ObjectMove(chartID, name, pointindex, time, price); + + // + return result; +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) +{ + // + bool result = false; + + // + // delete a trend line ... + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 // +) +{ + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) + { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) + { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) + { + price2 = price1; + } +} + +// +// Text Functions ... + +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time, price); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // + // create Text object + result = ObjectCreate(chartID, objName, OBJ_TEXT, subWindow, time, price); + if (!result) + { + return result; + } + + // + // set the text ... + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, objName, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, objName, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the object by mouse ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // + // if point position is not set, move it to the current bar having Bid price + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, name, 0, time, price); + + // + return result; +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) +{ + // + bool result = false; + + // + // change object text ... + result = ObjectSetString(chartID, name, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) +{ + // + bool result = false; + + // + // delete the object ... + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price // +) +{ + // + // if the point's time is not set, it will be on the current bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} + +// +// Fibonacchi Functions ... + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create Fibonacci Retracement by the given coordinates ... + result = ObjectCreate(chartID, objName, OBJ_FIBO, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create Fibonacci Retracement by the given coordinates ... + result = ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + objName); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) +{ + // + bool result = false; + + // + // check array sizes ... + result = levels == ArraySize(colors) && + levels == ArraySize(styles) && + levels == ArraySize(widths) && + levels == ArraySize(widths); + if (!result) + { + return result; + } + + // + // set the number of levels ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for (int i = 0; i < levels; i++) + { + // + // level value ... + ObjectSetDouble(chartID, name, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, name, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return result; +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, name, pointIndex, time, price); + + // + return result; +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) +{ + // + bool result = false; + + // + // delete the object ... + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 // +) +{ + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) + { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) + { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time2, 10, temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) + { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} + +// +// Event Functions ... + +// +// Create an Event ... +bool EventCreate( + const long chartID = 0, // chart's ID + const string name = "Event", // object name + const int subWindow = 0, // subwindow index + const string text = "Content", // event text + datetime time = 0, // anchor point time + const color clr = clrRed, // color + const int width = 1, // point width when highlighted + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + if (!time) + { + time = TimeCurrent(); + } + + // + result = ObjectCreate(chartID, name, OBJ_EVENT, subWindow, time, 0); + if (!result) + { + return result; + } + + // + // set event text + ObjectSetString(chartID, name, OBJPROP_TEXT, text); + + // + // set color + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set anchor point width if the object is highlighted + ObjectSetInteger(chartID, name, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving event by mouse + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + // successful execution + return result; +} + +// +// Change Event object text +bool EventTextChange( + const long chartID = 0, // chart's ID + const string name = "Event", // event name + const string text = "Content" // text +) +{ + // + bool result = false; + + // + // change object text + result = ObjectSetString(chartID, name, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Move Event object +bool EventMove( + const long chartID = 0, // chart's ID + const string name = "Event", // event name + datetime time = 0 // time +) +{ + // + bool result = false; + + // + // if time is not set, move event to the last bar + if (!time) + { + time = TimeCurrent(); + } + + // + // move the object + result = ObjectMove(chartID, name, 0, time, 0); + + // + return result; +} + +// +// Delete Event object +bool EventDelete( + const long chartID = 0, // chart's ID + const string name = "Event" // event name +) +{ + // + bool result = false; + + // + // delete the object + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Button Functions ... + +// +// Create the button ... +bool ButtonCreate( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // button width + const int height = 15, // button height + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const string text = "Button", // text + const string font = "Arial", // font + const int fontSize = 8, // font size + const color clr = clrBlack, // text color + const color bgColor = clrLightGray, // background color + const color borderColor = clrNONE, // border color + const bool state = false, // pressed/released + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // create the button + result = ObjectCreate(chartID, name, OBJ_BUTTON, subWindow, 0, 0); + if (!result) + { + return result; + } + + // + // set button coordinates + ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + // set button size + ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + // set the chart's corner, relative to which point coordinates are defined + ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + // set the text + ObjectSetString(chartID, name, OBJPROP_TEXT, text); + + // + // set text font + ObjectSetString(chartID, name, OBJPROP_FONT, font); + + // + // set font size + ObjectSetInteger(chartID, name, OBJPROP_FONTSIZE, fontSize); + + // + // set text color + ObjectSetInteger(chartID, name, OBJPROP_COLOR, clr); + + // + // set background color + ObjectSetInteger(chartID, name, OBJPROP_BGCOLOR, bgColor); + + // + // set border color + ObjectSetInteger(chartID, name, OBJPROP_BORDER_COLOR, borderColor); + + // + // display in the foreground false or background true + ObjectSetInteger(chartID, name, OBJPROP_BACK, back); + + // + // set button state + ObjectSetInteger(chartID, name, OBJPROP_STATE, state); + + // + // enable true or disable false the mode of moving the button by mouse + ObjectSetInteger(chartID, name, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, name, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list + ObjectSetInteger(chartID, name, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, name, OBJPROP_ZORDER, zOrder); + + // + return result; +} + +// +// Move the button ... +bool ButtonMove( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int x = 0, // X coordinate + const int y = 0 // Y coordinate +) +{ + // + bool result = false; + + // + // move the button + + // + result = ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, x); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, y); + + // + return result; +} + +// +// Change button size ... +bool ButtonChangeSize( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int width = 50, // button width + const int height = 18 // button height +) +{ + // + bool result = false; + + // + // change the button size + + // + result = ObjectSetInteger(chartID, name, OBJPROP_XSIZE, width); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, name, OBJPROP_YSIZE, height); + + // + return result; +} + +// +// Change corner of the chart for binding the button ... +bool ButtonChangeCorner( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER // chart corner for anchoring +) +{ + // + bool result = false; + + // + // change anchor corner + result = ObjectSetInteger(chartID, name, OBJPROP_CORNER, corner); + + // + return result; +} + +// +// Change button text ... +bool ButtonTextChange( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const string text = "Text" // text +) +{ + // + bool result = false; + + // + // change object text + result = ObjectSetString(chartID, name, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Delete the button ... +bool ButtonDelete( + const long chartID = 0, // chart's ID + const string name = "Button" // button name +) +{ + // + bool result = false; + + // + // delete the button + result = ObjectDelete(chartID, name); + + // + return result; +} + +// +// Chart Style Drawers ... + +// +// Apply Styles On Chart ... +void ApplyChartStyle( + long mChartId = -1, // chart's ID + ENUM_CHART_MODE mMode = CHART_CANDLES, // chart's mMode + bool mShowBidLine = true, // show bid line + bool mShowAskLine = true, // show ask line + bool mShowGrid = false, // show grids on chart + bool mShowVolumes = false, // show volumes + bool mShowTradeLevels = true, // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) + bool mAutoScroll = true, // chart autoscroll + bool mQuickNavigation = true, // chart quick navigation state + color mForeGroundColor = clrWhite, // chart's foreground color + color mBackGroundColor = clrBlack, // chart's background color + color mUpColor = clrGreen, // Up Color + color mDownColor = clrRed, // Down Color + color mBullishColor = clrGreen, // Bullish color + color mBearishColor = clrRed, // Bearish color + color mGridColor = clrGray, // grid color + color mBidLineColor = clrGray, // bid line color + color mAskLineColor = clrRed, // ask line color + color mLineColor = clrLime, // line mMode and doji candlestick color + color mStopColor = clrGold, // Color of stop order levels (Stop Loss and Take Profit) + color mVolumesColor = clrGreen // volumes color +) +{ + // + // Validate Args ... + if (mChartId == -1) + { + mChartId = 0; + } + + // + ChartSetInteger(mChartId, CHART_MODE, mMode); + ChartSetInteger(mChartId, CHART_SHOW_BID_LINE, mShowBidLine); + ChartSetInteger(mChartId, CHART_SHOW_ASK_LINE, mShowAskLine); + ChartSetInteger(mChartId, CHART_SHOW_GRID, mShowGrid); + ChartSetInteger(mChartId, CHART_SHOW_VOLUMES, mShowVolumes); + ChartSetInteger(mChartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); + ChartSetInteger(mChartId, CHART_AUTOSCROLL, mAutoScroll); + ChartSetInteger(mChartId, CHART_QUICK_NAVIGATION, mQuickNavigation); + ChartSetInteger(mChartId, CHART_COLOR_FOREGROUND, mForeGroundColor); + ChartSetInteger(mChartId, CHART_COLOR_BACKGROUND, mBackGroundColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_UP, mUpColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_DOWN, mDownColor); + ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BULL, mBullishColor); + ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); + ChartSetInteger(mChartId, CHART_COLOR_GRID, mGridColor); + ChartSetInteger(mChartId, CHART_COLOR_BID, mBidLineColor); + ChartSetInteger(mChartId, CHART_COLOR_ASK, mAskLineColor); + ChartSetInteger(mChartId, CHART_COLOR_STOP_LEVEL, mStopColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_LINE, mLineColor); + ChartSetInteger(mChartId, CHART_COLOR_VOLUME, mVolumesColor); +} + +// +// Tools ... + +// +// Retrieve Chart Size ... +bool GetChartSize( + XSize &result, // Holds Result ... + long chartID = 0 // Specified Chart ID ... +) +{ + // + bool mResult = false; + + // + mResult = ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0, result.width); + if (!mResult) + { + return mResult; + } + + // + mResult = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0, result.height); + + // + return mResult; +} diff --git a/MQL5.code-workspace b/MQL5.code-workspace index 876a1499..8f4073c0 100644 --- a/MQL5.code-workspace +++ b/MQL5.code-workspace @@ -4,5 +4,9 @@ "path": "." } ], - "settings": {} + "settings": { + "C_Cpp.default.includePath": [ + "c:\\Users\\saherelm\\AppData\\Roaming\\MetaQuotes\\Terminal\\FAE4959D5A0334AE230243FCFFFD4053\\MQL5\\Include" + ] + } } \ No newline at end of file