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

Profit calculation at position or trade closing

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

    Profit calculation at position or trade closing

    Hello

    I would like to calculate the profit when a position is closed on the event OnExecutionUpdate (in the instrument currency).

    I cannot use the account profits information before and after the trade because because the account information is common to all strategies running for the same account..

    Looking at execution object, the order associated with the execution has the exit price but not the average opening price to make the calculation.

    One idea that I had is to store the strategy position information about average price for this instrument when the trade is opened and make the calcutions when it is closed.

    Is there a simpler approach? Would this one provide the right information?

    Also, I would like so Sync the position with the account on startup of the strategy. In this case, the information in the strategy position would be consistent?

    Regards

    Zulok

    #2
    Hi zulok, thanks for your post.

    You can get the average entry price at time of entry and use that in the PnL calculation, that would probably be the most straight forward way of doing that. You can also monitor the OnPositionUpdate event.

    The Adopt Account Position startup behavior would be the one to use to do this. Make sure to enable IsAdoptAccountPositionAware and that the strategies order objects are hendled properly. I attached an example strategy to this post.

    Please let me know if I can assist any further.
    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks CrisL

      As an alternative could TRADES collection be used?

      thanks

      zulok

      Comment


        #4
        Hi zulok, thanks for your reply.

        The Trade collection would only contain closed trades, so I don't think you would want to use this if you need to calculate PnL before the position is closed.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris L

          Then it is what I was looking for. I want to calculate the profit as the position closes.

          Thanks

          Zulok

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Started by frankthearm, Today, 09:08 AM
          4 responses
          10 views
          0 likes
          Last Post frankthearm  
          Started by yertle, Today, 08:38 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by adeelshahzad, Today, 03:54 AM
          3 responses
          18 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by bill2023, Yesterday, 08:51 AM
          6 responses
          27 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X