• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

      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!

          Comment


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

            http://www.ninjatrader.com/support/h.../positions.htm

            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.

              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.

                  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!

                      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 thgamey, Today, 02:05 AM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_PatrickG  
                        Started by yeshujbp, Yesterday, 02:40 PM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_PaulH  
                        Started by sardana, Today, 05:52 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post sardana
                        by sardana
                         
                        Started by Mykro, Yesterday, 04:58 PM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_PaulH  
                        Started by akuntysh, Today, 02:43 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post akuntysh  
                        Working...
                        X