This is one of those problems that seems more complex than it actually is.
For a start, you only need to look in four directions for the whole thing, Up/Right, right, Down/Right and Down. All other directions are just duplicates of those four.
The first step is to find the first cell of the five and for this you don't need to check the entire grid.
Suppose your grid is 10 x 10;
5 in a row horizontally or diagonally must have room for four more to the right of it, so MUST start in the left most six columns.
Similarly 5 in a row vertically or diagonally down and right MUST start in the top six rows.
Diagonally up and right MUST start in the bottom six rows and the left six columns
For each X in these locations you do a loop counting from 1 to 4 and check the cells offset by that amount, if any do not contain an X, move onto the next start point.
If all four match you have the five.
So for example, if you have an X at position 2,3, firstly set a flag to assume a match, then if one fails, clear that flag;
Here's some sample code to check for diagonal down and right, assuming you have found an "x" at x=2, y=3
x = 2
y = 3
matchDownRight = 1
for i=1 to 4
if cell[ x + i , y + i] <> "x"
matchDownRight = 0
exit
endif
next i
If you get to the end of the loop and "matchDownRight" is still 1, then you have your five.
Do a similar loop for other directions.