This commit is contained in:
2025-01-09 13:12:31 +03:30
parent a8ecc92e46
commit 0fd0889413
4 changed files with 388 additions and 376 deletions
+364
View File
@@ -9743,6 +9743,370 @@ double CalculateTarget(
return result;
}
/**
* Test Market for Detect Order Block FVG ...
*
* @param forDir: Direction
* @param bullishOrderBlocks: Detected Bullish Order Blocks ...
* @param bearishOrderBlocks: Detected Bearish Order Blocks ...
* @param orderBlockState: Order Block Detection POIState ...
* @param fairValueGapState: Fair Value Gap Detection POIState ...
* @param barIndex: Bar Index ...
*
* @return ( bool )
*/
bool DetectFVGOB(
ENUM_X_DIRECTION &forDir, // Test For Specified Direction ...
XFVGOrderBlock &bullishOrderBlocks[], // Bullish Order Blocks ...
XFVGOrderBlock &bearishOrderBlocks[], // Bearish Order Blocks ...
XPOIState &orderBlockState, // Order Block Detection TF POI(s) ...
XPOIState &fairValueGapState, // Fair Value Gap Detection TF POI(s) ...
int barIndex = 0 // Bar Index ...
)
{
//
bool result = false;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
forDir = X_DIRECTION_NONE;
//
// Validate Args ...
result =
orderBlockState.HasChild() &&
fairValueGapState.HasChild();
if (!result)
{
return result;
}
//
string symbol = orderBlockState.symbol;
ENUM_TIMEFRAMES period = orderBlockState.period;
//
// Retrieve Bars ...
XOHCL triggerCBar;
result = triggerCBar.Init(
symbol,
period,
barIndex //
);
//
// Select Order Blocks Which Has Big Changes ...
int count = 0;
datetime cTime = TimeCurrent();
//
XOHCL jBar;
result = jBar.Init(
fairValueGapState.symbol,
fairValueGapState.period,
barIndex //
);
if (!result)
{
return result;
}
double jBarLL = jBar.FindLowest(3, MODE_LOW);
double jBarHH = jBar.FindHighest(3, MODE_HIGH);
//
// Bullish ...
int bullishOrderBlocksCount = orderBlockState.CountBullishOrderBlocks();
count = bullishOrderBlocksCount;
if (IsValidSize(count))
{
//
for (int i = count - 1; i >= 0; i--)
{
//
XCFVG *iFVG = NULL;
XStateZones iStateZones;
XCOrderBlock *iOb = orderBlockState.bullishOrderBlocks[i];
iOb.To(cTime);
//
// Find Exit Bar of Bullish OrderBlock Upper ...
XOHCL breakerBar;
bool hasBreakerBar = iOb.DetectBreakerBar(breakerBar);
if (!hasBreakerBar)
{
continue;
}
//
// Detect Order Block is Hunted Or Not ...
XOHCL huntedBar;
bool isHunted = iOb.IsHunted(huntedBar);
if (isHunted)
{
continue;
}
//
// Check Validation of Order Block ...
bool isValid = iOb.IsValidOrderBlock();
if (!isValid)
{
continue;
}
//
// Check Order Block Has Fair Value Gap ...
int fvgsCount = fairValueGapState.CountBullishFairValueGaps();
bool hasFVG = IsValidSize(fvgsCount);
if (!hasFVG)
{
continue;
}
//
// Detect an FVG for Order Block ...
for (int j = fvgsCount - 1; j >= 0; j--)
{
//
XCFVG *jFVG = fairValueGapState.bullishFairValueGaps[j];
//
bool isValid =
//
jFVG.IsBullish() &&
jBarLL > jFVG.Upper() &&
jBar.low > jFVG.Upper() &&
jFVG.From() >= iOb.From() &&
((jFVG.Upper() > iOb.Upper() &&
jFVG.Lower() <= iOb.Upper()) ||
(jFVG.Upper() <= iOb.Upper() &&
jFVG.Lower() >= iOb.Lower()))
//
;
if (isValid)
{
//
jFVG.To(cTime);
iFVG = jFVG;
break;
}
}
//
hasFVG = iFVG != NULL;
result = hasFVG;
if (!result)
{
continue;
}
// //
// double upper = MathMax(iOb.Upper(), iFVG.Upper());
// double lower = MathMin(iOb.Lower(), iFVG.Lower());
// datetime from = iFVG.From();
// //
// // Detect Price Zones ...
// // Based On Decision State ...
// bool hasStateZones = CalculateStateZones(
// iStateZones,
// decisionState,
// upper,
// lower,
// from //
// );
// result = hasStateZones;
// if (!result)
// {
// continue;
// }
//
XFVGOrderBlock iModel;
iModel.orderBlock = iOb;
iModel.fairValueGap = iFVG;
// iModel.stateZones = iStateZones;
//
AddRef(
iModel,
bullishOrderBlocks //
);
}
}
//
// Bearish ...
int bearishOrderBlocksCount = orderBlockState.CountBearishOrderBlocks();
count = bearishOrderBlocksCount;
if (IsValidSize(count))
{
//
for (int i = count - 1; i >= 0; i--)
{
//
XCFVG *iFVG = NULL;
XStateZones iStateZones;
XCOrderBlock *iOb = orderBlockState.bearishOrderBlocks[i];
iOb.To(cTime);
//
// Find Exit Bar of Bullish OrderBlock Upper ...
XOHCL breakerBar;
bool hasBreakerBar = iOb.DetectBreakerBar(breakerBar);
if (!hasBreakerBar)
{
continue;
}
//
// Detect Order Block is Hunted Or Not ...
XOHCL huntedBar;
bool isHunted = iOb.IsHunted(huntedBar);
if (isHunted)
{
continue;
}
//
// Check Validation of Order Block ...
bool isValid = iOb.IsValidOrderBlock();
if (!isValid)
{
continue;
}
//
// Check Order Block Has Fair Value Gap ...
int fvgsCount = fairValueGapState.CountBearishFairValueGaps();
bool hasFVG = IsValidSize(fvgsCount);
if (!hasFVG)
{
continue;
}
//
// Detect an FVG for Order Block ...
for (int j = fvgsCount - 1; j >= 0; j--)
{
//
XCFVG *jFVG = fairValueGapState.bearishFairValueGaps[j];
//
bool isValid =
//
jFVG.IsBearish() &&
jBarHH < jFVG.Lower() &&
jBar.high < jFVG.Lower() &&
jFVG.From() >= iOb.From() &&
((jFVG.Upper() > iOb.Lower() &&
jFVG.Lower() <= iOb.Lower()) ||
(jFVG.Upper() <= iOb.Upper() &&
jFVG.Lower() >= iOb.Lower()))
//
;
if (isValid)
{
//
jFVG.To(cTime);
iFVG = jFVG;
break;
}
}
//
hasFVG = iFVG != NULL;
result = hasFVG;
if (!result)
{
continue;
}
//
double upper = MathMax(iOb.Upper(), iFVG.Upper());
double lower = MathMin(iOb.Lower(), iFVG.Lower());
datetime from = iFVG.From();
// //
// // Detect Price Zones ...
// // Based On Decision State ...
// bool hasStateZones = CalculateStateZones(
// iStateZones,
// decisionState,
// upper,
// lower,
// from //
// );
// result = hasStateZones;
// if (!result)
// {
// continue;
// }
//
XFVGOrderBlock iModel;
iModel.orderBlock = iOb;
iModel.fairValueGap = iFVG;
// iModel.stateZones = iStateZones;
//
AddRef(
iModel,
bearishOrderBlocks //
);
}
}
//
// Check Order Blocks ...
bullishOrderBlocksCount = ArraySize(bullishOrderBlocks);
bool hasBullishOrderBlocks = IsValidSize(bullishOrderBlocksCount);
//
// Check Order Blocks ...
bearishOrderBlocksCount = ArraySize(bearishOrderBlocks);
bool hasBearishOrderBlocks = IsValidSize(bearishOrderBlocksCount);
//
result =
//
hasBullishOrderBlocks ||
hasBearishOrderBlocks
//
;
if (!result)
{
return result;
}
//
bool isBullish = hasBullishOrderBlocks && !hasBearishOrderBlocks;
bool isBearish = hasBearishOrderBlocks && !hasBullishOrderBlocks;
//
forDir =
isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
result = forDir != X_DIRECTION_NONE;
if (!result)
{
return result;
}
//
return result;
}
//
typedef void (*TOnPOIEvent)(ENUM_XPOI_EVENTS event,
XCBasePOI *param //