Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1537

 
maxvoronin74 #:
What formula is used to calculate SYMBOL_PRICE_VOLATILITY?

Is this not satisfactory?

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Info_Print()
  {
   double change=0.0; // объявим и инициализируем переменную change (изменение цены в % с момента открытия торговой сессии)
   MqlTick mql_tick; // объявим и инициализируем переменную mql_tick для упрощенного доступа к структуре MqlTick
   SymbolInfoTick(_Symbol,mql_tick); // получим актуальные текущие цены
   double price_bid=mql_tick.bid; // получим текущую цену bid
   double price_open_day=iOpen(_Symbol,PERIOD_D1,0); // получим цену открытия торговой сессии
   if(price_open_day>0 && price_bid>0) // если все цены получены и они больше нуля
      change=((price_bid-price_open_day)*100)/price_open_day; // вычисляем изменение цены в %
   return(change); // возвращаем значение изменения цены в %
  }
//+------------------------------------------------------------------+

Regards, Vladimir.

 
MrBrooklin #:

Wouldn't that be okay?

Regards, Vladimir.

Thank you. Coefficient of price change per day. I understand. But for scalping I would like to have a flexible tool to determine volatility to compare it with spread for example.

SYMBOL_PRICE_VOLATILITY was added in 2020. Is the formula not known? The search engine doesn't show it...
 
Aleksandr Slavskii #:

Well, I wrote about incorrect bid ascii in position openings in the previous post.

I corrected the opening conditions, and the problem of closing positions was solved. :)) I did not understand why it was so. But your advice solved the problem. Thanks again.

 
maxvoronin74 #:

... But for scalping, one wants to have a flexible tool to determine volatility to compare it with the spread, for example.

SYMBOL_PRICE_VOLATILITY was added in 2020. Is the formula not known? The search engine doesn't show it...

What prevents you from inserting thespread instead of the session opening price? It can be easily obtained using SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) and multiplied by SymbolInfoDouble(_Symbol, SYMBOL_POINT).

Regards, Vladimir.

 
MrBrooklin #:

What prevents you from inserting thespread instead of the session opening price? It can be easily obtained using SymbolInfoInteger(_Symbol, SYMBOL_SPREAD) and multiplied by SymbolInfoDouble(_Symbol, SYMBOL_POINT).

Regards, Vladimir.

Thank you for your reply. Perhaps I just don't understand what should be obtained then. Spread coefficient? The spread is already there. Current value. Volatility is problematic. I tried to write the code to get the volatility, it turned out to be very stretched. So I didn't finish it. And if the function for volatility, which I am asking about, would work, it would be much easier.

So far it does not open positions.

Files:
 
maxvoronin74 #:

Thanks for the reply. Perhaps I just don't understand what should be the result then. Spread factor? The spread is already there. Current value. Volatility is problematic. I tried to write the code to get the volatility, it turned out to be very stretched. So I didn't finish it. But if the function for volatility, which I am asking about, would work, it would be much easier.

So far it does not open positions.

I assume that this EA will never open positions under these conditions. It seems that the PerVolatiliti variable is always equal to zero.

Regards, Vladimir.

 

Also. Frankly speaking, I don't understand the condition under which a position should be opened. How can spread and volatility be compared at all? )) I guess I don't know or understand something else.

Regards, Vladimir.

 
MrBrooklin #:

I assume that this EA will never open a position under these conditions. It seems that the PerVolatiliti variable is always equal to zero.

Regards, Vladimir.

Thank you. Do you think this is a bug or have I done something wrong?
 
MrBrooklin position should be opened. How can spread and volatility be compared at all? )) I guess I don't know or understand something else.

Regards, Vladimir.

Spread is often higher than volatility on small timeframes. In such cases, it makes no sense to open positions with this code without indicators and stop loss. I converted the spread into per cent (((ask-bid)/ask)*100) so that spread and volatility can be compared. And I thought that SYMBOL_PRICE_VOLATILITY takes timeframe into account. I will look into the logs tomorrow.
 
maxvoronin74 #:
Thank you. Do you think this is a bug, or did I do something wrong?

I don't know what it is, but try to get the SYMBOL_PRICE_VOLATILITY volatility value on your terminal. It is done very simply. Create a new Expert Advisor and print the value of volatility on each tick. Run this Expert Advisor, let's say, from the beginning of this year until today's date. For example, on my terminal the volatility is always equal to zero. And then see what is set in the conditions of the Expert Advisor Perevertysh20240508.mq5. How can it be fulfilled if volatility is always equal to zero?

Regards, Vladimir.

P.S. Here is a ready version of the Expert Advisor. Run it on your terminal and look in the Journal tab of the tester - it will display at least one value of volatility or not. I am 100% sure that you will not get any volatility value greater than zero.

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(SymbolInfoDouble(_Symbol,SYMBOL_PRICE_VOLATILITY) > 0)
      Print("Волатильность = ", SymbolInfoDouble(_Symbol,SYMBOL_PRICE_VOLATILITY));
  }
//+------------------------------------------------------------------+