How To Filter History Deals Using Position Comment

 

How do do I filter the History Deals using position comment?....Please help fix the code 

int MaxConsecutiveLosses(){

    HistorySelect(0,TimeCurrent());
    
    int max_losses = 0;
    int current_losses = 0;
    
    // Get the total number of closed trades
    int total_trades = HistoryDealsTotal();
    
    for(int i = 0; i < total_trades; i++){
        // Get the ticket number of the trade
        ulong ticket = HistoryDealGetTicket(i);       
        // Get the profit of the trade
        if(HistoryDealGetString(ticket,DEAL_COMMENT) == COMMENT){
           double profit = HistoryDealGetDouble(ticket,DEAL_PROFIT);        
           if(profit < 0){
               // If the trade is a loss, increment the current loss count
               current_losses++;           
               // Update the maximum losses if the current sequence is longer
               if(current_losses > max_losses){
                  max_losses = current_losses;
               }
           }
           else if(profit > 0){
               // If the trade is not a loss, reset the current loss count
               current_losses = 0;
           }
        }
    }
    
    return max_losses;
}