[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 245

 
Vinin:

Have you tried error handling?
No. What good would that do? You would have to make another query anyway
 
AndEv:
No. What good would that do? You'll have to do another query anyway.

You'll know why there's no data, and maybe it's pointless to repeat the query.
 
AndEv:
No. What good would that do? You will have to do another query anyway
What data from other currencies and timeframes do you need: standard or custom indicator, price, something else? Show me the part of the code where you don't succeed.
 

Just to be safe, I'll ask. Question about MQL4 specification. If according to MSDN documentation the called function has a pointer in its parameters, in MQL4 I can use passing of the parameter by reference, right?

At least in C++

int a;//переменная
int *ra = &a;//адрес(* ra) равен ссылке(& a) на а (переменную)
 
paladin80:
What data from other currencies and timeframes do you need: standard or custom indicator, price, something else? Show me the part of the code where you don't succeed.
Actually, besides OHLC you don't need anything else. It is not about the code. At open charts, timeseries are created in the virtual memory and all incoming quotes are stored in the working memory withoutwriting them into historyfiles. History files are written only when we close MT4. When requesting data without opening the corresponding chart, the time series are not created, but the downloaded data are directly written to the history files. In order to get this data, we need to query again and only in this case we will get fresh data (from the file). I wanted to try to simulate in some way the presence of an open graph in order to get the data from the RAM, not from the file.
 
AndEv:
In fact, you don't need anything else except OHLC. And it's not about the code. When charts are open, timeseries are created in virtual memory and all incoming quotes are stored in the main memory without being written to history files. History files are written only when we close MT4. When requesting data without opening the corresponding chart, the time series are not created, but the downloaded data are directly written to the history files. In order to get this data, we need to query again and only in this case we will get fresh data (from the file). I wanted to try to simulate in some way the presence of an open chart, in order to get the data from RAM rather than from a file.
To be honest, I've never got into such processes. I wonder what type of task you need to know this for?
 
paladin80:
To be honest, I've never really delved into such processes. I wonder what type of task you need to know this for?
A three-in-one task - selecting instruments, calculating weights and finding an entry point for trading three currencies simultaneously.
 

gyfto: 

Is this okay?

#import "kernel32.dll"
int GetModuleHandleA (string lpModuleName);//возвращает хэндл процесса; если lpModuleName=NULL то - текущего
#import

string lpModuleName;// неинициализированная строка содержит только /0, т.е. NULL
int hInstance;// передадим в CreateWindowExA

hInstance=GetModuleHandleA(lpModuleName);// аналогично GetModuleHandleA(NULL)


Looks like it'll work... Here's the code for the indicator:

#import "kernel32.dll"//в комментариях типы данных в С++ :
int GetModuleHandleA (string lpModuleName);//LPCSTR, т.е. LP (указатель) на строку (STR) с завершающим /0, которая является константой (C). Имя модуля, возм. с path
//на выходе HMODULE (целое без знака, 4 байта). Дескриптор приложения (процесса)
int GetModuleFileNameA(int hModule,//HMODULE (целое без знака, 4 байта). Он же.
                        int& lpFileName[],//LPSTR, т.е. LP (указатель) на строку (STR) с завершающим /0. Это выходной параметр - path
                        int nSize);//DWORD (целое, 4 знака). Расчётная длина буфера.
//на выходе DWORD (целое, 4 знака). Длина строки с path
#import
#property indicator_chart_window

extern string    lpModuleName;//Path. Сейчас там '/0', то есть GetModuleHandleA возвращает дескриптор текущего управляющего процесса. Path задавать не через '/', a '\'.  
string path="";//инициализация пустой строкой
int lpFileName[64];//через string задать не получается. Почему не разобрался. 64 это 0х100/4 байта (длина int)=0х40=64.
int hModule;//для выхода функции GetModuleHandleA, т.е. дескриптора процесса
int nSize=255;//не 256, потому что последний 256-й символ по идее будет 0х00 = '/0' (максимальная длина строки)
int sizeFileName;// так обзовём выходной параметр с GetModuleFileNameA
int i;//счётчик цикла

int start()
  {
   hModule = GetModuleHandleA(lpModuleName);
   sizeFileName = GetModuleFileNameA(hModule, lpFileName, nSize);
   for (i=0; i<sizeFileName; i++){//конвертация int[] в string 
      path=path//конкатенация с проходом от 0 до sizeFileName-1, на каждом проходе обрабатываем по одному каждый байт:
            + CharToStr(lpFileName[i] & 255)//битовое and, обнуление старших разрядов. Н-р, 0xkkllmmnn&0x000000FF(т.е.255)=0x000000nn, т.к. x&0=0, x&1=x (0xFF=0b11111111)
            + CharToStr(lpFileName[i] >> 8 & 255)//сдвиг вправо на 1 байт (8 бит), потом обнуление старших разрядов. На выходе, как и в предыдущей строке, 1 (один) байт
            + CharToStr(lpFileName[i] >> 16 & 255)//сдвиг вправо на 2 байта (16 бит), чтобы получить третий в int байт, и обнуление старших разрядов. 
            + CharToStr(lpFileName[i] >> 24 & 255)// аналогично: на 3 байта (24 бит), четвёртый байт. Параллельно везде конвертация в string.
      ;
   }
   Print("hmodule = ", hModule, ", sizeFileName = ", sizeFileName, ", path = ", path);//в журнал.
   path="";//обнуляем строку на выходе, чтобы не было дальнейшей конкатенации по циклу
   return(0);
  }

In the initial parameters of the tool, "empty" is specified instead of the path to the application, in the output it returns (in the log) its handle and full path. And then...

 
gyfto:


It seems to fit... Here is the code of the indicator:

The initial parameters of the indicator specify "empty" instead of the path to the application, in the output it returns (in the log) its handle and full path. Next...

hModule = GetModuleHandleA(lpModuleName);
sizeFileName = GetModuleFileNameA(hModule, lpFileName, nSize);

Why does the first line use a string buffer, and the second uses an integer array?

What prevents you from using an initialized string in both cases? It would cut the code down by a dozen lines.

 

Zhunko:

What prevents you from using an initialised string in both cases?


The log says function 'GetModuleFileNameA' call from dll 'kernel32.dll' critical error c0000005 at 7C902128 in case of string declaration. I still don't understand why. On the surface - terminal crashes about 3-7 seconds after opening, no time to write anything in logs, i.e. terminal closes not by itself.
Reason: