[Any Timeframe]-Homerun
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Nightweevil2477-Version 3-Initially Published On 20220727
//
// FYI
// This script is intended to be used as a 'indicator/visual aid'. End users will be able to see 'WHY' plot was shown and if wanted a dynamic alert can be set/triggered in tradingview.com for it
// 
// New Version Release Schedule;  Every Wednesday evening UTC+10 -only if their is a script update
// For each script version the author releases the end user is not forced to use the newer version, only if they want to
// End users are encouraged to migrate from old versions to new versions (Educates end user on what settings they use and their are always benefits/features when using the new script).
//
// Available script main functions
// 1. Identify 'Strike' patterns on the selected chart/timeframe
// 2. Plot 3 EMA lines on the on the selected chart/timeframe 
// 3. Plot when the EMA lines cross on the on the selected chart/timeframe
// 4. Plot when strike patterns appear for a certain EMA
// 5. Plot 3 SMA lines on the on the selected chart/timeframe
// 6. Plot when the SMA lines cross on the on the selected chart/timeframe
// 7. Plot when strike patterns appear for a certain SMA
// 8. Display a table of details end user can see immediately
//
// Available script end user customization options
// Settings Area
// -=Root setting=- (all settings are disabled by default-end user can decide if they want on or off)
// Enable/Disable 'Strike' bearish pattern from being shown
// Enable/Disable 'Strike' bullish pattern from being shown
// Enable/Disable 3 EMA lines from being shown
// Enable/Disable when the EMA line cross's
// Enable/Disable 3 SMA lines from being shown
// Enable/Disable when the SMA line cross's
// Enable/Disable if want BB to be shown
// Enable/Disable when BB bars go outside the cloud
// Enable/Disable if you want table to be shown
// Enable/Disable if want Psar to be shown
// The 2 below are not required to be adjusted
// Symbol = current chart trading pair
// Time Period = current chart period (By default this is ALL) 
//
// -=Granularity=-
// Added ability to enable/disable each EMA line
// 3x Set each EMA line length
// Added ability to enable/disable each EMA line
// 3x Set each SMA line length
// Added more EMA crossover labels on the chart
// Set BB scope
// Set Psar settings
// Added ability for end users to have their own customised table heading names
// Table: General oscillator stats added to table of details-RSI, ATR, Stochastic, W%R, CCI, AO, MACD, Aroon, ADX, Dem, Chande, ROC, DMI, VI
//
// Available dynamic alerts – can be used as triggers on tradingview.com 
// Related to ‘Strike’ pattern identification
// Strike Bullish – Reason; pattern found
// Strike Bearish – Reason; pattern found
// Related to EMA plotted lines (crossing)
// EMA X Up-Reason; EMA line 1 goes up/over EMA line 2
// EMA X Down-Reason; EMA line 2 goes down/below EMA line 1
// Related to SMA plotted lines (crossing)
// SMA X Up-Reason; SMA line 1 goes up/over SMA line 2
// SMA X Down-Reason; SMA line 2 goes down/below SMA line 1
// BB Bullish-Reason; Bar sticking out upper cloud
// BB Bearish-Reason; Bar sticking out lower cloud
//
// Script modularity
// Each section of code is broken up into easily specific/editable areas
// For example; you can home in onto a specific code related area or you can make new area just 
// specifically what you are trying to accomplish and just slot it into the existing code without 
// breaking the format (their might be minimal conflict, normally this might be pre-used variables – if 
// so; its easy to fix)
//
// For example; Work on individual/separate scripts and when its working, just slot it in to this 'Mega Script' + add script module description
//				Normal conditions apply; is it an indicator or strategy. is it coded in the right pine script version 3/4/5
//				(if not v5 then can convert old code to new code on tradingview.com) 
//
//  Table Explanation (more green the better)-Green = lower risk , Orange = medium risk, Red = higher risk
//	Using default values supplied via script
//	Ande Open
//	-Real-Time chart info of the current pair price
//	Last Close
//	-Real-Time chart info of the current pair price
//	Volume
//	-Real-Time chart info of the current pair volume
//	if over 0 then go green
//	if under -0 then go red
//	RSI - Relative Strength Index
//	if over 70 then go red
//	if between 69 through to 31 then go orange
//	if under 30 then go green
//	ATR - Average True Range
//	if over 40 then go green
//	if between 49 through to 27 then go orange
//	if under 28 then go red
//	Stoch Line 1 - Stochastic Oscillator
//	if over 80 then go green
//	if between 21 through to 79 then go orange
//	if under 20 then go red
//	Stoch Line 2 - Stochastic Oscillator
//	if over 50 then go green
//	if under 49 then go red
//	W%R - William Percent Range
//	if under -20 then go green
//	if between -21 through to -79 then go orange
//	if under -80 then go red
//	CCI - Commodity Channel Index
//	if over 100 then go green
//	if between 99 through to -99 then go orange
//	if under -100 then go red
//	AO - Awesome Oscillator
//	if over 0 then go green
//	if under -0 then go red
//	MACD Line 1 - Moving Average Convergence Divergence
//	if over 0 then go green
//	if under -0 then go red
//	MACD Line 2 - Moving Average Convergence Divergence
//	if over 0 then go green
//	if under -0 then go red
//	MACD Hist - Moving Average Convergence Divergence
//	if over 0 then go green
//	if under -0 then go red
//	Aroon - Aroon Oscillator
//	if over 50 then go green
//	if under -0 then go red
//	ADX - Average Directional Index
//	if over 50 then go green
//	if under -50 then go red
//  DeM -DeMarker Indicator
//	if over 0.7 then go red
//	if under 0.3 then go green
//  Chande - Chande Momentum Oscillator
//	if over 50 then go red
//	if under -50 then go green
//  ROC - Rate of change
//	if under 0 then go green
//	if under 0 then go red
//  DMI+ - Directional Movement Index
//	if above DMI- then go green
//	if under DMI- then go red
//  DMI- - Directional Movement Index
//	if below DMI+ then go red
//	if above DMI+ then go green
//  VI - Vorteex Indicator
//	if above VI- then go green
//	if under VI- then go red
//  VI - Vorteex Indicator
//	if below VI+ then go red
//	if above VI+ then go green
//
//	V1 Change log – 27/7/22
//	Published initial ‘Strike Pattern Identification’ script
//	Included chart plots if detected pattern was ‘Bullish or Bearish’
//	Included chart dynamic alerts (depends on the real-time market data and when new pattern is plotted Chart)
//
//	V2 Change log – 11/8/22
//	Made each coded feature to be either Enabled/Disabled by the end user (all is default OFF as end user can decide if they want to enable else to many plots Chart, this can confuse end users)
//	Added EMA lines (x3)
//	Added chart plots when the EMA lines cross
//	Added SMA lines (x3)
//	Added chart plots when the SMA lines cross
//	Added granularity – ability for end users to alter few defined parametersAC
//	Added table of useful details the end user might want to see at a glance
//	For each plotted item added it to the dynamic alert option end user can use as trigger on tradingview.com
//	Encapsulated each feature into their own sperate easy to modify/switch out for other modules
//	Added all this same info + more in the actual script beginning/blurb as end user not always see tradingview.com or profile site, they just see the item from the site ‘indicator’ area prior to adding it to the ‘Chart or Favorites’
//
//  V3 Change log – 31/7/22
//  Added missing module descriptions from the previous release
//  Fixed some spelling/grammar mistakes
//  Decided timeline for future script releases (Every Wednesday evening UTC+10 -only if their is a script update)
//  Added Bollinger Bands (In the script it’s called ‘BB’)
//  Added Parabolic Sar (In the script it’s called ‘Psar’)
//  Added chart plots when the BB exits the cloud
//  Add ability to change table orientation
//  Improved table colors (more green the better) -Green = lower risk , Orange = medium risk, Red = higher risk
//	General oscillator stats added to table of details-RSI, ATR, Stochastic, W%R, CCI, AO, MACD, Aroon, ADX
//  Added script Disclaimer to the Settings area
//
//  V4 Change log – 5/10/22
//  Added ability for end users to have their own customised table heading names
//  Cleaned up Settings-->Inputs screen slightly
//  Converted code for end user table to be a reuseable functions
//  Tweaked table colors
//  Added MACD (Histogram) stats to the table
//  Added ability to enable/disable each EMA line
//  Added more EMA crossover labels on the chart
//  Added ability to enable/disable each SMA line
//  Added more SMA crossover labels on the chart
//  Added DeM stats to the table
//  Added Chande stats to the table
//  Added ROC stats to the table
//  Added VI stats to the table
//  Added a tooltip for every table stat to allow end users to be reminded what stat means (i.e; why does the color keep changing)
//  Added new module based on Strike patterns and if above or below the EMA line specified
//  Added new module based on Strike patterns and if above or below the SMA line specified
//  Updated Psar module to have some alerts to use via tradingview.com
//
//@version=5
indicator(title='[Any Timeframe]-Homerun', overlay=true)

