// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © benso87
//
// Credit to:
// Eric Crown for the strategy
// The_Caretaker for the indicators referenced for calculations.
//
//@version=5
indicator('Stochtaker', shorttitle='Stochtaker', precision=2, max_bars_back=500)
////////////////////////////////////////////////////////////
// Variables
noColor = color.new(color.white, transp=100)
// BBWP
var c_prcntSpctrm1 = array.new_color(na)
if barstate.isfirst
array.push ( c_prcntSpctrm1, #0000FF )
array.push ( c_prcntSpctrm1, #000AFF ), array.push ( c_prcntSpctrm1, #0014FF ), array.push ( c_prcntSpctrm1, #001FFF ), array.push ( c_prcntSpctrm1, #0029FF ), array.push ( c_prcntSpctrm1, #0033FF ),
array.push ( c_prcntSpctrm1, #003DFF ), array.push ( c_prcntSpctrm1, #0047FF ), array.push ( c_prcntSpctrm1, #0052FF ), array.push ( c_prcntSpctrm1, #005CFF ), array.push ( c_prcntSpctrm1, #0066FF ),
array.push ( c_prcntSpctrm1, #0070FF ), array.push ( c_prcntSpctrm1, #007AFF ), array.push ( c_prcntSpctrm1, #0085FF ), array.push ( c_prcntSpctrm1, #008FFF ), array.push ( c_prcntSpctrm1, #0099FF ),
array.push ( c_prcntSpctrm1, #00A3FF ), array.push ( c_prcntSpctrm1, #00ADFF ), array.push ( c_prcntSpctrm1, #00B8FF ), array.push ( c_prcntSpctrm1, #00C2FF ), array.push ( c_prcntSpctrm1, #00CCFF ),
array.push ( c_prcntSpctrm1, #00D6FF ), array.push ( c_prcntSpctrm1, #00E0FF ), array.push ( c_prcntSpctrm1, #00EBFF ), array.push ( c_prcntSpctrm1, #00F5FF ), array.push ( c_prcntSpctrm1, #00FFFF ),
array.push ( c_prcntSpctrm1, #00FFF5 ), array.push ( c_prcntSpctrm1, #00FFEB ), array.push ( c_prcntSpctrm1, #00FFE0 ), array.push ( c_prcntSpctrm1, #00FFD6 ), array.push ( c_prcntSpctrm1, #00FFCC ),
array.push ( c_prcntSpctrm1, #00FFC2 ), array.push ( c_prcntSpctrm1, #00FFB8 ), array.push ( c_prcntSpctrm1, #00FFAD ), array.push ( c_prcntSpctrm1, #00FFA3 ), array.push ( c_prcntSpctrm1, #00FF99 ),
array.push ( c_prcntSpctrm1, #00FF8F ), array.push ( c_prcntSpctrm1, #00FF85 ), array.push ( c_prcntSpctrm1, #00FF7A ), array.push ( c_prcntSpctrm1, #00FF70 ), array.push ( c_prcntSpctrm1, #00FF66 ),
array.push ( c_prcntSpctrm1, #00FF5C ), array.push ( c_prcntSpctrm1, #00FF52 ), array.push ( c_prcntSpctrm1, #00FF47 ), array.push ( c_prcntSpctrm1, #00FF3D ), array.push ( c_prcntSpctrm1, #00FF33 ),
array.push ( c_prcntSpctrm1, #00FF29 ), array.push ( c_prcntSpctrm1, #00FF1F ), array.push ( c_prcntSpctrm1, #00FF14 ), array.push ( c_prcntSpctrm1, #00FF0A ), array.push ( c_prcntSpctrm1, #00FF00 ),
array.push ( c_prcntSpctrm1, #0AFF00 ), array.push ( c_prcntSpctrm1, #14FF00 ), array.push ( c_prcntSpctrm1, #1FFF00 ), array.push ( c_prcntSpctrm1, #29FF00 ), array.push ( c_prcntSpctrm1, #33FF00 ),
array.push ( c_prcntSpctrm1, #3DFF00 ), array.push ( c_prcntSpctrm1, #47FF00 ), array.push ( c_prcntSpctrm1, #52FF00 ), array.push ( c_prcntSpctrm1, #5CFF00 ), array.push ( c_prcntSpctrm1, #66FF00 ),
array.push ( c_prcntSpctrm1, #70FF00 ), array.push ( c_prcntSpctrm1, #7AFF00 ), array.push ( c_prcntSpctrm1, #85FF00 ), array.push ( c_prcntSpctrm1, #8FFF00 ), array.push ( c_prcntSpctrm1, #99FF00 ),
array.push ( c_prcntSpctrm1, #A3FF00 ), array.push ( c_prcntSpctrm1, #ADFF00 ), array.push ( c_prcntSpctrm1, #B8FF00 ), array.push ( c_prcntSpctrm1, #C2FF00 ), array.push ( c_prcntSpctrm1, #CCFF00 ),
array.push ( c_prcntSpctrm1, #D6FF00 ), array.push ( c_prcntSpctrm1, #E0FF00 ), array.push ( c_prcntSpctrm1, #EBFF00 ), array.push ( c_prcntSpctrm1, #F5FF00 ), array.push ( c_prcntSpctrm1, #FFFF00 ),
array.push ( c_prcntSpctrm1, #FFF500 ), array.push ( c_prcntSpctrm1, #FFEB00 ), array.push ( c_prcntSpctrm1, #FFE000 ), array.push ( c_prcntSpctrm1, #FFD600 ), array.push ( c_prcntSpctrm1, #FFCC00 ),
array.push ( c_prcntSpctrm1, #FFC200 ), array.push ( c_prcntSpctrm1, #FFB800 ), array.push ( c_prcntSpctrm1, #FFAD00 ), array.push ( c_prcntSpctrm1, #FFA300 ), array.push ( c_prcntSpctrm1, #FF9900 ),
array.push ( c_prcntSpctrm1, #FF8F00 ), array.push ( c_prcntSpctrm1, #FF8500 ), array.push ( c_prcntSpctrm1, #FF7A00 ), array.push ( c_prcntSpctrm1, #FF7000 ), array.push ( c_prcntSpctrm1, #FF6600 ),
array.push ( c_prcntSpctrm1, #FF5C00 ), array.push ( c_prcntSpctrm1, #FF5200 ), array.push ( c_prcntSpctrm1, #FF4700 ), array.push ( c_prcntSpctrm1, #FF3D00 ), array.push ( c_prcntSpctrm1, #FF3300 ),
array.push ( c_prcntSpctrm1, #FF2900 ), array.push ( c_prcntSpctrm1, #FF1F00 ), array.push ( c_prcntSpctrm1, #FF1400 ), array.push ( c_prcntSpctrm1, #FF0000 ), array.push ( c_prcntSpctrm1, #FF0000 )
var c_prcntSpctrm2 = array.new_color(na)
if barstate.isfirst
array.push ( c_prcntSpctrm2, #0000FF )
array.push ( c_prcntSpctrm2, #0200FC ), array.push ( c_prcntSpctrm2, #0500F9 ), array.push ( c_prcntSpctrm2, #0700F7 ), array.push ( c_prcntSpctrm2, #0A00F4 ), array.push ( c_prcntSpctrm2, #0C00F2 ),
array.push ( c_prcntSpctrm2, #0F00EF ), array.push ( c_prcntSpctrm2, #1100ED ), array.push ( c_prcntSpctrm2, #1400EA ), array.push ( c_prcntSpctrm2, #1600E8 ), array.push ( c_prcntSpctrm2, #1900E5 ),
array.push ( c_prcntSpctrm2, #1C00E2 ), array.push ( c_prcntSpctrm2, #1E00E0 ), array.push ( c_prcntSpctrm2, #2100DD ), array.push ( c_prcntSpctrm2, #2300DB ), array.push ( c_prcntSpctrm2, #2600D8 ),
array.push ( c_prcntSpctrm2, #2800D6 ), array.push ( c_prcntSpctrm2, #2B00D3 ), array.push ( c_prcntSpctrm2, #2D00D1 ), array.push ( c_prcntSpctrm2, #3000CE ), array.push ( c_prcntSpctrm2, #3300CC ),
array.push ( c_prcntSpctrm2, #3500C9 ), array.push ( c_prcntSpctrm2, #3800C6 ), array.push ( c_prcntSpctrm2, #3A00C4 ), array.push ( c_prcntSpctrm2, #3D00C1 ), array.push ( c_prcntSpctrm2, #3F00BF ),
array.push ( c_prcntSpctrm2, #4200BC ), array.push ( c_prcntSpctrm2, #4400BA ), array.push ( c_prcntSpctrm2, #4700B7 ), array.push ( c_prcntSpctrm2, #4900B5 ), array.push ( c_prcntSpctrm2, #4C00B2 ),
array.push ( c_prcntSpctrm2, #4F00AF ), array.push ( c_prcntSpctrm2, #5100AD ), array.push ( c_prcntSpctrm2, #5400AA ), array.push ( c_prcntSpctrm2, #5600A8 ), array.push ( c_prcntSpctrm2, #5900A5 ),
array.push ( c_prcntSpctrm2, #5B00A3 ), array.push ( c_prcntSpctrm2, #5E00A0 ), array.push ( c_prcntSpctrm2, #60009E ), array.push ( c_prcntSpctrm2, #63009B ), array.push ( c_prcntSpctrm2, #660099 ),
array.push ( c_prcntSpctrm2, #680096 ), array.push ( c_prcntSpctrm2, #6B0093 ), array.push ( c_prcntSpctrm2, #6D0091 ), array.push ( c_prcntSpctrm2, #70008E ), array.push ( c_prcntSpctrm2, #72008C ),
array.push ( c_prcntSpctrm2, #750089 ), array.push ( c_prcntSpctrm2, #770087 ), array.push ( c_prcntSpctrm2, #7A0084 ), array.push ( c_prcntSpctrm2, #7C0082 ), array.push ( c_prcntSpctrm2, #7F007F ),
array.push ( c_prcntSpctrm2, #82007C ), array.push ( c_prcntSpctrm2, #84007A ), array.push ( c_prcntSpctrm2, #870077 ), array.push ( c_prcntSpctrm2, #890075 ), array.push ( c_prcntSpctrm2, #8C0072 ),
array.push ( c_prcntSpctrm2, #8E0070 ), array.push ( c_prcntSpctrm2, #91006D ), array.push ( c_prcntSpctrm2, #93006B ), array.push ( c_prcntSpctrm2, #960068 ), array.push ( c_prcntSpctrm2, #990066 ),
array.push ( c_prcntSpctrm2, #9B0063 ), array.push ( c_prcntSpctrm2, #9E0060 ), array.push ( c_prcntSpctrm2, #A0005E ), array.push ( c_prcntSpctrm2, #A3005B ), array.push ( c_prcntSpctrm2, #A50059 ),
array.push ( c_prcntSpctrm2, #A80056 ), array.push ( c_prcntSpctrm2, #AA0054 ), array.push ( c_prcntSpctrm2, #AD0051 ), array.push ( c_prcntSpctrm2, #AF004F ), array.push ( c_prcntSpctrm2, #B2004C ),
array.push ( c_prcntSpctrm2, #B50049 ), array.push ( c_prcntSpctrm2, #B70047 ), array.push ( c_prcntSpctrm2, #BA0044 ), array.push ( c_prcntSpctrm2, #BC0042 ), array.push ( c_prcntSpctrm2, #BF003F ),
array.push ( c_prcntSpctrm2, #C1003D ), array.push ( c_prcntSpctrm2, #C4003A ), array.push ( c_prcntSpctrm2, #C60038 ), array.push ( c_prcntSpctrm2, #C90035 ), array.push ( c_prcntSpctrm2, #CC0033 ),
array.push ( c_prcntSpctrm2, #CE0030 ), array.push ( c_prcntSpctrm2, #D1002D ), array.push ( c_prcntSpctrm2, #D3002B ), array.push ( c_prcntSpctrm2, #D60028 ), array.push ( c_prcntSpctrm2, #D80026 ),
array.push ( c_prcntSpctrm2, #DB0023 ), array.push ( c_prcntSpctrm2, #DD0021 ), array.push ( c_prcntSpctrm2, #E0001E ), array.push ( c_prcntSpctrm2, #E2001C ), array.push ( c_prcntSpctrm2, #E50019 ),
array.push ( c_prcntSpctrm2, #E80016 ), array.push ( c_prcntSpctrm2, #EA0014 ), array.push ( c_prcntSpctrm2, #ED0011 ), array.push ( c_prcntSpctrm2, #EF000F ), array.push ( c_prcntSpctrm2, #F2000C ),
array.push ( c_prcntSpctrm2, #F4000A ), array.push ( c_prcntSpctrm2, #F70007 ), array.push ( c_prcntSpctrm2, #F90005 ), array.push ( c_prcntSpctrm2, #FC0002 ), array.push ( c_prcntSpctrm2, #FF0000 )
var string STM = 'Spectrum'
var string SLD = 'Solid'
var string BGR = 'Blue Green Red'
var string BR = 'Blue Red'
// PMARP
var string s_pmarp = 'Price Moving Average Ratio Percentile'
var string s_pmar = 'Price Moving Average Ratio'
var string s_BGR = 'Blue Green Red'
var string s_BR = 'Blue Red'
var float pmarHigh = 0.0
////////////////////////////////////////////////////////////
// Inputs
// Signals
// showSignals = input.bool(true, title='Show Signals', group='Signals')
// sigLongColor = input.color(color.new(#0bff00, transp=50), title='Long', group='Signals')
// sigShortColor = input.color(color.new(#ff0014, transp=50), title='Short', group='Signals')
// sigType = input.string('Dot', title='Signal Type', options=['Dot', 'Background'], group='Signals')
// Stoch
showStoch = input.bool(false, title='Plot', group='Stochastic')
periodK = input.int(title='K', minval=1, defval=14, group='Stochastic')
smoothK = input.int(title='K Smoothing', minval=1, defval=6, group='Stochastic')
periodD = input.int(title='D Smoothing', minval=1, defval=3, group='Stochastic')
src = input(title='Source', defval=close, group='Stochastic')
iKColor = input.color(color.blue, title='K Color', group='Stochastic', inline='0')
iDColor = input.color(color.red, title='D Color', group='Stochastic', inline='0')
obLevel = input(title='Overbought Level', defval=80, group='Stochastic', inline='1')
obLevelColor = input.color(color.new(color.yellow, transp=50), title='', group='Stochastic', inline='1')
osLevel = input(title='Oversold Level', defval=20, group='Stochastic', inline='2')
osLevelColor = input.color(color.new(color.yellow, transp=50), title='', group='Stochastic', inline='2')
highlightBreakouts = input(title='Highlight Overbought/Oversold Breakouts ?', defval=false, group='Stochastic', inline='4')
breakoutColorHigh = input.color(color.new(color.blue, transp=70), title='Overbought', group='Stochastic', inline='5')
breakoutColorLow = input.color(color.new(color.red, transp=70), title='Oversold', group='Stochastic', inline='5')
highlightCrossovers = input(title='Highlight K/D Crossovers ?', defval=false, group='Stochastic', inline='6')
applyRibbonFilling = input(title='Apply Ribbon Filling ?', defval=false, group='Stochastic', inline='7')
// BBWP
showBBWP = input.bool ( true, 'Plot', group='BBWP Properties')
i_priceSrc = input.source ( close, 'Price Source', group='BBWP Properties')
i_basisType = input.string ( 'SMA', 'Basis Type', options=['SMA', 'EMA', 'VWMA'], group='BBWP Properties')
i_bbwpLen = input.int ( 13, 'Length', minval=1, group='BBWP Properties')
i_bbwpLkbk = input.int ( 252, 'Lookback', minval=1, group='BBWP Properties')
i_c_bbwpTyped = input.string ( STM, 'Color Type', options=[STM, SLD], inline='1', group='BBWP Plot Settings')
i_c_spctrmType = input.string ( BGR, 'Spectrum', options=[BR, BGR], inline='1', group='BBWP Plot Settings')
i_c_bbwpsolid = input.color ( #FFFF00, 'Solid', inline='1', group='BBWP Plot Settings')
i_bbwpWidth = input.int ( 1, 'Line Width', minval=1, maxval=4, inline='2', group='BBWP Plot Settings')
i_bbwpTransp = input.int (20, 'Transparency', minval=0, maxval=100, inline='2', group='BBWP Plot Settings')
i_bbwpPlotType = input.string ('Area', title='Plot Type', options=['Area', 'Line'], inline='3', group='BBWP Plot Settings')
i_ma1On = input.bool ( false, '', inline='1', group='BBWP Moving Average Settings')
i_ma1Type = input.string ( 'SMA', 'MA 1 Type', options=['SMA', 'EMA', 'VWMA'], inline='1', group='BBWP Moving Average Settings')
i_c_ma1 = input.color ( #FFFFFF, '', inline='1', group='BBWP Moving Average Settings')
i_ma1Len = input.int ( 5, 'Length', minval=1, inline='1', group='BBWP Moving Average Settings')
i_ma2On = input.bool ( false, '', inline='2', group='BBWP Moving Average Settings')
i_ma2Type = input.string ( 'SMA', 'MA 2 Type', options=['SMA', 'EMA', 'VWMA'], inline='2', group='BBWP Moving Average Settings')
i_c_ma2 = input.color ( #00FFFF, '', inline='2', group='Moving Average Settings')
i_ma2Len = input.int ( 8, 'Length', minval=1, inline='2', group='BBWP Moving Average Settings')
i_alrtsOn = input.bool ( false, 'Alerts On', group='BBWP Visual Alerts')
i_upperLevel = input.int ( 100, 'Extreme High', minval=1, inline='1', group='BBWP Visual Alerts')
i_lowerLevel = input.int ( 35, 'Extreme Low', minval=1, inline='1', group='BBWP Visual Alerts')
// PMARP
showPMARP = input.bool ( true, 'Plot', group='PMARP Properties')
i_src_price = input.source ( close, 'Price source', inline='1', group='PMARP Properties')
i_ma_len = input.int ( 20, 'PMAR length', minval=1, inline='3', group='PMARP Properties')
i_ma_typ = input.string ( 'VWMA', 'MA type...', options=[ 'SMA', 'EMA', 'HMA', 'RMA', 'VWMA' ], inline='3', group='PMARP Properties')
i_c_typ_line = input.string ( 'Alerts', 'Color type', options=[ 'Spectrum', 'Solid', 'Alerts' ], inline='1', group='PMARP plot settings')
i_c_typ_spctrm_line = input.string ( s_BGR, 'Spectrum', options=[ s_BR, s_BGR ], inline='1', group='PMARP plot settings')
i_c_solid_line = input.color (color.new(color.gray, transp=50), 'Solid color', inline='1', group='PMARP plot settings')
i_c_alert_high = input.color (#ff0014, 'Alert high', inline='2', group='PMARP plot settings')
i_c_alert_low = input.color (#0bff00, 'Alert low', inline='2', group='PMARP plot settings')
i_p_width_line = input.int ( 4, 'Line width', minval=1, maxval=4, inline='3', group='PMARP plot settings')
i_pmarpTransp = input.int (100, 'Transparency', minval=0, maxval=100, inline='3', group='PMARP plot settings')
i_pmarpPlotType = input.string ('Line', title='Plot Type', options=['Area', 'Line'], inline='4', group='PMARP plot settings')
i_pmarp_lookback = input.int ( 350, 'Lookback', minval=1, maxval=1900, inline='5', group='PMARP plot settings')
i_show_signal_ma = input.bool ( false, 'Signal MA', inline='0', group='PMARP Signal MA Settings')
i_signal_ma_Len = input.int ( 20, 'MA length', minval=1, inline='1', group='PMARP Signal MA Settings')
i_signal_ma_typ = input.string ( 'SMA', 'MA type', options=[ 'SMA', 'EMA', 'HMA', 'RMA', 'VWMA' ], inline='1', group='PMARP Signal MA Settings')
i_c_typ_sig = input.string ( 'Solid', 'Color type', options=[ 'Spectrum', 'Solid' ], inline='2', group='PMARP Signal MA Settings')
i_c_typ_spctrm_sig = input.string ( s_BGR, 'Spectrum', options=[ s_BR, s_BGR ], inline='2', group='PMARP Signal MA Settings')
i_c_solid_sig = input.color ( color.white, 'Solid color', inline='2', group='PMARP Signal MA Settings')
i_p_width_sig = input.int ( 1, 'Line width', minval=1, maxval=4, inline='3', group='PMARP Signal MA Settings')
i_hi_alert_pmarp = input.float ( 85, 'Hi PMARP alert level', minval=0.1, maxval=100, step=0.01, inline='6', group='PMARP Visual Alert Level Settings')
i_lo_alert_pmarp = input.float ( 15, 'Lo PMARP alert level', minval=0.1, maxval=100, step=0.01, inline='6', group='PMARP Visual Alert Level Settings')
i_hi_alert_line_on = input.bool ( true, 'Hi alert line.', inline='8', group='PMARP Visual Alert Level Settings')
i_lo_alert_line_on = input.bool ( true, 'Lo alert line.', inline='8', group='PMARP Visual Alert Level Settings')
i_bg_hi_signal_on = input.bool ( false, 'Hi signal bars', inline='9', group='PMARP Visual Alert Level Settings')
i_bg_lo_signal_on = input.bool ( false, 'Lo signal bars', inline='9', group='PMARP Visual Alert Level Settings')
////////////////////////////////////////////////////////////
// Functions
// BBWP
f_maType ( _price, _len, _type ) =>
_type == 'SMA' ? ta.sma ( _price, _len ) : _type == 'EMA' ? ta.ema ( _price, _len ) : ta.vwma ( _price, _len )
f_bbwp ( _price, _bbwLen, _bbwpLen, _type ) =>
float _basis = f_maType ( _price, _bbwLen, _type )
float _dev = ta.stdev ( _price, _bbwLen )
_bbw = ( _basis + _dev - ( _basis - _dev )) / _basis
_bbwSum = 0.0
_len = bar_index < _bbwpLen ? bar_index : _bbwpLen
for _i = 1 to _len by 1
_bbwSum += ( _bbw[_i] > _bbw ? 0 : 1 )
_bbwSum
_return = bar_index >= _bbwLen ? ( _bbwSum / _len) * 100 : na
_return
f_clrSlct ( _percent, _select, _type, _solid, _array1, _array2 ) =>
_select == 'Solid' ? _solid : array.get ( _type == 'Blue Green Red' ? _array1 : _array2, math.round ( _percent ) )
// PMARP
f_prior_sum ( _P, _X ) =>
math.sum ( _P[1], _X - 1 )
f_ma_val ( _P, _typ, _len ) =>
_typ == 'SMA' ? ta.sma ( _P, _len ) : _typ == 'EMA' ? ta.ema ( _P, _len ) : _typ == 'RMA' ? ta.rma ( _P, _len ) : _typ == 'HMA' ? ta.hma ( _P, _len ) : ta.vwma ( _P, _len )
f_pmarp ( _price, _pmarLen, _pmarpLen, _type ) =>
_pmar = math.abs ( _price / f_ma_val ( _price, _type, _pmarLen ))
_pmarpSum = 0
_len = bar_index < _pmarpLen ? bar_index : _pmarpLen
for i = 1 to _len by 1
_pmarpSum += ( _pmar[i] > _pmar ? 0 : 1 )
_pmarpSum
_return = bar_index >= _pmarLen ? _pmarpSum / _len * 100 : na
////////////////////////////////////////////////////////////
// Calculations
// Stoch
k = ta.sma(ta.stoch(src, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
trendColor = k >= d ? iKColor : iDColor
kColor = applyRibbonFilling ? trendColor : iKColor
dColor = applyRibbonFilling ? trendColor : iDColor
defaultPlotColor = color.new(#989898, transp=0)
obFillColor = k > obLevel and highlightBreakouts ? breakoutColorHigh : na
osFillColor = k < osLevel and highlightBreakouts ? breakoutColorLow : na
kSlope = k - k[1]
kForecast = k + kSlope
dForecast = ta.sma(kForecast, periodD)
// BBWP
bbwp = f_bbwp ( i_priceSrc, i_bbwpLen, i_bbwpLkbk, i_basisType )
c_bbwp = f_clrSlct ( bbwp, i_c_bbwpTyped, i_c_spctrmType, i_c_bbwpsolid, c_prcntSpctrm1, c_prcntSpctrm2 )
bbwpMA1 = i_ma1On ? f_maType ( bbwp, i_ma1Len, i_ma1Type ) : na
bbwpMA2 = i_ma2On ? f_maType ( bbwp, i_ma2Len, i_ma2Type ) : na
hiAlrtBar = i_alrtsOn and bbwp >= i_upperLevel ? bbwp : na
loAlrtBar = i_alrtsOn and bbwp <= i_lowerLevel ? bbwp : na
bbwpTransp = 100 - i_bbwpTransp
bbwpPlotType = i_bbwpPlotType == 'Area' ? plot.style_area : plot.style_line
// PMARP
ma = f_ma_val ( i_src_price, i_ma_typ, i_ma_len )
pmarp = f_pmarp ( i_src_price, i_ma_len, i_pmarp_lookback, i_ma_typ )
hi_alert = i_hi_alert_pmarp
lo_alert = i_lo_alert_pmarp
c_alerts = pmarp <= lo_alert ? i_c_alert_low : pmarp >= hi_alert ? i_c_alert_high : i_c_solid_line
c_pmarp = i_c_typ_line == 'Alerts' ? c_alerts : f_clrSlct (pmarp, i_c_typ_line, i_c_typ_spctrm_line, i_c_solid_line, c_prcntSpctrm1, c_prcntSpctrm2)
signal_ma = f_ma_val ( pmarp, i_signal_ma_typ, i_signal_ma_Len )
c_plotsig = f_clrSlct ( signal_ma, i_c_typ_sig, i_c_typ_spctrm_sig, i_c_solid_sig, c_prcntSpctrm1, c_prcntSpctrm2 )
hi_alertc = i_hi_alert_pmarp
c_hi_alert = i_c_typ_line == 'Alerts' ? c_alerts : f_clrSlct ( hi_alertc, i_c_typ_line, i_c_typ_spctrm_sig, i_c_solid_sig, c_prcntSpctrm1, c_prcntSpctrm2 )
c_lo_alert = i_c_typ_line == 'Alerts' ? c_alerts : f_clrSlct ( lo_alert, i_c_typ_line, i_c_typ_spctrm_sig, i_c_solid_sig, c_prcntSpctrm1, c_prcntSpctrm2 )
c_bg = color.new ( i_c_typ_line == 'Alerts' ? c_alerts : f_clrSlct ( pmarp, i_c_typ_line, i_c_typ_spctrm_line, i_c_solid_line, c_prcntSpctrm1, c_prcntSpctrm2 ), 50 )
p_hi_alert = pmarp > hi_alert
p_lo_alert = pmarp < lo_alert
pmarpTransp = 100 - i_pmarpTransp
pmarpPlotType = i_pmarpPlotType == 'Area' ? plot.style_area : plot.style_line
// Signals
// longSignal = pmarp <= lo_alert and bbwp <= i_lowerLevel
// shortSignal = pmarp >= hi_alert and bbwp <= i_lowerLevel
// Signal colors
// sigColor = longSignal ? sigLongColor : shortSignal ? sigShortColor : na
////////////////////////////////////////////////////////////
// Plots
// Lines
maxLevelPlot = hline (100, title='Scale High', color=#ff0000, linestyle=hline.style_solid )
midLevelPlot = hline (50, title='Mid Level', color=defaultPlotColor, linestyle=hline.style_dashed)
minLevelPlot = hline (0, title='Scale Low', color=#0000ff, linestyle=hline.style_solid )
// Stoch
kPlot = plot(showStoch ? k : na, title='K', color=kColor, linewidth=3)
dPlot = plot(showStoch ? d : na, title='D', color=dColor, linewidth=3)
fillColor = applyRibbonFilling ? color.new(trendColor, transp=70) : noColor
fill(kPlot, dPlot, title='Ribbon', color=fillColor)
plotshape(showStoch and highlightCrossovers and barstate.isconfirmed and ta.crossover(k, d) ? k : na, title='K/D Crossover', location=location.absolute, style=shape.circle, size=size.tiny, color=kColor)
plotshape(showStoch and highlightCrossovers and barstate.isconfirmed and ta.crossunder(k, d) ? d : na, title='K/D Crossunder', location=location.absolute, style=shape.circle, size=size.tiny, color=dColor)
plot(showStoch ? kForecast : na, title='K Forecast', color=iKColor, style=plot.style_circles, offset=1, show_last=1, linewidth=2)
plot(showStoch ? dForecast : na, title='D Forecast', color=iDColor, style=plot.style_circles, offset=1, show_last=1, linewidth=2)
obLevelPlot = hline(obLevel, title='Overbought Level', linestyle=hline.style_dashed, color=obLevelColor)
osLevelPlot = hline(osLevel, title='Oversold Level', linestyle=hline.style_dashed, color=osLevelColor)
fill(obLevelPlot, osLevelPlot, title='Middle Zone', color=color.new(color.purple, transp=95))
fill(maxLevelPlot, obLevelPlot, title='Upper Band Breakout', color=obFillColor)
fill(minLevelPlot, osLevelPlot, title='Lower Band Breakout', color=osFillColor)
// BBWP
p_bbwp = plot ( showBBWP ? bbwp : na, 'BBWP', color.new(c_bbwp, transp=bbwpTransp), i_bbwpWidth, bbwpPlotType )
p_hiAlrt = plot ( hiAlrtBar, 'BBWP Extreme Hi', color.new(c_bbwp, transp=70), 1, plot.style_columns, histbase=0, editable=false )
p_loAlrt = plot ( loAlrtBar, 'BBWP Extreme Lo', color.new(c_bbwp, transp=70), 1, plot.style_columns, histbase=100, editable=false )
p_ma1 = plot ( showBBWP ? bbwpMA1 : na, 'BBWP MA 1', i_c_ma1, 1, plot.style_line, 0 )
p_ma2 = plot ( showBBWP ? bbwpMA2 : na, 'BBWP MA 2', i_c_ma2, 1, plot.style_line, 0 )
hline(i_lowerLevel, 'BBWP Low', color.new(color.silver, transp=50), linestyle=hline.style_dotted)
// PMARP
plot ( showPMARP ? pmarp : na, 'PMARP', color.new(c_pmarp, transp=pmarpTransp), i_p_width_line, style=pmarpPlotType )
plot ( showPMARP and i_show_signal_ma ? signal_ma : na, 'PMARP Signal', c_plotsig, i_p_width_sig, editable=false )
hline ( i_hi_alert_line_on ? i_hi_alert_pmarp : na, 'High alert level', i_c_alert_high, linestyle = hline.style_dotted )
hline ( i_lo_alert_line_on ? i_lo_alert_pmarp : na, 'Low alert level', i_c_alert_low, linestyle = hline.style_dotted )
bgcolor ( p_hi_alert and i_hi_alert_line_on and i_bg_hi_signal_on ? color.new(c_bg, transp=70) : na )
bgcolor ( p_lo_alert and i_lo_alert_line_on and i_bg_lo_signal_on ? color.new(c_bg, transp=70) : na )
// Signals
// bgcolor(sigType == 'Background' and showSignals ? sigColor : na)
// plot(sigType == 'Dot' and showSignals and (longSignal or shortSignal) ? 108 : na, title='Signal Dots', color=color.new(sigColor, transp=0), linewidth=3, style=plot.style_circles)
////////////////////////////////////////////////////////////
// Testing
Show all 322 lines