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 DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Working...
        X