CleanUp Workspace after Backup all Contents Even X121 Setup ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,835 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor Constructor ...
|
||||
void ~X121SetupCycleInputs()
|
||||
{
|
||||
delete setup;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
@@ -1,106 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// --------------------------------------
|
||||
// Name: XSCXMan
|
||||
// Description: Market Analyzer ...
|
||||
//
|
||||
//
|
||||
// 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"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXMan : public XSCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCXMan(
|
||||
string _symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES _period // Trading Timeframe
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = _symbol;
|
||||
mPeriod = _period;
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCXMan() {}
|
||||
|
||||
//
|
||||
// Override(s) ...
|
||||
|
||||
//
|
||||
// Represent Basic Unique Tag ...
|
||||
string GetTag() override
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = GetTypeName(this);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Class Token ...
|
||||
string GetToken() override
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = GetSpecificToken(this);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string mSymbol; // Trading Symbol
|
||||
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame
|
||||
|
||||
//
|
||||
// Configurations ...
|
||||
|
||||
int _maxNumberOfHoldingItems;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,54 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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)
|
||||
|
||||
//
|
||||
|
||||
};
|
||||
@@ -1,736 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 ...
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,330 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,746 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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;
|
||||
};
|
||||
|
||||
//
|
||||
@@ -1,805 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 ...
|
||||
};
|
||||
Reference in New Issue
Block a user