I debugged a problem with my code which came down to the fact that getBarStateInterval() only returns correct results the first time it is called within an iteration of main().
The code below (run on a daily chart) shows this. I would expect the output to be "ok1 ok2 ok1...". But instead only "ok1 ok1..." is output.
I got around the problem by initially assigning the bar state value to a variable which is then used at several times in the code. But I thought I would pass this on in case it's a bug.
function preMain() {
setPriceStudy(false);
setStudyTitle("Test2");
setCursorLabelName("tst", 0);
setComputeOnClose();
}
function main() {
if (getBarStateInterval("D") == BARSTATE_NEWBAR) {debugPrintln("ok1")}
if (getBarStateInterval("D") == BARSTATE_NEWBAR) {debugPrintln("ok2")}
return null;
}
function postMain() {
}
The code below (run on a daily chart) shows this. I would expect the output to be "ok1 ok2 ok1...". But instead only "ok1 ok1..." is output.
I got around the problem by initially assigning the bar state value to a variable which is then used at several times in the code. But I thought I would pass this on in case it's a bug.
function preMain() {
setPriceStudy(false);
setStudyTitle("Test2");
setCursorLabelName("tst", 0);
setComputeOnClose();
}
function main() {
if (getBarStateInterval("D") == BARSTATE_NEWBAR) {debugPrintln("ok1")}
if (getBarStateInterval("D") == BARSTATE_NEWBAR) {debugPrintln("ok2")}
return null;
}
function postMain() {
}
Comment