Daily profit/loss limit

This free NinjaScript strategy  will close any open positions and stop trading for the current day if your daily P/L reaches a set negative or positive value. If you have a strategy that you run uninterrupted over multiple days, this indicator will reset the daily P/L back to zero at the beginning of each day for a fresh start. In addition to limiting trading based on P/L, you can limit the daily timeframe in which you’d like to trade, i.e. trade only from 9am to 11am.

This NinjaScript download is a single zip file that you import directly into NinjaTrader. It’s not assembled which means you have full access to view and change the source code either in NinjaScript Editor or your preferred way to edit .cs files.

Details / Instructions:
There are simpler ways to accomplish a daily PL limit if you stop and restart your strategy every trading day, but those ways don’t always work when back testing over multiple days – this way does.

Calculate must be set to on each tick.

If you paste this exit logic into your code, make sure your entries have a signal name that the exits reference. In this case they’re “long” and “short”.

Adjustable variables:
The dailyLossLimit and dailyProfitLimit variables located in the Dashboard region of the code determine the negative or positive daily P/L in currency at which you want the strategy to stop taking trades for the day.

The dailyOpenTime and dailyCloseTime are the beginning and end times of your trading day (in hhmmss format).

This code will work with any time series because it’s checking the time within the OnMarketData method. If you’re running a 1-tick time series you could move this code from OnMarketData to OnBarUpdate and check the time with ToTime(Time[0]). Note: NT doesn’t currently offer a way to check the session start/stop time which is why we have to set variables for this.

This code will not work with releases prior to NinjaTrader 8. Click here if you don’t know how to install NT strategies. Use at your own risk, and backtest backtest backtest before you go live with any strategy.


  1. Hi. This is very cool. Thank you so much.
    I installed it and I don’t know if I set it up correctly but it doesn’t work in my SIM account.
    Do I need a strategy to make it work? If you trade by yourself should it work too?
    Thank you!

    1. Hello. This is meant to stop an automated strategy from trading, so if you’re trying to prevent manual entries, this won’t do it.

    1. Yes. Just replace the stuff in the “entry logic” region with your own entry logic that uses an SMA crossover. You can copy and paste from the SampleMACrossOver strategy.

  2. Good Day,
    I am actually need this indicator that will work with NT-7, but for MANUAL ENTRY.
    Is it possible to find someone that can help to create one for me ?
    Your response will be appreciated.


  3. Greatly needed functionality for NinjaTrader! Been trying to accomplish this on my own and NO GO.

    But my strategies are being created with Strategy Builder. And although I assume I can take the logic and force fit it into this strategy it would be a greater benefit if it was an indicator that I could call from Strategy Builder.

    Is there any chance this can be modified for that?

    1. I’m planning on creating an indicator section to the site very soon so keep checking back. I’ll add this request to the shortlist.

    2. I now have a sister site up for indicators ninjatrader-indicators.com. You’ll see an “indicators” link in the menu at the top of the page. I’ll bump this request to the top of the list to develop next. Thanks!

    1. I now have a sister site up for indicators ninjatrader-indicators.com. You’ll see an “indicators” link in the menu at the top of the page. I’ll bump this request to the top of the list to develop next. Thanks!

    1. It’s not a standalone strategy, but rather example code meant to be incorporated into your own strategy, so if you’re running multiple strategies, you could add the logic to each one and it will work.

  4. I down loaded it. Now what? Is there a video I can watch? I have no Idea how to use code. I’m barely good with strategy builder.

    1. Hi Brett, All the code on this site is for advanced users who manually code their strategies and have some knowledge of C#. I’m currently working on an indicator version of this that will be accessible in strategy builder. That should be uploaded to ninjatrader-indicators.com this week. If you want to learn more about coding ninjascript I’d start by watching some C# intro videos on youtube and poking around in some of the indicators/strategies that come with ninjatrader in the ninjascript editor.

Leave a Reply

Your email address will not be published. Required fields are marked *