I am trying to create a set of bands that allow me to define a range. I have created a starting point that draws a midband at the middle of the previous bar. What I want to do is draw the band at the same level until the high of the current bar exceeds that level by a certain number of ticks and then the midband will trail the high by that number of ticks, and vice versa for the low.
I am drawing the midband with a function I called calcMB. My challenge has come trying to determine what the value of the midband was on the previous bar. I have tried to call calcMB(-1), MidBand(-1), RangeBands(-1) etc but none of those work. I must be missing something stupid. Any help is appreciated.
There is probably a way to put my code in a box but I could not figure it out.
Thanks,
Murray
var MidBand;
var aRange = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("RangeBands");
setShowTitleParameters(false);
setPlotType(PLOTTYPE_LINE, 0);
setCursorLabelName("MidBand", 0); //MidBand
setCursorLabelName("UpperBand", 1); //UpperBand
setCursorLabelName("LowerBand", 2); //LowerBand
setDefaultBarFgColor(Color.RGB(255,0,0), 0); // MidBand
setDefaultBarFgColor(Color.RGB(0,255,0), 1); // UpperBand
setDefaultBarFgColor(Color.RGB(0,255,0), 2); // LowerBand
setDefaultBarStyle(PS_SOLID,0); // MidBand
setDefaultBarStyle(PS_SOLID,1); // UpperBand
setDefaultBarStyle(PS_SOLID,2); // LowerBand
var colBGColor = new FunctionParameter("cColor", FunctionParameter.COLOR);
colBGColor.setName("Range Color")
colBGColor.setDefault(Color.yellow);
var x = 0;
aRange[x] = new FunctionParameter("Range", FunctionParameter.NUMBER);
with(aRange[x++]) {
setLowerLimit(1);
setDefault(10);
}
}
function main(Range,cColor) {
var nDisp = getMinTick() * Range;
MidBand = efsInternal("calcMB");
var UpperBand = MidBand + nDisp
var LowerBand = MidBand - nDisp
setBarBgColor(cColor,0,UpperBand,LowerBand);
return new Array(MidBand, UpperBand, LowerBand);
}
function calcMB() {
var nMid = (high(-1) + low(-1))/2;
/* if (high() - nDisp) > (MidBand(-1) {
nMid = (high() - nDisp);
}
if (high() > high(-1)) {
nMid = high() - nDisp;
}
*/
return nMid;
}
I am drawing the midband with a function I called calcMB. My challenge has come trying to determine what the value of the midband was on the previous bar. I have tried to call calcMB(-1), MidBand(-1), RangeBands(-1) etc but none of those work. I must be missing something stupid. Any help is appreciated.
There is probably a way to put my code in a box but I could not figure it out.
Thanks,
Murray
var MidBand;
var aRange = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("RangeBands");
setShowTitleParameters(false);
setPlotType(PLOTTYPE_LINE, 0);
setCursorLabelName("MidBand", 0); //MidBand
setCursorLabelName("UpperBand", 1); //UpperBand
setCursorLabelName("LowerBand", 2); //LowerBand
setDefaultBarFgColor(Color.RGB(255,0,0), 0); // MidBand
setDefaultBarFgColor(Color.RGB(0,255,0), 1); // UpperBand
setDefaultBarFgColor(Color.RGB(0,255,0), 2); // LowerBand
setDefaultBarStyle(PS_SOLID,0); // MidBand
setDefaultBarStyle(PS_SOLID,1); // UpperBand
setDefaultBarStyle(PS_SOLID,2); // LowerBand
var colBGColor = new FunctionParameter("cColor", FunctionParameter.COLOR);
colBGColor.setName("Range Color")
colBGColor.setDefault(Color.yellow);
var x = 0;
aRange[x] = new FunctionParameter("Range", FunctionParameter.NUMBER);
with(aRange[x++]) {
setLowerLimit(1);
setDefault(10);
}
}
function main(Range,cColor) {
var nDisp = getMinTick() * Range;
MidBand = efsInternal("calcMB");
var UpperBand = MidBand + nDisp
var LowerBand = MidBand - nDisp
setBarBgColor(cColor,0,UpperBand,LowerBand);
return new Array(MidBand, UpperBand, LowerBand);
}
function calcMB() {
var nMid = (high(-1) + low(-1))/2;
/* if (high() - nDisp) > (MidBand(-1) {
nMid = (high() - nDisp);
}
if (high() > high(-1)) {
nMid = high() - nDisp;
}
*/
return nMid;
}
Comment