We study a stock trading method based on dynamic bayesian networks to model the dynamics of the trend of stock prices. We design a three level hierarchical hidden Markov model (HHMM). There are five states describing the trend in first level. Second and third levels are and concrete hidden Markov models to produce the observed patterns. To train the HHMM, we adapt a semi-supervised learning so that the trend states of first layer is manually labelled. The inferred probability distribution of first level are used as an indicator for the trading signal, which is more natural and reasonable than technical indicators. Experimental results on representative 20 companies of Korean stock market show that the proposed HHMM outperforms a technical indicator in trading performances.