backup v1 and compile ...
This commit is contained in:
@@ -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
@@ -0,0 +1,652 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center X121EA MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121EA
|
||||
// Description: an Exper Advisor which used RSI and MA
|
||||
// to Analyse Market ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Classes/x-saherelm.x121.setup.xea.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "X121EA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long x121EAMagicNumber = 78692110; // Magic Number
|
||||
input int x121EASlippage = 10; // Slippgae
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
input group "Symbol(s)";
|
||||
input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols
|
||||
input bool x121EAUseAllSymbols = false; // Use All Available Symbols
|
||||
input bool x121EAUseAllWatchListSymbols = false; // Use All Watch List Symbols
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input bool x121EAAllowLong = true; // Allow Long Trades
|
||||
input bool x121EAAllowShort = true; // Allow Short Trades
|
||||
input int x121EAStartSignallingHoure = 3; // Start Signalling at Specific Time
|
||||
input int x121EAEndSignallingHoure = 22; // End Signalling at Specific Time
|
||||
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
|
||||
input int x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals
|
||||
input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals
|
||||
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
|
||||
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input double x121EAVolume = 0.01; // Static Volume
|
||||
input double x121EATPPoint = 1000; // TP Point
|
||||
input double x121EASLPoint = 1000; // SL Point
|
||||
input bool x121EAIgnoreSL = false; // Ignore Calculated SL
|
||||
input bool x121EAIgnoreTP = false; // Ignore Calculated TP
|
||||
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
|
||||
input int x121EAMaxAllowedTrades = 2; // Max Allowed Positions Per Symbol
|
||||
input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction
|
||||
input int x121EAMinFreeMargingForOpenTrades = 900; // Min Margin For Opening Trades
|
||||
input bool x121EAIncreaseNextSignalsVolume = true; // Increase Next Signals Volume
|
||||
input double x121EAIncreaseNextSignalsVolumeMultiplier = 1; // Increase Next Signals Volume Multiplier
|
||||
input bool x121EAAcceptNextDirectionalSignalsWhenFirstInProfit = true; // Accept Same Symbol/Type Signal when Last in Profit
|
||||
|
||||
//
|
||||
input group "Trailling";
|
||||
input bool x121EAAllowTrailStop = true; // Enable Trailling Stop Losses
|
||||
input bool x121EADisableTrailingWhenOpposit = true; // Disable Trailling When has Opposite In Drawdown
|
||||
input double x121EAFirstTrailDistance = 100; // Start Trailling Distance
|
||||
input double x121EAFirstTrailPoint = 60; // First Stop Trail
|
||||
input double x121EANextTrailDistance = 50; // Next Trailling Distance
|
||||
input double x121EANextTrailPoint = 25; // Next Trailling Step
|
||||
|
||||
//
|
||||
input group "Supporting";
|
||||
input bool x121EAAllowSupport = false; // Allow Support Signals
|
||||
input bool x121EASupportOnlyForces = false; // Support Only Force Signals
|
||||
double x121EASupportDistance = 0; // Supporting Distance
|
||||
input int x121EAMaxNumberOfSupports = 0; // Max Number of Support Signals
|
||||
input double x121EASupportVolumeMultiplier = 0; // Support Signals Volume Multiplier
|
||||
input double x121EAMaxAllowedSupportVolume = 0; // Max Allowed Support Signals Volume
|
||||
|
||||
//
|
||||
input group "Grid";
|
||||
input bool x121EAAllowGrid = false; // Allow Grid Signals
|
||||
input bool x121EAGridOnlyForces = false; // Grid Only Force Signals
|
||||
input int x121EAMaxNumberOfGrids = 0; // Max Number of Grid Signals
|
||||
input double x121EAGridDistance = 0; // Grid Distance
|
||||
input double x121EAGridVolumeMultiplier = 0; // Grid Volume Multiplier
|
||||
input double x121EAMaxAllowedGridVolume = 0; // Max Allowed Grid Signals Volume
|
||||
|
||||
//
|
||||
input group "Recovery";
|
||||
input bool x121EAAllowRecovery = false; // Allow Recovery Signals
|
||||
input bool x121EARecoverOnlyForces = false; // Recover Only Force Signals
|
||||
input int x121EAMaxNumberOfRecoveries = 0; // Max Number of Recovery Signals
|
||||
input double x121EARecoveryDistance = 0; // Recovery Distance
|
||||
input double x121EARecoveryVolumeMultiplier = 0; // Recovery Volume Multiplier
|
||||
input double x121EAMaxAllowedRecoveryVolume = 0; // Max Allowed Recovery Signals Volume
|
||||
|
||||
//
|
||||
input group "Hedging";
|
||||
input int x121EARestingAfterHedge = 1000; // Resting Seconds After Hedge
|
||||
input double x121EAMinRequiredProfitPerTrade = 0.3; // Minimum Required Profit for Hedging
|
||||
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
input group "Alerts";
|
||||
input bool x121EAEnableAlerts = true; // Enable Alerts
|
||||
input bool x121EALogAlerts = true; // Log Alerts
|
||||
input bool x121EAMailAlerts = false; // Mail Alerts
|
||||
input bool x121EAPushAlerts = false; // Push Alerts
|
||||
input bool x121EATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Local Variables ...
|
||||
|
||||
//
|
||||
string x121EAUsedSymbols[];
|
||||
XSCX121SetupEA *x121EA;
|
||||
|
||||
//
|
||||
XSCXCTHelper *x121EACTHelper;
|
||||
XSCXCCHelper *x121EACCHelper;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XSampleEA Providers ...
|
||||
delete x121EA;
|
||||
|
||||
//
|
||||
delete x121EACTHelper;
|
||||
delete x121EACCHelper;
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
x121EA.OnTick();
|
||||
|
||||
//
|
||||
X121ReportState();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default();
|
||||
x121EACTHelper = new XSCXCTHelper();
|
||||
result = x121EACTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default();
|
||||
x121EACCHelper = new XSCXCCHelper();
|
||||
result = x121EACCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TesterHideIndicators(true);
|
||||
|
||||
//
|
||||
string inputSymbols[];
|
||||
int inputSymbolsCount = SplitContent(
|
||||
inputSymbols,
|
||||
x121EASymbols //
|
||||
);
|
||||
|
||||
//
|
||||
string allSymbols[];
|
||||
int allSymbolsCount = GetAllSymbols(
|
||||
allSymbols //
|
||||
);
|
||||
|
||||
//
|
||||
string watchListSymbols[];
|
||||
int watchListSymbolsCount = GetAllSymbols(
|
||||
watchListSymbols,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
Clean(x121EAUsedSymbols);
|
||||
if (x121EAUseAllSymbols)
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
allSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else if (x121EAUseAllWatchListSymbols)
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
watchListSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else if (IsValidSize(inputSymbolsCount))
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
inputSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Add(
|
||||
_Symbol,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
int symbolsCount = ArraySize(x121EAUsedSymbols);
|
||||
result = IsValidSize(symbolsCount);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
x121EA = new XSCX121SetupEA(
|
||||
x121EASlippage,
|
||||
x121EAMagicNumber //
|
||||
);
|
||||
|
||||
//
|
||||
// Configure EA Class Instance ...
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
x121EA.AllowLong(x121EAAllowLong);
|
||||
x121EA.AllowShort(x121EAAllowShort);
|
||||
x121EA.DelayBetweenTwoSignal(x121EADelayBetweenTwoSignal);
|
||||
x121EA.ExecuteSignalsOnBreakout(x121EAExecuteSignalsOnBreakout);
|
||||
x121EA.ReuiredSignalVerifications(x121EAReuiredSignalVerifications);
|
||||
x121EA.GetVerificationFromOtherTimeFrames(x121EAGetVerificationFromOtherTimeFrames);
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
x121EA.Volume(x121EAVolume);
|
||||
x121EA.TPPoint(x121EATPPoint);
|
||||
x121EA.SLPoint(x121EASLPoint);
|
||||
x121EA.IgnoreSL(x121EAIgnoreSL);
|
||||
x121EA.IgnoreTP(x121EAIgnoreTP);
|
||||
x121EA.MaxAllowedTrades(x121EAMaxAllowedTrades);
|
||||
x121EA.IncreaseNextSignalsVolume(x121EAIncreaseNextSignalsVolume);
|
||||
x121EA.UseMaxAllowedPerDirection(x121EAUseMaxAllowedPerDirection);
|
||||
x121EA.MinFreeMargingForOpenTrades(x121EAMinFreeMargingForOpenTrades);
|
||||
x121EA.IncreaseNextSignalsVolumeMultiplier(x121EAIncreaseNextSignalsVolumeMultiplier);
|
||||
x121EA.AcceptNextDirectionalSignalsWhenFirstInProfit(x121EAAcceptNextDirectionalSignalsWhenFirstInProfit);
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
x121EA.CloseOnOpposit(x121EACloseOnOpposit);
|
||||
x121EA.EndSignallingHoure(x121EAEndSignallingHoure);
|
||||
x121EA.CloseOnSpecificTime(x121EACloseOnSpecificTime);
|
||||
x121EA.StartSignallingHoure(x121EAStartSignallingHoure);
|
||||
|
||||
//
|
||||
// Trailling ...
|
||||
x121EA.AllowTrailStop(x121EAAllowTrailStop);
|
||||
x121EA.NextTrailPoint(x121EANextTrailPoint);
|
||||
x121EA.FirstTrailPoint(x121EAFirstTrailPoint);
|
||||
x121EA.NextTrailDistance(x121EANextTrailDistance);
|
||||
x121EA.FirstTrailDistance(x121EAFirstTrailDistance);
|
||||
x121EA.DisableTrailingWhenOpposit(x121EADisableTrailingWhenOpposit);
|
||||
|
||||
//
|
||||
// Supporting ...
|
||||
x121EA.AllowSupport(x121EAAllowSupport);
|
||||
x121EA.SupportOnlyForces(x121EASupportOnlyForces);
|
||||
x121EA.SupportDistance(x121EASupportDistance);
|
||||
x121EA.MaxNumberOfSupports(x121EAMaxNumberOfSupports);
|
||||
x121EA.SupportVolumeMultiplier(x121EASupportVolumeMultiplier);
|
||||
x121EA.MaxAllowedSupportVolume(x121EAMaxAllowedSupportVolume);
|
||||
|
||||
//
|
||||
// Grid ...
|
||||
x121EA.AllowGrid(x121EAAllowGrid);
|
||||
x121EA.GridOnlyForces(x121EAGridOnlyForces);
|
||||
x121EA.GridDistance(x121EAGridDistance);
|
||||
x121EA.MaxNumberOfGrids(x121EAMaxNumberOfGrids);
|
||||
x121EA.GridVolumeMultiplier(x121EAGridVolumeMultiplier);
|
||||
x121EA.MaxAllowedGridVolume(x121EAMaxAllowedGridVolume);
|
||||
|
||||
//
|
||||
// Recovery ...
|
||||
x121EA.AllowRecovery(x121EAAllowRecovery);
|
||||
x121EA.RecoverOnlyForces(x121EARecoverOnlyForces);
|
||||
x121EA.RecoveryDistance(x121EARecoveryDistance);
|
||||
x121EA.MaxNumberOfRecoveries(x121EAMaxNumberOfRecoveries);
|
||||
x121EA.RecoveryVolumeMultiplier(x121EARecoveryVolumeMultiplier);
|
||||
x121EA.MaxAllowedRecoveryVolume(x121EAMaxAllowedRecoveryVolume);
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
x121EA.RestingAfterHedge(x121EARestingAfterHedge);
|
||||
x121EA.MinProfitPerTrade(x121EAMinRequiredProfitPerTrade);
|
||||
x121EA.MinProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor);
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
x121EA.SetAlertPrefix(ShortName);
|
||||
x121EA.SetAlertEnableAlerts(x121EAEnableAlerts);
|
||||
x121EA.SetAlertLogAlerts(x121EALogAlerts);
|
||||
x121EA.SetAlertMailAlerts(x121EAMailAlerts);
|
||||
x121EA.SetAlertPushAlerts(x121EAPushAlerts);
|
||||
x121EA.SetAlertTerminalAlerts(x121EATerminalAlerts);
|
||||
|
||||
//
|
||||
// Configure Indicators ...
|
||||
X121SetupInputs setupInputsDefault;
|
||||
setupInputsDefault.Default();
|
||||
X121PreConfigureStyles(setupInputsDefault);
|
||||
|
||||
//
|
||||
// Prepare Providers and Add them into mX121EA class ...
|
||||
for (int i = 0; i < symbolsCount; i++)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
string iSymbol = x121EAUsedSymbols[i];
|
||||
ENUM_TIMEFRAMES iHostPeriod = _Period;
|
||||
|
||||
//
|
||||
XSCX121SetupCycles *iSetupCycle;
|
||||
iSetupCycle = new XSCX121SetupCycles();
|
||||
result = iSetupCycle.Init(
|
||||
setupInputsDefault,
|
||||
iSymbol,
|
||||
iHostPeriod //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = x121EA.AddSetup(iSetupCycle);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void X121PreConfigureStyles(X121SetupInputs &inputs)
|
||||
{
|
||||
//
|
||||
// XHTD ...
|
||||
inputs.htdInputs.show = false;
|
||||
|
||||
//
|
||||
// XATSL ...
|
||||
inputs.atslInputs.show = false;
|
||||
|
||||
//
|
||||
// XSLN ...
|
||||
inputs.slnInputs.show = false;
|
||||
|
||||
//
|
||||
// XDMNT ...
|
||||
inputs.dmntInputs.showBull = false;
|
||||
inputs.dmntInputs.showBear = false;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
inputs.strInputs.showTrends = false;
|
||||
inputs.strInputs.fillTrends = false;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
inputs.pvInputs.showPeaksAndVales = false;
|
||||
inputs.pvInputs.showLevels = false;
|
||||
inputs.pvInputs.showConsolidations = false;
|
||||
inputs.pvInputs.showFibo1Levels = false;
|
||||
inputs.pvInputs.showFibo2Levels = false;
|
||||
inputs.pvInputs.showFibo3Levels = false;
|
||||
inputs.pvInputs.showFibo4Levels = false;
|
||||
inputs.pvInputs.showFibo5Levels = false;
|
||||
|
||||
//
|
||||
// XMC ...
|
||||
inputs.mcInputs.showSar = false;
|
||||
inputs.mcInputs.showFastMa = false;
|
||||
inputs.mcInputs.showSlowMa = false;
|
||||
inputs.mcInputs.showVerifierMa = false;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
inputs.hkInputs.drawHikenAshi = false;
|
||||
inputs.hkInputs.drawSmoothedHikenAshi = false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
inputs.cheInputs.showLongExit1Line = false;
|
||||
inputs.cheInputs.showShortExit1Line = false;
|
||||
inputs.cheInputs.showLongExit2Line = false;
|
||||
inputs.cheInputs.showShortExit2Line = false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
inputs.ichInputs.showTenkanSen = false;
|
||||
inputs.ichInputs.showKijunSen = false;
|
||||
inputs.ichInputs.showKijunSenPlus = false;
|
||||
inputs.ichInputs.showKijunSenNegative = false;
|
||||
inputs.ichInputs.showChikouSpan = false;
|
||||
inputs.ichInputs.showSenkouSpanA = false;
|
||||
inputs.ichInputs.showSenkouSpanB = false;
|
||||
inputs.ichInputs.showKumo = false;
|
||||
|
||||
//
|
||||
// XMRB ...
|
||||
inputs.mrbInputs.showFastMa = false;
|
||||
inputs.mrbInputs.showSlowMa = false;
|
||||
inputs.mrbInputs.showRibbon = false;
|
||||
|
||||
//
|
||||
// XASCT ...
|
||||
inputs.asctInputs.showLongs = false;
|
||||
inputs.asctInputs.showShorts = false;
|
||||
|
||||
//
|
||||
// XSSLC ...
|
||||
inputs.sslcInputs.showUp = false;
|
||||
inputs.sslcInputs.showDown = false;
|
||||
|
||||
//
|
||||
// XHULL ...
|
||||
inputs.hullInputs.showUpZone = false;
|
||||
inputs.hullInputs.showDownZone = false;
|
||||
}
|
||||
|
||||
//
|
||||
void X121ReportState()
|
||||
{
|
||||
//
|
||||
string comment = NULL;
|
||||
|
||||
//
|
||||
comment =
|
||||
ShortName + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Trading Symbols: " + ToString(ArraySize(x121EAUsedSymbols)) + "\n" + "\n";
|
||||
|
||||
//
|
||||
// Detect What we Want to Show as Comment ...
|
||||
// bool isInForceState = x121EA.ForceState();
|
||||
double bullishScore = 0; // x121EA.GetBullishScore();
|
||||
double bearishScore = 0; // x121EA.GetBearishScore();
|
||||
double drawDownPercent = x121EA.GetDrawdownPercent();
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
(bullishScore > 0 || bearishScore > 0
|
||||
? "Scores:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Bullish: " + ToString(bullishScore) + "\n" +
|
||||
"Bearish: " + ToString(bearishScore) + "\n" +
|
||||
"------------" + "\n"
|
||||
: "") +
|
||||
"Drawdown: " + ToString(drawDownPercent) + "%" + "\n" +
|
||||
// "------------" + "\n" +
|
||||
// "Force State: " + ToString(isInForceState) + "\n" +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = x121EA.mTrader.GetPositions(
|
||||
positions //
|
||||
);
|
||||
if (IsValidSize(positionsCount))
|
||||
{
|
||||
//
|
||||
int longs = 0;
|
||||
double longVolumes = 0;
|
||||
double longProfits = 0;
|
||||
|
||||
//
|
||||
int shorts = 0;
|
||||
double shortVolumes = 0;
|
||||
double shortProfits = 0;
|
||||
|
||||
//
|
||||
// Retrieve Required Informations of Positions ...
|
||||
CountPositions(
|
||||
positions,
|
||||
longs,
|
||||
longProfits,
|
||||
longVolumes,
|
||||
shorts,
|
||||
shortProfits,
|
||||
shortVolumes //
|
||||
);
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
"------------" + "\n" +
|
||||
"Positions: " + "\n" +
|
||||
"------------" + "\n" +
|
||||
(longs <= 0
|
||||
? ""
|
||||
: "\n" + "Longs:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Count: " + ToString(longs) + "\n" +
|
||||
"Profits: " + ToString(longProfits) + "\n" +
|
||||
""
|
||||
//
|
||||
) +
|
||||
//
|
||||
(shorts <= 0
|
||||
? ""
|
||||
: "\n" + "Shorts:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Count: " + ToString(shorts) + "\n" +
|
||||
"Profits: " + ToString(shortProfits) + "\n" +
|
||||
""
|
||||
//
|
||||
) +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
if (positionsCount > 1 && x121EAMinRequiredProfitPerTrade > 0 && x121EAMinRequiredProfitPerVolumeFactor > 0)
|
||||
{
|
||||
//
|
||||
double profit = SpecifiedCalculatePositionsProfit(
|
||||
positions //
|
||||
);
|
||||
double requiredProfitForHedge = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
x121EAMinRequiredProfitPerTrade,
|
||||
x121EAMinRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
"\n" + "Hedging: " + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Profits: " + ToString(profit) + "\n" +
|
||||
"RequiredProft: " + ToString(requiredProfitForHedge) + "\n" +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValid(comment))
|
||||
{
|
||||
Comment(comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,704 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XADXTD
|
||||
// Description: provides Indicator implementation
|
||||
// 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.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Indicator Buffers ...
|
||||
enum ENUM_XADXTD_BUFFERS
|
||||
{
|
||||
XADXTD_STRENGTH_LINE = 0, // Strenght Buffer ...
|
||||
XADXTD_BULL_LINE = 1, // Bull Buffer ...
|
||||
XADXTD_BEAR_LINE = 2, // Bear Buffer ...
|
||||
};
|
||||
|
||||
//
|
||||
// XADXTD Indicator Inputs ...
|
||||
struct XADXTDInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
int length; // Length
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XADXTDInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
length = 21;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Max Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
int values[1] = {
|
||||
length //
|
||||
};
|
||||
|
||||
//
|
||||
result = GetMax(values);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XADXTDConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double strength[];
|
||||
double bullp[];
|
||||
double bearp[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isStrong;
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
bool isStrongSwitchedToBullish;
|
||||
bool isStrongSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(strength);
|
||||
Clean(bullp);
|
||||
Clean(bearp);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(strength, true);
|
||||
ArraySetAsSeries(bullp, true);
|
||||
ArraySetAsSeries(bearp, true);
|
||||
|
||||
//
|
||||
isStrong = false;
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
isStrongSwitchedToBullish = false;
|
||||
isStrongSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
bullishScore++;
|
||||
if (isStrong)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
}
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
if (isStrong)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
if (isStrong)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
if (isStrong)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
if (isStrongSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isStrongSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isStrong", isStrong, ignoreFalseConditions, separator) +
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongSwitchedToBullish", isStrongSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongSwitchedToBearish", isStrongSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XADXTD";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXADXTDHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXADXTDHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXADXTDHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XADXTDInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullpBuffer, true);
|
||||
ArraySetAsSeries(bearpBuffer, true);
|
||||
ArraySetAsSeries(strengthBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xadxtd",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.length // Length
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XADXTDInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XADXTDInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Strength ...
|
||||
|
||||
//
|
||||
double GetStrength(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(strengthBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return strengthBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyStrength(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
strengthBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// BullP ...
|
||||
|
||||
//
|
||||
double GetBullP(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(bullpBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return bullpBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyBullP(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
bullpBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// BearP ...
|
||||
|
||||
//
|
||||
double GetBearP(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(bearpBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return bearpBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyBearP(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
bearpBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XADXTDConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyStrength(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.strength //
|
||||
);
|
||||
|
||||
//
|
||||
CopyBullP(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bullp //
|
||||
);
|
||||
|
||||
//
|
||||
CopyBearP(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bearp //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isStrong = conditions.strength[cIndex] >= 20;
|
||||
|
||||
//
|
||||
bool isBullish = conditions.bullp[cIndex] > conditions.bearp[cIndex];
|
||||
bool isBearish = conditions.bearp[cIndex] > conditions.bullp[cIndex];
|
||||
|
||||
//
|
||||
bool isBullishPrev = conditions.bullp[pIndex] > conditions.bearp[pIndex];
|
||||
bool isBearishPrev = conditions.bearp[pIndex] > conditions.bullp[pIndex];
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
bool isStrongSwitchedToBullish = isStrong &&
|
||||
isSwitchedToBullish;
|
||||
bool isStrongSwitchedToBearish = isStrong &&
|
||||
isSwitchedToBearish;
|
||||
|
||||
//
|
||||
conditions.isStrong = isStrong;
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish;
|
||||
conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XADXTDInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double bullpBuffer[];
|
||||
double bearpBuffer[];
|
||||
double strengthBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Strength Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XADXTD_STRENGTH_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
strengthBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// BullP Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XADXTD_BULL_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
bullpBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// BearP Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XADXTD_BEAR_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
bearpBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,320 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXAMAHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XAMA_BUFFERS
|
||||
{
|
||||
XAMA_MAIN_LINE = 0
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XAMAInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
//
|
||||
// Market ...
|
||||
int length; // Period
|
||||
int fastEMA; // Fast EMA Period
|
||||
int slowEMA; // Slow EMA Period
|
||||
int maShift; // Shift
|
||||
ENUM_APPLIED_PRICE appliedTo; // Applied To
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLine; // Show Line
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XAMAInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0;
|
||||
fastEMA = 0;
|
||||
slowEMA = 0;
|
||||
maShift = 0;
|
||||
showLine = false;
|
||||
appliedTo = PRICE_CLOSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 18;
|
||||
fastEMA = 2;
|
||||
slowEMA = 30;
|
||||
maShift = 0;
|
||||
showLine = true;
|
||||
appliedTo = PRICE_CLOSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 0 &&
|
||||
fastEMA > 0 &&
|
||||
slowEMA > 0 &&
|
||||
slowEMA > fastEMA
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(length, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXAMAHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXAMAHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXAMAHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XAMAInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mainBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xama",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length, // Period
|
||||
mInputs.fastEMA, // Fast EMA Period
|
||||
mInputs.slowEMA, // Slow EMA Period
|
||||
mInputs.maShift, // Shift
|
||||
mInputs.appliedTo, // Applied To
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showLine // Show Line
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XAMAInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XAMAInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetMain(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(mainBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return mainBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyMain(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
mainBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XAMAInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XAMA_MAIN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
mainBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,578 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXASCTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XASCT_BUFFERS
|
||||
{
|
||||
XASCT_LONG_LINE = 0,
|
||||
XASCT_SHORT_LINE = 1
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XASCTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
//
|
||||
// Market ...
|
||||
int risk; // Risk
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLongs; // Show Long Arrows
|
||||
bool showShorts; // Show Short Arrows
|
||||
uchar longArrowCode; // Long Arrow
|
||||
uchar shortArrowCode; // Short Arrow
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XASCTInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
risk = 0;
|
||||
|
||||
//
|
||||
showLongs = false;
|
||||
showShorts = false;
|
||||
longArrowCode = 0;
|
||||
shortArrowCode = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
risk = 4;
|
||||
|
||||
//
|
||||
showLongs = true;
|
||||
showShorts = true;
|
||||
longArrowCode = 233;
|
||||
shortArrowCode = 234;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
risk >= 1
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = int(MathMax(3 + risk * 2, 4) + 1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XASCTConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double longSignal[];
|
||||
double shortSignal[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isLongSignal;
|
||||
bool isShortSignal;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(longSignal);
|
||||
Clean(shortSignal);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(longSignal, true);
|
||||
ArraySetAsSeries(shortSignal, true);
|
||||
|
||||
//
|
||||
isLongSignal = false;
|
||||
isShortSignal = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isLongSignal)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isShortSignal)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isLongSignal", isLongSignal, ignoreFalseConditions, separator) +
|
||||
ToString("isShortSignal", isShortSignal, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XASCT";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXASCTHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXASCTHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXASCTHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XASCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(longsBuffer, true);
|
||||
ArraySetAsSeries(shortsBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xasct",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.risk, // Risk
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showLongs, // Show Long Arrows
|
||||
mInputs.showShorts, // Show Short Arrows
|
||||
mInputs.longArrowCode, // Long Arrow
|
||||
mInputs.shortArrowCode // Short Arrow
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XASCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XASCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetLong(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(longsBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return longsBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyLong(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
longsBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetShort(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(shortsBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return shortsBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyShort(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
shortsBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XASCTConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyLong(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.longSignal //
|
||||
);
|
||||
CopyShort(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.shortSignal //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isLongSignal = NotEmptyZero(conditions.longSignal[cIndex]);
|
||||
bool isShortSignal = NotEmptyZero(conditions.shortSignal[cIndex]);
|
||||
|
||||
//
|
||||
conditions.isLongSignal = isLongSignal;
|
||||
conditions.isShortSignal = isShortSignal;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XASCTInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double longsBuffer[];
|
||||
double shortsBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Longs Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XASCT_LONG_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
longsBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Shorts Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XASCT_SHORT_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
shortsBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,552 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXATSLHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XATSL_BUFFERS
|
||||
{
|
||||
XATSL_MAIN_LINE = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XATSLInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
double coeff; // Coefficient
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool show; // Show
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XATSLInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0;
|
||||
coeff = 0;
|
||||
|
||||
//
|
||||
show = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 14;
|
||||
coeff = 2.0;
|
||||
|
||||
//
|
||||
show = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 2 &&
|
||||
coeff > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XATSLConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double atsl[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(atsl);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atsl, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XATSL";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXATSLHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXATSLHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXATSLHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XATSLInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atslBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xatsl",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length,
|
||||
mInputs.coeff,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.show
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XATSLInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XATSLInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetATSL(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(atslBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return atslBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyATSL(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
atslBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XATSLConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyATSL(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.atsl //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = conditions.atsl[cIndex] < cBar.close;
|
||||
bool isBullishPrev = conditions.atsl[pIndex] < pBar.close;
|
||||
|
||||
//
|
||||
bool isBearish = conditions.atsl[cIndex] > cBar.close;
|
||||
bool isBearishPrev = conditions.atsl[pIndex] > pBar.close;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XATSLInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double atslBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000)
|
||||
{
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Longs Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XATSL_MAIN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
atslBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,245 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCCHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XCCInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Chart Style ...
|
||||
ENUM_CHART_MODE mode; // Mode
|
||||
color upColor; // Up Color
|
||||
color downColor; // Down Color
|
||||
color lineColor; // Line mode and Doji candlestick Color
|
||||
color bearishColor; // Bullish Color
|
||||
color bullishColor; // Bearish Color
|
||||
color volumesColor; // Volumes Color
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandles; // Show Candles
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XCCInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = CLR_NONE;
|
||||
downColor = CLR_NONE;
|
||||
lineColor = CLR_NONE;
|
||||
bearishColor = CLR_NONE;
|
||||
bullishColor = CLR_NONE;
|
||||
volumesColor = CLR_NONE;
|
||||
|
||||
//
|
||||
showCandles = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
mode = CHART_CANDLES;
|
||||
|
||||
//
|
||||
upColor = clrLime;
|
||||
downColor = clrRed;
|
||||
lineColor = clrLime;
|
||||
bearishColor = clrRed;
|
||||
bullishColor = clrLime;
|
||||
volumesColor = clrGreen;
|
||||
//
|
||||
showCandles = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXCCHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXCCHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XCCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xcc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Chart Style ...
|
||||
"",
|
||||
mInputs.mode, // Mode
|
||||
mInputs.upColor, // Up Color
|
||||
mInputs.downColor, // Down Color
|
||||
mInputs.lineColor, // Line mode and Doji candlestick Color
|
||||
mInputs.bearishColor, // Bullish Color
|
||||
mInputs.bullishColor, // Bearish Color
|
||||
mInputs.volumesColor, // Volumes Color
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandles // Show Candles
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XCCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XCCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XCCInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,805 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCHEHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XCHE_BUFFERS
|
||||
{
|
||||
X_CHE_LONG_EXIT_1_LINE = 0,
|
||||
X_CHE_SHORT_EXIT_1_LINE = 1,
|
||||
X_CHE_LONG_EXIT_2_LINE = 2,
|
||||
X_CHE_SHORT_EXIT_2_LINE = 3,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XCHEInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
int loopback; // Loopback
|
||||
double multiplier1; // 1st Multiplier
|
||||
double multiplier2; // 2nd Multiplier
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied To
|
||||
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLongExit1Line; // Show 1st Long Exit
|
||||
bool showShortExit1Line; // Show 1st Short Exit
|
||||
bool showLongExit2Line; // Show 2st Long Exit
|
||||
bool showShortExit2Line; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XCHEInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0;
|
||||
loopback = 0;
|
||||
multiplier1 = 0;
|
||||
multiplier2 = 0;
|
||||
|
||||
//
|
||||
upAppliedTo = PRICE_HIGH;
|
||||
downAppliedTo = PRICE_LOW;
|
||||
|
||||
//
|
||||
showLongExit1Line = false;
|
||||
showShortExit1Line = false;
|
||||
showLongExit2Line = false;
|
||||
showShortExit2Line = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 35;
|
||||
loopback = 26;
|
||||
multiplier1 = 3.0;
|
||||
multiplier2 = 3.5;
|
||||
|
||||
//
|
||||
upAppliedTo = PRICE_HIGH;
|
||||
downAppliedTo = PRICE_LOW;
|
||||
|
||||
//
|
||||
showLongExit1Line = true;
|
||||
showShortExit1Line = true;
|
||||
showLongExit2Line = true;
|
||||
showShortExit2Line = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 0 &&
|
||||
loopback < length &&
|
||||
multiplier1 > 0 &&
|
||||
multiplier2 > multiplier1
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(length, loopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XCHEConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double long1[];
|
||||
double long2[];
|
||||
double short1[];
|
||||
double short2[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isStrongBullish;
|
||||
bool isStrongBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
bool isStrongSwitchedToBullish;
|
||||
bool isStrongSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(long1);
|
||||
Clean(long2);
|
||||
Clean(short1);
|
||||
Clean(short2);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(long1, true);
|
||||
ArraySetAsSeries(long2, true);
|
||||
ArraySetAsSeries(short1, true);
|
||||
ArraySetAsSeries(short2, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isStrongBullish = false;
|
||||
isStrongBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
isStrongSwitchedToBullish = false;
|
||||
isStrongSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isStrongBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isStrongSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isStrongBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isStrongSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongBullish", isStrongBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongBearish", isStrongBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongSwitchedToBullish", isStrongSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isStrongSwitchedToBearish", isStrongSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XCHE";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXCHEHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXCHEHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXCHEHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XCHEInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(longExit1Buffer, true);
|
||||
ArraySetAsSeries(longExit2Buffer, true);
|
||||
ArraySetAsSeries(shortExit1Buffer, true);
|
||||
ArraySetAsSeries(shortExit2Buffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xche",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length,
|
||||
mInputs.loopback,
|
||||
mInputs.multiplier1,
|
||||
mInputs.multiplier2,
|
||||
//
|
||||
// Calculations ...
|
||||
"",
|
||||
mInputs.upAppliedTo,
|
||||
mInputs.downAppliedTo,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showLongExit1Line, // Show 1st Long Exit,
|
||||
mInputs.showShortExit1Line, // Show 1st Short Exit,
|
||||
mInputs.showLongExit2Line, // Show 2st Long Exit,
|
||||
mInputs.showShortExit2Line // Show 2st Short Exit
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XCHEInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XCHEInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetLongExit1(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return longExit1Buffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Long Exits 1 ...
|
||||
int CopyLongExit1(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
longExit1Buffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetLongExit2(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return longExit2Buffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Long Exits 2 ...
|
||||
int CopyLongExit2(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
longExit2Buffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetShortExit1(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return shortExit1Buffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Short Exits 1 ...
|
||||
int CopyShortExit1(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
shortExit1Buffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetShortExit2(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return shortExit2Buffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Short Exits 2 ...
|
||||
int CopyShortExit2(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
shortExit2Buffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XCHEConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyLongExit1(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.long1 //
|
||||
);
|
||||
CopyLongExit2(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.long2 //
|
||||
);
|
||||
CopyShortExit1(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.short1 //
|
||||
);
|
||||
CopyShortExit2(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.short2 //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = NotEmptyZero(conditions.long1[cIndex]);
|
||||
bool isBearish = NotEmptyZero(conditions.short1[cIndex]);
|
||||
|
||||
//
|
||||
bool isBullishPrev = NotEmptyZero(conditions.long1[pIndex]);
|
||||
bool isBearishPrev = NotEmptyZero(conditions.short1[pIndex]);
|
||||
|
||||
//
|
||||
bool isStrongBullish = isBullish &&
|
||||
NotEmptyZero(conditions.long2[cIndex]);
|
||||
bool isStrongBearish = isBearish &&
|
||||
NotEmptyZero(conditions.short2[cIndex]);
|
||||
|
||||
//
|
||||
bool isStrongBullishPrev = isBullishPrev &&
|
||||
NotEmptyZero(conditions.long2[pIndex]);
|
||||
bool isStrongBearishPrev = isBearishPrev &&
|
||||
NotEmptyZero(conditions.short2[pIndex]);
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
bool isStrongSwitchedToBullish = isStrongBullish &&
|
||||
!isStrongBullishPrev;
|
||||
bool isStrongSwitchedToBearish = isStrongBearish &&
|
||||
!isStrongBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isStrongBullish = isStrongBullish;
|
||||
conditions.isStrongBearish = isStrongBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish;
|
||||
conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XCHEInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
//
|
||||
double longExit1Buffer[];
|
||||
double longExit2Buffer[];
|
||||
double shortExit1Buffer[];
|
||||
double shortExit2Buffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X_CHE_LONG_EXIT_1_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
longExit1Buffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X_CHE_LONG_EXIT_2_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
longExit2Buffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X_CHE_SHORT_EXIT_1_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
shortExit1Buffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X_CHE_SHORT_EXIT_2_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
shortExit2Buffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,220 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXCTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XCTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
color clr; // Text Color
|
||||
ENUM_BASE_CORNER corner; // Text Position
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showCandleTime; // Show Candle Time
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XCTInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
clr = CLR_NONE;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
clr = clrYellow;
|
||||
corner = CORNER_RIGHT_LOWER;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showCandleTime = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXCTHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXCTHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XCTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xct",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.clr, // Text Color
|
||||
mInputs.corner, // Text Position
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showCandleTime // Show Candle Time
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XCTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XCTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XCTInputs mInputs; // Inputs ...
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,568 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXDMNTHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XDMNT_BUFFERS
|
||||
{
|
||||
XDMNT_BULL_LINE = 0,
|
||||
XDMNT_BEAR_LINE = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XDMNTInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showBull; // Show Bull
|
||||
bool showBear; // Show Bear
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XDMNTInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
showBull = false;
|
||||
showBear = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
showBull = true;
|
||||
showBear = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XDMNTConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double bull[];
|
||||
double bear[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(bull);
|
||||
Clean(bear);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bull, true);
|
||||
ArraySetAsSeries(bear, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XDMNT";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXDMNTHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXDMNTHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXDMNTHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XDMNTInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullBuffer, true);
|
||||
ArraySetAsSeries(bearBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xdmnt",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showBull,
|
||||
mInputs.showBear
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XDMNTInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XDMNTInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Bull ...
|
||||
|
||||
//
|
||||
double GetBull(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(bullBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return bullBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyBull(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
bullBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Bear ...
|
||||
|
||||
//
|
||||
double GetBear(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(bearBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return bearBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyBear(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
bearBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XDMNTConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyBull(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bull //
|
||||
);
|
||||
|
||||
//
|
||||
CopyBear(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bear //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = conditions.bull[cIndex] != 0;
|
||||
|
||||
//
|
||||
bool isBearish = conditions.bear[cIndex] != 0;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XDMNTInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double bullBuffer[];
|
||||
double bearBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000)
|
||||
{
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Bull Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XDMNT_BULL_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
bullBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Bear Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XDMNT_BEAR_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
bearBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,560 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXHTDHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XHTD_BUFFERS
|
||||
{
|
||||
XHTD_MAIN_LINE = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XHTDInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
ENUM_APPLIED_PRICE appliedTo; // Applied To
|
||||
double multiplier; // Multiplier
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool show; // Show
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XHTDInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0;
|
||||
multiplier = 0;
|
||||
|
||||
//
|
||||
appliedTo = PRICE_CLOSE;
|
||||
|
||||
//
|
||||
show = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 14;
|
||||
multiplier = 0.66;
|
||||
|
||||
//
|
||||
appliedTo = PRICE_CLOSE;
|
||||
|
||||
//
|
||||
show = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 2 &&
|
||||
multiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XHTDConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double htd[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(htd);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(htd, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XHTD";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXHTDHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXHTDHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXHTDHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XHTDInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(htdBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xhtd",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length,
|
||||
mInputs.appliedTo,
|
||||
mInputs.multiplier,
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.show
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XHTDInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XHTDInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetHTD(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(htdBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return htdBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyHTD(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
htdBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XHTDConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopyHTD(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.htd //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
result = cBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
cIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
result = pBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
pIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = conditions.htd[cIndex] < cBar.close;
|
||||
bool isBullishPrev = conditions.htd[pIndex] < pBar.close;
|
||||
|
||||
//
|
||||
bool isBearish = conditions.htd[cIndex] > cBar.close;
|
||||
bool isBearishPrev = conditions.htd[pIndex] > pBar.close;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XHTDInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double htdBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000)
|
||||
{
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Longs Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHTD_MAIN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
htdBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,674 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXHULLHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XHULLC_BUFFERS
|
||||
{
|
||||
XHULLC_UP_LINE = 0,
|
||||
XHULLC_DOWN_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XHULLInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
double divisor; // Divisor (Speed)
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to
|
||||
ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showUpZone; // Show Up Zone
|
||||
bool showDownZone; // Show Down Zone
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XHULLInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
length = 0;
|
||||
divisor = 0;
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
upAppliedTo = PRICE_HIGH;
|
||||
downAppliedTo = PRICE_LOW;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showUpZone = false;
|
||||
showDownZone = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
length = 72;
|
||||
divisor = 2.0;
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
upAppliedTo = PRICE_HIGH;
|
||||
downAppliedTo = PRICE_LOW;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showUpZone = true;
|
||||
showDownZone = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 9 &&
|
||||
divisor >= 0.5
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XHULLConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double up[];
|
||||
double down[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isUpBullish;
|
||||
bool isUpBearish;
|
||||
bool isDownBullish;
|
||||
bool isDownBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(up);
|
||||
Clean(down);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(up, true);
|
||||
ArraySetAsSeries(down, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isUpBullish = false;
|
||||
isUpBearish = false;
|
||||
isDownBullish = false;
|
||||
isDownBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isUpBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isDownBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isUpBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isDownBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isUpBullish", isUpBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isUpBearish", isUpBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isDownBullish", isDownBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isDownBearish", isDownBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XHULL";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXHULLHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXHULLHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXHULLHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XHULLInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
// ArraySetAsSeries(mainBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xhull",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length, // Length
|
||||
mInputs.divisor, // Divisor (Speed)
|
||||
//
|
||||
// Calculation ...
|
||||
"",
|
||||
mInputs.upAppliedTo, // Up Zone Applied to
|
||||
mInputs.downAppliedTo, // Down Zone Applied to
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showUpZone, // Show Up Zone
|
||||
mInputs.showDownZone // Show Down Zone
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XHULLInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XHULLInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetUp(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(upBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return upBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyUp(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
upBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetDown(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(downBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return downBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyDown(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
downBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XHULLConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 4 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 4)
|
||||
{
|
||||
loopback = 4;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
CopyUp(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.up //
|
||||
);
|
||||
CopyDown(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.down //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isUpBullish = conditions.up[cIndex] > conditions.up[pIndex];
|
||||
bool isUpBearish = conditions.up[cIndex] < conditions.up[pIndex];
|
||||
|
||||
//
|
||||
bool isUpBullishPrev = conditions.up[pIndex] > conditions.up[ppIndex];
|
||||
bool isUpBearishPrev = conditions.up[pIndex] < conditions.up[ppIndex];
|
||||
|
||||
//
|
||||
bool isDownBullish = conditions.down[cIndex] > conditions.down[pIndex];
|
||||
bool isDownBearish = conditions.down[cIndex] < conditions.down[pIndex];
|
||||
|
||||
//
|
||||
bool isDownBullishPrev = conditions.down[pIndex] > conditions.down[ppIndex];
|
||||
bool isDownBearishPrev = conditions.down[pIndex] < conditions.down[ppIndex];
|
||||
|
||||
//
|
||||
bool isBullish = isUpBullish &&
|
||||
isDownBullish;
|
||||
bool isBearish = isUpBearish &&
|
||||
isDownBearish;
|
||||
|
||||
//
|
||||
bool isBullishPrev = isUpBullishPrev &&
|
||||
isDownBullishPrev;
|
||||
bool isBearishPrev = isUpBearishPrev &&
|
||||
isDownBearishPrev;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isUpBullish = isUpBullish;
|
||||
conditions.isUpBearish = isUpBearish;
|
||||
conditions.isDownBullish = isDownBullish;
|
||||
conditions.isDownBearish = isDownBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XHULLInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double upBuffer[];
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHULLC_UP_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
upBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Down Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XHULLC_DOWN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
downBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,638 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXSLNHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XSLN_STATE
|
||||
{
|
||||
XSLN_STATE_BULLISH = 1,
|
||||
XSLN_STATE_BEARISH = -1,
|
||||
};
|
||||
|
||||
//
|
||||
enum ENUM_XSLN_BUFFERS
|
||||
{
|
||||
XSLN_MAIN_LINE = 0,
|
||||
XSLN_STATE_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XSLNInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool show; // Show
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XSLNInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
show = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
show = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XSLNConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double sln[];
|
||||
double state[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(sln);
|
||||
Clean(state);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(sln, true);
|
||||
ArraySetAsSeries(state, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XSLN";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXSLNHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXSLNHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXSLNHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XSLNInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slnBuffer, true);
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xsln",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.show
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XSLNInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XSLNInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetSLN(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(slnBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return slnBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopySLN(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
slnBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetState(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(stateBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return stateBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyState(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
stateBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_XSLN_STATE ToState(double value)
|
||||
{
|
||||
return (ENUM_XSLN_STATE)value;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBullish(double state)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = state == 1 || state == -1;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_XSLN_STATE eState = ToState(state);
|
||||
result = eState == XSLN_STATE_BULLISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBearish(double state)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = state == 1 || state == -1;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_XSLN_STATE eState = ToState(state);
|
||||
result = eState == XSLN_STATE_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XSLNConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
CopySLN(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.sln //
|
||||
);
|
||||
|
||||
//
|
||||
CopyState(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.state //
|
||||
);
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(conditions.state[cIndex]);
|
||||
bool isBullishPrev = IsBullish(conditions.state[pIndex]);
|
||||
|
||||
//
|
||||
bool isBearish = IsBearish(conditions.state[cIndex]);
|
||||
bool isBearishPrev = IsBearish(conditions.state[pIndex]);
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XSLNInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double slnBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000)
|
||||
{
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Longs Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSLN_MAIN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
slnBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Longs Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSLN_STATE_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
stateBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,631 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXSSLCHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XSSLC_BUFFERS
|
||||
{
|
||||
XSSLC_UP_LINE = 0,
|
||||
XSSLC_DOWN_LINE = 1,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XSSLCInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
ENUM_MA_METHOD method; // Method
|
||||
ENUM_APPLIED_PRICE upAppliedTo; // Up Applied To
|
||||
ENUM_APPLIED_PRICE downAppliedTo; // Down Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showUp; // Show Up
|
||||
bool showDown; // Show Down
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XSSLCInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
length = 0;
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
method = MODE_SMA;
|
||||
upAppliedTo = PRICE_HIGH;
|
||||
downAppliedTo = PRICE_LOW;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showUp = false;
|
||||
showDown = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
length = 36;
|
||||
|
||||
//
|
||||
// Calculation ...
|
||||
method = MODE_SMA;
|
||||
upAppliedTo = PRICE_HIGH;
|
||||
downAppliedTo = PRICE_LOW;
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
showUp = true;
|
||||
showDown = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(0, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XSSLCConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double up[];
|
||||
double down[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(up);
|
||||
Clean(down);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(up, true);
|
||||
ArraySetAsSeries(down, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XSSLC";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXSSLCHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXSSLCHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXSSLCHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XSSLCInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(upBuffer, true);
|
||||
ArraySetAsSeries(downBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xsslc",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.length, // Length
|
||||
//
|
||||
// Calculation ...
|
||||
"",
|
||||
mInputs.method, // Method
|
||||
mInputs.upAppliedTo, // Up Applied To
|
||||
mInputs.downAppliedTo, // Down Applied To
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showUp, // Show Up
|
||||
mInputs.showDown // Show Down
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XSSLCInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XSSLCInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Up ...
|
||||
|
||||
//
|
||||
double GetUp(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(upBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return upBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyUp(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
upBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Down ...
|
||||
|
||||
//
|
||||
double GetDown(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(downBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return downBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyDown(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
downBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XSSLCConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
CopyUp(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.up //
|
||||
);
|
||||
CopyDown(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.down //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = conditions.up[cIndex] > conditions.down[cIndex];
|
||||
bool isBearish = conditions.up[cIndex] < conditions.down[cIndex];
|
||||
|
||||
//
|
||||
bool isBullishPrev = conditions.up[pIndex] > conditions.down[pIndex];
|
||||
bool isBearishPrev = conditions.up[pIndex] < conditions.down[pIndex];
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XSSLCInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double upBuffer[];
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Up ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSSLC_UP_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
upBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XSSLC_DOWN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
downBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,643 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXSTRHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XSTR_BUFFERS
|
||||
{
|
||||
X_STR_TREND_LINE = 0,
|
||||
X_STR_STATE_LINE = 5,
|
||||
};
|
||||
|
||||
//
|
||||
enum ENUM_XSTR_TREND_STATES
|
||||
{
|
||||
X_STR_BULLISH = 1, // Bullish
|
||||
X_STR_BEARISH = -1, // Bearish
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XSTRInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int length; // Length
|
||||
double multiplier; // Multiplier
|
||||
ENUM_APPLIED_PRICE appliedTo; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
bool showTrends; // Show Trends
|
||||
bool fillTrends; // Fill Trends
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XSTRInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0;
|
||||
multiplier = 0;
|
||||
appliedTo = PRICE_CLOSE;
|
||||
//
|
||||
showTrends = false;
|
||||
fillTrends = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 14;
|
||||
multiplier = 3.5;
|
||||
appliedTo = PRICE_MEDIAN;
|
||||
//
|
||||
showTrends = true;
|
||||
fillTrends = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 0 &&
|
||||
multiplier > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XSTRConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double trend[];
|
||||
double state[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isTrendBullish;
|
||||
bool isTrendBearish;
|
||||
bool isTrendSwitchedToBullish;
|
||||
bool isTrendSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(trend);
|
||||
Clean(state);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trend, true);
|
||||
ArraySetAsSeries(state, true);
|
||||
|
||||
//
|
||||
isTrendBullish = false;
|
||||
isTrendBearish = false;
|
||||
isTrendSwitchedToBullish = false;
|
||||
isTrendSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isTrendBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isTrendSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isTrendBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isTrendSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isTrendSwitchedToBullish", isTrendSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isTrendSwitchedToBearish", isTrendSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XSTR";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXSTRHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXSTRHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXSTRHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XSTRInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(trendBuffer, true);
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xstr",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// ATR ...
|
||||
"",
|
||||
mInputs.length, // Length
|
||||
mInputs.multiplier, // Multiplier
|
||||
mInputs.appliedTo, // Applied To
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showTrends, // Show Trends
|
||||
mInputs.fillTrends // Fill Trends
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XSTRInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XSTRInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
|
||||
//
|
||||
double GetTrend(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return trendBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Buffer ...
|
||||
int CopyTrend(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
trendBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// State ...
|
||||
|
||||
//
|
||||
ENUM_XSTR_TREND_STATES GetState(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return (ENUM_XSTR_TREND_STATES)((int)stateBuffer[barIndex]);
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Buffer ...
|
||||
int CopyState(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
stateBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
ENUM_XSTR_TREND_STATES ToState(double state)
|
||||
{
|
||||
return (ENUM_XSTR_TREND_STATES)((int)state);
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBullish(double state)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
ToState(state) == X_STR_BULLISH;
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBearish(double state)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
ToState(state) == X_STR_BEARISH;
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XSTRConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
CopyTrend(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.trend //
|
||||
);
|
||||
CopyState(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.state //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isTrendBullish = IsBullish(conditions.state[cIndex]);
|
||||
bool isTrendBearish = IsBearish(conditions.state[cIndex]);
|
||||
|
||||
//
|
||||
bool isTrendBullishPrev = IsBullish(conditions.state[pIndex]);
|
||||
bool isTrendBearishPrev = IsBearish(conditions.state[pIndex]);
|
||||
|
||||
//
|
||||
bool isTrendSwitchedToBullish = isTrendBullish &&
|
||||
!isTrendBullishPrev;
|
||||
bool isTrendSwitchedToBearish = isTrendBearish &&
|
||||
!isTrendBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isTrendBullish = isTrendBullish;
|
||||
conditions.isTrendBearish = isTrendBearish;
|
||||
conditions.isTrendSwitchedToBullish = isTrendSwitchedToBullish;
|
||||
conditions.isTrendSwitchedToBearish = isTrendSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XSTRInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double trendBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X_STR_TREND_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
trendBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// State ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
X_STR_STATE_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
stateBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,681 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXTDHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XTD_BUFFERS
|
||||
{
|
||||
XTD_BULLISH_LINE = 0,
|
||||
XTD_BEARISH_LINE = 1,
|
||||
XTD_SIGNAL_LINE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XTDInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
//
|
||||
int length; // Market Length
|
||||
bool drawCrosses; // Draw Cross Arrows
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
uchar bullishArrowCode; // Cross Over Arrow Code
|
||||
color bullishArrowColor; // Cross Over Arrow Color
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
uchar bearishArrowCode; // Cross Under Arrow Code
|
||||
color bearishArrowColor; // Cross Under Arrow Color
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XTDInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
length = 0;
|
||||
drawCrosses = false;
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
bullishArrowCode = 228;
|
||||
bullishArrowColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bearishArrowCode = 230;
|
||||
bearishArrowColor = CLR_NONE;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
length = 14;
|
||||
drawCrosses = false;
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
bullishArrowCode = 228;
|
||||
bullishArrowColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
bearishArrowCode = 230;
|
||||
bearishArrowColor = CLR_NONE;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XTDConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double bullish[];
|
||||
double bearish[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish;
|
||||
bool isBearish;
|
||||
bool isSwitchedToBullish;
|
||||
bool isSwitchedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(bullish);
|
||||
Clean(bearish);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullish, true);
|
||||
ArraySetAsSeries(bearish, true);
|
||||
|
||||
//
|
||||
isBullish = false;
|
||||
isBearish = false;
|
||||
isSwitchedToBullish = false;
|
||||
isSwitchedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isSwitchedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isSwitchedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isBullish", isBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isBearish", isBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XTD";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXTDHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXTDHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXTDHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XTDInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullishBuffer, true);
|
||||
ArraySetAsSeries(bearishBuffer, true);
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xtd",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
mInputs.length, // Market Length
|
||||
mInputs.drawCrosses, // Draw Cross Arrows
|
||||
//
|
||||
// Bullish ...
|
||||
mInputs.bullishArrowCode, // Cross Over Arrow Code
|
||||
mInputs.bullishArrowColor, // Cross Over Arrow Color
|
||||
//
|
||||
// Bearish ...
|
||||
mInputs.bearishArrowCode, // Cross Under Arrow Code
|
||||
mInputs.bearishArrowColor // Cross Under Arrow Color
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XTDInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XTDInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetBullish(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(bullishBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return bullishBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyBullish(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
bullishBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetBearish(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(bearishBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return bearishBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyBearish(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
bearishBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetSignal(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(signalBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return signalBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopySignal(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
signalBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XTDConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 3)
|
||||
{
|
||||
loopback = 3;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
CopyBullish(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bullish //
|
||||
);
|
||||
CopyBearish(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.bearish //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isBullish = conditions.bullish[cIndex] > conditions.bearish[cIndex];
|
||||
bool isBearish = conditions.bullish[cIndex] < conditions.bearish[cIndex];
|
||||
|
||||
//
|
||||
bool isBullishPrev = conditions.bullish[pIndex] > conditions.bearish[pIndex];
|
||||
bool isBearishPrev = conditions.bullish[pIndex] < conditions.bearish[pIndex];
|
||||
|
||||
//
|
||||
bool isSwitchedToBullish = isBullish &&
|
||||
!isBullishPrev;
|
||||
bool isSwitchedToBearish = isBearish &&
|
||||
!isBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isBullish = isBullish;
|
||||
conditions.isBearish = isBearish;
|
||||
conditions.isSwitchedToBullish = isSwitchedToBullish;
|
||||
conditions.isSwitchedToBearish = isSwitchedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XTDInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double bullishBuffer[];
|
||||
double bearishBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XTD_BULLISH_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
bullishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XTD_BEARISH_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
bearishBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XTD_SIGNAL_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
signalBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,313 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXTMHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XTM_BUFFERS
|
||||
{
|
||||
XTM_MAIN_LINE = 0
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XTMInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
//
|
||||
// Market ...
|
||||
int maPeriod; // Period
|
||||
int maShift; // Shift
|
||||
ENUM_MA_METHOD maMethod; // Method
|
||||
ENUM_APPLIED_PRICE maAppliedTo; // Applied To
|
||||
//
|
||||
// Presentation ...
|
||||
bool showLine; // Show Line
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XTMInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
maShift = 0;
|
||||
maPeriod = 0;
|
||||
showLine = false;
|
||||
maMethod = MODE_SMA;
|
||||
maAppliedTo = PRICE_CLOSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
maShift = 0;
|
||||
maPeriod = 14;
|
||||
showLine = true;
|
||||
maMethod = MODE_SMA;
|
||||
maAppliedTo = PRICE_CLOSE;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
maPeriod >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, maPeriod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXTMHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXTMHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXTMHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XTMInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mainBuffer, true);
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xtm",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.maPeriod, // Period
|
||||
mInputs.maShift, // Shift
|
||||
mInputs.maMethod, // Method
|
||||
mInputs.maAppliedTo, // Applied To
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showLine // Show Line
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XTMInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XTMInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetMain(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(mainBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return mainBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyMain(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
mainBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XTMInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XTM_MAIN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
mainBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,553 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXVLMHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
enum ENUM_XVLM_BUFFERS
|
||||
{
|
||||
XVLM_VOLUME_LINE = 0
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XVLMInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
int length; // Length
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XVLMInputs()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
length = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
length = 14;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
length > 1
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Define Conditions ...
|
||||
struct XVLMConditions
|
||||
{
|
||||
//
|
||||
// Common ...
|
||||
string symbol;
|
||||
ENUM_TIMEFRAMES period;
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double volume[];
|
||||
|
||||
//
|
||||
// Conditions ...
|
||||
|
||||
//
|
||||
bool isVolumeBullish;
|
||||
bool isVolumeBearish;
|
||||
bool isVolumeOverLast;
|
||||
bool isVolumeUnderLast;
|
||||
bool isVolumeChangedToBullish;
|
||||
bool isVolumeChangedToBearish;
|
||||
|
||||
//
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(volume);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(volume, true);
|
||||
|
||||
//
|
||||
isVolumeBullish = false;
|
||||
isVolumeBearish = false;
|
||||
isVolumeOverLast = false;
|
||||
isVolumeUnderLast = false;
|
||||
isVolumeChangedToBullish = false;
|
||||
isVolumeChangedToBearish = false;
|
||||
}
|
||||
|
||||
//
|
||||
void GenerateScore(
|
||||
double &bullishScore,
|
||||
double &bearishScore //
|
||||
)
|
||||
{
|
||||
//
|
||||
bullishScore = 0;
|
||||
bearishScore = 0;
|
||||
|
||||
//
|
||||
if (isVolumeBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isVolumeOverLast)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
if (isVolumeChangedToBullish)
|
||||
{
|
||||
bullishScore++;
|
||||
}
|
||||
|
||||
//
|
||||
if (isVolumeBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isVolumeUnderLast)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
if (isVolumeChangedToBearish)
|
||||
{
|
||||
bearishScore++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
string GenerateSummary(
|
||||
bool onlyCommons = false,
|
||||
bool onlyConditions = false,
|
||||
bool includeScores = true,
|
||||
bool ignoreFalseConditions = true,
|
||||
string separator = "\n" //
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
double bullishScore = 0;
|
||||
double bearishScore = 0;
|
||||
GenerateScore(
|
||||
bullishScore,
|
||||
bearishScore //
|
||||
);
|
||||
|
||||
//
|
||||
string scoresStr =
|
||||
//
|
||||
"Scores: " + separator +
|
||||
"---------------" + separator +
|
||||
"Bullish: " + ToString(bullishScore) + separator +
|
||||
"Bearish: " + ToString(bearishScore) + separator +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
string commonStr = GenerateSpecifiedCommonSummary(
|
||||
this,
|
||||
separator,
|
||||
includeScores //
|
||||
);
|
||||
|
||||
//
|
||||
string conditionsStr =
|
||||
//
|
||||
ToString("isVolumeBullish", isVolumeBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeBearish", isVolumeBearish, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeOverLast", isVolumeOverLast, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeUnderLast", isVolumeUnderLast, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeChangedToBullish", isVolumeChangedToBullish, ignoreFalseConditions, separator) +
|
||||
ToString("isVolumeChangedToBearish", isVolumeChangedToBearish, ignoreFalseConditions, separator) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
"[" + GetTag() + "]" + separator +
|
||||
(onlyConditions
|
||||
? ""
|
||||
: commonStr) +
|
||||
(!includeScores
|
||||
? ""
|
||||
: scoresStr) +
|
||||
" " + separator +
|
||||
(onlyCommons
|
||||
? ""
|
||||
: conditionsStr) +
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string GetTag()
|
||||
{
|
||||
return "XVLM";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXVLMHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXVLMHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXVLMHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XVLMInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xvlm",
|
||||
//
|
||||
// Inputs ...
|
||||
mInputs.length // Length
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XVLMInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XVLMInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Volume ...
|
||||
|
||||
//
|
||||
double GetVolume(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
return volumeBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Buffer ...
|
||||
int CopyVolume(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
volumeBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
bool IsBullish(double volume)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
volume > 0;
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsBearish(double volume)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
volume < 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool GetConditions(
|
||||
XVLMConditions &conditions, //
|
||||
int barIndex = 0, //
|
||||
int loopback = 4 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
if (loopback < 4)
|
||||
{
|
||||
loopback = 4;
|
||||
}
|
||||
|
||||
//
|
||||
conditions.Clean();
|
||||
|
||||
//
|
||||
conditions.symbol = mSymbol;
|
||||
conditions.period = mPeriod;
|
||||
conditions.time = TimeCurrent();
|
||||
|
||||
//
|
||||
int zIndex = barIndex;
|
||||
int cIndex = zIndex + 1;
|
||||
int pIndex = cIndex + 1;
|
||||
int ppIndex = pIndex + 1;
|
||||
|
||||
//
|
||||
CopyVolume(
|
||||
zIndex,
|
||||
loopback,
|
||||
conditions.volume //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Conditions ...
|
||||
|
||||
//
|
||||
bool isVolumeBullish = conditions.volume[cIndex] > 0;
|
||||
bool isVolumeBullishPrev = conditions.volume[pIndex] > 0;
|
||||
|
||||
//
|
||||
bool isVolumeBearish = conditions.volume[cIndex] < 0;
|
||||
bool isVolumeBearishPrev = conditions.volume[pIndex] < 0;
|
||||
|
||||
//
|
||||
bool isVolumeOverLast = conditions.volume[cIndex] > conditions.volume[pIndex];
|
||||
bool isVolumeOverLastPrev = conditions.volume[pIndex] > conditions.volume[ppIndex];
|
||||
|
||||
//
|
||||
bool isVolumeUnderLast = conditions.volume[cIndex] < conditions.volume[pIndex];
|
||||
bool isVolumeUnderLastPrev = conditions.volume[pIndex] < conditions.volume[ppIndex];
|
||||
|
||||
//
|
||||
bool isVolumeChangedToBullish = isVolumeBullish &&
|
||||
!isVolumeBullishPrev;
|
||||
bool isVolumeChangedToBearish = isVolumeBearish &&
|
||||
!isVolumeBearishPrev;
|
||||
|
||||
//
|
||||
conditions.isVolumeBullish = isVolumeBullish;
|
||||
conditions.isVolumeBearish = isVolumeBearish;
|
||||
conditions.isVolumeOverLast = isVolumeOverLast;
|
||||
conditions.isVolumeUnderLast = isVolumeUnderLast;
|
||||
conditions.isVolumeChangedToBullish = isVolumeChangedToBullish;
|
||||
conditions.isVolumeChangedToBearish = isVolumeChangedToBearish;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XVLMInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Trend ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XVLM_VOLUME_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
volumeBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,530 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Helper Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCXZGHelper
|
||||
// Description: provides all Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.xhelper.class.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// How to Calculate Up and Down Price ...
|
||||
enum ENUM_X_ZG_PRICE_MODE
|
||||
{
|
||||
//
|
||||
X_ZG_PRICE_HIGH_LOW_MODE = 1,
|
||||
X_ZG_PRICE_OPEN_CLOSE_MODE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
enum ENUM_XZG_BUFFERS
|
||||
{
|
||||
//
|
||||
XZG_MAIN_LINE = 0,
|
||||
XZG_PEAKSANDVALES_LINE = 2,
|
||||
XZG_HIGHS_LINE = 4,
|
||||
XZG_LOWS_LINE = 5,
|
||||
};
|
||||
|
||||
//
|
||||
// Input Models ...
|
||||
struct XZGInputs
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
int depth; // Depth
|
||||
int deviation; // Deviation
|
||||
int backStep; // Back Step
|
||||
ENUM_X_ZG_PRICE_MODE mode; // Mode
|
||||
//
|
||||
// Presentation ...
|
||||
bool showZigZag; // Show ZigZag
|
||||
bool showPeaksAndVales; // Show Peaks and Vales
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
XZGInputs()
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Clean ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
depth = 0;
|
||||
deviation = 0;
|
||||
backStep = 0;
|
||||
mode = X_ZG_PRICE_HIGH_LOW_MODE;
|
||||
//
|
||||
// Presentation ...
|
||||
showZigZag = false;
|
||||
showPeaksAndVales = false;
|
||||
}
|
||||
|
||||
//
|
||||
// Default ...
|
||||
void Default()
|
||||
{
|
||||
//
|
||||
// Market ...
|
||||
depth = 12;
|
||||
deviation = 5;
|
||||
backStep = 3;
|
||||
mode = X_ZG_PRICE_HIGH_LOW_MODE;
|
||||
//
|
||||
// Presentation ...
|
||||
showZigZag = true;
|
||||
showPeaksAndVales = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
depth > 0 &&
|
||||
deviation > 0 &&
|
||||
backStep > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve MAx Length ...
|
||||
int Max()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(backStep, depth);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Class ...
|
||||
class XSCXZGHelper : public XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructors ...
|
||||
XSCXZGHelper() : XSCBaseHelper(_Symbol, _Period)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCXZGHelper() {}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Period
|
||||
XZGInputs &inputs // Inputs
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
result = inputs.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mInputs = inputs;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(mainBuffer, true);
|
||||
ArraySetAsSeries(PeaksAndValesBuffer, true);
|
||||
ArraySetAsSeries(highsBuffer, true);
|
||||
ArraySetAsSeries(lowsBuffer, true);
|
||||
|
||||
//
|
||||
mHandler = iCustom(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
"x-saherelm.xzg",
|
||||
//
|
||||
// Inputs ...
|
||||
//
|
||||
// Market ...
|
||||
"",
|
||||
mInputs.depth, // Depth
|
||||
mInputs.deviation, // Deviation
|
||||
mInputs.backStep, // Back Step
|
||||
mInputs.mode, // Mode
|
||||
//
|
||||
// Presentation ...
|
||||
"",
|
||||
mInputs.showZigZag, // Show ZigZag
|
||||
mInputs.showPeaksAndVales // Show Peaks and Vales
|
||||
//
|
||||
);
|
||||
result = mHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
XZGInputs GetInputs()
|
||||
{
|
||||
return mInputs;
|
||||
}
|
||||
|
||||
//
|
||||
bool SetInputs(
|
||||
XZGInputs &inputs // Configs
|
||||
)
|
||||
{
|
||||
//
|
||||
return Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
inputs
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
double GetMain(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(mainBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return mainBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyMain(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
mainBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetPeaksAndVales(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(PeaksAndValesBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return PeaksAndValesBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyPeaksAndVales(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
PeaksAndValesBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetHigh(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(highsBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return highsBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyHigh(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
highsBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double GetLow(
|
||||
int barIndex // Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
Calculate();
|
||||
|
||||
//
|
||||
int count = ArraySize(lowsBuffer);
|
||||
if (barIndex >= count)
|
||||
{
|
||||
barIndex = count - 1;
|
||||
}
|
||||
|
||||
//
|
||||
return lowsBuffer[barIndex];
|
||||
}
|
||||
|
||||
//
|
||||
// Copy Required Items ...
|
||||
int CopyLow(
|
||||
int start, // Start
|
||||
int count, // Number of Items for read
|
||||
double &buffer[], // Dest Buffer
|
||||
bool forceClean = true // Force To Clean buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
// Update Calculations ...
|
||||
Calculate();
|
||||
|
||||
//
|
||||
// Copy Items ...
|
||||
return Copy(
|
||||
start,
|
||||
count,
|
||||
lowsBuffer,
|
||||
buffer,
|
||||
forceClean
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
XZGInputs mInputs; // Inputs ...
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
double mainBuffer[];
|
||||
double PeaksAndValesBuffer[];
|
||||
double highsBuffer[];
|
||||
double lowsBuffer[];
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Calculate Values Until Now ...
|
||||
void Calculate()
|
||||
{
|
||||
//
|
||||
int totalBars = CountBars();
|
||||
if (totalBars > 1000) {
|
||||
totalBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XZG_MAIN_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
mainBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Peaks and Vales Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XZG_PEAKSANDVALES_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
PeaksAndValesBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Highs Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XZG_HIGHS_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
highsBuffer
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Lows Buffer ...
|
||||
CopyBuffer(
|
||||
mHandler,
|
||||
XZG_LOWS_LINE,
|
||||
0,
|
||||
totalBars,
|
||||
lowsBuffer
|
||||
//
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
@@ -0,0 +1,223 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XADXTD
|
||||
// Description: ADX TD Channel ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XADXTD Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XADXTD"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
input int length = 21; // Length
|
||||
|
||||
//
|
||||
// BUFFERS ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
#define strengthBufferIndex 0
|
||||
double strengthBuffer[];
|
||||
|
||||
//
|
||||
#define bullpBufferIndex 1
|
||||
double bullpBuffer[];
|
||||
|
||||
//
|
||||
#define bearpBufferIndex 2
|
||||
double bearpBuffer[];
|
||||
|
||||
//
|
||||
int maxLength = 0;
|
||||
int mHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
mHandler = iADX(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length //
|
||||
);
|
||||
if (mHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int adxCalculatedBars = BarsCalculated(mHandler);
|
||||
if (adxCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedADXStrength = CopyBuffer(mHandler, MAIN_LINE, 0, limit, strengthBuffer);
|
||||
int copiedADXBullp = CopyBuffer(mHandler, PLUSDI_LINE, 0, limit, bullpBuffer);
|
||||
int copiedADXBearP = CopyBuffer(mHandler, MINUSDI_LINE, 0, limit, bearpBuffer);
|
||||
if (copiedADXBullp <= 0 ||
|
||||
copiedADXBearP <= 0 ||
|
||||
copiedADXStrength <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(length > 0)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(strengthBuffer, true);
|
||||
SetIndexBuffer(strengthBufferIndex, strengthBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullpBuffer, true);
|
||||
SetIndexBuffer(bullpBufferIndex, bullpBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bearpBuffer, true);
|
||||
SetIndexBuffer(bearpBufferIndex, bearpBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XAMA Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XAMA
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Constants ...
|
||||
|
||||
#define ShortName "XAMA"
|
||||
|
||||
//
|
||||
// Indicator States ...
|
||||
enum ENUM_X_XAMA_STATES
|
||||
{
|
||||
X_XAMA_BULLISH = 1,
|
||||
X_XAMA_BEARISH = -1,
|
||||
X_XAMA_NEUTURAL = 0,
|
||||
};
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
input int length = 18; // Period
|
||||
input int fastEMA = 2; // Fast EMA Period
|
||||
input int slowEMA = 30; // Slow EMA Period
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showLine = true; // Show Line
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
#define stateBufferIndex 2
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
#property indicator_label1 "XAMA"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed, CLR_NONE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iAMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
fastEMA,
|
||||
slowEMA,
|
||||
maShift,
|
||||
appliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(maHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(fastEMA, slowEMA);
|
||||
maxLength = MathMax(maxLength, length);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", length, ")");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle;
|
||||
candle.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Define State Value ...
|
||||
// lineColorIndex == 0 => Bullish => 1;
|
||||
// lineColorIndex == 1 => Neutural => 0;
|
||||
// lineColorIndex == 2 => Bearish => -1;
|
||||
double stateValue =
|
||||
lineColorIndex == 0 ? X_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
|
||||
: X_XAMA_NEUTURAL;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = showLine ? lineColorIndex : 3;
|
||||
|
||||
//
|
||||
// Set State Buffer Value ...
|
||||
stateBuffer[bar_index] = stateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,442 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XASCT
|
||||
// Description: XASCTrend Detector ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XASCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XASCT"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int risk = 4; // Risk
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLongs = true; // Show Long Arrows
|
||||
input bool showShorts = true; // Show Short Arrows
|
||||
input uchar longArrowCode = 233; // Long Arrow
|
||||
input uchar shortArrowCode = 234; // Short Arrow
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define longBufferIndex 0
|
||||
double longBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XASCT Long"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 3
|
||||
|
||||
//
|
||||
#define shortBufferIndex 1
|
||||
double shortBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XASCT Short"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 3
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
int maxLength = 0;
|
||||
int wPRHandlers[3];
|
||||
int x1, x2 = 0;
|
||||
int value10, value11 = 0;
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
x1 = 67 + risk;
|
||||
x2 = 33 - risk;
|
||||
value10 = 2;
|
||||
value11 = value10;
|
||||
|
||||
//
|
||||
wPRHandlers[0] = iWPR(_Symbol, _Period, 3);
|
||||
if (wPRHandlers[0] == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
wPRHandlers[1] = iWPR(_Symbol, _Period, 4);
|
||||
if (wPRHandlers[1] == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
wPRHandlers[2] = iWPR(_Symbol, _Period, 3 + risk * 2);
|
||||
if (wPRHandlers[2] == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
BarsCalculated(wPRHandlers[0]) == rates_total &&
|
||||
BarsCalculated(wPRHandlers[1]) == rates_total &&
|
||||
BarsCalculated(wPRHandlers[2]) == rates_total
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Declare Some Local Variables for Use ...
|
||||
int limit, bar, count, iii;
|
||||
double value2, value3, vel = 0, wprs[];
|
||||
double trueCount, range, avgRange, mrO1, mrO2;
|
||||
|
||||
//
|
||||
// checking for the first start of the indicator calculation ...
|
||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
{
|
||||
limit = rates_total - maxLength;
|
||||
}
|
||||
//
|
||||
// starting index for calculation of all bars
|
||||
else
|
||||
{
|
||||
limit = rates_total - prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
ArraySetAsSeries(wprs, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (bar = limit; bar >= 0 && !IsStopped(); bar--)
|
||||
{
|
||||
//
|
||||
range = 0.0;
|
||||
avgRange = 0.0;
|
||||
for (count = bar; count <= bar + 9; count++)
|
||||
{
|
||||
avgRange = avgRange + MathAbs(high[count] - low[count]);
|
||||
}
|
||||
|
||||
//
|
||||
count = bar;
|
||||
trueCount = 0;
|
||||
range = avgRange / 10;
|
||||
|
||||
//
|
||||
while (count < bar + 9 && trueCount < 1)
|
||||
{
|
||||
//
|
||||
if (MathAbs(open[count] - close[count + 1]) >= range * 2.0)
|
||||
{
|
||||
trueCount++;
|
||||
}
|
||||
|
||||
//
|
||||
count++;
|
||||
}
|
||||
|
||||
//
|
||||
if (trueCount >= 1)
|
||||
{
|
||||
mrO1 = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
mrO1 = -1;
|
||||
}
|
||||
|
||||
//
|
||||
count = bar;
|
||||
trueCount = 0;
|
||||
|
||||
//
|
||||
while (count < bar + 6 && trueCount < 1)
|
||||
{
|
||||
//
|
||||
if (MathAbs(close[count + 3] - close[count]) >= range * 4.6)
|
||||
{
|
||||
trueCount++;
|
||||
}
|
||||
|
||||
//
|
||||
count++;
|
||||
}
|
||||
|
||||
//
|
||||
if (trueCount >= 1)
|
||||
{
|
||||
mrO2 = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
mrO2 = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (mrO1 > -1)
|
||||
{
|
||||
value11 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
value11 = value10;
|
||||
}
|
||||
if (mrO2 > -1)
|
||||
{
|
||||
value11 = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
value11 = value10;
|
||||
}
|
||||
|
||||
//
|
||||
if (CopyBuffer(wPRHandlers[value11], 0, bar, 1, wprs) <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
value2 = 100 - MathAbs(wprs[0]);
|
||||
|
||||
//
|
||||
longBuffer[bar] = 0;
|
||||
shortBuffer[bar] = 0;
|
||||
|
||||
//
|
||||
value3 = 0;
|
||||
|
||||
//
|
||||
if (value2 < x2)
|
||||
{
|
||||
//
|
||||
iii = 1;
|
||||
while (bar + iii < rates_total)
|
||||
{
|
||||
//
|
||||
if (CopyBuffer(wPRHandlers[value11], 0, bar + iii, 1, wprs) <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
vel = 100 - MathAbs(wprs[0]);
|
||||
if (vel >= x2 && vel <= x1)
|
||||
{
|
||||
iii++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (vel > x1)
|
||||
{
|
||||
value3 = high[bar] + range * 0.5;
|
||||
shortBuffer[bar] = value3;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (value2 > x1)
|
||||
{
|
||||
//
|
||||
iii = 1;
|
||||
while (bar + iii < rates_total)
|
||||
{
|
||||
//
|
||||
if (CopyBuffer(wPRHandlers[value11], 0, bar + iii, 1, wprs) <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
vel = 100 - MathAbs(wprs[0]);
|
||||
if (vel >= x2 && vel <= x1)
|
||||
{
|
||||
iii++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (vel < x2)
|
||||
{
|
||||
value3 = low[bar] - range * 0.5;
|
||||
longBuffer[bar] = value3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
risk >= 1;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = int(MathMax(3 + risk * 2, 4) + 1);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Longs Buffer ...
|
||||
ENUM_DRAW_TYPE longsDrawType = showLongs ? DRAW_ARROW : DRAW_NONE;
|
||||
ArraySetAsSeries(longBuffer, true);
|
||||
SetIndexBuffer(longBufferIndex, longBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(longBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(longBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(longBufferIndex, PLOT_SHOW_DATA, showLongs);
|
||||
PlotIndexSetInteger(longBufferIndex, PLOT_DRAW_TYPE, longsDrawType);
|
||||
PlotIndexSetInteger(longBufferIndex, PLOT_ARROW, longArrowCode);
|
||||
|
||||
//
|
||||
// Short Buffer ...
|
||||
ENUM_DRAW_TYPE shortsDrawType = showShorts ? DRAW_ARROW : DRAW_NONE;
|
||||
ArraySetAsSeries(shortBuffer, true);
|
||||
SetIndexBuffer(shortBufferIndex, shortBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(shortBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(shortBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(shortBufferIndex, PLOT_SHOW_DATA, showShorts);
|
||||
PlotIndexSetInteger(shortBufferIndex, PLOT_DRAW_TYPE, shortsDrawType);
|
||||
PlotIndexSetInteger(shortBufferIndex, PLOT_ARROW, shortArrowCode);
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XATSL
|
||||
// Description: ATR SL ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XATSL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XATSL"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 14; // Length
|
||||
input double coeff = 2.0; // Coefficient
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool show = true; // Show
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define mainBufferIndex 0
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainBufferColorIndex 1
|
||||
double mainBufferColor[];
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullColorIDX 1
|
||||
#define bearColorIDX 2
|
||||
|
||||
//
|
||||
#property indicator_label1 "XATSL"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define hlBufferIndex 2
|
||||
double hlBuffer[];
|
||||
|
||||
//
|
||||
#define wmaBufferIndex 3
|
||||
double wmaBuffer[];
|
||||
|
||||
//
|
||||
#define tmpBufferIndex 4
|
||||
double tmpBuffer[];
|
||||
|
||||
//
|
||||
#define diffBufferIndex 5
|
||||
double diffBuffer[];
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
int maPeriod;
|
||||
double k;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
maPeriod = int(length < 1 ? 1 : length);
|
||||
double n1 = 2.0 * double(maPeriod - 1);
|
||||
k = 2.0 / (n1 + 1);
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
|
||||
//
|
||||
if (rates_total < maPeriod)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit = rates_total - prev_calculated;
|
||||
if (limit > 1)
|
||||
{
|
||||
//
|
||||
limit = rates_total - 2;
|
||||
|
||||
//
|
||||
ArrayInitialize(mainBuffer, EMPTY_VALUE);
|
||||
ArrayInitialize(hlBuffer, 0);
|
||||
ArrayInitialize(diffBuffer, 0);
|
||||
ArrayInitialize(wmaBuffer, 0);
|
||||
ArrayInitialize(tmpBuffer, 0);
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
hlBuffer[i] = high[i] - low[i];
|
||||
|
||||
//
|
||||
double href = 0;
|
||||
double lref = 0;
|
||||
|
||||
//
|
||||
double sma = MAOnArray(hlBuffer, 0, maPeriod, 0, MODE_SMA, i);
|
||||
double hiLo = fmin(hlBuffer[i], sma);
|
||||
|
||||
//
|
||||
href = (low[i] <= high[i + 1] ? high[i] - close[i + 1] : (hlBuffer[i] - close[i + 1] + high[i + 1]) / 2);
|
||||
lref = (high[i] >= low[i + 1] ? close[i + 1] - low[i] : (close[i + 1] - low[i + 1] + hlBuffer[i]) / 2);
|
||||
|
||||
//
|
||||
diffBuffer[i] = fmax(hiLo, fmax(href, lref));
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
if (i == rates_total - 2)
|
||||
{
|
||||
wmaBuffer[i] = MAOnArray(diffBuffer, 0, maPeriod, 0, MODE_EMA, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
wmaBuffer[i] = (diffBuffer[i] - wmaBuffer[i + 1]) * k + wmaBuffer[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
double loss = wmaBuffer[i] * coeff;
|
||||
if (close[i] > tmpBuffer[i + 1] && close[i + 1] > tmpBuffer[i + 1])
|
||||
{
|
||||
//
|
||||
tmpBuffer[i] = fmax(tmpBuffer[i + 1], close[i] - loss);
|
||||
|
||||
//
|
||||
mainBuffer[i] = tmpBuffer[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (close[i] < tmpBuffer[i + 1] && close[i + 1] < tmpBuffer[i + 1])
|
||||
{
|
||||
//
|
||||
tmpBuffer[i] = fmin(tmpBuffer[i + 1], close[i] + loss);
|
||||
|
||||
//
|
||||
mainBuffer[i] = tmpBuffer[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
if (close[i] > tmpBuffer[i + 1])
|
||||
{
|
||||
//
|
||||
tmpBuffer[i] = close[i] - loss;
|
||||
|
||||
//
|
||||
mainBuffer[i] = tmpBuffer[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
tmpBuffer[i] = close[i] + loss;
|
||||
|
||||
//
|
||||
mainBuffer[i] = tmpBuffer[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Define Color Buffer ...
|
||||
double clrValue = !show
|
||||
? hideColorIDX
|
||||
: mainBuffer[i] > close[i]
|
||||
? bearColorIDX
|
||||
: bullColorIDX;
|
||||
mainBufferColor[i] = clrValue;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = length >= 2 &&
|
||||
coeff > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(mainBuffer, true);
|
||||
ArraySetAsSeries(mainBufferColor, true);
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(hlBuffer, true);
|
||||
SetIndexBuffer(hlBufferIndex, hlBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(wmaBuffer, true);
|
||||
SetIndexBuffer(wmaBufferIndex, wmaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(tmpBuffer, true);
|
||||
SetIndexBuffer(tmpBufferIndex, tmpBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(diffBuffer, true);
|
||||
SetIndexBuffer(diffBufferIndex, diffBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,458 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Styles
|
||||
// ---------------------------------------------------
|
||||
// Name: XCC
|
||||
// Description: Candle Styles ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XCC"
|
||||
|
||||
//
|
||||
// Holds an SnapShot of Charts Configuration ...
|
||||
struct XChartStyle
|
||||
{
|
||||
//
|
||||
// chart's ID ...
|
||||
long chartId;
|
||||
//
|
||||
// chart's mode ...
|
||||
ENUM_CHART_MODE mode;
|
||||
//
|
||||
// show bid line ...
|
||||
bool showBidLine;
|
||||
//
|
||||
// show ask line ...
|
||||
bool showAskLine;
|
||||
//
|
||||
// show grids on chart ...
|
||||
bool showGrid;
|
||||
//
|
||||
// show volumes ...
|
||||
bool showVolumes;
|
||||
//
|
||||
// Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ...
|
||||
bool showTradeLevels;
|
||||
//
|
||||
// chart autoscroll ...
|
||||
bool autoScroll;
|
||||
//
|
||||
// chart quick navigation state ...
|
||||
bool quickNavigation;
|
||||
//
|
||||
// chart's foreground color ...
|
||||
color foreGroundColor;
|
||||
//
|
||||
// chart's background color ...
|
||||
color backGroundColor;
|
||||
//
|
||||
// Up Color ...
|
||||
color upColor;
|
||||
//
|
||||
// Down Color ...
|
||||
color downColor;
|
||||
//
|
||||
// Bullish color ...
|
||||
color bullishColor;
|
||||
//
|
||||
// Bearish color ...
|
||||
color bearishColor;
|
||||
//
|
||||
// grid color ...
|
||||
color gridColor;
|
||||
//
|
||||
// bid line color ...
|
||||
color bidLineColor;
|
||||
//
|
||||
// ask line color ...
|
||||
color askLineColor;
|
||||
//
|
||||
// line mode and doji candlestick color ...
|
||||
color lineColor;
|
||||
//
|
||||
// Color of stop order levels (Stop Loss and Take Profit) ...
|
||||
color stopColor;
|
||||
//
|
||||
// volumes color ...
|
||||
color volumesColor;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Chart Style";
|
||||
input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode
|
||||
input color upColor = clrLime; // Up Color
|
||||
input color downColor = clrRed; // Down Color
|
||||
input color lineColor = clrLime; // Line mode and Doji candlestick Color
|
||||
input color bearishColor = clrRed; // Bullish Color
|
||||
input color bullishColor = clrLime; // Bearish Color
|
||||
input color volumesColor = clrGreen; // Volumes Color
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandles = true; // Show Candles
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XChartStyle chartStyle;
|
||||
XChartStyle clearStyle;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Apply Chart Style ...
|
||||
ApplyCustomChartStyle();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[]
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Custom Chart Style ...
|
||||
void ApplyCustomChartStyle()
|
||||
{
|
||||
//
|
||||
// Read Current Chart Config and Store it ...
|
||||
ReadChartStyle();
|
||||
|
||||
//
|
||||
// After Reading Current Chart Style ...
|
||||
// we have to Save Configs and Change Styles ...
|
||||
clearStyle = chartStyle;
|
||||
|
||||
//
|
||||
clearStyle.upColor = CLR_NONE;
|
||||
clearStyle.downColor = CLR_NONE;
|
||||
clearStyle.lineColor = CLR_NONE;
|
||||
clearStyle.bullishColor = CLR_NONE;
|
||||
clearStyle.bearishColor = CLR_NONE;
|
||||
|
||||
//
|
||||
// Decide to Show or not Candles based on User Input ...
|
||||
if (showCandles)
|
||||
{
|
||||
SetChartStyle(chartStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetChartStyle(clearStyle);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Read Previous Chart Style ...
|
||||
void ReadChartStyle()
|
||||
{
|
||||
//
|
||||
// Retrieve Current Chart ID ...
|
||||
long chartId = ChartID();
|
||||
chartStyle.chartId = chartId;
|
||||
|
||||
//
|
||||
// Retrieve Chart Mode ...
|
||||
chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE);
|
||||
|
||||
//
|
||||
chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE);
|
||||
chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE);
|
||||
chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID);
|
||||
chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES);
|
||||
chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS);
|
||||
chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL);
|
||||
chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION);
|
||||
|
||||
//
|
||||
chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND);
|
||||
chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND);
|
||||
chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP);
|
||||
chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN);
|
||||
chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL);
|
||||
chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR);
|
||||
chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID);
|
||||
chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID);
|
||||
chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK);
|
||||
chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL);
|
||||
chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE);
|
||||
chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME);
|
||||
|
||||
//
|
||||
chartStyle.mode = mode;
|
||||
chartStyle.upColor = upColor;
|
||||
chartStyle.downColor = downColor;
|
||||
chartStyle.lineColor = lineColor;
|
||||
chartStyle.bearishColor = bearishColor;
|
||||
chartStyle.bullishColor = bullishColor;
|
||||
chartStyle.volumesColor = volumesColor;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Chart Style ...
|
||||
void SetChartStyle(
|
||||
XChartStyle &mChartStyle // Chart Style to Apply
|
||||
)
|
||||
{
|
||||
//
|
||||
ApplyChartStyle(
|
||||
mChartStyle.chartId,
|
||||
mChartStyle.mode,
|
||||
mChartStyle.showBidLine,
|
||||
mChartStyle.showAskLine,
|
||||
mChartStyle.showGrid,
|
||||
mChartStyle.showVolumes,
|
||||
mChartStyle.showTradeLevels,
|
||||
mChartStyle.autoScroll,
|
||||
mChartStyle.quickNavigation,
|
||||
mChartStyle.foreGroundColor,
|
||||
mChartStyle.backGroundColor,
|
||||
mChartStyle.upColor,
|
||||
mChartStyle.downColor,
|
||||
mChartStyle.bullishColor,
|
||||
mChartStyle.bearishColor,
|
||||
mChartStyle.gridColor,
|
||||
mChartStyle.bidLineColor,
|
||||
mChartStyle.askLineColor,
|
||||
mChartStyle.lineColor,
|
||||
mChartStyle.stopColor,
|
||||
mChartStyle.volumesColor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,631 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XCHE
|
||||
// Description: Chandelier Exit Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCHE Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "XCHE"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 35; // Length
|
||||
input int loopback = 26; // Loopback
|
||||
input double multiplier1 = 3.0; // 1st Multiplier
|
||||
input double multiplier2 = 3.5; // 2nd Multiplier
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLongExit1Line = true; // Show 1st Long Exit
|
||||
input bool showShortExit1Line = true; // Show 1st Short Exit
|
||||
input bool showLongExit2Line = true; // Show 2st Long Exit
|
||||
input bool showShortExit2Line = true; // Show 2st Short Exit
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
#define longExit1BufferIndex 0
|
||||
double longExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XCHE LE 1"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
#define shortExit1BufferIndex 1
|
||||
double shortExit1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XCHE SE 1"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color2 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
#define longExit2BufferIndex 2
|
||||
double longExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XCHE LE 2"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color3 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
#define shortExit2BufferIndex 3
|
||||
double shortExit2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XCHE SE 2"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_color4 clrMagenta
|
||||
|
||||
//
|
||||
// START Arrows ...
|
||||
|
||||
//
|
||||
// Long Exit 1 Start ...
|
||||
#define longExit1StartBufferIndex 4
|
||||
double longExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XCHE LES 1"
|
||||
#property indicator_type5 DRAW_ARROW
|
||||
#property indicator_color5 clrLime
|
||||
|
||||
//
|
||||
// Short Exit 1 Start ...
|
||||
#define shortExit1StartBufferIndex 5
|
||||
double shortExit1StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XCHE SES 1"
|
||||
#property indicator_type6 DRAW_ARROW
|
||||
#property indicator_color6 clrRed
|
||||
|
||||
//
|
||||
// Long Exit 2 Start ...
|
||||
#define longExit2StartBufferIndex 6
|
||||
double longExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XCHE LES 2"
|
||||
#property indicator_type7 DRAW_ARROW
|
||||
#property indicator_color7 clrAqua
|
||||
|
||||
//
|
||||
// Short Exit 2 Start ...
|
||||
#define shortExit2StartBufferIndex 7
|
||||
double shortExit2StartBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "XCHE SES 2"
|
||||
#property indicator_type8 DRAW_ARROW
|
||||
#property indicator_color8 clrMagenta
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// Working Array ...
|
||||
double work[][6];
|
||||
#define hi1Idx 0
|
||||
#define lo1Idx 1
|
||||
#define hi2Idx 2
|
||||
#define lo2Idx 3
|
||||
#define trend1Idx 4
|
||||
#define trend2Idx 5
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
if (Bars(_Symbol, _Period) < rates_total)
|
||||
{
|
||||
return (prev_calculated);
|
||||
}
|
||||
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
ArrayResize(work, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
loopback >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(length, loopback);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
uint arrowCode = 159;
|
||||
|
||||
//
|
||||
// LEVEL 1 ...
|
||||
|
||||
//
|
||||
// Long Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
|
||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 1 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
|
||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
|
||||
|
||||
//
|
||||
// LEVEL 2 ...
|
||||
|
||||
//
|
||||
// Long Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
|
||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
|
||||
|
||||
//
|
||||
// Short Exit 2 ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
|
||||
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
|
||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
|
||||
|
||||
//
|
||||
// Start Buffer ...
|
||||
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int prevCalculated, // Previous Calculated
|
||||
int ratesTotal, // Total Rates
|
||||
const double &open[], // Rates Open ...
|
||||
const double &high[], // Rates High ...
|
||||
const double &low[], // Rates Low ...
|
||||
const double &close[] // Rates Close ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Cleanup Buffers ...
|
||||
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
int start = MathMax(bar_index - loopback, 0);
|
||||
|
||||
//
|
||||
// Calculate ATR Value ...
|
||||
double atrValue = 0;
|
||||
for (int k = 1; k <= length && (bar_index - k - 1) >= 0; k++)
|
||||
{
|
||||
//
|
||||
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
|
||||
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
|
||||
}
|
||||
atrValue /= (double)length;
|
||||
|
||||
//
|
||||
// Retrieve Highest High and Lowest Lows ...
|
||||
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
|
||||
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
|
||||
|
||||
//
|
||||
// Fill Multi Dimesional Working Array ...
|
||||
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
|
||||
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
|
||||
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
|
||||
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue;
|
||||
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
|
||||
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
|
||||
|
||||
//
|
||||
if (bar_index > 0)
|
||||
{
|
||||
//
|
||||
// Calculate Trends ...
|
||||
if (close[bar_index] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][trend1Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[bar_index] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][trend2Idx] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Exit Values ...
|
||||
|
||||
//
|
||||
// Exit 1 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
|
||||
{
|
||||
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
|
||||
|
||||
//
|
||||
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
|
||||
{
|
||||
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
|
||||
|
||||
//
|
||||
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Exit 2 ...
|
||||
|
||||
//
|
||||
// Long ...
|
||||
if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1)
|
||||
{
|
||||
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
|
||||
{
|
||||
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
|
||||
|
||||
//
|
||||
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Short ...
|
||||
if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1)
|
||||
{
|
||||
//
|
||||
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
|
||||
{
|
||||
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
|
||||
}
|
||||
|
||||
//
|
||||
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
|
||||
|
||||
//
|
||||
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
||||
{
|
||||
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,261 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XCT
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XCT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "XCT"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input color clr = clrYellow; // Text Color
|
||||
input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showCandleTime = true; // Show Candle Time
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (showCandleTime)
|
||||
{
|
||||
CreateIndicatorObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjectDelete(0, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
ulong chID = FindChartID(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Delete Object ...
|
||||
ObjectDelete(chID, ShortName);
|
||||
|
||||
//
|
||||
Comment("");
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(time, true);
|
||||
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
ulong chID = FindChartID(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
XBarRemainsTime barRemains;
|
||||
barRemains.Init(
|
||||
_Symbol,
|
||||
_Period
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
string msg = barRemains
|
||||
.ToString(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
":",
|
||||
true
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD);
|
||||
|
||||
//
|
||||
string _sp = "";
|
||||
if (mSpread < 10)
|
||||
_sp = "..";
|
||||
else if (mSpread < 100)
|
||||
_sp = ".";
|
||||
|
||||
//
|
||||
string objText = "Spread: " + IntegerToString(mSpread) + _sp + " Next Bar in: " + msg;
|
||||
|
||||
//
|
||||
ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr);
|
||||
ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText);
|
||||
ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10);
|
||||
ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier");
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
void CreateIndicatorObject()
|
||||
{
|
||||
//
|
||||
if (!showCandleTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10);
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2);
|
||||
|
||||
//
|
||||
ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER;
|
||||
switch (corner)
|
||||
{
|
||||
case CORNER_LEFT_UPPER:
|
||||
Anchor = ANCHOR_LEFT_UPPER;
|
||||
break;
|
||||
case CORNER_RIGHT_UPPER:
|
||||
Anchor = ANCHOR_RIGHT_UPPER;
|
||||
break;
|
||||
case CORNER_LEFT_LOWER:
|
||||
Anchor = ANCHOR_LEFT_LOWER;
|
||||
break;
|
||||
case CORNER_RIGHT_LOWER:
|
||||
Anchor = ANCHOR_RIGHT_LOWER;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,222 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XDMNT
|
||||
// Description: Dominant ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XDMNT Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XDMNT"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showBull = true; // Show Bull
|
||||
input bool showBear = true; // Show Bear
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define bullBufferIndex 0
|
||||
double bullBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XDMNT Bull"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrAqua
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
#define bearBufferIndex 1
|
||||
double bearBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XDMNT Bear"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(time, true);
|
||||
|
||||
//
|
||||
for (int i = 1; i < rates_total - 2; i++)
|
||||
{
|
||||
//
|
||||
// Bullish ...
|
||||
if (open[i] < close[i] && open[i + 1] < close[i + 1] && open[i] >= close[i + 1] && low[i] < close[i + 1] && high[i + 1] > open[i])
|
||||
{
|
||||
//
|
||||
bullBuffer[i] = low[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
bullBuffer[i] = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
if (open[i] > close[i] && open[i + 1] > close[i + 1] && open[i] <= close[i + 1] && high[i] > close[i + 1] && low[i + 1] < open[i])
|
||||
{
|
||||
//
|
||||
bearBuffer[i] = high[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
bearBuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Bull ...
|
||||
ENUM_DRAW_TYPE bullDrawType = showBull ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bullBuffer, true);
|
||||
PlotIndexSetInteger(bullBufferIndex, PLOT_ARROW, 225);
|
||||
PlotIndexSetDouble(bullBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
SetIndexBuffer(bullBufferIndex, bullBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(bullBufferIndex, PLOT_SHOW_DATA, showBull);
|
||||
PlotIndexSetInteger(bullBufferIndex, PLOT_DRAW_TYPE, bullDrawType);
|
||||
|
||||
//
|
||||
// Bear ...
|
||||
ENUM_DRAW_TYPE bearDrawType = showBear ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(bearBuffer, true);
|
||||
PlotIndexSetInteger(bearBufferIndex, PLOT_ARROW, 225);
|
||||
PlotIndexSetDouble(bearBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
SetIndexBuffer(bearBufferIndex, bearBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(bearBufferIndex, PLOT_SHOW_DATA, showBull);
|
||||
PlotIndexSetInteger(bearBufferIndex, PLOT_DRAW_TYPE, bearDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,366 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XDON
|
||||
// Description: DONCHAIN Channel ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XDON Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XDON"
|
||||
|
||||
//
|
||||
// INPUT ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 52; // Market Length
|
||||
input double offset = 0; // Offset
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showOpen = true; // Show Open
|
||||
input bool showHigh = true; // Show High
|
||||
input bool showClose = true; // Show Close
|
||||
input bool showLow = true; // Show Low
|
||||
|
||||
//
|
||||
// BUFFERS ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 8
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
#define upperOBufferIndex 0
|
||||
double upperOBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XDON OU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrCornflowerBlue
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
#define lowerOBufferIndex 1
|
||||
double lowerOBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XDON OL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrCornflowerBlue
|
||||
#property indicator_width2 2
|
||||
|
||||
//
|
||||
#define upperCBufferIndex 2
|
||||
double upperCBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XDON CU"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrCoral
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
#define lowerCBufferIndex 3
|
||||
double lowerCBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XDON CL"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrCoral
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
#define upperHBufferIndex 4
|
||||
double upperHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XDON HU"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrAquamarine
|
||||
#property indicator_width5 2
|
||||
|
||||
//
|
||||
#define lowerHBufferIndex 5
|
||||
double lowerHBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XDON HL"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAquamarine
|
||||
#property indicator_width6 2
|
||||
|
||||
//
|
||||
#define upperLBufferIndex 6
|
||||
double upperLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XDON LU"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrDarkOrchid
|
||||
#property indicator_width7 2
|
||||
|
||||
//
|
||||
#define lowerLBufferIndex 7
|
||||
double lowerLBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "XDON LL"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrDarkOrchid
|
||||
#property indicator_width8 2
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (rates_total < length - 1)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
int start = prev_calculated == 0
|
||||
? length
|
||||
: prev_calculated - 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int barIndex = start; barIndex < rates_total; barIndex++)
|
||||
{
|
||||
//
|
||||
// OPEN ...
|
||||
|
||||
//
|
||||
double upperOValue = open[ArrayMaximum(open, barIndex - length + 1, length)];
|
||||
double lowerOValue = open[ArrayMinimum(open, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double oDelta = MathAbs(upperOValue - lowerOValue);
|
||||
double oOffsetValue = oDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperOBuffer[barIndex] = upperOValue - oOffsetValue;
|
||||
lowerOBuffer[barIndex] = lowerOValue + oOffsetValue;
|
||||
|
||||
//
|
||||
// CLOSE ...
|
||||
|
||||
//
|
||||
double upperCValue = close[ArrayMaximum(close, barIndex - length + 1, length)];
|
||||
double lowerCValue = close[ArrayMinimum(close, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double cDelta = MathAbs(upperCValue - lowerCValue);
|
||||
double cOffsetValue = cDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperCBuffer[barIndex] = upperCValue - cOffsetValue;
|
||||
lowerCBuffer[barIndex] = lowerCValue + cOffsetValue;
|
||||
|
||||
//
|
||||
// HIGH ...
|
||||
|
||||
//
|
||||
double upperHValue = high[ArrayMaximum(high, barIndex - length + 1, length)];
|
||||
double lowerHValue = high[ArrayMinimum(high, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double hDelta = MathAbs(upperHValue - lowerHValue);
|
||||
double hOffsetValue = hDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperHBuffer[barIndex] = upperHValue - hOffsetValue;
|
||||
lowerHBuffer[barIndex] = lowerHValue + hOffsetValue;
|
||||
|
||||
//
|
||||
// LOW ...
|
||||
|
||||
//
|
||||
double upperLValue = low[ArrayMaximum(low, barIndex - length + 1, length)];
|
||||
double lowerLValue = low[ArrayMinimum(low, barIndex - length + 1, length)];
|
||||
|
||||
//
|
||||
double lDelta = MathAbs(upperLValue - lowerLValue);
|
||||
double lOffsetValue = lDelta * (offset) * 0.01;
|
||||
|
||||
//
|
||||
upperLBuffer[barIndex] = upperLValue - lOffsetValue;
|
||||
lowerLBuffer[barIndex] = lowerLValue + lOffsetValue;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = length >= 7;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Open ...
|
||||
ENUM_DRAW_TYPE openDrawType = showOpen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperOBufferIndex, upperOBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperOBufferIndex, PLOT_SHOW_DATA, showOpen);
|
||||
PlotIndexSetDouble(upperOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(upperOBufferIndex, PLOT_DRAW_TYPE, openDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerOBufferIndex, lowerOBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerOBufferIndex, PLOT_SHOW_DATA, showOpen);
|
||||
PlotIndexSetDouble(lowerOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(lowerOBufferIndex, PLOT_DRAW_TYPE, openDrawType);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ENUM_DRAW_TYPE closeDrawType = showClose ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperCBufferIndex, upperCBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperCBufferIndex, PLOT_SHOW_DATA, showClose);
|
||||
PlotIndexSetDouble(upperCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(upperCBufferIndex, PLOT_DRAW_TYPE, closeDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerCBufferIndex, lowerCBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerCBufferIndex, PLOT_SHOW_DATA, showClose);
|
||||
PlotIndexSetDouble(lowerCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(lowerCBufferIndex, PLOT_DRAW_TYPE, closeDrawType);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ENUM_DRAW_TYPE highDrawType = showHigh ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperHBufferIndex, upperHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperHBufferIndex, PLOT_SHOW_DATA, showHigh);
|
||||
PlotIndexSetDouble(upperHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(upperHBufferIndex, PLOT_DRAW_TYPE, highDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerHBufferIndex, lowerHBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerHBufferIndex, PLOT_SHOW_DATA, showHigh);
|
||||
PlotIndexSetDouble(lowerHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(lowerHBufferIndex, PLOT_DRAW_TYPE, highDrawType);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ENUM_DRAW_TYPE lowDrawType = showLow ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
SetIndexBuffer(upperLBufferIndex, upperLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upperLBufferIndex, PLOT_SHOW_DATA, showLow);
|
||||
PlotIndexSetDouble(upperLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(upperLBufferIndex, PLOT_DRAW_TYPE, lowDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
SetIndexBuffer(lowerLBufferIndex, lowerLBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowerLBufferIndex, PLOT_SHOW_DATA, showLow);
|
||||
PlotIndexSetDouble(lowerLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(lowerLBufferIndex, PLOT_DRAW_TYPE, lowDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
@@ -0,0 +1,479 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------------
|
||||
// Name: XHK
|
||||
// Description: Hiken Ashi ...
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XHK Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Constants ...
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XHK"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include <MovingAverages.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int smoothingLength = 17; // Smoothing Length
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool drawHikenAshi = true; // Draw Hiken Ashi
|
||||
input bool drawSmoothedHikenAshi = true; // Draw Smoothed Hiken Ashi
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 10
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
// Open ...
|
||||
#define openBufferIndex 0
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
// High ...
|
||||
#define highBufferIndex 1
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
// Low ...
|
||||
#define lowBufferIndex 2
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
// Close ...
|
||||
#define closeBufferIndex 3
|
||||
double closeBuffer[];
|
||||
|
||||
//
|
||||
// Candle Color ...
|
||||
#define candleColorBufferIndex 4
|
||||
double candleColorBuffer[];
|
||||
|
||||
//
|
||||
#define candlesBufferIndex 0
|
||||
|
||||
//
|
||||
#property indicator_label1 "XHK Open;XHK High;XHK Low;XHK Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta
|
||||
|
||||
//
|
||||
// SM Open ...
|
||||
#define openSMBufferIndex 5
|
||||
double openSMBuffer[];
|
||||
|
||||
//
|
||||
// SM High ...
|
||||
#define highSMBufferIndex 6
|
||||
double highSMBuffer[];
|
||||
|
||||
//
|
||||
// SM Low ...
|
||||
#define lowSMBufferIndex 7
|
||||
double lowSMBuffer[];
|
||||
|
||||
//
|
||||
// SM Close ...
|
||||
#define closeSMBufferIndex 8
|
||||
double closeSMBuffer[];
|
||||
|
||||
//
|
||||
// SM Candle Color ...
|
||||
#define candleColorSMBufferIndex 9
|
||||
double candleColorSMBuffer[];
|
||||
|
||||
//
|
||||
#define candlesSMBufferIndex 1
|
||||
|
||||
//
|
||||
#property indicator_label2 "XSMHK Open;XSMHK High;XSMHK Low;XSMHK Close"
|
||||
#property indicator_type2 DRAW_COLOR_CANDLES
|
||||
#property indicator_color2 CLR_NONE, clrDarkGreen, clrDarkRed
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double mHideColorIDX = 0;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low);
|
||||
}
|
||||
|
||||
//
|
||||
CalculateSM(rates_total, prev_calculated);
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Candles Color ...
|
||||
ArraySetAsSeries(candleColorBuffer, true);
|
||||
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(candleColorBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openBuffer, true);
|
||||
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, false);
|
||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highBuffer, true);
|
||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeBuffer, true);
|
||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowBuffer, true);
|
||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Candles Color ...
|
||||
ArraySetAsSeries(candleColorSMBuffer, true);
|
||||
SetIndexBuffer(candleColorSMBufferIndex, candleColorSMBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Set EMPTY_VALUE on Candles Buffer ...
|
||||
PlotIndexSetDouble(candlesSMBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(candlesSMBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(candleColorSMBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Open ...
|
||||
ArraySetAsSeries(openSMBuffer, true);
|
||||
PlotIndexSetInteger(openSMBufferIndex, PLOT_SHOW_DATA, false);
|
||||
SetIndexBuffer(openSMBufferIndex, openSMBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// High ...
|
||||
ArraySetAsSeries(highSMBuffer, true);
|
||||
SetIndexBuffer(highSMBufferIndex, highSMBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(highSMBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeSMBuffer, true);
|
||||
SetIndexBuffer(closeSMBufferIndex, closeSMBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(closeSMBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowSMBuffer, true);
|
||||
SetIndexBuffer(lowSMBufferIndex, lowSMBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(lowSMBufferIndex, PLOT_SHOW_DATA, false);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
double mPrevHKOpenValue;
|
||||
double mPrevHKCloseValue;
|
||||
|
||||
//
|
||||
if (ArraySize(open) <= bar_index + 1)
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = 0;
|
||||
mPrevHKCloseValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mPrevHKOpenValue = openBuffer[bar_index + 1];
|
||||
mPrevHKCloseValue = closeBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
|
||||
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
|
||||
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
|
||||
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
|
||||
|
||||
//
|
||||
openBuffer[bar_index] = mHKOpenValue;
|
||||
highBuffer[bar_index] = mHKHighValue;
|
||||
lowBuffer[bar_index] = mHKLowValue;
|
||||
closeBuffer[bar_index] = mHKCloseValue;
|
||||
|
||||
//
|
||||
bool isBearish =
|
||||
//
|
||||
openBuffer[bar_index] > closeBuffer[bar_index]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
candleColorBuffer[bar_index] = !drawHikenAshi
|
||||
? mHideColorIDX
|
||||
: isBearish
|
||||
? 2
|
||||
: 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Smoothed HikenAshi ...
|
||||
void CalculateSM(
|
||||
int ratesTotal, // Total Bars
|
||||
int prevCalculated // Calculated Bars
|
||||
)
|
||||
{
|
||||
//
|
||||
// Open ...
|
||||
int calculatedSMHKOpens = ExponentialMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
0,
|
||||
smoothingLength,
|
||||
openBuffer,
|
||||
openSMBuffer);
|
||||
|
||||
//
|
||||
// High ...
|
||||
int calculatedSMHKHighs = ExponentialMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
0,
|
||||
smoothingLength,
|
||||
highBuffer,
|
||||
highSMBuffer);
|
||||
|
||||
//
|
||||
// Low ...
|
||||
int calculatedSMHKLows = ExponentialMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
0,
|
||||
smoothingLength,
|
||||
lowBuffer,
|
||||
lowSMBuffer);
|
||||
|
||||
//
|
||||
// Close ...
|
||||
int calculatedSMHKCloses = ExponentialMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
0,
|
||||
smoothingLength,
|
||||
closeBuffer,
|
||||
closeSMBuffer);
|
||||
|
||||
//
|
||||
// Find Calculated Items for Colors ...
|
||||
int mNumberOfItems = MathMin(calculatedSMHKOpens, calculatedSMHKHighs);
|
||||
mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKLows);
|
||||
mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKCloses);
|
||||
|
||||
//
|
||||
// Create a Loop for Color of Candles ...
|
||||
for (int i = 0; i < mNumberOfItems; i++)
|
||||
{
|
||||
//
|
||||
bool isBearish =
|
||||
//
|
||||
openSMBuffer[i] > closeSMBuffer[i]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (drawSmoothedHikenAshi)
|
||||
{
|
||||
//
|
||||
candleColorSMBuffer[i] = isBearish
|
||||
? 2
|
||||
: 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
candleColorSMBuffer[i] = mHideColorIDX;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XHTD
|
||||
// Description: HULL Trend Detector ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XHTD Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XHTD"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 14; // Length
|
||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
||||
input double multiplier = 0.66; // Multiplier
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool show = true; // Show
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define mainBufferIndex 0
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainBufferColorIndex 1
|
||||
double mainBufferColor[];
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullColorIDX 1
|
||||
#define bearColorIDX 2
|
||||
|
||||
//
|
||||
#property indicator_label1 "XHTD"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define upBufferIndex 2
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#define downBufferIndex 3
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#define directionBufferIndex 4
|
||||
double directionBuffer[];
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (ArraySize(directionBuffer) != rates_total)
|
||||
{
|
||||
//
|
||||
ArrayResize(upBuffer, rates_total);
|
||||
ArrayResize(downBuffer, rates_total);
|
||||
ArrayResize(directionBuffer, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = (int)MathMax(prev_calculated - 1, 1); i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
double atr = 0;
|
||||
for (int k = 0; k < length && (i - k - 1) >= 0; k++)
|
||||
{
|
||||
atr += MathMax(high[i - k], close[i - k - 1]) - MathMin(low[i - k], close[i - k - 1]);
|
||||
}
|
||||
|
||||
//
|
||||
atr /= length;
|
||||
|
||||
//
|
||||
double cprice = close[i];
|
||||
double appliedPrice = getPrice(
|
||||
appliedTo,
|
||||
open,
|
||||
close,
|
||||
high,
|
||||
low,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
double mprice = iHull(
|
||||
appliedPrice,
|
||||
length,
|
||||
i,
|
||||
rates_total //
|
||||
);
|
||||
|
||||
//
|
||||
upBuffer[i] = mprice + multiplier * atr;
|
||||
downBuffer[i] = mprice - multiplier * atr;
|
||||
|
||||
//
|
||||
mainBufferColor[i] = mainBufferColor[i - 1];
|
||||
directionBuffer[i] = directionBuffer[i - 1];
|
||||
|
||||
//
|
||||
if (cprice > upBuffer[i - 1])
|
||||
{
|
||||
directionBuffer[i] = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (cprice < downBuffer[i - 1])
|
||||
{
|
||||
directionBuffer[i] = -1;
|
||||
}
|
||||
|
||||
//
|
||||
if (directionBuffer[i] > 0)
|
||||
{
|
||||
//
|
||||
downBuffer[i] = MathMax(downBuffer[i], downBuffer[i - 1]);
|
||||
|
||||
//
|
||||
mainBuffer[i] = downBuffer[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
upBuffer[i] = MathMin(upBuffer[i], upBuffer[i - 1]);
|
||||
|
||||
//
|
||||
mainBuffer[i] = upBuffer[i];
|
||||
}
|
||||
|
||||
//
|
||||
if (directionBuffer[i] == 1)
|
||||
{
|
||||
mainBufferColor[i] = bullColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (directionBuffer[i] == -1)
|
||||
{
|
||||
mainBufferColor[i] = bearColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = length >= 2 &&
|
||||
multiplier > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
SetIndexBuffer(directionBufferIndex, directionBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Hull Handler ...
|
||||
double workHull[][2];
|
||||
double iHull(
|
||||
double price,
|
||||
double period,
|
||||
int r,
|
||||
int bars,
|
||||
int instanceNo = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
if (ArrayRange(workHull, 0) != bars)
|
||||
{
|
||||
ArrayResize(workHull, bars);
|
||||
}
|
||||
|
||||
//
|
||||
int HmaPeriod = (int)MathMax(period, 2);
|
||||
int HalfPeriod = (int)MathFloor(HmaPeriod / 2);
|
||||
int HullPeriod = (int)MathFloor(MathSqrt(HmaPeriod));
|
||||
double hma, hmw, weight;
|
||||
instanceNo *= 2;
|
||||
|
||||
//
|
||||
workHull[r][instanceNo] = price;
|
||||
|
||||
//
|
||||
hmw = HalfPeriod;
|
||||
hma = hmw * price;
|
||||
for (int k = 1; k < HalfPeriod && (r - k) >= 0; k++)
|
||||
{
|
||||
//
|
||||
weight = HalfPeriod - k;
|
||||
hmw += weight;
|
||||
hma += weight * workHull[r - k][instanceNo];
|
||||
}
|
||||
workHull[r][instanceNo + 1] = 2.0 * hma / hmw;
|
||||
|
||||
//
|
||||
hmw = HmaPeriod;
|
||||
hma = hmw * price;
|
||||
for (int k = 1; k < period && (r - k) >= 0; k++)
|
||||
{
|
||||
//
|
||||
weight = HmaPeriod - k;
|
||||
hmw += weight;
|
||||
hma += weight * workHull[r - k][instanceNo];
|
||||
}
|
||||
workHull[r][instanceNo + 1] -= hma / hmw;
|
||||
|
||||
//
|
||||
hmw = HullPeriod;
|
||||
hma = hmw * workHull[r][instanceNo + 1];
|
||||
for (int k = 1; k < HullPeriod && (r - k) >= 0; k++)
|
||||
{
|
||||
//
|
||||
weight = HullPeriod - k;
|
||||
hmw += weight;
|
||||
hma += weight * workHull[r - k][1 + instanceNo];
|
||||
}
|
||||
|
||||
//
|
||||
return (hma / hmw);
|
||||
}
|
||||
|
||||
//
|
||||
double getPrice(ENUM_APPLIED_PRICE price, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars)
|
||||
{
|
||||
switch (price)
|
||||
{
|
||||
case PRICE_CLOSE: return(close[i]);
|
||||
case PRICE_OPEN: return(open[i]);
|
||||
case PRICE_HIGH: return(high[i]);
|
||||
case PRICE_LOW: return(low[i]);
|
||||
case PRICE_MEDIAN: return((high[i]+low[i])/2.0);
|
||||
case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0);
|
||||
case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0);
|
||||
//case PRICE_AVERAGE: return((high[i]+low[i]+close[i]+open[i])/4.0);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,583 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XHULL
|
||||
// Description: Hull Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XHULL Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
#define ShortName "XHULL"
|
||||
|
||||
//
|
||||
struct XHullData
|
||||
{
|
||||
//
|
||||
double value;
|
||||
double value3;
|
||||
|
||||
//
|
||||
double wsum1;
|
||||
double wsum2;
|
||||
double wsum3;
|
||||
|
||||
//
|
||||
double lsum1;
|
||||
double lsum2;
|
||||
double lsum3;
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class For Hull Calculations ...
|
||||
class XSCHull
|
||||
{
|
||||
//
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
|
||||
{
|
||||
//
|
||||
// These are a way above to assign Private variables at Construct time ...
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
~XSCHull()
|
||||
{
|
||||
ArrayFree(mData);
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Hull ...
|
||||
bool Init(
|
||||
int mPeriod,
|
||||
double mDivisor)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
|
||||
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
|
||||
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
|
||||
|
||||
//
|
||||
mArraySize = -1;
|
||||
mWeight1 = mWeight2 = mWeight3 = 1;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// CalCulate Specific Value ...
|
||||
double Calculate(
|
||||
double value,
|
||||
int i,
|
||||
int bars)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (mArraySize < bars)
|
||||
{
|
||||
//
|
||||
mArraySize = ArrayResize(mData, bars + 500);
|
||||
if (mArraySize < bars)
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].value = value;
|
||||
if (i > mFullPeriod)
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
|
||||
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
|
||||
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
|
||||
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 = mData[i].wsum2 =
|
||||
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
|
||||
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
|
||||
{
|
||||
//
|
||||
if (w1 > 0)
|
||||
{
|
||||
//
|
||||
mData[i].wsum1 += mData[i - k].value * w1;
|
||||
mData[i].lsum1 += mData[i - k].value;
|
||||
mWeight1 += w1;
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].wsum2 += mData[i - k].value * w2;
|
||||
mData[i].lsum2 += mData[i - k].value;
|
||||
mWeight2 += w2;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
|
||||
|
||||
//
|
||||
if (i > mSqrtPeriod)
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
|
||||
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 =
|
||||
mData[i].lsum3 = mWeight3 = 0;
|
||||
|
||||
//
|
||||
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
|
||||
{
|
||||
//
|
||||
mData[i].wsum3 += mData[i - k].value3 * w3;
|
||||
mData[i].lsum3 += mData[i - k].value3;
|
||||
mWeight3 += w3;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = mData[i].wsum3 / mWeight3;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
int mFullPeriod;
|
||||
int mHalfPeriod;
|
||||
int mSqrtPeriod;
|
||||
int mArraySize;
|
||||
double mWeight1;
|
||||
double mWeight2;
|
||||
double mWeight3;
|
||||
|
||||
//
|
||||
XHullData mData[];
|
||||
};
|
||||
|
||||
//
|
||||
// END XSCHULL Class Definition ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 72; // Length
|
||||
input double divisor = 2.0; // Divisor (Speed)
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showUpZone = true; // Show Up Zone
|
||||
input bool showDownZone = true; // Show Down Zone
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// UP Zone ...
|
||||
|
||||
//
|
||||
#define upZoneBufferIndex 0
|
||||
#define upZoneColorBufferIndex 1
|
||||
|
||||
//
|
||||
double upZoneBuffer[];
|
||||
double upZoneColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XHULL Up"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLightGray, clrAqua, clrMagenta
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// DOWN Zone ...
|
||||
|
||||
//
|
||||
#define downZoneBufferIndex 2
|
||||
#define downZoneColorBufferIndex 3
|
||||
|
||||
//
|
||||
double downZoneBuffer[];
|
||||
double downZoneColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XHULL Down"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrLightGray, clrAqua, clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
XSCHull *mUpZHull;
|
||||
XSCHull *mDownZHull;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Make an Instance of Hull Class ...
|
||||
|
||||
//
|
||||
mUpZHull = new XSCHull();
|
||||
mUpZHull.Init(
|
||||
length,
|
||||
divisor);
|
||||
|
||||
//
|
||||
mDownZHull = new XSCHull();
|
||||
mDownZHull.Init(
|
||||
length,
|
||||
divisor);
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
delete mUpZHull;
|
||||
delete mDownZHull;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
limit = prev_calculated - 1;
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
double upPrice = getPrice(
|
||||
upAppliedTo,
|
||||
open, high, low, close, i);
|
||||
|
||||
//
|
||||
double downPrice = getPrice(
|
||||
downAppliedTo,
|
||||
open, high, low, close, i);
|
||||
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
rates_total,
|
||||
upPrice,
|
||||
downPrice);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
result =
|
||||
length >= 9 &&
|
||||
divisor >= 0.5;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// UP Zone ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE upZoneDrawType = showUpZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(upZoneBufferIndex, upZoneBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_SHOW_DATA, showUpZone);
|
||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_DRAW_TYPE, upZoneDrawType);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
SetIndexBuffer(upZoneColorBufferIndex, upZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DOWN Zone ...
|
||||
|
||||
//
|
||||
// Draw Type ...
|
||||
ENUM_DRAW_TYPE downZoneDrawType = showDownZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Buffer ...
|
||||
SetIndexBuffer(downZoneBufferIndex, downZoneBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_SHOW_DATA, showDownZone);
|
||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_DRAW_TYPE, downZoneDrawType);
|
||||
|
||||
//
|
||||
// Color Buffer ...
|
||||
SetIndexBuffer(downZoneColorBufferIndex, downZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int ratesTotal, // Total Rates
|
||||
double upPrice, // Up Price ...
|
||||
double downPrice // Down Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double upValue = mUpZHull.Calculate(
|
||||
upPrice,
|
||||
bar_index,
|
||||
ratesTotal);
|
||||
upZoneBuffer[bar_index] = upValue;
|
||||
double upColorIDX = (bar_index > 0)
|
||||
? (upZoneBuffer[bar_index] > upZoneBuffer[bar_index - 1])
|
||||
? 1
|
||||
: (upZoneBuffer[bar_index] < upZoneBuffer[bar_index - 1])
|
||||
? 2
|
||||
: upZoneColorBuffer[bar_index - 1]
|
||||
: 0;
|
||||
upZoneColorBuffer[bar_index] = upColorIDX;
|
||||
|
||||
//
|
||||
double downValue = mDownZHull.Calculate(
|
||||
downPrice,
|
||||
bar_index,
|
||||
ratesTotal);
|
||||
downZoneBuffer[bar_index] = downValue;
|
||||
double downColorIDX = (bar_index > 0)
|
||||
? (downZoneBuffer[bar_index] > downZoneBuffer[bar_index - 1])
|
||||
? 1
|
||||
: (downZoneBuffer[bar_index] < downZoneBuffer[bar_index - 1])
|
||||
? 2
|
||||
: downZoneColorBuffer[bar_index - 1]
|
||||
: 0;
|
||||
downZoneColorBuffer[bar_index] = downColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TEMPLATE Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,846 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XICH
|
||||
// Description: Ichimoku Kinko Hyo ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XICH Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XICH"
|
||||
|
||||
//
|
||||
// Ichimoku Golden Numbers ...
|
||||
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
|
||||
{
|
||||
X_ICH_BASE = 9,
|
||||
X_ICH_GOLDEN = 17,
|
||||
X_ICH_CYCLE = 26,
|
||||
X_ICH_PERIOD = 35,
|
||||
X_ICH_STAR = 45,
|
||||
X_ICH_MED = 52,
|
||||
X_ICH_LONG = 63,
|
||||
X_ICH_FULL = 72
|
||||
};
|
||||
|
||||
//
|
||||
// Ichimoku Lines Calculator Mode ...
|
||||
enum ENUM_X_ICHIMOKU_CALCULATION_MODE
|
||||
{
|
||||
//
|
||||
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
|
||||
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
|
||||
};
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ICHIMOKU Kinko Hyo ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
input group "Tenkan Sen";
|
||||
input int tenkanSenLength = 9; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
input group "Kijun Sen";
|
||||
input int kijunSenLength = 26; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
input group "Senkou Span B";
|
||||
input int senkouSpanBLength = 52; // Length
|
||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
input group "Chikou Span";
|
||||
input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showTenkanSen = true; // Show Tenkan Sen
|
||||
input bool showKijunSen = true; // Show Kijun Sen
|
||||
input bool showKijunSenPlus = false; // Show Kijun Sen +
|
||||
input bool showKijunSenNegative = false; // Show Kijun Sen -
|
||||
input bool showChikouSpan = true; // Show Chikou Span
|
||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
||||
input bool showKumo = true; // Show Kumo
|
||||
input bool shiftKumo = true; // Shift Kumo to Future
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 8
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
#define tenkanSenBufferIndex 0
|
||||
double tenkanSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XICH TK"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBrown
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
#define kijunSenBufferIndex 1
|
||||
double kijunSenBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XICH KJ"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDodgerBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define kijunSenPlusBufferIndex 2
|
||||
double kijunSenPlusBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XICH KJ+"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrMediumTurquoise
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define kijunSenNegativeBufferIndex 3
|
||||
double kijunSenNegativeBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XICH KJ-"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrDarkSeaGreen
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
#define chikouSpanBufferIndex 4
|
||||
double chikouSpanBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XICH CS"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrDarkGreen
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define senkouABufferIndex 5
|
||||
double senkouABuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XICH SSA"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrLightGray
|
||||
#property indicator_style6 STYLE_DASHDOTDOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define senkouBBufferIndex 6
|
||||
double senkouBBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XICH SSB"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrLightGray
|
||||
#property indicator_style7 STYLE_DASHDOTDOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
|
||||
//
|
||||
#define senkouSpanABufferIndex 7
|
||||
double senkouSpanABuffer[];
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
#define senkouSpanBBufferIndex 8
|
||||
double senkouSpanBBuffer[];
|
||||
|
||||
//
|
||||
// KUMOCLOUD ...
|
||||
|
||||
//
|
||||
#define kumoBufferIndex 7
|
||||
|
||||
//
|
||||
#property indicator_label8 "XICH Kumo"
|
||||
#property indicator_type8 DRAW_FILLING
|
||||
#property indicator_color8 clrAqua, clrMagenta
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define dTenkanBufferIndex 9
|
||||
double dTenkanBuffer[];
|
||||
|
||||
//
|
||||
#define dKijunBufferIndex 10
|
||||
double dKijunBuffer[];
|
||||
|
||||
//
|
||||
#define dChikouBufferIndex 11
|
||||
double dChikouBuffer[];
|
||||
|
||||
//
|
||||
#define dSSABufferIndex 12
|
||||
double dSSABuffer[];
|
||||
|
||||
//
|
||||
#define dSSBBufferIndex 13
|
||||
double dSSBBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
|
||||
ENUM_SERIESMODE mTenkanSenBottomMode = NULL;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mKijunSenTopMode = NULL;
|
||||
ENUM_SERIESMODE mKijunSenBottomMode = NULL;
|
||||
|
||||
//
|
||||
ENUM_SERIESMODE mSenkouSpanBTopMode = NULL;
|
||||
ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Init Handler ...
|
||||
mHandler = iIchimoku(
|
||||
_Symbol,
|
||||
_Period,
|
||||
tenkanSenLength,
|
||||
kijunSenLength,
|
||||
senkouSpanBLength);
|
||||
if (mHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int ichCalculatedBars = BarsCalculated(mHandler);
|
||||
if (ichCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedTenkans = CopyBuffer(mHandler, TENKANSEN_LINE, 0, limit, dTenkanBuffer);
|
||||
int copiedKijuns = CopyBuffer(mHandler, KIJUNSEN_LINE, 0, limit, dKijunBuffer);
|
||||
int copiedChikous = CopyBuffer(mHandler, CHIKOUSPAN_LINE, 0, limit, dChikouBuffer);
|
||||
int copiedSSAs = CopyBuffer(mHandler, SENKOUSPANA_LINE, 0, limit, dSSABuffer);
|
||||
int copiedSSBs = CopyBuffer(mHandler, SENKOUSPANB_LINE, 0, limit, dSSBBuffer);
|
||||
if (
|
||||
copiedSSAs < 0 ||
|
||||
copiedSSBs < 0 ||
|
||||
copiedKijuns < 0 ||
|
||||
copiedTenkans < 0 ||
|
||||
copiedChikous < 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(tenkanSenLength > 2 &&
|
||||
kijunSenLength > tenkanSenLength &&
|
||||
senkouSpanBLength > kijunSenLength)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ichimoku ...
|
||||
result = MathMax(result, tenkanSenLength);
|
||||
result = MathMax(result, kijunSenLength);
|
||||
result = MathMax(result, senkouSpanBLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(tenkanSenBuffer, true);
|
||||
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
|
||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenBuffer, true);
|
||||
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
|
||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
|
||||
|
||||
//
|
||||
// KIJUNSEN Plus ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenPlusDrawType = showKijunSenPlus ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenPlusBuffer, true);
|
||||
SetIndexBuffer(kijunSenPlusBufferIndex, kijunSenPlusBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHIFT, kijunSenLength);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_TYPE, kijunSenPlusDrawType);
|
||||
|
||||
//
|
||||
// KIJUNSEN Negative ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kijunSenNegativeDrawType = showKijunSenNegative ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kijunSenNegativeBuffer, true);
|
||||
SetIndexBuffer(kijunSenNegativeBufferIndex, kijunSenNegativeBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_TYPE, kijunSenNegativeDrawType);
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(chikouSpanBuffer, true);
|
||||
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
|
||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
|
||||
|
||||
//
|
||||
// SENKOUSPAN A and B ...
|
||||
int shiftSize = shiftKumo ? kijunSenLength : 0;
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(senkouABuffer, true);
|
||||
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
|
||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(senkouBBuffer, true);
|
||||
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
|
||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
||||
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
||||
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
|
||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// D Tenkan ...
|
||||
ArraySetAsSeries(dTenkanBuffer, true);
|
||||
SetIndexBuffer(dTenkanBufferIndex, dTenkanBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D Kijun ...
|
||||
ArraySetAsSeries(dKijunBuffer, true);
|
||||
SetIndexBuffer(dKijunBufferIndex, dKijunBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D Chikou ...
|
||||
ArraySetAsSeries(dChikouBuffer, true);
|
||||
SetIndexBuffer(dChikouBufferIndex, dChikouBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D SSA ...
|
||||
ArraySetAsSeries(dSSABuffer, true);
|
||||
SetIndexBuffer(dSSABufferIndex, dSSABuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// D SSB ...
|
||||
ArraySetAsSeries(dSSBBuffer, true);
|
||||
SetIndexBuffer(dSSBBufferIndex, dSSBBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// ICHIMOKU ...
|
||||
|
||||
//
|
||||
double topValue;
|
||||
double bottomValue;
|
||||
|
||||
//
|
||||
// TENKANSEN ...
|
||||
|
||||
//
|
||||
// Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (tenkanSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_HIGH;
|
||||
mTenkanSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mTenkanSenTopMode = MODE_OPEN;
|
||||
mTenkanSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = bar
|
||||
.FindHighest(
|
||||
tenkanSenLength,
|
||||
mTenkanSenTopMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = bar
|
||||
.FindLowest(
|
||||
tenkanSenLength,
|
||||
mTenkanSenBottomMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
double tenkanSenValue = (topValue + bottomValue) / 2;
|
||||
tenkanSenBuffer[bar_index] = tenkanSenValue;
|
||||
|
||||
//
|
||||
// KIJUNSEN ...
|
||||
|
||||
//
|
||||
// Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (kijunSenMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_HIGH;
|
||||
mKijunSenBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mKijunSenTopMode = MODE_OPEN;
|
||||
mKijunSenBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = bar
|
||||
.FindHighest(
|
||||
kijunSenLength,
|
||||
mKijunSenTopMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = bar
|
||||
.FindLowest(
|
||||
kijunSenLength,
|
||||
mKijunSenBottomMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
double kijunSenValue = (topValue + bottomValue) / 2;
|
||||
kijunSenBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
kijunSenPlusBuffer[bar_index] = kijunSenValue;
|
||||
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
|
||||
|
||||
//
|
||||
// CHIKOUSPAN ...
|
||||
double chikouSpanValue = bar
|
||||
.GetPrice(chikuoSpanAppliedTo);
|
||||
|
||||
//
|
||||
chikouSpanBuffer[bar_index] = chikouSpanValue;
|
||||
|
||||
//
|
||||
// KUMO ...
|
||||
|
||||
//
|
||||
// SENKOUSPANA ...
|
||||
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
|
||||
senkouABuffer[bar_index] = senkouSpanAValue;
|
||||
senkouSpanABuffer[bar_index] = senkouSpanAValue;
|
||||
|
||||
//
|
||||
// SENKOUSPANB ...
|
||||
|
||||
//
|
||||
// Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ...
|
||||
if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL)
|
||||
{
|
||||
//
|
||||
switch (senkouSpanBMode)
|
||||
{
|
||||
//
|
||||
case X_XICH_HH_LL_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_HIGH;
|
||||
mSenkouSpanBBottomMode = MODE_LOW;
|
||||
break;
|
||||
|
||||
//
|
||||
case X_XICH_HO_LC_MODE:
|
||||
//
|
||||
mSenkouSpanBTopMode = MODE_OPEN;
|
||||
mSenkouSpanBBottomMode = MODE_CLOSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Top ...
|
||||
topValue = bar
|
||||
.FindHighest(
|
||||
senkouSpanBLength,
|
||||
mSenkouSpanBTopMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Bottom ...
|
||||
bottomValue = bar
|
||||
.FindLowest(
|
||||
senkouSpanBLength,
|
||||
mSenkouSpanBBottomMode
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
double senkouSpanBValue = (topValue + bottomValue) / 2;
|
||||
senkouBBuffer[bar_index] = senkouSpanBValue;
|
||||
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,483 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 XMC MA Cross Indicator
|
||||
// ---------------------------------------------------
|
||||
// Name: XMC
|
||||
// Description: Moving Average Crosses
|
||||
// Market Analysor ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XMC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XMC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Fast";
|
||||
input int fastMaLength = 21; // Length
|
||||
input int fastMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Slow";
|
||||
input int slowMaLength = 50; // Length
|
||||
input int slowMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Verifier";
|
||||
input int verifierMaLength = 200; // Length
|
||||
input int verifierMaShift = 0; // Shift
|
||||
input ENUM_MA_METHOD verifierMaMethod = MODE_EMA; // Method
|
||||
input ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "PSar";
|
||||
input double sarStep = 0.02; // Step
|
||||
input double sarMaximum = 0.2; // Maximum
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showSar = true; // Show Sar
|
||||
input bool showFastMa = true; // Show Fast
|
||||
input bool showSlowMa = true; // Show Slow
|
||||
input bool showVerifierMa = true; // Show Verifier
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define fastMaBufferIndex 0
|
||||
double fastMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XMC MA F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define slowMaBufferIndex 1
|
||||
double slowMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XMC MA S"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrDarkOrange
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// VERIFIER ...
|
||||
#define verifierMaBufferIndex 2
|
||||
double verifierMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XMC MA V"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrDarkBlue
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
#define sarBufferIndex 3
|
||||
double sarBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XMC SAR"
|
||||
#property indicator_type4 DRAW_ARROW
|
||||
#property indicator_color4 clrDarkGreen
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int sarHandler = INVALID_HANDLE;
|
||||
int fastMaHandler = INVALID_HANDLE;
|
||||
int slowMaHandler = INVALID_HANDLE;
|
||||
int verifierMaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// SAR Initializer ...
|
||||
sarHandler = iSAR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
sarStep,
|
||||
sarMaximum //
|
||||
);
|
||||
if (sarHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// MA Initialization ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
fastMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fastMaLength,
|
||||
fastMaShift,
|
||||
fastMaMethod,
|
||||
fastMaAppliedTo);
|
||||
if (fastMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
slowMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slowMaLength,
|
||||
slowMaShift,
|
||||
slowMaMethod,
|
||||
slowMaAppliedTo);
|
||||
if (slowMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// VERIFIER ...
|
||||
verifierMaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
verifierMaLength,
|
||||
verifierMaShift,
|
||||
verifierMaMethod,
|
||||
verifierMaAppliedTo);
|
||||
if (verifierMaHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(sarHandler);
|
||||
IndicatorRelease(fastMaHandler);
|
||||
IndicatorRelease(slowMaHandler);
|
||||
IndicatorRelease(verifierMaHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
||||
int fastMaCalculatedBars = BarsCalculated(fastMaHandler);
|
||||
int slowMaCalculatedBars = BarsCalculated(slowMaHandler);
|
||||
int verifierMaCalculatedBars = BarsCalculated(verifierMaHandler);
|
||||
if (sarCalculatedBars < maxLength ||
|
||||
fastMaCalculatedBars < maxLength ||
|
||||
slowMaCalculatedBars < maxLength ||
|
||||
verifierMaCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
||||
int copiedFastMas = CopyBuffer(fastMaHandler, 0, 0, limit, fastMaBuffer);
|
||||
int copiedSlowMas = CopyBuffer(slowMaHandler, 0, 0, limit, slowMaBuffer);
|
||||
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
|
||||
if (copiedSars <= 0 ||
|
||||
copiedFastMas <= 0 ||
|
||||
copiedSlowMas <= 0 ||
|
||||
copiedVerifierMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// Validate Ma ...
|
||||
(fastMaLength > 2 &&
|
||||
slowMaLength > fastMaLength &&
|
||||
verifierMaLength > slowMaLength)
|
||||
//
|
||||
&&
|
||||
//
|
||||
(sarStep > 0 &&
|
||||
sarMaximum > sarStep)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
result = MathMax(result, fastMaLength);
|
||||
result = MathMax(result, slowMaLength);
|
||||
result = MathMax(result, verifierMaLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// SAR ...
|
||||
ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
ArraySetAsSeries(sarBuffer, true);
|
||||
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, 225);
|
||||
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar);
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType);
|
||||
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(fastMaBuffer, true);
|
||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastMaDrawType);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(slowMaBuffer, true);
|
||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowMaDrawType);
|
||||
|
||||
//
|
||||
// VERIFIER ...
|
||||
ENUM_DRAW_TYPE verifierMaDrawType = showVerifierMa ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(verifierMaBuffer, true);
|
||||
SetIndexBuffer(verifierMaBufferIndex, verifierMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_SHOW_DATA, showVerifierMa);
|
||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_TYPE, verifierMaDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, "");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,855 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// --------------------------------------
|
||||
// Name: XMRB
|
||||
// Description: Moving Average Ribbon
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XMRB Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XMRB"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Ribbon 1";
|
||||
input int fast1Length = 20; // Fast
|
||||
input int slow1Length = 50; // Slow
|
||||
input ENUM_APPLIED_PRICE r1AppliedTo = PRICE_HIGH; // Applied To
|
||||
|
||||
//
|
||||
input group "Ribbon 2";
|
||||
input int fast2Length = 20; // Fast
|
||||
input int slow2Length = 50; // Slow
|
||||
input ENUM_APPLIED_PRICE r2AppliedTo = PRICE_OPEN; // Applied To
|
||||
|
||||
//
|
||||
input group "Ribbon 3";
|
||||
input int fast3Length = 20; // Fast
|
||||
input int slow3Length = 50; // Slow
|
||||
input ENUM_APPLIED_PRICE r3AppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Ribbon 4";
|
||||
input int fast4Length = 20; // Fast
|
||||
input int slow4Length = 50; // Slow
|
||||
input ENUM_APPLIED_PRICE r4AppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
input group "Ribbon 5";
|
||||
input int fast5Length = 20; // Fast
|
||||
input int slow5Length = 50; // Slow
|
||||
input ENUM_APPLIED_PRICE r5AppliedTo = PRICE_TYPICAL; // Applied To
|
||||
|
||||
//
|
||||
input group "Ribbon 6";
|
||||
input int fast6Length = 20; // Fast
|
||||
input int slow6Length = 50; // Slow
|
||||
input ENUM_APPLIED_PRICE r6AppliedTo = PRICE_LOW; // Applied To
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // Mode
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showFastMa = true; // Show Fast
|
||||
input bool showSlowMa = true; // Show Slow
|
||||
input bool showRibbon = false; // Show Ribbon
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 14
|
||||
#property indicator_plots 14
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
// MA ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define fastMaBufferIndex 0
|
||||
double fastMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XMRB F"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define slowMaBufferIndex 1
|
||||
double slowMaBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XMRB S"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
|
||||
//
|
||||
#define fast1BufferIndex 2
|
||||
double fast1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label3 "XMRB 1 F"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrAquamarine
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
#define fast2BufferIndex 3
|
||||
double fast2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label4 "XMRB 2 F"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrAquamarine
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 1
|
||||
|
||||
//
|
||||
#define fast3BufferIndex 4
|
||||
double fast3Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label5 "XMRB 3 F"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrAquamarine
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 1
|
||||
|
||||
//
|
||||
#define fast4BufferIndex 5
|
||||
double fast4Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label6 "XMRB 4 F"
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 clrAquamarine
|
||||
#property indicator_style6 STYLE_DOT
|
||||
#property indicator_width6 1
|
||||
|
||||
//
|
||||
#define fast5BufferIndex 6
|
||||
double fast5Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label7 "XMRB 5 F"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrAquamarine
|
||||
#property indicator_style7 STYLE_DOT
|
||||
#property indicator_width7 1
|
||||
|
||||
//
|
||||
#define fast6BufferIndex 7
|
||||
double fast6Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "XMRB 6 F"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrAquamarine
|
||||
#property indicator_style8 STYLE_DOT
|
||||
#property indicator_width8 1
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
|
||||
//
|
||||
#define slow1BufferIndex 8
|
||||
double slow1Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "XMRB 1 S"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrPlum
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define slow2BufferIndex 9
|
||||
double slow2Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "XMRB 2 S"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrPlum
|
||||
#property indicator_style10 STYLE_DOT
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
#define slow3BufferIndex 10
|
||||
double slow3Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "XMRB 3 S"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrPlum
|
||||
#property indicator_style11 STYLE_DOT
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define slow4BufferIndex 11
|
||||
double slow4Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label12 "XMRB 4 S"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrPlum
|
||||
#property indicator_style12 STYLE_DOT
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
#define slow5BufferIndex 12
|
||||
double slow5Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label13 "XMRB 5 S"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrPlum
|
||||
#property indicator_style13 STYLE_DOT
|
||||
#property indicator_width13 1
|
||||
|
||||
//
|
||||
#define slow6BufferIndex 13
|
||||
double slow6Buffer[];
|
||||
|
||||
//
|
||||
#property indicator_label14 "XMRB 6 S"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrPlum
|
||||
#property indicator_style14 STYLE_DOT
|
||||
#property indicator_width14 1
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int fast1MaHandler = INVALID_HANDLE;
|
||||
int fast2MaHandler = INVALID_HANDLE;
|
||||
int fast3MaHandler = INVALID_HANDLE;
|
||||
int fast4MaHandler = INVALID_HANDLE;
|
||||
int fast5MaHandler = INVALID_HANDLE;
|
||||
int fast6MaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int slow1MaHandler = INVALID_HANDLE;
|
||||
int slow2MaHandler = INVALID_HANDLE;
|
||||
int slow3MaHandler = INVALID_HANDLE;
|
||||
int slow4MaHandler = INVALID_HANDLE;
|
||||
int slow5MaHandler = INVALID_HANDLE;
|
||||
int slow6MaHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize MAs ...
|
||||
if (!InitializeMas())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
|
||||
//
|
||||
IndicatorRelease(fast1MaHandler);
|
||||
IndicatorRelease(fast2MaHandler);
|
||||
IndicatorRelease(fast3MaHandler);
|
||||
IndicatorRelease(fast4MaHandler);
|
||||
IndicatorRelease(fast5MaHandler);
|
||||
IndicatorRelease(fast6MaHandler);
|
||||
|
||||
//
|
||||
IndicatorRelease(slow1MaHandler);
|
||||
IndicatorRelease(slow2MaHandler);
|
||||
IndicatorRelease(slow3MaHandler);
|
||||
IndicatorRelease(slow4MaHandler);
|
||||
IndicatorRelease(slow5MaHandler);
|
||||
IndicatorRelease(slow6MaHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
//
|
||||
int fast1MaCalculatedBars = BarsCalculated(fast1MaHandler);
|
||||
int fast2MaCalculatedBars = BarsCalculated(fast2MaHandler);
|
||||
int fast3MaCalculatedBars = BarsCalculated(fast3MaHandler);
|
||||
int fast4MaCalculatedBars = BarsCalculated(fast4MaHandler);
|
||||
int fast5MaCalculatedBars = BarsCalculated(fast5MaHandler);
|
||||
int fast6MaCalculatedBars = BarsCalculated(fast6MaHandler);
|
||||
//
|
||||
int slow1MaCalculatedBars = BarsCalculated(slow1MaHandler);
|
||||
int slow2MaCalculatedBars = BarsCalculated(slow2MaHandler);
|
||||
int slow3MaCalculatedBars = BarsCalculated(slow3MaHandler);
|
||||
int slow4MaCalculatedBars = BarsCalculated(slow4MaHandler);
|
||||
int slow5MaCalculatedBars = BarsCalculated(slow5MaHandler);
|
||||
int slow6MaCalculatedBars = BarsCalculated(slow6MaHandler);
|
||||
if (
|
||||
fast1MaCalculatedBars < maxLength ||
|
||||
fast2MaCalculatedBars < maxLength ||
|
||||
fast3MaCalculatedBars < maxLength ||
|
||||
fast4MaCalculatedBars < maxLength ||
|
||||
fast5MaCalculatedBars < maxLength ||
|
||||
fast6MaCalculatedBars < maxLength ||
|
||||
slow1MaCalculatedBars < maxLength ||
|
||||
slow2MaCalculatedBars < maxLength ||
|
||||
slow3MaCalculatedBars < maxLength ||
|
||||
slow4MaCalculatedBars < maxLength ||
|
||||
slow5MaCalculatedBars < maxLength ||
|
||||
slow6MaCalculatedBars < maxLength //
|
||||
)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
//
|
||||
int copiedFast1Mas = CopyBuffer(fast1MaHandler, 0, 0, limit, fast1Buffer);
|
||||
int copiedFast2Mas = CopyBuffer(fast2MaHandler, 0, 0, limit, fast2Buffer);
|
||||
int copiedFast3Mas = CopyBuffer(fast3MaHandler, 0, 0, limit, fast3Buffer);
|
||||
int copiedFast4Mas = CopyBuffer(fast4MaHandler, 0, 0, limit, fast4Buffer);
|
||||
int copiedFast5Mas = CopyBuffer(fast5MaHandler, 0, 0, limit, fast5Buffer);
|
||||
int copiedFast6Mas = CopyBuffer(fast6MaHandler, 0, 0, limit, fast6Buffer);
|
||||
//
|
||||
int copiedSlow1Mas = CopyBuffer(slow1MaHandler, 0, 0, limit, slow1Buffer);
|
||||
int copiedSlow2Mas = CopyBuffer(slow2MaHandler, 0, 0, limit, slow2Buffer);
|
||||
int copiedSlow3Mas = CopyBuffer(slow3MaHandler, 0, 0, limit, slow3Buffer);
|
||||
int copiedSlow4Mas = CopyBuffer(slow4MaHandler, 0, 0, limit, slow4Buffer);
|
||||
int copiedSlow5Mas = CopyBuffer(slow5MaHandler, 0, 0, limit, slow5Buffer);
|
||||
int copiedSlow6Mas = CopyBuffer(slow6MaHandler, 0, 0, limit, slow6Buffer);
|
||||
if (
|
||||
copiedFast1Mas <= 0 ||
|
||||
copiedFast2Mas <= 0 ||
|
||||
copiedFast3Mas <= 0 ||
|
||||
copiedFast4Mas <= 0 ||
|
||||
copiedFast5Mas <= 0 ||
|
||||
copiedFast6Mas <= 0 ||
|
||||
copiedSlow1Mas <= 0 ||
|
||||
copiedSlow2Mas <= 0 ||
|
||||
copiedSlow3Mas <= 0 ||
|
||||
copiedSlow4Mas <= 0 ||
|
||||
copiedSlow5Mas <= 0 ||
|
||||
copiedSlow6Mas <= 0 //
|
||||
)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(fast1Length > 2 &&
|
||||
fast2Length > 2 &&
|
||||
fast3Length > 2 &&
|
||||
fast4Length > 2 &&
|
||||
fast5Length > 2 &&
|
||||
fast6Length > 2 &&
|
||||
slow1Length > fast1Length &&
|
||||
slow2Length > fast2Length &&
|
||||
slow3Length > fast3Length &&
|
||||
slow4Length > fast4Length &&
|
||||
slow5Length > fast5Length &&
|
||||
slow6Length > fast6Length
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Ma ...
|
||||
|
||||
//
|
||||
result = MathMax(fast1Length, fast2Length);
|
||||
result = MathMax(result, fast3Length);
|
||||
result = MathMax(result, fast4Length);
|
||||
result = MathMax(result, fast5Length);
|
||||
result = MathMax(result, fast6Length);
|
||||
|
||||
//
|
||||
result = MathMax(result, slow1Length);
|
||||
result = MathMax(result, slow2Length);
|
||||
result = MathMax(result, slow3Length);
|
||||
result = MathMax(result, slow4Length);
|
||||
result = MathMax(result, slow5Length);
|
||||
result = MathMax(result, slow6Length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Ma Handlers ...
|
||||
bool InitializeMas()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
fast1MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast1Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r1AppliedTo);
|
||||
fast2MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast2Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r2AppliedTo);
|
||||
fast3MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast3Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r3AppliedTo);
|
||||
fast4MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast4Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r4AppliedTo);
|
||||
fast5MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast5Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r5AppliedTo);
|
||||
fast6MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
fast6Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r6AppliedTo);
|
||||
|
||||
//
|
||||
slow1MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow1Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r1AppliedTo);
|
||||
slow2MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow2Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r2AppliedTo);
|
||||
slow3MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow3Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r3AppliedTo);
|
||||
slow4MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow4Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r4AppliedTo);
|
||||
slow5MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow5Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r5AppliedTo);
|
||||
slow6MaHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
slow6Length,
|
||||
0,
|
||||
ribbonMode,
|
||||
r6AppliedTo);
|
||||
|
||||
//
|
||||
result =
|
||||
fast1MaHandler != INVALID_HANDLE &&
|
||||
fast2MaHandler != INVALID_HANDLE &&
|
||||
fast3MaHandler != INVALID_HANDLE &&
|
||||
fast4MaHandler != INVALID_HANDLE &&
|
||||
fast5MaHandler != INVALID_HANDLE &&
|
||||
fast6MaHandler != INVALID_HANDLE &&
|
||||
slow1MaHandler != INVALID_HANDLE &&
|
||||
slow2MaHandler != INVALID_HANDLE &&
|
||||
slow3MaHandler != INVALID_HANDLE &&
|
||||
slow4MaHandler != INVALID_HANDLE &&
|
||||
slow5MaHandler != INVALID_HANDLE &&
|
||||
slow6MaHandler != INVALID_HANDLE;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// FAST ...
|
||||
ENUM_DRAW_TYPE fastDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(fastMaBuffer, true);
|
||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
ENUM_DRAW_TYPE slowDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(slowMaBuffer, true);
|
||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
||||
|
||||
//
|
||||
// DATA ...
|
||||
ENUM_DRAW_TYPE ribbonDrawType = showRibbon ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast1Buffer, true);
|
||||
SetIndexBuffer(fast1BufferIndex, fast1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast2Buffer, true);
|
||||
SetIndexBuffer(fast2BufferIndex, fast2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast3Buffer, true);
|
||||
SetIndexBuffer(fast3BufferIndex, fast3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast4Buffer, true);
|
||||
SetIndexBuffer(fast4BufferIndex, fast4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast5Buffer, true);
|
||||
SetIndexBuffer(fast5BufferIndex, fast5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(fast6Buffer, true);
|
||||
SetIndexBuffer(fast6BufferIndex, fast6Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fast6BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(fast6BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(fast6BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow1Buffer, true);
|
||||
SetIndexBuffer(slow1BufferIndex, slow1Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow2Buffer, true);
|
||||
SetIndexBuffer(slow2BufferIndex, slow2Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow3Buffer, true);
|
||||
SetIndexBuffer(slow3BufferIndex, slow3Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow4Buffer, true);
|
||||
SetIndexBuffer(slow4BufferIndex, slow4Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow5Buffer, true);
|
||||
SetIndexBuffer(slow5BufferIndex, slow5Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(slow6Buffer, true);
|
||||
SetIndexBuffer(slow6BufferIndex, slow6Buffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(slow6BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
||||
PlotIndexSetInteger(slow6BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(slow6BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index // Selected Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Retireve Values ...
|
||||
|
||||
//
|
||||
double fast1Value = fast1Buffer[bar_index];
|
||||
double fast2Value = fast2Buffer[bar_index];
|
||||
double fast3Value = fast3Buffer[bar_index];
|
||||
double fast4Value = fast4Buffer[bar_index];
|
||||
double fast5Value = fast5Buffer[bar_index];
|
||||
double fast6Value = fast6Buffer[bar_index];
|
||||
|
||||
//
|
||||
double fasts[] = {
|
||||
fast1Value,
|
||||
fast2Value,
|
||||
fast3Value,
|
||||
fast4Value,
|
||||
fast5Value,
|
||||
fast6Value};
|
||||
|
||||
//
|
||||
double slow1Value = slow1Buffer[bar_index];
|
||||
double slow2Value = slow2Buffer[bar_index];
|
||||
double slow3Value = slow3Buffer[bar_index];
|
||||
double slow4Value = slow4Buffer[bar_index];
|
||||
double slow5Value = slow5Buffer[bar_index];
|
||||
double slow6Value = slow6Buffer[bar_index];
|
||||
|
||||
//
|
||||
double slows[] = {
|
||||
slow1Value,
|
||||
slow2Value,
|
||||
slow3Value,
|
||||
slow4Value,
|
||||
slow5Value,
|
||||
slow6Value};
|
||||
|
||||
//
|
||||
double fastValue = GetAverage(fasts);
|
||||
fastMaBuffer[bar_index] = fastValue;
|
||||
|
||||
//
|
||||
double slowValue = GetAverage(slows);
|
||||
slowMaBuffer[bar_index] = slowValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,721 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XOSC
|
||||
// Description: provides some oscillator values
|
||||
// as empty Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XOSC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "RVI";
|
||||
input int rviLength = 10; // Length
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
input group "Bulls Power";
|
||||
input int bullpLength = 13; // Length
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
input group "Bears Power";
|
||||
input int bearpLength = 13; // Length
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
input group "Volumes";
|
||||
input ENUM_APPLIED_VOLUME volumeAppliedTo = VOLUME_TICK; // Applied To
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
input group "RSI";
|
||||
input int rsiLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
input group "CCI";
|
||||
input int cciLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE cciAppliedTo = PRICE_TYPICAL; // Applied To
|
||||
|
||||
//
|
||||
// STDDEV ...
|
||||
input group "Standard Deviation";
|
||||
input int stddevLength = 20; // Length
|
||||
input int stddevShift = 0; // Shift
|
||||
input ENUM_MA_METHOD stddevMethod = MODE_SMA; // Mode
|
||||
input ENUM_APPLIED_PRICE stddevAppliedTo = PRICE_CLOSE; // AppliedTo
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
input group "Momentum";
|
||||
input int momentumLength = 14; // Length
|
||||
input ENUM_APPLIED_PRICE momentumAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
input group "SAR";
|
||||
input double sarStep = 0.02; // Step
|
||||
input double sarMaximum = 0.2; // Maximum
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "MACD";
|
||||
input int macdFastLength = 12; // Fast Length
|
||||
input int macdSlowLength = 26; // Slow Length
|
||||
input int macdSignaLength = 9; // Signal Length
|
||||
input ENUM_APPLIED_PRICE macdAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
// The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
||||
input group "Stochastic";
|
||||
input int stochKLength = 5; // K Length
|
||||
input int stochDLength = 3; // D Length
|
||||
input int stochSlowing = 3; // Slowing
|
||||
input ENUM_MA_METHOD stochMaMethod = MODE_SMA; // Ma Method
|
||||
input ENUM_STO_PRICE stochMode = STO_LOWHIGH; // Calculation Mode
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 15
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
#define atrBufferIndex 0
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
#define rviMainBufferIndex 1
|
||||
#define rviSignalBufferIndex 2
|
||||
double rviMainBuffer[];
|
||||
double rviSignalBuffer[];
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
#define bullPBufferIndex 3
|
||||
double bullPBuffer[];
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
#define bearPBufferIndex 4
|
||||
double bearPBuffer[];
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
#define volumeBufferIndex 5
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex 6
|
||||
double rsiBuffer[];
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
#define cciBufferIndex 7
|
||||
double cciBuffer[];
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
#define momentumBufferIndex 8
|
||||
double momentumBuffer[];
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
#define sarBufferIndex 9
|
||||
double sarBuffer[];
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
#define macdMainBufferIndex 10
|
||||
#define macdSignalBufferIndex 11
|
||||
double macdMainBuffer[];
|
||||
double macdSignalBuffer[];
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
#define stochMainBufferIndex 12
|
||||
#define stochSignalBufferIndex 13
|
||||
double stochMainBuffer[];
|
||||
double stochSignalBuffer[];
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
#define stddevBufferIndex 14
|
||||
double stddevBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
int rviHandler = INVALID_HANDLE;
|
||||
int bullPHandler = INVALID_HANDLE;
|
||||
int bearPHandler = INVALID_HANDLE;
|
||||
int volumeHandler = INVALID_HANDLE;
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
int cciHandler = INVALID_HANDLE;
|
||||
int momentumHandler = INVALID_HANDLE;
|
||||
int sarHandler = INVALID_HANDLE;
|
||||
int macdHandler = INVALID_HANDLE;
|
||||
int stochHandler = INVALID_HANDLE;
|
||||
int stddevHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Initializing Handlers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
rviHandler = iRVI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rviLength);
|
||||
|
||||
//
|
||||
// BULLSPOWER ...
|
||||
bullPHandler = iBullsPower(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bullpLength);
|
||||
|
||||
//
|
||||
// BEARSPOWER ...
|
||||
bearPHandler = iBearsPower(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bullpLength);
|
||||
|
||||
//
|
||||
// VOLUMES ...
|
||||
volumeHandler = iVolumes(
|
||||
_Symbol,
|
||||
_Period,
|
||||
volumeAppliedTo);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
rsiHandler = iRSI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
rsiLength,
|
||||
rsiAppliedTo);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
cciHandler = iCCI(
|
||||
_Symbol,
|
||||
_Period,
|
||||
cciLength,
|
||||
cciAppliedTo);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
momentumHandler = iMomentum(
|
||||
_Symbol,
|
||||
_Period,
|
||||
momentumLength,
|
||||
momentumAppliedTo);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
sarHandler = iSAR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
sarStep,
|
||||
sarMaximum);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
macdHandler = iMACD(
|
||||
_Symbol,
|
||||
_Period,
|
||||
macdFastLength,
|
||||
macdSlowLength,
|
||||
macdSignaLength,
|
||||
macdAppliedTo);
|
||||
|
||||
//
|
||||
// STOCHASTIC ...
|
||||
stochHandler = iStochastic(
|
||||
_Symbol,
|
||||
_Period,
|
||||
stochKLength,
|
||||
stochDLength,
|
||||
stochSlowing,
|
||||
stochMaMethod,
|
||||
stochMode);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
stddevHandler = iStdDev(
|
||||
_Symbol,
|
||||
_Period,
|
||||
stddevLength,
|
||||
stddevShift,
|
||||
stddevMethod,
|
||||
stddevAppliedTo);
|
||||
|
||||
//
|
||||
bool isAllHandlersInit =
|
||||
//
|
||||
atrHandler != INVALID_HANDLE &&
|
||||
rviHandler != INVALID_HANDLE &&
|
||||
bullPHandler != INVALID_HANDLE &&
|
||||
bearPHandler != INVALID_HANDLE &&
|
||||
volumeHandler != INVALID_HANDLE &&
|
||||
rsiHandler != INVALID_HANDLE &&
|
||||
cciHandler != INVALID_HANDLE &&
|
||||
momentumHandler != INVALID_HANDLE &&
|
||||
sarHandler != INVALID_HANDLE &&
|
||||
macdHandler != INVALID_HANDLE &&
|
||||
stochHandler != INVALID_HANDLE &&
|
||||
stddevHandler != INVALID_HANDLE
|
||||
//
|
||||
;
|
||||
if (!isAllHandlersInit)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
IndicatorRelease(rviHandler);
|
||||
IndicatorRelease(bullPHandler);
|
||||
IndicatorRelease(bearPHandler);
|
||||
IndicatorRelease(volumeHandler);
|
||||
IndicatorRelease(rsiHandler);
|
||||
IndicatorRelease(cciHandler);
|
||||
IndicatorRelease(momentumHandler);
|
||||
IndicatorRelease(sarHandler);
|
||||
IndicatorRelease(macdHandler);
|
||||
IndicatorRelease(stochHandler);
|
||||
IndicatorRelease(stddevHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
int rviCalculatedBars = BarsCalculated(rviHandler);
|
||||
int bullPCalculatedBars = BarsCalculated(bullPHandler);
|
||||
int bearPCalculatedBars = BarsCalculated(bearPHandler);
|
||||
int volumeCalculatedBars = BarsCalculated(volumeHandler);
|
||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
||||
int cciCalculatedBars = BarsCalculated(cciHandler);
|
||||
int momentumCalculatedBars = BarsCalculated(momentumHandler);
|
||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
||||
int macdCalculatedBars = BarsCalculated(macdHandler);
|
||||
int stochCalculatedBars = BarsCalculated(stochHandler);
|
||||
int stddevCalculatedBars = BarsCalculated(stddevHandler);
|
||||
|
||||
//
|
||||
bool isCalculatedBarsPassed =
|
||||
//
|
||||
atrCalculatedBars >= maxLength &&
|
||||
rviCalculatedBars >= maxLength &&
|
||||
bullPCalculatedBars >= maxLength &&
|
||||
bearPCalculatedBars >= maxLength &&
|
||||
volumeCalculatedBars >= maxLength &&
|
||||
rsiCalculatedBars >= maxLength &&
|
||||
cciCalculatedBars >= maxLength &&
|
||||
momentumCalculatedBars >= maxLength &&
|
||||
sarCalculatedBars >= maxLength &&
|
||||
macdCalculatedBars >= maxLength &&
|
||||
stochCalculatedBars >= maxLength &&
|
||||
stddevCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isCalculatedBarsPassed)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int atrCopiedItems = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
int rviMainCopiedItems = CopyBuffer(rviHandler, MAIN_LINE, 0, limit, rviMainBuffer);
|
||||
int rviSignalCopiedItems = CopyBuffer(rviHandler, SIGNAL_LINE, 0, limit, rviSignalBuffer);
|
||||
int bullPCopiedItems = CopyBuffer(bullPHandler, 0, 0, limit, bullPBuffer);
|
||||
int bearPCopiedItems = CopyBuffer(bearPHandler, 0, 0, limit, bearPBuffer);
|
||||
int volumeCopiedItems = CopyBuffer(volumeHandler, 0, 0, limit, volumeBuffer);
|
||||
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
||||
int cciCopiedItems = CopyBuffer(cciHandler, 0, 0, limit, cciBuffer);
|
||||
int momentumCopiedItems = CopyBuffer(momentumHandler, 0, 0, limit, momentumBuffer);
|
||||
int sarCopiedItems = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
||||
int macdMainCopiedItems = CopyBuffer(macdHandler, MAIN_LINE, 0, limit, macdMainBuffer);
|
||||
int macdSignalCopiedItems = CopyBuffer(macdHandler, SIGNAL_LINE, 0, limit, macdSignalBuffer);
|
||||
int stochMainCopiedItems = CopyBuffer(stochHandler, MAIN_LINE, 0, limit, stochMainBuffer);
|
||||
int stocSignalhCopiedItems = CopyBuffer(stochHandler, SIGNAL_LINE, 0, limit, stochSignalBuffer);
|
||||
int stddevCopiedItems = CopyBuffer(stddevHandler, 0, 0, limit, stddevBuffer);
|
||||
|
||||
//
|
||||
bool isCopiedBarsPassed =
|
||||
//
|
||||
atrCopiedItems > 0 &&
|
||||
rviMainCopiedItems > 0 &&
|
||||
rviSignalCopiedItems > 0 &&
|
||||
bullPCopiedItems > 0 &&
|
||||
bearPCopiedItems > 0 &&
|
||||
volumeCopiedItems > 0 &&
|
||||
rsiCopiedItems > 0 &&
|
||||
cciCopiedItems > 0 &&
|
||||
momentumCopiedItems > 0 &&
|
||||
sarCopiedItems > 0 &&
|
||||
macdMainCopiedItems > 0 &&
|
||||
macdSignalCopiedItems > 0 &&
|
||||
stochMainCopiedItems > 0 &&
|
||||
stocSignalhCopiedItems > 0 &&
|
||||
stddevCopiedItems > 0
|
||||
//
|
||||
;
|
||||
if (!isCopiedBarsPassed)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
// HERE We Do Not anything ...
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2 &&
|
||||
rviLength >= 2 &&
|
||||
bullpLength >= 2 &&
|
||||
bearpLength >= 2 &&
|
||||
rsiLength >= 2 &&
|
||||
cciLength >= 2 &&
|
||||
momentumLength >= 2 &&
|
||||
sarStep > 0 &&
|
||||
sarStep < sarMaximum &&
|
||||
macdFastLength >= 2 &&
|
||||
macdSlowLength > macdFastLength &&
|
||||
macdSignaLength >= 2 &&
|
||||
stochKLength >= 2 &&
|
||||
stochDLength >= 2 &&
|
||||
stochSlowing >= 2 &&
|
||||
stddevLength >= 2 &&
|
||||
stddevShift >= 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(atrLength, rviLength);
|
||||
result = MathMax(result, bullpLength);
|
||||
result = MathMax(result, bearpLength);
|
||||
result = MathMax(result, rsiLength);
|
||||
result = MathMax(result, cciLength);
|
||||
result = MathMax(result, momentumLength);
|
||||
result = MathMax(result, macdFastLength);
|
||||
result = MathMax(result, macdSlowLength);
|
||||
result = MathMax(result, macdSignaLength);
|
||||
result = MathMax(result, stochKLength);
|
||||
result = MathMax(result, stochDLength);
|
||||
result = MathMax(result, stochSlowing);
|
||||
result = MathMax(result, stddevLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RVI ...
|
||||
|
||||
//
|
||||
// Main ...
|
||||
ArraySetAsSeries(rviMainBuffer, true);
|
||||
SetIndexBuffer(rviMainBufferIndex, rviMainBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
ArraySetAsSeries(rviSignalBuffer, true);
|
||||
SetIndexBuffer(rviSignalBufferIndex, rviSignalBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// BULLPOWER ...
|
||||
ArraySetAsSeries(bullPBuffer, true);
|
||||
SetIndexBuffer(bullPBufferIndex, bullPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// BEARPOWER ...
|
||||
ArraySetAsSeries(bearPBuffer, true);
|
||||
SetIndexBuffer(bearPBufferIndex, bearPBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// VOLUME ...
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// CCI ...
|
||||
ArraySetAsSeries(cciBuffer, true);
|
||||
SetIndexBuffer(cciBufferIndex, cciBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MOMENTUM ...
|
||||
ArraySetAsSeries(momentumBuffer, true);
|
||||
SetIndexBuffer(momentumBufferIndex, momentumBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
ArraySetAsSeries(sarBuffer, true);
|
||||
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// STANDARDDEVIATION ...
|
||||
ArraySetAsSeries(stddevBuffer, true);
|
||||
SetIndexBuffer(stddevBufferIndex, stddevBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// MACD ...
|
||||
|
||||
//
|
||||
// Main ...
|
||||
ArraySetAsSeries(macdMainBuffer, true);
|
||||
SetIndexBuffer(macdMainBufferIndex, macdMainBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Signal ...
|
||||
ArraySetAsSeries(macdSignalBuffer, true);
|
||||
SetIndexBuffer(macdSignalBufferIndex, macdSignalBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,279 @@
|
||||
///////////////////////////////////////////////////////
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------
|
||||
// Name: XSLN
|
||||
// Description: HULL Trend Detector ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XSLN Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XSLN"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool show = true; // Show
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define mainBufferIndex 0
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainBufferColorIndex 1
|
||||
double mainBufferColor[];
|
||||
|
||||
//
|
||||
#define stateBufferIndex 2
|
||||
double stateBuffer[];
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullColorIDX 1
|
||||
#define bearColorIDX 2
|
||||
|
||||
//
|
||||
#property indicator_label1 "XSLN"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
double work[][5];
|
||||
#define hHi 0
|
||||
#define hLo 1
|
||||
#define lHi 2
|
||||
#define lLo 3
|
||||
#define trend 4
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
if (ArrayRange(work, 0) != rates_total)
|
||||
{
|
||||
//
|
||||
ArrayResize(work, rates_total);
|
||||
ArrayResize(stateBuffer, rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = (int)MathMax(prev_calculated - 1, 0); i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
if (i == 0)
|
||||
{
|
||||
//
|
||||
work[i][hHi] = high[i];
|
||||
work[i][hLo] = low[i];
|
||||
work[i][lHi] = high[i];
|
||||
work[i][lLo] = low[i];
|
||||
work[i][trend] = -1;
|
||||
stateBuffer[i] = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
work[i][trend] = work[i - 1][trend];
|
||||
work[i][hHi] = work[i - 1][hHi];
|
||||
work[i][hLo] = work[i - 1][hLo];
|
||||
work[i][lHi] = work[i - 1][lHi];
|
||||
work[i][lLo] = work[i - 1][lLo];
|
||||
|
||||
//
|
||||
if (work[i - 1][trend] == 1)
|
||||
{
|
||||
//
|
||||
work[i][hHi] = MathMax(work[i - 1][hHi], high[i]);
|
||||
work[i][hLo] = MathMax(work[i - 1][hLo], low[i]);
|
||||
|
||||
//
|
||||
if (high[i] < work[i][hLo])
|
||||
{
|
||||
//
|
||||
work[i][trend] = -1;
|
||||
work[i][lHi] = high[i];
|
||||
work[i][lLo] = low[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (work[i - 1][trend] == -1)
|
||||
{
|
||||
//
|
||||
work[i][lHi] = MathMin(work[i - 1][lHi], high[i]);
|
||||
work[i][lLo] = MathMin(work[i - 1][lLo], low[i]);
|
||||
|
||||
//
|
||||
if (low[i] > work[i][lHi])
|
||||
{
|
||||
//
|
||||
work[i][trend] = 1;
|
||||
work[i][hHi] = high[i];
|
||||
work[i][hLo] = low[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (work[i][trend] == 1)
|
||||
{
|
||||
mainBuffer[i] = work[i][hLo];
|
||||
}
|
||||
else
|
||||
{
|
||||
mainBuffer[i] = work[i][lHi];
|
||||
}
|
||||
|
||||
//
|
||||
stateBuffer[i] = stateBuffer[i - 1];
|
||||
mainBufferColor[i] = mainBufferColor[i - 1];
|
||||
|
||||
//
|
||||
if (work[i][trend] == 1)
|
||||
{
|
||||
//
|
||||
stateBuffer[i] = 1;
|
||||
mainBufferColor[i] = bullColorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
if (work[i][trend] == -1)
|
||||
{
|
||||
//
|
||||
stateBuffer[i] = -1;
|
||||
mainBufferColor[i] = bearColorIDX;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = true;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
||||
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -0,0 +1,440 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ----------------------------------------------------
|
||||
// Name: XSSLC
|
||||
// Description: SSL Channel Indicator
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XSSLC Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// Indicator Short Name ...
|
||||
#define ShortName "XSSLC"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int length = 36; // Length
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_MA_METHOD method = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Applied To
|
||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showUp = true; // Show Up
|
||||
input bool showDown = true; // Show Down
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Includes and Imports ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#define upBufferIndex 0
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XSSLC Up"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#define downBufferIndex 1
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XSSLC Down"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define upMaBufferIndex 2
|
||||
double upMaBuffer[];
|
||||
|
||||
//
|
||||
#define downMaBufferIndex 3
|
||||
double downMaBuffer[];
|
||||
|
||||
//
|
||||
#define kpiBufferIndex 4
|
||||
double kpiBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int upHandler = INVALID_HANDLE;
|
||||
int downHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Initialize Requierd Handlers ...
|
||||
upHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
upAppliedTo);
|
||||
downHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
length,
|
||||
0,
|
||||
method,
|
||||
downAppliedTo);
|
||||
if (upHandler == INVALID_HANDLE || downHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
string msg = "Error in Initilizing Indicator ...";
|
||||
Print(msg);
|
||||
|
||||
//
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Release Indicators ...
|
||||
IndicatorRelease(upHandler);
|
||||
IndicatorRelease(downHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int upCalculatedBars = BarsCalculated(upHandler);
|
||||
int downCalculatedBars = BarsCalculated(downHandler);
|
||||
if (upCalculatedBars < maxLength ||
|
||||
downCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedUps = CopyBuffer(upHandler, 0, 0, limit, upMaBuffer);
|
||||
int copiedDowns = CopyBuffer(downHandler, 0, 0, limit, downMaBuffer);
|
||||
if (copiedUps <= 0 ||
|
||||
copiedDowns <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
CalculateBuffers(i, limit, rates_total, prev_calculated, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
(length > 2)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, length);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// UP ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(upBuffer, true);
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, showUp);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
ArraySetAsSeries(downBuffer, true);
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, showDown);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_TYPE, downDrawType);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// UP MA ...
|
||||
ArraySetAsSeries(upMaBuffer, true);
|
||||
SetIndexBuffer(upMaBufferIndex, upMaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN MA ...
|
||||
ArraySetAsSeries(downMaBuffer, true);
|
||||
SetIndexBuffer(downMaBufferIndex, downMaBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// KPI ...
|
||||
ArraySetAsSeries(kpiBuffer, true);
|
||||
SetIndexBuffer(kpiBufferIndex, kpiBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index, // Selected Bar Index
|
||||
int limit,
|
||||
int ratesTotal,
|
||||
int prevCalculated,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
double upMaValue = upMaBuffer[bar_index];
|
||||
double downMaValue = downMaBuffer[bar_index];
|
||||
|
||||
//
|
||||
double closeValue = close[bar_index];
|
||||
|
||||
//
|
||||
double kpiValue;
|
||||
if (closeValue > upMaValue)
|
||||
{
|
||||
kpiValue = 1;
|
||||
}
|
||||
else if (closeValue < downMaValue)
|
||||
{
|
||||
kpiValue = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
kpiValue = kpiBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
kpiBuffer[bar_index] = kpiValue;
|
||||
|
||||
//
|
||||
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
|
||||
upBuffer[bar_index] = upValue;
|
||||
|
||||
//
|
||||
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
|
||||
downBuffer[bar_index] = downValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,580 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XSTR
|
||||
// Description: Super Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121_XAMA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
|
||||
#define ShortName "XSTR"
|
||||
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Market ...
|
||||
input group "ATR";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 3.0; // Multiplier
|
||||
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showTrends = true; // Show Trends
|
||||
input bool fillTrends = true; // Fill Trends
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define fillUpBufferIndex 0
|
||||
double fillUpBuffer[];
|
||||
|
||||
#define fillDownBufferIndex 1
|
||||
double fillDownBuffer[];
|
||||
|
||||
//
|
||||
#define fillingPlotBufferIndex 0
|
||||
|
||||
//
|
||||
#property indicator_label1 "XSTR Filling"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrBisque, clrPaleGreen
|
||||
|
||||
//
|
||||
#define mainBufferIndex 2
|
||||
#define mainPlotBufferIndex 1
|
||||
double mainBuffer[];
|
||||
|
||||
//
|
||||
#define mainColorBufferIndex 3
|
||||
double mainColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XSTR"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
#define atrBufferIndex 4
|
||||
double atrBuffer[];
|
||||
|
||||
//
|
||||
#define trendBufferIndex 5
|
||||
double trendBuffer[];
|
||||
|
||||
//
|
||||
#define upBufferIndex 6
|
||||
double upBuffer[];
|
||||
|
||||
//
|
||||
#define downBufferIndex 7
|
||||
double downBuffer[];
|
||||
|
||||
//
|
||||
#define priceBufferIndex 8
|
||||
double priceBuffer[];
|
||||
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
int changeOfTrend;
|
||||
int startBearishTrend;
|
||||
int startBullishTrend;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength);
|
||||
if (atrHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
int numOfRequiredAtrs;
|
||||
if (prev_calculated > rates_total || prev_calculated < 0)
|
||||
{
|
||||
numOfRequiredAtrs = rates_total;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
numOfRequiredAtrs = rates_total - prev_calculated;
|
||||
if (prev_calculated > 0)
|
||||
{
|
||||
numOfRequiredAtrs++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Checking for stop ...
|
||||
if (IsStopped())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Number of items Copy or not ...
|
||||
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
|
||||
if (copiedATRs <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
// checking for the limit start of calculation of an indicator ...
|
||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
{
|
||||
//
|
||||
// starting index for calculation of all bars ...
|
||||
limit = maxLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// starting number for calculation of new bars
|
||||
limit = prev_calculated - 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
// Calculated Price ...
|
||||
double price = getPrice(
|
||||
atrAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
i);
|
||||
// price = (high[i] + low[i]) / 2;
|
||||
priceBuffer[i] = price;
|
||||
|
||||
//
|
||||
double atr = atrBuffer[i];
|
||||
|
||||
//
|
||||
// Up ...
|
||||
upBuffer[i] = price + (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
// Down ...
|
||||
downBuffer[i] = price - (atrMultiplier * atr);
|
||||
|
||||
//
|
||||
if (close[i] > upBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (close[i] < downBuffer[i - 1])
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
changeOfTrend = 1;
|
||||
}
|
||||
}
|
||||
else if (trendBuffer[i - 1] == 1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = 1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
else if (trendBuffer[i - 1] == -1)
|
||||
{
|
||||
//
|
||||
trendBuffer[i] = -1;
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Down Trend Starting ...
|
||||
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
|
||||
{
|
||||
startBearishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBearishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Up Trend Starting ...
|
||||
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
|
||||
{
|
||||
startBullishTrend = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
startBullishTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
|
||||
{
|
||||
downBuffer[i] = downBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
|
||||
{
|
||||
upBuffer[i] = upBuffer[i - 1];
|
||||
}
|
||||
|
||||
//
|
||||
if (startBearishTrend == 1)
|
||||
{
|
||||
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
if (startBullishTrend == 1)
|
||||
{
|
||||
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the indicator ...
|
||||
|
||||
//
|
||||
double colorIDX = 0;
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
|
||||
//
|
||||
if (trendBuffer[i] == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = downBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 1;
|
||||
}
|
||||
else if (trendBuffer[i] == -1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = upBuffer[i];
|
||||
if (changeOfTrend == 1)
|
||||
{
|
||||
//
|
||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX = 2;
|
||||
}
|
||||
|
||||
//
|
||||
if (showTrends)
|
||||
{
|
||||
mainColorBuffer[i] = colorIDX;
|
||||
}
|
||||
|
||||
//
|
||||
// Filling ...
|
||||
if (fillTrends)
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = mainBuffer[i];
|
||||
fillDownBuffer[i] = close[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
fillUpBuffer[i] = EMPTY_VALUE;
|
||||
fillDownBuffer[i] = EMPTY_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
atrLength >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = atrLength;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// PLOT Buffers ...
|
||||
|
||||
//
|
||||
// FILLINGS ...
|
||||
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
|
||||
|
||||
//
|
||||
// MAIN ...
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
|
||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// DATA Buffers ...
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// TREND ...
|
||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// UP ...
|
||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// DOWN ...
|
||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// PRICE ...
|
||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// TEMPLATE Function ...
|
||||
|
||||
template <typename T>
|
||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
||||
{
|
||||
switch (tprice)
|
||||
{
|
||||
case PRICE_CLOSE:
|
||||
return (close[i]);
|
||||
case PRICE_OPEN:
|
||||
return (open[i]);
|
||||
case PRICE_HIGH:
|
||||
return (high[i]);
|
||||
case PRICE_LOW:
|
||||
return (low[i]);
|
||||
case PRICE_MEDIAN:
|
||||
return ((high[i] + low[i]) / 2.0);
|
||||
case PRICE_TYPICAL:
|
||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
||||
case PRICE_WEIGHTED:
|
||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,457 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Trend Detector Oscillator
|
||||
// --------------------------------------------------
|
||||
// Name: XTD
|
||||
// Description: trend detecting in both sides ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTD Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTD"
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 14; // Market Length
|
||||
input bool drawCrosses = true; // Draw Cross Arrows
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
|
||||
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
|
||||
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
// #property indicator_separate_window
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
// #property indicator_plots 3
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
#define bullishBufferIndex 0
|
||||
#define bearishBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
|
||||
//
|
||||
double bullishBuffer[];
|
||||
double bearishBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
// #property indicator_label1 "XBullPower"
|
||||
// #property indicator_type1 DRAW_LINE
|
||||
// #property indicator_color1 clrLime
|
||||
// #property indicator_style1 STYLE_SOLID
|
||||
// #property indicator_width1 1
|
||||
|
||||
//
|
||||
// #property indicator_label2 "XBearPower"
|
||||
// #property indicator_type2 DRAW_LINE
|
||||
// #property indicator_color2 clrRed
|
||||
// #property indicator_style2 STYLE_SOLID
|
||||
// #property indicator_width2 1
|
||||
|
||||
//
|
||||
// #property indicator_label3 "XSignal"
|
||||
// #property indicator_type3 DRAW_LINE
|
||||
// #property indicator_color3 clrGold
|
||||
// #property indicator_style3 STYLE_DOT
|
||||
// #property indicator_width3 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
int xtdBullishCandleCount = 0;
|
||||
int xtdBearishCandleCount = 0;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 5)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Bullish Buffer ...
|
||||
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bullishBuffer, true);
|
||||
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_CALCULATIONS);
|
||||
// SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
||||
// PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
// PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
|
||||
|
||||
//
|
||||
// Bearish Buffer ...
|
||||
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bearishBuffer, true);
|
||||
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_CALCULATIONS);
|
||||
// SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
||||
// PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
// PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_CALCULATIONS);
|
||||
// SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||
// PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
// PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
// Reset Global Counters ...
|
||||
xtdBullishCandleCount = 0;
|
||||
xtdBearishCandleCount = 0;
|
||||
|
||||
//
|
||||
// Loop through Closes ...
|
||||
for (int i = bar_index; i <= bar_index + length; i++)
|
||||
{
|
||||
for (int j = i + 1; j <= bar_index + length; j++)
|
||||
{
|
||||
//
|
||||
if (close[i] > close[j])
|
||||
{
|
||||
xtdBullishCandleCount++;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[i] < close[j])
|
||||
{
|
||||
xtdBearishCandleCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Power Buffer ...
|
||||
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
|
||||
|
||||
//
|
||||
// Bearish Power Buffer ...
|
||||
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Check and Draw Crosses if it's Specified ...
|
||||
if (drawCrosses)
|
||||
{
|
||||
DrawCrosses(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
double GetState(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Cross Points ...
|
||||
// bullishCrossedOverBearish = 2;
|
||||
// bullishOverBearish = 1;
|
||||
// bullishCrossedUnderBearish = -2;
|
||||
// bullishUnderBearish = -1;
|
||||
// OtherWise = 0;
|
||||
bool isBullishCrossedOverBearish = IsCrossedOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishCrossedUnderBearish = IsCrossedUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishOverBearish = IsOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishUnderBearish = IsUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double result = X_XTD_NEUTURAL;
|
||||
if (isBullishCrossedOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishCrossedUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
|
||||
}
|
||||
else if (isBullishOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_UNDER_BEARISH;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = X_XTD_NEUTURAL;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Crosses ...
|
||||
void DrawCrosses(
|
||||
int bar_index // the bars which required to draw cross arrow on it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double stateValue = GetState(bar_index);
|
||||
|
||||
//
|
||||
bool isOver = stateValue == 2;
|
||||
double low = iLow(_Symbol, _Period, bar_index);
|
||||
double high = iHigh(_Symbol, _Period, bar_index);
|
||||
|
||||
//
|
||||
double price = isOver ? low : high;
|
||||
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
|
||||
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
|
||||
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
|
||||
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
0,
|
||||
crossName,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
arrowColor);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,457 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Trend Detector Oscillator
|
||||
// --------------------------------------------------
|
||||
// Name: XTD
|
||||
// Description: trend detecting in both sides ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTD Oscillator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTD"
|
||||
|
||||
//
|
||||
// XTD Oscillator States ...
|
||||
enum ENUM_X_XTD_STATES
|
||||
{
|
||||
X_XTD_BULLISH_CROSSED_OVER_BEARISH = 2,
|
||||
X_XTD_BULLISH_OVER_BEARISH = 1,
|
||||
X_XTD_NEUTURAL = 0,
|
||||
X_XTD_BULLISH_UNDER_BEARISH = -1,
|
||||
X_XTD_BULLISH_CROSSED_UNDER_BEARISH = -2
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int length = 14; // Market Length
|
||||
input bool drawCrosses = true; // Draw Cross Arrows
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
input uchar bullishArrowCode = 228; // Cross Over Arrow Code
|
||||
input color bullishArrowColor = clrAqua; // Cross Over Arrow Color
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
input uchar bearishArrowCode = 230; // Cross Under Arrow Code
|
||||
input color bearishArrowColor = clrMagenta; // Cross Under Arrow Color
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
||||
|
||||
//
|
||||
// Includes Draw Library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5";
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
// #property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 2
|
||||
// #property indicator_plots 0
|
||||
|
||||
//
|
||||
#define bullishBufferIndex 0
|
||||
#define bearishBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
|
||||
//
|
||||
double bullishBuffer[];
|
||||
double bearishBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XBullPower"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_label2 "XBearPower"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// #property indicator_label3 "XSignal"
|
||||
// #property indicator_type3 DRAW_LINE
|
||||
// #property indicator_color3 clrGold
|
||||
// #property indicator_style3 STYLE_DOT
|
||||
// #property indicator_width3 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
//
|
||||
int xtdBullishCandleCount = 0;
|
||||
int xtdBearishCandleCount = 0;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, length);
|
||||
|
||||
//
|
||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(i, close);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (length >= 5)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Bullish Buffer ...
|
||||
string bullishBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bullishBuffer, true);
|
||||
// SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
|
||||
|
||||
//
|
||||
// Bearish Buffer ...
|
||||
string bearishBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(bearishBuffer, true);
|
||||
// SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
|
||||
ArraySetAsSeries(signalBuffer, true);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_CALCULATIONS);
|
||||
// SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
||||
// PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
||||
// PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(
|
||||
int bar_index,
|
||||
const double &close[])
|
||||
{
|
||||
//
|
||||
// Reset Global Counters ...
|
||||
xtdBullishCandleCount = 0;
|
||||
xtdBearishCandleCount = 0;
|
||||
|
||||
//
|
||||
// Loop through Closes ...
|
||||
for (int i = bar_index; i <= bar_index + length; i++)
|
||||
{
|
||||
for (int j = i + 1; j <= bar_index + length; j++)
|
||||
{
|
||||
//
|
||||
if (close[i] > close[j])
|
||||
{
|
||||
xtdBullishCandleCount++;
|
||||
}
|
||||
|
||||
//
|
||||
if (close[i] < close[j])
|
||||
{
|
||||
xtdBearishCandleCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Power Buffer ...
|
||||
bullishBuffer[bar_index] = MathAbs(xtdBullishCandleCount);
|
||||
|
||||
//
|
||||
// Bearish Power Buffer ...
|
||||
bearishBuffer[bar_index] = MathAbs(xtdBearishCandleCount);
|
||||
|
||||
//
|
||||
// Signal Buffer ...
|
||||
signalBuffer[bar_index] = bullishBuffer[bar_index] - bearishBuffer[bar_index];
|
||||
|
||||
//
|
||||
// Check and Draw Crosses if it's Specified ...
|
||||
if (drawCrosses)
|
||||
{
|
||||
DrawCrosses(bar_index);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
double GetState(
|
||||
int bar_index // Specified Bar Index
|
||||
)
|
||||
{
|
||||
//
|
||||
// Check Cross Points ...
|
||||
// bullishCrossedOverBearish = 2;
|
||||
// bullishOverBearish = 1;
|
||||
// bullishCrossedUnderBearish = -2;
|
||||
// bullishUnderBearish = -1;
|
||||
// OtherWise = 0;
|
||||
bool isBullishCrossedOverBearish = IsCrossedOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishCrossedUnderBearish = IsCrossedUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishOverBearish = IsOver(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
bool isBullishUnderBearish = IsUnder(
|
||||
bullishBuffer,
|
||||
bearishBuffer,
|
||||
bar_index);
|
||||
|
||||
//
|
||||
double result = X_XTD_NEUTURAL;
|
||||
if (isBullishCrossedOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishCrossedUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_CROSSED_UNDER_BEARISH;
|
||||
}
|
||||
else if (isBullishOverBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_OVER_BEARISH;
|
||||
}
|
||||
else if (isBullishUnderBearish)
|
||||
{
|
||||
result = X_XTD_BULLISH_UNDER_BEARISH;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = X_XTD_NEUTURAL;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Crosses ...
|
||||
void DrawCrosses(
|
||||
int bar_index // the bars which required to draw cross arrow on it ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double stateValue = GetState(bar_index);
|
||||
|
||||
//
|
||||
bool isOver = stateValue == 2;
|
||||
double low = iLow(_Symbol, _Period, bar_index);
|
||||
double high = iHigh(_Symbol, _Period, bar_index);
|
||||
|
||||
//
|
||||
double price = isOver ? low : high;
|
||||
datetime time = iTime(_Symbol, _Period, bar_index);
|
||||
ENUM_ARROW_ANCHOR anchor = isOver ? ANCHOR_TOP : ANCHOR_BOTTOM;
|
||||
uchar arrowCode = isOver ? bullishArrowCode : bearishArrowCode;
|
||||
color arrowColor = isOver ? bullishArrowColor : bearishArrowColor;
|
||||
string crossName = "Trend " + (isOver ? "Up" : "Down") + "_" + (string)time + "_" + (string)price;
|
||||
|
||||
//
|
||||
DrawArrow(
|
||||
0,
|
||||
crossName,
|
||||
0,
|
||||
time,
|
||||
price,
|
||||
arrowCode,
|
||||
anchor,
|
||||
arrowColor);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,351 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Candle Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XTM
|
||||
// Description: Trend Magic Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XTM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Constants ...
|
||||
//
|
||||
#define ShortName "XTM"
|
||||
|
||||
//
|
||||
// XTM Indicator States ...
|
||||
enum ENUM_X_XTM_STATES
|
||||
{
|
||||
X_XTM_BULLISH = 1,
|
||||
X_XTM_BEARISH = -1,
|
||||
X_XTM_NEUTURAL = 0,
|
||||
};
|
||||
//
|
||||
// END Constants ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int maPeriod = 14; // Period
|
||||
input int maShift = 0; // Shift
|
||||
input ENUM_MA_METHOD maMethod = MODE_SMA; // Method
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showLine = true; // Show Line
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes Common Library ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// START Buffers ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// maBuffer ...
|
||||
#define maBufferIndex 0
|
||||
#define maColorBufferIndex 1
|
||||
#define stateBufferIndex 2
|
||||
|
||||
double maBuffer[];
|
||||
double maColorBuffer[];
|
||||
double stateBuffer[];
|
||||
|
||||
#property indicator_label1 "XTM"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLime, clrGray, clrRed, CLR_NONE
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//
|
||||
// END Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
int maHandler = INVALID_HANDLE;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Initializing MA Handler ...
|
||||
maHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maPeriod,
|
||||
maShift,
|
||||
maMethod,
|
||||
maAppliedTo);
|
||||
if (maHandler == INVALID_HANDLE)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
//
|
||||
// total Candles on chart ...
|
||||
const int rates_total,
|
||||
//
|
||||
// total calculated Candles on charts ...
|
||||
const int prev_calculated,
|
||||
//
|
||||
// history of Candles Open Time ...
|
||||
const datetime &time[],
|
||||
//
|
||||
// history of Candles Open Price ...
|
||||
const double &open[],
|
||||
//
|
||||
// history of Candles High Price ...
|
||||
const double &high[],
|
||||
//
|
||||
// history of Candles Low Price ...
|
||||
const double &low[],
|
||||
//
|
||||
// history of Candles Close Price ...
|
||||
const double &close[],
|
||||
//
|
||||
// history of Tick Volumes on Candle ...
|
||||
const long &tick_volume[],
|
||||
//
|
||||
// history of Trade Volumes ...
|
||||
const long &volume[],
|
||||
//
|
||||
// history of Candles Spread Price ...
|
||||
const int &spread[])
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
int maxLength = MathMax(0, maPeriod);
|
||||
|
||||
//
|
||||
// Check Calculated Bars ...
|
||||
int maCalculatedBars = BarsCalculated(maHandler);
|
||||
if (maCalculatedBars < maxLength)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
||||
if (copiedMas <= 0)
|
||||
{
|
||||
return prev_calculated;
|
||||
}
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
// Do Buffers Calculation ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
if (maPeriod >= 2)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
string maBufferLabel = "XTM " + "(" + (string)maPeriod + ")";
|
||||
|
||||
//
|
||||
// Ma Buffer ...
|
||||
ArraySetAsSeries(maBuffer, true);
|
||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
||||
|
||||
//
|
||||
// Ma Color Buffer ...
|
||||
ArraySetAsSeries(maColorBuffer, true);
|
||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// State Buffer ...
|
||||
ArraySetAsSeries(stateBuffer, true);
|
||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
string indicatorShortName = "";
|
||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", maPeriod, ")");
|
||||
|
||||
//
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
void CalculateBuffers(int bar_index)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
XOHCL candle;
|
||||
candle.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
double maValue = maBuffer[bar_index];
|
||||
|
||||
//
|
||||
double lineColorIndex =
|
||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
||||
: 1;
|
||||
|
||||
//
|
||||
// Define State Value ...
|
||||
// lineColorIndex == 0 => Bullish => 1;
|
||||
// lineColorIndex == 1 => Neutural => 0;
|
||||
// lineColorIndex == 2 => Bearish => -1;
|
||||
double stateValue =
|
||||
lineColorIndex == 0 ? X_XTM_BULLISH : lineColorIndex == 2 ? X_XTM_BEARISH
|
||||
: X_XTM_NEUTURAL;
|
||||
|
||||
//
|
||||
// Set Ma Buffer Color Index ...
|
||||
maColorBuffer[bar_index] = showLine ? lineColorIndex : 3;
|
||||
|
||||
//
|
||||
// Set State Buffer Value ...
|
||||
stateBuffer[bar_index] = stateValue;
|
||||
}
|
||||
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,231 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XVLM
|
||||
// Description: Volume Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XVLM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include <Math/Stat/Normal.mqh>
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "XVLM"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input int length = 14; // Length
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 0
|
||||
|
||||
///
|
||||
#define volumeBufferIndex 0
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
#define volumeColorBufferIndex 1
|
||||
double volumeColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XVLM"
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrLime, clrRed
|
||||
|
||||
//
|
||||
#define bullishColorIndex 0
|
||||
#define bearishColorIndex 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double volumes[];
|
||||
double distances[];
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
ArrayResize(volumes, maxLength, 0);
|
||||
ArrayResize(distances, maxLength, 0);
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
static int i = maxLength * 2;
|
||||
for (i; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
for (int x = 0; x < length; x++)
|
||||
{
|
||||
//
|
||||
volumes[x] = (double)tick_volume[i - x];
|
||||
distances[x] =
|
||||
(close[i - x] > open[i - x])
|
||||
? high[i - x] - low[i - x]
|
||||
: low[i - x] - high[i - x];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = MathMean(volumes) * MathMean(distances);
|
||||
|
||||
//
|
||||
volumeBuffer[i] = iValue;
|
||||
volumeColorBuffer[i] = iValue > 0
|
||||
? bullishColorIndex
|
||||
: bearishColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
i = rates_total - 1;
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
length >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(volumeColorBufferIndex, volumeColorBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XVLM
|
||||
// Description: Volume Trend Indicator ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XVLM Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include <Math/Stat/Normal.mqh>
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "XVLM"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input int length = 14; // Length
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
///
|
||||
#define volumeBufferIndex 0
|
||||
double volumeBuffer[];
|
||||
|
||||
//
|
||||
#define volumeColorBufferIndex 1
|
||||
double volumeColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XVLM"
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_color1 clrLime, clrRed
|
||||
|
||||
//
|
||||
#define bullishColorIndex 0
|
||||
#define bearishColorIndex 1
|
||||
|
||||
//
|
||||
// Variables ...
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
double volumes[];
|
||||
double distances[];
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
ArrayResize(volumes, maxLength, 0);
|
||||
ArrayResize(distances, maxLength, 0);
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// Here we can handle De Initialization Reasons ...
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
static int i = maxLength * 2;
|
||||
for (i; i < rates_total; i++)
|
||||
{
|
||||
//
|
||||
for (int x = 0; x < length; x++)
|
||||
{
|
||||
//
|
||||
volumes[x] = (double)tick_volume[i - x];
|
||||
distances[x] =
|
||||
(close[i - x] > open[i - x])
|
||||
? high[i - x] - low[i - x]
|
||||
: low[i - x] - high[i - x];
|
||||
}
|
||||
|
||||
//
|
||||
double iValue = MathMean(volumes) * MathMean(distances);
|
||||
|
||||
//
|
||||
volumeBuffer[i] = iValue;
|
||||
volumeColorBuffer[i] = iValue > 0
|
||||
? bullishColorIndex
|
||||
: bearishColorIndex;
|
||||
}
|
||||
|
||||
//
|
||||
i = rates_total - 1;
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
length >= 2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve all Exists Input Max Length ...
|
||||
// use for Start Of Drawing ...
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = length;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(volumeColorBufferIndex, volumeColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
}
|
||||
@@ -0,0 +1,750 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// ---------------------------------------------
|
||||
// Name: XZG
|
||||
// Description: Zogzag Implementation ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XZG Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XZG"
|
||||
|
||||
//
|
||||
// DEFINITIONS ...
|
||||
enum ENUM_X_ZG_SEARCH_MODE
|
||||
{
|
||||
X_ZG_SEARCH_EXTREMUM = 0, // searching for the first extremum
|
||||
X_ZG_SEARCH_PEAK = 1, // searching for the next ZigZag peak
|
||||
X_ZG_SEARCH_VALE = -1 // searching for the next ZigZag vale
|
||||
};
|
||||
|
||||
//
|
||||
// How to Calculate Up and Down Price ...
|
||||
enum ENUM_X_ZG_PRICE_MODE
|
||||
{
|
||||
//
|
||||
X_ZG_PRICE_HIGH_LOW_MODE = 1,
|
||||
X_ZG_PRICE_OPEN_CLOSE_MODE = 2,
|
||||
};
|
||||
|
||||
//
|
||||
// INPUT ...
|
||||
|
||||
//
|
||||
input group "Market";
|
||||
input int depth = 12; // Depth
|
||||
input int deviation = 5; // Deviation
|
||||
input int backStep = 3; // Back Step
|
||||
input ENUM_X_ZG_PRICE_MODE mode = X_ZG_PRICE_HIGH_LOW_MODE; // Mode
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
input bool showZigZag = true; // Show ZigZag
|
||||
input bool showPeaksAndVales = true; // Show Peaks and Vales
|
||||
|
||||
//
|
||||
// BUFFERS ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 4
|
||||
|
||||
//
|
||||
// ZigZag ...
|
||||
|
||||
//
|
||||
#define mainBufferIndex 0
|
||||
#define mainBufferPlotIndex 0
|
||||
double mainBuffer[];
|
||||
|
||||
#define mainColorBufferIndex 1
|
||||
double mainColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label1 "XZG Main"
|
||||
#property indicator_type1 DRAW_COLOR_SECTION
|
||||
#property indicator_color1 CLR_NONE, clrRoyalBlue, clrSaddleBrown
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
|
||||
//
|
||||
// ZigZag Pointer or Line Indicator ...
|
||||
#define arrowBufferIndex 2
|
||||
#define arrowBufferPlotIndex 1
|
||||
double arrowBuffer[];
|
||||
|
||||
//
|
||||
#define arrowColorBufferIndex 3
|
||||
double arrowColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label2 "XZG PV"
|
||||
#property indicator_type2 DRAW_COLOR_ARROW
|
||||
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#define highsBufferIndex 4
|
||||
double highsBuffer[];
|
||||
|
||||
//
|
||||
// Lows ...
|
||||
|
||||
//
|
||||
#define lowsBufferIndex 5
|
||||
double lowsBuffer[];
|
||||
|
||||
//
|
||||
// VARIABLES ...
|
||||
|
||||
//
|
||||
int mRecalc = 3; // Number of last extremes for recalculation
|
||||
|
||||
//
|
||||
// EVENT Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// logTag = ShortName;
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
int OnCalculate(
|
||||
const int rates_total, // Total Bars on Chart ...
|
||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
||||
const datetime &time[], // History of Open Time ...
|
||||
const double &open[], // History of Open Price ...
|
||||
const double &high[], // History of High Price ...
|
||||
const double &low[], // History of Low Price ...
|
||||
const double &close[], // History of Close Price ...
|
||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
||||
const long &volume[], // History of Trade Volumes ...
|
||||
const int &spread[] // History of Spread Price ...
|
||||
)
|
||||
{
|
||||
//
|
||||
double mZGHigh[];
|
||||
double mZGLow[];
|
||||
if (mode == X_ZG_PRICE_OPEN_CLOSE_MODE)
|
||||
{
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGHigh,
|
||||
open
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGLow,
|
||||
close
|
||||
//
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGHigh,
|
||||
high
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
ArrayCopy(
|
||||
mZGLow,
|
||||
low
|
||||
//
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
int zigZagResult = CalcukateZigZag(
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
mZGHigh,
|
||||
mZGLow
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
if (zigZagResult != rates_total)
|
||||
{
|
||||
return zigZagResult;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// CUSTOM Functions ...
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
depth > 0 &&
|
||||
deviation > 0 &&
|
||||
backStep > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Indexes and Styles ...
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Main ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_SHOW_DATA, showZigZag);
|
||||
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetDouble(mainBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Arrow ...
|
||||
|
||||
//
|
||||
SetIndexBuffer(arrowBufferIndex, arrowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW, 159);
|
||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW_SHIFT, 0);
|
||||
PlotIndexSetDouble(arrowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
||||
|
||||
//
|
||||
// Arrow Color ...
|
||||
SetIndexBuffer(arrowColorBufferIndex, arrowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// Highs ...
|
||||
SetIndexBuffer(highsBufferIndex, highsBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// Lows ...
|
||||
SetIndexBuffer(lowsBufferIndex, lowsBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
//
|
||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
void SetIndicatorName()
|
||||
{
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating Zig Zag ...
|
||||
int CalcukateZigZag(
|
||||
const int prev_calculated,
|
||||
const int rates_total,
|
||||
double &high[],
|
||||
double &low[]
|
||||
//
|
||||
)
|
||||
{
|
||||
//
|
||||
if (rates_total < 100)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Variables ...
|
||||
int i = 0;
|
||||
|
||||
//
|
||||
int start = 0;
|
||||
int extreme_counter = 0;
|
||||
int extreme_search = X_ZG_SEARCH_EXTREMUM;
|
||||
int shift = 0;
|
||||
int back = 0;
|
||||
int last_high_pos = 0;
|
||||
int last_low_pos = 0;
|
||||
|
||||
//
|
||||
double val = 0;
|
||||
double res = 0;
|
||||
double curlow = 0;
|
||||
double curhigh = 0;
|
||||
double last_high = 0;
|
||||
double last_low = 0;
|
||||
|
||||
//
|
||||
double colorIDX = 0;
|
||||
double lastZigZagValue = 0;
|
||||
|
||||
//
|
||||
// Initializing ...
|
||||
if (prev_calculated == 0)
|
||||
{
|
||||
//
|
||||
ArrayInitialize(mainBuffer, 0);
|
||||
ArrayInitialize(highsBuffer, 0);
|
||||
ArrayInitialize(lowsBuffer, 0);
|
||||
|
||||
//
|
||||
start = depth;
|
||||
}
|
||||
|
||||
//
|
||||
// Already Calculated Before ...
|
||||
if (prev_calculated > 0)
|
||||
{
|
||||
//
|
||||
i = rates_total - 1;
|
||||
|
||||
//
|
||||
// Searching for the third X_ZG_SEARCH_EXTREMUM from the last UnComplete Bar ...
|
||||
while (extreme_counter < mRecalc && i > rates_total - 100)
|
||||
{
|
||||
//
|
||||
res = mainBuffer[i];
|
||||
if (res != 0)
|
||||
{
|
||||
extreme_counter++;
|
||||
}
|
||||
|
||||
//
|
||||
i--;
|
||||
}
|
||||
|
||||
//
|
||||
i++;
|
||||
start = i;
|
||||
|
||||
//
|
||||
// What type of X_ZG_SEARCH_EXTREMUM we Search for ...
|
||||
if (lowsBuffer[i] != 0)
|
||||
{
|
||||
//
|
||||
curlow = lowsBuffer[i];
|
||||
extreme_search = X_ZG_SEARCH_PEAK;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
curhigh = highsBuffer[i];
|
||||
extreme_search = X_ZG_SEARCH_VALE;
|
||||
}
|
||||
|
||||
//
|
||||
// Clear Values ...
|
||||
for (i = start + 1; i < rates_total && !IsStopped(); i++)
|
||||
{
|
||||
//
|
||||
mainBuffer[i] = 0;
|
||||
lowsBuffer[i] = 0;
|
||||
highsBuffer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Search for High and Low Extremes ...
|
||||
for (shift = start; shift < rates_total && !IsStopped(); shift++)
|
||||
{
|
||||
//
|
||||
// Low ...
|
||||
val = low[Lowest(low, depth, shift)];
|
||||
if (val == last_low)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
last_low = val;
|
||||
|
||||
//
|
||||
if ((low[shift] - val) > deviation * _Point)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
for (back = 1; back <= backStep; back++)
|
||||
{
|
||||
//
|
||||
res = lowsBuffer[shift - back];
|
||||
if ((res != 0) && (res > val))
|
||||
{
|
||||
lowsBuffer[shift - back] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (low[shift] == val)
|
||||
{
|
||||
lowsBuffer[shift] = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
lowsBuffer[shift] = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// High ...
|
||||
val = high[Highest(high, depth, shift)];
|
||||
if (val == last_high)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
last_high = val;
|
||||
|
||||
//
|
||||
if ((val - high[shift]) > deviation * _Point)
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
for (back = 1; back <= backStep; back++)
|
||||
{
|
||||
//
|
||||
res = highsBuffer[shift - back];
|
||||
if ((res != 0) && (res < val))
|
||||
{
|
||||
highsBuffer[shift - back] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (high[shift] == val)
|
||||
{
|
||||
highsBuffer[shift] = val;
|
||||
}
|
||||
else
|
||||
{
|
||||
highsBuffer[shift] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Set Last Value ...
|
||||
if (extreme_search == 0) // Undefined Values ...
|
||||
{
|
||||
//
|
||||
last_low = 0;
|
||||
last_high = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
last_low = curlow;
|
||||
last_high = curhigh;
|
||||
}
|
||||
|
||||
//
|
||||
// Final Selection of Extreme Points for ZigZag ...
|
||||
for (shift = start; shift < rates_total && !IsStopped(); shift++)
|
||||
{
|
||||
//
|
||||
res = 0;
|
||||
|
||||
//
|
||||
switch (extreme_search)
|
||||
{
|
||||
//
|
||||
case X_ZG_SEARCH_EXTREMUM:
|
||||
//
|
||||
if (last_low == 0 && last_high == 0)
|
||||
{
|
||||
//
|
||||
if (highsBuffer[shift] != 0)
|
||||
{
|
||||
//
|
||||
last_high_pos = shift;
|
||||
last_high = high[shift];
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_VALE;
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_high;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (lowsBuffer[shift] != 0)
|
||||
{
|
||||
//
|
||||
last_low_pos = shift;
|
||||
last_low = low[shift];
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_PEAK;
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_low;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
case X_ZG_SEARCH_PEAK:
|
||||
//
|
||||
if (lowsBuffer[shift] != 0 && lowsBuffer[shift] < last_low && highsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
mainBuffer[last_low_pos] = 0;
|
||||
|
||||
//
|
||||
last_low_pos = shift;
|
||||
last_low = lowsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_low;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (highsBuffer[shift] != 0 && lowsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
last_high_pos = shift;
|
||||
last_high = highsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_high;
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_VALE;
|
||||
|
||||
//
|
||||
res = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
//
|
||||
case X_ZG_SEARCH_VALE:
|
||||
//
|
||||
if (highsBuffer[shift] != 0 && highsBuffer[shift] > last_high && lowsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
mainBuffer[last_high_pos] = 0;
|
||||
|
||||
//
|
||||
last_high_pos = shift;
|
||||
last_high = highsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_high;
|
||||
}
|
||||
|
||||
//
|
||||
if (lowsBuffer[shift] != 0 && highsBuffer[shift] == 0)
|
||||
{
|
||||
//
|
||||
last_low_pos = shift;
|
||||
last_low = lowsBuffer[shift];
|
||||
|
||||
//
|
||||
mainBuffer[shift] = last_low;
|
||||
|
||||
//
|
||||
extreme_search = X_ZG_SEARCH_PEAK;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
double iZigZagForColor = lastZigZagValue;
|
||||
double iZigZag = mainBuffer[shift];
|
||||
if (iZigZag == 0 && lastZigZagValue != 0)
|
||||
{
|
||||
arrowBuffer[shift] = lastZigZagValue;
|
||||
}
|
||||
else if (iZigZag != 0)
|
||||
{
|
||||
//
|
||||
lastZigZagValue = iZigZag;
|
||||
arrowBuffer[shift] = lastZigZagValue;
|
||||
}
|
||||
|
||||
//
|
||||
colorIDX =
|
||||
lastZigZagValue > iZigZagForColor
|
||||
? 1
|
||||
: lastZigZagValue < iZigZagForColor
|
||||
? 2
|
||||
: colorIDX;
|
||||
|
||||
//
|
||||
mainColorBuffer[shift] = showZigZag ? colorIDX : 0;
|
||||
arrowColorBuffer[shift] = showPeaksAndVales ? colorIDX : 0;
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// TOOLS ...
|
||||
|
||||
//
|
||||
// Search for the index of the highest bar ...
|
||||
int Highest(
|
||||
const double &mArray[],
|
||||
const int mDepth,
|
||||
const int mStart //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (mStart < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double max = mArray[mStart];
|
||||
result = mStart;
|
||||
|
||||
//
|
||||
// Start searching ...
|
||||
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
|
||||
{
|
||||
//
|
||||
if (mArray[i] > max)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
max = mArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Return index of the highest bar
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Search for the index of the lowest bar ...
|
||||
int Lowest(
|
||||
const double &mArray[],
|
||||
const int mDepth,
|
||||
const int mStart //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (mStart < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double min = mArray[mStart];
|
||||
result = mStart;
|
||||
|
||||
//
|
||||
// Start searching ...
|
||||
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
|
||||
{
|
||||
//
|
||||
if (mArray[i] < min)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
min = mArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Return index of the lowest bar
|
||||
return result;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,652 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center X121EA MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: X121EA
|
||||
// Description: an Exper Advisor which used RSI and MA
|
||||
// to Analyse Market ...
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////x
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
||||
#include "../Classes/x-saherelm.x121.setup.xea.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "X121EA"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
// Common ...
|
||||
input group "Common";
|
||||
input long x121EAMagicNumber = 78692110; // Magic Number
|
||||
input int x121EASlippage = 10; // Slippgae
|
||||
|
||||
//
|
||||
// Symbols ...
|
||||
input group "Symbol(s)";
|
||||
input string x121EASymbols = "EURUSDb,USDCHFb,EURCHFb,USDJPYb,EURJPYb,GBPUSDb"; // Symbols
|
||||
input bool x121EAUseAllSymbols = false; // Use All Available Symbols
|
||||
input bool x121EAUseAllWatchListSymbols = false; // Use All Watch List Symbols
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input bool x121EAAllowLong = true; // Allow Long Trades
|
||||
input bool x121EAAllowShort = true; // Allow Short Trades
|
||||
input int x121EAStartSignallingHoure = 3; // Start Signalling at Specific Time
|
||||
input int x121EAEndSignallingHoure = 22; // End Signalling at Specific Time
|
||||
input int x121EACloseOnSpecificTime = -1; // Close All Trades in Specific Time
|
||||
input int x121EADelayBetweenTwoSignal = 10; // Delay Between two Same Signals
|
||||
input int x121EAReuiredSignalVerifications = 4; // Required Verifications for Signals
|
||||
input bool x121EAExecuteSignalsOnBreakout = false; // Execute Signals On Breakouts
|
||||
input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications from Other Time Frames
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input double x121EAVolume = 0.01; // Static Volume
|
||||
input double x121EATPPoint = 1000; // TP Point
|
||||
input double x121EASLPoint = 1000; // SL Point
|
||||
input bool x121EAIgnoreSL = false; // Ignore Calculated SL
|
||||
input bool x121EAIgnoreTP = false; // Ignore Calculated TP
|
||||
input bool x121EACloseOnOpposit = false; // Close all Positions on Opposit
|
||||
input int x121EAMaxAllowedTrades = 2; // Max Allowed Positions Per Symbol
|
||||
input bool x121EAUseMaxAllowedPerDirection = true; // Use Max Allowed Positions Per Direction
|
||||
input int x121EAMinFreeMargingForOpenTrades = 900; // Min Margin For Opening Trades
|
||||
input bool x121EAIncreaseNextSignalsVolume = true; // Increase Next Signals Volume
|
||||
input double x121EAIncreaseNextSignalsVolumeMultiplier = 1; // Increase Next Signals Volume Multiplier
|
||||
input bool x121EAAcceptNextDirectionalSignalsWhenFirstInProfit = true; // Accept Same Symbol/Type Signal when Last in Profit
|
||||
|
||||
//
|
||||
input group "Trailling";
|
||||
input bool x121EAAllowTrailStop = true; // Enable Trailling Stop Losses
|
||||
input bool x121EADisableTrailingWhenOpposit = true; // Disable Trailling When has Opposite In Drawdown
|
||||
input double x121EAFirstTrailDistance = 100; // Start Trailling Distance
|
||||
input double x121EAFirstTrailPoint = 60; // First Stop Trail
|
||||
input double x121EANextTrailDistance = 50; // Next Trailling Distance
|
||||
input double x121EANextTrailPoint = 25; // Next Trailling Step
|
||||
|
||||
//
|
||||
input group "Supporting";
|
||||
input bool x121EAAllowSupport = false; // Allow Support Signals
|
||||
input bool x121EASupportOnlyForces = false; // Support Only Force Signals
|
||||
double x121EASupportDistance = 0; // Supporting Distance
|
||||
input int x121EAMaxNumberOfSupports = 0; // Max Number of Support Signals
|
||||
input double x121EASupportVolumeMultiplier = 0; // Support Signals Volume Multiplier
|
||||
input double x121EAMaxAllowedSupportVolume = 0; // Max Allowed Support Signals Volume
|
||||
|
||||
//
|
||||
input group "Grid";
|
||||
input bool x121EAAllowGrid = false; // Allow Grid Signals
|
||||
input bool x121EAGridOnlyForces = false; // Grid Only Force Signals
|
||||
input int x121EAMaxNumberOfGrids = 0; // Max Number of Grid Signals
|
||||
input double x121EAGridDistance = 0; // Grid Distance
|
||||
input double x121EAGridVolumeMultiplier = 0; // Grid Volume Multiplier
|
||||
input double x121EAMaxAllowedGridVolume = 0; // Max Allowed Grid Signals Volume
|
||||
|
||||
//
|
||||
input group "Recovery";
|
||||
input bool x121EAAllowRecovery = false; // Allow Recovery Signals
|
||||
input bool x121EARecoverOnlyForces = false; // Recover Only Force Signals
|
||||
input int x121EAMaxNumberOfRecoveries = 0; // Max Number of Recovery Signals
|
||||
input double x121EARecoveryDistance = 0; // Recovery Distance
|
||||
input double x121EARecoveryVolumeMultiplier = 0; // Recovery Volume Multiplier
|
||||
input double x121EAMaxAllowedRecoveryVolume = 0; // Max Allowed Recovery Signals Volume
|
||||
|
||||
//
|
||||
input group "Hedging";
|
||||
input int x121EARestingAfterHedge = 1000; // Resting Seconds After Hedge
|
||||
input double x121EAMinRequiredProfitPerTrade = 0.3; // Minimum Required Profit for Hedging
|
||||
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
input group "Alerts";
|
||||
input bool x121EAEnableAlerts = true; // Enable Alerts
|
||||
input bool x121EALogAlerts = true; // Log Alerts
|
||||
input bool x121EAMailAlerts = false; // Mail Alerts
|
||||
input bool x121EAPushAlerts = false; // Push Alerts
|
||||
input bool x121EATerminalAlerts = false; // Terminal Alerts
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
// Local Variables ...
|
||||
|
||||
//
|
||||
string x121EAUsedSymbols[];
|
||||
XSCX121SetupEA *x121EA;
|
||||
|
||||
//
|
||||
XSCXCTHelper *x121EACTHelper;
|
||||
XSCXCCHelper *x121EACCHelper;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
if (!InitialEA())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// DeInitialization ...
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
// De Initialize XSampleEA Providers ...
|
||||
delete x121EA;
|
||||
|
||||
//
|
||||
delete x121EACTHelper;
|
||||
delete x121EACCHelper;
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
x121EA.OnTick();
|
||||
|
||||
//
|
||||
X121ReportState();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
bool InitialEA()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Bar Timer ...
|
||||
XCTInputs ctInputs;
|
||||
ctInputs.Default();
|
||||
x121EACTHelper = new XSCXCTHelper();
|
||||
result = x121EACTHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ctInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bar Styles ...
|
||||
XCCInputs ccInputs;
|
||||
ccInputs.Default();
|
||||
x121EACCHelper = new XSCXCCHelper();
|
||||
result = x121EACCHelper.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
ccInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TesterHideIndicators(true);
|
||||
|
||||
//
|
||||
string inputSymbols[];
|
||||
int inputSymbolsCount = SplitContent(
|
||||
inputSymbols,
|
||||
x121EASymbols //
|
||||
);
|
||||
|
||||
//
|
||||
string allSymbols[];
|
||||
int allSymbolsCount = GetAllSymbols(
|
||||
allSymbols //
|
||||
);
|
||||
|
||||
//
|
||||
string watchListSymbols[];
|
||||
int watchListSymbolsCount = GetAllSymbols(
|
||||
watchListSymbols,
|
||||
true //
|
||||
);
|
||||
|
||||
//
|
||||
Clean(x121EAUsedSymbols);
|
||||
if (x121EAUseAllSymbols)
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
allSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else if (x121EAUseAllWatchListSymbols)
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
watchListSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else if (IsValidSize(inputSymbolsCount))
|
||||
{
|
||||
//
|
||||
Copy(
|
||||
inputSymbols,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
Add(
|
||||
_Symbol,
|
||||
x121EAUsedSymbols //
|
||||
);
|
||||
}
|
||||
int symbolsCount = ArraySize(x121EAUsedSymbols);
|
||||
result = IsValidSize(symbolsCount);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
x121EA = new XSCX121SetupEA(
|
||||
x121EASlippage,
|
||||
x121EAMagicNumber //
|
||||
);
|
||||
|
||||
//
|
||||
// Configure EA Class Instance ...
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
x121EA.AllowLong(x121EAAllowLong);
|
||||
x121EA.AllowShort(x121EAAllowShort);
|
||||
x121EA.DelayBetweenTwoSignal(x121EADelayBetweenTwoSignal);
|
||||
x121EA.ExecuteSignalsOnBreakout(x121EAExecuteSignalsOnBreakout);
|
||||
x121EA.ReuiredSignalVerifications(x121EAReuiredSignalVerifications);
|
||||
x121EA.GetVerificationFromOtherTimeFrames(x121EAGetVerificationFromOtherTimeFrames);
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
x121EA.Volume(x121EAVolume);
|
||||
x121EA.TPPoint(x121EATPPoint);
|
||||
x121EA.SLPoint(x121EASLPoint);
|
||||
x121EA.IgnoreSL(x121EAIgnoreSL);
|
||||
x121EA.IgnoreTP(x121EAIgnoreTP);
|
||||
x121EA.MaxAllowedTrades(x121EAMaxAllowedTrades);
|
||||
x121EA.IncreaseNextSignalsVolume(x121EAIncreaseNextSignalsVolume);
|
||||
x121EA.UseMaxAllowedPerDirection(x121EAUseMaxAllowedPerDirection);
|
||||
x121EA.MinFreeMargingForOpenTrades(x121EAMinFreeMargingForOpenTrades);
|
||||
x121EA.IncreaseNextSignalsVolumeMultiplier(x121EAIncreaseNextSignalsVolumeMultiplier);
|
||||
x121EA.AcceptNextDirectionalSignalsWhenFirstInProfit(x121EAAcceptNextDirectionalSignalsWhenFirstInProfit);
|
||||
|
||||
//
|
||||
// Protection ...
|
||||
|
||||
//
|
||||
// Signalling ...
|
||||
x121EA.CloseOnOpposit(x121EACloseOnOpposit);
|
||||
x121EA.EndSignallingHoure(x121EAEndSignallingHoure);
|
||||
x121EA.CloseOnSpecificTime(x121EACloseOnSpecificTime);
|
||||
x121EA.StartSignallingHoure(x121EAStartSignallingHoure);
|
||||
|
||||
//
|
||||
// Trailling ...
|
||||
x121EA.AllowTrailStop(x121EAAllowTrailStop);
|
||||
x121EA.NextTrailPoint(x121EANextTrailPoint);
|
||||
x121EA.FirstTrailPoint(x121EAFirstTrailPoint);
|
||||
x121EA.NextTrailDistance(x121EANextTrailDistance);
|
||||
x121EA.FirstTrailDistance(x121EAFirstTrailDistance);
|
||||
x121EA.DisableTrailingWhenOpposit(x121EADisableTrailingWhenOpposit);
|
||||
|
||||
//
|
||||
// Supporting ...
|
||||
x121EA.AllowSupport(x121EAAllowSupport);
|
||||
x121EA.SupportOnlyForces(x121EASupportOnlyForces);
|
||||
x121EA.SupportDistance(x121EASupportDistance);
|
||||
x121EA.MaxNumberOfSupports(x121EAMaxNumberOfSupports);
|
||||
x121EA.SupportVolumeMultiplier(x121EASupportVolumeMultiplier);
|
||||
x121EA.MaxAllowedSupportVolume(x121EAMaxAllowedSupportVolume);
|
||||
|
||||
//
|
||||
// Grid ...
|
||||
x121EA.AllowGrid(x121EAAllowGrid);
|
||||
x121EA.GridOnlyForces(x121EAGridOnlyForces);
|
||||
x121EA.GridDistance(x121EAGridDistance);
|
||||
x121EA.MaxNumberOfGrids(x121EAMaxNumberOfGrids);
|
||||
x121EA.GridVolumeMultiplier(x121EAGridVolumeMultiplier);
|
||||
x121EA.MaxAllowedGridVolume(x121EAMaxAllowedGridVolume);
|
||||
|
||||
//
|
||||
// Recovery ...
|
||||
x121EA.AllowRecovery(x121EAAllowRecovery);
|
||||
x121EA.RecoverOnlyForces(x121EARecoverOnlyForces);
|
||||
x121EA.RecoveryDistance(x121EARecoveryDistance);
|
||||
x121EA.MaxNumberOfRecoveries(x121EAMaxNumberOfRecoveries);
|
||||
x121EA.RecoveryVolumeMultiplier(x121EARecoveryVolumeMultiplier);
|
||||
x121EA.MaxAllowedRecoveryVolume(x121EAMaxAllowedRecoveryVolume);
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
x121EA.RestingAfterHedge(x121EARestingAfterHedge);
|
||||
x121EA.MinProfitPerTrade(x121EAMinRequiredProfitPerTrade);
|
||||
x121EA.MinProfitPerVolumeFactor(x121EAMinRequiredProfitPerVolumeFactor);
|
||||
|
||||
//
|
||||
// Alert ...
|
||||
x121EA.SetAlertPrefix(ShortName);
|
||||
x121EA.SetAlertEnableAlerts(x121EAEnableAlerts);
|
||||
x121EA.SetAlertLogAlerts(x121EALogAlerts);
|
||||
x121EA.SetAlertMailAlerts(x121EAMailAlerts);
|
||||
x121EA.SetAlertPushAlerts(x121EAPushAlerts);
|
||||
x121EA.SetAlertTerminalAlerts(x121EATerminalAlerts);
|
||||
|
||||
//
|
||||
// Configure Indicators ...
|
||||
X121SetupInputs setupInputsDefault;
|
||||
setupInputsDefault.Default();
|
||||
X121PreConfigureStyles(setupInputsDefault);
|
||||
|
||||
//
|
||||
// Prepare Providers and Add them into mX121EA class ...
|
||||
for (int i = 0; i < symbolsCount; i++)
|
||||
{
|
||||
//
|
||||
// Requirements ...
|
||||
string iSymbol = x121EAUsedSymbols[i];
|
||||
ENUM_TIMEFRAMES iHostPeriod = _Period;
|
||||
|
||||
//
|
||||
XSCX121SetupCycles *iSetupCycle;
|
||||
iSetupCycle = new XSCX121SetupCycles();
|
||||
result = iSetupCycle.Init(
|
||||
setupInputsDefault,
|
||||
iSymbol,
|
||||
iHostPeriod //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = x121EA.AddSetup(iSetupCycle);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void X121PreConfigureStyles(X121SetupInputs &inputs)
|
||||
{
|
||||
//
|
||||
// XHTD ...
|
||||
inputs.htdInputs.show = false;
|
||||
|
||||
//
|
||||
// XATSL ...
|
||||
inputs.atslInputs.show = false;
|
||||
|
||||
//
|
||||
// XSLN ...
|
||||
inputs.slnInputs.show = false;
|
||||
|
||||
//
|
||||
// XDMNT ...
|
||||
inputs.dmntInputs.showBull = false;
|
||||
inputs.dmntInputs.showBear = false;
|
||||
|
||||
//
|
||||
// XSTR ...
|
||||
inputs.strInputs.showTrends = false;
|
||||
inputs.strInputs.fillTrends = false;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
inputs.pvInputs.showPeaksAndVales = false;
|
||||
inputs.pvInputs.showLevels = false;
|
||||
inputs.pvInputs.showConsolidations = false;
|
||||
inputs.pvInputs.showFibo1Levels = false;
|
||||
inputs.pvInputs.showFibo2Levels = false;
|
||||
inputs.pvInputs.showFibo3Levels = false;
|
||||
inputs.pvInputs.showFibo4Levels = false;
|
||||
inputs.pvInputs.showFibo5Levels = false;
|
||||
|
||||
//
|
||||
// XMC ...
|
||||
inputs.mcInputs.showSar = false;
|
||||
inputs.mcInputs.showFastMa = false;
|
||||
inputs.mcInputs.showSlowMa = false;
|
||||
inputs.mcInputs.showVerifierMa = false;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
inputs.hkInputs.drawHikenAshi = false;
|
||||
inputs.hkInputs.drawSmoothedHikenAshi = false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
inputs.cheInputs.showLongExit1Line = false;
|
||||
inputs.cheInputs.showShortExit1Line = false;
|
||||
inputs.cheInputs.showLongExit2Line = false;
|
||||
inputs.cheInputs.showShortExit2Line = false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
inputs.ichInputs.showTenkanSen = false;
|
||||
inputs.ichInputs.showKijunSen = false;
|
||||
inputs.ichInputs.showKijunSenPlus = false;
|
||||
inputs.ichInputs.showKijunSenNegative = false;
|
||||
inputs.ichInputs.showChikouSpan = false;
|
||||
inputs.ichInputs.showSenkouSpanA = false;
|
||||
inputs.ichInputs.showSenkouSpanB = false;
|
||||
inputs.ichInputs.showKumo = false;
|
||||
|
||||
//
|
||||
// XMRB ...
|
||||
inputs.mrbInputs.showFastMa = false;
|
||||
inputs.mrbInputs.showSlowMa = false;
|
||||
inputs.mrbInputs.showRibbon = false;
|
||||
|
||||
//
|
||||
// XASCT ...
|
||||
inputs.asctInputs.showLongs = false;
|
||||
inputs.asctInputs.showShorts = false;
|
||||
|
||||
//
|
||||
// XSSLC ...
|
||||
inputs.sslcInputs.showUp = false;
|
||||
inputs.sslcInputs.showDown = false;
|
||||
|
||||
//
|
||||
// XHULL ...
|
||||
inputs.hullInputs.showUpZone = false;
|
||||
inputs.hullInputs.showDownZone = false;
|
||||
}
|
||||
|
||||
//
|
||||
void X121ReportState()
|
||||
{
|
||||
//
|
||||
string comment = NULL;
|
||||
|
||||
//
|
||||
comment =
|
||||
ShortName + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Trading Symbols: " + ToString(ArraySize(x121EAUsedSymbols)) + "\n" + "\n";
|
||||
|
||||
//
|
||||
// Detect What we Want to Show as Comment ...
|
||||
// bool isInForceState = x121EA.ForceState();
|
||||
double bullishScore = 0; // x121EA.GetBullishScore();
|
||||
double bearishScore = 0; // x121EA.GetBearishScore();
|
||||
double drawDownPercent = x121EA.GetDrawdownPercent();
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
(bullishScore > 0 || bearishScore > 0
|
||||
? "Scores:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Bullish: " + ToString(bullishScore) + "\n" +
|
||||
"Bearish: " + ToString(bearishScore) + "\n" +
|
||||
"------------" + "\n"
|
||||
: "") +
|
||||
"Drawdown: " + ToString(drawDownPercent) + "%" + "\n" +
|
||||
// "------------" + "\n" +
|
||||
// "Force State: " + ToString(isInForceState) + "\n" +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = x121EA.mTrader.GetPositions(
|
||||
positions //
|
||||
);
|
||||
if (IsValidSize(positionsCount))
|
||||
{
|
||||
//
|
||||
int longs = 0;
|
||||
double longVolumes = 0;
|
||||
double longProfits = 0;
|
||||
|
||||
//
|
||||
int shorts = 0;
|
||||
double shortVolumes = 0;
|
||||
double shortProfits = 0;
|
||||
|
||||
//
|
||||
// Retrieve Required Informations of Positions ...
|
||||
CountPositions(
|
||||
positions,
|
||||
longs,
|
||||
longProfits,
|
||||
longVolumes,
|
||||
shorts,
|
||||
shortProfits,
|
||||
shortVolumes //
|
||||
);
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
"------------" + "\n" +
|
||||
"Positions: " + "\n" +
|
||||
"------------" + "\n" +
|
||||
(longs <= 0
|
||||
? ""
|
||||
: "\n" + "Longs:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Count: " + ToString(longs) + "\n" +
|
||||
"Profits: " + ToString(longProfits) + "\n" +
|
||||
""
|
||||
//
|
||||
) +
|
||||
//
|
||||
(shorts <= 0
|
||||
? ""
|
||||
: "\n" + "Shorts:" + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Count: " + ToString(shorts) + "\n" +
|
||||
"Profits: " + ToString(shortProfits) + "\n" +
|
||||
""
|
||||
//
|
||||
) +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
if (positionsCount > 1 && x121EAMinRequiredProfitPerTrade > 0 && x121EAMinRequiredProfitPerVolumeFactor > 0)
|
||||
{
|
||||
//
|
||||
double profit = SpecifiedCalculatePositionsProfit(
|
||||
positions //
|
||||
);
|
||||
double requiredProfitForHedge = SpecifiedCalculateRequiredProfitForHedge(
|
||||
positions,
|
||||
x121EAMinRequiredProfitPerTrade,
|
||||
x121EAMinRequiredProfitPerVolumeFactor //
|
||||
);
|
||||
|
||||
//
|
||||
comment +=
|
||||
//
|
||||
"\n" + "Hedging: " + "\n" +
|
||||
"------------" + "\n" +
|
||||
"Profits: " + ToString(profit) + "\n" +
|
||||
"RequiredProft: " + ToString(requiredProfitForHedge) + "\n" +
|
||||
//
|
||||
""
|
||||
//
|
||||
;
|
||||
}
|
||||
|
||||
//
|
||||
if (IsValid(comment))
|
||||
{
|
||||
Comment(comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user