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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
64 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
35 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
59 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
62 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
51 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment