fix: apply GAP-035 GAP-036 GAP-038 GAP-039 runtime remediations
This commit is contained in:
@@ -345,6 +345,7 @@ namespace NT8.Strategies.Examples
|
||||
lock (_lock)
|
||||
{
|
||||
EnsureInitialized();
|
||||
ClearSignalRejection(context);
|
||||
|
||||
UpdateRiskMode(context);
|
||||
UpdateConfluenceInputs(bar, context);
|
||||
@@ -380,7 +381,10 @@ namespace NT8.Strategies.Examples
|
||||
|
||||
// Only trade during RTH — bypassed in TestMode
|
||||
if (!testMode && (context.Session == null || !context.Session.IsRth))
|
||||
{
|
||||
RecordSignalRejection(context, "RthGuard", string.Format("SessionIsRth={0}", context.Session != null ? context.Session.IsRth.ToString() : "null"), bar.Time);
|
||||
return null;
|
||||
}
|
||||
|
||||
// GAP-008: CME Holiday Guard — skip ORB window on CME holidays
|
||||
if (!testMode && EnableCMEHolidayGuard)
|
||||
@@ -389,6 +393,7 @@ namespace NT8.Strategies.Examples
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("Skipping ORB window on CME holiday: {0:yyyy-MM-dd}", bar.Time.Date);
|
||||
RecordSignalRejection(context, "CmeHoliday", string.Format("Date={0:yyyy-MM-dd}", bar.Time.Date), bar.Time);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -413,6 +418,7 @@ namespace NT8.Strategies.Examples
|
||||
if (bar.Time <= _openingRangeEnd)
|
||||
{
|
||||
UpdateOpeningRange(bar);
|
||||
RecordSignalRejection(context, "OrbRangeNotEstablished", string.Format("ORB window still building start={0:HH:mm} end={1:HH:mm} high={2:F2} low={3:F2}", _openingRangeStart, _openingRangeEnd, _openingRangeHigh, _openingRangeLow), bar.Time);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -421,7 +427,10 @@ namespace NT8.Strategies.Examples
|
||||
if (_openingRangeHigh > _openingRangeLow)
|
||||
_openingRangeReady = true;
|
||||
else
|
||||
{
|
||||
RecordSignalRejection(context, "OrbRangeNotEstablished", string.Format("Invalid ORB high={0:F2} low={1:F2}", _openingRangeHigh, _openingRangeLow), bar.Time);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,6 +462,7 @@ namespace NT8.Strategies.Examples
|
||||
_currentSessionDate,
|
||||
bar.Time,
|
||||
context.Symbol);
|
||||
RecordSignalRejection(context, "MaxDailyTrades", string.Format("DailyTradeCount={0} MaxDailyTrades={1} Session={2:yyyy-MM-dd} Symbol={3}", _dailyTradeCount, maxDailyTrades, _currentSessionDate, context.Symbol), bar.Time);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -559,7 +569,10 @@ namespace NT8.Strategies.Examples
|
||||
}
|
||||
|
||||
if (candidate == null)
|
||||
{
|
||||
RecordSignalRejection(context, "OrbRangeNotEstablished", string.Format("No confirmed breakout close={0:F2} longTrigger={1:F2} shortTrigger={2:F2} breakoutBarSeen={3} pendingDirection={4}", bar.Close, longTrigger, shortTrigger, _breakoutBarSeen, _pendingBreakoutDirection), bar.Time);
|
||||
return null;
|
||||
}
|
||||
|
||||
AttachDailyBarContext(candidate, bar, context);
|
||||
|
||||
@@ -597,6 +610,7 @@ namespace NT8.Strategies.Examples
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("Short vetoed by regime filter: AVWAP slope {0:F4} > 0 (bullish)", slopeVal);
|
||||
RecordSignalRejection(context, "GradeFilter", string.Format("Regime veto before score; Side={0} AVWAPSlope={1:F4} EnableShortTrendFilter=True", candidate.Side, slopeVal), bar.Time);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -605,6 +619,7 @@ namespace NT8.Strategies.Examples
|
||||
// Long veto in bearish regime - always enforced (no parameter for this yet)
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("Trade vetoed: AVWAP slope {0:F4} against {1} direction", slopeVal, candidate.Side);
|
||||
RecordSignalRejection(context, "GradeFilter", string.Format("Regime veto before score; Side={0} AVWAPSlope={1:F4}", candidate.Side, slopeVal), bar.Time);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -632,6 +647,7 @@ namespace NT8.Strategies.Examples
|
||||
score.WeightedScore,
|
||||
score.Grade,
|
||||
minGrade);
|
||||
RecordSignalRejection(context, "GradeFilter", string.Format("Score={0:F3} Grade={1} MinTradeGrade={2} Factors={3}", score.WeightedScore, score.Grade, minGrade, FormatFactorBreakdown(score)), bar.Time);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -650,7 +666,8 @@ namespace NT8.Strategies.Examples
|
||||
candidate.Metadata["combined_multiplier"] = combinedMultiplier;
|
||||
|
||||
_tradeTaken = true;
|
||||
_dailyTradeCount++;
|
||||
if (ShouldIncrementDailyTradeCount(context))
|
||||
_dailyTradeCount++;
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogDebug(
|
||||
@@ -962,6 +979,66 @@ namespace NT8.Strategies.Examples
|
||||
_openingRangeLow = bar.Low;
|
||||
}
|
||||
|
||||
private void RecordSignalRejection(StrategyContext context, string reason, string detail, DateTime barTime)
|
||||
{
|
||||
if (context == null)
|
||||
return;
|
||||
|
||||
if (context.CustomData == null)
|
||||
context.CustomData = new Dictionary<string, object>();
|
||||
|
||||
context.CustomData["signal_reject_reason"] = reason;
|
||||
context.CustomData["signal_reject_detail"] = detail;
|
||||
context.CustomData["signal_reject_bar"] = barTime;
|
||||
context.CustomData["signal_reject_line"] = string.Format("REJECT: reason={0} detail={1} bar={2:yyyy-MM-dd HH:mm:ss}", reason, detail, barTime);
|
||||
}
|
||||
|
||||
private bool ShouldIncrementDailyTradeCount(StrategyContext context)
|
||||
{
|
||||
if (context == null || context.CustomData == null)
|
||||
return true;
|
||||
|
||||
if (!context.CustomData.ContainsKey("AllowDailyTradeCountIncrement"))
|
||||
return true;
|
||||
|
||||
object value = context.CustomData["AllowDailyTradeCountIncrement"];
|
||||
if (value is bool)
|
||||
return (bool)value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ClearSignalRejection(StrategyContext context)
|
||||
{
|
||||
if (context == null || context.CustomData == null)
|
||||
return;
|
||||
|
||||
if (context.CustomData.ContainsKey("signal_reject_reason"))
|
||||
context.CustomData.Remove("signal_reject_reason");
|
||||
if (context.CustomData.ContainsKey("signal_reject_detail"))
|
||||
context.CustomData.Remove("signal_reject_detail");
|
||||
if (context.CustomData.ContainsKey("signal_reject_bar"))
|
||||
context.CustomData.Remove("signal_reject_bar");
|
||||
if (context.CustomData.ContainsKey("signal_reject_line"))
|
||||
context.CustomData.Remove("signal_reject_line");
|
||||
}
|
||||
|
||||
private string FormatFactorBreakdown(ConfluenceScore score)
|
||||
{
|
||||
if (score == null || score.Factors == null)
|
||||
return "none";
|
||||
|
||||
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||||
foreach (ConfluenceFactor factor in score.Factors)
|
||||
{
|
||||
if (sb.Length > 0)
|
||||
sb.Append(";");
|
||||
sb.Append(string.Format("{0}={1:F2}x{2:F2}", factor.Type, factor.Score, factor.Weight));
|
||||
}
|
||||
|
||||
return sb.Length > 0 ? sb.ToString() : "none";
|
||||
}
|
||||
|
||||
private StrategyIntent CreateIntent(string symbol, OrderSide side, double openingRange, double lastPrice)
|
||||
{
|
||||
var stopTicks = _config != null && _config.Parameters.ContainsKey("StopTicks")
|
||||
|
||||
Reference in New Issue
Block a user