Rate of Change |
Top Previous Next |
roc( length [, source | sym() | inv()] [, barIndex] )
The Rate-of-Change (ROC) indicator displays the difference between the current price and the price x time periods ago. The difference can be displayed either in points or as a percentage. The momentum indicator displays the same information but expresses it as a ratio.
Parameters
To Create a Series
var myStudy = null; var bInit = false;
function main() { var myVar;
if ( bInit == false ) {
myStudy = roc( 20 ); bInit = true;
}
//retrieve the current value myVar = myStudy.getValue(0);
return( myVar );
}
To Retrieve a Single Value
function main() {
... ... myVar = roc( 14 );
//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 = roc( 15, 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 = roc( 15, 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 = roc( 5, 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 = roc( 14, sym( "MSFT,30" ) );
//create a study that will be based on the high. myStudy = roc( 15, 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 = roc( 20, close( inv(15) ) );
|