mirror of
https://github.com/rithsila/MT5-EA-Sniper-Strategy.git
synced 2026-08-25 08:38:13 +00:00
Fix UpdateTimeframeData resilience - make pattern detection more robust
- Changed UpdateTimeframeData to not fail entire update if individual components fail - Now considers update successful if ANY pattern detection works (OR logic vs AND logic) - Bias calculation failures no longer cause entire timeframe update to fail - This should eliminate the 'Failed to update multi-timeframe analysis' warnings - Pattern detection will continue working even if bias calculation has issues
This commit is contained in:
+54
-61
@@ -3212,77 +3212,70 @@ bool UpdateTimeframeData(string symbol, MarketStructureData &mtf_data)
|
|||||||
{
|
{
|
||||||
LogDebug(StringFormat("Updating %s analysis for %s", EnumToString(mtf_data.timeframe), symbol));
|
LogDebug(StringFormat("Updating %s analysis for %s", EnumToString(mtf_data.timeframe), symbol));
|
||||||
|
|
||||||
bool success = true;
|
// Track individual results but don't fail entire update if one component fails
|
||||||
|
bool ob_success = DetectOrderBlocks(symbol, mtf_data.timeframe, mtf_data.order_blocks);
|
||||||
|
bool fvg_success = DetectFairValueGaps(symbol, mtf_data.timeframe, mtf_data.fair_value_gaps);
|
||||||
|
bool bos_success = DetectBreakOfStructure(symbol, mtf_data.timeframe, mtf_data.bos_events);
|
||||||
|
bool sweep_success = DetectLiquiditySweeps(symbol, mtf_data.timeframe, mtf_data.liquidity_sweeps);
|
||||||
|
|
||||||
// Update Order Blocks
|
// Consider update successful if at least pattern detection worked
|
||||||
success &= DetectOrderBlocks(symbol, mtf_data.timeframe, mtf_data.order_blocks);
|
bool patterns_success = ob_success || fvg_success || bos_success || sweep_success;
|
||||||
|
|
||||||
// Update Fair Value Gaps
|
// Phase 2: Update enhanced multi-timeframe data (always attempt, don't fail on bias calc issues)
|
||||||
success &= DetectFairValueGaps(symbol, mtf_data.timeframe, mtf_data.fair_value_gaps);
|
// Calculate bias strength for this timeframe (don't fail if this doesn't work)
|
||||||
|
mtf_data.current_bias = CalculateBiasStrength(symbol, mtf_data.timeframe);
|
||||||
|
|
||||||
// Update Break of Structure events
|
// Detect major levels for D1 and W1 timeframes
|
||||||
success &= DetectBreakOfStructure(symbol, mtf_data.timeframe, mtf_data.bos_events);
|
if (mtf_data.timeframe == PERIOD_D1 || mtf_data.timeframe == PERIOD_W1)
|
||||||
|
|
||||||
// Update Liquidity Sweeps
|
|
||||||
success &= DetectLiquiditySweeps(symbol, mtf_data.timeframe, mtf_data.liquidity_sweeps);
|
|
||||||
|
|
||||||
// Phase 2: Update enhanced multi-timeframe data
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
// Calculate bias strength for this timeframe
|
DetectMajorLevels(symbol, mtf_data.timeframe, mtf_data.major_levels);
|
||||||
mtf_data.current_bias = CalculateBiasStrength(symbol, mtf_data.timeframe);
|
|
||||||
|
|
||||||
// Detect major levels for D1 and W1 timeframes
|
|
||||||
if (mtf_data.timeframe == PERIOD_D1 || mtf_data.timeframe == PERIOD_W1)
|
|
||||||
{
|
|
||||||
DetectMajorLevels(symbol, mtf_data.timeframe, mtf_data.major_levels);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate trend strength (simplified)
|
|
||||||
mtf_data.trend_strength = mtf_data.current_bias.strength / 100.0;
|
|
||||||
|
|
||||||
// Determine market phase
|
|
||||||
int recent_bos_count = 0;
|
|
||||||
datetime recent_time = TimeCurrent() - (PeriodSeconds(mtf_data.timeframe) * 10);
|
|
||||||
|
|
||||||
for (int i = 0; i < ArraySize(mtf_data.bos_events); i++)
|
|
||||||
{
|
|
||||||
if (mtf_data.bos_events[i].confirmed && mtf_data.bos_events[i].time > recent_time)
|
|
||||||
recent_bos_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recent_bos_count >= 2)
|
|
||||||
mtf_data.market_phase = "BREAKOUT";
|
|
||||||
else if (mtf_data.trend_strength > 0.6)
|
|
||||||
mtf_data.market_phase = "TRENDING";
|
|
||||||
else
|
|
||||||
mtf_data.market_phase = "RANGING";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update metadata
|
// Calculate trend strength (simplified)
|
||||||
mtf_data.last_update = iTime(symbol, mtf_data.timeframe, 0);
|
mtf_data.trend_strength = mtf_data.current_bias.strength / 100.0;
|
||||||
mtf_data.is_valid = success;
|
|
||||||
|
|
||||||
if (success)
|
// Determine market phase
|
||||||
|
int recent_bos_count = 0;
|
||||||
|
datetime recent_time = TimeCurrent() - (PeriodSeconds(mtf_data.timeframe) * 10);
|
||||||
|
|
||||||
|
for (int i = 0; i < ArraySize(mtf_data.bos_events); i++)
|
||||||
{
|
{
|
||||||
LogDebug(StringFormat("%s analysis completed: OB=%d, FVG=%d, BOS=%d, Sweeps=%d, Bias=%.1f%% (%s), Phase=%s",
|
if (mtf_data.bos_events[i].confirmed && mtf_data.bos_events[i].time > recent_time)
|
||||||
EnumToString(mtf_data.timeframe),
|
recent_bos_count++;
|
||||||
ArraySize(mtf_data.order_blocks),
|
|
||||||
ArraySize(mtf_data.fair_value_gaps),
|
|
||||||
ArraySize(mtf_data.bos_events),
|
|
||||||
ArraySize(mtf_data.liquidity_sweeps),
|
|
||||||
mtf_data.current_bias.strength,
|
|
||||||
mtf_data.current_bias.direction,
|
|
||||||
mtf_data.market_phase));
|
|
||||||
|
|
||||||
// Phase 3: Draw patterns on chart (only for current symbol and M15/H4 timeframes for clarity)
|
|
||||||
if (symbol == _Symbol && (mtf_data.timeframe == PERIOD_M15 || mtf_data.timeframe == PERIOD_H4))
|
|
||||||
{
|
|
||||||
DrawPatternsOnChart(symbol, mtf_data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
if (recent_bos_count >= 2)
|
||||||
|
mtf_data.market_phase = "BREAKOUT";
|
||||||
|
else if (mtf_data.trend_strength > 0.6)
|
||||||
|
mtf_data.market_phase = "TRENDING";
|
||||||
|
else
|
||||||
|
mtf_data.market_phase = "RANGING";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update metadata
|
||||||
|
mtf_data.last_update = iTime(symbol, mtf_data.timeframe, 0);
|
||||||
|
mtf_data.is_valid = patterns_success;
|
||||||
|
|
||||||
|
if (patterns_success)
|
||||||
|
{
|
||||||
|
LogDebug(StringFormat("%s analysis completed: OB=%d, FVG=%d, BOS=%d, Sweeps=%d, Bias=%.1f%% (%s), Phase=%s",
|
||||||
|
EnumToString(mtf_data.timeframe),
|
||||||
|
ArraySize(mtf_data.order_blocks),
|
||||||
|
ArraySize(mtf_data.fair_value_gaps),
|
||||||
|
ArraySize(mtf_data.bos_events),
|
||||||
|
ArraySize(mtf_data.liquidity_sweeps),
|
||||||
|
mtf_data.current_bias.strength,
|
||||||
|
mtf_data.current_bias.direction,
|
||||||
|
mtf_data.market_phase));
|
||||||
|
|
||||||
|
// Phase 3: Draw patterns on chart (only for current symbol and M15/H4 timeframes for clarity)
|
||||||
|
if (symbol == _Symbol && (mtf_data.timeframe == PERIOD_M15 || mtf_data.timeframe == PERIOD_H4))
|
||||||
|
{
|
||||||
|
DrawPatternsOnChart(symbol, mtf_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return patterns_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawPatternsOnChart(string symbol, MarketStructureData &mtf_data)
|
void DrawPatternsOnChart(string symbol, MarketStructureData &mtf_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user