Understanding some FX mechanics and MT4 Functions

 

I've been dabbling in FX for a few years.... sometimes a lot more active than others. I've gotten back into it again and am currently coding a mini MQL4 emulator in VC++ to help me with logic bugs that always creep into my EA's that take forever for me to find in MT4. Instead of doing something quick and fast I'm going in depth. The idea being I just copy/paste my EA code into VC++, point to some tick data and press play to see where the bugs show up in the debugger.


I have a few questions. More functions may popup but I'm currently working on the "account" functions. What does AccountCredit() do? The description in the reference manual is rather vague.... "Returns credit value of the current account." Which returns 0 with trades active/inactive... in the init() or start() functions. At what point is something other than 0 returned?


My other question mainly focuses on margin. If I remember right the counter-currency is the "righthand" currency in the pair... a.k.a. the denominator in the fraction... etc. If I'm wrong that's what I'll be refereing to.... i.e. in EURGBP.... the GBP :). I've used many different demo accounts over the years across several brokers. I've noticed that some calculate margin differently. Specifically, let's say for a standard account, 1 lot in any currency controls $100,000 of the counter currency.... where $ does not mean dollars but pound, yen, crona, etc.... whatever the rightside is in the pair.


A recent trade I did in my MT4 demo acct with FXCM with the GBPJPY. The USDJPY was 98.138... the inverse was 0.01019. So controlling 10,000,000 JPY = 101897.33 USD .... dividing that by the leverage (200:1) I get the margin being about 509.49 USD. Some brokers I've noticed this to be true. Other brokers I've noticed that they seem to always use the currency the account in denominated in... so no matter what the trade the margin always is # of lots in the market * 100,000/leverage... which for a single lot in a USD demoniated standard acct is $500.


The way to truly calculate the margin is the first method is it not?


Thanks for your help

Reason: