1707 lines
42 KiB
Plaintext
1707 lines
42 KiB
Plaintext
//
|
|
bool IsZoneActivated(
|
|
int &zoneIDX,
|
|
int &fvgIDX,
|
|
ENUM_X_DIRECTION &dir,
|
|
ENUM_X121SMC_XWZ_PROVIDERS &signalProvider,
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
fvgIDX = -1;
|
|
zoneIDX = -1;
|
|
dir = X_DIRECTION_NONE;
|
|
signalProvider = X121SMC_XWZ_PROVIDER_NONE;
|
|
|
|
//
|
|
// Normalize Bar Index ...
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex = 1;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid() &&
|
|
HasWaitingZones();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL bar;
|
|
result = bar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double peak = provider.decisionXConditions.peaksBuffer[1];
|
|
double vale = provider.decisionXConditions.valesBuffer[1];
|
|
|
|
//
|
|
double analysePeak = provider.analyseXConditions.peaksBuffer[1];
|
|
double analyseVale = provider.analyseXConditions.valesBuffer[1];
|
|
|
|
//
|
|
double consolidationPeak = provider.consolidationXConditions.peaksBuffer[1];
|
|
double consolidationVale = provider.consolidationXConditions.valesBuffer[1];
|
|
|
|
//
|
|
double visionPeak = provider.visionXConditions.peaksBuffer[1];
|
|
double visionVale = provider.visionXConditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isPeaksSame =
|
|
peak == analysePeak &&
|
|
analysePeak == consolidationPeak;
|
|
|
|
//
|
|
bool isValesSame =
|
|
vale == analyseVale &&
|
|
analyseVale == consolidationVale;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isDecisionScoreBullish =
|
|
provider.decisionBullishScore > provider.decisionBearishScore;
|
|
|
|
//
|
|
bool isDecisionScoreBearish =
|
|
provider.decisionBearishScore > provider.decisionBullishScore;
|
|
|
|
//
|
|
bool isAnalyseScoreBullish =
|
|
provider.analyseBullishScore > provider.analyseBearishScore;
|
|
|
|
//
|
|
bool isAnalyseScoreBearish =
|
|
provider.analyseBearishScore > provider.analyseBullishScore;
|
|
|
|
//
|
|
bool isConsolidationScoreBullish =
|
|
provider.consolidationBullishScore > provider.consolidationBearishScore;
|
|
|
|
//
|
|
bool isConsolidationScoreBearish =
|
|
provider.consolidationBearishScore > provider.consolidationBullishScore;
|
|
|
|
//
|
|
bool isVisionScoreBullish =
|
|
provider.visionBullishScore > provider.visionBearishScore;
|
|
|
|
//
|
|
bool isVisionScoreBearish =
|
|
provider.visionBearishScore > provider.visionBullishScore;
|
|
|
|
//
|
|
int count = CountWaitingZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XOBFVG iOBFVG = waitingZones[i];
|
|
|
|
//
|
|
ENUM_X_DIRECTION iDir = iOBFVG.GetDirection();
|
|
bool isBullish = iOBFVG.IsBullish();
|
|
|
|
//
|
|
int fvgsCount = iOBFVG.CountFVGs();
|
|
bool has = IsValidSize(fvgsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int j = 0; j < fvgsCount; j++)
|
|
{
|
|
//
|
|
XCFVG *jFVG = iOBFVG.fvgs[j];
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
has = ToBox(
|
|
iBox,
|
|
jFVG //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
double iRange = iBox.lower + ((iBox.upper - iBox.lower) / 2);
|
|
|
|
//
|
|
// Activate Zone Using PV ...
|
|
bool isPVPassed =
|
|
isBullish
|
|
? vale <= iBox.upper &&
|
|
vale >= iBox.lower
|
|
: peak <= iBox.upper &&
|
|
peak >= iBox.lower;
|
|
bool isPV50Passed =
|
|
isBullish
|
|
? vale < iBox.upper &&
|
|
vale <= iRange &&
|
|
vale > iBox.lower
|
|
: peak < iBox.upper &&
|
|
peak >= iRange &&
|
|
peak > iBox.lower;
|
|
|
|
//
|
|
// Activate Zone using Rejection ...
|
|
bool isRejected =
|
|
isBullish
|
|
? bar.low <= iBox.upper &&
|
|
bar.GetDown() > iBox.upper
|
|
: bar.high >= iBox.lower &&
|
|
bar.GetUp() < iBox.lower;
|
|
|
|
//
|
|
// Combine Result ...
|
|
// result = isPVPassed;
|
|
// || isPVPassed
|
|
// || isPV50Passed
|
|
// || isRejected;
|
|
|
|
//
|
|
result = isPVPassed;
|
|
|
|
if (result)
|
|
{
|
|
//
|
|
fvgIDX = j;
|
|
iBox.Clean();
|
|
zoneIDX = i;
|
|
|
|
//
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
ZeroMemory(jFVG);
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
result =
|
|
IsValidIndex(fvgIDX) &&
|
|
IsValidIndex(zoneIDX);
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
bar.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool IsBoxActivated(
|
|
XBoxZone &box,
|
|
ENUM_X_DIRECTION &dir,
|
|
ENUM_X121SMC_XWZ_PROVIDERS &signalProvider,
|
|
X121SMCStrategySignalProviderData &provider,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
box.Clean();
|
|
dir = X_DIRECTION_NONE;
|
|
signalProvider = X121SMC_XWZ_PROVIDER_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
result = IsValid() &&
|
|
HasWaitingBoxes();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL bar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
result = bar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
result =
|
|
result &&
|
|
bar.GetPreviousBar(cBar);
|
|
result =
|
|
result &&
|
|
cBar.GetPreviousBar(pBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
cBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve Some Required Data ...
|
|
|
|
//
|
|
double peakZ = provider.decisionXConditions.peaksBuffer[0];
|
|
double valeZ = provider.decisionXConditions.valesBuffer[0];
|
|
double peak = provider.decisionXConditions.peaksBuffer[1];
|
|
double vale = provider.decisionXConditions.valesBuffer[1];
|
|
|
|
//
|
|
double analysePeak = provider.analyseXConditions.peaksBuffer[1];
|
|
double analyseVale = provider.analyseXConditions.valesBuffer[1];
|
|
|
|
//
|
|
double consolidationPeak = provider.consolidationXConditions.peaksBuffer[1];
|
|
double consolidationVale = provider.consolidationXConditions.valesBuffer[1];
|
|
|
|
//
|
|
double visionPeak = provider.visionXConditions.peaksBuffer[1];
|
|
double visionVale = provider.visionXConditions.valesBuffer[1];
|
|
|
|
//
|
|
bool isPeaksSame =
|
|
peak == analysePeak &&
|
|
analysePeak == consolidationPeak;
|
|
|
|
//
|
|
bool isValesSame =
|
|
vale == analyseVale &&
|
|
analyseVale == consolidationVale;
|
|
|
|
//
|
|
// Calculate Scores Conditions ...
|
|
|
|
//
|
|
bool isDecisionScoreBullish =
|
|
provider.decisionBullishScore > provider.decisionBearishScore;
|
|
|
|
//
|
|
bool isDecisionScoreBearish =
|
|
provider.decisionBearishScore > provider.decisionBullishScore;
|
|
|
|
//
|
|
bool isAnalyseScoreBullish =
|
|
provider.analyseBullishScore > provider.analyseBearishScore;
|
|
|
|
//
|
|
bool isAnalyseScoreBearish =
|
|
provider.analyseBearishScore > provider.analyseBullishScore;
|
|
|
|
//
|
|
bool isConsolidationScoreBullish =
|
|
provider.consolidationBullishScore > provider.consolidationBearishScore;
|
|
|
|
//
|
|
bool isConsolidationScoreBearish =
|
|
provider.consolidationBearishScore > provider.consolidationBullishScore;
|
|
|
|
//
|
|
bool isVisionScoreBullish =
|
|
provider.visionBullishScore > provider.visionBearishScore;
|
|
|
|
//
|
|
bool isVisionScoreBearish =
|
|
provider.visionBearishScore > provider.visionBullishScore;
|
|
|
|
//
|
|
bool isScoreBullish =
|
|
isVisionScoreBullish &&
|
|
isAnalyseScoreBullish &&
|
|
isConsolidationScoreBullish;
|
|
|
|
//
|
|
bool isScoreBearish =
|
|
isVisionScoreBearish &&
|
|
isAnalyseScoreBearish &&
|
|
isConsolidationScoreBearish;
|
|
|
|
//
|
|
// Waiting Boxes ...
|
|
int count = CountWaitingBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = waitingBoxes[i];
|
|
bool isBullish = iBox.IsBullish();
|
|
|
|
//
|
|
// Check Score ...
|
|
|
|
//
|
|
bool isScorePassed =
|
|
isBullish
|
|
? isScoreBullish
|
|
: isScoreBearish;
|
|
|
|
//
|
|
// Check Bar Insides ...
|
|
|
|
//
|
|
bool isPBarInside =
|
|
(pBar.high <= iBox.upper &&
|
|
pBar.low >= iBox.lower) ||
|
|
(isBullish
|
|
? pBar.low < iBox.upper &&
|
|
pBar.GetDown() < iBox.upper
|
|
: pBar.high > iBox.lower &&
|
|
pBar.GetUp() > iBox.lower);
|
|
|
|
//
|
|
bool isCBarInside =
|
|
(cBar.high <= iBox.upper &&
|
|
cBar.low >= iBox.lower) ||
|
|
(isBullish
|
|
? cBar.low < iBox.upper &&
|
|
cBar.GetDown() < iBox.upper
|
|
: cBar.high > iBox.lower &&
|
|
cBar.GetUp() > iBox.lower);
|
|
|
|
//
|
|
// Checking Rejection ...
|
|
|
|
//
|
|
// Bullish ...
|
|
bool isBullishRejected =
|
|
isBullish &&
|
|
cBar.low <= iBox.upper &&
|
|
cBar.GetDown() > iBox.upper;
|
|
|
|
//
|
|
// Bearish ...
|
|
bool isBearishRejected =
|
|
!isBullish &&
|
|
cBar.high >= iBox.lower &&
|
|
cBar.GetUp() < iBox.lower;
|
|
|
|
//
|
|
// Check Breaktion ...
|
|
|
|
//
|
|
// Bullish ...
|
|
bool isBullishBreaked =
|
|
isBullish &&
|
|
cBar.high > iBox.upper &&
|
|
cBar.GetUp() > iBox.upper &&
|
|
cBar.low >= iBox.lower;
|
|
|
|
//
|
|
// Bearish ...
|
|
bool isBearishBreaked =
|
|
!isBullish &&
|
|
cBar.low < iBox.lower &&
|
|
cBar.GetDown() < iBox.lower &&
|
|
cBar.high <= iBox.upper;
|
|
|
|
//
|
|
// Checking PV Pass ...
|
|
|
|
//
|
|
bool isBullishPVPassed =
|
|
isBullish &&
|
|
vale == valeZ &&
|
|
vale > iBox.lower &&
|
|
vale < iBox.upper;
|
|
|
|
//
|
|
bool isBearishPVPassed =
|
|
!isBullish &&
|
|
peak == peakZ &&
|
|
peak > iBox.lower &&
|
|
peak < iBox.upper;
|
|
|
|
//
|
|
// Summarise ...
|
|
|
|
//
|
|
// Rejection ...
|
|
bool isRejected = isBullishRejected ||
|
|
isBearishRejected;
|
|
|
|
//
|
|
// Breaktion ...
|
|
bool isBreaked =
|
|
isPBarInside &&
|
|
(isBullishBreaked ||
|
|
isBearishBreaked);
|
|
|
|
//
|
|
bool isPVPassed =
|
|
(isBullishPVPassed ||
|
|
isBearishPVPassed);
|
|
|
|
//
|
|
// Trend Conditions ...
|
|
|
|
//
|
|
bool isX3MABullish =
|
|
provider.decisionXConditions.isX3MaFastOverMid &&
|
|
provider.decisionXConditions.x3maMidBuffer[1] > provider.decisionXConditions.x3maSlowBuffer[1];
|
|
|
|
//
|
|
bool isX3MABearish =
|
|
provider.decisionXConditions.isX3MaFastUnderMid &&
|
|
provider.decisionXConditions.x3maMidBuffer[1] < provider.decisionXConditions.x3maSlowBuffer[1];
|
|
|
|
//
|
|
bool isVWapBullish =
|
|
provider.decisionXConditions.isVWapFastOverMid &&
|
|
provider.decisionXConditions.vwapMidBuffer[1] > provider.decisionXConditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
bool isVWapBearish =
|
|
provider.decisionXConditions.isX3MaFastUnderMid &&
|
|
provider.decisionXConditions.vwapMidBuffer[1] < provider.decisionXConditions.vwapSlowBuffer[1];
|
|
|
|
//
|
|
bool isTrendBullish =
|
|
isX3MABullish &&
|
|
isVWapBullish;
|
|
|
|
//
|
|
bool isTrendBearish =
|
|
isX3MABearish &&
|
|
isVWapBearish;
|
|
|
|
//
|
|
bool isTrendPassed =
|
|
isBullish
|
|
? isTrendBullish
|
|
: isTrendBearish;
|
|
|
|
//
|
|
// Summarize Conditions ...
|
|
|
|
//
|
|
result =
|
|
//
|
|
// isBreaked ||
|
|
// isRejected ||
|
|
isPVPassed &&
|
|
isRejected &&
|
|
isTrendPassed &&
|
|
isScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
box = iBox;
|
|
dir = iBox.dir;
|
|
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX;
|
|
|
|
//
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
// MA Trends ...
|
|
if (!result)
|
|
{
|
|
//
|
|
result = provider.analyseState.HasOrderBlocks();
|
|
if (result)
|
|
{
|
|
//
|
|
//
|
|
// Trend Conditions ...
|
|
|
|
//
|
|
bool isX3MABullish =
|
|
provider.decisionXConditions.isX3MaFastCrossedOverMid;
|
|
|
|
//
|
|
bool isX3MABearish =
|
|
provider.decisionXConditions.isX3MaFastCrossedUnderMid;
|
|
|
|
//
|
|
bool isVWapBullish =
|
|
provider.decisionXConditions.isVWapFastCrossedOverMid;
|
|
|
|
//
|
|
bool isVWapBearish =
|
|
provider.decisionXConditions.isVWapFastCrossedUnderMid;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isTrendBullish =
|
|
(isX3MABullish ||
|
|
isVWapBullish) &&
|
|
provider.decisionXConditions.isNewPeakOverLast;
|
|
|
|
//
|
|
bool isTrendBearish =
|
|
(isX3MABearish ||
|
|
isVWapBearish) &&
|
|
provider.decisionXConditions.isNewValeUnderLast;
|
|
|
|
//
|
|
result = isTrendBullish ||
|
|
isTrendBearish;
|
|
if (result)
|
|
{
|
|
//
|
|
// Select Signal Box ...
|
|
|
|
//
|
|
bool isScorePassed =
|
|
isTrendBullish
|
|
? isScoreBullish
|
|
: isScoreBearish;
|
|
|
|
//
|
|
XBoxZone tmpBoxes[];
|
|
ToBox(
|
|
provider.analyseState.orderBlocks,
|
|
tmpBoxes //
|
|
);
|
|
Copy(
|
|
waitingBoxes,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
int idx = -1;
|
|
// bool has = false;
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
if (isTrendBullish)
|
|
{
|
|
idx = GetHighest(tmpBoxes);
|
|
}
|
|
else
|
|
{
|
|
idx = GetLowest(tmpBoxes);
|
|
}
|
|
|
|
//
|
|
result = IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
|
|
//
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
int insideIDX = -1;
|
|
bool hasInsideBox = HasInsideBox(
|
|
insideIDX,
|
|
iBox,
|
|
tmpBoxes //
|
|
);
|
|
if (hasInsideBox)
|
|
{
|
|
//
|
|
hasInsideBox =
|
|
isTrendBullish
|
|
? iBox.lower < tmpBoxes[insideIDX].lower
|
|
: iBox.upper > tmpBoxes[insideIDX].upper;
|
|
}
|
|
|
|
//
|
|
bool isBullishPlacePassed =
|
|
// !hasInsideBox &&
|
|
isTrendBullish &&
|
|
iBox.IsBullish() &&
|
|
bar.low >= iBox.upper &&
|
|
cBar.low >= iBox.upper &&
|
|
provider.decisionXConditions.x3maMin >= iBox.lower &&
|
|
provider.decisionXConditions.vwapMin >= iBox.lower;
|
|
|
|
//
|
|
bool isBearishPlacePassed =
|
|
// !hasInsideBox &&
|
|
isTrendBearish &&
|
|
iBox.IsBearish() &&
|
|
bar.high <= iBox.lower &&
|
|
cBar.high <= iBox.lower &&
|
|
provider.decisionXConditions.x3maMax <= iBox.upper &&
|
|
provider.decisionXConditions.vwapMax <= iBox.upper;
|
|
|
|
//
|
|
result = isScorePassed &&
|
|
(isBullishPlacePassed ||
|
|
isBearishPlacePassed);
|
|
if (result)
|
|
{
|
|
//
|
|
box = iBox;
|
|
iBox.Clean();
|
|
dir =
|
|
isTrendBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_MA;
|
|
break;
|
|
}
|
|
|
|
//
|
|
}
|
|
Clean(tmpBoxes);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Supply and Demand ...
|
|
if (false && !result)
|
|
{
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
XBoxZone tmpBoxes[];
|
|
|
|
//
|
|
// Detecting Youngest Zones ...
|
|
|
|
//
|
|
XBoxZone bullishBox;
|
|
bool hasBullishBox = false;
|
|
if (!hasBullishBox)
|
|
{
|
|
//
|
|
XCOrderBlock *ob = NULL;
|
|
idx = GetYoungest(provider.analyseState.bullishOrderBlocks);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
ob = provider.analyseState.bullishOrderBlocks[idx];
|
|
|
|
//
|
|
XOHCL startedBar;
|
|
bool isBodyOut = false;
|
|
bool isStarted = ob.IsStarted(
|
|
ob.GetDirection(),
|
|
startedBar,
|
|
isBodyOut //
|
|
);
|
|
has = isStarted &&
|
|
isBodyOut;
|
|
if (has)
|
|
{
|
|
//
|
|
hasBullishBox = ToBox(
|
|
bullishBox,
|
|
ob //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (!hasBullishBox)
|
|
{
|
|
bullishBox.Clean();
|
|
}
|
|
|
|
//
|
|
ZeroMemory(ob);
|
|
}
|
|
|
|
//
|
|
XBoxZone bearishBox;
|
|
bool hasBearishBox = false;
|
|
if (!hasBearishBox)
|
|
{
|
|
//
|
|
XCOrderBlock *ob = NULL;
|
|
idx = GetYoungest(provider.analyseState.bearishOrderBlocks);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
ob = provider.analyseState.bearishOrderBlocks[idx];
|
|
|
|
//
|
|
XOHCL startedBar;
|
|
bool isBodyOut = false;
|
|
bool isStarted = ob.IsStarted(
|
|
ob.GetDirection(),
|
|
startedBar,
|
|
isBodyOut //
|
|
);
|
|
has = isStarted &&
|
|
isBodyOut;
|
|
if (has)
|
|
{
|
|
//
|
|
hasBearishBox = ToBox(
|
|
bearishBox,
|
|
ob //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
if (!hasBearishBox)
|
|
{
|
|
bearishBox.Clean();
|
|
}
|
|
|
|
//
|
|
ZeroMemory(ob);
|
|
}
|
|
|
|
//
|
|
XBoxZone bullishCZBox;
|
|
bool hasBullishConsolidationZone = false;
|
|
XConsolidationZone bullishConsolidationZone;
|
|
hasBullishConsolidationZone = provider.decisionState.HasBullishConsolidationZones();
|
|
if (hasBullishConsolidationZone)
|
|
{
|
|
//
|
|
idx = GetYoungest(provider.decisionState.bullishConsolidationZones);
|
|
hasBullishConsolidationZone = IsValidIndex(idx);
|
|
if (hasBullishConsolidationZone)
|
|
{
|
|
//
|
|
bullishConsolidationZone = provider.decisionState.bullishConsolidationZones[idx];
|
|
if (hasBullishConsolidationZone)
|
|
{
|
|
//
|
|
hasBullishConsolidationZone = ToBox(
|
|
bullishCZBox,
|
|
bullishConsolidationZone //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
XBoxZone bearishCZBox;
|
|
bool hasBearishConsolidationZone = false;
|
|
XConsolidationZone bearishConsolidationZone;
|
|
hasBearishConsolidationZone = provider.decisionState.HasBearishConsolidationZones();
|
|
if (hasBearishConsolidationZone)
|
|
{
|
|
//
|
|
idx = GetYoungest(provider.decisionState.bearishConsolidationZones);
|
|
hasBearishConsolidationZone = IsValidIndex(idx);
|
|
if (hasBearishConsolidationZone)
|
|
{
|
|
//
|
|
bearishConsolidationZone = provider.decisionState.bearishConsolidationZones[idx];
|
|
if (hasBearishConsolidationZone)
|
|
{
|
|
//
|
|
hasBearishConsolidationZone = ToBox(
|
|
bearishCZBox,
|
|
bearishConsolidationZone //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Supply Zone ...
|
|
has = provider.visionState.HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
ToBox(
|
|
provider.visionState.supplyZones,
|
|
tmpBoxes //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
idx = GetYoungest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Price Must Be Inside a Zonne More Than 5 Bar ...
|
|
bool isPriceInside =
|
|
//
|
|
bar.high < iBox.upper &&
|
|
bar.low > iBox.lower &&
|
|
//
|
|
cBar.high < iBox.upper &&
|
|
cBar.low > iBox.lower &&
|
|
//
|
|
pBar.high < iBox.upper &&
|
|
pBar.low > iBox.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBearishBoxPassed =
|
|
hasBearishBox &&
|
|
IsBoxInside(
|
|
bearishBox,
|
|
iBox //
|
|
);
|
|
|
|
//
|
|
bool isBearishCZBoxPassed =
|
|
hasBearishConsolidationZone &&
|
|
IsBoxInside(
|
|
bearishCZBox,
|
|
iBox //
|
|
);
|
|
|
|
//
|
|
result = isPriceInside &&
|
|
(isBearishBoxPassed ||
|
|
isBearishCZBoxPassed);
|
|
if (result)
|
|
{
|
|
//
|
|
if (isBearishBoxPassed)
|
|
{
|
|
box = bearishBox;
|
|
}
|
|
else
|
|
{
|
|
box = bearishCZBox;
|
|
}
|
|
|
|
//
|
|
iBox.to = TimeCurrent();
|
|
XCBoxObject *iObj;
|
|
provider.visionCycleHelper.mPOIDrawer.DrawBox(
|
|
iBox,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
dir = X_DIRECTION_BEARISH;
|
|
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_AREA;
|
|
|
|
//
|
|
iBox.Clean();
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
}
|
|
|
|
//
|
|
// Demand Zone ...
|
|
has = provider.visionState.HasDemandZones();
|
|
if (!result && has)
|
|
{
|
|
//
|
|
ToBox(
|
|
provider.visionState.demandZones,
|
|
tmpBoxes //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
idx = GetYoungest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Price Must Be Inside a Zonne More Than 5 Bar ...
|
|
bool isPriceInside =
|
|
//
|
|
bar.high < iBox.upper &&
|
|
bar.low > iBox.lower &&
|
|
//
|
|
cBar.high < iBox.upper &&
|
|
cBar.low > iBox.lower &&
|
|
//
|
|
pBar.high < iBox.upper &&
|
|
pBar.low > iBox.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBullishBoxPassed =
|
|
hasBullishBox &&
|
|
IsBoxInside(
|
|
bullishBox,
|
|
iBox //
|
|
);
|
|
|
|
//
|
|
bool isBullishCZBoxPassed =
|
|
hasBullishConsolidationZone &&
|
|
IsBoxInside(
|
|
bullishCZBox,
|
|
iBox //
|
|
);
|
|
|
|
//
|
|
result = isPriceInside &&
|
|
(isBullishBoxPassed ||
|
|
isBullishCZBoxPassed);
|
|
if (result)
|
|
{
|
|
//
|
|
if (isBullishBoxPassed)
|
|
{
|
|
box = bullishBox;
|
|
}
|
|
else
|
|
{
|
|
box = bullishCZBox;
|
|
}
|
|
|
|
//
|
|
iBox.to = TimeCurrent();
|
|
XCBoxObject *iObj;
|
|
provider.visionCycleHelper.mPOIDrawer.DrawBox(
|
|
iBox,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
dir = X_DIRECTION_BULLISH;
|
|
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_AREA;
|
|
|
|
//
|
|
iBox.Clean();
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
bullishBox.Clean();
|
|
bearishBox.Clean();
|
|
bullishCZBox.Clean();
|
|
bearishCZBox.Clean();
|
|
bullishConsolidationZone.Clean();
|
|
bearishConsolidationZone.Clean();
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
bar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// bool isZoneActivated =
|
|
// hasWorkingZone &&
|
|
// hasWaitingZones &&
|
|
// workingZone.IsZoneActivated(
|
|
// activatedZoneIDX,
|
|
// activatedFVGIDX,
|
|
// signalBoxDir,
|
|
// signalProvider,
|
|
// provider,
|
|
// zIndex //
|
|
// );
|
|
|
|
//
|
|
// hasSignalBox =
|
|
// hasWorkingZone &&
|
|
// hasWaitingBoxes &&
|
|
// workingZone.IsBoxActivated(
|
|
// signalBox,
|
|
// signalBoxDir,
|
|
// signalProvider,
|
|
// provider,
|
|
// zIndex //
|
|
// );
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
int activatedFVGIDX = -1;
|
|
int activatedZoneIDX = -1;
|
|
bool hasWaitingZones = false;
|
|
|
|
//
|
|
// Remove Invalidate Zones ...
|
|
if (hasWaitingZones)
|
|
{
|
|
//
|
|
// Validate Waiting Zones ...
|
|
workingZone.ValidateWaitingZones(zIndex);
|
|
hasWaitingZones = workingZone.HasWaitingZones();
|
|
}
|
|
|
|
//
|
|
// Detect Zones and Boxes ...
|
|
// hasWaitingZones = workingZone.DetectZone(
|
|
// provider //
|
|
// );
|
|
|
|
//
|
|
hasWaitingBoxes = workingZone.HasWaitingBoxes();
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Senario 1:
|
|
// ----------
|
|
bool useSenario1 = true;
|
|
bool isSenario1Happend = false;
|
|
bool isSenario1Bullish = false;
|
|
bool isSenario1Bearish = false;
|
|
if (useSenario1)
|
|
{
|
|
//
|
|
// Senario 1 Bullish Conditions ...
|
|
isSenario1Bullish =
|
|
//
|
|
// X3Ma / XVwap Switched To Bulish ...
|
|
(
|
|
//
|
|
// X3Ma Switched To Bulish ...
|
|
(
|
|
//
|
|
(provider.decisionXConditions.isX3MaFastCrossedOverMid &&
|
|
decisionParser.isX3MaBullishStateUnderValesGoldenZone)
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
// XVWap Switched To Bulish ...
|
|
(
|
|
//
|
|
(provider.decisionXConditions.isVWapFastCrossedOverMid &&
|
|
decisionParser.isVWapBullishStateUnderValesGoldenZone)
|
|
//
|
|
)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Checking other Conditions ...
|
|
(
|
|
//
|
|
// XSTR ...
|
|
provider.decisionXConditions.isStrBullish &&
|
|
//
|
|
// XCHE ...
|
|
provider.decisionXConditions.isCheBullish &&
|
|
provider.decisionXConditions.le1Buffer[cIDX] < cBar.low &&
|
|
provider.decisionXConditions.le2Buffer[cIDX] < cBar.low
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Senario 1 Bearish Conditions ...
|
|
isSenario1Bearish =
|
|
//
|
|
// X3Ma / XVwap Switched To Bearish ...
|
|
(
|
|
//
|
|
// X3Ma Switched To Bearish ...
|
|
(
|
|
//
|
|
(provider.decisionXConditions.isX3MaFastCrossedUnderMid &&
|
|
decisionParser.isX3MaBearishStateOverPeaksGoldenZone)
|
|
//
|
|
)
|
|
//
|
|
||
|
|
//
|
|
// XVWap Switched To Bearish ...
|
|
(
|
|
//
|
|
(provider.decisionXConditions.isVWapFastCrossedUnderMid &&
|
|
decisionParser.isVWapBearishStateOverPeaksGoldenZone)
|
|
//
|
|
)
|
|
//
|
|
)
|
|
//
|
|
&&
|
|
//
|
|
// Checking other Conditions ...
|
|
(
|
|
//
|
|
// XSTR ...
|
|
provider.decisionXConditions.isStrBearish &&
|
|
//
|
|
// XCHE ...
|
|
provider.decisionXConditions.isCheBearish &&
|
|
provider.decisionXConditions.se1Buffer[cIDX] > cBar.high &&
|
|
provider.decisionXConditions.se2Buffer[cIDX] > cBar.high
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
isSenario2Happend = cParser.HasSenario2Conditions(
|
|
X_CYCLE_DECISION, // TFT Cycle ...
|
|
X_CYCLE_ANALYSE, // MTF Cycle ...
|
|
X_CYCLE_CONSOLIDATION, // HTF Cycle ...
|
|
box,
|
|
holderBox,
|
|
dir,
|
|
provider,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
isSenario2Bullish =
|
|
isSenario2Happend &&
|
|
IsBullish(dir);
|
|
|
|
//
|
|
isSenario2Bearish =
|
|
isSenario2Happend &&
|
|
IsBearish(dir);
|
|
|
|
//
|
|
if (isSenario2Happend)
|
|
{
|
|
signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Extract Cycles ...
|
|
|
|
//
|
|
// TTF Cycle ...
|
|
XPOIState ttfState;
|
|
X121Conditions ttfXConditions;
|
|
XC121SMCCycleHelper *ttfHelper;
|
|
X121SMCCycleConditions ttfConditions;
|
|
result = provider.SelectCycle(
|
|
ttfCycle,
|
|
ttfState,
|
|
ttfXConditions,
|
|
ttfHelper,
|
|
ttfConditions //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
ttfState.Clean();
|
|
ZeroMemory(ttfHelper);
|
|
ttfConditions.Clean();
|
|
ttfXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
Parse(ttfXConditions);
|
|
|
|
//
|
|
// MTF Cycle ...
|
|
XPOIState mtfState;
|
|
X121Conditions mtfXConditions;
|
|
XC121SMCCycleHelper *mtfHelper;
|
|
X121SMCCycleConditions mtfConditions;
|
|
result = provider.SelectCycle(
|
|
mtfCycle,
|
|
mtfState,
|
|
mtfXConditions,
|
|
mtfHelper,
|
|
mtfConditions //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
ttfState.Clean();
|
|
mtfState.Clean();
|
|
ZeroMemory(ttfHelper);
|
|
ttfConditions.Clean();
|
|
ZeroMemory(mtfHelper);
|
|
mtfConditions.Clean();
|
|
ttfXConditions.Clean();
|
|
mtfXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
Parse(mtfXConditions);
|
|
|
|
//
|
|
// HTF Cycle ...
|
|
XPOIState htfState;
|
|
X121Conditions htfXConditions;
|
|
XC121SMCCycleHelper *htfHelper;
|
|
X121SMCCycleConditions htfConditions;
|
|
result = provider.SelectCycle(
|
|
htfCycle,
|
|
htfState,
|
|
htfXConditions,
|
|
htfHelper,
|
|
htfConditions //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
ttfState.Clean();
|
|
mtfState.Clean();
|
|
htfState.Clean();
|
|
ZeroMemory(ttfHelper);
|
|
ZeroMemory(mtfHelper);
|
|
ZeroMemory(htfHelper);
|
|
ttfConditions.Clean();
|
|
mtfConditions.Clean();
|
|
htfConditions.Clean();
|
|
ttfXConditions.Clean();
|
|
mtfXConditions.Clean();
|
|
htfXConditions.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
Parse(htfXConditions);
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
dir =
|
|
isBullish
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
box.dir = dir;
|
|
box.to = TimeCurrent();
|
|
box.symbol = ttfXConditions.symbol;
|
|
box.period = ttfXConditions.period;
|
|
|
|
//
|
|
int fromIDX = -1;
|
|
if (isBullish)
|
|
{
|
|
//
|
|
double vale = ttfXConditions.valesBuffer[cIDX];
|
|
box.lower = vale;
|
|
box.upper = ttfXConditions.valesGoldenBuffer[cIDX];
|
|
|
|
//
|
|
int lowerValeIDX = -1;
|
|
double lowerVale = ttfHelper
|
|
.mX121Helper
|
|
.xpvHelper
|
|
.GetLowerVale(
|
|
lowerValeIDX,
|
|
vale,
|
|
cBar.Index() //
|
|
);
|
|
|
|
//
|
|
int higherValeIDX = -1;
|
|
double higherVale = ttfHelper
|
|
.mX121Helper
|
|
.xpvHelper
|
|
.GetHigherVale(
|
|
higherValeIDX,
|
|
vale,
|
|
cBar.Index() //
|
|
);
|
|
|
|
//
|
|
if (IsValidIndex(lowerValeIDX) &&
|
|
IsValidIndex(higherValeIDX))
|
|
{
|
|
//
|
|
fromIDX =
|
|
lowerValeIDX < higherValeIDX
|
|
? lowerValeIDX
|
|
: higherValeIDX;
|
|
}
|
|
else if (IsValidIndex(lowerValeIDX) &&
|
|
!IsValidIndex(higherValeIDX))
|
|
{
|
|
//
|
|
fromIDX = lowerValeIDX;
|
|
}
|
|
else if (!IsValidIndex(lowerValeIDX) &&
|
|
IsValidIndex(higherValeIDX))
|
|
{
|
|
//
|
|
fromIDX = higherValeIDX;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
double peak = ttfXConditions.peaksBuffer[cIDX];
|
|
box.upper = peak;
|
|
|
|
//
|
|
box.lower = ttfXConditions.peaksGoldenBuffer[cIDX];
|
|
|
|
//
|
|
int lowerPeakIDX = -1;
|
|
double lowerPeak = ttfHelper
|
|
.mX121Helper
|
|
.xpvHelper
|
|
.GetLowerPeak(
|
|
lowerPeakIDX,
|
|
peak,
|
|
cBar.Index() //
|
|
);
|
|
|
|
//
|
|
int higherPeakIDX = -1;
|
|
double higherPeak = ttfHelper
|
|
.mX121Helper
|
|
.xpvHelper
|
|
.GetHigherPeak(
|
|
higherPeakIDX,
|
|
peak,
|
|
cBar.Index() //
|
|
);
|
|
|
|
//
|
|
if (IsValidIndex(lowerPeakIDX) &&
|
|
IsValidIndex(higherPeakIDX))
|
|
{
|
|
//
|
|
fromIDX =
|
|
lowerPeakIDX < higherPeakIDX
|
|
? lowerPeakIDX
|
|
: higherPeakIDX;
|
|
}
|
|
else if (IsValidIndex(lowerPeakIDX) &&
|
|
!IsValidIndex(higherPeakIDX))
|
|
{
|
|
//
|
|
fromIDX = lowerPeakIDX;
|
|
}
|
|
else if (!IsValidIndex(lowerPeakIDX) &&
|
|
IsValidIndex(higherPeakIDX))
|
|
{
|
|
//
|
|
fromIDX = higherPeakIDX;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (IsValidIndex(fromIDX))
|
|
{
|
|
//
|
|
box.from = iTime(
|
|
zBar.symbol,
|
|
zBar.period,
|
|
fromIDX //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
box.from = pBar.time;
|
|
}
|
|
|
|
//
|
|
// Detect Holder Box ...
|
|
XBoxZone tmpBoxes[];
|
|
if (htfState.IsValid())
|
|
{
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Demand Zones ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
htfState.demandZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Bullish Order Blocks ...
|
|
ToBox(
|
|
htfState.bullishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Bullish Fair Value Gaps ...
|
|
ToBox(
|
|
htfState.bullishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Supply Zones ...
|
|
XBoxZone tmp[];
|
|
ToBox(
|
|
htfState.supplyZones,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Bearish Order Blocks ...
|
|
ToBox(
|
|
htfState.bearishOrderBlocks,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
Clean(tmp);
|
|
|
|
//
|
|
// Bearish Fair Value Gaps ...
|
|
ToBox(
|
|
htfState.bearishFairValueGaps,
|
|
tmp //
|
|
);
|
|
Copy(
|
|
tmp,
|
|
tmpBoxes,
|
|
false //
|
|
);
|
|
Clean(tmp);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasChild(tmpBoxes);
|
|
if (has)
|
|
{
|
|
//
|
|
while (HasChild(tmpBoxes))
|
|
{
|
|
//
|
|
idx = GetOldest(tmpBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox = tmpBoxes[idx];
|
|
ArrayRemove(
|
|
tmpBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
has = IsBoxInside(
|
|
box,
|
|
iBox //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
holderBox = iBox;
|
|
holderBox.to = TimeCurrent();
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
|
|
//
|
|
// Validate Conditions to Force Has Holder Box ...
|
|
result =
|
|
result &&
|
|
holderBox.IsValid();
|
|
if (!result)
|
|
{
|
|
//
|
|
isBullish = false;
|
|
isBearish = false;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Here we Looking for Detectiong Signal Conditions ...
|
|
if (result)
|
|
{
|
|
//
|
|
insideBox.from = insideBox.to;
|
|
insideBox.to = zBar.time;
|
|
|
|
//
|
|
XCBoxObject *iObj;
|
|
has = ttfHelper.mPOIDrawer.DrawBox(
|
|
insideBox,
|
|
iObj //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
iObj.Width(2);
|
|
iObj.BoxColor(clrGray);
|
|
}
|
|
|
|
//
|
|
Print("Has Inside Box ...");
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////
|