int shiftMin,shiftMax; double min,max; min = 999999999; max = 0; buy = false; sell = false; for (i = y; i <= y + MeasureBars - 1; i++) { // from right to left if (Low[i] < min) { min = Low[i]; shiftMin = i; } if (High[i] > max) { max = High[i]; shiftMax = i; } if (max - Close[y] >= MeasurePips * PointX) {sell = true; break;} // max comes later -> upward. break because the last trend counts only if (Close[y] - min >= MeasurePips * PointX) {buy = true; break;}