update workspace ...

This commit is contained in:
2024-05-17 04:54:01 +03:30
parent 3fa288c92c
commit 642713072e
429 changed files with 111729 additions and 9330 deletions
@@ -0,0 +1,62 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSC121Provider
// Description: a Market Analyser and Signal Provider
//
//
// 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
//
// TODO:
// - [] add XCT for Candle Timing ...
// - [] add XCS for Candle Styling ...
// - [] add Support for XZG Indicator ...
// - [] implement XPV based on Market Cycles ...
// - [] create XPV Helper class ...
// - [] create XZG Helper class ...
// - [] add Pivots Functionality based on XZG and XPV ...
// - [] add File as Struct functionality and implement it ...
// - [] add Support for OnSignal Event ...
// - [] add support for Alerting ...
// - [] Refactor XSignal:
// -- [] Add support for Multiple TPS and Trailing Stops ...
// -- [] Add support for Clean, Constructor and Init Functions on struct ...
// -- [] Add support for Prepare Signal inside struct ...
// -- [] Add Support for Position Management inside XTrade Class for Handling
// Trail SL, or Partial Close Positions ...
// -- [] Convert providers from Array to string ...
// -- [] Add Support For Serializing and also Deseriallizing functionality ...
//
// Imports ...
//
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
//
// Definitions ...
//
// Configuration of X121 Provider ...
struct X121ProviderInputs
{
};
//
// Class ...
//
// Tools ...
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,444 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCDataCollector
// Description: provides Data Collection Requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
template <typename T>
class XSCDataCollector
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
void XSCDataCollector(
string path = NULL, // Base Folder for Data Store
string fileName = NULL // File Name for Data Store
)
{
//
if (!IsValid(path))
{
path = GetType();
}
//
if (!IsValid(fileName))
{
fileName = GetType() + ".txt";
}
//
Path(path);
FileName(fileName);
}
//
// Deconstructor ...
void ~XSCDataCollector() {}
//
// Properties ...
//
bool Path(string value)
{
//
bool result = false;
//
result = IsValid(value);
if (!result)
{
return result;
}
//
result = value != mPath;
if (!result)
{
return result;
}
//
mPath = value;
//
return result;
}
//
string Path()
{
return mPath;
}
//
bool FileName(string value)
{
//
bool result = false;
//
result = IsValid(value);
if (!result)
{
return result;
}
//
result = value != mFileName;
if (!result)
{
return result;
}
//
mFileName = value;
//
return result;
}
//
string FileName()
{
return mFileName;
}
//
// Tools ...
//
// Clear Exists Collected Data ...
void Clear()
{
//
ResetLastError();
//
string dataStorePath = GetStorePath();
//
// Check Data Store Exists or not ...
bool isExists = FileIsExist(dataStorePath);
if (!isExists)
{
return;
}
//
FileDelete(dataStorePath);
}
//
// Collect All Stored Items ...
int Collect(
T &items[] // Hold Result
)
{
//
int result = 0;
//
Clean(items);
//
// Reading Store Whole Content ...
//
string storePath = GetStorePath();
int mFileHandler = FileOpen(
storePath,
FILE_READ | FILE_TXT);
result = mFileHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
// Parse Store Content and Read Data ...
while (!FileIsEnding(mFileHandler))
{
//
// Each Line Represent One Model ...
string content = FileReadString(mFileHandler);
//
T iItem;
bool isValid = iItem.Parse(content);
if (isValid)
{
//
AddRef(
iItem,
items
//
);
}
}
//
// Close File ...
FileClose(mFileHandler);
//
result = ArraySize(items);
//
return result;
}
//
// Add Item ...
bool Add(
T &item // Item to Store
)
{
//
bool result = false;
//
result = item.IsValid();
if (!result)
{
return result;
}
//
string content = item.ToString();
result = IsValid(content);
if (!result)
{
return result;
}
//
string storePath = GetStorePath();
int mFileHandler = FileOpen(
storePath,
FILE_READ | FILE_WRITE | FILE_TXT);
result = mFileHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
FileSeek(mFileHandler, 0, SEEK_END);
FileWrite(mFileHandler, content);
FileFlush(mFileHandler);
FileClose(mFileHandler);
//
return result;
}
//
// Add Items ...
int Add(
T &items[] // Items to Add ...
)
{
//
int result = 0;
//
int itemsCount = ArraySize(items);
if (itemsCount <= 0)
{
return result;
}
//
for (int i = 0; i < itemsCount; i++)
{
//
T iItem = items[i];
//
if (!iItem.IsValid())
{
continue;
}
//
bool isAdded = Add(iItem);
if (isAdded)
{
result++;
}
}
//
return result;
}
//
// Remove Item ...
bool Remove(
T &item // Item to Remove
)
{
//
bool result = false;
//
result = item.IsValid();
if (!result)
{
return result;
}
//
T items[];
int itemsCount = Collect(items);
if (itemsCount <= 0)
{
return result;
}
//
int itemIndex = item.FindIndex(items);
result = ArrayRemove(
items,
itemIndex,
1);
if (!result)
{
return result;
}
//
Clear();
//
int itemsAdded = Add(items);
//
result = itemsAdded == ArraySize(items);
//
return result;
}
//
// Protected ...
protected:
//
// Tools ...
//
// Retrieve Type of Class as String ...
string GetType()
{
//
string mType = (string) typename(T);
//
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;
}
//
// Pricate ...
private:
//
// Props ...
//
string mPath; // Path
string mFileName; // Data Store File Name
//
// Tools ...
//
// Generate Full File Path ...
string GetFilePath(string fileName)
{
//
string result = "";
//
result =
//
Path() + "\\" + fileName
//
;
//
return result;
}
//
// Retrieve Data Store File Address ...
string GetStorePath()
{
//
string result = NULL;
//
result = GetFilePath(mFileName);
//
return result;
}
};
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,123 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCBaseHelper
// Description: provides all Base Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Includes ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Definitions ...
//
// a Class for Handle base requirements ...
// for indicators ...
class XSCBaseHelper
{
//
// Public ...
public:
//
// Constructor ...
void XSCBaseHelper(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period // Trading Time Frame
)
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCBaseHelper()
{
//
IndicatorRelease(mHandler);
}
//
// Setter(s) / Getter(s) ...
//
// Symbol ...
string GetSymbol()
{
return mSymbol;
}
//
// Period ...
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
// Retrieve Bars ...
int CountBars()
{
//
int result =
Bars(
mSymbol,
mPeriod);
//
return result;
}
//
int CountCalculatedBars()
{
return BarsCalculated(mHandler);
}
//
// Functions ...
//
// Protected ...
protected:
//
// Props ...
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Indicator Handler ...
int mHandler;
//
// Private ...
private:
//
};
//
// Tools ....
@@ -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;
}
};
@@ -0,0 +1,319 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCEABaseProvider
// Description: provides base requirements for
// Specific Sgnal Provider ...
//
//
// 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 Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// Notified a Signal was Appears ...
typedef void (*OnSignal)(
XSignal &signal);
//
// Notified a Guard Appears ...
typedef void (*OnGuard)(XGuard &guard);
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Base Class for All of our EA's ...
class XSCEABaseProvider
{
//
// Public ...
public:
//
// Constructor ...
void XSCEABaseProvider()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCEABaseProvider(
string symbol,
ENUM_TIMEFRAMES period,
bool ignoreTicksAfterSignalTillNewCandle = true)
{
//
mSymbol = symbol;
mPeriod = period;
//
mTag = mSymbol + "," + ToString(mPeriod);
//
mIsInTestMode = IsRunningOnTestMode();
//
mIgnoreTicksAfterSignalTillNewCandle = ignoreTicksAfterSignalTillNewCandle;
}
//
// Deconstructor ...
void ~XSCEABaseProvider()
{
}
//
bool CanIgnoreTick()
{
//
mIsNewCandle = IsNewCandle(
mSymbol,
mPeriod);
bool result = mIsInTestMode
? !mIsNewCandle
: !mIsNewCandle && mWaitUntilNewCandle;
//
if (result)
{
//
result = mIgnoreTicksAfterSignalTillNewCandle;
}
//
return result;
}
//
// Prepare State ...
void OnTick()
{
//
mIsNewCandle = IsNewCandle(
mSymbol,
mPeriod);
mCanIgnoreTick = mIsInTestMode
? !mIsNewCandle
: !mIsNewCandle && mWaitUntilNewCandle;
//
ProcessBuffers();
//
if (mCanIgnoreTick)
{
return;
}
//
mWaitUntilNewCandle = false;
//
ProcessTick();
}
//
virtual void PrepareTag();
//
// Initialize Indicators and Requirements ...
virtual bool Init();
//
virtual int GetMaxLength();
//
virtual int GetCalculatedBars();
//
// Handle Update Buffers ...
virtual void ProcessBuffers()
{
return;
}
//
// Handle On Tick Event ...
virtual void ProcessTick()
{
return;
}
//
// Check for Guards ...
virtual bool GuardCheck(XGuard &guards[]);
//
// Add Specific On Signal Event Handler ...
int AddOnSignalEventHandler(OnSignal handler)
{
//
ArrayResize(
mSignalEventHandlers,
ArraySize(mSignalEventHandlers) + 1);
//
int result = ArraySize(mSignalEventHandlers) - 1;
mSignalEventHandlers[result] = handler;
//
return result;
}
//
// Remove All On Signal Event Handler ...
void ReoveOnSignalEventHandlers()
{
//
ArrayFree(mSignalEventHandlers);
}
//
// Notify a Signal Found on all Event Listeners ...
void NotifyOnSignalEvent(XSignal &info)
{
//
int listenerCount = ArraySize(mSignalEventHandlers);
if (listenerCount <= 0)
{
return;
}
//
// Loop Through Listeners ...
for (int i = 0; i < listenerCount; i++)
{
//
OnSignal listener = mSignalEventHandlers[i];
//
listener(info);
}
}
//
// Protected ...
protected:
//
string mSymbol;
//
ENUM_TIMEFRAMES mPeriod;
//
string mTag;
//
bool mIsNewCandle;
bool mIsInTestMode;
bool mCanIgnoreTick;
bool mWaitUntilNewCandle;
//
// Private ...
private:
//
// Signal Event Handlers ...
OnSignal mSignalEventHandlers[];
//
bool mIgnoreTicksAfterSignalTillNewCandle;
};
//
// START Definitions ...
//
//
// Model Signal Providers Definitions ...
struct XBaseSignalProvider
{
//
// Provider use Which Symbol ...
string symbol;
//
// Provider use Which Time Frame ...
ENUM_TIMEFRAMES period;
//
// Risk Amount Per Trades Related to Time Frames ...
// Percent of Available Balance ...
double riskAmount;
//
// Desired Magic Number ...
ulong magicNumber;
};
//
struct XLastSignal
{
datetime at;
string provider;
};
//
// END Definitions ...
//
//
// START Usefull Functions ...
//
//
// Add Specific Provider to List ...
void Add(
XBaseSignalProvider &item, // item want to add
XBaseSignalProvider &buffer[] // Destination buffer
)
{
//
ArrayResize(
buffer,
ArraySize(buffer) + 1);
//
buffer[ArraySize(buffer) - 1] = item;
}
//
// END Usefull Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,603 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Seriallize Library
// ---------------------------------------
// Name: XSeriallizer
// Description: provides Seriallizing EA abilities ...
//
//
// 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
//
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
string XProviderToken = "PRV";
string XSupportToken = "SP";
string XSLTrailToken = "SLT";
string XPeriodToken = "PR";
//
string XConfigToken = "XPV";
string XItemSeparator = "|";
string XItemContentSeparator = ",";
//
string XFirstGenToken = "0";
//
// PERIOD ...
//
// Detect a Comment has period or not ...
bool HasPeriod(string comment)
{
//
bool result = false;
//
if (StringLen(comment) == 0)
{
return result;
}
//
int tokenPos = StringFind(
comment,
XPeriodToken);
result = tokenPos >= 0;
//
return result;
}
//
// Extract Period String ...
string ExtractPeriodString(string comment)
{
//
string result = "";
//
bool hasPeriod = HasPeriod(comment);
if (!hasPeriod)
{
return result;
}
//
result = ExtractString(
comment,
XPeriodToken + "(",
")");
//
return result;
}
//
// Extract Time Frame From Comment ...
ENUM_TIMEFRAMES ExtractPeriod(string comment)
{
//
ENUM_TIMEFRAMES result = NULL;
//
if (StringLen(comment) <= 0)
{
return result;
}
//
string periodStr = ExtractPeriodString(comment);
if (StringLen(periodStr) <= 0)
{
return result;
}
//
result = ToPeriod(periodStr);
//
return result;
}
//
// PROVIDER ...
//
// Extract a Provider name if exists from a Comment ...
string ExtractProvider(string comment)
{
//
string result = "";
if (StringLen(comment) <= 0)
{
return result;
}
//
result = ExtractString(
comment,
XProviderToken + "(",
")");
//
return result;
}
//
// Generate Provider String for Using in Positions Comment ...
// NOTE: if there is more than One Provider, it takes first
// provider as main and the others used to increase volume ...
string GenerateProvidersString(XSignal &signal)
{
//
string result = "";
//
int providersCount = ArraySize(signal.providers);
if (providersCount <= 0)
{
return result;
}
//
result = XProviderToken + "(" + signal.providers[0] + ")";
//
return result;
}
//
// SLTRAIL ...
//
string GenerateSLTrailComment(int level)
{
//
string result = "";
//
if (level <= 0)
{
return result;
}
//
result = XSLTrailToken + "(" + ToString(level) + ")";
//
return result;
}
//
int ExtractSLTrailLevel(string comment)
{
//
int result = 0;
//
if (StringLen(comment) == 0)
{
return result;
}
//
string levelStr = ExtractString(
comment,
XSLTrailToken + "(",
")");
if (StringLen(levelStr) == 0)
{
return result;
}
//
result = (int)levelStr;
//
return result;
}
//
string PrepareSLTrailComment(
const string comment // Original Position Comment ...
)
{
//
string result = "";
//
if (StringLen(comment) == 0)
{
return result;
}
//
int level = 0;
result = comment;
//
// Check Comment Contains SL Trailing or not ...
int lastTrailLevel = ExtractSLTrailLevel(comment);
if (lastTrailLevel <= 0)
{
level++;
}
else
{
//
level = lastTrailLevel + 1;
string lastLevelStr = GenerateSLTrailComment(lastTrailLevel);
StringReplace(
result,
lastLevelStr,
"");
}
//
// Generate level Comment ...
string levelStr = GenerateSLTrailComment(level);
result += levelStr;
//
return result;
}
//
// SUPPORT ...
//
// Generate Specific Position's Support Comment
// index is number of Supports ...
string GenerateSupportSignalComment(
ulong ticket, // Position/Order Ticket
int index // Support Index ...
)
{
//
string result = "";
//
result = XSupportToken + "(" + (string)ticket + "," + ToString(index) + ")";
//
return result;
}
//
// Extract Support Parameters String from specified Comment ...
string ExtractSupportParam(string comment)
{
//
string result = "";
if (StringLen(comment) <= 0)
{
return result;
}
//
result = ExtractString(
comment,
XSupportToken + "(",
")");
//
return result;
}
//
// Extract Support Info as String array for Specific Comment ...
bool ExtractSupportParams(
string comment, // Specified Comment ...
string &params[] // Hold Result ...
)
{
//
bool result = false;
//
string supParam = ExtractSupportParam(comment);
if (StringLen(supParam) == 0)
{
return result;
}
//
SplitContent(
params,
supParam);
int paramsCount = ArraySize(params);
//
result = paramsCount == 2;
//
return result;
}
//
// Extract Support Parent Ticket ...
ulong ExtractParentTicket(string comment)
{
//
ulong result = 0;
//
string params[];
bool isSupport = ExtractSupportParams(
comment,
params);
if (!isSupport)
{
return result;
}
//
result = (ulong)params[0];
//
return result;
}
//
// Extract Support Index ...
int ExtractSupportIndex(string comment)
{
//
int result = -1;
//
string params[];
bool isSupport = ExtractSupportParams(
comment,
params);
if (!isSupport)
{
return result;
}
//
result = (int)params[1];
//
return result;
}
//
// START XEQM Support ...
//
//
string XEQMSupportToken = "XEQM";
//
// Generate String Tag for EQM Support Signals ...
string GenerateXEQMSupportComment()
{
//
string result = XEQMSupportToken;
//
return result;
}
//
// Check a Comment belongs to a EQM Support or not ...
bool IsEQMSupport(string comment)
{
//
bool result = false;
//
if (StringLen(comment) <= 0)
{
return result;
}
//
int tokenPosition = StringFind(
comment,
XEQMSupportToken);
result = tokenPosition >= 0;
//
return result;
}
//
// Select EQM Support Orders ...
int GetEQMSupportOrders(
XOrder &supports[], // Hold Result ...
XOrder &orders[], // List of All Orders ...
ENUM_TIMEFRAMES period = NULL // Specified Period ...
)
{
//
int result = 0;
//
// Cleanup Array ...
Clean(supports);
//
// Count Orders ...
int ordersCount = ArraySize(orders);
if (ordersCount <= 0)
{
return result;
}
//
// Loop through Orders ...
for (int i = 0; i < ordersCount; i++)
{
//
// Select Indexed Order ...
XOrder iOrder = orders[i];
//
// Check Order is Support or not ...
bool isSupport = IsEQMSupport(iOrder.comment);
if (!isSupport)
{
continue;
}
//
// Check Order is not Triggered ...
if (iOrder.state != ORDER_STATE_PLACED)
{
continue;
}
//
// Check Period ...
if (period != NULL && iOrder.period != period)
{
continue;
}
//
// we now sure this order is EQM Support ...
Add(
iOrder,
supports);
}
//
// Count Result ...
result = ArraySize(supports);
//
return result;
}
//
// Select EQM Support Positions ...
int GetEQMSupportPositions(
XPosition &supports[], // Hold Result ...
XPosition &positions[], // List of All Positions ...
ENUM_TIMEFRAMES period = NULL // Specified Period ...
)
{
//
int result = 0;
//
// Cleanup Array ...
Clean(supports);
//
// Count Positions ...
int positionsCount = ArraySize(positions);
if (positionsCount <= 0)
{
return result;
}
//
// Loop through Positions ...
for (int i = 0; i < positionsCount; i++)
{
//
// Select Indexed Position ...
XPosition iPosition = positions[i];
//
// Check Position is Support or not ...
bool isSupport = IsEQMSupport(iPosition.comment);
if (!isSupport)
{
continue;
}
//
// Check Period ...
if (period != NULL && iPosition.period != period)
{
continue;
}
//
// we now sure this order is EQM Support ...
Add(
iPosition,
supports);
}
//
// Count Result ...
result = ArraySize(supports);
//
return result;
}
//
// END XEQM Support ...
//
//
// START FirstGen ...
//
//
string GenerateFirstGenIdentifier(const string signaller)
{
//
string result = "";
//
if (StringLen(signaller) <= 0)
{
return result;
}
//
return signaller + XFirstGenToken;
//
return result;
}
//
bool IsFirstGenOf(
const string signaller, // Specified Signaller
const string comment // Comment
)
{
//
bool result = false;
//
string id = GenerateFirstGenIdentifier(signaller);
//
int idPos = StringFind(
comment,
id
);
result = idPos >= 0;
//
return result;
}
//
// END FirstGen ...
//
@@ -0,0 +1,294 @@
//+------------------------------------------------------------------+
//| ZigZag.mq5 |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1
//--- plot ZigZag
#property indicator_label1 "ZigZag"
#property indicator_type1 DRAW_SECTION
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int InpDepth =12; // Depth
input int InpDeviation=5; // Deviation
input int InpBackstep =3; // Back Step
//--- indicator buffers
double ZigZagBuffer[]; // main buffer
double HighMapBuffer[]; // ZigZag high extremes (peaks)
double LowMapBuffer[]; // ZigZag low extremes (bottoms)
int ExtRecalc=3; // number of last extremes for recalculation
enum EnSearchMode
{
Extremum=0, // searching for the first extremum
Peak=1, // searching for the next ZigZag peak
Bottom=-1 // searching for the next ZigZag bottom
};
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ZigZagBuffer,INDICATOR_DATA);
SetIndexBuffer(1,HighMapBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,LowMapBuffer,INDICATOR_CALCULATIONS);
//--- set short name and digits
string short_name=StringFormat("ZigZag(%d,%d,%d)",InpDepth,InpDeviation,InpBackstep);
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
PlotIndexSetString(0,PLOT_LABEL,short_name);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set an empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
}
//+------------------------------------------------------------------+
//| ZigZag calculation |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(rates_total<100)
return(0);
//---
int i=0;
int start=0,extreme_counter=0,extreme_search=Extremum;
int shift=0,back=0,last_high_pos=0,last_low_pos=0;
double val=0,res=0;
double curlow=0,curhigh=0,last_high=0,last_low=0;
//--- initializing
if(prev_calculated==0)
{
ArrayInitialize(ZigZagBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
start=InpDepth;
}
//--- ZigZag was already calculated before
if(prev_calculated>0)
{
i=rates_total-1;
//--- searching for the third extremum from the last uncompleted bar
while(extreme_counter<ExtRecalc && i>rates_total-100)
{
res=ZigZagBuffer[i];
if(res!=0.0)
extreme_counter++;
i--;
}
i++;
start=i;
//--- what type of exremum we search for
if(LowMapBuffer[i]!=0.0)
{
curlow=LowMapBuffer[i];
extreme_search=Peak;
}
else
{
curhigh=HighMapBuffer[i];
extreme_search=Bottom;
}
//--- clear indicator values
for(i=start+1; i<rates_total && !IsStopped(); i++)
{
ZigZagBuffer[i] =0.0;
LowMapBuffer[i] =0.0;
HighMapBuffer[i]=0.0;
}
}
//--- searching for high and low extremes
for(shift=start; shift<rates_total && !IsStopped(); shift++)
{
//--- low
val=low[Lowest(low,InpDepth,shift)];
if(val==last_low)
val=0.0;
else
{
last_low=val;
if((low[shift]-val)>InpDeviation*_Point)
val=0.0;
else
{
for(back=1; back<=InpBackstep; back++)
{
res=LowMapBuffer[shift-back];
if((res!=0) && (res>val))
LowMapBuffer[shift-back]=0.0;
}
}
}
if(low[shift]==val)
LowMapBuffer[shift]=val;
else
LowMapBuffer[shift]=0.0;
//--- high
val=high[Highest(high,InpDepth,shift)];
if(val==last_high)
val=0.0;
else
{
last_high=val;
if((val-high[shift])>InpDeviation*_Point)
val=0.0;
else
{
for(back=1; back<=InpBackstep; back++)
{
res=HighMapBuffer[shift-back];
if((res!=0) && (res<val))
HighMapBuffer[shift-back]=0.0;
}
}
}
if(high[shift]==val)
HighMapBuffer[shift]=val;
else
HighMapBuffer[shift]=0.0;
}
//--- set last values
if(extreme_search==0) // undefined values
{
last_low=0.0;
last_high=0.0;
}
else
{
last_low=curlow;
last_high=curhigh;
}
//--- final selection of extreme points for ZigZag
for(shift=start; shift<rates_total && !IsStopped(); shift++)
{
res=0.0;
switch(extreme_search)
{
case Extremum:
if(last_low==0.0 && last_high==0.0)
{
if(HighMapBuffer[shift]!=0)
{
last_high=high[shift];
last_high_pos=shift;
extreme_search=Bottom;
ZigZagBuffer[shift]=last_high;
res=1;
}
if(LowMapBuffer[shift]!=0.0)
{
last_low=low[shift];
last_low_pos=shift;
extreme_search=Peak;
ZigZagBuffer[shift]=last_low;
res=1;
}
}
break;
case Peak:
if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<last_low && HighMapBuffer[shift]==0.0)
{
ZigZagBuffer[last_low_pos]=0.0;
last_low_pos=shift;
last_low=LowMapBuffer[shift];
ZigZagBuffer[shift]=last_low;
res=1;
}
if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
{
last_high=HighMapBuffer[shift];
last_high_pos=shift;
ZigZagBuffer[shift]=last_high;
extreme_search=Bottom;
res=1;
}
break;
case Bottom:
if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>last_high && LowMapBuffer[shift]==0.0)
{
ZigZagBuffer[last_high_pos]=0.0;
last_high_pos=shift;
last_high=HighMapBuffer[shift];
ZigZagBuffer[shift]=last_high;
}
if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
{
last_low=LowMapBuffer[shift];
last_low_pos=shift;
ZigZagBuffer[shift]=last_low;
extreme_search=Peak;
}
break;
default:
return(rates_total);
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Search for the index of the highest bar |
//+------------------------------------------------------------------+
int Highest(const double &array[],const int depth,const int start)
{
if(start<0)
return(0);
double max=array[start];
int index=start;
//--- start searching
for(int i=start-1; i>start-depth && i>=0; i--)
{
if(array[i]>max)
{
index=i;
max=array[i];
}
}
//--- return index of the highest bar
return(index);
}
//+------------------------------------------------------------------+
//| Search for the index of the lowest bar |
//+------------------------------------------------------------------+
int Lowest(const double &array[],const int depth,const int start)
{
if(start<0)
return(0);
double min=array[start];
int index=start;
//--- start searching
for(int i=start-1; i>start-depth && i>=0; i--)
{
if(array[i]<min)
{
index=i;
min=array[i];
}
}
//--- return index of the lowest bar
return(index);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,34 @@
void CommentLab(string CommentText)
{
//
string CommentLabel;
int CommentIndex = 0;
//
if (CommentText == "")
{
//
// delete all Comment texts
while (ObjectFind(StringConcatenate("CommentLabel", CommentIndex)) >= 0)
{
//
ObjectDelete(StringConcatenate("CommentLabel", CommentIndex));
CommentIndex++;
}
return;
}
//
while (ObjectFind(StringConcatenate("CommentLabel", CommentIndex)) >= 0)
{
CommentIndex++;
}
//
CommentLabel = StringConcatenate("CommentLabel", CommentIndex);
ObjectCreate(CommentLabel, OBJ_LABEL, 0, 0, 0);
ObjectSet(CommentLabel, OBJPROP_CORNER, 0);
ObjectSet(CommentLabel, OBJPROP_XDISTANCE, 5);
ObjectSet(CommentLabel, OBJPROP_YDISTANCE, 15 + (CommentIndex * 15));
ObjectSetText(CommentLabel, CommentText, 10, "Tahoma", Status_Color);
}
@@ -0,0 +1,102 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Models Library
// ---------------------------------------
// Name: XModels
// Description: provides all required models ...
//
//
// 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 Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// How To Calculate Static Volume ...
enum ENUM_STATIC_VOLUME_METHODS
{
//
// Based On Deposit ...
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
//
// Based On Balance ...
X_STATIC_VOLUME_BASED_ON_BALANCE,
};
//
// START Model Definitions ...
//
//
// Select Positions Type ...
enum ENUM_X_POSITION_SELECT_METHODS
{
X_POSITION_SELECT_NONE, // None
X_POSITION_SELECT_MAX, // Max
X_POSITION_SELECT_MIN, // Min
X_POSITION_SELECT_ALL, // Min
};
//
// Available Guard Action ...
enum ENUM_X_GUARD_ACTIONS
{
X_GUARD_ACTION_NOTHING, // Nothing
X_GUARD_ACTION_HEDGE, // Hedge
X_GUARD_PARTIAL_CLOSE, // Partial Close
X_GUARD_ACTION_TRAIL_STOP, // Trail StopLoss
X_GUARD_ACTION_FORCE_CLOSE, // Force Close
X_GUARD_ACTION_ADD_SUPPORT_SIGNAL, // Add Support Signal
X_GUARD_ACTION_CANCEL_PENDING_ORDERS, // Cancel Pending Orders
};
//
// Model Guard Info ...
struct XGuard
{
string symbol;
string provider;
ENUM_TIMEFRAMES period;
ENUM_POSITION_TYPE type;
ENUM_X_GUARD_ACTIONS action;
//
double dblPayLoad;
string strPayload;
};
//
// EXTENSION Methods ...
//
// END Provided Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,728 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
// -------------------------------------------------
// Name: XSAMPLE
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XSAMPLE"
#property strict
//
#define ShortName "XSAMPLE"
//
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
#include "../Helpers/x-saherelm.x121.xmc.helper.mq5"
#include "../Helpers/x-saherelm.x121.xstr.helper.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.mq5"
#include "../Helpers/x-saherelm.x121.xosc.helper.mq5"
//
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
//
// Inputs ...
long xSampleEAMagicNumber = 78692110; // Magic Number
int xSampleEASlippage = 10; // Slippgae
//
double xSampleEAVolume = 0.01;
//
// Vars ...
string xSampleEASymbol;
ENUM_TIMEFRAMES xSampleEAPeriod;
//
int maxBuys = 1;
int maxSells = 1;
int buyCount = 0;
int sellCount = 0;
//
double _tp = 0;
double _sl = 0;
double _entry = 0;
ENUM_POSITION_TYPE _type = NULL;
//
MqlTick xSampleEATick;
XSCTrade *xSampleEATrader;
// //
// // XCHE ...
// X121CHEInputs xSampleEACHEInputs;
// XSCX121CHEHelper xSampleEACHEHelper;
// //
// // XMC ...
// X121MCInputs xSampleEAMCInputs;
// XSCX121MCHelper xSampleEAMCHelper;
// //
// // XSTR ...
// X121STRInputs xSampleEASTRInputs;
// XSCX121STRHelper xSampleEASTRHelper;
// //
// // XOSC ...
// X121OSCInputs xSampleEAOSCInputs;
// XSCX121OSCHelper xSampleEAOSCHelper;
// //
// // XICH ...
// X121ICHInputs xSampleEAICHInputs;
// XSCX121ICHHelper xSampleEAICHHelper;
//
// X121MCycle ...
X121MCycleInputs xSampleEA121MCInputs;
XSC121Market xSampleEA121MC;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0)
{
xSampleEASymbol = _Symbol;
}
//
if (xSampleEAPeriod == NULL)
{
xSampleEAPeriod = _Period;
}
//
// Validate Inputs ...
if (!XSampleEAValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
drawPrefix = ShortName;
// //
// // XCHE ...
// //
// xSampleEACHEInputs.Default();
// if (!xSampleEACHEInputs.IsValid())
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// if (!xSampleEACHEHelper.Init(
// xSampleEASymbol,
// xSampleEAPeriod,
// xSampleEACHEInputs))
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// // XMC ...
// //
// xSampleEAMCInputs.Default();
// if (!xSampleEAMCInputs.IsValid())
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// if (!xSampleEAMCHelper.Init(
// xSampleEASymbol,
// xSampleEAPeriod,
// xSampleEAMCInputs))
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// // XSTR ...
// //
// xSampleEASTRInputs.Default();
// if (!xSampleEASTRInputs.IsValid())
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// if (!xSampleEASTRHelper.Init(
// xSampleEASymbol,
// xSampleEAPeriod,
// xSampleEASTRInputs))
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// // XOSC ...
// //
// xSampleEAOSCInputs.Default();
// if (!xSampleEAOSCInputs.IsValid())
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// if (!xSampleEAOSCHelper.Init(
// xSampleEASymbol,
// xSampleEAPeriod,
// xSampleEAOSCInputs))
// {
// return INIT_PARAMETERS_INCORRECT;
// }
//
// XICH ...
// //
// xSampleEAICHInputs.Default();
// if (!xSampleEAICHInputs.IsValid())
// {
// return INIT_PARAMETERS_INCORRECT;
// }
// //
// if (!xSampleEAICHHelper.Init(
// xSampleEASymbol,
// xSampleEAPeriod,
// xSampleEAICHInputs))
// {
// return INIT_PARAMETERS_INCORRECT;
// }
//
// X121Market Cycle ...
bool result = xSampleEA121MCInputs.Init(
xSampleEASymbol,
xSampleEAPeriod,
X_MARKET_CYCLE_SHORT,
PERIOD_H1,
X_PERIOD_MANUALLY //
);
//
// after Inputs Initialize Successfully we must prepare Styling for Draw ...
ApplyMCDrawStyles();
//
result = xSampleEA121MC.Init(
xSampleEA121MCInputs
//
);
if (!result)
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize XTrader ...
xSampleEATrader = new XSCTrade(
xSampleEASlippage,
xSampleEAMagicNumber);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize XSampleEA Providers ...
delete xSampleEATrader;
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!IsNewCandle(
xSampleEASymbol,
xSampleEAPeriod))
{
return;
}
//
// Reading Tick ...
if (!SymbolInfoTick(xSampleEASymbol, xSampleEATick))
{
return;
}
//
// Counting Currently Open Positions ...
buyCount = xSampleEATrader.CountPositions(xSampleEASymbol, POSITION_TYPE_BUY);
sellCount = xSampleEATrader.CountPositions(xSampleEASymbol, POSITION_TYPE_SELL);
//
// TestMC();
// TestCHE();
// TestSTR();
// TestOSC();
// TestICH();
//
// TestMCycle();
//
// Draw Market Cycle Bars On Chart ...
int offset = 0;
xSampleEA121MC.Draw(
ChartID(),
0,
offset
//
);
//
if (buyCount < maxBuys)
{
//
// Check For Buy Signals ...
}
//
if (sellCount < maxSells)
{
//
// Check for Sell Signals ...
}
}
//
// Custom Functions ...
//
// Validate Variables nd Inputs ...
bool XSampleEAValidateInputs()
{
//
bool result = false;
//
result =
//
xSampleEASlippage > 0 &&
xSampleEAMagicNumber > 0
//
;
//
return result;
}
//
// Tools ...
// //
// void TestCHE()
// {
// //
// double longExit1 = xSampleEACHEHelper.GetLongExit1(0);
// if (NotEmpty(longExit1))
// {
// Print("LE1: " + ToString(longExit1));
// }
// //
// double lEs[];
// int lEsCount = xSampleEACHEHelper.CopyLongExit1(
// 0,
// 2,
// lEs);
// if (lEsCount > 0)
// {
// //
// for (int i = 0; i < lEsCount; i++)
// {
// //
// double iVal = lEs[i];
// //
// if (NotEmpty(iVal))
// {
// //
// Print("LE " + ToString(i) + ": " + ToString(iVal));
// }
// }
// //
// Print(" ");
// }
// }
// //
// void TestMC()
// {
// //
// double fast = xSampleEAMCHelper.GetFast(0);
// if (NotEmpty(fast))
// {
// Print("Fast: " + ToString(fast));
// }
// //
// double slow = xSampleEAMCHelper.GetSlow(0);
// if (NotEmpty(slow))
// {
// Print("Slow: " + ToString(slow));
// }
// }
// //
// void TestSTR()
// {
// //
// double trend = xSampleEASTRHelper.GetTrend(0);
// if (NotEmpty(trend))
// {
// Print("Trend: " + ToString(trend));
// }
// //
// double state = xSampleEASTRHelper.GetState(0);
// if (NotEmpty(state))
// {
// Print("State: " + EnumToString(xSampleEASTRHelper.ToState(state)));
// }
// }
// //
// void TestOSC()
// {
// //
// double rsi = xSampleEAOSCHelper.GetRSI(0);
// if (NotEmpty(rsi))
// {
// Print("RSI: " + ToString(rsi));
// }
// //
// double cci = xSampleEAOSCHelper.GetCCI(0);
// if (NotEmpty(cci))
// {
// Print("CCI: " + ToString(cci));
// }
// }
// //
// void TestICH()
// {
// //
// double tenkanSen = xSampleEAICHHelper.GetTenkanSen(1);
// double tenkanSenLast = xSampleEAICHHelper.GetTenkanSen(2);
// //
// double kijunSen = xSampleEAICHHelper.GetKijunSen(1);
// double kijunSenLast = xSampleEAICHHelper.GetKijunSen(2);
// //
// double chikouSpan = xSampleEAICHHelper.GetChikouSpan(1);
// //
// double senkouSpanA = xSampleEAICHHelper.GetSenkouSpanA(1);
// double senkouSpanALast = xSampleEAICHHelper.GetSenkouSpanA(2);
// //
// double senkouSpanB = xSampleEAICHHelper.GetSenkouSpanB(1);
// double senkouSpanBLast = xSampleEAICHHelper.GetSenkouSpanB(2);
// //
// double futureSenkouSpanA = xSampleEAICHHelper.GetFutureSenkouSpanA(1);
// double futureSenkouSpanALast = xSampleEAICHHelper.GetFutureSenkouSpanA(2);
// //
// double futureSenkouSpanB = xSampleEAICHHelper.GetFutureSenkouSpanB(1);
// double futureSenkouSpanBLast = xSampleEAICHHelper.GetFutureSenkouSpanB(2);
// //
// bool isTenkanSenCrossedOverKijunSen =
// //
// tenkanSen > kijunSen &&
// tenkanSenLast <= kijunSenLast
// //
// ;
// if (isTenkanSenCrossedOverKijunSen)
// {
// Print("isTenkanSenCrossedOverKijunSen");
// }
// //
// bool isTenkanSenCrossedUnderKijunSen =
// //
// tenkanSen < kijunSen &&
// tenkanSenLast >= kijunSenLast
// //
// ;
// if (isTenkanSenCrossedUnderKijunSen)
// {
// Print("isTenkanSenCrossedUnderKijunSen");
// }
// //
// bool isKumoSwitchedToBullish =
// //
// senkouSpanA > senkouSpanB &&
// senkouSpanALast <= senkouSpanBLast
// //
// ;
// if (isKumoSwitchedToBullish)
// {
// Print("isKumoSwitchedToBullish");
// }
// //
// bool isKumoSwitchedToBearish =
// //
// senkouSpanA < senkouSpanB &&
// senkouSpanALast >= senkouSpanBLast
// //
// ;
// if (isKumoSwitchedToBearish)
// {
// Print("isKumoSwitchedToBearish");
// }
// //
// bool isFutureKumoSwitchedToBullish =
// //
// futureSenkouSpanA > futureSenkouSpanB &&
// futureSenkouSpanALast <= futureSenkouSpanBLast
// //
// ;
// if (isFutureKumoSwitchedToBullish)
// {
// Print("isFutureKumoSwitchedToBullish");
// }
// //
// bool isFutureKumoSwitchedToBearish =
// //
// futureSenkouSpanA < futureSenkouSpanB &&
// futureSenkouSpanALast >= futureSenkouSpanBLast
// //
// ;
// if (isFutureKumoSwitchedToBearish)
// {
// Print("isFutureKumoSwitchedToBearish");
// }
// }
// //
// void TestMCycle()
// {
// //
// // double fast0 = xSampleEA121MC.mc.GetFast(0);
// // double fast1 = xSampleEA121MC.mc.GetFast(1);
// // //
// // double slow0 = xSampleEA121MC.mc.GetSlow(0);
// // double slow1 = xSampleEA121MC.mc.GetSlow(1);
// // //
// // double tenkanSen = xSampleEA121MC.ich.GetTenkanSen(0);
// // //
// // Print("Fast0: " + ToString(fast0));
// // Print("Slow0: " + ToString(slow0));
// // //
// // Print("Fast1: " + ToString(fast1));
// // Print("Slow1: " + ToString(slow1));
// // //
// // Print("TenkanSen: " + ToString(tenkanSen));
// // //
// // bool isFastCrossedOverSlow =
// // //
// // fast0 > slow0 &&
// // fast1 <= slow1
// // //
// // ;
// // if (isFastCrossedOverSlow)
// // {
// // //
// // Print("Fast Crossed Over Slow");
// // }
// //
// X121MCycleConditions conditions = xSampleEA121MC.GetMarketConditions(0);
// string mcSummary = conditions.GenerateSummary();
// Print(mcSummary);
// //
// Print(" ");
// }
void ApplyMCDrawStyles()
{
//
// Here we Apply All Draw Styles on Input of Market Cycle ...
xSampleEA121MCInputs.drawCBar = true;
xSampleEA121MCInputs.drawPBar = true;
xSampleEA121MCInputs.drawLabels = true;
xSampleEA121MCInputs.drawCBarMid = true;
xSampleEA121MCInputs.drawPBarMid = true;
//
// Current ...
//
// MidLine ...
xSampleEA121MCInputs.cBarMidDrawSpecs.width = 1;
xSampleEA121MCInputs.cBarMidDrawSpecs.style = STYLE_DOT;
xSampleEA121MCInputs.cBarMidDrawSpecs.clr = clrSpringGreen;
xSampleEA121MCInputs.cBarMidDrawSpecs.Label(
xSampleEA121MCInputs.cycle.prefix + "_C MID",
xSampleEA121MCInputs.cBarMidDrawSpecs.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
//
// XOHCL ...
xSampleEA121MCInputs.cBarDrawSpecs.Default();
xSampleEA121MCInputs.cBarDrawSpecs.Width(1);
xSampleEA121MCInputs.cBarDrawSpecs.Style(STYLE_DOT);
//
xSampleEA121MCInputs.cBarDrawSpecs.openStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C O",
xSampleEA121MCInputs.cBarDrawSpecs.openStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.cBarDrawSpecs.highStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C H",
xSampleEA121MCInputs.cBarDrawSpecs.highStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C C",
xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C L",
xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
//
// Prev ...
//
// MidLine ...
xSampleEA121MCInputs.pBarMidDrawSpecs.width = 2;
xSampleEA121MCInputs.pBarMidDrawSpecs.style = STYLE_SOLID;
xSampleEA121MCInputs.pBarMidDrawSpecs.clr = clrLimeGreen;
xSampleEA121MCInputs.pBarMidDrawSpecs.Label(
xSampleEA121MCInputs.cycle.prefix + "_P MID",
xSampleEA121MCInputs.pBarMidDrawSpecs.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
//
// XOHCL ...
xSampleEA121MCInputs.pBarDrawSpecs.Default();
xSampleEA121MCInputs.pBarDrawSpecs.Width(2);
//
xSampleEA121MCInputs.pBarDrawSpecs.openStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P O",
xSampleEA121MCInputs.pBarDrawSpecs.openStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.pBarDrawSpecs.highStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P H",
xSampleEA121MCInputs.pBarDrawSpecs.highStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P C",
xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P L",
xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
}
@@ -0,0 +1,180 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
// -------------------------------------------------
// Name: XSAMPLE
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XSAMPLE"
#property strict
//
#define ShortName "XSAMPLE"
//
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
// Inputs ...
long xSampleEAMagicNumber = 78692110; // Magic Number
int xSampleEASlippage = 10; // Slippgae
//
double xSampleEAVolume = 0.01;
//
// Vars ...
string xSampleEASymbol;
ENUM_TIMEFRAMES xSampleEAPeriod;
//
int maxBuys = 1;
int maxSells = 1;
int buyCount = 0;
int sellCount = 0;
//
double _tp = 0;
double _sl = 0;
double _entry = 0;
ENUM_POSITION_TYPE _type = NULL;
//
MqlTick xSampleEATick;
XSCTrade *xSampleEATrader;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0)
{
xSampleEASymbol = _Symbol;
}
//
if (xSampleEAPeriod == NULL)
{
xSampleEAPeriod = _Period;
}
//
// Validate Inputs ...
if (!XSampleEAValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
drawPrefix = ShortName;
//
// Initialize XTrader ...
xSampleEATrader = new XSCTrade(
xSampleEASlippage,
xSampleEAMagicNumber);
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize XSampleEA Providers ...
delete xSampleEATrader;
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!IsNewCandle(
xSampleEASymbol,
xSampleEAPeriod))
{
return;
}
//
// Reading Tick ...
if (!SymbolInfoTick(xSampleEASymbol, xSampleEATick))
{
return;
}
//
// Counting Currently Open Positions ...
buyCount = xSampleEATrader.CountPositions(xSampleEASymbol, POSITION_TYPE_BUY);
sellCount = xSampleEATrader.CountPositions(xSampleEASymbol, POSITION_TYPE_SELL);
//
if (buyCount < maxBuys)
{
//
// Check For Buy Signals ...
}
//
if (sellCount < maxSells)
{
//
// Check for Sell Signals ...
}
}
//
// Custom Functions ...
//
// Validate Variables nd Inputs ...
bool XSampleEAValidateInputs()
{
//
bool result = false;
//
result =
//
xSampleEASlippage > 0 &&
xSampleEAMagicNumber > 0
//
;
//
return result;
}
@@ -0,0 +1,297 @@
//+------------------------------------------------------------------+
//| ZigZag.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1
//---- plot Zigzag
#property indicator_label1 "Zigzag"
#property indicator_type1 DRAW_SECTION
#property indicator_color1 Red
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int ExtDepth=12;
input int ExtDeviation=5;
input int ExtBackstep=3;
//--- indicator buffers
double ZigzagBuffer[]; // main buffer
double HighMapBuffer[]; // highs
double LowMapBuffer[]; // lows
int level=3; // recounting depth
double deviation; // deviation in points
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ZigzagBuffer,INDICATOR_DATA);
SetIndexBuffer(1,HighMapBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,LowMapBuffer,INDICATOR_CALCULATIONS);
//--- set short name and digits
PlotIndexSetString(0,PLOT_LABEL,"ZigZag("+(string)ExtDepth+","+(string)ExtDeviation+","+(string)ExtBackstep+")");
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set empty value
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
//--- to use in cycle
deviation=ExtDeviation*_Point;
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| searching index of the highest bar |
//+------------------------------------------------------------------+
int iHighest(const double &array[],
int depth,
int startPos)
{
int index=startPos;
//--- start index validation
if(startPos<0)
{
Print("Invalid parameter in the function iHighest, startPos =",startPos);
return 0;
}
int size=ArraySize(array);
//--- depth correction if need
if(startPos-depth<0) depth=startPos;
double max=array[startPos];
//--- start searching
for(int i=startPos;i>startPos-depth;i--)
{
if(array[i]>max)
{
index=i;
max=array[i];
}
}
//--- return index of the highest bar
return(index);
}
//+------------------------------------------------------------------+
//| searching index of the lowest bar |
//+------------------------------------------------------------------+
int iLowest(const double &array[],
int depth,
int startPos)
{
int index=startPos;
//--- start index validation
if(startPos<0)
{
Print("Invalid parameter in the function iLowest, startPos =",startPos);
return 0;
}
int size=ArraySize(array);
//--- depth correction if need
if(startPos-depth<0) depth=startPos;
double min=array[startPos];
//--- start searching
for(int i=startPos;i>startPos-depth;i--)
{
if(array[i]<min)
{
index=i;
min=array[i];
}
}
//--- return index of the lowest bar
return(index);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int i=0;
int limit=0,counterZ=0,whatlookfor=0;
int shift=0,back=0,lasthighpos=0,lastlowpos=0;
double val=0,res=0;
double curlow=0,curhigh=0,lasthigh=0,lastlow=0;
//--- auxiliary enumeration
enum looling_for
{
Pike=1, // searching for next high
Sill=-1 // searching for next low
};
//--- initializing
if(prev_calculated==0)
{
ArrayInitialize(ZigzagBuffer,0.0);
ArrayInitialize(HighMapBuffer,0.0);
ArrayInitialize(LowMapBuffer,0.0);
}
//---
if(rates_total<100) return(0);
//--- set start position for calculations
if(prev_calculated==0) limit=ExtDepth;
//--- ZigZag was already counted before
if(prev_calculated>0)
{
i=rates_total-1;
//--- searching third extremum from the last uncompleted bar
while(counterZ<level && i>rates_total-100)
{
res=ZigzagBuffer[i];
if(res!=0) counterZ++;
i--;
}
i++;
limit=i;
//--- what type of exremum we are going to find
if(LowMapBuffer[i]!=0)
{
curlow=LowMapBuffer[i];
whatlookfor=Pike;
}
else
{
curhigh=HighMapBuffer[i];
whatlookfor=Sill;
}
//--- chipping
for(i=limit+1;i<rates_total && !IsStopped();i++)
{
ZigzagBuffer[i]=0.0;
LowMapBuffer[i]=0.0;
HighMapBuffer[i]=0.0;
}
}
//--- searching High and Low
for(shift=limit;shift<rates_total && !IsStopped();shift++)
{
val=low[iLowest(low,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((low[shift]-val)>deviation) val=0.0;
else
{
for(back=1;back<=ExtBackstep;back++)
{
res=LowMapBuffer[shift-back];
if((res!=0) && (res>val)) LowMapBuffer[shift-back]=0.0;
}
}
}
if(low[shift]==val) LowMapBuffer[shift]=val; else LowMapBuffer[shift]=0.0;
//--- high
val=high[iHighest(high,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-high[shift])>deviation) val=0.0;
else
{
for(back=1;back<=ExtBackstep;back++)
{
res=HighMapBuffer[shift-back];
if((res!=0) && (res<val)) HighMapBuffer[shift-back]=0.0;
}
}
}
if(high[shift]==val) HighMapBuffer[shift]=val; else HighMapBuffer[shift]=0.0;
}
//--- last preparation
if(whatlookfor==0)// uncertain quantity
{
lastlow=0;
lasthigh=0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}
//--- final rejection
for(shift=limit;shift<rates_total && !IsStopped();shift++)
{
res=0.0;
switch(whatlookfor)
{
case 0: // search for peak or lawn
if(lastlow==0 && lasthigh==0)
{
if(HighMapBuffer[shift]!=0)
{
lasthigh=high[shift];
lasthighpos=shift;
whatlookfor=Sill;
ZigzagBuffer[shift]=lasthigh;
res=1;
}
if(LowMapBuffer[shift]!=0)
{
lastlow=low[shift];
lastlowpos=shift;
whatlookfor=Pike;
ZigzagBuffer[shift]=lastlow;
res=1;
}
}
break;
case Pike: // search for peak
if(LowMapBuffer[shift]!=0.0 && LowMapBuffer[shift]<lastlow && HighMapBuffer[shift]==0.0)
{
ZigzagBuffer[lastlowpos]=0.0;
lastlowpos=shift;
lastlow=LowMapBuffer[shift];
ZigzagBuffer[shift]=lastlow;
res=1;
}
if(HighMapBuffer[shift]!=0.0 && LowMapBuffer[shift]==0.0)
{
lasthigh=HighMapBuffer[shift];
lasthighpos=shift;
ZigzagBuffer[shift]=lasthigh;
whatlookfor=Sill;
res=1;
}
break;
case Sill: // search for lawn
if(HighMapBuffer[shift]!=0.0 && HighMapBuffer[shift]>lasthigh && LowMapBuffer[shift]==0.0)
{
ZigzagBuffer[lasthighpos]=0.0;
lasthighpos=shift;
lasthigh=HighMapBuffer[shift];
ZigzagBuffer[shift]=lasthigh;
}
if(LowMapBuffer[shift]!=0.0 && HighMapBuffer[shift]==0.0)
{
lastlow=LowMapBuffer[shift];
lastlowpos=shift;
ZigzagBuffer[shift]=lastlow;
whatlookfor=Pike;
}
break;
default: return(rates_total);
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
@@ -0,0 +1,22 @@
const int rates_total, // total calculated Candles on charts ...
const int prev_calculated, // total calculated Candles on charts ...
const datetime &time[], // history of Candles Open Time ...
const double &open[], // history of Candles Open Price ...
const double &high[], // history of Candles High Price ...
const double &low[], // history of Candles Low Price ...
const double &close[], // history of Candles Close Price ...
const long &tick_volume[], // history of Tick Volumes on Candle ...
const long &volume[], // history of Trade Volumes ...
const int &spread[] // history of Candles Spread Price ...
// //
// // XICH ...
// string ich =
// //
// "" + "\n" +
// "-------------" + "\n" +
// (( || !ignoreFalseConditions) ? ": " + ToString() + "\n" : "") +
// "\n"
// //
// ;
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,398 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
// -------------------------------------------------
// Name: XSAMPLE
// Description: an Exper Advisor which used RSI and MA
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XSAMPLE"
#property strict
//
#define ShortName "XSAMPLE"
//
#include "../Libraries/x-saherelm.log.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
#include "../Helpers/x-saherelm.x121.xmc.helper.mq5"
#include "../Helpers/x-saherelm.x121.xstr.helper.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.mq5"
#include "../Helpers/x-saherelm.x121.xosc.helper.mq5"
//
#include "../Classes/x-saherelm.xtrade.class.mq5"
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
//
// Inputs ...
long xSampleEAMagicNumber = 78692110; // Magic Number
int xSampleEASlippage = 10; // Slippgae
//
double xSampleEAVolume = 0.01;
//
// Vars ...
string xSampleEASymbol;
ENUM_TIMEFRAMES xSampleEAPeriod;
//
int maxBuys = 1;
int maxSells = 1;
int buyCount = 0;
int sellCount = 0;
//
double _tp = 0;
double _sl = 0;
double _entry = 0;
ENUM_POSITION_TYPE _type = NULL;
//
MqlTick xSampleEATick;
//
XBarTracker xSamplEABarTracker;
//
// X121MCycle ...
X121MCycleInputs xSampleEA121MCInputs;
XSC121Market xSampleEA121MC;
//
XSCSignalCollector signalCollector;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0)
{
xSampleEASymbol = _Symbol;
}
//
if (xSampleEAPeriod == NULL)
{
xSampleEAPeriod = _Period;
}
//
// Validate Inputs ...
if (!XSampleEAValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
drawPrefix = ShortName;
//
bool result = xSamplEABarTracker.Init(
xSampleEASymbol,
xSampleEAPeriod);
if (!result)
{
return INIT_PARAMETERS_INCORRECT;
}
//
// X121Market Cycle ...
result = xSampleEA121MCInputs.Init(
xSampleEASymbol,
xSampleEAPeriod,
X_MARKET_CYCLE_SHORT,
PERIOD_H1,
X_PERIOD_MANUALLY //
);
if (!result)
{
return INIT_PARAMETERS_INCORRECT;
}
//
// after Inputs Initialize Successfully we must prepare Styling for Draw ...
ApplyMCDrawStyles();
//
result = xSampleEA121MC.Init(
xSampleEA121MCInputs
//
);
if (!result)
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize XSampleEA Providers ...
}
//
// On Tick Handler ...
void OnTick()
{
//
if (!xSamplEABarTracker.IsNewBar())
{
return;
}
//
// Reading Tick ...
if (!SymbolInfoTick(xSampleEASymbol, xSampleEATick))
{
return;
}
//
// Draw Market Cycle Bars On Chart ...
int offset = 0;
xSampleEA121MC.Draw(
ChartID(),
0,
offset
//
);
//
// TestXSignalCollector();
}
//
// Custom Functions ...
//
// Validate Variables nd Inputs ...
bool XSampleEAValidateInputs()
{
//
bool result = false;
//
result =
//
xSampleEASlippage > 0 &&
xSampleEAMagicNumber > 0
//
;
//
return result;
}
//
// Tools ...
//
void TestXSignalCollector()
{
//
XSignal signal;
bool isPrepared = signal.Prepare(
xSampleEASymbol,
"XTest",
xSampleEAPeriod,
POSITION_TYPE_BUY,
X_ORDER_MODE_MARKET,
GetEntry(
xSampleEASymbol,
POSITION_TYPE_BUY),
0.01,
0,
0
//
);
if (isPrepared)
{
//
bool isAdded = signalCollector
.Add(signal);
//
if (isAdded)
{
LogMessage("Signal Added Successfully ...");
}
}
//
// Try to Reading Collection ...
XSignal collectedSignals[];
int collectedSignalsCount = signalCollector.Collect(collectedSignals);
if (collectedSignalsCount > 0)
{
LogMessage("Number of Loaded Signals: " + ToString(collectedSignalsCount));
}
}
//
void ApplyMCDrawStyles()
{
//
// Here we Apply All Draw Styles on Input of Market Cycle ...
xSampleEA121MCInputs.drawCBar = true;
xSampleEA121MCInputs.drawPBar = true;
xSampleEA121MCInputs.drawLabels = true;
xSampleEA121MCInputs.drawCBarMid = true;
xSampleEA121MCInputs.drawPBarMid = true;
//
// Current ...
//
// MidLine ...
xSampleEA121MCInputs.cBarMidDrawSpecs.width = 1;
xSampleEA121MCInputs.cBarMidDrawSpecs.style = STYLE_DOT;
xSampleEA121MCInputs.cBarMidDrawSpecs.clr = clrSpringGreen;
xSampleEA121MCInputs.cBarMidDrawSpecs.Label(
xSampleEA121MCInputs.cycle.prefix + "_C MID",
xSampleEA121MCInputs.cBarMidDrawSpecs.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
//
// XOHCL ...
xSampleEA121MCInputs.cBarDrawSpecs.Default();
xSampleEA121MCInputs.cBarDrawSpecs.Width(1);
xSampleEA121MCInputs.cBarDrawSpecs.Style(STYLE_DOT);
//
xSampleEA121MCInputs.cBarDrawSpecs.openStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C O",
xSampleEA121MCInputs.cBarDrawSpecs.openStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.cBarDrawSpecs.highStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C H",
xSampleEA121MCInputs.cBarDrawSpecs.highStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C C",
xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_C L",
xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
//
// Prev ...
//
// MidLine ...
xSampleEA121MCInputs.pBarMidDrawSpecs.width = 2;
xSampleEA121MCInputs.pBarMidDrawSpecs.style = STYLE_SOLID;
xSampleEA121MCInputs.pBarMidDrawSpecs.clr = clrLimeGreen;
xSampleEA121MCInputs.pBarMidDrawSpecs.Label(
xSampleEA121MCInputs.cycle.prefix + "_P MID",
xSampleEA121MCInputs.pBarMidDrawSpecs.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
//
// XOHCL ...
xSampleEA121MCInputs.pBarDrawSpecs.Default();
xSampleEA121MCInputs.pBarDrawSpecs.Width(2);
//
xSampleEA121MCInputs.pBarDrawSpecs.openStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P O",
xSampleEA121MCInputs.pBarDrawSpecs.openStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.pBarDrawSpecs.highStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P H",
xSampleEA121MCInputs.pBarDrawSpecs.highStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P C",
xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.Label(
xSampleEA121MCInputs.cycle.prefix + "_P L",
xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.clr,
"Arial",
8,
ANCHOR_LEFT_UPPER,
90
//
);
}
@@ -0,0 +1,492 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCX121CHEHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_XCHE_BUFFERS
{
X_CHE_LONG_EXIT_1_LINE = 0,
X_CHE_SHORT_EXIT_1_LINE = 1,
X_CHE_LONG_EXIT_2_LINE = 2,
X_CHE_SHORT_EXIT_2_LINE = 3,
};
//
// Input Models ...
struct X121CHEInputs
{
//
// Props ...
//
// Market ...
int length; // Length
int loopback; // Loopback
double multiplier1; // 1st Multiplier
double multiplier2; // 2nd Multiplier
//
// Calculation ...
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied To
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied To
//
// Constructor(s) ...
X121CHEInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
loopback = 0;
multiplier1 = 0;
multiplier2 = 0;
//
upAppliedTo = PRICE_HIGH;
downAppliedTo = PRICE_LOW;
}
//
// Default ...
void Default()
{
//
length = 35;
loopback = 26;
multiplier1 = 3.0;
multiplier2 = 3.5;
//
upAppliedTo = PRICE_HIGH;
downAppliedTo = PRICE_LOW;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 0 &&
loopback < length &&
multiplier1 > 0 &&
multiplier2 > multiplier1
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(length, loopback);
//
return result;
}
};
//
// Class ...
class XSCX121CHEHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121CHEHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX121CHEHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121CHEInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(longExit1Buffer, true);
ArraySetAsSeries(longExit2Buffer, true);
ArraySetAsSeries(shortExit1Buffer, true);
ArraySetAsSeries(shortExit2Buffer, true);
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xche",
//
// Inputs ...
//
// Market ...
"",
mInputs.length,
mInputs.loopback,
mInputs.multiplier1,
mInputs.multiplier2,
//
// Calculations ...
"",
mInputs.upAppliedTo,
mInputs.downAppliedTo,
//
// Presentation ...
"",
false,
false,
false,
false
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121CHEInputs GetInputs() {
return mInputs;
}
//
bool SetInputs(
X121CHEInputs &inputs // Configs
) {
//
return Init(
mSymbol,
mPeriod,
inputs
);
}
//
// Buffers ...
//
double GetLongExit1(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return longExit1Buffer[barIndex];
}
//
// Copy Required Long Exits 1 ...
int CopyLongExit1(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
longExit1Buffer,
buffer,
forceClean
//
);
}
//
double GetLongExit2(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return longExit2Buffer[barIndex];
}
//
// Copy Required Long Exits 2 ...
int CopyLongExit2(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
longExit2Buffer,
buffer,
forceClean
//
);
}
//
double GetShortExit1(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return shortExit1Buffer[barIndex];
}
//
// Copy Required Short Exits 1 ...
int CopyShortExit1(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
shortExit1Buffer,
buffer,
forceClean
//
);
}
//
double GetShortExit2(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return shortExit2Buffer[barIndex];
}
//
// Copy Required Short Exits 2 ...
int CopyShortExit2(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
shortExit2Buffer,
buffer,
forceClean
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121CHEInputs mInputs; // Inputs ...
//
// Buffers ...
//
double longExit1Buffer[];
double longExit2Buffer[];
double shortExit1Buffer[];
double shortExit2Buffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
int calculatedBars = CountCalculatedBars();
//
// Long Exit 1 ...
CopyBuffer(
mHandler,
X_CHE_LONG_EXIT_1_LINE,
0,
totalBars,
longExit1Buffer
//
);
//
// Long Exit 2 ...
CopyBuffer(
mHandler,
X_CHE_LONG_EXIT_2_LINE,
0,
totalBars,
longExit2Buffer
//
);
//
// Short Exit 1 ...
CopyBuffer(
mHandler,
X_CHE_SHORT_EXIT_1_LINE,
0,
totalBars,
shortExit1Buffer
//
);
//
// Short Exit 2 ...
CopyBuffer(
mHandler,
X_CHE_SHORT_EXIT_2_LINE,
0,
totalBars,
shortExit2Buffer
//
);
}
};
//
// Tools ...
@@ -0,0 +1,717 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCX121ICHHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
// Ichimoku Lines Calculator Mode ...
enum ENUM_XICH_CALCULATION_MODE
{
//
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
};
//
enum ENUM_XICH_BUFFERS
{
X_ICH_TEANKANSEN_LINE = 0,
X_ICH_KIJUNSEN_LINE = 1,
X_ICH_CHIKOUSPAN_LINE = 4,
X_ICH_SENKOUSPANA_LINE = 5,
X_ICH_SENKOUSPANB_LINE = 6,
};
//
// Input Models ...
struct X121ICHInputs
{
//
// Props ...
//
// Market ...
//
// Tenkan Sen ...
int tenkanSenLength; // Length
ENUM_XICH_CALCULATION_MODE tenkanSenMode; // Calculation Mode
//
// Kijun Sen ...
int kijunSenLength; // Length
ENUM_XICH_CALCULATION_MODE kijunSenMode; // Calculation Mode
//
// Senkou Span B ...
int senkouSpanBLength; // Length
ENUM_XICH_CALCULATION_MODE senkouSpanBMode; // Calculation Mode
//
// Chikou Span ...
ENUM_APPLIED_PRICE chikuoSpanAppliedTo; // Price Type
//
// Constructor(s) ...
X121ICHInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
kijunSenLength = 0;
tenkanSenLength = 0;
senkouSpanBLength = 0;
//
kijunSenMode = X_XICH_HH_LL_MODE;
tenkanSenMode = X_XICH_HH_LL_MODE;
senkouSpanBMode = X_XICH_HH_LL_MODE;
//
chikuoSpanAppliedTo = PRICE_CLOSE;
}
//
// Default ...
void Default()
{
//
kijunSenLength = 26;
tenkanSenLength = 9;
senkouSpanBLength = 52;
//
kijunSenMode = X_XICH_HH_LL_MODE;
tenkanSenMode = X_XICH_HH_LL_MODE;
senkouSpanBMode = X_XICH_HH_LL_MODE;
//
chikuoSpanAppliedTo = PRICE_CLOSE;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
tenkanSenLength > 2 &&
kijunSenLength > tenkanSenLength &&
senkouSpanBLength > kijunSenLength
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(result, tenkanSenLength);
result = MathMax(result, kijunSenLength);
result = MathMax(result, senkouSpanBLength);
//
return result;
}
};
//
// Class ...
class XSCX121ICHHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121ICHHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX121ICHHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121ICHInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(tenkanSenBuffer, true);
ArraySetAsSeries(kijunSenBuffer, true);
ArraySetAsSeries(chikouSpanBuffer, true);
ArraySetAsSeries(senkouSpanABuffer, true);
ArraySetAsSeries(senkouSpanBBuffer, true);
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xich",
//
// Inputs ...
//
// TenkanSen ...
"",
mInputs.tenkanSenLength,
mInputs.tenkanSenMode,
//
// KijunSen ...
"",
mInputs.kijunSenLength,
mInputs.kijunSenMode,
//
// SenkouSpan B ...
"",
mInputs.senkouSpanBLength,
mInputs.senkouSpanBMode,
//
// ChikouSpan ...
"",
mInputs.chikuoSpanAppliedTo,
//
// Presentation ...
"",
false,
false,
false,
false,
false,
false,
false,
false,
false,
true // Push Kumo to Future ...
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121ICHInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121ICHInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs);
}
//
// Buffers ...
//
// TenkanSen ...
//
double GetTenkanSen(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return tenkanSenBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyTenkanSen(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
tenkanSenBuffer,
buffer,
forceClean
//
);
}
//
// KijunSen ...
//
double GetKijunSen(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return kijunSenBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyKijunSen(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
kijunSenBuffer,
buffer,
forceClean
//
);
}
//
// ChikouSpan ...
//
double GetChikouSpan(
int barIndex // Bar Index
)
{
//
barIndex -= mInputs.kijunSenLength;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
if (barIndex > ArraySize(chikouSpanBuffer)) {
barIndex = ArraySize(chikouSpanBuffer) - 1;
}
//
Calculate();
//
return chikouSpanBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyChikouSpan(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start - mInputs.kijunSenLength,
count,
chikouSpanBuffer,
buffer,
forceClean
//
);
}
//
// SenkouSpanA ...
//
double GetSenkouSpanA(
int barIndex // Bar Index
)
{
//
barIndex += mInputs.kijunSenLength;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
if (barIndex > ArraySize(senkouSpanABuffer)) {
barIndex = ArraySize(senkouSpanABuffer) - 1;
}
//
Calculate();
//
return senkouSpanABuffer[barIndex];
}
//
// Copy Required Items ...
int CopySenkouSpanA(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start + mInputs.kijunSenLength,
count,
senkouSpanABuffer,
buffer,
forceClean
//
);
}
//
// SenkouSpanB ...
//
double GetSenkouSpanB(
int barIndex // Bar Index
)
{
//
barIndex += mInputs.kijunSenLength;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
if (barIndex > ArraySize(senkouSpanBBuffer)) {
barIndex = ArraySize(senkouSpanBBuffer) - 1;
}
//
Calculate();
//
return senkouSpanBBuffer[barIndex + mInputs.kijunSenLength];
}
//
// Copy Required Items ...
int CopySenkouSpanB(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start + mInputs.kijunSenLength,
count,
senkouSpanBBuffer,
buffer,
forceClean
//
);
}
//
// Future SenkouSpanA ...
//
double GetFutureSenkouSpanA(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return senkouSpanABuffer[barIndex];
}
//
// Copy Required Items ...
int CopyFutureSenkouSpanA(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
senkouSpanABuffer,
buffer,
forceClean
//
);
}
//
// SenkouSpanB ...
//
double GetFutureSenkouSpanB(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return senkouSpanBBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyFutureSenkouSpanB(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
senkouSpanBBuffer,
buffer,
forceClean
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121ICHInputs mInputs; // Inputs ...
//
// Buffers ...
double tenkanSenBuffer[];
double kijunSenBuffer[];
double chikouSpanBuffer[];
double senkouSpanABuffer[];
double senkouSpanBBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
int calculatedBars = CountCalculatedBars();
//
// TenkanSen ...
CopyBuffer(
mHandler,
X_ICH_TEANKANSEN_LINE,
0,
totalBars,
tenkanSenBuffer
//
);
//
// KijunSen ...
CopyBuffer(
mHandler,
X_ICH_KIJUNSEN_LINE,
0,
totalBars,
kijunSenBuffer
//
);
//
// ChikouSpan ...
CopyBuffer(
mHandler,
X_ICH_CHIKOUSPAN_LINE,
0,
totalBars,
chikouSpanBuffer
//
);
//
// SenkouSpan A ...
CopyBuffer(
mHandler,
X_ICH_SENKOUSPANA_LINE,
0,
totalBars,
senkouSpanABuffer
//
);
//
// SenkouSpan B ...
CopyBuffer(
mHandler,
X_ICH_SENKOUSPANB_LINE,
0,
totalBars,
senkouSpanBBuffer
//
);
}
};
//
// Tools ...
@@ -0,0 +1,481 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCX121MCHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_XMC_BUFFERS
{
X_MC_FAST_LINE = 0,
X_MC_SLOW_LINE = 1,
X_MC_VERIFIER_LINE = 2,
};
//
// Input Models ...
struct X121MCInputs
{
//
// Props ...
//
// Market ...
//
// Fast ...
int fastLength; // Length
int fastShift; // Shift
ENUM_MA_METHOD fastMethod; // Method
ENUM_APPLIED_PRICE fastAppliedTo; // Applied To
//
// Slow ...
int slowLength; // Length
int slowShift; // Shift
ENUM_MA_METHOD slowMethod; // Method
ENUM_APPLIED_PRICE slowAppliedTo; // Applied To
//
// Verifier ...
int verifierLength; // Length
int verifierShift; // Shift
ENUM_MA_METHOD verifierMethod; // Method
ENUM_APPLIED_PRICE verifierAppliedTo; // Applied To
//
// Constructor(s) ...
X121MCInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
fastLength = 0;
fastShift = 0;
fastMethod = 0;
fastAppliedTo = PRICE_CLOSE;
//
slowLength = 0;
slowShift = 0;
slowMethod = 0;
slowAppliedTo = PRICE_CLOSE;
//
verifierLength = 0;
verifierShift = 0;
verifierMethod = 0;
verifierAppliedTo = PRICE_CLOSE;
}
//
// Default ...
void Default()
{
//
fastLength = 9;
fastShift = 0;
fastMethod = MODE_EMA;
fastAppliedTo = PRICE_CLOSE;
//
slowLength = 18;
slowShift = 0;
slowMethod = MODE_EMA;
slowAppliedTo = PRICE_CLOSE;
//
verifierLength = 200;
verifierShift = 0;
verifierMethod = MODE_EMA;
verifierAppliedTo = PRICE_CLOSE;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
fastLength > 1 &&
slowLength > fastLength &&
verifierLength > slowLength
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(fastLength, slowLength);
result = MathMax(result, verifierLength);
//
return result;
}
};
//
// Class ...
class XSCX121MCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121MCHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX121MCHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121MCInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(fastBuffer, true);
ArraySetAsSeries(slowBuffer, true);
ArraySetAsSeries(verifierBuffer, true);
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xmc",
//
// Inputs ...
//
// Fast ...
"",
mInputs.fastLength,
mInputs.fastShift,
mInputs.fastMethod,
mInputs.fastAppliedTo,
//
// Slow ...
"",
mInputs.slowLength,
mInputs.slowShift,
mInputs.slowMethod,
mInputs.slowAppliedTo,
//
// Verifier ...
"",
mInputs.verifierLength,
mInputs.verifierShift,
mInputs.verifierMethod,
mInputs.verifierAppliedTo,
//
// Presentation ...
"",
false,
false,
false
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121MCInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121MCInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs);
}
//
// Buffers ...
//
// Fast ...
//
double GetFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return fastBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyFast(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
fastBuffer,
buffer,
forceClean
//
);
}
//
// Slow ...
//
double GetSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return slowBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySlow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
slowBuffer,
buffer,
forceClean
//
);
}
//
// Verifier ...
//
double GetVerifier(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return verifierBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyVerifier(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
verifierBuffer,
buffer,
forceClean
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121MCInputs mInputs; // Inputs ...
//
// Buffers ...
//
double fastBuffer[];
double slowBuffer[];
double verifierBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
int calculatedBars = CountCalculatedBars();
//
// Fast ...
CopyBuffer(
mHandler,
X_MC_FAST_LINE,
0,
totalBars,
fastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
X_MC_SLOW_LINE,
0,
totalBars,
slowBuffer
//
);
//
// Verifier ...
CopyBuffer(
mHandler,
X_MC_VERIFIER_LINE,
0,
totalBars,
verifierBuffer
//
);
}
};
//
// Tools ...
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,408 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCX121STRHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
#include "../Classes/x-saherelm.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_XSTR_BUFFERS
{
X_STR_TREND_LINE = 0,
X_STR_STATE_LINE = 5,
};
//
enum ENUM_XSTR_TREND_STATES
{
X_STR_BULLISH = 1, // Bullish
X_STR_BEARISH = -1, // Bearish
};
//
// Input Models ...
struct X121STRInputs
{
//
// Props ...
//
// ATR ...
int length; // Length
double multiplier; // Multiplier
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Constructor(s) ...
X121STRInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
multiplier = 0;
appliedTo = PRICE_CLOSE;
}
//
// Default ...
void Default()
{
//
length = 14;
multiplier = 3.5;
appliedTo = PRICE_MEDIAN;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 0 &&
multiplier > 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = length;
//
return result;
}
};
//
// Class ...
class XSCX121STRHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCX121STRHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCX121STRHelper() {}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121STRInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(trendBuffer, true);
ArraySetAsSeries(stateBuffer, true);
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xstr",
//
// Inputs ...
//
// ATR ...
"",
mInputs.length,
mInputs.multiplier,
mInputs.appliedTo,
//
// Presentation ...
"",
false,
false
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121STRInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121STRInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs);
}
//
// Buffers ...
//
// Trend ...
//
double GetTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return trendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyTrend(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
trendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XSTR_TREND_STATES GetState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XSTR_TREND_STATES)((int)stateBuffer[barIndex]);
}
//
// Copy Required Buffer ...
int CopyState(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
stateBuffer,
buffer,
forceClean
//
);
}
//
// Tools ...
//
ENUM_XSTR_TREND_STATES ToState(double state)
{
return (ENUM_XSTR_TREND_STATES)((int)state);
}
//
bool IsBullish(double state)
{
//
bool result = false;
//
result =
//
ToState(state) == X_STR_BULLISH;
//
;
//
return result;
}
//
bool IsBearish(double state)
{
//
bool result = false;
//
result =
//
ToState(state) == X_STR_BEARISH;
//
;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121STRInputs mInputs; // Inputs ...
//
// Buffers ...
double trendBuffer[];
double stateBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
int calculatedBars = CountCalculatedBars();
//
// Trend ...
CopyBuffer(
mHandler,
X_STR_TREND_LINE,
0,
totalBars,
trendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
X_STR_STATE_LINE,
0,
totalBars,
stateBuffer
//
);
}
};
//
// Tools ...
@@ -0,0 +1,469 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X121_XMC MA Cross Indicator
// ---------------------------------------------------
// Name: X121_XMC
// Description: Moving Average Crosses
// Market Analysor ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121_XMC Indicator"
#property strict
//
// START Constants ...
//
//
// Indicator Short Name ...
#define ShortName "X121_XMC"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Fast";
input int fastMaLength = 9; // Length
input int fastMaShift = 0; // Shift
input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Slow";
input int slowMaLength = 18; // Length
input int slowMaShift = 0; // Shift
input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Verifier";
input int verifierMaLength = 50; // Length
input int verifierMaShift = 0; // Shift
input ENUM_MA_METHOD verifierMaMethod = MODE_EMA; // Method
input ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE; // Applied To
//
input group "Presentation";
input bool showFastMa = true; // Show Fast
input bool showSlowMa = true; // Show Slow
input bool showVerifierMa = true; // Show Verifier
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Logging Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Includes Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
//
// START Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 3
#property indicator_plots 3
//
// PLOTTED Buffers ...
//
// MA ...
//
// FAST ...
#define fastMaBufferIndex 0
double fastMaBuffer[];
//
#property indicator_label1 "X121_XMC MA F"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//
// SLOW ...
#define slowMaBufferIndex 1
double slowMaBuffer[];
//
#property indicator_label2 "X121_XMC MA S"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrDarkOrange
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//
// VERIFIER ...
#define verifierMaBufferIndex 2
double verifierMaBuffer[];
//
#property indicator_label3 "X121_XMC MA V"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrDarkBlue
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
int maxLength;
//
int fastMaHandler = INVALID_HANDLE;
int slowMaHandler = INVALID_HANDLE;
int verifierMaHandler = INVALID_HANDLE;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
logTag = ShortName;
//
// because in some cases we may have more than one input for
// calculation and we must prevent any calculation
// untill we pass the biggest input length, here we get max Input length
// and then wait until pass it ...
maxLength = ExtractMaxLengthOfInputs();
//
// Define Index Buffers ...
DefineBuffers();
//
// Set Indicator ShortName ...
SetIndicatorName();
//
// MA Initialization ...
//
// FAST ...
fastMaHandler = iMA(
_Symbol,
_Period,
fastMaLength,
fastMaShift,
fastMaMethod,
fastMaAppliedTo);
if (fastMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// SLOW ...
slowMaHandler = iMA(
_Symbol,
_Period,
slowMaLength,
slowMaShift,
slowMaMethod,
slowMaAppliedTo);
if (slowMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// VERIFIER ...
verifierMaHandler = iMA(
_Symbol,
_Period,
verifierMaLength,
verifierMaShift,
verifierMaMethod,
verifierMaAppliedTo);
if (verifierMaHandler == INVALID_HANDLE)
{
//
string msg = "Error in Initilizing Indicator ...";
LogMessage(msg);
//
return INIT_FAILED;
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// 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 ...
IndicatorRelease(fastMaHandler);
IndicatorRelease(slowMaHandler);
IndicatorRelease(verifierMaHandler);
}
//
// Calculations ...
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
{
//
// Prepare Buffers ...
ArraySetAsSeries(time, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
ArraySetAsSeries(tick_volume, true);
ArraySetAsSeries(volume, true);
ArraySetAsSeries(spread, true);
//
// this counts Available Bars ...
int limit;
//
// Check Calculated Bars ...
int fastMaCalculatedBars = BarsCalculated(fastMaHandler);
int slowMaCalculatedBars = BarsCalculated(slowMaHandler);
int verifierMaCalculatedBars = BarsCalculated(verifierMaHandler);
if (fastMaCalculatedBars < maxLength ||
slowMaCalculatedBars < maxLength ||
verifierMaCalculatedBars < maxLength)
{
return prev_calculated;
}
//
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
int copiedFastMas = CopyBuffer(fastMaHandler, 0, 0, limit, fastMaBuffer);
int copiedSlowMas = CopyBuffer(slowMaHandler, 0, 0, limit, slowMaBuffer);
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
if (copiedFastMas <= 0 ||
copiedSlowMas <= 0 ||
copiedVerifierMas <= 0
)
{
return prev_calculated;
}
//
// Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
{
CalculateBuffers(i);
}
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result =
//
// Validate Ma ...
(fastMaLength > 2 &&
slowMaLength > fastMaLength &&
verifierMaLength > slowMaLength)
//
;
//
return result;
}
//
// Retrieve all Exists Input Max Length ...
// use for Start Of Drawing ...
int ExtractMaxLengthOfInputs()
{
//
int result = 0;
//
// Ma ...
result = MathMax(result, fastMaLength);
result = MathMax(result, slowMaLength);
result = MathMax(result, verifierMaLength);
//
return result;
}
//
// Define Indexes and Styles ...
void DefineBuffers()
{
//
// MA ...
//
// FAST ...
ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(fastMaBuffer, true);
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastMaDrawType);
//
// SLOW ...
ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(slowMaBuffer, true);
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowMaDrawType);
//
// VERIFIER ...
ENUM_DRAW_TYPE verifierMaDrawType = showVerifierMa ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(verifierMaBuffer, true);
SetIndexBuffer(verifierMaBufferIndex, verifierMaBuffer, INDICATOR_DATA);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_TYPE, verifierMaDrawType);
}
//
// Set Indicator Short Name and also we can define Buffers Labels ...
void SetIndicatorName()
{
//
string indicatorShortName = "";
StringConcatenate(indicatorShortName, ShortName, "");
//
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
}
//
// Calculate Buffers ...
void CalculateBuffers(
int bar_index // Selected Bar Index
)
{
}
//
// END Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,506 @@
/**
* XColor Tools Module ...
* a module for handle colorify text contents in node js ...
*
* Maintainer
*
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
*/
//
//#region Module Imports ...
const XValueTools = require("./x-value.tools");
//#endregion
//
//#region Constants ...
/**
* these are available style which can applied to an string ...
*/
const AVAILABLE_STYLES = {
//
Bold: "\x1b[1m",
Dim: "\x1b[2m",
Underlined: "\x1b[4m",
Blink: "\x1b[5m",
ReverseFandB: "\x1b[7m",
Hidden: "\x1b[8m",
//
// Commonly used for reset all Styles ...
Reset: "\x1b[0m"
};
/**
* these are available foreground colors which can applied to an string ...
*/
const AVAILABLE_FOREGROUND_COLORS = {
Default: "\x1b[39m",
Black: "\x1b[30m",
Red: "\x1b[31m",
Green: "\x1b[32m",
Yellow: "\x1b[33m",
Blue: "\x1b[34m",
Magenta: "\x1b[35m",
Cyan: "\x1b[36m",
LightGray: "\x1b[37m",
DarkGray: "\x1b[90m",
LightRed: "\x1b[91m",
LightGreen: "\x1b[92m",
LightYellow: "\x1b[93m",
LightBlue: "\x1b[94m",
LightMagenta: "\x1b[95m",
LightCyan: "\x1b[96m",
White: "\x1b[97m",
};
/**
* these are available background colors which can applied to an string ...
*/
const AVAILABLE_BACKGROUND_COLORS = {
Default: "\x1b[49m",
Black: "\x1b[40m",
Red: "\x1b[41m",
Green: "\x1b[42m",
Yellow: "\x1b[43m",
Blue: "\x1b[44m",
Magenta: "\x1b[45m",
Cyan: "\x1b[46m",
LightGray: "\x1b[47m",
DarkGray: "\x1b[100m",
LightRed: "\x1b[101m",
LightGreen: "\x1b[102m",
LightYellow: "\x1b[103m",
LightBlue: "\x1b[104m",
LightMagenta: "\x1b[105m",
LightCyan: "\x1b[106m",
White: "\x1b[107m",
};
/**
* these are available style names, which exports from module and
* users can use them ...
*/
const STYLE_NAMES = {
Bold: "Bold",
Dim: "Dim",
Underlined: "Underlined",
Blink: "Blink",
ReverseFandB: "ReverseFandB",
Hidden: "Hidden",
Reset: "Reset",
};
/**
* these are available color names, which exports from module and
* users can use them ...
*/
const COLOR_NAMES = {
Default: "Default",
Black: "Black",
Red: "Red",
Green: "Green",
Yellow: "Yellow",
Blue: "Blue",
Magenta: "Magenta",
Cyan: "Cyan",
LightGray: "LightGray",
DarkGray: "DarkGray",
LightRed: "LightRed",
LightGreen: "LightGreen",
LightYellow: "LightYellow",
LightBlue: "LightBlue",
LightMagenta: "LightMagenta",
LightCyan: "LightCyan",
White: "White",
};
//#endregion
//
//#region Actions ...
/**
* apply specified style and color on a content ...
*
* @param {string} content specified content for styling ...
* @param {string} color specific color name for using to styling ...
* @param {string} style soecufic style name to use ...
* @param {boolean} toForeground apply specified color as foreground ...
* @param {boolean} toBackground apply specified color as background ...
* @returns {string} styled content ...
*/
function apply(
content,
color,
style,
toForeground = true,
toBackground = false
) {
//
let result = content;
//
// Validate Arg ...
if (!XValueTools.isValidArg(content)) {
return result;
}
//
// Detect and Validate Style and Apply it ...
let eStyle = AVAILABLE_STYLES[style];
if (XValueTools.isValidArg(eStyle)) {
result = `${eStyle}${result}${AVAILABLE_STYLES.Reset}`;
}
//
// Detect and Validate Foreground Color and Apply it ...
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
if (
!!toForeground
&& XValueTools.isValidArg(eFColor)
) {
result = `${eFColor}${result}${AVAILABLE_STYLES.Reset}`;
}
//
// Detect and Validate Background Color and Apply it ...
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
if (
!!toBackground
&& XValueTools.isValidArg(eBColor)
) {
result = `${eBColor}${result}${AVAILABLE_STYLES.Reset}`;
}
}
/**
* apply specific style on a content ...
*
* @param {string} content specific content which going to styled ...
* @param {string} style a member of STYLE_NAMES which specified that which style going to applied to content ...
* @returns {string} styled content ...
*/
function applyStyle(content, style) {
//
// Validate Arg ...
if (!XValueTools.isValidArg(content)) {
return content;
}
//
let eStyle = AVAILABLE_STYLES[style];
if (eStyle === undefined) {
return content;
}
//
return `${eStyle}${content}${AVAILABLE_STYLES.Reset}`;
}
/**
* apply specific foreground color on a content ...
*
* @param {string} content specific content which going to colorified ...
* @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ...
* @returns {string} colorified content ...
*/
function applyForegroundColor(content, color) {
//
// Validate Arg ...
if (!XValueTools.isValidArg(content)) {
return content;
}
//
let eColor = AVAILABLE_FOREGROUND_COLORS[color];
if (eColor === undefined) {
return content;
}
//
return `${eColor}${content}${AVAILABLE_STYLES.Reset}`;
}
/**
* apply specific background color on a content ...
*
* @param {string} content specific content which going to colorified ...
* @param {string} color a member of COLOR_NAMES which specified that which color going to applied to content ...
* @returns {string} colorified content ...
*/
function applyBackgroundColor(content, color) {
//
// Validate Arg ...
if (!XValueTools.isValidArg(content)) {
return content;
}
//
let eColor = AVAILABLE_BACKGROUND_COLORS[color];
if (eColor === undefined) {
return content;
}
//
return `${eColor}${content}${AVAILABLE_STYLES.Reset}`;
}
/**
* generate style and color applier expression ...
*
* @param {string} color specific color name for using to styling ...
* @param {string} style soecufic style name to use ...
* @param {boolean} reset close applier string by reset styles ...
* @param {boolean} toForeground apply specified color as foreground ...
* @param {boolean} toBackground apply specified color as background ...
* @returns {string} style and color applier string ...
*/
function getApplier(
style = "",
color = "",
reset = false,
toForeground = true,
toBackground = false
) {
//
let result = "";
//
// Detect and Validate Style and Apply it ...
let eStyle = AVAILABLE_STYLES[style];
if (XValueTools.isValidArg(eStyle)) {
result = `${eStyle}`;
}
//
// Detect and Validate Foreground Color and Apply it ...
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
if (
!!toForeground
&& XValueTools.isValidArg(eFColor)
) {
result = `${eFColor}`;
}
//
// Detect and Validate Background Color and Apply it ...
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
if (
!!toBackground
&& XValueTools.isValidArg(eBColor)
) {
result = `${eBColor}`;
}
//
if (
!!reset &&
result.length > 0
) {
result = `${result}${AVAILABLE_STYLES.Reset}`;
}
//
return result;
}
/**
* generate style applier expression ...
*
* @param {string} style soecufic style name to use ...
* @param {boolean} reset close applier string by reset styles ...
* @returns {string} style applier string ...
*/
function getStyleApplier(
style = "",
reset = false
) {
//
let result = "";
//
// Detect and Validate Style and Apply it ...
let eStyle = AVAILABLE_STYLES[style];
if (XValueTools.isValidArg(eStyle)) {
result = `${eStyle}`;
}
//
if (
!!reset &&
result.length > 0
) {
result = `${result}${AVAILABLE_STYLES.Reset}`;
}
//
return result;
}
/**
* generate color applier expression ...
*
* @param {string} color specific color name for using to styling ...
* @param {boolean} reset close applier string by reset styles ...
* @param {boolean} toForeground apply specified color as foreground ...
* @param {boolean} toBackground apply specified color as background ...
* @returns {string} color applier string ...
*/
function getColorApplier(
color = "",
reset = false,
toForeground = true,
toBackground = false
) {
//
let result = "";
//
// Detect and Validate Foreground Color and Apply it ...
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
if (
!!toForeground
&& XValueTools.isValidArg(eFColor)
) {
result = `${eFColor}`;
}
//
// Detect and Validate Background Color and Apply it ...
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
if (
!!toBackground
&& XValueTools.isValidArg(eBColor)
) {
result = `${eBColor}`;
}
//
if (
!!reset &&
result.length > 0
) {
result = `${result}${AVAILABLE_STYLES.Reset}`;
}
//
return result;
}
/**
* colorified specific content ...
*
* @param {string} content specified content for styling ...
* @param {string} color specific color name for using to styling ...
* @param {boolean} toForeground apply specified color as foreground ...
* @param {boolean} toBackground apply specified color as background ...
* @returns {string}
*/
function colorifyContent(
content = "",
color = "",
toForeground = true,
toBackground = false
) {
//
let result = content;
//
if (!XValueTools.isValidArg(content)) {
return result;
}
//
// Finde Colors ...
//
// Detect and Validate Foreground Color and Apply it ...
let eFColor = AVAILABLE_FOREGROUND_COLORS[color];
if (
!!toForeground
&& XValueTools.isValidArg(eFColor)
) {
result = `${eFColor}${result}`;
}
//
// Detect and Validate Background Color and Apply it ...
let eBColor = AVAILABLE_BACKGROUND_COLORS[color];
if (
!!toBackground
&& XValueTools.isValidArg(eBColor)
) {
result = `${eBColor}${result}`;
}
//
if (
result.length > 0
&& (
XValueTools.isValidArg(eFColor) ||
XValueTools.isValidArg(eBColor)
)
) {
result = `${result}${AVAILABLE_STYLES.Reset}`;
}
//
return result;
}
/**
* apply style on specific content ...
*
* @param {string} content specified content for styling ...
* @param {string} style soecufic style name to use ...
* @returns {string}
*/
function stylifiyContent(
content = "",
style = "",
) {
//
let result = content;
//
if (!XValueTools.isValidArg(content)) {
return result;
}
//
// Detect and Validate Style and Apply it ...
let eStyle = AVAILABLE_STYLES[style];
if (XValueTools.isValidArg(eStyle)) {
result = `${eStyle}${result}`;
}
//
if (
result.length > 0
&& XValueTools.isValidArg(eStyle)
) {
result = `${result}${AVAILABLE_STYLES.Reset}`;
}
//
return result;
}
//#endregion
//
//#region Module Exports ...
module.exports = {
//
STYLE_NAMES,
COLOR_NAMES,
//
apply,
applyStyle,
getApplier,
getColorApplier,
getStyleApplier,
colorifyContent,
stylifiyContent,
applyForegroundColor,
applyBackgroundColor,
}
//#endregion
@@ -0,0 +1,830 @@
/**
* XFile Tools Module ...
* a module for handle all file/folder manipulating task in node js ...
*
* Maintainer
*
* Hadi Khazaee Asl <https://saherelm.ir> (hadi_khazaee_asl@yahoo.com)
*/
//
//#region Module Imports ...
const fs = require('fs');
const os = require('os');
const Path = require('path');
const http = require('http');
const https = require('https');
const XValueTools = require('./x-value.tools');
//#endregion
//
//#region Constants ...
/**
* current os path separators ...
*/
const PathSeparator = Path.sep;
/**
* current directory ...
*/
const CurrentDir = __dirname;
//#endregion
//
//#region Actions ...
//
//#region Global ...
/**
* retrieve a path status ...
*
* @param {string} path a path value to check ...
* @returns an stat object ...
*/
function getStatus(path = '') {
//
if (!XValueTools.isValidArg(path)) {
return undefined;
}
//
return fs.statSync(path);
}
/**
* retrieve user's Home path ...
*
* @returns {string} a path ...
*/
function getHomePath() {
return os.homedir();
}
//#endregion
//
//#region Path ...
/**
* retrieve the base name of specific address path ...
*
* @param {string} path address of file or folder ...
* @returns string ...
*/
function basename(path = '') {
//
if (!XValueTools.isValidArg(path)) {
return '';
}
//
const result = Path.basename(path);
return result;
}
/**
* join several path segments together ...
*
* @param {...string} path path params ...
* @returns a joined paths ...
*/
function joinPath(...path) {
return Path.join(...path);
}
/**
* resolve a relative path to absolute ...
*
* @param {string[]} path a path value to check ...
* @returns {string}
*/
function resolvePath(...path) {
return Path.resolve(...path);
}
//#endregion
//
//#region File ...
/**
* determines a path destination is a file or not ...
*
* @param {string} path a path value to check ...
* @returns a boolean value ...
*/
function isFileExists(path = '') {
//
if (!XValueTools.isValidArg(path)) {
return false;
}
//
try {
const stat = getStatus(path);
if (!stat) {
return false;
}
//
return stat.isFile();
} catch {
return false;
}
}
/**
* remove a file ...
*
* @param {string} path a file path ...
* @returns {Promise<boolean>} action done or not ...
*/
function removeFile(path = '') {
return new Promise((resolve) => {
//
if (!isFileExists(path)) {
resolve(false);
}
//
fs.unlink(path, (err) => {
//
if (err) {
resolve(false);
return;
}
//
resolve(true);
});
});
}
/**
* copy a file to destination path ...
*
* @param {string} source source file path ...
* @param {string} dest dest folder path ...
* @returns {Promise<boolean>} action done or not ...
*/
function copyFile(
source = '',
dest = ''
) {
return new Promise((resolve) => {
//
if (
!isFileExists(source) ||
!isDirectoryExists(dest)
) {
resolve(false);
return;
}
//
const destFilePath = Path.join(dest, Path.basename(source));
fs.copyFile(source, destFilePath, (err) => {
//
if (err) {
resolve(false);
return;
}
//
resolve(true);
});
});
}
/**
* reading specified file content ...
*
* @param {string} path a file path ...
* @returns {Promise<string>} file content ...
*/
function readFile(path = '') {
return new Promise((resolve) => {
//
if (!isFileExists(path)) {
resolve('');
return;
}
//
fs.readFile(path, 'utf8', (err, content) => {
//
if (err) {
resolve(undefined);
return;
}
//
resolve(content);
});
});
}
/**
* write content to a file ...
*
* @param {string} path a file path ...
* @param {string} content the content which going to write to the file ...
* @param {bool} overwrite determines file overwrite if exists ...
* @returns {Promise<boolean>} action done or not ...
*/
function writeFile(
path = '',
content = '',
overwrite = true
) {
return new Promise((resolve) => {
//
if (isFileExists(path) && !overwrite) {
//
resolve(false);
return;
}
//
// Normalize Content ...
content = XValueTools.isValidArg(content) ?
content :
'';
//
fs.writeFile(path, content, (err) => {
//
if (err) {
//
resolve(false);
return;
}
//
resolve(true);
});
});
}
/**
* create a file ...
*
* @param {string} path file path ...
* @param {string} fileName file name ...
* @returns {Promise<boolean>} action done or not ...
*/
function createFile(
path = '',
fileName = ''
) {
return new Promise((resolve) => {
//
const filePath = Path.join(path, fileName);
if (
isFileExists(filePath) ||
!XValueTools.isValidArg(path) ||
!XValueTools.isValidArg(fileName)
) {
//
resolve(false);
return;
}
//
fs.writeFile(filePath, '', (err) => {
//
if (err) {
//
resolve(false);
return;
}
//
resolve(true);
});
});
}
/**
* remove a file name extension ...
*
* @param {string} name
* @returns {string} name without extension ...
*/
function removeFileExtension(name = '') {
return name.substring(0, name.lastIndexOf('.')) || name;
}
/**
* retrieve a file extension ...
*
* @param {string} path a path which locate a file ...
* @returns {string}
*/
function getFileExtension(path = '') {
//
let result = "";
//
// Validate Arg ...
if (
!XValueTools.isValidArg(path)
|| !isFileExists(path)
) {
return result;
}
//
// Retrieve just file name ...
const fileName = basename(path);
result = fileName.replace(
removeFileExtension(fileName),
""
);
//
return result;
}
/**
* retrieve all files list recursively from specific path ...
*
* @param {string} path a source folder path ...
* @param {string[]} extensions which file extensions need to be listed, live empty for all files ...
* @returns {Promise<string[]>}
*/
async function getRecursiveFilesList(
path = "",
extensions = []
) {
//
let result = [];
//
// Validate Args ...
if (
!XValueTools.isValidArg(path)
|| !isDirectoryExists(path)
) {
return result;
}
//
const contents = await getDirectoryContents(path);
for(const item of contents) {
//
const itemPath = joinPath(
path,
item
);
//
const isItemFile = isFileExists(itemPath);
if (isItemFile) {
//
const itemFileExtension = getFileExtension(itemPath);
const isFileInSupportedExtensions =
extensions === undefined || extensions.length === 0
? true
: extensions.includes(itemFileExtension)
;
if (isFileInSupportedExtensions) {
result.push(itemPath);
}
} else if (isDirectoryExists(itemPath)) {
//
const itemPathFiles = await getRecursiveFilesList(itemPath, extensions);
result.push(...itemPathFiles);
}
}
//
return result;
}
//#endregion
//
//#region Directory ...
/**
* create a directory ...
*
* @param {string} path destination path including dir name ...
* @param {boolean} recursive create directories recursively ...
* @returns action done or not ...
*/
function createDirectory(
path = '',
recursive = true
) {
//
let result = false;
//
if (
isDirectoryExists(path) ||
!XValueTools.isValidArg(path)
) {
return false;
}
//
try {
//
fs.mkdirSync(path, { recursive: recursive });
result = true;
return result;
} catch {
return false;
}
}
/**
* remove a directory ...
*
* @param {string} path destination path including dir name ...
* @param {boolean} recursive removes directories recursively ...
* @returns {Promise<boolean>} action done or not ...
*/
function removeDirectory(
path = '',
recursive = false
) {
return new Promise((resolve) => {
//
if (!isDirectoryExists(path)) {
resolve(false);
return;
}
//
fs.rm(path, {
recursive
}, (err) => {
//
if (err) {
resolve(false);
return;
}
//
resolve(true);
});
});
}
/**
* determines a path destination is a directory or not ...
*
* @param {string} path a folder path ...
* @returns represent destnation path is Directory or not ...
*/
function isDirectoryExists(path = '') {
//
if (!XValueTools.isValidArg(path)) {
return false;
}
//
try {
//
const isExists = fs.existsSync(path);
if (!isExists) {
return false;
}
//
const stat = getStatus(path);
if (!stat) {
return false;
}
//
const result = stat.isDirectory();
return result;
} catch {
return false;
}
}
/**
* retrieve a directory content ...
*
* @param {string} path a folder path ...
* @returns {Promise<string[]>} a collection of folder files ...
*/
function getDirectoryContents(path = '') {
return new Promise((resolve) => {
//
if (!isDirectoryExists(path)) {
resolve([]);
return;
}
//
fs.readdir(path, (err, content) => {
//
if (err) {
resolve([]);
return;
}
//
resolve(content);
});
});
}
/**
* retrieve a directory files ...
*
* @param {string} path a folder path ...
* @returns {Promise<string[]>} a collection of folder files ...
*/
function getDirectoryFiles(
path = '',
containsHiddenFiles = false
) {
return new Promise((resolve) => {
//
if (!isDirectoryExists(path)) {
resolve([]);
return;
}
//
fs.readdir(path, (err, content) => {
//
if (err) {
resolve([]);
return;
}
//
if (!containsHiddenFiles) {
content = content.filter(c => !c.startsWith('.'));
}
//
const result = [];
content
.forEach(c => {
//
const cPath = Path.join(path, c);
if (isFileExists(cPath)) {
result.push(c);
}
});
//
resolve(result);
});
});
}
/**
* retrieve a directory folders ...
*
* @param {string} path a folder path ...
* @returns {Promise<string[]>} a collection of folder names ...
*/
function getDirectoryFolders(path = '') {
return new Promise((resolve) => {
//
if (!isDirectoryExists(path)) {
resolve([]);
return;
}
//
fs.readdir(path, (err, content) => {
//
if (err) {
resolve([]);
return;
}
//
const result = [];
content.forEach(c => {
//
const cPath = Path.join(path, c);
if (isDirectoryExists(cPath)) {
result.push(c);
}
});
//
resolve(result);
});
});
}
/**
* copy a folder with all of it's content to dest ...
*
* @param {string} source source folder path ...
* @param {string} dest dest folder path ...
* @returns {Promise<boolean>} action done or not ...
*/
async function copyFolder(
source = '',
dest = ''
) {
//
if (
!isDirectoryExists(source) ||
!XValueTools.isValidArg(dest) ||
!XValueTools.isValidArg(source)
) {
return false;
}
//
const folderName = Path.basename(source);
const destPath = Path.join(dest, folderName);
//
// Create Dest Path folder if not exists ...
if (!isDirectoryExists(destPath)) {
//
let result = createDirectory(destPath, true);
if (!result) {
return false;
}
}
//
// Files ...
const files = await getDirectoryFiles(source);
if (files && files.constructor === Array && files.length > 0) {
//
const filesPromises = files.map(file => copyFile(Path.join(source, file), destPath));
const filesResult = (await Promise.all(filesPromises)).every(r => !!r);
if (!filesResult) {
return false;
}
}
//
// Folders ...
const folders = await getDirectoryFolders(source);
if (folders && folders.constructor === Array && folders.length > 0) {
//
const folderPromises = folders.map(folder => copyFolder(Path.join(source, folder), destPath));
const filesResult = (await Promise.all(folderPromises)).every(r => !!r);
if (!filesResult) {
return false;
}
}
//
return true;
}
//#endregion
//
//#region Downloader ...
/**
* download a file from specific url and store it ...
*
* @param {string} filepath the file name and path which required to put download file on it ...
* @param {string} url the web url for downloading ...
*/
function download(filepath, url) {
//
// Validate Args ...
if (
!XValueTools.isValidArg(url)
|| !XValueTools.isValidURL(url)
|| !XValueTools.isValidArg(filepath)
) {
return;
}
//
var file = fs.createWriteStream(filepath);
//
if (url.startsWith('https:')) {
https.get(url, function (response) {
response.pipe(file);
});
} else if (url.startsWith('http:')) {
http.get(url, function (response) {
response.pipe(file);
});
}
}
//#endregion
//
//#region JSON ...
/**
* read and parse a JSON content from a file ...
*
* @param {string} path source file path ...
* @returns {any}
*/
function readJSON(path = "") {
//
// Validate Args ...
if (!isFileExists(path)) {
return undefined;
}
//
let result = undefined;
try {
result = require(path);
} catch {
result = undefined;
}
//
return result;
}
/**
* write a JSON Object content into a file ...
*
* @param {string} path dest file path ...
* @param {any} content an object which required to write to file ...
* @returns {Promise<boolean>}
*/
async function writeJSON(
path = "",
content = undefined
) {
//
let result = false;
//
// Validate Args ...
if (!XValueTools.isValidArg(path)) {
return result;
}
//
// Normallize Content ...
if (content === undefined) {
content = {};
}
//
const contentString = XValueTools.beautifyJSON(content);
//
result = await writeFile(
path,
contentString,
true
);
//
return result;
}
//#endregion
//#endregion
//
//#region Module Exports ...
module.exports = {
//
CurrentDir,
PathSeparator,
//
getStatus,
getHomePath,
//
basename,
joinPath,
resolvePath,
//
download,
//
readJSON,
writeJSON,
//
copyFile,
readFile,
writeFile,
createFile,
removeFile,
isFileExists,
getFileExtension,
removeFileExtension,
getRecursiveFilesList,
//
copyFolder,
createDirectory,
removeDirectory,
createDirectory,
removeDirectory,
isDirectoryExists,
isDirectoryExists,
getDirectoryFiles,
getDirectoryFolders,
getDirectoryContents,
}
//#endregion

Some files were not shown because too many files have changed in this diff Show More