It differs for every destination how many days upfront you have to book a ticket to get the lowest price. For a trip from Amsterdam to Berlin you can regularly buy a ticket at its lowest price 10 days upfront. So, buy your tickets around 0,5 months upfront to get the cheapest train ticket.