transparency

Download script
Author: Copyright � 2014, Vladimir Karputov

This script is designed to modify the visual appearance of your MetaTrader 5 trading platform by adjusting the transparency of the active chart window. Unlike standard platform settings, this tool interacts directly with the computer's operating system interface to achieve a specific visual effect.

How the Logic Works

The script follows a linear process to identify and modify the chart's properties:

1. Identification of the Active Window First, the script identifies the specific chart you are currently viewing on your screen. It retrieves a unique identification number for that chart window so it knows exactly which part of the software to modify.

2. Locating the Root Parent Because trading platforms often have multiple overlapping layers (such as menus, toolbars, and various sub-windows), the script performs a "walk" through these layers. It searches backward until it finds the "Root" window—the main container that holds everything else. This ensures that the transparency effect is applied correctly to the entire chart area rather than just a small internal element.

3. Enabling Layered Windows Once the main window is located, the script communicates with the operating system to change its style properties. It applies a specific attribute called "Layered Window." This tells the computer that this specific window is allowed to have varied levels of transparency, rather than being a solid, opaque block.

4. Applying Transparency Finally, the script sets the specific opacity level. Based on the internal logic, it calculates a percentage (specifically aiming for a 70% visibility level) and applies it to the window. This allows you to see other elements on your desktop or secondary monitors through the trading chart.

Summary of Purpose

The primary goal of this script is to create a "see-through" effect for your trading charts. By moving beyond the standard limitations of the software and interacting with the system's display settings, it allows for a more customized workspace where your charts can blend into your background environment.

13 Views
0 Downloads
0 Favorites
transparency
//+------------------------------------------------------------------+
//|                                                 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.10"
#import "user32.dll"
//+------------------------------------------------------------------+
//| Retrieves the handle to the ancestor of the specified window.    |
//+------------------------------------------------------------------+
int GetAncestor(int hwnd,int gaFlags);
//+------------------------------------------------------------------+
//| Retrieves information about the specified window.                |
//+------------------------------------------------------------------+
int GetWindowLongW(int hWnd,
                   int nIndex);          // GWL_EXSTYLE
//+------------------------------------------------------------------+
//| Changes an attribute of the specified window                     |
//+------------------------------------------------------------------+
int SetWindowLongW(int hWnd,
                   char nIndex,        // GWL_EXSTYLE
                   int dwNewLong);     // WS_EX_LAYERED
//+------------------------------------------------------------------+
//| 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,   // opacity 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()
  {
//--- get ID of the current chart
   long mainChartID=ChartID();
   int hdlmainChartID=ChartWindowsHandle(mainChartID);
   int hdlRoot=GetAncestor(hdlmainChartID,GA_ROOT);
   int SetWindowLongW_func;
//--- set WS_EX_LAYERED on the ROOT window
   SetWindowLongW_func=SetWindowLongW(hdlRoot,GWL_EXSTYLE,
                                      GetWindowLongW(hdlRoot,GWL_EXSTYLE)|WS_EX_LAYERED);
   GetWindowLongW(hdlRoot,GWL_EXSTYLE);
   SetLayeredWindowAttributes(hdlRoot,0,(255*70)/100,LWA_ALPHA);
   return;
  }
//+------------------------------------------------------------------+
//| The function gets the chart handle                               |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+

Comments