Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 128
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
Are there any indicators/advisors on the charts?
No Expert Advisors, only standard indicators from the terminal
I.e. you open the chart, draw a horizontal line, close the terminal, open the terminal, the chart (opened for drawing the line) is in place, but the line itself is gone?
It is.
It's mystical, it shouldn't be...
Hello, could you please tell me how I can programmatically check if a certain custom indicator exists or does not exist in the MQL4\Indicators folder by its name?
I need it to check if the iCustom function has found and works with an indicator.
Check if the indicator with this name exists (I don't know how)
if( !=Indicatorname)//Well, or another "signal" that there is no indicator with this name, like -1, false ...
{here I write something :)}
else //receive value from the indicator
{
iCustom(....Indicatorname....)
}
I suspect that the topic lies in the plane of "File operations without constraints" ( I could be wrong), but I've never encountered the system libraries that are usually used in "this topic"...
Anyway, need some advice..., maybe there is something ready-made already, or at least - where to "dig"
Thanks
Hello, could you please tell me how I can programmatically check if a certain custom indicator exists or does not exist in the MQL4\Indicators folder by its name?
I need it to check if the iCustom function has found and works with an indicator.
Check if the indicator with this name exists (I don't know how)
if( !=Indicatorname)//Well, or another "signal" that there is no indicator with this name, like -1, false ...
{here I write something :)}
else //receive value from the indicator
{
iCustom(....Indicatorname....)
}
I suspect that the topic lies in the plane of "File operations without constraints" ( I could be wrong), but I've never encountered the system libraries that are usually used in "this topic"...
Anyway, need some advice..., maybe there is something ready-made already, or at least - where to "dig"
Thanks
you'd better connect the indicator as a resource, then you won't need to search for it, it will always be there
file operations might help you, here is an example from the file search documentation
#property script_show_inputs
//--- дата для старых файлов
input datetime InpFilesDate=D'2013.01.01 00:00';
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
string file_name; // переменная для хранения имен файлов
string filter="*.txt"; // фильтр для поиска файлов
datetime create_date; // дата создания файла
string files[]; // список имен файлов
int def_size=25; // размер массива по умолчанию
int size=0; // количество файлов
//--- выдели память для массива
ArrayResize(files,def_size);
//--- получение хэндла поиска в корне локальной папки
long search_handle=FileFindFirst(filter,file_name);
//--- проверим, успешно ли отработала функция FileFindFirst()
if(search_handle!=INVALID_HANDLE)
{
//--- в цикле перебираем файлы
do
{
files[size]=file_name;
//--- увеличим размер массива
size++;
if(size==def_size)
{
def_size+=25;
ArrayResize(files,def_size);
}
//--- сбрасываем значение ошибки
ResetLastError();
//--- получим дату создания файла
create_date=(datetime)FileGetInteger(file_name,FILE_CREATE_DATE,false);
//--- проверим, старый ли файл
if(create_date<InpFilesDate)
{
PrintFormat("Файл %s удален!",file_name);
//--- удаляем старый файл
FileDelete(file_name);
}
}
while(FileFindNext(search_handle,file_name));
//--- закрываем хэндл поиска
FileFindClose(search_handle);
}
else
{
Print("Files not found!");
return;
}
//--- проверим какие из файлов остались
PrintFormat("Результаты:");
for(int i=0;i<size;i++)
{
if(FileIsExist(files[i]))
PrintFormat("Файл %s существует!",files[i]);
else
PrintFormat("Файл %s удален!",files[i]);
}
}
....
then file operations might help you, here is an example from the file search documentation
#property script_show_inputs
//--- дата для старых файлов
input datetime InpFilesDate=D'2013.01.01 00:00';
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
string file_name; // переменная для хранения имен файлов
string filter="*.txt"; // фильтр для поиска файлов
datetime create_date; // дата создания файла
string files[]; // список имен файлов
int def_size=25; // размер массива по умолчанию
int size=0; // количество файлов
//--- выдели память для массива
ArrayResize(files,def_size);
//--- получение хэндла поиска в корне локальной папки
long search_handle=FileFindFirst(filter,file_name);
//--- проверим, успешно ли отработала функция FileFindFirst()
if(search_handle!=INVALID_HANDLE)
{
//--- в цикле перебираем файлы
do
{
files[size]=file_name;
//--- увеличим размер массива
size++;
if(size==def_size)
{
def_size+=25;
ArrayResize(files,def_size);
}
//--- сбрасываем значение ошибки
ResetLastError();
//--- получим дату создания файла
create_date=(datetime)FileGetInteger(file_name,FILE_CREATE_DATE,false);
//--- проверим, старый ли файл
if(create_date<InpFilesDate)
{
PrintFormat("Файл %s удален!",file_name);
//--- удаляем старый файл
FileDelete(file_name);
}
}
while(FileFindNext(search_handle,file_name));
//--- закрываем хэндл поиска
FileFindClose(search_handle);
}
else
{
Print("Files not found!");
return;
}
//--- проверим какие из файлов остались
PrintFormat("Результаты:");
for(int i=0;i<size;i++)
{
if(FileIsExist(files[i]))
PrintFormat("Файл %s существует!",files[i]);
else
PrintFormat("Файл %s удален!",files[i]);
}
}
....
then file operations might help you, here is an example from the file search documentation
}
....
If it doesn't work, you can't get into the indicators folder, try to open it via win api if it doesn't work
#property script_show_inputs
//--- фильтр
input string InpFilter="Dir1\\*";
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
string file_name;
string int_dir="";
int i=1,pos=0,last_pos=-1;
//--- ищем последний бэк-слеш
while(!IsStopped())
{
pos=StringFind(InpFilter,"\\",pos+1);
if(pos>=0)
last_pos=pos;
else
break;
}
//--- в фильтре присутствует имя папки
if(last_pos>=0)
int_dir=StringSubstr(InpFilter,0,last_pos+1);
//--- получение хэндла поиска в корне локальной папки
long search_handle=FileFindFirst(InpFilter,file_name);
//--- проверим, успешно ли отработала функция FileFindFirst()
if(search_handle!=INVALID_HANDLE)
{
//--- в цикле проверим являются ли переданные строки именами файлов или директорий
do
{
ResetLastError();
//--- если это файл, то функция вернет true, а если директория, то функция генерирует ошибку ERR_FILE_IS_DIRECTORY
FileIsExist(int_dir+file_name);
PrintFormat("%d : %s name = %s",i,GetLastError()==ERR_FILE_IS_DIRECTORY ? "Directory" : "File",file_name);
i++;
}
while(FileFindNext(search_handle,file_name));
//--- закрываем хэндл поиска
FileFindClose(search_handle);
}
else
Print("Files not found!");
}
...