Kimchi Premium Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © chanu_lev10k

//@version=5
strategy("Kimchi Premium Strategy", overlay=false)

// Inputs
sym_krw = input.symbol(title='Select BTCKRW Market', defval='BITHUMB:BTCKRW')
sym_usd = input.symbol(title='Select BTCUSD Market', defval='BITSTAMP:BTCUSD')
res = input.timeframe(title='Resolution', defval='')
src = input.source(title='Source', defval=close)
len1 = input.int(defval=4, title='Length of RSI')
len2 = input.int(defval=12, title='Length of Inverse Kimchi Premium RSI')
isikp = input.bool(title='Use Combination of Inverse Kimchi Premium RSI ?', defval=true)
bullLevel = input.float(title='Bull Level', defval=63, step=1.0, maxval=100, minval=0)
bearLevel = input.float(title='Bear Level', defval=28, step=1.0, maxval=100, minval=0)
highlightBreakouts = input(title='Highlight Bull/Bear Breakouts ?', defval=true)

// Inverse Kimichi Premium RSI Definition
up = ta.rma(math.max(ta.change(src), 0), len1)
down = ta.rma(-math.min(ta.change(src), 0), len1)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
usdkrw = request.security('FX_IDC:USDKRW', res, src)
btckrw = request.security(sym_krw, res, src)
btcusd = request.security(sym_usd, res, src)
btcusd_to_krw = btcusd * usdkrw
ikp = (btcusd_to_krw / btckrw - 1) * 100
ikp_f(res, len1, len2) =>
    n = rsi
    t = (rsi + ta.rsi(ikp, len2))/2
    isikp ? t : n
tot_rsi = ikp_f(res, len1, len2)

// Plot
rcColor = tot_rsi > bullLevel ? #0ebb23 : tot_rsi < bearLevel ? #ff0000 : #f4b77d
maxBand = hline(100, title='Max Level', linestyle=hline.style_dotted, color=color.white)
hline(0, title='Zero Level', linestyle=hline.style_dotted)
minBand = hline(0, title='Min Level', linestyle=hline.style_dotted, color=color.white)
bullBand = hline(bullLevel, title='Bull Level', linestyle=hline.style_dotted)
bearBand = hline(bearLevel, title='Bear Level', linestyle=hline.style_dotted)
fill(bullBand, bearBand, color=color.new(color.purple, 95))
bullFillColor = tot_rsi > bullLevel and highlightBreakouts ? color.green : na
bearFillColor = tot_rsi < bearLevel and highlightBreakouts ? color.red : na
fill(maxBand, bullBand, color=color.new(bullFillColor, 80))
fill(minBand, bearBand, color=color.new(bearFillColor, 80))
plot(tot_rsi, title='Total RSI', linewidth=2, color=rcColor)
plot(rsi, title='RSI', linewidth=1, color=color.new(color.purple, 0))
plot(ta.rsi(ikp, len2), title='Inverse Kimchi Premium RSI', linewidth=1, color=color.new(color.blue, 0))

// Long Short conditions
longCondition = ta.crossover(tot_rsi, bullLevel)
if longCondition
    strategy.entry('Long', strategy.long)
shortCondition = ta.crossunder(tot_rsi, bearLevel)
if shortCondition
    strategy.entry('Short', strategy.short)