Compound Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pcooma

//@version=5
indicator("Compound Indicator", shorttitle="Compound Indicator", overlay=true, precision = 5)
var     show         = input.string(title = "Show graph", options=['NONE','positive_signal','Volume Ocilator', 'Momentum Ocilator', 'Stochastic Indicator', 'RSI', 'MFI', 'RVI','BOP', 'SMA', 'EMA'], defval='NONE')  
hl_period = input.int(defval = 50,title = "look back period")
//Values for calculation

price_average_previous_bar = (open + close)/2
price_average_current_bar = (high+low)/2
volume_average = ta.sma(volume,100)
var float positive_signal = 0

//Volume Change Ocillator
var float cumVol = 0.
var float short = 0.0
var float long = 1.0
cumVol += nz(volume)
if barstate.islast and cumVol == 0
    runtime.error("No volume is provided by the data vendor.")
shortlen = input.int(5, minval=1, title = "Short Length of volume change ocillator", group = "Volume Change Ocillator")
longlen = input.int(200, minval=1, title = "Long Length of volume change ocillator", group = "Volume Change Ocillator")
cal_method_osc = input.string(title = "Calculation method of volume change ocillator is", options=['EMA', 'SMA'], defval='SMA', group = "Volume Change Ocillator")  
if cal_method_osc == 'SMA'
    short := ta.sma(volume, shortlen)
    long := ta.sma(volume, longlen)
else if cal_method_osc == 'EMA'
    short := ta.ema(volume, shortlen)
    long := ta.ema(volume, longlen)
osc = 100 * (short - long) / long

osc_crossunder_100 = ta.crossunder(osc,100)
osc_crossunder_200 = ta.crossunder(osc,200)
osc_crossunder_300 = ta.crossunder(osc,300)
osc_crossunder_400 = ta.crossunder(osc,400)
osc_crossunder_500 = ta.crossunder(osc,500)
osc_crossunder_600 = ta.crossunder(osc,600)
osc_crossunder_700 = ta.crossunder(osc,700)
osc_crossunder_800 = ta.crossunder(osc,800)
osc_crossunder_900 = ta.crossunder(osc,900)
osc_crossunder_1000 = ta.crossunder(osc,1000)

osc_crossover_100 = ta.crossover(osc,100)
osc_crossover_200 = ta.crossover(osc,200)
osc_crossover_300 = ta.crossover(osc,300)
osc_crossover_400 = ta.crossover(osc,400)
osc_crossover_500 = ta.crossover(osc,500)
osc_crossover_600 = ta.crossover(osc,600)
osc_crossover_700 = ta.crossover(osc,700)
osc_crossover_800 = ta.crossover(osc,800)
osc_crossover_900 = ta.crossover(osc,900)
osc_crossover_1000 = ta.crossover(osc,1000)

if open < close 
    if osc_crossover_100
        positive_signal := positive_signal + 1
    else if osc_crossunder_100
        positive_signal := positive_signal - 1
    else if osc_crossover_200
        positive_signal := positive_signal + 1
    else if osc_crossunder_200
        positive_signal := positive_signal - 1
    else if osc_crossover_300
        positive_signal := positive_signal + 1
    else if osc_crossunder_300
        positive_signal := positive_signal - 1
    else if osc_crossover_400
        positive_signal := positive_signal + 1
    else if osc_crossunder_400
        positive_signal := positive_signal - 1
    else if osc_crossover_500
        positive_signal := positive_signal + 1
    else if osc_crossunder_500
        positive_signal := positive_signal - 1
    else if osc_crossover_600
        positive_signal := positive_signal + 1
    else if osc_crossunder_600
        positive_signal := positive_signal - 1
    else if osc_crossover_700
        positive_signal := positive_signal + 1
    else if osc_crossunder_700
        positive_signal := positive_signal - 1
    else if osc_crossover_800
        positive_signal := positive_signal + 1
    else if osc_crossunder_800
        positive_signal := positive_signal - 1
    else if osc_crossover_900
        positive_signal := positive_signal + 1
    else if osc_crossunder_900
        positive_signal := positive_signal - 1
    else if osc_crossover_1000
        positive_signal := positive_signal + 1
    else if osc_crossunder_1000
        positive_signal := positive_signal - 1
else if open > close
    if osc_crossover_100
        positive_signal := positive_signal - 1
    else if osc_crossunder_100
        positive_signal := positive_signal + 1
    else if osc_crossover_200
        positive_signal := positive_signal - 1
    else if osc_crossunder_200
        positive_signal := positive_signal + 1
    else if osc_crossover_300
        positive_signal := positive_signal - 1
    else if osc_crossunder_300
        positive_signal := positive_signal + 1
    else if osc_crossover_400
        positive_signal := positive_signal - 1
    else if osc_crossunder_400
        positive_signal := positive_signal + 1
    else if osc_crossover_500
        positive_signal := positive_signal - 1
    else if osc_crossunder_500
        positive_signal := positive_signal + 1
    else if osc_crossover_600
        positive_signal := positive_signal - 1
    else if osc_crossunder_600
        positive_signal := positive_signal + 1
    else if osc_crossover_700
        positive_signal := positive_signal - 1
    else if osc_crossunder_700
        positive_signal := positive_signal + 1
    else if osc_crossover_800
        positive_signal := positive_signal - 1
    else if osc_crossunder_800
        positive_signal := positive_signal + 1
    else if osc_crossover_900
        positive_signal := positive_signal - 1
    else if osc_crossunder_900
        positive_signal := positive_signal + 1
    else if osc_crossover_1000
        positive_signal := positive_signal - 1
    else if osc_crossunder_1000
        positive_signal := positive_signal + 1

// Momemtum Ocillator
src_mom_10 = input(close, title = "Source of MOM - 10", group = "Momentun Ocillator")
lb_mom_10 = 10
momm_10 = ta.change(src_mom_10)
f1_10(m_10) => m_10 >= 0.0 ? m_10 : 0.0
f2_10(m_10) => m_10 >= 0.0 ? 0.0 : -m_10
m1_10 = f1_10(momm_10)
m2_10 = f2_10(momm_10)
sm1_10 = math.sum(m1_10, lb_mom_10)
sm2_10 = math.sum(m2_10, lb_mom_10)
percent_10(nom_10, div_10) => 100 * nom_10 / div_10
chandeMO_10 = percent_10(sm1_10-sm2_10, sm1_10+sm2_10)

src_mom_50 = input(close, title = "Source of MOM - 50", group = "Momentun Ocillator")
lb_mom_50 = 50
momm_50 = ta.change(src_mom_50)
f1_50(m_50) => m_50 >= 0.0 ? m_50 : 0.0
f2_50(m_50) => m_50 >= 0.0 ? 0.0 : -m_50
m1_50 = f1_50(momm_50)
m2_50 = f2_50(momm_50)
sm1_50 = math.sum(m1_50, lb_mom_50)
sm2_50 = math.sum(m2_50, lb_mom_50)
percent_50(nom_50, div_50) => 100 * nom_50 / div_50
chandeMO_50 = percent_50(sm1_50-sm2_50, sm1_50+sm2_50)

src_mom_100 = input(close, title = "Source of MOM - 100", group = "Momentun Ocillator")
lb_mom_100 = 100
momm_100 = ta.change(src_mom_100)
f1_100(m_100) => m_100 >= 0.0 ? m_100 : 0.0
f2_100(m_100) => m_100 >= 0.0 ? 0.0 : -m_100
m1_100 = f1_100(momm_100)
m2_100 = f2_100(momm_100)
sm1_100 = math.sum(m1_100, lb_mom_100)
sm2_100 = math.sum(m2_100, lb_mom_100)
percent_100(nom_100, div_100) => 100 * nom_100 / div_100
chandeMO_100 = percent_100(sm1_100-sm2_100, sm1_100+sm2_100)

src_mom_200 = input(close, title = "Source of MOM - 200", group = "Momentun Ocillator")
lb_mom_200 = 200
momm_200 = ta.change(src_mom_200)
f1_200(m_200) => m_200 >= 0.0 ? m_200 : 0.0
f2_200(m_200) => m_200 >= 0.0 ? 0.0 : -m_200
m1_200 = f1_200(momm_200)
m2_200 = f2_200(momm_200)
sm1_200 = math.sum(m1_200, lb_mom_200)
sm2_200 = math.sum(m2_200, lb_mom_200)
percent_200(nom_200, div_200) => 100 * nom_200 / div_200
chandeMO_200 = percent_200(sm1_200-sm2_200, sm1_200+sm2_200)

//MOM graphs cross over and cross under each other
mom_10_crossover_50 = ta.crossover(chandeMO_10,chandeMO_50)
mom_10_crossover_100 = ta.crossover(chandeMO_10,chandeMO_100)
mom_10_crossover_200 = ta.crossover(chandeMO_10,chandeMO_200)
mom_50_crossover_100 = ta.crossover(chandeMO_50,chandeMO_100)
mom_50_crossover_200 = ta.crossover(chandeMO_50,chandeMO_200)
mom_100_crossover_200 = ta.crossover(chandeMO_100,chandeMO_200)

mom_10_crossunder_50 = ta.crossunder(chandeMO_10,chandeMO_50)
mom_10_crossunder_100 = ta.crossunder(chandeMO_10,chandeMO_100)
mom_10_crossunder_200 = ta.crossunder(chandeMO_10,chandeMO_200)
mom_50_crossunder_100 = ta.crossunder(chandeMO_50,chandeMO_100)
mom_50_crossunder_200 = ta.crossunder(chandeMO_50,chandeMO_200)
mom_100_crossunder_200 = ta.crossunder(chandeMO_100,chandeMO_200)

if mom_10_crossover_50 or mom_10_crossover_100 or mom_10_crossover_200 or mom_50_crossover_100 or mom_50_crossover_200 or mom_100_crossover_200
    positive_signal := positive_signal + 1
if mom_10_crossunder_50 or mom_10_crossunder_100 or mom_10_crossunder_200 or mom_50_crossunder_100 or mom_50_crossunder_200 or mom_100_crossunder_200
    positive_signal := positive_signal - 1

//MOM cross over and cross under different values
mom_10_crossover_val_10 = ta.crossover(chandeMO_10,10)
mom_10_crossover_val_20 = ta.crossover(chandeMO_10,20)
mom_10_crossover_val_30 = ta.crossover(chandeMO_10,30)
mom_10_crossover_val_40 = ta.crossover(chandeMO_10,40)
mom_10_crossover_val_50 = ta.crossover(chandeMO_10,50)
mom_10_crossover_val_60 = ta.crossover(chandeMO_10,60)
mom_10_crossover_val_70 = ta.crossover(chandeMO_10,70)
mom_10_crossover_val_80 = ta.crossover(chandeMO_10,80)
mom_10_crossover_val_90 = ta.crossover(chandeMO_10,90)
mom_10_crossover_val_100 = ta.crossover(chandeMO_10,100)

mom_10_crossunder_val_10 = ta.crossunder(chandeMO_10,10)
mom_10_crossunder_val_20 = ta.crossunder(chandeMO_10,20)
mom_10_crossunder_val_30 = ta.crossunder(chandeMO_10,30)
mom_10_crossunder_val_40 = ta.crossunder(chandeMO_10,40)
mom_10_crossunder_val_50 = ta.crossunder(chandeMO_10,50)
mom_10_crossunder_val_60 = ta.crossunder(chandeMO_10,60)
mom_10_crossunder_val_70 = ta.crossunder(chandeMO_10,70)
mom_10_crossunder_val_80 = ta.crossunder(chandeMO_10,80)
mom_10_crossunder_val_90 = ta.crossunder(chandeMO_10,90)
mom_10_crossunder_val_100 = ta.crossunder(chandeMO_10,100)

