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

 
getch:

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

Of course there is no perversion in the script itself - I didn't say it exactly right. The perversion is in the way of accessing the list. But you should agree that access to the list of tools should be realized by means of the terminal, not through windows. And the script is very useful, especially for beginners like me who have no experience of working with the Windows. Thank you again, it has a lot of useful solutions, which would have taken me a lot of time to learn on my own.
 

Why did you have to make up such a perversion... It's easier to write an external DLL, in which the required data are pulled from MarketWatch object. You can't do it with MQL4, because the memory allocation procedure is required.

 
In MQL4 it is realistic (tested) to pull this data without writing a DLL. But the above approach is much more universal. Because you can easily and conveniently cram a lot of data into WriteSymbol() function...
 
 
Your video doesn't work...
Although, in principle, it's already clear how the script will work. But it's clearly an unreliable solution, and will probably cause frequent hangs of the terminal. It hangs often enough as it is...

getch:
In MQL4 you can (tried) get these data without writing a DLL. But the above approach is much more universal. You can easily and conveniently shove a lot of data into WriteSymbol() function...

I wonder how to get it out? With what commands? If such a thing is really possible, it would be greatly appreciated... Although I seriously doubt it's possible...


I have pulled data from Market Watch myself, but only in C++. To do this, you first create a new process (OpenProcess), reserve memory in it (VirtualAllocEx), place the required data structure there, and save the necessary information from the object there. And then we read the necessary data from there. But you can't get the information by messaging only, I tried it. The object is of ListView type.

 

For reasons unknown to me, the forum cannot display the video correctly. Therefore I have attached it as a ZIP-archive.


I haven't encountered any unreliability or inoperability of this script.

Files:
symbols.zip  1630 kb
 

Simpler (only one global variable) and more reliable (no hash function) version of the script:

// Запись в файл названий и торговых условий всех символов из окна "Market Watch"
// Во время работы скрипта желательно не производить никаких действий в терминале

#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 LVM_GETITEMCOUNT 0x1004

// Названия используемых глобальных переменных
#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;
}

// Запускает выбранный в окне "Navigator" скрипт (индикатор или советник) 
void RunScript()
{
  PostMessageA(Parent(), WM_COMMAND, 33042, 0); // исполнить скрипт на текущем графике
  
  return;
}

// Возвращает количество символов в окне "Market Watch"
int SymbolCount()
{
  int hwnd = Parent();
  int Count = 0;    

  if (hwnd != 0)  // нашли главное окно
  {
    hwnd = GetDlgItem(hwnd, 0xE81C); // Нашли список символов
    hwnd = GetDlgItem(hwnd, 0x50);
    hwnd = GetDlgItem(hwnd, 0x8A71);
   
    Count = SendMessageA(hwnd, LVM_GETITEMCOUNT, 0, 0); // получили количество элементов списка
  }
   
  return(Count);
}

// Записывает характеристика текущего торгового символа в файл
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, Count, i = 1;
  
  if (GlobalVariableCheck(VAR_HANDLE))  // Запустили не первый раз...
  {
    GlobalVariableSet(VAR_HANDLE, WindowHandle(Symbol(), Period()));
    WriteSymbol();
  }
  else  // запустили первый раз
  {
    GlobalVariableSet(VAR_HANDLE, WindowHandle(Symbol(), Period()));

    handle = FileOpen(FileName, FILE_WRITE); // обнулили файл с данными
    FileClose(handle);
    
    Count = SymbolCount();

    while(!IsStopped())
    {
      if (i > Count)
        break;
      
      OpenChart(i); // открыли график очередного символа из окна "Market Watch"
      Sleep(Pause);
      
      RunScript(); // запустили на только что открытом графике текущий скрипт
      Sleep(Pause);
      
      CloseChart(GlobalVariableGet(VAR_HANDLE)); // закрыли окно графика
      Sleep(Pause);

      i++;
    } 
    
    GlobalVariableDel(VAR_HANDLE);
    
    // записали в файл количество символов в окне "Market Watch"
    handle = FileOpen(FileName, FILE_READ|FILE_WRITE);
    FileSeek(handle, 0, SEEK_END);

    FileWrite(handle, "\nAMOUNT OF SYMBOLS = " + Count);
    FileClose(handle);
  }
  
  return;
}
 
getch:

// Открывает окно графика символа, расположенного в строке номер Num окна "Market Watch"
void OpenChart( int Num )

what command can I use to "reset" a symbol to an already open chart? i.e. switch the current chart to the symbol I want?

 

Here made ZG_All Quotings 1-80924!!!

Thanks getch for the great idea and flight of thought!!!

Would love to know the name of the hero :-)

This script is the last way to get quotes from a broker.

An even tougher way is to visit your broker in person with special tools to knock out quotes.

 
With irons, is it?
Reason: