Hello,
Complete noob when it comes to coding (am trying my best to learn!), so any help is greatly appreciated. Is it possible to colour code the bars that close outside the bollinger bands?
Ex. (Note, my candlestick colour scheme is black/white)
Candle(s) close outside the upper bollinger band, it gets painted blue.
Candle(s) close outside the lower bollinger band, it gets painted red.
Thank you.
There you go. I tested it on EurUsd daily and it worked:
defparam calculateonlastbars=500
// construction of Bollinger Bands
BBVal = 20 //20 periods
BBdev = 2.0 //2.0 Deviation
BBavg = Average[BBval,0](close) //BB mean (middle line) 0=sma
BollUP = BBavg + ((std[BBval](close)) * BBdev) //Bollinger Upper Band
BollDN = BBavg - ((std[BBval](close)) * BBdev) //Bollinger Lower Band
// initialize colours to null
r=0
g=0
b=0
// set colours when due
if close > BollUP then
b=255
elsif close < BollDN THEN
r=255
endif
// display candlestick, if above/below BB
IF (r + g + b) <> 0 THEN
DRAWCANDLE(open,high,low,close) COLOURED(r,g,b,255) //BORDERCOLOR(0,255,0,255)
ENDIF
RETURN
Roberto, many many thanks for this!
Question, if I was to replace bollingers and use the Keltner Channels found here (https://www.prorealcode.com/topic/keltner-channel-2/), would it work the samw?
It is, this is the modified code:
defparam calculateonlastbars=500
// construction of Bollinger Bands
a = average[20,0](customclose)
b = AverageTrueRange[20](close)
co= 1.5
//mm = a //middle line
hi = a + co*b //Upper Limit
lo = a - co*b //Lower Limit
// initialize colours to null
r=0
g=0
b=0
// set colours when due
if close > hi then
b=255
elsif close < lo THEN
r=255
endif
// display candlestick, if above/below Channel's limits
IF (r + g + b) <> 0 THEN
DRAWCANDLE(open,high,low,close) COLOURED(r,g,b,255) //BORDERCOLOR(0,255,0,255)
ENDIF
RETURN
Roberto, thank you for providing this! This works great!
Good evening Roberto:
is it possibile to get the same system but with the intraday stocastic indicator ???
specifically smoohed stochastic 5.3.3 80/20
overbought entry red colored bar >80
entry into oversold green colored bar <20
THANK YOU
I think that this indicator that color candlesticks based on the chosen oscillator might be of interest to you: 3D Candlesticks (CCI,RSI,Stochastic,Cycle,DI)
Thanks Nikolas but i’m not able to edit a script … i’ll ask roberto on the italian forum to specify better.. .. Tank you
There you go:
// Stochastic
Kline = Stochastic[5,3](close)
Dline = Average[3](Kline)
OB = 80
OS = 100 - OB
// initialize colours to null
r=0
g=0
b=0
// set colours when due
if Kline > OB then
r=255
elsif Kline < OS THEN
g=255
endif
// display candlestick, if above/below limits
IF (r + g + b) <> 0 THEN
DRAWCANDLE(open,high,low,close) COLOURED(r,g,b,255) //BORDERCOLOR(0,255,0,255)
ENDIF
RETURN
Grazie Roberto ..fine settimana lo provo
per l’intanto grazie per la gentilezza
TANKS ROBERTO !
Grazie Roberto ..fine settimana lo provo
per l’intanto grazie per la gentilezza
TANKS ROBERTO !
Gia testato ok perfetto … solo un’ultima richiesta se possibile :
è possibile invertire i colori ? il verde in ipercomprato / rosso in ipervenduto ? Grazie
……………
Already tested ok perfect … just one last request if possible: is it possible to invert the colors? green overbought / red oversold? Thanks