mom_50_crossover_val_10 = ta.crossover(chandeMO_50,4)
mom_50_crossover_val_20 = ta.crossover(chandeMO_50,8)
mom_50_crossover_val_30 = ta.crossover(chandeMO_50,12)
mom_50_crossover_val_40 = ta.crossover(chandeMO_50,16)
mom_50_crossover_val_50 = ta.crossover(chandeMO_50,20)
mom_50_crossover_val_60 = ta.crossover(chandeMO_50,24)
mom_50_crossover_val_70 = ta.crossover(chandeMO_50,28)
mom_50_crossover_val_80 = ta.crossover(chandeMO_50,32)
mom_50_crossover_val_90 = ta.crossover(chandeMO_50,36)
mom_50_crossover_val_100 = ta.crossover(chandeMO_50,40)

mom_50_crossunder_val_10 = ta.crossunder(chandeMO_50,-4)
mom_50_crossunder_val_20 = ta.crossunder(chandeMO_50,-8)
mom_50_crossunder_val_30 = ta.crossunder(chandeMO_50,-12)
mom_50_crossunder_val_40 = ta.crossunder(chandeMO_50,-16)
mom_50_crossunder_val_50 = ta.crossunder(chandeMO_50,-20)
mom_50_crossunder_val_60 = ta.crossunder(chandeMO_50,-24)
mom_50_crossunder_val_70 = ta.crossunder(chandeMO_50,-28)
mom_50_crossunder_val_80 = ta.crossunder(chandeMO_50,-32)
mom_50_crossunder_val_90 = ta.crossunder(chandeMO_50,-36)
mom_50_crossunder_val_100 = ta.crossunder(chandeMO_50,-40)

mom_100_crossover_val_10 = ta.crossover(chandeMO_100,3.5)
mom_100_crossover_val_20 = ta.crossover(chandeMO_100,7.0)
mom_100_crossover_val_30 = ta.crossover(chandeMO_100,10.5)
mom_100_crossover_val_40 = ta.crossover(chandeMO_100,14.0)
mom_100_crossover_val_50 = ta.crossover(chandeMO_100,17.5)
mom_100_crossover_val_60 = ta.crossover(chandeMO_100,21.0)
mom_100_crossover_val_70 = ta.crossover(chandeMO_100,24.5)
mom_100_crossover_val_80 = ta.crossover(chandeMO_100,28.0)
mom_100_crossover_val_90 = ta.crossover(chandeMO_100,31.5)
mom_100_crossover_val_100 = ta.crossover(chandeMO_100,35)

mom_100_crossunder_val_10 = ta.crossunder(chandeMO_100,-3.5)
mom_100_crossunder_val_20 = ta.crossunder(chandeMO_100,-7)
mom_100_crossunder_val_30 = ta.crossunder(chandeMO_100,-10.5)
mom_100_crossunder_val_40 = ta.crossunder(chandeMO_100,-14)
mom_100_crossunder_val_50 = ta.crossunder(chandeMO_100,-17.5)
mom_100_crossunder_val_60 = ta.crossunder(chandeMO_100,-21)
mom_100_crossunder_val_70 = ta.crossunder(chandeMO_100,-24.5)
mom_100_crossunder_val_80 = ta.crossunder(chandeMO_100,-28)
mom_100_crossunder_val_90 = ta.crossunder(chandeMO_100,-31.5)
mom_100_crossunder_val_100 = ta.crossunder(chandeMO_100,-35)

mom_200_crossover_val_10 = ta.crossover(chandeMO_200,2)
mom_200_crossover_val_20 = ta.crossover(chandeMO_200,4)
mom_200_crossover_val_30 = ta.crossover(chandeMO_200,6)
mom_200_crossover_val_40 = ta.crossover(chandeMO_200,8)
mom_200_crossover_val_50 = ta.crossover(chandeMO_200,10)
mom_200_crossover_val_60 = ta.crossover(chandeMO_200,12)
mom_200_crossover_val_70 = ta.crossover(chandeMO_200,14)
mom_200_crossover_val_80 = ta.crossover(chandeMO_200,16)
mom_200_crossover_val_90 = ta.crossover(chandeMO_200,18)
mom_200_crossover_val_100 = ta.crossover(chandeMO_200,20)

mom_200_crossunder_val_10 = ta.crossunder(chandeMO_200,-2)
mom_200_crossunder_val_20 = ta.crossunder(chandeMO_200,-4)
mom_200_crossunder_val_30 = ta.crossunder(chandeMO_200,-6)
mom_200_crossunder_val_40 = ta.crossunder(chandeMO_200,-8)
mom_200_crossunder_val_50 = ta.crossunder(chandeMO_200,-10)
mom_200_crossunder_val_60 = ta.crossunder(chandeMO_200,-12)
mom_200_crossunder_val_70 = ta.crossunder(chandeMO_200,-14)
mom_200_crossunder_val_80 = ta.crossunder(chandeMO_200,-16)
mom_200_crossunder_val_90 = ta.crossunder(chandeMO_200,-18)
mom_200_crossunder_val_100 = ta.crossunder(chandeMO_200,-20)

if mom_10_crossover_val_10 or mom_10_crossover_val_20 or mom_10_crossover_val_30 or mom_10_crossover_val_40 or mom_10_crossover_val_50 or mom_10_crossover_val_60 or mom_10_crossover_val_70 or mom_10_crossover_val_80 or mom_10_crossover_val_90 or mom_10_crossover_val_100 or mom_50_crossover_val_10 or mom_50_crossover_val_20 or mom_50_crossover_val_30 or mom_50_crossover_val_40 or mom_50_crossover_val_50 or mom_50_crossover_val_60 or mom_50_crossover_val_70 or mom_50_crossover_val_80 or mom_50_crossover_val_90 or mom_50_crossover_val_100 or mom_100_crossover_val_10 or mom_100_crossover_val_20 or mom_100_crossover_val_30 or mom_100_crossover_val_40 or mom_100_crossover_val_50 or mom_100_crossover_val_60 or mom_100_crossover_val_70 or mom_100_crossover_val_80 or mom_100_crossover_val_90 or mom_100_crossover_val_100 or mom_200_crossover_val_10 or mom_200_crossover_val_20 or mom_200_crossover_val_30 or mom_200_crossover_val_40 or mom_200_crossover_val_50 or mom_200_crossover_val_60 or mom_200_crossover_val_70 or mom_200_crossover_val_80 or mom_200_crossover_val_90 or mom_200_crossover_val_100
    positive_signal := positive_signal + 1
if mom_10_crossunder_val_10 or mom_10_crossunder_val_20 or mom_10_crossunder_val_30 or mom_10_crossunder_val_40 or mom_10_crossunder_val_50 or mom_10_crossunder_val_60 or mom_10_crossunder_val_70 or mom_10_crossunder_val_80 or mom_10_crossunder_val_90 or mom_10_crossunder_val_100 or mom_50_crossunder_val_10 or mom_50_crossunder_val_20 or mom_50_crossunder_val_30 or mom_50_crossunder_val_40 or mom_50_crossunder_val_50 or mom_50_crossunder_val_60 or mom_50_crossunder_val_70 or mom_50_crossunder_val_80 or mom_50_crossunder_val_90 or mom_50_crossunder_val_100 or mom_100_crossunder_val_10 or mom_100_crossunder_val_20 or mom_100_crossunder_val_30 or mom_100_crossunder_val_40 or mom_100_crossunder_val_50 or mom_100_crossunder_val_60 or mom_100_crossunder_val_70 or mom_100_crossunder_val_80 or mom_100_crossunder_val_90 or mom_100_crossunder_val_100 or mom_200_crossunder_val_10 or mom_200_crossunder_val_20 or mom_200_crossunder_val_30 or mom_200_crossunder_val_40 or mom_200_crossunder_val_50 or mom_200_crossunder_val_60 or mom_200_crossunder_val_70 or mom_200_crossunder_val_80 or mom_200_crossunder_val_90 or mom_200_crossunder_val_100
    positive_signal := positive_signal - 1

//Stochastic Indicator
period_of_stoch_ind = input.string (title = "Look back period of stochastic indicator", options=['10', '50','100','200'], defval='100', group = "Stochastic Indicator")  

var int periodK = 0
var int smoothK = 0
var int periodD = 0

if period_of_stoch_ind == '10'
    periodK := 10
    smoothK := 1
    periodD := 3
else if period_of_stoch_ind == '50'
    periodK := 50
    smoothK := 5
    periodD := 5
else if period_of_stoch_ind == '100'
    periodK := 100
    smoothK := 10
    periodD := 10
else if period_of_stoch_ind == '200'
    periodK := 200
    smoothK := 10
    periodD := 10

k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

// Graphs crossover and cross under each other
k_10 = ta.sma(ta.stoch(close, high, low, 10), 1)
d_10 = ta.sma(k, 3)

k_50 = ta.sma(ta.stoch(close, high, low, 50), 5)
d_50 = ta.sma(k, 5)

k_100 = ta.sma(ta.stoch(close, high, low, 100), 10)
d_100 = ta.sma(k, 10)

k_200 = ta.sma(ta.stoch(close, high, low, 200), 10)
d_200 = ta.sma(k, 10)

k_10_crossover_k_50 = ta.crossover(k_10,k_50)
k_10_crossover_k_100 = ta.crossover(k_10,k_100)
k_10_crossover_k_200 = ta.crossover(k_10,k_200)
k_50_crossover_k_100 = ta.crossover(k_50,k_100)
k_50_crossover_k_200 = ta.crossover(k_50,k_200)
k_100_crossover_k_200 = ta.crossover(k_100,k_200)

k_10_crossunder_k_50 = ta.crossunder(k_10,k_50)
k_10_crossunder_k_100 = ta.crossunder(k_10,k_100)
k_10_crossunder_k_200 = ta.crossunder(k_10,k_200)
k_50_crossunder_k_100 = ta.crossunder(k_50,k_100)
k_50_crossunder_k_200 = ta.crossunder(k_50,k_200)
k_100_crossunder_k_200 = ta.crossunder(k_100,k_200)

// Values cross over each other
var bool stochastic_10_buy = false
var bool stochastic_50_buy = false
var bool stochastic_100_buy = false
var bool stochastic_200_buy = false

if k_10 >= d_10
    stochastic_10_buy := true
else 
    stochastic_10_buy := false

if k_50 >= d_50
    stochastic_50_buy := true
else 
    stochastic_50_buy := false
    
if k_100 >= d_100
    stochastic_100_buy := true
else 
    stochastic_100_buy := false
    
if k_200 >= d_200
    stochastic_200_buy := true
else 
    stochastic_200_buy := false
    
if k_10_crossover_k_50 or k_10_crossover_k_100 or k_10_crossover_k_200 or k_50_crossover_k_100 or k_50_crossover_k_200 or k_100_crossover_k_200
    positive_signal := positive_signal + 1
if k_10_crossunder_k_50 or k_10_crossunder_k_100 or k_10_crossunder_k_200 or k_50_crossunder_k_100 or k_50_crossunder_k_200 or k_100_crossunder_k_200
    positive_signal := positive_signal - 1

if stochastic_10_buy == true or stochastic_50_buy == true or stochastic_100_buy == true or stochastic_100_buy == true
    positive_signal := positive_signal + 1
if stochastic_10_buy == false or stochastic_50_buy == false or stochastic_100_buy == false or stochastic_100_buy == false
    positive_signal := positive_signal - 1

//Multi timeframe RSI
src_rsi_10 = input(close, title = "Source of RSI - 10", group = "Relative Strength Index (RSI)", inline = "10")
lb_rsi_10 = 10
rsi_10 = ta.rsi(src_rsi_10,lb_rsi_10)

src_rsi_50 = input(close, title = "Source of RSI - 50", group = "Relative Strength Index (RSI)", inline = "50")
lb_rsi_50 = 50
rsi_50 = ta.rsi(src_rsi_50,lb_rsi_50)

src_rsi_100 = input(close, title = "Source of RSI - 100", group = "Relative Strength Index (RSI)", inline = "100")
lb_rsi_100 = 100
rsi_100 = ta.rsi(src_rsi_100,lb_rsi_100)

src_rsi_200 = input(close, title = "Source of RSI - 200", group = "Relative Strength Index (RSI)", inline = "200")
lb_rsi_200 = 200
rsi_200 = ta.rsi(src_rsi_200,lb_rsi_200)

