How can the script programmatically go through all the instruments that are selected in the Market Watch window? - page 2

 
KimIV:
VBAG:
Recently solved this problem for myself.
Doesn't work where DCs add something of their own to the name of the pair. For example, "m", "!", "." or "_".
Yes, of course, I did it in research purposes, but if you want to do something radical - to stump and search the number of combinations of all characters ASCII, say, the maximum reasonable number of characters in the name of the instrument (8-10). Such a script will probably take a few hours to run, but it is automatic and guaranteed.


to Zhunko.
-I remember, of course I got the idea from your code. Worked with your loader for a few days - it's fun! Thanks.
 
KimIV:
VBAG:

Recently solved this problem for myself.
Doesn't work where DCs add something of their own to the name of the pair. For example, "m", "!", "." or "_".
There are few such FCs and the number of characters they use is small. It is possible to foresee.
That's what I did with Moneiraine pairs. That's where "mini" and "pro" are.
I think there's also some shit in Lite.
I.e. you can divide the instruments into groups according to DTs.
I was interested only in the following brokerage companies: Alpari, ForexBest, MoneyRain, NorthFinance, NWBroker.
These are brokerage companies with the maximum number of instruments. And they were necessary for giving quotes for currency indexes calculation.
The script "ZZ_All Quotings 0-0080" is designed for them.
 
// Запись в файл названий и торговых условий всех символов из окна "Market Watch"
// Во время работы скрипта желательно не производить никаких действий в терминале
// NB: Используемая Хэш-функция не является корректной для данной задачи 
 
#include <WinUser32.mqh>
 
extern string FileName = "Symbols.txt";  // Имя файла для записи информации по символам
extern int Pause = 200; // Техническая пауза в миллисекундах
 
#import "user32.dll"
  int GetParent( int hWnd );
  int GetDlgItem( int hDlg, int nIDDlgItem );
#import
 
#define VK_HOME 0x24
#define VK_DOWN 0x28
 
// Названия используемых глобальных переменных
#define VAR_HASH "Symbol_Hash"
#define VAR_HANDLE "Symbol_Handle"
 
// Возвращает хэндл основного окна терминала
int Parent()
{
  int hwnd = WindowHandle(Symbol(), Period());
  int hwnd_parent = 0;
 
  while (!IsStopped())
  {
     hwnd = GetParent(hwnd);
     
     if (hwnd == 0)
       break;
       
     hwnd_parent = hwnd;
  }
   
  return(hwnd_parent);
}
 
// Открывает окно графика символа, расположенного в строке номер Num окна "Market Watch"
void OpenChart( int Num )
{
   int hwnd = Parent();
   
   if (hwnd != 0)  // нашли главное окно
   {
     hwnd = GetDlgItem(hwnd, 0xE81C); // нашли "Market Watch"
     hwnd = GetDlgItem(hwnd, 0x50);
     hwnd = GetDlgItem(hwnd, 0x8A71);
     
     PostMessageA(hwnd, WM_KEYDOWN, VK_HOME,0); // верхняя строчка окна "Market Watch"
     
     while (Num > 1)  
     {
       PostMessageA(hwnd, WM_KEYDOWN,VK_DOWN, 0); // сместились на нужную строчку
       Num--;
     }
   }
 
  PostMessageA(Parent(), WM_COMMAND, 33160, 0); // открыли график
 
  return;
}
 
// Закрывает окно графика
void CloseChart( int hwnd )
{
  PostMessageA(GetParent(hwnd), WM_CLOSE, 0, 0);
  
  return;
}
 
// Хэш-функция перевода строки в целое число
// NB: данная функция не совершенна (приводит к коллизиям)
int Hash( string Str )
{
  int HashRes = 0;
  int i; 
  
  i = StringLen(Str) - 1;
  
  while (i >= 0)
  {  
    HashRes += StringGetChar(Str, i);
    i--;
  }
 
  HashRes %= 101;
  
  return(HashRes);
}
 
// Запускает выбранный в окне "Navigator" скрипт (индикатор или советник) 
void RunScript()
{
  PostMessageA(Parent(), WM_COMMAND, 33042, 0); // исполнить скрипт на текущем графике
  
  return;
}
 
