Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetProfitLoss, unexpected results

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

    GetProfitLoss, unexpected results

    I'm trying to program a strategy with two instruments, where we can have two instruments open at the same time.

    I want to close the position once both PnL are beyond a Profit, so I watch the PnL of both operations to wait for the right moment.

    My problem is that I'm getting wrong PnL from the first instrument:

    Code:
    			double Pnl1 = Positions[0].GetProfitLoss(Close[0], PerformanceUnit.Currency);
    			double Pnl2 = Positions[1].GetProfitLoss(Close[0], PerformanceUnit.Currency);
    			
    			Print("AvPr: "+ Positions[0].AvgPrice +" | "+ Positions[1].AvgPrice );
    			Print("Open PnL: "+ Pnl1 +" | "+ Pnl2);
    Gives me:
    Code:
    AvPr: 1228 | 0
    Open PnL: 242050 | 0
    AvPr: 1228 | 0
    Open PnL: 242025 | 0
    AvPr: 1228 | 0
    Open PnL: 242050 | 0
    AvPr: 1228 | 0
    Open PnL: 242075 | 0
    AvPr: 1228 | 0
    Open PnL: 242050 | 0
    AvPr: 1228 | 0
    Open PnL:[COLOR="DarkGreen"] -25[/COLOR] | 0
    AvPr: 1228 | 0
    Open PnL: 242050 | 0
    As you can see once in a while I get a "normal" PnL.

    What am I doing wrong?

    P.S.: There is no problem for the second instrument PnL once it gets open.

    #2
    Hi Lalocom, you seem to feed the Close[0] in both cases in your calcs, can you try printing the PnL with Closes[1][0] for the second instrument instead please?

    Comment


      #3
      I had to use Closes for both sentences. Now it works.

      Thank you very much.

      Code:
      double Pnl1 = Positions[0].GetProfitLoss(Closes[0][0], PerformanceUnit.Currency);
      double Pnl2 = Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency);

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      59 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      143 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      161 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      97 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X