I have 2 scripts. The 2nd script (in study pane) is using values from the 1st (in price pane) and I want to make sure the parameters are the same.
The script test2 uses efsExternal to call test1. I am using getGlobalValue to retrieve the parameter from test1 and use it in test2.
For example: test1 plots an SMA of nLen. Test2 tries to retrieve the nLen value via getGlobalValue("gMALen"). If the value of nLen changes (in test1) then test2 should be reloaded with the new nLen.
The problem is the study in test2 is not using the correct value for nLen. The var x0 is getting the proper value from the Global but that value is not being used by the efsExternal call.
The script test2 uses efsExternal to call test1. I am using getGlobalValue to retrieve the parameter from test1 and use it in test2.
For example: test1 plots an SMA of nLen. Test2 tries to retrieve the nLen value via getGlobalValue("gMALen"). If the value of nLen changes (in test1) then test2 should be reloaded with the new nLen.
The problem is the study in test2 is not using the correct value for nLen. The var x0 is getting the proper value from the Global but that value is not being used by the efsExternal call.
PHP Code:
// test1.efs plots an SMA on the price pane
var xStudy = null;
var bInit = false;
var aFPArray = new Array();
function preMain() {
setPriceStudy(true);
setCursorLabelName("MA", 0)
x=0;
aFPArray[x] = new FunctionParameter("nLen", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setName("MA length");
setLowerLimit(1);
setDefault(10);
}
}
function main(nLen) {
if(bInit == false){
setGlobalValue( "gMALen", nLen );
xStudy = sma(nLen)
bInit = true;
}
var nMA = xStudy.getValue(0)
return ( nMA );
}
PHP Code:
// test2.efs uses an SMA to create a study
// the SMA here should be of the same length as
// the SMA being plotted by test1
debugClear();
var xStudy = null;
var bInit = false;
var x1 = 1;
var x0 = 1;
var nState;
function preMain() {
setPriceStudy(false);
}
function main() {
nState = getBarState();
if (nState == BARSTATE_NEWBAR) {
x1 = x0;
x0 = getGlobalValue( "gMALen" );
debugPrintln("old="+x1+" new="+x0);
if (x1 != x0) { reloadEFS(); }
}
if(bInit == false){
xStudy = efsExternal("test1.efs", x0)
bInit = true;
}
// do stuff with xStudy values
var myPlot = xStudy.getValue(0);
setBarBgColor(Color.RGB(220,220,220));
return (myPlot);
}
Comment