10875 lines
225 KiB
Plaintext
10875 lines
225 KiB
Plaintext
|
|
//
|
|
// Fix Signal TP Based On Working Zone ...
|
|
// double maxAllowedTP =
|
|
// hasLong
|
|
// ? mXWZConditions.workingZone.upper
|
|
// : mXWZConditions.workingZone.lower;
|
|
// bool canApplyMaxAlowedTP = (hasLong &&
|
|
// signal.tp > maxAllowedTP) ||
|
|
// (!hasLong && signal.tp < maxAllowedTP);
|
|
// if (canApplyMaxAlowedTP)
|
|
// {
|
|
// signal.tp = maxAllowedTP;
|
|
// }
|
|
|
|
//
|
|
// Configuring Global Protector ...
|
|
// signal.trailSL = true;
|
|
// signal.trailSLStartOnReachTPLevel = 3;
|
|
// signal.fullTPLevel = signal.GetRiskRewardRatio();
|
|
|
|
// //
|
|
// mXSupDemOBSSignalDetector.RemoveDraws();
|
|
// mXSupDemOBSSignalDetector.DrawConditions(
|
|
// mXSupDemOBSConditions,
|
|
// mVisionCycleHelper.mPOIDrawer //
|
|
// );
|
|
|
|
// //
|
|
// mXSupDemOBSSignalDetector.RemoveWorkingZoneDraws();
|
|
// mXSupDemOBSSignalDetector.DrawWorkingZone(
|
|
// mXSupDemOBSConditions,
|
|
// mVisionCycleHelper.mPOIDrawer //
|
|
// );
|
|
|
|
//
|
|
// bool canReplaceTarget =
|
|
// signal.target > 0 &&
|
|
// (hasLong
|
|
// ? signal.target > signal.tp
|
|
// : signal.target < signal.tp);
|
|
// if (canReplaceTarget)
|
|
// {
|
|
// //
|
|
// signal.tp = conditions.target;
|
|
// signal.target = tp;
|
|
// }
|
|
|
|
//
|
|
// consolidationState.UpdateTo(cTime);
|
|
// XPOIState filtered;
|
|
// consolidationState.Filter(
|
|
// filtered,
|
|
// NULL,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
// XCBaseObject *objects[];
|
|
// int objectsCount = drawer.DrawState(
|
|
// filtered,
|
|
// objects //
|
|
// );
|
|
// if (IsValidSize(objectsCount))
|
|
// {
|
|
// //
|
|
// Print("");
|
|
// }
|
|
|
|
// //
|
|
// XOBFVG activeObfvgs[];
|
|
// int activeObfvgsCount = ExtractOBFVGs(
|
|
// activeObfvgs,
|
|
// consolidationState,
|
|
// analyseState //
|
|
// );
|
|
// bool hasActiveOBFVGs = IsValidSize(activeObfvgsCount);
|
|
// if (hasActiveOBFVGs)
|
|
// {
|
|
// //
|
|
// SpecifiedUpdateTo(activeObfvgs);
|
|
// for (int i = 0; i < activeObfvgsCount; i++)
|
|
// {
|
|
// //
|
|
// XCBaseObject *objects[];
|
|
// int objectsCount = drawer.DrawOBFVG(
|
|
// activeObfvgs[i],
|
|
// objects //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Swings ...
|
|
// bool lookupSwings = ArraySize(mSwingLows) < mMaxRequiredPOIs ||
|
|
// ArraySize(mSwingHighs) < mMaxRequiredPOIs;
|
|
// lookupSwings =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupSwings;
|
|
// if (has &&
|
|
// lookupSwings)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // Momentum Bar ...
|
|
// bool lookupMomentums = ArraySize(mBullishMomentumBars) < mMaxRequiredPOIs ||
|
|
// ArraySize(mBearishMomentumBars) < mMaxRequiredPOIs;
|
|
// lookupMomentums =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupMomentums;
|
|
// if (has &&
|
|
// lookupMomentums)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // Rejection Bar ...
|
|
// bool lookupRejections = ArraySize(mBullishRejectionBars) < mMaxRequiredPOIs ||
|
|
// ArraySize(mBearishRejectionBars) < mMaxRequiredPOIs;
|
|
// lookupRejections =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupRejections;
|
|
// if (has &&
|
|
// lookupRejections)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // Support ...
|
|
// bool lookupSupports = ArraySize(mSupportZones) < mMaxRequiredPOIs;
|
|
// lookupSupports =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupSupports;
|
|
// if (has &&
|
|
// lookupSupports)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // Demand ...
|
|
// bool lookupDemands = ArraySize(mDemandZones) < mMaxRequiredPOIs;
|
|
// lookupDemands =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupDemands;
|
|
// if (has &&
|
|
// lookupDemands)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // Resistance ...
|
|
// bool lookupResistance = ArraySize(mResistanceZones) < mMaxRequiredPOIs;
|
|
// lookupResistance =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupResistance;
|
|
// if (has &&
|
|
// lookupResistance)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // Supply ...
|
|
// bool lookupSupplies = ArraySize(mSupplyZones) < mMaxRequiredPOIs;
|
|
// lookupSupplies =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupSupplies;
|
|
// if (has &&
|
|
// lookupSupplies)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // OrderBlock ...
|
|
// bool lookupOrderBlocks = ArraySize(mBullishOrderBlocks) < mMaxRequiredPOIs ||
|
|
// ArraySize(mBearishOrderBlocks) < mMaxRequiredPOIs;
|
|
// lookupOrderBlocks =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupOrderBlocks;
|
|
// if (has &&
|
|
// lookupOrderBlocks)
|
|
// {
|
|
// }
|
|
|
|
// //
|
|
// // FairValueGap ...
|
|
// bool lookupFairValeGaps = ArraySize(mBullishFairValueGaps) < mMaxRequiredPOIs ||
|
|
// ArraySize(mBearishFairValueGaps) < mMaxRequiredPOIs;
|
|
// lookupFairValeGaps =
|
|
// ignoreMaxAllowed
|
|
// ? true
|
|
// : lookupFairValeGaps;
|
|
// if (has &&
|
|
// (lookupFairValeGaps))
|
|
// {
|
|
// }
|
|
|
|
//
|
|
XCBaseObject *stateObjects[];
|
|
int stateObjectsCount = drawer.DrawState(
|
|
decisionState,
|
|
stateObjects,
|
|
false, //
|
|
true, // ignoreSwingHighs
|
|
true, // ignoreSwingLows
|
|
true, // ignoreSupportZones
|
|
true, // ignoreResistanceZones
|
|
true, // ignoreSupplyZones
|
|
true, // ignoreDemandZones
|
|
true, // ignoreBullishOrderBlocks
|
|
true, // ignoreBearishOrderBlocks
|
|
true, // ignoreBullishFairValueGaps
|
|
true, // ignoreBearishFairValueGaps
|
|
true, // ignoreBullishRejectionBars
|
|
true, // ignoreBearishRejectionBars
|
|
true, // ignoreBullishMomentumBars
|
|
true, // ignoreBearishMomentumBars
|
|
false, // ignoreBullishConsolidationZones
|
|
false // ignoreBearishConsolidationZones
|
|
);
|
|
|
|
//
|
|
// Draw ...
|
|
if (hasSelectedConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
selectedConsolidationZone.to = cTime;
|
|
bool isCreated = drawer.CreateConsolidationZone(
|
|
selectedConsolidationZone,
|
|
iObj //
|
|
);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// // Based On Waiting Zones ...
|
|
// has = isBarInited &&
|
|
// hasWorkingZone;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XOBFVG tmpZones[];
|
|
// Copy(
|
|
// workingZone.waitingZones,
|
|
// tmpZones //
|
|
// );
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// XOBFVG iOBFVG;
|
|
|
|
// //
|
|
// idx = GetYoungest(tmpZones);
|
|
// if (!IsValidIndex(idx))
|
|
// {
|
|
// //
|
|
// iOBFVG.Clean();
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// iOBFVG = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// double iTarget =
|
|
// isSelectedZonDirBullish
|
|
// ? iOBFVG.ob.Lower()
|
|
// : iOBFVG.ob.Upper();
|
|
|
|
// //
|
|
// has =
|
|
// isSelectedZonDirBullish
|
|
// ? cBar.high < iTarget
|
|
// : cBar.low > iTarget;
|
|
|
|
// //
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iTarget,
|
|
// targets //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// iOBFVG.Clean();
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// }
|
|
|
|
// //
|
|
// // Based On Breaked Zones ...
|
|
// has = isBarInited &&
|
|
// hasBreakedZones;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XOBFVG tmpZones[];
|
|
// Copy(
|
|
// workingZone.breakedZones,
|
|
// tmpZones //
|
|
// );
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// XOBFVG iOBFVG;
|
|
|
|
// //
|
|
// idx = GetYoungest(tmpZones);
|
|
// if (!IsValidIndex(idx))
|
|
// {
|
|
// //
|
|
// iOBFVG.Clean();
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// iOBFVG = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// double iTarget =
|
|
// isSelectedZonDirBullish
|
|
// ? iOBFVG.ob.Lower()
|
|
// : iOBFVG.ob.Upper();
|
|
|
|
// //
|
|
// has =
|
|
// isSelectedZonDirBullish
|
|
// ? cBar.high < iTarget
|
|
// : cBar.low > iTarget;
|
|
|
|
// //
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iTarget,
|
|
// targets //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// iOBFVG.Clean();
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// }
|
|
|
|
// //
|
|
// // Based On Priority ...
|
|
// if (hasPriority)
|
|
// {
|
|
// //
|
|
// switch (priority)
|
|
// {
|
|
// //
|
|
// case X121SMC_XWZ_PRIORITY_WEAK:
|
|
// //
|
|
// if (isSelectedZonDirBullish)
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.supplyZone.Lower(),
|
|
// targets //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.demandZone.Upper(),
|
|
// targets //
|
|
// );
|
|
// }
|
|
// break;
|
|
|
|
// //
|
|
// case X121SMC_XWZ_PRIORITY_LOW:
|
|
// //
|
|
// if (isSelectedZonDirBullish)
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.supplyZone.Lower(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter1,
|
|
// targets //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.demandZone.Upper(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter3,
|
|
// targets //
|
|
// );
|
|
// }
|
|
// break;
|
|
|
|
// //
|
|
// case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
// //
|
|
// if (isSelectedZonDirBullish)
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.supplyZone.Lower(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter1,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Regular ...
|
|
// Add(
|
|
// workingZone.quarter2,
|
|
// targets //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.demandZone.Upper(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter3,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Regular ...
|
|
// Add(
|
|
// workingZone.quarter2,
|
|
// targets //
|
|
// );
|
|
// }
|
|
// break;
|
|
|
|
// //
|
|
// case X121SMC_XWZ_PRIORITY_HIGH:
|
|
// //
|
|
// if (isSelectedZonDirBullish)
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.supplyZone.Lower(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter1,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Regular ...
|
|
// Add(
|
|
// workingZone.quarter2,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // High ...
|
|
// Add(
|
|
// workingZone.quarter3,
|
|
// targets //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.demandZone.Upper(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter3,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Regular ...
|
|
// Add(
|
|
// workingZone.quarter2,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // High ...
|
|
// Add(
|
|
// workingZone.quarter1,
|
|
// targets //
|
|
// );
|
|
// }
|
|
// break;
|
|
|
|
// //
|
|
// case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
// //
|
|
// if (isSelectedZonDirBullish)
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.supplyZone.Lower(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter1,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Regular ...
|
|
// Add(
|
|
// workingZone.quarter2,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // High ...
|
|
// Add(
|
|
// workingZone.quarter3,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Strong High ...
|
|
// Add(
|
|
// workingZone.demandZone.Upper(),
|
|
// targets //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Weak ...
|
|
// Add(
|
|
// workingZone.demandZone.Upper(),
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Low ...
|
|
// Add(
|
|
// workingZone.quarter3,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Regular ...
|
|
// Add(
|
|
// workingZone.quarter2,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // High ...
|
|
// Add(
|
|
// workingZone.quarter1,
|
|
// targets //
|
|
// );
|
|
|
|
// //
|
|
// // Strong High ...
|
|
// Add(
|
|
// workingZone.supplyZone.Lower(),
|
|
// targets //
|
|
// );
|
|
// }
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Based On Consolidation Zones ...
|
|
has = isBarInited &&
|
|
decisionState.HasConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XConsolidationZone tmpZones[];
|
|
if (isSelectedZonDirBullish)
|
|
{
|
|
//
|
|
Copy(
|
|
decisionState.bullishConsolidationZones,
|
|
tmpZones //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
Copy(
|
|
decisionState.bearishConsolidationZones,
|
|
tmpZones //
|
|
);
|
|
}
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XConsolidationZone iZone = tmpZones[idx];
|
|
|
|
//
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
hasSelectedConsolidationZone =
|
|
isSelectedZonDirBullish
|
|
? cBar.low < iZone.upper
|
|
: cBar.high < iZone.lower;
|
|
if (hasSelectedConsolidationZone)
|
|
{
|
|
//
|
|
selectedConsolidationZone = iZone;
|
|
iZone.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iZone.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
|
|
//
|
|
if (hasSelectedConsolidationZone)
|
|
{
|
|
//
|
|
XCConsolidationZoneObject *iObj;
|
|
selectedConsolidationZone.to = cTime;
|
|
bool isCreated = drawer.CreateConsolidationZone(
|
|
selectedConsolidationZone,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
double iSL =
|
|
isSelectedZonDirBullish
|
|
? selectedConsolidationZone.lower
|
|
: selectedConsolidationZone.upper;
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Based On Supply and Demand Zones ...
|
|
|
|
//
|
|
// Demand Zones ...
|
|
has = hasWorkingZone &&
|
|
workingZone.HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCDemandZone *tmpZones[];
|
|
Copy(
|
|
workingZone.demandZones,
|
|
tmpZones //
|
|
);
|
|
XCDemandZone *selectedDemand = NULL;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetLowest(tmpZones);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XCDemandZone *iZone = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Zone ...
|
|
has =
|
|
isSelectedZonDirBullish
|
|
? IsBelowDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsAboveDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
has =
|
|
selectedDemand == NULL
|
|
? true
|
|
: isSelectedZonDirBullish
|
|
? selectedDemand.Lower() < iZone.Lower()
|
|
: selectedDemand.Upper() > iZone.Upper();
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
selectedDemand = iZone;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
has = selectedDemand != NULL;
|
|
if (has)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iObj;
|
|
bool isCreated = drawer.CreateDemandZone(
|
|
selectedDemand,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
double iSL =
|
|
isSelectedZonDirBullish
|
|
? selectedDemand.Lower()
|
|
: selectedDemand.Upper();
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
ZeroMemory(selectedDemand);
|
|
}
|
|
|
|
//
|
|
// Support Zones ...
|
|
has = hasWorkingZone &&
|
|
workingZone.HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupportZone *tmpZones[];
|
|
Copy(
|
|
workingZone.supportZones,
|
|
tmpZones //
|
|
);
|
|
XCSupportZone *selectedSupport = NULL;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetLowest(tmpZones);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XCSupportZone *iZone = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Zone ...
|
|
has =
|
|
isSelectedZonDirBullish
|
|
? IsBelowDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsAboveDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
has =
|
|
selectedSupport == NULL
|
|
? true
|
|
: isSelectedZonDirBullish
|
|
? selectedSupport.Lower() < iZone.Lower()
|
|
: selectedSupport.Upper() > iZone.Upper();
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
selectedSupport = iZone;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
has = selectedSupport != NULL;
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupportZoneObject *iObj;
|
|
bool isCreated = drawer.CreateSupportZone(
|
|
selectedSupport,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
double iSL = isSelectedZonDirBullish
|
|
? selectedSupport.Lower()
|
|
: selectedSupport.Upper();
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
ZeroMemory(selectedSupport);
|
|
}
|
|
|
|
//
|
|
// Supply Zones ...
|
|
has = hasWorkingZone &&
|
|
workingZone.HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupplyZone *tmpZones[];
|
|
Copy(
|
|
workingZone.supplyZones,
|
|
tmpZones //
|
|
);
|
|
XCSupplyZone *selectedSupply = NULL;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetHighest(tmpZones);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XCSupplyZone *iZone = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Zone ...
|
|
has =
|
|
!isSelectedZonDirBullish
|
|
? IsAboveDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsBelowDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
has =
|
|
selectedSupply == NULL
|
|
? true
|
|
: !isSelectedZonDirBullish
|
|
? selectedSupply.Upper() > iZone.Upper()
|
|
: selectedSupply.Lower() < iZone.Lower();
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
selectedSupply = iZone;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
has = selectedSupply != NULL;
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *iObj;
|
|
bool isCreated = drawer.CreateSupplyZone(
|
|
selectedSupply,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
double iSL =
|
|
!isSelectedZonDirBullish
|
|
? selectedSupply.Upper()
|
|
: selectedSupply.Lower();
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
ZeroMemory(selectedSupply);
|
|
}
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
has = hasWorkingZone &&
|
|
workingZone.HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCResistanceZone *tmpZones[];
|
|
Copy(
|
|
workingZone.resistanceZones,
|
|
tmpZones //
|
|
);
|
|
XCResistanceZone *selectedResistance = NULL;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetHighest(tmpZones);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XCResistanceZone *iZone = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Zone ...
|
|
has =
|
|
!isSelectedZonDirBullish
|
|
? IsAboveDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsBelowDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
has =
|
|
selectedResistance == NULL
|
|
? true
|
|
: !isSelectedZonDirBullish
|
|
? selectedResistance.Upper() < iZone.Upper()
|
|
: selectedResistance.Lower() > iZone.Lower();
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
selectedResistance = iZone;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
has = selectedResistance != NULL;
|
|
if (has)
|
|
{
|
|
//
|
|
XCResistanceZoneObject *iObj;
|
|
bool isCreated = drawer.CreateResistanceZone(
|
|
selectedResistance,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
double iSL =
|
|
!isSelectedZonDirBullish
|
|
? selectedResistance.Upper()
|
|
: selectedResistance.Lower();
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
ZeroMemory(selectedResistance);
|
|
}
|
|
|
|
//
|
|
// Based On Passed Bars ...
|
|
XOHCL passedBar;
|
|
bool isPassed = false;
|
|
bool isBodyState = false;
|
|
ENUM_X_DIRECTION passedDir = selectedZone.GetDirection();
|
|
|
|
//
|
|
// Started Bar ...
|
|
isPassed = selectedZone.ob.IsStarted(
|
|
passedDir,
|
|
passedBar,
|
|
isBodyState //
|
|
);
|
|
if (isPassed)
|
|
{
|
|
//
|
|
double iSL =
|
|
isSelectedZonDirBullish
|
|
? passedBar.low
|
|
: passedBar.high;
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Activation Bar ...
|
|
passedBar.Clean();
|
|
isPassed = selectedZone.ob.IsActivated(
|
|
passedDir,
|
|
passedBar,
|
|
isBodyState //
|
|
);
|
|
if (isPassed)
|
|
{
|
|
//
|
|
double iSL =
|
|
isSelectedZonDirBullish
|
|
? passedBar.low
|
|
: passedBar.high;
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Worked Bar ...
|
|
passedBar.Clean();
|
|
isPassed = selectedZone.ob.IsActivated(
|
|
passedDir,
|
|
passedBar,
|
|
isBodyState //
|
|
);
|
|
if (isPassed)
|
|
{
|
|
//
|
|
double iSL =
|
|
isSelectedZonDirBullish
|
|
? passedBar.low
|
|
: passedBar.high;
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Breaked Bar ...
|
|
passedBar.Clean();
|
|
isPassed = selectedZone.ob.IsActivated(
|
|
passedDir,
|
|
passedBar,
|
|
isBodyState //
|
|
);
|
|
if (isPassed)
|
|
{
|
|
//
|
|
double iSL =
|
|
isSelectedZonDirBullish
|
|
? passedBar.low
|
|
: passedBar.high;
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// // Trail Stops Using Swings ...
|
|
|
|
// //
|
|
// bool canTrailLongUsingSwings =
|
|
// //
|
|
// isLong &&
|
|
// isInProfit &&
|
|
// (isSwingLow ||
|
|
// isStrongSwingLow) &&
|
|
// pBar.low > iPosition.sl &&
|
|
// pBar.low > iPosition.entry
|
|
// //
|
|
// ;
|
|
// if (canTrailLongUsingSwings)
|
|
// {
|
|
// sl = pBar.low;
|
|
// }
|
|
|
|
// //
|
|
// bool canTraiShortlUsingSwings =
|
|
// //
|
|
// !isLong &&
|
|
// isInProfit &&
|
|
// (isSwingHigh ||
|
|
// isStrongSwingHigh) &&
|
|
// pBar.high < iPosition.sl &&
|
|
// pBar.high < iPosition.entry
|
|
// //
|
|
// ;
|
|
// if (canTraiShortlUsingSwings)
|
|
// {
|
|
// sl = pBar.high;
|
|
// }
|
|
|
|
// //
|
|
// bool canTrailUsingSwings =
|
|
// canTrailLongUsingSwings ||
|
|
// canTraiShortlUsingSwings;
|
|
|
|
// //
|
|
// //
|
|
// //
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// XOHCL zBar;
|
|
// result = zBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// zIndex //
|
|
// );
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// result = HasChild(guards);
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// XOHCL cBar;
|
|
// result = cBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// cIndex //
|
|
// );
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// zBar.Clean();
|
|
// result = HasChild(guards);
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// XOHCL pBar;
|
|
// result = pBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// pIndex //
|
|
// );
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// zBar.Clean();
|
|
// cBar.Clean();
|
|
// result = HasChild(guards);
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// XOHCL ppBar;
|
|
// result = ppBar.Init(
|
|
// symbol,
|
|
// period,
|
|
// ppIndex //
|
|
// );
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// zBar.Clean();
|
|
// cBar.Clean();
|
|
// pBar.Clean();
|
|
// result = HasChild(guards);
|
|
// return result;
|
|
// }
|
|
|
|
//
|
|
// zBar.Clean();
|
|
// cBar.Clean();
|
|
// pBar.Clean();
|
|
// ppBar.Clean();
|
|
|
|
//
|
|
// Detect High Probability Swings ...
|
|
// bool isSwingLow =
|
|
// //
|
|
// cBar.low > pBar.low &&
|
|
// ppBar.low > pBar.low &&
|
|
// //
|
|
// zBar.low > pBar.low
|
|
// //
|
|
// ;
|
|
// bool isSwingHigh =
|
|
// //
|
|
// cBar.high < pBar.high &&
|
|
// ppBar.high < pBar.high &&
|
|
// //
|
|
// zBar.high < pBar.high
|
|
// //
|
|
// ;
|
|
// bool isStrongSwingLow =
|
|
// pBar.IsBullish() &&
|
|
// pBar.GetLowShadow() >= pBar.GetBody() * 2;
|
|
// bool isStrongSwingHigh =
|
|
// pBar.IsBearish() &&
|
|
// pBar.GetHighShadow() >= pBar.GetBody() * 2;
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
bool DetectX121Conditions(
|
|
double &pivot,
|
|
double &point,
|
|
double &sls[],
|
|
double &targets[],
|
|
ENUM_X_DIRECTION &dir,
|
|
XPOIState &stfState,
|
|
XPOIState &ttfState,
|
|
X121Conditions &conditions,
|
|
XCPOIDrawer *drawer = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool canDraw = drawer != NULL;
|
|
|
|
//
|
|
pivot = 0;
|
|
point = 0;
|
|
Clean(sls);
|
|
Clean(targets);
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
result =
|
|
stfState.IsValid() &&
|
|
ttfState.IsValid() &&
|
|
stfState.HasChild() &&
|
|
ttfState.HasChild();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
// Detect Inside STF Order Blocks Zones ...
|
|
|
|
//
|
|
XOBFVG tmpWaitingZones[];
|
|
count = ExtractOBFVGs(
|
|
tmpWaitingZones,
|
|
stfState,
|
|
ttfState //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
if (canDraw)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XOBFVG iOBFVG = tmpWaitingZones[i];
|
|
|
|
//
|
|
iOBFVG.UpdateTo();
|
|
|
|
//
|
|
XCBaseObject *iOBFVGObjects[];
|
|
int iOBFVGObjectsCount = drawer.DrawOBFVG(
|
|
iOBFVG,
|
|
iOBFVGObjects //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Check an XOBFVG instance has Required Conditions ...
|
|
*
|
|
* @param zone: XBoxZone instance ...
|
|
* @param state: XPOIState instance ...
|
|
* @param conditions: X121Conditions instance ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedBoxConditions(
|
|
bool &isReversal,
|
|
XBoxZone &zone,
|
|
XPOIState &state,
|
|
X121Conditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
isReversal = false;
|
|
|
|
//
|
|
result =
|
|
zone.IsValid() &&
|
|
state.IsValid() &&
|
|
state.HasChild();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = zone.IsBullish();
|
|
bool isBearish = zone.IsBearish();
|
|
|
|
//
|
|
bool isBullishTrend = conditions.isTrendBullish ||
|
|
conditions.isTrendSwitchedToBullish;
|
|
bool isBearishTrend = conditions.isTrendBearish ||
|
|
conditions.isTrendSwitchedToBearish;
|
|
|
|
//
|
|
double bullishScore = 0;
|
|
double bearishScore = 0;
|
|
double scoreMultiplier = 1.5;
|
|
conditions.GenerateScore(
|
|
bullishScore,
|
|
bearishScore //
|
|
);
|
|
|
|
//
|
|
bool isBullishScorePassed = bullishScore > 0 &&
|
|
bearishScore >= 0 &&
|
|
bullishScore > bearishScore * scoreMultiplier;
|
|
|
|
//
|
|
bool isBearishScorePassed = bearishScore > 0 &&
|
|
bullishScore >= 0 &&
|
|
bearishScore > bullishScore * scoreMultiplier;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
double vwapFast = conditions.vwapFastBuffer[0];
|
|
double vwapMid = conditions.vwapMidBuffer[0];
|
|
double vwapSlow = conditions.vwapSlowBuffer[0];
|
|
|
|
//
|
|
bool isVWapInside =
|
|
//
|
|
vwapFast > zone.lower &&
|
|
vwapFast < zone.upper
|
|
//
|
|
&&
|
|
vwapMid > zone.lower &&
|
|
vwapMid < zone.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapBullish =
|
|
//
|
|
(conditions.isVWapBullishState &&
|
|
conditions.isVWapSwitchedToBullishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isVWapBullishOrdered &&
|
|
conditions.isVWapSwitchedToBullishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapBearish =
|
|
//
|
|
(conditions.isVWapBearishState &&
|
|
conditions.isVWapSwitchedToBearishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isVWapBearishOrdered &&
|
|
conditions.isVWapSwitchedToBearishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
// X3Ma ...
|
|
|
|
//
|
|
double x3maFast = conditions.x3maFastBuffer[0];
|
|
double x3maMid = conditions.x3maMidBuffer[0];
|
|
double x3maSlow = conditions.x3maSlowBuffer[0];
|
|
|
|
//
|
|
bool isX3MaInside =
|
|
//
|
|
x3maFast > zone.lower &&
|
|
x3maFast < zone.upper
|
|
//
|
|
&&
|
|
x3maMid > zone.lower &&
|
|
x3maMid < zone.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isX3MaBullish =
|
|
//
|
|
(conditions.isX3MaBullishState &&
|
|
conditions.isX3MaSwitchedToBullishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isX3MaBullishOrdered &&
|
|
conditions.isX3MaSwitchedToBullishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isX3MaBearish =
|
|
//
|
|
(conditions.isX3MaBearishState &&
|
|
conditions.isX3MaSwitchedToBearishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isX3MaBearishOrdered &&
|
|
conditions.isX3MaSwitchedToBearishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isInside =
|
|
//
|
|
isVWapInside ||
|
|
isX3MaInside
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWap3MaBullish =
|
|
isVWapBullish ||
|
|
isX3MaBullish;
|
|
|
|
//
|
|
bool isVWap3MaBearish =
|
|
isVWapBearish ||
|
|
isX3MaBearish;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isDirectionalBullishPassed =
|
|
//
|
|
isInside &&
|
|
isBullish &&
|
|
isBullishTrend &&
|
|
isVWap3MaBullish &&
|
|
isBullishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDirectionalBearishPassed =
|
|
//
|
|
isInside &&
|
|
isBearish &&
|
|
isBearishTrend &&
|
|
isVWap3MaBearish &&
|
|
isBearishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDirectionalPassed =
|
|
isDirectionalBullishPassed ||
|
|
isDirectionalBearishPassed;
|
|
|
|
//
|
|
bool isReversalBullishPassed =
|
|
//
|
|
isInside &&
|
|
isBullish &&
|
|
isBearishTrend &&
|
|
isVWap3MaBearish &&
|
|
isBearishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isReversalBearishPassed =
|
|
//
|
|
isInside &&
|
|
isBearish &&
|
|
isBullishTrend &&
|
|
isVWap3MaBullish &&
|
|
isBullishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isReversalPassed = isReversalBullishPassed ||
|
|
isReversalBearishPassed;
|
|
|
|
//
|
|
result = isReversalPassed ||
|
|
isDirectionalPassed;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
isReversal = isReversalPassed;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// if (hasWaitingZones)
|
|
// {
|
|
// //
|
|
// int idx = -1;
|
|
// int count = 0;
|
|
// XOBFVG youngest;
|
|
// bool has = false;
|
|
// XCFVG *selectedFVG;
|
|
// XCFVG *unActivatedFVGs[];
|
|
|
|
// //
|
|
// idx = GetYoungest(workingZone.waitingZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// youngest = workingZone.waitingZones[idx];
|
|
// selectedZoneDir = youngest.GetDirection();
|
|
|
|
// //
|
|
// if (IsBullish(selectedZoneDir))
|
|
// {
|
|
// //
|
|
// Copy(
|
|
// analyseState.bullishFairValueGaps,
|
|
// unActivatedFVGs //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// Copy(
|
|
// analyseState.bearishFairValueGaps,
|
|
// unActivatedFVGs //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// count = ArraySize(unActivatedFVGs);
|
|
// has = IsValidSize(count);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// idx = GetYoungest(unActivatedFVGs);
|
|
// has = IsValidIndex(idx);
|
|
// if (has)
|
|
// {
|
|
// selectedFVG = unActivatedFVGs[idx];
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// has = selectedFVG != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCBaseObject *iObj;
|
|
// bool isCreated = drawer.CreateFairValueGap(
|
|
// selectedFVG,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// Print("Salam");
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Check an XOBFVG instance has Required Conditions ...
|
|
*
|
|
* @param zone: XOBFVG instance ...
|
|
* @param state: XPOIState instance ...
|
|
* @param conditions: X121Conditions instance ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectInsideSelectedZoneConditions(
|
|
bool &isReversal,
|
|
XOBFVG &zone,
|
|
XPOIState &state,
|
|
X121Conditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
isReversal = false;
|
|
|
|
//
|
|
result =
|
|
zone.IsValid() &&
|
|
state.IsValid() &&
|
|
state.HasChild();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = zone.IsBullish();
|
|
bool isBearish = zone.IsBearish();
|
|
|
|
//
|
|
bool isBullishTrend = conditions.isTrendBullish ||
|
|
conditions.isTrendSwitchedToBullish;
|
|
bool isBearishTrend = conditions.isTrendBearish ||
|
|
conditions.isTrendSwitchedToBearish;
|
|
|
|
//
|
|
double bullishScore = 0;
|
|
double bearishScore = 0;
|
|
double scoreMultiplier = 1.5;
|
|
conditions.GenerateScore(
|
|
bullishScore,
|
|
bearishScore //
|
|
);
|
|
|
|
//
|
|
bool isBullishScorePassed = bullishScore > 0 &&
|
|
bearishScore >= 0 &&
|
|
bullishScore > bearishScore * scoreMultiplier;
|
|
|
|
//
|
|
bool isBearishScorePassed = bearishScore > 0 &&
|
|
bullishScore >= 0 &&
|
|
bearishScore > bullishScore * scoreMultiplier;
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
double vwapFast = conditions.vwapFastBuffer[0];
|
|
double vwapMid = conditions.vwapMidBuffer[0];
|
|
double vwapSlow = conditions.vwapSlowBuffer[0];
|
|
|
|
//
|
|
bool isVWapInside =
|
|
//
|
|
vwapFast > zone.ob.Lower() &&
|
|
vwapFast < zone.ob.Upper()
|
|
//
|
|
&&
|
|
vwapMid > zone.ob.Lower() &&
|
|
vwapMid < zone.ob.Upper()
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapBullish =
|
|
//
|
|
(conditions.isVWapBullishState &&
|
|
conditions.isVWapSwitchedToBullishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isVWapBullishOrdered &&
|
|
conditions.isVWapSwitchedToBullishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapBearish =
|
|
//
|
|
(conditions.isVWapBearishState &&
|
|
conditions.isVWapSwitchedToBearishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isVWapBearishOrdered &&
|
|
conditions.isVWapSwitchedToBearishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
// X3Ma ...
|
|
|
|
//
|
|
double x3maFast = conditions.x3maFastBuffer[0];
|
|
double x3maMid = conditions.x3maMidBuffer[0];
|
|
double x3maSlow = conditions.x3maSlowBuffer[0];
|
|
|
|
//
|
|
bool isX3MaInside =
|
|
//
|
|
x3maFast > zone.ob.Lower() &&
|
|
x3maFast < zone.ob.Upper()
|
|
//
|
|
&&
|
|
x3maMid > zone.ob.Lower() &&
|
|
x3maMid < zone.ob.Upper()
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isX3MaBullish =
|
|
//
|
|
(conditions.isX3MaBullishState &&
|
|
conditions.isX3MaSwitchedToBullishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isX3MaBullishOrdered &&
|
|
conditions.isX3MaSwitchedToBullishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isX3MaBearish =
|
|
//
|
|
(conditions.isX3MaBearishState &&
|
|
conditions.isX3MaSwitchedToBearishOrdered)
|
|
//
|
|
||
|
|
//
|
|
(conditions.isX3MaBearishOrdered &&
|
|
conditions.isX3MaSwitchedToBearishState)
|
|
//
|
|
;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isInside =
|
|
//
|
|
isVWapInside ||
|
|
isX3MaInside
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWap3MaBullish =
|
|
isVWapBullish ||
|
|
isX3MaBullish;
|
|
|
|
//
|
|
bool isVWap3MaBearish =
|
|
isVWapBearish ||
|
|
isX3MaBearish;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool isDirectionalBullishPassed =
|
|
//
|
|
isInside &&
|
|
isBullish &&
|
|
isBullishTrend &&
|
|
isVWap3MaBullish &&
|
|
isBullishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDirectionalBearishPassed =
|
|
//
|
|
isInside &&
|
|
isBearish &&
|
|
isBearishTrend &&
|
|
isVWap3MaBearish &&
|
|
isBearishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDirectionalPassed =
|
|
isDirectionalBullishPassed ||
|
|
isDirectionalBearishPassed;
|
|
|
|
//
|
|
bool isReversalBullishPassed =
|
|
//
|
|
isInside &&
|
|
isBullish &&
|
|
isBearishTrend &&
|
|
isVWap3MaBearish &&
|
|
isBearishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isReversalBearishPassed =
|
|
//
|
|
isInside &&
|
|
isBearish &&
|
|
isBullishTrend &&
|
|
isVWap3MaBullish &&
|
|
isBullishScorePassed
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isReversalPassed = isReversalBullishPassed ||
|
|
isReversalBearishPassed;
|
|
|
|
//
|
|
result = isReversalPassed ||
|
|
isDirectionalPassed;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
isReversal = isReversalPassed;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool DetectBreakedSelectedZoneConditions(
|
|
bool &isReversal,
|
|
XOBFVG &zone,
|
|
XPOIState &mtfState,
|
|
XPOIState &stfState,
|
|
XPOIState &ttfState,
|
|
X121Conditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
isReversal = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
zone.IsValid() &&
|
|
mtfState.IsValid() &&
|
|
stfState.IsValid() &&
|
|
ttfState.IsValid() &&
|
|
mtfState.HasChild() &&
|
|
stfState.HasChild() &&
|
|
ttfState.HasChild()
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
result = ToBox(
|
|
iBox,
|
|
zone.ob //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION iDir = iBox.dir;
|
|
bool isBullish = IsBullish(iDir);
|
|
bool isBearish = IsBearish(iDir);
|
|
|
|
//
|
|
// X3Ma ...
|
|
|
|
//
|
|
double x3maFast = conditions.x3maFastBuffer[0];
|
|
double x3maMid = conditions.x3maMidBuffer[0];
|
|
double x3maSlow = conditions.x3maSlowBuffer[0];
|
|
|
|
//
|
|
bool isX3mInside =
|
|
//
|
|
(x3maFast < iBox.upper &&
|
|
x3maMid < iBox.upper &&
|
|
x3maSlow < iBox.upper)
|
|
//
|
|
&&
|
|
//
|
|
(x3maFast > iBox.lower &&
|
|
x3maMid > iBox.lower &&
|
|
x3maSlow > iBox.lower)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBullishConditions =
|
|
isBullish &&
|
|
isX3mInside;
|
|
|
|
//
|
|
bool isBearishConditions =
|
|
isBearish &&
|
|
isX3mInside;
|
|
|
|
//
|
|
result = isBullishConditions ||
|
|
isBearishConditions;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect Targets Based on Selected Zone for Specified type of Directions ...
|
|
*
|
|
* @param targets: double Collection ...
|
|
* @param selectedZone: XOBFVG instance, selected Zone ...
|
|
* @param forDir: ENUM_X_DIRECTION specified Position Direction ...
|
|
* @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ...
|
|
* @param barIndex: int Specified Bar Index ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedZonesTargets(
|
|
double &targets[],
|
|
XOBFVG &selectedZone,
|
|
ENUM_X_DIRECTION forDir,
|
|
ENUM_X121SMC_XWZ_PRIORITY forPriority,
|
|
X121SMCStrategyXWZWorkingZone &workingZone,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(targets);
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
selectedZone.IsValid() &&
|
|
HasDirection(forDir) &&
|
|
workingZone.IsValid() &&
|
|
forPriority != X121SMC_XWZ_PRIORITY_NONE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
workingZone.symbol,
|
|
workingZone.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
XOBFVG tmpZones[];
|
|
|
|
//
|
|
// Based On Waiting Zones ...
|
|
has = workingZone.HasWaitingZones();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
workingZone.waitingZones,
|
|
tmpZones //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
double iTarget =
|
|
isBullish
|
|
? iOBFVG.ob.Lower()
|
|
: iOBFVG.ob.Upper();
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? cBar.high < iTarget
|
|
: cBar.low > iTarget;
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
}
|
|
|
|
//
|
|
// Based On Breaked Zones ...
|
|
has = workingZone.HasBreakedZones();
|
|
if (has)
|
|
{
|
|
Copy(
|
|
workingZone.breakedZones,
|
|
tmpZones //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
double iTarget =
|
|
isBullish
|
|
? iOBFVG.ob.Lower()
|
|
: iOBFVG.ob.Upper();
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? cBar.high < iTarget
|
|
: cBar.low > iTarget;
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
}
|
|
|
|
//
|
|
// Based On Priority ...
|
|
has = forPriority != X121SMC_XWZ_PRIORITY_NONE;
|
|
if (has)
|
|
{
|
|
//
|
|
switch (forPriority)
|
|
{
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_WEAK:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_LOW:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = HasChild(targets);
|
|
|
|
//
|
|
// Cleanup ...
|
|
cBar.Clean();
|
|
Clean(tmpZones);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect Targets Based on Selected Zone for Specified type of Directions ...
|
|
*
|
|
* @param targets: double Collection ...
|
|
* @param selectedZone: XBoxZone instance, selected Zone ...
|
|
* @param forDir: ENUM_X_DIRECTION specified Position Direction ...
|
|
* @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ...
|
|
* @param barIndex: int Specified Bar Index ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedZonesTargets(
|
|
double &targets[],
|
|
XBoxZone &selectedZone,
|
|
ENUM_X_DIRECTION forDir,
|
|
ENUM_X121SMC_XWZ_PRIORITY forPriority,
|
|
X121SMCStrategyXWZWorkingZone &workingZone,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(targets);
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
selectedZone.IsValid() &&
|
|
HasDirection(forDir) &&
|
|
workingZone.IsValid() &&
|
|
forPriority != X121SMC_XWZ_PRIORITY_NONE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
workingZone.symbol,
|
|
workingZone.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
XOBFVG tmpZones[];
|
|
|
|
//
|
|
// Based On Waiting Zones ...
|
|
has = workingZone.HasWaitingZones();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
workingZone.waitingZones,
|
|
tmpZones //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
double iTarget =
|
|
isBullish
|
|
? iOBFVG.ob.Lower()
|
|
: iOBFVG.ob.Upper();
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? cBar.high < iTarget
|
|
: cBar.low > iTarget;
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
}
|
|
|
|
//
|
|
// Based On Breaked Zones ...
|
|
has = workingZone.HasBreakedZones();
|
|
if (has)
|
|
{
|
|
Copy(
|
|
workingZone.breakedZones,
|
|
tmpZones //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
double iTarget =
|
|
isBullish
|
|
? iOBFVG.ob.Lower()
|
|
: iOBFVG.ob.Upper();
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? cBar.high < iTarget
|
|
: cBar.low > iTarget;
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
}
|
|
|
|
//
|
|
// Based On Priority ...
|
|
has = forPriority != X121SMC_XWZ_PRIORITY_NONE;
|
|
if (has)
|
|
{
|
|
//
|
|
switch (forPriority)
|
|
{
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_WEAK:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_LOW:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = HasChild(targets);
|
|
|
|
//
|
|
// Cleanup ...
|
|
cBar.Clean();
|
|
Clean(tmpZones);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect SL Candidates Based on Selected Zone for Specified type of Directions ...
|
|
*
|
|
* @param sls: double Collection ...
|
|
* @param selectedZone: XOBFVG instance, selected Zone ...
|
|
* @param forDir: ENUM_X_DIRECTION specified Position Direction ...
|
|
* @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ...
|
|
* @param barIndex: int Specified Bar Index ...
|
|
* @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedZoneSLCandidates(
|
|
double &sls[],
|
|
XOBFVG &selectedZone,
|
|
ENUM_X_DIRECTION forDir,
|
|
X121SMCStrategyXWZWorkingZone &workingZone,
|
|
X121Conditions &conditions,
|
|
int barIndex = 0,
|
|
double maxAllowedSLDistanceInPoint = 300 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(sls);
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
selectedZone.IsValid() &&
|
|
HasDirection(forDir) &&
|
|
workingZone.IsValid()
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
double pivot =
|
|
isBullish
|
|
? selectedZone.ob.Lower()
|
|
: selectedZone.ob.Upper();
|
|
double points = GetPoints(workingZone.symbol);
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
workingZone.symbol,
|
|
workingZone.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
//
|
|
double pvSL = isBullish
|
|
? conditions.valesBuffer[0]
|
|
: conditions.peaksBuffer[1];
|
|
|
|
//
|
|
Add(
|
|
pvSL,
|
|
sls //
|
|
);
|
|
|
|
//
|
|
// Based On Passed Bars ...
|
|
// XOHCL passedBar;
|
|
// bool isPassed = false;
|
|
// bool isBodyState = false;
|
|
// ENUM_X_DIRECTION passedDir = selectedZone.GetDirection();
|
|
|
|
// //
|
|
// // Started Bar ...
|
|
// isPassed = selectedZone.ob.IsStarted(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Activation Bar ...
|
|
// passedBar.Clean();
|
|
// isPassed = selectedZone.ob.IsActivated(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Worked Bar ...
|
|
// passedBar.Clean();
|
|
// isPassed = selectedZone.ob.IsActivated(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Breaked Bar ...
|
|
// passedBar.Clean();
|
|
// isPassed = selectedZone.ob.IsActivated(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
//
|
|
// Based On Consolidation Zones ...
|
|
has = workingZone.HasConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XConsolidationZone tmpZones[];
|
|
Copy(
|
|
workingZone.consolidationZones,
|
|
tmpZones //
|
|
);
|
|
XConsolidationZone selectedConsolidationZone;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XConsolidationZone iZone = tmpZones[idx];
|
|
|
|
//
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
has =
|
|
!selectedConsolidationZone.IsValid()
|
|
? isBullish
|
|
? cBar.low < iZone.upper
|
|
: cBar.high < iZone.lower
|
|
: isBullish
|
|
? selectedConsolidationZone.lower < iZone.lower
|
|
: selectedConsolidationZone.upper > iZone.upper;
|
|
if (has)
|
|
{
|
|
//
|
|
selectedConsolidationZone = iZone;
|
|
iZone.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iZone.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
has = selectedConsolidationZone.IsValid();
|
|
if (has)
|
|
{
|
|
//
|
|
double iSL =
|
|
isBullish
|
|
? selectedConsolidationZone.lower
|
|
: selectedConsolidationZone.upper;
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Based On Supply and Demand Zones ...
|
|
|
|
//
|
|
// Demand Zones ...
|
|
has = workingZone.HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCDemandZone *tmpZones[];
|
|
Copy(
|
|
workingZone.demandZones,
|
|
tmpZones //
|
|
);
|
|
XCDemandZone *selectedDemand = NULL;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetLowest(tmpZones);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XCDemandZone *iZone = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Zone ...
|
|
has =
|
|
isBullish
|
|
? IsBelowDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsAboveDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
has =
|
|
selectedDemand == NULL
|
|
? true
|
|
: isBullish
|
|
? selectedDemand.Lower() < iZone.Lower()
|
|
: selectedDemand.Upper() > iZone.Upper();
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
selectedDemand = iZone;
|
|
}
|
|
|
|
//
|
|
has = selectedDemand != NULL;
|
|
if (has)
|
|
{
|
|
//
|
|
double iSL =
|
|
isBullish
|
|
? selectedDemand.Lower()
|
|
: selectedDemand.Upper();
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
ZeroMemory(selectedDemand);
|
|
}
|
|
|
|
//
|
|
// Support Zones ...
|
|
// has = workingZone.HasSupportZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCSupportZone *tmpZones[];
|
|
// Copy(
|
|
// workingZone.supportZones,
|
|
// tmpZones //
|
|
// );
|
|
// XCSupportZone *selectedSupport = NULL;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetLowest(tmpZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XCSupportZone *iZone = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// // Validate Zone ...
|
|
// has =
|
|
// isBullish
|
|
// ? IsBelowDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// )
|
|
// : IsAboveDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// );
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// has =
|
|
// selectedSupport == NULL
|
|
// ? true
|
|
// : isBullish
|
|
// ? selectedSupport.Lower() < iZone.Lower()
|
|
// : selectedSupport.Upper() > iZone.Upper();
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// selectedSupport = iZone;
|
|
|
|
// //
|
|
// }
|
|
|
|
// //
|
|
// has = selectedSupport != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL = isBullish
|
|
// ? selectedSupport.Lower()
|
|
// : selectedSupport.Upper();
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// ZeroMemory(selectedSupport);
|
|
// }
|
|
|
|
//
|
|
// Supply Zones ...
|
|
has = workingZone.HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupplyZone *tmpZones[];
|
|
Copy(
|
|
workingZone.supplyZones,
|
|
tmpZones //
|
|
);
|
|
XCSupplyZone *selectedSupply = NULL;
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
idx = GetHighest(tmpZones);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
XCSupplyZone *iZone = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
// Validate Zone ...
|
|
has =
|
|
!isBullish
|
|
? IsAboveDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
)
|
|
: IsBelowDiff(
|
|
iZone,
|
|
selectedZone.ob,
|
|
true // Ignore Inside ...
|
|
);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
has =
|
|
selectedSupply == NULL
|
|
? true
|
|
: !isBullish
|
|
? selectedSupply.Upper() > iZone.Upper()
|
|
: selectedSupply.Lower() < iZone.Lower();
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
selectedSupply = iZone;
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
has = selectedSupply != NULL;
|
|
if (has)
|
|
{
|
|
//
|
|
double iSL =
|
|
!isBullish
|
|
? selectedSupply.Upper()
|
|
: selectedSupply.Lower();
|
|
double iSLDiff = MathAbs(iSL - pivot);
|
|
has =
|
|
iSLDiff > 0 &&
|
|
iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iSL,
|
|
sls //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
ZeroMemory(selectedSupply);
|
|
}
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
// has = workingZone.HasDemandZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCResistanceZone *tmpZones[];
|
|
// Copy(
|
|
// workingZone.resistanceZones,
|
|
// tmpZones //
|
|
// );
|
|
// XCResistanceZone *selectedResistance = NULL;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetHighest(tmpZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XCResistanceZone *iZone = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// // Validate Zone ...
|
|
// has =
|
|
// !isBullish
|
|
// ? IsAboveDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// )
|
|
// : IsBelowDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// );
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// has =
|
|
// selectedResistance == NULL
|
|
// ? true
|
|
// : !isBullish
|
|
// ? selectedResistance.Upper() < iZone.Upper()
|
|
// : selectedResistance.Lower() > iZone.Lower();
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// selectedResistance = iZone;
|
|
|
|
// //
|
|
// }
|
|
|
|
// //
|
|
// has = selectedResistance != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// !isBullish
|
|
// ? selectedResistance.Upper()
|
|
// : selectedResistance.Lower();
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// ZeroMemory(selectedResistance);
|
|
// }
|
|
|
|
//
|
|
// Cleanp Resources ...
|
|
|
|
//
|
|
cBar.Clean();
|
|
// passedBar.Clean();
|
|
result = HasChild(sls);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Detect Targets Based on Selected Zone for Specified type of Directions ...
|
|
*
|
|
* @param targets: double Collection ...
|
|
* @param selectedZone: XBoxZone instance, selected Zone ...
|
|
* @param forDir: ENUM_X_DIRECTION specified Position Direction ...
|
|
* @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ...
|
|
* @param barIndex: int Specified Bar Index ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedZonesTargets(
|
|
double &targets[],
|
|
XBoxZone &selectedZone,
|
|
ENUM_X_DIRECTION forDir,
|
|
ENUM_X121SMC_XWZ_PRIORITY forPriority,
|
|
X121SMCStrategyXWZWorkingZone &workingZone,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(targets);
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
selectedZone.IsValid() &&
|
|
HasDirection(forDir) &&
|
|
workingZone.IsValid() &&
|
|
forPriority != X121SMC_XWZ_PRIORITY_NONE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
workingZone.symbol,
|
|
workingZone.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
XOBFVG tmpZones[];
|
|
|
|
//
|
|
// Based On Waiting Zones ...
|
|
has = workingZone.HasWaitingZones();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
workingZone.waitingZones,
|
|
tmpZones //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
double iTarget =
|
|
isBullish
|
|
? iOBFVG.ob.Lower()
|
|
: iOBFVG.ob.Upper();
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? cBar.high < iTarget
|
|
: cBar.low > iTarget;
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
}
|
|
|
|
//
|
|
// Based On Breaked Zones ...
|
|
has = workingZone.HasBreakedZones();
|
|
if (has)
|
|
{
|
|
Copy(
|
|
workingZone.breakedZones,
|
|
tmpZones //
|
|
);
|
|
|
|
//
|
|
while (HasChild(tmpZones))
|
|
{
|
|
//
|
|
XOBFVG iOBFVG;
|
|
|
|
//
|
|
idx = GetYoungest(tmpZones);
|
|
if (!IsValidIndex(idx))
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
iOBFVG = tmpZones[idx];
|
|
ArrayRemove(
|
|
tmpZones,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
double iTarget =
|
|
isBullish
|
|
? iOBFVG.ob.Lower()
|
|
: iOBFVG.ob.Upper();
|
|
|
|
//
|
|
has =
|
|
isBullish
|
|
? cBar.high < iTarget
|
|
: cBar.low > iTarget;
|
|
|
|
//
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
}
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
Clean(tmpZones);
|
|
}
|
|
|
|
//
|
|
// Based On Priority ...
|
|
has = forPriority != X121SMC_XWZ_PRIORITY_NONE;
|
|
if (has)
|
|
{
|
|
//
|
|
switch (forPriority)
|
|
{
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_WEAK:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_LOW:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = HasChild(targets);
|
|
|
|
//
|
|
// Cleanup ...
|
|
cBar.Clean();
|
|
Clean(tmpZones);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
struct X121SMCStrategyXWZWorkingZone
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
|
|
//
|
|
double quarter1;
|
|
double quarter2;
|
|
double quarter3;
|
|
|
|
//
|
|
XCSupplyZone *supplyZone;
|
|
XCDemandZone *demandZone;
|
|
|
|
//
|
|
XCSupplyZone *supplyZones[];
|
|
XCDemandZone *demandZones[];
|
|
|
|
//
|
|
XCSupportZone *supportZones[];
|
|
XCResistanceZone *resistanceZones[];
|
|
|
|
//
|
|
XOBFVG insideZones[];
|
|
XOBFVG breakedZones[];
|
|
XOBFVG waitingZones[];
|
|
|
|
//
|
|
XBoxZone insideBoxes[];
|
|
XBoxZone breakedBoxes[];
|
|
XConsolidationZone consolidationZones[];
|
|
|
|
//
|
|
CArrayObj mInsideZoneObjects;
|
|
CArrayObj mBreakedZoneObjects;
|
|
CArrayObj mWaitingZoneObjects;
|
|
CArrayObj mWorkingZoneObjects;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121SMCStrategyXWZWorkingZone()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
void Clean()
|
|
{
|
|
//
|
|
quarter1 = 0;
|
|
quarter2 = 0;
|
|
quarter3 = 0;
|
|
|
|
//
|
|
symbol = NULL;
|
|
period = NULL;
|
|
|
|
//
|
|
Clean(supplyZones);
|
|
Clean(demandZones);
|
|
|
|
//
|
|
Clean(insideZones);
|
|
Clean(waitingZones);
|
|
Clean(breakedZones);
|
|
|
|
//
|
|
Clean(insideBoxes);
|
|
Clean(breakedBoxes);
|
|
|
|
//
|
|
Clean(supportZones);
|
|
Clean(resistanceZones);
|
|
|
|
//
|
|
ZeroMemory(supplyZone);
|
|
ZeroMemory(demandZone);
|
|
|
|
//
|
|
mInsideZoneObjects.Clear();
|
|
mBreakedZoneObjects.Clear();
|
|
mWaitingZoneObjects.Clear();
|
|
mWorkingZoneObjects.Clear();
|
|
}
|
|
|
|
//
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
quarter1 > 0 &&
|
|
quarter2 > 0 &&
|
|
quarter3 > 0 &&
|
|
HasSupplyZone() &&
|
|
HasDemandZone() &&
|
|
quarter1 > quarter2 &&
|
|
quarter2 > quarter3
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool Init(
|
|
string _symbol,
|
|
ENUM_TIMEFRAMES _period,
|
|
int barIndex,
|
|
XPOIState &htfState,
|
|
XPOIState &mtfState,
|
|
XPOIState &stfState, //
|
|
XPOIState &ttfState //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
IsValid(_symbol) &&
|
|
IsValid(_period) &&
|
|
//
|
|
htfState.IsValid() &&
|
|
mtfState.IsValid() &&
|
|
stfState.IsValid() &&
|
|
ttfState.IsValid() &&
|
|
//
|
|
htfState.HasChild() &&
|
|
mtfState.HasChild() &&
|
|
stfState.HasChild() &&
|
|
ttfState.HasChild()
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
symbol = _symbol;
|
|
period = _period;
|
|
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
has = zBar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
result = has;
|
|
if (!result)
|
|
{
|
|
zBar.Clean();
|
|
return result;
|
|
}
|
|
double ll5 = zBar.FindLowest(5, MODE_LOW);
|
|
double hh5 = zBar.FindHighest(5, MODE_HIGH);
|
|
zBar.Clean();
|
|
|
|
//
|
|
// Supply Zone ...
|
|
has = HasSupplyZone();
|
|
if (!has)
|
|
{
|
|
//
|
|
idx = GetHighest(htfState.supplyZones);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
supplyZone = htfState.supplyZones[idx];
|
|
has = hh5 < supplyZone.Lower();
|
|
if (!has)
|
|
{
|
|
supplyZone = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand Zone ...
|
|
has = HasDemandZone();
|
|
if (!has)
|
|
{
|
|
//
|
|
idx = GetLowest(htfState.demandZones);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
demandZone = htfState.demandZones[idx];
|
|
has = ll5 > demandZone.Upper();
|
|
if (!has)
|
|
{
|
|
demandZone = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Supply Zones ...
|
|
has = HasSupplyZones();
|
|
if (!has)
|
|
{
|
|
//
|
|
count = mtfState.FilterSupplyZones(
|
|
supplyZones,
|
|
period,
|
|
XZONE_STATE_PASSED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_IGNORED,
|
|
false //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
has = HasDemandZones();
|
|
if (!has)
|
|
{
|
|
//
|
|
count = mtfState.FilterDemandZones(
|
|
demandZones,
|
|
period,
|
|
XZONE_STATE_PASSED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_IGNORED,
|
|
false //
|
|
);
|
|
}
|
|
|
|
//
|
|
has = ttfState.HasConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
ttfState.consolidationZones,
|
|
consolidationZones //
|
|
);
|
|
CleanupArray(
|
|
consolidationZones,
|
|
50 //
|
|
);
|
|
}
|
|
|
|
//
|
|
if (supplyZone != NULL &&
|
|
demandZone != NULL &&
|
|
supplyZone.IsValid() &&
|
|
demandZone.IsValid())
|
|
{
|
|
//
|
|
double upper = supplyZone.Lower();
|
|
double lower = demandZone.Upper();
|
|
|
|
//
|
|
double delta = ((upper - lower) / 100) * 25;
|
|
|
|
//
|
|
quarter1 = upper - (1 * delta);
|
|
quarter2 = upper - (2 * delta);
|
|
quarter3 = upper - (3 * delta);
|
|
}
|
|
|
|
//
|
|
// Detect OBFVG(s) ...
|
|
ExtractOBFVGs(
|
|
waitingZones,
|
|
mtfState,
|
|
stfState);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void Update(
|
|
int barIndex,
|
|
XPOIState &htfState,
|
|
XPOIState &mtfState,
|
|
XPOIState &stfState,
|
|
XPOIState &ttfState //
|
|
)
|
|
{
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
has =
|
|
//
|
|
IsValid() &&
|
|
//
|
|
htfState.IsValid() &&
|
|
mtfState.IsValid() &&
|
|
stfState.IsValid() &&
|
|
//
|
|
htfState.HasChild() &&
|
|
mtfState.HasChild() &&
|
|
stfState.HasChild()
|
|
//
|
|
;
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XOHCL zBar;
|
|
has = zBar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
if (!has)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
return;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
has = zBar.GetPreviousBar(cBar);
|
|
if (!has)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
|
|
//
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Adding New OBFVG to Waiting Zones if not Exists ...
|
|
XOBFVG tmpWaitingZones[];
|
|
count = ExtractOBFVGs(
|
|
tmpWaitingZones,
|
|
mtfState,
|
|
stfState //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
AddIfNotExists(
|
|
tmpWaitingZones,
|
|
waitingZones //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Since Usig States for Extracting Supply/Demand or
|
|
// Support/Resistance Zones and State's has Max Alllowed Restrication ...
|
|
// we have to Manage new Zones and also Hold's Breaked Zones ...
|
|
|
|
//
|
|
// MTF STF ...
|
|
|
|
//
|
|
// Supply Zones ...
|
|
XCSupplyZone *tmpSupplies[];
|
|
count = mtfState.FilterSupplyZones(
|
|
tmpSupplies,
|
|
NULL,
|
|
XZONE_STATE_PASSED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_IGNORED,
|
|
false //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
has = ToBox(
|
|
iBox,
|
|
tmpSupplies[i] //
|
|
);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Find Index ...
|
|
|
|
//
|
|
idx = FindIndex(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
idx = FindIndex(
|
|
iBox,
|
|
breakedBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
idx = FindIndex(
|
|
tmpSupplies[i],
|
|
supplyZones //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Checking Price Validation ...
|
|
has = cBar.high < tmpSupplies[i].Lower();
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
Add(
|
|
tmpSupplies[i],
|
|
supplyZones //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
Clean(tmpSupplies);
|
|
|
|
//
|
|
// Demand Zones ...
|
|
XCDemandZone *tmpDemands[];
|
|
count = mtfState.FilterDemandZones(
|
|
tmpDemands,
|
|
NULL,
|
|
XZONE_STATE_PASSED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_IGNORED,
|
|
false //
|
|
);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
has = ToBox(
|
|
iBox,
|
|
tmpDemands[i] //
|
|
);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Find Index ...
|
|
|
|
//
|
|
idx = FindIndex(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
idx = FindIndex(
|
|
iBox,
|
|
breakedBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
idx = FindIndex(
|
|
tmpDemands[i],
|
|
demandZones //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Checking Price Validation ...
|
|
has = cBar.low > tmpDemands[i].Upper();
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
Add(
|
|
tmpDemands[i],
|
|
demandZones //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
Clean(tmpDemands);
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Consolidation Zones ...
|
|
has = ttfState.HasConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
ttfState.consolidationZones,
|
|
consolidationZones //
|
|
);
|
|
CleanupArray(
|
|
consolidationZones,
|
|
50 //
|
|
);
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Detect Price Inside Zones ...
|
|
has = HasWaitingZones();
|
|
if (has)
|
|
{
|
|
//
|
|
int mustRemove[];
|
|
count = CountWaitingZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XOBFVG iOBFVG = waitingZones[i];
|
|
|
|
//
|
|
bool isInside =
|
|
//
|
|
zBar.high < iOBFVG.ob.Upper() &&
|
|
zBar.low > iOBFVG.ob.Lower() &&
|
|
//
|
|
cBar.high < iOBFVG.ob.Upper() &&
|
|
cBar.low > iOBFVG.ob.Lower()
|
|
//
|
|
;
|
|
if (isInside)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
iOBFVG,
|
|
insideZones //
|
|
);
|
|
has = IsValidSize(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
Add(
|
|
i,
|
|
mustRemove //
|
|
);
|
|
|
|
//
|
|
AddRef(
|
|
iOBFVG,
|
|
insideZones //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasChild(mustRemove);
|
|
if (has)
|
|
{
|
|
//
|
|
count = ArraySize(mustRemove);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
waitingZones,
|
|
mustRemove[i],
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(mustRemove);
|
|
}
|
|
|
|
//
|
|
// Here we Looking for Price Inside Supply or Demand Zones ...
|
|
|
|
//
|
|
// Supply Zones ...
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
int mustRemove[];
|
|
count = CountSupplyZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupplyZone *iZone = supplyZones[i];
|
|
|
|
//
|
|
bool isInside =
|
|
//
|
|
zBar.high < iZone.Upper() &&
|
|
zBar.low > iZone.Lower() &&
|
|
//
|
|
cBar.high < iZone.Upper() &&
|
|
cBar.low > iZone.Lower()
|
|
//
|
|
;
|
|
if (isInside)
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
has = ToBox(
|
|
iBox,
|
|
iZone //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
has = IsValidSize(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
Add(
|
|
i,
|
|
mustRemove //
|
|
);
|
|
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasChild(mustRemove);
|
|
if (has)
|
|
{
|
|
//
|
|
count = ArraySize(mustRemove);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
supplyZones,
|
|
mustRemove[i],
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(mustRemove);
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
int mustRemove[];
|
|
count = CountDemandZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCDemandZone *iZone = demandZones[i];
|
|
|
|
//
|
|
bool isInside =
|
|
//
|
|
zBar.high < iZone.Upper() &&
|
|
zBar.low > iZone.Lower() &&
|
|
//
|
|
cBar.high < iZone.Upper() &&
|
|
cBar.low > iZone.Lower()
|
|
//
|
|
;
|
|
if (isInside)
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
has = ToBox(
|
|
iBox,
|
|
iZone //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
has = IsValidSize(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
Add(
|
|
i,
|
|
mustRemove //
|
|
);
|
|
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasChild(mustRemove);
|
|
if (has)
|
|
{
|
|
//
|
|
count = ArraySize(mustRemove);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
demandZones,
|
|
mustRemove[i],
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(mustRemove);
|
|
}
|
|
|
|
//
|
|
// Here we Detect Breaked Zone/Box (s) ...
|
|
|
|
// //
|
|
// // Detect Breaked Zones ...
|
|
// has = HasInsideZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// int mustRemove[];
|
|
// count = CountInsideZones();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XOBFVG iOBFVG = insideZones[i];
|
|
// ENUM_X_DIRECTION iDir = iOBFVG.GetDirection();
|
|
// bool isBullish = IsBullish(iDir);
|
|
|
|
// //
|
|
// bool isBullishBreaked =
|
|
// //
|
|
// zBar.high < iOBFVG.ob.Lower() &&
|
|
// cBar.high < iOBFVG.ob.Lower()
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isBearishBreaked =
|
|
// //
|
|
// zBar.low > iOBFVG.ob.Upper() &&
|
|
// cBar.low > iOBFVG.ob.Upper()
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isBreaked =
|
|
// isBullish
|
|
// ? isBullishBreaked
|
|
// : isBearishBreaked;
|
|
|
|
// //
|
|
// if (isBreaked)
|
|
// {
|
|
// //
|
|
// idx = FindIndex(
|
|
// iOBFVG,
|
|
// breakedZones //
|
|
// );
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// i,
|
|
// mustRemove //
|
|
// );
|
|
|
|
// //
|
|
// AddRef(
|
|
// iOBFVG,
|
|
// breakedZones //
|
|
// );
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// has = HasChild(mustRemove);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// count = ArraySize(mustRemove);
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// ArrayRemove(
|
|
// insideZones,
|
|
// mustRemove[i],
|
|
// 1 //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(mustRemove);
|
|
// }
|
|
|
|
// //
|
|
// // Detect Breaked Boxes ...
|
|
// has = HasInsideBoxes();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// int mustRemove[];
|
|
// count = CountInsideBoxes();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XBoxZone iBox = insideBoxes[i];
|
|
// ENUM_X_DIRECTION iDir = iBox.dir;
|
|
// bool isBullish = iBox.IsBullish();
|
|
|
|
// //
|
|
// bool isBullishBreaked =
|
|
// //
|
|
// zBar.high < iBox.lower &&
|
|
// cBar.high < iBox.lower
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isBearishBreaked =
|
|
// //
|
|
// zBar.low > iBox.upper &&
|
|
// cBar.low > iBox.upper
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isBreaked =
|
|
// isBullish
|
|
// ? isBullishBreaked
|
|
// : isBearishBreaked;
|
|
|
|
// //
|
|
// if (isBreaked)
|
|
// {
|
|
// //
|
|
// idx = FindIndex(
|
|
// iBox,
|
|
// breakedBoxes //
|
|
// );
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// i,
|
|
// mustRemove //
|
|
// );
|
|
|
|
// //
|
|
// AddRef(
|
|
// iBox,
|
|
// breakedBoxes //
|
|
// );
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// has = HasChild(mustRemove);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// count = ArraySize(mustRemove);
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// ArrayRemove(
|
|
// insideBoxes,
|
|
// mustRemove[i],
|
|
// 1 //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(mustRemove);
|
|
// }
|
|
|
|
//
|
|
// Cleanup Resource ...
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
}
|
|
|
|
//
|
|
bool HasSupplyZone()
|
|
{
|
|
return supplyZone != NULL &&
|
|
supplyZone.IsValid();
|
|
}
|
|
|
|
//
|
|
bool HasDemandZone()
|
|
{
|
|
return demandZone != NULL &&
|
|
demandZone.IsValid();
|
|
}
|
|
|
|
//
|
|
bool HasSupplyZones()
|
|
{
|
|
return HasChild(supplyZones);
|
|
}
|
|
|
|
//
|
|
int CountSupplyZones()
|
|
{
|
|
return ArraySize(supplyZones);
|
|
}
|
|
|
|
//
|
|
bool HasDemandZones()
|
|
{
|
|
return HasChild(demandZones);
|
|
}
|
|
|
|
//
|
|
int CountDemandZones()
|
|
{
|
|
return ArraySize(demandZones);
|
|
}
|
|
|
|
//
|
|
bool HasSupportZones()
|
|
{
|
|
return HasChild(supportZones);
|
|
}
|
|
|
|
//
|
|
int CountSupportZones()
|
|
{
|
|
return ArraySize(supportZones);
|
|
}
|
|
|
|
//
|
|
bool HasResistanceZones()
|
|
{
|
|
return HasChild(resistanceZones);
|
|
}
|
|
|
|
//
|
|
int CountResistanceZones()
|
|
{
|
|
return ArraySize(resistanceZones);
|
|
}
|
|
|
|
//
|
|
bool HasWaitingZones()
|
|
{
|
|
return HasChild(waitingZones);
|
|
}
|
|
|
|
//
|
|
int CountWaitingZones()
|
|
{
|
|
return ArraySize(waitingZones);
|
|
}
|
|
|
|
//
|
|
bool HasInsideZones()
|
|
{
|
|
return HasChild(insideZones);
|
|
}
|
|
|
|
//
|
|
int CountInsideZones()
|
|
{
|
|
return ArraySize(insideZones);
|
|
}
|
|
|
|
//
|
|
bool HasBreakedZones()
|
|
{
|
|
return HasChild(breakedZones);
|
|
}
|
|
|
|
//
|
|
int CountBreakedZones()
|
|
{
|
|
return ArraySize(breakedZones);
|
|
}
|
|
|
|
//
|
|
bool HasConsolidationZones()
|
|
{
|
|
return HasChild(consolidationZones);
|
|
}
|
|
|
|
//
|
|
int CountConsolidationZones()
|
|
{
|
|
return ArraySize(consolidationZones);
|
|
}
|
|
|
|
//
|
|
bool HasInsideBoxes()
|
|
{
|
|
return HasChild(insideBoxes);
|
|
}
|
|
|
|
//
|
|
int CountInsideBoxes()
|
|
{
|
|
return ArraySize(insideBoxes);
|
|
}
|
|
|
|
//
|
|
bool HasBreakedBoxes()
|
|
{
|
|
return HasChild(breakedBoxes);
|
|
}
|
|
|
|
//
|
|
int CountBreakedBoxes()
|
|
{
|
|
return ArraySize(breakedBoxes);
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
bool IsDestroyed(
|
|
int barIndex = 0,
|
|
ENUM_TIMEFRAMES forPeriod = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (!IsValid(forPeriod))
|
|
{
|
|
forPeriod = period;
|
|
}
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL bar;
|
|
result = bar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = bar.GetPreviousBar(cBar);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
cBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isSupplyZoneBreaked =
|
|
//
|
|
bar.low > supplyZone.Upper() &&
|
|
cBar.low > supplyZone.Upper()
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isDemandZoneBreaked =
|
|
//
|
|
bar.high < demandZone.Lower() &&
|
|
cBar.high < demandZone.Lower()
|
|
//
|
|
;
|
|
|
|
//
|
|
bar.Clean();
|
|
cBar.Clean();
|
|
|
|
//
|
|
result = isSupplyZoneBreaked ||
|
|
isDemandZoneBreaked;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool DetectPriority(
|
|
ENUM_X121SMC_XWZ_PRIORITY &priority,
|
|
ENUM_X_DIRECTION forDir,
|
|
int barIndex = 0,
|
|
ENUM_TIMEFRAMES forPeriod = NULL //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
priority = X121SMC_XWZ_PRIORITY_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (!IsValid(forPeriod))
|
|
{
|
|
forPeriod = period;
|
|
}
|
|
|
|
//
|
|
result = IsValid() &&
|
|
HasDirection(forDir);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
XOHCL bar;
|
|
result = bar.Init(
|
|
symbol,
|
|
forPeriod,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (bar.high < supplyZone.Upper() &&
|
|
bar.low > supplyZone.Lower())
|
|
{
|
|
//
|
|
priority =
|
|
isBullish
|
|
? X121SMC_XWZ_PRIORITY_NONE
|
|
: X121SMC_XWZ_PRIORITY_STRONG_HIGH;
|
|
}
|
|
else if (bar.high < supplyZone.Lower() &&
|
|
bar.low > quarter1)
|
|
{
|
|
//
|
|
priority =
|
|
isBullish
|
|
? X121SMC_XWZ_PRIORITY_WEAK
|
|
: X121SMC_XWZ_PRIORITY_HIGH;
|
|
}
|
|
else if (bar.high < quarter1 &&
|
|
bar.low > quarter2)
|
|
{
|
|
//
|
|
priority =
|
|
isBullish
|
|
? X121SMC_XWZ_PRIORITY_LOW
|
|
: X121SMC_XWZ_PRIORITY_REGULAR;
|
|
}
|
|
else if (bar.high < quarter2 &&
|
|
bar.low > quarter3)
|
|
{
|
|
//
|
|
priority =
|
|
isBullish
|
|
? X121SMC_XWZ_PRIORITY_REGULAR
|
|
: X121SMC_XWZ_PRIORITY_LOW;
|
|
}
|
|
else if (bar.high < quarter3 &&
|
|
bar.low > demandZone.Upper())
|
|
{
|
|
//
|
|
priority =
|
|
isBullish
|
|
? X121SMC_XWZ_PRIORITY_HIGH
|
|
: X121SMC_XWZ_PRIORITY_WEAK;
|
|
}
|
|
else if (bar.high < demandZone.Upper() &&
|
|
bar.low > demandZone.Lower())
|
|
{
|
|
//
|
|
priority =
|
|
isBullish
|
|
? X121SMC_XWZ_PRIORITY_STRONG_HIGH
|
|
: X121SMC_XWZ_PRIORITY_NONE;
|
|
}
|
|
|
|
//
|
|
result = priority != X121SMC_XWZ_PRIORITY_NONE &&
|
|
priority != X121SMC_XWZ_PRIORITY_WEAK;
|
|
|
|
//
|
|
bar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
void UpdateTo(datetime value = NULL)
|
|
{
|
|
//
|
|
value = NormalizeTime(value);
|
|
|
|
//
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
has = HasSupplyZone();
|
|
if (has)
|
|
{
|
|
supplyZone.To(value);
|
|
}
|
|
|
|
//
|
|
has = HasDemandZone();
|
|
if (has)
|
|
{
|
|
demandZone.To(value);
|
|
}
|
|
|
|
//
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupplyZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
supplyZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountDemandZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
demandZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupportZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
supportZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasResistanceZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountResistanceZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
resistanceZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasWaitingZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountWaitingZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
waitingZones[i].UpdateTo(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasInsideZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountInsideZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
insideZones[i].UpdateTo(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountInsideBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
insideBoxes[i].to = value;
|
|
}
|
|
}
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
void Draw(
|
|
XCPOIDrawer *drawer,
|
|
bool drawWaitingZones = true,
|
|
bool drawInsideZones = false,
|
|
bool drawBreakedZones = false,
|
|
bool drawSupplyZone = false,
|
|
bool drawDemandZone = false,
|
|
bool drawSupplyZones = false,
|
|
bool drawDemandZones = false,
|
|
bool drawSupportZones = false,
|
|
bool drawResistanceZones = false //
|
|
)
|
|
{
|
|
//
|
|
if (drawer == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int count = 0;
|
|
bool has = false;
|
|
bool isCreated = false;
|
|
|
|
//
|
|
ulong chartID = drawer.ChartIdentification();
|
|
int subWindow = drawer.SubWindowIdentification();
|
|
color bullishColor = drawer.BarBullishColor();
|
|
color bearishColor = drawer.BarBearishColor();
|
|
|
|
//
|
|
// Supply Zone ...
|
|
if (drawSupplyZone)
|
|
{
|
|
//
|
|
has = HasSupplyZone();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *iObj;
|
|
isCreated = drawer.CreateSupplyZone(
|
|
supplyZone,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand Zone ...
|
|
if (drawDemandZone)
|
|
{
|
|
//
|
|
has = HasDemandZone();
|
|
if (has)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iObj;
|
|
isCreated = drawer.CreateDemandZone(
|
|
demandZone,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Supply Zones ...
|
|
if (drawSupplyZones)
|
|
{
|
|
//
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupplyZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *iObj;
|
|
isCreated = drawer.CreateSupplyZone(
|
|
supplyZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
if (drawDemandZones)
|
|
{
|
|
//
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountDemandZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iObj;
|
|
isCreated = drawer.CreateDemandZone(
|
|
demandZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Support Zones ...
|
|
if (drawSupportZones)
|
|
{
|
|
//
|
|
has = HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupportZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupportZoneObject *iObj;
|
|
isCreated = drawer.CreateSupportZone(
|
|
supportZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
if (drawResistanceZones)
|
|
{
|
|
//
|
|
has = HasResistanceZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountResistanceZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCResistanceZoneObject *iObj;
|
|
isCreated = drawer.CreateResistanceZone(
|
|
resistanceZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Waiting Zones ...
|
|
if (drawWaitingZones)
|
|
{
|
|
//
|
|
has = HasWaitingZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountWaitingZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCBaseObject *objects[];
|
|
int objectsCount = drawer.DrawOBFVG(
|
|
waitingZones[i],
|
|
objects //
|
|
);
|
|
has = IsValidSize(objectsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int j = 0; j < objectsCount; j++)
|
|
{
|
|
mWaitingZoneObjects.Add(objects[j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Inside Zones ...
|
|
if (drawInsideZones)
|
|
{
|
|
//
|
|
// Zones ...
|
|
has = HasInsideZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountInsideZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCBaseObject *objects[];
|
|
int objectsCount = drawer.DrawOBFVG(
|
|
insideZones[i],
|
|
objects //
|
|
);
|
|
|
|
//
|
|
has = IsValidSize(objectsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < objectsCount; i++)
|
|
{
|
|
mInsideZoneObjects.Add(objects[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// //
|
|
// // Boxes ...
|
|
// has = HasInsideBoxes();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// count = CountInsideBoxes();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XCBoxObject *object;
|
|
// bool isCreated = drawer.DrawBox(
|
|
// insideBoxes[i],
|
|
// object //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mInsideZoneObjects.Add(object);
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
|
|
//
|
|
// Breaked Zones ...
|
|
if (drawBreakedZones)
|
|
{
|
|
//
|
|
has = HasBreakedZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountBreakedZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCBaseObject *objects[];
|
|
int objectsCount = drawer.DrawOBFVG(
|
|
breakedZones[i],
|
|
objects //
|
|
);
|
|
|
|
//
|
|
has = IsValidSize(objectsCount);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < objectsCount; i++)
|
|
{
|
|
mBreakedZoneObjects.Add(objects[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// //
|
|
// // Boxes ...
|
|
// has = HasBreakedBoxes();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// count = CountBreakedBoxes();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XCBoxObject *object;
|
|
// bool isCreated = drawer.DrawBox(
|
|
// breakedBoxes[i],
|
|
// object //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// mInsideZoneObjects.Add(object);
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Quarters ...
|
|
has = IsValid();
|
|
if (has)
|
|
{
|
|
//
|
|
double zoneUpper = supplyZone.Upper();
|
|
double upper = supplyZone.Lower();
|
|
|
|
//
|
|
double lower = demandZone.Upper();
|
|
double zoneLower = demandZone.Lower();
|
|
|
|
//
|
|
string prefix = "X121WZone_" + symbol + "_" + ToString(period);
|
|
|
|
//
|
|
// Zone Upper ...
|
|
CChartObjectHLine *zoneUpperLine;
|
|
zoneUpperLine = new CChartObjectHLine();
|
|
isCreated = zoneUpperLine.Create(
|
|
chartID,
|
|
prefix + "_ZoneTop",
|
|
subWindow,
|
|
zoneUpper //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
zoneUpperLine.Color(clrRed);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(zoneUpperLine);
|
|
}
|
|
|
|
//
|
|
// Zone Lower ...
|
|
CChartObjectHLine *zoneLowerLine;
|
|
zoneLowerLine = new CChartObjectHLine();
|
|
isCreated = zoneLowerLine.Create(
|
|
chartID,
|
|
prefix + "_ZoneDown",
|
|
subWindow,
|
|
zoneLower //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
zoneLowerLine.Color(clrRed);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(zoneLowerLine);
|
|
}
|
|
|
|
//
|
|
// Upper ...
|
|
CChartObjectHLine *upperLine;
|
|
upperLine = new CChartObjectHLine();
|
|
isCreated = upperLine.Create(
|
|
chartID,
|
|
prefix + "_Upper",
|
|
subWindow,
|
|
upper //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
upperLine.Color(clrLime);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(upperLine);
|
|
}
|
|
|
|
//
|
|
// Lower ...
|
|
CChartObjectHLine *lowerLine;
|
|
lowerLine = new CChartObjectHLine();
|
|
isCreated = lowerLine.Create(
|
|
chartID,
|
|
prefix + "_Lower",
|
|
subWindow,
|
|
lower //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
lowerLine.Color(clrLime);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(lowerLine);
|
|
}
|
|
|
|
//
|
|
// Quarters ...
|
|
|
|
//
|
|
// Quarter 1 ...
|
|
CChartObjectHLine *q1Line;
|
|
q1Line = new CChartObjectHLine();
|
|
isCreated = q1Line.Create(
|
|
chartID,
|
|
prefix + "_Q1",
|
|
subWindow,
|
|
quarter1 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
q1Line.Color(clrYellow);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(q1Line);
|
|
}
|
|
|
|
//
|
|
// Quarter 2 ...
|
|
CChartObjectHLine *q2Line;
|
|
q2Line = new CChartObjectHLine();
|
|
isCreated = q2Line.Create(
|
|
chartID,
|
|
prefix + "_Q2",
|
|
subWindow,
|
|
quarter2 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
q2Line.Color(clrYellow);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(q2Line);
|
|
}
|
|
|
|
//
|
|
// Quarter 3 ...
|
|
CChartObjectHLine *q3Line;
|
|
q3Line = new CChartObjectHLine();
|
|
isCreated = q3Line.Create(
|
|
chartID,
|
|
prefix + "_Q3",
|
|
subWindow,
|
|
quarter3 //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
q3Line.Color(clrYellow);
|
|
|
|
//
|
|
mWaitingZoneObjects.Add(q3Line);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Detect Targets Based on Selected Zone for Specified type of Directions ...
|
|
*
|
|
* @param targets: double Collection ...
|
|
* @param selectedZone: XOBFVG instance, selected Zone ...
|
|
* @param forDir: ENUM_X_DIRECTION specified Position Direction ...
|
|
* @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ...
|
|
* @param barIndex: int Specified Bar Index ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedZonesTargets(
|
|
double &targets[],
|
|
XOBFVG &selectedZone,
|
|
ENUM_X_DIRECTION forDir,
|
|
ENUM_X121SMC_XWZ_PRIORITY forPriority,
|
|
X121SMCStrategyXWZWorkingZone &workingZone,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(targets);
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
selectedZone.IsValid() &&
|
|
HasDirection(forDir) &&
|
|
workingZone.IsValid() &&
|
|
forPriority != X121SMC_XWZ_PRIORITY_NONE
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
workingZone.symbol,
|
|
workingZone.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
//
|
|
// Based On Priority ...
|
|
has = forPriority != X121SMC_XWZ_PRIORITY_NONE;
|
|
if (has)
|
|
{
|
|
//
|
|
switch (forPriority)
|
|
{
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_WEAK:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_LOW:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_REGULAR:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
|
|
//
|
|
case X121SMC_XWZ_PRIORITY_STRONG_HIGH:
|
|
//
|
|
if (isBullish)
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Weak ...
|
|
Add(
|
|
workingZone.demandZone.Upper(),
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Low ...
|
|
Add(
|
|
workingZone.quarter3,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Regular ...
|
|
Add(
|
|
workingZone.quarter2,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// High ...
|
|
Add(
|
|
workingZone.quarter1,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
// Strong High ...
|
|
Add(
|
|
workingZone.supplyZone.Lower(),
|
|
targets //
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = HasChild(targets);
|
|
|
|
//
|
|
// Cleanup ...
|
|
cBar.Clean();
|
|
Clean(tmpZones);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Check an XOBFVG instance has Required Conditions ...
|
|
*
|
|
* @param zone: XOBFVG instance ...
|
|
* @param state: XPOIState instance ...
|
|
* @param conditions: X121Conditions instance ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectInsideSelectedZoneConditions(
|
|
bool &isReversal,
|
|
XOBFVG &zone,
|
|
XPOIState &state,
|
|
X121Conditions &conditions,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
isReversal = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
XOHCL bar;
|
|
result = bar.Init(
|
|
state.symbol,
|
|
state.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
zone.IsValid() &&
|
|
state.IsValid() &&
|
|
state.HasChild();
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = zone.IsBullish();
|
|
bool isBearish = zone.IsBearish();
|
|
|
|
//
|
|
double points = GetPoints(bar.symbol);
|
|
|
|
//
|
|
double bullishScore = 0;
|
|
double bearishScore = 0;
|
|
double scoreMultiplier = 1.5;
|
|
conditions.GenerateScore(
|
|
bullishScore,
|
|
bearishScore //
|
|
);
|
|
|
|
// //
|
|
// bool isLowerBreaked =
|
|
// //
|
|
// conditions.isSarBearish &&
|
|
// conditions.isCheBearish &&
|
|
// bar.high < zone.ob.Lower() &&
|
|
// bearishScore > bullishScore &&
|
|
// conditions.isX3MaBearishState &&
|
|
// conditions.isVWapBearishState &&
|
|
// conditions.isX3MaBearishOrdered &&
|
|
// conditions.isVWapBearishOrdered &&
|
|
// bar.low < conditions.atrLowerBuffer[1] &&
|
|
// conditions.atrLowerBuffer[1] < zone.ob.Lower()
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isUpperBreaked =
|
|
// //
|
|
// conditions.isSarBullish &&
|
|
// conditions.isCheBullish &&
|
|
// bar.low > zone.ob.Upper() &&
|
|
// bullishScore > bearishScore &&
|
|
// conditions.isX3MaBullishState &&
|
|
// conditions.isVWapBullishState &&
|
|
// conditions.isX3MaBullishOrdered &&
|
|
// conditions.isVWapBullishOrdered &&
|
|
// bar.high > conditions.atrUpperBuffer[1] &&
|
|
// conditions.atrUpperBuffer[1] > zone.ob.Upper()
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isPeakEqualsToUpper =
|
|
// MathAbs(conditions.peaksBuffer[0] - zone.ob.Upper()) > points * 1;
|
|
|
|
// //
|
|
// bool isValeEqualsToLower =
|
|
// MathAbs(conditions.valesBuffer[0] - zone.ob.Lower()) > points * 1;
|
|
|
|
//
|
|
// bool isDirectionalBullishPassed =
|
|
// //
|
|
// isBullish &&
|
|
// isUpperBreaked
|
|
// // (
|
|
|
|
// // ||
|
|
// // isValeEqualsToLower)
|
|
// //
|
|
// ;
|
|
|
|
//
|
|
// bool isDirectionalBearishPassed =
|
|
// //
|
|
// isBearish &&
|
|
// isLowerBreaked
|
|
// // ||
|
|
// // isPeakEqualsToUpper)
|
|
// //
|
|
// ;
|
|
|
|
//
|
|
// bool isDirectionalPassed =
|
|
// isDirectionalBullishPassed ||
|
|
// isDirectionalBearishPassed;
|
|
|
|
// //
|
|
// bool isReversalBullishPassed =
|
|
// //
|
|
// // isBullish &&
|
|
// // isLowerBreaked
|
|
// // ( ||
|
|
// // isPeakEqualsToUpper)
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool isReversalBearishPassed =
|
|
// //
|
|
// // isBearish &&
|
|
// // isUpperBreaked
|
|
// // ||
|
|
// // isValeEqualsToLower)
|
|
// //
|
|
// ;
|
|
|
|
//
|
|
// bool isReversalPassed = isReversalBullishPassed ||
|
|
// isReversalBearishPassed;
|
|
|
|
//
|
|
// result = isReversalPassed ||
|
|
// isDirectionalPassed;
|
|
|
|
//
|
|
result = false;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
// isReversal = isReversalPassed;
|
|
}
|
|
|
|
//
|
|
bar.Clean();
|
|
return result;
|
|
}
|
|
|
|
bool DetectBreakedSelectedZoneConditions(
|
|
bool &isReversal,
|
|
XOBFVG &zone,
|
|
XPOIState &mtfState,
|
|
XPOIState &stfState,
|
|
XPOIState &ttfState,
|
|
X121Conditions &conditions //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
isReversal = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
zone.IsValid() &&
|
|
mtfState.IsValid() &&
|
|
stfState.IsValid() &&
|
|
ttfState.IsValid() &&
|
|
mtfState.HasChild() &&
|
|
stfState.HasChild() &&
|
|
ttfState.HasChild()
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
result = ToBox(
|
|
iBox,
|
|
zone.ob //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ENUM_X_DIRECTION iDir = iBox.dir;
|
|
bool isBullish = IsBullish(iDir);
|
|
bool isBearish = IsBearish(iDir);
|
|
|
|
//
|
|
// X3Ma ...
|
|
|
|
//
|
|
double x3maFast = conditions.x3maFastBuffer[0];
|
|
double x3maMid = conditions.x3maMidBuffer[0];
|
|
double x3maSlow = conditions.x3maSlowBuffer[0];
|
|
|
|
//
|
|
bool isX3mInside =
|
|
//
|
|
(x3maFast < iBox.upper &&
|
|
x3maMid < iBox.upper &&
|
|
x3maSlow < iBox.upper)
|
|
//
|
|
&&
|
|
//
|
|
(x3maFast > iBox.lower &&
|
|
x3maMid > iBox.lower &&
|
|
x3maSlow > iBox.lower)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBullishConditions =
|
|
isBullish &&
|
|
isX3mInside;
|
|
|
|
//
|
|
bool isBearishConditions =
|
|
isBearish &&
|
|
isX3mInside;
|
|
|
|
//
|
|
result = isBullishConditions ||
|
|
isBearishConditions;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Detect SL Candidates Based on Selected Zone for Specified type of Directions ...
|
|
*
|
|
* @param sls: double Collection ...
|
|
* @param selectedZone: XOBFVG instance, selected Zone ...
|
|
* @param forDir: ENUM_X_DIRECTION specified Position Direction ...
|
|
* @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ...
|
|
* @param barIndex: int Specified Bar Index ...
|
|
* @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectSelectedZoneSLCandidates(
|
|
double &sls[],
|
|
XOBFVG &selectedZone,
|
|
ENUM_X_DIRECTION forDir,
|
|
X121SMCStrategyXWZWorkingZone &workingZone,
|
|
X121Conditions &conditions,
|
|
int barIndex = 0,
|
|
double maxAllowedSLDistanceInPoint = 300 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
Clean(sls);
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (barIndex == 0)
|
|
{
|
|
barIndex++;
|
|
}
|
|
|
|
//
|
|
result =
|
|
//
|
|
selectedZone.IsValid() &&
|
|
HasDirection(forDir) &&
|
|
workingZone.IsValid()
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isBullish = IsBullish(forDir);
|
|
|
|
//
|
|
double pivot =
|
|
isBullish
|
|
? selectedZone.ob.Lower()
|
|
: selectedZone.ob.Upper();
|
|
double points = GetPoints(workingZone.symbol);
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
workingZone.symbol,
|
|
workingZone.period,
|
|
barIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
cBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
// //
|
|
// double pvSL = isBullish
|
|
// ? conditions.valesBuffer[0]
|
|
// : conditions.peaksBuffer[1];
|
|
|
|
// //
|
|
// Add(
|
|
// pvSL,
|
|
// sls //
|
|
// );
|
|
|
|
//
|
|
// Based On Passed Bars ...
|
|
// XOHCL passedBar;
|
|
// bool isPassed = false;
|
|
// bool isBodyState = false;
|
|
// ENUM_X_DIRECTION passedDir = selectedZone.GetDirection();
|
|
|
|
// //
|
|
// // Started Bar ...
|
|
// isPassed = selectedZone.ob.IsStarted(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Activation Bar ...
|
|
// passedBar.Clean();
|
|
// isPassed = selectedZone.ob.IsActivated(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Worked Bar ...
|
|
// passedBar.Clean();
|
|
// isPassed = selectedZone.ob.IsActivated(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Breaked Bar ...
|
|
// passedBar.Clean();
|
|
// isPassed = selectedZone.ob.IsActivated(
|
|
// passedDir,
|
|
// passedBar,
|
|
// isBodyState //
|
|
// );
|
|
// if (isPassed)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? passedBar.low
|
|
// : passedBar.high;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
//
|
|
// Based On Consolidation Zones ...
|
|
// has = workingZone.HasConsolidationZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XConsolidationZone tmpZones[];
|
|
// Copy(
|
|
// workingZone.consolidationZones,
|
|
// tmpZones //
|
|
// );
|
|
// XConsolidationZone selectedConsolidationZone;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetYoungest(tmpZones);
|
|
// if (!IsValidIndex(idx))
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XConsolidationZone iZone = tmpZones[idx];
|
|
|
|
// //
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// has =
|
|
// !selectedConsolidationZone.IsValid()
|
|
// ? isBullish
|
|
// ? cBar.low < iZone.upper
|
|
// : cBar.high < iZone.lower
|
|
// : isBullish
|
|
// ? selectedConsolidationZone.lower < iZone.lower
|
|
// : selectedConsolidationZone.upper > iZone.upper;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// selectedConsolidationZone = iZone;
|
|
// iZone.Clean();
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// iZone.Clean();
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// has = selectedConsolidationZone.IsValid();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? selectedConsolidationZone.lower
|
|
// : selectedConsolidationZone.upper;
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//
|
|
// Based On Supply and Demand Zones ...
|
|
|
|
//
|
|
// Demand Zones ...
|
|
// has = workingZone.HasDemandZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCDemandZone *tmpZones[];
|
|
// Copy(
|
|
// workingZone.demandZones,
|
|
// tmpZones //
|
|
// );
|
|
// XCDemandZone *selectedDemand = NULL;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetLowest(tmpZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XCDemandZone *iZone = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// // Validate Zone ...
|
|
// has =
|
|
// isBullish
|
|
// ? IsBelowDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// )
|
|
// : IsAboveDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// );
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// has =
|
|
// selectedDemand == NULL
|
|
// ? true
|
|
// : isBullish
|
|
// ? selectedDemand.Lower() < iZone.Lower()
|
|
// : selectedDemand.Upper() > iZone.Upper();
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// selectedDemand = iZone;
|
|
// }
|
|
|
|
// //
|
|
// has = selectedDemand != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// isBullish
|
|
// ? selectedDemand.Lower()
|
|
// : selectedDemand.Upper();
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// ZeroMemory(selectedDemand);
|
|
// }
|
|
|
|
//
|
|
// Support Zones ...
|
|
// has = workingZone.HasSupportZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCSupportZone *tmpZones[];
|
|
// Copy(
|
|
// workingZone.supportZones,
|
|
// tmpZones //
|
|
// );
|
|
// XCSupportZone *selectedSupport = NULL;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetLowest(tmpZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XCSupportZone *iZone = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// // Validate Zone ...
|
|
// has =
|
|
// isBullish
|
|
// ? IsBelowDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// )
|
|
// : IsAboveDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// );
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// has =
|
|
// selectedSupport == NULL
|
|
// ? true
|
|
// : isBullish
|
|
// ? selectedSupport.Lower() < iZone.Lower()
|
|
// : selectedSupport.Upper() > iZone.Upper();
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// selectedSupport = iZone;
|
|
|
|
// //
|
|
// }
|
|
|
|
// //
|
|
// has = selectedSupport != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL = isBullish
|
|
// ? selectedSupport.Lower()
|
|
// : selectedSupport.Upper();
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// ZeroMemory(selectedSupport);
|
|
// }
|
|
|
|
//
|
|
// Supply Zones ...
|
|
// has = workingZone.HasSupplyZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCSupplyZone *tmpZones[];
|
|
// Copy(
|
|
// workingZone.supplyZones,
|
|
// tmpZones //
|
|
// );
|
|
// XCSupplyZone *selectedSupply = NULL;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetHighest(tmpZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XCSupplyZone *iZone = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// // Validate Zone ...
|
|
// has =
|
|
// !isBullish
|
|
// ? IsAboveDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// )
|
|
// : IsBelowDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// );
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// has =
|
|
// selectedSupply == NULL
|
|
// ? true
|
|
// : !isBullish
|
|
// ? selectedSupply.Upper() > iZone.Upper()
|
|
// : selectedSupply.Lower() < iZone.Lower();
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// selectedSupply = iZone;
|
|
|
|
// //
|
|
// }
|
|
|
|
// //
|
|
// has = selectedSupply != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// !isBullish
|
|
// ? selectedSupply.Upper()
|
|
// : selectedSupply.Lower();
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// ZeroMemory(selectedSupply);
|
|
// }
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
// has = workingZone.HasDemandZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCResistanceZone *tmpZones[];
|
|
// Copy(
|
|
// workingZone.resistanceZones,
|
|
// tmpZones //
|
|
// );
|
|
// XCResistanceZone *selectedResistance = NULL;
|
|
|
|
// //
|
|
// while (HasChild(tmpZones))
|
|
// {
|
|
// //
|
|
// idx = GetHighest(tmpZones);
|
|
// has = IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// //
|
|
// XCResistanceZone *iZone = tmpZones[idx];
|
|
// ArrayRemove(
|
|
// tmpZones,
|
|
// idx,
|
|
// 1 //
|
|
// );
|
|
|
|
// //
|
|
// // Validate Zone ...
|
|
// has =
|
|
// !isBullish
|
|
// ? IsAboveDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// )
|
|
// : IsBelowDiff(
|
|
// iZone,
|
|
// selectedZone.ob,
|
|
// true // Ignore Inside ...
|
|
// );
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// has =
|
|
// selectedResistance == NULL
|
|
// ? true
|
|
// : !isBullish
|
|
// ? selectedResistance.Upper() < iZone.Upper()
|
|
// : selectedResistance.Lower() > iZone.Lower();
|
|
// if (!has)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// selectedResistance = iZone;
|
|
|
|
// //
|
|
// }
|
|
|
|
// //
|
|
// has = selectedResistance != NULL;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// double iSL =
|
|
// !isBullish
|
|
// ? selectedResistance.Upper()
|
|
// : selectedResistance.Lower();
|
|
// double iSLDiff = MathAbs(iSL - pivot);
|
|
// has =
|
|
// iSLDiff > 0 &&
|
|
// iSLDiff <= maxAllowedSLDistanceInPoint * points;
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// Add(
|
|
// iSL,
|
|
// sls //
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(tmpZones);
|
|
// ZeroMemory(selectedResistance);
|
|
// }
|
|
|
|
//
|
|
// Cleanp Resources ...
|
|
|
|
//
|
|
cBar.Clean();
|
|
// passedBar.Clean();
|
|
result = HasChild(sls);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Support Zones ...
|
|
// has = HasSupportZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// int removeIDXs[];
|
|
// count = CountSupportZones();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XCSupportZone *iZone = supportZones[i];
|
|
// ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH;
|
|
|
|
// //
|
|
// XBoxZone iBox;
|
|
// bool hasBox = ToBox(
|
|
// iBox,
|
|
// iZone //
|
|
// );
|
|
// if (!hasBox)
|
|
// {
|
|
// //
|
|
// iBox.Clean();
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// XOHCL passedBar;
|
|
// bool isBodyIn = false;
|
|
// bool isBodyOut = false;
|
|
|
|
// //
|
|
// // Check Activation ...
|
|
// bool isActivated = iZone.IsActivated(
|
|
// iDir,
|
|
// passedBar,
|
|
// isBodyIn,
|
|
// true,
|
|
// period //
|
|
// );
|
|
// if (isActivated)
|
|
// {
|
|
// //
|
|
// // AddRef(
|
|
// // iBox,
|
|
// // insideBoxes //
|
|
// // );
|
|
|
|
// //
|
|
// Add(
|
|
// i,
|
|
// removeIDXs //
|
|
// );
|
|
|
|
// //
|
|
// iBox.Clean();
|
|
// passedBar.Clean();
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// // Checking Breaked ...
|
|
// bool isBreaked = iZone.IsBreaked(
|
|
// iDir,
|
|
// passedBar,
|
|
// isBodyOut,
|
|
// false,
|
|
// true,
|
|
// period //
|
|
// );
|
|
// if (isBreaked)
|
|
// {
|
|
// // //
|
|
// // AddRef(
|
|
// // iBox,
|
|
// // breakedBoxes //
|
|
// // );
|
|
|
|
// //
|
|
// Add(
|
|
// i,
|
|
// removeIDXs //
|
|
// );
|
|
|
|
// //
|
|
// iBox.Clean();
|
|
// passedBar.Clean();
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// passedBar.Clean();
|
|
// }
|
|
|
|
// //
|
|
// count = ArraySize(removeIDXs);
|
|
// has = IsValidSize(count);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// CleanupArray(
|
|
// removeIDXs,
|
|
// supportZones //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// Clean(removeIDXs);
|
|
// }
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
// has = HasResistanceZones();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// int removeIDXs[];
|
|
// count = CountResistanceZones();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XCResistanceZone *iZone = resistanceZones[i];
|
|
// ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH;
|
|
|
|
// //
|
|
// XBoxZone iBox;
|
|
// bool hasBox = ToBox(
|
|
// iBox,
|
|
// iZone //
|
|
// );
|
|
// if (!hasBox)
|
|
// {
|
|
// //
|
|
// iBox.Clean();
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// XOHCL passedBar;
|
|
// bool isBodyIn = false;
|
|
// bool isBodyOut = false;
|
|
|
|
// //
|
|
// // Check Activation ...
|
|
// bool isActivated = iZone.IsActivated(
|
|
// iDir,
|
|
// passedBar,
|
|
// isBodyIn,
|
|
// true,
|
|
// period //
|
|
// );
|
|
// if (isActivated)
|
|
// {
|
|
// //
|
|
// // AddRef(
|
|
// // iBox,
|
|
// // insideBoxes //
|
|
// // );
|
|
|
|
// //
|
|
// Add(
|
|
// i,
|
|
// removeIDXs //
|
|
// );
|
|
|
|
// //
|
|
// iBox.Clean();
|
|
// passedBar.Clean();
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// // Checking Breaked ...
|
|
// bool isBreaked = iZone.IsBreaked(
|
|
// iDir,
|
|
// passedBar,
|
|
// isBodyOut,
|
|
// false,
|
|
// true,
|
|
// period //
|
|
// );
|
|
// if (isBreaked)
|
|
// {
|
|
// // //
|
|
// // AddRef(
|
|
// // iBox,
|
|
// // breakedBoxes //
|
|
// // );
|
|
|
|
// //
|
|
// Add(
|
|
// i,
|
|
// removeIDXs //
|
|
// );
|
|
|
|
// //
|
|
// iBox.Clean();
|
|
// passedBar.Clean();
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// passedBar.Clean();
|
|
// }
|
|
|
|
// //
|
|
// count = ArraySize(removeIDXs);
|
|
// has = IsValidSize(count);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// CleanupArray(
|
|
// removeIDXs,
|
|
// resistanceZones //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// Clean(removeIDXs);
|
|
// }
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Waiting Zone Detection ...
|
|
// XPOIState iState = mtfState;
|
|
|
|
//
|
|
// Detect Waiting Zones ...
|
|
|
|
// //
|
|
// // Using Order Blocks ...
|
|
// if (mUseOrderBlocks)
|
|
// {
|
|
// //
|
|
// has = iState.HasOrderBlocks();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XCOrderBlock *obs[];
|
|
// count = iState.FilterOrderBlocks(
|
|
// obs,
|
|
// period,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
|
|
// //
|
|
// has = IsValidSize(count);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// ToBox(
|
|
// obs,
|
|
// waitingBoxes //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// Clean(obs);
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Using Fair Value Gaps ...
|
|
// if (mUseFairValueGaps)
|
|
// {
|
|
// //
|
|
// has = iState.HasFairValueGaps();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// XBoxZone boxes[];
|
|
// XCFVG *fvgs[];
|
|
// count = iState.FilterFairValueGaps(
|
|
// fvgs,
|
|
// period,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
|
|
// //
|
|
// has = IsValidSize(count);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// count = ToBox(
|
|
// fvgs,
|
|
// boxes //
|
|
// );
|
|
|
|
// //
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XBoxZone iBox = boxes[i];
|
|
|
|
// //
|
|
// int idx = FindIndex(
|
|
// iBox,
|
|
// waitingBoxes //
|
|
// );
|
|
// has = !IsValidIndex(idx);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// iBox,
|
|
// waitingBoxes //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// iBox.Clean();
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// Clean(fvgs);
|
|
// Clean(boxes);
|
|
// }
|
|
// }
|
|
|
|
//
|
|
// Cleaning State ...
|
|
// iState.Clean();
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Waiting Box Detected ...
|
|
bool hasWaitingBoxes = hasWorkingZone &&
|
|
workingZone.HasWaitingBoxes();
|
|
if (hasWaitingBoxes)
|
|
{
|
|
//
|
|
XOHCL zBar;
|
|
XOHCL cBar;
|
|
XOHCL pBar;
|
|
int count = 0;
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
//
|
|
bool isInited = zBar.Init(
|
|
symbol,
|
|
period,
|
|
zIndex //
|
|
);
|
|
isInited =
|
|
isInited &&
|
|
zBar.GetPreviousBar(cBar);
|
|
isInited =
|
|
isInited &&
|
|
cBar.GetPreviousBar(pBar);
|
|
|
|
//
|
|
count = workingZone.CountWaitingBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = workingZone.waitingBoxes[i];
|
|
ENUM_X_DIRECTION iDir = iBox.dir;
|
|
bool isBullish = IsBullish(iDir);
|
|
|
|
//
|
|
// Check Price Rejection ...
|
|
|
|
//
|
|
bool hasBullishFiboPressure =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasFiboPressure(
|
|
cBar,
|
|
X_DIRECTION_BULLISH,
|
|
X_FIBO_LEVEL_382 //
|
|
);
|
|
|
|
//
|
|
bool hasBearishFiboPressure =
|
|
decisionCycleHelper
|
|
.mBarAnalyser
|
|
.HasFiboPressure(
|
|
cBar,
|
|
X_DIRECTION_BEARISH,
|
|
X_FIBO_LEVEL_382 //
|
|
);
|
|
|
|
//
|
|
// Bullish Rejection ...
|
|
bool isBullishRejected =
|
|
//
|
|
isInited &&
|
|
isBullish &&
|
|
cBar.low < pBar.low &&
|
|
zBar.low > iBox.upper &&
|
|
cBar.low <= iBox.upper &&
|
|
zBar.open > iBox.upper &&
|
|
hasBullishFiboPressure &&
|
|
cBar.GetLowShadow() > pBar.GetLowShadow()
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Rejection ...
|
|
bool isBearishhRejected =
|
|
//
|
|
isInited &&
|
|
!isBullish &&
|
|
cBar.high > pBar.high &&
|
|
zBar.open < iBox.lower &&
|
|
zBar.high < iBox.lower &&
|
|
hasBearishFiboPressure &&
|
|
cBar.high >= iBox.lower &&
|
|
cBar.GetHighShadow() > pBar.GetHighShadow()
|
|
//
|
|
;
|
|
|
|
//
|
|
has = isBullishRejected ||
|
|
isBearishhRejected;
|
|
if (has)
|
|
{
|
|
//
|
|
idx = i;
|
|
signalBox = iBox;
|
|
hasSignalBox = has;
|
|
signalBox.to = cTime;
|
|
signalBoxDir = iBox.dir;
|
|
isSignalBoxReversal = false;
|
|
provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE;
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
|
|
//
|
|
// Remove Signal Box from Waiting Boxes of
|
|
// Working Zone ...
|
|
if (hasSignalBox)
|
|
{
|
|
//
|
|
if (IsValidIndex(idx))
|
|
{
|
|
//
|
|
ArrayRemove(
|
|
workingZone.waitingBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Ignore Zone's Signals ...
|
|
hasSignalBox = false;
|
|
|
|
//
|
|
// Cleanup Resources ...
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
}
|
|
|
|
//
|
|
// Check Conditions if Has Inside Boxes ...
|
|
bool hasInsideBoxes = hasWorkingZone &&
|
|
workingZone.HasInsideBoxes();
|
|
if (hasInsideBoxes)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Check Conditions if has Breaked Boxes ...
|
|
bool hasBreakedBoxes = hasWorkingZone &&
|
|
workingZone.HasBreakedBoxes();
|
|
if (hasBreakedBoxes)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Checking Other Conditions ...
|
|
if (!hasSignalBox)
|
|
{
|
|
//
|
|
// Senari A ...
|
|
// hasSignalBox = hasWorkingZone &&
|
|
// workingZone.DetectSenarioASignalBox(
|
|
// signalBox,
|
|
// signalBoxDir,
|
|
// decisionXConditions,
|
|
// analyseXConditions,
|
|
// decisionCycleHelper,
|
|
// drawer,
|
|
// zIndex //
|
|
// );
|
|
// if (hasSignalBox)
|
|
// {
|
|
// //
|
|
// signalBox.to = cTime;
|
|
// isSignalBoxReversal = false;
|
|
// provider = X121SMC_XWZ_PROVIDER_PV_ZONE;
|
|
// }
|
|
|
|
// //
|
|
// // Validating Signal Box if Exists ...
|
|
// if (hasSignalBox)
|
|
// {
|
|
// //
|
|
// // Validate Signal Boxes using Inside Box ...
|
|
// if (hasInsideBoxes)
|
|
// {
|
|
// //
|
|
// int idx = -1;
|
|
// bool has = false;
|
|
|
|
// //
|
|
// idx =
|
|
// IsBullish(signalBoxDir)
|
|
// ? GetLowest(workingZone.insideBoxes)
|
|
// : GetHighest(workingZone.insideBoxes);
|
|
// has = IsValidIndex(idx);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// hasSignalBox =
|
|
// signalBoxDir == workingZone.insideBoxes[idx].dir;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Validate Signal Box Using Overal Trend ...
|
|
// if (hasWorkingZoneOveralDirection)
|
|
// {
|
|
// //
|
|
// hasSignalBox =
|
|
// signalBoxDir == wzOveralDir;
|
|
// }
|
|
// }
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Supply Zones ...
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
int removeIDXs[];
|
|
count = CountSupplyZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupplyZone *iZone = supplyZones[i];
|
|
ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH;
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
bool hasBox = ToBox(
|
|
iBox,
|
|
iZone //
|
|
);
|
|
if (!hasBox)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
XOHCL passedBar;
|
|
bool isBodyIn = false;
|
|
bool isBodyOut = false;
|
|
|
|
//
|
|
// Check Activation ...
|
|
bool isActivated = iZone.IsActivated(
|
|
iDir,
|
|
passedBar,
|
|
isBodyIn,
|
|
true,
|
|
period //
|
|
);
|
|
if (isActivated)
|
|
{
|
|
//
|
|
// AddRef(
|
|
// iBox,
|
|
// insideBoxes //
|
|
// );
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
passedBar.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Checking Breaked ...
|
|
bool isBreaked = iZone.IsBreaked(
|
|
iDir,
|
|
passedBar,
|
|
isBodyOut,
|
|
false,
|
|
true,
|
|
period //
|
|
);
|
|
if (isBreaked)
|
|
{
|
|
// //
|
|
// AddRef(
|
|
// iBox,
|
|
// breakedBoxes //
|
|
// );
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
passedBar.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
passedBar.Clean();
|
|
}
|
|
|
|
//
|
|
count = ArraySize(removeIDXs);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
removeIDXs,
|
|
supplyZones //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(removeIDXs);
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
int removeIDXs[];
|
|
count = CountDemandZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCDemandZone *iZone = demandZones[i];
|
|
ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH;
|
|
|
|
//
|
|
XBoxZone iBox;
|
|
bool hasBox = ToBox(
|
|
iBox,
|
|
iZone //
|
|
);
|
|
if (!hasBox)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
XOHCL passedBar;
|
|
bool isBodyIn = false;
|
|
bool isBodyOut = false;
|
|
|
|
//
|
|
// Check Activation ...
|
|
bool isActivated = iZone.IsActivated(
|
|
iDir,
|
|
passedBar,
|
|
isBodyIn,
|
|
true,
|
|
period //
|
|
);
|
|
if (isActivated)
|
|
{
|
|
//
|
|
// AddRef(
|
|
// iBox,
|
|
// insideBoxes //
|
|
// );
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
passedBar.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Checking Breaked ...
|
|
bool isBreaked = iZone.IsBreaked(
|
|
iDir,
|
|
passedBar,
|
|
isBodyOut,
|
|
false,
|
|
true,
|
|
period //
|
|
);
|
|
if (isBreaked)
|
|
{
|
|
// //
|
|
// AddRef(
|
|
// iBox,
|
|
// breakedBoxes //
|
|
// );
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
passedBar.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
passedBar.Clean();
|
|
}
|
|
|
|
//
|
|
count = ArraySize(removeIDXs);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
removeIDXs,
|
|
demandZones //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(removeIDXs);
|
|
}
|
|
|
|
//
|
|
// Update Boxes ...
|
|
|
|
//
|
|
// Waiting Boxes ...
|
|
has = HasWaitingBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
int removeIDXs[];
|
|
count = CountWaitingBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = waitingBoxes[i];
|
|
ENUM_X_DIRECTION iDir = iBox.dir;
|
|
bool isBullish = IsBullish(iDir);
|
|
|
|
//
|
|
bool isInside =
|
|
//
|
|
zBar.low < iBox.upper &&
|
|
zBar.low > iBox.lower
|
|
//
|
|
;
|
|
if (isInside)
|
|
{
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
|
|
//
|
|
bool isBreakedUpper =
|
|
//
|
|
cBar.low < iBox.upper &&
|
|
cBar.low > iBox.lower &&
|
|
zBar.low > iBox.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBreakedLower =
|
|
//
|
|
cBar.high > iBox.lower &&
|
|
cBar.high < iBox.upper &&
|
|
zBar.high < iBox.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBreaked =
|
|
(isBullish &&
|
|
isBreakedLower) ||
|
|
(!isBullish &&
|
|
isBreakedUpper);
|
|
|
|
//
|
|
if (isBreaked)
|
|
{
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
breakedBoxes //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
count = ArraySize(removeIDXs);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
removeIDXs,
|
|
waitingBoxes //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(removeIDXs);
|
|
}
|
|
|
|
//
|
|
// Inside Boxes ...
|
|
has = HasInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
int removeIDXs[];
|
|
count = CountInsideBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = insideBoxes[i];
|
|
ENUM_X_DIRECTION iDir = iBox.dir;
|
|
bool isBullish = IsBullish(iDir);
|
|
|
|
//
|
|
bool isBreakedUpper =
|
|
//
|
|
cBar.low < iBox.upper &&
|
|
cBar.low > iBox.lower &&
|
|
zBar.low > iBox.upper
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBreakedLower =
|
|
//
|
|
cBar.high > iBox.lower &&
|
|
cBar.high < iBox.upper &&
|
|
zBar.high < iBox.lower
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isBreaked =
|
|
(isBullish &&
|
|
isBreakedLower) ||
|
|
(!isBullish &&
|
|
isBreakedUpper);
|
|
|
|
//
|
|
if (isBreaked)
|
|
{
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
breakedBoxes //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
count = ArraySize(removeIDXs);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
removeIDXs,
|
|
insideBoxes //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(removeIDXs);
|
|
}
|
|
|
|
//
|
|
has = HasBreakedBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
int removeIDXs[];
|
|
count = CountBreakedBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = breakedBoxes[i];
|
|
ENUM_X_DIRECTION iDir = iBox.dir;
|
|
bool isBullish = IsBullish(iDir);
|
|
|
|
//
|
|
bool isInside = false;
|
|
|
|
//
|
|
if (isInside)
|
|
{
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
breakedInsideBoxes //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
i,
|
|
removeIDXs //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
count = ArraySize(removeIDXs);
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
removeIDXs,
|
|
breakedBoxes //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(removeIDXs);
|
|
}
|
|
|
|
//
|
|
// Update Waiting Boxes ...
|
|
|
|
//
|
|
XPOIState iState = mtfState;
|
|
|
|
//
|
|
// Use Order Blocks ...
|
|
if (mUseOrderBlocks)
|
|
{
|
|
//
|
|
has = iState.HasOrderBlocks();
|
|
if (has)
|
|
{
|
|
//
|
|
XCOrderBlock *obs[];
|
|
count = iState.FilterOrderBlocks(
|
|
obs,
|
|
period,
|
|
XZONE_STATE_PASSED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_IGNORED,
|
|
false //
|
|
);
|
|
|
|
//
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
// Try to Add new OBs into Waiting Zones ...
|
|
// if it's not exists ...
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
bool hasBox = ToBox(
|
|
iBox,
|
|
obs[i] //
|
|
);
|
|
if (!hasBox)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Index in Waiting Boxes ...
|
|
idx = FindIndex(
|
|
iBox,
|
|
waitingBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Index in Inside Boxes ...
|
|
idx = FindIndex(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Index in Breaked Boxes ...
|
|
idx = FindIndex(
|
|
iBox,
|
|
breakedBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
waitingBoxes //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(obs);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Use Fair Value Gaps ...
|
|
if (mUseFairValueGaps)
|
|
{
|
|
//
|
|
has = iState.HasFairValueGaps();
|
|
if (has)
|
|
{
|
|
//
|
|
XCFVG *fvgs[];
|
|
count = iState.FilterFairValueGaps(
|
|
fvgs,
|
|
period,
|
|
XZONE_STATE_PASSED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_FAILED,
|
|
false,
|
|
XZONE_STATE_IGNORED,
|
|
false //
|
|
);
|
|
|
|
//
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
bool hasBox = ToBox(
|
|
iBox,
|
|
fvgs[i] //
|
|
);
|
|
if (!hasBox)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Index in Waiting Boxes ...
|
|
idx = FindIndex(
|
|
iBox,
|
|
waitingBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Index in Inside Boxes ...
|
|
idx = FindIndex(
|
|
iBox,
|
|
insideBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Check Index in Breaked Boxes ...
|
|
idx = FindIndex(
|
|
iBox,
|
|
breakedBoxes //
|
|
);
|
|
has = !IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
AddRef(
|
|
iBox,
|
|
waitingBoxes //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
Clean(fvgs);
|
|
}
|
|
}
|
|
|
|
//
|
|
iState.Clean();
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Update Working Zone ...
|
|
// workingZone.Update(
|
|
// zIndex,
|
|
// visionState,
|
|
// consolidationState,
|
|
// analyseState,
|
|
// decisionState //
|
|
// );
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Supply Zones ...
|
|
if (drawSupplyZones)
|
|
{
|
|
//
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupplyZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupplyZoneObject *iObj;
|
|
isCreated = drawer.CreateSupplyZone(
|
|
supplyZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
if (drawDemandZones)
|
|
{
|
|
//
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountDemandZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCDemandZoneObject *iObj;
|
|
isCreated = drawer.CreateDemandZone(
|
|
demandZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Support Zones ...
|
|
if (drawSupportZones)
|
|
{
|
|
//
|
|
has = HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupportZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCSupportZoneObject *iObj;
|
|
isCreated = drawer.CreateSupportZone(
|
|
supportZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
if (drawResistanceZones)
|
|
{
|
|
//
|
|
has = HasResistanceZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountResistanceZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XCResistanceZoneObject *iObj;
|
|
isCreated = drawer.CreateResistanceZone(
|
|
resistanceZones[i],
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
// Waiting Boxes ...
|
|
if (drawWaitingBoxes)
|
|
{
|
|
//
|
|
has = HasWaitingBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountWaitingBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = waitingBoxes[i];
|
|
|
|
//
|
|
XCBoxObject *iObj;
|
|
bool isCreated = drawer.DrawBox(
|
|
iBox,
|
|
iObj //
|
|
);
|
|
|
|
//
|
|
if (isCreated)
|
|
{
|
|
mWorkingZoneObjects.Add(iObj);
|
|
}
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Inside Boxes ...
|
|
if (drawInsideBoxes)
|
|
{
|
|
//
|
|
has = HasInsideBoxes();
|
|
if (has)
|
|
{
|
|
}
|
|
}
|
|
|
|
//
|
|
// Breaked Boxes ...
|
|
if (drawBreakedBoxes)
|
|
{
|
|
//
|
|
has = HasBreakedBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
}
|
|
}
|
|
|
|
//
|
|
// Breaked Inside Boxes ...
|
|
if (drawBreakedInsideBoxes)
|
|
{
|
|
//
|
|
has = HasBreakedInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountBreakedInsideBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
XBoxZone iBox = breakedInsideBoxes[i];
|
|
XCBoxObject *iObj;
|
|
has = drawer.DrawBox(
|
|
iBox,
|
|
iObj //
|
|
);
|
|
if (has)
|
|
{
|
|
//
|
|
iObj.BoxWidth(1);
|
|
mBreakedInsideZoneObjects.Add(iObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
XCSupplyZone *supplyZone;
|
|
XCDemandZone *demandZone;
|
|
|
|
//
|
|
XCSupplyZone *supplyZones[];
|
|
XCDemandZone *demandZones[];
|
|
|
|
//
|
|
XCSupportZone *supportZones[];
|
|
XCResistanceZone *resistanceZones[];
|
|
|
|
//
|
|
XBoxZone insideBoxes[];
|
|
XBoxZone breakedBoxes[];
|
|
XBoxZone waitingBoxes[];
|
|
XBoxZone breakedInsideBoxes[];
|
|
XConsolidationZone consolidationZones[];
|
|
|
|
//
|
|
bool mUseSupDems;
|
|
bool mUseOrderBlocks;
|
|
bool mUseFairValueGaps;
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
// //
|
|
// // Supply Zones ...
|
|
// has = HasSupplyZones();
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// count = mtfState.FilterSupplyZones(
|
|
// supplyZones,
|
|
// period,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// // Demand Zones ...
|
|
// has = HasDemandZones();
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// count = mtfState.FilterDemandZones(
|
|
// demandZones,
|
|
// period,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
// }
|
|
|
|
//
|
|
// Support Zones ...
|
|
// has = HasSupportZones();
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// count = mtfState.FilterSupportZones(
|
|
// supportZones,
|
|
// period,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
// }
|
|
|
|
//
|
|
// Resistance Zones ...
|
|
// has = HasResistanceZones();
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// count = mtfState.FilterResistanceZones(
|
|
// resistanceZones,
|
|
// period,
|
|
// XZONE_STATE_PASSED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_FAILED,
|
|
// false,
|
|
// XZONE_STATE_IGNORED,
|
|
// false //
|
|
// );
|
|
// }
|
|
|
|
//
|
|
// Update Exists Zones ...
|
|
|
|
//
|
|
// Supply Zones ...
|
|
has = mtfState.HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCSupplyZone *zone;
|
|
idx = GetYoungest(mtfState.supplyZones);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
zone = mtfState.supplyZones[idx];
|
|
has = IsSupplyExists(zone);
|
|
if (!has)
|
|
{
|
|
//
|
|
Add(
|
|
zone,
|
|
supplyZones //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
ZeroMemory(zone);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
has = mtfState.HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XCDemandZone *zone;
|
|
idx = GetYoungest(mtfState.demandZones);
|
|
has = IsValidIndex(idx);
|
|
if (has)
|
|
{
|
|
//
|
|
zone = mtfState.demandZones[idx];
|
|
has = IsDemandExists(zone);
|
|
if (!has)
|
|
{
|
|
//
|
|
Add(
|
|
zone,
|
|
demandZones //
|
|
);
|
|
}
|
|
else
|
|
{
|
|
ZeroMemory(zone);
|
|
}
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
bool IsExists(XBoxZone &box)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = box.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
bool has = false;
|
|
|
|
//
|
|
// Checking Index Waiting Box ...
|
|
has = HasWaitingBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
box,
|
|
waitingBoxes //
|
|
);
|
|
result = !IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Checking Index Inside Boxes ...
|
|
has = HasInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
box,
|
|
insideBoxes //
|
|
);
|
|
result = !IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Checking Index Breaked Boxes ...
|
|
has = HasBreakedBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
box,
|
|
breakedBoxes //
|
|
);
|
|
result = !IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Checking Index BreakedInside Boxes ...
|
|
has = HasBreakedInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
idx = FindIndex(
|
|
box,
|
|
breakedInsideBoxes //
|
|
);
|
|
result = !IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool IsSupplyExists(XCSupplyZone *zone)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = zone != NULL &&
|
|
zone.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Converts Zone to Box ...
|
|
XBoxZone box;
|
|
result = ToBox(
|
|
box,
|
|
zone //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Checking Index in SupplyZones ...
|
|
int idx = FindIndex(
|
|
zone,
|
|
supplyZones //
|
|
);
|
|
result = !IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsExists(box);
|
|
|
|
//
|
|
box.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool IsDemandExists(XCDemandZone *zone)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = zone != NULL &&
|
|
zone.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Converts Zone to Box ...
|
|
XBoxZone box;
|
|
result = ToBox(
|
|
box,
|
|
zone //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Checking Index in SupplyZones ...
|
|
int idx = FindIndex(
|
|
zone,
|
|
demandZones //
|
|
);
|
|
result = !IsValidIndex(idx);
|
|
if (!result)
|
|
{
|
|
//
|
|
box.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsExists(box);
|
|
|
|
//
|
|
box.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
Clean(supplyZones);
|
|
Clean(demandZones);
|
|
|
|
//
|
|
Clean(insideBoxes);
|
|
Clean(breakedBoxes);
|
|
Clean(waitingBoxes);
|
|
|
|
//
|
|
Clean(supportZones);
|
|
Clean(resistanceZones);
|
|
|
|
//
|
|
mUseSupDems = false;
|
|
mUseOrderBlocks = true;
|
|
mUseFairValueGaps = true;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
bool HasInsideBox(
|
|
XBoxZone &box //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
int index = -1;
|
|
|
|
//
|
|
result = box.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
has = HasWaitingBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
result = HasInsideBox(
|
|
index,
|
|
box,
|
|
waitingBoxes //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Supply Zones ...
|
|
if (!result)
|
|
{
|
|
//
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XBoxZone tmpBoxes[];
|
|
count = ToBox(
|
|
supplyZones,
|
|
tmpBoxes //
|
|
);
|
|
|
|
//
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
result = HasInsideBox(
|
|
index,
|
|
box,
|
|
tmpBoxes //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Demand Zones ...
|
|
if (!result)
|
|
{
|
|
//
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
XBoxZone tmpBoxes[];
|
|
count = ToBox(
|
|
demandZones,
|
|
tmpBoxes //
|
|
);
|
|
|
|
//
|
|
has = IsValidSize(count);
|
|
if (has)
|
|
{
|
|
//
|
|
result = HasInsideBox(
|
|
index,
|
|
box,
|
|
tmpBoxes //
|
|
);
|
|
}
|
|
|
|
//
|
|
Clean(tmpBoxes);
|
|
}
|
|
}
|
|
|
|
//
|
|
result = IsValidIndex(index);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool DetectSenarioASignalBox(
|
|
XBoxZone &signalBox,
|
|
ENUM_X_DIRECTION &signalDir,
|
|
X121Conditions &decisionXConditions,
|
|
X121Conditions &analyseXConditions,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
XCPOIDrawer *drawer = NULL,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
signalBox.Clean();
|
|
signalDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
result = decisionCycleHelper != NULL;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
double decisionBullishScore = 0;
|
|
double decisionBearishScore = 0;
|
|
decisionXConditions.GenerateScore(
|
|
decisionBullishScore,
|
|
decisionBearishScore //
|
|
);
|
|
|
|
//
|
|
// Analyse ...
|
|
double analyseBullishScore = 0;
|
|
double analyseBearishScore = 0;
|
|
analyseXConditions.GenerateScore(
|
|
analyseBullishScore,
|
|
analyseBearishScore //
|
|
);
|
|
|
|
//
|
|
// Score Conditions ...
|
|
double scoreMultiplier = 3;
|
|
bool isBullishScorePassed =
|
|
//
|
|
analyseBullishScore > (analyseBearishScore * scoreMultiplier) &&
|
|
decisionBullishScore > (decisionBearishScore * scoreMultiplier)
|
|
//
|
|
;
|
|
bool isBearishScorePassed =
|
|
//
|
|
analyseBearishScore > (analyseBullishScore * scoreMultiplier) &&
|
|
decisionBearishScore > (decisionBullishScore * scoreMultiplier)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Checking Other Conditions
|
|
|
|
//
|
|
bool isCommonBullish =
|
|
//
|
|
decisionXConditions.isSarBullish &&
|
|
decisionXConditions.isStrBullish &&
|
|
decisionXConditions.isCheBullish &&
|
|
decisionXConditions.isSMHKBullish &&
|
|
decisionXConditions.isRawHKBullish &&
|
|
decisionXConditions.isRawHKClosedOverSMHK
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCommonBearish =
|
|
//
|
|
decisionXConditions.isSarBearish &&
|
|
decisionXConditions.isStrBearish &&
|
|
decisionXConditions.isCheBearish &&
|
|
decisionXConditions.isSMHKBearish &&
|
|
decisionXConditions.isRawHKBearish &&
|
|
decisionXConditions.isRawHKClosedUnderSMHK
|
|
//
|
|
;
|
|
|
|
//
|
|
// X3Ma ...
|
|
|
|
//
|
|
// X3Ma Bullish ...
|
|
bool isX3MaBullish =
|
|
//
|
|
decisionXConditions.isX3MaBullishState &&
|
|
decisionXConditions.isX3MaSwitchedToBullishOrdered &&
|
|
decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1]
|
|
//
|
|
;
|
|
|
|
//
|
|
// X3Ma Bearish ...
|
|
bool isX3MaBearish =
|
|
//
|
|
decisionXConditions.isX3MaBearishState &&
|
|
decisionXConditions.isX3MaSwitchedToBearishOrdered &&
|
|
decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1]
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isX3MaHasCondition =
|
|
(isX3MaBullish &&
|
|
isCommonBullish &&
|
|
isBullishScorePassed) ||
|
|
(isX3MaBearish &&
|
|
isCommonBearish &&
|
|
isBearishScorePassed);
|
|
|
|
//
|
|
// VWap ...
|
|
|
|
//
|
|
// VWap Bullish ...
|
|
bool isVWapBullish =
|
|
//
|
|
decisionXConditions.isVWapBullishState &&
|
|
decisionXConditions.isVWapSwitchedToBullishOrdered &&
|
|
decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1]
|
|
//
|
|
;
|
|
|
|
//
|
|
// VWap Bearish ...
|
|
bool isVWapBearish =
|
|
//
|
|
decisionXConditions.isVWapBearishState &&
|
|
decisionXConditions.isVWapSwitchedToBearishOrdered &&
|
|
decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1]
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isVWapHasCondition =
|
|
(isVWapBullish &&
|
|
isBullishScorePassed) ||
|
|
(isVWapBearish &&
|
|
isBearishScorePassed);
|
|
|
|
//
|
|
// Senario ....
|
|
// - a vale Under X3MA Slow when X3MA Bullish Ordered ...
|
|
|
|
//
|
|
bool isX3MASenarioBBullish =
|
|
//
|
|
decisionXConditions.isX3MaBullishOrdered &&
|
|
decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] &&
|
|
decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2]
|
|
//
|
|
;
|
|
if (isX3MASenarioBBullish)
|
|
{
|
|
}
|
|
|
|
//
|
|
bool isX3MASenarioBBearish =
|
|
//
|
|
decisionXConditions.isX3MaBearishOrdered &&
|
|
decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] &&
|
|
decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2]
|
|
//
|
|
;
|
|
if (isX3MASenarioBBearish)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Checking Other Conditions XWZ Reject on EMA 20 ...
|
|
|
|
//
|
|
// Check Has Conditions ...
|
|
bool hasXConditions =
|
|
(isX3MaHasCondition ||
|
|
isVWapHasCondition);
|
|
|
|
//
|
|
result = hasXConditions;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (isX3MaHasCondition)
|
|
{
|
|
//
|
|
signalDir =
|
|
isX3MaBullish
|
|
? X_DIRECTION_BULLISH
|
|
: isX3MaBearish
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_NONE;
|
|
}
|
|
|
|
//
|
|
if (isVWapHasCondition)
|
|
{
|
|
//
|
|
signalDir =
|
|
isVWapBullish
|
|
? X_DIRECTION_BULLISH
|
|
: isVWapBearish
|
|
? X_DIRECTION_BEARISH
|
|
: X_DIRECTION_NONE;
|
|
}
|
|
|
|
//
|
|
// Creating SignalBox ...
|
|
|
|
//
|
|
// Detect Box based on PV ...
|
|
bool hasSignalBox = decisionCycleHelper.GeneratePVBox(
|
|
signalBox,
|
|
barIndex //
|
|
);
|
|
|
|
//
|
|
result =
|
|
hasSignalBox &&
|
|
signalDir == signalBox.dir;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
XCBoxObject *iObj;
|
|
bool isCreated = drawer.DrawBox(
|
|
signalBox,
|
|
iObj //
|
|
);
|
|
if (isCreated)
|
|
{
|
|
//
|
|
iObj.BoxWidth(1);
|
|
iObj.BoxColor(clrYellow);
|
|
iObj.BoxStyle(STYLE_SOLID);
|
|
}
|
|
|
|
//
|
|
Print("Senario A ...");
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool DetetctSenarioBSignalBox(
|
|
XBoxZone &signalBox,
|
|
ENUM_X_DIRECTION &signalDir,
|
|
X121Conditions &decisionXConditions,
|
|
X121Conditions &analyseXConditions,
|
|
XC121SMCCycleHelper *decisionCycleHelper,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
signalBox.Clean();
|
|
signalDir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
result = decisionCycleHelper != NULL;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Decision ...
|
|
double decisionBullishScore = 0;
|
|
double decisionBearishScore = 0;
|
|
decisionXConditions.GenerateScore(
|
|
decisionBullishScore,
|
|
decisionBearishScore //
|
|
);
|
|
|
|
//
|
|
// Analyse ...
|
|
double analyseBullishScore = 0;
|
|
double analyseBearishScore = 0;
|
|
analyseXConditions.GenerateScore(
|
|
analyseBullishScore,
|
|
analyseBearishScore //
|
|
);
|
|
|
|
//
|
|
// Score Conditions ...
|
|
double scoreMultiplier = 3;
|
|
bool isBullishScorePassed =
|
|
//
|
|
analyseBullishScore > (analyseBearishScore * scoreMultiplier) &&
|
|
decisionBullishScore > (decisionBearishScore * scoreMultiplier)
|
|
//
|
|
;
|
|
bool isBearishScorePassed =
|
|
//
|
|
analyseBearishScore > (analyseBullishScore * scoreMultiplier) &&
|
|
decisionBearishScore > (decisionBullishScore * scoreMultiplier)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Senario ....
|
|
// - a vale Under X3MA Slow when X3MA Bullish Ordered ...
|
|
|
|
//
|
|
bool isX3MASenarioBBullish =
|
|
//
|
|
decisionXConditions.isX3MaBullishOrdered &&
|
|
decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] &&
|
|
decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2]
|
|
//
|
|
;
|
|
if (isX3MASenarioBBullish)
|
|
{
|
|
}
|
|
|
|
//
|
|
bool isX3MASenarioBBearish =
|
|
//
|
|
decisionXConditions.isX3MaBearishOrdered &&
|
|
decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] &&
|
|
decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2]
|
|
//
|
|
;
|
|
if (isX3MASenarioBBearish)
|
|
{
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool HasSupplyZones()
|
|
{
|
|
return HasChild(supplyZones);
|
|
}
|
|
|
|
//
|
|
int CountSupplyZones()
|
|
{
|
|
return ArraySize(supplyZones);
|
|
}
|
|
|
|
//
|
|
bool HasDemandZones()
|
|
{
|
|
return HasChild(demandZones);
|
|
}
|
|
|
|
//
|
|
int CountDemandZones()
|
|
{
|
|
return ArraySize(demandZones);
|
|
}
|
|
|
|
//
|
|
bool HasSupportZones()
|
|
{
|
|
return HasChild(supportZones);
|
|
}
|
|
|
|
//
|
|
int CountSupportZones()
|
|
{
|
|
return ArraySize(supportZones);
|
|
}
|
|
|
|
//
|
|
bool HasResistanceZones()
|
|
{
|
|
return HasChild(resistanceZones);
|
|
}
|
|
|
|
//
|
|
int CountResistanceZones()
|
|
{
|
|
return ArraySize(resistanceZones);
|
|
}
|
|
|
|
//
|
|
bool HasConsolidationZones()
|
|
{
|
|
return HasChild(consolidationZones);
|
|
}
|
|
|
|
//
|
|
int CountConsolidationZones()
|
|
{
|
|
return ArraySize(consolidationZones);
|
|
}
|
|
|
|
//
|
|
bool HasWaitingBoxes()
|
|
{
|
|
return HasChild(waitingBoxes);
|
|
}
|
|
|
|
//
|
|
int CountWaitingBoxes()
|
|
{
|
|
return ArraySize(waitingBoxes);
|
|
}
|
|
|
|
//
|
|
bool HasInsideBoxes()
|
|
{
|
|
return HasChild(insideBoxes);
|
|
}
|
|
|
|
//
|
|
int CountInsideBoxes()
|
|
{
|
|
return ArraySize(insideBoxes);
|
|
}
|
|
|
|
//
|
|
bool HasBreakedBoxes()
|
|
{
|
|
return HasChild(breakedBoxes);
|
|
}
|
|
|
|
//
|
|
int CountBreakedBoxes()
|
|
{
|
|
return ArraySize(breakedBoxes);
|
|
}
|
|
|
|
//
|
|
bool HasBreakedInsideBoxes()
|
|
{
|
|
return HasChild(breakedInsideBoxes);
|
|
}
|
|
|
|
//
|
|
int CountBreakedInsideBoxes()
|
|
{
|
|
return ArraySize(breakedInsideBoxes);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
has = ttfState.HasConsolidationZones();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
ttfState.consolidationZones,
|
|
consolidationZones //
|
|
);
|
|
CleanupArray(
|
|
consolidationZones,
|
|
50 //
|
|
);
|
|
}
|
|
|
|
//
|
|
has = HasSupplyZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupplyZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
supplyZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasDemandZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountDemandZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
demandZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasSupportZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountSupportZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
supportZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasResistanceZones();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountResistanceZones();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
resistanceZones[i].To(value);
|
|
}
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
|
|
//
|
|
has = HasWaitingBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
count = ArraySize(waitingBoxes);
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
waitingBoxes[i].to = value;
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountInsideBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
insideBoxes[i].to = value;
|
|
}
|
|
}
|
|
|
|
//
|
|
has = HasBreakedBoxes();
|
|
if (has)
|
|
{
|
|
}
|
|
|
|
//
|
|
has = HasBreakedInsideBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
count = CountBreakedInsideBoxes();
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
breakedInsideBoxes[i].to = value;
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
XBoxZone waitingBoxes[];
|
|
has = workingZone.HasWaitingBoxes();
|
|
if (has)
|
|
{
|
|
//
|
|
Copy(
|
|
workingZone.waitingBoxes,
|
|
waitingBoxes //
|
|
);
|
|
|
|
//
|
|
while (HasChild(waitingBoxes))
|
|
{
|
|
//
|
|
XBoxZone iBox;
|
|
idx = GetYoungest(waitingBoxes);
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
//
|
|
iBox.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
iBox = waitingBoxes[idx];
|
|
ArrayRemove(
|
|
waitingBoxes,
|
|
idx,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
bool hasInside = workingZone.HasInsideBox(iBox);
|
|
if (!hasInside)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
double iTarget =
|
|
IsBullish(signalBoxDir)
|
|
? iBox.lower
|
|
: iBox.upper;
|
|
|
|
//
|
|
Add(
|
|
iTarget,
|
|
targets //
|
|
);
|
|
|
|
//
|
|
iBox.Clean();
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
void Update(
|
|
int barIndex,
|
|
XPOIState &htfState,
|
|
XPOIState &mtfState,
|
|
XPOIState &stfState,
|
|
XPOIState &ttfState //
|
|
)
|
|
{
|
|
//
|
|
int idx = -1;
|
|
int count = 0;
|
|
bool has = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
has =
|
|
//
|
|
IsValid() &&
|
|
//
|
|
htfState.IsValid() &&
|
|
mtfState.IsValid() &&
|
|
stfState.IsValid() &&
|
|
//
|
|
htfState.HasChild() &&
|
|
mtfState.HasChild() &&
|
|
stfState.HasChild()
|
|
//
|
|
;
|
|
if (!has)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XOHCL zBar;
|
|
has = zBar.Init(
|
|
symbol,
|
|
period,
|
|
barIndex //
|
|
);
|
|
if (!has)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
return;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
has = zBar.GetPreviousBar(cBar);
|
|
if (!has)
|
|
{
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
|
|
//
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Cleanup Resource ...
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
int ExtractOBFVGs(
|
|
XOBFVG &dest[],
|
|
XPOIState &obState,
|
|
XPOIState &fvgState,
|
|
//
|
|
ENUM_X_OBFVG_FVG_FILTERS filterFVGs = X_OBFVG_FVG_FILTER_INSIDE_OR,
|
|
ENUM_X_OBFVG_FVG_SELECTION selectFVG = X_OBFVG_FVG_SELECT_OLDEST,
|
|
//
|
|
ENUM_TIMEFRAMES forPeriod = NULL,
|
|
//
|
|
// Start ...
|
|
ENUM_XZONE_STATE startState = XZONE_STATE_PASSED,
|
|
bool forceStartedBodyOut = false,
|
|
//
|
|
// Activation ...
|
|
ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED,
|
|
bool forceActivatedBodyIn = false,
|
|
//
|
|
// Breaktion ...
|
|
ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED,
|
|
bool forceBreakedBodyOut = false,
|
|
//
|
|
// Works ...
|
|
ENUM_XZONE_STATE workState = XZONE_STATE_IGNORED,
|
|
bool forceWorkedBodyOut = false //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
bool has = false;
|
|
|
|
//
|
|
Clean(dest);
|
|
|
|
//
|
|
has = obState.IsValid() &&
|
|
fvgState.IsValid() &&
|
|
obState.HasChild() &&
|
|
fvgState.HasChild() &&
|
|
selectFVG != X_OBFVG_FVG_SELECT_NONE &&
|
|
filterFVGs != X_OBFVG_FVG_FILTER_NONE;
|
|
if (!has)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XCOrderBlock *obs[];
|
|
int obsCount = obState.FilterOrderBlocks(
|
|
obs,
|
|
forPeriod,
|
|
startState,
|
|
forceStartedBodyOut,
|
|
activeState,
|
|
forceActivatedBodyIn,
|
|
breakState,
|
|
forceBreakedBodyOut,
|
|
workState,
|
|
forceWorkedBodyOut //
|
|
);
|
|
has = IsValidSize(obsCount);
|
|
if (!has)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XCFVG *fvgs[];
|
|
int fvgsCount = fvgState.FilterFairValueGaps(
|
|
fvgs,
|
|
forPeriod,
|
|
startState,
|
|
forceStartedBodyOut,
|
|
activeState,
|
|
forceActivatedBodyIn,
|
|
breakState,
|
|
forceBreakedBodyOut,
|
|
workState,
|
|
forceWorkedBodyOut //
|
|
);
|
|
has = IsValidSize(fvgsCount);
|
|
if (!has)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < obsCount; i++)
|
|
{
|
|
//
|
|
XCOrderBlock *iOB = obs[i];
|
|
XCFVG *iFVG = NULL;
|
|
|
|
//
|
|
ENUM_X_DIRECTION iOBDir = iOB.GetDirection();
|
|
bool isIOBBullish = IsBullish(iOBDir);
|
|
|
|
//
|
|
XCFVG *iFVGs[];
|
|
for (int j = 0; j < fvgsCount; j++)
|
|
{
|
|
//
|
|
XCFVG *jFVG = fvgs[j];
|
|
ENUM_X_DIRECTION jFVGDir = jFVG.GetDirection();
|
|
|
|
//
|
|
bool isSameDir = iOBDir == jFVGDir;
|
|
bool isFromPassed = jFVG.From() >= iOB.From();
|
|
bool isInsideOr = IsInsideOrDiff(
|
|
jFVG,
|
|
iOB //
|
|
);
|
|
bool isAbove = IsAboveDiff(
|
|
jFVG,
|
|
iOB,
|
|
true //
|
|
);
|
|
bool isBelow = IsBelowDiff(
|
|
jFVG,
|
|
iOB,
|
|
true //
|
|
);
|
|
|
|
//
|
|
bool isFilterPassed =
|
|
filterFVGs == X_OBFVG_FVG_FILTER_ABOVE_BELOW
|
|
? isIOBBullish
|
|
? isAbove
|
|
: isBelow
|
|
: filterFVGs == X_OBFVG_FVG_FILTER_INSIDE_OR
|
|
? isInsideOr
|
|
: false;
|
|
|
|
//
|
|
has =
|
|
isSameDir &&
|
|
isFromPassed &&
|
|
isFilterPassed;
|
|
if (has)
|
|
{
|
|
//
|
|
Add(
|
|
jFVG,
|
|
iFVGs //
|
|
);
|
|
}
|
|
}
|
|
has = HasChild(iFVGs);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int idx = -1;
|
|
idx = selectFVG == X_OBFVG_FVG_SELECT_OLDEST
|
|
? GetOldest(iFVGs)
|
|
: selectFVG == X_OBFVG_FVG_SELECT_YOUNGEST
|
|
? GetYoungest(iFVGs)
|
|
: selectFVG == X_OBFVG_FVG_SELECT_HIGHEST_LOWEST
|
|
? isIOBBullish
|
|
? GetHighest(iFVGs)
|
|
: GetLowest(iFVGs)
|
|
: selectFVG == X_OBFVG_FVG_SELECT_LOWEST_HIGHEST
|
|
? isIOBBullish
|
|
? GetLowest(iFVGs)
|
|
: GetHighest(iFVGs)
|
|
: selectFVG == X_OBFVG_FVG_SELECT_LOWEST
|
|
? GetLowest(iFVGs)
|
|
: selectFVG == X_OBFVG_FVG_SELECT_HIGHEST
|
|
? GetHighest(iFVGs)
|
|
: -1;
|
|
|
|
//
|
|
has = IsValidIndex(idx);
|
|
if (!has)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
iFVG = iFVGs[idx];
|
|
Clean(iFVGs);
|
|
|
|
//
|
|
XOBFVG iOBFVG;
|
|
iOBFVG.ob = iOB;
|
|
iOBFVG.fvg = iFVG;
|
|
|
|
//
|
|
has = iOBFVG.IsValid();
|
|
if (!has)
|
|
{
|
|
//
|
|
iOBFVG.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
AddRef(
|
|
iOBFVG,
|
|
dest //
|
|
);
|
|
|
|
//
|
|
iOBFVG.Clean();
|
|
}
|
|
|
|
//
|
|
result = ArraySize(dest);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// XCBaseObject *obObject;
|
|
// bool isCreated = drawer.CreateOrderBlock(
|
|
// obFVG.ob,
|
|
// obObject //
|
|
// );
|
|
|
|
// //
|
|
// count = obFVG.CountFVGs();
|
|
// for (int i = 0; i < count; i++)
|
|
// {
|
|
// //
|
|
// XCBaseObject *fvgObject;
|
|
// isCreated = drawer.CreateFairValueGap(
|
|
// obFVG.fvgs[i],
|
|
// fvgObject //
|
|
// );
|
|
// }
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Detect OB FVG ...
|
|
// result =
|
|
// hasNewOrderBlock &&
|
|
// hasNewFairValueGap &&
|
|
// ob.GetDirection() == fvg.GetDirection();
|
|
// if (result)
|
|
// {
|
|
// //
|
|
// obFVG.ob = ob;
|
|
// obFVG.AddFVG(fvg);
|
|
|
|
// //
|
|
// has = obFVG.IsValid();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// has = IsExists(obFVG);
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// // New Waiting Zone ...
|
|
// AddRef(
|
|
// obFVG,
|
|
// waitingZones //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Check Item Is not Exists ...
|
|
// idx = FindIndex(
|
|
// obFVG,
|
|
// waitingZones //
|
|
// );
|
|
// has = !IsValidIndex(idx);
|
|
// if (!has)
|
|
// {
|
|
// //
|
|
// // Update Exists Waiting Zone ...
|
|
// waitingZones[idx].AddFVG(fvg);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// XCFVG *decisionFVG;
|
|
// bool hasNewDecisionFVG =
|
|
// Contains(
|
|
// X_BULLISH_FVG_DETECTED,
|
|
// provider
|
|
// .decisionPoiEvents //
|
|
// ) ||
|
|
// Contains(
|
|
// X_BEARISH_FVG_DETECTED,
|
|
// provider
|
|
// .decisionPoiEvents //
|
|
// );
|
|
// if (hasNewDecisionFVG)
|
|
// {
|
|
// //
|
|
// idx = GetYoungest(provider
|
|
// .decisionState
|
|
// .fairValueGaps //
|
|
// );
|
|
// has = IsValidIndex(idx);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// decisionFVG = provider
|
|
// .decisionState
|
|
// .fairValueGaps[idx];
|
|
|
|
// //
|
|
// XCBaseObject *iObj;
|
|
// bool isCreated = drawer.CreateFairValueGap(
|
|
// decisionFVG,
|
|
// iObj //
|
|
// );
|
|
|
|
// //
|
|
// if (isCreated)
|
|
// {
|
|
// Print("New Fair Value Gap ...");
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
//
|
|
// Detect SupDem FVG ...
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// result = hasNewFairValueGap &&
|
|
// (hasNewSupply ||
|
|
// hasNewDemand);
|
|
// if (result)
|
|
// {
|
|
// //
|
|
// // Converts Supply or Demand Zone to OrderBlock ...
|
|
// XOHCL bar;
|
|
// ob = new XCOrderBlock();
|
|
// if (hasNewSupply)
|
|
// {
|
|
// //
|
|
// has = supply.FillBar(bar);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// has = ob.Init(
|
|
// bar,
|
|
// X_DIRECTION_BEARISH //
|
|
// );
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// ob.Upper(supply.Upper());
|
|
// ob.Lower(supply.Lower());
|
|
// }
|
|
// }
|
|
// }
|
|
// else if (hasNewDemand)
|
|
// {
|
|
// //
|
|
// has = demand.FillBar(bar);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// has = ob.Init(
|
|
// bar,
|
|
// X_DIRECTION_BULLISH //
|
|
// );
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// ob.Upper(demand.Upper());
|
|
// ob.Lower(demand.Lower());
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// obFVG.ob = ob;
|
|
// obFVG.AddFVG(fvg);
|
|
|
|
// //
|
|
// has = obFVG.IsValid();
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// // Check Item Is not Exists ...
|
|
// idx = FindIndex(
|
|
// obFVG,
|
|
// waitingZones //
|
|
// );
|
|
// has = !IsValidIndex(idx);
|
|
// if (has)
|
|
// {
|
|
// //
|
|
// // New Waiting Zone ...
|
|
// AddRef(
|
|
// obFVG,
|
|
// waitingZones //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Update Exists Waiting Zone ...
|
|
// waitingZones[idx].AddFVG(fvg);
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// bar.Clean();
|
|
// }
|
|
// }
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
bool IsValidZone(
|
|
XOHCL &invalidBar,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
invalidBar.Clean();
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XCFVG *fvg;
|
|
result = GetMainFVG(fvg);
|
|
if (!result)
|
|
{
|
|
//
|
|
ZeroMemory(fvg);
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL startedBar;
|
|
bool isBodyOut = false;
|
|
result = fvg.IsStarted(
|
|
fvg.GetDirection(),
|
|
startedBar,
|
|
isBodyOut //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
ZeroMemory(fvg);
|
|
startedBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL bar;
|
|
bool isBullish = fvg.IsBullish();
|
|
|
|
//
|
|
int fromIndex = iBarShift(
|
|
fvg.GetSymbol(),
|
|
fvg.GetPeriod(),
|
|
startedBar.NextAt() //
|
|
);
|
|
result = IsValidIndex(fromIndex);
|
|
if (!result)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
ZeroMemory(fvg);
|
|
startedBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isInited = false;
|
|
for (int i = barIndex; i < fromIndex; i++)
|
|
{
|
|
//
|
|
isInited = bar.Init(
|
|
fvg.GetSymbol(),
|
|
fvg.GetPeriod(),
|
|
i //
|
|
);
|
|
if (!isInited)
|
|
{
|
|
//
|
|
bar.Clean();
|
|
continue;
|
|
}
|
|
|
|
//
|
|
bool isBarAbove =
|
|
bar.low > fvg.Upper();
|
|
bool isBarBelow =
|
|
bar.high < fvg.Lower();
|
|
|
|
//
|
|
result =
|
|
isBullish
|
|
? isBarAbove
|
|
: isBarBelow;
|
|
if (!result)
|
|
{
|
|
//
|
|
invalidBar = bar;
|
|
bar.Clean();
|
|
|
|
//
|
|
break;
|
|
}
|
|
|
|
//
|
|
bar.Clean();
|
|
}
|
|
|
|
//
|
|
bar.Clean();
|
|
ZeroMemory(fvg);
|
|
startedBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// XBoxZone iBox;
|
|
// result = iOBFVG.ToZone(iBox);
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// iBox.Clean();
|
|
// iOBFVG.Clean();
|
|
|
|
// //
|
|
// continue;
|
|
// }
|
|
|
|
//
|
|
// XCFVG *fvg;
|
|
// result = iOBFVG.GetMainFVG(fvg);
|
|
// if (!result)
|
|
// {
|
|
// //
|
|
// iOBFVG.Clean();
|
|
// ZeroMemory(fvg);
|
|
|
|
// //
|
|
// continue;
|
|
// }
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|