//+------------------------------------------------------------------+
//| HHLL.mq4 |
//+------------------------------------------------------------------+
#property copyright "wfy05@talkforex.com"
#property link "www.talkforex.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#define BUFFER_HIGH 0
#define BUFFER_LOW 1
#define BUFFER_HIGH_ARROW 2
#define BUFFER_LOW_ARROW 3
//---- indicator parameters
extern int nBars = 10;
extern bool ShowAllLine = false;
extern bool ShowArrow = true;
//---- indicator buffers
//high buffers
double MapBufferHigh[];
//low buffers;
double MapBufferLow[];
//high arrow buffers
double MapBufferHighArrow[];
//low arrow buffers;
double MapBufferLowArrow[];
//----
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
int draw_begin;
string short_name;
draw_begin=nBars-1;
short_name = "HHLL(";
IndicatorShortName(short_name+nBars+")");
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- drawing settings
for (int i=0; i < 4; i++) {
SetIndexStyle(i,DRAW_LINE);
SetIndexShift(i,0);
SetIndexDrawBegin(i,draw_begin);
}
//---- indicator buffers mapping
SetIndexBuffer(BUFFER_HIGH,MapBufferHigh);
SetIndexBuffer(BUFFER_LOW,MapBufferLow);
SetIndexBuffer(BUFFER_HIGH_ARROW,MapBufferHighArrow);
SetIndexBuffer(BUFFER_LOW_ARROW,MapBufferLowArrow);
SetIndexStyle(BUFFER_HIGH_ARROW,DRAW_ARROW);
SetIndexStyle(BUFFER_LOW_ARROW,DRAW_ARROW);
SetIndexArrow(BUFFER_HIGH_ARROW,SYMBOL_ARROWDOWN);
SetIndexArrow(BUFFER_LOW_ARROW,SYMBOL_ARROWUP);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int ExtCountedBars;
if(Bars<=nBars) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
//----
int i,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
if(pos<nBars) pos=nBars;
pos -= nBars;
//---- main calculation loop
int h, l;
h = Bars;
l = Bars;
static bool show_h = false, show_l = false;
string name;
while(pos>=0)
{
MapBufferHigh[pos]=High[Highest(NULL, 0, MODE_HIGH, nBars, pos)];
MapBufferLow[pos]=Low[Lowest(NULL, 0, MODE_LOW, nBars, pos)];
if (!ShowAllLine) {
for (i = pos+nBars; i < Bars; i++) {
if (Close
> MapBufferHigh[pos]) {
h = i;
break;
}
}
for (i = pos+nBars; i < Bars; i++) {
if (Close < MapBufferLow[pos]) {
l = i;
break;
}
}
MapBufferHighArrow[pos] = EMPTY_VALUE;
MapBufferLowArrow[pos] = EMPTY_VALUE;
if (h>l) {
//l is closer than h, hide high line
MapBufferHigh[pos] = EMPTY_VALUE;
if (show_l == false) {
show_l = true;
if (ShowArrow) MapBufferLowArrow[pos] = MapBufferLow[pos];
}
show_h = false;
} else if (h<l) {
//h is closer than l, hide low line
MapBufferLow[pos] = EMPTY_VALUE;
if (show_h == false) {
show_h = true;
if (ShowArrow) MapBufferHighArrow[pos] = MapBufferHigh[pos];
}
show_l = false;
} else {
//h equals to l
MapBufferHigh[pos] = EMPTY_VALUE;
MapBufferLow[pos] = EMPTY_VALUE;
show_h = false;
show_l = false;
}
}
pos--;
}
if(ExtCountedBars<1) {
for(i=1;i<nBars;i++) {
MapBufferHigh[Bars-i]=EMPTY_VALUE;
MapBufferLow[Bars-i]=EMPTY_VALUE;
MapBufferHighArrow[Bars-i]=EMPTY_VALUE;
MapBufferLowArrow[Bars-i]=EMPTY_VALUE;
}
}
//---- done
return(0);
}