I've run into this issue a few times before and ignored it but now I have to solve it. Due to recent volatility, I've had to add a short section of 1 minute bar trade stop code onto a 3000+ line efs running on a 5 minute chart and ended up withe quite a bit of null data on both dynamic and static time templates. Here is some proof of concept code:
function preMain() {
setPriceStudy(true)
}
//Globals
xStudy1min=null;
xStudy5min=null;
// Run this on a 5 minute chart (I'm using dynamic chart)
function main() {
if(xStudy1min==null) xStudy1min=close(inv(1));
if(xStudy5min==null) xStudy5min=close();
for (var i=0;i<5;i++){
debugPrintln(xStudy5min.getValue(0) +" "+xStudy1min.getValue(-i));
}
debugPrintln("********************");
}
On historic bars I am assuming that "main" only runs once per 5 minute bar so I try to specifically query the 5 individual minutes of the 1 minute series. The print-out consists of several hundred null values for the 1 minute series before I get a couple dozen prints at the end that are OK. Looks like:
A lot of this
********************
1254.5 null
1254.5 null
1254.5 null
1254.5 null
1254.5 null
********************
1198.75 null
1198.75 null
1198.75 null
1198.75 null
1198.75 null
********************
And then some of this at the very end (top):
********************
1160 1160
1160 1159.75
1160 1159.25
1160 1158.25
1160 1160
********************
I am assuming that what happens is that historical bars are only fetching the 5 minute series and the 1 minute series only exists for bars that were drawn when real - time data was being plotted (that's why a longer time series in a shorter time chart always works ok)???
I must be missing something. (Being lazy I'd rather not recode/debug a few thousand lines to make them 5 minute dependant so I can plot them on a 1 minute chart; I also thought of passing globals between charts but that would prevent back-test)
function preMain() {
setPriceStudy(true)
}
//Globals
xStudy1min=null;
xStudy5min=null;
// Run this on a 5 minute chart (I'm using dynamic chart)
function main() {
if(xStudy1min==null) xStudy1min=close(inv(1));
if(xStudy5min==null) xStudy5min=close();
for (var i=0;i<5;i++){
debugPrintln(xStudy5min.getValue(0) +" "+xStudy1min.getValue(-i));
}
debugPrintln("********************");
}
On historic bars I am assuming that "main" only runs once per 5 minute bar so I try to specifically query the 5 individual minutes of the 1 minute series. The print-out consists of several hundred null values for the 1 minute series before I get a couple dozen prints at the end that are OK. Looks like:
A lot of this
********************
1254.5 null
1254.5 null
1254.5 null
1254.5 null
1254.5 null
********************
1198.75 null
1198.75 null
1198.75 null
1198.75 null
1198.75 null
********************
And then some of this at the very end (top):
********************
1160 1160
1160 1159.75
1160 1159.25
1160 1158.25
1160 1160
********************
I am assuming that what happens is that historical bars are only fetching the 5 minute series and the 1 minute series only exists for bars that were drawn when real - time data was being plotted (that's why a longer time series in a shorter time chart always works ok)???
I must be missing something. (Being lazy I'd rather not recode/debug a few thousand lines to make them 5 minute dependant so I can plot them on a 1 minute chart; I also thought of passing globals between charts but that would prevent back-test)
Comment