Yup.
Actually the best way to debug a function is to convert the function to a macro like this (in a separate rough workbook) and then use F8 to run it line by line.
Sub CountIfMax
Set MyRange = Range("B2:F2")
n=2
Dim i As Integer
Dim cell As Range

i = ActiveCell.Row

For Each cell In Myrange

    Max = Application.Max(Range(Cells(i - n, cell.Column), Cells(i + n, cell.Column)))
    actcell = Cells(i, cell.Column)

    If actcell = Max Then
        CountIfMax = CountIfMax + 1
    End If

    
Next cell

End Sub