Files
MQL5Data/Helpers/x-saherelm.xchvwap.helper.mq5
T
saherelm f7040490c8 apply some changes to Pack npm scripts for support Pack and Compile Workspace ...
add XCHVWAP Indicator, extends it's Helper class and implement it's usage inside XCH strategy ...
2024-08-03 06:14:47 +03:30

2608 lines
52 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCHVWAPHelper
// 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_XCHVWAP_BUFFERS
{
//
XCHVWAP_S_LINE = 0,
XCHVWAP_S_STATE_LINE = 10,
//
XCHVWAP_M_LINE = 2,
XCHVWAP_M_STATE_LINE = 11,
//
XCHVWAP_L_LINE = 4,
XCHVWAP_L_STATE_LINE = 12,
//
XCHVWAP_H_LINE = 6,
XCHVWAP_H_STATE_LINE = 13,
};
//
enum ENUM_XCHVWAP_STATES
{
//
XCHVWAP_BULLISH_STATE = 1,
XCHVWAP_BEARISH_STATE = 2,
XCHVWAP_NEUTURAL_STATE = 3,
};
//
// Input Models ...
struct XCHVWAPInputs
{
//
// Props ...
//
// Market ...
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 showShort; // Show Short Cycle
bool showMedium; // Show Medium Cycle
bool showLong; // Show Long Cycle
bool showHind; // Show Hind Cycle
//
// Constructor(s) ...
XCHVWAPInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
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;
//
showShort = false;
showMedium = false;
showLong = false;
showHind = false;
}
//
// Default ...
void Default()
{
//
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;
//
showShort = true;
showMedium = true;
showLong = true;
showHind = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
(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, 0)
//
;
//
return result;
}
};
//
// Define Conditions ...
struct XCHVWAPConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
//
// Short ...
double s[];
double sState[];
//
// Medium ...
double m[];
double mState[];
//
// Long ...
double l[];
double lState[];
//
// Hind ...
double h[];
double hState[];
//
// Conditions ...
//
// Power ...
bool hasBullishPower;
bool hasBearishPower;
bool isBullishPowerUp;
bool isBearishPowerUp;
bool isBullishPowerIncreasing;
bool isBullishPowerDecreasing;
bool isBearishPowerIncreasing;
bool isBearishPowerDecreasing;
//
// 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(s);
Clean(sState);
Clean(m);
Clean(mState);
Clean(l);
Clean(lState);
Clean(h);
Clean(hState);
//
ArraySetAsSeries(s, true);
ArraySetAsSeries(sState, true);
ArraySetAsSeries(m, true);
ArraySetAsSeries(mState, true);
ArraySetAsSeries(l, true);
ArraySetAsSeries(lState, true);
ArraySetAsSeries(h, true);
ArraySetAsSeries(hState, true);
//
// Conditions ...
//
// Power ...
hasBullishPower = false;
hasBearishPower = false;
isBullishPowerUp = false;
isBearishPowerUp = false;
isBullishPowerIncreasing = false;
isBullishPowerDecreasing = false;
isBearishPowerIncreasing = false;
isBearishPowerDecreasing = 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++;
}
//
// 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) +
//
// 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 "XCHVWAP";
}
};
//
// Class ...
class XSCXCHVWAPHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCHVWAPHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCHVWAPHelper()
{
//
Clean(sBuffer);
Clean(sStateBuffer);
Clean(mBuffer);
Clean(mStateBuffer);
Clean(lBuffer);
Clean(lStateBuffer);
Clean(hBuffer);
Clean(hStateBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCHVWAPInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(sBuffer, true);
ArraySetAsSeries(sStateBuffer, true);
ArraySetAsSeries(mBuffer, true);
ArraySetAsSeries(mStateBuffer, true);
ArraySetAsSeries(lBuffer, true);
ArraySetAsSeries(lStateBuffer, true);
ArraySetAsSeries(hBuffer, true);
ArraySetAsSeries(hStateBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xchvwap",
//
// Inputs ...
//
// Market ...
"",
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.showShort,
mInputs.showMedium,
mInputs.showLong,
mInputs.showHind
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
XCHVWAPInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCHVWAPInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
// Short ...
//
double GetS(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return sBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyS(
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,
sBuffer,
buffer,
forceClean
//
);
}
//
double GetSState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return sStateBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySState(
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,
sStateBuffer,
buffer,
forceClean
//
);
}
//
// Medium ...
//
double GetM(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return mBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyM(
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,
mBuffer,
buffer,
forceClean
//
);
}
//
double GetMState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return mStateBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMState(
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,
mStateBuffer,
buffer,
forceClean
//
);
}
//
// Long ...
//
double GetL(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return lBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyL(
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,
lBuffer,
buffer,
forceClean
//
);
}
//
double GetLState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return lStateBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyLState(
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,
lStateBuffer,
buffer,
forceClean
//
);
}
//
// Hind ...
//
double GetH(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return hBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyH(
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,
hBuffer,
buffer,
forceClean
//
);
}
//
double GetHState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return hStateBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyHState(
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,
hStateBuffer,
buffer,
forceClean
//
);
}
//
// Tools ...
//
ENUM_XCHVWAP_STATES ToState(double value)
{
//
ENUM_XCHVWAP_STATES result = value == 1
? XCHVWAP_BULLISH_STATE
: value == 2
? XCHVWAP_BEARISH_STATE
: XCHVWAP_NEUTURAL_STATE;
//
return result;
}
//
bool IsBullish(double value)
{
//
bool result = false;
//
result =
//
ToState(value) == XCHVWAP_BULLISH_STATE;
//
;
//
return result;
}
//
bool IsBearish(double value)
{
//
bool result = false;
//
result =
//
ToState(value) == XCHVWAP_BEARISH_STATE;
//
;
//
return result;
}
//
int GetValues(
int barIndex, // Bar Index
double &values[] // Result
)
{
//
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 = GetCycleValue(
barIndex,
cycles[i] //
);
//
Add(
iValue,
values //
);
}
//
result = ArraySize(values);
//
return result;
}
//
double GetCycleValue(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle // Cycle
)
{
//
double result = 0;
//
switch (cycle)
{
//
// SHORT ...
case X_MARKET_CYCLE_SHORT:
result = GetS(barIndex);
break;
//
// MEDIUM ...
case X_MARKET_CYCLE_MEDIUM:
result = GetM(barIndex);
break;
//
// LONG ...
case X_MARKET_CYCLE_LONG:
result = GetL(barIndex);
break;
//
// HIND ...
case X_MARKET_CYCLE_HIND:
result = GetH(barIndex);
break;
}
//
return result;
}
//
double GetCycleState(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES cycle // Cycle
)
{
//
double result = 0;
//
switch (cycle)
{
//
// SHORT ...
case X_MARKET_CYCLE_SHORT:
result = GetSState(barIndex);
break;
//
// MEDIUM ...
case X_MARKET_CYCLE_MEDIUM:
result = GetMState(barIndex);
break;
//
// LONG ...
case X_MARKET_CYCLE_LONG:
result = GetLState(barIndex);
break;
//
// HIND ...
case X_MARKET_CYCLE_HIND:
result = GetHState(barIndex);
break;
}
//
return result;
}
//
int GetBullishCycles(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] // Result
)
{
//
int result = 0;
//
Clean(cycles);
//
ENUM_X_MARKET_CYCLES allCycles[];
int allCyclesCount = GetAllMarketCycles(allCycles);
if (!IsValidSize(allCyclesCount))
{
return result;
}
//
for (int i = 0; i < allCyclesCount; i++)
{
//
double cState = GetCycleState(
barIndex,
allCycles[i] //
);
//
if (IsBullish(cState))
{
//
Add(
allCycles[i],
cycles //
);
}
}
//
result = ArraySize(cycles);
//
return result;
}
//
int GetBearishCycles(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] // Result
)
{
//
int result = 0;
//
Clean(cycles);
//
ENUM_X_MARKET_CYCLES allCycles[];
int allCyclesCount = GetAllMarketCycles(allCycles);
if (!IsValidSize(allCyclesCount))
{
return result;
}
//
for (int i = 0; i < allCyclesCount; i++)
{
//
double cState = GetCycleState(
barIndex,
allCycles[i] //
);
//
if (IsBearish(cState))
{
//
Add(
allCycles[i],
cycles //
);
}
}
//
result = ArraySize(cycles);
//
return result;
}
//
int GetCyclesValues(
int barIndex, // Bar Index
double &values[], // Values
ENUM_X_MARKET_CYCLES &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 = GetCycleValue(
barIndex,
cycles[i] //
);
//
Add(
iValue,
values //
);
}
//
result = ArraySize(values);
//
return result;
}
//
int GetBullishCyclesValues(
int barIndex, // Bar Index
double &values[] // Values
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES cycles[];
int count = GetBullishCycles(
barIndex,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetCyclesValues(
barIndex,
values,
cycles //
);
//
return result;
}
//
int GetBearishCyclesValues(
int barIndex, // Bar Index
double &values[] // Values
)
{
//
int result = 0;
//
Clean(values);
//
ENUM_X_MARKET_CYCLES cycles[];
int count = GetBearishCycles(
barIndex,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetCyclesValues(
barIndex,
values,
cycles //
);
//
return result;
}
//
double GetCyclesMax(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] // Cycles
)
{
//
double result = 0;
//
double values[];
int count = GetCyclesValues(
barIndex,
values,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetCyclesMin(
int barIndex, // Bar Index
ENUM_X_MARKET_CYCLES &cycles[] // Cycles
)
{
//
double result = 0;
//
double values[];
int count = GetCyclesValues(
barIndex,
values,
cycles //
);
if (!IsValidSize(count))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetMax(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int valuesCount = GetValues(
barIndex,
values //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMax(values);
//
return result;
}
//
double GetMin(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int valuesCount = GetValues(
barIndex,
values //
);
if (!IsValidSize(valuesCount))
{
return result;
}
//
result = GetSpecifiedMin(values);
//
return result;
}
//
double GetBullishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBullishCyclesValues(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = MathAbs(GetSum(values));
//
return result;
}
//
double GetBearishPower(
int barIndex // Bar Index
)
{
//
double result = 0;
//
double values[];
int count = GetBearishCyclesValues(
barIndex,
values //
);
if (!IsValidSize(count))
{
return result;
}
//
result = MathAbs(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++)
{
//
double power = GetCycleValue(
barIndex,
cycles[i] //
);
//
if (IsBullish(power))
{
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++)
{
//
double power = GetCycleValue(
barIndex,
cycles[i] //
);
//
if (IsBearish(power))
{
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(
XCHVWAPConditions &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 ...
//
// Short ...
CopyS(
zIndex,
loopback,
conditions.s //
);
CopySState(
zIndex,
loopback,
conditions.sState //
);
//
// Medium ...
CopyM(
zIndex,
loopback,
conditions.m //
);
CopyMState(
zIndex,
loopback,
conditions.mState //
);
//
// Long ...
CopyL(
zIndex,
loopback,
conditions.l //
);
CopyLState(
zIndex,
loopback,
conditions.lState //
);
//
// Hind ...
CopyH(
zIndex,
loopback,
conditions.h //
);
CopyHState(
zIndex,
loopback,
conditions.hState //
);
//
// 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;
//
// Short ...
//
bool isSBullish = IsBullish(conditions.sState[cIndex]);
bool isSBullishPrev = IsBullish(conditions.sState[pIndex]);
//
bool isSBearish = IsBearish(conditions.sState[cIndex]);
bool isSBearishPrev = IsBearish(conditions.sState[pIndex]);
//
bool isSSwitchedToBullish = isSBullish &&
!isSBullishPrev;
bool isSSwitchedToBearish = isSBearish &&
!isSBearishPrev;
//
conditions.isSBullish = isSBullish;
conditions.isSBearish = isSBearish;
conditions.isSSwitchedToBullish = isSSwitchedToBullish;
conditions.isSSwitchedToBearish = isSSwitchedToBearish;
//
// Medium ...
//
bool isMBullish = IsBullish(conditions.mState[cIndex]);
bool isMBullishPrev = IsBullish(conditions.mState[pIndex]);
//
bool isMBearish = IsBearish(conditions.mState[cIndex]);
bool isMBearishPrev = IsBearish(conditions.mState[pIndex]);
//
bool isMSwitchedToBullish = isMBullish &&
!isMBullishPrev;
bool isMSwitchedToBearish = isMBearish &&
!isMBearishPrev;
//
conditions.isMBullish = isMBullish;
conditions.isMBearish = isMBearish;
conditions.isMSwitchedToBullish = isMSwitchedToBullish;
conditions.isMSwitchedToBearish = isMSwitchedToBearish;
//
// Long ...
//
bool isLBullish = IsBullish(conditions.lState[cIndex]);
bool isLBullishPrev = IsBullish(conditions.lState[pIndex]);
//
bool isLBearish = IsBearish(conditions.lState[cIndex]);
bool isLBearishPrev = IsBearish(conditions.lState[pIndex]);
//
bool isLSwitchedToBullish = isLBullish &&
!isLBullishPrev;
bool isLSwitchedToBearish = isLBearish &&
!isLBearishPrev;
//
conditions.isLBullish = isLBullish;
conditions.isLBearish = isLBearish;
conditions.isLSwitchedToBullish = isLSwitchedToBullish;
conditions.isLSwitchedToBearish = isLSwitchedToBearish;
//
// Hind ...
//
bool isHBullish = IsBullish(conditions.hState[cIndex]);
bool isHBullishPrev = IsBullish(conditions.hState[pIndex]);
//
bool isHBearish = IsBearish(conditions.hState[cIndex]);
bool isHBearishPrev = IsBearish(conditions.hState[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 ...
XCHVWAPInputs mInputs; // Inputs ...
//
// Buffers ...
//
// Short ...
double sBuffer[];
double sStateBuffer[];
//
// Medium ...
double mBuffer[];
double mStateBuffer[];
//
// Long ...
double lBuffer[];
double lStateBuffer[];
//
// Hind ...
double hBuffer[];
double hStateBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Short ...
CopyBuffer(
mHandler,
XCHVWAP_S_LINE,
0,
totalBars,
sBuffer
//
);
CopyBuffer(
mHandler,
XCHVWAP_S_STATE_LINE,
0,
totalBars,
sStateBuffer
//
);
//
// Medium ...
CopyBuffer(
mHandler,
XCHVWAP_M_LINE,
0,
totalBars,
mBuffer
//
);
CopyBuffer(
mHandler,
XCHVWAP_M_STATE_LINE,
0,
totalBars,
mStateBuffer
//
);
//
// Long ...
CopyBuffer(
mHandler,
XCHVWAP_L_LINE,
0,
totalBars,
lBuffer
//
);
CopyBuffer(
mHandler,
XCHVWAP_L_STATE_LINE,
0,
totalBars,
lStateBuffer
//
);
//
// Hind ...
CopyBuffer(
mHandler,
XCHVWAP_H_LINE,
0,
totalBars,
hBuffer
//
);
CopyBuffer(
mHandler,
XCHVWAP_H_STATE_LINE,
0,
totalBars,
hStateBuffer
//
);
};
};
//