Initial Commit ...
This commit is contained in:
@@ -0,0 +1,450 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 ...
|
||||
//
|
||||
//
|
||||
// Reading specified Buffer From ADX Indicator ...
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading specified Buffer from XHL Indicator ...
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading ADX Values ...
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Pivot States ...
|
||||
XPvtState GetPVTState(
|
||||
const int bar_index,
|
||||
const int marketLen
|
||||
) {
|
||||
//
|
||||
XPvtState result = {};
|
||||
|
||||
//
|
||||
double hh = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double ho = GetMarketHighestOpen(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double hc = GetMarketHighestClose(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double hl = GetMarketHighestLow(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double ll = GetMarketLowestLow(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double lo = GetMarketLowestOpen(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double lc = GetMarketLowestClose(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double lh = GetMarketLowestHigh(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
// Filling Result ...
|
||||
//
|
||||
result.hh = hh;
|
||||
result.ho = ho;
|
||||
result.hc = hc;
|
||||
result.hl = hl;
|
||||
|
||||
//
|
||||
result.ll = ll;
|
||||
result.lo = lo;
|
||||
result.lc = lc;
|
||||
result.lh = lh;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate XRange from Market ...
|
||||
static XRState lastXRState;
|
||||
XRState GetXRange(
|
||||
const int bar_index,
|
||||
const int rangeMarketLength
|
||||
) {
|
||||
//
|
||||
XRState result = {};
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
int marketBarIndex = bar_index + rangeMarketLength;
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
//
|
||||
int hhIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
marketBarIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double hh = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhIdx
|
||||
);
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
//
|
||||
int llIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
marketBarIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double ll = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llIdx
|
||||
);
|
||||
|
||||
//
|
||||
if (lastXRState.start == 0) {
|
||||
//
|
||||
lastXRState.start = barTime;
|
||||
lastXRState.length = rangeMarketLength;
|
||||
|
||||
//
|
||||
lastXRState.hh = hh;
|
||||
lastXRState.ll = ll;
|
||||
|
||||
//
|
||||
// Middle ...
|
||||
double mid = (hh + ll) / 2;
|
||||
lastXRState.mid = mid;
|
||||
} else {
|
||||
//
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lastXRState.start
|
||||
);
|
||||
|
||||
//
|
||||
if (startBarIndex - bar_index >= rangeMarketLength) {
|
||||
//
|
||||
lastXRState.start = barTime;
|
||||
lastXRState.length = rangeMarketLength;
|
||||
|
||||
//
|
||||
lastXRState.hh = hh;
|
||||
lastXRState.ll = ll;
|
||||
|
||||
//
|
||||
// Middle ...
|
||||
double mid = (hh + ll) / 2;
|
||||
lastXRState.mid = mid;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = lastXRState;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading XTPowState from Indicatoe ...
|
||||
XTPOWState GetXTPowState(
|
||||
const int bar_index,
|
||||
const int marketLen
|
||||
) {
|
||||
//
|
||||
XTPOWState result = {};
|
||||
|
||||
//
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
double signal = 0;
|
||||
|
||||
//
|
||||
string indicatorName = "x-saherelm.xtpow";
|
||||
|
||||
//
|
||||
int pUpIndex = 0;
|
||||
int pDownIndex = 1;
|
||||
int signalIndex = 2;
|
||||
|
||||
//
|
||||
powerUp = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
marketLen,
|
||||
//
|
||||
pUpIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
powerDown = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
marketLen,
|
||||
//
|
||||
pDownIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
signal = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
marketLen,
|
||||
//
|
||||
signalIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
result.signal = signal;
|
||||
result.powerUp = powerUp;
|
||||
result.powerDown = powerDown;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading XRState From Indicator ...
|
||||
XRState ReadXRange(
|
||||
const int bar_index,
|
||||
const int marketLen
|
||||
) {
|
||||
//
|
||||
XRState result = {};
|
||||
|
||||
//
|
||||
// Define Buffer Indexes ...
|
||||
int hhBufferIndex = 0;
|
||||
int llBufferIndex = 1;
|
||||
int midBufferIndex = 2;
|
||||
|
||||
//
|
||||
string indicatorName = "x-saherelm.xrange";
|
||||
|
||||
//
|
||||
// Read Values From XRange Indicator ...
|
||||
|
||||
//
|
||||
double hh = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
//
|
||||
hhBufferIndex, // Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double ll = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
//
|
||||
llBufferIndex, // Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double mid = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
//
|
||||
midBufferIndex, // Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// Filling Result ...
|
||||
result.hh = hh;
|
||||
result.ll = ll;
|
||||
result.mid = mid;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Indicator Reading Data ...
|
||||
//
|
||||
Reference in New Issue
Block a user