2622 lines
55 KiB
Plaintext
2622 lines
55 KiB
Plaintext
//
|
|
// Provided Signals Enumeration ...
|
|
enum ENUM_X121SMC_XWZ_PROVIDERS
|
|
{
|
|
X121SMC_XWZ_PROVIDER_NONE,
|
|
X121SMC_XWZ_PROVIDER_XHKMA,
|
|
X121SMC_XWZ_PROVIDER_XSHCNZ,
|
|
X121SMC_XWZ_PROVIDER_XBREAKED_BOX,
|
|
X121SMC_XWZ_PROVIDER_XREJECTED_BOX,
|
|
X121SMC_XWZ_PROVIDER_XACTIVATED_BOX,
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Rejected Box ...
|
|
bool HasRejectedBoxConditions(
|
|
ENUM_X_CYCLES cycle,
|
|
XBoxZone &box,
|
|
XBoxZone &holderBox,
|
|
ENUM_X_DIRECTION &dir,
|
|
XSignalBox &waitingBoxes[],
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Configure ...
|
|
bool forceRetestBox = false;
|
|
bool forceHolderBox = false;
|
|
bool forceConsolidationZone = false;
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
Parse(cXConditions);
|
|
|
|
//
|
|
// Checking Waiting Baoxes Exists ...
|
|
result = HasChild(waitingBoxes);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Normalize Args ...
|
|
|
|
//
|
|
box.Clean();
|
|
holderBox.Clean();
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
int zIDX = barIndex;
|
|
int cIDX = zIDX + 1;
|
|
int pIDX = cIDX + 1;
|
|
int ppIDX = pIDX + 1;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
|
|
//
|
|
// Initial Bars ...
|
|
result = zBar.Init(
|
|
cState.symbol,
|
|
cState.period,
|
|
barIndex //
|
|
);
|
|
result =
|
|
result &&
|
|
zBar.GetPreviousBar(cBar);
|
|
result =
|
|
result &&
|
|
cBar.GetPreviousBar(pBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
cState.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION iBarPosDir;
|
|
bool isBarValidForDir = cHelper
|
|
.mBarAnalyser
|
|
.IsValidForPosition(
|
|
cBar,
|
|
iBarPosDir //
|
|
);
|
|
bool isBarValidForBullish =
|
|
isBarValidForDir &&
|
|
IsBullish(iBarPosDir);
|
|
bool isBarValidForBearish =
|
|
isBarValidForDir &&
|
|
IsBearish(iBarPosDir);
|
|
|
|
//
|
|
XBoxZone selectedBox;
|
|
XSignalBox iSignalBox;
|
|
count = ArraySize(waitingBoxes);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XSignalBox iBox = waitingBoxes[i];
|
|
|
|
//
|
|
bool isBullish = iBox.ob.IsBullish();
|
|
bool hasFVG = iBox.fvg.IsValid();
|
|
|
|
//
|
|
bool isFVGBullishRejected =
|
|
//
|
|
hasFVG &&
|
|
cBar.low < iBox.fvg.upper &&
|
|
cBar.GetDown() > iBox.fvg.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isFVGBearishRejected =
|
|
//
|
|
hasFVG &&
|
|
cBar.high > iBox.fvg.lower &&
|
|
cBar.GetUp() < iBox.fvg.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isOBBullishRejected =
|
|
//
|
|
cBar.low < iBox.ob.upper &&
|
|
cBar.GetDown() > iBox.ob.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isOBBearishRejected =
|
|
//
|
|
cBar.high > iBox.ob.lower &&
|
|
cBar.GetUp() < iBox.ob.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? (hasFVG
|
|
? isFVGBullishRejected
|
|
: isOBBullishRejected)
|
|
: (hasFVG
|
|
? isFVGBearishRejected
|
|
: isOBBearishRejected);
|
|
|
|
//
|
|
// Force Using OB ...
|
|
if (!has && hasFVG)
|
|
{
|
|
//
|
|
has = isBullish
|
|
? isOBBullishRejected
|
|
: isOBBearishRejected;
|
|
|
|
//
|
|
selectedBox = iBox.ob;
|
|
}
|
|
if (has)
|
|
{
|
|
//
|
|
iSignalBox = iBox;
|
|
if (!selectedBox.IsValid())
|
|
{
|
|
//
|
|
if (hasFVG)
|
|
{
|
|
selectedBox = iBox.fvg;
|
|
}
|
|
else
|
|
{
|
|
selectedBox = iBox.ob;
|
|
}
|
|
}
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
has =
|
|
iSignalBox.IsValid() &&
|
|
selectedBox.IsValid();
|
|
|
|
//
|
|
// Retest Signal ...
|
|
int retests = 0;
|
|
if (has)
|
|
{
|
|
//
|
|
int iFromIDX = GetBarIndex(
|
|
cBar.symbol,
|
|
cBar.period,
|
|
selectedBox.from //
|
|
);
|
|
has = IsValidIndex(iFromIDX);
|
|
if (has)
|
|
{
|
|
//
|
|
// Counting Retests ...
|
|
for (int i = iFromIDX; i >= barIndex; i--)
|
|
{
|
|
//
|
|
XOHCL iBar;
|
|
has = iBar.Init(
|
|
cBar.symbol,
|
|
cBar.period,
|
|
i //
|
|
);
|
|
|
|
//
|
|
bool isBullishRetested =
|
|
//
|
|
iBar.low < selectedBox.upper &&
|
|
iBar.GetDown() > selectedBox.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearishRetested =
|
|
//
|
|
iBar.high > selectedBox.lower &&
|
|
iBar.GetUp() < selectedBox.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
has = selectedBox.IsBullish()
|
|
? isBullishRetested
|
|
: isBearishRetested;
|
|
if (has)
|
|
{
|
|
retests++;
|
|
}
|
|
|
|
//
|
|
iBar.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
bool isSignalBoxRetested =
|
|
!forceRetestBox
|
|
? retests >= 1
|
|
: retests >= 2;
|
|
bool hasSignalBox = iSignalBox.IsValid();
|
|
bool isSignalBoxBullish = IsBullish(iSignalBox.ob.dir);
|
|
|
|
//
|
|
// Check Consolidation Zone ...
|
|
bool hasBullishCZone = true;
|
|
bool hasBearishCZone = true;
|
|
if (forceConsolidationZone)
|
|
{
|
|
//
|
|
XBoxZone cZone;
|
|
XBoxZone tmpBoxes[];
|
|
if (isSignalBoxBullish)
|
|
{
|
|
//
|
|
ToBox(
|
|
cState.bullishConsolidationZones,
|
|
tmpBoxes //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
ToBox(
|
|
cState.bearishConsolidationZones,
|
|
tmpBoxes //
|
|
);
|
|
}
|
|
has = HasChild(tmpBoxes);
|
|
if (has)
|
|
{
|
|
//
|
|
XBoxZone selectedBox;
|
|
if (iSignalBox.fvg.IsValid())
|
|
{
|
|
selectedBox = iSignalBox.fvg;
|
|
}
|
|
else
|
|
{
|
|
selectedBox = iSignalBox.ob;
|
|
}
|
|
|
|
//
|
|
idx = GetYoungest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
cZone = tmpBoxes[idx];
|
|
|
|
//
|
|
// Check Consolidation Zone Place ...
|
|
has =
|
|
//
|
|
(
|
|
//
|
|
IsBoxInsideOr(
|
|
cZone,
|
|
selectedBox //
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
cZone.from >= selectedBox.from
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
IsBoxInsideOr(
|
|
selectedBox,
|
|
cZone //
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
selectedBox.from >= cZone.from
|
|
//
|
|
)
|
|
//
|
|
;
|
|
if (!has)
|
|
{
|
|
cZone.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
selectedBox.Clean();
|
|
}
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
hasBullishCZone = cZone.IsValid() &&
|
|
cZone.IsBullish();
|
|
|
|
//
|
|
hasBearishCZone = cZone.IsValid() &&
|
|
cZone.IsBearish();
|
|
|
|
//
|
|
cZone.Clean();
|
|
}
|
|
|
|
//
|
|
// Bullish Conditions ...
|
|
isBullish =
|
|
//
|
|
// Base Condition ...
|
|
(
|
|
//
|
|
hasSignalBox &&
|
|
hasBullishCZone &&
|
|
isSignalBoxBullish &&
|
|
isSignalBoxRetested &&
|
|
isBarValidForBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Conditions ...
|
|
isBearish =
|
|
//
|
|
// Base Condition ...
|
|
(
|
|
//
|
|
hasSignalBox &&
|
|
hasBearishCZone &&
|
|
!isSignalBoxBullish &&
|
|
isSignalBoxRetested &&
|
|
isBarValidForBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Filling Requirements ...
|
|
result =
|
|
isBullish ||
|
|
isBearish;
|
|
if (result)
|
|
{
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
box = selectedBox;
|
|
box.to = TimeCurrent();
|
|
|
|
//
|
|
// Detect Holder Box ...
|
|
if (forceHolderBox)
|
|
{
|
|
//
|
|
XBoxZone tmpBoxes[];
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Order Blocks ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
cState.bullishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bullishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Support Zones ...
|
|
ToBox(
|
|
cState.supportZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Order Blocks ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
cState.bearishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bearishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
ToBox(
|
|
cState.resistanceZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
|
|
//
|
|
count = ArraySize(tmpBoxes);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
idx = GetOldest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
has = IsBoxInside(
|
|
iBox,
|
|
box //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
holderBox = iBox;
|
|
holderBox.to = TimeCurrent();
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
result =
|
|
result &&
|
|
holderBox.IsValid() &&
|
|
holderBox.dir == dir;
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
isBullish = false;
|
|
isBearish = false;
|
|
holderBox.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check All Conditions ...
|
|
result =
|
|
box.IsValid() &&
|
|
HasDirection(dir) &&
|
|
(isBullish ||
|
|
isBearish);
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
cState.Clean();
|
|
iSignalBox.Clean();
|
|
selectedBox.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cStateEvents.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Activated Box
|
|
bool HasActivatedBoxConditions(
|
|
ENUM_X_CYCLES cycle,
|
|
XBoxZone &box,
|
|
XBoxZone &holderBox,
|
|
ENUM_X_DIRECTION &dir,
|
|
XSignalBox &waitingBoxes[],
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
Parse(cXConditions);
|
|
|
|
//
|
|
// Checking Waiting Baoxes Exists ...
|
|
result = HasChild(waitingBoxes);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Normalize Args ...
|
|
|
|
//
|
|
box.Clean();
|
|
holderBox.Clean();
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
int zIDX = barIndex;
|
|
int cIDX = zIDX + 1;
|
|
int pIDX = cIDX + 1;
|
|
int ppIDX = pIDX + 1;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
XOHCL pPBar;
|
|
|
|
//
|
|
// Initial Bars ...
|
|
result = zBar.Init(
|
|
cState.symbol,
|
|
cState.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();
|
|
cState.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION iBarPosDir;
|
|
bool isBarValidForDir = cHelper
|
|
.mBarAnalyser
|
|
.IsValidForPosition(
|
|
cBar,
|
|
iBarPosDir //
|
|
);
|
|
bool isBarValidForBullish =
|
|
isBarValidForDir &&
|
|
IsBullish(iBarPosDir);
|
|
bool isBarValidForBearish =
|
|
isBarValidForDir &&
|
|
IsBearish(iBarPosDir);
|
|
|
|
//
|
|
XSignalBox iSignalBox;
|
|
count = ArraySize(waitingBoxes);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XSignalBox iBox = waitingBoxes[i];
|
|
|
|
//
|
|
bool isBullish = iBox.ob.IsBullish();
|
|
bool hasFVG = iBox.fvg.IsValid();
|
|
|
|
//
|
|
// Checking Inside ...
|
|
|
|
//
|
|
bool isBullishInsideFVG =
|
|
//
|
|
hasFVG &&
|
|
pBar.high < iBox.fvg.upper &&
|
|
pPBar.high < iBox.fvg.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearishInsideFVG =
|
|
//
|
|
hasFVG &&
|
|
pBar.low > iBox.fvg.lower &&
|
|
pPBar.low > iBox.fvg.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBullishInsideOB =
|
|
//
|
|
pBar.high < iBox.ob.upper &&
|
|
pPBar.high < iBox.ob.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearishInsideOB =
|
|
//
|
|
pBar.low > iBox.ob.lower &&
|
|
pPBar.low > iBox.ob.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
// Checking Breakes Box ...
|
|
|
|
//
|
|
bool isFVGBullishBreaked =
|
|
//
|
|
hasFVG &&
|
|
isBullishInsideFVG &&
|
|
//
|
|
cBar.high > iBox.fvg.upper &&
|
|
cBar.close > iBox.fvg.upper &&
|
|
//
|
|
zBar.open > iBox.fvg.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isFVGBearishBreaked =
|
|
//
|
|
hasFVG &&
|
|
isBearishInsideFVG &&
|
|
//
|
|
cBar.low < iBox.fvg.lower &&
|
|
cBar.close < iBox.fvg.lower &&
|
|
//
|
|
zBar.open > iBox.fvg.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isOBBullishBreaked =
|
|
//
|
|
isBullishInsideOB &&
|
|
//
|
|
cBar.high > iBox.ob.upper &&
|
|
cBar.close > iBox.ob.upper &&
|
|
//
|
|
zBar.open > iBox.ob.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isOBBearishBreaked =
|
|
//
|
|
isBearishInsideOB &&
|
|
//
|
|
cBar.low < iBox.ob.lower &&
|
|
cBar.close < iBox.ob.lower &&
|
|
//
|
|
zBar.open > iBox.ob.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
// Summarise ...
|
|
|
|
//
|
|
bool isBullishBreaked =
|
|
isBarValidForBullish &&
|
|
(hasFVG
|
|
? isFVGBullishBreaked
|
|
: isOBBullishBreaked);
|
|
|
|
//
|
|
bool isBearishBreaked =
|
|
isBarValidForBearish &&
|
|
(hasFVG
|
|
? isFVGBearishBreaked
|
|
: isOBBearishBreaked);
|
|
|
|
//
|
|
has = isBullishBreaked ||
|
|
isBearishBreaked;
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
iSignalBox = iBox;
|
|
iBox.Clean();
|
|
|
|
//
|
|
dir =
|
|
isBullishBreaked
|
|
? X_DIRECTION_BULLISH
|
|
: isBearishBreaked
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_NONE;
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasSignalBox = HasDirection(dir) &&
|
|
iSignalBox.IsValid();
|
|
bool isSignalBoxBullish = IsBullish(dir);
|
|
|
|
//
|
|
// Bullish Conditions ...
|
|
isBullish =
|
|
//
|
|
// Base Condition ...
|
|
(
|
|
//
|
|
hasSignalBox &&
|
|
isSignalBoxBullish &&
|
|
isBarValidForBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Conditions ...
|
|
isBearish =
|
|
//
|
|
// Base Condition ...
|
|
(
|
|
//
|
|
hasSignalBox &&
|
|
!isSignalBoxBullish &&
|
|
isBarValidForBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Filling Requirements ...
|
|
result =
|
|
isBullish ||
|
|
isBearish;
|
|
if (result)
|
|
{
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
if (iSignalBox.fvg.IsValid())
|
|
{
|
|
box = iSignalBox.fvg;
|
|
}
|
|
else
|
|
{
|
|
box = iSignalBox.ob;
|
|
}
|
|
|
|
//
|
|
box.to = TimeCurrent();
|
|
|
|
//
|
|
// Detect Holder Box ...
|
|
XBoxZone tmpBoxes[];
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Order Blocks ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
cState.bullishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bullishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Support Zones ...
|
|
ToBox(
|
|
cState.supportZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Order Blocks ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
cState.bearishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bearishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
ToBox(
|
|
cState.resistanceZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
|
|
//
|
|
count = ArraySize(tmpBoxes);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
idx = GetOldest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
has = IsBoxInside(
|
|
iBox,
|
|
box //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
holderBox = iBox;
|
|
holderBox.to = TimeCurrent();
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
result =
|
|
result &&
|
|
holderBox.IsValid() &&
|
|
holderBox.dir == dir;
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
isBullish = false;
|
|
isBearish = false;
|
|
holderBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check All Conditions ...
|
|
result =
|
|
box.IsValid() &&
|
|
HasDirection(dir) &&
|
|
(isBullish ||
|
|
isBearish);
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
pPBar.Clean();
|
|
cState.Clean();
|
|
iSignalBox.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cStateEvents.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Breaked Box
|
|
bool HasBreakedBoxConditions(
|
|
ENUM_X_CYCLES cycle,
|
|
XBoxZone &box,
|
|
XBoxZone &holderBox,
|
|
ENUM_X_DIRECTION &dir,
|
|
XSignalBox &waitingBoxes[],
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
Parse(cXConditions);
|
|
|
|
//
|
|
// Checking Waiting Baoxes Exists ...
|
|
result = HasChild(waitingBoxes);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Normalize Args ...
|
|
|
|
//
|
|
box.Clean();
|
|
holderBox.Clean();
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
int zIDX = barIndex;
|
|
int cIDX = zIDX + 1;
|
|
int pIDX = cIDX + 1;
|
|
int ppIDX = pIDX + 1;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
XOHCL pPBar;
|
|
|
|
//
|
|
// Initial Bars ...
|
|
result = zBar.Init(
|
|
cState.symbol,
|
|
cState.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();
|
|
cState.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION iBarPosDir;
|
|
bool isBarValidForDir = cHelper
|
|
.mBarAnalyser
|
|
.IsValidForPosition(
|
|
cBar,
|
|
iBarPosDir //
|
|
);
|
|
bool isBarValidForBullish =
|
|
isBarValidForDir &&
|
|
IsBullish(iBarPosDir);
|
|
bool isBarValidForBearish =
|
|
isBarValidForDir &&
|
|
IsBearish(iBarPosDir);
|
|
|
|
//
|
|
XSignalBox iSignalBox;
|
|
count = ArraySize(waitingBoxes);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XSignalBox iBox = waitingBoxes[i];
|
|
|
|
//
|
|
bool isBullish = iBox.ob.IsBullish();
|
|
bool hasFVG = iBox.fvg.IsValid();
|
|
|
|
//
|
|
// Checking Breakes Box ...
|
|
|
|
//
|
|
bool isFVGBullishBreaked =
|
|
//
|
|
hasFVG &&
|
|
//
|
|
pBar.low < iBox.fvg.upper &&
|
|
//
|
|
cBar.high > iBox.fvg.upper &&
|
|
cBar.close > iBox.fvg.upper &&
|
|
//
|
|
zBar.open > iBox.fvg.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isFVGBearishBreaked =
|
|
//
|
|
hasFVG &&
|
|
//
|
|
pBar.high > iBox.fvg.lower &&
|
|
//
|
|
cBar.low < iBox.fvg.lower &&
|
|
cBar.close < iBox.fvg.lower &&
|
|
//
|
|
zBar.open > iBox.fvg.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isOBBullishBreaked =
|
|
//
|
|
pBar.low < iBox.ob.upper &&
|
|
//
|
|
cBar.high > iBox.ob.upper &&
|
|
cBar.close > iBox.ob.upper &&
|
|
//
|
|
zBar.open > iBox.ob.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isOBBearishBreaked =
|
|
//
|
|
pBar.high > iBox.ob.lower &&
|
|
//
|
|
cBar.low < iBox.ob.lower &&
|
|
cBar.close < iBox.ob.lower &&
|
|
//
|
|
zBar.open > iBox.ob.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
// Summarise ...
|
|
|
|
//
|
|
bool isBullishBreaked =
|
|
isBarValidForBullish &&
|
|
(hasFVG
|
|
? isFVGBullishBreaked
|
|
: isOBBullishBreaked);
|
|
|
|
//
|
|
bool isBearishBreaked =
|
|
isBarValidForBearish &&
|
|
(hasFVG
|
|
? isFVGBearishBreaked
|
|
: isOBBearishBreaked);
|
|
|
|
//
|
|
has = isBullishBreaked ||
|
|
isBearishBreaked;
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
iSignalBox = iBox;
|
|
iBox.Clean();
|
|
|
|
//
|
|
dir =
|
|
isBullishBreaked
|
|
? X_DIRECTION_BULLISH
|
|
: isBearishBreaked
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_NONE;
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
bool hasSignalBox = HasDirection(dir) &&
|
|
iSignalBox.IsValid();
|
|
bool isSignalBoxBullish = IsBullish(dir);
|
|
|
|
//
|
|
// Bullish Conditions ...
|
|
isBullish =
|
|
//
|
|
// Base Condition ...
|
|
(
|
|
//
|
|
hasSignalBox &&
|
|
isSignalBoxBullish &&
|
|
isBarValidForBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Conditions ...
|
|
isBearish =
|
|
//
|
|
// Base Condition ...
|
|
(
|
|
//
|
|
hasSignalBox &&
|
|
!isSignalBoxBullish &&
|
|
isBarValidForBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Filling Requirements ...
|
|
result =
|
|
isBullish ||
|
|
isBearish;
|
|
if (result)
|
|
{
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
if (iSignalBox.fvg.IsValid())
|
|
{
|
|
box = iSignalBox.fvg;
|
|
}
|
|
else
|
|
{
|
|
box = iSignalBox.ob;
|
|
}
|
|
|
|
//
|
|
box.to = TimeCurrent();
|
|
|
|
//
|
|
// Detect Holder Box ...
|
|
XBoxZone tmpBoxes[];
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Order Blocks ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
cState.bullishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bullishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Support Zones ...
|
|
ToBox(
|
|
cState.supportZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Order Blocks ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
cState.bearishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bearishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
ToBox(
|
|
cState.resistanceZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
|
|
//
|
|
count = ArraySize(tmpBoxes);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
idx = GetOldest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
has = IsBoxInside(
|
|
iBox,
|
|
box //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
holderBox = iBox;
|
|
holderBox.to = TimeCurrent();
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
result =
|
|
result &&
|
|
holderBox.IsValid() &&
|
|
holderBox.dir == dir;
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
isBullish = false;
|
|
isBearish = false;
|
|
holderBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Check All Conditions ...
|
|
result =
|
|
box.IsValid() &&
|
|
HasDirection(dir) &&
|
|
(isBullish ||
|
|
isBearish);
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
pPBar.Clean();
|
|
cState.Clean();
|
|
iSignalBox.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cStateEvents.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// XHKMA ...
|
|
bool HasXHKMAConditions(
|
|
ENUM_X_CYCLES cycle,
|
|
ENUM_X_DIRECTION trend,
|
|
XBoxZone &box,
|
|
XBoxZone &holderBox,
|
|
ENUM_X_DIRECTION &dir,
|
|
XSignalBox &waitingBoxes[],
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
// Normalize Args ...
|
|
|
|
//
|
|
box.Clean();
|
|
holderBox.Clean();
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
// Check Trend Exists ...
|
|
result = HasDirection(trend);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Extrand Trend Direction ...
|
|
bool hasBullishTrend = IsBullish(trend);
|
|
bool hasBearishTrend = IsBearish(trend);
|
|
|
|
//
|
|
// Checking Waiting Baoxes Exists ...
|
|
result = HasChild(waitingBoxes);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Current Waiting Box is Directional To Trend ...
|
|
XSignalBox iSignalBox;
|
|
idx = GetYoungest(waitingBoxes);
|
|
result = IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
//
|
|
iSignalBox.Clean();
|
|
return result;
|
|
}
|
|
iSignalBox = waitingBoxes[idx];
|
|
result = iSignalBox.IsValid() &&
|
|
iSignalBox.ob.dir == trend;
|
|
if (!result)
|
|
{
|
|
//
|
|
iSignalBox.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool hasBullishSignalBox = iSignalBox.IsValid() &&
|
|
iSignalBox.ob.IsBullish();
|
|
|
|
//
|
|
bool hasBearishSignalBox = iSignalBox.IsValid() &&
|
|
iSignalBox.ob.IsBearish();
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
Parse(cXConditions);
|
|
|
|
//
|
|
int zIDX = barIndex;
|
|
int cIDX = zIDX + 1;
|
|
int pIDX = cIDX + 1;
|
|
int ppIDX = pIDX + 1;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
XOHCL pPBar;
|
|
|
|
//
|
|
// Initial Bars ...
|
|
result = zBar.Init(
|
|
cState.symbol,
|
|
cState.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();
|
|
cState.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION iBarPosDir;
|
|
bool isBarValidForDir = cHelper
|
|
.mBarAnalyser
|
|
.IsValidForPosition(
|
|
cBar,
|
|
iBarPosDir //
|
|
);
|
|
bool isBarValidForBullish =
|
|
isBarValidForDir &&
|
|
IsBullish(iBarPosDir);
|
|
bool isBarValidForBearish =
|
|
isBarValidForDir &&
|
|
IsBearish(iBarPosDir);
|
|
|
|
//
|
|
// Check Bar Validation for Trend Based Directions ...
|
|
result =
|
|
isBarValidForDir &&
|
|
iBarPosDir == trend &&
|
|
HasDirection(iBarPosDir);
|
|
if (!result)
|
|
{
|
|
//
|
|
// Cleanup Resources ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
pPBar.Clean();
|
|
cState.Clean();
|
|
iSignalBox.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cStateEvents.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Here we Have to Check Other Consitions Based On Current
|
|
// Stuffs ...
|
|
XBoxZone zoneBox;
|
|
|
|
//
|
|
// Select Boxes for Zones ...
|
|
XBoxZone tmpBoxes[];
|
|
if (hasBullishTrend)
|
|
{
|
|
//
|
|
XBoxZone tmp[];
|
|
|
|
//
|
|
// Order Blocks ...
|
|
// ToBox(
|
|
// cState.bullishOrderBlocks,
|
|
// tmp //
|
|
// );
|
|
// Copy(
|
|
// tmp,
|
|
// tmpBoxes //
|
|
// );
|
|
// Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bullishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
else if (hasBearishTrend)
|
|
{
|
|
//
|
|
XBoxZone tmp[];
|
|
|
|
//
|
|
// Order Blocks ...
|
|
// ToBox(
|
|
// cState.bearishOrderBlocks,
|
|
// tmp //
|
|
// );
|
|
// Copy(
|
|
// tmp,
|
|
// tmpBoxes //
|
|
// );
|
|
// Clean(tmp);
|
|
|
|
//
|
|
// Fair Value Gaps ...
|
|
ToBox(
|
|
cState.bearishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false // Ignore Clean ...
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
has = HasChild(tmpBoxes);
|
|
if (has)
|
|
{
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
// Select Box based on Trend ...
|
|
idx = hasBullishTrend
|
|
? GetLowest(tmpBoxes)
|
|
: hasBearishTrend
|
|
? GetHighest(tmpBoxes)
|
|
: -1;
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Selected Box ...
|
|
bool isDirPassed = iBox.dir == trend;
|
|
bool isFromPassed =
|
|
iSignalBox.fvg.IsValid()
|
|
? iBox.from > iSignalBox.fvg.from
|
|
: iBox.from > iSignalBox.ob.from;
|
|
bool isPriceInsidePassed =
|
|
hasBullishTrend
|
|
? cBar.low < iBox.upper &&
|
|
cBar.low > iBox.lower
|
|
: hasBearishTrend
|
|
? cBar.high > iBox.lower &&
|
|
cBar.high < iBox.upper
|
|
: false;
|
|
has = isDirPassed &&
|
|
isFromPassed &&
|
|
isPriceInsidePassed;
|
|
if (has)
|
|
{
|
|
//
|
|
zoneBox = iBox;
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
bool hasBullishZoneBox = zoneBox.IsValid() &&
|
|
zoneBox.IsBullish();
|
|
|
|
//
|
|
bool hasBearishZoneBox = zoneBox.IsValid() &&
|
|
zoneBox.IsBearish();
|
|
|
|
//
|
|
// Detecting Consolidation Zone ...
|
|
XBoxZone cZone;
|
|
if (hasBullishTrend)
|
|
{
|
|
//
|
|
ToBox(
|
|
cState.bullishConsolidationZones,
|
|
tmpBoxes //
|
|
);
|
|
}
|
|
else if (hasBearishTrend)
|
|
{
|
|
//
|
|
ToBox(
|
|
cState.bearishConsolidationZones,
|
|
tmpBoxes //
|
|
);
|
|
}
|
|
has = HasChild(tmpBoxes);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = GetYoungest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
cZone = tmpBoxes[idx];
|
|
|
|
//
|
|
// Check Consolidation Zone Place ...
|
|
has =
|
|
//
|
|
(
|
|
//
|
|
IsBoxInsideOr(
|
|
cZone,
|
|
zoneBox //
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
cZone.from >= zoneBox.from
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
(
|
|
//
|
|
IsBoxInsideOr(
|
|
zoneBox,
|
|
cZone //
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
zoneBox.from >= cZone.from
|
|
//
|
|
)
|
|
//
|
|
;
|
|
if (!has)
|
|
{
|
|
cZone.Clean();
|
|
}
|
|
}
|
|
}
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
bool hasBullishCZone = cZone.IsValid() &&
|
|
cZone.IsBullish();
|
|
|
|
//
|
|
bool hasBearishCZone = cZone.IsValid() &&
|
|
cZone.IsBearish();
|
|
|
|
//
|
|
// Summarize Conditions ...
|
|
|
|
//
|
|
// Bullish ...
|
|
isBullish =
|
|
//
|
|
// Base Bullish Conditions ...
|
|
hasBullishTrend &&
|
|
hasBullishCZone &&
|
|
hasBullishZoneBox &&
|
|
hasBullishSignalBox &&
|
|
isBarValidForBullish &&
|
|
//
|
|
// Other Additional Conditions ...
|
|
true
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish ...
|
|
isBearish =
|
|
//
|
|
// Base Bearish Conditions ...
|
|
hasBearishTrend &&
|
|
hasBearishCZone &&
|
|
hasBearishZoneBox &&
|
|
hasBearishSignalBox &&
|
|
isBarValidForBearish &&
|
|
//
|
|
// Other Additional Conditions ...
|
|
true
|
|
//
|
|
;
|
|
|
|
//
|
|
// Filling Requirements ...
|
|
result =
|
|
isBullish ||
|
|
isBearish;
|
|
if (result)
|
|
{
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
box = zoneBox;
|
|
|
|
//
|
|
box.to = TimeCurrent();
|
|
cZone.to = TimeCurrent();
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
|
|
|
//
|
|
XCBoxObject *iObj;
|
|
has = drawer.DrawBox(
|
|
box,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
XCBoxObject *iCObject;
|
|
has = drawer.DrawBox(
|
|
cZone,
|
|
iCObject //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
iCObject.BoxColor(clrLime);
|
|
iCObject.BoxStyle(STYLE_SOLID);
|
|
}
|
|
|
|
//
|
|
Print("Found ...");
|
|
|
|
//
|
|
ZeroMemory(drawer);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
pPBar.Clean();
|
|
cZone.Clean();
|
|
cState.Clean();
|
|
zoneBox.Clean();
|
|
iSignalBox.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cStateEvents.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// XSHCNZ ...
|
|
bool HasXSHCNZConditions(
|
|
ENUM_X_CYCLES cycle,
|
|
ENUM_X_DIRECTION trend,
|
|
XBoxZone &box,
|
|
ENUM_X_DIRECTION &dir,
|
|
XSignalBox &waitingBoxes[],
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
box.Clean();
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
// Validate Args ...
|
|
result = IsValid(cycle) &&
|
|
HasDirection(trend) &&
|
|
HasChild(waitingBoxes);
|
|
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;
|
|
}
|
|
Parse(cXConditions);
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
int zIDX = barIndex;
|
|
int cIDX = zIDX + 1;
|
|
int pIDX = cIDX + 1;
|
|
int ppIDX = pIDX + 1;
|
|
|
|
//
|
|
bool isBullish = false;
|
|
bool isBearish = false;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
|
|
//
|
|
// Initial Bars ...
|
|
result = zBar.Init(
|
|
cState.symbol,
|
|
cState.period,
|
|
barIndex //
|
|
);
|
|
result =
|
|
result &&
|
|
zBar.GetPreviousBar(cBar);
|
|
result =
|
|
result &&
|
|
cBar.GetPreviousBar(pBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
cState.Clean();
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Extract XSHCNZ Boxes ...
|
|
XBoxZone sharpBox;
|
|
XBoxZone sharpBoxes[];
|
|
count = ArraySize(waitingBoxes);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
has = waitingBoxes[i].ob.type == "XSHCNZ";
|
|
if (has)
|
|
{
|
|
//
|
|
AddRef(
|
|
waitingBoxes[i].ob,
|
|
sharpBoxes //
|
|
);
|
|
}
|
|
}
|
|
count = ArraySize(sharpBoxes);
|
|
has = IsValidSize(count);
|
|
result = has;
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
cState.Clean();
|
|
Clean(sharpBoxes);
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
cStateEvents.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Detect Price Inside Sharp Box ...
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = sharpBoxes[i];
|
|
|
|
//
|
|
bool isInside = cBar.close > iBox.lower &&
|
|
cBar.close < iBox.upper;
|
|
if (isInside)
|
|
{
|
|
//
|
|
sharpBox = iBox;
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Validate Sharp Box Exists ...
|
|
has = sharpBox.IsValid();
|
|
result = has;
|
|
if (!result)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
cState.Clean();
|
|
sharpBox.Clean();
|
|
Clean(sharpBoxes);
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
cStateEvents.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer;
|
|
XCBoxObject *iSharpObj;
|
|
has = drawer.DrawBox(
|
|
sharpBox,
|
|
iSharpObj //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
iSharpObj.BoxColor(clrYellow);
|
|
|
|
//
|
|
Print("Sharp Box Selected ...");
|
|
}
|
|
|
|
//
|
|
// Validate Bar for Specified Position Type ...
|
|
ENUM_X_DIRECTION iBarPosDir;
|
|
bool isBarValidForDir = cHelper
|
|
.mBarAnalyser
|
|
.IsValidForPosition(
|
|
cBar,
|
|
iBarPosDir //
|
|
);
|
|
bool isBarValidForBullish =
|
|
isBarValidForDir &&
|
|
IsBullish(iBarPosDir);
|
|
bool isBarValidForBearish =
|
|
isBarValidForDir &&
|
|
IsBearish(iBarPosDir);
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
cState.Clean();
|
|
sharpBox.Clean();
|
|
Clean(sharpBoxes);
|
|
ZeroMemory(cHelper);
|
|
cConditions.Clean();
|
|
cXConditions.Clean();
|
|
cStateEvents.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Senario 1:
|
|
// ---------------------------------------------
|
|
// Rejected Box ...
|
|
// ---------------------------------------------
|
|
bool useSenario1 = false;
|
|
bool isSenario1Happend = false;
|
|
bool isSenario1Bullish = false;
|
|
bool isSenario1Bearish = false;
|
|
if (useSenario1)
|
|
{
|
|
//
|
|
isSenario1Happend = cParser.HasRejectedBoxConditions(
|
|
X_CYCLE_DECISION,
|
|
box,
|
|
holderBox,
|
|
dir,
|
|
waitingBoxes,
|
|
provider,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
isSenario1Bullish =
|
|
isSenario1Happend &&
|
|
IsBullish(dir);
|
|
|
|
//
|
|
isSenario1Bearish =
|
|
isSenario1Happend &&
|
|
IsBearish(dir);
|
|
|
|
//
|
|
if (isSenario1Happend)
|
|
{
|
|
signalProvider = X121SMC_XWZ_PROVIDER_XREJECTED_BOX;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Senario 2:
|
|
// ---------------------------------------------------
|
|
// Activated Box ...
|
|
// ---------------------------------------------------
|
|
bool useSenario2 = false;
|
|
bool isSenario2Happend = false;
|
|
bool isSenario2Bullish = false;
|
|
bool isSenario2Bearish = false;
|
|
if (!isSenario1Happend &&
|
|
useSenario2)
|
|
{
|
|
//
|
|
isSenario2Happend = cParser.HasActivatedBoxConditions(
|
|
X_CYCLE_DECISION,
|
|
box,
|
|
holderBox,
|
|
dir,
|
|
waitingBoxes,
|
|
provider,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
isSenario2Bullish =
|
|
isSenario2Happend &&
|
|
IsBullish(dir);
|
|
|
|
//
|
|
isSenario2Bearish =
|
|
isSenario2Happend &&
|
|
IsBearish(dir);
|
|
|
|
//
|
|
if (isSenario2Happend)
|
|
{
|
|
signalProvider = X121SMC_XWZ_PROVIDER_XACTIVATED_BOX;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Senario 3:
|
|
// ---------------------------------------------------
|
|
// Breaked Box ...
|
|
// ---------------------------------------------------
|
|
bool useSenario3 = false;
|
|
bool isSenario3Happend = false;
|
|
bool isSenario3Bullish = false;
|
|
bool isSenario3Bearish = false;
|
|
if (!isSenario1Happend &&
|
|
!isSenario2Happend &&
|
|
useSenario3)
|
|
{
|
|
//
|
|
isSenario3Happend = cParser.HasBreakedBoxConditions(
|
|
X_CYCLE_DECISION,
|
|
box,
|
|
holderBox,
|
|
dir,
|
|
waitingBoxes,
|
|
provider,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
isSenario3Bullish =
|
|
isSenario3Happend &&
|
|
IsBullish(dir);
|
|
|
|
//
|
|
isSenario3Bearish =
|
|
isSenario3Happend &&
|
|
IsBearish(dir);
|
|
|
|
//
|
|
if (isSenario3Happend)
|
|
{
|
|
signalProvider = X121SMC_XWZ_PROVIDER_XBREAKED_BOX;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Senario 4:
|
|
// -----------------------------------------------
|
|
// Detect Signal Box Based On XHKMA Conditions ...
|
|
// -----------------------------------------------
|
|
bool useSenario4 = false;
|
|
bool isSenario4Happend = false;
|
|
bool isSenario4Bullish = false;
|
|
bool isSenario4Bearish = false;
|
|
if (!isSenario1Happend &&
|
|
!isSenario2Happend &&
|
|
!isSenario3Happend &&
|
|
useSenario4)
|
|
{
|
|
//
|
|
isSenario4Happend = cParser.HasXHKMAConditions(
|
|
X_CYCLE_DECISION,
|
|
trend,
|
|
box,
|
|
holderBox,
|
|
dir,
|
|
waitingBoxes,
|
|
provider,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
isSenario4Bullish =
|
|
isSenario4Happend &&
|
|
IsBullish(dir);
|
|
|
|
//
|
|
isSenario4Bearish =
|
|
isSenario4Happend &&
|
|
IsBearish(dir);
|
|
|
|
//
|
|
if (isSenario4Happend)
|
|
{
|
|
signalProvider = X121SMC_XWZ_PROVIDER_XHKMA;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Senario 5:
|
|
// ---------------------------------------------
|
|
// XSHCNZ Signal Box Detection Conditions ...
|
|
// ---------------------------------------------
|
|
bool useSenario5 = true;
|
|
bool isSenario5Happend = false;
|
|
bool isSenario5Bullish = false;
|
|
bool isSenario5Bearish = false;
|
|
if (!isSenario1Happend &&
|
|
!isSenario2Happend &&
|
|
!isSenario3Happend &&
|
|
!isSenario4Happend &&
|
|
useSenario5)
|
|
{
|
|
//
|
|
isSenario5Happend = cParser.HasXSHCNZConditions(
|
|
X_CYCLE_DECISION,
|
|
trend,
|
|
box,
|
|
dir,
|
|
waitingBoxes,
|
|
provider,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
isSenario5Bullish =
|
|
isSenario5Happend &&
|
|
IsBullish(dir);
|
|
|
|
//
|
|
isSenario5Bearish =
|
|
isSenario5Happend &&
|
|
IsBearish(dir);
|
|
|
|
//
|
|
if (isSenario5Happend)
|
|
{
|
|
signalProvider = X121SMC_XWZ_PROVIDER_XSHCNZ;
|
|
}
|
|
}
|