Navigation´╝ÜHome > Content >

Trend_flat.mq4

Time: 2016-06-06 | Download file:Trend_flat.mq4

#property copyright "IgorM"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Yellow

extern int Normalize   = 3;
extern int period = 20;
extern int method = 1;
extern int price = 0;
double Up[];
double Dn[];
double Horizontal[];
double buf[];

int init() {
   IndicatorBuffers(4);
   SetIndexBuffer(0, Up);
   SetIndexBuffer(1, Dn);
   SetIndexBuffer(2, Horizontal);
   SetIndexBuffer(3, buf);
   ArraySetAsSeries(buf, TRUE);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 2);
   IndicatorShortName("Trend Line(" + period + ")");
   return (0);
}

int deinit() {
   return (0);
}


int start() {
   double buf_1[];
   double buf_2[];
   int counted = IndicatorCounted();
   if (counted < 0) return (-1);
   int i = 0;
   int sqrperiod = MathSqrt(period);
   int count = Bars - counted + period + 1;
   if (count > Bars) count = Bars;
   ArrayResize(buf_1, count);
   ArraySetAsSeries(buf_1, TRUE);
   ArrayResize(buf_2, count);
   ArraySetAsSeries(buf_2, TRUE);
   for (i = 0; i < count; i++) 
      buf_1[i] = 2.0 * iMA(NULL, 0, period / 2, 0, method, price, i)- iMA(NULL, 0, period, 0, method, price, i);
   
   for (i = 0; i < count - period; i++) buf[i] =NormalizeDouble( iMAOnArray(buf_1, 0, sqrperiod, 0, method, i),Normalize);
   for (i = count - period; i >= 0; i--) {
      buf_2[i] = buf_2[i + 1];
      if (buf[i] > buf[i + 1])  buf_2[i] = 1;
      if (buf[i] < buf[i + 1])  buf_2[i] = -1;
      if (buf[i] == buf[i + 1]) buf_2[i] = 0.0;
      if (buf_2[i] > 0.0) {
            Up[i] = buf[i];
            if (buf_2[i + 1] < 0.0) Up[i + 1] = buf[i + 1];
            Dn[i] = EMPTY_VALUE;
            Horizontal[i] = EMPTY_VALUE;
         } 
      
      if (buf_2[i] < 0.0) {
            Dn[i] = buf[i];
            if (buf_2[i + 1] > 0.0) Dn[i + 1] = buf[i + 1];
            Up[i] = EMPTY_VALUE;
            Horizontal[i] = EMPTY_VALUE;
         }
         
      if (buf_2[i] == 0.0) {
            Horizontal[i] = buf[i];
            Up[i] = buf[i];
            Dn[i] = buf[i];
         }
      
      }
 return (0);
}

Recommend