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

Cant get realt time Unrealized ProfitLoss

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

    Cant get realt time Unrealized ProfitLoss

    Follwoing code mostly provide with negative decreasing value as unrealized PnL

    double currentPrice = (Position.MarketPosition == MarketPosition.Long) ? GetCurrentBid() : GetCurrentAsk();
    Print ("currentPrice="+currentPrice );
    double currentProfit = Position.GetUnrealizedProfitLoss( PerformanceUnit.Currency, currentPrice);

    Even when my Unrealized pnl in Ninjatrader worksatetion under account section, is positive.

    I need to get current unrealized pnl to decide to close all of my positions.

    if (currentProfit>0)
    ExitLong();

    How can I get a realtime Unrealized PnL?

    Thanks in advance.



    #2
    Hello godric,

    Thank you for your note.

    I attached 4 sample strategies which demonstrate pulling PL. You may be most interested in PrintPLOfStrategyBothRealizedAndUnrealized.

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

    Comment


      #3
      Thank you so much Alan for the codes. It solved my problem.

      Now I faced another one. If I run the same strategy on two different instruments (Lets say QQQ and DIA) and on each instrument I have several positions open, then I think the Unrealized PnL I will get would be a shared value based on all the open positions on both instrument's positions.
      How can I track each position Unrealized PnL, or how can I access each instrument's total Unrealized PnL, separately?

      Thanks in advance.

      Comment


        #4
        Hello godric,

        When running the strategy, on the strategies tab, click the arrow drop down next to the strategies name which will expand the instruments in the strategy and associated positions/pl/etc. See screen shot.

        Please let us know if you need further assistance.



        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rogers101, 05-05-2024, 11:30 AM
        13 responses
        38 views
        0 likes
        Last Post Rogers101  
        Started by dcriador, Yesterday, 01:43 AM
        4 responses
        25 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
        22 responses
        116 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by tradingnasdaqprueba, Today, 03:42 AM
        3 responses
        23 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Quanto, 04-17-2024, 10:43 AM
        3 responses
        28 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X