Coding Indicator to show Margin $

I am new to Forex but an experienced programmer. I am using MT4 and trying to develop a set custom indicators for my own trading. In one of my indicators everything is working fine except it always returns 0.00 for the margin amount for all currency pairs. I am using the SYMBOL_MARGIN_INITIAL enum to add the margin to a string that I later display on the chart. I have tried several of the margin enums with no sucess on any. There are five other values in the displayed string that are correctly returned by their enum references.

Below is the partial code line that appends the margin value to the string prior to display.

… + “Margin: $” + DoubleToStr(SymbolInfoDouble(Symbol(), SYMBOL_MARGIN_INITIAL) * LotSize,2) + …

Any Ideas? Thanks in advance.
Jim

Hi Jim, have you asked your broker about this?

While many (most?) forex brokers offer MT4, certain MQL functions may work differently from one setup to the next.

Yes. I did contact my broker (Forex.com). After several emails I got nowhere. Did some searching on the MLQ5 site and found some code that displayed margin $.

Here’s the code lines…

DoubleToStr(MarketInfo(Symbol(),MODE_MARGINREQUIRED * LotSize)) // Works
DoubleToStr(SymbolInfoDouble(Symbol(),SYMBOL_MARGIN_INITIAL) * LotSize // NG

I also tried some of the other margin enums from SymbolInfoDouble as well with no success.

Although the other five parameters my indicator grabbed by SymbolInfoDouble returned correctly, margin always returned 0.00. The MLQ4 documentation is clear and everything but margin seems to work fine. Guess there is some kind of glitch somewhere.

Thanks for your reply… Jim

1 Like