You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The task I want to complete is to get the credit of all orders opened by my EA. Not the total for the account, which you can get by calling AccountCredit(). I couldn't find any easy way, so I wrote in, my opinion, rather complex code for the matter. Here it is:
//Gets the credit of all opened orders with the given "magicNumber". double GetCredit(int magicNumber) { double credit = 0; int totalOrders = OrdersTotal(); for (int i = 0; i < totalOrders; i++) { OrderSelect(i, SELECT_BY_POS); if (OrderMagicNumber() == magicNumber && OrderOpenTime() != 0) { string baseCurrency = StringSubstr(OrderSymbol(), 0, 3); credit += OrderLots() * AccountLeverage() * GetValueOfCurrency(baseCurrency, AccountCurrency()); } } return (credit); } //Gets the current value of one unit of "currency" measured in "counterCurrency". double GetValueOfCurrency(string currency, string counterCurrency) { string currencyPair = StringConcatenate(currency, counterCurrency); double val = MarketInfo(currencyPair, MODE_BID); int lastError = GetLastError(); if (lastError == 0 || lastError == 1) return (val); else { currencyPair = StringConcatenate(counterCurrency, currency); val = MarketInfo(currencyPair, MODE_ASK); val = 1 / val; return (val); } }This won't work for example with idexes. Also if my account currency does not match in a currency pair with all base currencies, that are in opened orders, it will fail. I even thought about path finding in gaphs, where every node is a currencyPair, so I can find what exchanges are to be made to link two currencies. But that's waaaaay too complex.
So, do you know any easier way to get a order's credit?