I hv written below script so that the background will display below colors when below conditions happen..
orange: lsma above ema AND RSI>=50
pink: lsma above ema AND RSI<=50
lime: lsma below ema AND RSI>=50
green: lsma below ema AND RSI<=50
However, it doesn't display show the correct background color.... For example, at ~8:30, the background color should be lime since RSI<=50 and lsma>=ema but it shows pink color instead.
BTW, I take the 10min data and put it on a 5min chart deliberately for some reasons.
pls advise. thx
var amLib = addLibrary("amStudies.efsLib");
// parameters
var RSILength = 14;
var RSI_Higher_Threshold = 50;
var RSI_Lower_Threshold = 50;
var StrongUp_Bg_Color = Color.green;
var Up_Bg_Color = Color.RGB(255,200,150);
var No_Direction_Bg_Color = Color.yellow;
var Down_Bg_Color = Color.RGB(128,255,128);
var StrongDown_Bg_Color = Color.RGB(255,128,0);
var nLSMALength = 20;
var nEMALength = 20;
var bRSIUP = false;
var bRSIDown = false;
function preMain() {
var x=0;
setPriceStudy(true);
setStudyTitle("RSI background (10min)");
setShowCursorLabel(false);
setComputeOnClose(true);
}
function main() {
// initialization
if (getBarState() == BARSTATE_NEWBAR) {
bRSIUp = false;
bRSIDown = false;
}
vRSI = rsi(RSILength,inv(10));
if (vRSI == null ) return;
dThisEMA = ema(nEMALength,inv(10));
dLastEMA = ema(nEMALength,inv(10),-1);
if (dThisEMA == null || dLastEMA == null ) return;
dThisLSMA = amLib.amLSMA(nLSMALength,inv(10));
dLastLSMA = amLib.amLSMA(nLSMALength,inv(10),-1);
if (dThisLSMA == null || dLastLSMA == null) return;
if(vRSI >= RSI_Higher_Threshold) {
if (dThisLSMA >= dThisEMA) {
setDefaultBarBgColor(StrongUp_Bg_Color);
} else {
setDefaultBarBgColor(Up_Bg_Color);
}
Trend = "RSI Up";
BgColor=Color.lime;
} else if(vRSI <= RSI_Lower_Threshold) {
if (dThisLSMA <= dThisEMA) {
setDefaultBarBgColor(StrongDown_Bg_Color);
} else {
setDefaultBarBgColor(Down_Bg_Color);
}
Trend = "RSI Dn";
BgColor=Color.red;
} else {
setDefaultBarBgColor(Color.yellow);
BgColor=Color.yellow;
Trend = "****"
}
drawTextAbsolute(2, 22, close(0).toFixed(2), Color.black, Color.white,
Text.BOLD|Text.LEFT|Text.RELATIVETOTOP|Text.RELATI VETORIGHT, null, 12, "PP");
// drawTextAbsolute(2, 4, Trend, Color.black, BgColor,
// Text.BOLD|Text.LEFT|Text.RELATIVETOTOP|Text.RELATI VETORIGHT, null, 12, "RSITrend");
drawTextAbsolute(2, 4, "RSI:"+vRSI.toFixed(0), Color.black, BgColor,
Text.BOLD|Text.LEFT|Text.RELATIVETOTOP|Text.RELATI VETORIGHT, null, 12, "RSITrend");
return;
}
orange: lsma above ema AND RSI>=50
pink: lsma above ema AND RSI<=50
lime: lsma below ema AND RSI>=50
green: lsma below ema AND RSI<=50
However, it doesn't display show the correct background color.... For example, at ~8:30, the background color should be lime since RSI<=50 and lsma>=ema but it shows pink color instead.
BTW, I take the 10min data and put it on a 5min chart deliberately for some reasons.
pls advise. thx
var amLib = addLibrary("amStudies.efsLib");
// parameters
var RSILength = 14;
var RSI_Higher_Threshold = 50;
var RSI_Lower_Threshold = 50;
var StrongUp_Bg_Color = Color.green;
var Up_Bg_Color = Color.RGB(255,200,150);
var No_Direction_Bg_Color = Color.yellow;
var Down_Bg_Color = Color.RGB(128,255,128);
var StrongDown_Bg_Color = Color.RGB(255,128,0);
var nLSMALength = 20;
var nEMALength = 20;
var bRSIUP = false;
var bRSIDown = false;
function preMain() {
var x=0;
setPriceStudy(true);
setStudyTitle("RSI background (10min)");
setShowCursorLabel(false);
setComputeOnClose(true);
}
function main() {
// initialization
if (getBarState() == BARSTATE_NEWBAR) {
bRSIUp = false;
bRSIDown = false;
}
vRSI = rsi(RSILength,inv(10));
if (vRSI == null ) return;
dThisEMA = ema(nEMALength,inv(10));
dLastEMA = ema(nEMALength,inv(10),-1);
if (dThisEMA == null || dLastEMA == null ) return;
dThisLSMA = amLib.amLSMA(nLSMALength,inv(10));
dLastLSMA = amLib.amLSMA(nLSMALength,inv(10),-1);
if (dThisLSMA == null || dLastLSMA == null) return;
if(vRSI >= RSI_Higher_Threshold) {
if (dThisLSMA >= dThisEMA) {
setDefaultBarBgColor(StrongUp_Bg_Color);
} else {
setDefaultBarBgColor(Up_Bg_Color);
}
Trend = "RSI Up";
BgColor=Color.lime;
} else if(vRSI <= RSI_Lower_Threshold) {
if (dThisLSMA <= dThisEMA) {
setDefaultBarBgColor(StrongDown_Bg_Color);
} else {
setDefaultBarBgColor(Down_Bg_Color);
}
Trend = "RSI Dn";
BgColor=Color.red;
} else {
setDefaultBarBgColor(Color.yellow);
BgColor=Color.yellow;
Trend = "****"
}
drawTextAbsolute(2, 22, close(0).toFixed(2), Color.black, Color.white,
Text.BOLD|Text.LEFT|Text.RELATIVETOTOP|Text.RELATI VETORIGHT, null, 12, "PP");
// drawTextAbsolute(2, 4, Trend, Color.black, BgColor,
// Text.BOLD|Text.LEFT|Text.RELATIVETOTOP|Text.RELATI VETORIGHT, null, 12, "RSITrend");
drawTextAbsolute(2, 4, "RSI:"+vRSI.toFixed(0), Color.black, BgColor,
Text.BOLD|Text.LEFT|Text.RELATIVETOTOP|Text.RELATI VETORIGHT, null, 12, "RSITrend");
return;
}
Comment