I'm confused--- I'm calling a function (in a separate file) once per bar, but that function is executing several times per bar.
In the following example, the MAIN and EMBEDDED function prints (correctly) once/bar, but the EXTERNAL function that is called by the embedded function is run multiple times per bar.
Why isn't the external function only run once per bar (I'm only calling it once per bar)
Thanks,
// **************************************************
******************
// test where a Main calls a function, which calls an external function
function embedded(aPrice1) {
debugPrintln("embedded: "+getMonth(0)+"/"+getDay(0)+" "+getHour(0)+":"+getMinute(0)+" close from embedded function:"+aPrice1[0]);
var externalclose = call("/Library/externalfunction.efs", aPrice1);
return ;
}
function preMain() {
setComputeOnClose();
setStudyTitle("array test");
}
var aMain = new Array(5);
function main() {
aMain.pop(); //remove right most element, and put the latest closing price at element [0]
aMain.unshift(close());
debugPrintln("MAIN: "+getMonth(0)+"/"+getDay(0)+" "+getHour(0)+":"+getMinute(0)+" close from main:"+aMain[0]);
var Cembedded = embedded(aMain); //ask the embedded function to pass closing price to called function
return;
}
------------------------------------------------
FILE externalfunction.efs:
function main(aPrice2) {
debugPrintln("extfunction: "+getMonth(0)+"/"+getDay(0)+" "+getHour(0)+":"+getMinute(0)+" close from extfunction:"+aPrice2[0]);
return;
}
-----------------------------------------------
Formula Output:
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
MAIN: 7/2 10:57 close from main:1486.5
embedded: 7/2 10:57 close from embedded function:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:3 close from extfunction:1486.5
MAIN: 7/2 11:0 close from main:1487.5
embedded: 7/2 11:0 close from embedded function:1487.5
In the following example, the MAIN and EMBEDDED function prints (correctly) once/bar, but the EXTERNAL function that is called by the embedded function is run multiple times per bar.
Why isn't the external function only run once per bar (I'm only calling it once per bar)
Thanks,
// **************************************************
******************
// test where a Main calls a function, which calls an external function
function embedded(aPrice1) {
debugPrintln("embedded: "+getMonth(0)+"/"+getDay(0)+" "+getHour(0)+":"+getMinute(0)+" close from embedded function:"+aPrice1[0]);
var externalclose = call("/Library/externalfunction.efs", aPrice1);
return ;
}
function preMain() {
setComputeOnClose();
setStudyTitle("array test");
}
var aMain = new Array(5);
function main() {
aMain.pop(); //remove right most element, and put the latest closing price at element [0]
aMain.unshift(close());
debugPrintln("MAIN: "+getMonth(0)+"/"+getDay(0)+" "+getHour(0)+":"+getMinute(0)+" close from main:"+aMain[0]);
var Cembedded = embedded(aMain); //ask the embedded function to pass closing price to called function
return;
}
------------------------------------------------
FILE externalfunction.efs:
function main(aPrice2) {
debugPrintln("extfunction: "+getMonth(0)+"/"+getDay(0)+" "+getHour(0)+":"+getMinute(0)+" close from extfunction:"+aPrice2[0]);
return;
}
-----------------------------------------------
Formula Output:
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 10:57 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
MAIN: 7/2 10:57 close from main:1486.5
embedded: 7/2 10:57 close from embedded function:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:0 close from extfunction:1486.5
extfunction: 7/2 11:3 close from extfunction:1486.5
MAIN: 7/2 11:0 close from main:1487.5
embedded: 7/2 11:0 close from embedded function:1487.5
Comment