//RSI Graphs cross eachother
rsi_10_crossover_rsi_50 = ta.crossover(rsi_10,rsi_50)
rsi_10_crossover_rsi_100 = ta.crossover(rsi_10,rsi_100)
rsi_10_crossover_rsi_200 = ta.crossover(rsi_10,rsi_200)
rsi_50_crossover_rsi_100 = ta.crossover(rsi_50,rsi_100)
rsi_50_crossover_rsi_200 = ta.crossover(rsi_50,rsi_200)
rsi_100_crossover_rsi_200 = ta.crossover(rsi_100,rsi_200)

rsi_10_crossunder_rsi_50 = ta.crossunder(rsi_10,rsi_50)
rsi_10_crossunder_rsi_100 = ta.crossunder(rsi_10,rsi_100)
rsi_10_crossunder_rsi_200 = ta.crossunder(rsi_10,rsi_200)
rsi_50_crossunder_rsi_100 = ta.crossunder(rsi_50,rsi_100)
rsi_50_crossunder_rsi_200 = ta.crossunder(rsi_50,rsi_200)
rsi_100_crossunder_rsi_200 = ta.crossunder(rsi_100,rsi_200)

if rsi_10_crossover_rsi_50 or rsi_10_crossover_rsi_100 or rsi_10_crossover_rsi_200 or rsi_50_crossover_rsi_100 or rsi_50_crossover_rsi_200 or rsi_100_crossover_rsi_200
    positive_signal := positive_signal + 1
if rsi_10_crossunder_rsi_50 or rsi_10_crossunder_rsi_100 or rsi_10_crossunder_rsi_200 or rsi_50_crossunder_rsi_100 or rsi_50_crossunder_rsi_200 or rsi_100_crossunder_rsi_200
    positive_signal := positive_signal - 1

//RSI crossing different values

rsi_10_crossover_val_0 = ta.cross(rsi_10,0)
rsi_10_crossover_val_10 = ta.crossover(rsi_10,10)
rsi_10_crossover_val_20 = ta.crossover(rsi_10,20)
rsi_10_crossover_val_30 = ta.crossover(rsi_10,30)
rsi_10_crossover_val_40 = ta.crossover(rsi_10,40)
rsi_10_crossover_val_50 = ta.crossover(rsi_10,50)
rsi_10_crossover_val_60 = ta.crossover(rsi_10,60)
rsi_10_crossover_val_70 = ta.crossover(rsi_10,70)
rsi_10_crossover_val_80 = ta.crossover(rsi_10,80)
rsi_10_crossover_val_90 = ta.crossover(rsi_10,90)
rsi_10_crossover_val_100 = ta.cross(rsi_10,100)

rsi_10_crossunder_val_0 = ta.cross(rsi_10,0)
rsi_10_crossunder_val_10 = ta.crossunder(rsi_10,10)
rsi_10_crossunder_val_20 = ta.crossunder(rsi_10,20)
rsi_10_crossunder_val_30 = ta.crossunder(rsi_10,30)
rsi_10_crossunder_val_40 = ta.crossunder(rsi_10,40)
rsi_10_crossunder_val_50 = ta.crossunder(rsi_10,50)
rsi_10_crossunder_val_60 = ta.crossunder(rsi_10,60)
rsi_10_crossunder_val_70 = ta.crossunder(rsi_10,70)
rsi_10_crossunder_val_80 = ta.crossunder(rsi_10,80)
rsi_10_crossunder_val_90 = ta.crossunder(rsi_10,90)
rsi_10_crossunder_val_100 = ta.cross(rsi_10,100)

if rsi_10_crossover_val_0 or rsi_10_crossover_val_10 or rsi_10_crossover_val_20 or rsi_10_crossover_val_30 or rsi_10_crossover_val_40 or rsi_10_crossover_val_50 or rsi_10_crossover_val_60 or rsi_10_crossover_val_70 or rsi_10_crossover_val_80 or rsi_10_crossover_val_90 or rsi_10_crossover_val_100
    positive_signal := positive_signal + 1
if rsi_10_crossunder_val_0 or rsi_10_crossunder_val_10 or rsi_10_crossunder_val_20 or rsi_10_crossunder_val_30 or rsi_10_crossunder_val_40 or rsi_10_crossunder_val_50 or rsi_10_crossunder_val_60 or rsi_10_crossunder_val_70 or rsi_10_crossunder_val_80 or rsi_10_crossunder_val_90 or rsi_10_crossunder_val_100
    positive_signal := positive_signal - 1

rsi_50_crossover_val_75 = ta.crossover(rsi_50,75)
rsi_50_crossover_val_70 = ta.crossover(rsi_50,70)
rsi_50_crossover_val_65 = ta.crossover(rsi_50,65)
rsi_50_crossover_val_60 = ta.crossover(rsi_50,60)
rsi_50_crossover_val_55 = ta.crossover(rsi_50,55)
rsi_50_crossover_val_50 = ta.crossover(rsi_50,50)
rsi_50_crossover_val_45 = ta.crossover(rsi_50,45)
rsi_50_crossover_val_40 = ta.crossover(rsi_50,40)
rsi_50_crossover_val_35 = ta.crossover(rsi_50,35)
rsi_50_crossover_val_30 = ta.crossover(rsi_50,30)
rsi_50_crossover_val_25 = ta.crossover(rsi_50,25)

rsi_50_crossunder_val_75 = ta.crossunder(rsi_50,75)
rsi_50_crossunder_val_70 = ta.crossunder(rsi_50,70)
rsi_50_crossunder_val_65 = ta.crossunder(rsi_50,65)
rsi_50_crossunder_val_60 = ta.crossunder(rsi_50,60)
rsi_50_crossunder_val_55 = ta.crossunder(rsi_50,55)
rsi_50_crossunder_val_50 = ta.crossunder(rsi_50,50)
rsi_50_crossunder_val_45 = ta.crossunder(rsi_50,45)
rsi_50_crossunder_val_40 = ta.crossunder(rsi_50,40)
rsi_50_crossunder_val_35 = ta.crossunder(rsi_50,35)
rsi_50_crossunder_val_30 = ta.crossunder(rsi_50,30)
rsi_50_crossunder_val_25 = ta.crossunder(rsi_50,25)

if rsi_50_crossover_val_75 or rsi_50_crossover_val_70 or rsi_50_crossover_val_65 or rsi_50_crossover_val_60 or rsi_50_crossover_val_55 or rsi_50_crossover_val_50 or rsi_50_crossover_val_45 or rsi_50_crossover_val_40 or rsi_50_crossover_val_35 or rsi_50_crossover_val_30 or rsi_50_crossover_val_25
    positive_signal := positive_signal + 1
if rsi_50_crossunder_val_75 or rsi_50_crossunder_val_70 or rsi_50_crossunder_val_65 or rsi_50_crossunder_val_60 or rsi_50_crossunder_val_55 or rsi_50_crossunder_val_50 or rsi_50_crossunder_val_45 or rsi_50_crossunder_val_40 or rsi_50_crossunder_val_35 or rsi_50_crossunder_val_30 or rsi_50_crossunder_val_25
    positive_signal := positive_signal - 1

rsi_100_crossover_val_65 = ta.crossover(rsi_100,65)
rsi_100_crossover_val_62 = ta.crossover(rsi_100,62)
rsi_100_crossover_val_59 = ta.crossover(rsi_100,59)
rsi_100_crossover_val_56 = ta.crossover(rsi_100,56)
rsi_100_crossover_val_53 = ta.crossover(rsi_100,53)
rsi_100_crossover_val_50 = ta.crossover(rsi_100,50)
rsi_100_crossover_val_47 = ta.crossover(rsi_100,47)
rsi_100_crossover_val_44 = ta.crossover(rsi_100,44)
rsi_100_crossover_val_41 = ta.crossover(rsi_100,41)
rsi_100_crossover_val_38 = ta.crossover(rsi_100,38)
rsi_100_crossover_val_35 = ta.crossover(rsi_100,35)

rsi_100_crossunder_val_65 = ta.crossunder(rsi_100,65)
rsi_100_crossunder_val_62 = ta.crossunder(rsi_100,62)
rsi_100_crossunder_val_59 = ta.crossunder(rsi_100,59)
rsi_100_crossunder_val_56 = ta.crossunder(rsi_100,56)
rsi_100_crossunder_val_53 = ta.crossunder(rsi_100,53)
rsi_100_crossunder_val_50 = ta.crossunder(rsi_100,50)
rsi_100_crossunder_val_47 = ta.crossunder(rsi_100,47)
rsi_100_crossunder_val_44 = ta.crossunder(rsi_100,44)
rsi_100_crossunder_val_41 = ta.crossunder(rsi_100,41)
rsi_100_crossunder_val_38 = ta.crossunder(rsi_100,38)
rsi_100_crossunder_val_35 = ta.crossunder(rsi_100,35)

if rsi_100_crossover_val_65 or rsi_100_crossover_val_62 or rsi_100_crossover_val_59 or rsi_100_crossover_val_56 or rsi_100_crossover_val_53 or rsi_100_crossover_val_50 or rsi_100_crossover_val_47 or rsi_100_crossover_val_44 or rsi_100_crossover_val_41 or rsi_100_crossover_val_38 or rsi_100_crossover_val_35
    positive_signal := positive_signal + 1
if rsi_100_crossunder_val_65 or rsi_100_crossunder_val_62 or rsi_100_crossunder_val_59 or rsi_100_crossunder_val_56 or rsi_100_crossunder_val_53 or rsi_100_crossunder_val_50 or rsi_100_crossunder_val_47 or rsi_100_crossunder_val_44 or rsi_100_crossunder_val_41 or rsi_100_crossunder_val_38 or rsi_100_crossunder_val_35
    positive_signal := positive_signal - 1

rsi_200_crossover_val_60 = ta.crossover(rsi_200,60)
rsi_200_crossover_val_58 = ta.crossover(rsi_200,58)
rsi_200_crossover_val_56 = ta.crossover(rsi_200,56)
rsi_200_crossover_val_54 = ta.crossover(rsi_200,54)
rsi_200_crossover_val_52 = ta.crossover(rsi_200,52)
rsi_200_crossover_val_50 = ta.crossover(rsi_200,50)
rsi_200_crossover_val_48 = ta.crossover(rsi_200,48)
rsi_200_crossover_val_46 = ta.crossover(rsi_200,46)
rsi_200_crossover_val_44 = ta.crossover(rsi_200,44)
rsi_200_crossover_val_42 = ta.crossover(rsi_200,42)
rsi_200_crossover_val_40 = ta.crossover(rsi_200,40)

rsi_200_crossunder_val_60 = ta.crossunder(rsi_200,60)
rsi_200_crossunder_val_58 = ta.crossunder(rsi_200,58)
rsi_200_crossunder_val_56 = ta.crossunder(rsi_200,56)
rsi_200_crossunder_val_54 = ta.crossunder(rsi_200,54)
rsi_200_crossunder_val_52 = ta.crossunder(rsi_200,52)
rsi_200_crossunder_val_50 = ta.crossunder(rsi_200,50)
rsi_200_crossunder_val_48 = ta.crossunder(rsi_200,48)
rsi_200_crossunder_val_46 = ta.crossunder(rsi_200,46)
rsi_200_crossunder_val_44 = ta.crossunder(rsi_200,44)
rsi_200_crossunder_val_42 = ta.crossunder(rsi_200,42)
rsi_200_crossunder_val_40 = ta.crossunder(rsi_200,40)

if rsi_200_crossover_val_60 or rsi_200_crossover_val_58 or rsi_200_crossover_val_56 or rsi_200_crossover_val_54 or rsi_200_crossover_val_52 or rsi_200_crossover_val_50 or rsi_200_crossover_val_48 or rsi_200_crossover_val_46 or rsi_200_crossover_val_44 or rsi_200_crossover_val_42 or rsi_200_crossover_val_40
    positive_signal := positive_signal + 1
