BolliTrigger





//+------------------------------------------------------------------+
//|                                           BolliTrigger.mq4       |
//|                      Copyright © 2005, DragonBonz Software       |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, DragonBonz Software"
//#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Blue
#property indicator_color4 Green

extern int     BollBandMovAvgPrd=13;
extern int     BollBandMovAvgShift=0;
extern int     BollBandMovAvgMethod=0;
extern double  BollBandStdDev=2.0;
//
// set default values of horizonatal lines to Fib ratios
//
extern double  TriggerLine    = 0.236;
extern double  AddLine        = 0.382;
extern double  ProfitLine     = 0.5;
//
// Trigger weights for bandwidth and %B
//
extern int     Bandwidth_Const = 110;
extern int     PercentB_Const = 13;

double  bbBandWidth;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- additional buffers are used for counting
   IndicatorBuffers(5);
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,ExtMapBuffer4);
 
   SetIndexDrawBegin( 2, BollBandMovAvgPrd );
   
   IndicatorShortName("Bolli Trigger");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int    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--;
   limit=Bars-counted_bars;
//---- 

   for(int i=0; i < limit; i++)
   {
      //
      // calculate Bollinger Moving Average and upper and lower bands
      //	   
      double ma     = iMA(NULL,0,BollBandMovAvgPrd,BollBandMovAvgShift,BollBandMovAvgMethod,PRICE_CLOSE,i);
      double up     = iBands( NULL,0,BollBandMovAvgPrd,BollBandStdDev,0,PRICE_CLOSE,MODE_UPPER,i);
	   double low    = iBands( NULL,0,BollBandMovAvgPrd,BollBandStdDev,0,PRICE_CLOSE,MODE_LOWER,i); 
	   
	   double r = up - low; // range 
	   double perB  	= 0;  // default value for %B
	   
	   if( r > 0 )
	     perB = (Close[i] - low)/r;
	     	
	   if( ma > 0 )
	     bbBandWidth = r/ma;
	   else
	     bbBandWidth = 0;
	     	   
      ExtMapBuffer1[i]  = TriggerLine;
	   ExtMapBuffer2[i] 	= AddLine;
	   ExtMapBuffer3[i] 	= ProfitLine;
      //
      // signal line
      //
      // this line is the weighted sum of bandwidth and a modified %B
      //
      // bandwidth gives us a relative size of bollinger bands. 
      //    Increasing Bandwidth_Const will smooth out signal, decreasing Bandwidth_Const makes 
      //    it more volatile 
      //
      // %B gives us a value of 1.0 at upperband, 0.5 at middle( moving avg ), and  0.0 at lower band
      //    we take the absolute value of 0.5 - %B to get a value that ranges from 0 to 1.0+
      //    this gives us a boost as bolli bands expand and can be used to speed or slow down
      //    the trigger by decreasing PercentB_Const to speed up( since it on bottom, it gives a
      //    greater weight when decreased), or increase PercentB_Const to slow down
      ExtMapBuffer4[i] =  ( bbBandWidth*Bandwidth_Const ) +  MathAbs((0.5-perB)/PercentB_Const);
	    	    
   }   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample



image not available


Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

Moving average indicator
Bollinger bands indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: