Features of the mql5 language, subtleties and tricks - page 10

 
Alexey Volchanskiy:
Can the hedged margin be calculated somehow?
I think you can calculate everything via Symbol functions.
 
fxsaber:
Thanks for the tip! In the wilderness it is SymbolInfoMarginRate. So now it's like this
// Размер свободных средств, необходимых для открытия 1 лота на покупку
double GetMarginRequired( const string Symb )
{
}

You have to clearly understand that in MT5 in different directions there can be very different margin requirements. That is, a single MT4 variant may not work. On Forex, of course, this will not be the case. But you have to remember. Therefore, in the general case it should be written like this
// Альтернатива OrderCalcMargin
bool MyOrderCalcMargin( const ENUM_ORDER_TYPE action, const string symbol, const double volume, const double price, double &margin )
{
}

Thank you very much! Now it works everywhere without any problems.

I wonder if"MyOrderCalcMargin" function is still trading, and if so, how to trade it at least in the tester)

 
fxsaber:
I think you can calculate everything via Symbol functions.
Unfortunately, Symbol functions are not working correctly.

Forum on trading, automated trading systems and trading strategies testing

Bugs, bugs, questions

fxsaber, 2017.02.28 10:48

Metaquotes-Demo, USD account, RTS-3.17.

TickValue gives wrong value - in rubles, not in account currency (USD).

FxPro-ECN. The symbols GOLD and GOLDEURO have the same TickValue. Although, obviously, they should be different in EURUSD times.

 
fxsaber:

MT5 prank on FIBOGroup-MT5 Server SGDJPY

In this situation, MyOrderCalcMargin calculates correctly, while the regular OrderCalcMargin does not!


Regular function counts in accordance with the contract specification specified in the settings of the instrument - with a margin currency NOK, respectively, for one lot is taken 1000 NOK.

You probably count as splitting the name of the currency pair SGDJPY - it takes 1000 SGD for one lot.

Accordingly, the problem is in the wrong specification of the contract on the broker's side. Contact the broker of the corresponding server.

 
fxsaber:

That is, to make all OrderSend synchronized with the trading environment and avoid pitfalls, it is sufficient to make the above source code as an mqh-file and do the corresponding #include in your programs.

You can stop dancing with tambourine.

The SD told me that since the next build OrderSend() will work properly :)

 
MQ Alexander:

The regular function counts in accordance with the contract specification specified in the settings of the instrument - with the margin currency NOK, respectively, for one lot is taken 1000 NOK.

In your case, it seems that the name of the currency pair SGDJPY is split - for one lot it takes 1000 SGD.

Accordingly, the problem is in incorrect specifying of the contract on the broker's side. Contact the broker of the corresponding server.

In MT5, there is an internal mechanism, which can convert any currency to the account currency. In this case, OrderCalcMargin 1000 NOK translates into the corresponding number of USD and outputs it.

Please make this mechanism open. For example,

double CurrencyExchange( const string Currency ); // возвращает курс валюты Currency к валюте счета

These exchange rates are 100% available in the terminal, since OrderCalcMargin calculates them. Their work is particularly noticeable on MetaQuotes-Demo USD accounts, when you take FORTS symbols - their margin currency is in RUR.

This is particularly relevant because of the TickValue bug.

Forum on trading, automated trading systems and trading strategies testing

Bugs, bugs, questions

fxsaber, 2017.02.28 10:48

Metaquotes-Demo, USD account, RTS-3.17.

TickValue gives wrong value - in rubles, not in account currency (USD).

FxPro-ECN. The symbols GOLD and GOLDEURO have the same TickValue. Although, obviously, they should be different in EURUSD times.

 
Hello! I'm reading the documentation:
OrdersTotal

Возвращает количество действующих ордеров.

int  OrdersTotal();

Возвращаемое значение

Значение типа int.

Примечание

Не следует путать между собой действующие отложенные ордера и позиции, которые также отображаются на вкладке "Торговля" в панели "Инструменты". Ордер – это распоряжение на проведение торговой операции, а позиция является результатом одной или нескольких сделок.

При "неттинговом" учете позиций (ACCOUNT_MARGIN_MODE_RETAIL_NETTING и ACCOUNT_MARGIN_MODE_EXCHANGE) по каждому символу в любой момент времени может быть открыта только одна позиция, которая является результатом одной или более сделок. Не следует путать между собой позиции и действующие отложенные ордера, которые также отображаются на вкладке "Торговля" в панели "Инструменты".

При независимом представлении позиций (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING) по каждому символу одновременно может быть открыто несколько позиций.

Смотри также

OrderSelect(), OrderGetTicket(), Свойства ордеров
And where can I find a deciphering of the term"active orders"?
"active pending orders", and NOT active pending orders, what are they?
 
Leo59:
Hello, I'm reading the documentation:
OrdersTotal

Возвращает количество действующих ордеров.

int  OrdersTotal();

Возвращаемое значение

Значение типа int.

Примечание

Не следует путать между собой действующие отложенные ордера и позиции, которые также отображаются на вкладке "Торговля" в панели "Инструменты". Ордер – это распоряжение на проведение торговой операции, а позиция является результатом одной или нескольких сделок.

При "неттинговом" учете позиций (ACCOUNT_MARGIN_MODE_RETAIL_NETTING и ACCOUNT_MARGIN_MODE_EXCHANGE) по каждому символу в любой момент времени может быть открыта только одна позиция, которая является результатом одной или более сделок. Не следует путать между собой позиции и действующие отложенные ордера, которые также отображаются на вкладке "Торговля" в панели "Инструменты".

При независимом представлении позиций (ACCOUNT_MARGIN_MODE_RETAIL_HEDGING) по каждому символу одновременно может быть открыто несколько позиций.

Смотри также

OrderSelect(), OrderGetTicket(), Свойства ордеров
And where do I find the deciphering of the term"active orders"?
"active pending orders", and NOT active pending orders, what are they?

Pending orders - bystop, sellstop, bylimit and bystop.

Positions - buy and sell.

Not active - deleted orders and closed positions.

 
Vitaly Muzichenko:

Pending orders - bystop, sellstop, bylimit and bystop.

Positions - buy and sell.

Not active - deleted orders and closed positions.

Thank you!
Since an order is an order to perform a trade operation, only pending orders can be considered as "active orders", while Buy and Sell Positions are not orders to perform a trade operation. Or am I missing something?
 
Active orders - trading orders which wait execution or cancellation, except for orders TP/SL and MarginCall. Active orders can be BUY and SELL.
Reason: