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

How to Detect Total PnL for all Enabled Strategies

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

    How to Detect Total PnL for all Enabled Strategies

    Hello,

    I am using Managed Approach with EnterLongLimit, SetProfitTarget, and SetStopLoss

    I have 5 strategies enabled for 5 instruments (ES, CL, YM, NQ, and TF). Total of 5 strategies running.

    If my total PnL for all 5 strategies running is less then $-450.00, I would like to Cancel and Exit all trades until the start on new session (Bars.FirstBarOfSession), then reset the total PnL to $0.00

    total PnL is the combined PnL for all strategies enabled on the 5 instruments.

    Questions:

    1. Does the attached logic accomplished my task?

    2. When does unrealized_pnl and realized_pnl reset back $0.00 in the attached logic? I need the reset to occur at the start time of new session.

    3. Since I am using Managed Approach will ExitLong() and ExitShort() execute with my EnterLongLimit?

    4. Will the Position.GetProfitLoss and Performance.AllTrades.TradesPerformance.Currency.C umProfit work in Market Replay and Strategy Analyzer? So far in back test simulation, it stops once cumulative PnL is less then $-450 and no reset.

    Thanks and I look forward to your response
    Attached Files
    Last edited by simple_goodoboy; 07-24-2017, 09:45 PM.

    #2
    Hello,

    Thank you for the post.

    The Position object would only relate to a Single strategies position. In the situation where you have 5 strategies, this logic would report only the position for the instrument it is running on.

    For your idea to work as you want, you would instead need to migrate the code for the 5 different strategies into a single strategy that trades 5 instruments. This could monitor all positions at once and then stop the overall strategy once your pre determined amount is met. There is a sample that comes with the platform of trading multiple instruments named SampleMultiInstrument.

    The logic you have would be reset each bar, you currently have it enclosed in a if(true) statement which is always true. The PnL would reset as the orders fill and your position changes to flat.


    Regarding the EnterLongLimit, the ExitLong would be ignored if EnterLongLimit was open, you can find this documented in the Internal Order Handling Rules here: http://ninjatrader.com/support/helpG...d_approach.htm
    Methods that generate orders to exit a position will be ignored if: A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction


    Regarding your final question, these items do work historically as you noted the value is changing. The reset is likely based on your logic. You would likely first need to address the items mentioned above and then review your logic using Print statements to determine what specifically is happening with the reset.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jim for responding

      A few more questions please:


      Originally posted by NinjaTrader_Jesse View Post
      For your idea to work as you want, you would instead need to migrate the code for the 5 different strategies into a single strategy that trades 5 instruments. This could monitor all positions at once and then stop the overall strategy once your pre determined amount is met. There is a sample that comes with the platform of trading multiple instruments named SampleMultiInstrument.
      With a multiple instrument strategy :

      1. Can back test with Strategy Analyzer and show the results of all 5 instruments in the report? Can I still Optimize this multiple instrument strategy for optimized parameters per instrument because I will have the total PnL stop logic in this strategy?

      2. Can I see each instrument trades in the Accounts Performance ---> Trades tab if using the multiple instrument strategy ?

      Originally posted by NinjaTrader_Jesse View Post
      Regarding the EnterLongLimit, the ExitLong would be ignored if EnterLongLimit was open, you can find this documented in the Internal Order Handling Rules here: http://ninjatrader.com/support/helpG...d_approach.htm
      Methods that generate orders to exit a position will be ignored if: A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
      1. Since I can not use ExitShort() and ExitLong() with EnterLongLimit and EnterShortLimit with the Managed Approach methods, how can exit open positions if needed with the Managed Approach?

      2. Is this the same case for NT8?

      3. Why can't use ExitShort() and ExitLong() with EnterLongLimit and EnterShortLimit with the Managed Approach methods? I am curious why this can not be done.

      Thank you so much for helping me with this effort.

      Comment


        #4
        Hello,

        Thank you for the reply.

        1. Can back test with Strategy Analyzer and show the results of all 5 instruments in the report?
        Yes, you can see the individual trades for each instrument along with the standard summarized results.

        Can I still Optimize this multiple instrument strategy for optimized parameters per instrument because I will have the total PnL stop logic in this strategy?
        You can still optimize the strategy and any optimizable properties it may have. A multi instrument strategy would work with the logic you supply to it so if you want to optimize only one instrument you would need to likely prevent it from doing any logic on the other instruments during that test specifically. Otherwise, this is treated the same as any other strategy in regard to where it can be used.


        2. Can I see each instrument trades in the Accounts Performance ---> Trades tab if using the multiple instrument strategy?
        Yes. You can see the individual trades and the Instrument the order was placed on. The most simple way to address these questions would be to create a simple multi instrument strategy with two instruments and then run it in each of the tools you would use to see the results. You would need to ensure that an order is placed to both instruments to see results for both instruments and not just the primary.

        1. Since I can not use ExitShort() and ExitLong() with EnterLongLimit and EnterShortLimit with the Managed Approach methods, how can exit open positions if needed with the Managed Approach?
        You would need to cancel the Limit order you have in place prior to trying to use ExitShort or ExitLong as you are running into a managed order handling rule.

        2. Is this the same case for NT8?
        Yes.

        3. Why can't use ExitShort() and ExitLong() with EnterLongLimit and EnterShortLimit with the Managed Approach methods? I am curious why this can not be done.
        This is a set rule in the platform when using the managed approach and is documented for each of the Managed approach methods. To avoid managed order handling rules you would instead need to use the Unmanaged approach. This is considerably more difficult as this assumes you are going to take total control and account for everything that happens in regard to your orders. You can read about this approach here: http://ninjatrader.com/support/helpG...tsub=unmanaged

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you Jesse for the response.

          A few more questions regarding canceling a filled limit entry order.

          See the example attached please.

          The limit order is filled on YM, and the Stop Loss (created by SetStopLoss) and Profit Target (created by SetProfitTarget)

          How would I exit these orders? I am using Managed Approach.

          Thank you,
          Attached Files
          Last edited by simple_goodoboy; 08-01-2017, 08:00 PM.

          Comment


            #6
            I also have the same problem.


            -----------------------------------------------------------------------
            *nhung tinh nang cua am thanh tren o to*| *do am thanh xe o to*| tien ich cua am thanh xe hoi*

            Comment


              #7
              Hello,

              Thank you for the reply.

              I wanted to check, by Exit these orders do you mean to cancel the Target and Stop or do you mean to Exit the Position that the Limit order had Entered?

              To Exit a position, you would need to either allow a Target or Stop that is active to fill, or use an Exit method rather than use a Stop and Target.

              To Cancel the Stop or Target, if exiting the position you could adjust one of the prices to the Close price to fill the order. If canceling the orders, you can catch the IOrder objects for these orders in OnOrderUpdate and store the IOrder as a variable. Later when needed, the IOrder can be used with CancelOrder()







              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Jesse View Post
                Hello,

                Thank you for the reply.

                I wanted to check, by Exit these orders do you mean to cancel the Target and Stop or do you mean to Exit the Position that the Limit order had Entered?
                Thanks for response Jesse,

                I mean to

                1. Exit the position that the limit order had entered.
                2. Then Cancel the Target and Stop Loss order.


                If I was manually trading, I would simply flatten all positions and orders.

                Of course, if I want to do this, I can move the profit target order or stop loss order to current Bid or Ask price, and this should exit the position and cancel the stop loss or target order.

                I was not sure if there was a more reliable method to exiting the position (which will automatically cancel the target and stop loss order).

                Maybe if I fist cancel the target and stop orders, then Exit the limit positiion using ExitShort() or ExitLong().

                Thanks for your any recommendation you have.

                Comment


                  #9
                  Hello,

                  Thank you for providing more details.

                  Yes, in this case, you could likely just use the Exit methods.

                  The ExitLong and ExitShort methods do not apply to the internal handling rules so if you have SetStopLoss active as an example, you can still use these methods to exit the position. A SetStopLoss has logic for the Position as well, in case the position is closed by an exit method it would be canceled:
                  A stop loss order is automatically canceled if the managing position is closed by another strategy generated exit order



                  You can still use the other options provided in the last post too it's really up to how you want your logic to handle the exit situation.


                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jesse View Post
                    Hello,

                    Thank you for the reply.



                    Yes, you can see the individual trades for each instrument along with the standard summarized results.


                    I look forward to being of further assistance.
                    I don't see that happening. For a Strategy Analyzer with 5 instruments, Display has no Analysis view enabled. Analysis would have been great, as it would have given a combined PNL view, which doesn't happen.

                    Is there a way to see such a combined PNL for a strategy running on 5 instruments?

                    Comment


                      #11
                      Hello andrei.reiand,

                      You could select trades under display to see the trades made on all instruments.

                      I will submit a feature request to allow the strategy analyzer to break it down PL by instrument on the strategy.

                      For now you could manually calculate PL or right click on the trades grid and export to excel to filter PL by instrument.

                      Please let us know if you need further assistance.
                      Alan P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by rtwave, 04-12-2024, 09:30 AM
                      2 responses
                      20 views
                      0 likes
                      Last Post rtwave
                      by rtwave
                       
                      Started by tsantospinto, 04-12-2024, 07:04 PM
                      5 responses
                      68 views
                      0 likes
                      Last Post tsantospinto  
                      Started by cre8able, Today, 03:20 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post cre8able  
                      Started by Fran888, 02-16-2024, 10:48 AM
                      3 responses
                      49 views
                      0 likes
                      Last Post Sam2515
                      by Sam2515
                       
                      Started by martin70, 03-24-2023, 04:58 AM
                      15 responses
                      115 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X