Hi I have made the folowing efs (PriceRelative.efs):
See attached.
I'm trying to call(load) it from a backtest.
For some reason the parameters passed to it is wrong.
I have tried with all versions of efs().
Any ideas ???
Thanks
JR
File:AlertTest.efs
=============================================
var vMACD = null;
var vRelStrInd = null;
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
function preMain()
{
setPriceStudy(true);
}
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
function main()
{
//var vRelStrInd = efs("PriceRelative.efs", 0, sym(getSymbol())), "$SPX", 20);
// var vRelStrInd = efs("\Wizards\PriceRelative.efs");
// if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()), "$SPX", 20);}
if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()));}
if(vMACD == null) {vMACD = new macd(12, 26, 9, "Close");}
debugPrintln("SDI_Alert_Test(" +getSymbol()+ ")=> vRelStrInd=" + vRelStrInd + ", vMACD=>"+vMACD);
}
=============================================
File:PriceRelative.efs
=============================================
//
// This formula was originally generated by the Alert Wizard
//
var vLastAlert = -1;
function preMain() {
var fp1 = new FunctionParameter("compareTo", FunctionParameter.STRING);
fp1.setName("compareTo");
fp1.addOption("$SPX");
fp1.setDefault("$SPX"); //Edit this value to set a new default
var fp2 = new FunctionParameter("MA_Periods", FunctionParameter.NUMBER);
fp2.setLowerLimit(1);
fp2.setDefault(20); //Edit this value to set a new default
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
setPriceStudy(false);
setStudyTitle("PriceRelative");
setCursorLabelName("Strength", 0);
setCursorLabelName("MA", 1);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.green, 1);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
}
function main(compareTo, MA_Periods) {
var vCurridx = getCurrentBarIndex();
var vMyClose = close(vCurridx);
var vTRelClose = close(vCurridx, 1, sym(compareTo));
debugPrintln(getSymbol()+".PriceRelative([" + vCurridx + "] compareTo="+compareTo+", MA_Periods="+ MA_Periods +"/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+nLength+", vValue="+vValue);
if(vTRelClose == 0.0)
{ return Array(null, null);}
var vMAret = null;
var vMyCurrVal = (vMyClose / vTRelClose);
//if(vCurridx == 0) debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vTRelClose + ", vMyClose="+vMyClose);
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
var vSum = 0.0;
var vValue = null;
var nLength = MA_Periods;
debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+nLength+", vValue="+vValue);
vValue = ref(-nLength, nLength);
// vSum += vMyCurrVal;
if(vValue != null && vValue.length >= nLength)
{
for(i = 0; i < nLength; i++)
{
if(vValue[i] != null)
{ vSum += vValue[i][0]; }
else
{ break;}
}
if(i >= nLength)
{ vMAret = (vSum / MA_Periods);}
}
// debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+getNumBars());
return Array(vMyCurrVal, vMAret);
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
=============================================
See attached.
I'm trying to call(load) it from a backtest.
For some reason the parameters passed to it is wrong.
I have tried with all versions of efs().
Any ideas ???
Thanks
JR
File:AlertTest.efs
=============================================
var vMACD = null;
var vRelStrInd = null;
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
function preMain()
{
setPriceStudy(true);
}
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
function main()
{
//var vRelStrInd = efs("PriceRelative.efs", 0, sym(getSymbol())), "$SPX", 20);
// var vRelStrInd = efs("\Wizards\PriceRelative.efs");
// if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()), "$SPX", 20);}
if(vRelStrInd == null) {vRelStrInd = efs("Wizard\\PriceRelative.efs", 0, sym(getSymbol()));}
if(vMACD == null) {vMACD = new macd(12, 26, 9, "Close");}
debugPrintln("SDI_Alert_Test(" +getSymbol()+ ")=> vRelStrInd=" + vRelStrInd + ", vMACD=>"+vMACD);
}
=============================================
File:PriceRelative.efs
=============================================
//
// This formula was originally generated by the Alert Wizard
//
var vLastAlert = -1;
function preMain() {
var fp1 = new FunctionParameter("compareTo", FunctionParameter.STRING);
fp1.setName("compareTo");
fp1.addOption("$SPX");
fp1.setDefault("$SPX"); //Edit this value to set a new default
var fp2 = new FunctionParameter("MA_Periods", FunctionParameter.NUMBER);
fp2.setLowerLimit(1);
fp2.setDefault(20); //Edit this value to set a new default
/**
* This function is called only once, before any of the bars are loaded.
* Place any study or EFS configuration commands here.
*/
setPriceStudy(false);
setStudyTitle("PriceRelative");
setCursorLabelName("Strength", 0);
setCursorLabelName("MA", 1);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.green, 1);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(2, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
}
function main(compareTo, MA_Periods) {
var vCurridx = getCurrentBarIndex();
var vMyClose = close(vCurridx);
var vTRelClose = close(vCurridx, 1, sym(compareTo));
debugPrintln(getSymbol()+".PriceRelative([" + vCurridx + "] compareTo="+compareTo+", MA_Periods="+ MA_Periods +"/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+nLength+", vValue="+vValue);
if(vTRelClose == 0.0)
{ return Array(null, null);}
var vMAret = null;
var vMyCurrVal = (vMyClose / vTRelClose);
//if(vCurridx == 0) debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vTRelClose + ", vMyClose="+vMyClose);
/**
* The main() function is called once per bar on all previous bars, once per
* each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
* in your preMain(), it is also called on every tick.
*/
var vSum = 0.0;
var vValue = null;
var nLength = MA_Periods;
debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+nLength+", vValue="+vValue);
vValue = ref(-nLength, nLength);
// vSum += vMyCurrVal;
if(vValue != null && vValue.length >= nLength)
{
for(i = 0; i < nLength; i++)
{
if(vValue[i] != null)
{ vSum += vValue[i][0]; }
else
{ break;}
}
if(i >= nLength)
{ vMAret = (vSum / MA_Periods);}
}
// debugPrintln("PriceRelative(" + vCurridx + ","+getSymbol()+ "/"+compareTo+")=>" + vMyCurrVal + "/"+vMAret+", vSum="+vSum+", nLength="+getNumBars());
return Array(vMyCurrVal, vMAret);
}
function postMain() {
/**
* The postMain() function is called only once, when the EFS is no longer used for
* the current symbol (ie, symbol change, chart closing, or application shutdown).
*/
}
=============================================
Comment