if rsi_200_crossunder_val_60 or rsi_200_crossunder_val_58 or rsi_200_crossunder_val_56 or rsi_200_crossunder_val_54 or rsi_200_crossunder_val_52 or rsi_200_crossunder_val_50 or rsi_200_crossunder_val_48 or rsi_200_crossunder_val_46 or rsi_200_crossunder_val_44 or rsi_200_crossunder_val_42 or rsi_200_crossunder_val_40
    positive_signal := positive_signal - 1

//Multi timeframe money flow index (MFI)
src_mfi_10 = input(close, title = "Source of MFI - 10", group = "Money Flow Index (MFI)", inline = "10")
lb_mfi_10 = 10
mfi_10 = ta.mfi(src_mfi_10,lb_mfi_10)

src_mfi_50 = input(close, title = "Source of MFI - 50", group = "Money Flow Index (MFI)", inline = "50")
lb_mfi_50 = 50
mfi_50 = ta.mfi(src_mfi_50,lb_mfi_50)

src_mfi_100 = input(close, title = "Source of MFI - 100", group = "Money Flow Index (MFI)", inline = "100")
lb_mfi_100 = 100
mfi_100 = ta.mfi(src_mfi_100,lb_mfi_100)

src_mfi_200 = input(close, title = "Source of MFI - 200", group = "Money Flow Index (MFI)", inline = "200")
lb_mfi_200 = 200
mfi_200 = ta.mfi(src_mfi_200,lb_mfi_200)

//MFI Crossing over and under each other
mfi_10_crossover_mfi_50 = ta.crossover(mfi_10,mfi_50)
mfi_10_crossover_mfi_100 = ta.crossover(mfi_10,mfi_100)
mfi_10_crossover_mfi_200 = ta.crossover(mfi_10,mfi_200)
mfi_50_crossover_mfi_100 = ta.crossover(mfi_50,mfi_100)
mfi_50_crossover_mfi_200 = ta.crossover(mfi_50,mfi_200)
mfi_100_crossover_mfi_200 = ta.crossover(mfi_100,mfi_200)

mfi_10_crossunder_mfi_50 = ta.crossunder(mfi_10,mfi_50)
mfi_10_crossunder_mfi_100 = ta.crossunder(mfi_10,mfi_100)
mfi_10_crossunder_mfi_200 = ta.crossunder(mfi_10,mfi_200)
mfi_50_crossunder_mfi_100 = ta.crossunder(mfi_50,mfi_100)
mfi_50_crossunder_mfi_200 = ta.crossunder(mfi_50,mfi_200)
mfi_100_crossunder_mfi_200 = ta.crossunder(mfi_100,mfi_200)

if mfi_10_crossover_mfi_50 or mfi_10_crossover_mfi_100 or mfi_10_crossover_mfi_200 or mfi_50_crossover_mfi_100 or mfi_50_crossover_mfi_200 or mfi_100_crossover_mfi_200
    positive_signal := positive_signal + 1
if mfi_10_crossunder_mfi_50 or mfi_10_crossunder_mfi_100 or mfi_10_crossunder_mfi_200 or mfi_50_crossunder_mfi_100 or mfi_50_crossunder_mfi_200 or mfi_100_crossunder_mfi_200
    positive_signal := positive_signal - 1

//Valued cross over & under
mfi_10_crossover_val_0 = ta.cross(mfi_10,0)
mfi_10_crossover_val_10 = ta.crossover(mfi_10,10)
mfi_10_crossover_val_20 = ta.crossover(mfi_10,20)
mfi_10_crossover_val_30 = ta.crossover(mfi_10,30)
mfi_10_crossover_val_40 = ta.crossover(mfi_10,40)
mfi_10_crossover_val_50 = ta.crossover(mfi_10,50)
mfi_10_crossover_val_60 = ta.crossover(mfi_10,60)
mfi_10_crossover_val_70 = ta.crossover(mfi_10,70)
mfi_10_crossover_val_80 = ta.crossover(mfi_10,80)
mfi_10_crossover_val_90 = ta.crossover(mfi_10,90)
mfi_10_crossover_val_100 = ta.cross(mfi_10,100)

mfi_10_crossunder_val_0 = ta.cross(mfi_10,0)
mfi_10_crossunder_val_10 = ta.crossunder(mfi_10,10)
mfi_10_crossunder_val_20 = ta.crossunder(mfi_10,20)
mfi_10_crossunder_val_30 = ta.crossunder(mfi_10,30)
mfi_10_crossunder_val_40 = ta.crossunder(mfi_10,40)
mfi_10_crossunder_val_50 = ta.crossunder(mfi_10,50)
mfi_10_crossunder_val_60 = ta.crossunder(mfi_10,60)
mfi_10_crossunder_val_70 = ta.crossunder(mfi_10,70)
mfi_10_crossunder_val_80 = ta.crossunder(mfi_10,80)
mfi_10_crossunder_val_90 = ta.crossunder(mfi_10,90)
mfi_10_crossunder_val_100 = ta.cross(mfi_10,100)

if mfi_10_crossover_val_0 or mfi_10_crossover_val_10 or mfi_10_crossover_val_20 or mfi_10_crossover_val_30 or mfi_10_crossover_val_40 or mfi_10_crossover_val_50 or mfi_10_crossover_val_60 or mfi_10_crossover_val_70 or mfi_10_crossover_val_80 or mfi_10_crossover_val_90 or mfi_10_crossover_val_100
    positive_signal := positive_signal + 1
if mfi_10_crossunder_val_0 or mfi_10_crossunder_val_10 or mfi_10_crossunder_val_20 or mfi_10_crossunder_val_30 or mfi_10_crossunder_val_40 or mfi_10_crossunder_val_50 or mfi_10_crossunder_val_60 or mfi_10_crossunder_val_70 or mfi_10_crossunder_val_80 or mfi_10_crossunder_val_90 or mfi_10_crossunder_val_100
    positive_signal := positive_signal - 1

mfi_50_crossover_val_90 = ta.crossover(mfi_50,90)
mfi_50_crossover_val_82 = ta.crossover(mfi_50,82)
mfi_50_crossover_val_74 = ta.crossover(mfi_50,74)
mfi_50_crossover_val_66 = ta.crossover(mfi_50,66)
mfi_50_crossover_val_58 = ta.crossover(mfi_50,58)
mfi_50_crossover_val_50 = ta.crossover(mfi_50,50)
mfi_50_crossover_val_42 = ta.crossover(mfi_50,42)
mfi_50_crossover_val_34 = ta.crossover(mfi_50,34)
mfi_50_crossover_val_26 = ta.crossover(mfi_50,26)
mfi_50_crossover_val_18 = ta.crossover(mfi_50,18)
mfi_50_crossover_val_10 = ta.crossover(mfi_50,10)

mfi_50_crossunder_val_90 = ta.crossunder(mfi_50,90)
mfi_50_crossunder_val_82 = ta.crossunder(mfi_50,82)
mfi_50_crossunder_val_74 = ta.crossunder(mfi_50,74)
mfi_50_crossunder_val_66 = ta.crossunder(mfi_50,66)
mfi_50_crossunder_val_58 = ta.crossunder(mfi_50,58)
mfi_50_crossunder_val_50 = ta.crossunder(mfi_50,50)
mfi_50_crossunder_val_42 = ta.crossunder(mfi_50,42)
mfi_50_crossunder_val_34 = ta.crossunder(mfi_50,34)
mfi_50_crossunder_val_26 = ta.crossunder(mfi_50,26)
mfi_50_crossunder_val_18 = ta.crossunder(mfi_50,18)
mfi_50_crossunder_val_10 = ta.crossunder(mfi_50,10)

if mfi_50_crossover_val_90 or mfi_50_crossover_val_82 or mfi_50_crossover_val_74 or mfi_50_crossover_val_66 or mfi_50_crossover_val_58 or mfi_50_crossover_val_50 or mfi_50_crossover_val_42 or mfi_50_crossover_val_34 or mfi_50_crossover_val_26 or mfi_50_crossover_val_18 or mfi_50_crossover_val_10
    positive_signal := positive_signal + 1
if mfi_50_crossunder_val_90 or mfi_50_crossunder_val_82 or mfi_50_crossunder_val_74 or mfi_50_crossunder_val_66 or mfi_50_crossunder_val_58 or mfi_50_crossunder_val_50 or mfi_50_crossunder_val_42 or mfi_50_crossunder_val_34 or mfi_50_crossunder_val_26 or mfi_50_crossunder_val_18 or mfi_50_crossunder_val_10
    positive_signal := positive_signal - 1

mfi_100_crossover_val_85 = ta.crossover(mfi_100,85)
mfi_100_crossover_val_78 = ta.crossover(mfi_100,78)
mfi_100_crossover_val_71 = ta.crossover(mfi_100,71)
mfi_100_crossover_val_64 = ta.crossover(mfi_100,64)
mfi_100_crossover_val_57 = ta.crossover(mfi_100,57)
mfi_100_crossover_val_50 = ta.crossover(mfi_100,50)
mfi_100_crossover_val_43 = ta.crossover(mfi_100,43)
mfi_100_crossover_val_36 = ta.crossover(mfi_100,36)
mfi_100_crossover_val_29 = ta.crossover(mfi_100,29)
mfi_100_crossover_val_22 = ta.crossover(mfi_100,22)
mfi_100_crossover_val_15 = ta.crossover(mfi_100,15)

mfi_100_crossunder_val_85 = ta.crossunder(mfi_100,85)
mfi_100_crossunder_val_78 = ta.crossunder(mfi_100,78)
mfi_100_crossunder_val_71 = ta.crossunder(mfi_100,71)
mfi_100_crossunder_val_64 = ta.crossunder(mfi_100,64)
mfi_100_crossunder_val_57 = ta.crossunder(mfi_100,57)
mfi_100_crossunder_val_50 = ta.crossunder(mfi_100,50)
mfi_100_crossunder_val_43 = ta.crossunder(mfi_100,43)
mfi_100_crossunder_val_36 = ta.crossunder(mfi_100,36)
mfi_100_crossunder_val_29 = ta.crossunder(mfi_100,29)
mfi_100_crossunder_val_22 = ta.crossunder(mfi_100,22)
mfi_100_crossunder_val_15 = ta.crossunder(mfi_100,15)

if mfi_100_crossover_val_85 or mfi_100_crossover_val_78 or mfi_100_crossover_val_71 or mfi_100_crossover_val_64 or mfi_100_crossover_val_57 or mfi_100_crossover_val_50 or mfi_100_crossover_val_43 or mfi_100_crossover_val_36 or mfi_100_crossover_val_29 or mfi_100_crossover_val_22 or mfi_100_crossover_val_15
    positive_signal := positive_signal + 1
if mfi_100_crossunder_val_85 or mfi_100_crossunder_val_78 or mfi_100_crossunder_val_71 or mfi_100_crossunder_val_64 or mfi_100_crossunder_val_57 or mfi_100_crossunder_val_50 or mfi_100_crossunder_val_43 or mfi_100_crossunder_val_36 or mfi_100_crossunder_val_29 or mfi_100_crossunder_val_22 or mfi_100_crossunder_val_15
    positive_signal := positive_signal - 1

mfi_200_crossover_val_80 = ta.crossover(mfi_200,80)
mfi_200_crossover_val_74 = ta.crossover(mfi_200,74)
mfi_200_crossover_val_68 = ta.crossover(mfi_200,68)
mfi_200_crossover_val_62 = ta.crossover(mfi_200,62)
mfi_200_crossover_val_56 = ta.crossover(mfi_200,56)
mfi_200_crossover_val_50 = ta.crossover(mfi_200,50)
mfi_200_crossover_val_44 = ta.crossover(mfi_200,44)
mfi_200_crossover_val_38 = ta.crossover(mfi_200,38)
mfi_200_crossover_val_32 = ta.crossover(mfi_200,32)
mfi_200_crossover_val_26 = ta.crossover(mfi_200,26)
mfi_200_crossover_val_20 = ta.crossover(mfi_200,20)

