// See: http://forum.mql4.com/49780
void CalculateSupRes() {
int commonPoint;
int minLevel, maxLevel;
double highest, lowest, stepIncrement, tolerance, high;
double storeLevel[];
///ArrayResize(storeLevel, loopback);
minLevel = iLowest(Symbol(), Period(), MODE_LOW, loopback, 0);
maxLevel = iHighest(Symbol(), Period(), MODE_HIGH, loopback, 0);
highest = iHigh(Symbol(), Period(), maxLevel);
lowest = iLow(Symbol(), Period(), minLevel);
//Print("max: " + highest + " min: " + lowest);
stepIncrement = 0.0005;
tolerance = 0.0002;
static double tmp;
tmp = 0.0;
for (double actPrice = lowest; actPrice <= highest; actPrice += stepIncrement) {
for (int i = 1; i <= loopback; i++) {
//do some stuff here...
high = iHigh(Symbol(), Period(), i);
double topRange, bottomRange;
// if is the first value tmp stores the first high encountered until that moment
if (tmp == 0) {
tmp = high;
} else {
//define a buffer adding a subtracting from tmp to check if the new high is within that value
topRange = tmp + tolerance;
bottomRange = tmp - tolerance;
if (high <= topRange && high >= bottomRange) {
commonPoint++;
}
}
//if has been touched at least three times reset common point
//tmp goes to the new high value to keep looping
if (commonPoint == 3) {
commonPoint = 0;
tmp = high;
///Print("valore tmp: " + tmp);
storeLevel[i] = tmp;
}
}
}
}