The use of various moving average (MA) rules remains popular with financial market practitioners. These rules have recently become the focus of a number empirical studies, but there have been very few studies of financial market models where some agents employ technical trading rules of the type used in practice. In this paper we propose a dynamic financial market model in which demand for traded assets has both a fundamentalist and a chartist component. The chartist demand is governed by the difference between current price and a (long-run) MA. Both types of traders are boundedly rational in the sense that, based on a fitness measure such as realized capital gains, traders switch from a strategy with low fitness to the one with high fitness. We characterize the stability and bifurcation properties of the underlying deterministic model via the reaction coefficient of the fundamentalists, the extrapolation rate of the chartists and the lag length used for the MA. By increasing the intensity of choice to switching strategies, we then examine various rational routes to randomness for different MA rules. The price dynamics of the moving average rule are also examined and one of our main findings is that an increase of the window length of the MA rule can destabilize an otherwise stable system, leading to more complicated, even chaotic behaviour. The analysis of the corresponding stochastic model is able to explain various market price phenomena, including temporary bubbles, sudden market crashes, price resistance and price switching between different levels.