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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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 algospoke, Today, 06:36 PM
|
0 responses
1 view
0 likes
|
Last Post
by algospoke
Today, 06:36 PM
|
||
Started by ETFVoyageur, Yesterday, 06:05 PM
|
8 responses
50 views
0 likes
|
Last Post
by ETFVoyageur
Today, 06:35 PM
|
||
Started by futtrader, 04-21-2024, 01:50 AM
|
7 responses
68 views
0 likes
|
Last Post Today, 06:31 PM | ||
Workspaces
by pibrew
Started by pibrew, Today, 06:10 PM
|
0 responses
7 views
0 likes
|
Last Post
by pibrew
Today, 06:10 PM
|
||
Started by pibrew, 04-28-2024, 06:37 AM
|
2 responses
19 views
0 likes
|
Last Post
by pibrew
Today, 06:06 PM
|
Comment