setStudyTitle("PPO");
setShowCursorLabel(false);
setDefaultBarFgColor(Color.cyan,0);
setDefaultBarFgColor(Color.red,1);
setDefaultBarFgColor(Color.lightgrey,2);
//addBand(0, PS_SOLID, 1, Color.lightgrey,"zero");
setDefaultBarThickness(2,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(2,2);
setPlotType(PLOTTYPE_HISTOGRAM,2);
//checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMAx2.efs"); //Comment this line out if modifying the code
var fp1 = new FunctionParameter("MALength", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(9);
var fp2 = new FunctionParameter("MAType", FunctionParameter.STRING);
fp2.setName("MAType");
fp2.addOption("Simple");
fp2.addOption("Exponential");
fp2.setDefault("Exponential"); //Edit this value to set a new default
var fp3 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
fp3.setLowerLimit(1);
fp3.setDefault(12); //Edit this value to set a new default
var fp4 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
fp4.setName("MA1Source");
fp4.addOption("Close");
fp4.addOption("High");
fp4.addOption("Low");
fp4.addOption("Open");
fp4.addOption("HL/2");
fp4.addOption("HLC/3");
fp4.addOption("OHLC/4");
fp4.setDefault("Close"); //Edit this value to set a new default
var fp5 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
fp5.setName("MA1Type");
fp5.addOption("MAStudy.SIMPLE");
fp5.addOption("MAStudy.EXPONENTIAL");
fp5.addOption("MAStudy.WEIGHTED");
fp5.addOption("MAStudy.VOLUMEWEIGHTED");
fp5.setDefault("MAStudy.EXPONENTIAL"); //Edit this value to set a new default
var fp6 = new FunctionParameter("MA2Length", FunctionParameter.NUMBER);
fp6.setLowerLimit(1);
fp6.setDefault(26); //Edit this value to set a new default
var fp7 = new FunctionParameter("MA2Source", FunctionParameter.STRING);
fp7.setName("MA1Source");
fp7.addOption("Close");
fp7.addOption("High");
fp7.addOption("Low");
fp7.addOption("Open");
fp7.addOption("HL/2");
fp7.addOption("HLC/3");
fp7.addOption("OHLC/4");
fp7.setDefault("Close"); //Edit this value to set a new default
var fp8 = new FunctionParameter("MA2Type", FunctionParameter.STRING);
fp8.setName("MA2Type");
fp8.addOption("MAStudy.SIMPLE");
fp8.addOption("MAStudy.EXPONENTIAL");
fp8.addOption("MAStudy.WEIGHTED");
fp8.addOption("MAStudy.VOLUMEWEIGHTED");
fp8.setDefault("MAStudy.EXPONENTIAL"); //Edit this value to set a new default
}
var bPrimed = false;
var vEMA = null;
var vEMA1 = null;
var dPercent = 0.0;
var vValue = 0.0;
var aValue = null;
var vAvg = null;//used in the example provided
function main(MALength,MAType,MA1Length,MA1Source,MA1Type,M A2Length,MA2Source,MA2Type) {
var i;
var vSum = 0.0;
//insert below the calculations required for the user defined variable (example provided)
if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Source, eval(MA1Type));
if (vMA2 == null) vMA2 = new MAStudy(MA2Length, MA2Source, eval(MA2Type));
var Avg1 = vMA1.getValue(MAStudy.MA)
if(Avg1 == null) return;
var Avg2 = vMA2.getValue(MAStudy.MA);
if(Avg2 == null) return;
vAvg = (Avg1-Avg2)/Avg1;
//end section for user defined variable
vValue = vAvg; //replace vAvg with the user defined variable
if(vValue == null) {
return;
}
if (aValue == null) {
aValue = new Array(MALength);
}
if (getBarState() == BARSTATE_NEWBAR) {
aValue.pop();
aValue.unshift(vValue);
} else {
aValue[0] = vValue;
}
Comment