Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 113
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
There are several ways to get current prices:
1. For any symbol: if you want to get guaranteed current prices, call SymbolInfoDouble() with the correct identifiers before using them.
2. For the current symbol, you can also get the current prices through the predefined variables Bid and Ask. They can get out of date, so if OnTick() is running, you should refresh them with RefreshRates().
"possible loss of data due to type conversion"
How do I overcome this warning?
Compiler warning:
"possible loss of data due to type conversion"
How can I overcome this warning?
You need to know the exact types of values returned by the functions and use explicit conversion. https://www.mql5.com/ru/docs/basis/types/casting
You don't have a complete template - you probably haven't set the indicator buffers in the wizard, where the calculated data will be written to.
But the basic principle for most indicators is the following:
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
if(rates_total<1) return(0); // проверка достаточности данных для расчёта индикатора, если не достаточно - выходим
// если для расчёта требуются некое количество баров слева от индекса цикла, ...
// ... то проверять нужно это количество, а не 1
//--- Действия для полного перерасчёта индикатора
int limit=rates_total-prev_calculated; // количество посчитанных уже баров
if(limit>1) { // если количество больше 1, значит имеем новые данные, и нужно полностью пересчитать индикатор
limit=rates_total-1; // задаём количество требуемых для расчёта баров равным количеству баров в истории,
// если для расчёта требуются некое количество баров слева от индекса цикла, ...
// ... то это количество тоже нужно вычесть из rates_total чтобы не выйти за пределы массива
// так же тут нужно при необходимости произвести инициализацию буферов индикатора
}
//--- Основной цикл индикатора
for(int i=limit; i>=0; i--) {
// тут выполняем нужные расчёты и записываем их результат в нужные буферы, например:
ExtMapBuffer[i]=(open[i]+high[i]+low[i]+close[i])/4.0; // Выведем на график среднюю цену каждой свечи (OHLC/4.0)
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Artem, the compiler gave an error: 'ExtMapBuffer' - undeclared identifier
That's why I put in this buffer. You should re-create the template, but you should be more responsible for this simple action and ask yourself - "But what does the wizard ask me and what does it need?
Hello! About four months ago I started studying MQL4 using Kovalev's tutorial. I also have videos. I watch the video and study the tutorial, I repeat codes that are used there. i understand that this is a very serious matter and it takes time to master it. but i know exactly i need practice. i need simple tasks and to write them and someone checks them out then i will be able to go further! another problem is that the book and the videos have been updated, i even repeat the code from the book, compile it, i get errors, i look like a sheep at the new gate...... that's the sadness!
Read the documentation for once. The textbook is out of date in some places. The documentation will help with this. About the tasks - solve the same tasks as described in the textbook. Read the problem, look at the solution, repeat it. And so on until you get the hang of it. It is better to take the tasks as close as possible to those you want to learn to implement yourself.
All, of course, IMHO.
It compiles fine for me.
Ok, do you want to explain why such objects are not differentiated?
If you change the object type, the properties will collapse with 2 labels or trendlines
Read the documentation for once. The textbook is out of date in some places. The documentation will help with this. As for the tasks - solve the same tasks as described in the textbook. Read the problem, look at the solution, repeat it. And so on until you get the hang of it. It is better to take the tasks as close as possible to those you want to learn to implement yourself.
All, of course, IMHO.
Thank you!
Ok, do you want to explain why such objects are not differentiated?
If you change the object type, the properties will collapse with 2 labels or trendlines