Download MetaTrader 5

AccountFreeMarginCheck & AccountFreeMargin MT4 problem

To add comments, please log in or register
zversky
38
zversky  
void OnTick()
  {
      double vol=0.01;
      Print("AccountFreeMargin before:",DoubleToStr(AccountFreeMargin()));
      Print("AccountFreeMarginCheck:",DoubleToStr(AccountFreeMarginCheck(Symbol(),OP_BUY,vol)));
      OrderSend(Symbol(),OP_BUY,vol,Ask,0,0,0,"test",0,0,Blue);
      Print("AccountFreeMargin immediately after:",DoubleToStr(AccountFreeMargin()));

   return;
  }


output:

0       17:01:20        2014.01.02 02:00  test2 AUDUSD,M1: AccountFreeMargin before:100.00000000
0       17:01:20        2014.01.02 02:00  test2 AUDUSD,M1: AccountFreeMarginCheck:98.00000000
2       17:01:20        2014.01.02 02:00  test2 AUDUSD,M1: open #1 buy 0.01 AUDUSD at 0.88851 ok
0       17:01:20        2014.01.02 02:00  test2 AUDUSD,M1: AccountFreeMargin immediately after:97.77000000


https://docs.mql4.com:

AccountFreeMarginCheck() - Returns free margin that remains after the specified order has been opened at the current price on the current account.

AccountFreeMargin() - Returns free margin value of the current account.

As I understand AccountFreeMarginCheck() call before opening an order should return the same value as AccountFreeMargin() straight after the order was opened


Why AccountFreeMarginCheck() does not match AccountFreeMargin()? What am I doing wrong?

Thanks!

whroeder1
15040
whroeder1  
You are forgetting about the spread. The moment you open a buy, you are now down by the spread. Open a sell and they would match because you pay the spread when it closes.
zversky
38
zversky  
0       15:47:56        2014.01.02 02:00  test2 AUDUSD,M1: AccountFreeMargin before:100.00000000
0       15:47:56        2014.01.02 02:00  test2 AUDUSD,M1: AccountFreeMarginCheck:98.00000000
2       15:47:56        2014.01.02 02:00  test2 AUDUSD,M1: open #1 buy 0.01 AUDUSD at 0.88851 ok
0       15:47:56        2014.01.02 02:00  test2 AUDUSD,M1: AccountFreeMargin immediately after:97.77000000
0       15:47:56        2014.01.02 02:00  test2 AUDUSD,M1: Spread:23.00000000


Hm, now it makes sence.

Thank you for clarification, you helped alot!


Does it mean that AccountFreeMargin() would be different across time whith floating spread broker?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  
zversky:


Hm, now it makes sence.

Thank you for clarification, you helped alot!


Does it mean that AccountFreeMargin() would be different across time whith floating spread broker?

Yes
To add comments, please log in or register