Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily Max Profit and Loss User Input Parameter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Daily Max Profit and Loss User Input Parameter

    Hello,

    I would like to create some code for the algo to stop trading for the day when:

    1. PnL is greater or equal to $400 Daily Max Profit user input parameter in strategy analyzer
    2. PnL is less than $200. Daily Max Loss user input parameter in strategy analyzer

    I would also like to use strategy analyzer to back test and optimize the Daily Max Profit and Daily Max Loss.

    Can I please have some help with building this logic?

    Thank you so much.

    #2
    Hello,

    Thanks for your post.

    We can provide you with help guide references for the method(s) you will use and provide a general concept for the logic. It will be up to you to code and debug your actual logic/strategy. If you would like a strategy created for you, we can provide references to 3rd party programmers in the NinjaTrader Ecosystem.

    In order to optimize, you will need to create two user inputs, one for Max Loss and the other for your Max loss values. These would be a double type of variable. If you are not familiar with how to create a user input, I would suggest using the Strategy Wizard (not the strategy builder). The wizard will create the inputs for you based on your selections. Here is a link to the ninjascript wizard (which provide a wizard for all types): https://ninjatrader.com/support/help...?ns_wizard.htm

    The strategy realized PNL is accumulated over the duration of the strategy and there is no "daily" PNL so this is something you would need to create from the strategy realized PNL. You can create a double type variable that, at the beginning of the trading day, can be assigned the current realized PNL of the strategy. Throughout the day then, the daily PNL would be equal to the strategy realized PNL minus the value of the variable. The next trading day, the variable is updated with the strategies realized PNL which again puts the daily PNL back to 0.

    You can decide when to update the double variable that holds the strategy PNL. Options are at the first bar of the trading session Reference: https://ninjatrader.com/support/help...rofsession.htm or you can create a time based on condition to do this at some specific time.

    So with the ability to pull the "daily" PNL you can compare that value to the daily max profit and loss values and suspend trading for the rest of the trading day when met or exceeded. To suspend trading you would want to use a bool type variable that is either true or false. You would use the bool variable in every entry condition set so when it is true and your other entry conditions are true and entry is made when it is false and your other entry conditions are true no entry will be made.

    Here is a link to the help guide for the realized PNL of a strategy: https://ninjatrader.com/support/help...?cumprofit.htm

    Comment


      #3
      Click image for larger version  Name:	1.png Views:	0 Size:	44.6 KB ID:	1174533




      Click image for larger version  Name:	2.png Views:	0 Size:	45.2 KB ID:	1174534
      Like this?
      Then just make sure it wont take a new position if psuedoDailyPNL(double) is lower than the DailyMaxLoss(double)? thanks

      Comment


        #4
        Hello ezrollin,

        Thanks for your post.

        No, that would not work. When you apply your strategy to a chart and the chart likely has historical data of 1 or more days then your strategy will be performing virtual historical trades as well as eventually real time trades and all of these trades PNL are accumulated. So this means that each day the strategy PNL will reflect the PNL of that day and all previous days.

        At the beginning of the session you would do something like this:

        1) store the accumulated pnl into a double type variable, this is the accumulated PNL up to the beginning of the day

        2) During the day, the daily PNL is actually the accumulatedPNL minus the value of the double variable from the beginning of the day.

        The issue is that the Strategy Builder cannot perform simple subtraction on a variable. You need to use a custom series as with a custom series you can perform math operations but a custom series means that you have to be able to keep moving values with each new bar. I've created a DailyPNL example and explained it in detail here: https://ninjatrader.com/support/foru...et#post1156861

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        49 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        67 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X