//+------------------------------------------------------------------+ //| Copyright © 2012, Ivan Kornilov| //| MaChannel.mq4| //+------------------------------------------------------------------+ #property copyright "Copyright © 2012, Ivan Kornilov. All rights reserved." #property link "excelf@gmail.com" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red extern int ma = 12; extern int shift = 600; extern int maType = 0; extern bool oneWay = true; double lineGreen[]; double lineRed[]; double up[]; double down[]; double trand[]; //#include //#include //#include //#include int init() { IndicatorBuffers(5); SetIndexBuffer(0, lineGreen); SetIndexBuffer(1, lineRed); SetIndexBuffer(2, up); SetIndexBuffer(3, down); SetIndexBuffer(4, trand); SetIndexStyle(0, DRAW_LINE, EMPTY, 1); SetIndexStyle(1, DRAW_LINE, EMPTY, 1); //objects.initArrawObjects(); if(Digits == 4) { shift = shift / 10; } } int deinit() { //objects.deinitArrawObjects(); } int start() { int indicatorCounted = IndicatorCounted(); if (indicatorCounted < 0) { return (-1); } if (indicatorCounted > 0) { indicatorCounted--; } int limit = Bars - indicatorCounted -1; for (int i = limit - 1; i >= 0; i--) { trand[i] = trand[i + 1]; up[i] = iMA(NULL, 0, ma, 0, maType, PRICE_HIGH, i + 1) + shift * Point; down[i] = iMA(NULL, 0, ma, 0, maType, PRICE_LOW, i + 1) - shift * Point; if(oneWay) { if(trand[i+1] == 1) { if(down[i] < down[i+1] && down[i+1] != EMPTY_VALUE) { down[i] = down[i+1]; } } else if(trand[i+1] == -1){ if(up[i] > up[i+1] && up[i+1] != EMPTY_VALUE) { up[i] = up[i+1]; } } } if (High[i] > up[i]) { trand[i] = 1; } else if (Low[i] < down[i]) { trand[i] = -1; } if (trand[i] == -1.0) { lineRed[i] = up[i]; lineGreen[i] = EMPTY_VALUE; } else if(trand[i] == 1.0) { lineGreen[i] = down[i]; lineRed[i] = EMPTY_VALUE; } } }