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

2956 lines
59 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCHTDHelper
// 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_XCHTD_MODE
{
XCHTD_POWER_MODE = 0, // Using Power
XCHTD_PRESSURE_MODE = 1, // Using Pressure
XCHTD_TYPE_MODE = 2, // Using Type
XCHTD_STRONG_MODE = 3, // Using Power and Pressures
};
//
enum ENUM_XCHTD_BUFFERS
{
//
XCHTD_C_BULL_LINE = 0,
XCHTD_C_BEAR_LINE = 1,
//
XCHTD_S_BULL_LINE = 2,
XCHTD_S_BEAR_LINE = 3,
//
XCHTD_M_BULL_LINE = 4,
XCHTD_M_BEAR_LINE = 5,
//
XCHTD_L_BULL_LINE = 6,
XCHTD_L_BEAR_LINE = 7,
//
XCHTD_H_BULL_LINE = 8,
XCHTD_H_BEAR_LINE = 9,
};
//
// Input Models ...
struct XCHTDInputs
{
//
// Props ...
//
// Market ...
int length; // Length
ENUM_XCHTD_MODE mode; // Mode
//
// 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 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) ...
XCHTDInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
mode = XCHTD_POWER_MODE;
//
scMethod = X_PERIOD_AUTO;
scPeriod = NULL;
mcMethod = X_PERIOD_AUTO;
mcPeriod = NULL;
lcMethod = X_PERIOD_AUTO;
lcPeriod = NULL;
hcMethod = X_PERIOD_AUTO;
hcPeriod = NULL;
//
showCurrent = false;
showShort = false;
showMedium = false;
showLong = false;
showHind = false;
}
//
// Default ...
void Default()
{
//
length = 14;
mode = XCHTD_POWER_MODE;
//
scMethod = X_PERIOD_AUTO;
scPeriod = NULL;
mcMethod = X_PERIOD_AUTO;
mcPeriod = NULL;
lcMethod = X_PERIOD_AUTO;
lcPeriod = NULL;
hcMethod = X_PERIOD_AUTO;
hcPeriod = NULL;
//
showCurrent = true;
showShort = true;
showMedium = true;
showLong = true;
showHind = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 0 &&
//
(IsValid(scMethod, scPeriod) &&
IsValid(mcMethod, mcPeriod) &&
IsValid(lcMethod, lcPeriod) &&
IsValid(hcMethod, hcPeriod))
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result =
//
MathMax(0, length)
//
;
//
return result;
}
};
//
// Define Conditions ...
struct XCHTDConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
//
// Current ...
double cBull[];
double cBear[];
//
// Short ...
double sBull[];
double sBear[];
//
// Medium ...
double mBull[];
double mBear[];
//
// Long ...
double lBull[];
double lBear[];
//
// Hind ...
double hBull[];
double hBear[];
//
// Conditions ...
//
// Power ...
bool hasBullishPower;
bool hasBearishPower;
bool isBullishPowerUp;
bool isBearishPowerUp;
bool isBullishPowerIncreasing;
bool isBullishPowerDecreasing;
bool isBearishPowerIncreasing;
bool isBearishPowerDecreasing;
//
// Current ...
bool isCBullish;
bool isCBearish;
bool isCSwitchedToBullish;
bool isCSwitchedToBearish;
//
// Short ...
bool isSBullish;
bool isSBearish;
bool isSSwitchedToBullish;
bool isSSwitchedToBearish;
//
// Medium ...
bool isMBullish;
bool isMBearish;
bool isMSwitchedToBullish;
bool isMSwitchedToBearish;
//
// Long ...
bool isLBullish;
bool isLBearish;
bool isLSwitchedToBullish;
bool isLSwitchedToBearish;
//
// Hind ...
bool isHBullish;
bool isHBearish;
bool isHSwitchedToBullish;
bool isHSwitchedToBearish;
//
void Clean()
{
//
Clean(cBull);
Clean(cBear);
Clean(sBull);
Clean(sBear);
Clean(mBull);
Clean(mBear);
Clean(lBull);
Clean(lBear);
Clean(hBull);
Clean(hBear);
//
ArraySetAsSeries(cBull, true);
ArraySetAsSeries(cBear, true);
ArraySetAsSeries(sBull, true);
ArraySetAsSeries(sBear, true);
ArraySetAsSeries(mBull, true);
ArraySetAsSeries(mBear, true);
ArraySetAsSeries(lBull, true);
ArraySetAsSeries(lBear, true);
ArraySetAsSeries(hBull, true);
ArraySetAsSeries(hBear, true);
//
// Conditions ...
//
// Power ...
hasBullishPower = false;
hasBearishPower = false;
isBullishPowerUp = false;
isBearishPowerUp = false;
isBullishPowerIncreasing = false;
isBullishPowerDecreasing = false;
isBearishPowerIncreasing = false;
isBearishPowerDecreasing = false;
//
// Current ...
isCBullish = false;
isCBearish = false;
isCSwitchedToBullish = false;
isCSwitchedToBearish = false;
//
// Short ...
isSBullish = false;
isSBearish = false;
isSSwitchedToBullish = false;
isSSwitchedToBearish = false;
//
// Medium ...
isMBullish = false;
isMBearish = false;
isMSwitchedToBullish = false;
isMSwitchedToBearish = false;
//
// Long ...
isLBullish = false;
isLBearish = false;
isLSwitchedToBullish = false;
isLSwitchedToBearish = false;
//
// Hind ...
isHBullish = false;
isHBearish = false;
isHSwitchedToBullish = false;
isHSwitchedToBearish = 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 ...
//
// Conditions ...
//
// 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++;
}
//
// Current ...
if (isCBullish)
{
bullishScore++;
}
if (isCBearish)
{
bearishScore++;
}
if (isCSwitchedToBullish)
{
bullishScore++;
}
if (isCSwitchedToBearish)
{
bearishScore++;
}
//
// Short ...
if (isSBullish)
{
bullishScore++;
}
if (isSBearish)
{
bearishScore++;
}
if (isSSwitchedToBullish)
{
bullishScore++;
}
if (isSSwitchedToBearish)
{
bearishScore++;
}
//
// Medium ...
if (isMBullish)
{
bullishScore++;
}
if (isMBearish)
{
bearishScore++;
}
if (isMSwitchedToBullish)
{
bullishScore++;
}
if (isMSwitchedToBearish)
{
bearishScore++;
}
//
// Long ...
if (isLBullish)
{
bullishScore++;
}
if (isLBearish)
{
bearishScore++;
}
if (isLSwitchedToBullish)
{
bullishScore++;
}
if (isLSwitchedToBearish)
{
bearishScore++;
}
//
// Hind ...
if (isHBullish)
{
bullishScore++;
}
if (isHBearish)
{
bearishScore++;
}
if (isHSwitchedToBullish)
{
bullishScore++;
}
if (isHSwitchedToBearish)
{
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) +
//
// Current ...
ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) +
ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) +
ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) +
//
// Short ...
ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) +
ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) +
ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) +
//
// Medium ...
ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) +
ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) +
ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) +
//
// Long ...
ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) +
ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) +
ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) +
//
// Hind ...
ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) +
ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) +
ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) +
//
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
//
string GetTag()
{
return "XCHTD";
}
};
//
// Class ...
class XSCXCHTDHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCHTDHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCHTDHelper()
{
//
Clean(cBullBuffer);
Clean(cBearBuffer);
Clean(sBullBuffer);
Clean(sBearBuffer);
Clean(mBullBuffer);
Clean(mBearBuffer);
Clean(lBullBuffer);
Clean(lBearBuffer);
Clean(hBullBuffer);
Clean(hBearBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCHTDInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(cBullBuffer, true);
ArraySetAsSeries(cBearBuffer, true);
ArraySetAsSeries(sBullBuffer, true);
ArraySetAsSeries(sBearBuffer, true);
ArraySetAsSeries(mBullBuffer, true);
ArraySetAsSeries(mBearBuffer, true);
ArraySetAsSeries(lBullBuffer, true);
ArraySetAsSeries(lBearBuffer, true);
ArraySetAsSeries(hBullBuffer, true);
ArraySetAsSeries(hBearBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xchtd",
//
// Inputs ...
//
// Market ...
"",
mInputs.length, // Length
mInputs.mode, // Mode
//
// Cycles ...
"",
//
// Short ...
"",
mInputs.scMethod,
mInputs.scPeriod,
//
// Medium ...
"",
mInputs.mcMethod,
mInputs.mcPeriod,
//
// Long ...
"",
mInputs.lcMethod,
mInputs.lcPeriod,
//
// Hind ...
"",
mInputs.hcMethod,
mInputs.hcPeriod,
//
// Presentation ...
"",
mInputs.showCurrent,
mInputs.showShort,
mInputs.showMedium,
mInputs.showLong,
mInputs.showHind
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCHTDInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCHTDInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
// Current ...
//
double GetCBull(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return cBullBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyCBull(
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,
cBullBuffer,
buffer,
forceClean
//
);
}
//
double GetCBear(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return cBearBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyCBear(
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,
cBearBuffer,
buffer,
forceClean
//
);
}
//
// Short ...
//
double GetSBull(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return sBullBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySBull(
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,
sBullBuffer,
buffer,
forceClean
//
);
}
//
double GetSBear(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return sBearBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySBear(
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,
sBearBuffer,
buffer,
forceClean
//
);
}
//
// Medium ...
//
double GetMBull(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return mBullBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMBull(
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,
mBullBuffer,
buffer,
forceClean
//
);
}
//
double GetMBear(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return mBearBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMBear(
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,
mBearBuffer,
buffer,
forceClean
//
);
}
//
// Long ...
//
double GetLBull(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return lBullBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyLBull(
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,
lBullBuffer,
buffer,
forceClean
//
);
}
//
double GetLBear(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return lBearBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyLBear(
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,
lBearBuffer,
buffer,
forceClean
//
);
}
//
// Hind ...
//
double GetHBull(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return hBullBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyHBull(
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,
hBullBuffer,
buffer,
forceClean
//
);
}
//
double GetHBear(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return hBearBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyHBear(
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,
hBearBuffer,
buffer,
forceClean
//
);
}
//
// Tools ...
//
void GetCycle(
int barIndex, // Bar Index
double &bull,
double &bear,
ENUM_X_MARKET_CYCLES cycle //
)
{
//
bull = 0;
bear = 0;
//
switch (cycle)
{
//
// CURRENT ...
case X_MARKET_CYCLE_UNKNOWN:
//
bull = GetCBull(barIndex);
bear = GetCBear(barIndex);
break;
//
// SHORT ...
case X_MARKET_CYCLE_SHORT:
//
bull = GetSBull(barIndex);
bear = GetSBear(barIndex);
break;
//
// MEDIUM ...
case X_MARKET_CYCLE_MEDIUM:
//
bull = GetMBull(barIndex);
bear = GetMBear(barIndex);
break;
//
// LONG ...
case X_MARKET_CYCLE_LONG:
//
bull = GetLBull(barIndex);
bear = GetLBear(barIndex);
break;
//
// HIND ...
case X_MARKET_CYCLE_HIND:
//
bull = GetHBull(barIndex);
bear = GetHBear(barIndex);
break;
}
}
//
bool IsCycleBullish(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
bool result = false;
//
double bull = 0;
double bear = 0;
GetCycle(
barIndex,
bull,
bear,
cycle //
);
//
result = bull > bear;
//
return result;
}
//
bool IsCycleBearish(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
bool result = false;
//
double bull = 0;
double bear = 0;
GetCycle(
barIndex,
bull,
bear,
cycle //
);
//
result = bull < bear;
//
return result;
}
//
double GetCyclePower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle //
)
{
//
double result = 0;
//
double bull = 0;
double bear = 0;
GetCycle(
barIndex,
bull,
bear,
cycle //
);
//
result = MathAbs(bull - bear);
//
return result;
}
//
int GetPowers(
int barIndex, // Bar Index
double &values[] //
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES allCycles[];
int count = GetAllMarketCycles(allCycles);
if (!IsValidSize(count))
{
return result;
}
//
result = GetCyclesPowers(
barIndex,
values,
allCycles //
);
//
return result;
}
//
int GetCyclesPowers(
int barIndex, // Bar Index
double &values[],
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
int result = 0;
//
Clean(values);
//
int count = ArraySize(cycles);
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
double iValue = GetCyclePower(
barIndex,
cycles[i] //
);
//
Add(
iValue,
values //
);
}
//
result = ArraySize(values);
//
return result;
}
//
int GetBullishCycles(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
int result = 0;
//
Clean(cycles);
//
ENUM_X_MARKET_CYCLES allCycles[];
int count = GetAllMarketCycles(allCycles);
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
bool isBullish = IsCycleBullish(
barIndex,
allCycles[i] //
);
//
if (isBullish)
{
//
Add(
allCycles[i],
cycles //
);
}
}
//
result = ArraySize(cycles);
//
return result;
}
//
int GetBearishCycles(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
int result = 0;
//
Clean(cycles);
//
ENUM_X_MARKET_CYCLES allCycles[];
int count = GetAllMarketCycles(allCycles);
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
bool isBearish = IsCycleBearish(
barIndex,
allCycles[i] //
);
//
if (isBearish)
{
//
Add(
allCycles[i],
cycles //
);
}
}
//
result = ArraySize(cycles);
//
return result;
}
//
int GetBullishCyclesPowers(
int barIndex, // Bar Index
double &values[] //
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES cycles[];
int count = GetBullishCycles(
barIndex,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetCyclesPowers(
barIndex,
values,
cycles //
);
//
return result;
}
//
int GetBearishCyclesPowers(
int barIndex, // Bar Index
double &values[] //
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES cycles[];
int count = GetBearishCycles(
barIndex,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetCyclesPowers(
barIndex,
values,
cycles //
);
//
return result;
}
//
double GetMaxPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetCyclesMaxPower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
double result = 0;
//
double values[];
int count = GetCyclesPowers(
barIndex,
values,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetCyclesMinPower(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] //
)
{
//
double result = 0;
//
double values[];
int count = GetCyclesPowers(
barIndex,
values,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetMaxBullishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBullishCyclesPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinBullishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBullishCyclesPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetMaxBearishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBearishCyclesPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMinBearishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBearishCyclesPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetBullishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBullishCyclesPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSum(values);
//
return result;
}
//
double GetBearishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBearishCyclesPowers(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSum(values);
//
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++)
{
//
bool isBullish = IsCycleBullish(
barIndex,
cycles[i] //
);
if (isBullish)
{
//
double power = GetCyclePower(
barIndex,
cycles[i] //
);
//
result += MathAbs(power);
}
}
//
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++)
{
//
bool isBearish = IsCycleBearish(
barIndex,
cycles[i] //
);
if (isBearish)
{
//
double power = GetCyclePower(
barIndex,
cycles[i] //
);
//
result += MathAbs(power);
}
}
//
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(
XCHTDConditions &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;
//
// Buffers ...
//
// Current ...
CopyCBull(
zIndex,
loopback,
conditions.cBull //
);
CopyCBear(
zIndex,
loopback,
conditions.cBear //
);
//
// Short ...
CopySBull(
zIndex,
loopback,
conditions.sBull //
);
CopySBear(
zIndex,
loopback,
conditions.sBear //
);
//
// Medium ...
CopyMBull(
zIndex,
loopback,
conditions.mBull //
);
CopyMBear(
zIndex,
loopback,
conditions.mBear //
);
//
// Long ...
CopyLBull(
zIndex,
loopback,
conditions.lBull //
);
CopyLBear(
zIndex,
loopback,
conditions.lBear //
);
//
// Hind ...
CopyHBull(
zIndex,
loopback,
conditions.hBull //
);
CopyHBear(
zIndex,
loopback,
conditions.hBear //
);
//
// 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;
}
//
// 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;
//
// Current ...
//
bool isCBullish = conditions.cBull[cIndex] > conditions.cBear[cIndex];
bool isCBullishPrev = conditions.cBull[pIndex] > conditions.cBear[pIndex];
//
bool isCBearish = conditions.cBull[cIndex] < conditions.cBear[cIndex];
bool isCBearishPrev = conditions.cBull[pIndex] < conditions.cBear[pIndex];
//
bool isCSwitchedToBullish = isCBullish &&
!isCBullishPrev;
bool isCSwitchedToBearish = isCBearish &&
!isCBearishPrev;
//
conditions.isCBullish = isCBullish;
conditions.isCBearish = isCBearish;
conditions.isCSwitchedToBullish = isCSwitchedToBullish;
conditions.isCSwitchedToBearish = isCSwitchedToBearish;
//
// Short ...
//
bool isSBullish = conditions.sBull[cIndex] > conditions.sBear[cIndex];
bool isSBullishPrev = conditions.sBull[pIndex] > conditions.sBear[pIndex];
//
bool isSBearish = conditions.sBull[cIndex] < conditions.sBear[cIndex];
bool isSBearishPrev = conditions.sBull[pIndex] < conditions.sBear[pIndex];
//
bool isSSwitchedToBullish = isSBullish &&
!isSBullishPrev;
bool isSSwitchedToBearish = isSBearish &&
!isSBearishPrev;
//
conditions.isSBullish = isSBullish;
conditions.isSBearish = isSBearish;
conditions.isSSwitchedToBullish = isSSwitchedToBullish;
conditions.isSSwitchedToBearish = isSSwitchedToBearish;
//
// Medium ...
//
bool isMBullish = conditions.mBull[cIndex] > conditions.mBear[cIndex];
bool isMBullishPrev = conditions.mBull[pIndex] > conditions.mBear[pIndex];
//
bool isMBearish = conditions.mBull[cIndex] < conditions.mBear[cIndex];
bool isMBearishPrev = conditions.mBull[pIndex] < conditions.mBear[pIndex];
//
bool isMSwitchedToBullish = isMBullish &&
!isMBullishPrev;
bool isMSwitchedToBearish = isMBearish &&
!isMBearishPrev;
//
conditions.isMBullish = isMBullish;
conditions.isMBearish = isMBearish;
conditions.isMSwitchedToBullish = isMSwitchedToBullish;
conditions.isMSwitchedToBearish = isMSwitchedToBearish;
//
// Long ...
//
bool isLBullish = conditions.lBull[cIndex] > conditions.lBear[cIndex];
bool isLBullishPrev = conditions.lBull[pIndex] > conditions.lBear[pIndex];
//
bool isLBearish = conditions.lBull[cIndex] < conditions.lBear[cIndex];
bool isLBearishPrev = conditions.lBull[pIndex] < conditions.lBear[pIndex];
//
bool isLSwitchedToBullish = isLBullish &&
!isLBullishPrev;
bool isLSwitchedToBearish = isLBearish &&
!isLBearishPrev;
//
conditions.isLBullish = isLBullish;
conditions.isLBearish = isLBearish;
conditions.isLSwitchedToBullish = isLSwitchedToBullish;
conditions.isLSwitchedToBearish = isLSwitchedToBearish;
//
// Hind ...
//
bool isHBullish = conditions.hBull[cIndex] > conditions.hBear[cIndex];
bool isHBullishPrev = conditions.hBull[pIndex] > conditions.hBear[pIndex];
//
bool isHBearish = conditions.hBull[cIndex] < conditions.hBear[cIndex];
bool isHBearishPrev = conditions.hBull[pIndex] < conditions.hBear[pIndex];
//
bool isHSwitchedToBullish = isHBullish &&
!isHBullishPrev;
bool isHSwitchedToBearish = isHBearish &&
!isHBearishPrev;
//
conditions.isHBullish = isHBullish;
conditions.isHBearish = isHBearish;
conditions.isHSwitchedToBullish = isHSwitchedToBullish;
conditions.isHSwitchedToBearish = isHSwitchedToBearish;
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
XCHTDInputs mInputs; // Inputs ...
//
// Buffers ...
//
// Current ...
double cBullBuffer[];
double cBearBuffer[];
//
// Short ...
double sBullBuffer[];
double sBearBuffer[];
//
// Medium ...
double mBullBuffer[];
double mBearBuffer[];
//
// Long ...
double lBullBuffer[];
double lBearBuffer[];
//
// Hind ...
double hBullBuffer[];
double hBearBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Current ...
//
// Bull ...
CopyBuffer(
mHandler,
XCHTD_C_BULL_LINE,
0,
totalBars,
cBullBuffer
//
);
//
// Bear ...
CopyBuffer(
mHandler,
XCHTD_C_BEAR_LINE,
0,
totalBars,
cBearBuffer
//
);
//
// Short ...
//
// Bull ...
CopyBuffer(
mHandler,
XCHTD_S_BULL_LINE,
0,
totalBars,
sBullBuffer
//
);
//
// Bear ...
CopyBuffer(
mHandler,
XCHTD_S_BEAR_LINE,
0,
totalBars,
sBearBuffer
//
);
//
// Medium ...
//
// Bull ...
CopyBuffer(
mHandler,
XCHTD_M_BULL_LINE,
0,
totalBars,
mBullBuffer
//
);
//
// Bear ...
CopyBuffer(
mHandler,
XCHTD_M_BEAR_LINE,
0,
totalBars,
mBearBuffer
//
);
//
// Long ...
//
// Bull ...
CopyBuffer(
mHandler,
XCHTD_L_BULL_LINE,
0,
totalBars,
lBullBuffer
//
);
//
// Bear ...
CopyBuffer(
mHandler,
XCHTD_L_BEAR_LINE,
0,
totalBars,
lBearBuffer
//
);
//
// Hind ...
//
// Bull ...
CopyBuffer(
mHandler,
XCHTD_H_BULL_LINE,
0,
totalBars,
hBullBuffer
//
);
//
// Bear ...
CopyBuffer(
mHandler,
XCHTD_H_BEAR_LINE,
0,
totalBars,
hBearBuffer
//
);
};
};
//