The attached file shows my amateurish attempt to color Bollinger Middle according to its gradient. Green for rising fast, red for falling fast, and caramel otherwise. It works except that the color changes one bar too late. So if, for example, Bollinger Middle was flat and then went up fast from bar 25, say, to bar 26 its color will change between bar 26 and bar 27. As I said, one bar too late. I've been through all the worked examples, and most of this forum, but still can't figure out how to put this right. Any help would be appreciated.
/*********************************************
This is BollingerBands supplied by eSignal
Modified by Ralph with params (10,1.9)
Modified to color BM by gradient
grad > 0.25% green
grad < -0.25% red
else default color
problem is color appears one bar too late
28July2012
*********************************************/
var bb = new BollingerStudy(10, "Close", 1.9);
function preMain() {
setPriceStudy(true);
// 0,1,2 refer to params returned in main.
setCursorLabelName("BBUpper", 0);
setCursorLabelName("BBBasis", 1);
setCursorLabelName("BBLower", 2);
// set default line colors
setDefaultBarFgColor(Color.RGB(255,155,0), 0);
setDefaultBarFgColor(Color.RGB(255,155,0), 1);
setDefaultBarFgColor(Color.RGB(255,155,0), 2);
setDefaultBarThickness(2,0);
setDefaultBarThickness(2,1);
setDefaultBarThickness(2,2);
}
function main() {
var vUpper = bb.getValue(BollingerStudy.UPPER);
var vBasis = bb.getValue(BollingerStudy.BASIS);
var vLower = bb.getValue(BollingerStudy.LOWER);
var yesterBasis = bb.getValue(BollingerStudy.BASIS,-1);
var grad = ((vBasis-yesterBasis)/yesterBasis)*100;
setDefaultBarFgColor(Color.RGB(255,155,0),1);
if (grad>=0.25) setDefaultBarFgColor(Color.darkgreen,1);
if (grad<=-0.25) setDefaultBarFgColor(Color.red,1);
return new Array(vUpper, vBasis, vLower);
}
/*********************************************
This is BollingerBands supplied by eSignal
Modified by Ralph with params (10,1.9)
Modified to color BM by gradient
grad > 0.25% green
grad < -0.25% red
else default color
problem is color appears one bar too late
28July2012
*********************************************/
var bb = new BollingerStudy(10, "Close", 1.9);
function preMain() {
setPriceStudy(true);
// 0,1,2 refer to params returned in main.
setCursorLabelName("BBUpper", 0);
setCursorLabelName("BBBasis", 1);
setCursorLabelName("BBLower", 2);
// set default line colors
setDefaultBarFgColor(Color.RGB(255,155,0), 0);
setDefaultBarFgColor(Color.RGB(255,155,0), 1);
setDefaultBarFgColor(Color.RGB(255,155,0), 2);
setDefaultBarThickness(2,0);
setDefaultBarThickness(2,1);
setDefaultBarThickness(2,2);
}
function main() {
var vUpper = bb.getValue(BollingerStudy.UPPER);
var vBasis = bb.getValue(BollingerStudy.BASIS);
var vLower = bb.getValue(BollingerStudy.LOWER);
var yesterBasis = bb.getValue(BollingerStudy.BASIS,-1);
var grad = ((vBasis-yesterBasis)/yesterBasis)*100;
setDefaultBarFgColor(Color.RGB(255,155,0),1);
if (grad>=0.25) setDefaultBarFgColor(Color.darkgreen,1);
if (grad<=-0.25) setDefaultBarFgColor(Color.red,1);
return new Array(vUpper, vBasis, vLower);
}
Comment