mfi_200_crossunder_val_80 = ta.crossunder(mfi_200,80)
mfi_200_crossunder_val_74 = ta.crossunder(mfi_200,74)
mfi_200_crossunder_val_68 = ta.crossunder(mfi_200,68)
mfi_200_crossunder_val_62 = ta.crossunder(mfi_200,62)
mfi_200_crossunder_val_56 = ta.crossunder(mfi_200,56)
mfi_200_crossunder_val_50 = ta.crossunder(mfi_200,50)
mfi_200_crossunder_val_44 = ta.crossunder(mfi_200,44)
mfi_200_crossunder_val_38 = ta.crossunder(mfi_200,38)
mfi_200_crossunder_val_32 = ta.crossunder(mfi_200,32)
mfi_200_crossunder_val_26 = ta.crossunder(mfi_200,26)
mfi_200_crossunder_val_20 = ta.crossunder(mfi_200,20)

if mfi_200_crossover_val_80 or mfi_200_crossover_val_74 or mfi_200_crossover_val_68 or mfi_200_crossover_val_62 or mfi_200_crossover_val_56 or mfi_200_crossover_val_50 or mfi_200_crossover_val_44 or mfi_200_crossover_val_38 or mfi_200_crossover_val_32 or mfi_200_crossover_val_26 or mfi_200_crossover_val_20
    positive_signal := positive_signal + 1
if mfi_200_crossunder_val_80 or mfi_200_crossunder_val_74 or mfi_200_crossunder_val_68 or mfi_200_crossunder_val_62 or mfi_200_crossunder_val_56 or mfi_200_crossunder_val_50 or mfi_200_crossunder_val_44 or mfi_200_crossunder_val_38 or mfi_200_crossunder_val_32 or mfi_200_crossunder_val_26 or mfi_200_crossunder_val_20
    positive_signal := positive_signal - 1
    
//Multi timeframe relative volatility index (RVI)
src_rvi_10 = input(close,title = "Source of RVI-10 is",  group = "Revative Volatility Index (RVI)",  inline = '10')
lb_rvi_10 = 10
cal_method_rvi_10 = input.string(title = "& calculation method is", options=['EMA', 'SMA'], defval='EMA', group = "Revative Volatility Index (RVI)",  inline = '10')  
stddev_rvi_10 = ta.stdev(src_rvi_10, lb_rvi_10)
var float upper_rvi_10 = 0
var float lower_rvi_10 = 0
if cal_method_rvi_10 == "EMA"
    upper_rvi_10 := ta.ema(ta.change(src_rvi_10) <= 0 ? 0 : stddev_rvi_10, lb_rvi_10)
    lower_rvi_10 := ta.ema(ta.change(src_rvi_10) > 0 ? 0 : stddev_rvi_10, lb_rvi_10)
else if cal_method_rvi_10 == "SMA"
    upper_rvi_10 := ta.sma(ta.change(src_rvi_10) <= 0 ? 0 : stddev_rvi_10, lb_rvi_10)
    lower_rvi_10 := ta.sma(ta.change(src_rvi_10) > 0 ? 0 : stddev_rvi_10, lb_rvi_10)
rvi_10 = upper_rvi_10 / (upper_rvi_10 + lower_rvi_10) * 100

src_rvi_50 = input(close,title = "Source of RVI-50 is",  group = "Revative Volatility Index (RVI)",  inline = '50')
lb_rvi_50 = 50
cal_method_rvi_50 = input.string(title = "& calculation method is", options=['EMA', 'SMA'], defval='EMA', group = "Revative Volatility Index (RVI)",  inline = '50')  
stddev_rvi_50 = ta.stdev(src_rvi_50, lb_rvi_50)
var float upper_rvi_50 = 0
var float lower_rvi_50 = 0
if cal_method_rvi_50 == "EMA"
    upper_rvi_50 := ta.ema(ta.change(src_rvi_50) <= 0 ? 0 : stddev_rvi_50, lb_rvi_50)
    lower_rvi_50 := ta.ema(ta.change(src_rvi_50) > 0 ? 0 : stddev_rvi_50, lb_rvi_50)
else if cal_method_rvi_50 == "SMA"
    upper_rvi_50 := ta.sma(ta.change(src_rvi_50) <= 0 ? 0 : stddev_rvi_50, lb_rvi_50)
    lower_rvi_50 := ta.sma(ta.change(src_rvi_50) > 0 ? 0 : stddev_rvi_50, lb_rvi_50)
rvi_50 = upper_rvi_50 / (upper_rvi_50 + lower_rvi_50) * 100

src_rvi_100 = input(close,title = "Source of RVI-100 is",  group = "Revative Volatility Index (RVI)",  inline = '100')
lb_rvi_100 = 100
cal_method_rvi_100 = input.string(title = "& calculation method is", options=['EMA', 'SMA'], defval='EMA', group = "Revative Volatility Index (RVI)",  inline = '100')  
stddev_rvi_100 = ta.stdev(src_rvi_100, lb_rvi_100)
var float upper_rvi_100 = 0
var float lower_rvi_100 = 0
if cal_method_rvi_100 == "EMA"
    upper_rvi_100 := ta.ema(ta.change(src_rvi_100) <= 0 ? 0 : stddev_rvi_100, lb_rvi_100)
    lower_rvi_100 := ta.ema(ta.change(src_rvi_100) > 0 ? 0 : stddev_rvi_100, lb_rvi_100)
else if cal_method_rvi_100 == "SMA"
    upper_rvi_100 := ta.sma(ta.change(src_rvi_100) <= 0 ? 0 : stddev_rvi_100, lb_rvi_100)
    lower_rvi_100 := ta.sma(ta.change(src_rvi_100) > 0 ? 0 : stddev_rvi_100, lb_rvi_100)
rvi_100 = upper_rvi_100 / (upper_rvi_100 + lower_rvi_100) * 100


src_rvi_200 = input(close,title = "Source of RVI-200 is",  group = "Revative Volatility Index (RVI)",  inline = '200')
lb_rvi_200 = 200
cal_method_rvi_200 = input.string(title = "& calculation method is", options=['EMA', 'SMA'], defval='EMA', group = "Revative Volatility Index (RVI)",  inline = '200')  
stddev_rvi_200 = ta.stdev(src_rvi_200, lb_rvi_200)
var float upper_rvi_200 = 0
var float lower_rvi_200 = 0
if cal_method_rvi_200 == "EMA"
    upper_rvi_200 := ta.ema(ta.change(src_rvi_200) <= 0 ? 0 : stddev_rvi_200, lb_rvi_200)
    lower_rvi_200 := ta.ema(ta.change(src_rvi_200) > 0 ? 0 : stddev_rvi_200, lb_rvi_200)
else if cal_method_rvi_200 == "SMA"
    upper_rvi_200 := ta.sma(ta.change(src_rvi_200) <= 0 ? 0 : stddev_rvi_200, lb_rvi_200)
    lower_rvi_200 := ta.sma(ta.change(src_rvi_200) > 0 ? 0 : stddev_rvi_200, lb_rvi_200)
rvi_200 = upper_rvi_200 / (upper_rvi_200 + lower_rvi_200) * 100

//RVI Crossing over and under each other
rvi_10_crossover_rvi_50 = ta.crossover(rvi_10,rvi_50)
rvi_10_crossover_rvi_100 = ta.crossover(rvi_10,rvi_100)
rvi_10_crossover_rvi_200 = ta.crossover(rvi_10,rvi_200)
rvi_50_crossover_rvi_100 = ta.crossover(rvi_50,rvi_100)
rvi_50_crossover_rvi_200 = ta.crossover(rvi_50,rvi_200)
rvi_100_crossover_rvi_200 = ta.crossover(rvi_100,rvi_200)

rvi_10_crossunder_rvi_50 = ta.crossunder(rvi_10,rvi_50)
rvi_10_crossunder_rvi_100 = ta.crossunder(rvi_10,rvi_100)
rvi_10_crossunder_rvi_200 = ta.crossunder(rvi_10,rvi_200)
rvi_50_crossunder_rvi_100 = ta.crossunder(rvi_50,rvi_100)
rvi_50_crossunder_rvi_200 = ta.crossunder(rvi_50,rvi_200)
rvi_100_crossunder_rvi_200 = ta.crossunder(rvi_100,rvi_200)

if rvi_10_crossover_rvi_50 or rvi_10_crossover_rvi_100 or rvi_10_crossover_rvi_200 or rvi_50_crossover_rvi_100 or rvi_50_crossover_rvi_200 or rvi_100_crossover_rvi_200
    positive_signal := positive_signal + 1
if rvi_10_crossunder_rvi_50 or rvi_10_crossunder_rvi_100 or rvi_10_crossunder_rvi_200 or rvi_50_crossunder_rvi_100 or rvi_50_crossunder_rvi_200 or rvi_100_crossunder_rvi_200
    positive_signal := positive_signal - 1

//RVI crossing different values
rvi_10_crossover_val_0 = ta.cross(rvi_10,0)
rvi_10_crossover_val_10 = ta.crossover(rvi_10,10)
rvi_10_crossover_val_20 = ta.crossover(rvi_10,20)
rvi_10_crossover_val_30 = ta.crossover(rvi_10,30)
rvi_10_crossover_val_40 = ta.crossover(rvi_10,40)
rvi_10_crossover_val_50 = ta.crossover(rvi_10,50)
rvi_10_crossover_val_60 = ta.crossover(rvi_10,60)
rvi_10_crossover_val_70 = ta.crossover(rvi_10,70)
rvi_10_crossover_val_80 = ta.crossover(rvi_10,80)
rvi_10_crossover_val_90 = ta.crossover(rvi_10,90)
rvi_10_crossover_val_100 = ta.cross(rvi_10,100)

rvi_10_crossunder_val_0 = ta.cross(rvi_10,0)
rvi_10_crossunder_val_10 = ta.crossunder(rvi_10,10)
rvi_10_crossunder_val_20 = ta.crossunder(rvi_10,20)
rvi_10_crossunder_val_30 = ta.crossunder(rvi_10,30)
rvi_10_crossunder_val_40 = ta.crossunder(rvi_10,40)
rvi_10_crossunder_val_50 = ta.crossunder(rvi_10,50)
rvi_10_crossunder_val_60 = ta.crossunder(rvi_10,60)
rvi_10_crossunder_val_70 = ta.crossunder(rvi_10,70)
rvi_10_crossunder_val_80 = ta.crossunder(rvi_10,80)
rvi_10_crossunder_val_90 = ta.crossunder(rvi_10,90)
rvi_10_crossunder_val_100 = ta.cross(rvi_10,100)

if rvi_10_crossover_val_0 or rvi_10_crossover_val_10 or rvi_10_crossover_val_20 or rvi_10_crossover_val_30 or rvi_10_crossover_val_40 or rvi_10_crossover_val_50 or rvi_10_crossover_val_60 or rvi_10_crossover_val_70 or rvi_10_crossover_val_80 or rvi_10_crossover_val_90 or rvi_10_crossover_val_100
    positive_signal := positive_signal + 1
if rvi_10_crossunder_val_0 or rvi_10_crossunder_val_10 or rvi_10_crossunder_val_20 or rvi_10_crossunder_val_30 or rvi_10_crossunder_val_40 or rvi_10_crossunder_val_50 or rvi_10_crossunder_val_60 or rvi_10_crossunder_val_70 or rvi_10_crossunder_val_80 or rvi_10_crossunder_val_90 or rvi_10_crossunder_val_100
    positive_signal := positive_signal - 1

rvi_50_crossover_val_75 = ta.crossover(rvi_50,75)
rvi_50_crossover_val_70 = ta.crossover(rvi_50,70)
rvi_50_crossover_val_65 = ta.crossover(rvi_50,65)
rvi_50_crossover_val_60 = ta.crossover(rvi_50,60)
rvi_50_crossover_val_55 = ta.crossover(rvi_50,55)
rvi_50_crossover_val_50 = ta.crossover(rvi_50,50)
rvi_50_crossover_val_45 = ta.crossover(rvi_50,45)
rvi_50_crossover_val_40 = ta.crossover(rvi_50,40)
rvi_50_crossover_val_35 = ta.crossover(rvi_50,35)
rvi_50_crossover_val_30 = ta.crossover(rvi_50,30)
rvi_50_crossover_val_25 = ta.crossover(rvi_50,25)

