Trying to use color coding to show a simple trend indicator based on MAs in a watchlist.
[PHP]
/************************************************** *******
Plot the trend on a watch list
************************************************** ********/
function preMain() {
setPriceStudy(true);
setDefaultBarBgColor(Color.lightgrey);
setShowTitleParameters(false)
// setPlotType(PLOTTYPE_LINE,0);
// setDefaultBarThickness(1,0);
// setPlotType(PLOTTYPE_LINE,1);
// setDefaultBarThickness(1,1);
// setDefaultBarFgColor(Color.blue,0);
// setDefaultBarFgColor(Color.red,1);
}
bInit = false;
var n50=0;
var n200 = 0;
var nPrc=0;
var rText=""
function main() {
if (!bInit) {
n50 = sma(50, 0);
n200 = sma(200, 0);
nPrc = close(0);
rText = "new Array(n50, n200)";
bInit = true;
}
if (nPrc > n50 && n50 > n200) {
setBarBgColor(Color.RGB(190,255,190), 0, nPrc);
setBarFgColor(Color.RGB(0,0,128));
rText = "new Array(n50, n200)";
} else if (nPrc < n50 && n50 < n200) {
setBarBgColor(Color.RGB(255,190,190), 0, 0, nPrc);
setBarFgColor(Color.RGB(128,0,0));
rText = "new Array(n200, n50)";
} else {
setBarFgColor(Color.darkgrey);
setBarBgColor(Color.lightgrey);
}
return eval(rText);
}
/[PHP]
[PHP]
/************************************************** *******
Plot the trend on a watch list
************************************************** ********/
function preMain() {
setPriceStudy(true);
setDefaultBarBgColor(Color.lightgrey);
setShowTitleParameters(false)
// setPlotType(PLOTTYPE_LINE,0);
// setDefaultBarThickness(1,0);
// setPlotType(PLOTTYPE_LINE,1);
// setDefaultBarThickness(1,1);
// setDefaultBarFgColor(Color.blue,0);
// setDefaultBarFgColor(Color.red,1);
}
bInit = false;
var n50=0;
var n200 = 0;
var nPrc=0;
var rText=""
function main() {
if (!bInit) {
n50 = sma(50, 0);
n200 = sma(200, 0);
nPrc = close(0);
rText = "new Array(n50, n200)";
bInit = true;
}
if (nPrc > n50 && n50 > n200) {
setBarBgColor(Color.RGB(190,255,190), 0, nPrc);
setBarFgColor(Color.RGB(0,0,128));
rText = "new Array(n50, n200)";
} else if (nPrc < n50 && n50 < n200) {
setBarBgColor(Color.RGB(255,190,190), 0, 0, nPrc);
setBarFgColor(Color.RGB(128,0,0));
rText = "new Array(n200, n50)";
} else {
setBarFgColor(Color.darkgrey);
setBarBgColor(Color.lightgrey);
}
return eval(rText);
}
/[PHP]
Comment