GAP-032: enforce session daily trade limit
- retain accepted-trade count after position-flat events - reject same-session entries with explicit MaxDailyTrades logging - verify next-session re-entry and update Gate 3 governance Build: clean | Tests: 500 passing | Dual-deployed: yes
This commit is contained in:
@@ -839,19 +839,13 @@ namespace NinjaTrader.NinjaScript.Strategies
|
||||
FileLog(string.Format("PNL_UPDATE DayPnL={0:C} Position={1} Qty={2}",
|
||||
dayPnL, marketPosition, quantity));
|
||||
|
||||
// GAP-006: Clear _tradeTaken when position goes flat (position-close-driven re-arm)
|
||||
// This replaces the bar-driven re-arm in SimpleORBStrategy which was unreliable
|
||||
// Position state must not reset the session-scoped daily trade limit.
|
||||
if (marketPosition == MarketPosition.Flat || quantity == 0)
|
||||
{
|
||||
if (_sdkStrategy != null && _sdkStrategy.GetParameters().ContainsKey("force_session_reset"))
|
||||
{
|
||||
// Let the strategy handle its own tradeTaken flag
|
||||
_sdkStrategy.SetParameters(new Dictionary<string, object> { { "clear_trade_taken", true } });
|
||||
}
|
||||
if (EnableVerboseLogging)
|
||||
Print(string.Format("[SDK] Position flat detected — clearing tradeTaken flag"));
|
||||
Print(string.Format("[SDK] Position flat detected — daily trade count remains active until session rollover"));
|
||||
if (EnableFileLogging && State == State.Realtime)
|
||||
FileLog("POSITION FLAT — clearing tradeTaken flag");
|
||||
FileLog("POSITION FLAT — daily trade count remains active until session rollover");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -443,11 +443,11 @@ namespace NT8.Strategies.Examples
|
||||
maxDailyTrades = (int)mdv;
|
||||
}
|
||||
|
||||
if (_tradeTaken && _dailyTradeCount >= maxDailyTrades)
|
||||
if (_dailyTradeCount >= maxDailyTrades)
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogDebug(
|
||||
"SimpleORBStrategy skip: daily trade limit reached ({0}/{1}) for session {2:yyyy-MM-dd}; bar={3:yyyy-MM-dd HH:mm}; symbol={4}",
|
||||
_logger.LogInformation(
|
||||
"MaxDailyTrades reached ({0}/{1}) for session {2:yyyy-MM-dd}; rejecting signal at {3:yyyy-MM-dd HH:mm}; symbol={4}",
|
||||
_dailyTradeCount,
|
||||
maxDailyTrades,
|
||||
_currentSessionDate,
|
||||
@@ -748,7 +748,8 @@ namespace NT8.Strategies.Examples
|
||||
}
|
||||
}
|
||||
|
||||
// GAP-006: clear_trade_taken from NT8StrategyBase.OnPositionUpdate when position goes flat
|
||||
// Retained for compatibility with older adapters. Position-flat state must not
|
||||
// reset session-scoped trade eligibility; ResetSession owns the daily reset.
|
||||
if (parameters.ContainsKey("clear_trade_taken"))
|
||||
{
|
||||
var val = parameters["clear_trade_taken"];
|
||||
@@ -756,11 +757,10 @@ namespace NT8.Strategies.Examples
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_tradeTaken = false;
|
||||
_breakoutBarSeen = false;
|
||||
_pendingBreakoutDirection = 0;
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("Position-close re-arm: _tradeTaken cleared");
|
||||
_logger.LogInformation("Position flat: MaxDailyTrades count retained until session rollover");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user