FadedBckgrnd

Download script
Author: Tino Wening
FadedBckgrnd

This script is a visual enhancement tool designed to modify the background of your trading charts. Instead of providing technical signals or data analysis, it focuses purely on the aesthetic presentation of the workspace by creating a smooth color transition across the price window.

Core Functionality

Dynamic Background Gradient The primary purpose of this script is to generate a "faded" background effect. It automatically identifies the highest and lowest price points currently visible on your screen and divides that vertical space into a series of distinct layers (steps).

Seamless Color Blending Rather than using a single flat color, the logic calculates a gradient between two user-defined colors (set at the top and bottom of the chart). It processes the transition so that the colors blend into one another progressively. By calculating the mathematical difference between the starting color and the ending color, it ensures the shift feels smooth rather than abrupt.

Adaptive Visibility The script is designed to be responsive to your current view:

  • Automatic Scaling: It detects the visible range of your chart, meaning the gradient will adjust if you zoom in or out.
  • Auto-Positioning: It identifies the boundaries of what you are currently seeing and places the visual layers accordingly.
  • Background Layering: The elements are set to appear "behind" the price action, ensuring that candles, lines, and other indicators remain clearly visible and unobstructed.

Clean Workspace Management To maintain optimal performance, the script includes a management system that automatically handles the creation and removal of these visual layers. When the indicator is loaded, it builds the gradient; when it is removed, it ensures all temporary visual elements are cleared from the chart to keep your workspace clean.

3 Views
0 Downloads
0 Favorites
FadedBckgrnd
//+------------------------------------------------------------------+
//|                                                 FadedBckgrnd.mq4 |
//|                                                      Tino Wening |
//|                                                  info@prinova.de |
//+------------------------------------------------------------------+
#property copyright "Tino Wening"
#property link      "info@prinova.de"

#property indicator_chart_window
#import "stdlib.ex4"
int RGB(int red_value,int green_value,int blue_value);
double top, bottom;
datetime left;
int right_bound;
datetime right;
extern string topcol  ="000,000,000";
extern string bottomcol ="000,000,255";
int r,g,b;
extern int steps =20;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   //Print(colour);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int x=1;x<=steps;x++)
   {
      ObjectDelete("Padding_rect"+x);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   top =  WindowPriceMax();
   bottom = WindowPriceMin(); 
   left = Time[WindowFirstVisibleBar()];
   right_bound=WindowFirstVisibleBar()-WindowBarsPerChart();
   if(right_bound<0) right_bound=0;
   right=Time[right_bound]+Period()*60;
   for(int x=1;x<=steps;x++)
   {
      if(ObjectFind("Padding_rect"+x) ==-1) ObjectCreate("Padding_rect"+x,OBJ_RECTANGLE,0,left,top-((top-bottom)/steps)*(x-1),right,top-((top-bottom)/steps)*(x));
      ObjectSet("Padding_rect"+x, OBJPROP_TIME1, left);
      ObjectSet("Padding_rect"+x, OBJPROP_TIME2, right);
      ObjectSet("Padding_rect"+x, OBJPROP_PRICE1, top-((top-bottom)/steps)*(x-1));
      ObjectSet("Padding_rect"+x, OBJPROP_PRICE2, top-((top-bottom)/steps)*(x));
      ObjectSet("Padding_rect"+x,OBJPROP_BACK,true);
      
      ObjectSet("Padding_rect"+x,OBJPROP_COLOR, ss2rgb(topcol, bottomcol,steps, x));//  RGB((128/steps*x),(128/steps*x),(255/steps*x)));
   }
      WindowRedraw();

//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

int ss2rgb(string colour1, string colour2, int step, int index)
{
   
   int r1 = StrToInteger(StringSubstr(colour1, 0,3));
   int g1 = StrToInteger(StringSubstr(colour1, 4,3));
   int b1 = StrToInteger(StringSubstr(colour1, 8,3));
   
   int r2 = StrToInteger(StringSubstr(colour2, 0,3));
   int g2 = StrToInteger(StringSubstr(colour2, 4,3));
   int b2 = StrToInteger(StringSubstr(colour2, 8,3));
   
   if(r1>r2)
   {
      r = r1+((r2-r1)/step*index);
   }
   if(r1<r2)
   {
      r = r1-((r1-r2)/step*index);
   }
   
   if(g1>g2)
   {
      g = g1+((g2-g1)/step*index);
   }
   if(g1<g2)
   {
      g = g1-((g1-g2)/step*index);
   }
   
   if(b1>b2)
   {
      b = b1+((b2-b1)/step*index);
   }
   if(b1<b2)
   {
      b = b1-((b1-b2)/step*index);
   }
   
   g<<=8;
   b<<=16;
   return(r+g+b);
   
      
}

Comments