• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 aaadetos, Yesterday, 08:39 PM
          0 responses
          5 views
          0 likes
          Last Post aaadetos  
          Started by Teebone21, Yesterday, 03:57 PM
          0 responses
          5 views
          0 likes
          Last Post Teebone21  
          Started by GeoOrtiz, Yesterday, 03:44 PM
          0 responses
          7 views
          0 likes
          Last Post GeoOrtiz  
          Started by ralett, Yesterday, 03:41 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Tyler  
          Started by Walker DM, Yesterday, 03:14 PM
          2 responses
          12 views
          0 likes
          Last Post Walker DM  
          Working...
          X