stochosc
Stochastic oscillator
Description
calculates the stochastic oscillator.percentKnD
= stochosc(Data
)
adds optional name-value pair arguments. percentKnD
= stochosc(___,Name,Value
)
Examples
Calculate the Stochastic Oscillator for a Stock
Load the file SimulatedStock.mat
, which provides a timetable (TMW
) for financial data for TMW stock.
load SimulatedStock.mat oscillator = stochosc(TMW,'NumPeriodsD',7,'NumPeriodsK',10,'Type','exponential'); plot(oscillator.Time,oscillator.FastPercentK,oscillator.Time,oscillator.FastPercentD) title('Stochastic Oscillator for TMW')
Input Arguments
Data
— Data with high, low, open, close information
matrix | table | timetable
Data with high, low, open, close information, specified as a matrix,
table, or timetable. For matrix input, Data
is an
M
-by-3
matrix of high, low, and
closing prices stored in the corresponding columns, respectively. Timetables
and tables with M
rows must contain variables named
'High'
, 'Low'
, and
'Close'
(case insensitive).
Data Types: double
| table
| timetable
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: percentKnD =
stochosc(TMW,'NumPeriodsD',10,'NumPeriodsK',3,'Type','exponential')
NumPeriodsK
— Period difference for PercentK
10
(default) | positive integer
Period difference for PercentK, specified as the comma-separated pair
consisting of 'NumPeriodsK'
and a scalar positive
integer.
Data Types: double
NumPeriodsD
— Length of moving average in periods for PercentD
3
(default) | positive integer
Length of moving average in periods for PercentD, specified as the
comma-separated pair consisting of 'NumPeriodsD'
and
a scalar positive integer.
Data Types: double
Type
— Moving average method for PercentD calculation
'e'
(exponential) (default) | character vector with values 'exponential'
or 'triangular'
Moving average method for PercentD calculation, specified as the
comma-separated pair consisting of 'Type'
and a
character vector with a value of:
'exponential'
– Exponential moving average is a weighted moving average. Exponential moving averages reduce the lag by applying more weight to recent prices. For example, a 10 period exponential moving average weights the most recent price by 18.18%.'triangular'
– Triangular moving average is a double-smoothing of the data. The first simple moving average is calculated and then a second simple moving average is calculated on the first moving average with the same window size.
Data Types: char
Output Arguments
percentKnD
— PercentK and PercentD
matrix | table | timetable
PercentK and PercentD, returned with the same number of rows
(M
) and type (matrix, table, or timetable) as the
input Data
.
More About
Stochastic Oscillator
The stochastic oscillator calculates the Fast PercentK (F%K), Fast PercentD (F%D), Slow PercentK (S%K), and Slow PercentD (S%D) from the series of high, low, and closing stock prices.
By default, the stochastic oscillator is based on 10-period difference for PercentK and a 3-period exponential moving average for PercentD.
References
[1] Achelis, S. B. Technical Analysis from A to Z. Second Edition. McGraw-Hill, 1995, pp. 268–271.
Version History
Introduced before R2006aR2023a: fints
support removed for Data
input argument
fints
object support for the Data
input
argument is removed.
R2022b: Support for negative price data
The Data
input accepts negative prices.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)