Files
MQL5Data/Helpers/x-saherelm.x121.xki.helper.mq5
T
2025-12-30 04:31:39 +03:30

1027 lines
22 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XCX121XKIHelper
// 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.x-helper.class.mq5"
// #region Buffers ...
enum ENUM_X121_XKI_BUFFERS
{
//
// KI ...
X121_XKI_KI_LINE = 0,
X121_XKI_KI_COLOR_LINE = 1,
X121_XKI_KI_STATE_LINE = 8,
//
// KI Wave ...
X121_XKI_KI_WAVE_LINE = 2,
X121_XKI_KI_WAVE_RAW_LINE = 13,
X121_XKI_KI_WAVE_COLOR_LINE = 3,
X121_XKI_KI_WAVE_STATE_LINE = 14,
//
// Upper/Lower ...
X121_XKI_KI_UPPER_LINE = 4,
X121_XKI_KI_LOWER_LINE = 5,
//
// MA Fast/Slow ...
X121_XKI_MA_FAST_LINE = 6,
X121_XKI_MA_SLOW_LINE = 7,
//
// ATR ...
X121_XKI_ATR_LINE = 9,
X121_XKI_ATR_RAW_UPPER_LINE = 10,
X121_XKI_ATR_RAW_LOWER_LINE = 11,
//
// RSI ...
X121_XKI_RSI_LINE = 12,
};
// #endregion
// #region Inputs ...
struct X121XKIInputs
{
// #region Props ...
// #region Calculations ...
int kiLength; // KI Length
int maFastLength; // MA Fast Length
int maSlowLength; // MA Slow Length
ENUM_MA_METHOD maMethod; // MA Mode
ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To
int rsiLength; // RSI Length
ENUM_APPLIED_PRICE rsiAppliedTo; // RSI Applied To
int kiWaveSmoothingLength; // RSI KI Wave Smoothing Length
ENUM_X_MA_METHOD kiWaveSmoothingMode; // RSI KI Wave Smoothing Method
double rsiMultiplier; // RSI Multiplier
int atrLength; // ATR Length
double atrMultiplier; // ATR Multiplier
int atrSmoothingLength; // ATR Smoothing Length
ENUM_X_MA_METHOD atrSmoothingMode; // ATR Smoothing Method
ENUM_X_PRICE atrUpperPriceType; // ATR Upper Price Type
ENUM_X_PRICE atrLowerPriceType; // ATR Lower Price Type
// #endregion
// #region Presentations ...
bool showKI; // Show KI
bool showMaFast; // Show Ma Fast
bool showMaSlow; // Show MA Slow
bool showKIWave; // Show KI Wave
bool showKIUpper; // Show KI Upper
bool showKILower; // Show KI Lower
//
int startCalculationForLastBars; // Calculate Last n Bars
// #endregion
// #endregion
//
// Constructor(s) ...
X121XKIInputs()
{
Clean();
}
// #region Tools ...
//
// Clean ...
void Clean()
{
ZeroMemory(this);
}
//
// Default ...
void Default()
{
//
// Calculations ...
kiLength = 26;
maFastLength = 9;
maSlowLength = 26;
maMethod = MODE_EMA;
maAppliedTo = PRICE_CLOSE;
rsiLength = 14;
rsiAppliedTo = PRICE_CLOSE;
kiWaveSmoothingLength = 14;
kiWaveSmoothingMode = X_MA_MODE_EMA;
rsiMultiplier = 0.5;
atrLength = 14;
atrMultiplier = 2;
atrSmoothingLength = 14;
atrSmoothingMode = X_MA_MODE_EMA;
atrUpperPriceType = X_PRICE_HIGH;
atrLowerPriceType = X_PRICE_LOW;
//
// Presentations ...
showKI = true;
showMaFast = true;
showMaSlow = true;
showKIWave = true;
showKIUpper = true;
showKILower = true;
//
startCalculationForLastBars = 1500;
}
//
// Hide ...
void Hide()
{
//
// Presentations ...
showKI = false;
showMaFast = false;
showMaSlow = false;
showKIWave = false;
showKIUpper = false;
showKILower = false;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
// KI ...
kiLength >= 5 &&
//
// ATR ...
atrLength >= 5 &&
//
// RSI ...
rsiLength >= 5
//
;
//
return result;
}
// #endregion
};
// #endregion
// #region Conditions ...
struct X121XKIConditions
{
// #region Commons ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
datetime to;
datetime from;
XOHCL bars[];
// #endregion
// #region Buffers ...
double kiBuffer[];
double kiColorBuffer[];
double kiWaveBuffer[];
double kiWaveColorBuffer[];
double kiUpperBuffer[];
double kiLowerBuffer[];
double maFastBuffer[];
double maSlowBuffer[];
double kiStateBuffer[];
double atrBuffer[];
double atrRawUpperBuffer[];
double atrRawLowerBuffer[];
double rsiBuffer[];
double kiWaveRawBuffer[];
double kiWaveStateBuffer[];
// #endregion
//
// Constructor ...
X121XKIConditions()
{
Clean();
}
// #region Tools ...
/**
* Cleaning Up ...
*/
void Clean()
{
//
// Commons ...
to = NULL;
from = NULL;
time = NULL;
symbol = NULL;
period = NULL;
//
// Buffers ...
//
XClean(kiBuffer);
XClean(kiColorBuffer);
XClean(kiWaveBuffer);
XClean(kiWaveColorBuffer);
XClean(kiUpperBuffer);
XClean(kiLowerBuffer);
XClean(maFastBuffer);
XClean(maSlowBuffer);
XClean(kiStateBuffer);
XClean(atrBuffer);
XClean(atrRawUpperBuffer);
XClean(atrRawLowerBuffer);
XClean(rsiBuffer);
XClean(kiWaveRawBuffer);
XClean(kiWaveStateBuffer);
//
ArraySetAsSeries(kiBuffer, true);
ArraySetAsSeries(kiColorBuffer, true);
ArraySetAsSeries(kiWaveBuffer, true);
ArraySetAsSeries(kiWaveColorBuffer, true);
ArraySetAsSeries(kiUpperBuffer, true);
ArraySetAsSeries(kiLowerBuffer, true);
ArraySetAsSeries(maFastBuffer, true);
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(kiStateBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(atrRawUpperBuffer, true);
ArraySetAsSeries(atrRawLowerBuffer, true);
ArraySetAsSeries(rsiBuffer, true);
ArraySetAsSeries(kiWaveRawBuffer, true);
ArraySetAsSeries(kiWaveStateBuffer, true);
//
ZeroMemory(this);
}
/**
* Retrieve Unique Tag Identifier ...
*
* @return ( string )
*/
string GetTag()
{
return GetToken(this);
}
// #endregion
};
// #endregion
// #region Class ...
class XCX121XKIHelper : public XCBaseHelper
{
//
// Public ...
public:
//
// Constructors ...
XCX121XKIHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XCX121XKIHelper()
{
}
// #region Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121XKIInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xki",
"", // Calculation ...
mInputs.kiLength,
mInputs.maFastLength,
mInputs.maSlowLength,
mInputs.maMethod,
mInputs.maAppliedTo,
mInputs.rsiLength,
mInputs.rsiAppliedTo,
mInputs.kiWaveSmoothingLength,
mInputs.kiWaveSmoothingMode,
mInputs.rsiMultiplier,
mInputs.atrLength,
mInputs.atrMultiplier,
mInputs.atrSmoothingLength,
mInputs.atrSmoothingMode,
mInputs.atrUpperPriceType,
mInputs.atrLowerPriceType,
"", // Presentation ...
mInputs.showKI,
mInputs.showMaFast,
mInputs.showMaSlow,
mInputs.showKIWave,
mInputs.showKIUpper,
mInputs.showKILower,
mInputs.startCalculationForLastBars //
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121XKIInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121XKIInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs //
);
}
//
bool GetConditions(
X121XKIConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = true;
//
if (loopback < 5)
{
loopback = 5;
}
//
conditions.Clean();
//
conditions.symbol = mSymbol;
conditions.period = mPeriod;
conditions.time = TimeCurrent();
//
// Filling Bars ...
int barsCount = GetBars(
conditions.bars,
mSymbol,
mPeriod,
barIndex,
loopback //
);
result = barsCount == loopback;
if (!result)
{
//
conditions.Clean();
//
return result;
}
//
conditions.to = conditions.bars[0].time;
conditions.from = conditions.bars[ArraySize(conditions.bars) - 1].time;
//
int zIndex = barIndex;
// #region Reading Buffers ...
CopyKI(
zIndex,
loopback,
conditions.kiBuffer //
);
CopyKIColor(
zIndex,
loopback,
conditions.kiColorBuffer //
);
CopyKIState(
zIndex,
loopback,
conditions.kiStateBuffer //
);
CopyKIWave(
zIndex,
loopback,
conditions.kiWaveBuffer //
);
CopyKIWaveRaw(
zIndex,
loopback,
conditions.kiWaveRawBuffer //
);
CopyKIWaveColor(
zIndex,
loopback,
conditions.kiWaveColorBuffer //
);
CopyKIWaveState(
zIndex,
loopback,
conditions.kiWaveStateBuffer //
);
CopyKIUpper(
zIndex,
loopback,
conditions.kiUpperBuffer //
);
CopyKILower(
zIndex,
loopback,
conditions.kiLowerBuffer //
);
CopyMAFast(
zIndex,
loopback,
conditions.maFastBuffer //
);
CopyMASlow(
zIndex,
loopback,
conditions.maSlowBuffer //
);
CopyRSI(
zIndex,
loopback,
conditions.rsiBuffer //
);
CopyATR(
zIndex,
loopback,
conditions.atrBuffer //
);
CopyATRRawUpper(
zIndex,
loopback,
conditions.atrRawUpperBuffer //
);
CopyATRRawLower(
zIndex,
loopback,
conditions.atrRawLowerBuffer //
);
// #endregion
//
return result;
}
// #endregion
// #region Buffer Readers ...
// #region KI ...
//
double GetKI(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_LINE,
barIndex //
);
}
//
int CopyKI(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Color ...
//
double GetKIColor(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_COLOR_LINE,
barIndex //
);
}
//
int CopyKIColor(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_COLOR_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI State ...
//
double GetKIState(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_STATE_LINE,
barIndex //
);
}
//
int CopyKIState(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_STATE_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Wave ...
//
double GetKIWave(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_WAVE_LINE,
barIndex //
);
}
//
int CopyKIWave(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_WAVE_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Wave Raw ...
//
double GetKIWaveRaw(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_WAVE_RAW_LINE,
barIndex //
);
}
//
int CopyKIWaveRaw(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_WAVE_RAW_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Wave Color ...
//
double GetKIWaveColor(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_WAVE_COLOR_LINE,
barIndex //
);
}
//
int CopyKIWaveColor(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_WAVE_COLOR_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Wave State ...
//
double GetKIWaveState(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_WAVE_STATE_LINE,
barIndex //
);
}
//
int CopyKIWaveState(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_WAVE_STATE_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Upper ...
//
double GetKIUpper(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_UPPER_LINE,
barIndex //
);
}
//
int CopyKIUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_UPPER_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region KI Lower ...
//
double GetKILower(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_KI_LOWER_LINE,
barIndex //
);
}
//
int CopyKILower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_KI_LOWER_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region MA Fast ...
//
double GetMAFast(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_MA_FAST_LINE,
barIndex //
);
}
//
int CopyMAFast(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_MA_FAST_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region MA Slow ...
//
double GetMASlow(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_MA_SLOW_LINE,
barIndex //
);
}
//
int CopyMASlow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_MA_SLOW_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region RSI ...
//
double GetRSI(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_RSI_LINE,
barIndex //
);
}
//
int CopyRSI(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_RSI_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region ATR ...
//
double GetATR(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_ATR_LINE,
barIndex //
);
}
//
int CopyATR(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_ATR_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region ATR Raw Upper...
//
double GetATRRawUpper(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_ATR_RAW_UPPER_LINE,
barIndex //
);
}
//
int CopyATRRawUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_ATR_RAW_UPPER_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #region ATR Raw Lower...
//
double GetATRRawLower(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)X121_XKI_ATR_RAW_LOWER_LINE,
barIndex //
);
}
//
int CopyATRRawLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)X121_XKI_ATR_RAW_LOWER_LINE,
start,
count,
asSeries //
);
}
// #endregion
// #endregion
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121XKIInputs mInputs; // Inputs ...
};
// #endregion