In the present paper, a trading strategy is proposed for a portfolio composed of shares in the stock exchange. The proposed strategy is based mainly on three blocks: 1) a K-means clustering algorithm is used to determine and learn the internal hidden patterns in the time series of stock market prices, 2) a pattern predictor is performed based on a simple Markov chain, and 3) a fuzzy inference system take the decision to trade based on the estimation. The fuzzy inference system is composed of the rules provided by an expert trader. The performance of the trading algorithm is validated through simulations using real prices of
the Mexican stock exchange.