It appears that there is a bug in the close method of the File object.
I open a file and read it's contents then invoke the close() method. It appears that the close method throws an exception (I can only guess) and terminates the current call thread all the way back to main.
In my attached exampl the "before close" prints but the "after close" never does, nor does the "EMA plot:".
Has anyone seen this? Is this a known bug? I've reproduced this on two different machines with the attached script.
Thx,
Mike
Hmm attaching a .efs doesn't seem to work. Here it is:
/***************************************
EMA
************************************************** ***************/
var MALen = 125;
var bInit = false;
function preMain() {
debugPrintln("EMA preMain");
setComputeOnClose(true);
setPriceStudy(true);
setStudyTitle("EMA: " + MALen);
setDefaultBarThickness(2, 1);
setCursorLabelName("EMA.efs", 0);
}
function main() {
//Initialization
if (bInit == false) {
xMA = ema(MALen);
bInit = true;
}
var nEMA = xMA.getValue(0);
var plot;
plot = nEMA;
var cb = getCurrentBarIndex();
if (-1 == cb)
StatusCheck();
debugPrintln("EMA plot:" + plot);
return plot;
}
function StatusCheck() {
var f = new File("RequestTradingStatus.txt");
if (f.exists()) {
f.open("rt");
if (f.isOpen()) {
var f = f.read(1);
if (1 == f) {
debugPrintln("StatusCheck 1");
} else {
debugPrintln("StatusCheck 0");
}
// Important, closing a file not open appears to abort the
// outer function call
debugPrintln("before close");
f.close();
debugPrintln("after close");
}
}
}
I open a file and read it's contents then invoke the close() method. It appears that the close method throws an exception (I can only guess) and terminates the current call thread all the way back to main.
In my attached exampl the "before close" prints but the "after close" never does, nor does the "EMA plot:".
Has anyone seen this? Is this a known bug? I've reproduced this on two different machines with the attached script.
Thx,
Mike
Hmm attaching a .efs doesn't seem to work. Here it is:
/***************************************
EMA
************************************************** ***************/
var MALen = 125;
var bInit = false;
function preMain() {
debugPrintln("EMA preMain");
setComputeOnClose(true);
setPriceStudy(true);
setStudyTitle("EMA: " + MALen);
setDefaultBarThickness(2, 1);
setCursorLabelName("EMA.efs", 0);
}
function main() {
//Initialization
if (bInit == false) {
xMA = ema(MALen);
bInit = true;
}
var nEMA = xMA.getValue(0);
var plot;
plot = nEMA;
var cb = getCurrentBarIndex();
if (-1 == cb)
StatusCheck();
debugPrintln("EMA plot:" + plot);
return plot;
}
function StatusCheck() {
var f = new File("RequestTradingStatus.txt");
if (f.exists()) {
f.open("rt");
if (f.isOpen()) {
var f = f.read(1);
if (1 == f) {
debugPrintln("StatusCheck 1");
} else {
debugPrintln("StatusCheck 0");
}
// Important, closing a file not open appears to abort the
// outer function call
debugPrintln("before close");
f.close();
debugPrintln("after close");
}
}
}
Comment