vkw_bands_modify_candle_v1

Download script
Author: Copyright � 2008, Alksnis Gatis

This script is designed as a specialized visual tool for MetaTrader 5 that helps traders identify potential areas for placing pending orders. It works by analyzing price movements and projecting smoothed "bands" or levels based on historical extremes.

Here is a breakdown of the logic in non-technical terms:

Core Functionality

The indicator operates in a separate window below your main price chart. Its primary goal is to visualize high and low price boundaries over a specific period, smoothing out the market "noise" to reveal underlying trends or significant zones where price might react.

How it Processes Data

To achieve its visual output, the script follows a three-step logical process:

1. External Data Integration The script does not work alone; it pulls data from an external component called "METRO." It gathers four specific types of information from this source: Open, High, Low, and Close prices. By using these four data points, the script can reconstruct a more comprehensive view of how price is moving compared to just looking at a single line.

2. Boundary Detection and Candle Coloring Once it has the data, the script performs two specific tasks:

  • Extreme Mapping: It looks at each candle to determine its highest and lowest points. If a candle's internal "open" or "close" price is higher than the high recorded by the METRO source (or lower than the low), it updates those boundaries to ensure the visual "envelope" always encompasses the actual price action.
  • Visual Feedback: It automatically assigns colors to these candles based on their direction. It distinguishes between upward movement, downward movement, and neutral (flat) price action, making it easier for a trader to see market sentiment at a glance.

3. Smoothing and Band Projection This is the core "intelligence" of the script. Instead of showing jagged, erratic lines, the script uses complex smoothing algorithms (which you can customize in the settings, such as SMA, EMA, etc.):

  • Upper and Lower Bands: It identifies the maximum high and minimum low prices over a user-defined lookback period (the "RPeriod").
  • Trend Smoothing: It then applies a mathematical smoothing process to these highs and lows. This creates two distinct lines: an Upper Band and a Lower Band.
  • The Result: These bands act as dynamic corridors. Because they are smoothed, they reveal the "path of least resistance" and highlight areas where price has historically found support or resistance.

Summary for the Trader

Essentially, this tool acts like a high-tech "map" of price extremes. By smoothing out the minor fluctuations of the market, it highlights the broader boundaries of the current trend. Traders use these smoothed bands to identify significant zones where the price might "bounce" or "reject," providing a clearer visual guide for where to set entry points for pending orders.

