Files
MQL5Data/Documents/BKP/1/signals/2.mq5
T

2185 lines
50 KiB
Plaintext

//
// Checking Conditions ...
//
// Retrieve Some Values ...
//
double peak = cXConditions.peaksBuffer[cIDX];
double peakZ = cXConditions.peaksBuffer[zIDX];
double peakP = cXConditions.peaksBuffer[pIDX];
double peakPP = cXConditions.peaksBuffer[ppIDX];
//
double vale = cXConditions.valesBuffer[cIDX];
double valeZ = cXConditions.valesBuffer[zIDX];
double valeP = cXConditions.valesBuffer[pIDX];
double valePP = cXConditions.valesBuffer[ppIDX];
//
double cSMHKOpen = cXConditions.xhkSMOpenBuffer[cIDX];
double cSMHKHigh = cXConditions.xhkSMHighBuffer[cIDX];
double cSMHKClose = cXConditions.xhkSMCloseBuffer[cIDX];
double cSMHKLow = cXConditions.xhkSMLowBuffer[cIDX];
double cSMHKMin = MathMin(cSMHKOpen, cSMHKClose);
double cSMHKMax = MathMax(cSMHKOpen, cSMHKClose);
//
double pSMHKOpen = cXConditions.xhkSMOpenBuffer[pIDX];
double pSMHKHigh = cXConditions.xhkSMHighBuffer[pIDX];
double pSMHKClose = cXConditions.xhkSMCloseBuffer[pIDX];
double pSMHKLow = cXConditions.xhkSMLowBuffer[pIDX];
double pSMHKMin = MathMin(pSMHKOpen, pSMHKClose);
double pSMHKMax = MathMax(pSMHKOpen, pSMHKClose);
//
double atrUpperSM = cXConditions.atrUpperSMBuffer[cIDX];
double atrLowerSM = cXConditions.atrLowerSMBuffer[cIDX];
//
double atrUpperSMZ = cXConditions.atrUpperSMBuffer[zIDX];
double atrLowerSMZ = cXConditions.atrLowerSMBuffer[zIDX];
//
double atrUpperSMP = cXConditions.atrUpperSMBuffer[pIDX];
double atrLowerSMP = cXConditions.atrLowerSMBuffer[pIDX];
//
double atrUpperSMPP = cXConditions.atrUpperSMBuffer[ppIDX];
double atrLowerSMPP = cXConditions.atrLowerSMBuffer[ppIDX];
//
double rsiChange = cXConditions.rsiChangeBuffer[cIDX];
double rsiChangeZ = cXConditions.rsiChangeBuffer[zIDX];
double rsiChangeP = cXConditions.rsiChangeBuffer[pIDX];
double rsiChangePP = cXConditions.rsiChangeBuffer[ppIDX];
//
double rsiChangeSM = cXConditions.rsiChangeSMBuffer[cIDX];
double rsiChangeSMZ = cXConditions.rsiChangeSMBuffer[zIDX];
double rsiChangeSMP = cXConditions.rsiChangeSMBuffer[pIDX];
double rsiChangeSMPP = cXConditions.rsiChangeSMBuffer[ppIDX];
//
double peaksGolden = cXConditions.peaksGoldenBuffer[cIDX];
double peaksGoldenZ = cXConditions.peaksGoldenBuffer[zIDX];
double peaksGoldenP = cXConditions.peaksGoldenBuffer[pIDX];
double peaksGoldenPP = cXConditions.peaksGoldenBuffer[ppIDX];
//
double valesGolden = cXConditions.valesGoldenBuffer[cIDX];
double valesGoldenZ = cXConditions.valesGoldenBuffer[zIDX];
double valesGoldenP = cXConditions.valesGoldenBuffer[pIDX];
double valesGoldenPP = cXConditions.valesGoldenBuffer[ppIDX];
//
double priceChange = cXConditions.priceChangeBuffer[cIDX];
double priceChangeZ = cXConditions.priceChangeBuffer[zIDX];
double priceChangeP = cXConditions.priceChangeBuffer[pIDX];
double priceChangePP = cXConditions.priceChangeBuffer[ppIDX];
//
double priceChangeSM = cXConditions.priceChangeSMBuffer[cIDX];
double priceChangeSMZ = cXConditions.priceChangeSMBuffer[zIDX];
double priceChangeSMP = cXConditions.priceChangeSMBuffer[pIDX];
double priceChangeSMPP = cXConditions.priceChangeSMBuffer[ppIDX];
//
//
//
//
// XHK ...
//
bool isPBarClosedOverSMHK =
//
pBar.IsBullish() &&
pBar.GetUp() > pSMHKMax &&
pBar.GetDown() < pSMHKMin
//
;
//
bool isPBarClosedUnderSMHK =
//
pBar.IsBearish() &&
pBar.GetUp() > pSMHKMax &&
pBar.GetDown() < pSMHKMin
//
;
//
bool isPBarBullishPriceChangeVPattern =
priceChangeP > priceChangePP &&
priceChangeP > priceChange;
//
bool isPBarBerishPriceChangeVPattern =
priceChangeP < priceChangePP &&
priceChangeP < priceChange;
//
bool isPBarPriceChangeOverPeak =
priceChangeP > peak &&
priceChangeP > peakP &&
priceChangeP > peakPP;
//
bool isPBarPriceChangeUnderVale =
priceChangeP < vale &&
priceChangeP < valeP &&
priceChangeP < valePP;
//
bool isPBarCloseOverPeaksGoldenZone =
pBar.close > peaksGoldenP;
//
bool isPBarCloseUnderValesGoldenZone =
pBar.close < valesGoldenP;
//
bool isPBarPriceChangeOverAtrUpper =
priceChangeP > atrUpperSMP;
//
bool isPBarPriceChangeUnderAtrLower =
priceChangeP < atrLowerSMP;
//
isBullish =
//
// false
//
hasSelectedBox &&
selectedBox.IsBullish() &&
cXConditions.isStrBullish
//
// cBar.IsBullish() &&
// isPBarPriceChangeUnderVale &&
// isPBarPriceChangeUnderAtrLower &&
// isPBarBerishPriceChangeVPattern &&
// isPBarCloseUnderValesGoldenZone
//
;
//
isBearish =
//
// false
//
hasSelectedBox &&
selectedBox.IsBearish() &&
cXConditions.isStrBearish
//
// cBar.IsBearish() &&
// isPBarPriceChangeOverPeak &&
// isPBarPriceChangeOverAtrUpper &&
// isPBarCloseOverPeaksGoldenZone &&
// isPBarBullishPriceChangeVPattern
//
;
/////////////////////////////////////////////////////////
//
double xhkSL;
ENUM_X_DIRECTION xhkDir;
bool isXHKPassed = IsHKConditionsPassed(
xhkSL,
xhkDir,
cHelper,
cXConditions,
barIndex //
);
bool isXHKBullish =
isXHKPassed &&
IsBullish(xhkDir);
bool isXHKBearish =
isXHKPassed &&
IsBearish(xhkDir);
/////////////////////////////////////////////////////////
//
bool IsRejectedBox(
XOHCL &bar, // CBar ...
XBoxZone &box,
X121Conditions &conditions //
)
{
//
bool result = false;
//
result =
bar.IsValid() &&
box.IsValid();
if (!result)
{
return result;
}
//
bool isBullish = box.IsBullish();
//
bool isBullishRejected =
isBullish &&
bar.IsRejected(
box.upper,
box.dir,
true, // Force Type ...
true // Force Pressure ...
);
//
bool isBearishRejected =
!isBullish &&
bar.IsRejected(
box.lower,
box.dir,
true, // Force Type ...
true // Force Pressure ...
);
//
result = isBullishRejected ||
isBearishRejected;
//
return result;
}
//
bool IsPeaksOrValesPassedBox(
XBoxZone &box,
X121Conditions &conditions //
)
{
//
bool result = false;
//
result = box.IsValid();
if (!result)
{
return result;
}
//
double peakZ = conditions.peaksBuffer[0];
double peakC = conditions.peaksBuffer[1];
double peakP = conditions.peaksBuffer[2];
double peakPP = conditions.peaksBuffer[3];
//
double valeZ = conditions.valesBuffer[0];
double valeC = conditions.valesBuffer[1];
double valeP = conditions.valesBuffer[2];
double valePP = conditions.valesBuffer[3];
//
double boxQ = ((box.upper - box.lower) / 100) * 25;
double upperQuarter = box.upper - boxQ;
double lowerQuarter = box.lower + boxQ;
//
bool isPPeakInsideUpperQ =
peakP < box.upper &&
peakP > upperQuarter;
//
bool isPValeInsideLowerQ =
valeP > box.lower &&
valeP < lowerQuarter;
//
bool isPPPeakInsideUpperQ =
peakPP < box.upper &&
peakPP > upperQuarter;
//
bool isPPValeInsideLowerQ =
valePP > box.lower &&
valePP < lowerQuarter;
//
result =
//
(box.IsBullish() &&
(isPValeInsideLowerQ ||
isPPValeInsideLowerQ) &&
(valeC == valeP ||
valeP == valePP))
//
||
//
(box.IsBearish() &&
(isPPeakInsideUpperQ ||
isPPPeakInsideUpperQ) &&
(peakC == peakP ||
peakP == peakPP))
//
;
//
return result;
}
//
bool IsX3MaPassedBox(
XOHCL &bar, // CBar ...
XBoxZone &box,
X121Conditions &conditions //
)
{
//
bool result = false;
//
result =
bar.IsValid() &&
box.IsValid();
if (!result)
{
return result;
}
//
double x3maFast = conditions.x3maFastBuffer[1];
double x3maMid = conditions.x3maMidBuffer[1];
double x3maSlow = conditions.x3maSlowBuffer[1];
//
bool isx3MaInsideBox =
//
// Fast ...
x3maFast < box.upper &&
x3maFast > box.lower
//
&&
//
// Mid ...
x3maMid < box.upper &&
x3maMid > box.lower
//
&&
//
// Slow ...
x3maSlow < box.upper &&
x3maSlow > box.lower
//
;
//
bool isX3maSwitchedToBullishOrdered =
bar.IsBullish() &&
box.IsBullish() &&
isx3MaInsideBox &&
bar.close > conditions.x3maFastBuffer[1] &&
conditions.isX3MaSwitchedToBullishOrdered;
//
bool isX3maSwitchedToBearishOrdered =
bar.IsBearish() &&
box.IsBearish() &&
isx3MaInsideBox &&
bar.close < conditions.x3maFastBuffer[1] &&
conditions.isX3MaSwitchedToBearishOrdered;
//
result = isX3maSwitchedToBullishOrdered ||
isX3maSwitchedToBearishOrdered;
//
return result;
}
//
// TODO: Complete this ...
bool IsActivatedBoxPassed(
XBoxZone &box,
X121Conditions &conditions //
)
{
//
bool result = false;
//
result = box.IsValid();
if (!result)
{
return result;
}
//
return result;
}
//
//
//
//
bool IsHKConditionsPassed(
double &sl,
ENUM_X_DIRECTION &dir,
XC121SMCCycleHelper *helper,
X121Conditions &conditions,
int barIndex = 0 //
)
{
//
bool result = false;
//
sl = 0;
dir = X_DIRECTION_NONE;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
int ppIDX = pIDX + 1;
//
XOHCL zBar;
XOHCL cBar;
XOHCL pBar;
XOHCL ppBar;
//
// Retrieve Bars ...
result = zBar.Init(
conditions.symbol,
conditions.period,
barIndex //
);
result =
result &&
zBar.GetPreviousBar(cBar);
result =
result &&
cBar.GetPreviousBar(pBar);
result =
result &&
pBar.GetPreviousBar(ppBar);
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
ppBar.Clean();
//
return result;
}
//
// Check PBar Swing ...
ENUM_X_DIRECTION pBarSwingDir;
bool isPBarSwing = helper
.mBarAnalyser
.IsSwing(
pBar,
pBarSwingDir,
3 //
);
//
bool isPBarSwingLow =
isPBarSwing &&
IsBullish(pBarSwingDir);
//
bool isPBarSwingHigh =
isPBarSwing &&
IsBearish(pBarSwingDir);
//
// Check PBar Rejection ...
ENUM_X_DIRECTION pBarRejectionDir;
bool isPBarRejected = helper
.mBarAnalyser
.IsRejected(
pBar,
pBarRejectionDir,
false,
true //
);
//
bool isPBarBullishRejected =
isPBarRejected &&
IsBullish(pBarRejectionDir);
//
bool isPBarBearishRejected =
isPBarRejected &&
IsBearish(pBarRejectionDir);
//
// Checking Str Incresing/Decreasing ...
//
bool isStrIncresing =
//
(conditions.strBuffer[zIDX] > conditions.strBuffer[cIDX] &&
conditions.strBuffer[zIDX] > conditions.strBuffer[pIDX] &&
conditions.strBuffer[zIDX] > conditions.strBuffer[ppIDX])
//
&&
//
(
//
(conditions.strBuffer[zIDX] > conditions.strBuffer[cIDX] &&
conditions.strBuffer[cIDX] > conditions.strBuffer[pIDX])
//
||
//
(conditions.strBuffer[cIDX] > conditions.strBuffer[pIDX] &&
conditions.strBuffer[pIDX] > conditions.strBuffer[ppIDX])
//
)
//
;
//
bool isStrDecreasing =
//
(conditions.strBuffer[zIDX] < conditions.strBuffer[cIDX] &&
conditions.strBuffer[zIDX] < conditions.strBuffer[pIDX] &&
conditions.strBuffer[zIDX] < conditions.strBuffer[ppIDX])
//
&&
//
(
//
(conditions.strBuffer[zIDX] < conditions.strBuffer[cIDX] &&
conditions.strBuffer[cIDX] < conditions.strBuffer[pIDX])
//
||
//
(conditions.strBuffer[cIDX] < conditions.strBuffer[pIDX] &&
conditions.strBuffer[pIDX] < conditions.strBuffer[ppIDX])
//
)
//
;
//
bool isBullish =
//
isPBarSwingLow &&
isStrIncresing &&
cBar.IsBullish() &&
cBar.low > pBar.low &&
cBar.open > pBar.low &&
zBar.open > cBar.low &&
// isPBarBullishRejected &&
conditions.isSarBullish &&
conditions.isStrBullish &&
conditions.isSMHKBullish
//
;
//
bool isBearish =
//
isPBarSwingHigh &&
isStrDecreasing &&
cBar.IsBearish() &&
cBar.high < pBar.high &&
cBar.open < pBar.high &&
zBar.open < cBar.high &&
// isPBarBearishRejected &&
conditions.isSarBearish &&
conditions.isStrBearish &&
conditions.isSMHKBearish
//
;
//
result = isBullish ||
isBearish;
if (result)
{
//
dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Selecting SL ...
sl =
isBullish
? cBar.low
: cBar.high;
}
//
// Cleanup Resources ...
zBar.Clean();
cBar.Clean();
pBar.Clean();
ppBar.Clean();
//
return result;
}
//
bool IsSARConditionsPassed(
double &sl,
ENUM_X_DIRECTION &dir,
XC121SMCCycleHelper *helper,
X121Conditions &conditions,
int barIndex = 0 //
)
{
//
bool result = false;
//
sl = 0;
dir = X_DIRECTION_NONE;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int zIDX = 0;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
int ppIDX = pIDX + 1;
//
XOHCL zBar;
XOHCL cBar;
XOHCL pBar;
XOHCL ppBar;
//
// Retrieve Bars ...
result = zBar.Init(
conditions.symbol,
conditions.period,
barIndex //
);
result =
result &&
zBar.GetPreviousBar(cBar);
result =
result &&
cBar.GetPreviousBar(pBar);
result =
result &&
pBar.GetPreviousBar(ppBar);
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
ppBar.Clean();
//
return result;
}
//
// Check PBar Swing ...
ENUM_X_DIRECTION pBarSwingDir;
bool isPBarSwing = helper
.mBarAnalyser
.IsSwing(
pBar,
pBarSwingDir,
3 //
);
//
bool isPBarSwingLow =
isPBarSwing &&
IsBullish(pBarSwingDir);
//
bool isPBarSwingHigh =
isPBarSwing &&
IsBearish(pBarSwingDir);
//
bool isBullish =
//
isPBarSwingLow &&
cBar.IsBullish() &&
cBar.low > pBar.low &&
cBar.open > pBar.low &&
zBar.open > cBar.low &&
conditions.isSarSwitchedToBullish
//
;
//
bool isBearish =
//
isPBarSwingHigh &&
isStrDecreasing &&
cBar.IsBearish() &&
cBar.high < pBar.high &&
cBar.open < pBar.high &&
zBar.open < cBar.high &&
conditions.isSarSwitchedToBearish
//
;
//
result = isBullish ||
isBearish;
if (result)
{
//
dir = isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
// Selecting SL ...
sl =
isBullish
? cBar.low
: cBar.high;
}
//
// Cleanup Resources ...
zBar.Clean();
cBar.Clean();
pBar.Clean();
ppBar.Clean();
//
return result;
}
/////////////////////////////////////////////////////////
// //
// bool isPVPassed = IsPeaksOrValesPassedBox(
// iBox,
// cXConditions //
// );
// if (isPVPassed)
// {
// //
// selectedBox = iBox;
// iBox.Clean();
// break;
// }
//
// bool isx3MaPassed = IsX3MaPassedBox(
// cBar,
// iBox,
// cXConditions //
// );
// if (isx3MaPassed)
// {
// //
// selectedBox = iBox;
// iBox.Clean();
// break;
// }
//
// bool isRejected = IsRejectedBox(
// cBar,
// iBox,
// cXConditions //
// );
// if (isRejected)
// {
// //
// selectedBox = iBox;
// iBox.Clean();
// break;
// }
/////////////////////////////////////////////////////////
//
// Checking Bullish Fair Value Gaps ...
has = cState.HasBullishFairValueGaps();
if (has)
{
//
XBoxZone tmpBoxes[];
ToBox(
cState.bullishFairValueGaps,
tmpBoxes //
);
//
count = ArraySize(tmpBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = tmpBoxes[i];
bool isValid = IsBoxValid(
iBox,
0,
iBox.period //
);
if (!isValid)
{
//
iBox.Clean();
continue;
}
//
has = IsBoxExists(iBox);
if (!has)
{
//
AddRef(
iBox,
mWaitingBoxes //
);
}
//
iBox.Clean();
}
}
//
Clean(tmpBoxes);
}
//
// Checking Bearish Fair Value Gaps ...
has = cState.HasBearishFairValueGaps();
if (has)
{
//
XBoxZone tmpBoxes[];
ToBox(
cState.bearishFairValueGaps,
tmpBoxes //
);
//
count = ArraySize(tmpBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = tmpBoxes[i];
bool isValid = IsBoxValid(
iBox,
0,
iBox.period //
);
if (!isValid)
{
//
iBox.Clean();
continue;
;
}
//
has = IsBoxExists(iBox);
if (!has)
{
//
AddRef(
iBox,
mWaitingBoxes //
);
}
//
iBox.Clean();
}
}
//
Clean(tmpBoxes);
}
/////////////////////////////////////////////////////////
//
bool GeneratePVBox(
XBoxZone &box,
int barIndex = 0 //
)
{
//
bool result = false;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
box.Clean();
box.symbol = GetSymbol();
box.period = GetPeriod();
//
int index = barIndex;
//
// Peak ...
datetime peaksSameFrom = NULL;
double peak = mX121Helper.xpvHelper.GetPeak(index);
double prevPeak = mX121Helper.xpvHelper.GetPeak(index + 1);
bool startsByPeak = peak == prevPeak;
//
// Vale ...
datetime valesSameFrom = NULL;
double vale = mX121Helper.xpvHelper.GetVale(index);
double prevVale = mX121Helper.xpvHelper.GetVale(index + 1);
bool startsByVale =
!startsByPeak &&
vale == prevVale;
//
bool canBreak = false;
while (!canBreak)
{
//
index++;
//
datetime cTime = iTime(
box.symbol,
box.period,
index //
);
//
// Peak ...
double iPeak = mX121Helper.xpvHelper.GetPeak(index);
//
// Vale ...
double iVale = mX121Helper.xpvHelper.GetVale(index);
//
// Start By Peak or Value ...
bool isSame = false;
if (startsByPeak)
{
//
isSame = iPeak == peak;
bool canSetVale = vale == 0
? true
: iVale > vale;
if (canSetVale)
{
vale = iVale;
}
}
else if (startsByVale)
{
//
isSame = iVale == vale;
bool canSetPeak = peak == 0
? true
: iPeak < peak;
if (canSetPeak)
{
peak = iPeak;
}
}
//
if (isSame)
{
//
box.from = cTime;
box.upper = peak;
box.lower = vale;
}
else if (IsValid(box.from))
{
//
// Complete Box ...
box.to = iTime(
box.symbol,
box.period,
barIndex //
);
//
box.type = "XPVBox";
box.dir = startsByPeak
? X_DIRECTION_BEARISH
: startsByVale
? X_DIRECTION_BULLISH
: X_DIRECTION_NONE;
}
//
canBreak = !isSame;
}
//
result = box.IsValid();
if (!result)
{
box.Clean();
}
//
return result;
}
//
void DetectPVPivots(
int barIndex = 0,
int validation = 50,
int loopback = 100 //
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
loopback = NormalizeInt(loopback, 10);
validation = NormalizeInt(validation, 5);
//
int iPeakVerified = 0;
int iValeVerified = 0;
datetime iPeakTo = GetBarTime(
GetSymbol(),
GetPeriod(),
barIndex //
);
datetime iValeTo = GetBarTime(
GetSymbol(),
GetPeriod(),
barIndex //
);
double iPeak = mX121Helper.xpvHelper.GetPeak(barIndex);
double iVale = mX121Helper.xpvHelper.GetVale(barIndex);
double iPeakGolden = mX121Helper.xpvHelper.GetPeakGoldenZone(barIndex);
double iValeGolden = mX121Helper.xpvHelper.GetValeGoldenZone(barIndex);
for (int i = barIndex + 1; i < barIndex + 1 + loopback; i++)
{
//
double iiPeak = mX121Helper.xpvHelper.GetPeak(i);
double iiVale = mX121Helper.xpvHelper.GetVale(i);
double iiPeakGolden = mX121Helper.xpvHelper.GetPeakGoldenZone(i);
double iiValeGolden = mX121Helper.xpvHelper.GetValeGoldenZone(i);
//
if (iiPeak == iPeak)
{
//
iPeakVerified++;
iPeakGolden = iPeakGolden < iiPeakGolden
? iiPeakGolden
: iPeakGolden;
}
else
{
//
if (iPeakVerified > 0 &&
iPeakVerified < validation)
{
//
// Reset ...
iPeak = iiPeak;
iPeakVerified = 0;
iPeakGolden = iiPeakGolden;
iPeakTo = GetBarTime(
GetSymbol(),
GetPeriod(),
i //
);
}
}
//
if (iiVale == iVale)
{
//
iValeVerified++;
iValeGolden = iValeGolden > iiValeGolden
? iiValeGolden
: iValeGolden;
}
else
{
//
if (iValeVerified > 0 &&
iValeVerified < validation)
{
//
// Reset ...
iVale = iiVale;
iValeVerified = 0;
iValeGolden = iiValeGolden;
iValeTo = GetBarTime(
GetSymbol(),
GetPeriod(),
i //
);
}
}
//
if (iPeakVerified >= validation &&
iValeVerified >= validation)
{
break;
}
}
//
// Checking PV Pivots ...
//
if (iPeakVerified >= validation)
{
//
XPVPivot iPivot;
//
iPivot.to = iPeakTo;
iPivot.value = iPeak;
iPivot.type = X_PV_PEAK;
iPivot.golden = iPeakGolden;
iPivot.symbol = GetSymbol();
iPivot.period = GetPeriod();
iPivot.from = ((datetime)iPeakTo - (PeriodSeconds(GetPeriod()) * iPeakVerified));
//
if (iPivot.IsValid())
{
//
AddRef(
iPivot,
mPVPivots //
);
//
XBoxZone iBox;
XCBoxObject *iObj;
bool iHas = iPivot.AsBox(iBox);
if (iHas)
{
//
iHas = mPOIDrawer.DrawBox(
iBox,
iObj //
);
if (iHas)
{
Print("Peak Pivot ...");
}
}
}
//
iPivot.Clean();
}
//
if (iValeVerified >= validation)
{
//
XPVPivot iPivot;
//
iPivot.to = iValeTo;
iPivot.value = iVale;
iPivot.type = X_PV_VALE;
iPivot.symbol = GetSymbol();
iPivot.period = GetPeriod();
iPivot.golden = iValeGolden;
iPivot.from = ((datetime)iValeTo - (PeriodSeconds(GetPeriod()) * iValeVerified));
//
if (iPivot.IsValid())
{
//
AddRef(
iPivot,
mPVPivots //
);
//
XBoxZone iBox;
XCBoxObject *iObj;
bool iHas = iPivot.AsBox(iBox);
if (iHas)
{
//
iHas = mPOIDrawer.DrawBox(
iBox,
iObj //
);
if (iHas)
{
Print("Vale Pivot ...");
}
}
}
//
iPivot.Clean();
}
//
}
//
DetectPVPivots(barIndex);
/////////////////////////////////////////////////////////
//
// Detect Support and Resistances ...
XBoxZone tmpBoxes[];
XBoxZone selectedSupRes[];
count = provider.triggerState.SupportResistancesAsBox(tmpBoxes);
has = IsValidSize(count);
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = tmpBoxes[i];
//
// Validate Box ...
bool isDirPassed = iBox.dir == selectedBox.dir;
bool isPlacePassed = IsBoxInsideOr(iBox, selectedBox, true);
has = isDirPassed &&
isPlacePassed;
if (has)
{
//
AddRef(
iBox,
selectedSupRes //
);
}
//
iBox.Clean();
}
//
Clean(tmpBoxes);
}
has = HasChild(selectedSupRes);
if (has)
{
//
count = ArraySize(selectedSupRes);
for (int i = 0; i < count; i++)
{
//
selectedSupRes[i].to = TimeCurrent();
//
XCBoxObject *iObj;
has = drawer.DrawBox(
selectedSupRes[i],
iObj //
);
}
}
/////////////////////////////////////////////////////////
//
// double strSupport = 0;
// datetime strIn = NULL;
// datetime strOut = NULL;
// bool isStrInBox = false;
// double strResistance = 0;
// bool isStrOutBox = false;
// Checking STR Variables ...
// CheckBoxStr(
// cHelper,
// selectedBox,
// isStrInBox,
// strIn,
// isStrOutBox,
// strOut,
// strSupport,
// strResistance //
// );
/////////////////////////////////////////////////////////
//
bool IsFVGBoxValid(
XBoxZone &box,
ENUM_X_CYCLES cycle,
X121SMCStrategySignalProviderData &provider //
)
{
//
bool result = false;
//
result = box.IsValid();
if (!result)
{
return result;
}
//
// Fil Selected Data ...
XPOIState cState;
X121Conditions cXConditions;
XPOIStateEvents cStateEvents;
XC121SMCCycleHelper *cHelper;
X121SMCCycleConditions cConditions;
result = provider.SelectCycle(
cycle,
cState,
cStateEvents,
cXConditions,
cHelper,
cConditions //
);
if (!result)
{
//
cState.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
cStateEvents.Clean();
//
return result;
}
//
bool isBoxBullish = box.IsBullish();
//
int count = 0;
bool has = false;
//
XBoxZone tmpBoxes[];
count = cState.FairValueGapsAsBox(tmpBoxes);
has = IsValidSize(count);
//
// Check Must Contains Inner Cycle FVG ...
XBoxZone selectedBox;
bool hasSelectedBox = false;
if (has)
{
//
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = tmpBoxes[i];
//
// Regular Validation of Boxes ...
bool isValid = IsBoxValid(
iBox,
0,
iBox.period //
);
bool isTypePassed = iBox.dir == box.dir;
bool isFromPssed = iBox.from >= box.from;
bool isPlacePassed =
IsBoxInsideOr(
iBox,
box //
) &&
(isBoxBullish
? iBox.lower >= box.lower
: iBox.upper <= box.upper);
has =
isValid &&
isFromPssed &&
isTypePassed &&
isPlacePassed;
if (!has)
{
//
iBox.Clean();
continue;
}
//
has =
!hasSelectedBox
? true
: isBoxBullish
? selectedBox.upper > iBox.upper
: selectedBox.lower < iBox.lower;
if (has)
{
//
selectedBox = iBox;
hasSelectedBox = selectedBox.IsValid();
}
//
iBox.Clean();
}
}
//
result = hasSelectedBox;
//
// IGNORE Box Validations ...
// if (result)
// {
// // //
// // // From Index ...
// // int fromIndex = GetBarIndex(
// // selectedBox.symbol,
// // selectedBox.period,
// // selectedBox.from //
// // ) +
// // 1;
// // result = IsValidIndex(fromIndex);
// // //
// // // To Index ...
// // int toIndex = GetBarIndex(
// // selectedBox.symbol,
// // selectedBox.period,
// // selectedBox.to //
// // );
// // if (toIndex < 1)
// // {
// // toIndex = 1;
// // }
// // result = IsValidIndex(toIndex);
// // //
// // // Now we Have Retrieve X121Conditions between from and to Indexes ...
// // // for Check States ...
// // //
// // bool hasNewValeUnderLast = false;
// // bool isStrSwitchedToBullish = false;
// // bool isSarSwitchedToBullish = false;
// // bool hasValueGoldenZoneBreak = false;
// // bool isSMHKSwitchedToBullish = false;
// // bool isVWapSwitchedToBullishState = false;
// // bool isX3MaSwitchedToBullishState = false;
// // bool isVWapSwitchedToBullishOrdered = false;
// // bool isX3MaSwitchedToBullishOrdered = false;
// // //
// // bool hasNewPeakOverLast = false;
// // bool isStrSwitchedToBearish = false;
// // bool isSarSwitchedToBearish = false;
// // bool hasPeakGoldenZoneBreak = false;
// // bool isSMHKSwitchedToBearish = false;
// // bool isVWapSwitchedToBearishState = false;
// // bool isX3MaSwitchedToBearishState = false;
// // bool isVWapSwitchedToBearishOrdered = false;
// // bool isX3MaSwitchedToBearishOrdered = false;
// // //
// // for (int i = fromIndex; i >= toIndex; i--)
// // {
// // //
// // XOHCL iBar;
// // has = iBar.Init(
// // cState.symbol,
// // cState.period,
// // i //
// // );
// // X121Conditions iConditions;
// // has = has &&
// // cHelper.mX121Helper.GetConditions(
// // iConditions,
// // i //
// // );
// // if (!has)
// // {
// // continue;
// // }
// // //
// // // Bullish ...
// // //
// // if (!hasNewValeUnderLast)
// // {
// // hasNewValeUnderLast = iConditions.isNewValeUnderLast;
// // }
// // //
// // if (!isStrSwitchedToBullish)
// // {
// // isStrSwitchedToBullish = iConditions.isStrSwitchedToBullish;
// // }
// // //
// // if (!isSarSwitchedToBullish)
// // {
// // isSarSwitchedToBullish = iConditions.isSarSwitchedToBullish;
// // }
// // //
// // if (!hasValueGoldenZoneBreak)
// // {
// // //
// // hasValueGoldenZoneBreak =
// // iBar.IsBullish() &&
// // iBar.GetUp() > iConditions.valesGoldenBuffer[1] &&
// // iBar.GetDown() < iConditions.valesGoldenBuffer[1];
// // }
// // //
// // if (!isSMHKSwitchedToBullish)
// // {
// // isSMHKSwitchedToBullish = iConditions.isSMHKSwitchedToBullish;
// // }
// // //
// // if (!isVWapSwitchedToBullishState)
// // {
// // isVWapSwitchedToBullishState = iConditions.isVWapSwitchedToBullishState;
// // }
// // //
// // if (!isX3MaSwitchedToBullishState)
// // {
// // isX3MaSwitchedToBullishState = iConditions.isX3MaSwitchedToBullishState;
// // }
// // //
// // if (!isVWapSwitchedToBullishOrdered)
// // {
// // isVWapSwitchedToBullishOrdered = iConditions.isVWapSwitchedToBullishOrdered;
// // }
// // //
// // if (!isX3MaSwitchedToBullishOrdered)
// // {
// // isX3MaSwitchedToBullishOrdered = iConditions.isX3MaSwitchedToBullishOrdered;
// // }
// // //
// // // Bearish ...
// // //
// // if (!hasNewPeakOverLast)
// // {
// // hasNewPeakOverLast = iConditions.isNewPeakOverLast;
// // }
// // //
// // if (!isStrSwitchedToBearish)
// // {
// // isStrSwitchedToBearish = iConditions.isStrSwitchedToBearish;
// // }
// // //
// // if (!isSarSwitchedToBearish)
// // {
// // isSarSwitchedToBearish = iConditions.isSarSwitchedToBearish;
// // }
// // //
// // if (!hasPeakGoldenZoneBreak)
// // {
// // //
// // hasPeakGoldenZoneBreak =
// // iBar.IsBearish() &&
// // iBar.GetUp() > iConditions.peaksGoldenBuffer[1] &&
// // iBar.GetDown() < iConditions.peaksGoldenBuffer[1];
// // }
// // //
// // if (!isSMHKSwitchedToBearish)
// // {
// // isSMHKSwitchedToBearish = iConditions.isSMHKSwitchedToBearish;
// // }
// // //
// // if (!isVWapSwitchedToBearishState)
// // {
// // isVWapSwitchedToBearishState = iConditions.isVWapSwitchedToBearishState;
// // }
// // //
// // if (!isX3MaSwitchedToBearishState)
// // {
// // isX3MaSwitchedToBearishState = iConditions.isX3MaSwitchedToBearishState;
// // }
// // //
// // if (!isVWapSwitchedToBearishOrdered)
// // {
// // isVWapSwitchedToBearishOrdered = iConditions.isVWapSwitchedToBearishOrdered;
// // }
// // //
// // if (!isX3MaSwitchedToBearishOrdered)
// // {
// // isX3MaSwitchedToBearishOrdered = iConditions.isX3MaSwitchedToBearishOrdered;
// // }
// // //
// // iConditions.Clean();
// // }
// // //
// // // Bullish Conditions Summary ...
// // //
// // bool hasBullishOrConditions =
// // hasNewValeUnderLast ||
// // isStrSwitchedToBullish ||
// // isSarSwitchedToBullish ||
// // hasValueGoldenZoneBreak ||
// // isSMHKSwitchedToBullish ||
// // isVWapSwitchedToBullishState ||
// // isX3MaSwitchedToBullishState ||
// // isVWapSwitchedToBullishOrdered ||
// // isX3MaSwitchedToBullishOrdered;
// // //
// // bool hasBullishAndConditions =
// // hasNewValeUnderLast &&
// // hasValueGoldenZoneBreak &&
// // (isStrSwitchedToBullish ||
// // isSarSwitchedToBullish ||
// // isSMHKSwitchedToBullish ||
// // isVWapSwitchedToBullishState ||
// // isX3MaSwitchedToBullishState ||
// // isVWapSwitchedToBullishOrdered ||
// // isX3MaSwitchedToBullishOrdered);
// // //
// // // Bearish Conditions Summary ...
// // //
// // bool hasBearishOrConditions =
// // hasNewPeakOverLast ||
// // isStrSwitchedToBearish ||
// // isSarSwitchedToBearish ||
// // hasPeakGoldenZoneBreak ||
// // isSMHKSwitchedToBearish ||
// // isVWapSwitchedToBearishState ||
// // isX3MaSwitchedToBearishState ||
// // isVWapSwitchedToBearishOrdered ||
// // isX3MaSwitchedToBearishOrdered;
// // //
// // bool hasBearishAndConditions =
// // hasNewPeakOverLast &&
// // hasPeakGoldenZoneBreak &&
// // (isStrSwitchedToBearish ||
// // isSarSwitchedToBearish ||
// // isSMHKSwitchedToBearish ||
// // isVWapSwitchedToBearishState ||
// // isX3MaSwitchedToBearishState ||
// // isVWapSwitchedToBearishOrdered ||
// // isX3MaSwitchedToBearishOrdered);
// //
// bool isBullish =
// isBoxBullish
// // &&
// // !hasBearishOrConditions &&
// // hasBullishOrConditions
// ;
// //
// bool isBearish =
// !isBoxBullish
// // &&
// // !hasBullishOrConditions &&
// // hasBearishOrConditions
// ;
// //
// result = isBullish ||
// isBearish;
// //
// // if (result)
// // {
// // //
// // XCBoxObject *iBoxObj;
// // XCBoxObject *iInBoxObj;
// // //
// // has = provider
// // .verificationCycleHelper
// // .mPOIDrawer
// // .DrawBox(
// // box,
// // iBoxObj //
// // );
// // if (has)
// // {
// // //
// // iBoxObj.BoxWidth(2);
// // iBoxObj.BoxStyle(STYLE_SOLID);
// // }
// // //
// // has = provider
// // .verificationCycleHelper
// // .mPOIDrawer
// // .DrawBox(
// // selectedBox,
// // iInBoxObj //
// // );
// // if (has)
// // {
// // //
// // iInBoxObj.BoxWidth(2);
// // iInBoxObj.BoxStyle(STYLE_DASH);
// // }
// // //
// // Print("Inside Selected Box ...");
// // }
// }
//
// Cleanup Resources ...
//
cState.Clean();
Clean(tmpBoxes);
selectedBox.Clean();
ZeroMemory(cHelper);
cConditions.Clean();
cXConditions.Clean();
cStateEvents.Clean();
//
return result;
}
/////////////////////////////////////////////////////////
//
bool DetectXCAEAConditions(
XCAEAConditions &conditions,
XBoxZone &box,
ENUM_X_DIRECTION &dir,
XCXCAEAHelper *helper,
int barIndex = 0,
int loopback = 10 //
)
{
//
bool result = false;
//
box.Clean();
conditions.Clean();
dir = X_DIRECTION_NONE;
//
if (barIndex < 0)
{
barIndex = 0;
}
loopback = NormalizeInt(loopback, 5);
//
string symbol = helper.GetSymbol();
ENUM_TIMEFRAMES period = helper.GetPeriod();
//
result = helper.GetConditions(
conditions,
barIndex,
loopback //
);
if (!result)
{
//
conditions.Clean();
return result;
}
//
int zIDX = barIndex;
int cIDX = zIDX + 1;
int pIDX = cIDX + 1;
int ppIDX = pIDX + 1;
int p3IDX = ppIDX + 1;
int p4IDX = p3IDX + 1;
//
XOHCL zBar;
XOHCL cBar;
XOHCL pBar;
XOHCL ppBar;
XOHCL p3Bar;
XOHCL p4Bar;
result = zBar.Init(
symbol,
period,
zIDX //
);
result =
result &&
zBar.GetPreviousBar(cBar);
result =
result &&
cBar.GetPreviousBar(pBar);
result =
result &&
pBar.GetPreviousBar(ppBar);
result =
result &&
ppBar.GetPreviousBar(p3Bar);
result =
result &&
p3Bar.GetPreviousBar(p4Bar);
if (!result)
{
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
ppBar.Clean();
p3Bar.Clean();
p4Bar.Clean();
//
box.Clean();
conditions.Clean();
//
return result;
}
//
// Bars Conditions ...
//
ENUM_X_DIRECTION cBarDir;
//
// Hammer ...
bool isCBarHammer = helper
.barAnalyser
.IsHammer(
cBar,
cBarDir //
);
bool isCBarBullishHammer =
isCBarHammer &&
IsBullish(cBarDir);
bool isCBarBearishHammer =
isCBarHammer &&
IsBearish(cBarDir);
//
// Rejected ...
bool isCBarRejected = helper
.barAnalyser
.IsRejected(
cBar,
cBarDir,
false, // Force Type ...
true // Force Fibo Pressure ...
);
bool isCBarBullishRejected =
isCBarRejected &&
IsBullish(cBarDir);
bool isCBarBearishRejected =
isCBarRejected &&
IsBearish(cBarDir);
//
// Engulfed ...
bool isCBarEngulfed = helper
.barAnalyser
.IsEngulfed(
cBar,
cBarDir //
);
bool isCBarBullishEngulfed =
isCBarEngulfed &&
IsBullish(cBarDir);
bool isCBarBearishEngulfed =
isCBarEngulfed &&
IsBearish(cBarDir);
//
// Momentum ...
bool isCBarMomentum = helper
.barAnalyser
.IsMomentum(
cBar,
cBarDir,
1 //
);
bool isCBarBullishMomentum =
isCBarMomentum &&
IsBullish(cBarDir);
bool isCBarBearishMomentum =
isCBarMomentum &&
IsBearish(cBarDir);
//
// Bar Sumarise ...
//
bool isCBarValidForBullish =
(isCBarBullishHammer ||
isCBarBullishRejected ||
isCBarBullishMomentum ||
isCBarBullishEngulfed);
//
bool isCBarValidForBearish =
(isCBarBearishHammer ||
isCBarBearishRejected ||
isCBarBearishMomentum ||
isCBarBearishEngulfed);
//
// Conditions ...
//
bool isLowsUnderValesGolden =
//
pBar.low < conditions.valesGoldenBuffer[pIDX] &&
ppBar.low < conditions.valesGoldenBuffer[ppIDX] &&
p3Bar.low < conditions.valesGoldenBuffer[p3IDX] &&
p4Bar.low < conditions.valesGoldenBuffer[p4IDX]
//
;
//
bool isHighsOverPeaksGolden =
//
pBar.high > conditions.peaksGoldenBuffer[pIDX] &&
ppBar.high > conditions.peaksGoldenBuffer[ppIDX] &&
p3Bar.high > conditions.peaksGoldenBuffer[p3IDX] &&
p4Bar.high > conditions.peaksGoldenBuffer[p4IDX]
//
;
//
bool isSwingLowSameAsVale =
conditions.swingLowsBuffer[p4IDX] == conditions.valesBuffer[p4IDX];
//
bool isSwingHighSameAsPeak =
conditions.swingHighsBuffer[p4IDX] == conditions.peaksBuffer[p4IDX];
//
bool isStrSame = conditions.strBuffer[cIDX] == conditions.strBuffer[pIDX] &&
conditions.strBuffer[pIDX] == conditions.strBuffer[ppIDX];
//
bool isSameStrBreakedUp =
isStrSame &&
conditions.strBuffer[zIDX] > conditions.strBuffer[cIDX];
//
bool isSameStrBreakedDown =
isStrSame &&
conditions.strBuffer[zIDX] < conditions.strBuffer[cIDX];
//
bool isStrBullishVPattern =
//
conditions.strStateBuffer[zIDX] > 0 &&
conditions.strStateBuffer[cIDX] > 0 &&
conditions.strStateBuffer[pIDX] > 0 &&
conditions.strBuffer[pIDX] < conditions.strBuffer[ppIDX] &&
conditions.strBuffer[pIDX] < conditions.strBuffer[cIDX] &&
conditions.strBuffer[pIDX] < conditions.strBuffer[zIDX] &&
conditions.strBuffer[zIDX] > conditions.strBuffer[cIDX]
//
;
//
bool isStrBearishVPattern =
//
conditions.strStateBuffer[zIDX] < 0 &&
conditions.strStateBuffer[cIDX] < 0 &&
conditions.strStateBuffer[pIDX] < 0 &&
conditions.strBuffer[pIDX] > conditions.strBuffer[ppIDX] &&
conditions.strBuffer[pIDX] > conditions.strBuffer[cIDX] &&
conditions.strBuffer[pIDX] > conditions.strBuffer[zIDX] &&
conditions.strBuffer[zIDX] < conditions.strBuffer[cIDX]
//
;
//
bool isCBarLowInTKZone =
//
cBar.low < conditions.tenkanSenBuffer[cIDX] &&
cBar.low > conditions.kijunSenBuffer[cIDX]
//
;
//
bool isCBarHighInTKZone =
//
cBar.high > conditions.tenkanSenBuffer[cIDX] &&
cBar.high < conditions.kijunSenBuffer[cIDX]
//
;
//
// Summarise Conditions ...
//
bool isBullish =
//
isCBarLowInTKZone &&
isCBarBullishRejected &&
isCBarValidForBullish &&
conditions.isX3MaSlowBullish &&
conditions.isTenkanSenOverKijunSen &&
conditions.kijunSenBuffer[cIDX] > conditions.x3maSlowBuffer[cIDX]
//
;
//
bool isBearish =
//
isCBarHighInTKZone &&
isCBarBearishRejected &&
isCBarValidForBearish &&
conditions.isX3MaSlowBearish &&
conditions.isTenkanSenUnderKijunSen &&
conditions.kijunSenBuffer[cIDX] < conditions.x3maSlowBuffer[cIDX]
//
;
//
result = isBullish ||
isBearish;
if (result)
{
//
dir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
double entry = GetEntry(
conditions.symbol,
dir //
);
double sl = conditions.kijunSenBuffer[cIDX];
//
box.dir = dir;
box.symbol = conditions.symbol;
box.period = conditions.period;
//
box.upper =
isBullish
? entry
: sl;
//
box.lower =
isBullish
? sl
: entry;
//
box.to = zBar.time;
box.from = p4Bar.time;
//
box.type = ToString(dir) + "_Signal_" + conditions.symbol + "_" + ToString(conditions.period);
}
//
result = box.IsValid() &&
HasDirection(dir);
//
// Cleanup Resources ...
//
if (!result)
{
//
box.Clean();
conditions.Clean();
}
//
zBar.Clean();
cBar.Clean();
pBar.Clean();
ppBar.Clean();
p3Bar.Clean();
p4Bar.Clean();
//
return result;
}
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////