Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 996

 
Alexey Viktorov:


What you are trying to print is not correct. The correct way is this.

Here's the breakdown:

42 is a numerical identifier: ACCOUNT_MARGIN_FREE

i.e. we can get the free margin from the constant

AccountInfoDouble(ACCOUNT_MARGIN_FREE)

Or by its numeric identifier:

AccountInfoDouble(42)

Thank you!

 
killer67:

Here's the breakdown:

42 is a numerical identifier: ACCOUNT_MARGIN_FREE

i.e. we can get the free margin from the constant

Or by its numeric identifier:

Thank you!

The first version of writing is more informative.

 

https://www.mql5.com/ru/docs/constants/environment_state/marketinfoconstants

This is probably a silly question, but can these functions be used in MQL4? It's just that MQL4 tools are more limited.

How to get the data in MQL4:

SYMBOL_SESSION_DEALS

Number of trades in the current session

SYMBOL_SESSION_BUY_ORDERS

Total number of buy orders at the moment

long

SYMBOL_SESSION_SELL_ORDERS

Total number of sell orders at the moment

long

SYMBOL_VOLUME

Volume - Volume of the last trade

long

SYMBOL_VOLUMEHIGH

Maximum Volume for the day

long

SYMBOL_VOLUMELOW

Minimum Volume for the day

SYMBOL_BID

Bid - best bid

double

SYMBOL_BIDHIGH

Maximum Bid for the day

double

SYMBOL_BIDLOW

Minimum Bid for the day

double

SYMBOL_ASK

Ask - best bid

double

SYMBOL_ASKHIGH

Maximum Ask for the day

double

SYMBOL_ASKLOW

Minimum Ask for the day

SYMBOL_SESSION_VOLUME

Total volume of trades in the current session

double

SYMBOL_SESSION_TURNOVER

Total turnover in the current session

double

SYMBOL_SESSION_INTEREST

Total volume of open positions

double

SYMBOL_SESSION_BUY_ORDERS_VOLUME

Total volume of buy orders at the moment

double

SYMBOL_SESSION_SELL_ORDERS_VOLUME

Total volume of sell orders at the moment

double

SYMBOL_SESSION_OPEN

Session open price

double

SYMBOL_SESSION_CLOSE

Close price

double


