Following up on this thread here is another example of the new efs() function.
For the purpose of this example download the attached efs (which computes an EMA without using any builtiin studies) and save it in the same folder in which you will be saving the script enclosed in the following PHP box
In this example I am first calling the external efs and then using that as an input for the builtin EMA. In the same script I am also showing how flexible the new formula language is by providing two alternative methods to obtain the same result. Notice in the attached image how all three EMA of EMA are in fact returning the same result. The efs can be used with multiple intervals.
For the purpose of this example download the attached efs (which computes an EMA without using any builtiin studies) and save it in the same folder in which you will be saving the script enclosed in the following PHP box
PHP Code:
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("efs() function sample");
setCursorLabelName("ExtEMA",0);
setCursorLabelName("MAofExtEMA-1",1);
setCursorLabelName("MAofExtEMA-2",2);
setCursorLabelName("MAofExtEMA-3",3);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.red,1);
setDefaultBarFgColor(Color.red,2);
setDefaultBarFgColor(Color.red,3);
var x=0;
fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
with(fpArray[x++]){
setLowerLimit(1);
setDefault(10);
}
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.NUMBER);
with(fpArray[x++]){
setDefault("");
}
}
var bInit = false;
var vInterval = null;
function main(Length,Interval) {
if(bInit == false){
if(Interval == null) Interval = getInterval();
vInterval = Interval;
bInit = true;
}
//This line calls the external study which is an Exponential MA (non built-in study)
//and passes the parameters to that efs
var xMA = efs("externalEMA.efs",0,Length,close(inv(vInterval)));
//5 period Exponential MA (using built-in study) of the external efs called above
var MAxMA1 = ema(5,xMA);
//can also be written as follows
var MAxMA2 = ema(5,efs("externalEMA.efs",0,Length,close(inv(vInterval))));
//can also be written as follows. In this case I am recycling the external efs
var MAxMA3 = efs("externalEMA.efs",0,5,efs("externalEMA.efs",0,Length,close(inv(vInterval))));
return new Array (xMA,MAxMA1,MAxMA2,MAxMA3);
}