AccountBalance() Not Changed after Trade

 

      Hi, can anyone help on this one?

      Spent most of a day trying to get the value of  account balance before a trade and again afterwards. I want to see the amount of cash that the trade costs.

      Still  trying to work out why the account balance has not altered. Code as below.

      BalanceBefore=AccountBalance();

      RefreshRates();OrderID=OrderSend(Symbol(),OP_BUY,Lots,Ask,slip,Sl,Tp,"Long",Magic,0,Blue);

      BalanceAfter=AccountBalance();

     These are the results from the journal...

      AccountBalance() after opening trade 5000          

      EURUSD at 1.44164 ok                                      // <<< Journal confirms  Long trade opened

      AccountBalance() before opening trade 5000

     This is from back-testing with an account start balance of 5,000  - Trade is made, account balance stays same. So would be most grateful for advise on this

    Chris 

 
Opening an order doesn't change AccountBalance, only AccountEquity. When you close the order, they become equal.
 

    

      Thank you very much for your time in answering.

     As far as I can determine the AccountEquity is the cash balance plus the value of the opened position, i.e, as described, the equity. So on testing I am not getting the results I want.

    ( For example I tested with accountequity()  the purchase of 1 lot. The results showed a cash deduction from my 5k account of $2. If only that was possible in real life)

     What I am trying to determine is the cash in the account before and after a position is opened.

     For example with a starting account of 5k I open a position I then want to know the new account cash balance . Deduct one from the other I also determine the cost of opening that position.

     Looking at MQL4 documentation https://docs.mql4.com/account/accountbalance  it is clear that this function shows the cash in the account. But when running this with the short piece of code as in my original question the cash balance does not change after a position is opened. 

     How can this be done?

      Chris

 
I would think that if you know the account balance before any trades are made, just subtract the value of the trades, and that will, I think, give you the number you are trying to find.
 

     

      Hi, thanks, that is an alternative I have considerd. But with other variables such as swaps and roundings  and so on the true value of the account balance would soon be adrift from reality.

      There must be a point were AccountBalance() shows just that - as described in  https://docs.mql4.com/account/accountbalance - the balance of cash left in the account after a position is opened.

      Chris 

 
ChrisSouthwood:

     

      Hi, thanks, that is an alternative I have considerd. But with other variables such as swaps and roundings  and so on the true value of the account balance would soon be adrift from reality.

      There must be a point were AccountBalance() shows just that - as described in  https://docs.mql4.com/account/accountbalance - the balance of cash left in the account after a position is opened.

      Chris 

It sounds as though what you are interested in is AccountFreeMargin(). In essence, that's the cash balance on the account, minus any floating P/L on open positions, minus any commission and swap (*), minus the margin required to finance the open positions.

(* depending on the broker, swap and commission may either be reported against each individual position, affecting AccountProfit() and the difference between AccountEquity() and AccountBalance(), or may be booked as a series of daily credit adjustments on the account, altering AccountBalance() on a daily basis.)

 

             Thanks guys. I more or less have worked a way around this - still though, have confusion as to why the cash in the account does not decrease when I open a new trade  (If only real life was like that)

             Chris

 
ChrisSouthwood:

[...] still though, have confusion as to why the cash in the account does not decrease when I open a new trade  (If only real life was like that)

The "cash in the account" does decrease when you open a new trade. The "cash in the account" basically means the equity, and that immediately decreases by the cost of the spread, i.e. by the amount your open position is immediately in loss when you open it.

Free margin will decrease by the cost of the spread plus the margin required to maintain the open position, but that margin is still your money. If you wanted to close your account right now and withdraw your funds, what you would get back is the equity (not the free margin).

There are some platforms which, unlike MT4, only report an equity figure, not a balance figure. The balance in MT4 is basically a total of all closed transactions. It's like the difference reported by many (all?) banks between "balance" and "available funds", i.e. the latter including credits or debits which are going to hit the balance in future but haven't cleared yet.

 
jjc:

[...] what you would get back is the equity [...]

(Strictly speaking, on some brokers, the equity may not take into account some or all of the commission payable on open positions, or any swap incurred today.)
 
ChrisSouthwood: Deduct one from the other I also determine the cost of opening that position.
Only for a Buy. You pay the spread when you close a Sell.
 

We are probably wearing out this thread now but still find it odd that I cant access information to determine the amount of cash that is in the trading account until all positions are closed.

Bit like my bank telling me that having spent all my cash on a purchase I still have that original balance in my account. I understand equity, that is not what I want.

AccountBalance()  as described in MQL4 docs states "Balance value of the current account (the amount of money on the account)". It does not.

When trading live you have ' Account History' that shows the cash in the account and profit/loss. By clicking 'Trade' we can see the quantity and value of open trades. That information is what I am looking for to use in my code.

Chris

Reason: