bkp till 14040626 ...

This commit is contained in:
2025-09-17 09:05:15 +03:30
parent 2bba99ea88
commit afafeca00a
123 changed files with 166574 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,31 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Common Library
// --------------------------------------
// Name: XCommonLib
// Description: provide all commonly used functions ...
//
//
// 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.extensions.lib.mq5"
#include "../Libraries/x-saherelm.common.models.lib.mq5"
#include "../Libraries/x-saherelm.x-ohcl.lib.mq5"
//
// Models ...
//
@@ -0,0 +1,392 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Common Library
// --------------------------------------
// Name: XModelsLib
// Description: provide all commonly used functions ...
//
//
// 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.common.extensions.lib.mq5"
//
// Use To Parse Symbols for
// Ignore Brokers Additional Suffixes ...
struct XSymbolParser
{
//
string version; // Temp ...
//
// Symbol Parsing ...
//
// Forext ...
//
bool IsEURUSD(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"USD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsUSDJPY(string symbol)
{
//
string symbolIdentifiers[] = {
"USD",
"JPY" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsEURJPY(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"JPY" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsUSDCHF(string symbol)
{
//
string symbolIdentifiers[] = {
"USD",
"CHF" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsEURCHF(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"CHF" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsGBPUSD(string symbol)
{
//
string symbolIdentifiers[] = {
"GBP",
"USD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsEURGBP(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"GBP" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsAUDUSD(string symbol)
{
//
string symbolIdentifiers[] = {
"AUD",
"USD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsEURAUD(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"AUD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsUSDCAD(string symbol)
{
//
string symbolIdentifiers[] = {
"USD",
"CAD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsEURCAD(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"CAD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsNZDUSD(string symbol)
{
//
string symbolIdentifiers[] = {
"NZD",
"USD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsEURNZD(string symbol)
{
//
string symbolIdentifiers[] = {
"EUR",
"NZD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
// Metals ...
//
bool IsXAUUSD(string symbol)
{
//
string symbolIdentifiers[] = {
"XAU",
"USD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
bool IsXAGUSD(string symbol)
{
//
string symbolIdentifiers[] = {
"XAG",
"USD" //
};
//
bool result = Contains(
symbolIdentifiers,
symbol //
);
//
return result;
}
//
// Indexes ...
//
bool IsDowJones(string symbol)
{
//
bool result = Contains(
"DowJones30",
symbol //
);
//
return result;
}
//
// Oil ...
//
bool IsBrent(string symbol)
{
//
bool result = Contains(
"BRENT",
symbol //
);
//
return result;
}
//
// Symbol Finder ...
string GetEURUSDSymbol()
{
//
string result = NULL;
//
string symbols[];
int symbolsCount = GetAllSymbols(
symbols //
);
if (!IsValidSize(symbolsCount))
{
return result;
}
//
for (int i = 0; i < symbolsCount; i++)
{
//
string iSymbol = symbols[i];
if (IsEURUSD(iSymbol))
{
//
result = iSymbol;
break;
}
}
//
return result;
}
};
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,214 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Seriallize Library
// ---------------------------------------
// Name: XGuardLib
// Description: All models related to Guard ...
//
//
// 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"
//
// Enumeration ...
//
// Guard Actions ...
enum ENUM_X_GUARD_ACTIONS
{
X_GUARD_ACTION_NONE, // Nothing to Do
X_GUARD_ACTION_CLOSE, // Close Specified Position
X_GUARD_ACTION_CLOSE_ALL, // Close All Positions
X_GUARD_ACTION_CLOSE_LONGS, // Close All Long Positions
X_GUARD_ACTION_CLOSE_SHORTS, // Close All Short Position
X_GUARD_ACTION_CLOSE_IN_LOSTS, // Close All In Lost Position
X_GUARD_ACTION_CLOSE_IN_PROFITS, // Close All In Profit Position
X_GUARD_ACTION_CLOSE_IN_LOST_LONGS, // Close All In Lost Long Position
X_GUARD_ACTION_CLOSE_IN_PROFIT_LONGS, // Close All In Profit Long Position
X_GUARD_ACTION_CLOSE_IN_LOST_SHORTS, // Close All In Lost Short Position
X_GUARD_ACTION_CLOSE_IN_PROFITS_SHORT, // Close All In Profit Short Position
X_GUARD_ACTION_PARTIAL_CLOSE, // Partial Close Specified Position
X_GUARD_ACTION_TRAIL_STOP, // Trail Stop of Specified Position
X_GUARD_ACTION_TRAIL_TARGET, // Trail Target of Specified Position
X_GUARD_ACTION_HEDGE, // Hedge Specified Positions
};
//
// Definitions ...
//
// Model a Guard Action ...
struct XGuard
{
//
// Props ...
ENUM_X_GUARD_ACTIONS action;
datetime time;
//
string symbol;
string provider;
ENUM_TIMEFRAMES period;
//
// Specified Position ...
ulong ticket;
//
// Partial Close ...
double volumeMultiplier;
//
// SL Trial ...
double sl;
//
// TP Trial ...
double tp;
//
bool force;
//
// Constructor ...
XGuard()
{
Clean();
}
//
// Tools ...
/**
* Cleanup ...
*/
void Clean()
{
//
time = NULL;
action = X_GUARD_ACTION_NONE;
//
symbol = NULL;
period = NULL;
provider = NULL;
//
ticket = 0;
//
volumeMultiplier = 0;
//
sl = 0;
tp = 0;
//
force = false;
//
ZeroMemory(this);
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
//
IsSpecifiedValid(time) &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period) &&
IsSpecifiedValid(action) &&
IsSpecifiedValid(provider)
//
;
if (!result)
{
return result;
}
//
// Validate Model Based On Specified Guard Actions ...
//
return result;
}
};
//
// Extensions ...
//
bool IsValid(ENUM_X_GUARD_ACTIONS item)
{
//
bool result = false;
//
result = item != X_GUARD_ACTION_NONE;
//
return result;
}
bool IsSpecifiedValid(ENUM_X_GUARD_ACTIONS item)
{
return IsValid(item);
}
/**
* Add Guard to Collection ...
*
* @param guard: XGuard instance ...
* @param guards: XGuard instance Collection ...
*
* @return ( int )
*/
int AddGuard(
XGuard &guard,
XGuard &guards[] //
)
{
//
int result = 0;
//
if (!guard.IsValid())
{
return result;
}
//
AddRef(
guard,
guards //
);
//
result = ArraySize(guards);
//
return result;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,725 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Seriallize Library
// ---------------------------------------
// Name: XPOILib
// Description: All models related to POIs ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright `023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.base.class.mq5"
#include <Arrays/ArrayObj.mqh>
//
// Definitions ...
//
struct XBoxZone
{
//
// Props ...
string symbol;
ENUM_TIMEFRAMES period;
//
double upper;
double lower;
//
datetime at;
datetime from;
datetime to;
//
string type;
ENUM_X_DIRECTION dir;
//
// Constructor ...
XBoxZone()
{
Clean();
}
//
// Tools ...
/**
* Cleanup Model ...
*/
void Clean()
{
//
upper = 0;
lower = 0;
to = NULL;
at = NULL;
from = NULL;
symbol = NULL;
period = NULL;
dir = X_DIRECTION_NONE;
//
ZeroMemory(this);
}
/**
* Validate Model ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
//
upper > 0 &&
lower > 0 &&
from < to &&
IsSpecifiedValid(to) &&
upper >= lower &&
IsSpecifiedValid(from) &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period)
//
;
//
return result;
}
/**
* Check Box is Bullish or not ...
*
* @return ( bool )
*/
bool IsBullish()
{
return IsValid() &&
IsSpecifiedBullish(dir);
}
/**
* Check Box is Bearish or not ...
*
* @return ( bool )
*/
bool IsBearish()
{
return IsValid() &&
IsSpecifiedBearish(dir);
}
/**
* Clone Box by Provided Source ...
*
* @return ( bool )
*/
bool Clone(XBoxZone &source)
{
//
bool result = false;
//
Clean();
result = source.IsValid();
if (!result)
{
return result;
}
//
// Filling Props ...
to = source.to;
dir = source.dir;
from = source.from;
type = source.type;
upper = source.upper;
lower = source.lower;
symbol = source.symbol;
period = source.period;
//
result = IsValid();
if (!result)
{
Clean();
}
//
return result;
}
/**
* Check Box is Same as Other ...
*
* @param item: XBoxZone instance Resource ...
*
* @return ( bool )
*/
bool IsSameAs(XBoxZone &item)
{
//
return IsValid() &&
item.IsValid() &&
dir == item.dir &&
from == item.from &&
type == item.type &&
lower == item.lower &&
upper == item.upper &&
symbol == item.symbol &&
period == item.period;
}
/**
* Retrieve Box Age ...
*
* @param forPeriod: ENUM_TIMEFRAMES member ...
*
* @return ( int )
*/
int GetAge(
ENUM_TIMEFRAMES forPeriod = NULL //
)
{
//
int result = 0;
//
if (!IsValid())
{
return result;
}
//
if (!IsSpecifiedValid(forPeriod))
{
forPeriod = period;
}
//
result = iBarShift(
symbol,
forPeriod,
from //
);
//
return result;
}
/**
* Calculate Box Middle Price ...
*
* @return ( double )
*/
double GetMid()
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
double diffAvg = (upper - lower) / 2;
result = lower + diffAvg;
result = NormalizePrice(result, symbol);
//
return result;
}
/**
* Calculate Box Leg N Price ...
* N default is 2
*
* @param leg: int ...
*
* @return ( double )
*/
double GetLeg(int leg = 2)
{
//
double result = 0;
//
leg = NormalizeInt(leg, 2);
//
if (!IsValid())
{
return result;
}
//
double range = (upper - lower) * leg;
result =
IsBullish()
? upper + range
: lower - range;
result = NormalizePrice(result, symbol);
//
return result;
}
/**
* Calculate Box Range ...
*
* @return ( double )
*/
double GetRange()
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
result = (upper - lower);
result = NormalizePrice(result, symbol);
//
return result;
}
/**
* Retrieve Box Applied Price ...
*
* @return ( double )
*/
double GetDirectionalPrice()
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
result =
IsBullish()
? upper
: lower;
//
return result;
}
/**
* Retrieve Box Breaked Price ...
*
* @return ( double )
*/
double GetInDirectionalPrice()
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
result =
IsBullish()
? lower
: upper;
//
return result;
}
/**
* To Bar Index ...
*
* @return ( int )
*/
int ToIndex(
ENUM_TIMEFRAMES forPeriod = NULL //
)
{
//
int result = -1;
//
if (!IsValid())
{
return result;
}
//
if (!IsSpecifiedValid(forPeriod))
{
forPeriod = period;
}
//
result = GetBarIndex(
symbol,
forPeriod,
to //
);
//
return result;
}
/**
* Retrieve To Bar ...
*
* @return ( bool )
*/
bool ToBar(XOHCL &bar)
{
//
bool result = false;
//
bar.Clean();
//
int idx = ToIndex();
//
result =
IsValid() &&
IsValidIndex(idx);
if (!result)
{
return result;
}
//
result = bar.Init(
symbol,
period,
idx //
);
//
return result;
}
/**
* From Bar Index ...
*
* @return ( int )
*/
int FromIndex(
ENUM_TIMEFRAMES forPeriod = NULL //
)
{
//
int result = -1;
//
if (!IsValid())
{
return result;
}
//
if (!IsSpecifiedValid(forPeriod))
{
forPeriod = period;
}
//
result = GetBarIndex(
symbol,
forPeriod,
from //
);
//
return result;
}
/**
* Retrieve From Bar ...
*
* @return ( bool )
*/
bool FromBar(XOHCL &bar)
{
//
bool result = false;
//
bar.Clean();
//
int idx = FromIndex();
//
result =
IsValid() &&
IsValidIndex(idx);
if (!result)
{
return result;
}
//
result = bar.Init(
symbol,
period,
idx //
);
//
return result;
}
/**
* Retrieve Unique Identifier ...
*
* @return ( string )
*/
string GetTag()
{
//
int digits = GetDigits(symbol);
double nUpper = NormalizeDouble(NormalizePrice(upper, symbol), digits);
double nLower = NormalizeDouble(NormalizePrice(lower, symbol), digits);
//
string typeStr = IsSpecifiedValid(type)
? type
: "XBOX";
string result =
//
typeStr + "_" +
ToString(dir) + "_" +
symbol + "_" +
ToXString(period) + "_" +
ToXString(nUpper) + "_" +
ToXString(nLower)
//
;
//
return result;
}
/**
* Retrieve Unique Middle Identifier ...
*
* @return ( string )
*/
string GetMiddleTag()
{
//
int digits = GetDigits(symbol);
double nMid = NormalizeDouble(NormalizePrice(GetMid(), symbol), digits);
//
string typeStr = IsSpecifiedValid(type)
? type
: "XBOX";
string result =
//
typeStr + "_" +
"Mid_" +
ToString(dir) + "_" +
symbol + "_" +
ToXString(period) + "_" +
ToXString(nMid)
//
;
//
return result;
}
};
//
struct XDirectionShift
{
//
// Props ...
string type;
datetime at;
double after;
double before;
string symbol;
ENUM_TIMEFRAMES period;
ENUM_X_DIRECTION shiftTo;
//
// Constructor ...
XDirectionShift()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
at = NULL;
after = 0;
before = 0;
type = NULL;
symbol = NULL;
period = NULL;
shiftTo = X_DIRECTION_NONE;
//
ZeroMemory(this);
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
after > 0 &&
IsSpecifiedValid(at) &&
IsSpecifiedValid(type) &&
after != before &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period) &&
HasDirection(shiftTo);
//
return result;
}
//
// Get Bar Index of Direction Shift ...
int Index()
{
//
int result = -1;
//
// Validate ...
if (!IsValid())
{
return result;
}
//
// Retrieve Bar Index ...
result = GetBarIndex(
symbol,
period,
at //
);
//
return result;
}
//
// Get At Bar ...
bool AtBar(XOHCL &bar)
{
//
bool result = false;
//
// Normalize ...
bar.Clean();
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
int idx = Index();
if (IsValidIndex(idx))
{
//
result = bar.Init(
symbol,
period,
idx //
);
}
//
result = bar.IsValid();
//
return result;
}
//
// Check Same ...
bool IsSameAs(XDirectionShift &item)
{
//
bool result = false;
//
result = IsValid() &&
item.IsValid();
if (!result)
{
return result;
}
//
result =
//
at == item.at &&
type == item.type &&
after == item.after &&
before == item.before &&
symbol == item.symbol &&
period == item.period &&
shiftTo == item.shiftTo
//
;
//
return result;
}
};
//
File diff suppressed because it is too large Load Diff