It's a treasure trove of useful data in one go. The only question is how to do it in MQL4. Since MQL5 has a wider functionality, someone may ask, why I'm not studying MQL5. It's simple. Not all brokers support it. At the moment MQL4 is still the most popular and in demand.

Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Для получения текущей рыночной информации служат функции SymbolInfoInteger(), SymbolInfoDouble() и SymbolInfoString(). В качестве второго параметра этих функций допустимо передавать один из идентификаторов из перечислений ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE и ENUM_SYMBOL_INFO_STRING соответственно. Некоторые символы (как...
 
Gilmor:

https://www.mql5.com/ru/docs/constants/environment_state/marketinfoconstants

This is probably a silly question, but can these functions be used in MQL4? It's just that MQL4 tools are more limited.

How to get data in MQL4:


It's a treasure trove of useful data in one click. But how to do it in MQL4. This article will also contain some tips on how to prepare MQL5 for studying in MQL5. It's simple. Not all brokers support it. At the moment MQL4 is still the most popular and in demand.

In the documentation of mql4 all that do not work are marked.

SYMBOL_BID

Bid - best bid

double

SYMBOL_BIDHIGH

Not supported

double

SYMBOL_BIDLOW

Not supported

double

SYMBOL_ASK

Ask - best offer to buy

double

SYMBOL_ASKHIGH

Not supported

double

SYMBOL_ASKLOW

Not supported

double

SYMBOL_LAST

Not supported

double

SYMBOL_LASTHIGH

Not supported

double

SYMBOL_LASTLOW

Not supported

double

SYMBOL_POINT

Single point value

double

This is not the whole table. There is more than one in the documentation, you just have to press F1 and read it.

 
Alexey Viktorov:

In the mql4 documentation all those that don't work are marked.

Thank you.
 
Help to understand, can't set stop loss correctly.
Log lines:
2019.11.16 12:38:40.660 2019.01.02:35:00 To calculate stops, take value from broker = 30
2019.11.16 13:20:18.791 2019.01.02:03:00 Open an order: Price = 1.14595, Stop Loss = 1.14565, Take Profit = 1.14625
2019.11.16 13:20:18.791 2019.01.02 02:03:00 failed instant buy 0.01 EURUSD at 1.14595 sl: 1.14565 tp: 1.14625 [invalid stops]
2019.11.16 13:20:18.792 2019.01.02:03:00 CTrade::OrderSend: instant buy 0.01 EURUSD at 1.14595 sl: 1.14565 tp: 1.14625 [invalid stops]


And now a little clarity for this case:
In the code before opening an order I calculate:
price = best market price to buy, depending on the order, in this case a buy.
SL = calculate a right stop (the broker allows a stop of at least 30 units from the price) i.e.
price (1.14595) - 0.0003 = SL (1.14565)
TP = calculate a right stop (the broker allows a stop of at least 30 units from the price) i.e.
price (1.14595) + 0.0003 = TP (1.14625)
Well everything looks correct, I hold 30 points, but I get a setting error.

If we set SL = 0, then everything is OK, order and TP are set.
I get an error in calculation of SL, where is the error?
 
killer67:
Help me understand, I can't get the stop loss set correctly.
Log lines:
2019.11.16 12:38:40.660 2019.01.02 02:35:00 To calculate stops, take value from broker = 30
2019.11.16 13:20:18.791 2019.01.02 02:03:00 Open an order: Price = 1.14595, Stop Loss = 1.14565, Take Profit = 1.14625
2019.11.16 13:20:18.791 2019.01.02 02:03:00 failed instant buy 0.01 EURUSD at 1.14595 sl: 1.14565 tp: 1.14625 [Invalid stops]
2019.11.16 13:20:18.792 2019.01.02 02:03:00 CTrade::OrderSend: instant buy 0.01 EURUSD at 1.14595 sl: 1.14565 tp: 1.14625 [invalid stops]


And now some clarity for this case:
In the code I calculate before opening an order:
price = best market price to buy, depending on the order, in this case a buy.
SL = calculate a right stop (the broker allows stops at least 30 units away from the price), i.e.
price (1.14595) - 0.0003 = SL (1.14565)
TP = Calculate correct stop (broker allows stops at least 30 units away from price) i.e.
price (1.14595) + 0.0003 = TP (1.14625)
Well, everything seems to be right, I hold 30 pips, but I get a setting error.

We set SL = 0, then everything is OK, order and TP are set.
It turns out to be an error in calculation of SL, where is the error?

what type of price ?

 
Iurii Tokman:

what type of price ?

When buying Price = SYMBOL_ASK

On sale Price = SYMBOL_BID

 
killer67:

When buying Price = SYMBOL_ASK

When selling Price = SYMBOL_BID

Have you tried adding a spread?

 
Iurii Tokman:

Have you tried adding a spread?

Fixed it this way:

double CheckSetSL(ENUM_ORDER_TYPE OrderT, double price)
  {
   if(InpSL != 0)
     {
      double CalcSL = 0.0;
      double SL = 0.0;
      if(InpSL < 0.0003)
        {
         CalcSL = 0.0003; // Если SL в настройках указано меньше 30 (установки брокером) то ставим минимально допустимую.
        }
      else
        {
         CalcSL = InpSL;
        }

      // Формируем стоп-лимит.
      if(OrderT == ORDER_TYPE_BUY)
        {

         SL = SymbolInfoDouble(_Symbol,SYMBOL_BID) - CalcSL;

        }
      else
        {

         SL = SymbolInfoDouble(_Symbol,SYMBOL_ASK) + CalcSL;

        }

      return SL;
     }

   return 0.0;
  }
Reason: