can I clarify the use of ref() to retrieve previous values for a built-in study?
In the code below if I return "new Array(vMA1, vMA2, vMA3)" all is ok. But if I return "new Array(vMA1, vMA2)" then myValue3 is undefined.
For a study that makes use of multiple built-in studies but doesn't want to plot them, do you suggest using functions to get previous values?
// ref usage
var study1 = new MAStudy(10, 0, "Close", MAStudy.Simple);
var study2 = new MAStudy(20, 0, "Close", MAStudy.Simple);
var study3 = new MAStudy(30, 0, "Close", MAStudy.Simple);
function preMain() {
setPriceStudy(true);
}
var BarCount = 0;
function main() {
var vMA1 = study1.getValue(MAStudy.MA);
var vMA2 = study2.getValue(MAStudy.MA);
var vMA3 = study3.getValue(MAStudy.MA);
if (getBarState() == BARSTATE_NEWBAR) {
BarCount += 1;
}
if (BarCount > 30) {
var myRef = ref(-1);
var myValue1 = myRef[0];
var myValue2 = myRef[1];
var myValue3 = myRef[2];
debugPrintln(getCurrentBarIndex() + " " + vMA3 + " " + myValue3);
}
return new Array(vMA1, vMA2, vMA3);
}
In the code below if I return "new Array(vMA1, vMA2, vMA3)" all is ok. But if I return "new Array(vMA1, vMA2)" then myValue3 is undefined.
For a study that makes use of multiple built-in studies but doesn't want to plot them, do you suggest using functions to get previous values?
// ref usage
var study1 = new MAStudy(10, 0, "Close", MAStudy.Simple);
var study2 = new MAStudy(20, 0, "Close", MAStudy.Simple);
var study3 = new MAStudy(30, 0, "Close", MAStudy.Simple);
function preMain() {
setPriceStudy(true);
}
var BarCount = 0;
function main() {
var vMA1 = study1.getValue(MAStudy.MA);
var vMA2 = study2.getValue(MAStudy.MA);
var vMA3 = study3.getValue(MAStudy.MA);
if (getBarState() == BARSTATE_NEWBAR) {
BarCount += 1;
}
if (BarCount > 30) {
var myRef = ref(-1);
var myValue1 = myRef[0];
var myValue2 = myRef[1];
var myValue3 = myRef[2];
debugPrintln(getCurrentBarIndex() + " " + vMA3 + " " + myValue3);
}
return new Array(vMA1, vMA2, vMA3);
}
Comment