Announcement

Collapse
No announcement yet.

Position.realizedPL(PositionID) question

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

  • Position.realizedPL(PositionID) question

    I have been working with the Automated Trading Beta for awhile now and it works quite well, the execution speed and available functions are terrific. I have built an entire platform trading multiple currencies to Interactive Brokers and it all works great. I have only one query and it could be that I am misreading the documentation.

    I am attempting to determine the realized profit/loss, per my broker's records, from a particular trade, once the trade has been closed out. Documentation states that "Position.realizedPL(PositionID)" should return the realized P&L for that specified position ID. Instead I am getting the total P&L for the currency pair in question, with that trade included, as of the close of that trade.

    My question is, is there a method in place by which I can retrieve the realized P&L for a particular trade?

    Thanks in advance,
    Tom

  • #2
    Hi Tom

    I also use EFS-AT with IB and find it very good.

    I think that there is NO inbuilt function to give you the P&L for an individual trade.

    I calculate this info myself.

    Entry price for position can be fund quite easily using

    function onPositionUpadte(positionID)
    ....
    nEntryPrice = Position.price(positionID);

    Finding an exit price is a bit more difficult.

    I capture last execution price in
    function onExecutionUpdate(executionID)
    { ....
    nLastExecutionPrice = Execution.price(executionID);
    }

    and in OnPositionUpdate when position becomes 0
    I set exit price using nLastExecutionPrice


    if (Position.qty(positionID) == 0)
    nExitPrice = nLastExecutionPrice

    Comment


    • #3
      Thanks for getting back with me Adam,
      I've been doing it similar to how you have been but I have been using the fill price on whatever order, be it a stop or a profit exit, to do the calculations. I just figured that because we had to send a position Id that "Position.realizedPL(PositionID)" was intended to return the realized P&L for the position that the position ID referenced.
      Cheers !

      Comment


      • #4
        thanks
        this is great suggestion
        i missed out this function

        Comment

        Working...
        X