Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetUnrealizedProfitLoss not working

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

    GetUnrealizedProfitLoss not working

    Hi, I want to get the PnL each tick, real time, but it is not working... just this simple code:

    if (Position.MarketPosition != MarketPosition.Flat)
    {
    PL = Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency);
    Print(Convert.ToString(PL));
    }

    It always show 0, despite there being an order running and moving the unrealized PnL...

    Any idea? Thanks...​

    #2
    Hello federicoo,


    Thank you for your post.


    Please watch this quick video I made for you where I try to reproduce your results:


    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.



    I used your code snippet and was able to get the unrealized PnL to print to the output window.


    I suggest reviewing the Log window in the Control Center for any messages when running your strategy. Perhaps there is another section of code in your strategy that is preventing it from running.


    Additionally, for back-testing a double price to compare against should be provided like in our example below:
    https://ninjatrader.com/support/help...profitloss.htm


    This is because the last market update isn't available in backtest.​


    Please let me know if I can assist further.

    Comment


      #3
      Thanks Gaby, but it is not my case. I want to register PnL for manually open orders. If you take off the line entering orders by the script and try the strategy just openning orders manually, it doesn't work... How can I register the unrealize PnL for manual openned, real time positions?

      Comment


        #4
        Unfortunately, NinjaScript strategies are only able to see orders submitted from the strategy. It cannot see manually submitted orders.

        You can use the Add On approach to add an event handler to the Account.PositionUpdate in order to detect position changes to the account for manual orders.

        Please see this Help Guide page, which provides a code example of subscribing/unsubscribing to position update events from an Add On: PositionUpdate

        Please let me know if I can assist further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X