How to recognize AccountCurrency chart by EA - help needed!

 

Hello everybody,

I need to calculate RequiredMargin in my EA in the situation when:

AccountCurrency() != "USD" && AccountCurrency() != "EUR" 
To calculate RequiredMargin I use the formula:
extern string AccountCurrencyChart="USDPLN"; 
double RequiredMargin=Lot*100000*Ask/AccountLeverage()*MarketInfo(AccountCurrencyChart, MODE_ASK);

I would like my EA to automatically return "USDPLN" or any other ChartSymbol based on AccountCurrency(),

so there would be no need to write the string in the externs.

Can anyone help?

 
string AccountCurrencyChart=""; 


int init()
{  
if (StringFind(Symbol(), "USDJPY", 0)==0)AccountCurrencyChart=Symbol(); //Symbol can be  xxUSDJPY   USDJPYxx   xxUSDJPYxx

//...more code
 
Dadas: I need to calculate RequiredMargin

Not only do you need to calculate margin required to open. You need to calculate the available margin at the most unfavorable excursion (i.e. SL) to avoid a margin call/stop out.

See my code.

 
WHRoeder:

Not only do you need to calculate margin required to open. You need to calculate the available margin at the most unfavorable excursion (i.e. SL) to avoid a margin call/stop out.

See my code.


Hey, Guys, I know what I am doing!

Just read with understanding and if you can, please give me a solution.

My EA calculates the Stopout Level for an open order on the fly, i.e. on ticks,

plus I can refresh data any time clicking the Refresh button I have created.

I need my EA to return the string for the right chart only based on AccountCurrency().

So, i.e.

if(AccountCurrency()=="PLN") { string AccountChart = "USDPLN"; }

Only without me having to list all possible charts!

I am asking, if anybody knows or has a Script already containing such a list or some

function like that, please share the information.

 
Dadas:

Hello everybody,

I need to calculate RequiredMargin in my EA in the situation when:

To calculate RequiredMargin I use the formula:

I would like my EA to automatically return "USDPLN" or any other ChartSymbol based on AccountCurrency(),

so there would be no need to write the string in the externs.

Can anyone help?

Why do you have different account currencies ?
 
RaptorUK:
Why do you have different account currencies ?


I live in Poland - our currency is PLN, so I have an account in PLN.

My broker provides the option.

Thus, my AccountCurrency()="PLN".

In order to calculate RequiredMargin for i.e. EURUSD in PLN I must:

Calculate RequiredMargin in USD:

double MarReq=Lot*100000*Ask/AccountLeverage(); // This returns RequiredMargin in USD
In order to get the value in PLN, I must know the exchange rate of USDPLN, which is:
double USDPLNExchangeRate=MarketInfo("USDPLN", MODE_ASK);

So, for the moment, I simply feed an

extern string AccountCurrencyChart = "USDPLN";

so my EA can calculate RequiredMargin on the fly.

I would like to make this a universal mechanism, not that I need it at the moment,

but for the sake of knowledge, and for, perhaps future, I want my EA to do this for any

possible exchange currency, i.e. Forex currencies.

After all, my broker provides his MT4 on which I see my Terminal values in PLN,

but for the broker it is easy, because he provides only a limited amount of

AccountCurrency() options.

 

And further thinking,

This situation opens new possibilities of i.e.

opening, say, two accounts: PLN and USD;

then, exchanging between accounts at favorable rates.

 

OK I see, can't you just do this ?

double Marginrequired;

Marginrequired = AccountFreeMargin( ) - AccountFreeMarginCheck( string symbol, int cmd, double volume);
 
RaptorUK:

OK I see, can't you just do this ?


OK, but this will not give me my RequiredMargin before I open any orders.

My idea is to calculate the RequiredMargin before OrderSend, so I can see

what my max LotSize is before I click BUY or SELL button.

When an Order is Open, I control the StopoutLevel.

But I will try your code, with cmd=OP_BUY

 
OK, this is GOOD, THANKS!
 
Dadas:
OK, this is GOOD, THANKS!
You are most welcome :-)