If you want the write-off, the sale has to occur this year. The buy-in can be whenever you wish. Just not within 30 days.
My point is...you don't have to sell first and be totally out of the stock for 30 days. Assuming you're committed to taking a loss this year and have the money, buy first, wait thirty days and then sell your original shares on or before December 31st.
Times running out...
DoP