The stochastic oscillator operates on the principle that prices tend to close near the high in uptrends and near the low in downtrends. It consists of two lines: %K and %D. %K reflects the current closing price compared to the range over a set number of periods, while %D is a moving average of %K. Typically, these lines oscillate between 0 and 100, with readings above 80 indicating an overbought condition and readings below 20 indicating an oversold condition.