highest price and lowest price only for specified bar range between multiple trades

 

Hi,

I am trying to calculate the highest price and lowest price in the bar range from the bar at which 1st order was opened till the bar at which 'x' order was opened. but i dont know where am i am going wrong. The code seems to be refreshing the highest and lowest prices as new bars open up even after the 'x' order bar. How do i calculate the highest and lowest prices only for the range of 1st order bar to 'x' order bar, and stop calculating after 'x' order bar and just store the value?


Any Suggestions?

double highest_price = 0.0;
double lowest_price = 0.0;
int start_trade = 0;
int end_trade = 8;

void GetHighLowPrices()
//Return High and Low Prices for 8 trades Range
{
    int total_trades = OrdersTotal();
    if(total_trades >= end_trade)
    {
        for(int i = start_trade; i < end_trade; i++)
        {
            if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            int trade_ticket = OrderTicket();
            if(trade_ticket != -1)
            {
                int trade_open_bar = OrderOpenTime();
                
                int bar_index = iBarShift(NULL, 0, trade_open_bar, false);
                double curr_highest = iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, bar_index, 0));
                double curr_lowest = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW, bar_index, 0));
                if(i == start_trade)
                {
                    highest_price = curr_highest;
                    lowest_price = curr_lowest;
                }
                else if(i > start_trade && i <= end_trade)
                {
                    if(highest_price < curr_highest)
                        highest_price = curr_highest;
                    if(lowest_price > curr_lowest)
                        lowest_price = curr_lowest;
                }
            }
        }
    }
}
Reason: