Download MetaTrader 5

Indicators: Min/Max Bands

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
187089
MetaQuotes Software Corp.  

Min/Max Bands:

Indicator showing the Min/Max values for the last X bars

Author: Julien

MQL4 Comments
16319
MQL4 Comments  

Useful Tool. I will put it to good use. Thaks

Bluesky
138
Bluesky  

Quick note... there is a function in MQL4 which I find very useful: "iHighest" it does it automatically and you can re-code your indicator with less system usage.

I Also added the fibo retracement levels to the min/max ... see here:



//+------------------------------------------------------------------+

//| MaxMinBands.mq4 |

//| Copyright © 2005, MetaQuotes Software Corp. |

//| http://www.metaquotes.net/ |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2009, Julien Loutre"

#property link "http://www.zenhop.com"

//---- indicator settings

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 Blue

#property indicator_color2 Blue

#property indicator_color3 Green

#property indicator_color4 Green



extern int Band_Period = 120;



//---- buffers

double WWBuffer1[];

double WWBuffer2[];

double fibo382[];

double fibo618[];


int init() {

IndicatorBuffers(4);

//---- drawing settings

SetIndexStyle(0,DRAW_LINE, 2, 1);

SetIndexStyle(1,DRAW_LINE, 2, 1);

SetIndexStyle(2,DRAW_LINE, 2, 1);

SetIndexStyle(3,DRAW_LINE, 2, 1);

IndicatorDigits(Digits+2);


SetIndexBuffer(0, WWBuffer1);

SetIndexBuffer(1, WWBuffer2);

SetIndexBuffer(2, fibo382);

SetIndexBuffer(3, fibo618);

IndicatorShortName("Min/Max Bands");

return(0);

}

int start() {

int counted_bars=IndicatorCounted();

int limit,i;

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(i=limit-1; i>=0; i--) {


WWBuffer1[i] = High[iHighest(NULL,0,MODE_HIGH,Band_Period,i)];

WWBuffer2[i] = Low[iLowest(NULL,0,MODE_LOW,Band_Period,i)];

fibo382[i] = WWBuffer2[i]+(WWBuffer1[i]-WWBuffer2[i])*0.382;

fibo618[i] = WWBuffer2[i]+(WWBuffer1[i]-WWBuffer2[i])*0.618;

}

return(0);

}

MQL4 Comments
16319
MQL4 Comments  

Thanks. It very useful

fxdevguy123
5
fxdevguy123  

Your code is broken. I fixed it. You had the getPeriodHigh and getPeriodLow code TWICE and had a line that said: }--------------------------+

I do not know if this changed your code any, all I know is that it now lets me attach it to charts and it shows lines like in your picture.




//+------------------------------------------------------------------+

//|                                                  MaxMinBands.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Julien Loutre"
#property link      "http://www.zenhop.com"
//---- indicator settings
#property  indicator_chart_window
#property indicator_buffers  2
#property  indicator_color1  LightSkyBlue
#property  indicator_color2  Plum

//---- input parameters


extern int       Band_Period   = 120;


//---- buffers
double WWBuffer1[];
double WWBuffer2[];

double ATR;

int init() {
   IndicatorBuffers(2);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   IndicatorDigits(Digits+2);

   SetIndexBuffer(0, WWBuffer1);
   SetIndexBuffer(1, WWBuffer2);
   
   IndicatorShortName("Min/Max Bands");
   
   
   return(0);
  }
int start() {
   int    limit,i;
   
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars > 0)   counted_bars--;
   limit = Bars - counted_bars;
   if(counted_bars==0) limit-=1+Band_Period;      
   
   for(i=limit-1; i>=0; i--) {

      WWBuffer1[i] = getPeriodHigh(Band_Period,i);
      WWBuffer2[i] = getPeriodLow(Band_Period,i);
     
   }
   return(0);
}

//--------------------------+
//| getPeriodHigh                                                    |
//+------------------------------------------------------------------+
double getPeriodHigh(int period,int pos)
  {
   int i;
   double buffer=0;
   for(i=pos;i<=pos+period;i++) 
     {
      if(High[i]>buffer) 
        {
         buffer=High[i];
        }
     }
   return (buffer);
  }
//+------------------------------------------------------------------+
//| getPeriodLow                                                     |
//+------------------------------------------------------------------+
double getPeriodLow(int period,int pos) 
  {
   int i;
   double buffer=100000;
   for(i=pos;i<=pos+period;i++) 
     {
      if(Low[i]<buffer) 
        {
         buffer=Low[i];
        }
     }
   return (buffer);
  }
//+------------------------------------------------------------------+

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
MetaTrader 5 trading platform is a free Forex and stock trading tool.
To add comments, please log in or register