15 Views
0 Downloads
0 Favorites
vkw_bands_modify_candle_v1
//+---------------------------------------------------------------------+
//|                                         VKW_Bands_Modify_Candle.mq5 | 
//|                                     Copyright © 2008, Alksnis Gatis | 
//|                                                   2xpoint@gmail.com | 
//+---------------------------------------------------------------------+
//| Äëÿ ðàáîòû  èíäèêàòîðà  ñëåäóåò  ïîëîæèòü ôàéë SmoothAlgorithms.mqh |
//| â ïàïêó (äèðåêòîðèþ): terminal_data_folder\MQL5\Include             |
//+---------------------------------------------------------------------+
#property copyright "Copyright © 2008, Alksnis Gatis"
#property link "2xpoint@gmail.com"
#property description "Èíäèêàòîð ïîêàçûâàåò, ãäå âûñòàâëÿòü îòëîæåííûå îðäåðà"
//---- íîìåð âåðñèè èíäèêàòîðà
#property version   "1.00"
//---- îòðèñîâêà èíäèêàòîðà â îòäåëüíîì îêíå
#property indicator_separate_window
//---- êîëè÷åñòâî èíäèêàòîðíûõ áóôåðîâ
#property indicator_buffers 7 
//---- èñïîëüçîâàíî âñåãî òðè ãðàôè÷åñêèõ ïîñòðîåíèÿ
#property indicator_plots   3
//+-----------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà    |
//+-----------------------------------+
//---- â êà÷åñòâå èíäèêàòîðà èñïîëüçîâàíû öâåòíûå ñâå÷è
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1   clrRed,clrGray,clrBlue
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label1  "Open;High;Low;Close"
//+-----------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà    |
//+-----------------------------------+
//---- îòðèñîâêà èíäèêàòîðà â âèäå ëèíèè
#property indicator_type2   DRAW_LINE
//---- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàí DodgerBlue öâåò
#property indicator_color2 clrLimeGreen
//---- ëèíèÿ èíäèêàòîðà - íåïðåðûâíàÿ êðèâàÿ
#property indicator_style2  STYLE_SOLID
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 1
#property indicator_width2  1
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label2  "VKW_Bands Upper"
//+-----------------------------------+
//| Ïàðàìåòðû îòðèñîâêè èíäèêàòîðà    |
//+-----------------------------------+
//---- îòðèñîâêà èíäèêàòîðà â âèäå ëèíèè
#property indicator_type3   DRAW_LINE
//---- â êà÷åñòâå öâåòà ëèíèè èíäèêàòîðà èñïîëüçîâàí Magenta öâåò
#property indicator_color3 clrMagenta
//---- ëèíèÿ èíäèêàòîðà - íåïðåðûâíàÿ êðèâàÿ
#property indicator_style3  STYLE_SOLID
//---- òîëùèíà ëèíèè èíäèêàòîðà ðàâíà 1
#property indicator_width3  1
//---- îòîáðàæåíèå ìåòêè èíäèêàòîðà
#property indicator_label3  "VKW_Bands Lower"
//+-----------------------------------+
//| Ïàðàìåòðû óðîâíåé                 |
//+-----------------------------------+
#property indicator_level1 60
#property indicator_level2 40
#property indicator_levelcolor clrMagenta
#property indicator_levelstyle STYLE_DASHDOTDOT
//+-----------------------------------+
//| Îáúÿâëåíèå êîíñòàí                |
//+-----------------------------------+
#define RESET 0                      // êîíñòàíòà äëÿ âîçâðàòà òåðìèíàëó êîìàíäû íà ïåðåñ÷åò èíäèêàòîðà
//+-----------------------------------+
//| Îïèñàíèå êëàññà CXMA              |
//+-----------------------------------+
#include <SmoothAlgorithms.mqh> 
//+-----------------------------------+
//---- îáúÿâëåíèå ïåðåìåííûõ êëàññà CXMA èç ôàéëà SmoothAlgorithms.mqh
CXMA XMA1,XMA2;
//+-----------------------------------+
//| Îáúÿâëåíèå ïåðå÷èñëåíèé           |
//+-----------------------------------+
/*enum Smooth_Method - ïåðå÷èñëåíèå îáúÿâëåíî â ôàéëå SmoothAlgorithms.mqh
  {
   MODE_SMA_,  //SMA
   MODE_EMA_,  //EMA
   MODE_SMMA_, //SMMA
   MODE_LWMA_, //LWMA
   MODE_JJMA,  //JJMA
   MODE_JurX,  //JurX
   MODE_ParMA, //ParMA
   MODE_T3,    //T3
   MODE_VIDYA, //VIDYA
   MODE_AMA,   //AMA
  }; */
