AccountFreeMarginCheck & AccountFreeMargin MT4 problem

Back to topics list To post a new topic, please log in or register
avatar
8
zversky 2015.04.09 16:06
 
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!



avatar
12985
WHRoeder 2015.04.10 14:35 #
 
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.
avatar
8
zversky 2015.04.10 14:54 #
 
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?

avatar
1211
deysmacro 2015.04.11 03:40 #
 
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
Back to topics list  

To add comments, please log in or register