Compound Indicator Strategy - BTC/USDT 3h
// 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
strategy("Compound Indicator Strategy - BTC/USDT 3h", shorttitle="Compound - BTC/USDT 3h", overlay=true, calc_on_order_fills=false, close_entries_rule = "FIFO", calc_on_every_tick=false, initial_capital = 1000,pyramiding = 999,precision = 4, process_orders_on_close=true, currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 33, commission_type = strategy.commission.percent, max_lines_count = 500, commission_value = 0.1)
//strategy("OPV6 - Up & Down Trend Trading Strategy - BNB/USDT 15min", shorttitle="OPV6 U&D - BNB 15min", overlay=true, calc_on_order_fills=false, close_entries_rule = "FIFO", calc_on_every_tick=false, initial_capital = 1000,pyramiding = 999,precision = 4, process_orders_on_close=false, currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 33, commission_type = strategy.commission.percent, max_lines_count = 500, commission_value = 0.1)


var     show         = input.string(title = "Show graph", options=['NONE','Compound Indicater','Co-variances'], defval='NONE')  

//Values for calculation

price_average_previous_bar = (open + close)/2
price_average_current_bar = (high+low)/2
volume_average = ta.sma(volume,100)
ma_9 = ta.sma(close,9)
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
    
    
//Bollinger bands
var source_of_billinger_bands = input(defval = close, title = "Source of Bollinger bands will be", group = "Bollinger bands")
var look_back_period_of_billinger_bands = input.int(defval = 5, title = "Look back period of Bollinger bands will be", group = "Bollinger bands")


[middle_bb, upper_bb, lower_bb] = ta.bb(source_of_billinger_bands, look_back_period_of_billinger_bands, 1)

if close>middle_bb
    positive_signal := positive_signal + math.floor(close/upper_bb) + 1
else if close<=middle_bb
    positive_signal := positive_signal - math.floor(close/lower_bb) - 1

//Center of Gravity

cog_10 = ta.cog(close, 10)
sma_cog_10 = ta.sma(cog_10,3)

if cog_10>sma_cog_10
    positive_signal := positive_signal + 1
else if cog_10<=sma_cog_10
    positive_signal := positive_signal - 1
    
    
//End of calculations for positive signal
hl_period = input.int(defval = 50,title = "look back period")
//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, 5)
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
else 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

