Donchian Channel Width

Author:
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Donchian Channel Width
ÿþ//+------------------------------------------------------------------+

//|                                       Donchian Channel Width.mq4 |

//|                                                                  |

//|                                                                  |

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

#property copyright ""

#property link      "https://www.mql5.com/"

#property version   "1.00"

#property strict

#property indicator_separate_window



#property indicator_buffers 1

#property indicator_plots   1

#property indicator_type1   DRAW_LINE

#property indicator_color1  Aqua



input int InpPeriod=40;// Period

input bool InpExpandAlert=false; //ExpandAlert



double    WidthBuffer[];

string IndiName="Donchian Channel Width";

int lastAlertBars=0;



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

//| Custom indicator initialization function                         |

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

int OnInit()

  {



   SetIndexBuffer(0,WidthBuffer,INDICATOR_DATA);



   IndicatorSetString(INDICATOR_SHORTNAME,IndiName+"("+string(InpPeriod)+")");



   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);



   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);



   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

   int    limit,shift;



   if(prev_calculated < 0) return(0);



   if(prev_calculated==0)

     {

      limit=rates_total-1;

     }else if(prev_calculated==rates_total){

      limit=1;

     }else{

      limit=rates_total-prev_calculated-1;

     }



//--------------

   for(shift=limit; shift>=0 && !IsStopped(); shift--)

     {

      WidthBuffer[shift]=high[iHighest(_Symbol,_Period,MODE_HIGH,InpPeriod,shift)]-low[iLowest(_Symbol,_Period,MODE_LOW,InpPeriod,shift)];

     }



   if(InpExpandAlert && lastAlertBars!=rates_total)

     {

      if(WidthBuffer[0]>WidthBuffer[1] && WidthBuffer[1]<=WidthBuffer[2])

        {

         Alert("M"+string(_Period)+" "+IndiName+"("+string(InpPeriod)+"):","Expand");

         lastAlertBars=rates_total;

        }

     }



   return(rates_total);

  }

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

Comments