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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        30 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        47 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        38 views
        0 likes
        Last Post CarlTrading  
        Working...
        X