Using winning/losing position analysis you can tell that the correct move is to take:
You can work this out iteratively.
If you have 1 coin and it is your turn you will obviously lose. Thus 1 is a losing condition.
We can then create a set of winning conditions:
2-6 coins are all winning positions. The reason being that you can take as many coins as are needed to leave one coin left which is then a losing position for your opponent and thus a winning position for you.
You can then use that to work out more losing conditions.
7 coins is a losing position because no matter how many coins you take away you are left with somewhere between 2 and 6 coins, inclusive. Thus leaving your opponent with a winning position and thus you lose.
You can then extend this logic to create an formula to allow you to work out what positions are winning and what are losing. Then for any position you know that you just take coins to leave your opponent with one of the losing positions.
The losing positions are when there are 1+6n coins remaining (where n is a non-negative integer). This can be shown by the same logic as already used. It can also be verified by considering that if you are at 1+6n coins then if you take m coins then your opponent can take 6-m coins and your new position is still of the form 1+6n meaning you are still in a losing position. And of course any other position is a winning position you will have 1+6n+k coins where k is between 1 and 5 (inclusive). You thus just take k coins, leaving your opponent with a losing position.
So for this particular problem:
You have 1+6(1)+4 coins to start with, thus you take 4.