In the following study, a McClellan Oscillator that I downloaded from here somewhere... it displays
"McClellan Oscillator(Expotential,Off)"
in the upper left corner of the study.
I want to make it just say
"McClellan Oscillator"
without the (Expotential,Off) part.
Can somebody look at the following code and advise me what needs to be changed? Thanks!!
/************************************************** ***************
Provided By : eSignal. (c) Copyright 2003
************************************************** ***************/
function preMain() {
setStudyTitle("McClellan Oscillator");
setCursorLabelName("McClellan Osc");
addBand(-200, PS_SOLID, 1, Color.black, "-200");
addBand(-100, PS_SOLID, 1, Color.black, "-100");
addBand(100, PS_SOLID, 1, Color.black, "100");
addBand(200, PS_SOLID, 1, Color.black, "200");
var fp1 = new FunctionParameter("nMAType", FunctionParameter.STRING);
fp1.setName("MA Type");
fp1.addOption("Simple");
fp1.addOption("Exponential");
fp1.setDefault("Simple");
var fp2 = new FunctionParameter("bSum", FunctionParameter.STRING);
fp2.setName("Summation");
fp2.addOption("On");
fp2.addOption("Off");
fp2.setDefault("Off");
}
var vOsc = null;
var vOsc_ret = 0;
var vADD = null;
var aADD = new Array(39);
var bEdit = true;
function main(nMAType, bSum) {
var nState = getBarState();
if (bEdit == true) {
if (bSum == "On") {
setCursorLabelName("McClellan Osc");
} else if (bSum == "Off") {
setCursorLabelName("McClellan Sum");
}
bEdit = false;
}
if (nState == BARSTATE_NEWBAR && vADD != null) {
aADD.pop();
aADD.unshift(vADD);
}
vADD = open(0, 1, "$ADD");
if (vADD == null) return;
aADD[0] = vADD[0];
if (aADD[38] == null) return;
if(nMAType == "Simple") {
var sum = 0;
var s = 0;
var i = 0;
for(i = 0; i < 39; i++) {
sum += aADD[i];
if(i < 19) s += aADD[i];
}
vOsc = (s / 19) - (sum / 39);
} else if (nMAType == "Exponential") {
vEMA[0] = EMA(19, 0);
vEMA[1] = EMA(39, 1);
vOsc = vEMA[0] - vEMA[1];
}
if (bSum == "On") {
vOsc_ret += vOsc;
} else if (bSum == "Off") {
vOsc_ret = vOsc;
}
return vOsc_ret;
}
//0 = s, 1 = sum
var vEMA = new Array(2);
var vEMA1 = new Array(2);
var dPercent = new Array(2)
dPercent[0] = null;
dPercent[1] = null;
var bPrimed = new Array(2);
bPrimed[0] = false;
bPrimed[1] = false;
function EMA(nLength, nNum) {
var nBarState = getBarState();
var dSum = 0.0;
var dRef;
if(dPercent[nNum] == null) {
dPercent[nNum] = (2.0 / (nLength + 1.0));
bPrimed[nNum] = false;
}
if (nBarState == BARSTATE_NEWBAR) {
vEMA1[nNum] = vEMA[nNum];
}
if(bPrimed[nNum] == false) {
for(i = 0; i < nLength; i++) {
dSum += aADD[i];
}
bPrimed[nNum] = true;
return (dSum / nLength);
} else {
return (((vADD - vEMA1[nNum]) * dPercent[nNum]) + vEMA1[nNum]);
}
}
"McClellan Oscillator(Expotential,Off)"
in the upper left corner of the study.
I want to make it just say
"McClellan Oscillator"
without the (Expotential,Off) part.
Can somebody look at the following code and advise me what needs to be changed? Thanks!!
/************************************************** ***************
Provided By : eSignal. (c) Copyright 2003
************************************************** ***************/
function preMain() {
setStudyTitle("McClellan Oscillator");
setCursorLabelName("McClellan Osc");
addBand(-200, PS_SOLID, 1, Color.black, "-200");
addBand(-100, PS_SOLID, 1, Color.black, "-100");
addBand(100, PS_SOLID, 1, Color.black, "100");
addBand(200, PS_SOLID, 1, Color.black, "200");
var fp1 = new FunctionParameter("nMAType", FunctionParameter.STRING);
fp1.setName("MA Type");
fp1.addOption("Simple");
fp1.addOption("Exponential");
fp1.setDefault("Simple");
var fp2 = new FunctionParameter("bSum", FunctionParameter.STRING);
fp2.setName("Summation");
fp2.addOption("On");
fp2.addOption("Off");
fp2.setDefault("Off");
}
var vOsc = null;
var vOsc_ret = 0;
var vADD = null;
var aADD = new Array(39);
var bEdit = true;
function main(nMAType, bSum) {
var nState = getBarState();
if (bEdit == true) {
if (bSum == "On") {
setCursorLabelName("McClellan Osc");
} else if (bSum == "Off") {
setCursorLabelName("McClellan Sum");
}
bEdit = false;
}
if (nState == BARSTATE_NEWBAR && vADD != null) {
aADD.pop();
aADD.unshift(vADD);
}
vADD = open(0, 1, "$ADD");
if (vADD == null) return;
aADD[0] = vADD[0];
if (aADD[38] == null) return;
if(nMAType == "Simple") {
var sum = 0;
var s = 0;
var i = 0;
for(i = 0; i < 39; i++) {
sum += aADD[i];
if(i < 19) s += aADD[i];
}
vOsc = (s / 19) - (sum / 39);
} else if (nMAType == "Exponential") {
vEMA[0] = EMA(19, 0);
vEMA[1] = EMA(39, 1);
vOsc = vEMA[0] - vEMA[1];
}
if (bSum == "On") {
vOsc_ret += vOsc;
} else if (bSum == "Off") {
vOsc_ret = vOsc;
}
return vOsc_ret;
}
//0 = s, 1 = sum
var vEMA = new Array(2);
var vEMA1 = new Array(2);
var dPercent = new Array(2)
dPercent[0] = null;
dPercent[1] = null;
var bPrimed = new Array(2);
bPrimed[0] = false;
bPrimed[1] = false;
function EMA(nLength, nNum) {
var nBarState = getBarState();
var dSum = 0.0;
var dRef;
if(dPercent[nNum] == null) {
dPercent[nNum] = (2.0 / (nLength + 1.0));
bPrimed[nNum] = false;
}
if (nBarState == BARSTATE_NEWBAR) {
vEMA1[nNum] = vEMA[nNum];
}
if(bPrimed[nNum] == false) {
for(i = 0; i < nLength; i++) {
dSum += aADD[i];
}
bPrimed[nNum] = true;
return (dSum / nLength);
} else {
return (((vADD - vEMA1[nNum]) * dPercent[nNum]) + vEMA1[nNum]);
}
}
Comment