Navigation:Home > Content >

Keltner_Channels_1.mq4

Time: 2017-05-28 | Download file:Keltner_Channels_1.mq4

#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 White
#property indicator_color4 Red
#property indicator_color5 Yellow

double g_ibuf_76[];
double g_ibuf_80[];
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
extern int period = 10;
extern double fib = 2.61;

int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexShift(0, 0);
   SetIndexDrawBegin(0, 0);
   SetIndexBuffer(0, g_ibuf_76);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexShift(1, 0);
   SetIndexDrawBegin(1, 0);
   SetIndexBuffer(1, g_ibuf_80);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexShift(2, 0);
   SetIndexDrawBegin(2, 0);
   SetIndexBuffer(2, g_ibuf_84);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexShift(3, 0);
   SetIndexDrawBegin(3, 0);
   SetIndexBuffer(3, g_ibuf_88);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexShift(4, 0);
   SetIndexDrawBegin(4, 0);
   SetIndexBuffer(4, g_ibuf_92);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double ld_0;
   int li_8 = IndicatorCounted();
   if (li_8 < 0) return (-1);
   if (li_8 > 0) li_8--;
   int li_12 = Bars - li_8;
   for (int li_16 = 0; li_16 < li_12; li_16++) {
      g_ibuf_80[li_16] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_MEDIAN, li_16);
      ld_0 = findAvg(period, li_16);
      g_ibuf_76[li_16] = g_ibuf_80[li_16] + ld_0;
      g_ibuf_84[li_16] = g_ibuf_80[li_16] - ld_0;
      g_ibuf_88[li_16] = g_ibuf_80[li_16] + ld_0 * fib;
      g_ibuf_92[li_16] = g_ibuf_80[li_16] - ld_0 * fib;
   }
   return (0);
}

double findAvg(int ai_0, int ai_4) {
   double ld_ret_8 = 0;
   for (int li_16 = ai_4; li_16 < ai_4 + ai_0; li_16++) ld_ret_8 += MathMax(High[li_16], Close[li_16 + 1]) - MathMin(Low[li_16], Close[li_16 + 1]);
   ld_ret_8 /= ai_0;
   return (ld_ret_8);
}

Recommend