# mfe & mae calculation

206

Hi,

I like to get candles highs & lows to calculate mfe&mae. I have written a script wich is getiing trade infos from history after magic number and symbol. The script is working properly until the code arrives to get the candle highs&lows.

Here is the code, I have a problem with

`for ...`

I am printing out the variables and I see difference between counter2 and bar_number[0]. In the bar_number array are the closed trades bar numbers wich I get from the closed trades opening time with iBarShift.

```counter1=1;
bar_high=0; //I give value to get later the max high and min low.
bar_low=1000;
for (counter2=bar_number[0]; counter2 >= 0; counter2--)
{
Print(bar_szam[0]); // I get problem here, counter2 is not equal with bar_number[0] as in for operator needed.
Print(counter2);
//    Print(b_l);
if (b_h>bar_high) bar_high=b_h;  // here I try the find the max bar high & low
if (b_l<bar_low) bar_low=b_l;
if (counter2!=bar_number[counter1]) {    // if I reach the bar of the next opened trade, the code try to write out the datas
continue;
}
else {
Print(counter2+"  "+bar_szam[counter1]);
if (long_short[counter1]==0) {
bar_high=0;
}
if (long_short[counter1]==1) {
bar_low=1000;
}
Print("counter1:  ",IntegerToString(counter1,0));
counter1++;
}

//     if (counter1==array_counter1) {break;}

}
FileClose(filehandle);
```

Maybe in the code are more failure, I don't know coz the script is stoping work properly after for operator.

Cheers
Gabor

16096

1. You have the trade's OrderOpenTime and OrderCloseTime.
2. Use iBarShift to find the chart's indexes.
3. Use iHighest, iLowest to find the index of the most extreme bar in the timeframe.
4. Get the price.
Note if the extreme occurred on the starting/ending bar, it could have been before/after the order.
206

WHRoeder:
1. You have the trade's OrderOpenTime and OrderCloseTime.
2. Use iBarShift to find the chart's indexes.
3. Use iHighest, iLowest to find the index of the most extreme bar in the timeframe.
4. Get the price.
Note if the extreme occurred on the starting/ending bar, it could have been before/after the order.
WhRoeder, thanks!!! The iHighest & iLowest has escaped my notice.
16096