Co-relation and St-deviation Strategy - BNB/USDT 15min
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © pcooma

//version 35

//@version=5
strategy("OPV15 V2 (Duplicate of Used for Signal Generation) - Co-relation and St-deviation Strategy - BNB/USDT 15min", shorttitle="OPV15 V2 Duplicate CS - 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=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)
//Backtest dates
fromDay                      = input.int(defval     = 25,      title    = "From (DD/MM/YYYY) - ",     minval = 1, maxval = 31,        group = 'Time Period Values', inline = 'From')
fromMonth                    = input.int(defval     = 02,      title    = "/",                        minval = 1, maxval = 12,        group = 'Time Period Values', inline = 'From')
fromYear                     = input.int(defval     = 2022,    title    = "/",                        minval = 1970,                  group = 'Time Period Values', inline = 'From')

thruDay                      = input.int(defval     = 1,       title    = "Thru (DD/MM/YYYY) - ",     minval = 1, maxval = 31,        group = 'Time Period Values', inline = 'Thru')
thruMonth                    = input.int(defval     = 1,       title    = "/",                        minval = 1, maxval = 12,        group = 'Time Period Values', inline = 'Thru')
thruYear                     = input.int(defval     = 2112,    title    = "/",                        minval = 1970,                  group = 'Time Period Values', inline = 'Thru')

start                        = timestamp(fromYear, fromMonth, fromDay, 00, 00)         // backtest start window
finish                       = timestamp(thruYear, thruMonth, thruDay, 23, 59)         // backtest finish window
//window()  => 
//    time >= start and time <= finish ? true : false                 // create function "within window of time"
use_timeframe               = input.bool(defval = true, title = "Use data window to limit trade")
var window = true
if use_timeframe == true
    window  := time >= start and time <= finish ? true : false
else
    window := true

//Buy and Sell range
var factor_of_supertrend_to_determine_sell_comand               = input.int     (defval = 1,                                                                                            title = "Factor of supertrend to determine buy command",                            group = "Determination of buy or sell command")
var artperiod_of_supertrend_to_determine_sell_comand            = input.int     (defval = 24,                                                                                           title = "ArtPeriod of supertrend to determine buy command",                         group = "Determination of buy or sell command")
buy_comand_high_value                                           = input         (defval = high,                                                                                         title = "Source of Higher value of Look back period",                               group = "Determination of buy or sell command")
buy_comand_low_value                                            = input         (defval = low,                                                                                          title = "Source of Lower value of Look back period",                                group = "Determination of buy or sell command")
var buy_or_sell_lookback                                        = input.int     (defval = 280,                                                                                          title = "Look back period to determine lower low points",                           group = "Determination of buy or sell command")
source_of_lower_point                                           = input         (defval = open,                                                                                         title = "Source of Lower point to initiate purchase",                               group = "Determination of buy or sell command")

// Calculation of profit precentage
var profit_precentage                                           = input.float   (defval = 7,                                                                                            title = "Profit precentage will be",                                                group = "Profit Calculations",                                                                                          step = 0.01)
var intermidiate_selling                                        = input         (defval = false,                                                                                        title = "Enable Swing Trading",                                                     group = "Profit Calculations")
var profit_precentage_intermidiate                              = input.float   (defval = 2,                                                                                            title = "Swing Trading profit precentage will be",                                  group = "Profit Calculations",                                                                                          step = 0.01)

//Fund Management
var int_cap                                                     = input.float   (defval = 1000,                                                                                         title = "Cumilative Investment",                                                    group = "Fund Management")
var purchaseing_method                                          = input.string  (defval ='Equal amounts',                                                                               title = "Value of Purchas will be",                                                 group = "Fund Management",                                                                                              options=['Equal amounts','Incremental amounts'])
var dev_of_equal_amounts                                        = input.string  (defval ='Equal amounts with fixed USDT',                                                               title = "Value of Purchas will be",                                                 group = "Fund Management",                                                                                              options=['Equal amounts with fixed USDT','Equal amounts with fixed entries'])
var int_val_prc                                                 = input.float   (defval = 44,                                                                                           title = "Value of first purchase will be",                                          group = "Fund Management",                                                                                              tooltip = "Minimum value of initial purchase will be 15USDT",       inline = "Investment")
var int_val_allocation                                          = input.string  (defval ='USDT',                                                                                        title = "",                                                                         group = "Fund Management",                                                                                              options=['% of cumilative investment', 'USDT'],                                                                                                  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 r_value                                                     = input.float   (defval = 3.259,                                                                                        title = "Calculated r value",                                                       group = "Input parameters for fund management")

//Principle input
look_back_period                                                = input.int     (defval = 7,                                                                                            title = "General look back period for calculations",                                group = "Principle inputs")
source_of_price_average                                         = input         (defval = close,                                                                                        title = "Source of Average Price",                                                  group = "Principle inputs")
look_back_period_for_price_falling                              = input.int     (defval = 3,                                                                                            title = "Look back period for price falling",                                       group = "Principle inputs")
source_of_ma9                                                   = input         (defval = hl2,                                                                                          title = "Source of average price to determine selling and buying",                  group = "Principle inputs")
look_back_period_of_sma9                                        = input.int     (defval = 3,                                                                                            title = "Look back period of average price to determine buy and sell",              group = "Principle inputs")
ma_9_calculation                                                = input.string  (defval = 'Exponentially Weighted Moving Average (EMA)',                                                title = "Calculation method of average price",                                      group = "Principle inputs",                                                                                             options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])
volume_profile_calculation                                      = input.string  (defval = 'Lenior regression',                                                                          title = "Calculation method of volume profile",                                     group = "Principle inputs",                                                                                             options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Parabolic SAR (parabolic stop and reverse) 
var float sar_start_value                                       = input.float   (defval = 0.2,                                                                                          title = "Start value of SAR",                                                       group = "Parabolic Stop and Reverse (SAR)",                                                                             minval = 0, step = 0.01)
var float sar_incrimant_value                                   = input.float   (defval = 0.2,                                                                                          title = "Increment value  of SAR",                                                  group = "Parabolic Stop and Reverse (SAR)",                                                                             minval = 0, step = 0.01)
var float sar_mac_value                                         = input.float   (defval = 0.2,                                                                                          title = "Max value  of SAR",                                                        group = "Parabolic Stop and Reverse (SAR)",                                                                             minval = 0, step = 0.01)

//Supertrend
var ST_factor_value                                             = input.int     (defval = 1,                                                                                            title = "Factor of Supertrend",                                                     group = "Supertrend",                                                                                                   minval = 0, step = 1)
var ST_art_period_value                                         = input.int     (defval = 10,                                                                                           title = "ArtPeriod of Supertrend",                                                  group = "Supertrend",                                                                                                   minval = 0, step = 1)

//Relative strength index (RSI)
source_of_rsi                                                   = input         (defval = close,                                                                                        title = "Source of RSI",                                                            group = "Relative strength index (RSI)")

//Money flow index (MFI)
source_of_mfi                                                   = input         (defval = close,                                                                                        title = "Source of MFI",                                                            group = "Money flow index (MFI)")

//Balance of Power
bop_calculation                                                 = input.string  (defval='Lenior regression',                                                                            title = "Calculation method of Balance of Power",                                   group = "Balance of Power(BOP)",                                                                                        options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Chande Momentum Oscillator
source_of_mom                                                   = input         (defval = close,                                                                                        title = "Source of MOM",                                                            group = "Chande Momentum Oscillator (MOM)")

//Center of Gravity (COG)
source_of_cog                                                   = input         (defval = close,                                                                                        title = "Source of COG",                                                            group = "The Center of Gravity (COG)")

//Directional Movement Index (DMI)
var dmi_di_length                                               = input.int     (defval = 3,                                                                                            title = "DI Length",                                                                group = "Directional movement index (DMI)",                                                                             minval = 0, step = 1)
var dmi_adx_smoothing_length                                    = input.int     (defval = 10,                                                                                           title = "ADX Smoothing length",                                                     group = "Directional movement index (DMI)",                                                                             minval = 0, step = 1)

//Stochastic
source_of_stoch                                                 = input         (defval = close,                                                                                        title = "Source of Stochastic",                                                     group = "Stochastic")
stoch_calculation                                               = input.string  (defval ='Lenior regression',                                                                           title = "Calculation method of Stochastic",                                         group = "Stochastic",                                                                                                   options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Symmetrically weighted moving average with fixed length
source_of_swma                                                  = input         (defval = close,                                                                                        title = "Source of SWMA",                                                           group = "Symmetrically weighted moving average with fixed length")
swma_calculation                                                = input.string  (defval ='Lenior regression',                                                                           title = "Calculation method of SWMA",                                               group = "Symmetrically weighted moving average with fixed length",                                                      options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//True strength index (TSI)
source_of_tsi                                                   = input         (defval = close,                                                                                        title = "Source of TSI",                                                            group = "True strength index (TSI)")
var tsi_short_length                                            = input.int     (defval = 14,                                                                                           title = "Short Length of TSI",                                                      group = "True strength index (TSI)",                                                                                    minval = 0, step = 1)
var tsi_long_length                                             = input.int     (defval = 28,                                                                                           title = "Long length of TSI",                                                       group = "True strength index (TSI)",                                                                                    minval = 0, step = 1)

//Williams %R
wpr_calculation                                                 = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Williams %R",                                        group = "Williams %R",                                                                                                  options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Accumulation/distribution index
accdist_calculation                                             = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Accumulation/distribution Index",                    group = "Accumulation/distribution Index",                                                                              options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Intraday Intensity Index
iii_calculation                                                 = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Intraday Intensity Index",                           group = "Intraday Intensity Index",                                                                                     options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Negative Volume Index
nvi_calculation                                                 = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Negative Volume Index",                              group = "Negative Volume Index",                                                                                        options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Positive Volume Index
pvi_calculation                                                 = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Positive Volume Index",                              group = "Positive Volume Index",                                                                                        options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//On Balance Volume
obv_calculation                                                 = input.string  (defval ='Weighted Moving Average (WMA)',                                                               title = "Calculation method of On Balance Volume",                                  group = "On Balance Volume",                                                                                            options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Price-Volume Trend
pvt_calculation                                                 = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Price-Volume Trend",                                 group = "Price-Volume Trend",                                                                                           options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//True range
tr_calculation                                                  = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of True range",                                         group = "True range",                                                                                                   options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Volume-weighted average price
vwap_calculation                                                = input.string  (defval ='Hull Moving Average (HMA)',                                                                   title = "Calculation method of Volume-weighted average price",                      group = "Volume-weighted average price",                                                                                options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Williams Accumulation/Distribution
wad_calculation                                                 = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Williams Accumulation/Distribution",                 group = "Williams Accumulation/Distribution",                                                                           options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Williams Variable Accumulation/Distribution
wvad_calculation                                                = input.string  (defval ='Exponentially Weighted Moving Average (EMA)',                                                 title = "Calculation method of Williams Variable Accumulation/Distribution",        group = "Williams Variable Accumulation/Distribution",                                                                  options=['NONE','Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Simple Moving Average
source_of_sma                                                   = input         (defval = close,                                                                                        title = "Source of Simple Moving Average (SMA)",                                    group = "Simple Moving Average (SMA)")

//Exponential Moving Average
source_of_ema                                                   = input         (defval = close,                                                                                        title = "Source of Exponential Moving Average (EMA)",                               group = "Exponential Moving Average (EMA)")

//CCI (commodity channel index)
source_of_cci                                                   = input         (defval = close,                                                                                        title = "Source of Commodity Channel Index (CCI)",                                  group = "Commodity Channel Index (CCI)")

//Chop Zone
source_of_cz                                                    = input         (defval = close,                                                                                        title = "Source of Chop Zone (CZ)",                                                 group = " Chop Zone (CZ)")
source_of_cz_avg                                                = input         (defval = hlc3,                                                                                         title = "Source of Average of Chop Zone (CZ)",                                      group = " Chop Zone (CZ)")
cz_calculation                                                  = input.string  (defval = 'Exponentially Weighted Moving Average (EMA)',                                                title = "Calculation method of Chop Zone",                                          group = " Chop Zone (CZ)",                                                                                              options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Ease of Movement
source_of_eom                                                   = input         (defval = hl2,                                                                                          title = "Source of Ease of Movement (EOM)",                                         group = "Ease of Movement")
eom_calculation                                                 = input.string  (defval = 'Simple Moving Average (SMA)',                                                                title = "Calculation method of Ease of Movement",                                   group = "Ease of Movement",                                                                                             options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Detrended Price Oscillator
source_of_dpo                                                   = input         (defval = close,                                                                                        title = "Source of Detrended Price Oscillator (DPO)",                               group = "Detrended Price Oscillator (DPO)")
isCentered                                                      = input         (defval = false,                                                                                        title="Alignment to center - Detrended Price Oscillator (DPO)",                     group = "Detrended Price Oscillator (DPO)")
dpo_calculation                                                 = input.string  (defval='Simple Moving Average (SMA)',                                                                  title = "Calculation method of Ease of Movement",                                   group = "Detrended Price Oscillator (DPO)",                                                                             options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//Advance Decline Line
source_of_adl                                                   = input         (defval = close,                                                                                        title = "Source of Advance Decline Line (ADL)",                                     group = "Advance Decline Line (ADL)")

//Bull Bear Power
source_of_bullp                                                 = input         (defval = high,                                                                                         title = "Source of Bull Power",                                                     group = "Bull Bear Power (BBP)")
source_of_bearp                                                 = input         (defval = low,                                                                                          title = "Source of Bear Power",                                                     group = "Bull Bear Power (BBP)")
source_of_cal_bullp                                             = input         (defval = close,                                                                                        title = "Source of Baseline of Bull Power",                                         group = "Bull Bear Power (BBP)")
source_of_cal_bearp                                             = input         (defval = close,                                                                                        title = "Source of Baseline of Bear Power",                                         group = "Bull Bear Power (BBP)")
bullp_calculation                                               = input.string  (defval ='Simple Moving Average (SMA)',                                                                 title = "Calculation method of Bull Power",                                         group = "Bull Bear Power (BBP)" ,                                                                                       options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])
bearp_calculation                                               = input.string  (defval ='Simple Moving Average (SMA)',                                                                 title = "Calculation method of Bull Power",                                         group = "Bull Bear Power (BBP)",                                                                                        options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//high
high_impact_calculation                                         = input.string  (defval ='Simple Moving Average (SMA)',                                                                 title = "Impact calculation method of high",                                        group = "Impact Calculation",                                                                                           options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//low
low_impact_calculation                                          = input.string  (defval ='Simple Moving Average (SMA)',                                                                 title = "Impact calculation method of low",                                         group = "Impact Calculation",                                                                                           options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//open
open_impact_calculation                                         = input.string  (defval ='Simple Moving Average (SMA)',                                                                 title = "Impact calculation method of open",                                        group = "Impact Calculation",                                                                                           options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])

//close
close_impact_calculation                                        = input.string  (defval ='Simple Moving Average (SMA)',                                                                 title = "Impact calculation method of close",                                       group = "Impact Calculation",                                                                                           options=['Lenior regression', 'Simple Moving Average (SMA)','Exponentially Weighted Moving Average (EMA)', 'Hull Moving Average (HMA)', 'Exponentially Weighted Moving average with alpha length (RMA)', 'Weighted Moving Average (WMA)', 'Arnaud Legoux Moving Average (ALMA)', 'Symmetrically weighted moving average with fixed length (SWMA)','Volume-weighted Moving Average (VWMA)'])


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//General Calculations
var float volume_avg_14 = 0
var float ma_9 = 0
price_avg_14 = ta.linreg((source_of_price_average), look_back_period, 0)
price_rising = ta.rising(price_avg_14,2)
price_falling = ta.falling(price_avg_14,look_back_period_for_price_falling)

//Volume profile
if volume_profile_calculation == 'Lenior regression'
    volume_avg_14 := ta.linreg(volume, look_back_period, 0)
else if volume_profile_calculation == 'Simple Moving Average (SMA)'
    volume_avg_14 := ta.sma(volume, look_back_period)
else if volume_profile_calculation == 'Exponentially Weighted Moving Average (EMA)'
    volume_avg_14 := ta.ema(volume, look_back_period)
else if volume_profile_calculation == 'Hull Moving Average (HMA)'
    volume_avg_14 := ta.hma(volume, look_back_period)
else if volume_profile_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    volume_avg_14 := ta.rma(volume, look_back_period)
else if volume_profile_calculation == 'Weighted Moving Average (WMA)'
    volume_avg_14 := ta.wma(volume, look_back_period)
else if volume_profile_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    volume_avg_14 := ta.alma(volume, look_back_period,0,3)
else if volume_profile_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    volume_avg_14 := ta.swma(volume)
else if volume_profile_calculation == 'Volume-weighted Moving Average (VWMA)'
    volume_avg_14 := ta.vwma(volume, look_back_period)
if ma_9_calculation == 'Lenior regression'
    ma_9 := ta.linreg(source_of_ma9, look_back_period, 0)
else if ma_9_calculation == 'Simple Moving Average (SMA)'
    ma_9 := ta.sma(source_of_ma9, look_back_period)
else if ma_9_calculation == 'Exponentially Weighted Moving Average (EMA)'
    ma_9 := ta.ema(source_of_ma9, look_back_period)
else if ma_9_calculation == 'Hull Moving Average (HMA)'
    ma_9 := ta.hma(source_of_ma9, look_back_period)
else if ma_9_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    ma_9 := ta.rma(source_of_ma9, look_back_period)
else if ma_9_calculation == 'Weighted Moving Average (WMA)'
    ma_9 := ta.wma(source_of_ma9, look_back_period)
else if ma_9_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    ma_9 := ta.alma(source_of_ma9, look_back_period,0,3)
else if ma_9_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    ma_9 := ta.swma(source_of_ma9)
else if ma_9_calculation == 'Volume-weighted Moving Average (VWMA)'
    ma_9 := ta.vwma(source_of_ma9, look_back_period)
st_dev_of_price_avg_14 = ta.stdev(price_avg_14, look_back_period)
st_dev_of_volume_avg_14 = ta.stdev(volume_avg_14, look_back_period)
corelation_btw_price_avg_14_and_volume_avg_14 = ta.correlation(volume_avg_14,price_avg_14,look_back_period)

//Parabolic SAR (parabolic stop and reverse) 
indicator_sar_14 = ta.sar(sar_start_value, sar_incrimant_value, sar_mac_value)
[middle_sar_14, upper_sar_14, lower_sar_14] = ta.bb(indicator_sar_14, 5, 4)
bb_gap_of_sar_14 = indicator_sar_14 - middle_sar_14
st_dev_of_bb_gap_of_sar_14 = ta.stdev(bb_gap_of_sar_14, look_back_period)
st_dev_of_indicator_sar_14 = ta.stdev(indicator_sar_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_sar_14 = ta.correlation(indicator_sar_14,price_avg_14,look_back_period)
first_degree_indicator_sar_14 = st_dev_of_indicator_sar_14 * corelation_btw_price_avg_14_and_indicator_sar_14 

//Supertrend (ST)
var float st_line = 0
[supertrend, direction] = ta.supertrend(ST_factor_value, ST_art_period_value)
up_direction = direction < 0 ? supertrend : na
down_direction = direction < 0? na : supertrend
if up_direction > 0
    st_line := up_direction
else
    st_line := down_direction
indicator_st_14 = st_line
[middle_st_14, upper_st_14, lower_st_14] = ta.bb(indicator_st_14, 5, 4)
bb_gap_of_st_14 = indicator_st_14 - middle_st_14
st_dev_of_bb_gap_of_st_14 = ta.stdev(bb_gap_of_st_14, look_back_period)
st_dev_of_indicator_st_14 = ta.stdev(indicator_st_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_st_14 = ta.correlation(indicator_st_14,price_avg_14,look_back_period)
first_degree_indicator_st_14 = st_dev_of_indicator_st_14 * corelation_btw_price_avg_14_and_indicator_st_14

//Relative strength index (RSI)
indicator_rsi_14 = ta.rsi(source_of_rsi,look_back_period)
[middle_rsi_14, upper_rsi_14, lower_rsi_14] = ta.bb(indicator_rsi_14, 5, 4)
bb_gap_of_rsi_14 = indicator_rsi_14 - middle_rsi_14
st_dev_of_bb_gap_of_rsi_14 = ta.stdev(bb_gap_of_rsi_14, look_back_period)
st_dev_of_indicator_rsi_14 = ta.stdev(indicator_rsi_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_rsi_14 = ta.correlation(indicator_rsi_14,price_avg_14,look_back_period)
first_degree_indicator_rsi_14 = st_dev_of_indicator_rsi_14 * corelation_btw_price_avg_14_and_indicator_rsi_14 * st_dev_of_bb_gap_of_rsi_14

//Money flow index (MFI)
indicator_mfi_14 = ta.mfi(source_of_mfi,look_back_period)
[middle_mfi_14, upper_mfi_14, lower_mfi_14] = ta.bb(indicator_mfi_14, 5, 4)
bb_gap_of_mfi_14 = indicator_mfi_14 - middle_mfi_14
st_dev_of_bb_gap_of_mfi_14 = ta.stdev(bb_gap_of_mfi_14, look_back_period)
st_dev_of_indicator_mfi_14 = ta.stdev(indicator_mfi_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_mfi_14 = ta.correlation(indicator_mfi_14,price_avg_14,look_back_period)
first_degree_indicator_mfi_14 = st_dev_of_indicator_mfi_14 * corelation_btw_price_avg_14_and_indicator_mfi_14 * st_dev_of_bb_gap_of_mfi_14

//Balance of Power (BOP)
var float bop_f = 0
bop_nf = ta.linreg((((close - open) / (high - low) * 100)+100)/2, look_back_period, 0)
if bop_calculation == 'Lenior regression'
    bop_f := bop_nf
else if bop_calculation == 'Simple Moving Average (SMA)'
    bop_f := ta.sma(bop_nf, look_back_period)
else if bop_calculation == 'Exponentially Weighted Moving Average (EMA)'
    bop_f := ta.ema(bop_nf, look_back_period)
else if bop_calculation == 'Hull Moving Average (HMA)'
    bop_f := ta.hma(bop_nf, look_back_period)
else if bop_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    bop_f := ta.rma(bop_nf, look_back_period)
else if bop_calculation == 'Weighted Moving Average (WMA)'
    bop_f := ta.wma(bop_nf, look_back_period)
else if bop_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    bop_f := ta.alma(bop_nf, look_back_period,0,3)
else if bop_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    bop_f := ta.swma(bop_nf)
else if bop_calculation == 'Volume-weighted Moving Average (VWMA)'
    bop_f := ta.vwma(bop_nf, look_back_period)
indicator_bop_14 = bop_f
[middle_bop_14, upper_bop_14, lower_bop_14] = ta.bb(indicator_bop_14, 5, 4)
bb_gap_of_bop_14 = indicator_bop_14 - middle_bop_14
st_dev_of_bb_gap_of_bop_14 = ta.stdev(bb_gap_of_bop_14, look_back_period)
st_dev_of_indicator_bop_14 = ta.stdev(indicator_bop_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_bop_14 = ta.correlation(indicator_bop_14,price_avg_14,look_back_period)
first_degree_indicator_bop_14 = st_dev_of_indicator_bop_14 * corelation_btw_price_avg_14_and_indicator_bop_14 * st_dev_of_bb_gap_of_bop_14

//Chande Momentum Oscillator
indicator_mom_14 = ta.cmo(source_of_mom,look_back_period)
[middle_mom_14, upper_mom_14, lower_mom_14] = ta.bb(indicator_mom_14, 5, 4)
bb_gap_of_mom_14 = indicator_mom_14 - middle_mom_14
st_dev_of_bb_gap_of_mom_14 = ta.stdev(bb_gap_of_mom_14, look_back_period)
st_dev_of_indicator_mom_14 = ta.stdev(indicator_mom_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_mom_14 = ta.correlation(indicator_mom_14,price_avg_14,look_back_period)
first_degree_indicator_mom_14 = st_dev_of_indicator_mom_14 * corelation_btw_price_avg_14_and_indicator_mom_14 * st_dev_of_bb_gap_of_mom_14

//Center of Gravity (COG)
indicator_cog_14 = ta.cog(source_of_cog,look_back_period)
[middle_cog_14, upper_cog_14, lower_cog_14] = ta.bb(indicator_cog_14, 5, 4)
bb_gap_of_cog_14 = indicator_cog_14 - middle_cog_14
st_dev_of_bb_gap_of_cog_14 = ta.stdev(bb_gap_of_cog_14, look_back_period)
st_dev_of_indicator_cog_14 = ta.stdev(indicator_cog_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_cog_14 = ta.correlation(indicator_cog_14,price_avg_14,look_back_period)
first_degree_indicator_cog_14 = st_dev_of_indicator_cog_14 * corelation_btw_price_avg_14_and_indicator_cog_14 * st_dev_of_bb_gap_of_cog_14

//Directional Movement Index (DMI)
[diplus, diminus,indicator_dmi_14] = ta.dmi(dmi_di_length, dmi_adx_smoothing_length)
[middle_dmi_14, upper_dmi_14, lower_dmi_14] = ta.bb(indicator_dmi_14, 5, 4)
bb_gap_of_dmi_14 = indicator_dmi_14 - middle_dmi_14
st_dev_of_bb_gap_of_dmi_14 = ta.stdev(bb_gap_of_dmi_14, look_back_period)
st_dev_of_indicator_dmi_14 = ta.stdev(indicator_dmi_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_dmi_14 = ta.correlation(indicator_dmi_14,price_avg_14,look_back_period)
first_degree_indicator_dmi_14 = st_dev_of_indicator_dmi_14 * corelation_btw_price_avg_14_and_indicator_dmi_14 * st_dev_of_bb_gap_of_dmi_14

//Stochastic
stoch_nf = ta.stoch(source_of_stoch, high, low, look_back_period)
var float stoch_f = 0
if stoch_calculation == 'Lenior regression'
    stoch_f := ta.linreg(stoch_nf, look_back_period, 0)
else if stoch_calculation == 'Simple Moving Average (SMA)'
    stoch_f := ta.sma(stoch_nf, look_back_period)
else if stoch_calculation == 'Exponentially Weighted Moving Average (EMA)'
    stoch_f := ta.ema(stoch_nf, look_back_period)
else if stoch_calculation == 'Hull Moving Average (HMA)'
    stoch_f := ta.hma(stoch_nf, look_back_period)
else if stoch_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    stoch_f := ta.rma(stoch_nf, look_back_period)
else if stoch_calculation == 'Weighted Moving Average (WMA)'
    stoch_f := ta.wma(stoch_nf, look_back_period)
else if stoch_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    stoch_f := ta.alma(stoch_nf, look_back_period,0,3)
else if stoch_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    stoch_f := ta.swma(stoch_nf)
else if stoch_calculation == 'Volume-weighted Moving Average (VWMA)'
    stoch_f := ta.vwma(stoch_nf, look_back_period)
indicator_stoch_14 = stoch_f
[middle_stoch_14, upper_stoch_14, lower_stoch_14] = ta.bb(indicator_stoch_14, 5, 4)
bb_gap_of_stoch_14 = indicator_stoch_14 - middle_stoch_14
st_dev_of_bb_gap_of_stoch_14 = ta.stdev(bb_gap_of_stoch_14, look_back_period)
st_dev_of_indicator_stoch_14 = ta.stdev(indicator_stoch_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_stoch_14 = ta.correlation(indicator_stoch_14,price_avg_14,look_back_period)
first_degree_indicator_stoch_14 = st_dev_of_indicator_stoch_14 * corelation_btw_price_avg_14_and_indicator_stoch_14 * st_dev_of_bb_gap_of_stoch_14

//Symmetrically weighted moving average with fixed length
swma_nf = ta.swma(source_of_swma)
var float swma_f = 0
if swma_calculation == 'Lenior regression'
    swma_f := ta.linreg(swma_nf, look_back_period, 0)
else if swma_calculation == 'Simple Moving Average (SMA)'
    swma_f := ta.sma(swma_nf, look_back_period)
else if swma_calculation == 'Exponentially Weighted Moving Average (EMA)'
    swma_f := ta.ema(swma_nf, look_back_period)
else if swma_calculation == 'Hull Moving Average (HMA)'
    swma_f := ta.hma(swma_nf, look_back_period)
else if swma_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    swma_f := ta.rma(swma_nf, look_back_period)
else if swma_calculation == 'Weighted Moving Average (WMA)'
    swma_f := ta.wma(swma_nf, look_back_period)
else if swma_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    swma_f := ta.alma(swma_nf, look_back_period,0,3)
else if swma_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    swma_f := ta.swma(swma_nf)
else if swma_calculation == 'Volume-weighted Moving Average (VWMA)'
    swma_f := ta.vwma(swma_nf, look_back_period)
indicator_swma_14 = swma_f
[middle_swma_14, upper_swma_14, lower_swma_14] = ta.bb(indicator_swma_14, 5, 4)
bb_gap_of_swma_14 = indicator_swma_14 - middle_swma_14
st_dev_of_bb_gap_of_swma_14 = ta.stdev(bb_gap_of_swma_14, look_back_period)
st_dev_of_indicator_swma_14 = ta.stdev(indicator_swma_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_swma_14 = ta.correlation(indicator_swma_14,price_avg_14,look_back_period)
first_degree_indicator_swma_14 = st_dev_of_indicator_swma_14 * corelation_btw_price_avg_14_and_indicator_swma_14 *  st_dev_of_bb_gap_of_swma_14

//True strength index (TSI)
indicator_tsi_14 = ta.tsi(source_of_tsi, tsi_short_length, tsi_long_length)
[middle_tsi_14, upper_tsi_14, lower_tsi_14] = ta.bb(indicator_tsi_14, 5, 4)
bb_gap_of_tsi_14 = indicator_tsi_14 - middle_tsi_14
st_dev_of_bb_gap_of_tsi_14 = ta.stdev(bb_gap_of_tsi_14, look_back_period)
st_dev_of_indicator_tsi_14 = ta.stdev(indicator_tsi_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_tsi_14 = ta.correlation(indicator_tsi_14,price_avg_14,look_back_period)
first_degree_indicator_tsi_14 = st_dev_of_indicator_tsi_14 * corelation_btw_price_avg_14_and_indicator_tsi_14 * st_dev_of_bb_gap_of_tsi_14

//Williams %R
var float wpr_f = 0
wpr_nf = ta.wpr(look_back_period)
if wpr_calculation == 'NONE'
    wpr_f := wpr_nf
else if wpr_calculation == 'Lenior regression'
    wpr_f := ta.linreg(wpr_nf, look_back_period, 0)
else if wpr_calculation == 'Simple Moving Average (SMA)'
    wpr_f := ta.sma(wpr_nf, look_back_period)
else if wpr_calculation == 'Exponentially Weighted Moving Average (EMA)'
    wpr_f := ta.ema(wpr_nf, look_back_period)
else if wpr_calculation == 'Hull Moving Average (HMA)'
    wpr_f := ta.hma(wpr_nf, look_back_period)
else if wpr_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    wpr_f := ta.rma(wpr_nf, look_back_period)
else if wpr_calculation == 'Weighted Moving Average (WMA)'
    wpr_f := ta.wma(wpr_nf, look_back_period)
else if wpr_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    wpr_f := ta.alma(wpr_nf, look_back_period,0,3)
else if wpr_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    wpr_f := ta.swma(wpr_nf)
else if wpr_calculation == 'Volume-weighted Moving Average (VWMA)'
    wpr_f := ta.vwma(wpr_nf, look_back_period)
indicator_wpr_14 = wpr_f
[middle_wpr_14, upper_wpr_14, lower_wpr_14] = ta.bb(indicator_wpr_14, 5, 4)
bb_gap_of_wpr_14 = indicator_wpr_14 - middle_wpr_14
st_dev_of_bb_gap_of_wpr_14 = ta.stdev(bb_gap_of_wpr_14, look_back_period)
st_dev_of_indicator_wpr_14 = ta.stdev(indicator_wpr_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_wpr_14 = ta.correlation(indicator_wpr_14,price_avg_14,look_back_period)
first_degree_indicator_wpr_14 = st_dev_of_indicator_wpr_14 * corelation_btw_price_avg_14_and_indicator_wpr_14 * st_dev_of_bb_gap_of_wpr_14

//Accumulation/distribution index
var float accdist_f = 0
accdist_nf = ta.accdist
if accdist_calculation == 'NONE'
    accdist_f := accdist_nf
else if accdist_calculation == 'Lenior regression'
    accdist_f := ta.linreg(accdist_nf, look_back_period, 0)
else if accdist_calculation == 'Simple Moving Average (SMA)'
    accdist_f := ta.sma(accdist_nf, look_back_period)
else if accdist_calculation == 'Exponentially Weighted Moving Average (EMA)'
    accdist_f := ta.ema(accdist_nf, look_back_period)
else if accdist_calculation == 'Hull Moving Average (HMA)'
    accdist_f := ta.hma(accdist_nf, look_back_period)
else if accdist_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    accdist_f := ta.rma(accdist_nf, look_back_period)
else if accdist_calculation == 'Weighted Moving Average (WMA)'
    accdist_f := ta.wma(accdist_nf, look_back_period)
else if accdist_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    accdist_f := ta.alma(accdist_nf, look_back_period,0,3)
else if accdist_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    accdist_f := ta.swma(accdist_nf)
else if accdist_calculation == 'Volume-weighted Moving Average (VWMA)'
    accdist_f := ta.vwma(accdist_nf, look_back_period)
indicator_accdist_14 = accdist_f
[middle_accdist_14, upper_accdist_14, lower_accdist_14] = ta.bb(indicator_accdist_14, 5, 4)
bb_gap_of_accdist_14 = indicator_accdist_14 - middle_accdist_14
st_dev_of_bb_gap_of_accdist_14 = ta.stdev(bb_gap_of_accdist_14, look_back_period)
st_dev_of_indicator_accdist_14 = ta.stdev(indicator_accdist_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_accdist_14 = ta.correlation(indicator_accdist_14,price_avg_14,look_back_period)
first_degree_indicator_accdist_14 = st_dev_of_indicator_accdist_14 * corelation_btw_price_avg_14_and_indicator_accdist_14 * st_dev_of_bb_gap_of_accdist_14

//Intraday Intensity Index
var float iii_f = 0
iii_nf = ta.iii
if iii_calculation == 'NONE'
    iii_f := iii_nf
else if iii_calculation == 'Lenior regression'
    iii_f := ta.linreg(iii_nf, look_back_period, 0)
else if iii_calculation == 'Simple Moving Average (SMA)'
    iii_f := ta.sma(iii_nf, look_back_period)
else if iii_calculation == 'Exponentially Weighted Moving Average (EMA)'
    iii_f := ta.ema(iii_nf, look_back_period)
else if iii_calculation == 'Hull Moving Average (HMA)'
    iii_f := ta.hma(iii_nf, look_back_period)
else if iii_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    iii_f := ta.rma(iii_nf, look_back_period)
else if iii_calculation == 'Weighted Moving Average (WMA)'
    iii_f := ta.wma(iii_nf, look_back_period)
else if iii_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    iii_f := ta.alma(iii_nf, look_back_period,0,3)
else if iii_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    iii_f := ta.swma(iii_nf)
else if iii_calculation == 'Volume-weighted Moving Average (VWMA)'
    iii_f := ta.vwma(iii_nf, look_back_period)
indicator_iii_14 = iii_f
[middle_iii_14, upper_iii_14, lower_iii_14] = ta.bb(indicator_iii_14, 5, 4)
bb_gap_of_iii_14 = indicator_iii_14 - middle_iii_14
st_dev_of_bb_gap_of_iii_14 = ta.stdev(bb_gap_of_iii_14, look_back_period)
st_dev_of_indicator_iii_14 = ta.stdev(indicator_iii_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_iii_14 = ta.correlation(indicator_iii_14,price_avg_14,look_back_period)
first_degree_indicator_iii_14 = st_dev_of_indicator_iii_14 * corelation_btw_price_avg_14_and_indicator_iii_14 * st_dev_of_bb_gap_of_iii_14

//Negative Volume Index
var float nvi_f = 0
nvi_nf = ta.nvi
if nvi_calculation == 'NONE'
    nvi_f := nvi_nf
else if nvi_calculation == 'Lenior regression'
    nvi_f := ta.linreg(nvi_nf, look_back_period, 0)
else if nvi_calculation == 'Simple Moving Average (SMA)'
    nvi_f := ta.sma(nvi_nf, look_back_period)
else if nvi_calculation == 'Exponentially Weighted Moving Average (EMA)'
    nvi_f := ta.ema(nvi_nf, look_back_period)
else if nvi_calculation == 'Hull Moving Average (HMA)'
    nvi_f := ta.hma(nvi_nf, look_back_period)
else if nvi_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    nvi_f := ta.rma(nvi_nf, look_back_period)
else if nvi_calculation == 'Weighted Moving Average (WMA)'
    nvi_f := ta.wma(nvi_nf, look_back_period)
else if nvi_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    nvi_f := ta.alma(nvi_nf, look_back_period,0,3)
else if nvi_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    nvi_f := ta.swma(nvi_nf)
else if nvi_calculation == 'Volume-weighted Moving Average (VWMA)'
    nvi_f := ta.vwma(nvi_nf, look_back_period)
indicator_nvi_14 = nvi_f
[middle_nvi_14, upper_nvi_14, lower_nvi_14] = ta.bb(indicator_nvi_14, 5, 4)
bb_gap_of_nvi_14 = indicator_nvi_14 - middle_nvi_14
st_dev_of_bb_gap_of_nvi_14 = ta.stdev(bb_gap_of_nvi_14, look_back_period)
st_dev_of_indicator_nvi_14 = ta.stdev(indicator_nvi_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_nvi_14 = ta.correlation(indicator_nvi_14,price_avg_14,look_back_period)
first_degree_indicator_nvi_14 = st_dev_of_indicator_nvi_14 * corelation_btw_price_avg_14_and_indicator_nvi_14*st_dev_of_bb_gap_of_nvi_14

//Positive Volume Index
var float pvi_f = 0
pvi_nf = ta.pvi
if pvi_calculation == 'NONE'
    pvi_f := pvi_nf
else if pvi_calculation == 'Lenior regression'
    pvi_f := ta.linreg(pvi_nf, look_back_period, 0)
else if pvi_calculation == 'Simple Moving Average (SMA)'
    pvi_f := ta.sma(pvi_nf, look_back_period)
else if pvi_calculation == 'Exponentially Weighted Moving Average (EMA)'
    pvi_f := ta.ema(pvi_nf, look_back_period)
else if pvi_calculation == 'Hull Moving Average (HMA)'
    pvi_f := ta.hma(pvi_nf, look_back_period)
else if pvi_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    pvi_f := ta.rma(pvi_nf, look_back_period)
else if pvi_calculation == 'Weighted Moving Average (WMA)'
    pvi_f := ta.wma(pvi_nf, look_back_period)
else if pvi_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    pvi_f := ta.alma(pvi_nf, look_back_period,0,3)
else if pvi_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    pvi_f := ta.swma(pvi_nf)
else if pvi_calculation == 'Volume-weighted Moving Average (VWMA)'
    pvi_f := ta.vwma(pvi_nf, look_back_period)
indicator_pvi_14 = pvi_f
[middle_pvi_14, upper_pvi_14, lower_pvi_14] = ta.bb(indicator_pvi_14, 5, 4)
bb_gap_of_pvi_14 = indicator_pvi_14 - middle_pvi_14
st_dev_of_bb_gap_of_pvi_14 = ta.stdev(bb_gap_of_pvi_14, look_back_period)
st_dev_of_indicator_pvi_14 = ta.stdev(indicator_pvi_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_pvi_14 = ta.correlation(indicator_pvi_14,price_avg_14,look_back_period)
first_degree_indicator_pvi_14 = st_dev_of_indicator_pvi_14 * corelation_btw_price_avg_14_and_indicator_pvi_14*st_dev_of_bb_gap_of_pvi_14

//On Balance Volume
var float obv_f = 0
obv_nf = ta.obv
if obv_calculation == 'NONE'
    obv_f := obv_nf
else if obv_calculation == 'Lenior regression'
    obv_f := ta.linreg(obv_nf, look_back_period, 0)
else if obv_calculation == 'Simple Moving Average (SMA)'
    obv_f := ta.sma(obv_nf, look_back_period)
else if obv_calculation == 'Exponentially Weighted Moving Average (EMA)'
    obv_f := ta.ema(obv_nf, look_back_period)
else if obv_calculation == 'Hull Moving Average (HMA)'
    obv_f := ta.hma(obv_nf, look_back_period)
else if obv_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    obv_f := ta.rma(obv_nf, look_back_period)
else if obv_calculation == 'Weighted Moving Average (WMA)'
    obv_f := ta.wma(obv_nf, look_back_period)
else if obv_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    obv_f := ta.alma(obv_nf, look_back_period,0,3)
else if obv_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    obv_f := ta.swma(obv_nf)
else if obv_calculation == 'Volume-weighted Moving Average (VWMA)'
    obv_f := ta.vwma(obv_nf, look_back_period)
indicator_obv_14 = obv_f
[middle_obv_14, upper_obv_14, lower_obv_14] = ta.bb(indicator_obv_14, 5, 4)
bb_gap_of_obv_14 = indicator_obv_14 - middle_obv_14
st_dev_of_bb_gap_of_obv_14 = ta.stdev(bb_gap_of_obv_14, look_back_period)
st_dev_of_indicator_obv_14 = ta.stdev(indicator_obv_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_obv_14 = ta.correlation(indicator_obv_14,price_avg_14,look_back_period)
first_degree_indicator_obv_14 = st_dev_of_indicator_obv_14 * corelation_btw_price_avg_14_and_indicator_obv_14*st_dev_of_bb_gap_of_obv_14

//Price-Volume Trend
var float pvt_f = 0
pvt_nf = ta.pvt
if pvt_calculation == 'NONE'
    pvt_f := pvt_nf
else if pvt_calculation == 'Lenior regression'
    pvt_f := ta.linreg(pvt_nf, look_back_period, 0)
else if pvt_calculation == 'Simple Moving Average (SMA)'
    pvt_f := ta.sma(pvt_nf, look_back_period)
else if pvt_calculation == 'Exponentially Weighted Moving Average (EMA)'
    pvt_f := ta.ema(pvt_nf, look_back_period)
else if pvt_calculation == 'Hull Moving Average (HMA)'
    pvt_f := ta.hma(pvt_nf, look_back_period)
else if pvt_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    pvt_f := ta.rma(pvt_nf, look_back_period)
else if pvt_calculation == 'Weighted Moving Average (WMA)'
    pvt_f := ta.wma(pvt_nf, look_back_period)
else if pvt_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    pvt_f := ta.alma(pvt_nf, look_back_period,0,3)
else if pvt_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    pvt_f := ta.swma(pvt_nf)
else if pvt_calculation == 'Volume-weighted Moving Average (VWMA)'
    pvt_f := ta.vwma(pvt_nf, look_back_period)
indicator_pvt_14 = pvt_f
[middle_pvt_14, upper_pvt_14, lower_pvt_14] = ta.bb(indicator_pvt_14, 5, 4)
bb_gap_of_pvt_14 = indicator_pvt_14 - middle_pvt_14
st_dev_of_bb_gap_of_pvt_14 = ta.stdev(bb_gap_of_pvt_14, look_back_period)
st_dev_of_indicator_pvt_14 = ta.stdev(indicator_pvt_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_pvt_14 = ta.correlation(indicator_pvt_14,price_avg_14,look_back_period)
first_degree_indicator_pvt_14 = st_dev_of_indicator_pvt_14 * corelation_btw_price_avg_14_and_indicator_pvt_14*st_dev_of_bb_gap_of_pvt_14

//True range
var float tr_f = 0
tr_nf = ta.tr
if tr_calculation == 'NONE'
    tr_f := tr_nf
else if tr_calculation == 'Lenior regression'
    tr_f := ta.linreg(tr_nf, look_back_period, 0)
else if tr_calculation == 'Simple Moving Average (SMA)'
    tr_f := ta.sma(tr_nf, look_back_period)
else if tr_calculation == 'Exponentially Weighted Moving Average (EMA)'
    tr_f := ta.ema(tr_nf, look_back_period)
else if tr_calculation == 'Hull Moving Average (HMA)'
    tr_f := ta.hma(tr_nf, look_back_period)
else if tr_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    tr_f := ta.rma(tr_nf, look_back_period)
else if tr_calculation == 'Weighted Moving Average (WMA)'
    tr_f := ta.wma(tr_nf, look_back_period)
else if tr_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    tr_f := ta.alma(tr_nf, look_back_period,0,3)
else if tr_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    tr_f := ta.swma(tr_nf)
else if tr_calculation == 'Volume-weighted Moving Average (VWMA)'
    tr_f := ta.vwma(tr_nf, look_back_period)
indicator_tr_14 = tr_f
[middle_tr_14, upper_tr_14, lower_tr_14] = ta.bb(indicator_tr_14, 5, 4)
bb_gap_of_tr_14 = indicator_tr_14 - middle_tr_14
st_dev_of_bb_gap_of_tr_14 = ta.stdev(bb_gap_of_tr_14, look_back_period)
st_dev_of_indicator_tr_14 = ta.stdev(indicator_tr_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_tr_14 = ta.correlation(indicator_tr_14,price_avg_14,look_back_period)
first_degree_indicator_tr_14 = st_dev_of_indicator_tr_14 * corelation_btw_price_avg_14_and_indicator_tr_14*st_dev_of_bb_gap_of_tr_14

//Volume-weighted average price
var float vwap_f = 0
vwap_nf = ta.vwap
if vwap_calculation == 'NONE'
    vwap_f := vwap_nf
else if vwap_calculation == 'Lenior regression'
    vwap_f := ta.linreg(vwap_nf, look_back_period, 0)
else if vwap_calculation == 'Simple Moving Average (SMA)'
    vwap_f := ta.sma(vwap_nf, look_back_period)
else if vwap_calculation == 'Exponentially Weighted Moving Average (EMA)'
    vwap_f := ta.ema(vwap_nf, look_back_period)
else if vwap_calculation == 'Hull Moving Average (HMA)'
    vwap_f := ta.hma(vwap_nf, look_back_period)
else if vwap_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    vwap_f := ta.rma(vwap_nf, look_back_period)
else if vwap_calculation == 'Weighted Moving Average (WMA)'
    vwap_f := ta.wma(vwap_nf, look_back_period)
else if vwap_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    vwap_f := ta.alma(vwap_nf, look_back_period,0,3)
else if vwap_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    vwap_f := ta.swma(vwap_nf)
else if vwap_calculation == 'Volume-weighted Moving Average (VWMA)'
    vwap_f := ta.vwma(vwap_nf, look_back_period)
indicator_vwap_14 = vwap_f
[middle_vwap_14, upper_vwap_14, lower_vwap_14] = ta.bb(indicator_vwap_14, 5, 4)
bb_gap_of_vwap_14 = indicator_vwap_14 - middle_vwap_14
st_dev_of_bb_gap_of_vwap_14 = ta.stdev(bb_gap_of_vwap_14, look_back_period)
st_dev_of_indicator_vwap_14 = ta.stdev(indicator_vwap_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_vwap_14 = ta.correlation(indicator_vwap_14,price_avg_14,look_back_period)
first_degree_indicator_vwap_14 = st_dev_of_indicator_vwap_14 * corelation_btw_price_avg_14_and_indicator_vwap_14*st_dev_of_bb_gap_of_vwap_14

//Williams Accumulation/Distribution
var float wad_f = 0
wad_nf = ta.wad
if wad_calculation == 'NONE'
    wad_f := wad_nf
else if wad_calculation == 'Lenior regression'
    wad_f := ta.linreg(wad_nf, look_back_period, 0)
else if wad_calculation == 'Simple Moving Average (SMA)'
    wad_f := ta.sma(wad_nf, look_back_period)
else if wad_calculation == 'Exponentially Weighted Moving Average (EMA)'
    wad_f := ta.ema(wad_nf, look_back_period)
else if wad_calculation == 'Hull Moving Average (HMA)'
    wad_f := ta.hma(wad_nf, look_back_period)
else if wad_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    wad_f := ta.rma(wad_nf, look_back_period)
else if wad_calculation == 'Weighted Moving Average (WMA)'
    wad_f := ta.wma(wad_nf, look_back_period)
else if wad_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    wad_f := ta.alma(wad_nf, look_back_period,0,3)
else if wad_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    wad_f := ta.swma(wad_nf)
else if wad_calculation == 'Volume-weighted Moving Average (VWMA)'
    wad_f := ta.vwma(wad_nf, look_back_period)
indicator_wad_14 = wad_f
[middle_wad_14, upper_wad_14, lower_wad_14] = ta.bb(indicator_wad_14, 5, 4)
bb_gap_of_wad_14 = indicator_wad_14 - middle_wad_14
st_dev_of_bb_gap_of_wad_14 = ta.stdev(bb_gap_of_wad_14, look_back_period)
st_dev_of_indicator_wad_14 = ta.stdev(indicator_wad_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_wad_14 = ta.correlation(indicator_wad_14,price_avg_14,look_back_period)
first_degree_indicator_wad_14 = st_dev_of_indicator_wad_14 * corelation_btw_price_avg_14_and_indicator_wad_14*st_dev_of_bb_gap_of_wad_14

//Williams Variable Accumulation/Distribution
var float wvad_f = 0
wvad_nf = ta.wvad
if wvad_calculation == 'NONE'
    wvad_f := wvad_nf
else if wvad_calculation == 'Lenior regression'
    wvad_f := ta.linreg(wvad_nf, look_back_period, 0)
else if wvad_calculation == 'Simple Moving Average (SMA)'
    wvad_f := ta.sma(wvad_nf, look_back_period)
else if wvad_calculation == 'Exponentially Weighted Moving Average (EMA)'
    wvad_f := ta.ema(wvad_nf, look_back_period)
else if wvad_calculation == 'Hull Moving Average (HMA)'
    wvad_f := ta.hma(wvad_nf, look_back_period)
else if wvad_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    wvad_f := ta.rma(wvad_nf, look_back_period)
else if wvad_calculation == 'Weighted Moving Average (WMA)'
    wvad_f := ta.wma(wvad_nf, look_back_period)
else if wvad_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    wvad_f := ta.alma(wvad_nf, look_back_period,0,3)
else if wvad_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    wvad_f := ta.swma(wvad_nf)
else if wvad_calculation == 'Volume-weighted Moving Average (VWMA)'
    wvad_f := ta.vwma(wvad_nf, look_back_period)
indicator_wvad_14 = wvad_f
[middle_wvad_14, upper_wvad_14, lower_wvad_14] = ta.bb(indicator_wvad_14, 5, 4)
bb_gap_of_wvad_14 = indicator_wvad_14 - middle_wvad_14
st_dev_of_bb_gap_of_wvad_14 = ta.stdev(bb_gap_of_wvad_14, look_back_period)
st_dev_of_indicator_wvad_14 = ta.stdev(indicator_wvad_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_wvad_14 = ta.correlation(indicator_wvad_14,price_avg_14,look_back_period)
first_degree_indicator_wvad_14 = st_dev_of_indicator_wvad_14 * corelation_btw_price_avg_14_and_indicator_wvad_14*st_dev_of_bb_gap_of_wvad_14

//Simple Moving Average
indicator_sma_14 = ta.sma(source_of_sma,look_back_period) - ta.sma(source_of_sma,200)
[middle_sma_14, upper_sma_14, lower_sma_14] = ta.bb(indicator_sma_14, 5, 4)
bb_gap_of_sma_14 = indicator_sma_14 - middle_sma_14
st_dev_of_bb_gap_of_sma_14 = ta.stdev(bb_gap_of_sma_14, look_back_period)
st_dev_of_indicator_sma_14 = ta.stdev(indicator_sma_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_sma_14 = ta.correlation(indicator_sma_14,price_avg_14,look_back_period)
first_degree_indicator_sma_14 = st_dev_of_indicator_sma_14 * corelation_btw_price_avg_14_and_indicator_sma_14*st_dev_of_bb_gap_of_sma_14

//Exponential Moving Average
indicator_ema_14 = ta.ema(source_of_ema,look_back_period) - ta.sma(source_of_ema,200)
[middle_ema_14, upper_ema_14, lower_ema_14] = ta.bb(indicator_ema_14, 5, 4)
bb_gap_of_ema_14 = indicator_ema_14 - middle_ema_14
st_dev_of_bb_gap_of_ema_14 = ta.stdev(bb_gap_of_ema_14, look_back_period)
st_dev_of_indicator_ema_14 = ta.stdev(indicator_ema_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_ema_14 = ta.correlation(indicator_ema_14,price_avg_14,look_back_period)
first_degree_indicator_ema_14 = st_dev_of_indicator_ema_14 * corelation_btw_price_avg_14_and_indicator_ema_14*st_dev_of_bb_gap_of_ema_14

//CCI (commodity channel index)
indicator_cci_14 = ta.cci(source_of_cci, look_back_period)
[middle_cci_14, upper_cci_14, lower_cci_14] = ta.bb(indicator_cci_14, 5, 4)
bb_gap_of_cci_14 = indicator_cci_14 - middle_cci_14
st_dev_of_bb_gap_of_cci_14 = ta.stdev(bb_gap_of_cci_14, look_back_period)
st_dev_of_indicator_cci_14 = ta.stdev(indicator_cci_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_cci_14 = ta.correlation(indicator_cci_14,price_avg_14,look_back_period)
first_degree_indicator_cci_14 = st_dev_of_indicator_cci_14 * corelation_btw_price_avg_14_and_indicator_cci_14 * st_dev_of_bb_gap_of_cci_14

//Chop Zone
source = source_of_cz
avg = source_of_cz_avg
var float ema34_f = 0
cz_nf = ta.ema(source, 34)
if cz_calculation == 'Lenior regression'
    ema34_f := ta.linreg(cz_nf, look_back_period, 0)
else if cz_calculation == 'Simple Moving Average (SMA)'
    ema34_f := ta.sma(cz_nf, look_back_period)
else if cz_calculation == 'Exponentially Weighted Moving Average (EMA)'
    ema34_f := cz_nf
else if cz_calculation == 'Hull Moving Average (HMA)'
    ema34_f := ta.hma(cz_nf, look_back_period)
else if cz_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    ema34_f := ta.rma(cz_nf, look_back_period)
else if cz_calculation == 'Weighted Moving Average (WMA)'
    ema34_f := ta.wma(cz_nf, look_back_period)
else if cz_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    ema34_f := ta.alma(cz_nf, look_back_period,0,3)
else if cz_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    ema34_f := ta.swma(cz_nf)
else if cz_calculation == 'Volume-weighted Moving Average (VWMA)'
    ema34_f := ta.vwma(cz_nf, look_back_period)
pi = math.atan(1) * 4
periods = 30
highestHigh = ta.highest(periods)
lowestLow = ta.lowest(periods)
span = 25 / (highestHigh - lowestLow) * lowestLow
ema34 = ema34_f
x1_ema34 = 0
x2_ema34 = 1
y1_ema34 = 0
y2_ema34 = (ema34[1] - ema34) / avg * span
c_ema34 = math.sqrt((x2_ema34 - x1_ema34)*(x2_ema34 - x1_ema34) + (y2_ema34 - y1_ema34)*(y2_ema34 - y1_ema34))
emaAngle_1 = math.round(180 * math.acos((x2_ema34 - x1_ema34)/c_ema34) / pi)
emaAngle = y2_ema34 > 0? - emaAngle_1: emaAngle_1
indicator_chop_zone_14 = emaAngle
[middle_chop_zone_14, upper_chop_zone_14, lower_chop_zone_14] = ta.bb(indicator_chop_zone_14, 5, 4)
bb_gap_of_chop_zone_14 = indicator_chop_zone_14 - middle_chop_zone_14
st_dev_of_bb_gap_of_chop_zone_14 = ta.stdev(bb_gap_of_chop_zone_14, look_back_period)
st_dev_of_indicator_chop_zone_14 = ta.stdev(indicator_chop_zone_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_chop_zone_14 = ta.correlation(indicator_chop_zone_14,price_avg_14,look_back_period)
first_degree_indicator_chop_zone_14 = st_dev_of_indicator_chop_zone_14 * corelation_btw_price_avg_14_and_indicator_chop_zone_14 * st_dev_of_bb_gap_of_chop_zone_14

//Ease of Movement
var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
    runtime.error("No volume is provided by the data vendor.")
div = 10000 //input.int(10000, title="Divisor", minval=1)
eom_nf = (div * ta.change(source_of_eom) * (high - low) / volume)
var float eom_f = 0
if eom_calculation == 'Lenior regression'
    eom_f := ta.linreg(eom_nf, look_back_period, 0)
else if eom_calculation == 'Simple Moving Average (SMA)'
    eom_f := ta.sma(eom_nf, look_back_period)
else if eom_calculation == 'Exponentially Weighted Moving Average (EMA)'
    eom_f := eom_nf
else if eom_calculation == 'Hull Moving Average (HMA)'
    eom_f := ta.hma(eom_nf, look_back_period)
else if eom_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    eom_f := ta.rma(eom_nf, look_back_period)
else if eom_calculation == 'Weighted Moving Average (WMA)'
    eom_f := ta.wma(eom_nf, look_back_period)
else if eom_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    eom_f := ta.alma(eom_nf, look_back_period,0,3)
else if eom_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    eom_f := ta.swma(eom_nf)
else if eom_calculation == 'Volume-weighted Moving Average (VWMA)'
    eom_f := ta.vwma(eom_nf, look_back_period)
eom = eom_f
indicator_eom_14 = eom
[middle_eom_14, upper_eom_14, lower_eom_14] = ta.bb(indicator_eom_14, 5, 4)
bb_gap_of_eom_14 = indicator_eom_14 - middle_eom_14
st_dev_of_bb_gap_of_eom_14 = ta.stdev(bb_gap_of_eom_14, look_back_period)
st_dev_of_indicator_eom_14 = ta.stdev(indicator_eom_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_eom_14 = ta.correlation(indicator_eom_14,price_avg_14,look_back_period)
first_degree_indicator_eom_14 = st_dev_of_indicator_eom_14 * corelation_btw_price_avg_14_and_indicator_eom_14 * st_dev_of_bb_gap_of_eom_14

//Detrended Price Oscillator
var float ma_f = 0
ma_nf = ta.sma(source_of_dpo, look_back_period)
if dpo_calculation == 'Lenior regression'
    ma_f:= ta.linreg(ma_nf, look_back_period, 0)
else if dpo_calculation == 'Simple Moving Average (SMA)'
    ma_f:= ta.sma(source_of_dpo, look_back_period)
else if dpo_calculation == 'Exponentially Weighted Moving Average (EMA)'
    ma_f:= ta.ema(source_of_dpo, look_back_period)
else if dpo_calculation == 'Hull Moving Average (HMA)'
    ma_f:= ta.hma(source_of_dpo, look_back_period)
else if dpo_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    ma_f:= ta.rma(source_of_dpo, look_back_period)
else if dpo_calculation == 'Weighted Moving Average (WMA)'
    ma_f:= ta.wma(source_of_dpo, look_back_period)
else if dpo_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    ma_f:= ta.alma(source_of_dpo, look_back_period,0,3)
else if dpo_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    ma_f:= ta.swma(source_of_dpo)
else if dpo_calculation == 'Volume-weighted Moving Average (VWMA)'
    ma_f:= ta.vwma(source_of_dpo, look_back_period)
barsback = look_back_period/2 + 1
ma = ma_f
dpo = isCentered ? close[barsback] - ma : close - ma[barsback]
indicator_dpo_14 = dpo
[middle_dpo_14, upper_dpo_14, lower_dpo_14] = ta.bb(indicator_dpo_14, 5, 4)
bb_gap_of_dpo_14 = indicator_dpo_14 - middle_dpo_14
st_dev_of_bb_gap_of_dpo_14 = ta.stdev(bb_gap_of_dpo_14, look_back_period)
st_dev_of_indicator_dpo_14 = ta.stdev(indicator_dpo_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_dpo_14 = ta.correlation(indicator_dpo_14,price_avg_14,look_back_period)
first_degree_indicator_dpo_14 = st_dev_of_indicator_dpo_14 * corelation_btw_price_avg_14_and_indicator_dpo_14 * st_dev_of_bb_gap_of_dpo_14

//Advance Decline Line
sym(s) => request.security(s, timeframe.period, source_of_adl)
difference = (sym("USI:ADVN.NY") - sym("USI:DECL.NY"))/(sym("USI:UNCH.NY") + 1)
adline = ta.cum(difference > 0 ? math.sqrt(difference) : -math.sqrt(-difference))
indicator_adl_14 = adline
[middle_adl_14, upper_adl_14, lower_adl_14] = ta.bb(indicator_adl_14, 5, 4)
bb_gap_of_adl_14 = indicator_adl_14 - middle_adl_14
st_dev_of_bb_gap_of_adl_14 = ta.stdev(bb_gap_of_adl_14, look_back_period)
st_dev_of_indicator_adl_14 = ta.stdev(indicator_adl_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_adl_14 = ta.correlation(indicator_adl_14,price_avg_14,look_back_period)
first_degree_indicator_adl_14 = st_dev_of_indicator_adl_14 * corelation_btw_price_avg_14_and_indicator_adl_14 * st_dev_of_bb_gap_of_adl_14

//Bull Bear Power
var float bullp_f = 0
var float bearp_f = 0
bullp_nf = ta.ema(source_of_cal_bullp, look_back_period)
bearp_nf = ta.ema(source_of_cal_bullp, look_back_period)
if bullp_calculation == 'Lenior regression'
    bullp_f := ta.linreg(bullp_nf, look_back_period, 0)
else if bullp_calculation == 'Simple Moving Average (SMA)'
    bullp_f := ta.sma(source_of_bullp, look_back_period)
else if bullp_calculation == 'Exponentially Weighted Moving Average (EMA)'
    bullp_f := ta.ema(source_of_bullp, look_back_period)
else if bullp_calculation == 'Hull Moving Average (HMA)'
    bullp_f := ta.hma(source_of_bullp, look_back_period)
else if bullp_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    bullp_f := ta.rma(source_of_bullp, look_back_period)
else if bullp_calculation == 'Weighted Moving Average (WMA)'
    bullp_f := ta.wma(source_of_bullp, look_back_period)
else if bullp_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    bullp_f := ta.alma(source_of_bullp, look_back_period,0,3)
else if bullp_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    bullp_f := ta.swma(source_of_bullp)
else if bullp_calculation == 'Volume-weighted Moving Average (VWMA)'
    bullp_f := ta.vwma(source_of_bullp, look_back_period)
if bearp_calculation == 'Lenior regression'
    bearp_f := ta.linreg(bearp_nf, look_back_period, 0)
else if bearp_calculation == 'Simple Moving Average (SMA)'
    bearp_f := ta.sma(source_of_bearp, look_back_period)
else if bearp_calculation == 'Exponentially Weighted Moving Average (EMA)'
    bearp_f := ta.ema(source_of_bearp, look_back_period)
else if bearp_calculation == 'Hull Moving Average (HMA)'
    bearp_f := ta.hma(source_of_bearp, look_back_period)
else if bearp_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    bearp_f := ta.rma(source_of_bearp, look_back_period)
else if bearp_calculation == 'Weighted Moving Average (WMA)'
    bearp_f := ta.wma(source_of_bearp, look_back_period)
else if bearp_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    bearp_f := ta.alma(source_of_bearp, look_back_period,0,3)
else if bearp_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    bearp_f := ta.swma(source_of_bearp)
else if bearp_calculation == 'Volume-weighted Moving Average (VWMA)'
    bearp_f := ta.vwma(source_of_bearp, look_back_period)
bullPower = source_of_bullp - bullp_f
bearPower = source_of_bearp - bearp_f
indicator_bbp_14 = bullPower + bearPower
[middle_bbp_14, upper_bbp_14, lower_bbp_14] = ta.bb(indicator_bbp_14, 5, 4)
bb_gap_of_bbp_14 = indicator_bbp_14 - middle_bbp_14
st_dev_of_bb_gap_of_bbp_14 = ta.stdev(bb_gap_of_bbp_14, look_back_period)
st_dev_of_indicator_bbp_14 = ta.stdev(indicator_bbp_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_bbp_14 = ta.correlation(indicator_bbp_14,price_avg_14,look_back_period)
first_degree_indicator_bbp_14 = st_dev_of_indicator_bbp_14 * corelation_btw_price_avg_14_and_indicator_bbp_14 * st_dev_of_bb_gap_of_bbp_14

//high
var float high_f = 0
if high_impact_calculation == 'Lenior regression'
    high_f := ta.linreg(high, look_back_period, 0)
else if high_impact_calculation == 'Simple Moving Average (SMA)'
    high_f := ta.sma(high, look_back_period)
else if high_impact_calculation == 'Exponentially Weighted Moving Average (EMA)'
    high_f := ta.ema(high, look_back_period)
else if high_impact_calculation == 'Hull Moving Average (HMA)'
    high_f := ta.hma(high, look_back_period)
else if high_impact_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    high_f := ta.rma(high, look_back_period)
else if high_impact_calculation == 'Weighted Moving Average (WMA)'
    high_f := ta.wma(high, look_back_period)
else if high_impact_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    high_f := ta.alma(high, look_back_period,0,3)
else if high_impact_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    high_f := ta.swma(high)
else if high_impact_calculation == 'Volume-weighted Moving Average (VWMA)'
    high_f := ta.vwma(high, look_back_period)
indicator_high_14 = high_f
[middle_high_14, upper_high_14, lower_high_14] = ta.bb(indicator_high_14, 5, 4)
bb_gap_of_high_14 = indicator_high_14 - middle_high_14
st_dev_of_bb_gap_of_high_14 = ta.stdev(bb_gap_of_high_14, look_back_period)
st_dev_of_indicator_high_14 = ta.stdev(indicator_high_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_high_14 = ta.correlation(indicator_high_14,price_avg_14,look_back_period)
first_degree_indicator_high_14 = st_dev_of_indicator_high_14 * corelation_btw_price_avg_14_and_indicator_high_14 * st_dev_of_bb_gap_of_high_14

//low
var float low_f = 0
if low_impact_calculation == 'Lenior regression'
    low_f := ta.linreg(low, look_back_period, 0)
else if low_impact_calculation == 'Simple Moving Average (SMA)'
    low_f := ta.sma(low, look_back_period)
else if low_impact_calculation == 'Exponentially Weighted Moving Average (EMA)'
    low_f := ta.ema(low, look_back_period)
else if low_impact_calculation == 'Hull Moving Average (HMA)'
    low_f := ta.hma(low, look_back_period)
else if low_impact_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    low_f := ta.rma(low, look_back_period)
else if low_impact_calculation == 'Weighted Moving Average (WMA)'
    low_f := ta.wma(low, look_back_period)
else if low_impact_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    low_f := ta.alma(low, look_back_period,0,3)
else if low_impact_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    low_f := ta.swma(low)
else if low_impact_calculation == 'Volume-weighted Moving Average (VWMA)'
    low_f := ta.vwma(low, look_back_period)
indicator_low_14 = low_f
[middle_low_14, upper_low_14, lower_low_14] = ta.bb(indicator_low_14, 5, 4)
bb_gap_of_low_14 = indicator_low_14 - middle_low_14
st_dev_of_bb_gap_of_low_14 = ta.stdev(bb_gap_of_low_14, look_back_period)
st_dev_of_indicator_low_14 = ta.stdev(indicator_low_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_low_14 = ta.correlation(indicator_low_14,price_avg_14,look_back_period)
first_degree_indicator_low_14 = st_dev_of_indicator_low_14 * corelation_btw_price_avg_14_and_indicator_low_14 * st_dev_of_bb_gap_of_low_14

//open
var float open_f = 0
if open_impact_calculation == 'Lenior regression'
    open_f := ta.linreg(open, look_back_period, 0)
else if open_impact_calculation == 'Simple Moving Average (SMA)'
    open_f := ta.sma(open, look_back_period)
else if open_impact_calculation == 'Exponentially Weighted Moving Average (EMA)'
    open_f := ta.ema(open, look_back_period)
else if open_impact_calculation == 'Hull Moving Average (HMA)'
    open_f := ta.hma(open, look_back_period)
else if open_impact_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    open_f := ta.rma(open, look_back_period)
else if open_impact_calculation == 'Weighted Moving Average (WMA)'
    open_f := ta.wma(open, look_back_period)
else if open_impact_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    open_f := ta.alma(open, look_back_period,0,3)
else if open_impact_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    open_f := ta.swma(open)
else if open_impact_calculation == 'Volume-weighted Moving Average (VWMA)'
    open_f := ta.vwma(open, look_back_period)
indicator_open_14 = open_f
[middle_open_14, upper_open_14, lower_open_14] = ta.bb(indicator_open_14, 5, 4)
bb_gap_of_open_14 = indicator_open_14 - middle_open_14
st_dev_of_bb_gap_of_open_14 = ta.stdev(bb_gap_of_open_14, look_back_period)
st_dev_of_indicator_open_14 = ta.stdev(indicator_open_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_open_14 = ta.correlation(indicator_open_14,price_avg_14,look_back_period)
first_degree_indicator_open_14 = st_dev_of_indicator_open_14 * corelation_btw_price_avg_14_and_indicator_open_14 * st_dev_of_bb_gap_of_open_14

//close
var float close_f = 0
if close_impact_calculation == 'Lenior regression'
    close_f := ta.linreg(close, look_back_period, 0)
else if close_impact_calculation == 'Simple Moving Average (SMA)'
    close_f := ta.sma(close, look_back_period)
else if close_impact_calculation == 'Exponentially Weighted Moving Average (EMA)'
    close_f := ta.ema(close, look_back_period)
else if close_impact_calculation == 'Hull Moving Average (HMA)'
    close_f := ta.hma(close, look_back_period)
else if close_impact_calculation == 'Exponentially Weighted Moving average with alpha length (RMA)'
    close_f := ta.rma(close, look_back_period)
else if close_impact_calculation == 'Weighted Moving Average (WMA)'
    close_f := ta.wma(close, look_back_period)
else if close_impact_calculation == 'Arnaud Legoux Moving Average (ALMA)'
    close_f := ta.alma(close, look_back_period,0,3)
else if close_impact_calculation == 'Symmetrically weighted moving average with fixed length (SWMA)'
    close_f := ta.swma(close)
else if close_impact_calculation == 'Volume-weighted Moving Average (VWMA)'
    close_f := ta.vwma(close, look_back_period)
indicator_close_14 = close_f
[middle_close_14, upper_close_14, lower_close_14] = ta.bb(indicator_close_14, 5, 4)
bb_gap_of_close_14 = indicator_close_14 - middle_close_14
st_dev_of_bb_gap_of_close_14 = ta.stdev(bb_gap_of_close_14, look_back_period)
st_dev_of_indicator_close_14 = ta.stdev(indicator_close_14, look_back_period)
corelation_btw_price_avg_14_and_indicator_close_14 = ta.correlation(indicator_close_14,price_avg_14,look_back_period)
first_degree_indicator_close_14 = st_dev_of_indicator_close_14 * corelation_btw_price_avg_14_and_indicator_close_14 * st_dev_of_bb_gap_of_close_14

//Primary indicator
all_indicators_final_graph = first_degree_indicator_sar_14 + first_degree_indicator_st_14 + first_degree_indicator_rsi_14 + first_degree_indicator_mfi_14 + first_degree_indicator_bop_14 + first_degree_indicator_mom_14 + first_degree_indicator_cog_14+ first_degree_indicator_dmi_14 + first_degree_indicator_stoch_14 + first_degree_indicator_swma_14 + first_degree_indicator_wpr_14 + first_degree_indicator_tsi_14 + first_degree_indicator_iii_14 + first_degree_indicator_nvi_14 + first_degree_indicator_pvi_14 + first_degree_indicator_obv_14 + first_degree_indicator_accdist_14 + first_degree_indicator_pvt_14 + first_degree_indicator_tr_14 + first_degree_indicator_vwap_14 + first_degree_indicator_wad_14 + first_degree_indicator_sma_14 + first_degree_indicator_ema_14 + first_degree_indicator_cci_14 + first_degree_indicator_chop_zone_14 + first_degree_indicator_eom_14 + first_degree_indicator_dpo_14 + first_degree_indicator_adl_14 + first_degree_indicator_bbp_14 + first_degree_indicator_high_14 + first_degree_indicator_low_14 + first_degree_indicator_open_14 + first_degree_indicator_close_14                                                                                                                                                                                             
//st. dev, co-relation, degree of change and rate of change of primary indicator
st_dev_of_all_indicators_final_graph = ta.stdev(all_indicators_final_graph, look_back_period)
corelation_btw_price_avg_14_and_all_indicators_final_graph = ta.correlation(all_indicators_final_graph,price_avg_14,look_back_period)
first_degree_change_of_st_dev_of_all_indicators_final_graph = ta.change(all_indicators_final_graph, 2)
first_degree_of_rate_of_change_first_degree_change_of_st_dev_of_all_indicators_final_graph = 100 * (ta.change(first_degree_change_of_st_dev_of_all_indicators_final_graph, 2)/ first_degree_change_of_st_dev_of_all_indicators_final_graph[1])
final_graph_of_corelation = all_indicators_final_graph * corelation_btw_price_avg_14_and_all_indicators_final_graph
final_graph_of_st_dev = corelation_btw_price_avg_14_and_all_indicators_final_graph * st_dev_of_all_indicators_final_graph

//final_graph_of_corelation
st_dev_of_final_graph_of_corelation = ta.stdev(final_graph_of_corelation, look_back_period)
corelation_btw_price_avg_14_and_final_graph_of_corelation = ta.correlation(final_graph_of_corelation,price_avg_14,look_back_period)
second_degree_change_of_st_dev_of_final_graph_of_corelation = ta.change(final_graph_of_corelation, 2)
second_degree_of_rate_of_change_first_degree_change_of_st_dev_of_all_indicators_final_graph_1 = 100 * (ta.change(second_degree_change_of_st_dev_of_final_graph_of_corelation, 2)/ second_degree_change_of_st_dev_of_final_graph_of_corelation[1])
second_degree_final_graph_of_corelation_one = final_graph_of_corelation * corelation_btw_price_avg_14_and_final_graph_of_corelation
second_degree_final_graph_of_st_dev_one = corelation_btw_price_avg_14_and_final_graph_of_corelation * st_dev_of_final_graph_of_corelation

//final_graph_of_st_dev
st_dev_of_final_graph_of_st_dev = ta.stdev(final_graph_of_st_dev, look_back_period)
corelation_btw_price_avg_14_and_final_graph_of_st_dev = ta.correlation(final_graph_of_st_dev,price_avg_14,look_back_period)
second_degree_change_of_st_dev_of_final_graph_of_st_dev = st_dev_of_final_graph_of_st_dev - st_dev_of_final_graph_of_st_dev [1] 
second_degree_of_rate_of_change_first_degree_change_of_st_dev_of_all_indicators_final_graph_2 = second_degree_change_of_st_dev_of_final_graph_of_st_dev - second_degree_change_of_st_dev_of_final_graph_of_st_dev[1]
second_degree_final_graph_of_corelation_two = final_graph_of_st_dev * corelation_btw_price_avg_14_and_final_graph_of_st_dev
second_degree_final_graph_of_st_dev_two = corelation_btw_price_avg_14_and_final_graph_of_st_dev * st_dev_of_final_graph_of_st_dev

//second_degree_final_graph_of_corelation_one
st_dev_of_second_degree_final_graph_of_corelation_one = ta.stdev(second_degree_final_graph_of_corelation_one, look_back_period)
corelation_btw_price_avg_14_and_second_degree_final_graph_of_corelation_one = ta.correlation(second_degree_final_graph_of_corelation_one,price_avg_14,look_back_period)
third_degree_final_graph_of_corelation_three = second_degree_final_graph_of_corelation_one  * corelation_btw_price_avg_14_and_second_degree_final_graph_of_corelation_one

//second_degree_final_graph_of_corelation_two
st_dev_of_second_degree_final_graph_of_corelation_two = ta.stdev(second_degree_final_graph_of_corelation_two, look_back_period)
corelation_btw_price_avg_14_and_second_degree_final_graph_of_corelation_two = ta.correlation(second_degree_final_graph_of_corelation_two,price_avg_14,look_back_period)
third_degree_final_graph_of_corelation_four = st_dev_of_second_degree_final_graph_of_corelation_two * corelation_btw_price_avg_14_and_second_degree_final_graph_of_corelation_two

//final_graph_of_corelation
change_of_final_graph_of_corelation = final_graph_of_corelation - final_graph_of_corelation[1]
second_level_change_of_change_of_final_graph_of_corelation = (change_of_final_graph_of_corelation - change_of_final_graph_of_corelation[1])*math.pow(ta.correlation(change_of_final_graph_of_corelation,price_avg_14,look_back_period),3)*ta.stdev(change_of_final_graph_of_corelation, look_back_period)

//Graph Identification
show_graph_1 = input.bool(defval = false, title = "(1) Show Cumilative graph(CG)", group = "Graphs")

show_graph_2 = input.bool(defval = false, title = "(2) CG corelation to price", group = "Graphs")
show_graph_3 = input.bool(defval = false, title = "(3) St dev of CG", group = "Graphs")
show_graph_4 = input.bool(defval = false, title = "(4) Degree of change - CG", group = "Graphs")
show_graph_5 = input.bool(defval = false, title = "(5) Rate of change - CG", inline = 'Graph 5', group = "Graphs")
scale_of_graph_5 = input.int(defval = 1, title = "& scale (n) will be 10 to the power n", inline = 'Graph 5', group = "Graphs")

show_graph_6 = input.bool(defval = false, title = "(6) Co-relation of CG (CCG), corelation to price", group = "Graphs")
show_graph_7 = input.bool(defval = false, title = "(7) St dev of corelation of CCG", group = "Graphs")
show_graph_8 = input.bool(defval = false, title = "(8) Degree of change - CCG", group = "Graphs")
show_graph_9 = input.bool(defval = false, title = "(9) Rate of change - CCG", inline = 'Graph 9', group = "Graphs")
scale_of_graph_9 = input.int(defval = 1, title = "& scale (n) will be 10 to the power n", inline = 'Graph 9', group = "Graphs")

show_graph_10 = input.bool(defval = false, title = "(10) STDV of CG (SCG), corelation to price", group = "Graphs")
show_graph_11 = input.bool(defval = false, title = "(11) St dev of corelation of SCG", group = "Graphs")
show_graph_12 = input.bool(defval = false, title = "(12) Degree of change - SCG", group = "Graphs")
show_graph_13 = input.bool(defval = false, title = "(13) Rate of change - SCG", inline = 'Graph 13', group = "Graphs")
scale_of_graph_13 = input.int(defval = 1, title = "& scale (n) will be 10 to the power n", inline = 'Graph 13', group = "Graphs")

show_graph_14 = input.bool(defval = false, title = "(14) Third degree cor to price", group = "Graphs")
show_graph_15 = input.bool(defval = false, title = "(15) Third degree cor to price", group = "Graphs")
show_graph_16 = input.bool(defval = false, title = "(16) Change of graph no 2", group = "Graphs")

graph_1 = all_indicators_final_graph

graph_2 = final_graph_of_corelation
graph_3 = final_graph_of_st_dev
graph_4 = first_degree_change_of_st_dev_of_all_indicators_final_graph
graph_5 = first_degree_of_rate_of_change_first_degree_change_of_st_dev_of_all_indicators_final_graph

graph_6 = second_degree_final_graph_of_corelation_one
graph_7 = second_degree_final_graph_of_st_dev_one
graph_8 = second_degree_change_of_st_dev_of_final_graph_of_corelation
graph_9 = second_degree_of_rate_of_change_first_degree_change_of_st_dev_of_all_indicators_final_graph_1

graph_10 = second_degree_final_graph_of_corelation_two
graph_11 = second_degree_final_graph_of_st_dev_two
graph_12 = second_degree_change_of_st_dev_of_final_graph_of_st_dev
graph_13 = second_degree_of_rate_of_change_first_degree_change_of_st_dev_of_all_indicators_final_graph_2

graph_14 = third_degree_final_graph_of_corelation_three
graph_15 = third_degree_final_graph_of_corelation_four
graph_16 = second_level_change_of_change_of_final_graph_of_corelation

//buy signal generation
buy_1 = price_falling and ta.crossunder(graph_7,0)
buy_2 = price_falling and ta.cross(graph_11,0)
buy_3 = price_falling and ta.cross(graph_5,0) and ta.cross(graph_9,0) and ta.cross(graph_13,0)
buy_4 = price_falling and ta.cross(graph_4,0) and ta.cross(graph_8,0) and ta.cross(graph_12,0)
buy_5 = price_falling and ta.cross(graph_2,0) and ta.cross(graph_3,0) and ta.cross(graph_4,0)
buy_6 = price_falling and ta.cross(graph_4,graph_8) and ta.cross(graph_4,graph_12) and ta.cross(graph_12,graph_8)



// Trading Arrangement
//Buy and Sell range
hi_high = ta.highest(buy_comand_high_value,buy_or_sell_lookback)
lowerlowest = ta.lowest(buy_comand_low_value,buy_or_sell_lookback)
var  float hi_point = na
var  float low_point = na
for i = 1 to 0 by 1
    if hi_high[i] < hi_high[i+1]
        hi_point := hi_high[i+1]
    
    else if lowerlowest [i] > lowerlowest [i+1]
        low_point := lowerlowest [i+1]

//Trading Arrangement
// Generate sell signal
var bool sell_comand = false
[pinesupertrend, pinedirection] = ta.supertrend(factor_of_supertrend_to_determine_sell_comand, artperiod_of_supertrend_to_determine_sell_comand)
if pinedirection[1] < 0 and pinedirection > 0
    sell_comand := true
else if pinedirection > 0 and (buy_1 or buy_2 or buy_3 or buy_4 or buy_5 or buy_6)
    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] and intermidiate_selling == true
    int_selling := true
else if strategy.opentrades  == strategy.opentrades [1] - 1 or intermidiate_selling == false
    int_selling := false

// Calculation of profit precentage
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 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] 

//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 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'
    value_of_purchase := (total_investment/(piramiding + 1))
else if purchaseing_method == 'Equal amounts' and dev_of_equal_amounts == 'Equal amounts with fixed USDT'
    value_of_purchase := int_val_prc

if purchaseing_method == 'Incremental amounts' and int_val_allocation == '% of cumilative investment' 
    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' 
    value_of_purchase := (int_val_prc)* math.pow((1 + (r_value/100)),y)
    
var float final_value_of_purchase = 0
if value_of_purchase <= 21
    final_value_of_purchase := 21
else 
    final_value_of_purchase := value_of_purchase
    
quantity = final_value_of_purchase/low

var float r_ff = 0
if purchaseing_method == 'Equal amounts'
    r_ff := na
else 
    r_ff := r_f
    
//current expenditure
currentexpenditure() =>
    result_v2 = 0.
    for i = 0 to strategy.opentrades-1
        result_v2 += strategy.opentrades.entry_price(i) * strategy.opentrades.size(i)
    strategy.opentrades > 0 ? result_v2  : na


//cash in hand
var float cash_in_hand = 0
if currentexpenditure() > 0
    cash_in_hand := total_investment  - currentexpenditure()
else
    cash_in_hand := total_investment

//unrealised profit
unrealised_profit = (high+low)/2*strategy.position_size - currentexpenditure()

//last entry price
lastentryprice() =>
    result_v3 = 0.
    for i = 0 to strategy.opentrades-1
        result_v3 := strategy.opentrades.entry_price(i)// * strategy.opentrades.size(i)
    strategy.opentrades > 0 ? result_v3  : na
    
var float last_entry_price = 0
var index_of_array_maxval = 0
var index_of_array_minval = 0
var entryprice = array.new_float(49)
if currentexpenditure() [1] < currentexpenditure()
    last_entry_price := lastentryprice()
    array.push(entryprice, last_entry_price)
else if strategy.opentrades [1] == 0 and strategy.opentrades > 0
    last_entry_price := lastentryprice()
    array.push(entryprice, last_entry_price)
else if strategy.position_size == 0
    last_entry_price := 0
    array.clear(entryprice)

array_maxval = array.max(entryprice)
array_minval = array.min(entryprice)

if array.lastindexof(entryprice, array_maxval) >= 0
    index_of_array_maxval := array.lastindexof(entryprice, array_maxval) + 1
    index_of_array_minval := array.lastindexof(entryprice, array_minval) + 1 
else
    index_of_array_maxval := na
    index_of_array_minval := na

if ta.sma(close,9)> array_minval*(1 + profit_precentage_intermidiate/100)// and int_selling == true and hi_point[1] and low_point and strategy.position_avg_price > ma_9
    array.clear(entryprice)

//Calculation of profit line
var float profit_line = 0
profit_line_nf = strategy.position_avg_price * cal_profit_precentage
//strategy.position_avg_price * cal_profit_precentage
if strategy.position_size[1] == 0 and strategy.position_size > 0
    profit_line := profit_line_nf
else if strategy.position_size [1] < strategy.position_size
    profit_line := profit_line - profit_line_nf[1] + profit_line_nf
else if strategy.position_size [1] > strategy.position_size
    profit_line := profit_line [1]
else if strategy.opentrades == 0
    profit_line := 0
    
// count of max trade count
var int max_trade_count = 0
if purchaseing_method == 'Incremental amounts'
    max_trade_count := piramiding - 1
else if purchaseing_method == 'Equal amounts' and dev_of_equal_amounts == 'Equal amounts with fixed USDT'
    max_trade_count := math.floor(total_investment / int_val_prc) - 1
else if purchaseing_method == 'Equal amounts' and dev_of_equal_amounts == 'Equal amounts with fixed entries'
    max_trade_count := piramiding - 1

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

//Trading
if ((buy_1 or buy_2 or buy_3  )) and window and strategy.position_size == 0 and source_of_lower_point < low_point
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)
else if ((buy_1 or buy_2 or buy_3 or buy_4 )  and window and ma_9 < strategy.position_avg_price *.99 and  strategy.position_size > 0 ) and strategy.opentrades <= (max_trade_count * 0.75) //and source_of_lower_point < low_point
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)
else if ((buy_6)  and ma_9 < strategy.position_avg_price and window and  strategy.position_size > 0 ) and strategy.opentrades > (max_trade_count * 0.75) and strategy.opentrades <= max_trade_count //and source_of_lower_point < low_point
    strategy.entry("long", strategy.long, comment = buy_comment, qty = quantity)

if (sell_comand==true) and profit_line < ma_9 and hi_point[1] and low_point
    strategy.close("long", qty = strategy.position_size, comment = sell_comment)

//intermediate selling
if ta.sma(close,9)> array_minval*(1 + profit_precentage_intermidiate/100) and int_selling == true and hi_point[1] and low_point and strategy.position_avg_price > ma_9
    strategy.close("long", qty = last_purchase[x], comment = sell_comment)
    
//Graphs
//color change
plot(r_ff,                                      title = "Calculated R value",       color = color.new(color.white,100))

plot(strategy.position_avg_price,               title = "AVG",                      color = color.green,                    style = plot.style_circles)
plot(profit_line,                               title = "Adj.Profit",               color = color.yellow,                   style = plot.style_circles)
plot(strategy.opentrades,                       title = "Numbers of open trades",   color = color.new(color.white,100))
plot(max_open_trades,                           title = "Max Opentrades",           color = color.new(color.red,100))
plot(strategy.netprofit,                        title = "Cumilative Profit",        color = color.new(color.white,100))
plot(unrealised_profit,                         title = "Unrealised Profit",        color = color.new(color.blue,100))
plot(currentexpenditure(),                      title = "Current Expenditure",      color = color.new(color.blue,100))
plot(cash_in_hand,                              title = "Cash in Hand",             color = color.new(color.blue,100))
plot(total_investment,                          title = "Total Investment",         color = color.new(color.white,100))
plot(last_purchase,                             title = "Quantity Last purchase",   color = color.new(color.white,100))
plot(final_value_of_purchase,                   title = "Value of Purchase",        color = color.new(color.white,100))
//plot(last_entry_price,                          title = "Lastentry Price",          color = color.new(color.blue,100))
//plot(result,                                    title = "Entry Price",              color = color.new(color.white,100))


hidden_color = color.new(color.white,100)
var color_1 = color.white

var color_2 = color.red
var color_3 = color.yellow
var color_4 = color.blue
var color_5 = color.green

var color_6 = color.orange //line
var color_7 = color.maroon //bar
var color_8 = color.new(color.gray,50) //area
var color_9 = color.new(color.aqua,50) //area

var color_10 = color.orange //line
var color_11 = color.maroon //bar
var color_12 = color.new(color.gray,50) //area
var color_13 = color.new(color.aqua,50) //area

var color_14 = color.orange //line
var color_15 = color.maroon //bar
var color_16 = color.maroon //bar

if show_graph_1 == true
    color_1 := color.white
else 
    color_1 := hidden_color

if show_graph_2 == true
    color_2 := color.red
else 
    color_2 := hidden_color

if show_graph_3 == true
    color_3 := color.new(color.yellow,50)
else 
    color_3 := hidden_color

if show_graph_4 == true
    color_4 := color.new(color.blue,50)
else 
    color_4 := hidden_color

if show_graph_5 == true
    color_5 := color.new(color.green,30)
else 
    color_5 := hidden_color

if show_graph_6 == true
    color_6 := color.orange
else 
    color_6 := hidden_color

if show_graph_7 == true
    color_7 := color.green
else 
    color_7 := hidden_color

if show_graph_8 == true
    color_8 := color.new(color.silver,50)
else 
    color_8 := hidden_color

if show_graph_9 == true
    color_9 := color.new(color.yellow,50)
else 
    color_9 := hidden_color

if show_graph_10 == true
    color_10 := color.new(color.teal,50)
else 
    color_10 := hidden_color

if show_graph_11 == true
    color_11 := color.new(color.maroon,50)
else 
    color_11 := hidden_color

if show_graph_12 == true
    color_12 := color.new(color.aqua,50)
else 
    color_12 := hidden_color

if show_graph_13 == true
    color_13 := color.new(color.red,50)
else 
    color_13 := hidden_color

if show_graph_14 == true
    color_14 := color.new(color.red,50)
else 
    color_14 := hidden_color
    
if show_graph_15 == true
    color_15 := color.new(color.blue,50)
else 
    color_15 := hidden_color

if show_graph_16 == true
    color_16 := color.new(color.blue,50)
else 
    color_16 := hidden_color

hline(0, color = color.white, title = "o")
plot(show_graph_1 == true ? graph_1:na, color = color_1, title = "(1) Cumilative graph(CG)", style = plot.style_linebr)

plot(show_graph_2 == true ? graph_2:na, color = color_2, title = "(2) CG corelation to price", style = plot.style_linebr)
plot(show_graph_3 == true ? graph_3:na, color = color_3, title = "(3) St dev of CG", style = plot.style_columns)
plot(show_graph_4 == true ? graph_4:na, color = color_4, title = "(4) Degree of change - CG", style = plot.style_linebr)
plot(show_graph_5 == true ? graph_5*math.pow(10,scale_of_graph_5):na, color = color_5, title = "(5) Rate of change - CG", style = plot.style_area)

plot(show_graph_6 == true ? graph_6:na, color = color_6, title = "(6) corelation of CG (CCG), corelation to price", style = plot.style_linebr)
plot(show_graph_7 == true ? graph_7:na, color = color_7, title = "(7) St dev of corelation of CCG", style = plot.style_columns)
plot(show_graph_8 == true ? graph_8:na, color = color_8, title = "(8) Degree of change - CCG", style = plot.style_linebr)
plot(show_graph_9 == true ? graph_9*math.pow(10,scale_of_graph_9):na, color = color_9, title = "(9) Rate of change - CCG", style = plot.style_area)

plot(show_graph_10 == true ? graph_10:na, color = color_10, title = "(10) STDV of CG (SCG), corelation to price", style = plot.style_linebr)
plot(show_graph_11 == true ? graph_11:na, color = color_11, title = "(11) St dev of corelation of SCG", style = plot.style_columns)
plot(show_graph_12 == true ? graph_12:na, color = color_12, title = "(12) Degree of change - SCG", style = plot.style_linebr)
plot(show_graph_13 == true ? graph_13*math.pow(10,scale_of_graph_13):na, color = color_13, title = "(13) Rate of change - SCG", style = plot.style_area)

plot(show_graph_14 == true ? graph_14:na, color = color_14, title = "(14) Third degree cor to price", style = plot.style_linebr)
plot(show_graph_15 == true ? graph_15:na, color = color_15, title = "(15) Third degree cor to price", style = plot.style_columns)
plot(show_graph_16 == true ? ta.ema(graph_16,14):na, color = color_16, title = "(16) Degree of change - SCG", style = plot.style_area)




plotshape(ma_9 < strategy.position_avg_price *.99 and strategy.opentrades <= (max_trade_count * 0.75)  ? buy_1: na, style = shape.arrowdown, location = location.abovebar, size = size.large, text = "1")
plotshape(ma_9 < strategy.position_avg_price *.99 and strategy.opentrades <= (max_trade_count * 0.75)  ? buy_2: na, style = shape.arrowdown, location = location.abovebar, size = size.large, text = "2")
plotshape(ma_9 < strategy.position_avg_price *.99 and strategy.opentrades <= (max_trade_count * 0.75)  ? buy_3: na, style = shape.arrowdown, location = location.abovebar, size = size.large, text = "3")
plotshape(ma_9 < strategy.position_avg_price *.99 and strategy.opentrades <= (max_trade_count * 0.75)  ? buy_4: na, style = shape.arrowdown, location = location.abovebar, size = size.large, text = "4", color = color.green)
plotshape(ma_9 < strategy.position_avg_price *.99 and strategy.opentrades <= (max_trade_count * 0.75)  ? buy_5: na, style = shape.arrowdown, location = location.abovebar, size = size.large, text = "5", color = color.red)
plotshape(ma_9 < strategy.position_avg_price *.99 ? buy_6: na,                                                      style = shape.arrowdown, location = location.abovebar, size = size.large, text = "6", color = color.orange)

//Table
var tbl = table.new(position.top_right, 2, 9, frame_color=#151715, frame_width=1, border_width=2, border_color=color.new(color.white, 100))
//column values
table.cell(tbl, 0,0, text = "Cumilative profit (USDT)",                                                     text_color = color.white,       text_halign = text.align_left,      text_valign  = text.align_center, bgcolor = color.green)
table.cell(tbl, 0,1, text = "Current Expenditure",                                                          text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,2, text = "Cash balance",                                                                 text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,3, text = "Cumilative assert (USDT)",                                                     text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,4, text = "Count of open trades",                                                         text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
table.cell(tbl, 0,5, text = "Strategy position Size",                                                       text_color = color.red,         text_halign = text.align_left,      text_valign  = text.align_center)
    
table.cell(tbl, 1,0, str.tostring(strategy.netprofit, format.mintick),                                      text_color = color.white,       text_halign = text.align_right,     text_valign  = text.align_center, bgcolor = color.green)
table.cell(tbl, 1,1, str.tostring(currentexpenditure(), format.mintick),                                    text_color = color.red,         text_halign = text.align_right,     text_valign  = text.align_center)
table.cell(tbl, 1,2, str.tostring(cash_in_hand, format.mintick),                                            text_color = color.red,         text_halign = text.align_right,     text_valign  = text.align_center)
table.cell(tbl, 1,3, str.tostring(total_investment, format.mintick),                                        text_color = color.red,         text_halign = text.align_right,     text_valign  = text.align_center)
table.cell(tbl, 1,4, str.tostring(strategy.opentrades, format.mintick), text_color = color.red,             text_halign = text.align_right, text_valign = text.align_center)
table.cell(tbl, 1,5, str.tostring(strategy.position_size, format.mintick), text_color = color.red,          text_halign = text.align_right, text_valign = text.align_center)






