This commit is contained in:
2025-02-15 12:57:41 +03:30
parent b9ce179fa3
commit 7fbb3970e0
3 changed files with 1453 additions and 216 deletions
+681 -12
View File
@@ -36,6 +36,45 @@ enum ENUM_X121SMC_XWZ_PRIORITY
X121SMC_XWZ_PRIORITY_HIGH,
};
//
struct X121SMCXWZOBFVG
{
//
// Props ...
XCOrderBlock *ob;
XCFVG *fvg;
//
// Constructor ...
X121SMCXWZOBFVG()
{
Clean();
}
//
// Tools ...
//
void Clean()
{
//
ZeroMemory(ob);
ZeroMemory(fvg);
}
//
bool IsValid()
{
//
return ob != NULL &&
fvg != NULL &&
ob.IsValid() &&
fvg.IsValid();
}
//
};
//
struct X121SMCXWZWorkingZone
{
@@ -362,6 +401,9 @@ struct X121SMCStrategyXWZSignalConditions
XCDemandZone *demandZone;
X121SMCXWZWorkingZone workingZone;
//
X121SMCXWZOBFVG startZones[];
//
// Constructor ...
X121SMCStrategyXWZSignalConditions()
@@ -489,13 +531,20 @@ struct X121SMCStrategyXWZSignalConditions
amountPercent = 0;
//
delete supplyZone;
ZeroMemory(supplyZone);
//
delete demandZone;
ZeroMemory(demandZone);
//
ZeroMemory(orderBlock);
//
ZeroMemory(fairValueGap);
//
Clean(startZones);
//
workingZone.Clean();
}
@@ -514,12 +563,22 @@ struct X121SMCStrategyXWZSignalConditions
// Working Zone is an Area which
// we decide to trade inside it ...
bool ExtractWorkingZone(
XPOIState &state //
XPOIState &htfState,
XPOIState &mtfState,
XPOIState &stfState,
int barIndex = 0 //
)
{
//
bool result = false;
//
if (barIndex < 0)
{
barIndex = 0;
}
int zIndex = barIndex;
//
result = !HasWorkingZone();
if (!result)
@@ -528,10 +587,39 @@ struct X121SMCStrategyXWZSignalConditions
}
//
result = state.IsValid() &&
state.HasChild() &&
state.HasSupplyZones() &&
state.HasDemandZones();
result = IsValid(symbol) &&
IsValid(period);
if (!result)
{
//
Clean();
return result;
}
//
datetime cTime = iTime(
symbol,
period,
zIndex //
);
//
result =
//
htfState.IsValid() &&
htfState.HasChild() &&
htfState.HasSupplyZones() &&
htfState.HasDemandZones() &&
//
mtfState.IsValid() &&
mtfState.HasChild() &&
mtfState.HasSupplyZones() &&
mtfState.HasDemandZones() &&
//
stfState.IsValid() &&
stfState.HasChild()
//
;
if (!result)
{
return result;
@@ -539,8 +627,8 @@ struct X121SMCStrategyXWZSignalConditions
//
// Retrieve Highest Supply Zone ...
int hSupplyIDX = GetHighest(state.supplyZones);
int lDemandIDX = GetLowest(state.demandZones);
int hSupplyIDX = GetHighest(htfState.supplyZones);
int lDemandIDX = GetLowest(htfState.demandZones);
//
result =
@@ -555,8 +643,8 @@ struct X121SMCStrategyXWZSignalConditions
}
//
supplyZone = state.supplyZones[hSupplyIDX];
demandZone = state.demandZones[lDemandIDX];
supplyZone = htfState.supplyZones[hSupplyIDX];
demandZone = htfState.demandZones[lDemandIDX];
//
result =
@@ -575,6 +663,587 @@ struct X121SMCStrategyXWZSignalConditions
}
//
// Check Validation of Supply and Demand Zones ...
lDemandIDX = GetLowest(mtfState.demandZones);
hSupplyIDX = GetHighest(mtfState.supplyZones);
result = IsValidIndex(lDemandIDX) &&
IsValidIndex(hSupplyIDX);
if (!result)
{
//
Clean();
return result;
}
//
// Validate Supply and Demand ...
bool isMTFHSupplyInside =
IsInside(
mtfState.supplyZones[hSupplyIDX],
supplyZone);
bool isMTFLDemandInside =
IsInside(
mtfState.demandZones[lDemandIDX],
demandZone //
);
if (isMTFHSupplyInside &&
!isMTFLDemandInside)
{
demandZone = mtfState.demandZones[lDemandIDX];
}
else if (!isMTFHSupplyInside &&
isMTFLDemandInside)
{
supplyZone = mtfState.supplyZones[hSupplyIDX];
}
else if (isMTFHSupplyInside &&
isMTFLDemandInside)
{
//
supplyZone = mtfState.supplyZones[hSupplyIDX];
demandZone = mtfState.demandZones[lDemandIDX];
}
//
// Check Zones Validation ...
bool hasTrend =
supplyZone != NULL &&
supplyZone.IsValid() &&
demandZone != NULL &&
demandZone.IsValid();
result = hasTrend;
if (!result)
{
//
Clean();
return result;
}
//
datetime from = MathMax(
supplyZone.From(),
demandZone.From());
//
int fromIndex = iBarShift(
symbol,
period,
from //
);
//
// Detect Trend ...
ENUM_X_DIRECTION trend = X_DIRECTION_NONE;
datetime supplyTouch = NULL;
datetime demandTouch = NULL;
for (int i = zIndex; i < fromIndex; i++)
{
//
XOHCL iBar;
bool isInited = iBar.Init(
symbol,
period,
i //
);
if (!isInited)
{
continue;
}
//
bool isTouchSupplyZone =
//
iBar.low < supplyZone.Lower() &&
iBar.GetUp() > supplyZone.Lower()
//
;
if (isTouchSupplyZone &&
!IsValid(supplyTouch))
{
supplyTouch = iBar.time;
}
//
bool isTouchDemandZone =
//
iBar.high > demandZone.Upper() &&
iBar.GetDown() < demandZone.Upper()
//
;
if (isTouchDemandZone &&
!IsValid(demandTouch))
{
demandTouch = iBar.time;
}
//
bool canBreak =
IsValid(supplyTouch) &&
IsValid(demandTouch);
//
iBar.Clean();
//
if (canBreak)
{
break;
}
}
//
hasTrend =
//
IsValid(supplyTouch) &&
IsValid(demandTouch)
//
;
if (hasTrend)
{
//
trend =
//
supplyTouch > demandTouch
? X_DIRECTION_BEARISH
: X_DIRECTION_BULLISH
//
;
}
//
// Check Trend ...
result = hasTrend;
if (!result)
{
//
Clean();
return result;
}
//
bool hasBullishTrend = IsBullish(trend);
bool hasBearishTrend = IsBearish(trend);
//
// Find Order Block and FVG for Trend Approve ...
//
// Now We Have to Detect at least One OrderBlock with FVG ...
// for Trend Approvement ...
bool hasOrderBlock = HasOrderBlock();
bool hasFairValueGap = HasFairValueGap();
if (!hasOrderBlock &&
!hasFairValueGap)
{
//
int count = 0;
bool has = false;
//
XCFVG *fvg = NULL;
XCOrderBlock *ob = NULL;
//
if (hasBullishTrend)
{
//
has = mtfState.HasBullishOrderBlocks();
count = mtfState.CountBullishOrderBlocks();
//
if (has)
{
//
// Check Order Block ...
for (int i = 0; i < count; i++)
{
//
XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i];
//
iOB.To(cTime);
//
// Check From Passes ...
bool isFromPassed = iOB.From() > demandZone.From();
if (!isFromPassed)
{
continue;
}
//
// Must inside DemandZone ...
bool isInsideDemand = IsInsideDiff(
iOB,
demandZone //
);
if (!isInsideDemand)
{
continue;
}
//
// Check Started ...
XOHCL startedBar;
ENUM_X_DIRECTION startedDir;
bool isStarted = iOB.IsStarted(
X_DIRECTION_BULLISH,
startedBar,
startedDir //
);
if (!isStarted)
{
//
startedBar.Clean();
continue;
}
//
// Converts to Box ...
XBoxZone obBox;
bool hasOBBox = ToBox(
obBox,
iOB //
);
if (!hasOBBox)
{
//
obBox.Clean();
startedBar.Clean();
continue;
}
//
// Check Zone Must not Used before ...
bool isUsed = IsBoxUsed(
obBox,
startedBar.Index() - 1,
zIndex //
);
if (isUsed)
{
//
obBox.Clean();
startedBar.Clean();
continue;
}
//
ob = iOB;
//
obBox.Clean();
startedBar.Clean();
//
break;
}
//
// Detect Fair Value Gap ...
if (ob != NULL &&
ob.IsValid())
{
//
has = stfState.HasBullishFairValueGaps();
count = stfState.CountBullishFairValueGaps();
if (has)
{
//
// Check Fir Value Gap ...
for (int i = 0; i < count; i++)
{
//
XCFVG *iFVG = stfState.bullishFairValueGaps[i];
//
iFVG.To(cTime);
//
// Check From Passes ...
bool isFromPassed = iFVG.From() > ob.From();
if (!isFromPassed)
{
continue;
}
//
// Check Started ...
XOHCL startedBar;
ENUM_X_DIRECTION startedDir;
bool isStarted = iFVG.IsStarted(
X_DIRECTION_BULLISH,
startedBar,
startedDir //
);
if (!isStarted)
{
//
startedBar.Clean();
continue;
}
//
// Converts to Box ...
XBoxZone fvgBox;
bool hasFVGBox = ToBox(
fvgBox,
iFVG //
);
if (!hasFVGBox)
{
//
fvgBox.Clean();
startedBar.Clean();
continue;
}
//
// Check Inside Order Block ...
bool isInside = IsInsideDiff(
iFVG,
ob,
true // Force Side Out ...
);
if (!isInside)
{
continue;
}
//
fvg = iFVG;
//
fvgBox.Clean();
startedBar.Clean();
//
break;
}
}
else
{
//
ob = NULL;
}
}
}
}
else if (hasBearishTrend)
{
//
has = mtfState.HasBearishOrderBlocks();
count = mtfState.CountBearishOrderBlocks();
//
if (has)
{
//
// Check Order Block ...
for (int i = 0; i < count; i++)
{
//
XCOrderBlock *iOB = mtfState.bearishOrderBlocks[i];
//
iOB.To(cTime);
//
// Check From Passes ...
bool isFromPassed = iOB.From() > supplyZone.From();
if (!isFromPassed)
{
continue;
}
//
// Must inside DemandZone ...
bool isInsideDemand = IsInsideDiff(
iOB,
supplyZone //
);
if (!isInsideDemand)
{
continue;
}
//
// Check Started ...
XOHCL startedBar;
ENUM_X_DIRECTION startedDir;
bool isStarted = iOB.IsStarted(
X_DIRECTION_BEARISH,
startedBar,
startedDir //
);
if (!isStarted)
{
//
startedBar.Clean();
continue;
}
//
// Converts to Box ...
XBoxZone obBox;
bool hasOBBox = ToBox(
obBox,
iOB //
);
if (!hasOBBox)
{
//
obBox.Clean();
startedBar.Clean();
continue;
}
//
// Check Zone Must not Used before ...
bool isUsed = IsBoxUsed(
obBox,
startedBar.Index() - 1,
zIndex //
);
if (isUsed)
{
//
obBox.Clean();
startedBar.Clean();
continue;
}
//
ob = iOB;
//
obBox.Clean();
startedBar.Clean();
//
break;
}
//
// Detect Fair Value Gap ...
if (ob != NULL &&
ob.IsValid())
{
//
has = stfState.HasBearishFairValueGaps();
count = stfState.CountBearishFairValueGaps();
if (has)
{
//
// Check Fir Value Gap ...
for (int i = 0; i < count; i++)
{
//
XCFVG *iFVG = stfState.bearishFairValueGaps[i];
//
iFVG.To(cTime);
//
// Check From Passes ...
bool isFromPassed = iFVG.From() > ob.From();
if (!isFromPassed)
{
continue;
}
//
// Check Started ...
XOHCL startedBar;
ENUM_X_DIRECTION startedDir;
bool isStarted = iFVG.IsStarted(
X_DIRECTION_BEARISH,
startedBar,
startedDir //
);
if (!isStarted)
{
//
startedBar.Clean();
continue;
}
//
// Converts to Box ...
XBoxZone fvgBox;
bool hasFVGBox = ToBox(
fvgBox,
iFVG //
);
if (!hasFVGBox)
{
//
fvgBox.Clean();
startedBar.Clean();
continue;
}
//
// Check Inside Order Block ...
bool isInside = IsInsideDiff(
iFVG,
ob,
true // Force Side Out ...
);
if (!isInside)
{
continue;
}
//
fvg = iFVG;
//
fvgBox.Clean();
startedBar.Clean();
//
break;
}
}
else
{
//
ob = NULL;
}
}
}
}
//
if (ob != NULL &&
fvg != NULL)
{
//
orderBlock = ob;
fairValueGap = fvg;
}
//
hasOrderBlock = HasOrderBlock();
hasFairValueGap = HasFairValueGap();
}
//
// Check Trend Approved ...
bool isTrendApproved =
hasOrderBlock &&
hasFairValueGap;
result = isTrendApproved;
if (!result)
{
//
Clean();
return result;
}
//
// Prepare Working Zone ...
workingZone.symbol = symbol;
workingZone.period = period;
@@ -587,7 +1256,7 @@ struct X121SMCStrategyXWZSignalConditions
workingZone.zoneLower = demandZone.Lower();
//
workingZone.from = MathMax(supplyZone.From(), demandZone.From());
workingZone.from = from;
//
double upper = workingZone.upper;