Scripts: Transparent MetaTrader 5 - page 2

 

Version changes:

Version 1.20: When rejoining the chart, the terminal becomes opaque again.

At the moment version 1.2 is sent for moderation.

 
Hello! Help me to find a script for setting stoploss for mt5. I trade rts.
 

Changes in: 

Version 1.20: When re-accession to the schedule, the terminal becomes opaque.

 

Версия 1.10: Поддержка Windows XP 32-bit.

you have spoilt everything.

you were obliged to make two variants of calling DLL functions for 32 and 64 handles/pointers

example

 

barabashkakvn:

Version 1.10: Support Windows XP 32-bit.

sergeev:

you have spoilt everything.

you had to make two variants of calling DLL functions for 32 and 64 handles/pointers

example

Thanks for the example! I can't promise to fix it right away, because I need to solve the question: what functions the user32.dll library contains in operating systems from Windows XP to Windows 8.1, and I need to take into account the system bitness.
 
I have a suspicion that in MT5 build 900 or 910 the mechanism of calling DLL is broken. Application in the service desk #976227. Crashes may be related to this. Gentlemen developers, please look there....
 
Very interesting!)
 
micle:
I have a suspicion that in MT5 build 900 or 910 the mechanism of calling DLL is broken. Request in the service desk #976227. Crashes may be related to this. Gentlemen developers, please look there...
My problem was solved by another function declaration... Live and learn )
 
barabashkakvn:

Changes in: 

Version 1.20: When re-accession to the schedule, the terminal becomes opaque.

On English codebase, available version is still 1.10.
 

Version 1.20

//+------------------------------------------------------------------+
//|                                                 transparency.mq5 |
//|                              Copyright © 2014, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.20"
#import "user32.dll"
//+------------------------------------------------------------------+
//| GetAncestor. Retrieves the handle to the ancestor of the         |
//| specified window. Извлекает дескриптор предка заданного окна     |
//+------------------------------------------------------------------+
int GetAncestor(int hwnd,int gaFlags);
//+------------------------------------------------------------------+
//| GetWindowLongW. Retrieves information about the specified        |
//| window. Получает информацию об указанном окне                    |
//+------------------------------------------------------------------+
int GetWindowLongW(
                   int hWnd,
                   int nIndex          // GWL_EXSTYLE
                   );
//+------------------------------------------------------------------+
//| SetWindowLongW. Изменяет атрибут заданного окна                  |
//+------------------------------------------------------------------+
int SetWindowLongW(
                   int hWnd,
                   char nIndex,        // GWL_EXSTYLE
                   int dwNewLong       // WS_EX_LAYERED
                   );
//+------------------------------------------------------------------+
//| SetLayeredWindowAttributes. Sets the opacity and transparency    |
//| color key of a layered window. Устанавливает светопроницаемость  |
//| и прозрачность окраски многослойного окна                        |
//+------------------------------------------------------------------+
bool SetLayeredWindowAttributes(
                                int hwnd,// A handle to the layered window
                                int crKey,   // 0
                                int bAlpha,  // степень непрозрачности 0-255
                                int dwFlags  // 0x00000002
                                );
#import
#define  GA_ROOT           0x0002      // Retrieves the root window by walking the chain of parent windows.
#define  GWL_EXSTYLE       -20               // Sets a new extended window style
#define  WS_EX_LAYERED     0x00080000        // Style. The window is a layered window. 
#define  LWA_ALPHA         0x00000002        // Use bAlpha to determine the opacity of the layered window.
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long  mainChartID=ChartID();         // возвращает идентификатор текущего графика
   int   hdlmainChartID=ChartWindowsHandle(mainChartID);
   int   hdlRoot=GetAncestor(hdlmainChartID,GA_ROOT);
   int   SetWindowLongW_func;
   if(GetWindowLongW(hdlRoot,GWL_EXSTYLE)&WS_EX_LAYERED)
     {
      // У окна уже есть стиль WS_EX_LAYERED. Удалим WS_EX_LAYERED из этого окна стилей.
      // Window already has a style WS_EX_LAYERED. Remove WS_EX_LAYERED from this window styles.
      SetWindowLongW_func=SetWindowLongW(hdlRoot,GWL_EXSTYLE,
                                         GetWindowLongW(hdlRoot,GWL_EXSTYLE)&~WS_EX_LAYERED);
      return;
     }
// Устанавливаем WS_EX_LAYERED на ROOT окно
   SetWindowLongW_func=SetWindowLongW(hdlRoot,GWL_EXSTYLE,
                                      GetWindowLongW(hdlRoot,GWL_EXSTYLE)|WS_EX_LAYERED);
   SetLayeredWindowAttributes(hdlRoot,0,(255*70)/100,LWA_ALPHA);
   return;
  }
//+------------------------------------------------------------------+
//| The function gets the handle graphics                            |
//| Функция получает хэндл графика                                   |
//+------------------------------------------------------------------+
int ChartWindowsHandle(long chart_ID)
  {
//--- prepare the variable to get the property value
//--- подготовим переменную для получения значения свойства
   long result=-1;
//--- reset the error value
//--- сбросим значение ошибки
   ResetLastError();
//--- receive the property value
//--- получим значение свойства
   if(!ChartGetInteger(chart_ID,CHART_WINDOW_HANDLE,0,result))
     {
      //--- display the error message in Experts journal
      //--- выведем сообщение об ошибке в журнал "Эксперты"
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
//--- вернем значение свойства графика
   return((int)result);
  }
//+------------------------------------------------------------------+