rvi_50_crossunder_val_75 = ta.crossunder(rvi_50,75)
rvi_50_crossunder_val_70 = ta.crossunder(rvi_50,70)
rvi_50_crossunder_val_65 = ta.crossunder(rvi_50,65)
rvi_50_crossunder_val_60 = ta.crossunder(rvi_50,60)
rvi_50_crossunder_val_55 = ta.crossunder(rvi_50,55)
rvi_50_crossunder_val_50 = ta.crossunder(rvi_50,50)
rvi_50_crossunder_val_45 = ta.crossunder(rvi_50,45)
rvi_50_crossunder_val_40 = ta.crossunder(rvi_50,40)
rvi_50_crossunder_val_35 = ta.crossunder(rvi_50,35)
rvi_50_crossunder_val_30 = ta.crossunder(rvi_50,30)
rvi_50_crossunder_val_25 = ta.crossunder(rvi_50,25)

if rvi_50_crossover_val_75 or rvi_50_crossover_val_70 or rvi_50_crossover_val_65 or rvi_50_crossover_val_60 or rvi_50_crossover_val_55 or rvi_50_crossover_val_50 or rvi_50_crossover_val_45 or rvi_50_crossover_val_40 or rvi_50_crossover_val_35 or rvi_50_crossover_val_30 or rvi_50_crossover_val_25
    positive_signal := positive_signal + 1
if rvi_50_crossunder_val_75 or rvi_50_crossunder_val_70 or rvi_50_crossunder_val_65 or rvi_50_crossunder_val_60 or rvi_50_crossunder_val_55 or rvi_50_crossunder_val_50 or rvi_50_crossunder_val_45 or rvi_50_crossunder_val_40 or rvi_50_crossunder_val_35 or rvi_50_crossunder_val_30 or rvi_50_crossunder_val_25
    positive_signal := positive_signal - 1

rvi_100_crossover_val_70 = ta.crossover(rvi_100,70)
rvi_100_crossover_val_66 = ta.crossover(rvi_100,66)
rvi_100_crossover_val_62 = ta.crossover(rvi_100,62)
rvi_100_crossover_val_58 = ta.crossover(rvi_100,58)
rvi_100_crossover_val_54 = ta.crossover(rvi_100,54)
rvi_100_crossover_val_50 = ta.crossover(rvi_100,50)
rvi_100_crossover_val_46 = ta.crossover(rvi_100,46)
rvi_100_crossover_val_42 = ta.crossover(rvi_100,42)
rvi_100_crossover_val_38 = ta.crossover(rvi_100,38)
rvi_100_crossover_val_34 = ta.crossover(rvi_100,34)
rvi_100_crossover_val_30 = ta.crossover(rvi_100,30)

rvi_100_crossunder_val_70 = ta.crossunder(rvi_100,70)
rvi_100_crossunder_val_66 = ta.crossunder(rvi_100,66)
rvi_100_crossunder_val_62 = ta.crossunder(rvi_100,62)
rvi_100_crossunder_val_58 = ta.crossunder(rvi_100,58)
rvi_100_crossunder_val_54 = ta.crossunder(rvi_100,54)
rvi_100_crossunder_val_50 = ta.crossunder(rvi_100,50)
rvi_100_crossunder_val_46 = ta.crossunder(rvi_100,46)
rvi_100_crossunder_val_42 = ta.crossunder(rvi_100,42)
rvi_100_crossunder_val_38 = ta.crossunder(rvi_100,38)
rvi_100_crossunder_val_34 = ta.crossunder(rvi_100,34)
rvi_100_crossunder_val_30 = ta.crossunder(rvi_100,30)

if rvi_100_crossover_val_70 or rvi_100_crossover_val_66 or rvi_100_crossover_val_62 or rvi_100_crossover_val_58 or rvi_100_crossover_val_54 or rvi_100_crossover_val_50 or rvi_100_crossover_val_46 or rvi_100_crossover_val_42 or rvi_100_crossover_val_38 or rvi_100_crossover_val_34 or rvi_100_crossover_val_30
    positive_signal := positive_signal + 1
if rvi_100_crossunder_val_70 or rvi_100_crossunder_val_66 or rvi_100_crossunder_val_62 or rvi_100_crossunder_val_58 or rvi_100_crossunder_val_54 or rvi_100_crossunder_val_50 or rvi_100_crossunder_val_46 or rvi_100_crossunder_val_42 or rvi_100_crossunder_val_38 or rvi_100_crossunder_val_34 or rvi_100_crossunder_val_30
    positive_signal := positive_signal - 1
    
rvi_200_crossover_val_65 = ta.crossover(rvi_200,65)
rvi_200_crossover_val_62 = ta.crossover(rvi_200,62)
rvi_200_crossover_val_59 = ta.crossover(rvi_200,59)
rvi_200_crossover_val_56 = ta.crossover(rvi_200,56)
rvi_200_crossover_val_53 = ta.crossover(rvi_200,53)
rvi_200_crossover_val_50 = ta.crossover(rvi_200,50)
rvi_200_crossover_val_47 = ta.crossover(rvi_200,47)
rvi_200_crossover_val_44 = ta.crossover(rvi_200,44)
rvi_200_crossover_val_41 = ta.crossover(rvi_200,41)
rvi_200_crossover_val_38 = ta.crossover(rvi_200,38)
rvi_200_crossover_val_35 = ta.crossover(rvi_200,35)

rvi_200_crossunder_val_65 = ta.crossunder(rvi_200,65)
rvi_200_crossunder_val_62 = ta.crossunder(rvi_200,62)
rvi_200_crossunder_val_59 = ta.crossunder(rvi_200,59)
rvi_200_crossunder_val_56 = ta.crossunder(rvi_200,56)
rvi_200_crossunder_val_53 = ta.crossunder(rvi_200,53)
rvi_200_crossunder_val_50 = ta.crossunder(rvi_200,50)
rvi_200_crossunder_val_47 = ta.crossunder(rvi_200,47)
rvi_200_crossunder_val_44 = ta.crossunder(rvi_200,44)
rvi_200_crossunder_val_41 = ta.crossunder(rvi_200,41)
rvi_200_crossunder_val_38 = ta.crossunder(rvi_200,38)
rvi_200_crossunder_val_35 = ta.crossunder(rvi_200,35)

if rvi_200_crossover_val_65 or rvi_200_crossover_val_62 or rvi_200_crossover_val_59 or rvi_200_crossover_val_56 or rvi_200_crossover_val_53 or rvi_200_crossover_val_50 or rvi_200_crossover_val_47 or rvi_200_crossover_val_44 or rvi_200_crossover_val_41 or rvi_200_crossover_val_38 or rvi_200_crossover_val_35
    positive_signal := positive_signal + 1
if rvi_200_crossunder_val_65 or rvi_200_crossunder_val_62 or rvi_200_crossunder_val_59 or rvi_200_crossunder_val_56 or rvi_200_crossunder_val_53 or rvi_200_crossunder_val_50 or rvi_200_crossunder_val_47 or rvi_200_crossunder_val_44 or rvi_200_crossunder_val_41 or rvi_200_crossunder_val_38 or rvi_200_crossunder_val_35
    positive_signal := positive_signal - 1

//Balance of power
bop = ((((close - open) / (high - low))*100)+50)
cal_method_bop_10 = input.string(title = "BOP-10 cal method is", options=['EMA', 'SMA'], defval='EMA', group = "Balance of Power (BOP)")  
cal_method_bop_50 = input.string(title = "BOP-50 cal method is", options=['EMA', 'SMA'], defval='EMA', group = "Balance of Power (BOP)")
cal_method_bop_100 = input.string(title = "BOP-100 cal method is", options=['EMA', 'SMA'], defval='EMA', group = "Balance of Power (BOP)")
cal_method_bop_200 = input.string(title = "BOP-200 cal method is", options=['EMA', 'SMA'], defval='EMA', group = "Balance of Power (BOP)")

var float bop_10 = 0
var float bop_50 = 0
var float bop_100 = 0
var float bop_200 = 0

if cal_method_bop_10 == "SMA"
    bop_10 := ta.sma(bop,10)
else if cal_method_bop_10 == "EMA"
    bop_10 := ta.ema(bop,10)

if cal_method_bop_50 == "SMA"
    bop_50 := ta.sma(bop,50)
else if cal_method_bop_50 == "EMA"
    bop_50 := ta.ema(bop,50)
    
if cal_method_bop_100 == "SMA"
    bop_100 := ta.sma(bop,100)
else if cal_method_bop_100 == "EMA"
    bop_100 := ta.ema(bop,100)

if cal_method_bop_200 == "SMA"
    bop_200 := ta.sma(bop,200)
else if cal_method_bop_200 == "EMA"
    bop_200 := ta.ema(bop,200)
    
//BOP Crossing over and under each other
bop_10_crossover_bop_50 = ta.crossover(bop_10,bop_50)
bop_10_crossover_bop_100 = ta.crossover(bop_10,bop_100)
bop_10_crossover_bop_200 = ta.crossover(bop_10,bop_200)
bop_50_crossover_bop_100 = ta.crossover(bop_50,bop_100)
bop_50_crossover_bop_200 = ta.crossover(bop_50,bop_200)
bop_100_crossover_bop_200 = ta.crossover(bop_100,bop_200)

bop_10_crossunder_bop_50 = ta.crossunder(bop_10,bop_50)
bop_10_crossunder_bop_100 = ta.crossunder(bop_10,bop_100)
bop_10_crossunder_bop_200 = ta.crossunder(bop_10,bop_200)
bop_50_crossunder_bop_100 = ta.crossunder(bop_50,bop_100)
bop_50_crossunder_bop_200 = ta.crossunder(bop_50,bop_200)
bop_100_crossunder_bop_200 = ta.crossunder(bop_100,bop_200)

if bop_10_crossover_bop_50 or bop_10_crossover_bop_100 or bop_10_crossover_bop_200 or bop_50_crossover_bop_100 or bop_50_crossover_bop_200 or bop_100_crossover_bop_200
    positive_signal := positive_signal + 1
if bop_10_crossunder_bop_50 or bop_10_crossunder_bop_100 or bop_10_crossunder_bop_200 or bop_50_crossunder_bop_100 or bop_50_crossunder_bop_200 or bop_100_crossunder_bop_200
    positive_signal := positive_signal - 1

//BOP crossing different values
bop_10_crossover_val_0 = ta.cross(bop_10,0)
bop_10_crossover_val_10 = ta.crossover(bop_10,10)
bop_10_crossover_val_20 = ta.crossover(bop_10,20)
bop_10_crossover_val_30 = ta.crossover(bop_10,30)
bop_10_crossover_val_40 = ta.crossover(bop_10,40)
bop_10_crossover_val_50 = ta.crossover(bop_10,50)
bop_10_crossover_val_60 = ta.crossover(bop_10,60)
bop_10_crossover_val_70 = ta.crossover(bop_10,70)
bop_10_crossover_val_80 = ta.crossover(bop_10,80)
bop_10_crossover_val_90 = ta.crossover(bop_10,90)
bop_10_crossover_val_100 = ta.cross(bop_10,100)

bop_10_crossunder_val_0 = ta.cross(bop_10,0)
bop_10_crossunder_val_10 = ta.crossunder(bop_10,10)
bop_10_crossunder_val_20 = ta.crossunder(bop_10,20)
bop_10_crossunder_val_30 = ta.crossunder(bop_10,30)
bop_10_crossunder_val_40 = ta.crossunder(bop_10,40)
bop_10_crossunder_val_50 = ta.crossunder(bop_10,50)
bop_10_crossunder_val_60 = ta.crossunder(bop_10,60)
bop_10_crossunder_val_70 = ta.crossunder(bop_10,70)
bop_10_crossunder_val_80 = ta.crossunder(bop_10,80)
bop_10_crossunder_val_90 = ta.crossunder(bop_10,90)
bop_10_crossunder_val_100 = ta.cross(bop_10,100)

