I've come up with 3 ways to get plots using efsInternal() using posts found in the forum.
Is there a way to test which is the least CPU intensive approach?
Thanks in advance.
Is there a way to test which is the least CPU intensive approach?
Thanks in advance.
PHP Code:
//three methods of using getSeries and efsInternal
debugClear();
var aFPArray = new Array();
var bInit = false;
function preMain() {
setPriceStudy(false);
setStudyTitle("Donchian Strength 8c");
setShowTitleParameters( true );
var x=0;
aFPArray[x] = new FunctionParameter( "WhichMethod", FunctionParameter.STRING);
with( aFPArray[x++] ) {
setName( "Use Which Method" );
addOption("getSeries in bInit");
addOption("getSeries in return statement");
addOption("getSeries using two efsInternal Functions");
setDefault( "getSeries in bInit" );
}
}
var xStrengthPlot = null;
var MySubStudy2 = null;
var vSymbol = null;
var Interval0 = null;
var xMA_Avg = null;
function main(WhichMethod){
if ( bInit == false ) {
if(vSymbol == null || vSymbol == "") vSymbol = getSymbol();
if(Interval0 == "Default" || Interval0 == null) Interval0 = getInterval();
xSymbol = vSymbol+","+Interval0;
if(WhichMethod == "getSeries in bInit"){
xStrengthPlot = efsInternal("Strength",xSymbol);
if(xMA_Avg == null) xMA_Avg = ema(34,eval(xStrengthPlot));
}else if(WhichMethod == "getSeries in return statement"){
//alternatively I can use the following with the corresponding "return new Array(xStrengthPlot,xMA_Avg);"
xStrengthPlot = getSeries(efsInternal("Strength",xSymbol),0);
if(xMA_Avg == null) xMA_Avg = getSeries(ema(34,eval(xStrengthPlot)));
}else if(WhichMethod == "getSeries using two efsInternal Functions"){
xStrengthPlot = getSeries(efsInternal("DonchianStrength",xSymbol),0);
xMA_Avg = getSeries(efsInternal("DonchianStrength",xSymbol),1);
}
bInit = true;
}
if(WhichMethod == "getSeries in bInit")
return new Array(getSeries(xStrengthPlot),getSeries(xMA_Avg));
else if(WhichMethod == "getSeries in return statement")
return new Array(xStrengthPlot,getSeries(xMA_Avg));
else if(WhichMethod == "getSeries using two efsInternal Functions"){
VarDonch = xStrengthPlot.getValue(0);
VarMA_Avg = xMA_Avg.getValue(0);
return new Array(VarDonch,VarMA_Avg);
}
}
function Strength(VSymbol) {
return (2*close(0,sym(VSymbol))-upperDonchian(34,sym(VSymbol))-lowerDonchian(34,sym(VSymbol)));
}
// function DonchianStrength(aSymbol) is used only for [WhichMethod == "getSeries using two efsInternal Functions"]
var rStrengthPlot = null;
var rMA_Avg = null;
function DonchianStrength(aSymbol){
rStrengthPlot = efsInternal("Strength",aSymbol);
if(rMA_Avg == null) rMA_Avg = ema(34,eval(rStrengthPlot));
return new Array(rStrengthPlot,rMA_Avg.getValue(0));
}
Comment