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!
See more
See less

Partner 728x90

Collapse

Realized PnL Reset

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

    Realized PnL Reset

    Hello!

    I read another post that you said the broker resets at their own discretion but when does Ninjatrader reset?

    I I got the summary email from them at 8 am EST and my Ninjatrader has not yet shown the reset.

    I am testing out a strategy where it takes profit at a certain level and then turns it self off until the next day without having to reset it manually. The profit stop has triggered but it still shows from yesterday so the strategy did not engage in any trades. Is there a setting I need to turn on?

    #2
    Hello litamm89,

    Thanks for your post.

    A running strategy will accumulate the PNL over the course of its run including on historical data. It (a strategy's PNL) has nothing to do with a broker resetting anything.

    You will need to create your own double type variable where at the beginning of the session you save the strategy's current PNL into the variable and then through the session, you can find your daily PNL by subtracting the strategy PNL from the variable. You then use that difference in guiding your strategy trade decisions.

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_PaulH

      Thanks for your response.

      Is that achievable through the strategy builder?

      How would I go about doing that so it resets at session close?

      Comment


        #4
        Hello litamm89,

        Thanks for your reply.

        It is a bit difficult to do in the strategy builder but it can be done. I have attached an example strategy to demonstrate, on a sim101 account, how this can be done.

        This Example strategy uses a custom series to be able to perform the simple math needed to track an accumulated PNL and a PNL that resets each session.

        The example strategy uses a simple cross over event to place market orders and profit/stops. The user inputs are:
        • DailyLossLimit - Sets the dollar amount of maximum daily loss that stops further trading in that session
        • DailyProfitLimit - Sets the dollar amount of maximum daily profit that stops further trading in that session.
        • UseDailyProfitLimit - A bool (default is false) then enables the use of a dailyProfitLimit.
        • EnableDebuggingPrints - A bool (default is false) that enables prints to the output window. Prints when first bar of session (to notify of first bar ) and per bar values of realizedPNL per session and accumulated realizedPNL.

        User variables are:

        DailyPNL - double, holds the current sessions PNL.

        OkToTrade - Bool that provides permission to the entry sets based on the Daily PNL compared to the limit(s)

        The strategy uses two custom series:

        YesterdaysPNL - Holds the last session PNL

        StrategyTotalPNL - Holds the strategies' accumulatedPNL.

        The sequence of sets 1-3 is critical and must be in the order of:

        Set1 - No conditions, Updates the custom series StrategyTotalPNL on each OBU and pull the previous value of YesterdaysPNl to the current bar of YesterdaysPNL.

        Set 2 - Condition is FirstBarOfSession, Actions: Pull in RealizedPNL into YesterdaysPNL, Prints on the chart the value of both dailyPNL and TotalPNL, reset dailyPNL to 0, resets OktoTrade to true

        Set-3 Condition is NOT firstbar of session, action is subtract the StrategyTotalPNL[0]- YesterdaysPNL[0] and put into DailyPNL variable.

        Sets 4 & 5 are for the debugging prints

        Set 6 Draws with text fixed on the lower left of the chart, the dailyPNL value.

        Sets 7 & 8 are trade entry with the OKtoTrade condition

        Sets 9 & 10 determine if daily loss/profit are exceeded and set OktoTrade false

        Set 11 drawing the backplane grey if !OktoTrade.

        Please note that this strategy is an educational example only and should not be considered as a viable strategy. Its purpose is to demonstrate how to use a DailyPNL per session, how to use that to trigger a bool that is used as the trade entry. Consequentially demonstrates how to use bools for input, use and set inputs, and how to use debugging with prints.

        DailyPNLexample.zip

        Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

        Note — To import NinjaScripts you will need the original .zip file.

        To Import:
        1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
        2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
        3. Select the downloaded .zip file
        4. NinjaTrader will then confirm if the import has been successful.

        Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_PaulH

          This is amazing!

          Thank you so much it looks like everything I need and asked for!

          Comment


            #6
            Hey Paul, how did was YesterdayPNL[0] = YesterdayPNL[1] was set? I can't figure the click sequence in Strategy Builder to pick previous day PNL.
            Click image for larger version

Name:	Screen Shot 2021-06-23 at 3.44.39 AM.png
Views:	884
Size:	135.1 KB
ID:	1161005
            Attached Files

            Comment


              #7
              Custom Series option allows custom expressions, right?

              Comment


                #8
                Click image for larger version

Name:	Screen Shot 2021-06-23 at 3.59.36 AM.png
Views:	902
Size:	104.8 KB
ID:	1161010For the sets 1-5, is it sufficient to add time conditions to trade between specific hours to those sets for actions not to take place unless between specified hours? Also, can you confirm the FirstBarOrSession would evaluate in this case to First Bar after session time start?

                Comment


                  #9
                  Hello mgalal,

                  Thanks for your replies.

                  how did was YesterdayPNL[0] = YesterdayPNL[1] was set? You should be able to select that line and then click the edit button to work back through it. However, it is not clear so here is the sequence:
                  1) Under Misc folder select "Set YesterdaysPNL"
                  2) This will then show BarsAgo and YesterdaysPNL
                  3) Move the mouse into the field "YesterdaysPNL (which shows a 0) and left click when "set" appears.
                  4) In the new "Value" window, select Misc>Custom series>
                  5) In the lower part make sure the field "Custom series" shows "YesterdaysPNL"
                  6) Change the bars ago to 1
                  7) Click Ok, Ok

                  Custom Series option allows custom expressions, right? Custom series was used because you can perform offset/math on them whereas you cannot with a standard variable once the value has been stored. However, to keep a value current in a custom series, you have to keep moving it to the current bar which is what the above sequence does.

                  the sets 1-5, is it sufficient to add time conditions to trade between specific hours to those sets for actions not to take place unless between specified hours? I would not use a time filter on sets 1 - 5. Use a time filter on the sets that place entries as that is really what you are after.

                  Also, can you confirm the FirstBarOrSession would evaluate in this case to First Bar after session time start? No, if you place a time filter, it would not change the trading hours first bar of session bool.

                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    NinjaTrader_PaulH

                    In the set 2 example when it shows Draw.TText and has as Tag. Does the @ make a difference what text there is? It is currently @DailyPNLexample Text_1" + COnvert.ToString(CurrentBars[0])

                    If I change that will it change anything? Does the tag have to match the strategy name?

                    Comment


                      #11
                      NinjaTrader_PaulH

                      Sorry I sent my email a bit early.

                      In the second set what does the Y value represent?

                      I used the trial set and changed some things around in terms of the entry and exit. It looked to work until I threw in another Custom Series double TotalPnL. I have them both using the OkToTrade bool. Could that be messing it up because they are both changing the bool to false? The Total PNL is set to $225 profit and -$450 loss but it doesnt seem to respect what I set. If I create another bool and call it OkToTradeDaily would that fix the issue to have each the Daily PNL and TotalPnL on their own bool?

                      Comment


                        #12
                        Hello litamm89,

                        Thanks for your replies.

                        In the Draw.Text(), the @ is added by the strategy builder and it just means to take the string as is without trying to look for escape code within the text. You can change the tag name to be anything you wish. I added Misc>Current bar to the tag name to make the tag name unique per bar so that the text is always visible, but it is only drawn on the first bar of the session.
                        No, the tag name does not have to match the strategy name, again that is a strategy builder default naming convention, you can change it to suit your needs.

                        The Y Value is the Y axis location (the price value) (height in chart display) where you want to display the value.

                        Here is a link to a short video that actually covers the tag name and Y value: https://paul-ninjatrader.tinytake.co...MF8xMTMwNTc0MA

                        It would be difficult to answer regarding your change to the logic. In general, a separate bool would likely be the better way to proceed.

                        If it is still not performing as expected then you will need to begin a debugging process by printing the value/state of the bools on a per bar basis. Here is a link to a short video on constructing a print statement in the Strategy Builder: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw

                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Will the DailyPNL be calculated correctly if I enable and disable the strategy during a session?

                          Comment


                            #14
                            Hello councilsoft,

                            Thank you for your reply.

                            If you stop and restart the strategy it will calculate over the historical data on the chart and calculate what the PnL would have been had it been running that whole time. This may differ slightly to the real time performance, but it should be pretty close to the live calculated PnL since the example runs On Bar Close anyway. If you were running it On Price Change or On Each Tick, you'd see greater differences, as on Historical data, all that is known is the OHLC of a bar, so the strategy can only run On Bar Close on historical data, which would cause more significant differences between live and historical calculations.

                            Please let us know if we may be of further assistance to you.
                            Kate W.NinjaTrader Customer Service

                            Comment


                              #15
                              So it would not reset my current day/sessions PNL when I disable enable? I will see the PnL from where I left off?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Barry Milan, Today, 10:35 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by WeyldFalcon, 12-10-2020, 06:48 PM
                              14 responses
                              1,428 views
                              0 likes
                              Last Post Handclap0241  
                              Started by DJ888, Yesterday, 06:09 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              40 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Today, 08:51 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post bill2023  
                              Working...
                              X