Moving Average |
Top Previous Next |
sma( length [, source | sym() | inv()] [, barIndex] ) ema( length [, source | sym() | inv()] [, barIndex] ) wma( length [, source | sym() | inv()] [, barIndex] ) vwma( length [, source | sym() | inv()] [, barIndex] )
A Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average, a mathematical analysis of the security's average value over a predetermined time period is made. As the security's price changes, its average price moves up or down.
Parameters
To Create a Series
var myStudy1 = null; var myStudy2 = null; var myStudy3 = null; var bInit = false;
function main() { var myVar1; var myVar2; var myVar3;
if ( bInit == false ) {
myStudy1 = ema( 20 ); myStudy2 = sma( 10 ); myStudy3 = wma( 40 );
bInit = true;
}
//retrieve the current values myVar1 = myStudy1.getValue(0); myVar2 = myStudy2.getValue(0); myVar3 = myStudy3.getValue(0);
return new Array( myVar1, myVar2, myVar3 );
}
To Retrieve a Single Value
function main() {
... ... myVar = sma( 10 );
//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 = sma( 20, 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 = ema( 10, 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 = wma( 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 = vwma( 14, sym( "MSFT,30" ) );
//create a study that will be based on the high. myStudy = ema( 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 = sma( 20, close( inv(15) ) );
|