I sem to be having a problem with my series variables. This script is causing the program to freeze up.
PHP Code:
var fpArray = new Array();
function preMain() {
setPriceStudy(false);
setStudyTitle("MACD of 2ROC");
setCursorLabelName("diff", 0);
setDefaultBarFgColor(Color.black, 0);
setPlotType(PLOTTYPE_LINE,0);
setDefaultBarThickness(2,0);
setCursorLabelName("dAvg", 1);
setDefaultBarFgColor(Color.magenta, 1);
setPlotType(PLOTTYPE_LINE,1);
setDefaultBarThickness(1,1);
setCursorLabelName("MA-s", 2);
setDefaultBarFgColor(Color.blue, 2);
setPlotType(PLOTTYPE_LINE,2);
setDefaultBarThickness(1,2);
setCursorLabelName("MA-f", 3);
setDefaultBarFgColor(Color.red, 3);
setPlotType(PLOTTYPE_LINE,3);
setDefaultBarThickness(1,3);
var x=0;
fpArray[x] = new FunctionParameter("sLen", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Slow ROC Length");
setLowerLimit(1);
setDefault(28);
}
fpArray[x] = new FunctionParameter("fLen", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Fast ROC Length");
setLowerLimit(1);
setDefault(14);
}
fpArray[x] = new FunctionParameter("maLen", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("MA Length");
setLowerLimit(1);
setDefault(8);
}
fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
with(fpArray[x++]){
addOption("open");
addOption("high");
addOption("low");
addOption("close");
addOption("hl2");
addOption("hlc3");
addOption("ohlc4");
setDefault("close");
}
fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
with(fpArray[x++]){
setDefault();
}
fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
with(fpArray[x++]){
setName("Show Parameters");
setDefault(false);
}
}
var bInit = false;
var sROC, fROC, xMAs, xMAf, xDiff;
function main(sLen,fLen,maLen,Source,Interval,Params) {
if(bInit == false){
var Symbol = getSymbol();
if(Interval == null) Interval = getInterval();
var vSymbol = Symbol+","+Interval;
sROC = roc(sLen,eval(Source)(sym(vSymbol)));
fROC = roc(fLen,eval(Source)(sym(vSymbol)));
xMAs = sma(maLen,sROC);
xMAf = sma(maLen,fROC);
addBand(0,PS_SOLID,1,Color.grey,"Centerline");
setShowTitleParameters(eval(Params));
bInit = true;
}
var s = xMAs.getValue(0);
var f = xMAf.getValue(0);
xDiff = efsInternal(CalcDiff, s, f );
dAvg = ema(10,xDiff);
return new Array (getSeries(xDiff), getSeries(dAvg), getSeries(xMAs), getSeries(xMAf) );
}
function CalcDiff(s1, f1){
d1 = (s1 - f1);
return(d1);
}
Comment