RSI 30 CROSS
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thambumalvino87

//@version=4
study(title="RSI 30 CROSS", shorttitle="RSI,30,10", format=format.price, precision=2, resolution="",overlay=true)
//study(title="Rsi 30 cross", shorttitle="rsi 30,10", overlay=true, resolution="")
len = input(10, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)

offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
//plot(up, color=color.blue, title="Entry", offset=offset)
//plot(down, color=color.green, title="Target", offset=offset)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
chdown = 0.000
chup = 0.000
chdownf = 0.000
chupf = 0.000
chdowns = 0.000
chups = 0.000

if rsi > 30
    chdown := chdown+ (up *(len-1)/0.428)-(down * (len-1))
else 
    chup := chup+ (0.428*(down*(len-1)))-(up * (len-1))

x = close -chdown +chup





if rsi > 40
    chdownf := chdownf + (up *(len-1)/0.6666)-(down * (len-1))
else 
    chupf := chupf + (0.6666*(down*(len-1)))-(up * (len-1))

xf = close -chdownf +chupf

if rsi > 70
    chdowns := chdowns + (up *(len-1)/2.33333)-(down * (len-1))
else 
    chups := chups + (2.33333*(down*(len-1)))-(up * (len-1))

xs = close -chdowns +chups




plot(x, color=color.red, title="Stop loss", offset=offset)
plot(xf, color=color.blue, title="Stop loss", offset=offset)
plot(xs, color=color.green, title="Stop loss", offset=offset)

len1 = input(200, minval=1, title="Length")
src1 = input(close, title="Source")

out = sma(src1, len1)
plot(out, color=color.black, title="MA", offset=offset)

pivot = (high + low + close) / 3.0
BC = (high + low) / 2 //Below Central povit
TC = (pivot - BC) + pivot //Top Central povot
bc = (high + low) / 2.0
tc = (pivot - bc) + pivot
R1 = (2*pivot) - low
S1 = (2*pivot) - high
R2 = pivot + ( high - low)
S2 = pivot - ( high - low)

sw = input(false, title="Show Weekly Pivots?")

wtime_pvt = security(syminfo.tickerid, 'W', pivot[1], lookahead=barmerge.lookahead_on)
wtime_R1 = security(syminfo.tickerid, 'W', R1[1], lookahead=barmerge.lookahead_on)
wtime_S1 = security(syminfo.tickerid, 'W', S1[1], lookahead=barmerge.lookahead_on)

plot(sw and wtime_pvt ? wtime_pvt : na, title="Weekly pvt",style= plot.style_line, color=color.fuchsia,linewidth=1)
plot(sw and wtime_R1 ? wtime_R1 : na, title="Weekly R1",style= plot.style_line, color=color.fuchsia,linewidth=1)
plot(sw and wtime_S1 ? wtime_S1 : na, title="Weekly S1",style=plot.style_line, color=color.fuchsia,linewidth=1)

sm = input(false, title="Show Monthly Pivots?")

mtime_pvt = security(syminfo.tickerid, 'M', pivot[1], lookahead=barmerge.lookahead_on)
mtime_R1 = security(syminfo.tickerid, 'M', R1[1], lookahead=barmerge.lookahead_on)
mtime_S1 = security(syminfo.tickerid, 'M', S1[1], lookahead=barmerge.lookahead_on)


plot(sm and mtime_pvt ? mtime_pvt : na, title="Monthly pvt",style=plot.style_circles, color=color.lime,linewidth=2)
plot(sm and mtime_R1 ? mtime_R1 : na, title="Monthly R1",style=plot.style_circles, color=color.lime,linewidth=2)
plot(sm and mtime_S1 ? mtime_S1 : na, title="Monthly S1",style=plot.style_circles, color=color.lime,linewidth=2)


