How is the profit calculated when trading gold?

 

Hi everyone,


I am pretty fresh in trading as well as in MT5 and am trying to figure out some details when trading gold.  I developed a rather simple two moving average expert advisor which trades gold as follows:

When criterion for buying is met, I buy gold with this command:

    if( goodToBuy || lowRsi ) {
      bool succ = trade.Buy(Lots,         // lots to buy
                            _Symbol,
                            0.0,          // price
                            0.0,          // stop loss
                            0.0,          // take profit
                            "Buying");
      if(succ) {
        // Store the ticket
        order.ticket = trade.ResultOrder();  

        // Report the trade
        FileWrite(fileHandle, " - balance: ", AccountInfoDouble(ACCOUNT_BALANCE));
        FileWrite(fileHandle, " - equity:  ", AccountInfoDouble(ACCOUNT_EQUITY));
        FileWrite(fileHandle, " - margin:  ", AccountInfoDouble(ACCOUNT_MARGIN));
        FileWrite(fileHandle, " - profit:  ", AccountInfoDouble(ACCOUNT_PROFIT));
      }
    }     

As you can see, I do not explicitly specify SL and TP, but hold them in variables local to OnTick function and constantly checking against the price of gold for risk management.  If criterion for selling is met, I simply close the position:

    if( goodToSell || highRsi || stopLoss || takeProfit ) {
      bool succ = trade.PositionClose(order.ticket);

      if(succ) {
        FileWrite(fileHandle, " - balance: ", AccountInfoDouble(ACCOUNT_BALANCE));
        FileWrite(fileHandle, " - equity:  ", AccountInfoDouble(ACCOUNT_EQUITY));
        FileWrite(fileHandle, " - margin:  ", AccountInfoDouble(ACCOUNT_MARGIN));
        FileWrite(fileHandle, " - profit:  ", AccountInfoDouble(ACCOUNT_PROFIT));        
      }
    }    

(I do understand that there might be more sophisticated ways to perform trade, but at the level of experience at which I am with MT5 and trading in general, I feel better with such a simple approach).

OK, after this introduction, comes my real question through an example.  The first purchase which my EA does is  on 2022.01.04 at 04:00 when the price of gold was: 1596.91.  I purchased 0.01 lots, and I set leverage to 1:1 (to make things simple and try to understand things.  What is written in the file which I create for reporting trades is:

 - balance:  10000.0
 - equity:   9999.54
 - margin:   1596.91
 - profit:   -0.46

Balance is clear, that is the money (EUR) I started with.  Margin is also clear, 0.01 lots should correspond to 1 oz of gold, and price per oz was exactly  1596.91, so that is also the margin I needed to open the position for its price and size.

But could somebody please explain to me why is profit -0.46, and how is it calculated?  (Since I don't understand why is profit as it is, I also don't understand the equity.)

Just to make the question complete.  My EA sold the gold on the same day at 20:00, at price 1605.57, and the reported values were:

 - balance:  10008.66
 - equity:   10008.66
 - margin:   0.0
 - profit:   0.0

Here again everything makes sense.  I sold for 8.66 EUR more than for what I bought and that's exactly the profit I made.  But still, why was profit -0.46 after purchase (above) is beyond me :-(

I would highly appreciate any insight on that.


    Kind regards