# Ported to Indie from https://www.tradingview.com/script/xOm7jSPf-CM-RSI-2-Strategy-Lower-Indicator/ created by @ChrisMoody
# Based on Larry Connors RSI-2 Strategy - Lower RSI

# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.  
# If a copy of the MPL was not distributed with this file, you can obtain one at  
# <https://mozilla.org/MPL/2.0/>.

# indie:lang_version = 5
from indie import indicator, color, plot, level, band, line_style
from indie.algorithms import Rsi, Sma


@indicator('RSI-2')
@plot.line(line_width=4, title='RSI', id='#plot_0')
@level(100, line_width=3, line_color=color.AQUA, line_style=line_style.SOLID, title='Upper Line 100')
@level(0, line_width=3, line_color=color.AQUA, line_style=line_style.SOLID, title='Lower Line 0')
@level(90, line_width=3, line_color=color.AQUA, line_style=line_style.SOLID, title='Upper Line 90')
@level(10, line_width=3, line_color=color.AQUA, line_style=line_style.SOLID, title='Lower Line 10')
@band(10, 90, fill_color=color.SILVER(0.1))
def Main(self):
    rsi = Rsi.new(self.close, 2)[0]

    ma5 = Sma.new(self.close, 5)[0]
    ma200 = Sma.new(self.close, 200)[0]

    col = color.SILVER
    if self.close[0] > ma200 and self.close[0] < ma5 and rsi < 10:
        col = color.LIME
    elif self.close[0] < ma200 and self.close[0] > ma5 and rsi > 90:
        col = color.RED
    
    return plot.Line(rsi, color=col)
