backup v1 and compile ...

This commit is contained in:
2024-06-29 10:53:40 +03:30
parent 8514dc6cba
commit 1d3aa422a6
74 changed files with 72225 additions and 0 deletions
@@ -0,0 +1,79 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XBaseClass
// Description: provides all based classes for use ...
//
//
// 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.lib.mq5"
//
// XBase Class ...
class XSCBase
{
//
// Public ...
public:
//
// Protected ...
//
// Represent Basic Unique Tag ...
virtual string GetTag();
//
// Retrieve Class Token ...
virtual string GetToken();
protected:
//
// Private ...
private:
};
//
template <typename T>
string GenerateSpecifiedCommonSummary(
T &mItem,
string separator = "\n",
bool includeScores = true,
bool setLabel = false //
)
{
//
string result = NULL;
//
result =
//
(!setLabel
? ""
: "Commons:" + separator) +
"---------------" + separator +
"Symbol: " + mItem.symbol + separator +
"Period: " + ToString(mItem.period) + separator +
"Time: " + ToString(mItem.time) + separator +
""
//
;
//
return result;
}
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,828 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCX121SetupCycle
// Description: provides implementation of X121
// Setup on Specified Market Cycle ...
//
//
// 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 <Arrays/ArrayObj.mqh>
#include "../Classes/x-saherelm.x121.setup.class.mq5"
//
// Definitions ...
//
// Inputs ...
struct X121SetupCycleInputs
{
//
// Props ...
//
XMarketCycle cycle; // Market Cycle
//
X121SetupInputs inputs; // Inputs
//
XSCX121Setup *setup; // Setup
//
// Constructor ...
void X121SetupCycleInputs()
{
}
//
// Initialization ...
bool Init(
X121SetupInputs &_inputs, // Configurations
ENUM_TIMEFRAMES _hostPeriod, // Host Period
ENUM_X_MARKET_CYCLES _cycle, // Init Cycle
ENUM_X_PERIOD_METHOD _method, // Period Selection Method
ENUM_TIMEFRAMES _period, // Provided Period
string _prefix = "" // Prefix
)
{
//
bool result = false;
//
// Validate Inputs ...
result =
//
IsValid(_inputs.symbol)
//
;
if (!result)
{
return result;
}
//
// Init Cycle ...
result = cycle.Init(
inputs.symbol,
_hostPeriod,
_cycle,
_method,
_period,
_prefix //
);
if (!result)
{
return result;
}
//
cycle.Update(0);
//
_inputs.period = cycle.period;
//
result = _inputs.IsValid();
if (!result)
{
return result;
}
//
this.inputs = _inputs;
//
setup = new XSCX121Setup();
result = setup.Init(
inputs //
);
//
return result;
}
//
// Tools ...
//
string GetSymbol()
{
return inputs.symbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return inputs.period;
}
//
bool CanProcessBar()
{
return cycle.barTracker.CanProcessBar();
}
//
void WaitsUntilNextBar()
{
cycle.barTracker.Waits();
}
//
bool GetConditions(
X121SetupConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = false;
//
result = cycle.Update(
barIndex //
);
//
result = setup.GetConditions(
conditions,
barIndex,
loopback //
);
//
return result;
}
};
//
// Class ...
class XSCX121SetupCycles : public XSCBaseAlert
{
//
// Public ...
public:
//
// Props ...
X121SignalGenerator signalGenerator;
//
X121SetupCycleInputs cCycle; // Current (Host) Cycle
X121SetupCycleInputs sCycle; // Short Cycle
X121SetupCycleInputs mCycle; // Medium Cycle
X121SetupCycleInputs lCycle; // Long Cycle
X121SetupCycleInputs hCycle; // Hind Cycle
//
// Constructor(s) ...
void XSCX121SetupCycles() {}
//
// Deconstructor ...
void ~XSCX121SetupCycles() {}
//
// Initialized ...
bool Init(
X121SetupInputs &_inputs, // Configurations
string _symbol, // Trading Symbol
ENUM_TIMEFRAMES _hostPeriod, // Host Period
ENUM_X_PERIOD_METHOD _sMethod = X_PERIOD_AUTO, // Short Period Selection Method
ENUM_TIMEFRAMES _sPeriod = NULL, // Short Provided Period
ENUM_X_PERIOD_METHOD _mMethod = X_PERIOD_AUTO, // Medium Period Selection Method
ENUM_TIMEFRAMES _mPeriod = NULL, // Medium Provided Period
ENUM_X_PERIOD_METHOD _lMethod = X_PERIOD_AUTO, // Long Period Selection Method
ENUM_TIMEFRAMES _lPeriod = NULL, // Long Provided Period
ENUM_X_PERIOD_METHOD _hMethod = X_PERIOD_AUTO, // Hind Period Selection Method
ENUM_TIMEFRAMES _hPeriod = NULL // Hind Provided Period
)
{
//
bool result = false;
//
// Check Validation of Symbol and Period ...
result =
//
IsValid(_symbol) &&
IsValid(_hostPeriod)
//
;
if (!result)
{
return result;
}
//
// Initialize Market Cycles ...
//
// Current ...
_inputs.symbol = _symbol;
result = cCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_SHORT,
X_PERIOD_MANUALLY,
_hostPeriod,
"CURR" //
);
if (!result)
{
return result;
}
//
result = cBarTracker.Init(
_inputs.symbol,
_hostPeriod //
);
if (!result)
{
return result;
}
//
// Short ...
result = sCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_SHORT,
_sMethod,
_sPeriod //
);
if (!result)
{
return result;
}
//
result = sBarTracker.Init(
_inputs.symbol,
sCycle.cycle.period //
);
if (!result)
{
return result;
}
//
// Medium ...
result = mCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_MEDIUM,
_mMethod,
_mPeriod //
);
if (!result)
{
return result;
}
//
result = mBarTracker.Init(
_inputs.symbol,
mCycle.cycle.period //
);
if (!result)
{
return result;
}
//
// Long ...
result = lCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_LONG,
_lMethod,
_lPeriod //
);
if (!result)
{
return result;
}
//
result = lBarTracker.Init(
_inputs.symbol,
lCycle.cycle.period //
);
if (!result)
{
return result;
}
//
// Hind ...
result = hCycle.Init(
_inputs,
_hostPeriod,
X_MARKET_CYCLE_HIND,
_hMethod,
_hPeriod //
);
if (!result)
{
return result;
}
//
result = hBarTracker.Init(
_inputs.symbol,
hCycle.cycle.period //
);
if (!result)
{
return result;
}
//
_inputs.period = cCycle.GetPeriod();
//
this.inputs = _inputs;
result = inputs.IsValid();
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
X121SetupInputs GetInputs()
{
return this.inputs;
}
//
bool SetInputs(
X121SetupInputs &_inputs // Cycles Configurations
)
{
//
bool result = Init(
_inputs,
_inputs.symbol,
_inputs.period //
);
//
return result;
}
//
string GetSymbol()
{
return cCycle.GetSymbol();
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return cCycle.GetPeriod();
}
//
bool ForceState()
{
return forceState;
}
//
void ForceState(bool value)
{
forceState = value;
}
//
bool CanProcessBar(
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN //
)
{
//
bool result = false;
//
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
//
result = sBarTracker.CanProcessBar();
break;
//
case X_MARKET_CYCLE_MEDIUM:
//
result = mBarTracker.CanProcessBar();
break;
//
case X_MARKET_CYCLE_LONG:
//
result = lBarTracker.CanProcessBar();
break;
//
case X_MARKET_CYCLE_HIND:
//
result = hBarTracker.CanProcessBar();
break;
//
default:
case X_MARKET_CYCLE_UNKNOWN:
//
result = cBarTracker.CanProcessBar();
break;
}
//
return result;
}
//
datetime GetNextSignalTime(
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN //
)
{
//
datetime result = NULL;
//
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
result = sNextValidSignal;
break;
//
case X_MARKET_CYCLE_MEDIUM:
result = mNextValidSignal;
break;
//
case X_MARKET_CYCLE_LONG:
result = lNextValidSignal;
break;
//
case X_MARKET_CYCLE_HIND:
result = hNextValidSignal;
break;
//
default:
case X_MARKET_CYCLE_UNKNOWN:
result = cNextValidSignal;
break;
}
//
return result;
}
//
void WaitsUntilNextBar(
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN //
)
{
//
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
//
FillNextBarTime(
sNextValidSignal,
sBarTracker //
);
sBarTracker.Waits();
break;
//
case X_MARKET_CYCLE_MEDIUM:
//
FillNextBarTime(
mNextValidSignal,
mBarTracker //
);
mBarTracker.Waits();
break;
//
case X_MARKET_CYCLE_LONG:
//
FillNextBarTime(
lNextValidSignal,
lBarTracker //
);
lBarTracker.Waits();
break;
//
case X_MARKET_CYCLE_HIND:
//
FillNextBarTime(
hNextValidSignal,
hBarTracker //
);
hBarTracker.Waits();
break;
//
default:
case X_MARKET_CYCLE_UNKNOWN:
//
FillNextBarTime(
cNextValidSignal,
cBarTracker //
);
cBarTracker.Waits();
break;
}
}
//
bool GetConditions(
X121SetupConditions &conditions, //
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = false;
//
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
//
result = sCycle.GetConditions(
conditions,
barIndex,
loopback //
);
break;
//
case X_MARKET_CYCLE_MEDIUM:
//
result = mCycle.GetConditions(
conditions,
barIndex,
loopback //
);
break;
//
case X_MARKET_CYCLE_LONG:
//
result = lCycle.GetConditions(
conditions,
barIndex,
loopback //
);
break;
//
case X_MARKET_CYCLE_HIND:
//
result = hCycle.GetConditions(
conditions,
barIndex,
loopback //
);
break;
//
default:
case X_MARKET_CYCLE_UNKNOWN:
//
result = cCycle.GetConditions(
conditions,
barIndex,
loopback //
);
break;
}
//
return result;
}
//
XSCZones *GetZones(
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN, //
int barIndex = 0, //
int numberOfZones = 10 //
)
{
//
XSCZonesInput zInputs;
zInputs.numberOfZones = numberOfZones;
//
int length = 0;
ENUM_TIMEFRAMES zPeriod = NULL;
switch (cycle)
{
//
case X_MARKET_CYCLE_SHORT:
//
zPeriod = sCycle.GetPeriod();
break;
//
case X_MARKET_CYCLE_MEDIUM:
//
zPeriod = mCycle.GetPeriod();
break;
//
case X_MARKET_CYCLE_LONG:
//
zPeriod = lCycle.GetPeriod();
break;
//
case X_MARKET_CYCLE_HIND:
//
zPeriod = hCycle.GetPeriod();
break;
//
default:
case X_MARKET_CYCLE_UNKNOWN:
//
zPeriod = cCycle.GetPeriod();
break;
}
//
ENUM_TIMEFRAMES cPeriod = GetPeriod();
length = (PeriodSeconds(zPeriod) / PeriodSeconds(cPeriod)) + 1;
//
zInputs.length = length;
XSCZones *result = new XSCZones(
GetSymbol(),
cPeriod //
);
if (!result.Init(zInputs))
{
return NULL;
}
//
return result;
}
//
bool ProcessMarket(
XSignal &signal,
X121SetupConditions &conditions,
int &pushers,
string &provider,
double &tp,
double &sl,
ENUM_X_MARKET_CYCLES cycle = X_MARKET_CYCLE_UNKNOWN,
bool allowSupports = false, // Allow Support Signal Generating ...
bool allowLong = false,
bool allowShort = false,
double volume = 0.01,
double slPoint = 100,
bool ignoreSL = false,
double tpPoint = 100,
bool ignoreTP = false,
int barIndex = 0,
int loopback = 5 //
)
{
//
bool result = false;
//
result = CanProcessBar(
cycle //
);
if (!result)
{
return result;
}
//
result = GetConditions(
conditions,
cycle, // Current Market ...
barIndex, // Bar Index ...
loopback // Loop Back ...
);
if (!result)
{
return result;
}
//
// Parse Conditions for Signal ...
result = signalGenerator.HasSignal(
conditions,
signal,
pushers,
provider,
tp,
sl,
allowSupports,
allowLong,
allowShort,
volume,
slPoint,
ignoreSL,
tpPoint,
ignoreTP //
);
//
if (result)
{
//
WaitsUntilNextBar(
cycle //
);
}
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
//
X121SetupInputs inputs; // Cycles Configurations
//
bool forceState; // Force State
//
// Bar Trackers ...
XBarTracker cBarTracker;
XBarTracker sBarTracker;
XBarTracker mBarTracker;
XBarTracker lBarTracker;
XBarTracker hBarTracker;
//
datetime cNextValidSignal;
datetime sNextValidSignal;
datetime mNextValidSignal;
datetime lNextValidSignal;
datetime hNextValidSignal;
//
void FillNextBarTime(
datetime &next,
XBarTracker &tracker //
)
{
//
next = iTime(
tracker.symbol,
tracker.period,
0) +
PeriodSeconds(tracker.period);
}
};
//
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,398 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCAccount
// Description: provides all Account 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 ...
//
//
// END Definitions ...
//
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include <Trade/AccountInfo.mqh>
#include "../Classes/x-saherelm.base.class.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
//
// a Class for Manage Account ...
class XSCAccount : public XSCBase
{
//
// Public ...
public:
//
// Constructor ...
void XSCAccount()
{
//
mAccountInfo = new CAccountInfo();
}
//
// Deconstructor ...
void ~XSCAccount()
{
}
//
// START Provided Functions ...
//
//
// User Account ...
long GetUserAccount()
{
return mAccountInfo.Login();
}
//
// Account Leverage ...
long GetLeverage()
{
return mAccountInfo.Leverage();
}
//
// Get Trade Expert State ...
bool CanExpertTrade()
{
return mAccountInfo.TradeExpert();
}
//
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
// --------------------------
// ACCOUNT_TRADE_MODE_DEMO
// ACCOUNT_TRADE_MODE_CONTEST
// ACCOUNT_TRADE_MODE_REAL
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
{
return mAccountInfo.TradeMode();
}
//
// Get Account Balance ...
double GetBalance()
{
return mAccountInfo.Balance();
}
//
// Get the amount of give Credit ...
double GetCredit()
{
return mAccountInfo.Credit();
}
//
// Get the amount of current Profit on account ...
double GetProfit()
{
return mAccountInfo.Profit();
}
//
// Get the amount of current Equity on account ...
double GetEquity()
{
return mAccountInfo.Equity();
}
//
// Get the amount of reserved Margin ...
double GetMargin()
{
return mAccountInfo.Margin();
}
//
// Get the amount of free Margin ...
double GetFreeMargin()
{
return mAccountInfo.FreeMargin();
}
//
// Get the Level of Margin ...
double GetMarginLevel()
{
return mAccountInfo.MarginLevel();
}
//
// Get the Level Of Margin for a Deposit ...
double GetMarginCall()
{
return mAccountInfo.MarginCall();
}
//
// Get the Level of Margin for Stop out ...
double GetMarginStopOut()
{
return mAccountInfo.MarginStopOut();
}
//
// Get the Client Name ...
string GetName()
{
return mAccountInfo.Name();
}
//
// Get the Trade Server Name ...
string GetServerName()
{
return mAccountInfo.Server();
}
//
// Get deposit Currency Name ...
string GetCurrency()
{
return mAccountInfo.Currency();
}
//
// Get the Company Name that serves an Account ...
string GetCompany()
{
return mAccountInfo.Company();
}
//
// Calculate Profits for the current account based on passed parameters ...
double CalculateTradeProfit(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry, // open price
double exit // close price
)
{
//
double result = mAccountInfo.OrderProfitCheck(
symbol,
type,
volume,
entry,
exit);
//
return result;
}
//
// Calculate amount of margin which required for trade operation ...
double CalculateMarging(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry // open price
)
{
//
double result = mAccountInfo.MarginCheck(
symbol,
type,
volume,
entry);
//
return result;
}
//
// Calculate amount of free margin left after trade operation ...
double CalculateFreeMarging(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double volume, // volume
double entry // open price
)
{
//
double result = mAccountInfo.FreeMarginCheck(
symbol,
type,
volume,
entry);
//
return result;
}
//
// Calculate the Maximum possible volume of trade operation ...
double CalculateMaxVolume(
const string symbol, // trading symbol
ENUM_ORDER_TYPE type, // order type
double entry, // open price
double percent = 100 // percent of available margin
)
{
//
double result = mAccountInfo.MaxLotCheck(
symbol,
type,
entry,
percent);
//
return result;
}
//
// Calculate Point Value for Given Symbol based on Account ...
double GetPointValue(
string symbol // trading symbol
)
{
//
double result = 0;
//
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
//
double ticksPerPoint = tickSize / point;
//
result = tickValue / ticksPerPoint;
//
return result;
}
//
// Calculate Risk Amount based on account Currency by Providing:
// Points and Volume ...
double CalculateRiskAmount(
string symbol, // trading symbol
double points, // amount of Risk Points
double volume // position Volume
)
{
//
double result = 0;
//
double pointValue = GetPointValue(symbol);
//
result = pointValue * volume * points;
//
return result;
}
//
// Calculate Risk Points based on account Currency by Providing:
// Volume and Amount ...
double CalculateRiskPoints(
string symbol, // trading symbol
double volume, // position Volume
double amount // amount of Risk based on Account Currency
)
{
//
double result = 0;
//
double pointValue = GetPointValue(symbol);
//
result = amount / (pointValue * volume);
//
return result;
}
//
// Calculate Volume based on account Currency by Providing:
// Amount and Risk Points ...
double CalculateVolume(
string symbol, // trading symbol
double amount, // amount of Risk based on Account Currency
double points // amount of Risk Points
)
{
//
double result = 0;
//
points =
points <= 0
? 10
: points;
//
double pointValue = GetPointValue(symbol);
//
result = amount / (pointValue * points);
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Private ...
private:
//
// Account Info ...
CAccountInfo mAccountInfo;
};
//
// START Usefull Functions ...
//
//
// END Usefull Functions ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,148 @@
///////////////////////////////////////////////////////
//
// 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 "../Classes/x-saherelm.base.class.mq5"
//
// Definitions ...
//
// a Class for Handle base requirements ...
// for indicators ...
class XSCBaseHelper : public XSCBase
{
//
// 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;
}
//
// Retrieve Indicator Calculated Bars ...
int CountCalculatedBars()
{
return BarsCalculated(mHandler);
}
//
// Generate Tag ...
virtual string GetTag()
{
//
string result = NULL;
//
result =
//
GetToken() +
"[" +
GetSymbol() + "|" +
ToString(GetPeriod()) +
"]"
//
;
//
return result;
}
//
// Functions ...
//
// Protected ...
protected:
//
// Props ...
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Indicator Handler ...
int mHandler;
//
// Private ...
private:
//
};
//
// Tools ....
@@ -0,0 +1,373 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCHttp
// Description: provides all HTTP 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
//
// Definitions ...
//
enum X_HTTP_METHOD
{
X_HTTP_GET,
X_HTTP_POST
};
//
// Imports ...
//
// Includes ...
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// a Class for Manage Account ...
class XSCHttp : public XSCBase
{
//
// Public ...
public:
//
// Constructor ...
void XSCHttp()
{
XSCHttp("", 10000);
}
void XSCHttp(
string path, // Base Folder to Store Data
int timeout // base timeout for Requests
)
{
//
Path(path);
Timeout(timeout);
}
//
// Deconstructor ...
void ~XSCHttp()
{
}
//
// Properties Getter(s) / Setter(s) ...
//
// Path ...
void Path(string value)
{
//
mPath = value;
//
if (!IsValid(mPath))
{
mPath = GetTag();
}
}
string Path()
{
return mPath;
}
//
// Timeout ...
void Timeout(int value)
{
mTimeout = value;
}
//
int Timeout()
{
return mTimeout;
}
//
// Error ...
int Error()
{
return mError;
}
//
// Response ...
string Response()
{
return mResponse;
}
//
// Overrides ...
string GetTag() override
{
return GetSpecificToken(this);
}
//
// Tools ...
//
// Send Global Request ...
int SendRequest(
X_HTTP_METHOD method, // Httm Request Method
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = -1;
//
string strMethod = ToString(method);
if (StringLen(strMethod) == 0)
{
return result;
}
//
// Reset State ...
ResetState();
//
result = WebRequest(
strMethod,
url,
headers,
timeout,
payload,
response,
responseHeaders);
//
if (result < 0)
{
mError = GetLastError();
}
else
{
mResponse = CharArrayToString(response);
}
//
return result;
}
//
// Get Request ...
int GetRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = SendRequest(
X_HTTP_GET,
url,
headers,
payload,
response,
responseHeaders,
timeout);
//
return result;
}
//
// Post Request ...
int PostRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = SendRequest(
X_HTTP_POST,
url,
headers,
payload,
response,
responseHeaders,
timeout);
//
return result;
}
//
// Handle Download Specific URL Content to Specific Path and File Name ...
bool Download(
string url, // the URL address which going to download
string fileName // Specify Destination file name to Store Response
)
{
//
bool result = false;
//
string filePath = GetFilePath(fileName);
string cookie = NULL;
string referer = NULL;
int timeout = Timeout();
//
char payload[];
string headers;
char response[];
string responseHeaders;
//
// Send Request ...
int requestResult = GetRequest(
url,
headers,
payload,
response,
responseHeaders,
timeout);
//
// Define File Handler ...
int mFileHandler = FileOpen(
filePath,
FILE_WRITE | FILE_BIN);
if (mFileHandler == INVALID_HANDLE)
{
//
mError = GetLastError();
return result;
}
//
// Write Response to File ...
uint writed = FileWriteArray(
mFileHandler,
response,
0,
ArraySize(response));
FileFlush(mFileHandler);
FileClose(mFileHandler);
//
result = writed > 0;
//
return result;
}
//
// END Provided Functions ...
//
//
// Protected ...
protected:
//
// Destintion Folder Path ...
string mPath;
//
// WEB Request Timeout Value ...
int mTimeout;
//
// WEB Request's Response ...
string mResponse;
//
// Error Value ...
int mError;
//
// Private ...
private:
//
// Reset Errors State ...
void ResetState()
{
//
// Reset Errors ...
mError = -1;
mResponse = "";
ResetLastError();
}
//
// Generate Full File Path ...
string GetFilePath(string fileName)
{
//
string result = "";
//
result =
//
Path() + "\\" + fileName
//
;
//
return result;
}
};
//
// Tools ...
//
// Convert enum to String ...
string ToString(X_HTTP_METHOD method)
{
//
string result = "";
//
switch (method)
{
//
case X_HTTP_GET:
result = "GET";
break;
//
case X_HTTP_POST:
result = "POST";
break;
}
//
return result;
}
//
@@ -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,54 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCRange
// Description: provides all Range 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 "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Definitions ...
//
enum ENUM_XSCRANGE_CALCULATION_MODE {
//
XSCRANGE_CALCULATE_MANUALLY = 0,
XSCRANGE_CALCULATE_DAILY = 1,
XSCRANGE_CALCULATE_HALFDAY = 2,
XSCRANGE_CALCULATE_4H = 3,
};
//
struct XSCRangeInput
{
//
// Props ...
//
datetime startTime; // Range Start Time
datetime endTime; // Range End Time
//
int lifetime; // Range Live Time (Secconds)
//
};
@@ -0,0 +1,736 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCRange
// Description: provides all Range 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 "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Definitions ...
//
struct XSCCFInput
{
//
// Props ...
//
int length; // Minimum of Same Bars
//
color clrUpper; // Upper Color ...
color clrLower; // Lower Color ...
//
// Constructor ...
void XSCCFInput()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
length = 0;
//
clrUpper = CLR_NONE;
clrLower = CLR_NONE;
}
//
// Defualt Configs ...
void Default()
{
//
length = 4;
//
clrLower = clrAqua;
clrUpper = clrMagenta;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length >= 2
//
;
//
return result;
}
};
//
// Class ...
class XSCCF : public XSCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
void XSCCF(
string symbol,
ENUM_TIMEFRAMES period //
) : XSCBase()
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCCF() {}
//
// Initialize ...
bool Init(XSCCFInput &inputs)
{
//
bool result = false;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
// Find Bullish Bar ...
result = FindBullishBar(0);
if (!result)
{
return result;
}
//
// Find Bearish Bar ...
result = FindBearishBar(0);
if (!result)
{
return result;
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
string GetSymbol()
{
return mSymbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
XSCCFInput GetInputs()
{
return mInputs;
}
//
bool SetInputs(XSCCFInput &inputs)
{
return Init(inputs);
}
//
XOHCL GetBullishBar()
{
return bullishBar;
}
//
XOHCL GetBearishBar()
{
return bearishBar;
}
//
// Overrides ...
string GetTag() override
{
return "XCF";
}
//
// Tools ...
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
bullishBar.IsValid() &&
bearishBar.IsValid()
//
;
//
return result;
}
//
// Retrieve Title Prefix ...
string GetIdentifier()
{
//
string result = NULL;
//
if (!IsValid())
{
return result;
}
//
result = GetTag() + "_" +
mSymbol + "_" +
ToString(mPeriod) + "_" +
ToFormatString(bullishBar.time) + "_";
//
return result;
}
//
// Remove Draws ...
bool Remove(
long chartId = 0,
int subWindow = 0 //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
string prefix = GetIdentifier();
result = IsSpecifiedValid(prefix);
if (!result)
{
return result;
}
//
RemoveDraws(
prefix,
chartId,
subWindow //
);
//
return result;
}
//
bool Draw(
long chartId = 0,
string prefix = NULL,
int subWindow = 0,
string upperPrefix = "Upper",
string lowerPrefix = "Lower" //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
result = DrawBullishBar(
chartId,
prefix,
subWindow,
upperPrefix,
lowerPrefix //
);
if (!result)
{
return result;
}
//
result = DrawBearishBar(
chartId,
prefix,
subWindow,
upperPrefix,
lowerPrefix //
);
if (!result)
{
return result;
}
//
return result;
}
//
// Protected ...
protected:
//
// Tools ...
//
bool FindBullishBar(
int barIndex //
)
{
//
bool result = false;
//
int next = barIndex + 1;
//
int totalBars = iBars(
mSymbol,
mPeriod //
);
result = barIndex >= 0 && barIndex + 1 + mInputs.length < totalBars;
if (!result)
{
return result;
}
//
bool isNextValid = next >= 0 && next + 1 + mInputs.length < totalBars;
//
int bullBarIndex = barIndex + 1;
int start = bullBarIndex + 1;
int end = start + mInputs.length;
//
XOHCL startBar;
result = startBar.Init(
mSymbol,
mPeriod,
bullBarIndex //
);
if (!result)
{
return result;
}
//
result = startBar.IsBullish();
if (!result)
{
if (isNextValid)
{
return FindBullishBar(next);
}
else
{
return result;
}
}
//
// Loop Back to Find Bearish Bars ...
for (int i = start; i < end; i++)
{
//
XOHCL iBar;
result = iBar.Init(
mSymbol,
mPeriod,
i //
);
if (!result || !iBar.IsBearish())
{
//
if (isNextValid)
{
return FindBullishBar(next);
}
else
{
return result;
}
//
break;
}
}
//
if (result)
{
bullishBar = startBar;
}
//
return result;
}
//
bool FindBearishBar(
int barIndex //
)
{
//
bool result = false;
//
int next = barIndex + 1;
//
int totalBars = iBars(
mSymbol,
mPeriod //
);
result = barIndex >= 0 && barIndex + 1 + mInputs.length < totalBars;
if (!result)
{
return result;
}
//
bool isNextValid = next >= 0 && next + 1 + mInputs.length < totalBars;
//
int bearBarIndex = barIndex + 1;
int start = bearBarIndex + 1;
int end = start + mInputs.length;
//
XOHCL startBar;
result = startBar.Init(
mSymbol,
mPeriod,
bearBarIndex //
);
if (!result)
{
return result;
}
//
result = startBar.IsBearish();
if (!result)
{
if (isNextValid)
{
return FindBearishBar(next);
}
else
{
return result;
}
}
//
// Loop Back to Find Bearish Bars ...
for (int i = start; i < end; i++)
{
//
XOHCL iBar;
result = iBar.Init(
mSymbol,
mPeriod,
i //
);
if (!result || !iBar.IsBullish())
{
//
if (isNextValid)
{
return FindBearishBar(next);
}
else
{
return result;
}
//
break;
}
}
//
if (result)
{
bearishBar = startBar;
}
//
return result;
}
//
bool DrawBullishBar(
long chartId = 0,
string prefix = NULL,
int subWindow = 0,
string upperPrefix = "Upper",
string lowerPrefix = "Lower" //
)
{
//
bool result = false;
//
result = bullishBar.IsValid();
if (!result)
{
return result;
}
//
if (!IsSpecifiedValid(upperPrefix))
{
upperPrefix = "High";
}
//
if (!IsSpecifiedValid(lowerPrefix))
{
lowerPrefix = "Low";
}
//
datetime cTime = TimeCurrent();
//
string identifier = GetIdentifier();
//
// High Line ...
string bullishHighLineName =
(IsSpecifiedValid(prefix)
? prefix + "_"
: "") +
identifier + "_" +
"BULL_" +
upperPrefix;
//
result = DrawTrendLine(
chartId,
bullishHighLineName,
subWindow,
bullishBar.time,
bullishBar.high,
cTime,
bullishBar.high,
mInputs.clrUpper,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
//
// Low Line ...
string bullishLowLineName =
(IsSpecifiedValid(prefix)
? prefix + "_"
: "") +
identifier + "_" +
"BULL_" +
lowerPrefix;
//
result = DrawTrendLine(
chartId,
bullishLowLineName,
subWindow,
bullishBar.time,
bullishBar.low,
cTime,
bullishBar.low,
mInputs.clrLower,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
//
return result;
}
//
bool DrawBearishBar(
long chartId = 0,
string prefix = NULL,
int subWindow = 0,
string upperPrefix = "Upper",
string lowerPrefix = "Lower" //
)
{
//
bool result = false;
//
result = bearishBar.IsValid();
if (!result)
{
return result;
}
//
if (!IsSpecifiedValid(upperPrefix))
{
upperPrefix = "High";
}
//
if (!IsSpecifiedValid(lowerPrefix))
{
lowerPrefix = "Low";
}
//
datetime cTime = TimeCurrent();
//
string identifier = GetIdentifier();
//
// High Line ...
string bearishHighLineName =
(IsSpecifiedValid(prefix)
? prefix + "_"
: "") +
identifier + "_" +
"BEAR_" +
upperPrefix;
//
result = DrawTrendLine(
chartId,
bearishHighLineName,
subWindow,
bearishBar.time,
bearishBar.high,
cTime,
bearishBar.high,
mInputs.clrUpper,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
//
// Low Line ...
string bearishLowLineName =
(IsSpecifiedValid(prefix)
? prefix + "_"
: "") +
identifier + "_" +
"BEAR_" +
lowerPrefix;
//
result = DrawTrendLine(
chartId,
bearishLowLineName,
subWindow,
bearishBar.time,
bearishBar.low,
cTime,
bearishBar.low,
mInputs.clrLower,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
//
return result;
}
//
// Private ...
private:
//
// Props ...
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading Period ...
//
XOHCL bearishBar; // Bearish Order Block Bar
XOHCL bullishBar; // Bullish Order Block Bar
//
XSCCFInput mInputs; // Configs ...
};
//
@@ -0,0 +1,330 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCSupRes
// Description: provides all Support and Resistances 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 "../Classes/x-saherelm.base.class.mq5"
#include "../Helpers/x-saherelm.xpv.helper.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// Definitions ...
struct XSCSupResInput
{
//
// Props ...
//
int numberOfSupports; // Number of Required Supports
int numberOfResistances; // Number of Required Resistances
//
int pivotsVerifications; // Pivots Verifications
//
double distance; // Distance between Pivots
//
double price; // Price for Support and Resistance Finding
//
color clrSupport;
color clrResistance;
//
// Constructor ...
void XSCSupResInput()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
numberOfSupports = 0;
numberOfResistances = 0;
//
price = 0;
distance = 0;
pivotsVerifications = 0;
//
clrSupport = CLR_NONE;
clrResistance = CLR_NONE;
}
//
// Defualt Configs ...
void Default()
{
//
numberOfSupports = 5;
numberOfResistances = 5;
//
price = 0;
distance = 10;
pivotsVerifications = 35;
//
clrSupport = clrAqua;
clrResistance = clrMagenta;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
price > 0 &&
distance >= 0 &&
numberOfSupports > 0 &&
numberOfResistances > 0 &&
pivotsVerifications > 2
//
;
//
return result;
}
};
//
// Class ...
//
class XSCSupRes : public XSCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
void XSCSupRes(
string symbol,
ENUM_TIMEFRAMES period //
) : XSCBase()
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCSupRes() {}
//
// Initializer ...
bool Init(XSCSupResInput &inputs)
{
//
bool result = false;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
// Find Pivots ...
result = FindPivots();
if (!result)
{
return result;
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
string GetSymbol()
{
return mSymbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
XSCSupResInput GetInputs()
{
return mInputs;
}
//
bool SetInputs(XSCSupResInput &inputs)
{
return Init(inputs);
}
//
// Overrides ...
//
string GetTag() override
{
return "XSupRes";
}
//
// Tools ...
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
false
//
;
//
return result;
}
//
// Retrieve Title Prefix ...
string GetIdentifier()
{
//
string result = NULL;
//
if (!IsValid())
{
return result;
}
//
result = GetTag() + "_" +
mSymbol + "_" +
ToString(mPeriod) + "_";
//
return result;
}
//
// Protected ...
protected:
//
// Tools ...
//
// Private ...
private:
//
// Props ...
//
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading Period ...
//
XSCSupResInput mInputs; // Configs ...
//
double mSupports[];
double mResistances[];
//
// Tools ...
//
bool FindPivots(int barIndex = 0)
{
//
bool result = false;
//
int totalBars = iBars(
mSymbol,
mPeriod //
);
//
result = barIndex >= 0 && barIndex < totalBars - mInputs.pivotsVerifications;
if (!result) {
return result;
}
//
int next = barIndex + 1;
bool canNext = next >= 0 && next < totalBars - mInputs.pivotsVerifications;
//
XSCXPVHelper helper = new XSCXPVHelper();
XPVInputs pvInputs;
pvInputs.Default();
result = helper.Init(
mSymbol,
mPeriod,
pvInputs //
);
if (!result)
{
return result;
}
//
// TODO: Complete this ...
//
// Check States ...
//
return result;
}
};
//
@@ -0,0 +1,746 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCTrend
// Description: provides all Trend 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 "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// All Required Inputs ...
struct XSCTrendInput
{
//
int numberOfShoulders; // Number of Shoulders
//
color clrUpper; // Upper Colors
color clrLower; // Lower Colors
color clrHighs; // Highs Colors
color clrLows; // Lows Colors
//
// Constructor ...
void XSCTrendInput()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
numberOfShoulders = 0;
//
clrUpper = CLR_NONE;
clrLower = CLR_NONE;
clrHighs = CLR_NONE;
clrLows = CLR_NONE;
}
//
// Defualt Configs ...
void Default()
{
//
numberOfShoulders = 7;
//
clrUpper = clrRed;
clrLower = clrGreen;
//
clrHighs = clrAqua;
clrLows = clrMagenta;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
numberOfShoulders >= 2
//
;
//
return result;
}
};
//
// Class Definitions ...
class XSCTrend : public XSCBase
{
//
// Public ...
public:
//
// Props ...
//
// Constructor ...
void XSCTrend(
string symbol,
ENUM_TIMEFRAMES period //
) : XSCBase()
{
//
mSymbol = symbol;
mPeriod = period;
}
//
// Deconstructor ...
void ~XSCTrend()
{
Remove();
}
//
// Initialize ...
bool Init(XSCTrendInput &inputs)
{
//
bool result = false;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
result = zBar.Init(
mSymbol,
mPeriod,
0 //
);
//
int firstSwingLowIndex = FindSwing(
zBar.symbol,
zBar.period,
X_SWING_LOW,
mInputs.numberOfShoulders,
zBar.Index() + 1 //
);
result = firstSwingLowBar.Init(
zBar.symbol,
zBar.period,
firstSwingLowIndex //
);
if (!result)
{
return result;
}
//
int secondSwingLowIndex = FindSwing(
zBar.symbol,
zBar.period,
X_SWING_LOW,
mInputs.numberOfShoulders,
firstSwingLowIndex + 1 //
);
//
result = secondSwingLowBar.Init(
zBar.symbol,
zBar.period,
secondSwingLowIndex //
);
if (!result)
{
return result;
}
//
int firstSwingHighIndex = FindSwing(
zBar.symbol,
zBar.period,
X_SWING_HIGH,
mInputs.numberOfShoulders,
zBar.Index() + 1 //
);
result = firstSwingHighBar.Init(
zBar.symbol,
zBar.period,
firstSwingHighIndex //
);
if (!result)
{
return result;
}
//
int secondSwingHighIndex = FindSwing(
zBar.symbol,
zBar.period,
X_SWING_HIGH,
mInputs.numberOfShoulders,
firstSwingHighIndex + 1 //
);
result = secondSwingHighBar.Init(
zBar.symbol,
zBar.period,
secondSwingHighIndex //
);
if (!result)
{
return result;
}
//
return result;
}
//
// Getter(s) / Setter(s) ...
//
string GetSymbol()
{
return mSymbol;
}
//
ENUM_TIMEFRAMES GetPeriod()
{
return mPeriod;
}
//
XSCTrendInput GetInputs()
{
return mInputs;
}
//
bool SetInputs(XSCTrendInput &inputs)
{
return Init(inputs);
}
//
XOHCL GetBar()
{
return zBar;
}
//
XOHCL GetFirstSwingLowBar()
{
return firstSwingLowBar;
}
//
XOHCL GetSecondSwingLowBar()
{
return secondSwingLowBar;
}
//
XOHCL GetFirstSwingHighBar()
{
return firstSwingHighBar;
}
//
XOHCL GetSecondSwingHighBar()
{
return secondSwingHighBar;
}
//
// Overrides ...
//
string GetTag() override
{
return "XTREND";
}
//
// Tools ...
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
zBar.IsValid() &&
firstSwingLowBar.IsValid() &&
secondSwingLowBar.IsValid() &&
firstSwingHighBar.IsValid() &&
secondSwingHighBar.IsValid()
//
;
//
return result;
}
//
// Retrieve Title Prefix ...
string GetIdentifier()
{
//
string result = NULL;
//
if (!IsValid())
{
return result;
}
//
result = GetTag() + "_" +
mSymbol + "_" +
ToString(mPeriod) + "_" +
ToFormatString(zBar.time);
//
return result;
}
//
// Retrieve Chart Line Values ...
//
// Get Lows Line Price at Specific Time ...
double GetLows(datetime time = NULL)
{
//
double result = 0;
//
result = GetObjectPrice(
lowsName,
time //
);
//
return result;
}
//
// Get Highs Line Price at Specific Time ...
double GetHighs(datetime time = NULL)
{
//
double result = 0;
//
result = GetObjectPrice(
highsName,
time //
);
//
return result;
}
//
// Get Support Line Price at Specific Time ...
double GetSupport(datetime time = NULL)
{
//
double result = 0;
//
result = GetObjectPrice(
supportName,
time //
);
//
return result;
}
//
// Get Resistance Line Price at Specific Time ...
double GetResistance(datetime time = NULL)
{
//
double result = 0;
//
result = GetObjectPrice(
resistanceName,
time //
);
//
return result;
}
//
// Remove Draws ...
bool Remove(
long chartId = 0,
int subWindow = 0 //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
string prefix = GetIdentifier();
result = IsSpecifiedValid(prefix);
if (!result)
{
return result;
}
//
RemoveDraws(
prefix,
chartId,
subWindow //
);
//
return result;
}
//
// Draw Trend Object on Chart ...
bool Draw(
long chartId = 0,
string prefix = NULL,
int subWindow = 0,
string upperPrefix = "Upper",
string lowerPrefix = "Lower",
string highsPrefix = "Highs",
string lowsPrefix = "Lows" //
)
{
//
bool result = false;
//
result = IsValid();
if (!result)
{
return result;
}
//
// Normalize Prefixes ...
//
if (!IsSpecifiedValid(upperPrefix))
{
upperPrefix = "Upper";
}
//
if (!IsSpecifiedValid(lowerPrefix))
{
lowerPrefix = "Lower";
}
//
if (!IsSpecifiedValid(highsPrefix))
{
highsPrefix = "Highs";
}
//
if (!IsSpecifiedValid(lowsPrefix))
{
lowsPrefix = "Lows";
}
//
string identifier = GetIdentifier();
result = IsSpecifiedValid(identifier);
if (!result)
{
return result;
}
//
double support = secondSwingLowBar.low;
datetime supportTime =
secondSwingLowBar.time > secondSwingHighBar.time
? secondSwingHighBar.time
: secondSwingLowBar.time;
supportName =
//
identifier +
(IsSpecifiedValid(prefix)
? "_" + prefix + "_"
: "") +
"_" + lowerPrefix + "_" +
""
//
;
//
double resistance = secondSwingHighBar.high;
datetime resistanceTime =
secondSwingLowBar.time > secondSwingHighBar.time
? secondSwingHighBar.time
: secondSwingLowBar.time;
resistanceName =
//
identifier +
(IsSpecifiedValid(prefix)
? "_" + prefix + "_"
: "") +
"_" + upperPrefix + "_" +
""
//
;
//
double newLow = firstSwingLowBar.low;
datetime newLowTime = firstSwingLowBar.time;
//
double oldLow = secondSwingLowBar.low;
datetime oldLowTime = secondSwingLowBar.time;
lowsName =
//
identifier +
(IsSpecifiedValid(prefix)
? "_" + prefix + "_"
: "") +
"_" + lowsPrefix + "_" +
""
//
;
//
double newHigh = firstSwingHighBar.high;
datetime newHighTime = firstSwingHighBar.time;
//
double oldHigh = secondSwingHighBar.high;
datetime oldHighTime = secondSwingHighBar.time;
highsName =
//
identifier +
(IsSpecifiedValid(prefix)
? "_" + prefix + "_"
: "") +
"_" + highsPrefix + "_" +
""
//
;
//
// Draw Support ...
result = DrawTrendLine(
chartId,
supportName,
subWindow,
supportTime,
support,
newLowTime,
support,
mInputs.clrLower,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
// Draw Resistance ...
result = DrawTrendLine(
chartId,
resistanceName,
subWindow,
resistanceTime,
resistance,
newHighTime,
resistance,
mInputs.clrUpper,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
// Draw Highs ...
result = DrawTrendLine(
chartId,
highsName,
subWindow,
oldHighTime,
oldHigh,
newHighTime,
newHigh,
mInputs.clrHighs,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
// Draw Lows ...
result = DrawTrendLine(
chartId,
lowsName,
subWindow,
oldLowTime,
oldLow,
newLowTime,
newLow,
mInputs.clrLows,
STYLE_SOLID,
2,
false,
false,
true // Ray Right ...
);
if (!result)
{
return result;
}
//
return result;
}
//
// Protected ...
protected:
//
// Tools ...
//
double GetObjectPrice(
string objName,
datetime objTime,
long chartId = 0,
int subWindow = 0 //
)
{
//
double result = 0;
//
if (!IsValid())
{
return result;
}
//
if (!IsSpecifiedValid(objName))
{
return result;
}
//
objTime = NormalizeTime(objTime);
//
string objectName = FindObjectName(
objName,
chartId,
subWindow //
);
//
result = ObjectGetValueByTime(
chartId,
objectName,
objTime //
);
//
return result;
}
//
// Private ...
private:
//
// Props ...
string mSymbol; // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod; // Trading Period ...
//
XSCTrendInput mInputs; // Configs ...
//
XOHCL zBar;
XOHCL firstSwingLowBar;
XOHCL secondSwingLowBar;
XOHCL firstSwingHighBar;
XOHCL secondSwingHighBar;
//
// Object Names ...
string lowsName;
string highsName;
string supportName;
string resistanceName;
};
//
@@ -0,0 +1,805 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// ----------------------------------------------
// Name: XSCZone
// Description: provides all Zone 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 <Arrays/ArrayObj.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh>
#include "../Classes/x-saherelm.base.class.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
#include <ChartObjects/ChartObjectsTxtControls.mqh>
//
// Definitions ...
#define defZoneBGColor CLR_NONE // clrLightGray
#define defZoneLBLColor clrWhite
//
// All Required Inputs ...
struct XSCZonesInput
{
//
int length; // Calculation Length
int numberOfZones; // Number of Zones
//
double levels[]; // Levels Percentage
color colors[]; // level Colors
//
// Constructor ...
void XSCZonesInput()
{
Clean();
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
length = 0;
numberOfZones = 0;
//
Clean(levels);
Clean(colors);
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length >= 5 &&
numberOfZones >= 2
//
;
//
return result;
}
//
// Add Specified Level/Color ...
void AddLevelColor(
double level,
color clr //
)
{
//
Add(
level,
levels);
//
Add(
clr,
colors //
);
}
//
// Retrieve Sort Indexed Levels Color ...
void RetrieveSortedLevels(
double &_levels[],
color &_colors[] //
)
{
//
Clean(_levels);
Clean(_colors);
//
int levelsCount = ArraySize(levels);
int colorsCount = ArraySize(colors);
//
bool hasChild = IsValidSize(levelsCount) &&
IsValidSize(colorsCount);
if (!hasChild)
{
return;
}
//
// Create Temp Levels ...
double tmpLevels[];
Copy(
levels,
tmpLevels //
);
ArraySort(tmpLevels);
ArrayReverse(tmpLevels);
//
// Size of Looping ...
int minSize = MathMin(levelsCount, colorsCount);
//
for (int i = 0; i < minSize; i++)
{
//
double iLevel = tmpLevels[i];
//
int iLevelIDX = FindIndex(
iLevel,
levels //
);
if (!IsValidIndex(iLevelIDX))
{
continue;
}
//
Add(
levels[iLevelIDX],
_levels //
);
//
Add(
colors[iLevelIDX],
_colors //
);
}
}
};
//
// Class ...
//
// Specific Zone ...
class XSCZone : public CObject
{
//
// Public ...
public:
//
// Props ...
double high;
double low;
int ticks;
double percent;
//
// Compare Two Zone With Each Other ...
virtual int Compare(
const CObject *node,
const int mode = 0 //
) const
{
//
const XSCZone *other = (XSCZone *)node;
//
return other.ticks - ticks;
}
//
// Create Object ...
//
// Protected ...
protected:
//
// Private ...
private:
};
//
// Zones ...
//
class XSCZones : public XSCBase
{
//
// Public ...
public:
//
// Constructor(s) ...
void XSCZones(
string symbol,
ENUM_TIMEFRAMES period //
) : XSCBase()
{
//
this.mSymbol = symbol;
this.mPeriod = period;
}
//
void ~XSCZones()
{
//
mZones.Clear();
mChartObjects.Clear();
}
//
// Initialize Zones by Providing required
// Input Variables ...
bool Init(
XSCZonesInput &inputs // Inputs ...
)
{
//
bool result = false;
//
// Validate Inputs ...
result = inputs.IsValid();
if (!result)
{
return result;
}
//
// Set Inputs ...
mInputs = inputs;
//
// Do Calculatins ...
Calculate();
//
return result;
}
//
XSCZonesInput GetInputs()
{
return mInputs;
}
//
bool SetInputs(XSCZonesInput &inputs)
{
return Init(inputs);
}
//
// Overrides ...
//
string GetTag() override
{
return "XZONE";
}
//
// Retrieve Title Prefix ...
string GetIdentifier()
{
//
string result = NULL;
//
if (!IsValid())
{
return result;
}
//
result = GetTag() + "_" +
mSymbol + "_" +
ToString(mPeriod) +
ToFormatString(mStartTime) + "_" +
ToFormatString(mEndTime);
//
return result;
}
//
bool IsValid()
{
//
bool result = false;
//
result =
//
mZones.Total() > 0
//
;
//
return result;
}
//
// Add Specified Level/Color ...
void AddLevelColor(
double level,
color clr //
)
{
//
mInputs.AddLevelColor(
level,
clr //
);
}
//
void Calculate()
{
//
// Prevent Double Calculating ...
int bars = iBars(
mSymbol,
mPeriod //
);
if (mCalculatedBars == bars)
{
return;
}
//
mCalculatedBars = bars;
//
// Calculate Start and End Time ...
//
mStartTime = iTime(
mSymbol,
mPeriod,
mInputs.length + 1 //
);
//
mEndTime = iTime(
mSymbol,
mPeriod,
0 //
);
//
// Retrieve Ticks between Times ...
Clean(mTicks);
CopyTicksRange(
mSymbol,
mTicks,
COPY_TICKS_ALL,
mStartTime * 1000,
mEndTime * 1000 //
);
//
// Retrieve Highs ...
Clean(mHighs);
CopyHigh(
mSymbol,
mPeriod,
mStartTime,
mEndTime,
mHighs //
);
//
// Find Highest Value in Range ...
int highIDX = ArrayMaximum(mHighs);
mRangeHigh = mHighs[highIDX];
//
// Retrieve Lows ...
Clean(mLows);
CopyLow(
mSymbol,
mPeriod,
mStartTime,
mEndTime,
mLows //
);
//
// Find Lowest Value in Range ...
int lowIDX = ArrayMinimum(mLows);
mRangeLow = mLows[lowIDX];
//
datetime mTimes[];
CopyTime(
mSymbol,
mPeriod,
mStartTime,
mEndTime,
mTimes //
);
mRangeHighTime = mTimes[highIDX];
mRangeLowTime = mTimes[lowIDX];
//
double mRangeSize = GetRange();
//
// Prepare Zones Array ...
mZones.Clear();
//
// Create Zones ...
for (int i = 0; i < mInputs.numberOfZones; i++)
{
//
// Instance a New Zone ...
XSCZone *iZone = new XSCZone();
//
// Calculate Each Zones High / Low based on Range ...
double iH = mRangeHigh - mRangeSize * i / mInputs.numberOfZones;
double iL = mRangeHigh - mRangeSize * (i + 1) / mInputs.numberOfZones;
//
// Set Zone High Low Properties ...
iZone.low = iL;
iZone.high = iH;
//
// Add Zone to Zone Array Objects ...
mZones.Add(iZone);
}
//
// Calculate Each Zone Ticks ...
int mTicksCount = CountTicks();
for (int i = 0; i < mTicksCount; i++)
{
//
// Retrieve i Index Tick Object ...
MqlTick iTick = mTicks[i];
//
// Loop Through Zones ...
for (int j = 0; j < mZones.Total(); j++)
{
//
// Retrieve j Index Zone Object ...
XSCZone *jZone = mZones.At(j);
//
bool isInRange = IsTickInZoneRange(
iTick,
jZone //
);
if (isInRange)
{
//
jZone.ticks++;
break;
}
}
}
//
// Calculating Zone Percents ...
for (int i = 0; i < mZones.Total(); i++)
{
//
XSCZone *iZone = mZones.At(i);
//
double percent = CalculateZoneTickPercent(iZone);
iZone.percent = percent;
}
//
mZones.Sort();
}
//
int CountZones()
{
return mZones.Total();
}
//
XSCZone *GetZone(int index)
{
return mZones.At(index);
}
//
double CalculateZoneTickPercent(
XSCZone *zone,
int normalizationDigits = 2 //
)
{
//
double result = 0;
//
if (normalizationDigits < 2 || normalizationDigits > 5)
{
normalizationDigits = 2;
}
//
int ticksCount = CountTicks();
if (ticksCount <= 0)
{
return result;
}
//
result = (double)zone.ticks / ticksCount * 100;
result = NormalizeDouble(result, normalizationDigits);
//
return result;
}
//
bool Draw(
long chartId = 0,
string prefix = "XSCZone",
int subWindow = 0,
bool redraw = false //
)
{
//
bool result = false;
//
if (redraw)
{
mChartObjects.Clear();
}
//
if (StringLen(prefix) <= 0)
{
prefix = "XSCZone";
}
//
int zonesCount = mZones.Total();
result = IsValidSize(zonesCount);
if (!result)
{
return result;
}
//
mZones.Sort();
//
int ticksCount = CountTicks();
result = IsValidSize(ticksCount);
if (!result)
{
return result;
}
//
double levels[];
color colors[];
mInputs.RetrieveSortedLevels(
levels,
colors //
);
int levelsCount = ArraySize(levels);
int colorsCount = ArraySize(colors);
bool canSetLevels = IsValidSize(levelsCount) &&
IsValidSize(colorsCount) &&
levelsCount == colorsCount;
//
// Loop Through Zones ...
for (int i = 0; i < zonesCount; i++)
{
//
XSCZone *iZone = mZones.At(i);
//
// Generate Chart Object Names ...
string iRectName = prefix + ToString(i);
string iLabelName = iRectName + "_lbl";
//
// Creating Rectangles ...
CChartObjectRectangle *iRect = new CChartObjectRectangle();
result = iRect.Create(
chartId,
iRectName,
subWindow,
mStartTime,
iZone.high,
mEndTime,
iZone.low //
);
if (!result)
{
break;
}
//
// Set Default Rectangle Color ...
// iRect.Color(defZoneBGColor);
iRect.Fill(true);
//
// Create Label ...
CChartObjectLabel *iLabel = new CChartObjectLabel();
result = iLabel.Create(
chartId,
iLabelName,
subWindow,
mStartTime,
iZone.high //
);
if (!result)
{
break;
}
//
iLabel.Color(defZoneLBLColor);
//
iLabel.Description(ToString(iZone.percent) + "%");
//
// Set Levels and Colors if Provided ...
if (canSetLevels)
{
//
color iRectColor = defZoneBGColor;
for (int z = 0; z < levelsCount; z++)
{
//
double zLevel = levels[z];
color zColor = colors[z];
//
if (iZone.ticks >= ticksCount * zLevel)
{
//
iRectColor = zColor;
break;
}
}
//
iRect.Color(iRectColor);
}
//
mChartObjects.Add(iRect);
mChartObjects.Add(iLabel);
}
//
return result;
}
//
bool Remove(
long chartId = 0,
string prefix = "XSCZone",
int subWindow = 0,
bool redraw = false //
)
{
//
bool result = false;
//
mChartObjects.Clear();
//
result =
//
true
//
;
//
return result;
}
//
// Protected ...
protected:
//
// Props ...
//
datetime mStartTime;
datetime mEndTime;
//
MqlTick mTicks[];
double mHighs[];
double mLows[];
double mRangeHigh;
datetime mRangeHighTime;
double mRangeLow;
datetime mRangeLowTime;
//
CArrayObj mZones;
CArrayObj mChartObjects;
//
// Tools ...
//
int CountTicks()
{
return ArraySize(mTicks);
}
//
double GetRange()
{
return mRangeHigh - mRangeLow;
}
//
// Check a Tick is in a Zone rage or not ...
bool IsTickInZoneRange(
MqlTick &tick, // Tick For Checking
XSCZone *zone // Zone For Checking
)
{
//
bool result = false;
//
result =
//
tick.bid >= zone.low &&
tick.bid <= zone.high
//
;
//
return result;
}
//
// Private ...
private:
//
// Props ...
//
string mSymbol; // Analyzing Symbol
ENUM_TIMEFRAMES mPeriod; // Analyzing Period
//
XSCZonesInput mInputs; // Configurations
//
int mCalculatedBars; // Calculated Bars ...
};
File diff suppressed because it is too large Load Diff