Chart Window

Author: Copyright 2020, Danil Makov.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each barSeries array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains open prices of each bar
0 Views
0 Downloads
0 Favorites
Chart Window
//+------------------------------------------------------------------+
//|                                                 Chart Window.mq4 |
//|                                     Copyright 2020, Danil Makov. |
//|                                       https://vk.com/danil_makov |
//+------------------------------------------------------------------+
#property copyright   "Copyright 2020, Danil Makov."
#property link        "https://vk.com/danil_makov"
#property version     "1.00"
#property description "Chart Window"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   4
//--- plot Close
#property indicator_label1  "Close"
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  clrRoyalBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  3
//--- plot Open
#property indicator_label2  "Open"
#property indicator_type2   DRAW_HISTOGRAM
#property indicator_color2  clrOrangeRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  3
//--- plot HighLow
#property indicator_label3  "High / Low"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  clrRoyalBlue
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- plot LowHigh
#property indicator_label4  "Low / High"
#property indicator_type4   DRAW_HISTOGRAM
#property indicator_color4  clrOrangeRed
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1
//--- input parameters
input string symbol = "EURUSD";          // Symbol
input int    period = 100;               // Period
//--- indicator buffers
double       CloseBuffer[];
double       OpenBuffer[];
double       HighLowBuffer[];
double       LowHighBuffer[];
//--- global variables
double       main_max,main_min,main_avg; // max, min, avg. (main)
double       corr_max,corr_min,corr_avg; // max, min, avg. (corr.)
double       high,low,scale;             // high, low, symbol scale.
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //---
   IndicatorDigits(Digits);
   IndicatorShortName("Chart Window: "+symbol);
   //--- indicator buffers mapping
   SetIndexBuffer(0,CloseBuffer);
   SetIndexBuffer(1,OpenBuffer);
   SetIndexBuffer(2,HighLowBuffer);
   SetIndexBuffer(3,LowHighBuffer);
   //--- 0 value will not be displayed
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   //---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //--- initialization of the buffers
   ArrayInitialize(CloseBuffer,0.0);
   ArrayInitialize(OpenBuffer,0.0);
   ArrayInitialize(HighLowBuffer,0.0);
   ArrayInitialize(LowHighBuffer,0.0);
   //--- start bar
   int bar=WindowFirstVisibleBar()-WindowBarsPerChart();
   if(bar<0)bar=0;
   //--- local maximum, local minimum, average
   main_max=High[iHighest(NULL,0,MODE_HIGH,period,bar)];
   main_min=Low[iLowest(NULL,0,MODE_LOW,period,bar)];
   main_avg=(main_max+main_min)/2;
   //---
   corr_max=iHigh(symbol,0,iHighest(symbol,0,MODE_HIGH,period,bar));
   corr_min=iLow(symbol,0,iLowest(symbol,0,MODE_LOW,period,bar));
   corr_avg=(corr_max+corr_min)/2;
   //--- drawing candles
   for(int i=bar; i<=bar+period; i++)
     {
      //--- scale calculation
      high=0.0; low=0.0; scale=0.0;
      while((high-low)<(iHigh(symbol,0,i)-iLow(symbol,0,i)))
        {
         high=(iHigh(symbol,0,i)-corr_avg)*scale+main_avg;
         low=(iLow(symbol,0,i)-corr_avg)*scale+main_avg;
         scale+=0.01;
        }
      //--- high & low
      if(iClose(symbol,0,i)>iOpen(symbol,0,i)) // bulls
        {
         HighLowBuffer[i]=(iHigh(symbol,0,i)-corr_avg)*scale+main_avg;
         LowHighBuffer[i]=(iLow(symbol,0,i)-corr_avg)*scale+main_avg;
        }
      else                                     // bears
        {
         HighLowBuffer[i]=(iLow(symbol,0,i)-corr_avg)*scale+main_avg;
         LowHighBuffer[i]=(iHigh(symbol,0,i)-corr_avg)*scale+main_avg;
        }
      //--- close & open
      CloseBuffer[i]=(iClose(symbol,0,i)-corr_avg)*scale+main_avg;
      OpenBuffer[i]=(iOpen(symbol,0,i)-corr_avg)*scale+main_avg;
     }
   //---
   return(NULL);
  }
//+------------------------------------------------------------------+

Comments