Files
MQL4Data/Bkp/Used/14020431/Libraries/x-saherelm.indicator.lib.mq4
2024-01-25 04:05:58 +03:30

536 lines
9.2 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL4 Indicator Global Library
// ---------------------------------------------------
// saherelm useful tools and definitions ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Includes library ...
#include "../Libraries/x-saherelm.lib.mq4"
//
// Includes Models library ...
#include "../Libraries/x-saherelm.models.lib.mq4"
//
// START Global Requirement Functions ...
//
//
double GetMaxRangeAllowedTP(
const ENUM_X_SIGNAL_TYPE type,
const XRange &range
) {
//
bool isLongSignal =
type != X_SIGNAL_NONE
&& type == X_SIGNAL_LONG
;
//
double maxAllowedTPRange = ((range.levels - 0.5) * range.rate);
//
double result =
isLongSignal ?
range.lowestLow + maxAllowedTPRange
:
range.highestHigh - maxAllowedTPRange
;
//
return result;
}
//
double GetMaxRangeAllowedEntry(
const ENUM_X_SIGNAL_TYPE type,
const XRange &range
) {
//
bool isLongSignal =
type != X_SIGNAL_NONE
&& type == X_SIGNAL_LONG
;
//
double maxAllowedEntryRange = (range.levels - 1.5) * range.rate;
//
double result =
isLongSignal ?
range.lowestLow + maxAllowedEntryRange
:
range.highestHigh - maxAllowedEntryRange
;
//
return result;
}
//
// Range Verification ...
bool IsRangeVerified(
const int bar_index,
const int marketLen,
const int levels,
const ENUM_X_SIGNAL_TYPE type,
const double entry,
const double tp,
const XRange &range
) {
//
bool isLongSignal =
type == X_SIGNAL_LONG
&& type != X_SIGNAL_NONE
;
//
double maxAllowedTP =
GetMaxRangeAllowedTP(
type,
range
)
;
//
double maxAllowedEntry =
GetMaxRangeAllowedEntry(
type,
range
)
;
//
bool result =
isLongSignal
?
//
entry < maxAllowedEntry
&& tp < maxAllowedTP
:
//
entry > maxAllowedEntry
&& tp > maxAllowedTP
;
//
return result;
}
//
// START Global Requirement Functions ...
//
//
// Signal Range Verification ...
bool IsSignalRangeVerified(
const int bar_index,
const int marketLen,
const int levels,
const XSignal &signal,
const XRange &range
) {
//
bool result =
IsRangeVerified(
bar_index,
marketLen,
levels,
signal.type,
signal.entry,
signal.tp,
range
);
//
return result;
}
//
double ReadXMABuffer(
const int bar_index,
const int buffer_index,
//
const int marketLen,
//
const double stp,
const double mxm,
//
const int shortCycleMult,
const int mediumCycleMult,
const int longCycleMult
) {
//
string xmaIndicatorName = "x-saherelm.x.xma";
//
double result = iCustom(
_Symbol,
_Period,
xmaIndicatorName,
//
// Inputs ...
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult,
MODE_SMA,
//
buffer_index,
bar_index
);
//
return result;
}
//
double ReadXHLBuffer(
const int bar_index,
const int buffer_index,
//
const int marketLen,
//
const int shortCycleMult,
const int mediumCycleMult,
const int longCycleMult
) {
//
string xhlIndicatorName = "x-saherelm.x.hl";
//
double result = iCustom(
_Symbol,
_Period,
xhlIndicatorName,
//
// Inputs ...
marketLen,
shortCycleMult,
mediumCycleMult,
longCycleMult,
MODE_SMA,
//
buffer_index,
bar_index
);
//
return result;
}
//
double ReadADX(
const int bar_index,
const int marketLen,
const int mult
) {
//
double result;
//
int period = marketLen * mult;
//
result = iADX(
_Symbol,
_Period,
period,
PRICE_CLOSE,
MODE_MAIN,
bar_index
);
//
return result;
}
//
XState GetXState(
const int bar_index,
//
const int marketLen,
//
const double stp,
const double mxm,
//
const int shortCycleMult,
const int mediumCycleMult,
const int longCycleMult
) {
//
XState result = {};
//
// Cycle Buffer Indexes ...
int scFastBufferIndex = 0;
int scSlowBufferIndex = 1;
int mcFastBufferIndex = 2;
int mcSlowBufferIndex = 3;
int lcFastBufferIndex = 4;
int lcSlowBufferIndex = 5;
int psarBufferIndex = 6;
//
// HH and LL Buffer Indexes ...
int scHHBufferIndex = 0;
int scLLBufferIndex = 1;
int mcHHBufferIndex = 2;
int mcLLBufferIndex = 3;
int lcHHBufferIndex = 4;
int lcLLBufferIndex = 5;
//
// Short Cycle ...
//
// Fast ...
double scFast = ReadXMABuffer(
bar_index,
scFastBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Slow ...
double scSlow = ReadXMABuffer(
bar_index,
scSlowBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Highest High ...
double scHH = ReadXHLBuffer(
bar_index,
scHHBufferIndex,
//
marketLen,
//
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Lowest Low ...
double scLL = ReadXHLBuffer(
bar_index,
scLLBufferIndex,
//
marketLen,
//
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Integrate Result ...
XCycleState sc = {};
sc.fast = scFast;
sc.slow = scSlow;
sc.hh = scHH;
sc.ll = scLL;
//
// Attach Result ...
result.sc = sc;
//
// Medium Cycle ...
//
// Fast ...
double mcFast = ReadXMABuffer(
bar_index,
mcFastBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Slow ...
double mcSlow = ReadXMABuffer(
bar_index,
mcSlowBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Highest High ...
double mcHH = ReadXHLBuffer(
bar_index,
mcHHBufferIndex,
//
marketLen,
//
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Lowest Low ...
double mcLL = ReadXHLBuffer(
bar_index,
mcLLBufferIndex,
//
marketLen,
//
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
double di = GetMA(
bar_index,
(mediumCycleMult + 1) * marketLen,
0,
MODE_SMA,
PRICE_CLOSE
);
result.di = di;
//
// Integrate Result ...
XCycleState mc = {};
mc.fast = mcFast;
mc.slow = mcSlow;
mc.hh = mcHH;
mc.ll = mcLL;
//
// Attach Result ...
result.mc = mc;
//
// Long Cycle ...
//
// Fast ...
double lcFast = ReadXMABuffer(
bar_index,
lcFastBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Slow ...
double lcSlow = ReadXMABuffer(
bar_index,
lcSlowBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Highest High ...
double lcHH = ReadXHLBuffer(
bar_index,
lcHHBufferIndex,
//
marketLen,
//
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Lowest Low ...
double lcLL = ReadXHLBuffer(
bar_index,
lcLLBufferIndex,
//
marketLen,
//
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
// Integrate Result ...
XCycleState lc = {};
lc.fast = lcFast;
lc.slow = lcSlow;
lc.hh = lcHH;
lc.ll = lcLL;
//
// Attach Result ...
result.lc = lc;
//
// Parabolic SAR ...
double psar = ReadXMABuffer(
bar_index,
psarBufferIndex,
//
marketLen,
stp,
mxm,
shortCycleMult,
mediumCycleMult,
longCycleMult
);
//
result.parabolicSAR = psar;
//
return result;
}
//
// END XMA Data ...
//
//
// END Indicator Reading Data ...
//