Could someone please help me merge the following two studies while retaining their individual functionalities?
I need the range value of of the first study to be used as the "Points" parameter of the second study. (Obviously the "Points" parameter would be fixed but all the other parameters of both studies could still be changed by the user)
1st----------------------------------------------
function preMain() {
setPriceStudy(false);
setStudyTitle("HL Range");
setCursorLabelName("HL Range");
}
var aRange = null;
function main(MALength) {
if (MALength == null) MALength = 1;
var vRange = high()-low();
if (aRange == null) {
aRange = new Array(MALength);
}
if (getBarState() == BARSTATE_NEWBAR) {
aRange.pop();
aRange.unshift(vRange);
} else {
aRange[0] = vRange;
}
if (aRange[MALength-1] == null) return;
var nSum = 0;
for (i = 0; i < MALength; ++i) {
nSum += aRange[i];
}
var vMARange = nSum/MALength;
return vMARange;
}
2nd--------------------------------------------------
var vMA = null;
vUpper = null;
vLower = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("MAChannel");
setCursorLabelName("Short", 0);
setCursorLabelName("MA", 1);
setCursorLabelName("Long", 2);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.yellow, 1);
setDefaultBarFgColor(Color.lime, 2);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setPlotType(PLOTTYPE_LINE,2);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code
var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(1); //Edit this value to set a new default
var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
fp2.setDefault(0); //Edit this value to set a new default
var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
fp3.setName("Source");
fp3.addOption("Close");
fp3.addOption("High");
fp3.addOption("Low");
fp3.addOption("Open");
fp3.addOption("HL/2");
fp3.addOption("HLC/3");
fp3.addOption("OHLC/4");
fp3.setDefault("HL/2"); //Edit this value to set a new default
var fp4 = new FunctionParameter("Type", FunctionParameter.STRING);
fp4.setName("Type");
fp4.addOption("MAStudy.SIMPLE");
fp4.addOption("MAStudy.EXPONENTIAL");
fp4.addOption("MAStudy.WEIGHTED");
fp4.addOption("MAStudy.VOLUMEWEIGHTED");
fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp5 = new FunctionParameter("Value", FunctionParameter.STRING);
fp5.setName("Value");
fp5.addOption("Points");
fp5.addOption("Percent");
fp5.setDefault("Points");
var fp6 = new FunctionParameter("Points", FunctionParameter.NUMBER);
fp6.setName("Points");
fp6.setLowerLimit(-2);
fp6.setDefault(.5);
}
function main(Length,Offset,Source,Type,Value,Points) {
if (vMA == null) vMA = new MAStudy(Length, Offset, Source, eval(Type));
/*****************************************
Insert your code following this text block
Use vMA.getValue(MAStudy.MA) for your code
******************************************/
if(Value=="Points"){
var vUpper = vMA.getValue(MAStudy.MA)+Points;
var vLower = vMA.getValue(MAStudy.MA)-Points;
}
else if(Value == "Percent"){
var vUpper = vMA.getValue(MAStudy.MA)*(1+(Points/100));
var vLower = vMA.getValue(MAStudy.MA)*(1-(Points/100));
}
return new Array (vUpper,vMA.getValue(MAStudy.MA),vLower);
}
I need the range value of of the first study to be used as the "Points" parameter of the second study. (Obviously the "Points" parameter would be fixed but all the other parameters of both studies could still be changed by the user)
1st----------------------------------------------
function preMain() {
setPriceStudy(false);
setStudyTitle("HL Range");
setCursorLabelName("HL Range");
}
var aRange = null;
function main(MALength) {
if (MALength == null) MALength = 1;
var vRange = high()-low();
if (aRange == null) {
aRange = new Array(MALength);
}
if (getBarState() == BARSTATE_NEWBAR) {
aRange.pop();
aRange.unshift(vRange);
} else {
aRange[0] = vRange;
}
if (aRange[MALength-1] == null) return;
var nSum = 0;
for (i = 0; i < MALength; ++i) {
nSum += aRange[i];
}
var vMARange = nSum/MALength;
return vMARange;
}
2nd--------------------------------------------------
var vMA = null;
vUpper = null;
vLower = null;
function preMain() {
setPriceStudy(true);
setStudyTitle("MAChannel");
setCursorLabelName("Short", 0);
setCursorLabelName("MA", 1);
setCursorLabelName("Long", 2);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.yellow, 1);
setDefaultBarFgColor(Color.lime, 2);
setPlotType(PLOTTYPE_LINE,0);
setPlotType(PLOTTYPE_LINE,1);
setPlotType(PLOTTYPE_LINE,2);
setDefaultBarThickness(1,0);
setDefaultBarThickness(1,1);
setDefaultBarThickness(1,2);
checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code
var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
fp1.setLowerLimit(1);
fp1.setDefault(1); //Edit this value to set a new default
var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
fp2.setDefault(0); //Edit this value to set a new default
var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
fp3.setName("Source");
fp3.addOption("Close");
fp3.addOption("High");
fp3.addOption("Low");
fp3.addOption("Open");
fp3.addOption("HL/2");
fp3.addOption("HLC/3");
fp3.addOption("OHLC/4");
fp3.setDefault("HL/2"); //Edit this value to set a new default
var fp4 = new FunctionParameter("Type", FunctionParameter.STRING);
fp4.setName("Type");
fp4.addOption("MAStudy.SIMPLE");
fp4.addOption("MAStudy.EXPONENTIAL");
fp4.addOption("MAStudy.WEIGHTED");
fp4.addOption("MAStudy.VOLUMEWEIGHTED");
fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
var fp5 = new FunctionParameter("Value", FunctionParameter.STRING);
fp5.setName("Value");
fp5.addOption("Points");
fp5.addOption("Percent");
fp5.setDefault("Points");
var fp6 = new FunctionParameter("Points", FunctionParameter.NUMBER);
fp6.setName("Points");
fp6.setLowerLimit(-2);
fp6.setDefault(.5);
}
function main(Length,Offset,Source,Type,Value,Points) {
if (vMA == null) vMA = new MAStudy(Length, Offset, Source, eval(Type));
/*****************************************
Insert your code following this text block
Use vMA.getValue(MAStudy.MA) for your code
******************************************/
if(Value=="Points"){
var vUpper = vMA.getValue(MAStudy.MA)+Points;
var vLower = vMA.getValue(MAStudy.MA)-Points;
}
else if(Value == "Percent"){
var vUpper = vMA.getValue(MAStudy.MA)*(1+(Points/100));
var vLower = vMA.getValue(MAStudy.MA)*(1-(Points/100));
}
return new Array (vUpper,vMA.getValue(MAStudy.MA),vLower);
}
Comment