protected override void OnBarUpdate()
{
// At the start of a new session
if (Bars.FirstBarOfSession && FirstTickOfBar)
{
priorTradesCumProfit = Performance.AllTrades.TradesPerformance.Currency.CumProfit;
}
//// After our strategy has a PnL less than -$1500 we will stop our strategy
if (Performance.AllTrades.TradesPerformance.Currency.CumProfit - priorTradesCumProfit <= -1500)
{
/* A custom method designed to close all open positions and cancel all working orders will be called.
This will ensure we do not have an unmanaged position left after we halt our strategy. */
StopStrategy();
// Halt further processing of our strategy
return;
}
//Conditions for Entry here...
if(ToTime(Time[0]) >= 155000)
{
ExitLong(200);
}
if (Positions.MarketPosition == MarketPosition.Flat && entrySubmit)
{
// Reset our bool to false to allow for submission of our entry order
entrySubmit = false;
}
}
private void StopStrategy()
{
// If our Long Limit order is still active we will need to cancel it.
CancelOrder(myEntryOrder);
// If we have a position we will need to close the position
if (Position.MarketPosition == MarketPosition.Long)
ExitLong(200);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
PnL max loss per day & Exit delay.
Collapse
X
-
PnL max loss per day & Exit delay.
Backtesting purposes. I'm using the script below from the Sample script for Halt Processing. I have a condition to exit by 3:55 each day and limit daily loss to 1500. Near to the last day of the backtest run period(which is a month long) a bunch of trades do not exit by the end of the day and do not exit until 2 days later on a Friday at 4pm. Any idea why it might be doing this?
Code:Tags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment