Calculating the highest (or lowest) Bid during the most recently closed order - Asking for code help please

 
Hello all:

Would anyone kindly provide me with a code snippet to meet my objective of determining retroactively what the highest (or lowest) Bid was during the time period that the most recently closed order was active? To explain more easily (since I am obviously still learning), let me put it this way:
--I had an open long
--I closed that open long
--I want to know what was the HIGHEST Bid during the entire time that my long position was open.
CONVERSELY:
--I had an open short
--I closed that open short
--I want to know what was the LOWEST Bid during the entire time that my short position was open.

I currently have a piece of code sitting at the end of my EA that allows me to begin the EA by querying the history to find out how the last trade closed. Using this code, I can easily find out if the most recent order that closed was a closing of a buy order, or closing of a sell order. Can I somehow use this existing code snippet to help me to obtain this new information I seek? If so, how? If not, can anyone provide me with code snippet for finding the low or high as described above?

Thanks,
Andre

AT THE TOP OF MY EA, I HAVE THIS:
//--------------------------------------------------
 if(ticket!=-1)
     {
     if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY))
        {
        if ( OrderType() == OP_SELL )
//------in this case, if the order that just closed was a sell, then
//------I am going to do something different than if it were a buy
//------This opening code works because of the end code:

THIS SITS AT THE END OF MY EA (and works!)
/--------------------------------------------------
int SelectOldestClosed()
   {
   int ticket=-1;
   datetime oldestOrderTime=-1;
   for(int ii=OrdersHistoryTotal()-1;ii>0;ii--)
      {
      if(!OrderSelect(ii,SELECT_BY_POS,MODE_HISTORY))
         {
         Alert("SelectOldestClosed: OrderSelect failed - ",ErrorDescription(GetLastError()));
         return(-1);
         }
      else
         {
         if(OrderSymbol()==Symbol())
            {
            if(oldestOrderTime==-1 || OrderCloseTime()>oldestOrderTime)
               {
               oldestOrderTime=OrderCloseTime();
               ticket=OrderTicket();
               }
            }
         }        
      }
   return(ticket);
   }
//+------------------------------------------------------------------+
 

After you have selected the order, you need to define the opening and closing bars:

int CloseBar=iBarShift(NULL,0,OrderCloseTime(),false);
int OpenBar=iBarShift(NULL,0,OrderOpenTime(),false);

This defines the range of bars over which you then want to identify the lowest and highest.

int HighestBar=iHighest(NULL,0,MODE_HIGH,OpenBar-CloseBar+1,CloseBar);
int LowestBar=iLowest(NULL,0,MODE_LOW,OpenBar-CloseBar+1,CloseBar);

Now it is simple matter of defining the lowest and highest bids:

double lowestbid=iLow(NULL,0,LowestBar);
double highestbid=iHigh(NULL,0,HighestBar);

Caveats here are that in the event that the lowest bid or highest bid happen to occur in either the same candle in which the the trade opened or closed then it is possible that the lowest-bid or highest-bid computed above occurred before the trade was opened (but within the same candle) or after the trade closed (also within the same candle).

Also note there are simpler ways of expressing these equations, these are the ones I happen to use for consistency in my more generalized currency-pair agnostic codes.