var use_point_1_cutoff_value = input.bool(defval = true, title = "Use Group 1 positive value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 1')
var point_1_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 1')
//var point_1_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& negative value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 1')

var use_point_2_cutoff_value = input.bool(defval = true, title = "Use Group 2 positive value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 2')
var point_2_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 2')
//var point_2_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& negative value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 2')

var use_point_3_cutoff_value = input.bool(defval = true, title = "Use Group 3 positive value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 3')
var point_3_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 3')
//var point_3_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& negative value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 3')

var use_point_4_cutoff_value = input.bool(defval = true, title = "Use Group 4 negative value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 4')
//var point_4_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "Group 4 positive value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 4')
var point_4_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 4')

var use_point_5_cutoff_value = input.bool(defval = true, title = "Use Group 5 positive value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 5')
var point_5_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 5')
//var point_5_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& negative value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 5')

var use_point_6_cutoff_value = input.bool(defval = true, title = "Use Group 6 negative value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 6')
//var point_6_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "Group 6 positive value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 6')
var point_6_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 6')

var use_point_7_cutoff_value = input.bool(defval = true, title = "Use Group 7 positive value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 7')
var point_7_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 7')
//var point_7_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& negative value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 7')

var use_point_8_cutoff_value = input.bool(defval = true, title = "Use Group 8 negative value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 8')
//var point_8_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "Group 8 positive value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 8')
var point_8_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 8')

var use_point_9_cutoff_value = input.bool(defval = true, title = "Use Group 9 positive value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 9')
var point_9_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 9')
//var point_9_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& negative value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 9')

var use_point_10_cutoff_value = input.bool(defval = true, title = "Use Group 10 negative value", group = "Applicability of Co-variance and it’s values ", inline = 'Group 10')
//var point_10_positive_cutoff_value = input.float(defval = 1, step = 0.1, minval = 0, title = "Group 10 positive value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 10')
var point_10_negative_cutoff_value = input.float(defval = -0.5, step = 0.1, maxval = 0, title = "& value is", group = "Applicability of Co-variance and it’s values ", inline = 'Group 10')





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
var bool point_seven = false
var bool point_eight = false
var bool point_nine = false
var bool point_ten = 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 >= point_1_positive_cutoff_value 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 >= point_2_positive_cutoff_value 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 >= point_3_positive_cutoff_value 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 <= point_4_negative_cutoff_value 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 >= point_5_positive_cutoff_value 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 <= point_6_negative_cutoff_value and price_falling
    point_six := true
else
    point_six := 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 >= point_7_positive_cutoff_value and price_falling
    point_seven := true
else
    point_seven := 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 <= point_8_negative_cutoff_value and price_falling
    point_eight := true
else
    point_eight := 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 >= point_9_positive_cutoff_value and price_rising
    point_nine := true
else
    point_nine := 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 <= point_10_negative_cutoff_value and price_rising
    point_ten := true
else
    point_ten := false
    
    
//Trading Arrangement
// Generate sell signal

var bool sell_comand = false
var factor_of_supertrend_to_determine_sell_comand = input.int(defval = 3, title = "Factor of supertrend to determine sell comand", group = "Determination of sell command")
var artperiod_of_supertrend_to_determine_sell_comand = input.int(defval = 10, title = "artPeriod of supertrend to determine sell comand", group = "Determination of sell command")

[pinesupertrend, pinedirection] = ta.supertrend(factor_of_supertrend_to_determine_sell_comand, artperiod_of_supertrend_to_determine_sell_comand)
plot(pinedirection < 0 ? pinesupertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(pinedirection < 0? na : pinesupertrend, "Down direction", color = color.red, style=plot.style_linebr)

if pinedirection[1] < 0 and pinedirection > 0
    sell_comand := true
else if pinedirection > 0 and (point_two == true or point_three == true)
    sell_comand := true
else
    sell_comand := false




//Intermediate selling count & Count of open trades
var int open_trades = 0
var int x = 0

if strategy.position_size == 0
    open_trades := 0
else if strategy.position_size[1] == 0 and strategy.position_size > 0
    open_trades := 1
else if strategy.position_size[1] < strategy.position_size
    open_trades := open_trades + 1
else if strategy.position_size[1] > strategy.position_size and strategy.position_size > 0
    open_trades := open_trades - 1
else
    open_trades := open_trades
    
    
if strategy.position_size[1] < strategy.position_size and strategy.position_size[1] > 0
    x := open_trades
else if strategy.position_size[1] < strategy.position_size and strategy.position_size[1] == 0
    x := 1
else if strategy.position_size[1] > strategy.position_size and strategy.position_size > 0
    x := x - 1
else if strategy.position_size[1] > strategy.position_size and strategy.position_size == 0
    x := 0
else
    x := x
// Max count of open trades
var float max_open_trades = 0

if strategy.opentrades > max_open_trades
    max_open_trades := strategy.opentrades
else
    max_open_trades := max_open_trades


// Contrall Selling 

var bool int_selling = false
if strategy.opentrades == strategy.opentrades [1]
    int_selling := true
else if strategy.opentrades  == strategy.opentrades [1] - 1
    int_selling := false


// Calculation of profit precentage
var profit_precentage = input.int(defval=3, title = "Profit precentage will be")
var profit_precentage_intermidiate = input.int(defval=1, title = "Intermediate selling minimum profit precentage will be")
var float cal_profit_precentage = 0
if strategy.position_size == 0
    cal_profit_precentage := na
else if strategy.position_size > 0
    cal_profit_precentage := (profit_precentage/100) + 1
else 
    cal_profit_precentage := cal_profit_precentage


//Open trades entry price

var float result = 0
for i = 0 to strategy.opentrades-1
    result := strategy.opentrades.entry_price(i) 


var int y = 0
var int z = 0
if strategy.position_size[1] > 0 and strategy.position_size == 0
    y := 0
    z := 0
else if strategy.position_size[1] == 0 and strategy.position_size > 0
    y := 1
    z := 1
else if strategy.position_size[1] > strategy.position_size and strategy.position_size[1] > 0 and strategy.position_size > 0
    y := y - 1
    z := z + 1
else if strategy.position_size[1] < strategy.position_size and strategy.position_size[1] > 0 and strategy.position_size > 0
    z := z + 1
    y := y + 1
    

m = result




// Fund management - r value calculation
var int_cap = input.float(defval = 1000, title = "Cumilative Investment", group = "Fund Management")
var int_val_prc = input.float(defval = 15, title = "Value of first purchase will be", tooltip = "Minimum value of initial purchase will be 15USDT", group = "Fund Management", inline = "Investment")
int_val_allocation = input.string( title="", options=['% of cumilative investment', 'USDT'], defval='USDT', group = "Fund Management", inline = "Investment")  
var piramiding = input.int(defval = 35, title = "Numbers of pararal entries", group = "Fund Management")
var r = input.float(defval = 5, title = "r starting value", group = "Input parameters for fund management")
var r_change_input = input.int(defval = 1, title = "Initiative value for r change", group = "Input parameters for fund management")
var r_finetune = input.bool(defval = false, title = "Use r = 0.001 to finetune r value", group = "Input parameters for fund management")

var float int_val_3 = 0
var float installment_2 = 0
var float installment_3 = 0
var float installment_4 = 0
var float r_f = 0
var float int_val = 0

if int_cap * int_val_prc/100 <= 15 and int_val_allocation != "USDT"
    int_val := 15
if int_val_prc <= 15 and int_val_allocation == "USDT"
    int_val := 15
if int_cap * int_val_prc/100 > 15 and int_val_allocation != "USDT"
    int_val := int_cap * int_val_prc/100
if int_val_prc > 15 and int_val_allocation == "USDT"
    int_val := int_val_prc
    
var float r_change = 0
if r_finetune == false
    r_change := r_change_input
else if r_finetune == true
    r_change := 0.001
    
for i = 0 to piramiding+2 by 1
    if i == 0
        int_val_3 := int_val
    if i <= piramiding
        installment_2 := int_val_3*math.pow((1 + r/100),i)
    if i >= 0 and i < piramiding+1
        installment_3 := installment_3 + installment_2
    if i == piramiding+1
        installment_4 := installment_3 - installment_3[1]

if installment_4 < int_cap
    r := r + r_change
else if installment_4 > int_cap
    r := r - r_change
else 
    r := r
    
if r[1] < r
    r_f := r[1] 
    
    

plot(r_f, title = "Calculated R value", color = color.new(color.white,100))

//Fund Management
var float total_investment = int_cap
if strategy.position_size[1] >0 and strategy.position_size == 0
    total_investment := int_cap + strategy.netprofit
else 
    total_investment := total_investment
    
// Stratergy possition size
var float last_purchase = 0
if strategy.position_size[1] < strategy.position_size and strategy.position_size[1] == 0
    last_purchase := strategy.position_size
else if strategy.position_size[1] < strategy.position_size and strategy.position_size[1] > 0
    last_purchase := (strategy.position_size - strategy.position_size[1])
else if strategy.position_size == 0
    last_purchase :=  0
else
    last_purchase := last_purchase

//Quantity Calculation

var purchaseing_method = input.string(title = "Value of Purchas will be", options=['Equal amounts','Incremental amounts'], defval='Equal amounts')
var dev_of_equal_amounts = input.string(title = "Value of Purchas will be", options=['Equal amounts with fixed USDT','Equal amounts with fixed entries'], defval='Equal amounts with fixed USDT')
var r_value = input.float(defval = 3.259, title = "Calculated r value")

var float value_of_purchase = 0
var float initial_quantity = 0
if purchaseing_method == 'Equal amounts' and dev_of_equal_amounts == 'Equal amounts with fixed entries' and y <= piramiding + 1
    value_of_purchase := (total_investment/(piramiding + 1))
else if purchaseing_method == 'Equal amounts' and dev_of_equal_amounts == 'Equal amounts with fixed USDT' and y <= piramiding + 1
    value_of_purchase := total_investment / (piramiding + 1)


if purchaseing_method == 'Incremental amounts' and int_val_allocation == '% of cumilative investment' and y <= piramiding + 1
    value_of_purchase := (total_investment * (int_val_prc/100))* math.pow((1+(r_value/100)),y)
else if purchaseing_method == 'Incremental amounts' and int_val_allocation == 'USDT' and y <= piramiding + 1
    value_of_purchase := (int_val_prc)* math.pow((1 + (r_value/100)),y)
    
    



quantity = value_of_purchase/close[1]


//Enter Coustom comand to perform buy and sell actions link with webhook
string buy_comment      =   "BUY" 
string sell_comment     =   "SELL" 

//Trading
if ((point_one == true )) and strategy.position_size == 0 and strategy.opentrades <= piramiding - 1 and sell_comand == false
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)
else if ((point_one == true or point_five == true or point_six == true or point_seven == true)  and ma_9 < strategy.position_avg_price *.99 and  strategy.position_size > 0 ) and strategy.opentrades <= piramiding - 1  and sell_comand == false
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)

if (sell_comand==true) and strategy.position_avg_price * cal_profit_precentage < ma_9
    strategy.close("long", qty = strategy.position_size, comment = sell_comment)

//intermediate selling
if ((sell_comand==true) and m * (1 + profit_precentage_intermidiate/100) < ma_9 and strategy.position_avg_price * 0.98 > ma_9) and int_selling == true
    strategy.close("long", qty = last_purchase[x], comment = sell_comment)


//Graphs

//color change
var hidden_color = color.new(color.white,100)
var color1 = color.blue
var color2 = color.orange
var color3 = color.white
var color4 = color.green

if show == "Compound Indicater"
    color1 := color.blue
else 
    color1 := color.new(color.blue,100)
    
if show == "Co-variances"
    color2 := color.orange
    color3 := color.yellow
    color4 := color.green
else 
    color2 := color.new(color.orange,100)
    color3 := color.new(color.yellow,100)
    color4 := color.new(color.green,100) 

plot(strategy.position_avg_price, title = "Strategy Position Average Price", color = color.green, style = plot.style_circles)
plot(strategy.position_avg_price* cal_profit_precentage, title = "Strategy Profit Line", color = color.yellow, style = plot.style_circles)
plot(strategy.opentrades, title = "open trades", color = color.new(color.white,100))
plot(strategy.netprofit, title = "Cumilative Profits", color = color.new(color.white,100))
plot(total_investment, title = "Total Investment", color = color.new(color.white,100))
plot(result, title = "Entry Price", color = color.new(color.white,100))
plot(last_purchase, title = "Last purchase", color = color.new(color.white,100))
plot(y, title = "Y", color = color.new(color.white,100))
plot(value_of_purchase, title = "value_of_purchase", color = color.new(color.white,100))
plot(max_open_trades, title = "Max Opentrades", color = color.new(color.red,100))
plot(m, title = "m value", color = color.new(color.yellow,100))
//plot(pq, title = "pq value", color = color.new(color.yellow,100))





plot(positive_signal/1000, title = "Compound Indicater", color = color1)
plot((co_variance_price_and_positive_signal), title = "CV between Price & Signal", color = color2)
plot((co_variance_positive_signal_and_signal_high), title = "CV between Higher values & Signal", color = color3)
plot((co_variance_positive_signal_and_signal_low), title = "CV between Lower values & Signal", color = color4)

//Shapes
plotshape(ma_9<strategy.position_avg_price *.99 ? point_one == true:na, title = "End of Major downtrend", style =  shape.arrowdown, color = color.orange, location = location.abovebar, size = size.large, text = "1")
plotshape(((sell_comand==true) and strategy.position_avg_price * cal_profit_precentage < ma_9) or ((sell_comand==true) and m * cal_profit_precentage < ma_9 and strategy.position_avg_price * 0.98 > ma_9)? point_two == true:na, title = "End of Major uptrend", style =  shape.arrowdown, color = color.red, location = location.abovebar, size = size.large, text = "2")

plotshape(((sell_comand==true) and strategy.position_avg_price * cal_profit_precentage < ma_9) or ((sell_comand==true) and m * cal_profit_precentage < ma_9 and strategy.position_avg_price * 0.98 > ma_9)? point_three == true:na, title = "End of intermidiate uptrend", style =  shape.arrowdown, color = color.white, location = location.abovebar, size = size.large, text = "3")

plotshape(ma_9<strategy.position_avg_price *.99 ? point_five == true:na, title = "End of intermidiate downtrend", style =  shape.arrowdown, color = color.green, location = location.abovebar, size = size.large, text = "5")
plotshape(ma_9<strategy.position_avg_price *.99 ? point_six == true:na, title = "End of intermidiate downtrend", style =  shape.arrowdown, color = color.olive, location = location.abovebar, size = size.large, text = "6")
plotshape(ma_9<strategy.position_avg_price *.99 ? point_seven == true:na, title = "End of intermidiate downtrend", style =  shape.arrowdown, color = color.teal, location = location.abovebar, size = size.large, text = "7")

//plotshape(point_four == true, title = "4", style =  shape.arrowdown, color = color.navy, location = location.abovebar, size = size.large, text = "4")
//plotshape(point_eight == true, title = "8", style =  shape.arrowdown, color = color.gray, location = location.abovebar, size = size.large, text = "8")
//plotshape(point_nine == true, title = "9", style =  shape.arrowdown, color = color.purple, location = location.abovebar, size = size.large, text = "9")
//plotshape(point_ten == true, title = "10", style =  shape.arrowdown, color = color.maroon, location = location.abovebar, size = size.large, text = "10")











