osc() Built-in Study Functions
The Price Oscillator displays the difference between two moving averages of a security's price. The difference between the moving averages can be expressed in either points or percentages.
Syntax
osc( nFastLength , nSlowLength , bExponential [, Series | sym() | inv() ][, nBarIndex ] )
Parameters
Parameter: | Description: | Default: |
nFastLength | Required. Number for the fast period length to use for the calculation. | n/a |
nSlowLength | Required. Number for the slow period length to use for the calculation. | n/a |
bExponential | Required. Boolean true or false to use exponential calculations. | n/a |
Series or sym() or inv() |
[Optional] Series Object or function of sym() or inv() to determine symbol/interval source for the study. | Chart's sym/inv |
nBarIndex | [Optional] Bar index of series to retrieve . | n/a |
Return Value(s)
Returns a Series Object when nBarIndex is not specified.
Returns a single value when nBarIndex is specified.
Notes
Only available in versions 7.9 or later.
Code Examples
function main() { return new Array(osc(10, 21, false)); }
function main() { return new Array(osc(10, 21, false, hl2())); }
Retrieve single values:
function main() { var nValue_0 = osc(10, 21, false, 0); // Current Bar Index var nValue_1 = osc(10, 21, false, -1); // Prior Bar Index return new Array(nValue_0, nValue_1); }
//global Series Object variable var xStudy = null; function main() { if (xStudy == null) xStudy = osc(10, 21, false); // retrieve single values for conditional statements var nValue_0 = xStudy.getValue(0); // Current Bar Index value var nValue_1 = xStudy.getValue(-1); // Prior Bar Index value // Plot Current Bar Index Value return nValue_0; }
// global Series Object variables var xStudy = null; var bInit = false; // Initialization flag function main() { if (bInit == false) { xStudy = osc(10, 21, false, inv(20)); // 20-min interval bInit = true; } // retrieve single values for conditional statements var nValue_0 = xStudy.getValue(0); // Current Bar Index value var nValue_1 = xStudy.getValue(-1); // Prior Bar Index value // Synchronized Series plot return getSeries(xStudy); }
// global Series Object variables var xStudy = null; var bInit = false; // Initialization flag function main() { if (bInit == false) { xStudy = osc(10, 21, false, sym("IBM,20")); // IBM 20-min interval bInit = true; } // retrieve single values for conditional statements var nValue_0 = xStudy.getValue(0); // Current Bar Index value var nValue_1 = xStudy.getValue(-1); // Prior Bar Index value // Synchronized Series plot return getSeries(xStudy); }
See Also
Series Object
getSeries()
Built-in Study Functions
eSignal Forum Search Engine
Help Guides and Tutorials