if bop_10_crossover_val_0 or bop_10_crossover_val_10 or bop_10_crossover_val_20 or bop_10_crossover_val_30 or bop_10_crossover_val_40 or bop_10_crossover_val_50 or bop_10_crossover_val_60 or bop_10_crossover_val_70 or bop_10_crossover_val_80 or bop_10_crossover_val_90 or bop_10_crossover_val_100
    positive_signal := positive_signal + 1
if bop_10_crossunder_val_0 or bop_10_crossunder_val_10 or bop_10_crossunder_val_20 or bop_10_crossunder_val_30 or bop_10_crossunder_val_40 or bop_10_crossunder_val_50 or bop_10_crossunder_val_60 or bop_10_crossunder_val_70 or bop_10_crossunder_val_80 or bop_10_crossunder_val_90 or bop_10_crossunder_val_100
    positive_signal := positive_signal - 1

bop_50_crossover_val_80 = ta.crossover(bop_50,80)
bop_50_crossover_val_74 = ta.crossover(bop_50,74)
bop_50_crossover_val_68 = ta.crossover(bop_50,68)
bop_50_crossover_val_62 = ta.crossover(bop_50,62)
bop_50_crossover_val_56 = ta.crossover(bop_50,56)
bop_50_crossover_val_50 = ta.crossover(bop_50,50)
bop_50_crossover_val_44 = ta.crossover(bop_50,44)
bop_50_crossover_val_38 = ta.crossover(bop_50,38)
bop_50_crossover_val_32 = ta.crossover(bop_50,32)
bop_50_crossover_val_26 = ta.crossover(bop_50,26)
bop_50_crossover_val_20 = ta.crossover(bop_50,20)

bop_50_crossunder_val_80 = ta.crossunder(bop_50,80)
bop_50_crossunder_val_74 = ta.crossunder(bop_50,74)
bop_50_crossunder_val_68 = ta.crossunder(bop_50,68)
bop_50_crossunder_val_62 = ta.crossunder(bop_50,62)
bop_50_crossunder_val_56 = ta.crossunder(bop_50,56)
bop_50_crossunder_val_50 = ta.crossunder(bop_50,50)
bop_50_crossunder_val_44 = ta.crossunder(bop_50,44)
bop_50_crossunder_val_38 = ta.crossunder(bop_50,38)
bop_50_crossunder_val_32 = ta.crossunder(bop_50,32)
bop_50_crossunder_val_26 = ta.crossunder(bop_50,26)
bop_50_crossunder_val_20 = ta.crossunder(bop_50,20)

if bop_50_crossover_val_80 or bop_50_crossover_val_74 or bop_50_crossover_val_68 or bop_50_crossover_val_62 or bop_50_crossover_val_56 or bop_50_crossover_val_50 or bop_50_crossover_val_44 or bop_50_crossover_val_38 or bop_50_crossover_val_32 or bop_50_crossover_val_26 or bop_50_crossover_val_20
    positive_signal := positive_signal + 1
if bop_50_crossunder_val_80 or bop_50_crossunder_val_74 or bop_50_crossunder_val_68 or bop_50_crossunder_val_62 or bop_50_crossunder_val_56 or bop_50_crossunder_val_50 or bop_50_crossunder_val_44 or bop_50_crossunder_val_38 or bop_50_crossunder_val_32 or bop_50_crossunder_val_26 or bop_50_crossunder_val_20
    positive_signal := positive_signal - 1

bop_100_crossover_val_75 = ta.crossover(bop_100,75)
bop_100_crossover_val_70 = ta.crossover(bop_100,70)
bop_100_crossover_val_65 = ta.crossover(bop_100,65)
bop_100_crossover_val_60 = ta.crossover(bop_100,60)
bop_100_crossover_val_55 = ta.crossover(bop_100,55)
bop_100_crossover_val_50 = ta.crossover(bop_100,50)
bop_100_crossover_val_45 = ta.crossover(bop_100,45)
bop_100_crossover_val_40 = ta.crossover(bop_100,40)
bop_100_crossover_val_35 = ta.crossover(bop_100,35)
bop_100_crossover_val_30 = ta.crossover(bop_100,30)
bop_100_crossover_val_25 = ta.crossover(bop_100,25)

bop_100_crossunder_val_75 = ta.crossunder(bop_100,75)
bop_100_crossunder_val_70 = ta.crossunder(bop_100,70)
bop_100_crossunder_val_65 = ta.crossunder(bop_100,65)
bop_100_crossunder_val_60 = ta.crossunder(bop_100,60)
bop_100_crossunder_val_55 = ta.crossunder(bop_100,55)
bop_100_crossunder_val_50 = ta.crossunder(bop_100,50)
bop_100_crossunder_val_45 = ta.crossunder(bop_100,45)
bop_100_crossunder_val_40 = ta.crossunder(bop_100,40)
bop_100_crossunder_val_35 = ta.crossunder(bop_100,35)
bop_100_crossunder_val_30 = ta.crossunder(bop_100,30)
bop_100_crossunder_val_25 = ta.crossunder(bop_100,25)

if bop_100_crossover_val_75 or bop_100_crossover_val_70 or bop_100_crossover_val_65 or bop_100_crossover_val_60 or bop_100_crossover_val_55 or bop_100_crossover_val_50 or bop_100_crossover_val_45 or bop_100_crossover_val_40 or bop_100_crossover_val_35 or bop_100_crossover_val_30 or bop_100_crossover_val_25
    positive_signal := positive_signal + 1
if bop_100_crossunder_val_75 or bop_100_crossunder_val_70 or bop_100_crossunder_val_65 or bop_100_crossunder_val_60 or bop_100_crossunder_val_55 or bop_100_crossunder_val_50 or bop_100_crossunder_val_45 or bop_100_crossunder_val_40 or bop_100_crossunder_val_35 or bop_100_crossunder_val_30 or bop_100_crossunder_val_25
    positive_signal := positive_signal - 1

bop_200_crossover_val_70 = ta.crossover(bop_200,70)
bop_200_crossover_val_66 = ta.crossover(bop_200,66)
bop_200_crossover_val_62 = ta.crossover(bop_200,62)
bop_200_crossover_val_58 = ta.crossover(bop_200,58)
bop_200_crossover_val_54 = ta.crossover(bop_200,54)
bop_200_crossover_val_50 = ta.crossover(bop_200,50)
bop_200_crossover_val_46 = ta.crossover(bop_200,46)
bop_200_crossover_val_42 = ta.crossover(bop_200,42)
bop_200_crossover_val_38 = ta.crossover(bop_200,38)
bop_200_crossover_val_34 = ta.crossover(bop_200,34)
bop_200_crossover_val_30 = ta.crossover(bop_200,30)

bop_200_crossunder_val_70 = ta.crossunder(bop_200,70)
bop_200_crossunder_val_66 = ta.crossunder(bop_200,66)
bop_200_crossunder_val_62 = ta.crossunder(bop_200,62)
bop_200_crossunder_val_58 = ta.crossunder(bop_200,58)
bop_200_crossunder_val_54 = ta.crossunder(bop_200,54)
bop_200_crossunder_val_50 = ta.crossunder(bop_200,50)
bop_200_crossunder_val_46 = ta.crossunder(bop_200,46)
bop_200_crossunder_val_42 = ta.crossunder(bop_200,42)
bop_200_crossunder_val_38 = ta.crossunder(bop_200,38)
bop_200_crossunder_val_34 = ta.crossunder(bop_200,34)
bop_200_crossunder_val_30 = ta.crossunder(bop_200,30)

if bop_200_crossover_val_70 or bop_200_crossover_val_66 or bop_200_crossover_val_62 or bop_200_crossover_val_58 or bop_200_crossover_val_54 or bop_200_crossover_val_50 or bop_200_crossover_val_46 or bop_200_crossover_val_42 or bop_200_crossover_val_38 or bop_200_crossover_val_34 or bop_200_crossover_val_30
    positive_signal := positive_signal + 1
if bop_200_crossunder_val_70 or bop_200_crossunder_val_66 or bop_200_crossunder_val_62 or bop_200_crossunder_val_58 or bop_200_crossunder_val_54 or bop_200_crossunder_val_50 or bop_200_crossunder_val_46 or bop_200_crossunder_val_42 or bop_200_crossunder_val_38 or bop_200_crossunder_val_34 or bop_200_crossunder_val_30
    positive_signal := positive_signal - 1
    
//Simple moving average (SMA)
src_sma_10= input(close,title = "Source of SMA-10 is",  group = "Simple moving average (SMA)")
sma_10 = ta.sma(src_sma_10,10)

src_sma_50= input(close,title = "Source of SMA-50 is",  group = "Simple moving average (SMA)")
sma_50 = ta.sma(src_sma_50,50)

src_sma_100= input(close,title = "Source of SMA-100 is",  group = "Simple moving average (SMA)")
sma_100 = ta.sma(src_sma_100,100)

src_sma_200= input(close,title = "Source of SMA-200 is",  group = "Simple moving average (SMA)")
sma_200 = ta.sma(src_sma_200,200)

//SMA Crossing over and under each other
sma_10_crossover_sma_50 = ta.crossover(sma_10,sma_50)
sma_10_crossover_sma_100 = ta.crossover(sma_10,sma_100)
sma_10_crossover_sma_200 = ta.crossover(sma_10,sma_200)
sma_50_crossover_sma_100 = ta.crossover(sma_50,sma_100)
sma_50_crossover_sma_200 = ta.crossover(sma_50,sma_200)
sma_100_crossover_sma_200 = ta.crossover(sma_100,sma_200)

sma_10_crossunder_sma_50 = ta.crossunder(sma_10,sma_50)
sma_10_crossunder_sma_100 = ta.crossunder(sma_10,sma_100)
sma_10_crossunder_sma_200 = ta.crossunder(sma_10,sma_200)
sma_50_crossunder_sma_100 = ta.crossunder(sma_50,sma_100)
sma_50_crossunder_sma_200 = ta.crossunder(sma_50,sma_200)
sma_100_crossunder_sma_200 = ta.crossunder(sma_100,sma_200)

if sma_10_crossover_sma_50 or sma_10_crossover_sma_100 or sma_10_crossover_sma_200 or sma_50_crossover_sma_100 or sma_50_crossover_sma_200 or sma_100_crossover_sma_200
    positive_signal := positive_signal + 1
if sma_10_crossunder_sma_50 or sma_10_crossunder_sma_100 or sma_10_crossunder_sma_200 or sma_50_crossunder_sma_100 or sma_50_crossunder_sma_200 or sma_100_crossunder_sma_200
    positive_signal := positive_signal - 1

//Exponential Moving average (EMA)
src_ema_10= input(close,title = "Source of EMA-10 is",  group = "Exponential Moving average (EMA)")
ema_10 = ta.ema(src_ema_10,10)

src_ema_50= input(close,title = "Source of EMA-50 is",  group = "Exponential Moving average (EMA)")
ema_50 = ta.ema(src_ema_50,50)

src_ema_100= input(close,title = "Source of EMA-100 is",  group = "Exponential Moving average (EMA)")
ema_100 = ta.ema(src_ema_100,100)

src_ema_200= input(close,title = "Source of EMA-200 is",  group = "Exponential Moving average (EMA)")
ema_200 = ta.ema(src_ema_200,200)

//EMA Crossing over and under each other
ema_10_crossover_ema_50 = ta.crossover(ema_10,ema_50)
ema_10_crossover_ema_100 = ta.crossover(ema_10,ema_100)
ema_10_crossover_ema_200 = ta.crossover(ema_10,ema_200)
ema_50_crossover_ema_100 = ta.crossover(ema_50,ema_100)
ema_50_crossover_ema_200 = ta.crossover(ema_50,ema_200)
ema_100_crossover_ema_200 = ta.crossover(ema_100,ema_200)

