#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red #property indicator_minimum 0 #property indicator_maximum 1 int maxHistoryBarsToCount = 5000; double DistanceFromThresholdBuffer1[]; double DistanceFromThresholdBuffer2[]; int init() { SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 2); SetIndexBuffer(0, DistanceFromThresholdBuffer1); SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2); SetIndexBuffer(1, DistanceFromThresholdBuffer2); return(0); } int start() { int countedBars = IndicatorCounted(); int countFrom = MathMin(Bars - countedBars - 1, maxHistoryBarsToCount); if (countFrom >= 0 && countFrom < Bars) { countIndicator(countFrom); } return(0); } int countIndicator(int countFrom) { int i; bool isUpSwing; double upSwingLine; double downSwingLine; for (i = countFrom; i >= 0; i--) { isUpSwing = (iCustom(NULL, 0, "Clear", 0, i) > 0); if (isUpSwing) { upSwingLine = iCustom(NULL, 0, "Clear", 1, i); DistanceFromThresholdBuffer1[i] = 1; DistanceFromThresholdBuffer2[i] = 0.0; } else { downSwingLine = iCustom(NULL, 0, "Clear", 2, i); DistanceFromThresholdBuffer1[i] = 0.0; DistanceFromThresholdBuffer2[i] = 1; } } return(0); }