274 lines
5.0 KiB
Plaintext
274 lines
5.0 KiB
Plaintext
//
|
|
// Detect SignalBox Trigger ...
|
|
// Cond1:
|
|
// - Close Under Min / Max ...
|
|
// - All Trendings in Direction ...
|
|
// - Consolidating Trendings ...
|
|
// - ...
|
|
bool CanTriggerCond1(
|
|
XCXCAEAHelper *helper,
|
|
XBoxZone &box,
|
|
ENUM_X_DIRECTION &dir,
|
|
double &sls[],
|
|
int barIndex = 0,
|
|
int loopback = 10 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize Args ...
|
|
Clean(sls);
|
|
dir = X_DIRECTION_NONE;
|
|
loopback = NormalizeInt(loopback, 5);
|
|
barIndex = NormalizeInt(barIndex, 0);
|
|
|
|
//
|
|
// Validate Decision Box ...
|
|
result = box.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve Market Conditions ...
|
|
XCAEAConditions conditions;
|
|
result = helper.GetConditions(
|
|
conditions,
|
|
barIndex,
|
|
loopback //
|
|
);
|
|
|
|
//
|
|
// Extract CBar ...
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
conditions.symbol,
|
|
conditions.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
conditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Bar Conditions ...
|
|
|
|
//
|
|
ENUM_X_DIRECTION barDir;
|
|
|
|
//
|
|
// ENGULF ...
|
|
|
|
//
|
|
bool isCBarEngulfed = helper
|
|
.barAnalyser
|
|
.IsEngulfed(
|
|
cBar,
|
|
barDir //
|
|
);
|
|
|
|
//
|
|
bool isCBarBullishEngulfed =
|
|
isCBarEngulfed &&
|
|
IsBullish(barDir);
|
|
|
|
//
|
|
bool isCBarBearishEngulfed =
|
|
isCBarEngulfed &&
|
|
IsBearish(barDir);
|
|
|
|
//
|
|
bool isBullish = box.IsBullish();
|
|
bool isBearish = box.IsBearish();
|
|
|
|
//
|
|
int zIDX = 0;
|
|
int cIDX = zIDX + 1;
|
|
int pIDX = cIDX + 1;
|
|
int p2IDX = pIDX + 1;
|
|
int p3IDX = p2IDX + 1;
|
|
int p4IDX = p3IDX + 1;
|
|
|
|
//
|
|
// Reading Values ...
|
|
|
|
//
|
|
// SAR ...
|
|
double cSAR = conditions.sarBuffer[cIDX];
|
|
|
|
//
|
|
// SWH ...
|
|
double cSWH = conditions.swingHighBuffer[cIDX];
|
|
|
|
//
|
|
// SWL ...
|
|
double cSWL = conditions.swingLowBuffer[cIDX];
|
|
|
|
//
|
|
// PEAK ...
|
|
double cPeak = conditions.peakBuffer[cIDX];
|
|
|
|
//
|
|
// VALE ...
|
|
double cVale = conditions.valeBuffer[cIDX];
|
|
|
|
//
|
|
// MAH ...
|
|
double cMAH = conditions.mahBuffer[cIDX];
|
|
|
|
//
|
|
// MAC ...
|
|
double cMAC = conditions.macBuffer[cIDX];
|
|
|
|
//
|
|
// MAL ...
|
|
double cMAL = conditions.malBuffer[cIDX];
|
|
|
|
//
|
|
// KI ...
|
|
double cKI = conditions.kiBuffer[cIDX];
|
|
double cKIState = conditions.kiStateBuffer[cIDX];
|
|
|
|
//
|
|
// TKI ...
|
|
double cTKI = conditions.tkiBuffer[cIDX];
|
|
double cTKIState = conditions.tkiStateBuffer[cIDX];
|
|
|
|
//
|
|
// FAST ...
|
|
double cFast = conditions.fastBuffer[cIDX];
|
|
double cFastState = conditions.fastStateBuffer[cIDX];
|
|
|
|
//
|
|
// VIDYA ...
|
|
double cVidya = conditions.vidyaBuffer[cIDX];
|
|
double cVidyaState = conditions.vidyaStateBuffer[cIDX];
|
|
|
|
//
|
|
// TREND ...
|
|
double cTrend = conditions.trendBuffer[cIDX];
|
|
double cTrendState = conditions.trendStateBuffer[cIDX];
|
|
|
|
//
|
|
// Generating Conditions ...
|
|
|
|
//
|
|
bool isSWLOverBox = cSWL > box.lower;
|
|
bool isSWHUnderBox = cSWH < box.upper;
|
|
|
|
//
|
|
bool isValeOverBox = cVale > box.lower;
|
|
bool isPeakUnderBox = cPeak < box.upper;
|
|
|
|
//
|
|
bool hasBullishPress =
|
|
// isBullish &&
|
|
(isSWLOverBox ||
|
|
isValeOverBox);
|
|
|
|
//
|
|
bool hasBearishPress =
|
|
// isBearish &&
|
|
(isSWHUnderBox ||
|
|
isPeakUnderBox);
|
|
|
|
//
|
|
double trends[] = {
|
|
cMAH,
|
|
cMAC,
|
|
cMAL,
|
|
cKI,
|
|
cTKI,
|
|
cFast,
|
|
cVidya,
|
|
cTrend //
|
|
};
|
|
double trendMax = GetMax(trends);
|
|
double trendMin = GetMin(trends);
|
|
Copy(
|
|
trends,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
bool isCloseOverMax = cBar.close > trendMax;
|
|
bool isCloseUnderMin = cBar.close < trendMin;
|
|
|
|
//
|
|
bool isStateBullish =
|
|
cKIState > 0 &&
|
|
cTKIState > 0 &&
|
|
cFastState > 0 &&
|
|
cTrendState > 0 &&
|
|
cVidyaState > 0;
|
|
|
|
//
|
|
bool isStateBearish =
|
|
cKIState < 0 &&
|
|
cTKIState < 0 &&
|
|
cFastState < 0 &&
|
|
cTrendState < 0 &&
|
|
cVidyaState < 0;
|
|
|
|
//
|
|
bool hasBullishTrend =
|
|
// isBullish &&
|
|
isStateBullish &&
|
|
isCloseOverMax;
|
|
|
|
//
|
|
bool hasBearishTrend =
|
|
// isBearish &&
|
|
isStateBearish &&
|
|
isCloseUnderMin;
|
|
|
|
//
|
|
// Summarizing ...
|
|
|
|
//
|
|
bool canTriggerLong =
|
|
// isBullish &&
|
|
hasBullishPress &&
|
|
hasBullishTrend;
|
|
|
|
//
|
|
bool canTriggerShort =
|
|
// isBearish &&
|
|
hasBearishPress &&
|
|
hasBearishTrend;
|
|
|
|
//
|
|
result = canTriggerLong ||
|
|
canTriggerShort;
|
|
if (result)
|
|
{
|
|
//
|
|
dir = canTriggerLong
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
Print("Triggered ...");
|
|
}
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
|
|
//
|
|
cBar.Clean();
|
|
Clean(trends);
|
|
conditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|