I'm seaarching the literature at the moment to write a literature review but I don't know when should I stop searching and start writing?
The facile answer is you don't stop searching the literature. Even as the review evolves, you should be including new references if they are noteworthy in addressing questions within the field. This process should continue as long as you are working in the field of the problem.
Of course, from a practical standpoint, you do need to select a cutoff. There should be a reasonable point in time in which you've set the outline of the review, and decided on the main topics and questions to be discussed. At that point, it would be fair to set aside adding more references, and stick to what's been published. However, you should continue to monitor the field, and if further revisions or updates of the text are necessary, then you should include the papers published in the interim as part of your updates.
Start writing the review before (or at the same time) as you start searching the literature.
I'd suggest to determine the scope of the review before you start searching the literature, and already write it down. This would answer questions like Which problem am I looking at? or Why is this problem relevant now? Answers to these questions will also guide your literature search.
Stop searching the literature when you stop writing.
Writing is not a linear process - it is going from a rough outline to a focussed text. As you go into focus, you will need to research more and more specific references. While you define your questions, search for literature dealing with these questions, and when you develop an argument, search for literature that would support (or contradict!) that argument.
My key suggestion would be to not view the literature search as shopping around randomly, but more like a visit to the grocery store with the shopping list in your hand.
Note that these suggestions apply to writing a literature review. Staying on top of recent literature or reading to get into a new field would be a different story.
You need to be very productive in terms of knowing your area. knowing what is happening is different from understanding it. This includes utilising every available tool which makes it easier to keep updated with what is published. An easy way , in Computer Science, is setting alerts (both on Arxiv and Google Scholar) and following pioneers in your area.
As a personal experience, I spent plenty of time gathering, reading and understanding related papers/books. I came across many interesting ideas. But finally, I found some of my ideas are published in others papers. Some were exactly the same! This is the curse of PhD. Try to publish before others as long as you have the required knowledge and a clear contribution. The literature is then translated to the cumulative process of publishing different papers related to your thesis problem. You stop when you do the defence (assuming you will change the area thereafter).
You should develop an outline, in consultation with your advisor, of what is to be included in the literature review - this should be based on the research foci and priorities of your research.
What I do when writing a literature review, is to actually write the review at the same time as doing the research.
When should you stop? when you have covered each of the foci and priorities to the point when you (and your advisor) are satisfied that you have synthesised the scope of each of the foci and priorities.