in the minimal code below, why would i declare xSMA=sma(21) only the first time? is this because xSMA is an object and it saves memory so that object is not created again for each bar? it gives the same data whether or not i use bInit.
if that is so, why can't i declare it globally where i initialize it at the top to null? thanks!
********************************
var xSMA = null;
var bInit = false;
function main() {
if (getCurrentBarIndex() == 0 ) return;
if (!bInit) {
xSMA = sma(21);
bInit = true;
}
return xSMA.getValue(0);
}
if that is so, why can't i declare it globally where i initialize it at the top to null? thanks!
********************************
var xSMA = null;
var bInit = false;
function main() {
if (getCurrentBarIndex() == 0 ) return;
if (!bInit) {
xSMA = sma(21);
bInit = true;
}
return xSMA.getValue(0);
}
Comment