//+-----------------------------------+
//| Âõîäíûå ïàðàìåòðû èíäèêàòîðà      |
//+-----------------------------------+
input uint PeriodRSI=7;                               // Ïåðèîä èíäèêàòîðà
input int StepSizeFast=5;                             // Áûñòðûé øàã
input int StepSizeSlow=15;                            // Ìåäëåííûé øàã
input int IShift=0;                                   // Ñäâèã èíäèêàòîðà ïî ãîðèçîíòàëè â áàðàõ 
input uint RPeriod=25;                                // Ïåðèîä ïîèñêà äëÿ ýêñòðåìóìîâ
input Smooth_Method SmMA_Method=MODE_SMA;             // Ìåòîä ñãëàæèâàíèÿ
input uint SLength=3;                                 // Ãëóáèíà ñãëàæèâàíèÿ                    
input int SPhase=100;                                 // Ïàðàìåòð ñãëàæèâàíèÿ
//---- äëÿ JJMA èçìåíÿþùèéñÿ â ïðåäåëàõ -100 ... +100, âëèÿåò íà êà÷åñòâî ïåðåõîäíîãî ïðîöåññà;
//---- äëÿ VIDIA ýòî ïåðèîä CMO, äëÿ AMA ýòî ïåðèîä ìåäëåííîé ñêîëüçÿùåé
input int SShift=0;                                   // Ñäâèã èíäèêàòîðà êàíàëà ïî ãîðèçîíòàëè â áàðàõ
//+-----------------------------------+
//---- îáúÿâëåíèå äèíàìè÷åñêîãî ìàññèâîâ, êîòîðûå áóäóò â 
//---- äàëüíåéøåì èñïîëüçîâàíû â êà÷åñòâå èíäèêàòîðíûõ áóôåðîâ
double ExtOpenBuffer[],ExtHighBuffer[],ExtLowBuffer[],ExtCloseBuffer[],ExtColorBuffer[];
double UpIndBuffer[],DnIndBuffer[];
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ äëÿ õåíäëîâ èíäèêàòîðîâ
int Ind_Handle[4];
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
int min_rates_total,min_rates_1;
//+------------------------------------------------------------------+   
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int OnInit()
  {
//---- èíèöèàëèçàöèÿ ïåðåìåííûõ íà÷àëà îòñ÷åòà äàííûõ
   min_rates_1=int(PeriodRSI);
   min_rates_1+=int(RPeriod);
   min_rates_total=min_rates_1+GetStartBars(SmMA_Method,SLength,SPhase);
//---- ïîëó÷åíèå õåíäëîâ èíäèêàòîðà METRO
   Ind_Handle[0]=iCustom(NULL,0,"METRO",PeriodRSI,StepSizeFast,StepSizeSlow,0,PRICE_OPEN);
   if(Ind_Handle[0]==INVALID_HANDLE)
     {
      Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà METRO["+string(0)+"]!");
      return(INIT_FAILED);
     }
//----
   Ind_Handle[1]=iCustom(NULL,0,"METRO",PeriodRSI,StepSizeFast,StepSizeSlow,0,PRICE_HIGH);
   if(Ind_Handle[1]==INVALID_HANDLE)
     {
      Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà METRO["+string(1)+"]!");
      return(INIT_FAILED);
     }
//----
   Ind_Handle[2]=iCustom(NULL,0,"METRO",PeriodRSI,StepSizeFast,StepSizeSlow,0,PRICE_LOW);
   if(Ind_Handle[2]==INVALID_HANDLE)
     {
      Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà METRO["+string(2)+"]!");
      return(INIT_FAILED);
     }
//----
   Ind_Handle[3]=iCustom(NULL,0,"METRO",PeriodRSI,StepSizeFast,StepSizeSlow,0,PRICE_CLOSE);
   if(Ind_Handle[3]==INVALID_HANDLE)
     {
      Print(" Íå óäàëîñü ïîëó÷èòü õåíäë èíäèêàòîðà METRO["+string(3)+"]!");
      return(INIT_FAILED);
     }
///---- ïðåâðàùåíèå äèíàìè÷åñêèõ ìàññèâîâ â èíäèêàòîðíûå áóôåðû
   SetIndexBuffer(0,ExtOpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtHighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtLowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtCloseBuffer,INDICATOR_DATA);
//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â öâåòîâîé, èíäåêñíûé áóôåð   
   SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðàõ êàê â òàéìñåðèÿõ
   ArraySetAsSeries(ExtOpenBuffer,true);
   ArraySetAsSeries(ExtHighBuffer,true);
   ArraySetAsSeries(ExtLowBuffer,true);
   ArraySetAsSeries(ExtCloseBuffer,true);
   ArraySetAsSeries(ExtColorBuffer,true);
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà ïî ãîðèçîíòàëè
   PlotIndexSetInteger(0,PLOT_SHIFT,IShift);

//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(5,UpIndBuffer,INDICATOR_DATA);
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 2 ïî ãîðèçîíòàëè
   PlotIndexSetInteger(1,PLOT_SHIFT,SShift);
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðàõ êàê â òàéìñåðèÿõ   
   ArraySetAsSeries(UpIndBuffer,true);

//---- ïðåâðàùåíèå äèíàìè÷åñêîãî ìàññèâà â èíäèêàòîðíûé áóôåð
   SetIndexBuffer(6,DnIndBuffer,INDICATOR_DATA);
//---- îñóùåñòâëåíèå ñäâèãà èíäèêàòîðà 3 ïî ãîðèçîíòàëè
   PlotIndexSetInteger(2,PLOT_SHIFT,SShift);
//---- îñóùåñòâëåíèå ñäâèãà íà÷àëà îòñ÷åòà îòðèñîâêè èíäèêàòîðà
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,min_rates_total);
//---- óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);
//---- èíäåêñàöèÿ ýëåìåíòîâ â áóôåðàõ êàê â òàéìñåðèÿõ   
   ArraySetAsSeries(DnIndBuffer,true);

//---- èíèöèàëèçàöèÿ ïåðåìåííîé äëÿ êîðîòêîãî èìåíè èíäèêàòîðà
   string shortname="VKW_Bands_METRO_Candle";
