Stochastic |
Top Previous Next |
stochK( kLength, kSmoothing, dLength [, source | sym() | inv()] [, barIndex] ) stochD( kLength, kSmoothing, dLength [, source | sym() | inv()] [, barIndex] )
The Stochastic is designed to indicate when the market is overbought or oversold. It is based on the premise that when a market's price increases, the closing prices tend to move toward the daily highs and, conversely, when a market's price decreases, the closing prices move toward the daily lows. A Stochastic displays two lines, %K and %D. %K is calculated by finding the highest and lowest point in a trading period and then finding where the current close is in relation to that trading range, %K is then smoothed with a moving average. %D is a moving average of %K.
Parameters
To Create a Series
var myStudy1 = null; var myStudy2 = null; var bInit = false;
function main() { var myVar1; var myVar2;
if ( bInit == false ) {
myStudy1 = stochK( 14, 1, 3 ); myStudy2 = stochD( 14, 1, 3 );
bInit = true;
}
//retrieve the current values myVar1 = myStudy1.getValue(0); myVar2 = myStudy2.getValue(0);
return new Array( myVar1, myVar2 );
}
To Retrieve a Single Value
function main() {
... ... myVar = stochD( 14, 3, 5 );
//do something with the value in myVar
}
Calling Examples
//create a study that uses IBM as the symbol along with whatever bar //interval you are using in the chart where the script is loaded myStudy = stochK( 14, 1, 3, sym( "IBM") );
//create a study that uses the 15-min bar interval, regardless of the bar //interval of the chart in which the script is loaded myStudy = stochD( 14, 1, 3, inv(15) );
//create a study that uses the Daily bar interval, regardless of the bar //interval of the chart in which the script is loaded myStudy = stochK( 5, 3, 3, inv("D") );
//create a study that will be based on MSFT 30-min bars, regardless of //the symbol/bar interval of the chart in which the script is loaded myStudy = stochK( 14, 2, 5, sym( "MSFT,30" ) );
//create a study that will be based on the high. myStudy = stochD( 15, 3, 5, high() );
//create a study that will be based on the close, using 15-min bars, regardless of //the bar interval of the chart in which the script is loaded myStudy = stochK( 14, 1, 3, close( inv(15) ) );
|