This study extends the work of Sudtasan (Int. J. Intell. Techn. Appl. Stat. 5, 143–155, 2012) to apply genetic algorithm to detect regime switching of eight stock prices before XD dates in the stock exchange of Thailand during 2005–2011. It reveals that regime switching does exist before XD dates only in the first half of the year. The study successfully discovers that ADVANC and PTT are good for short-term investment. CPALL and SCC are appropriate for medium-term investment. CPF, IVL, KBANK, and TCAP are potential for the long-term investment. Average buying days for all stocks are around 31 days before the XD dates. Rates of return of the investment in the first half of the year are higher than in the second half. Average annual rate of return is around 76 %. Technically, genetic algorithm without mutation performs better than a model with mutation. For the performance of the best genetic algorithm, a model with zero mutation rate that is applied to the data in the first half of the year can extract around 62 % of the highest potential profit.