Optimal trend-following trading rules under a three-state regime switching model