Version: 1.0.0
Stochastic Oscillator
Implement the Stochastic Oscillator displaying K and D lines on a separate oscillator sub-pane.
Overview
The Stochastic Oscillator is a momentum indicator comparing a specific closing price of an asset to a range of its prices over a certain period of time.
Stochastic Math
- %K Line:
((Current Close - Lowest Low) / (Highest High - Lowest Low)) * 100calculated over the period (typically 14). - %D Line: 3-period simple moving average of the %K line.
API Registration
Register the Stochastic Oscillator using the Charting API:
window.ChartingAPI.registerIndicator('stoch', {
name: 'Stochastic Oscillator',
type: 'pane',
levels: [20, 80],
params: { kPeriod: 14, dPeriod: 3 },
defaultColor: '#ff9800',
calculate: function(bars, params) {
// Returns { kValues, dValues }
},
render: function(ctx, chart, values, bounds, color) {
// Render %K (orange) and %D (blue) line plots...
}
});