Indikatoren: Donchian Channels

 

Donchian Channels:

Der Donchian Channels ist ein Volatilitäts-Indikator, der auf der Berechnung der aktuellen Kurs-Bandbreite unter Verwendung der letzten Höchst- und Tiefstkurse basiert

Donchian Channels

Autor: Nikolay Kositsin

 

Dieser Indikator arbeitet nur korrekt falls Margin auf 0 eingestellt ist, die Farben sind ungültig, alles obsolete.


Hier eine überarbeitete, code reduzierte, Version. 86 Zeilen anstelle von 232 Zeilen.

//+------------------------------------------------------------------+
//|                                                         DCCH.mq5 |
//|                                Copyright © 2018 Ing. Otto Pauser |
//|                       https://www.mql5.com/de/users/kronenchakra |
//+------------------------------------------------------------------+
#property copyright     "Copyright © 2019 Ing. Otto Pauser"
#property link          "https://www.mql5.com/de/users/kronenchakra"
#property version       "1.0"
#property description   "DCCH - Donchian Channel corrected and simplified"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3

//+------------------------------------------------------------------+
input int   inp_Period     =           20;   // Period
input int   inp_Offset     =            0;   // Offset (points)
input int   inp_Shift      =            0;   // Shift
input int   inp_LineWidth  =            2;   // Linewidth
input color inp_lineColor  = clrSteelBlue;   // Linecolor
//+------------------------------------------------------------------+

double buUpper[];
double buMidle[];
double buLower[];

double upper,lower,offset;
int    first,bar;

//+------------------------------------------------------------------+
void OnInit()
{
   InitBuffer(buUpper,"Donchian Upper");
   InitBuffer(buMidle,"Donchian Center");
   InitBuffer(buLower,"Donchian Lower");
   IndicatorSetString(INDICATOR_SHORTNAME,"Donchian("+IntegerToString(inp_Period)+")");
   offset=inp_Offset*_Point;
}

//+------------------------------------------------------------------+
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[])
{
   if(rates_total<inp_Period+1) return(0);

   first=(prev_calculated==0)?inp_Period:prev_calculated-1;

   for(bar=first; bar<rates_total; bar++)
      {
         upper=high[ArrayMaximum(high,bar-inp_Period+1,inp_Period)];
         lower=low [ArrayMinimum(low ,bar-inp_Period+1,inp_Period)];
         buUpper[bar]=upper+offset;
         buLower[bar]=lower-offset;
         buMidle[bar]=(upper+lower)*0.5;
      }

   return(rates_total);
}

//+------------------------------------------------------------------+
//| could be outsourced to a .mqh                                   |
//+------------------------------------------------------------------+
void InitBuffer(double &buffer[], string plotlabel)
{
   static int bufferindex=0;
   SetIndexBuffer     (bufferindex,buffer,INDICATOR_DATA);

   PlotIndexSetInteger(bufferindex,PLOT_DRAW_TYPE ,DRAW_LINE);
   PlotIndexSetInteger(bufferindex,PLOT_LINE_STYLE,STYLE_SOLID);
   PlotIndexSetInteger(bufferindex,PLOT_LINE_WIDTH,inp_LineWidth);
   PlotIndexSetInteger(bufferindex,PLOT_LINE_COLOR,inp_lineColor);
   PlotIndexSetString (bufferindex,PLOT_LABEL     ,plotlabel);
   PlotIndexSetInteger(bufferindex,PLOT_SHIFT     ,inp_Shift);
   PlotIndexSetInteger(bufferindex,PLOT_DRAW_BEGIN,inp_Period-1);
   PlotIndexSetDouble (bufferindex,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   bufferindex++;
}
Dateien:
DCCH.mq5  7 kb