Files
xMQL5/X121-EA/V1.0/Helpers/x-saherelm.xchm.helper.mq5
T
2024-10-11 19:46:23 +03:30

4126 lines
83 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCHMHelper
// 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.xhelper.class.mq5"
//
// Definitions ...
//
enum ENUM_XCHM_BUFFERS
{
//
// Main ...
XCHM_FAST_LINE = 0,
XCHM_SLOW_LINE = 1,
//
// Current ...
XCHM_CFAST_LINE = 2,
XCHM_CSLOW_LINE = 3,
//
// Short ...
XCHM_SFAST_LINE = 4,
XCHM_SSLOW_LINE = 5,
//
// Medium ...
XCHM_MFAST_LINE = 6,
XCHM_MSLOW_LINE = 7,
//
// Long ...
XCHM_LFAST_LINE = 8,
XCHM_LSLOW_LINE = 9,
//
// Hind ...
XCHM_HFAST_LINE = 10,
XCHM_HSLOW_LINE = 11,
};
//
// Input Models ...
struct XCHMInputs
{
//
// Props ...
//
// Market ...
int fastLength; // Fast Length
int slowLength; // Slow Length
ENUM_MA_METHOD method; // Mode
ENUM_APPLIED_PRICE appliedTo; // Applied To
//
// Cycles ...
//
// Short ...
ENUM_X_PERIOD_METHOD scMethod; // How to Find Period
ENUM_TIMEFRAMES scPeriod; // Time Period
//
// Medium ...
ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period
ENUM_TIMEFRAMES mcPeriod; // Time Period
//
// Long ...
ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period
ENUM_TIMEFRAMES lcPeriod; // Time Period
//
// Hind ...
ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period
ENUM_TIMEFRAMES hcPeriod; // Time Period
//
// Presentation ...
//
bool showFast; // Show Fast
bool showSlow; // Show Slow
//
bool showAVG; // Show Average
//
bool showCurrent; // Show Current Cycle
bool showShort; // Show Short Cycle
bool showMedium; // Show Medium Cycle
bool showLong; // Show Long Cycle
bool showHind; // Show Hind Cycle
//
// Constructor(s) ...
XCHMInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
fastLength = 0;
slowLength = 0;
method = MODE_EMA;
appliedTo = PRICE_CLOSE;
//
scMethod = X_PERIOD_AUTO;
scPeriod = NULL;
mcMethod = X_PERIOD_AUTO;
mcPeriod = NULL;
lcMethod = X_PERIOD_AUTO;
lcPeriod = NULL;
hcMethod = X_PERIOD_AUTO;
hcPeriod = NULL;
//
showFast = false;
showSlow = false;
//
showAVG = false;
//
showCurrent = false;
showShort = false;
showMedium = false;
showLong = false;
showHind = false;
}
//
// Default ...
void Default()
{
//
fastLength = 9;
slowLength = 18;
method = MODE_EMA;
appliedTo = PRICE_CLOSE;
//
scMethod = X_PERIOD_AUTO;
scPeriod = NULL;
mcMethod = X_PERIOD_AUTO;
mcPeriod = NULL;
lcMethod = X_PERIOD_AUTO;
lcPeriod = NULL;
hcMethod = X_PERIOD_AUTO;
hcPeriod = NULL;
//
showFast = true;
showSlow = true;
//
showAVG = true;
//
showCurrent = true;
showShort = true;
showMedium = true;
showLong = true;
showHind = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
fastLength > 2 &&
slowLength > fastLength &&
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result =
//
MathMax(fastLength, slowLength)
//
;
//
return result;
}
};
//
// Define Conditions ...
struct XCHMConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
//
double fast[];
double slow[];
//
// Current ...
double cFast[];
double cSlow[];
//
// Short ...
double sFast[];
double sSlow[];
//
// Medium ...
double mFast[];
double mSlow[];
//
// Long ...
double lFast[];
double lSlow[];
//
// Hind ...
double hFast[];
double hSlow[];
//
// Conditions ...
//
// Power ...
bool hasBullishPower;
bool hasBearishPower;
bool isBullishPowerUp;
bool isBearishPowerUp;
bool isBullishPowerIncreasing;
bool isBullishPowerDecreasing;
bool isBearishPowerIncreasing;
bool isBearishPowerDecreasing;
//
// AVG ...
//
bool isFastOverSlow;
bool isFastUnderSlow;
//
bool isFastCrossedOverSlow;
bool isFastCrossedUnderSlow;
//
bool isClosedOverFast;
bool isClosedUnderFast;
//
// Current ...
//
bool isCFastOverSlow;
bool isCFastUnderSlow;
//
bool isCFastCrossedOverSlow;
bool isCFastCrossedUnderSlow;
//
bool isClosedOverCFast;
bool isClosedUnderCFast;
//
// Short ...
//
bool isSFastOverSlow;
bool isSFastUnderSlow;
//
bool isSFastCrossedOverSlow;
bool isSFastCrossedUnderSlow;
//
bool isClosedOverSFast;
bool isClosedUnderSFast;
//
// Medium ...
//
bool isMFastOverSlow;
bool isMFastUnderSlow;
//
bool isMFastCrossedOverSlow;
bool isMFastCrossedUnderSlow;
//
bool isClosedOverMFast;
bool isClosedUnderMFast;
//
// Long ...
//
bool isLFastOverSlow;
bool isLFastUnderSlow;
//
bool isLFastCrossedOverSlow;
bool isLFastCrossedUnderSlow;
//
bool isClosedOverLFast;
bool isClosedUnderLFast;
//
// Hind ...
//
bool isHFastOverSlow;
bool isHFastUnderSlow;
//
bool isHFastCrossedOverSlow;
bool isHFastCrossedUnderSlow;
//
bool isClosedOverHFast;
bool isClosedUnderHFast;
//
void Clean()
{
//
Clean(fast);
Clean(slow);
Clean(cFast);
Clean(cSlow);
Clean(sFast);
Clean(sSlow);
Clean(mFast);
Clean(mSlow);
Clean(lFast);
Clean(lSlow);
Clean(hFast);
Clean(hSlow);
//
ArraySetAsSeries(fast, true);
ArraySetAsSeries(slow, true);
ArraySetAsSeries(cFast, true);
ArraySetAsSeries(cSlow, true);
ArraySetAsSeries(sFast, true);
ArraySetAsSeries(sSlow, true);
ArraySetAsSeries(mFast, true);
ArraySetAsSeries(mSlow, true);
ArraySetAsSeries(lFast, true);
ArraySetAsSeries(lSlow, true);
ArraySetAsSeries(hFast, true);
ArraySetAsSeries(hSlow, true);
//
// Power ...
hasBullishPower = false;
hasBearishPower = false;
isBullishPowerUp = false;
isBearishPowerUp = false;
isBullishPowerIncreasing = false;
isBullishPowerDecreasing = false;
isBearishPowerIncreasing = false;
isBearishPowerDecreasing = false;
//
// AVG ...
//
isFastOverSlow = false;
isFastUnderSlow = false;
//
isFastCrossedOverSlow = false;
isFastCrossedUnderSlow = false;
//
isClosedOverFast = false;
isClosedUnderFast = false;
//
// Current ...
//
isCFastOverSlow = false;
isCFastUnderSlow = false;
//
isCFastCrossedOverSlow = false;
isCFastCrossedUnderSlow = false;
//
isClosedOverCFast = false;
isClosedUnderCFast = false;
//
// Short ...
//
isSFastOverSlow = false;
isSFastUnderSlow = false;
//
isSFastCrossedOverSlow = false;
isSFastCrossedUnderSlow = false;
//
isClosedOverSFast = false;
isClosedUnderSFast = false;
//
// Medium ...
//
isMFastOverSlow = false;
isMFastUnderSlow = false;
//
isMFastCrossedOverSlow = false;
isMFastCrossedUnderSlow = false;
//
isClosedOverMFast = false;
isClosedUnderMFast = false;
//
// Long ...
//
isLFastOverSlow = false;
isLFastUnderSlow = false;
//
isLFastCrossedOverSlow = false;
isLFastCrossedUnderSlow = false;
//
isClosedOverLFast = false;
isClosedUnderLFast = false;
//
// Hind ...
//
isHFastOverSlow = false;
isHFastUnderSlow = false;
//
isHFastCrossedOverSlow = false;
isHFastCrossedUnderSlow = false;
//
isClosedOverHFast = false;
isClosedUnderHFast = false;
}
//
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
// Since We have to Use this
// Only for Filtering Signals ...
// We Can Ignore Scoring ...
// or Complete this later ...
//
// Power ...
if (hasBullishPower)
{
bullishScore++;
}
if (hasBearishPower)
{
bearishScore++;
}
if (isBullishPowerUp)
{
bullishScore++;
}
if (isBearishPowerUp)
{
bearishScore++;
}
if (isBullishPowerIncreasing)
{
bullishScore++;
}
if (isBullishPowerDecreasing)
{
bearishScore++;
}
if (isBearishPowerIncreasing)
{
bearishScore++;
}
if (isBearishPowerDecreasing)
{
bullishScore++;
}
//
// AVG ...
//
if (isFastOverSlow)
{
bullishScore++;
}
if (isFastUnderSlow)
{
bearishScore++;
}
if (isFastCrossedOverSlow)
{
bullishScore++;
}
if (isFastCrossedUnderSlow)
{
bearishScore++;
}
if (isClosedOverFast)
{
bullishScore++;
}
if (isClosedUnderFast)
{
bearishScore++;
}
//
// Current ...
//
if (isCFastOverSlow)
{
bullishScore++;
}
if (isCFastUnderSlow)
{
bearishScore++;
}
if (isCFastCrossedOverSlow)
{
bullishScore++;
}
if (isCFastCrossedUnderSlow)
{
bearishScore++;
}
if (isClosedOverCFast)
{
bullishScore++;
}
if (isClosedUnderCFast)
{
bearishScore++;
}
//
// Short ...
//
if (isSFastOverSlow)
{
bullishScore++;
}
if (isSFastUnderSlow)
{
bearishScore++;
}
if (isSFastCrossedOverSlow)
{
bullishScore++;
}
if (isSFastCrossedUnderSlow)
{
bearishScore++;
}
if (isClosedOverSFast)
{
bullishScore++;
}
if (isClosedUnderSFast)
{
bearishScore++;
}
//
// Medium ...
//
if (isMFastOverSlow)
{
bullishScore++;
}
if (isMFastUnderSlow)
{
bearishScore++;
}
if (isMFastCrossedOverSlow)
{
bullishScore++;
}
if (isMFastCrossedUnderSlow)
{
bearishScore++;
}
if (isClosedOverMFast)
{
bullishScore++;
}
if (isClosedUnderMFast)
{
bearishScore++;
}
//
// Long ...
//
if (isLFastOverSlow)
{
bullishScore++;
}
if (isLFastUnderSlow)
{
bearishScore++;
}
if (isLFastCrossedOverSlow)
{
bullishScore++;
}
if (isLFastCrossedUnderSlow)
{
bearishScore++;
}
if (isClosedOverLFast)
{
bullishScore++;
}
if (isClosedUnderLFast)
{
bearishScore++;
}
//
// Hind ...
//
if (isHFastOverSlow)
{
bullishScore++;
}
if (isHFastUnderSlow)
{
bearishScore++;
}
if (isHFastCrossedOverSlow)
{
bullishScore++;
}
if (isHFastCrossedUnderSlow)
{
bearishScore++;
}
if (isClosedOverHFast)
{
bullishScore++;
}
if (isClosedUnderHFast)
{
bearishScore++;
}
}
//
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 =
//
// Power ...
ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) +
ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) +
ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) +
ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) +
ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) +
ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) +
ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) +
ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) +
//
// AVG ...
ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) +
ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) +
ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) +
ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) +
ToString("isClosedOverFast", isClosedOverFast, ignoreFalseConditions, separator) +
ToString("isClosedUnderFast", isClosedUnderFast, ignoreFalseConditions, separator) +
//
// Current ...
ToString("isCFastOverSlow", isCFastOverSlow, ignoreFalseConditions, separator) +
ToString("isCFastUnderSlow", isCFastUnderSlow, ignoreFalseConditions, separator) +
ToString("isCFastCrossedOverSlow", isCFastCrossedOverSlow, ignoreFalseConditions, separator) +
ToString("isCFastCrossedUnderSlow", isCFastCrossedUnderSlow, ignoreFalseConditions, separator) +
ToString("isClosedOverCFast", isClosedOverCFast, ignoreFalseConditions, separator) +
ToString("isClosedUnderCFast", isClosedUnderCFast, ignoreFalseConditions, separator) +
//
// Short ...
ToString("isSFastOverSlow", isSFastOverSlow, ignoreFalseConditions, separator) +
ToString("isSFastUnderSlow", isSFastUnderSlow, ignoreFalseConditions, separator) +
ToString("isSFastCrossedOverSlow", isSFastCrossedOverSlow, ignoreFalseConditions, separator) +
ToString("isSFastCrossedUnderSlow", isSFastCrossedUnderSlow, ignoreFalseConditions, separator) +
ToString("isClosedOverSFast", isClosedOverSFast, ignoreFalseConditions, separator) +
ToString("isClosedUnderSFast", isClosedUnderSFast, ignoreFalseConditions, separator) +
//
// Medium ...
ToString("isMFastOverSlow", isMFastOverSlow, ignoreFalseConditions, separator) +
ToString("isMFastUnderSlow", isMFastUnderSlow, ignoreFalseConditions, separator) +
ToString("isMFastCrossedOverSlow", isMFastCrossedOverSlow, ignoreFalseConditions, separator) +
ToString("isMFastCrossedUnderSlow", isMFastCrossedUnderSlow, ignoreFalseConditions, separator) +
ToString("isClosedOverMFast", isClosedOverMFast, ignoreFalseConditions, separator) +
ToString("isClosedUnderMFast", isClosedUnderMFast, ignoreFalseConditions, separator) +
//
// Long ...
ToString("isLFastOverSlow", isLFastOverSlow, ignoreFalseConditions, separator) +
ToString("isLFastUnderSlow", isLFastUnderSlow, ignoreFalseConditions, separator) +
ToString("isLFastCrossedOverSlow", isLFastCrossedOverSlow, ignoreFalseConditions, separator) +
ToString("isLFastCrossedUnderSlow", isLFastCrossedUnderSlow, ignoreFalseConditions, separator) +
ToString("isClosedOverLFast", isClosedOverLFast, ignoreFalseConditions, separator) +
ToString("isClosedUnderLFast", isClosedUnderLFast, ignoreFalseConditions, separator) +
//
// Hind ...
ToString("isHFastOverSlow", isHFastOverSlow, ignoreFalseConditions, separator) +
ToString("isHFastUnderSlow", isHFastUnderSlow, ignoreFalseConditions, separator) +
ToString("isHFastCrossedOverSlow", isHFastCrossedOverSlow, ignoreFalseConditions, separator) +
ToString("isHFastCrossedUnderSlow", isHFastCrossedUnderSlow, ignoreFalseConditions, separator) +
ToString("isClosedOverHFast", isClosedOverHFast, ignoreFalseConditions, separator) +
ToString("isClosedUnderHFast", isClosedUnderHFast, ignoreFalseConditions, separator) +
//
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return "XCHM";
}
};
//
// Class ...
class XSCXCHMHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCHMHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCHMHelper()
{
//
Clean(fastBuffer);
Clean(slowBuffer);
Clean(cFastBuffer);
Clean(cSlowBuffer);
Clean(sFastBuffer);
Clean(sSlowBuffer);
Clean(mFastBuffer);
Clean(mSlowBuffer);
Clean(lFastBuffer);
Clean(lSlowBuffer);
Clean(hFastBuffer);
Clean(hSlowBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCHMInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(fastBuffer, true);
ArraySetAsSeries(slowBuffer, true);
ArraySetAsSeries(cFastBuffer, true);
ArraySetAsSeries(cSlowBuffer, true);
ArraySetAsSeries(sFastBuffer, true);
ArraySetAsSeries(sSlowBuffer, true);
ArraySetAsSeries(mFastBuffer, true);
ArraySetAsSeries(mSlowBuffer, true);
ArraySetAsSeries(lFastBuffer, true);
ArraySetAsSeries(lSlowBuffer, true);
ArraySetAsSeries(hFastBuffer, true);
ArraySetAsSeries(hSlowBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xchm",
//
// Inputs ...
//
// Market ...
"",
mInputs.fastLength,
mInputs.slowLength,
mInputs.method,
mInputs.appliedTo,
//
// Cycles ...
"",
//
// Short ...
"",
mInputs.scMethod,
mInputs.scPeriod,
//
// Medium ...
"",
mInputs.mcMethod,
mInputs.mcPeriod,
//
// Long ...
"",
mInputs.lcMethod,
mInputs.lcPeriod,
//
// Hind ...
"",
mInputs.hcMethod,
mInputs.hcPeriod,
//
// Presentation ...
"",
//
mInputs.showFast,
mInputs.showSlow,
//
mInputs.showAVG,
//
mInputs.showCurrent,
mInputs.showShort,
mInputs.showMedium,
mInputs.showLong,
mInputs.showHind
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCHMInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCHMInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
// AVG ...
//
double GetFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(fastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return fastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyFast(
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,
fastBuffer,
buffer,
forceClean
//
);
}
//
double GetSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(slowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return slowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopySlow(
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,
slowBuffer,
buffer,
forceClean
//
);
}
//
// Current ...
//
double GetCFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(cFastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return cFastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyCFast(
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,
cFastBuffer,
buffer,
forceClean
//
);
}
//
double GetCSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(cSlowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return cSlowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyCSlow(
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,
cSlowBuffer,
buffer,
forceClean
//
);
}
//
// Short ...
//
double GetSFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(sFastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return sFastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopySFast(
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,
sFastBuffer,
buffer,
forceClean
//
);
}
//
double GetSSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(sSlowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return sSlowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopySSlow(
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,
sSlowBuffer,
buffer,
forceClean
//
);
}
//
// Medium ...
//
double GetMFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(mFastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return mFastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyMFast(
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,
mFastBuffer,
buffer,
forceClean
//
);
}
//
double GetMSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(mSlowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return mSlowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyMSlow(
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,
mSlowBuffer,
buffer,
forceClean
//
);
}
//
// Long ...
//
double GetLFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(lFastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return lFastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyLFast(
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,
lFastBuffer,
buffer,
forceClean
//
);
}
//
double GetLSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(lSlowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return lSlowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyLSlow(
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,
lSlowBuffer,
buffer,
forceClean
//
);
}
//
// Hind ...
//
double GetHFast(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(hFastBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hFastBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyHFast(
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,
hFastBuffer,
buffer,
forceClean
//
);
}
//
double GetHSlow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(hSlowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hSlowBuffer[barIndex];
}
//
// Copy Required Items ...
int CopyHSlow(
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,
hSlowBuffer,
buffer,
forceClean
//
);
}
//
// Tools ...
//
void GetCycle(
double &fast,
double &slow,
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
fast = 0;
slow = 0;
//
switch (cycle)
{
//
// CURRENT ...
case X_MARKET_CYCLE_UNKNOWN:
//
fast = GetCFast(barIndex);
slow = GetCSlow(barIndex);
break;
//
// SHORT ...
case X_MARKET_CYCLE_SHORT:
//
fast = GetSFast(barIndex);
slow = GetSSlow(barIndex);
break;
//
// MEDIUM ...
case X_MARKET_CYCLE_MEDIUM:
//
fast = GetMFast(barIndex);
slow = GetMSlow(barIndex);
break;
//
// LONG ...
case X_MARKET_CYCLE_LONG:
//
fast = GetLFast(barIndex);
slow = GetLSlow(barIndex);
break;
//
// HIND ...
case X_MARKET_CYCLE_HIND:
//
fast = GetHFast(barIndex);
slow = GetHSlow(barIndex);
break;
}
}
//
double GetCyclePower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
double result = 0;
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycle //
);
//
result = MathAbs(fast - slow);
//
return result;
}
//
double GetCycleFast(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
double result = 0;
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycle //
);
//
result = fast;
//
return result;
}
//
double GetCycleSlow(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
double result = 0;
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycle //
);
//
result = slow;
//
return result;
}
//
double GetCycleMax(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
double result = 0;
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycle //
);
//
result = MathMax(fast, slow);
//
return result;
}
//
double GetCycleMin(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
double result = 0;
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycle //
);
//
result = MathMin(fast, slow);
//
return result;
}
//
int GetFasts(
double &values[],
int barIndex // Bar Index
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetAllMarketCycles(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleFast(
barIndex,
cycles[i] //
);
//
if (iValue > 0)
{
//
Add(
iValue,
values //
);
}
}
//
result = ArraySize(values);
//
return result;
}
//
int GetSlows(
double &values[],
int barIndex // Bar Index
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetAllMarketCycles(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleSlow(
barIndex,
cycles[i] //
);
//
if (iValue > 0)
{
//
Add(
iValue,
values //
);
}
}
//
result = ArraySize(values);
//
return result;
}
//
int GetCyclesFast(
double &values[],
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
int result = 0;
//
Clean(values);
//
int cyclesCount = ArraySize(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleFast(
barIndex,
cycles[i] //
);
//
if (iValue > 0)
{
//
Add(
iValue,
values //
);
}
}
//
result = ArraySize(values);
//
return result;
}
//
int GetCyclesSlow(
double &values[],
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
int result = 0;
//
Clean(values);
//
int cyclesCount = ArraySize(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleSlow(
barIndex,
cycles[i] //
);
//
if (iValue > 0)
{
//
Add(
iValue,
values //
);
}
}
//
result = ArraySize(values);
//
return result;
}
//
int GetBullishCycles(
ENUM_X_MARKET_CYCLES &cycles[], // Holds Result
int barIndex // Bar Index
)
{
//
int result = 0;
//
Clean(cycles);
//
ENUM_X_MARKET_CYCLES mCycles[];
int cyclesCount = GetAllMarketCycles(
mCycles //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
mCycles[i] //
);
//
bool isBullish = fast > slow;
if (isBullish)
{
//
Add(
mCycles[i],
cycles //
);
}
}
//
result = ArraySize(cycles);
//
return result;
}
//
int GetBearishCycles(
ENUM_X_MARKET_CYCLES &cycles[], // Holds Result
int barIndex // Bar Index
)
{
//
int result = 0;
//
Clean(cycles);
//
ENUM_X_MARKET_CYCLES mCycles[];
int cyclesCount = GetAllMarketCycles(
mCycles //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
mCycles[i] //
);
//
bool isBearish = fast < slow;
if (isBearish)
{
//
Add(
mCycles[i],
cycles //
);
}
}
//
result = ArraySize(cycles);
//
return result;
}
//
double GetMax(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetAllMarketCycles(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMax(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue > result
? iValue
: result;
}
//
return result;
}
//
double GetMin(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetAllMarketCycles(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMin(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue < result
? iValue
: result;
}
//
return result;
}
//
double GetCyclesMax(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
double result = 0;
//
int cyclesCount = ArraySize(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMax(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue > result
? iValue
: result;
}
//
return result;
}
//
double GetCyclesMin(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
double result = 0;
//
int cyclesCount = ArraySize(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMin(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue < result
? iValue
: result;
}
//
return result;
}
//
double GetMaxBullish(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMax(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue > result
? iValue
: result;
}
//
return result;
}
//
double GetMinBullish(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMin(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue < result
? iValue
: result;
}
//
return result;
}
//
double GetMaxBearish(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMax(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue > result
? iValue
: result;
}
//
return result;
}
//
double GetMinBearish(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iValue = GetCycleMin(
barIndex,
cycles[i] //
);
//
result =
result == 0 || iValue < result
? iValue
: result;
}
//
return result;
}
//
double GetMaxBullishFast(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesFast(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinBullishFast(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesFast(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetMaxBullishSlow(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesSlow(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinBullishSlow(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesSlow(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetMaxBearishFast(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesFast(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinBearishFast(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesFast(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetMaxBearishSlow(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesSlow(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinBearishSlow(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
double values[];
int valuesCount = GetCyclesSlow(
values,
barIndex,
cycles //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetBullishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBullishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iPower = GetCyclePower(
barIndex,
cycles[i] //
);
//
if (iPower > 0)
{
result += iPower;
}
}
//
return result;
}
//
double GetBearishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
ENUM_X_MARKET_CYCLES cycles[];
int cyclesCount = GetBearishCycles(
cycles,
barIndex //
);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double iPower = GetCyclePower(
barIndex,
cycles[i] //
);
//
if (iPower > 0)
{
result += iPower;
}
}
//
return result;
}
//
double GetCyclesBullishPower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
double result = 0;
//
int cyclesCount = ArraySize(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycles[i] //
);
//
if (fast > slow)
{
//
double iPower = GetCyclePower(
barIndex,
cycles[i] //
);
//
if (iPower > 0)
{
result += iPower;
}
}
}
//
return result;
}
//
double GetCyclesBearishPower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
double result = 0;
//
int cyclesCount = ArraySize(cycles);
if (!IsValidSize(cyclesCount))
{
return result;
}
//
for (int i = 0; i < cyclesCount; i++)
{
//
double fast = 0;
double slow = 0;
GetCycle(
fast,
slow,
barIndex,
cycles[i] //
);
//
if (fast < slow)
{
//
double iPower = GetCyclePower(
barIndex,
cycles[i] //
);
//
if (iPower > 0)
{
result += iPower;
}
}
}
//
return result;
}
//
bool HasBullishPower(
int barIndex // Bar Index
)
{
//
bool result = false;
//
double bullishPower = GetBullishPower(barIndex);
double bearishPower = GetBearishPower(barIndex);
//
result =
//
bearishPower >= 0 &&
bullishPower > bearishPower
//
;
//
return result;
}
//
bool HasBearishPower(
int barIndex // Bar Index
)
{
//
bool result = false;
//
double bullishPower = GetBullishPower(barIndex);
double bearishPower = GetBearishPower(barIndex);
//
result =
//
bullishPower >= 0 &&
bearishPower > bullishPower
//
;
//
return result;
}
//
bool HasCyclesBullishPower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
bool result = false;
//
double bullishPower = GetCyclesBullishPower(barIndex, cycles);
double bearishPower = GetCyclesBearishPower(barIndex, cycles);
//
result =
//
bearishPower >= 0 &&
bullishPower > bearishPower
//
;
//
return result;
}
//
bool HasCyclesBearishPower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
bool result = false;
//
double bullishPower = GetCyclesBullishPower(barIndex, cycles);
double bearishPower = GetCyclesBearishPower(barIndex, cycles);
//
result =
//
bullishPower >= 0 &&
bearishPower > bullishPower
//
;
//
return result;
}
//
// Check Bullish Power Increasing ...
bool IsBullishPowerIncreasing(
int barIndex, // Bar Index
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetBullishPower(barIndex);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetBullishPower(i);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower > iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower > lastPower
//
;
}
//
return result;
}
//
// Check Bullish Power Decreasing ...
bool IsBullishPowerDecreasing(
int barIndex, // Bar Index
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetBullishPower(barIndex);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetBullishPower(i);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower < iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower < lastPower
//
;
}
//
return result;
}
//
// Check Bearish Power Increasing ...
bool IsBearishPowerIncreasing(
int barIndex, // Bar Index
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetBearishPower(barIndex);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetBearishPower(i);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower > iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower > lastPower
//
;
}
//
return result;
}
//
// Check Bearish Power Decreasing ...
bool IsBearishPowerDecreasing(
int barIndex, // Bar Index
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetBearishPower(barIndex);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetBearishPower(i);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower < iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower < lastPower
//
;
}
//
return result;
}
//
// Check Bullish Power Increasing ...
bool IsCyclesBullishPowerIncreasing(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[], //
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetCyclesBullishPower(barIndex, cycles);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetCyclesBullishPower(i, cycles);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower > iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower > lastPower
//
;
}
//
return result;
}
//
// Check Bullish Power Decreasing ...
bool IsCyclesBullishPowerDecreasing(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[], //
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetCyclesBullishPower(barIndex, cycles);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetCyclesBullishPower(i, cycles);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower < iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower < lastPower
//
;
}
//
return result;
}
//
// Check Bearish Power Increasing ...
bool IsCyclesBearishPowerIncreasing(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[], //
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetCyclesBearishPower(barIndex, cycles);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetCyclesBearishPower(i, cycles);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower > iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower > lastPower
//
;
}
//
return result;
}
//
// Check Bearish Power Decreasing ...
bool IsCyclesBearishPowerDecreasing(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[], //
int loopback = 5 // Loopback
)
{
//
bool result = false;
//
if (loopback <= 0)
{
loopback = 5;
}
//
double firstPower = GetCyclesBearishPower(barIndex, cycles);
double lastPower = firstPower;
for (int i = barIndex + 1; i < barIndex + loopback; i++)
{
//
double iPower = GetCyclesBearishPower(i, cycles);
//
result =
//
iPower > 0 &&
firstPower > 0 &&
lastPower < iPower
//
;
if (!result)
{
break;
}
//
lastPower = iPower;
}
//
if (result)
{
//
result =
//
firstPower < lastPower
//
;
}
//
return result;
}
//
// Conditions ...
//
bool GetConditions(
XCHMConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = true;
//
if (loopback < 3)
{
loopback = 3;
}
//
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;
//
// Buffers ...
//
// AVG ...
//
// Fast ...
CopyFast(
zIndex,
loopback,
conditions.fast //
);
//
// Slow ...
CopySlow(
zIndex,
loopback,
conditions.slow //
);
//
// Current ...
//
// Fast ...
CopyCFast(
zIndex,
loopback,
conditions.cFast //
);
//
// Slow ...
CopyCSlow(
zIndex,
loopback,
conditions.cSlow //
);
//
// Short ...
//
// Fast ...
CopySFast(
zIndex,
loopback,
conditions.sFast //
);
//
// Slow ...
CopySSlow(
zIndex,
loopback,
conditions.sSlow //
);
//
// Medium ...
//
// Fast ...
CopyMFast(
zIndex,
loopback,
conditions.mFast //
);
//
// Slow ...
CopyMSlow(
zIndex,
loopback,
conditions.mSlow //
);
//
// Long ...
//
// Fast ...
CopyLFast(
zIndex,
loopback,
conditions.lFast //
);
//
// Slow ...
CopyLSlow(
zIndex,
loopback,
conditions.lSlow //
);
//
// Hind ...
//
// Fast ...
CopyHFast(
zIndex,
loopback,
conditions.hFast //
);
//
// Slow ...
CopyHSlow(
zIndex,
loopback,
conditions.hSlow //
);
//
// Conditions ...
//
XOHCL cBar;
result = cBar.Init(
mSymbol,
mPeriod,
cIndex //
);
if (!result)
{
return result;
}
//
XOHCL pBar;
result = pBar.Init(
mSymbol,
mPeriod,
pIndex //
);
if (!result)
{
return result;
}
double hhValue = pBar.FindHighest(
loopback,
MODE_HIGH //
);
double llValue = pBar.FindLowest(
loopback,
MODE_LOW //
);
//
XOHCL ppBar;
result = ppBar.Init(
mSymbol,
mPeriod,
ppIndex //
);
if (!result)
{
return result;
}
double phhValue = ppBar.FindHighest(
loopback * 2,
MODE_HIGH //
);
double pllValue = ppBar.FindLowest(
loopback * 2,
MODE_LOW //
);
//
double allValues[];
double maxValue = 0;
double minValue = 0;
double maxValuePrev = 0;
double minValuePrev = 0;
//
// Power ...
//
bool hasBullishPower = HasBullishPower(cIndex);
bool hasBullishPowerPrev = HasBullishPower(pIndex);
//
bool hasBearishPower = HasBearishPower(cIndex);
bool hasBearishPowerPrev = HasBearishPower(pIndex);
//
bool isBullishPowerUp = hasBullishPower &&
!hasBullishPowerPrev;
bool isBearishPowerUp = hasBearishPower &&
!hasBearishPowerPrev;
//
bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex);
bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex);
bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex);
bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex);
//
conditions.hasBullishPower = hasBullishPower;
conditions.hasBearishPower = hasBearishPower;
conditions.isBullishPowerUp = isBullishPowerUp;
conditions.isBearishPowerUp = isBearishPowerUp;
conditions.isBullishPowerIncreasing = isBullishPowerIncreasing;
conditions.isBullishPowerDecreasing = isBullishPowerDecreasing;
conditions.isBearishPowerIncreasing = isBearishPowerIncreasing;
conditions.isBearishPowerDecreasing = isBearishPowerDecreasing;
//
// AVG ...
//
bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex];
bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex];
//
bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex];
bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex];
//
bool isFastCrossedOverSlow = isFastOverSlow &&
!isFastOverSlowPrev;
bool isFastCrossedUnderSlow = isFastUnderSlow &&
!isFastUnderSlowPrev;
//
bool isClosedOverFast = cBar.close > conditions.fast[cIndex];
bool isClosedUnderFast = cBar.close < conditions.fast[cIndex];
//
conditions.isFastOverSlow = isFastOverSlow;
conditions.isFastUnderSlow = isFastUnderSlow;
//
conditions.isFastCrossedOverSlow = isFastCrossedOverSlow;
conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow;
//
conditions.isClosedOverFast = isClosedOverFast;
conditions.isClosedUnderFast = isClosedUnderFast;
//
// Current ...
//
bool isCFastOverSlow = conditions.cFast[cIndex] > conditions.cSlow[cIndex];
bool isCFastOverSlowPrev = conditions.cFast[pIndex] > conditions.cSlow[pIndex];
//
bool isCFastUnderSlow = conditions.cFast[cIndex] < conditions.cSlow[cIndex];
bool isCFastUnderSlowPrev = conditions.cFast[pIndex] < conditions.cSlow[pIndex];
//
bool isCFastCrossedOverSlow = isCFastOverSlow &&
!isCFastOverSlowPrev;
bool isCFastCrossedUnderSlow = isCFastUnderSlow &&
!isCFastUnderSlowPrev;
//
bool isClosedOverCFast = cBar.close > conditions.cFast[cIndex];
bool isClosedUnderCFast = cBar.close < conditions.cFast[cIndex];
//
conditions.isCFastOverSlow = isCFastOverSlow;
conditions.isCFastUnderSlow = isCFastUnderSlow;
//
conditions.isCFastCrossedOverSlow = isCFastCrossedOverSlow;
conditions.isCFastCrossedUnderSlow = isCFastCrossedUnderSlow;
//
conditions.isClosedOverCFast = isClosedOverCFast;
conditions.isClosedUnderCFast = isClosedUnderCFast;
//
// Short ...
//
bool isSFastOverSlow = conditions.sFast[cIndex] > conditions.sSlow[cIndex];
bool isSFastOverSlowPrev = conditions.sFast[pIndex] > conditions.sSlow[pIndex];
//
bool isSFastUnderSlow = conditions.sFast[cIndex] < conditions.sSlow[cIndex];
bool isSFastUnderSlowPrev = conditions.sFast[pIndex] < conditions.sSlow[pIndex];
//
bool isSFastCrossedOverSlow = isSFastOverSlow &&
!isSFastOverSlowPrev;
bool isSFastCrossedUnderSlow = isSFastUnderSlow &&
!isSFastUnderSlowPrev;
//
bool isClosedOverSFast = cBar.close > conditions.sFast[cIndex];
bool isClosedUnderSFast = cBar.close < conditions.sFast[cIndex];
//
conditions.isSFastOverSlow = isSFastOverSlow;
conditions.isSFastUnderSlow = isSFastUnderSlow;
//
conditions.isSFastCrossedOverSlow = isSFastCrossedOverSlow;
conditions.isSFastCrossedUnderSlow = isSFastCrossedUnderSlow;
//
conditions.isClosedOverSFast = isClosedOverSFast;
conditions.isClosedUnderSFast = isClosedUnderSFast;
//
// Medium ...
//
bool isMFastOverSlow = conditions.mFast[cIndex] > conditions.mSlow[cIndex];
bool isMFastOverSlowPrev = conditions.mFast[pIndex] > conditions.mSlow[pIndex];
//
bool isMFastUnderSlow = conditions.mFast[cIndex] < conditions.mSlow[cIndex];
bool isMFastUnderSlowPrev = conditions.mFast[pIndex] < conditions.mSlow[pIndex];
//
bool isMFastCrossedOverSlow = isMFastOverSlow &&
!isMFastOverSlowPrev;
bool isMFastCrossedUnderSlow = isMFastUnderSlow &&
!isMFastUnderSlowPrev;
//
bool isClosedOverMFast = cBar.close > conditions.mFast[cIndex];
bool isClosedUnderMFast = cBar.close < conditions.mFast[cIndex];
//
conditions.isMFastOverSlow = isMFastOverSlow;
conditions.isMFastUnderSlow = isMFastUnderSlow;
//
conditions.isMFastCrossedOverSlow = isMFastCrossedOverSlow;
conditions.isMFastCrossedUnderSlow = isMFastCrossedUnderSlow;
//
conditions.isClosedOverMFast = isClosedOverMFast;
conditions.isClosedUnderMFast = isClosedUnderMFast;
//
// Long ...
//
bool isLFastOverSlow = conditions.lFast[cIndex] > conditions.lSlow[cIndex];
bool isLFastOverSlowPrev = conditions.lFast[pIndex] > conditions.lSlow[pIndex];
//
bool isLFastUnderSlow = conditions.lFast[cIndex] < conditions.lSlow[cIndex];
bool isLFastUnderSlowPrev = conditions.lFast[pIndex] < conditions.lSlow[pIndex];
//
bool isLFastCrossedOverSlow = isLFastOverSlow &&
!isLFastOverSlowPrev;
bool isLFastCrossedUnderSlow = isLFastUnderSlow &&
!isLFastUnderSlowPrev;
//
bool isClosedOverLFast = cBar.close > conditions.lFast[cIndex];
bool isClosedUnderLFast = cBar.close < conditions.lFast[cIndex];
//
conditions.isLFastOverSlow = isLFastOverSlow;
conditions.isLFastUnderSlow = isLFastUnderSlow;
//
conditions.isLFastCrossedOverSlow = isLFastCrossedOverSlow;
conditions.isLFastCrossedUnderSlow = isLFastCrossedUnderSlow;
//
conditions.isClosedOverLFast = isClosedOverLFast;
conditions.isClosedUnderLFast = isClosedUnderLFast;
//
// Hind ...
//
bool isHFastOverSlow = conditions.hFast[cIndex] > conditions.hSlow[cIndex];
bool isHFastOverSlowPrev = conditions.hFast[pIndex] > conditions.hSlow[pIndex];
//
bool isHFastUnderSlow = conditions.hFast[cIndex] < conditions.hSlow[cIndex];
bool isHFastUnderSlowPrev = conditions.hFast[pIndex] < conditions.hSlow[pIndex];
//
bool isHFastCrossedOverSlow = isHFastOverSlow &&
!isHFastOverSlowPrev;
bool isHFastCrossedUnderSlow = isHFastUnderSlow &&
!isHFastUnderSlowPrev;
//
bool isClosedOverHFast = cBar.close > conditions.hFast[cIndex];
bool isClosedUnderHFast = cBar.close < conditions.hFast[cIndex];
//
conditions.isHFastOverSlow = isHFastOverSlow;
conditions.isHFastUnderSlow = isHFastUnderSlow;
//
conditions.isHFastCrossedOverSlow = isHFastCrossedOverSlow;
conditions.isHFastCrossedUnderSlow = isHFastCrossedUnderSlow;
//
conditions.isClosedOverHFast = isClosedOverHFast;
conditions.isClosedUnderHFast = isClosedUnderHFast;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XCHMInputs mInputs; // Inputs ...
//
// Buffers ...
//
// AVG ...
double fastBuffer[];
double slowBuffer[];
//
// Current ...
double cFastBuffer[];
double cSlowBuffer[];
//
// Short ...
double sFastBuffer[];
double sSlowBuffer[];
//
// Medium ...
double mFastBuffer[];
double mSlowBuffer[];
//
// Long ...
double lFastBuffer[];
double lSlowBuffer[];
//
// Hind ...
double hFastBuffer[];
double hSlowBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Fast ...
CopyBuffer(
mHandler,
XCHM_FAST_LINE,
0,
totalBars,
fastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
XCHM_SLOW_LINE,
0,
totalBars,
slowBuffer
//
);
//
// Current ...
//
// Fast ...
CopyBuffer(
mHandler,
XCHM_CFAST_LINE,
0,
totalBars,
cFastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
XCHM_CSLOW_LINE,
0,
totalBars,
cSlowBuffer
//
);
//
// Short ...
//
// Fast ...
CopyBuffer(
mHandler,
XCHM_SFAST_LINE,
0,
totalBars,
sFastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
XCHM_SSLOW_LINE,
0,
totalBars,
sSlowBuffer
//
);
//
// Medium ...
//
// Fast ...
CopyBuffer(
mHandler,
XCHM_MFAST_LINE,
0,
totalBars,
mFastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
XCHM_MSLOW_LINE,
0,
totalBars,
mSlowBuffer
//
);
//
// Long ...
//
// Fast ...
CopyBuffer(
mHandler,
XCHM_LFAST_LINE,
0,
totalBars,
lFastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
XCHM_LSLOW_LINE,
0,
totalBars,
lSlowBuffer
//
);
//
// Hind ...
//
// Fast ...
CopyBuffer(
mHandler,
XCHM_HFAST_LINE,
0,
totalBars,
hFastBuffer
//
);
//
// Slow ...
CopyBuffer(
mHandler,
XCHM_HSLOW_LINE,
0,
totalBars,
hSlowBuffer
//
);
}
};
//