A question about spread costs in MQL5

 
Dear all,


I am new to trading and am developing my first strategies in MQL5.  Up to now, I am only testing different strategies in Strategy Tester.  Whenever I open a position, I am essentially buying, I only "go long", because "going short" is still a bit nebulous in my mind.

Imagine I start with 10'000.  I open a position (buy it) and using these functions:
FileWrite(LogFile, " - balance:                 ", AccountInfoDouble(ACCOUNT_BALANCE));
FileWrite(LogFile, " - equity:                  ", AccountInfoDouble(ACCOUNT_EQUITY));
FileWrite(LogFile, " - profit:                  ", AccountInfoDouble(ACCOUNT_PROFIT));
double spreadCost = SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) * _Point * Lots * CONTRACT_SIZE;
FileWrite(LogFile, " - spread cost:             ", NormalizeDouble(spreadCost, _Digits));

After that purchase I see the following in the log file:

 - balance:                 10000.0
 - equity:                  9988.9
 - profit:                  -11.1
 - spread cost:             11.1
Equity is balance plus profit, 10000 - 11.1 = 9988.9, all is fine and logical.  The profit (-11.1) is due to spread cost, which I double check with last two lines of the code snippet above and third and fourth line in the log file.  So far all is still clear.

However, when I close the position (sell it in my case), which I sold for mere 2.7 more than I bough it, I get the following output in my log file:
 - balance:                   9996.02
 - equity:                    9996.02
 - profit:                    0.0
 - spread cost:             11.4 
Although I earned 2.7, I also had to pay for keeping the position over one night.  I checked it with a call to:

HistoryDealGetDouble(closeTicket, DEAL_SWAP);
and it amounts to 6.68.  So, I started with 10000, earned 2.7, but spent 6.68 for deal swap, so balance is 10000 - 6.68 + 2.7 = 9996.02, but I don't see the spread costs ever accounted for?  Where did all the spread costs go?  

I am trying to be cautions / conservative in the assessment of my strategies, but I can't see how did spread costs dissapper from the MQL5 AccountInfoDouble functions?

Could anyone please shed light on that?


    Best regards,


    Butch

 
Your topic has been moved to the section: Expert Advisors and Automated Trading — Please consider which section is most appropriate — https://www.mql5.com/en/forum/443428#comment_49114884