Files
xMQL5/BKPS/14030823/BKPs/14030802-X121/Helpers/x-saherelm.xosc.helper.mq5
T
2024-11-15 10:50:11 +03:30

1343 lines
27 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXOSCHelper
// 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_XOSC_BUFFERS
{
X_OSC_ATR_LINE = 0,
X_OSC_RVI_MAIN_LINE = 1,
X_OSC_RVI_SIGNAL_LINE = 2,
X_OSC_BULL_POWER_LINE = 3,
X_OSC_BEAR_POWER_LINE = 4,
X_OSC_VOLUME_LINE = 5,
X_OSC_RSI_LINE = 6,
X_OSC_CCI_LINE = 7,
X_OSC_MOMENTUM_LINE = 8,
X_OSC_SAR_LINE = 9,
X_OSC_MACD_MAIN_LINE = 10,
X_OSC_MACD_SIGNAL_LINE = 11,
X_OSC_STOCH_MAIN_LINE = 12,
X_OSC_STOCH_SIGNAL_LINE = 13,
X_OSC_STDDEV_LINE = 14,
};
//
// Input Models ...
struct XOSCInputs
{
//
// Props ...
//
// ATR ...
int atrLength; // Length
//
// RVI ...
int rviLength; // Length
//
// BULLPOWER ...
int bullpLength; // Length
//
// BEARPOWER ...
int bearpLength; // Length
//
// VOLUME ...
ENUM_APPLIED_VOLUME volumeAppliedTo; // Applied To
//
// RSI ...
int rsiLength; // Length
ENUM_APPLIED_PRICE rsiAppliedTo; // Applied To
//
// CCI ...
int cciLength; // Length
ENUM_APPLIED_PRICE cciAppliedTo; // Applied To
//
// STDDEV ...
int stddevLength; // Length
int stddevShift; // Shift
ENUM_MA_METHOD stddevMethod; // Mode
ENUM_APPLIED_PRICE stddevAppliedTo; // AppliedTo
//
// MOMENTUM ...
int momentumLength; // Length
ENUM_APPLIED_PRICE momentumAppliedTo; // Applied To
//
// SAR ...
double sarStep; // Step
double sarMaximum; // Maximum
//
// MACD ...
int macdFastLength; // Fast Length
int macdSlowLength; // Slow Length
int macdSignaLength; // Signal Length
ENUM_APPLIED_PRICE macdAppliedTo; // Applied To
//
// STOCHASTIC ...
// The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
int stochKLength; // K Length
int stochDLength; // D Length
int stochSlowing; // Slowing
ENUM_MA_METHOD stochMaMethod; // Ma Method
ENUM_STO_PRICE stochMode; // Calculation Mode
//
// Constructor(s) ...
XOSCInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
atrLength = 0; // Length
rviLength = 0; // Length
bullpLength = 0; // Length
bearpLength = 0; // Length
volumeAppliedTo = VOLUME_TICK; // Applied To
rsiLength = 0; // Length
rsiAppliedTo = PRICE_CLOSE; // Applied To
cciLength = 0; // Length
cciAppliedTo = PRICE_TYPICAL; // Applied To
stddevLength = 0; // Length
stddevShift = 0; // Shift
stddevMethod = MODE_SMA; // Mode
stddevAppliedTo = PRICE_CLOSE; // AppliedTo
momentumLength = 0; // Length
momentumAppliedTo = PRICE_CLOSE; // Applied To
sarStep = 0; // Step
sarMaximum = 0; // Maximum
macdFastLength = 0; // Fast Length
macdSlowLength = 0; // Slow Length
macdSignaLength = 0; // Signal Length
macdAppliedTo = PRICE_CLOSE; // Applied To
stochKLength = 0; // K Length
stochDLength = 0; // D Length
stochSlowing = 0; // Slowing
stochMaMethod = MODE_SMA; // Ma Method
stochMode = STO_LOWHIGH; // Calculation Mode
}
//
// Default ...
void Default()
{
//
atrLength = 14; // Length
rviLength = 10; // Length
bullpLength = 13; // Length
bearpLength = 13; // Length
volumeAppliedTo = VOLUME_TICK; // Applied To
rsiLength = 14; // Length
rsiAppliedTo = PRICE_CLOSE; // Applied To
cciLength = 14; // Length
cciAppliedTo = PRICE_TYPICAL; // Applied To
stddevLength = 20; // Length
stddevShift = 0; // Shift
stddevMethod = MODE_SMA; // Mode
stddevAppliedTo = PRICE_CLOSE; // AppliedTo
momentumLength = 14; // Length
momentumAppliedTo = PRICE_CLOSE; // Applied To
sarStep = 0.02; // Step
sarMaximum = 0.2; // Maximum
macdFastLength = 12; // Fast Length
macdSlowLength = 26; // Slow Length
macdSignaLength = 9; // Signal Length
macdAppliedTo = PRICE_CLOSE; // Applied To
stochKLength = 5; // K Length
stochDLength = 3; // D Length
stochSlowing = 3; // Slowing
stochMaMethod = MODE_SMA; // Ma Method
stochMode = STO_LOWHIGH; // Calculation Mode
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
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 MAx Length ...
int Max()
{
//
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;
}
};
//
// Class ...
class XSCXOSCHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXOSCHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXOSCHelper()
{
//
Clean(atrBuffer);
Clean(rsiBuffer);
Clean(cciBuffer);
Clean(sarBuffer);
Clean(bullPBuffer);
Clean(bearPBuffer);
Clean(stddevBuffer);
Clean(volumeBuffer);
Clean(rviMainBuffer);
Clean(momentumBuffer);
Clean(macdMainBuffer);
Clean(rviSignalBuffer);
Clean(stochMainBuffer);
Clean(macdSignalBuffer);
Clean(stochSignalBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XOSCInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(rviMainBuffer, true);
ArraySetAsSeries(rviSignalBuffer, true);
ArraySetAsSeries(bullPBuffer, true);
ArraySetAsSeries(bearPBuffer, true);
ArraySetAsSeries(volumeBuffer, true);
ArraySetAsSeries(rsiBuffer, true);
ArraySetAsSeries(cciBuffer, true);
ArraySetAsSeries(momentumBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(macdMainBuffer, true);
ArraySetAsSeries(macdSignalBuffer, true);
ArraySetAsSeries(stochMainBuffer, true);
ArraySetAsSeries(stochSignalBuffer, true);
ArraySetAsSeries(stddevBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xosc",
//
// Inputs ...
//
// ATR ...
"",
mInputs.atrLength,
//
// RVI ...
"",
mInputs.rviLength,
//
// Bulls Power ...
"",
mInputs.bullpLength,
//
// Bears Power ...
"",
mInputs.bearpLength,
//
// Voluem ...
"",
mInputs.volumeAppliedTo,
//
// RSI ...
"",
mInputs.rsiLength,
mInputs.rsiAppliedTo,
//
// CCI ...
"",
mInputs.cciLength,
mInputs.cciAppliedTo,
//
// STDDev ...
"",
mInputs.stddevLength,
mInputs.stddevShift,
mInputs.stddevMethod,
mInputs.stddevAppliedTo,
//
// Momentum ...
"",
mInputs.momentumLength,
mInputs.momentumAppliedTo,
//
// SAR ...
"",
mInputs.sarStep,
mInputs.sarMaximum,
//
// MACD ...
"",
mInputs.macdFastLength,
mInputs.macdSlowLength,
mInputs.macdSignaLength,
mInputs.macdAppliedTo,
//
// Stochastic ...
"",
mInputs.stochKLength,
mInputs.stochDLength,
mInputs.stochSlowing,
mInputs.stochMaMethod,
mInputs.stochMode
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XOSCInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XOSCInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs);
}
//
// Buffers ...
//
// ATR ...
//
double GetATR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return atrBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyATR(
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,
atrBuffer,
buffer,
forceClean
//
);
}
//
// RVI ...
//
double GetRVI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return rviMainBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyRVI(
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,
rviMainBuffer,
buffer,
forceClean
//
);
}
//
double GetRVISignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return rviSignalBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyRVISignal(
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,
rviSignalBuffer,
buffer,
forceClean
//
);
}
//
// BULLP ...
//
double GetBullPower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return bullPBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyBullPower(
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 GetBearPower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return bearPBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyBearPower(
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
//
);
}
//
// 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
//
);
}
//
// RSI ...
//
double GetRSI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return rsiBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyRSI(
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,
rsiBuffer,
buffer,
forceClean
//
);
}
//
// CCI ...
//
double GetCCI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return cciBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyCCI(
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,
cciBuffer,
buffer,
forceClean
//
);
}
//
// MOMENTUM ...
//
double GetMomentum(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return momentumBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMomentum(
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,
momentumBuffer,
buffer,
forceClean
//
);
}
//
// SAR ...
//
double GetSAR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return sarBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySAR(
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,
sarBuffer,
buffer,
forceClean
//
);
}
//
// STDDEV ...
//
double GetSTDDEV(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return stddevBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySTDDEV(
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,
stddevBuffer,
buffer,
forceClean
//
);
}
//
// MACD ...
//
double GetMACD(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return macdMainBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMACD(
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,
macdMainBuffer,
buffer,
forceClean
//
);
}
//
double GetMACDSignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return macdSignalBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMACDSignal(
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,
macdSignalBuffer,
buffer,
forceClean
//
);
}
//
// STOCH ...
//
double GetSTOCH(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return stochMainBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySTOCH(
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,
stochMainBuffer,
buffer,
forceClean
//
);
}
//
double GetSTOCHSignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return stochSignalBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySTOCHSignal(
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,
stochSignalBuffer,
buffer,
forceClean
//
);
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XOSCInputs mInputs; // Inputs ...
//
// Buffers ...
double atrBuffer[];
double rviMainBuffer[];
double rviSignalBuffer[];
double bullPBuffer[];
double bearPBuffer[];
double volumeBuffer[];
double rsiBuffer[];
double cciBuffer[];
double momentumBuffer[];
double sarBuffer[];
double macdMainBuffer[];
double macdSignalBuffer[];
double stochMainBuffer[];
double stochSignalBuffer[];
double stddevBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// ATR ...
CopyBuffer(
mHandler,
X_OSC_ATR_LINE,
0,
totalBars,
atrBuffer
//
);
//
// BULLP ...
CopyBuffer(
mHandler,
X_OSC_BULL_POWER_LINE,
0,
totalBars,
bullPBuffer
//
);
//
// BEARP ...
CopyBuffer(
mHandler,
X_OSC_BEAR_POWER_LINE,
0,
totalBars,
bearPBuffer
//
);
//
// VOLUME ...
CopyBuffer(
mHandler,
X_OSC_VOLUME_LINE,
0,
totalBars,
volumeBuffer
//
);
//
// RSI ...
CopyBuffer(
mHandler,
X_OSC_RSI_LINE,
0,
totalBars,
rsiBuffer
//
);
//
// CCI ...
CopyBuffer(
mHandler,
X_OSC_CCI_LINE,
0,
totalBars,
cciBuffer
//
);
//
// MOMENTUM ...
CopyBuffer(
mHandler,
X_OSC_MOMENTUM_LINE,
0,
totalBars,
momentumBuffer
//
);
//
// SAR ...
CopyBuffer(
mHandler,
X_OSC_SAR_LINE,
0,
totalBars,
sarBuffer
//
);
//
// STDDEV ...
CopyBuffer(
mHandler,
X_OSC_STDDEV_LINE,
0,
totalBars,
stddevBuffer
//
);
//
// RVI ...
//
// RVI Main ...
CopyBuffer(
mHandler,
X_OSC_RVI_MAIN_LINE,
0,
totalBars,
rviMainBuffer
//
);
//
// RVI Signal ...
CopyBuffer(
mHandler,
X_OSC_RVI_SIGNAL_LINE,
0,
totalBars,
rviSignalBuffer
//
);
//
// MACD ...
//
// MACD Main ...
CopyBuffer(
mHandler,
X_OSC_MACD_MAIN_LINE,
0,
totalBars,
macdMainBuffer
//
);
//
// MACD Signal ...
CopyBuffer(
mHandler,
X_OSC_MACD_SIGNAL_LINE,
0,
totalBars,
macdSignalBuffer
//
);
//
// STOCH ...
//
// STOCH Main ...
CopyBuffer(
mHandler,
X_OSC_STOCH_MAIN_LINE,
0,
totalBars,
stochMainBuffer
//
);
//
// STOCH Signal ...
CopyBuffer(
mHandler,
X_OSC_STOCH_SIGNAL_LINE,
0,
totalBars,
stochSignalBuffer
//
);
}
};
//
// Tools ...