OnTester code not working
double OnTester() { double X = 0; double Y = 1000; for(PositionIndex = OrdersHistoryTotal() - 1; PositionIndex >=0; PositionIndex --) { OrderSelect(PositionIndex,SELECT_BY_POS,MODE_HISTORY); if(OrderType() == OP_BUY || OrderType() == OP_SELL) { X += 1; Y += (OrderProfit()+OrderCommision()+OrderSwap()); } } return (Y); }
You are missing commision and swap.


Hello,
I have written code to output a custom value using the Strategy Tester in MQL4. The following is only part of the code which failed (calculating R2), it seems to go already wrong with calculating Y (total profit). It correctly calculates the number of trades (so correctly excludes all cancelled trades) but adding up the profits of all closed trades does not give the same value as what the Strategy Tester outputs as Profit. Any suggestions where I went wrong?