ema_10_crossunder_ema_50 = ta.crossunder(ema_10,ema_50)
ema_10_crossunder_ema_100 = ta.crossunder(ema_10,ema_100)
ema_10_crossunder_ema_200 = ta.crossunder(ema_10,ema_200)
ema_50_crossunder_ema_100 = ta.crossunder(ema_50,ema_100)
ema_50_crossunder_ema_200 = ta.crossunder(ema_50,ema_200)
ema_100_crossunder_ema_200 = ta.crossunder(ema_100,ema_200)

if ema_10_crossover_ema_50 or ema_10_crossover_ema_100 or ema_10_crossover_ema_200 or ema_50_crossover_ema_100 or ema_50_crossover_ema_200 or ema_100_crossover_ema_200
    positive_signal := positive_signal + 1
if ema_10_crossunder_ema_50 or ema_10_crossunder_ema_100 or ema_10_crossunder_ema_200 or ema_50_crossunder_ema_100 or ema_50_crossunder_ema_200 or ema_100_crossunder_ema_200
    positive_signal := positive_signal - 1

//SAR indicator
start = input(0.02, title = "SAR Start value",  group = "SAR")
increment = input(0.02, title = "SAR Incremental value",  group = "SAR")
maximum = input(0.2, title = "SAR Max Value",  group = "SAR")
out = ta.sar(start, increment, maximum)

if out <= close
    positive_signal := positive_signal + 1
if out > close
    positive_signal := positive_signal - 1
    
//SUper trend
atrPeriod = input(10, "ATR Length",  group = "Super Trend")
factor = input.float(3.0, "Factor", step = 0.01,  group = "Super Trend")

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

if direction < 0
    positive_signal := positive_signal + 1
else
    positive_signal := positive_signal - 1

//End of calculations for positive signal

price_indicator_corelation = ta.correlation(positive_signal, close, hl_period)
signal_average = ta.sma(positive_signal/100,hl_period)
signal_high = ta.highest(positive_signal/100,hl_period)
signal_low = ta.lowest(positive_signal/100,hl_period)

var float co_variance_positive_signal_and_signal_high_high = 0
var float co_variance_positive_signal_and_signal_low_high = 0

a = array.new_float(0)
b = array.new_float(0)
c = array.new_float(0)
e = array.new_float(0)
f = array.new_float(0)
for i = 0 to 10
	array.push(a, positive_signal[i])
	array.push(b, ((close+open)/2)[i])
	array.push(c, signal_high[i])
	array.push(e, signal_low[i])

co_variance_price_and_positive_signal = math.round(array.covariance(a, b)/100, 2)
co_variance_price_and_positive_signal_high = ta.highest(co_variance_price_and_positive_signal,5)


co_variance_positive_signal_and_signal_high = math.round(array.covariance(a, c), 5)
co_variance_positive_signal_and_signal_low = math.round(array.covariance(a, e), 5)

highest_val_co_variance_positive_signal_and_signal_high = ta.highest(co_variance_positive_signal_and_signal_high,5)
lowest_val_co_variance_positive_signal_and_signal_high = ta.lowest(co_variance_positive_signal_and_signal_high,5)

highest_val_co_variance_positive_signal_and_signal_low = ta.highest(co_variance_positive_signal_and_signal_low,5)
lowest_val_co_variance_positive_signal_and_signal_low = ta.lowest(co_variance_positive_signal_and_signal_low,5)

if co_variance_positive_signal_and_signal_high > 0
    co_variance_positive_signal_and_signal_high_high := highest_val_co_variance_positive_signal_and_signal_high
else if  co_variance_positive_signal_and_signal_high <= 0
    co_variance_positive_signal_and_signal_high_high := lowest_val_co_variance_positive_signal_and_signal_high

if co_variance_positive_signal_and_signal_low > 0
    co_variance_positive_signal_and_signal_low_high := highest_val_co_variance_positive_signal_and_signal_low
if co_variance_positive_signal_and_signal_low <= 0
    co_variance_positive_signal_and_signal_low_high := lowest_val_co_variance_positive_signal_and_signal_low


//signal generation

price_rising = ta.rising(ta.sma(close,9),5)
price_falling = ta.falling(ta.sma(close,9),5)

var bool point_one = false
var bool point_two = false
var bool point_three = false
var bool point_four = false
var bool point_five = false
var bool point_six = false


if co_variance_price_and_positive_signal[1] == co_variance_price_and_positive_signal_high[1] and co_variance_price_and_positive_signal < co_variance_price_and_positive_signal_high and co_variance_price_and_positive_signal >= 1 and price_falling
    point_one := true
else
    point_one := false
if co_variance_price_and_positive_signal[1] == co_variance_price_and_positive_signal_high[1] and co_variance_price_and_positive_signal < co_variance_price_and_positive_signal_high and co_variance_price_and_positive_signal >= 1 and price_rising
    point_two := true
else
    point_two := false

if co_variance_positive_signal_and_signal_high[1] == co_variance_positive_signal_and_signal_high_high[1] and co_variance_positive_signal_and_signal_high < co_variance_positive_signal_and_signal_high_high and co_variance_positive_signal_and_signal_high >= 1 and price_rising
    point_three := true
else
    point_three := false
if co_variance_positive_signal_and_signal_high[1] == co_variance_positive_signal_and_signal_high_high[1] and co_variance_positive_signal_and_signal_high > co_variance_positive_signal_and_signal_high_high and co_variance_positive_signal_and_signal_high <= -0.5 and price_rising
    point_four := true
else
    point_four := false

if co_variance_positive_signal_and_signal_low[1] == co_variance_positive_signal_and_signal_low_high[1] and co_variance_positive_signal_and_signal_low < co_variance_positive_signal_and_signal_low_high and co_variance_positive_signal_and_signal_low >= 1 and price_falling
    point_five := true
else
    point_five := false
if co_variance_positive_signal_and_signal_low[1] == co_variance_positive_signal_and_signal_low_high[1] and co_variance_positive_signal_and_signal_low > co_variance_positive_signal_and_signal_low_high and co_variance_positive_signal_and_signal_low <= -0.5 and price_falling
    point_six := true
else
    point_six := false



//Graphs

//MOM
plot(show == "Momentum Ocilator" ? chandeMO_10:na,      color=color.new(color.green,50),    title = "MOM-10")
plot(show == "Momentum Ocilator" ? chandeMO_50:na,      color=color.yellow,                 title = "MOM-50")
plot(show == "Momentum Ocilator" ? chandeMO_100:na,     color=color.orange,                 title = "MOM-100")
plot(show == "Momentum Ocilator" ? chandeMO_200:na,     color=color.red,                    title = "MOM-200")
plot(show == "Momentum Ocilator" ? 80:na,               color=color.new(color.white,50),    title = "80")
plot(show == "Momentum Ocilator" ? 40:na,               color=color.new(color.white,50),    title = "40")
plot(show == "Momentum Ocilator" ? 00:na,               color=color.new(color.white,50),    title = "00")
plot(show == "Momentum Ocilator" ? -40:na,              color=color.new(color.white,50),    title = "-40")
plot(show == "Momentum Ocilator" ? -80:na,              color=color.new(color.white,50),    title = "-80")
//Volume change
plot(show == "Volume Ocilator" ? osc:na,                color=#2962FF,                      title = "Volume Ocillator")
plot(show == "Volume Ocilator" ? 100:na,                color=color.new(color.white,50),    title = "100")
plot(show == "Volume Ocilator" ? 300:na,                color=color.new(color.white,50),    title = "300")
plot(show == "Volume Ocilator" ? 500:na,                color=color.new(color.white,50),    title = "500")
plot(show == "Volume Ocilator" ? 0:na,                  color=color.new(color.white,50),    title = "0")
//RSI
plot(show == "RSI" ? rsi_10:na,                         color=color.new(color.green,50),    title = "RSI-10")
plot(show == "RSI" ? rsi_50:na,                         color=color.yellow,                 title = "RSI-50")
plot(show == "RSI" ? rsi_100:na,                        color=color.orange,                 title = "RSI-100")
plot(show == "RSI" ? rsi_200:na,                        color=color.red,                    title = "RSI-200")

//MFI
plot(show == "MFI" ? mfi_10:na,                         color=color.new(color.green,50),    title = "MFI-10")
plot(show == "MFI" ? mfi_50:na,                         color=color.yellow,                 title = "MFI-50")
plot(show == "MFI" ? mfi_100:na,                        color=color.orange,                 title = "MFI-100")
plot(show == "MFI" ? mfi_200:na,                        color=color.red,                    title = "MFI-200")

//RVI
plot(show == "RVI" ? rvi_10:na,                         color=color.new(color.green,50),    title = "RVI-10")
plot(show == "RVI" ? rvi_50:na,                         color=color.yellow,                 title = "RVI-50")
plot(show == "RVI" ? rvi_100:na,                        color=color.orange,                 title = "RVI-100")
plot(show == "RVI" ? rvi_200:na,                        color=color.red,                    title = "RVI-200")

//BOP
plot(show == "BOP" ? bop_10:na,                         color=color.new(color.green,50),    title = "BOP-10")
plot(show == "BOP" ? bop_50:na,                         color=color.yellow,                 title = "BOP-50")
plot(show == "BOP" ? bop_100:na,                        color=color.orange,                 title = "BOP-100")
plot(show == "BOP" ? bop_200:na,                        color=color.red,                    title = "BOP-200")

//SMA
plot(show == "SMA" ? sma_10:na,                         color=color.new(color.green,50),    title = "SMA-10")
plot(show == "SMA" ? sma_50:na,                         color=color.yellow,                 title = "SMA-50")
plot(show == "SMA" ? sma_100:na,                        color=color.orange,                 title = "SMA-100")
plot(show == "SMA" ? sma_200:na,                        color=color.red,                    title = "SMA-200")
//EMA
plot(show == "EMA" ? ema_10:na,                         color=color.new(color.green,50),    title = "EMA-10")
plot(show == "EMA" ? ema_50:na,                         color=color.yellow,                 title = "EMA-50")
plot(show == "EMA" ? ema_100:na,                        color=color.orange,                 title = "EMA-100")
plot(show == "EMA" ? ema_200:na,                        color=color.red,                    title = "EMA-200")


plot(show == "RSI" or show == "MFI" or show == "RVI" or show == "BOP" ? 60:na,                             color=color.new(color.white,50),    title = "60")
plot(show == "RSI" or show == "MFI" or show == "RVI" or show == "BOP" ? 50:na,                             color=color.new(color.white,50),    title = "50")
plot(show == "RSI" or show == "MFI" or show == "RVI" or show == "BOP" ? 40:na,                             color=color.new(color.white,50),    title = "40")

//Stochastic Indicator
plot(show == 'Stochastic Indicator'? k:na,              color=#2962FF,                      title="%K")
plot(show == 'Stochastic Indicator'? d:na,              color=#FF6D00,                      title="%D")

plot(show == "positive_signal" ? positive_signal/100 : na, title = "positive_signal")
plot(show == "positive_signal" ? (co_variance_price_and_positive_signal):na, title = "CV between Price & Signal", color = color.orange)
plot(show == "positive_signal" ? (co_variance_positive_signal_and_signal_high):na, title = "CV between High values & Signal", color = color.white)
plot(show == "positive_signal" ? (co_variance_positive_signal_and_signal_low):na, title = "CV between Low values & Signal", color = color.green)



//Shapes
plotshape(point_one == true, style =  shape.arrowdown, color = color.orange, location = location.abovebar, size = size.large, text = "1")
plotshape(point_two == true, style =  shape.arrowdown, color = color.red, location = location.abovebar, size = size.large, text = "2")

plotshape(point_three == true, style =  shape.arrowdown, color = color.white, location = location.abovebar, size = size.large, text = "3")
plotshape(point_four == true, style =  shape.arrowdown, color = color.silver, location = location.abovebar, size = size.large, text = "4")

plotshape(point_five == true, style =  shape.arrowdown, color = color.green, location = location.abovebar, size = size.large, text = "5")
plotshape(point_six == true, style =  shape.arrowdown, color = color.olive, location = location.abovebar, size = size.large, text = "6")