//--- ñîçäàíèå èìåíè äëÿ îòîáðàæåíèÿ â îòäåëüíîì ïîäîêíå è âî âñïëûâàþùåé ïîäñêàçêå
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- îïðåäåëåíèå òî÷íîñòè îòîáðàæåíèÿ çíà÷åíèé èíäèêàòîðà
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- çàâåðøåíèå èíèöèàëèçàöèè
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+ 
//| Custom iteration function                                        | 
//+------------------------------------------------------------------+ 
int OnCalculate(const int rates_total,    // êîëè÷åñòâî èñòîðèè â áàðàõ íà òåêóùåì òèêå
                const int prev_calculated,// êîëè÷åñòâî èñòîðèè â áàðàõ íà ïðåäûäóùåì òèêå
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---- ïðîâåðêà êîëè÷åñòâà áàðîâ íà äîñòàòî÷íîñòü äëÿ ðàñ÷åòà
   if(BarsCalculated(Ind_Handle[0])<rates_total
      || BarsCalculated(Ind_Handle[1])<rates_total
      || BarsCalculated(Ind_Handle[2])<rates_total
      || BarsCalculated(Ind_Handle[3])<rates_total
      || rates_total<min_rates_total)
      return(RESET);
//---- îáúÿâëåíèå ïåðåìåííûõ ñ ïëàâàþùåé òî÷êîé  
   double d_max,d_min;
//---- îáúÿâëåíèå öåëî÷èñëåííûõ ïåðåìåííûõ è ïîëó÷åíèå óæå ïîñ÷èòàííûõ áàðîâ
   int limit,to_copy,bar,maxbar;
   maxbar=rates_total-1-min_rates_1;
//---- ðàñ÷åò ñòàðòîâîãî íîìåðà first äëÿ öèêëà ïåðåñ÷åòà áàðîâ
   if(prev_calculated>rates_total || prev_calculated<=0) // ïðîâåðêà íà ïåðâûé ñòàðò ðàñ÷åòà èíäèêàòîðà
     {
      limit=maxbar; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà âñåõ áàðîâ
     }
   else limit=rates_total-prev_calculated; // ñòàðòîâûé íîìåð äëÿ ðàñ÷åòà íîâûõ áàðîâ
   to_copy=limit+1+int(RPeriod);
//---- êîïèðóåì âíîâü ïîÿâèâøèåñÿ äàííûå â ìàññèâû
   if(CopyBuffer(Ind_Handle[0],0,0,to_copy,ExtOpenBuffer)<=0) return(RESET);
   if(CopyBuffer(Ind_Handle[1],0,0,to_copy,ExtHighBuffer)<=0) return(RESET);
   if(CopyBuffer(Ind_Handle[2],0,0,to_copy,ExtLowBuffer)<=0) return(RESET);
   if(CopyBuffer(Ind_Handle[3],0,0,to_copy,ExtCloseBuffer)<=0) return(RESET);
//---- îñíîâíîé öèêë èñïðàâëåíèÿ è îêðàøèâàíèÿ ñâå÷åé
   for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      double Max=MathMax(ExtOpenBuffer[bar],ExtCloseBuffer[bar]);
      double Min=MathMin(ExtOpenBuffer[bar],ExtCloseBuffer[bar]);
      //----
      ExtHighBuffer[bar]=MathMax(Max,ExtHighBuffer[bar]);
      ExtLowBuffer[bar]=MathMin(Min,ExtLowBuffer[bar]);
      //----
      if(ExtOpenBuffer[bar]<ExtCloseBuffer[bar]) ExtColorBuffer[bar]=2.0;
      else if(ExtOpenBuffer[bar]>ExtCloseBuffer[bar]) ExtColorBuffer[bar]=0.0;
      else ExtColorBuffer[bar]=1.0;
     }
//---- îñíîâíîé öèêë ðàñ÷åòà èíäèêàòîðà
   for(bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      d_max=ExtHighBuffer[ArrayMaximum(ExtHighBuffer,bar,RPeriod)];
      d_min=ExtLowBuffer[ArrayMinimum(ExtLowBuffer,bar,RPeriod)];
      UpIndBuffer[bar]=XMA1.XMASeries(maxbar,prev_calculated,rates_total,SmMA_Method,SPhase,SLength,d_max,bar,true);
      DnIndBuffer[bar]=XMA2.XMASeries(maxbar,prev_calculated,rates_total,SmMA_Method,SPhase,SLength,d_min,bar,true);
     }
//----     
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments