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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      646 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      367 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X