What is the syntax for returning a moving average in an offset position to the price chart?
Thanx
Thanx
var study = new MAStudy(3, 3, "Close", MAStudy.SIMPLE);
function main() {
var vDMA = study.getValue(MAStudy.MA);
if (vDMA == null) {
return;
}
return vDMA;
}
var study = null;
var myArray = null;
var vMA = null;
function main(nLength) {
if (nLength == null)
nLength = 10;
if (myArray == null || study == null) {
myArray = new Array(nLength);
study = new MAStudy(nLength, 0, "Close", MAStudy.SIMPLE);
}
vMA = study.getValue(MAStudy.MA);
if (vMA == null)
return;
if (getBarState() == BARSTATE_NEWBAR) {
myArray.pop() // removes the last element of the array
myArray.unshift(vMA) // inserts a new element to the front and shifts the others by 1.
} else {
myArray[0] = vMA;
}
return myArray[2];
}
function main() {
var vPrices = getValue("Close", -10, 5);
if (getCurrentBarIndex() == -1) {
debugPrintln(vPrices); // open your formula output window to view the results.
}
// perform custom ma calculations here and set vMA to your custom ma
return vMA;
}
Comment