Just revisiting some multi-interval efs, I can't work out why the NEWBAR for an auxillary interval does not seem to occur when I thought it did (it seems to be delayed by one chart candle, this is a ComputeOnClose script). Please see description in the efs sample.
PHP Code:
// Unexpected time of arrival of NEWBAR for an auxillary interval. [r4, 2008-02-11, using ES]
// With, say, chart interval = 5mins, and an aux Interval of 30mins, and ComputeOnClose,
// As expected for the chart interval, I get the NEWBAR for, say, the candle starting at 07:55 when it closes at the first tick after 08:00.
// And if I print the candle time (getHour() and getMinute()) I see the proper 07:55 start time.
// For the aux interval, I expect to see NEWBAR at the the first tick after the 30 min period ends, too, hence I would expect the
// 30 minute candle starting at 07:30 to also complete at the first tick after 08:00,
// ie at the same tick (and call to main()) as the 07:55 5 minute candle ends.
// BUT I'm seeing the "aux" interval's NEWBAR delayed by one period of the chart interval,
// ie it completes just after 08:05 at the same main() call as the 08:00 5 minute candle.
// And when I access it with getHour() and getMinute() I get the time of 08:00, ie the new 30 minute candle, not the completed one.
// This occurs both with the "live" candles and the historic candles in the chart,
// but is easier to "understand" with the "live" candles as you can also look at the Wall Clock time.
//
// Am I wrong or is this a bug?
// This sample outputs to the Output window only, not the chart
function preMain() {
setPriceStudy(true);
setStudyTitle("Test NEWBAR timing for 2nd Interval - see Output Window");
debugPrint("Test NEWBAR timing for 2nd Interval, does not work wth TickReplay\n");
setComputeOnClose();
}
var mbStudyInit = false;
var msIntChart = null; // chart
var msIntAux = null; // auxillary
var mserSym = null; // Aux series
var gnCCO = 0; // With ComputeOnClose the nCandle argument for the closing candle = 0
function TwoDigits(n) {// for n is 0 to 60 usually, ie time / date in hh mm ss etc
var s = n.toString();
if (s.length == 1) s = "0"+s;
return s; // ignore longer
}
function WallClockString() {
var dDate = new Date();
return TwoDigits(dDate.getMonth())+"/"+TwoDigits(dDate.getDate())+"-"
+TwoDigits(dDate.getHours())+":"+TwoDigits(dDate.getMinutes())+":"+TwoDigits(dDate.getSeconds());
}
function BarTimeOnlyString(nCandle,mserSym) {
if (mserSym == null) { // how do this properly?
if (getMonth(nCandle) == null) return "No candle?";
return TwoDigits(getHour(nCandle))+":"+TwoDigits(getMinute(nCandle));
} else {
if (getMonth(nCandle,mserSym) == null) return "No candle?";
return TwoDigits(getHour(nCandle ,mserSym))+":"+TwoDigits(getMinute(nCandle ,mserSym));
}
}
function main() {
debugPrint(" \n");
debugPrint("Main() called at WC = " + WallClockString() + " \n");
var nBSChart = getBarState();
if (nBSChart == BARSTATE_ALLBARS) {
debugPrint("ALLBARS\n");
return; // wait for real bars I find better
}
if(mbStudyInit == false){
if (isComputeOnClose()) {
gnCCO = 0;
debugPrint("ComputeOnClose, nCandle for CandleJustClose = " + gnCCO + "\n");
} else {
gnCCO = -1;
debugPrint("ComputeOnClose NOT SET - Not intened in this test\n");
}
msIntChart = getInterval();
msIntAux = "30";
//msIntAux = "5";
if (msIntChart != msIntAux) {
debugPrint("Diff Int: " + msIntChart + ", " + msIntAux + "\n");
} else {
// ???
debugPrint("Diff Int NOT SET\n");
}
mserSym = sym(getSymbol().toUpperCase()+","+msIntAux); // same symbol, aux interval, for getting Candle time
mbStudyInit = true;
}
var nIntBS = getBarStateInterval(msIntAux); // http://forum.esignalcentral.com/showthread.php?s=&threadid=20800 only one per interval per _main().
if (nBSChart == BARSTATE_NEWBAR) {
var sText = BarTimeOnlyString(gnCCO); //candle time of just ending displayed bar, ie at just after 8:00 this would be the 07:55 candle
debugPrint("NEWBAR (Chart), Start Time of Completed Candle =" + sText+"\n");
}
if (nIntBS == BARSTATE_NEWBAR) {
var sText= BarTimeOnlyString(gnCCO,mserSym); //candle time of just ending aux interval, ie, at juust after 08:00 this would be the 07:30 candle
debugPrint("NEWBAR (aux), Start Time of Completed Candle =" + sText+"\n");
}
return;
}
Comment