//+------------------------------------------------------------------+
// GoldMiner-Histo.mq4
// Based on goldminer aka silvertrend aka 
// Limited the number of recalculated bars
//+------------------------------------------------------------------+
// Indicator properties
#property copyright "©"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 RoyalBlue
#property indicator_color2 Crimson
#property indicator_width1  4
#property indicator_width2  4
#property indicator_maximum 1
#property indicator_minimum 0

// indicator parameters
extern int       SSP=7;
extern double    KMax=50.6;

// Histogram buffers
double hs_up_buf[];
double hs_dn_buf[];
// Goldminer buffers
double gm_up_buf[];
double gm_dn_buf[];

//+------------------------------------------------------------------+
int init() {
  IndicatorBuffers(4);
  SetIndexStyle(0,DRAW_HISTOGRAM);
  SetIndexBuffer(0,hs_up_buf);
  SetIndexLabel(0,NULL);
  SetIndexStyle(1,DRAW_HISTOGRAM);
  SetIndexBuffer(1,hs_dn_buf);
  SetIndexLabel(1,NULL);
  SetIndexStyle(2,DRAW_NONE);
  SetIndexBuffer(2,gm_up_buf);
  SetIndexLabel(2,NULL);
  SetIndexStyle(3,DRAW_NONE);
  SetIndexBuffer(3,gm_dn_buf);
  SetIndexLabel(3,NULL);
  IndicatorShortName("GoldMiner");
  return(0);
}

//+------------------------------------------------------------------+
int deinit() {
   return (0);
}


//+------------------------------------------------------------------+
int start() {
  int limit;
  int counted_bars; 
  int i;
  double ss_max, ss_min, s_max;
  
  // Get unprocessed ticks
  counted_bars=IndicatorCounted();
  if(counted_bars < 0) return (-1); 
  if(counted_bars>0) counted_bars--;
  limit=MathMax(Bars-counted_bars,SSP*4);
  
  for(i=limit;i>=0;i--) { 
    ss_max = iHigh(Symbol(),0,iHighest(NULL,0,MODE_HIGH,SSP,i-SSP+1)); 
    ss_min = iLow(Symbol(),0,iLowest(NULL,0,MODE_LOW,SSP,i-SSP+1)); 
    s_max = ss_max-(ss_max-ss_min)*KMax/100;
    gm_up_buf[i-SSP+6]=s_max;
    gm_dn_buf[i-SSP-1]=s_max;
    
    if (ss_max==0 || ss_min==0) {
      hs_dn_buf[i]=EMPTY_VALUE;
      hs_dn_buf[i]=EMPTY_VALUE;
    }
    else if (gm_up_buf[i]>=gm_dn_buf[i]) {
      hs_up_buf[i]=1;
      hs_dn_buf[i]=0;
    }
    else { 
      hs_dn_buf[i]=1;
      hs_up_buf[i]=0;
    }
  } 
  
  return(0);
}
//+------------------------------------------------------------------+



