//+------------------------------------------------------------------+
//|                                                  ValueCharts.mq4 |
//|                                       Copyright © 2009, NsTrader |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, NsTrader"
#property link      ""

#property indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  Green
#property  indicator_color2  Green
#property  indicator_color3  Yellow
#property  indicator_color5  Black
#property  indicator_color6  Black

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width5 1
#property indicator_width6 1

#property indicator_level1 0.0
#property indicator_level2 1.0
#property indicator_level3 -1.0
#property indicator_level4 2.0
#property indicator_level5 -2.0

double   HBuffer[];
double   LBuffer[];
double   CBuffer[];
double   OBuffer[];
double   HBuffern[];
double   LBuffern[];

double   Avg[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
IndicatorBuffers(7);

IndicatorShortName("Value Charts (H,L,C,O)");



SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,HBuffer);
SetIndexLabel(0,"High");

SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,LBuffer);
SetIndexLabel(1,"Low");

SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,CBuffer);
SetIndexLabel(2,"Close");

SetIndexStyle(3,DRAW_NONE);
SetIndexBuffer(3,OBuffer);
SetIndexLabel(3,"Open");

SetIndexStyle(4,DRAW_HISTOGRAM);
SetIndexBuffer(4,HBuffern);
SetIndexLabel(4,NULL);

SetIndexStyle(5,DRAW_HISTOGRAM);
SetIndexBuffer(5,LBuffern);
SetIndexLabel(5,NULL);

SetIndexStyle(6,DRAW_NONE);
SetIndexBuffer(6,Avg);
SetIndexLabel(6,NULL);



//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i,limit, counted_bars=IndicatorCounted();
//----
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//---- 
if(counted_bars<1) i=Bars-1;
else i=Bars-counted_bars;
//---- 
while (i >= 0)
{
   Avg[i] = High[i]-Low[i];
   i--;
}
//---- 
if(counted_bars<1) i=Bars-5-1;
else i=Bars-counted_bars;
//---- 
while (i >= 0)
{
   double MA = iMA(Symbol(),0,5,0,MODE_SMA,PRICE_MEDIAN,i);
   double VFactor = iMAOnArray(Avg,0,5,0,MODE_SMA,i);
   if(VFactor != 0)
   {
      OBuffer[i] = (Open[i]-MA)/VFactor;
      CBuffer[i] = (Close[i]-MA)/VFactor;
      HBuffer[i] = (High[i]-MA)/VFactor;
      LBuffer[i] = (Low[i]-MA)/VFactor;
      
      if(HBuffer[i] < 0) HBuffern[i] = HBuffer[i];//oculta histograma
      if(LBuffer[i] > 0) LBuffern[i] = LBuffer[i];//oculta histograma
   }
   else
   {
      OBuffer[i] = 0;
      CBuffer[i] = 0;
      HBuffer[i] = 0;
      LBuffer[i] = 0;
      HBuffern[i] = 0;
      LBuffern[i] = 0;
   }
   i--;
}
//----
   return(0);
  }
//+------------------------------------------------------------------+