Bottom catch strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © footlz

//@version=4
strategy("Bottom catch strategy", overlay=true)

v_len = input(20, title="Volume SMA Length")
mult = input(2)
rsi_len = input(20, title="RSI Length")
oversold = input(30, title="Oversold")
close_time = input(10, title="Close After")

v = volume
basis = sma(v, v_len)
dev = mult * stdev(v, v_len)
upper_volume = basis + dev

rsi = rsi(close, rsi_len)

long = v > upper_volume and rsi < oversold

strategy.entry("Long", true, when=long)

passed_time = 0.0
if strategy.position_size != 0
    passed_time := 1
else
    passed_time := 0

if strategy.position_size != 0 and strategy.position_size[1] != 0
    passed_time := passed_time[1] + 1

if passed_time >= close_time
    strategy.close_all()

// If want to enable plot, change overlay=false.
v_color = close >= close[1] ? color.new(#3eb370, 0) : color.new(#e9546b, 0)

// plot(v, title="volume", color=v_color, style=plot.style_columns)
// plot(upper_volume, title="Threshold", color=color.aqua)