Files
MQL5Data/Helpers/x-saherelm.xchstr.helper.mq5
T

1666 lines
33 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XSCXCHSTRHelper
// 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_XCHSTR_BUFFERS
{
//
XCHSTR_C_LINE = 0,
XCHSTR_C_STATE_LINE = 11,
//
XCHSTR_S_LINE = 2,
XCHSTR_S_STATE_LINE = 16,
//
XCHSTR_M_LINE = 4,
XCHSTR_M_STATE_LINE = 21,
//
XCHSTR_L_LINE = 6,
XCHSTR_L_STATE_LINE = 26,
//
XCHSTR_H_LINE = 8,
XCHSTR_H_STATE_LINE = 31,
};
//
enum ENUM_XCHSTR_TREND_STATES
{
X_STR_BULLISH = 1, // Bullish
X_STR_BEARISH = -1, // Bearish
};
//
// Input Models ...
struct XCHSTRInputs
{
//
// Props ...
//
// Market ...
int length; // Length
double multiplier; // Multiplier
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 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) ...
XCHSTRInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
length = 0;
multiplier = 0;
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;
//
showCurrent = false;
showShort = false;
showMedium = false;
showLong = false;
showHind = false;
}
//
// Default ...
void Default()
{
//
length = 14;
multiplier = 3.5;
appliedTo = PRICE_MEDIAN;
//
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 &&
multiplier > 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 XCHSTRConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
//
// Current ...
double cTrend[];
double cState[];
//
// Short ...
double sTrend[];
double sState[];
//
// Medium ...
double mTrend[];
double mState[];
//
// Long ...
double lTrend[];
double lState[];
//
// Hind ...
double hTrend[];
double hState[];
//
// Conditions ...
//
// 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(cTrend);
Clean(cState);
Clean(sTrend);
Clean(sState);
Clean(mTrend);
Clean(mState);
Clean(lTrend);
Clean(lState);
Clean(hTrend);
Clean(hState);
//
ArraySetAsSeries(cTrend, true);
ArraySetAsSeries(cState, true);
ArraySetAsSeries(sTrend, true);
ArraySetAsSeries(sState, true);
ArraySetAsSeries(mTrend, true);
ArraySetAsSeries(mState, true);
ArraySetAsSeries(lTrend, true);
ArraySetAsSeries(lState, true);
ArraySetAsSeries(hTrend, true);
ArraySetAsSeries(hState, true);
//
// Conditions ...
//
// 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 ...
//
// 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 =
//
// 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 "XCHSTR";
}
};
//
// Class ...
class XSCXCHSTRHelper : public XSCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XSCXCHSTRHelper() : XSCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XSCXCHSTRHelper()
{
//
Clean(cTrendBuffer);
Clean(cStateBuffer);
Clean(sTrendBuffer);
Clean(sStateBuffer);
Clean(mTrendBuffer);
Clean(mStateBuffer);
Clean(lTrendBuffer);
Clean(lStateBuffer);
Clean(hTrendBuffer);
Clean(hStateBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
XCHSTRInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
mInputs = inputs;
//
ArraySetAsSeries(cTrendBuffer, true);
ArraySetAsSeries(cStateBuffer, true);
ArraySetAsSeries(sTrendBuffer, true);
ArraySetAsSeries(sStateBuffer, true);
ArraySetAsSeries(mTrendBuffer, true);
ArraySetAsSeries(mStateBuffer, true);
ArraySetAsSeries(lTrendBuffer, true);
ArraySetAsSeries(lStateBuffer, true);
ArraySetAsSeries(hTrendBuffer, true);
ArraySetAsSeries(hStateBuffer, true);
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.xchstr",
//
// Inputs ...
//
// Market ...
"",
mInputs.length, // Length
mInputs.multiplier, // Multiplier
mInputs.appliedTo, // Applied To
//
// 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 ...
//
XCHSTRInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
XCHSTRInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Buffers ...
//
// Current ...
//
// Trend ...
//
double GetCTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return cTrendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyCTrend(
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,
cTrendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XCHSTR_TREND_STATES GetCState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XCHSTR_TREND_STATES)((int)cStateBuffer[barIndex]);
}
//
// Copy Required Buffer ...
int CopyCState(
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,
cStateBuffer,
buffer,
forceClean
//
);
}
//
// Short ...
//
// Trend ...
//
double GetSTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return sTrendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopySTrend(
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,
sTrendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XCHSTR_TREND_STATES GetSState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XCHSTR_TREND_STATES)((int)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 ...
//
// Trend ...
//
double GetMTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return mTrendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyMTrend(
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,
mTrendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XCHSTR_TREND_STATES GetMState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XCHSTR_TREND_STATES)((int)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 ...
//
// Trend ...
//
double GetLTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return lTrendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyLTrend(
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,
lTrendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XCHSTR_TREND_STATES GetLState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XCHSTR_TREND_STATES)((int)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 ...
//
// Trend ...
//
double GetHTrend(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return hTrendBuffer[barIndex];
}
//
// Copy Required Buffer ...
int CopyHTrend(
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,
hTrendBuffer,
buffer,
forceClean
//
);
}
//
// State ...
//
ENUM_XCHSTR_TREND_STATES GetHState(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
return (ENUM_XCHSTR_TREND_STATES)((int)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_XCHSTR_TREND_STATES ToState(double state)
{
return (ENUM_XCHSTR_TREND_STATES)((int)state);
}
//
bool IsBullish(double state)
{
//
bool result = false;
//
result =
//
ToState(state) == X_STR_BULLISH;
//
;
//
return result;
}
//
bool IsBearish(double state)
{
//
bool result = false;
//
result =
//
ToState(state) == X_STR_BEARISH;
//
;
//
return result;
}
//
// Conditions ...
//
bool GetConditions(
XCHSTRConditions &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 ...
CopyCTrend(
zIndex,
loopback,
conditions.cTrend //
);
CopyCState(
zIndex,
loopback,
conditions.cState //
);
//
// Short ...
CopyCTrend(
zIndex,
loopback,
conditions.sTrend //
);
CopyCState(
zIndex,
loopback,
conditions.sState //
);
//
// Medium ...
CopyCTrend(
zIndex,
loopback,
conditions.mTrend //
);
CopyCState(
zIndex,
loopback,
conditions.mState //
);
//
// Long ...
CopyCTrend(
zIndex,
loopback,
conditions.lTrend //
);
CopyCState(
zIndex,
loopback,
conditions.lState //
);
//
// Hind ...
CopyCTrend(
zIndex,
loopback,
conditions.hTrend //
);
CopyCState(
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;
}
//
// Current ...
//
bool isCBullish = IsBullish(conditions.cState[cIndex]);
bool isCBullishPrev = IsBullish(conditions.cState[pIndex]);
//
bool isCBearish = IsBearish(conditions.cState[cIndex]);
bool isCBearishPrev = IsBearish(conditions.cState[pIndex]);
//
bool isCSwitchedToBullish = isCBullish &&
!isCBullishPrev;
bool isCSwitchedToBearish = isCBearish &&
!isCBearishPrev;
//
conditions.isCBullish = isCBullish;
conditions.isCBearish = isCBearish;
conditions.isCSwitchedToBullish = isCSwitchedToBullish;
conditions.isCSwitchedToBearish = isCSwitchedToBearish;
//
// 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 ...
XCHSTRInputs mInputs; // Inputs ...
//
// Buffers ...
//
// Current ...
double cTrendBuffer[];
double cStateBuffer[];
//
// Short ...
double sTrendBuffer[];
double sStateBuffer[];
//
// Medium ...
double mTrendBuffer[];
double mStateBuffer[];
//
// Long ...
double lTrendBuffer[];
double lStateBuffer[];
//
// Hind ...
double hTrendBuffer[];
double hStateBuffer[];
//
// Tools ...
//
// Calculate Values Until Now ...
void Calculate()
{
//
int totalBars = CountBars();
if (totalBars > 1000)
{
totalBars = 1000;
}
//
// Current ...
//
// Trend ...
CopyBuffer(
mHandler,
XCHSTR_C_LINE,
0,
totalBars,
cTrendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
XCHSTR_C_STATE_LINE,
0,
totalBars,
cStateBuffer
//
);
//
// Short ...
//
// Trend ...
CopyBuffer(
mHandler,
XCHSTR_S_LINE,
0,
totalBars,
sTrendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
XCHSTR_S_STATE_LINE,
0,
totalBars,
sStateBuffer
//
);
//
// Medium ...
//
// Trend ...
CopyBuffer(
mHandler,
XCHSTR_M_LINE,
0,
totalBars,
mTrendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
XCHSTR_M_STATE_LINE,
0,
totalBars,
mStateBuffer
//
);
//
// Long ...
//
// Trend ...
CopyBuffer(
mHandler,
XCHSTR_L_LINE,
0,
totalBars,
lTrendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
XCHSTR_L_STATE_LINE,
0,
totalBars,
lStateBuffer
//
);
//
// Hind ...
//
// Trend ...
CopyBuffer(
mHandler,
XCHSTR_H_LINE,
0,
totalBars,
hTrendBuffer
//
);
//
// State ...
CopyBuffer(
mHandler,
XCHSTR_H_STATE_LINE,
0,
totalBars,
hStateBuffer
//
);
};
};
//