// Записывает характеристика текущего торгового символа в файл
void WriteSymbol()
{
  int handle;
  string Str;
  
  
  Str = "\n" + Symbol() + ":";
  Str = Str + "\n  Spread = " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD), 0);
  Str = Str + "\n  StopLevel = " + DoubleToStr(MarketInfo(Symbol(), MODE_STOPLEVEL), 0);
  Str = Str + "\n  Digits = " + DoubleToStr(MarketInfo(Symbol(), MODE_DIGITS), 0);
  Str = Str + "\n  Price(Example) = " + DoubleToStr(Bid, Digits);
 
  handle = FileOpen(FileName, FILE_READ|FILE_WRITE);
  FileSeek(handle, 0, SEEK_END);
 
  FileWrite(handle, Str);
  FileClose(handle);
  return;
}
 
void start()
{
  int handle, i = 1;
  
  if (GlobalVariableCheck(VAR_HASH))  // Запустили не первый раз...
  {
    GlobalVariableSet(VAR_HANDLE, WindowHandle(Symbol(), Period()));
 
    if (GlobalVariableGet(VAR_HASH) != Hash(Symbol())) // проверка достижения конца списка символов окна "Market Watch"
    {  
      GlobalVariableSet(VAR_HASH, Hash(Symbol()));
      WriteSymbol();
    }
    else
      GlobalVariableDel(VAR_HASH);
  }
  else  // запустили первый раз
  {
    GlobalVariableSet(VAR_HASH, -1);
    
    handle = FileOpen(FileName, FILE_WRITE); // обнулили файл с данными
    FileClose(handle);
 
    while(!IsStopped())
    {
      OpenChart(i); // открыли график очередного символа из окна "Market Watch"
      Sleep(Pause);
      
      RunScript(); // запустили на только что открытом графике текущий скрипт
      Sleep(Pause);
      
      CloseChart(GlobalVariableGet(VAR_HANDLE)); // закрыли окно графика
      Sleep(Pause);
      
      if (!GlobalVariableCheck(VAR_HASH)) // Достигнут ли конец списка символов окна "Market Watch"?
        break;
        
      i++;
    }
    
    GlobalVariableDel(VAR_HANDLE);
    i--;
    
    // записали в файл количество символов в окне "Market Watch"
    handle = FileOpen(FileName, FILE_READ|FILE_WRITE);
    FileSeek(handle, 0, SEEK_END);
 
    FileWrite(handle, "AMOUNT OF SYMBOLS = " + i);
    FileClose(handle);
  }
  
 
  return;
}
 
It's a fun toy, but it doesn't work properly. I got stuck on the last tool. Attempting to stop it caused an MT4 error.
Let it open windows of each instrument with each TF.
This is the kind of procedure that is missing at the beginning:
#property show_inputs
 
Wow! That's great!
Thank you! (Laughs)
 
Oh, I'll give it a try.
 
Zhunko:
It's a fun toy, but it doesn't work properly. I got stuck on the last tool. Attempting to stop it caused an MT4 error.
Let it open windows of each instrument with each TF.
This is the procedure missing in the beginning:
#property show_inputs


Make it
extern int Pause = 1000; // Техническая пауза в миллисекундах

If it caused an error, delete the following global variables again before running (F3):

"Symbol_Hash"
"Symbol_Handle"
NB: The script is only a demonstration of the idea of a possible solution to the problem at hand.
 
getch:

NB: The script is only a demonstration of the idea of a possible solution to the task at hand.

The programming experience beautifully demonstrates both the ingenuity of the human mind and the lack of functionality of the tool... hooray and alas...
 
Shu:

Lack of functionality of the tool... hooray and alas...
Let's hope that in MQL5 we won't be forced to make such distortions.

P.S. On the other hand - the process is important!
 

There is no perversion in the script. It is a bit unconventional, that's all.

Idea: The script opens chart windows of each trading instrument from the "Market Watch" window, runs itself on them and closes the window. It regulates itself using global variables created by itself (and deleted at the end of operation). That's all.


The script will work 99% of the time, if the following conditions are met:

- The DLL will be allowed to be used without manual confirmation;

- The value of the Pause variable will be set greater than 1000 (technical pause, depends on the performance of the computer and the Internet connection. The better these characteristics, the less you can set the Pause value and respectively reduce the running time of the script);

- delete the global variables(F3) "Symbol_Hash" and "Symbol_Handle" before running the script (this may be the case if the script failed to run before).


After finishing the script, the terminal looks the same as it did before it was started. All symbol data is in the Symbols.txt file.