[GAP-054]: runner trail breakeven fix complete
- src/NT8.Adapters/Strategies/NT8StrategyBase.cs: removed post-entry runner SetStopLoss breakeven overwrite so SetTrailStop remains authoritative - src/NT8.Adapters/Strategies/NT8StrategyBase.cs: removed stale runner breakeven diagnostic draw Build: clean | Tests: 511 passing | Dual-deployed: yes
This commit is contained in:
@@ -678,39 +678,18 @@ namespace NinjaTrader.NinjaScript.Strategies
|
|||||||
// Draw chart diagnostics for visual proof of every decision
|
// Draw chart diagnostics for visual proof of every decision
|
||||||
DrawDiagnostics();
|
DrawDiagnostics();
|
||||||
|
|
||||||
// --- Breakeven and runner trailing monitor ---
|
// --- Runner trailing monitor ---
|
||||||
if (_runnerActive && !string.IsNullOrEmpty(_runnerSignalName) && Position.Quantity != 0)
|
if (_runnerActive && !string.IsNullOrEmpty(_runnerSignalName) && Position.Quantity != 0)
|
||||||
{
|
{
|
||||||
double entryPrice = Position.AveragePrice;
|
|
||||||
double currentClose = Close[0];
|
|
||||||
bool isLong = Position.MarketPosition == MarketPosition.Long;
|
|
||||||
|
|
||||||
double profitTicks = isLong
|
|
||||||
? (currentClose - entryPrice) / TickSize
|
|
||||||
: (entryPrice - currentClose) / TickSize;
|
|
||||||
|
|
||||||
// Move runner stop to breakeven + offset once trigger is reached
|
|
||||||
if (EnableAutoBreakeven && !_breakevenMoved && profitTicks >= BreakevenTriggerTicks)
|
|
||||||
{
|
|
||||||
double bePrice = isLong
|
|
||||||
? entryPrice + (BreakevenOffsetTicks * TickSize)
|
|
||||||
: entryPrice - (BreakevenOffsetTicks * TickSize);
|
|
||||||
|
|
||||||
SetStopLoss(_runnerSignalName, CalculationMode.Price, bePrice, false);
|
|
||||||
_breakevenMoved = true;
|
|
||||||
|
|
||||||
Print(String.Format("[SDK] Runner breakeven set at {0:F2} (profit={1:F0} ticks)",
|
|
||||||
bePrice, profitTicks));
|
|
||||||
if (EnableFileLogging && State == State.Realtime)
|
|
||||||
FileLog(String.Format("BREAKEVEN runner stop -> {0:F2} profit={1:F0}ticks",
|
|
||||||
bePrice, profitTicks));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trailing stop is set at entry via SetTrailStop in SubmitOrderToNT8.
|
// Trailing stop is set at entry via SetTrailStop in SubmitOrderToNT8.
|
||||||
// NT8 manages it natively tick-by-tick. Do NOT call SetTrailStop here
|
// NT8 manages it natively tick-by-tick. Do NOT call SetTrailStop here
|
||||||
// on bar close — that resets the trail anchor to bar-close price each
|
// on bar close — that resets the trail anchor to bar-close price each
|
||||||
// bar and causes near-breakeven exits on fast reversals within a bar.
|
// bar and causes near-breakeven exits on fast reversals within a bar.
|
||||||
// (See session log 2026-04-13: MFE $1,127 vs exit $133 — confirmed cause.)
|
// (See session log 2026-04-13: MFE $1,127 vs exit $133 — confirmed cause.)
|
||||||
|
// Do NOT call SetStopLoss here either. In NT8 managed orders,
|
||||||
|
// SetStopLoss and SetTrailStop are signal-scoped Set() methods;
|
||||||
|
// the later call for the same runner signal replaces the earlier
|
||||||
|
// protective exit and disables the live trail for the trade.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear runner state when flat
|
// Clear runner state when flat
|
||||||
@@ -1840,14 +1819,7 @@ namespace NinjaTrader.NinjaScript.Strategies
|
|||||||
Draw.Line(this, "Diag_ATRStop", false, CurrentBar - 1, stopPrice, CurrentBar, stopPrice, Brushes.Cyan, DashStyleHelper.Dash, 2);
|
Draw.Line(this, "Diag_ATRStop", false, CurrentBar - 1, stopPrice, CurrentBar, stopPrice, Brushes.Cyan, DashStyleHelper.Dash, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Breakeven Level - visual line when breakeven is triggered
|
RemoveDrawObject("Diag_Breakeven");
|
||||||
if (EnableAutoBreakeven && _breakevenMoved && !string.IsNullOrEmpty(_runnerSignalName))
|
|
||||||
{
|
|
||||||
double bePrice = Position.MarketPosition == MarketPosition.Long
|
|
||||||
? Position.AveragePrice + (BreakevenOffsetTicks * TickSize)
|
|
||||||
: Position.AveragePrice - (BreakevenOffsetTicks * TickSize);
|
|
||||||
Draw.Line(this, "Diag_Breakeven", false, CurrentBar - 1, bePrice, CurrentBar, bePrice, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. Provenance Link - subtle text with settings file reference
|
// 7. Provenance Link - subtle text with settings file reference
|
||||||
Draw.TextFixed(this, "Diag_Prov", "Prov: settings_" + Name.Replace(" ", "_") + "_" + DateTime.Now.ToString("yyyyMMdd"), TextPosition.BottomRight, Brushes.Gray, new SimpleFont("Arial", 8), Brushes.Transparent, Brushes.Transparent, 50);
|
Draw.TextFixed(this, "Diag_Prov", "Prov: settings_" + Name.Replace(" ", "_") + "_" + DateTime.Now.ToString("yyyyMMdd"), TextPosition.BottomRight, Brushes.Gray, new SimpleFont("Arial", 8), Brushes.Transparent, Brushes.Transparent, 50);
|
||||||
|
|||||||
Reference in New Issue
Block a user