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

Compare unrealized PnL with realized one

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

    Compare unrealized PnL with realized one

    Please help me compare unrealized PnL with realized one. I do this through the Strategy Builder. One of the values ​​should be my input (unrealized PnL in currency, for example), so that I can create a condition like: if the realized PnL is greater equal to unrealized PnL. The idea is to cure losses if any ...

    So the problem is that realized PnL in case of losses is shown with a minus sign (- $ 100 for example). So I need to somehow multiply realized PnL by -1 so that the strategy can compare them ..? If I use my Input value for this it seems impossible. Perhaps there are some other methods?


    Click image for larger version

Name:	P&L.jpg
Views:	513
Size:	79.5 KB
ID:	1103202

    #2
    Hello Aporshnev,

    Thanks for your post.

    I do not know if this can work for you but I would suggest creating a double type custom series (in the additional data window> Custom series) as you are able to perform math via the Offset on custom series.

    Then in a set use the condition Strategy>MarketPosition, Not Equal, Strategy>MarketPosition> Flat. In the action side you can assign the realized PNL to the current bar of the custom series (under Misc> Set (name of series). This is to get the realizedPNL into the series.

    In the set where you wish to check realized to unrealized you would select Misc>Custom series> (name of series) (which holds the realizedPNL) and can now offset with a times -1.

    Reference: "How to offset an item value" https://ninjatrader.com/support/help...on_builder.htm

    Alternatively, you can unlock the strategy builder strategy and work directly in Ninjascript.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you, the solution turned out to be useful. If possible, I will ask another question: the method above allows to work with a fixed value and perform math for further condition, nevertheless, is it possible to make a direct comparison of the realized pl with the unrealized pl through the strategy builder?
      I do not have enough qualifications to work with an unlocked script directly ...

      Thank you.

      Comment


        #4
        Hello Aporshnev,

        Thanks for your reply.

        For common understanding, RealizedPNl is what the PNL of the strategy is accumulated over the history of tsades of the Strategy. Unrealized PNL is the active trade (if any) PNL which the value would depend on the moment when it is checked. So yes you could compare then two when you are in a market position that is not flat.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you for the clarification. My idea is that if there is a negative result from closed trades, by opening another position, the strategy compares unrealized PnL with realized ones and closes the position when they are equal.
          Therefore, I am interested in how they can be compared in order to establish this as a condition.
          Can you please clarify how can I compare them using strategy builder?

          Comment


            #6
            Hello Aporshnev,

            Thanks for your reply.

            Using your idea to multiply the PNL * -1 in the custom series will provide the opposite result, IE a positive value when PNl is less than zero You can then compare the unrealized PNl (when you are in aposition) with the custom series PNL proxy and if Greater or equal to then exit the position.

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply and for your efforts in helping me. I have already implemented what you write about and tested it - yes, it works well, however, this is a comparison with the "proxy" PnL. This can only serve well as a driver for activating a condition (necessary variable, etc.) The result is not always accurate, since the number in the custom series is never equal to the exact PnL - there is always an offset either up or down (due to commissions, etc.). Therefore, what I want to achieve is to make the most accurate comparison of the realized versus the unrealized, in order to exit a position with zero loss.

              Comment


                #8
                Hello Aporshnev,

                Thanks for your reply.

                The strategy, in the Strategy Builder, only knows of the RealizedPNL it can access.

                As a workaround, you may wish to add a further offset.

                If you would like your strategy created for your specific needs, we can provide a link to 3rd party programmers who can provide that service.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you. I understand.
                  If you suppose this possible I will be grateful if we can initiate this as a future request to the development team to add such an option to the strategy builder.
                  Have a nice day.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by algospoke, Yesterday, 06:40 PM
                  2 responses
                  23 views
                  0 likes
                  Last Post algospoke  
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  45 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  22 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  181 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X