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:
rithsila
2025-09-26 11:04:58 +07:00
parent affe043af6
commit af4f250125
+54 -61
View File
@@ -3212,77 +3212,70 @@ bool UpdateTimeframeData(string symbol, MarketStructureData &mtf_data)
{
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
success &= DetectOrderBlocks(symbol, mtf_data.timeframe, mtf_data.order_blocks);
// Consider update successful if at least pattern detection worked
bool patterns_success = ob_success || fvg_success || bos_success || sweep_success;
// Update Fair Value Gaps
success &= DetectFairValueGaps(symbol, mtf_data.timeframe, mtf_data.fair_value_gaps);
// Phase 2: Update enhanced multi-timeframe data (always attempt, don't fail on bias calc issues)
// 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
success &= DetectBreakOfStructure(symbol, mtf_data.timeframe, mtf_data.bos_events);
// Update Liquidity Sweeps
success &= DetectLiquiditySweeps(symbol, mtf_data.timeframe, mtf_data.liquidity_sweeps);
// Phase 2: Update enhanced multi-timeframe data
if (success)
// Detect major levels for D1 and W1 timeframes
if (mtf_data.timeframe == PERIOD_D1 || mtf_data.timeframe == PERIOD_W1)
{
// Calculate bias strength for this timeframe
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";
DetectMajorLevels(symbol, mtf_data.timeframe, mtf_data.major_levels);
}
// Update metadata
mtf_data.last_update = iTime(symbol, mtf_data.timeframe, 0);
mtf_data.is_valid = success;
// Calculate trend strength (simplified)
mtf_data.trend_strength = mtf_data.current_bias.strength / 100.0;
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",
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);
}
if (mtf_data.bos_events[i].confirmed && mtf_data.bos_events[i].time > recent_time)
recent_bos_count++;
}
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)