Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 is an object-oriented language?
Gabor Keresztessy
201
Gabor Keresztessy 2015.07.06 20:44 

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;
   Alert(bar_number[0]);
   for (counter2=bar_number[0]; counter2 >= 0; counter2--)
      {
      b_h=iHigh(szimbolum,trade_tf,counter2);
      Print(bar_szam[0]); // I get problem here, counter2 is not equal with bar_number[0] as in for operator needed.
      Print(counter2);
      b_l=iLow(szimbolum,trade_tf,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) {
            adatok=TimeToString(trade_open_time[counter1],TIME_DATE|TIME_MINUTES)+"   max pip:"+DoubleToStr((bar_high-open_price[counter1]),5);
            bar_high=0;
            }
         if (long_short[counter1]==1) {
            adatok=TimeToString(trade_open_time[counter1],TIME_DATE|TIME_MINUTES)+"   min pip:"+DoubleToStr((open_price[counter1]-bar_low),5);
            bar_low=1000;
            }
         FileWriteString(filehandle,adatok+"\r\n");
         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.

Thanks in advance for help

Cheers
Gabor

whroeder1
13610
whroeder1 2015.07.07 12:19  
  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.
Gabor Keresztessy
201
Gabor Keresztessy 2015.07.07 15:49  
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.
whroeder1
13610
/
To add comments, please log in or register