//End user notice of script intention
ScriptEula = "This script is intended to be used as a 'indicator/visual aid'. End users will be able to see 'WHY' plot was shown and if wanted a dynamic alert can be set/triggered in tradingview.com for it"
SettingsInputPage = input.bool(true, ScriptEula, group="-=Disclaimer=-")
plotshape(false, color=color.white, title="-=Disclaimer=-  " + ScriptEula)

//Strike Pattern Module--------------------------------------------------------------------------
//Give end user the option if they want strike section enabled or not
showBullishStrikepattern = input.bool(false,"Show Bullish Strike Pattern", group="Pattern")
showBearishStrikepattern = input.bool(false,"Show Bearish Strike Pattern", group="Pattern")

//identify bullish pattern; green green green red
StrikeBullcandleCheck1st = barstate.isconfirmed and close[3] > open[3]
StrikeBullcandleCheck2nd = barstate.isconfirmed and close[2] > open[2]
StrikeBullcandleCheck3rd = barstate.isconfirmed and  close[1] > open[1]
StrikeBullcandleCheck4th = barstate.isconfirmed and close[0] < open[0]
StrikeBullpatternCheck = StrikeBullcandleCheck1st and StrikeBullcandleCheck2nd and StrikeBullcandleCheck3rd and StrikeBullcandleCheck4th

//identify bearish pattern; red red red green
StrikeBearcandleCheck1st = barstate.isconfirmed and close[3] < open[3]
StrikeBearcandleCheck2nd = barstate.isconfirmed and close[2] < open[2]
StrikeBearcandleCheck3rd = barstate.isconfirmed and  close[1] < open[1]
StrikeBearcandleCheck4th = barstate.isconfirmed and close[0] > open[0]
StrikeBearpatternCheck = StrikeBearcandleCheck1st and StrikeBearcandleCheck2nd and StrikeBearcandleCheck3rd and StrikeBearcandleCheck4th

