How do Metatrader brokers calculate P&L for futures contracts???

 

Hi.  After posting (then deleting!) a long and confusing post regarding 'decrepencies' in the Profit totals in the Accounts history menu, I decided it is probably better to just state that today I put a high-frequency scalper (hundreds of trades) on the YM demo-chart scalping pennys (0.02 lots) and let it run.  End of day I noticed that my standard code for calculating P&L:

TotalProfit = TotalProfit + OrderProfit() + OrderCommission() + OrderSwap();

- displayed the expected P&L for the day at $106.85, whereas in Account History for the day, it is listed  at $59.75 - that's one hell of a difference!  As this 'always-less-than-expected' decrepency was noticed throughout the day, I am wondering is this some 'hidden' brokers charge that I don't know about, or is it a bug with MetaTrader itself?  

 

I can't guess without details. And why your formula looks so strange?

TotalProfit = TotalProfit + OrderProfit() + OrderCommission() + OrderSwap();

What does it mean?
 
Rosh :

I can't guess without details. And why your formula looks so strange?

TotalProfit = TotalProfit + OrderProfit() + OrderCommission() + OrderSwap();

What does it mean?

What's strange about it?  Specifically, TotalProfit is a global variable that is updated each time an order is closed - each closed-order is selected with the OrderSelect(ticket,SELECT_BY_TICKET) function, then each of the 3 possible monetary changes are added to it,  (trade-profit, commission and swap) to find the exact P&L, and display a running tally of the current trading session.  The below pic lists a fraction of the trades in question.  As can be seen, individual order commissions and profits are listed correctly, however the Profit/Loss figure at the bottom (not shown) for all the combined closed-orders is much less than what the combined total calculated using 'OrderProfit() + OrderCommission()' is.  My question; why?  I have only noticed this with futures, where the problem may lie, or possibly it's just more noticable where there are several hundreds of very small trades involved...

Anyway, something is wrong, either with me, MetaTrader or the broker (Broco)...

 



 
Ask your broker, please. I have not enough information in your case.
 

I figured it out eventually. Basically, the broker ripping its customers off! The decrepency between the 'expected' profit and the actual, is down to 'slippage' it appears - that or a hidden spread! Specifically, the problem lies with OrderProfit() - for example, if you check an orders open-profit with OrderProfit() to determine if it should be closed, the profit returned is almost always far better than when the order is closed out. (see example trade below)

Not that I was using profits read before closing the orders, the problem is that after using the OrderClose function, you must then explicitly issue a fresh OrderSelect() call to the closed-out order, or OrderProfit() will not return the real order-profit!

Is this a bug, or just something else I was unaware of?

Order stats. before Order closure: OrderProfit() = 0.4 Ordercommission() = -0.1
08:18:30 SimpleTrader YMH9,M1: close #11918060 buy 0.01 YMH9 at 7466 sl: 7450 tp: 7495 at price 7473
08:18:30 SimpleTrader YMH9,M1: Order stats. after Order closure (Old OrderSelect): OrderProfit() = 0.4 Ordercommission() = -0.1
08:18:30 SimpleTrader YMH9,M1: Order stats. after Order closure (New OrderSelect): OrderProfit() = 0.35 Ordercommission() = -0.1



 
You must to select order by ticket not by position in your case.
 
Rosh :
You must to select order by ticket not by position in your case.

I am not selecting orders by position - all open-order ticket numbers are stored in an array, and at close-time each ticket is read, an OrderSelect(ticket,SELECT_BY_TICKET) issued, both before (to check order-profitability) and after, to determine what the 'real' profit after slippage was!

Therefore this problem occurs when selecting orders by ticket - the sequence, select order by ticket, read its OpenProfit() value (let's call this profit 'x1'), close the order, immediately re-read its OrderProfit() (call this profit 'x2'), finally issue a new OrderSelect(ticket,SELECT_BY_TICKET) for the same ticket number and read its profit value (calling this 'x3').

Result: x1 always equals x2 but x1 rarely equals x3 - x3 profit value is almost always less than x1.

Therefore MetaTrader must be storing two different OrderProfit() values in memory for the same order-ticket - an order-still-open value, and a closed-order value which will reflect any slippage that may have occurred at close-time, and you must specifically issue a second OrderSelect(ticket,SELECT_BY_TICKET) before issuing an OrderProfit() function call to ensure that the closed-profit is 'real', ie. as is seen in the Account History.

This definitely occurs with the YM futures contract, I haven't checked if it occurs with currencies - I wonder, would it have anything to do with the fact that Broco lists their CFD's as having zero-spread, but in reality... ?

 
Ask your broker, please.
Reason: