RSI Enhanced Candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// IMPOTANT:
// In order to use this script, the default candles must be hidden via
// Chart Settings->Symbol Body, Borders and Wick.
//
// © Javafuel

//@version=4
study("RSI Enhanced Candles", overlay=true)

// RSI Settings
src = input(close, title="RSI Source")
len = input(14, minval=1, title="RSI Length")
len1 = input(70, minval=1, title="RSI Upper Level")
len2 = input(30, minval=1, title="RSI Lower Level")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

// RSI candles cretiera
upRsiCandleBull = rsi >= len1 and close >= open
upRsiCandleBear = rsi >= len1 and close <= open
lowRsiCandleBull = rsi <= len2 and close >= open
lowRsiCandleBear = rsi <= len2 and close <= open

// Stanard Candles Coloring
bullCandle = close >= open
bullCandleP = input(40, minval=0, maxval=100, step=10, title="Candles Transparency")
bullCandleC = input(title="Bull Candles Color", type=input.color, defval=#26a69a)
bearCandleC = input(title="Bear Candles Color", type=input.color, defval=#ef5350)

// Plot Stanard Candles
// Plot Stanard Bull Candles
plotcandle(bullCandle ? open : na, bullCandle ? high : na, bullCandle ? low : na, bullCandle ? close : na, 
 color=color.new(bullCandleC, bullCandleP), wickcolor=color.new(bullCandleC, bullCandleP), bordercolor=color.new(bullCandleC, bullCandleP), title="Bull Candles")
// plot Stanard Bear Candles
plotcandle(bullCandle ? na : open, bullCandle ? na : high, bullCandle ? na : low, bullCandle ? na : close, 
 color=color.new(bearCandleC, bullCandleP), wickcolor=color.new(bearCandleC, bullCandleP), bordercolor=color.new(bearCandleC, bullCandleP),  title="Bear Candles")

// RSI Candles Coloring
rsiCandleP = input(0, minval=0, maxval=100, step=10, title="RSI Candles Transparency")
rsiBullCandleC = input(title="RSI Bull Candles Color", type=input.color, defval=#50ffee)
rsiBearCandleC = input(title="RSI Bear Candles Color", type=input.color, defval=#ff0065)

// Plot RSI Candles
// Plot upRsiCandleBull
plotcandle(upRsiCandleBull ? open : na, upRsiCandleBull ? high : na, upRsiCandleBull ? low : na, upRsiCandleBull ? close : na, 
 color=color.new(rsiBullCandleC, rsiCandleP), wickcolor=color.new(rsiBullCandleC, rsiCandleP), bordercolor=color.new(rsiBullCandleC, rsiCandleP), title="RSI Upper Bulls")
// Plot pRsiCandleBear
plotcandle(upRsiCandleBear ? open : na, upRsiCandleBear ? high : na, upRsiCandleBear ? low : na, upRsiCandleBear ? close : na, 
 color=color.new(rsiBearCandleC, rsiCandleP), wickcolor=color.new(rsiBearCandleC, rsiCandleP), bordercolor=color.new(rsiBearCandleC, rsiCandleP), title="RSI Upper Bears")

// Plot lowRsiCandleBull
plotcandle(lowRsiCandleBull ? open : na, lowRsiCandleBull ? high : na, lowRsiCandleBull ? low : na, lowRsiCandleBull ? close : na, 
 color=color.new(rsiBullCandleC, rsiCandleP), wickcolor=color.new(rsiBullCandleC, rsiCandleP), bordercolor=color.new(rsiBullCandleC, rsiCandleP), title="RSI Lower Bulls")
 // Plot lowRsiCandleBear
plotcandle(lowRsiCandleBear ? open : na, lowRsiCandleBear ? high : na, lowRsiCandleBear ? low : na, lowRsiCandleBear ? close : na, 
 color=color.new(rsiBearCandleC, rsiCandleP), wickcolor=color.new(rsiBearCandleC, rsiCandleP), bordercolor=color.new(rsiBearCandleC, rsiCandleP), title="RSI Lower Bears")