Files
MQL5Data/Helpers/x-saherelm.x121.xoscs.helper.mq5
T
2025-04-10 03:03:10 +03:30

2012 lines
39 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XCX121XOCSHelper
// 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"
//
// Buffers ...
enum ENUM_X121_XOSCS_BUFFERS
{
//
// https://www.mql5.com/en/articles/11467 ...
X121_XOSCS_XAC_LINE = 0,
// https://www.mql5.com/en/articles/10993 ...
X121_XOSCS_XAD_LINE = 1,
// https://www.mql5.com/en/articles/10715 ...
X121_XOSCS_XADX_LINE = 2,
X121_XOSCS_XADX_P_LINE = 3,
X121_XOSCS_XADX_N_LINE = 4,
// https://www.mql5.com/en/articles/10748 ...
X121_XOSCS_XATR_LINE = 5,
// https://www.mql5.com/en/articles/10592 ...
X121_XOSCS_XCCI_LINE = 6,
// https://www.mql5.com/en/articles/10528 ...
X121_XOSCS_XRSI_LINE = 7,
// https://www.mql5.com/en/articles/11037 ...
X121_XOSCS_XMFI_LINE = 8,
// https://www.mql5.com/en/articles/11425 ...
X121_XOSCS_XRVI_LINE = 9,
X121_XOSCS_XRVI_S_LINE = 10,
// https://www.mql5.com/en/articles/10674 ...
X121_XOSCS_XMACD_LINE = 11,
X121_XOSCS_XMACD_S_LINE = 12,
// https://www.mql5.com/en/articles/10547 ...
X121_XOSCS_XMOMENTUM_LINE = 13,
// https://www.mql5.com/en/articles/10692 ..
X121_XOSCS_XSTOCHASTIC_LINE = 14,
X121_XOSCS_XSTOCHASTIC_S_LINE = 15,
};
//
// Inputs ...
struct X121XOCSInputs
{
//
// Props ...
//
// Accumulation/Distribution ...
ENUM_APPLIED_VOLUME adAppliedTo; // Applied To
//
// ADX ...
int adxLength; // Length
//
// ATR ...
int atrLength; // Length
//
// CCI ...
int cciLength; // Length
ENUM_APPLIED_PRICE cciAppliedTo; // Applied To
//
// RSI ...
int rsiLength; // Length
ENUM_APPLIED_PRICE rsiAppliedTo; // Applied To
//
// MFI ...
int mfiLength; // Length
ENUM_APPLIED_VOLUME mfiAppliedTo; // Applied To
//
// RVI ...
int rviLength; // Length
//
// MACD ...
int macdFastLength; // Fast EMA Length
int macdSlowLength; // Slow EMA Length
int macdSignalLength; // Signal Length
ENUM_APPLIED_PRICE macdAppliedTo; // Applied To
//
// Momentum ...
int momentumLength; // Length
ENUM_APPLIED_PRICE momentumAppliedTo; // Applied To
//
// Stochastic ...
int stochasticKLength; // K Length (Bars for Calculation)
int stochasticDLength; // D Length (first Smoothing)
int stochasticSmoothingLength; // Smoothing Length
ENUM_MA_METHOD stochasticSmoothingMethod; // Smoothing Method
ENUM_STO_PRICE stochasticAppliedTo; // Applied To
//
// Presentation ...
int startCalculationForLastBars; // Calculate Last n Bars
//
// Constructor(s) ...
X121XOCSInputs()
{
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
// Accumulation/Distribution ...
adAppliedTo = VOLUME_TICK; // Applied To
//
// ADX ...
adxLength = 0; // Length
//
// ATR ...
atrLength = 0; // Length
//
// CCI ...
cciLength = 0; // Length
cciAppliedTo = PRICE_TYPICAL; // Applied To
//
// RSI ...
rsiLength = 0; // Length
rsiAppliedTo = PRICE_CLOSE; // Applied To
//
// MFI ...
mfiLength = 0; // Length
mfiAppliedTo = VOLUME_TICK; // Applied To
//
// RVI ...
rviLength = 0; // Length
//
// MACD ...
macdFastLength = 0; // Fast EMA Length
macdSlowLength = 0; // Slow EMA Length
macdSignalLength = 0; // Signal Length
macdAppliedTo = PRICE_CLOSE; // Applied To
//
// Momentum ...
momentumLength = 0; // Length
momentumAppliedTo = PRICE_CLOSE; // Applied To
//
// Stochastic ...
stochasticKLength = 0; // K Length (Bars for Calculation)
stochasticDLength = 0; // D Length (first Smoothing)
stochasticSmoothingLength = 0; // Smoothing Length
stochasticSmoothingMethod = MODE_SMA; // Smoothing Method
stochasticAppliedTo = STO_LOWHIGH; // Applied To
//
// Presentation ...
startCalculationForLastBars = 0; // Calculate Last n Bars
//
ZeroMemory(this);
}
//
// Default ...
void Default()
{
//
// Accumulation/Distribution ...
adAppliedTo = VOLUME_TICK; // Applied To
//
// ADX ...
adxLength = 14; // Length
//
// ATR ...
atrLength = 14; // Length
//
// CCI ...
cciLength = 14; // Length
cciAppliedTo = PRICE_TYPICAL; // Applied To
//
// RSI ...
rsiLength = 14; // Length
rsiAppliedTo = PRICE_CLOSE; // Applied To
//
// MFI ...
mfiLength = 14; // Length
mfiAppliedTo = VOLUME_TICK; // Applied To
//
// RVI ...
rviLength = 14; // Length
//
// MACD ...
macdFastLength = 12; // Fast EMA Length
macdSlowLength = 26; // Slow EMA Length
macdSignalLength = 9; // Signal Length
macdAppliedTo = PRICE_CLOSE; // Applied To
//
// Momentum ...
momentumLength = 14; // Length
momentumAppliedTo = PRICE_CLOSE; // Applied To
//
// Stochastic ...
stochasticKLength = 5; // K Length (Bars for Calculation)
stochasticDLength = 3; // D Length (first Smoothing)
stochasticSmoothingLength = 3; // Smoothing Length
stochasticSmoothingMethod = MODE_SMA; // Smoothing Method
stochasticAppliedTo = STO_LOWHIGH; // Applied To
//
// Presentation ...
startCalculationForLastBars = 1000; // Calculate Last n Bars
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
adxLength > 0 &&
atrLength > 0 &&
cciLength > 0 &&
rsiLength > 0 &&
mfiLength > 0 &&
rviLength > 0 &&
//
macdFastLength > 0 &&
macdSlowLength > 0 &&
macdSignalLength > 0 &&
macdFastLength < macdSlowLength &&
//
stochasticKLength > 0 &&
stochasticDLength > 0 &&
stochasticSmoothingLength > 0 &&
//
momentumLength > 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(adxLength, atrLength);
result = MathMax(result, cciLength);
result = MathMax(result, rsiLength);
result = MathMax(result, mfiLength);
result = MathMax(result, rviLength);
result = MathMax(result, momentumLength);
result = MathMax(result, macdFastLength);
result = MathMax(result, macdSlowLength);
result = MathMax(result, macdSignalLength);
result = MathMax(result, stochasticKLength);
result = MathMax(result, stochasticDLength);
result = MathMax(result, stochasticSmoothingLength);
//
return result;
}
};
//
// Conditions ...
struct X121XOCSConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double acBuffer[];
double adBuffer[];
double atrBuffer[];
double cciBuffer[];
double rsiBuffer[];
double mfiBuffer[];
double rviBuffer[];
double adxBuffer[];
double adxpBuffer[];
double adxnBuffer[];
double macdBuffer[];
double momentumBuffer[];
double rviSignalBuffer[];
double macdSignalBuffer[];
double stochasticBuffer[];
double stochasticSignalBuffer[];
//
// Conditions ...
//
// Constructor ...
X121XOCSConditions()
{
Clean();
}
//
// Tools ...
/**
* Cleaning Up ...
*/
void Clean()
{
//
// Commons ...
symbol = NULL;
period = NULL;
time = NULL;
//
// Buffers ...
//
Clean(acBuffer);
Clean(adBuffer);
Clean(atrBuffer);
Clean(cciBuffer);
Clean(rsiBuffer);
Clean(mfiBuffer);
Clean(rviBuffer);
Clean(adxBuffer);
Clean(adxpBuffer);
Clean(adxnBuffer);
Clean(macdBuffer);
Clean(momentumBuffer);
Clean(rviSignalBuffer);
Clean(macdSignalBuffer);
Clean(stochasticBuffer);
Clean(stochasticSignalBuffer);
//
ArraySetAsSeries(acBuffer, true);
ArraySetAsSeries(adBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(cciBuffer, true);
ArraySetAsSeries(rsiBuffer, true);
ArraySetAsSeries(mfiBuffer, true);
ArraySetAsSeries(rviBuffer, true);
ArraySetAsSeries(adxBuffer, true);
ArraySetAsSeries(adxpBuffer, true);
ArraySetAsSeries(adxnBuffer, true);
ArraySetAsSeries(macdBuffer, true);
ArraySetAsSeries(momentumBuffer, true);
ArraySetAsSeries(rviSignalBuffer, true);
ArraySetAsSeries(macdSignalBuffer, true);
ArraySetAsSeries(stochasticBuffer, true);
ArraySetAsSeries(stochasticSignalBuffer, true);
//
// Conditions ...
//
ZeroMemory(this);
}
/**
* Generate Conditions Scores ...
*
* @param bullishScore: Double, Directional Scores Reference ...
* @param bearishScore: Double, Directional Scores Reference ...
*/
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
double score = 1;
double minScore = 0.5;
double highScore = 1.5;
// //
// if (isSarBullish)
// {
// bullishScore += minScore;
// }
// if (isSarSwitchedToBullish)
// {
// bullishScore += score;
// }
// //
// if (isSarBearish)
// {
// bearishScore += minScore;
// }
// if (isSarSwitchedToBearish)
// {
// bearishScore += score;
// }
}
/**
* Generate Summary String for Represent Conditions State ...
*
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
* @param includeScores: Boolean, Attach Scores Representations on Result ...
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
* @param separator: String, Separate Lines ...
*
* @return ( string )
*/
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 =
//
"-----------------------" + separator +
"XOSCS: " + separator +
"-----------------------" + separator +
// ToString("isSarBullish", isSarBullish, ignoreFalseConditions, separator) +
//
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
/**
* Retrieve nique Tag Identifier ...
*
* @return ( string )
*/
string GetTag()
{
return GetTypeName(this);
}
};
//
// Helper Class Implementation ...
class XCX121XOCSHelper : XCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XCX121XOCSHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XCX121XOCSHelper()
{
//
mInputs.Clean();
//
// Clean(x3maFastBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121XOCSInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
// ArraySetAsSeries(x3maFastBuffer, true);
//
mInputs = inputs;
//
// mHandler = iCustom(
// mSymbol,
// mPeriod,
// "x-saherelm.x121.x3ma",
// //
// // Inputs ...
// //
// // Market ...
// "",
// mInputs.x3maFastMALength,
// mInputs.x3maMidMALength,
// mInputs.x3maSlowMALength,
// mInputs.x3maMaMethod,
// mInputs.x3maMaAppliedTo,
// //
// // Presentation ...
// "",
// //
// mInputs.startCalculationForLastBars,
// //
// mInputs.showX3MaFast,
// mInputs.showX3MaMid,
// mInputs.showX3MaSlow
// //
// );
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121XOCSInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121XOCSInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Readers ...
//
// AC ...
//
double GetAC(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(acBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return acBuffer[barIndex];
}
//
int CopyAC(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
acBuffer,
buffer,
forceClean
//
);
}
//
// AD ...
//
double GetAD(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(adBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return adBuffer[barIndex];
}
//
int CopyAD(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
adBuffer,
buffer,
forceClean
//
);
}
//
// ADX ...
//
double GetADX(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(adxBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return adxBuffer[barIndex];
}
//
int CopyADX(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
adxBuffer,
buffer,
forceClean
//
);
}
//
// ADXP ...
//
double GetADXP(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(adxpBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return adxpBuffer[barIndex];
}
//
int CopyADXP(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
adxpBuffer,
buffer,
forceClean
//
);
}
//
// ADXN ...
//
double GetADXN(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(adxnBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return adxnBuffer[barIndex];
}
//
int CopyADXN(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
adxnBuffer,
buffer,
forceClean
//
);
}
//
// ATR ...
//
double GetATR(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(atrBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
atrBuffer,
buffer,
forceClean
//
);
}
//
// CCI ...
//
double GetCCI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(cciBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return cciBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
cciBuffer,
buffer,
forceClean
//
);
}
//
// RSI ...
//
double GetRSI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(rsiBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return rsiBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
rsiBuffer,
buffer,
forceClean
//
);
}
//
// MFI ...
//
double GetMFI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(mfiBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return mfiBuffer[barIndex];
}
//
int CopyMFI(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
mfiBuffer,
buffer,
forceClean
//
);
}
//
// Momentum ...
//
double GetMomentum(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(momentumBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return momentumBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
momentumBuffer,
buffer,
forceClean
//
);
}
//
// RVI ...
//
double GetRVI(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(rviBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return rviBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
rviBuffer,
buffer,
forceClean
//
);
}
//
// RVI Signal ...
//
double GetRVISignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(rviSignalBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return rviSignalBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
rviSignalBuffer,
buffer,
forceClean
//
);
}
//
// MACD ...
//
double GetMACD(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(macdBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return macdBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
macdBuffer,
buffer,
forceClean
//
);
}
//
// MACD Signal ...
//
double GetMACDSignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(macdSignalBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return macdSignalBuffer[barIndex];
}
//
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(start);
//
// Copy Items ...
return Copy(
0,
count,
macdSignalBuffer,
buffer,
forceClean
//
);
}
//
// Stochastic ...
//
double GetStochastic(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(stochasticBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return stochasticBuffer[barIndex];
}
//
int CopyStochastic(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
stochasticBuffer,
buffer,
forceClean
//
);
}
//
// Stochastic Signal ...
//
double GetStochasticSignal(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(stochasticSignalBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return stochasticSignalBuffer[barIndex];
}
//
int CopyStochasticSignal(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
stochasticSignalBuffer,
buffer,
forceClean
//
);
}
//
void Free() override
{
Cleanup(10);
}
//
bool GetConditions(
X121XOCSConditions &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();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
XOHCL zBar;
result = zBar.Init(
mSymbol,
mPeriod,
zIndex //
);
if (!result)
{
return result;
}
//
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
cIndex //
);
if (!result)
{
return result;
}
//
XOHCL pBar;
result = pBar.Init(
mSymbol,
mPeriod,
pIndex //
);
if (!result)
{
return result;
}
//
// Buffers ...
//
CopyAC(
zIndex,
loopback,
conditions.acBuffer //
);
//
CopyAD(
zIndex,
loopback,
conditions.adBuffer //
);
//
CopyADX(
zIndex,
loopback,
conditions.adxBuffer //
);
//
CopyADXP(
zIndex,
loopback,
conditions.adxpBuffer //
);
//
CopyADXN(
zIndex,
loopback,
conditions.adxnBuffer //
);
//
CopyATR(
zIndex,
loopback,
conditions.atrBuffer //
);
//
CopyCCI(
zIndex,
loopback,
conditions.cciBuffer //
);
//
CopyRSI(
zIndex,
loopback,
conditions.rsiBuffer //
);
//
CopyMFI(
zIndex,
loopback,
conditions.mfiBuffer //
);
//
CopyMomentum(
zIndex,
loopback,
conditions.momentumBuffer //
);
//
CopyRVI(
zIndex,
loopback,
conditions.rviBuffer //
);
//
CopyRVISignal(
zIndex,
loopback,
conditions.rviSignalBuffer //
);
//
CopyMACD(
zIndex,
loopback,
conditions.macdBuffer //
);
//
CopyMACDSignal(
zIndex,
loopback,
conditions.macdSignalBuffer //
);
//
CopyStochastic(
zIndex,
loopback,
conditions.stochasticBuffer //
);
//
CopyStochasticSignal(
zIndex,
loopback,
conditions.stochasticSignalBuffer //
);
//
// Conditions ...
//
int cIDX = 1;
int pIDX = cIDX + 1;
//
Cleanup();
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121XOCSInputs mInputs; // Inputs ...
//
// Buffers ...
double acBuffer[];
double adBuffer[];
double atrBuffer[];
double cciBuffer[];
double rsiBuffer[];
double mfiBuffer[];
double rviBuffer[];
double adxBuffer[];
double adxpBuffer[];
double adxnBuffer[];
double macdBuffer[];
double momentumBuffer[];
double rviSignalBuffer[];
double macdSignalBuffer[];
double stochasticBuffer[];
double stochasticSignalBuffer[];
//
void Calculate(
int barIndex = 0,
int maxRequiredBars = 100 //
)
{
//
// Buffers ...
if (barIndex < 0)
{
barIndex = 0;
}
//
// AC ...
CopyBuffer(
mHandler,
X121_XOSCS_XAC_LINE,
barIndex,
maxRequiredBars,
acBuffer //
);
//
// AD ...
CopyBuffer(
mHandler,
X121_XOSCS_XAD_LINE,
barIndex,
maxRequiredBars,
adBuffer //
);
//
// ADX ...
CopyBuffer(
mHandler,
X121_XOSCS_XADX_LINE,
barIndex,
maxRequiredBars,
adxBuffer //
);
//
// ADX P ...
CopyBuffer(
mHandler,
X121_XOSCS_XADX_P_LINE,
barIndex,
maxRequiredBars,
adxpBuffer //
);
//
// ADX N ...
CopyBuffer(
mHandler,
X121_XOSCS_XADX_N_LINE,
barIndex,
maxRequiredBars,
adxnBuffer //
);
//
// ATR ...
CopyBuffer(
mHandler,
X121_XOSCS_XATR_LINE,
barIndex,
maxRequiredBars,
atrBuffer //
);
//
// CCI ...
CopyBuffer(
mHandler,
X121_XOSCS_XCCI_LINE,
barIndex,
maxRequiredBars,
cciBuffer //
);
//
// RSI ...
CopyBuffer(
mHandler,
X121_XOSCS_XRSI_LINE,
barIndex,
maxRequiredBars,
rsiBuffer //
);
//
// MFI ...
CopyBuffer(
mHandler,
X121_XOSCS_XMFI_LINE,
barIndex,
maxRequiredBars,
mfiBuffer //
);
//
// MOMENTUM ...
CopyBuffer(
mHandler,
X121_XOSCS_XMOMENTUM_LINE,
barIndex,
maxRequiredBars,
momentumBuffer //
);
//
// RVI ...
CopyBuffer(
mHandler,
X121_XOSCS_XRVI_LINE,
barIndex,
maxRequiredBars,
rviBuffer //
);
//
// RVI Signal ...
CopyBuffer(
mHandler,
X121_XOSCS_XRVI_S_LINE,
barIndex,
maxRequiredBars,
rviSignalBuffer //
);
//
// MACD ...
CopyBuffer(
mHandler,
X121_XOSCS_XMACD_LINE,
barIndex,
maxRequiredBars,
macdBuffer //
);
//
// MACD Signal ...
CopyBuffer(
mHandler,
X121_XOSCS_XMACD_S_LINE,
barIndex,
maxRequiredBars,
macdSignalBuffer //
);
//
// STOCHASTIC ...
CopyBuffer(
mHandler,
X121_XOSCS_XSTOCHASTIC_LINE,
barIndex,
maxRequiredBars,
stochasticBuffer //
);
//
// STOCHASTIC Signal ...
CopyBuffer(
mHandler,
X121_XOSCS_XSTOCHASTIC_S_LINE,
barIndex,
maxRequiredBars,
stochasticSignalBuffer //
);
}
//
void Cleanup(
int maxAllowed = 100 //
)
{
//
CleanupArray(
acBuffer,
maxAllowed //
);
//
CleanupArray(
adBuffer,
maxAllowed //
);
//
CleanupArray(
atrBuffer,
maxAllowed //
);
//
CleanupArray(
cciBuffer,
maxAllowed //
);
//
CleanupArray(
rsiBuffer,
maxAllowed //
);
//
CleanupArray(
mfiBuffer,
maxAllowed //
);
//
CleanupArray(
rviBuffer,
maxAllowed //
);
//
CleanupArray(
adxBuffer,
maxAllowed //
);
//
CleanupArray(
adxpBuffer,
maxAllowed //
);
//
CleanupArray(
adxnBuffer,
maxAllowed //
);
//
CleanupArray(
macdBuffer,
maxAllowed //
);
//
CleanupArray(
momentumBuffer,
maxAllowed //
);
//
CleanupArray(
rviSignalBuffer,
maxAllowed //
);
//
CleanupArray(
macdSignalBuffer,
maxAllowed //
);
//
CleanupArray(
stochasticBuffer,
maxAllowed //
);
//
CleanupArray(
stochasticSignalBuffer,
maxAllowed //
);
}
//
};