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 display realtime PnL in Chart Stradegy

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

    How to display realtime PnL in Chart Stradegy

    OK so I have a simple strategy once the trade goes long or short,

    I want to display the current real time PnL in the toolbar or anywhere in the chart, just like Bartimer works.

    How can that be done, the other problem is that in SuperDom PnL shows IT I guess in ticks where as if I have a 5 minute chart It wont get a PnL update until next bar event.

    That is not fast enough, PnL just like Time as in the case of Bartimer should be counting away irrelevant to the chart period.

    So how do I display PnL of the current trade withing a strategy chart of say 5 minutes where we want the PnL to reflect the fastest PnL going on for that trade, just like it is displayed in SuperDom or the Chart trader, programmatic-ally.

    Thanks http://www.ninjatrader.com/support/f...lies/smile.png

    #2
    Hello Nettony,

    Thank you for your post.

    Your best bet would be to calculate the Unrealized PnL with the example below -
    Position.GetProfitLoss(Close[0], PerformanceUnit.Points)
    http://www.ninjatrader.com/support/h...profitloss.htm

    Additionally, if you want this to update more frequently you would want to run a timer event to call the timer method and update your PnL this way.
    http://www.dotnetperls.com/timer
    .
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Multiple concurrent orders

      What if one has submitted multiple concurrent managed orders with unique entry signal names and one wants the realtime PnL of each order? Thanks.
      Multi-Dimensional Managed Trading
      jeronymite
      NinjaTrader Ecosystem Vendor - Mizpah Software

      Comment


        #4
        jeronymite, I'm assuming all on the same instrument and a single series script - in this case you want to self calculate from the individual executions seen - what Cal had posted was for the overall strategy position.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Different Instruments

          Thanks for the response, Bertrand.

          Multiple instruments (28), longs and shorts, individual ask and bid series per instrument (28x2).

          Looking for an accurate realtime PnL for each entry order submitted during the entire duration of the trade, and for the final PnL after each order exit / trade completion.

          So, for example, three orders: EURUSD Long, AUDNZD Short, CHFJPY Long, all submitted at different times on the relevant ask or bid of the instrument, all completing in due course at different times on the relevant bid or ask of the instrument. Subsequent trades on the same instruments may be made in the same invocation of the strategy.

          Thanks, as always, for your advice!
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment


            #6
            If you have different instruments, then you can also directly access the Positions array for the GetPnl call -



            Or you self calculate via the individual executions you have access to...
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Progress ... and Regress

              Using the Positions array, I am able to get the real-time PnL during the life of the position. Thanks!

              However, another oddity is occurring. After the position closes, I use the Performance methods to obtain the final PnL for the position using the following approach, noting that every Enter and Exit method uses unique signal names:

              Code:
              Performance.RealtimeTrades.GetTrades(Instrument,EntrySignal,1).
                   TradesPerformance.Currency.AvgProfit ;
              The oddity is that it works perfectly for Longs but returns zero for Shorts. In fact, all the Performance metrics behave the same: for Longs, all values are populated with valid values; for Shorts, all values are zero. It suggests incorrect parameters for the Shorts, but the documentation states the parameters as per the invocation above.

              Your advice most appreciated, as always! Thanks.
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment


                #8
                Hi jeronymite,

                With
                Code:
                Performance.RealtimeTrades.GetTrades(Instrument,EntrySignal,1).TradesPerformance.Currency.AvgProfit;
                Are you getting a compile error with this?

                Instrument is an object but this call needs a string with the name of the instrument. (Instrument.FullName).

                The entry signal also needs to be a string with the name of the order. Is EntrySignal a string?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  More info

                  The "code" I gave is "pseudo-code". Yes, I use appropriate string values. As I say, it works perfectly for Longs, but not at all for Shorts. I have checked the actual string values being passed and they are exactly as expected.
                  Multi-Dimensional Managed Trading
                  jeronymite
                  NinjaTrader Ecosystem Vendor - Mizpah Software

                  Comment


                    #10
                    Hi jeronymite,

                    I did a test with this and I can confirm I get the same behavior. Works for long orders but does not work for short orders.

                    I have alerted our development department about this issue.

                    In the meantime try the following work around instead:
                    Code:
                    for (int i = Performance.RealtimeTrades.Count; i>0; i--)
                    {
                    if (Performance.RealtimeTrades[i-1].EntryExecution.MarketPosition == MarketPosition.Short)
                    {
                    Print(Performance.RealtimeTrades[i-1].ProfitCurrency);
                    }
                    }
                    This will print the profit of the last real time short trade.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks!

                      Thanks, Chelsea!
                      Multi-Dimensional Managed Trading
                      jeronymite
                      NinjaTrader Ecosystem Vendor - Mizpah Software

                      Comment


                        #12
                        Hi jeronymite,

                        Wanted to let you know that this issue is tracked with ID # NTEIGHT-8503 and has been corrected with Beta 3.

                        Thanks for tracking that down!
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by michi08, 10-05-2018, 09:31 AM
                        2 responses
                        738 views
                        0 likes
                        Last Post Denver_Wayne  
                        Started by sightcareclickhere, Today, 01:55 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post sightcareclickhere  
                        Started by Mindset, 05-06-2023, 09:03 PM
                        9 responses
                        258 views
                        0 likes
                        Last Post ender_wiggum  
                        Started by Mizzouman1, Today, 07:35 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post Mizzouman1  
                        Started by philmg, Today, 01:17 PM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_ChristopherJ  
                        Working...
                        X