//Plot it Chart
//For every strike pattern found
plotshape(showBullishStrikepattern ? StrikeBullpatternCheck: na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Strike-Bullish", title="Chart-Pattern-Strike-Bullish")
plotshape(showBearishStrikepattern ? StrikeBearpatternCheck: na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Strike-Bearish", title="Chart-Pattern-Strike-Bearish")

//Trigger Alert (only works if trigger set on tradingview.com site)
//For every strike pattern found
alertcondition(showBullishStrikepattern ? StrikeBullpatternCheck: na, title='Chart-Pattern-Strike-Bullish')
alertcondition(showBearishStrikepattern ? StrikeBearpatternCheck: na, title='Chart-Pattern-Strike-Bearish')

//EMA Module----------------------------------------------------------------------------------------
//Give end user the option if they want EMA line 1 enabled or not
showEmaLine1 = input.bool(false,"Show EMA Line 1", group="EMA")
ema1=input.int(defval=20, title="Chart-EMA-Line 1", group="EMA")
setEma1 = ta.ema(close, ema1)

//Give end user the option if they want EMA line 2 enabled or not
showEmaLine2 = input.bool(false,"Show EMA Line 2", group="EMA")
ema2=input.int(defval=50, title="Chart-EMA-Line 2", group="EMA")
setEma2 = ta.ema(close, ema2)

//Give end user the option if they want EMA line 3 enabled or not
showEmaLine3 = input.bool(false,"Show EMA Line 3", group="EMA")
ema3=input.int(defval=200, title="Chart-EMA-Line 3", group="EMA")
setEma3 = ta.ema(close, ema3)

//Plot it Chart
//Plot EMA lines Chart only if item is enabled in the settings area
plot(showEmaLine1 ? setEma1 : na, color=color.red, linewidth=2, title="Chart-EMA-Line 1")
plot(showEmaLine2 ? setEma2 : na, color=color.green, linewidth=2, title="Chart-EMA-Line 2")
plot(showEmaLine3 ? setEma3 : na, color=color.black, linewidth=2, title="Chart-EMA-Line 3")

//Plot Ema line crosses
//Give end user the option if they want shox x's section enabled or not
showEmaLineCrosses = input.bool(false,"Show EMA X's", group="EMA")

//Detect line cross
ema_crossing_up = ta.crossover(setEma1, setEma2) //red above green
ema_crossing_down = ta.crossunder(setEma1, setEma2) //red under green
ema_crossing_up2 = ta.crossover(setEma2, setEma1) //green above red
ema_crossing_down2 = ta.crossunder(setEma2, setEma1) //green under red

//Plot it Chart if setting is enabled
plotshape(showEmaLineCrosses ? ema_crossing_up : na, style=shape.cross, location=location.abovebar, color=color.new(color.red, 0), text='Chart-EMA-Line 1 X Above Line 2', title='Chart-EMA-Line 1 X Above Line 2')
plotshape(showEmaLineCrosses ? ema_crossing_down : na, style=shape.cross, location=location.abovebar, color=color.new(color.red, 0), text='Chart-EMA-Line 1 X Under Line 2', title='Chart-EMA-Line 1 X Under Line 2')
plotshape(showEmaLineCrosses ? ema_crossing_up2 : na, style=shape.cross, location=location.belowbar, color=color.new(color.red, 0), text='Chart-EMA-Line 2 X Above Line 1', title='Chart-EMA-Line 2 X Above Line 1')
plotshape(showEmaLineCrosses ? ema_crossing_down2 : na, style=shape.cross, location=location.belowbar, color=color.new(color.red, 0), text='Chart-EMA-Line 2 X Under Line 1', title='Chart-EMA-Line 2 X Under Line 1')

//Trigger Alert (only works if trigger set on tradingview.com site)
//When EMA line crosses
alertcondition(showEmaLineCrosses ? ema_crossing_up: na, title='Chart-EMA-Line 1 X Above Line 2')
alertcondition(showEmaLineCrosses ? ema_crossing_down: na, title='Chart-EMA-Line 1 X Under Line 2')
alertcondition(showEmaLineCrosses ? ema_crossing_up2: na, title='Chart-EMA-Line 2 X Above Line 1')
alertcondition(showEmaLineCrosses ? ema_crossing_down2: na, title='Chart-EMA-Line 2 X Under Line 1')

//EMA Strike Module--------------------------------------------------------------------------------------------------------
//Show pattern were filter condition is true
showBullishStrikepatternEMALine1 = input.bool(false,"Show Bullish Strike Pattern Above The EMA Line 1", group="Pattern/EMA")
showBullishStrikepatternEMALine2 = input.bool(false,"Show Bullish Strike Pattern Above The EMA Line 2", group="Pattern/EMA")
showBullishStrikepatternEMALine3 = input.bool(false,"Show Bullish Strike Pattern Above The EMA Line 3", group="Pattern/EMA")

showBearishStrikepatternEMALine1 = input.bool(false,"Show Bearish Strike Pattern Below The EMA Line 1", group="Pattern/EMA")
showBearishStrikepatternEMALine2 = input.bool(false,"Show Bearish Strike Pattern Below The EMA Line 2", group="Pattern/EMA")
showBearishStrikepatternEMALine3 = input.bool(false,"Show Bearish Strike Pattern Below The EMA Line 3", group="Pattern/EMA")

//Filter found patterns to be only above or below the EMA Line
strikebullpatternEMALine1filter = StrikeBullpatternCheck == true and close > setEma1
strikebearpatternEMALine1filter = StrikeBearpatternCheck == true and close < setEma1
strikebullpatternEMALine2filter = StrikeBullpatternCheck == true and close > setEma2
strikebearpatternEMALine2filter = StrikeBearpatternCheck == true and close < setEma2
strikebullpatternEMALine3filter = StrikeBullpatternCheck == true and close > setEma3
strikebearpatternEMALine3filter = StrikeBearpatternCheck == true and close < setEma3

//Plot it on the chart
plotshape(showBullishStrikepatternEMALine1 ? strikebullpatternEMALine1filter : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Above EMA Line 1-Strike-Bullish", title="Chart-Pattern-Above EMA Line 1-Strike-Bullish")
plotshape(showBearishStrikepatternEMALine1 ? strikebearpatternEMALine1filter : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Below EMA Line 1-Strike-Bearish", title="Chart-Pattern-Below EMA Line 1-Strike-Bearish")
plotshape(showBullishStrikepatternEMALine2 ? strikebullpatternEMALine2filter : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Above EMA Line 1-2-Strike-Bullish", title="Chart-Pattern-Above EMA Line 2-Strike-Bullish")
plotshape(showBearishStrikepatternEMALine2 ? strikebearpatternEMALine2filter : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Below EMA Line 2-Strike-Bearish", title="Chart-Pattern-Below EMA Line 2-Strike-Bearish")
plotshape(showBullishStrikepatternEMALine3 ? strikebullpatternEMALine3filter : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Above EMA Line 3-Strike-Bullish", title="Chart-Pattern-Above EMA Line 3-Strike-Bullish")
plotshape(showBearishStrikepatternEMALine3 ? strikebearpatternEMALine3filter : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Below EMA Line 3-Strike-Bearish", title="Chart-Pattern-Below EMA Line 3-Strike-Bearish")

//Trigger Alert (only works if trigger set on tradingview.com site)
//For every strike pattern found
alertcondition(strikebullpatternEMALine1filter, title='Pattern-Above EMA Line 1-Strike-Bullish')
alertcondition(strikebearpatternEMALine1filter, title='Pattern-Below EMA Line 1-Strike-Bearish')
alertcondition(strikebullpatternEMALine2filter, title='Pattern-Above EMA Line 2-Strike-Bullish')
alertcondition(strikebearpatternEMALine2filter, title='Pattern-Below EMA Line 2-Strike-Bearish')
alertcondition(strikebullpatternEMALine3filter, title='Pattern-Above EMA Line 3-Strike-Bullish')
alertcondition(strikebearpatternEMALine3filter, title='Pattern-Below EMA Line 3-Strike-Bearish')

//SMA Module----------------------------------------------------------------------------------------
//Give end user the option if they want SMA line 1 enabled or not
showSmaLine1 = input.bool(false,"Show SMA Line 1", group="SMA")
sma1=input.int(defval=20, title="Chart-SMA-Line 1", group="SMA")
setSma1 = ta.sma(close, sma1)

//Give end user the option if they want SMA line 2 enabled or not
showSmaLine2 = input.bool(false,"Shows SMA Line 2", group="SMA")
sma2=input.int(defval=50, title="Chart-SMA-Line 2", group="SMA")
setSma2 = ta.sma(close, sma2)

//Give end user the option if they want SMA line 3 enabled or not
showSmaLine3 = input.bool(false,"Show SMA Line 3", group="SMA")
sma3=input.int(defval=100, title="Chart-SMA-Line 3", group="SMA")
setSma3 = ta.sma(close, sma3)

//Plot SMA lines Chart only if item is enabled in the settings area
plot(showSmaLine1 ? setSma1 : na, color=color.purple, linewidth=2, title="Chart-SMA-Line 1")
plot(showSmaLine2 ? setSma2 : na, color=color.orange, linewidth=2, title="Chart-SMA-Line 2")
plot(showSmaLine3 ? setSma3 : na, color=color.aqua, linewidth=2, title="Chart-SMA-Line 3")

//Plot Sma line crosses
//Give end user the option if they want table of details enabled or not
showSmaLineCrosses = input.bool(false,"Show SMA X's", group="SMA")

//Detect line cross
sma_crossing_up = ta.crossover(setSma1, setSma2) //purple above orange
sma_crossing_down = ta.crossunder(setSma1, setSma2) //purple under orange
sma_crossing_up2= ta.crossover(setSma2, setSma1) //orange above purple
sma_crossing_down2 = ta.crossunder(setSma2, setSma1) //orange under purple

//Plot it Chart if setting is enabled
plotshape(showSmaLineCrosses ? sma_crossing_up : na, style=shape.cross, location=location.abovebar, color=color.new(color.red, 0), text='Chart-SMA-Line 1 X Above Line 2', title='Chart-SMA-Line 1 X Above Line 2')
plotshape(showSmaLineCrosses ? sma_crossing_down : na, style=shape.cross, location=location.abovebar, color=color.new(color.red, 0), text='Chart-SMA-Line 1 X Under Line 2', title='Chart-SMA-Line 1 X Under Line 2')
plotshape(showSmaLineCrosses ? sma_crossing_up2 : na, style=shape.cross, location=location.belowbar, color=color.new(color.red, 0), text='Chart-SMA-Line 2 X Above Line 1', title='Chart-SMA-Line 2 X Above Line 1')
plotshape(showSmaLineCrosses ? sma_crossing_down2 : na, style=shape.cross, location=location.belowbar, color=color.new(color.red, 0), text='Chart-SMA-Line 2 X Under Line 1', title='Chart-SMA-Line 2 X Under Line 1')

//Trigger Alert (only works if trigger set on tradingview.com site)
//When SMA line crosses
alertcondition(showSmaLineCrosses ? sma_crossing_up: na, title='Chart-SMA-Line 1 X Above Line 2')
alertcondition(showSmaLineCrosses ? sma_crossing_down : na, title='Chart-SMA-Line 1 X Under Line 2')
alertcondition(showSmaLineCrosses ? sma_crossing_up2 : na, title='Chart-SMA-Line 2 X Above Line 1')
alertcondition(showSmaLineCrosses ? sma_crossing_down2 : na, title='Chart-SMA-Line 2 X Under Line 1')

//SMA Strike Module--------------------------------------------------------------------------------------------------------
//Show pattern were filter condition is true
showBullishStrikepatternSMALine1 = input.bool(false,"Show Bullish Strike Pattern Above The SMA Line 1", group="Pattern/SMA")
showBullishStrikepatternSMALine2 = input.bool(false,"Show Bullish Strike Pattern Above The SMA Line 2", group="Pattern/SMA")
showBullishStrikepatternSMALine3 = input.bool(false,"Show Bullish Strike Pattern Above The SMA Line 3", group="Pattern/SMA")

showBearishStrikepatternSMALine1 = input.bool(false,"Show Bearish Strike Pattern Below The SMA Line 1", group="Pattern/SMA")
showBearishStrikepatternSMALine2 = input.bool(false,"Show Bearish Strike Pattern Below The SMA Line 2", group="Pattern/SMA")
showBearishStrikepatternSMALine3 = input.bool(false,"Show Bearish Strike Pattern Below The SMA Line 3", group="Pattern/SMA")

//Filter found patterns to be only above or below the SMA Line
strikebullpatternSMALine1filter = StrikeBullpatternCheck == true and close > setSma1
strikebearpatternSMALine1filter = StrikeBearpatternCheck == true and close < setSma1
strikebullpatternSMALine2filter = StrikeBullpatternCheck == true and close > setSma2
strikebearpatternSMALine2filter = StrikeBearpatternCheck == true and close < setSma2
strikebullpatternSMALine3filter = StrikeBullpatternCheck == true and close > setSma3
strikebearpatternSMALine3filter = StrikeBearpatternCheck == true and close < setSma3

//Plot it on the chart
plotshape(showBullishStrikepatternSMALine1 ? strikebullpatternSMALine1filter : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Above SMA Line 1-Strike-Bullish", title="Chart-Pattern-Above SMA Line 1-Strike-Bullish")
plotshape(showBearishStrikepatternSMALine1 ? strikebearpatternSMALine1filter : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Below SMA Line 1-Strike-Bearish", title="Chart-Pattern-Below SMA Line 1-Strike-Bearish")
plotshape(showBullishStrikepatternSMALine2 ? strikebullpatternSMALine2filter : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Above SMA Line 1-2-Strike-Bullish", title="Chart-Pattern-Above SMA Line 2-Strike-Bullish")
plotshape(showBearishStrikepatternSMALine2 ? strikebearpatternSMALine2filter : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Below SMA Line 2-Strike-Bearish", title="Chart-Pattern-Below SMA Line 2-Strike-Bearish")
plotshape(showBullishStrikepatternSMALine3 ? strikebullpatternSMALine3filter : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Pattern-Above SMA Line 3-Strike-Bullish", title="Chart-Pattern-Above SMA Line 3-Strike-Bullish")
plotshape(showBearishStrikepatternSMALine3 ? strikebearpatternSMALine3filter : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Pattern-Below SMA Line 3-Strike-Bearish", title="Chart-Pattern-Below SMA Line 3-Strike-Bearish")

//Trigger Alert (only works if trigger set on tradingview.com site)
//For every strike pattern found
alertcondition(strikebullpatternSMALine1filter, title='Pattern-Above SMA Line 1-Strike-Bullish')
alertcondition(strikebearpatternSMALine1filter, title='Pattern-Below SMA Line 1-Strike-Bearish')
alertcondition(strikebullpatternSMALine2filter, title='Pattern-Above SMA Line 2-Strike-Bullish')
alertcondition(strikebearpatternSMALine2filter, title='Pattern-Below SMA Line 2-Strike-Bearish')
alertcondition(strikebullpatternSMALine3filter, title='Pattern-Above SMA Line 3-Strike-Bullish')
alertcondition(strikebearpatternSMALine3filter, title='Pattern-Below SMA Line 3-Strike-Bearish')

//Psar Module--------------------------------------------------------------------------------------
//Give end user the option if they want to show Psar
showPsar= input.bool(false,"Show Psar Bands",group="Psar")

//Get Psar values to use from the end user
Psarstart = input.float(title='Chart-Psar-Start', step=0.00005, defval=0.00252,group="Psar")
Psarincrement = input.float(title='Chart-Psar-Increment', step=0.00005, defval=0.00133,group="Psar")
Psarmaximum = input.float(title='Chart-Psar-Maximum', step=0.01, defval=0.220,group="Psar")

//Caclculate
psar = ta.sar(Psarstart, Psarincrement, Psarmaximum)
dir = psar < close ? 1 : -1

//Plot it Chart
//Boarder
plot(showPsar ? psar : na, style=plot.style_circles, color=color.blue, title="Chart-Psar-Boarder")

//Give end user the option if they want table of details enabled or not
showPsarLabels = input.bool(false,"Show Psar Bullish & Bearish labels on the Chart", group="Psar")

//Bullish & Bearish labels
plotshape(showPsarLabels and dir == 1 and dir[1] == -1 ? psar : na, style=shape.triangledown, location=location.abovebar, color=color.green, text="Psar-Bullish", title="Chart-Psar-Bullish")
plotshape(showPsarLabels and dir == -1 and dir[1] == 1 and showPsarLabels ? psar : na, style=shape.triangleup, location=location.belowbar, color=color.red, text="Psar-Bearish", title="Chart-Psar-Bearish")

//Trigger Alert (only works if trigger set on tradingview.com site)
alertcondition(showPsarLabels and dir == 1 and dir[1] == -1  ? psar : na, title='Chart-Psar-Bullish')
alertcondition(showPsarLabels and dir == -1 and dir[1] == -1  ? psar : na, title='Chart-Psar-Bearish')

//BB Module-----------------------------------------------------------------------------------------
//Give end user the option if they want to show BB
showBB= input.bool(false,"Show Bollinger Bands", group="BB")

//Get BB values to use from the end user
getBBlength=input.int(defval=20, title="Chart-BB-Length",group="BB")
getBBDeviation=input.float(2.0, title="Chart-BB-Deveation",group="BB")
getBBlOffset=input.int(defval=0, title="Chart-BB-Offset",group="BB")

basis = ta.sma(close, getBBlength)
dev = getBBDeviation * ta.stdev(close, getBBlength)
setBBUpperlinecolor = basis + dev
setBBLowerlinecolor = basis-dev

//Plots the various BB lines Chart and provides option to change its color in the 'Settings' area
setBBLineatTop = plot(showBB ? setBBUpperlinecolor : na, "Chart-BB-Upper Line", color=#2962FF, offset = getBBlOffset)
plot(showBB ? basis: na, "Chart-BB-Middle Line", color=#FF6D00, offset = getBBlOffset)
setBBLineatBottom = plot(showBB ? setBBLowerlinecolor: na, "Chart-BB-Lower Line", color=#2962FF, offset = getBBlOffset)

//Plot BB background color Chart and provides option to change its color in the 'Settings' area
fill(setBBLineatTop, setBBLineatBottom, title = "Chart-BB-Background", color=color.rgb(33, 150, 243, 95))

//Give end user the option if they want to show BB
showBBPokingOut= input.bool(false,"Show BB Poking out",group="BB")

//Calculate BB bars stickingout
down = close < setBBLowerlinecolor
up = close > setBBUpperlinecolor
BBUp = ta.barssince(up)
BBDown = ta.barssince(down)
BBBearish = BBUp < BBDown and not (BBUp < BBDown)[1]
BBBullish = BBDown < BBUp and not (BBDown < BBUp)[1]

//Plot BB bars with symbol when above or below the BB fill area
plotshape(showBBPokingOut ? BBBearish : na, color=color.new(#008000, 0), style=shape.triangledown, location=location.abovebar, title='Chart-BB-Poking out-Bullish', text='Chart-BB-Poking out-Bullish')
plotshape(showBBPokingOut ? BBBullish : na, color=color.new(#ff0100, 0), style=shape.triangleup, location=location.belowbar, title='Chart-BB-Poking out-Bearish', text='Chart-BB-Poking out-Bearish')

//Trigger Alert (only works if trigger set on tradingview.com site)
//When bars go outside the BB cloud
alertcondition(showBBPokingOut ? BBBullish: na, title='Chart-BB-Poking out-Bullish')
alertcondition(showBBPokingOut ? BBBearish: na, title='Chart-BB-Poking out-Bearish')

//Table Module--------------------------------------------------------------------------------------
//Give end user the option if they want table displayed enabled or not
showInfoTable = input.bool(false,"Show Info Table (Display/Build it the way you want)",group="Table Of Details")

//Global variables - table portrait 
var colum_Portrait = 0
var row_Portrait = 1
var colum2_Portrait = 1
var row2_Portrait = 1

//Global variables - table landscape 
var colum_Landscape = 0
var row_Landscape = 0
var colum2_Landscape = 0
var row2_Landscape = 1

//Preset variables 
noneNumber=0
noneText=""
heading="heading"
row="row"
color_order_change="color_order_change"
BUYNSELL="BUYNSELL"
MULTI="MULTI"

//Table Positions
bright = position.bottom_right
bleft = position.bottom_left
bcenter = position.bottom_center
tright = position.top_right
tleft = position.top_left
tcenter = position.top_center
mright = position.middle_right
mleft = position.middle_left
mcenter = position.middle_center
itablePosition = input.string(bleft, title="Table Position", options=[bright, bleft, bcenter, tright, tleft, tcenter, mright, mleft, mcenter],group="Table Of Details")

//Show table
createTableposition = table.new(itablePosition,99,99,border_width=4,border_color=color.gray, frame_color=color.gray, frame_width=4)
setCurrenciyPair = input.symbol("","Symbol",group="Table Of Details") //By default the script uses the current selected pair
setChartPeriod=input.timeframe(defval="",title="Time Period",group="Table Of Details") //By default the script uses the current all of the chart as the time period

//Table Layout
option1 = "Portrait"
option2 = "Landscape"
tableScale = input.string(option1, title="Table Layout", options=[option1, option2],group="Table Of Details")

createTable(heading_or_row, type, name, mainvalue, highvalue, lowvalue, endUserDisplayedValue, tip) =>
    if heading_or_row == "heading"
	    //This if statement applies to table rows: meregcellheading1, meregcellheading2
        if tableScale == "Portrait"
            table.cell(createTableposition, colum_Portrait, row_Portrait, bgcolor=color.black, text_color=color.white, text=name)
            table.cell(createTableposition, colum2_Portrait, row2_Portrait, bgcolor=color.black)
            table.merge_cells(createTableposition, colum_Portrait, row_Portrait, colum2_Portrait, row2_Portrait)
        if tableScale == "Landscape"
            table.cell(createTableposition, colum_Landscape, row_Landscape, bgcolor=color.black, text_color=color.white, text=name)
            table.cell(createTableposition, colum2_Landscape, row2_Landscape, bgcolor=color.black)
            table.merge_cells(createTableposition, colum_Landscape, row_Landscape, colum2_Landscape, row2_Landscape)
    if heading_or_row == "row"
    //This if statement applies to table rows: lastopenprice, lastcloseprice, change, volume
	    color_lower_risk = color.green
	    color_medium_risk = color.orange
	    color_high_risk = color.red
        if tableScale == "Portrait"
            table.cell(createTableposition, colum_Portrait, row_Portrait, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Portrait, row2_Portrait, bgcolor=mainvalue >= highvalue ? color_lower_risk : mainvalue <= lowvalue ?  color_lower_risk : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
        if tableScale == "Landscape"
            table.cell(createTableposition, colum_Landscape, row_Landscape, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Landscape, row2_Landscape, bgcolor=mainvalue >= highvalue ? color_lower_risk : mainvalue <= lowvalue ?  color_lower_risk : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
    if type == "color_order_change"
		//This if statement applies to table rows: atr, cci, cmo
        color_lower_risk = color.red
		color_medium_risk = color.orange
		color_high_risk = color.green
        if tableScale == "Portrait"
            table.cell(createTableposition, colum_Portrait, row_Portrait, bgcolor=color.black, text_color=color.white, text=name), tooltip=tip
            table.cell(createTableposition, colum2_Portrait, row2_Portrait, bgcolor=mainvalue >= highvalue ? color_lower_risk : mainvalue <= lowvalue ?  color_lower_risk : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
        if tableScale == "Landscape"
            table.cell(createTableposition, colum_Landscape, row_Landscape, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Landscape, row2_Landscape, bgcolor=mainvalue >= highvalue ? color_lower_risk : mainvalue <= lowvalue ?  color_lower_risk : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
    if type == "BUYNSELL"
		//This if statement applies to table rows: rsi, stochline1,stochline2, wpr, dem
        color_sell = color.red
		color_medium_risk = color.orange
		color_buy = color.green
        if tableScale == "Portrait"
            table.cell(createTableposition, colum_Portrait, row_Portrait, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Portrait, row2_Portrait, bgcolor=mainvalue >= highvalue ? color_sell : mainvalue <= lowvalue ?  color_buy : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
        if tableScale == "Landscape"
            table.cell(createTableposition, colum_Landscape, row_Landscape, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Landscape, row2_Landscape, bgcolor=mainvalue >= highvalue ? color_sell : mainvalue <= lowvalue ?  color_buy : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
    if type == "MULTI"
		//This if statement applies to table rows: ao, macdline1, macdline2, macdhist, aroon, adx, roc, dmiplus, dminegative, vortexplus, vortexnegative
        color_below_line = color.red
		color_medium_risk = color.orange
		color_above_line = color.green
        if tableScale == "Portrait"
            table.cell(createTableposition, colum_Portrait, row_Portrait, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Portrait, row2_Portrait, bgcolor=mainvalue >= highvalue ? color_above_line : mainvalue <= lowvalue ?  color_below_line : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)
        if tableScale == "Landscape"
            table.cell(createTableposition, colum_Landscape, row_Landscape, bgcolor=color.black, text_color=color.white, text=name, tooltip=tip)
            table.cell(createTableposition, colum2_Landscape, row2_Landscape, bgcolor=mainvalue >= highvalue ? color_above_line : mainvalue <= lowvalue ?  color_below_line : color_medium_risk, text_color=color.white, text=endUserDisplayedValue)


//tradingview.com indicator formula for MACD
fast_ma = ta.sma(close, 12)
slow_ma = ta.sma(close, 26)
macd = fast_ma - slow_ma
signal = ta.sma(macd, 9)

//tradingview.com indicator formula for ADX
dirmov(len) =>
	up = ta.change(high)
	down = -ta.change(low)
	plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
	minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
	truerange = ta.rma(ta.tr, len)
	plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
	minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
	[plus, minus]

//tradingview.com indicator formula for ADX
adx(dilen, adxlen) =>
	[plus, minus] = dirmov(dilen)
	sum = plus + minus
	adx = 100 * ta.rma(math.abs(plus-minus) / (sum == 0 ? 1 : sum), adxlen)

//tradingview.com indicator formula for DeM
per=14
demax = high > high[1] ? high - high[1] : 0
demin = low < low[1] ? low[1] - low : 0
demax_av = ta.sma(demax, per)
demin_av = ta.sma(demin, per)

//tradingview.com indicator formula for CMO
momm = ta.change(close)
f1(m) => m >= 0.0 ? m : 0.0
f2(m) => m >= 0.0 ? 0.0 : -m
m1 = f1(momm)
m2 = f2(momm)
sm1 = math.sum(m1, 9)
sm2 = math.sum(m2, 9)
percent(nom, div) => 100 * nom / div

//tradingview.com indicator formula for DMI
lensig = 14
len = 14
updmi = ta.change(high)
downdmi = -ta.change(low)
plusDM = na(updmi) ? na : (updmi > downdmi and updmi > 0 ? updmi : 0)
minusDM = na(downdmi) ? na : (downdmi > updmi and downdmi > 0 ? downdmi : 0)
trur = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / trur)
minus = fixnan(100 * ta.rma(minusDM, len) / trur)
//sum = plus + minus
//average directional index
//adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)

////tradingview.com indicator formula for DVI
VMP = math.sum( math.abs( high - low[1]), 14 )
VMM = math.sum( math.abs( low - high[1]), 14)
STR = math.sum( ta.atr(1), 14)
VIP = VMP / STR
VIM = VMM / STR

//Shorten decimal points
truncate(number, decimals) =>
    factor = math.pow(10, decimals)
    int(number * factor) / factor

//Get end users input on wanted
Add_Row_Name_meregcellheading1 = input.bool(false,"---Add Below Associated Table Heading",group="Edit Table Heading/Market")
meregcellheading1=input(defval="Market", title="Table Heading", group="Edit Table Heading/Market")

//Get end users input on wanted
Add_Row_Name_lastopenprice = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Market")
Cell_Name_lastopenprice = input(defval="Candle Open", title="Table Heading", group="Edit Table Heading/Market")

//Get end users input on wanted
Add_Row_Name_lastcloseprice = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Market")
Cell_Name_lastcloseprice = input(defval="Last Closed", title="Table Heading", group="Edit Table Heading/Market")

//Get end users input on wanted
Add_Row_Name_change = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Market")
Cell_Name_change = input(defval="% Changed", title="Table Heading", group="Edit Table Heading/Market")

//Get end users input on wanted
Add_Row_Name_volume = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Market")
Cell_Name_volume = input(defval="Volume", title="Table Heading", group="Edit Table Heading/Market")

//Get end users input on wanted
Add_Row_Name_meregcellheading2 = input.bool(false,"---Add Below Associated Table Heading",group="Edit Table Heading")
meregcellheading2=input(defval="Oscillators", title="Table Heading", group="Edit Table Heading")

//Get end users input on wanted RSI
Add_Row_Name_rsi = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_rsi=input(defval="RSI", title="Table Heading", group="Edit Table Heading/Stat Threshold")
RSIOverbought = input.int(defval=70, title="RSI OverBought",group="Edit Table Heading/Stat Threshold")
RSIOversold = input.int(defval=30, title="RSI OverSold",group="Edit Table Heading/Stat Threshold")
tooltiprsi = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on wanted ATR
Add_Row_Name_atr = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_atr=input(defval="ATR", title="Table Heading", group="Edit Table Heading/Stat Threshold")
ATRHigh = input.int(defval=40, title="ATR High level of volatility",group="Edit Table Heading/Stat Threshold")
ATRLow = input.int(defval=28, title="ATR Low level of volatility",group="Edit Table Heading/Stat Threshold")
tooltipatr = "Green=High Movement/Orange=Neutral/Red=Low Movement"

//Get end users input on wanted Stochastic line 1 levels
Add_Row_Name_stochline1 = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_stochline1=input(defval="Stoch (Line 1)", title="Table Heading", group="Edit Table Heading/Stat Threshold")
StochOverbought = input.int(defval=80, title="Stoch OverBought",group="Edit Table Heading/Stat Threshold")
StochOversold = input.int(defval=30, title="Stoch OverSold",group="Edit Table Heading/Stat Threshold")
tooltipstochline1 = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on wanted Stochastic line 2 levels
Add_Row_Name_stochline2 = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_stochline2=input(defval="Stoch (Line 2)", title="Table Heading", group="Edit Table Heading/Stat Threshold")
StochHigh = input.int(defval=50, title="Stoch OverBought",group="Edit Table Heading/Stat Threshold")
StochLow = input.int(defval=49, title="Stoch OverSold",group="Edit Table Heading/Stat Threshold")
tooltipstochline2 = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on what config for William percent range 
Add_Row_Name_wpr = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_wpr=input(defval="W%R", title="Table Heading", group="Edit Table Heading/Stat Threshold")
WpercentRMax = input.int(defval=-20, title="WPR OverSold",group="Edit Table Heading/Stat Threshold")
WpercentRMin = input.int(defval=-80, title="WPR OverBought",group="Edit Table Heading/Stat Threshold")
tooltiwpr = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on wanted CCI levels
Add_Row_Name_cci = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_cci=input(defval="CCI", title="Table Heading", group="Edit Table Heading/Stat Threshold")
CCIOverbought = input.int(defval=100, title="CCI OverBought",group="Edit Table Heading/Stat Threshold")
CCIOversold = input.int(defval=-100, title="CCI OverSold",group="Edit Table Heading/Stat Threshold")
tooltipcci = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on wanted AO levels
Add_Row_Name_ao = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_ao=input(defval="AO", title="Table Heading", group="Edit Table Heading/Stat Threshold")
AOAbove0 = input.int(defval=0, title="AO Above",group="Edit Table Heading/Stat Threshold")
AObelow0 = input.int(defval=-0, title="AO Below",group="Edit Table Heading/Stat Threshold")
tooltipao = "Green=High Movement/Orange=Neutral/Red=Low Movement"

//Get end users input on wanted MACD Line 1 levels
Add_Row_Name_macdline1 = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_macdline1=input(defval="MACD (Line 1)", title="Table Heading", group="Edit Table Heading/Stat Threshold")
MACDLine1Above0 = input.int(defval=0, title="MACD Line 1 Above",group="Edit Table Heading/Stat Threshold")
MACDLine1below0 = input.int(defval=-0, title="MACD Line 1 Below",group="Edit Table Heading/Stat Threshold")
tooltipmacdline1 = "Green=Buying Strength/Red=Selling Strength"

//Get end users input on wanted MACD Line 2 levels
Add_Row_Name_macdline2 = input.bool(false,"Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_macdline2=input(defval="MACD (Line 2)", title="Table Heading", group="Edit Table Heading/Stat Threshold")
MACDLine2Above0 = input.int(defval=0, title="MACD Line 2 Above",group="Edit Table Heading/Stat Threshold")
MACDLine2below0 = input.int(defval=-0, title="MACD Line 2 Below",group="Edit Table Heading/Stat Threshold")
tooltipmacdline2 = "Green=Buying Strength/Red=Selling Strength"

//Get end users input on wanted MACD Histogram levels
Add_Row_Name_macdhist = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_macdhist=input(defval="MACD (Hist)", title="Table Heading", group="Edit Table Heading/Stat Threshold")
MACDLineHistAbove0 = input.int(defval=0, title="MACD Line 2 Above",group="Edit Table Heading/Stat Threshold")
MACDLineHistbelow0 = input.int(defval=-0, title="MACD Line 2 Below",group="Edit Table Heading/Stat Threshold")
tooltipmacdhist = "Green=Buying Strength/Red=Selling Strength"

//Get end users input on wanted Aroon levels
Add_Row_Name_aroon = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_aroon=input(defval="Aroon", title="Table Heading", group="Edit Table Heading/Stat Threshold")
AroonHigh = input.int(defval=50, title="Aroon Above",group="Edit Table Heading/Stat Threshold")
AroonLow = input.int(defval=-50, title="Aroon Below",group="Edit Table Heading/Stat Threshold")
tooltiparoon = "Green=High Movement/Orange=Neutral/Red=Low Movement"

//Get end users input on wanted ADX levels
Add_Row_Name_adx = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_adx=input(defval="ADX", title="Table Heading", group="Edit Table Heading/Stat Threshold")
ADXHigh = input.int(defval=25, title="ADX Above",group="Edit Table Heading/Stat Threshold")
ADXLow = input.int(defval=-20, title="ADX Below",group="Edit Table Heading/Stat Threshold")
tooltipadx = "Green=High Movement/Orange=Neutral/Red=Low Movement"

//Get end users input on wanted DeMarker levels
Add_Row_Name_DeM = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_DeM = input(defval="DeM", title="Table Heading", group="Edit Table Heading/Stat Threshold")
DeMOverbought = input.float(defval=0.7, title="DeM Overbought",group="Edit Table Heading/Stat Threshold")
DeMOversold = input.float(defval=0.3, title="DeM Oversold",group="Edit Table Heading/Stat Threshold")
tooltipdem = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on wanted CMO levels
Add_Row_Name_cmo = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_cmo = input(defval="Chande", title="Table Heading", group="Edit Table Heading/Stat Threshold")
cmoOverbought = input.int(defval=50, title="CMO Overbought",group="Edit Table Heading/Stat Threshold")
cmoOversold = input.int(defval=-50, title="CMO Oversold",group="Edit Table Heading/Stat Threshold")
tooltipcmo = "Green=Good time to Buy/Orange=Neutral/RED=Good time to Sell"

//Get end users input on wanted ROC levels
Add_Row_Name_roc = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_roc = input(defval="ROC", title="Table Heading", group="Edit Table Heading/Stat Threshold")
rocOverbought = input.int(defval=0, title="ROC Overbought",group="Edit Table Heading/Stat Threshold")
rocOversold = input.int(defval=-0, title="ROC Oversold",group="Edit Table Heading/Stat Threshold")
tooltiproc = "Green=Good Momentum/Orange=Netural/Red=Low Momentem"

//Get end users input on wanted DMI Plus levels
Add_Row_Name_dmiplus = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_dmiplus = input(defval="DMI+", title="Table Heading", group="Edit Table Heading/Stat Threshold")
tooltipdmiplus = "Green=Good Momentum/Orange=Netural/Red=Low Momentem"

//Get end users input on wanted DMI Negative levels
Add_Row_Name_dminegative = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_dminegative = input(defval="DMI-", title="Table Heading", group="Edit Table Heading/Stat Threshold")
tooltipdminegative = "Red=High Sell Momentum/Orange=Netural/Green=Low Sell Momentum"

//Get end users input on wanted DMI Plus levels
Add_Row_Name_vortexplus = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_vortexplus= input(defval="VI+", title="Table Heading", group="Edit Table Heading/Stat Threshold")
tooltipvortexplus = "Green=Good Momentum/Orange=Netural/Red=Low Momentem"

//Get end users input on wanted DMI Negative levels
Add_Row_Name_vortexnegative = input.bool(false,"---Add Below Associated Table Line",group="Edit Table Heading/Stat Threshold")
Cell_Name_vortexnegative = input(defval="VI-", title="Table Heading", group="Edit Table Heading/Stat Threshold")
tooltipvortexnegative = "Red=High Sell Momentum/Orange=Netural/Green=Low Sell Momentum"

//Get chart data
getchartRealTimeLastOpenprice = request.security(setCurrenciyPair,setChartPeriod,open)
getchartRealTimeLastCloseprice = request.security(setCurrenciyPair,setChartPeriod,close)
getchartRealTimePriceChange = request.security(setCurrenciyPair,setChartPeriod,(ta.change(close)/close[1])*100)
getchartRealTimeVolume = request.security(setCurrenciyPair,setChartPeriod,volume)
getchartRealTimeRSIValue = request.security(setCurrenciyPair,setChartPeriod,truncate(ta.rsi(close,14),2))
getchartRealTimeATRValue = request.security(setCurrenciyPair,setChartPeriod,truncate(ta.atr(14),2))
getchartRealTimeStochValueLine1 = request.security(setCurrenciyPair,setChartPeriod, truncate(ta.stoch(close, high, low, 14),2))
getchartRealTimeStochValueLine2 = truncate(ta.sma(getchartRealTimeStochValueLine1, 3),2)
getchartRealTimeWPRValue = request.security(setCurrenciyPair,setChartPeriod,truncate(ta.wpr(14),2))
getchartRealTimeCCIValue = request.security(setCurrenciyPair,setChartPeriod, truncate(ta.sma(hlc3,20),2))
getchartRealTimeAOValue = request.security(setCurrenciyPair,setChartPeriod, truncate(ta.sma(hl2,5)-ta.sma(hl2,34),2))
getchartRealTimeMACDLine1Value = request.security(setCurrenciyPair,setChartPeriod, truncate(ta.ema(close, 12)-ta.ema(close, 26),2))
getchartRealTimeMACDLine2Value = request.security(setCurrenciyPair,setChartPeriod, truncate(ta.ema(close, 12)-ta.ema(close, 26),2))
getchartRealTimeMACDLine2ValueCalculate = ta.ema(getchartRealTimeMACDLine2Value,9)
getchartRealTimeMACDHistValueCalculate = macd - signal
getchartRealTimeAroonValue = truncate((100 * (ta.highestbars(high, 25+1) + 25)/25)-(100 * (ta.lowestbars(low, 25+1) + 25)/25),2)
getchartRealTimeADXValue = truncate(adx(14, 14),2)
getchartRealTimeDeMValue = truncate(demax_av / (demax_av + demin_av),2)
getchartRealTimeCMOValue = truncate(percent(sm1-sm2, sm1+sm2),2)
getchartRealTimeROCValue = truncate(100 * (close - close[9])/close[9],2)
getchartRealTimeDMIPlusValue = truncate(fixnan(100 * ta.rma(plusDM, len) / trur),2)
getchartRealTimeDMINegativeValue = truncate(fixnan(100 * ta.rma(minusDM, len) / trur),2)
getchartRealTimeVIPlusValue = truncate(VIP,2)
getchartRealTimeVINegativeValue = truncate(VIM,2)

//Convert chart data to string
tostringRealTimeLastOpenprice = str.tostring(getchartRealTimeLastOpenprice)
tostringRealTimeLastCloseprice = str.tostring(getchartRealTimeLastCloseprice)
tostringRealTimePriceChange = str.tostring(getchartRealTimePriceChange) +" %"
tostringRealTimeVolume=str.tostring(getchartRealTimeVolume)
tostringRealTimeRSIValue = str.tostring(math.round_to_mintick(getchartRealTimeRSIValue))
tostringRealTimeATRValue=str.tostring(math.round_to_mintick(getchartRealTimeATRValue))
tostringRealTimeStochValueLine1 = str.tostring(math.round_to_mintick(getchartRealTimeStochValueLine1))
tostringRealTimeStochValueLine2 = str.tostring(math.round_to_mintick(getchartRealTimeStochValueLine2))
tostringRealTimeWPRValue=str.tostring(math.round_to_mintick(getchartRealTimeWPRValue))
tostringRealTimeCCIValue = str.tostring(math.round_to_mintick((hlc3-getchartRealTimeCCIValue) / (0.015 * ta.dev(hlc3,20))))
tostringRealTimeAOValue = str.tostring(math.round_to_mintick(getchartRealTimeAOValue))
tostringtRealTimeMACDLine1Value = str.tostring(math.round_to_mintick(getchartRealTimeMACDLine1Value))
tostringtRealTimeMACDLine2Value = str.tostring(math.round_to_mintick(getchartRealTimeMACDLine2ValueCalculate))
tostringRealTimeMACDHistValue = str.tostring(math.round_to_mintick(getchartRealTimeMACDHistValueCalculate))
tostringtRealTimeAroonValue = str.tostring(math.round_to_mintick(getchartRealTimeAroonValue))
tostringtRealTimeADXValue = str.tostring(math.round_to_mintick(getchartRealTimeADXValue))
tostringtRealTimeDeMValue = str.tostring((getchartRealTimeDeMValue))
tostringtRealTimeCMOValue = str.tostring(math.round_to_mintick(getchartRealTimeCMOValue))
tostringtRealTimeROCValue = str.tostring(math.round_to_mintick(getchartRealTimeROCValue))
tostringtRealTimeDMIPlusValue = str.tostring(math.round_to_mintick(getchartRealTimeDMIPlusValue))
tostringtRealTimeDMINegativeValue = str.tostring(math.round_to_mintick(getchartRealTimeDMINegativeValue))
tostringtRealTimeVIPlusValue = str.tostring(math.round_to_mintick(getchartRealTimeVIPlusValue))
tostringtRealTimeVINegativeValue = str.tostring(math.round_to_mintick(getchartRealTimeVINegativeValue))

//Reset in use global variables (else script crashes) - table portrait 
colum_Portrait := 0
row_Portrait := 1
colum2_Portrait := 1
row2_Portrait := 1

//Reset in use global variables (else script crashes) - table landscape 
colum_Landscape := 0
row_Landscape := 0
colum2_Landscape := 0
row2_Landscape := 1

//Script process's only if setting is enabled
if barstate.islast and showInfoTable==true
    if tableScale == option1
        //Display Table-Portrait
        if Add_Row_Name_meregcellheading1 == true
            createTable(heading,noneText,meregcellheading1,noneNumber,noneNumber,noneNumber,noneText,noneText)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_lastopenprice == true
            createTable(row,noneText, Cell_Name_lastopenprice, noneNumber, noneNumber, noneNumber, tostringRealTimeLastOpenprice, noneText)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_lastcloseprice == true
            createTable(row,noneText, Cell_Name_lastcloseprice, noneNumber, noneNumber, noneNumber, tostringRealTimeLastCloseprice, noneText)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_change == true
            createTable(row,noneText, Cell_Name_change, getchartRealTimePriceChange, noneNumber, noneNumber, tostringRealTimePriceChange, noneText)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_volume == true
            createTable(row,noneText, Cell_Name_volume, noneNumber, noneNumber, noneNumber, tostringRealTimeVolume, noneText)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_meregcellheading2 == true
            createTable(heading,noneText,meregcellheading2, noneNumber, noneNumber, noneNumber, noneText, noneText)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_rsi == true
            createTable(row,BUYNSELL, Cell_Name_rsi, getchartRealTimeRSIValue, RSIOverbought, RSIOversold, tostringRealTimeRSIValue, tooltiprsi)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_atr == true
            createTable(row,color_order_change, Cell_Name_atr, getchartRealTimeATRValue, ATRHigh, ATRLow, tostringRealTimeATRValue, tooltipatr)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_stochline1 == true
            createTable(row,BUYNSELL, Cell_Name_stochline1, getchartRealTimeStochValueLine1, StochOverbought, StochOversold, tostringRealTimeStochValueLine1, tooltipstochline1)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_stochline2 == true
            createTable(row,BUYNSELL, Cell_Name_stochline2, getchartRealTimeStochValueLine2, StochHigh, StochLow, tostringRealTimeStochValueLine2, tooltipstochline2)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_wpr == true
            createTable(row,BUYNSELL, Cell_Name_wpr, getchartRealTimeWPRValue, WpercentRMax, WpercentRMin, tostringRealTimeWPRValue, tooltiwpr)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_cci == true
            createTable(row,color_order_change, Cell_Name_cci, getchartRealTimeCCIValue, CCIOverbought, CCIOversold, tostringRealTimeCCIValue, tooltipcci)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_ao == true
            createTable(row,MULTI, Cell_Name_ao, getchartRealTimeAOValue, AOAbove0, AObelow0, tostringRealTimeAOValue, tooltipao)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_macdline1 == true
            createTable(row,MULTI, Cell_Name_macdline1, getchartRealTimeMACDLine1Value, MACDLine1Above0, MACDLine1below0, tostringtRealTimeMACDLine1Value, tooltipmacdline1)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_macdline2 == true
            createTable(row,MULTI, Cell_Name_macdline2, getchartRealTimeMACDLine2ValueCalculate, MACDLine2Above0, MACDLine2below0, tostringtRealTimeMACDLine2Value, tooltipmacdline2)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_macdhist == true
            createTable(row,MULTI, Cell_Name_macdhist, getchartRealTimeMACDHistValueCalculate, MACDLineHistAbove0, MACDLineHistbelow0, tostringRealTimeMACDHistValue, tooltipmacdhist)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_aroon == true
            createTable(row,MULTI, Cell_Name_aroon, getchartRealTimeAroonValue, AroonHigh, AroonLow, tostringtRealTimeAroonValue, tooltiparoon)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_adx == true
            createTable(row,MULTI, Cell_Name_adx, getchartRealTimeADXValue, ADXHigh, ADXLow, tostringtRealTimeADXValue, tooltipadx)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_DeM == true
            createTable(row,BUYNSELL, Cell_Name_DeM, getchartRealTimeDeMValue, DeMOverbought, DeMOversold, tostringtRealTimeDeMValue, tooltipdem)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_cmo == true
            createTable(row,BUYNSELL, Cell_Name_cmo, getchartRealTimeCMOValue, cmoOverbought, cmoOversold, tostringtRealTimeCMOValue, tooltipcmo)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_roc == true
            createTable(row,MULTI, Cell_Name_roc, getchartRealTimeROCValue, rocOverbought, rocOversold, tostringtRealTimeROCValue, tooltiproc)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_dmiplus == true
            createTable(row,MULTI, Cell_Name_dmiplus, getchartRealTimeDMIPlusValue, getchartRealTimeDMINegativeValue, getchartRealTimeDMINegativeValue, tostringtRealTimeDMIPlusValue, tooltipdmiplus)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_dminegative == true
            createTable(row,MULTI, Cell_Name_dminegative, getchartRealTimeDMINegativeValue, getchartRealTimeDMIPlusValue, getchartRealTimeDMIPlusValue, tostringtRealTimeDMINegativeValue, tooltipdminegative)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_vortexplus == true
            createTable(row,MULTI, Cell_Name_vortexplus, getchartRealTimeVIPlusValue, getchartRealTimeVINegativeValue, getchartRealTimeVINegativeValue, tostringtRealTimeVIPlusValue, tooltipvortexplus)
            row_Portrait += 1
            row2_Portrait += 1
        if Add_Row_Name_vortexnegative == true
            createTable(row,MULTI, Cell_Name_vortexnegative, getchartRealTimeVINegativeValue, getchartRealTimeVIPlusValue, getchartRealTimeVIPlusValue, tostringtRealTimeVINegativeValue, tooltipvortexnegative)
            row_Portrait += 1
            row2_Portrait += 1

    if tableScale == option2
        //Display Table-Landscape
        if Add_Row_Name_meregcellheading1 == true
            createTable(heading,noneText,meregcellheading1,noneNumber,noneNumber,noneNumber,noneText,noneText)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_lastopenprice == true
            createTable(row,noneText, Cell_Name_lastopenprice, noneNumber, noneNumber, noneNumber, tostringRealTimeLastOpenprice, noneText)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_lastcloseprice == true
            createTable(row,noneText, Cell_Name_lastcloseprice, noneNumber, noneNumber, noneNumber, tostringRealTimeLastCloseprice, noneText)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_change == true
            createTable(row,noneText, Cell_Name_change, getchartRealTimePriceChange, noneNumber, noneNumber, tostringRealTimePriceChange, noneText)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_volume == true
            createTable(row,noneText, Cell_Name_volume, noneNumber, noneNumber, noneNumber, tostringRealTimeVolume, noneText)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_meregcellheading2 == true
            createTable(heading,noneText,meregcellheading2, noneNumber, noneNumber, noneNumber, noneText, noneText)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_rsi == true
            createTable(row,BUYNSELL, Cell_Name_rsi, getchartRealTimeRSIValue, RSIOverbought, RSIOversold, tostringRealTimeRSIValue, tooltiprsi)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_atr == true
            createTable(row,color_order_change, Cell_Name_atr, getchartRealTimeATRValue, ATRHigh, ATRLow, tostringRealTimeATRValue, tooltipatr)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_stochline1 == true
            createTable(row,BUYNSELL, Cell_Name_stochline1, getchartRealTimeStochValueLine1, StochOverbought, StochOversold, tostringRealTimeStochValueLine1, tooltipstochline1)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_stochline2 == true
            createTable(row,BUYNSELL, Cell_Name_stochline2, getchartRealTimeStochValueLine2, StochHigh, StochLow, tostringRealTimeStochValueLine2, tooltipstochline2)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_wpr == true
            createTable(row,BUYNSELL, Cell_Name_wpr, getchartRealTimeWPRValue, WpercentRMax, WpercentRMin, tostringRealTimeWPRValue, tooltiwpr)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_cci == true
            createTable(row,color_order_change, Cell_Name_cci, getchartRealTimeCCIValue, CCIOverbought, CCIOversold, tostringRealTimeCCIValue, tooltipcci)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_ao == true
            createTable(row,MULTI, Cell_Name_ao, getchartRealTimeAOValue, AOAbove0, AObelow0, tostringRealTimeAOValue, tooltipao)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_macdline1 == true
            createTable(row,MULTI, Cell_Name_macdline1, getchartRealTimeMACDLine1Value, MACDLine1Above0, MACDLine1below0, tostringtRealTimeMACDLine1Value, tooltipmacdline1)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_macdline2 == true
            createTable(row,MULTI, Cell_Name_macdline2, getchartRealTimeMACDLine2ValueCalculate, MACDLine2Above0, MACDLine2below0, tostringtRealTimeMACDLine2Value, tooltipmacdline2)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_macdhist == true
            createTable(row,MULTI, Cell_Name_macdhist, getchartRealTimeMACDHistValueCalculate, MACDLineHistAbove0, MACDLineHistbelow0, tostringRealTimeMACDHistValue, tooltipmacdhist)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_aroon == true
            createTable(row,MULTI, Cell_Name_aroon, getchartRealTimeAroonValue, AroonHigh, AroonLow, tostringtRealTimeAroonValue, tooltiparoon)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_adx == true
            createTable(row,MULTI, Cell_Name_adx, getchartRealTimeADXValue, ADXHigh, ADXLow, tostringtRealTimeADXValue, tooltipadx)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_DeM == true
            createTable(row,BUYNSELL, Cell_Name_DeM, getchartRealTimeDeMValue, DeMOverbought, DeMOversold, tostringtRealTimeDeMValue, tooltipdem)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_cmo == true
            createTable(row,BUYNSELL, Cell_Name_cmo, getchartRealTimeCMOValue, cmoOverbought, cmoOversold, tostringtRealTimeCMOValue, tooltipcmo)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_roc == true
            createTable(row,MULTI, Cell_Name_roc, getchartRealTimeROCValue, rocOverbought, rocOversold, tostringtRealTimeROCValue, tooltiproc)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_dmiplus == true
            createTable(row,MULTI, Cell_Name_dmiplus, getchartRealTimeDMIPlusValue, getchartRealTimeDMINegativeValue, getchartRealTimeDMINegativeValue, tostringtRealTimeDMIPlusValue, tooltipdmiplus)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_dminegative == true
            createTable(row,MULTI, Cell_Name_dminegative, getchartRealTimeDMINegativeValue, getchartRealTimeDMIPlusValue, getchartRealTimeDMIPlusValue, tostringtRealTimeDMINegativeValue, tooltipdminegative)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_vortexplus == true
            createTable(row,MULTI, Cell_Name_vortexplus, getchartRealTimeVIPlusValue, getchartRealTimeVINegativeValue, getchartRealTimeVINegativeValue, tostringtRealTimeVIPlusValue, tooltipvortexplus)
            colum_Landscape += 1
            colum2_Landscape += 1
        if Add_Row_Name_vortexnegative == true
            createTable(row,MULTI, Cell_Name_vortexnegative, getchartRealTimeVINegativeValue, getchartRealTimeVIPlusValue, getchartRealTimeVIPlusValue, tostringtRealTimeVINegativeValue, tooltipvortexnegative)
            colum_Landscape += 1
            colum2_Landscape += 1