xmd79

DIY Custom Strategy Builder [ZP] - v1

Sep 20th, 2023
282
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 175.16 KB | None | 0 0
  1. //@ZPayab
  2.  
  3. //@version=5
  4.  
  5. indicator(title='DIY Custom Strategy Builder [ZP] - v1', overlay=true)
  6.  
  7. ma(_source, _length, _type) =>
  8. switch _type
  9. "SMA" => ta.sma (_source, _length)
  10. "EMA" => ta.ema (_source, _length)
  11. "RMA" => ta.rma (_source, _length)
  12. "WMA" => ta.wma (_source, _length)
  13. "VWMA" => ta.vwma(_source, _length)
  14.  
  15.  
  16. alarm(_osc, _message) =>
  17. alert(syminfo.ticker + ' ' + _osc + ' : ' + _message + ', price (' + str.tostring(close, format.mintick) + ')')
  18.  
  19.  
  20. //Conditional Sampling EMA Function
  21. Cond_EMA(x, cond, n) =>
  22. var val = array.new_float(0)
  23. var ema_val = array.new_float(1)
  24. if cond
  25. array.push(val, x)
  26. if array.size(val) > 1
  27. array.remove(val, 0)
  28. if na(array.get(ema_val, 0))
  29. array.fill(ema_val, array.get(val, 0))
  30. array.set(ema_val, 0, (array.get(val, 0) - array.get(ema_val, 0)) * (2 / (n + 1)) + array.get(ema_val, 0))
  31. EMA = array.get(ema_val, 0)
  32. EMA
  33.  
  34. //Conditional Sampling SMA Function
  35. Cond_SMA(x, cond, n) =>
  36. var vals = array.new_float(0)
  37. if cond
  38. array.push(vals, x)
  39. if array.size(vals) > n
  40. array.remove(vals, 0)
  41. SMA = array.avg(vals)
  42. SMA
  43.  
  44. //Standard Deviation Function
  45. Stdev(x, n) =>
  46. math.sqrt(Cond_SMA(math.pow(x, 2), 1, n) - math.pow(Cond_SMA(x, 1, n), 2))
  47.  
  48. //Range Size Function
  49. rng_size(x, scale, qty, n) =>
  50. ATR = Cond_EMA(ta.tr(true), 1, n)
  51. AC = Cond_EMA(math.abs(x - x[1]), 1, n)
  52. SD = Stdev(x, n)
  53. rng_size = scale == 'Pips' ? qty * 0.0001 : scale == 'Points' ? qty * syminfo.pointvalue : scale == '% of Price' ? close * qty / 100 : scale == 'ATR' ? qty * ATR : scale == 'Average Change' ? qty * AC : scale == 'Standard Deviation' ? qty * SD : scale == 'Ticks' ? qty * syminfo.mintick : qty
  54. rng_size
  55.  
  56. //Two Type Range Filter Function
  57. rng_filt(h, l, rng_, n, type, smooth, sn, av_rf, av_n) =>
  58. rng_smooth = Cond_EMA(rng_, 1, sn)
  59. r = smooth ? rng_smooth : rng_
  60. var rfilt = array.new_float(2, (h + l) / 2)
  61. array.set(rfilt, 1, array.get(rfilt, 0))
  62. if type == 'Type 1'
  63. if h - r > array.get(rfilt, 1)
  64. array.set(rfilt, 0, h - r)
  65. if l + r < array.get(rfilt, 1)
  66. array.set(rfilt, 0, l + r)
  67. if type == 'Type 2'
  68. if h >= array.get(rfilt, 1) + r
  69. array.set(rfilt, 0, array.get(rfilt, 1) + math.floor(math.abs(h - array.get(rfilt, 1)) / r) * r)
  70. if l <= array.get(rfilt, 1) - r
  71. array.set(rfilt, 0, array.get(rfilt, 1) - math.floor(math.abs(l - array.get(rfilt, 1)) / r) * r)
  72. rng_filt1 = array.get(rfilt, 0)
  73. hi_band1 = rng_filt1 + r
  74. lo_band1 = rng_filt1 - r
  75. rng_filt2 = Cond_EMA(rng_filt1, rng_filt1 != rng_filt1[1], av_n)
  76. hi_band2 = Cond_EMA(hi_band1, rng_filt1 != rng_filt1[1], av_n)
  77. lo_band2 = Cond_EMA(lo_band1, rng_filt1 != rng_filt1[1], av_n)
  78. rng_filt = av_rf ? rng_filt2 : rng_filt1
  79. hi_band = av_rf ? hi_band2 : hi_band1
  80. lo_band = av_rf ? lo_band2 : lo_band1
  81. [hi_band, lo_band, rng_filt]
  82.  
  83. ma_function(source, length, type) =>
  84.  
  85.  
  86. if type == 'RMA'
  87. ta.rma(source, length)
  88. else if type == 'SMA'
  89. ta.sma(source, length)
  90. else if type == 'EMA'
  91. ta.ema(source, length)
  92. else if type == 'WMA'
  93. ta.wma(source, length)
  94. else if type == 'HMA'
  95. if(length<2)
  96. ta.hma(source,2)
  97. else
  98. ta.hma(source, length)
  99. else
  100. ta.vwma(source, length)
  101.  
  102.  
  103. respect_expiry_count = input.bool (false, "", group='========= Indicator Setup =========', inline='expiry')
  104.  
  105. signalexpiry = input.int(defval=3, title='Signal Expiry Candle Count',group='========= Indicator Setup =========', inline='expiry')
  106. alternatesignal = input.bool (true, "Alternate Signal", group='========= Indicator Setup =========', inline='alternate')
  107.  
  108. showdashboard = input.bool (true, "Show Dashboard", group='========= Indicator Setup =========',inline='respectema')
  109. string i_tab1Ypos = input.string('bottom', 'Dashboard Position',group='========= Indicator Setup =========', inline='dashboard', options=['top', 'middle', 'bottom'])
  110. string i_tab1Xpos = input.string('right', '', inline='dashboard', group='========= Indicator Setup =========',options=['left', 'center', 'right'])
  111.  
  112. //candlecount = input.int(defval=3, title='Candle Count', group='cc', inline='cc',tooltip = "Max number of candles to wait for leading and confirmation indicators to generaate signal")
  113.  
  114. ///////////////////////////////////////////////
  115. ///// Signal filters
  116. /////////////////////////////////////////////
  117.  
  118. leadingindicator = input.string(title="Leading Indicator", defval="Range Filter",
  119. options=["Range Filter", "RQK", "Trend Trader","Supertrend","Ichimoku Cloud","SuperIchi","VMC","Donchian Trend Ribbon","Stochastic","RSI","VWAP","CCI","2 EMA Cross","3 EMA Cross","B-Xtrender","Bull Bear Power Trend","BB Oscillator","Trend Meter","Chandelier Exit","DMI (Adx)","Parabolic SAR (PSAR)","MACD","SSL Channel","Waddah Attar Explosion","Chaikin Money Flow","Vortex Index","Schaff Trend Cycle (STC)","Awesome Oscillator","Volatility Oscillator","Wolfpack Id","QQE Mod","Hull Suite"], group='========= Main Indicator (signal) =========', inline='li')
  120.  
  121. ema_tooltip = "EMA filter for confirmation.\n\n Validates Long signal if price is above the EMA FILTER level, and validates Short signal if price is below the EMA FILTER level. \n\nDefault is 200, you can change that to meet your requiremnt."
  122. respectema = input.bool (false, "EMA Filter", group='========= Confirmation Indicators (filter) =========', inline='respectema')
  123. respectemaperiod = input.int(defval=200, minval=1, title='', group='========= Confirmation Indicators (filter) =========', inline='respectema', tooltip=ema_tooltip)
  124.  
  125. ema2_tooltip = "Generates Long signal if Fast EMA cross above Slow EMA.\n\n Generates Short signal when Fast EMA cross below the Slow EMA.\n\n Default values are 50 and 200. you can change that to meet your requirement."
  126. respect2ma = input.bool (false, "2 EMA Cross : ", group='========= Confirmation Indicators (filter) =========', inline='2ma')
  127. respect2maperiod_1 = input.int(defval=50, title='',group='========= Confirmation Indicators (filter) =========', inline='2ma')
  128. respect2maperiod_2 = input.int(defval=200, title='',group='========= Confirmation Indicators (filter) =========', inline='2ma',tooltip=ema2_tooltip)
  129.  
  130. ema3_tooltip = "Generates Long signal if first EMA (Fastest) cross above 2nd and 3rd EMA and 2nd EMA cross above 3rd EMA.\n\n Generates Short signal if first EMA (Fastest) cross below 2nd and 3rd EMA and 2nd EMA cross below 3rd EMA .\n\n Default values are 9,21 and 55. you can change that to meet your requirement."
  131. respect3ma = input.bool (false, "3 EMA Cross : ", group='========= Confirmation Indicators (filter) =========', inline='3ma',tooltip=ema3_tooltip)
  132. respect3maperiod_1 = input.int(defval=9, title='',group='========= Confirmation Indicators (filter) =========', inline='3ma',tooltip=ema3_tooltip)
  133. respect3maperiod_2 = input.int(defval=21, title='',group='========= Confirmation Indicators (filter) =========', inline='3ma',tooltip=ema3_tooltip)
  134. respect3maperiod_3 = input.int(defval=55, title='',group='========= Confirmation Indicators (filter) =========', inline='3ma',tooltip=ema3_tooltip)
  135.  
  136.  
  137.  
  138. respectrf = input.bool (false, "Range Filter", group='========= Confirmation Indicators (filter) =========', inline='rf')
  139. rftype = input.string(title="", defval="Default", options=["Default","DW"], group='========= Confirmation Indicators (filter) =========', inline='rf')
  140.  
  141. respectrqk = input.bool (true, "RQK", group='========= Confirmation Indicators (filter) =========', inline='rqk')
  142.  
  143.  
  144.  
  145.  
  146. respectst = input.bool (false, "SuperTrend", group='========= Confirmation Indicators (filter) =========', inline='st')
  147.  
  148.  
  149.  
  150.  
  151. respectdonchian = input.bool (false, "Donchian Trend Ribbon", group='========= Confirmation Indicators (filter) =========', inline='donchian')
  152.  
  153.  
  154. respectichi = input.bool (false, "Ichimoku Cloud", group='========= Confirmation Indicators (filter) =========', inline='ichi')
  155. //ichitype = input.string(title="", defval="Standard", options=["Standard", "Price above cloud","Conversion and baseline crossover", "Lagging Span above cloud","Leading cloud green/rred"], group='========= Confirmation Indicators (filter) =========', inline='ichi',tooltip="Ichimoku Cloud Conditions: \n \n Standarrd \n\n When all the 4 conditions are satisfied \n\n 2. Candle above cloud \n \n 3. Converstion Line above base line \n \n 4. Leading 26 bar cloud is green \n \n 5. lagging span is above the cloud")
  156.  
  157.  
  158. respectsuperichi = input.bool (false, "SuperIchi", group='========= Confirmation Indicators (filter) =========', inline='ichi',tooltip="Ichimoku Cloud Conditions: \n \n 1. Candle above cloud \n \n 2. Converstion Line above base line \n \n 3. Leading 26 bar cloud is green \n \n 4. lagging span is above the cloud")
  159.  
  160. respectbx = input.bool (false, "B-Xtrender", group='========= Confirmation Indicators (filter) =========', inline='bx')
  161. bxtype = input.string(title="", defval="Short and Long term trend", options=["Short and Long term trend","Short Term trend"], group='========= Confirmation Indicators (filter) =========', inline='bx', tooltip = "Short term trend:\n\n===================== \n\n For buy signal the short term trend line must turn green, and for the sell signal, the short term trend line must turn red. \n\n Short and Long term trend: \n\n===================== \n\n For buy signal, the short term trend must change from red to green and long term trend cross above zero line, for Sell signal the short term trend must turn red and long term trend line cross down the zero line..")
  162.  
  163.  
  164. respectbbpt = input.bool (false, "Bull bear Power Trend", group='========= Confirmation Indicators (filter) =========', inline='bbpt')
  165. bbpttype = input.string(title="", defval="Follow Trend", options=["Follow Trend","Without Trend"], group='========= Confirmation Indicators (filter) =========', inline='bbpt', tooltip = "Follow Trend:\n\n===================== \n\n Buy signal will be validated if the BBPT trend line is above 2, and Sell signal will be validated if BBPT trend line is below -2. \n\n Without Trend: \n\n===================== \n\n Ignore the BBPT trend line.")
  166.  
  167.  
  168.  
  169. respectvwap = input.bool (false, "VWAP", group='========= Confirmation Indicators (filter) =========', inline='vwap')
  170.  
  171. respectbbosc = input.bool (false, "BB Oscillator", group='========= Confirmation Indicators (filter) =========', inline='bbosc')
  172. bbtype = input.string(title="", defval="Entering Lower/Upper Band", options=["Entering Lower/Upper Band","Exiting Lower/Upper Band"], group='========= Confirmation Indicators (filter) =========', inline='bbosc')
  173.  
  174.  
  175. respecttm = input.bool (false, "Trend Meter", group='========= Confirmation Indicators (filter) =========', inline='tm')
  176. tmtype = input.string(title="", defval="3 TM and 2 TB change to same color", options=["3 TM change to same color", "3 TM and 2 TB change to same color", "3 TM, 2 TB and Wavetrend change to same color"], group='========= Confirmation Indicators (filter) =========', inline='tm')
  177.  
  178.  
  179. respectce = input.bool (false, "Chandelier Exit", group='========= Confirmation Indicators (filter) =========', inline='ce')
  180.  
  181.  
  182.  
  183. respectcci = input.bool (false, "CCI", group='========= Confirmation Indicators (filter) =========', inline='cci')
  184. //ccitype = input.string(title="", defval="Standard", options=["Standard"], group='========= Confirmation Indicators (filter) =========', inline='cci')
  185.  
  186.  
  187.  
  188. respectao = input.bool (false, "Awesome Oscillator", group='========= Confirmation Indicators (filter) =========', inline='ao')
  189. aotype = input.string(title="", defval="Zero Line Cross", options=["Zero Line Cross","AC Zero Line Cross","AC Momentum Bar"], group='========= Confirmation Indicators (filter) =========', inline='ao', tooltip = "Zero Line Cross:\n\n If AO value cross the zero line up, Buy signal will be generated, and if AO value cross down the zero line, sell signal will be generated.")
  190.  
  191.  
  192. respectadx = input.bool (false, "DMI (ADx)", group='========= Confirmation Indicators (filter) =========', inline='adx')
  193. adxtype = input.string(title="", defval="Adx & +Di -Di", options=["Adx Only","Adx & +Di -Di", "Advance"], group='========= Confirmation Indicators (filter) =========', inline='adx', tooltip = "Adx Only:\n\n If Adx value is above the defined level. \n\n Adx & +Di -DI :\n\n When Adx value is above the defined level and croseeover between +di and -di. Di will determine the direction of the movement. \n\n Advance: ")
  194.  
  195. respectsar = input.bool (false, "Parabolic SAR (PSAR)", group='========= Confirmation Indicators (filter) =========', inline='sar')
  196.  
  197.  
  198. respectwae = input.bool (false, "Waddah Attar Explosion", group='========= Confirmation Indicators (filter) =========', inline='wae')
  199.  
  200.  
  201.  
  202. vo_tooltip = "Volatility Oscillator: \n\n ======================= \n\n If the spike line is above the upper line, buy signal is generated (or validated). \n\n If the spike line is below the lower line, sell signal is generated (or validated)."
  203. respectvo = input.bool (false, "Volatility Oscillator", group='========= Confirmation Indicators (filter) =========', inline='vo', tooltip = vo_tooltip)
  204.  
  205.  
  206. respectdv = input.bool (false, "Damiani Volatility (DV)", group='========= Confirmation Indicators (filter) =========', inline='dv')
  207.  
  208. dvtype = input.string(title="", defval="Simple", options=["Simple", "Threshold","10p Difference"], group='========= Confirmation Indicators (filter) =========', inline='dv', tooltip = "Simple\n Volatility is green. \nThreshold\n Volatility green and >1.1")
  209.  
  210.  
  211. stochtooltip="CrossOver:\n------------------\n\n CrossOver of K and D line at any level. \n\n CrossOver in OB & OS levels:\n\n Generate buy signal if crossover happens in oversold area and crossing up oversold level.\n\n Generate sell signal on crossover in overbought area and cross down upper level. \n------------------\n\n %K above/below %D\n------------------\n: Generate Buy signal or validate other signal if %K is above %D and opposite for Sell Signal."
  212.  
  213. respectstochastic = input.bool (false, "Stochastic", group='========= Confirmation Indicators (filter) =========', inline='stoch')
  214. stochtype = input.string(title="", defval="CrossOver", options=["CrossOver", "CrossOver in OB & OS levels","%K above/below %D"],tooltip=stochtooltip, group='========= Confirmation Indicators (filter) =========', inline='stoch')
  215. rsi_tooltip = "RSI MA Cross:\n=============\n Generate buy signal when RSI cross up RSI MA line and sell signal when RSI cross down RSI MA line.\n\nRSI Exits OB/OS zones:\n==================\n Generate Buy signal when RSI crosses down the overbough zone and sell signal when RSI crosses up the oversold zone.\n\nRSI Level:\n==========\nGenerate buy signal if RSI cross above the specific level and sell signal when RSI crossdown the level.\n\n\n +++++\nYou can change the setting to define the OB/OS and MidLine Levels"
  216.  
  217. respectrsi = input.bool (false, "RSI", group='========= Confirmation Indicators (filter) =========', inline='rsi')
  218. rsitype = input.string(title="", defval="RSI MA Cross", options=["RSI MA Cross", "RSI Exits OB/OS zones","RSI Level"], tooltip=rsi_tooltip, group='========= Confirmation Indicators (filter) =========', inline='rsi')
  219.  
  220. rsima_tooltip = "RSI MA Direction:\n=============\n The buy and sell signal will respect the RSI MA direction. For buy signal, the RSI MA should be increasing or same compared to previous RSI MA. \n\n for SHORT, the RSI MA should be same or decreasing compared to last RSI MA"
  221. respectrsima = input.bool (false, "RSI MA Direction", group='========= Confirmation Indicators (filter) =========', inline='rsi2',tooltip=rsima_tooltip)
  222.  
  223. rsilimit_tooltip = "RSI Limit:\n=============\n This is to allow you to set limit for the RSI value for long and short. default value for long is 40, which means if the RSI is 40 or above, only then BUY signal will be validated. \n\nfor short if RSI is 60 or less, only then sell signal willbe validated."
  224. respectrsilimit = input.bool (false, "RSI Limit : ", group='========= Confirmation Indicators (filter) =========', inline='rsi3',tooltip=rsilimit_tooltip)
  225.  
  226. rsilimitup = input.int(40, title="Long",inline='rsi3', group='========= Confirmation Indicators (filter) =========')
  227. rsilimitdown = input.int(60, title="short",inline='rsi3', group='========= Confirmation Indicators (filter) =========')
  228.  
  229.  
  230. rsimalimit_tooltip = "RSI MA Limit:\n=============\n This is to allow you to set limit for the RSI MA value for long and short. default value for long is 40, which means if the RSI MA is 40 or above, only then BUY signal will be validated. \n\nfor short if RSI MA is 60 or less, only then sell signal willbe validated."
  231. respectrsimalimit = input.bool (false, "RSI MA Limit : ", group='========= Confirmation Indicators (filter) =========', inline='rsi4',tooltip=rsimalimit_tooltip)
  232.  
  233. rsimalimitup = input.int(40, title="Long",inline='rsi4', group='========= Confirmation Indicators (filter) =========')
  234. rsimalimitdown = input.int(60, title="short",inline='rsi4', group='========= Confirmation Indicators (filter) =========')
  235.  
  236.  
  237.  
  238.  
  239.  
  240. macdtooltip="MACD Crossover:\n------------------\n\n CrossOver of MACD and the Signal line. Generates Long signal when MACD cross up Signal line and Short signal when MACD cross down Signal Line. . \n\n Zero line crossover:\n------------------\n\n Generate buy signal when MACD cross up the zero line and Sell signal when MACD cross down the zero line."
  241. respectmacd = input.bool (false, "MACD", group='========= Confirmation Indicators (filter) =========', inline='macd')
  242. macdtype = input.string(title="", defval="MACD Crossover", options=["MACD Crossover", "Zero line crossover"],tooltip=macdtooltip, group='========= Confirmation Indicators (filter) =========', inline='macd')
  243.  
  244. respectssl = input.bool (false, "SSL Channel", group='========= Confirmation Indicators (filter) =========', inline='ssl')
  245.  
  246. respectstc = input.bool (false, "Schaff Trend Cycle (STC)", group='========= Confirmation Indicators (filter) =========', inline='stc')
  247. respectchaikin = input.bool (false, "Chaikin Money Flow", group='========= Confirmation Indicators (filter) =========', inline='chaikin')
  248.  
  249. respectvol = input.bool (false, "Volume", group='========= Confirmation Indicators (filter) =========', inline='volume')
  250. volumetype = input.string(title="", defval="Simple", options=["Simple", "Delta"], group='========= Confirmation Indicators (filter) =========', inline='volume', tooltip = "Simple volume is comparing the up/down volme with previous candle. \nVolume delta will compare the delta or difference between up and down volume with previous candle.\nExample:\n up volume = 100 \n Down volume=-1100\n Delta = -1000\n Satisfy the bear flag condition if previous -ve delta is lower")
  251.  
  252. respectwolf = input.bool (false, "Wolfpack Id", group='========= Confirmation Indicators (filter) =========', inline='wolf')
  253.  
  254.  
  255. respectqqe = input.bool (false, "QQE Mod", group='========= Confirmation Indicators (filter) =========', inline='qqe')
  256. qqetype = input.string(title="", defval="Line", options=["Line", "Bar","Line & Bar"], group='========= Confirmation Indicators (filter) =========', inline='qqe', tooltip = "Line: signal generated when QQE line is above or below 0. \nBar: when Blue bar is above 0 or Red bar below 0 \nLine & Bar: Both Bar and Line to be above(bullist) or below (bearish) 0" )
  257.  
  258. respecthull = input.bool (false, "Hull Suite",group='========= Confirmation Indicators (filter) =========', inline='hull')
  259.  
  260.  
  261. respectvi = input.bool (false, "Vortex Indicator",group='========= Confirmation Indicators (filter) =========', inline='vi')
  262. vitype = input.string(title="", defval="Simple", options=["Simple", "Advance"],group='========= Confirmation Indicators (filter) =========', inline='vi',
  263. tooltip = "Simple\n Green Cross Red. \Advance\n vipcondition := vip > vim and vip > viupper and vip > vip[1] and vim < vim[1] and vim[1] <= vilower and vip[1] >= viupper
  264. vimcondition := vip < vim and vim > viupper and vim > vim[1] and vip < vip [1] and vip[1] <= vilower and vim [1] >= viupper ")
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. /////////////////////////////////////////////////////////////////////////
  272. // Switch Board
  273. ////////////////////////////////////////////////////////////////////////
  274. switch_ema = input.bool (false, "EMA", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch1')
  275. switch_supportresistance = input.bool (false, "S/R", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch1')
  276. switch_poi = input.bool (true, "Supply/Demand Zone", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch1')
  277. switch_sar = input.bool (false, "PSAR", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch1')
  278. switch_ichi = input.bool (false, "Ichimoku Cloud", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch2')
  279. switch_superichi = input.bool (false, "SuperIchi", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch2')
  280. switch_vwap = input.bool (false, "VWAP", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch3')
  281.  
  282. switch_supertrend = input.bool (false, "Supertrend", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch2')
  283. switch_rangefilter = input.bool (false, "Range Filter", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch2')
  284. switch_rangefilter2 = input.bool (false, "Range Filter DW", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch2')
  285.  
  286. switch_atr = input.bool (false, "ATR", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch2')
  287.  
  288. switch_stc = input.bool (false, "STC", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch3')
  289. switch_pvsra = input.bool (true, "PVSRA", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch3')
  290. switch_vectorzone = input.bool (false, "Liquidity Zone", group='-------Switch Board (Turn On/Off Overlay Indicators)-------', inline='Switch3')
  291. bool show_markets = input.bool(true, group='-------Switch Board (Turn On/Off Overlay Indicators)-------', title='Show Market Sessions?', tooltip='Turn on or off all market sessions')
  292. string rectStyle = input.string(group='-------Switch Board (Turn On/Off Overlay Indicators)-------', defval='Dashed', title='Line style of Market Session hi/lo line', options=['Dashed', 'Solid'])
  293. sessLineStyle = line.style_dashed
  294. bool show_markets_weekends = input.bool(false, group='-------Switch Board (Turn On/Off Overlay Indicators)-------', title='Show Market Session on Weekends?', tooltip='Turn on or off market sessions in the weekends. Note do not turn this on for exchanges that dont have weekend data like OANDA')
  295.  
  296.  
  297. /////////////////////////////////////////////////////////////////////////
  298. // EMA Selection
  299. ////////////////////////////////////////////////////////////////////////
  300. len1bool = input.bool(true,'',group='-------------------------MAs line-------------------------',inline='len1')
  301. len1 = input.int(5, title='MA 1',group='-------------------------MAs line-------------------------',inline='len1')
  302. string ma_1_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA','HMA','VWMA'], inline='len1',group='-------------------------MAs line-------------------------')
  303. color ma_1_colour = input.color(color.rgb(254, 234, 74, 0), '', inline='len1',group='-------------------------MAs line-------------------------')
  304.  
  305.  
  306. len2bool = input.bool(true,'',group='-------------------------MAs line-------------------------',inline='len2')
  307. len2 = input.int(13, minval=1, title='MA 2',group='-------------------------MAs line-------------------------',inline='len2')
  308. string ma_2_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA','HMA','VWMA'], inline='len2',group='-------------------------MAs line-------------------------')
  309. color ma_2_colour = input.color(color.rgb(253, 84, 87, 0), '', inline='len2',group='-------------------------MAs line-------------------------')
  310.  
  311.  
  312. len3bool = input.bool(false,'',group='-------------------------MAs line-------------------------',inline='len3')
  313. len3 = input.int(20, minval=1, title='MA 3',group='-------------------------MAs line-------------------------',inline='len3')
  314. string ma_3_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA','HMA','VWMA'], inline='len3',group='-------------------------MAs line-------------------------')
  315. color ma_3_colour = input.color(color.new(color.aqua, 0), '', inline='len3',group='-------------------------MAs line-------------------------')
  316.  
  317. len4bool = input.bool(true,'',group='-------------------------MAs line-------------------------',inline='len4')
  318. len4 = input.int(50, minval=1, title='MA 4',group='-------------------------MAs line-------------------------',inline='len4')
  319. string ma_4_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA','HMA','VWMA'], inline='len4',group='-------------------------MAs line-------------------------')
  320. color ma_4_colour = input.color(color.new(color.blue, 0), '', inline='len4',group='-------------------------MAs line-------------------------')
  321.  
  322. len5bool = input.bool(true,'',group='-------------------------MAs line-------------------------',inline='len5')
  323. len5 = input.int(200, minval=1, title='MA 5',group='-------------------------MAs line-------------------------',inline='len5')
  324. string ma_5_type = input.string(defval='EMA', title='Type', options=['RMA', 'SMA', 'EMA', 'WMA','HMA','VWMA'], inline='len5',group='-------------------------MAs line-------------------------')
  325. color ma_5_colour = input.color(color.new(color.white, 0), '', inline='len5',group='-------------------------MAs line-------------------------')
  326.  
  327.  
  328.  
  329. //ema1 = ta.ema(close, len1)
  330. ema1 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len1, ma_1_type))
  331. ema2 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len2, ma_2_type))
  332. ema3 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len3, ma_3_type))
  333. ema4 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len4, ma_4_type))
  334. ema5 = request.security(syminfo.tickerid, timeframe.period, ma_function(close, len5, ma_5_type))
  335.  
  336.  
  337. plot(len1bool and switch_ema ? ema1:na, color=ma_1_colour, linewidth=2, title='MA 1')
  338. plot(len2bool and switch_ema? ema2:na, color=ma_2_colour, linewidth=2, title='MA 2')
  339. plot(len3bool and switch_ema? ema3:na, color=ma_3_colour, linewidth=2, title='MA 3')
  340. plot(len4bool and switch_ema? ema4:na, color=ma_4_colour, linewidth=2, title='MA 4')
  341. plot(len5bool and switch_ema? ema5:na, color=ma_5_colour, linewidth=2, title='MA 5')
  342.  
  343.  
  344.  
  345.  
  346. ////////////////////////////////////////////////////////////////////////////
  347. //////////// 2EMA cross
  348. ////////////////////////////////////////////////////////////////////////////
  349.  
  350. first_2ema = ta.ema(close, respect2maperiod_1)
  351. second_2ema = ta.ema(close, respect2maperiod_2)
  352.  
  353.  
  354. ////////////////////////////////////////////////////////////////////////////
  355. //////////// 3EMA cross
  356. ////////////////////////////////////////////////////////////////////////////
  357.  
  358. first_3ema = ta.ema(close, respect3maperiod_1)
  359. second_3ema = ta.ema(close, respect3maperiod_2)
  360. third_3ema = ta.ema(close, respect3maperiod_3)
  361.  
  362.  
  363.  
  364.  
  365. //////////////////////////////////////////////////////////////////////////
  366. // Range Filter
  367. //////////////////////////////////////////////////////////////////////////
  368.  
  369.  
  370.  
  371. //switch_rangefilter = input.bool (true, "Show Range Filter Signals", group='-------------------------Range Filter-------------------------')
  372. showrfline = input.bool (true, "Show RF line", group='-------------------------Range Filter-------------------------')
  373.  
  374. // Source
  375.  
  376. src = input.source(defval=close, title='Source', group='-------------------------Range Filter-------------------------',inline = 'rf')
  377.  
  378. // Sampling Period
  379. // Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
  380.  
  381. per = input.int(defval=100, minval=1, title='Period', group='-------------------------Range Filter-------------------------',inline = 'rf')
  382.  
  383. // Range Multiplier
  384.  
  385. mult = input.float(defval=3.0, minval=0.1, title='Multiplier', group='-------------------------Range Filter-------------------------',inline = 'rf')
  386.  
  387. // Smooth Average Range
  388.  
  389. smoothrng(x, t, m) =>
  390. wper = t * 2 - 1
  391. avrng = ta.ema(math.abs(x - x[1]), t)
  392. smoothrng = ta.ema(avrng, wper) * m
  393. smoothrng
  394. smrng = smoothrng(src, per, mult)
  395.  
  396. // Range Filter
  397.  
  398. rngfilt(x, r) =>
  399. rngfilt = x
  400. rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
  401. rngfilt
  402. filt = rngfilt(src, smrng)
  403.  
  404. // Filter Direction
  405.  
  406. upward = 0.0
  407. upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
  408. downward = 0.0
  409. downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])
  410.  
  411. // Target Bands
  412.  
  413. hband = filt + smrng
  414. lband = filt - smrng
  415.  
  416. // Colors
  417.  
  418.  
  419. ///////////////////////////////
  420. ////// RF2
  421. ///////////////////////////////
  422.  
  423. //Filter Type
  424. f_type = input.string(defval='Type 1', options=['Type 1', 'Type 2'], title='Filter Type')
  425.  
  426. //Movement Source
  427. mov_src = input.string(defval='Close', options=['Wicks', 'Close'], title='Movement Source')
  428.  
  429. //Range Size Inputs
  430. rng_qty = input.float(defval=2.618, minval=0.0000001, title='Range Size')
  431. rng_scale = input.string(defval='Average Change', options=['Points', 'Pips', 'Ticks', '% of Price', 'ATR', 'Average Change', 'Standard Deviation', 'Absolute'], title='Range Scale')
  432.  
  433. //Range Period
  434. rng_per = input.int(defval=14, minval=1, title='Range Period (for ATR, Average Change, and Standard Deviation)')
  435.  
  436. //Range Smoothing Inputs
  437. smooth_range = input(defval=true, title='Smooth Range')
  438. smooth_per = input.int(defval=27, minval=1, title='Smoothing Period')
  439.  
  440. //Filter Value Averaging Inputs
  441. av_vals = input(defval=false, title='Average Filter Changes')
  442. av_samples = input.int(defval=2, minval=1, title='Number Of Changes To Average')
  443.  
  444.  
  445. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  446. //Definitions
  447. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  448.  
  449. //High And Low Values
  450. h_val = mov_src == 'Wicks' ? high : close
  451. l_val = mov_src == 'Wicks' ? low : close
  452.  
  453. //Range Filter Values
  454. [h_band, l_band, filt2] = rng_filt(h_val, l_val, rng_size((h_val + l_val) / 2, rng_scale, rng_qty, rng_per), rng_per, f_type, smooth_range, smooth_per, av_vals, av_samples)
  455.  
  456. //Direction Conditions
  457. var fdir2 = 0.0
  458. fdir2 := filt2 > filt2[1] ? 1 : filt2 < filt2[1] ? -1 : fdir2
  459. rfupward = fdir2 == 1 ? 1 : 0
  460. rfdownward= fdir2 == -1 ? 1 : 0
  461.  
  462.  
  463. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  464. //color and switchboard rf
  465. //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
  466.  
  467.  
  468. filtcolor = upward > 0 ? color.lime : downward > 0 ? color.red : color.orange
  469. filt2_color = rfupward ? #05ff9b : rfdownward ? #ff0583 : #cccccc
  470.  
  471. filttype = string(na)
  472. if rftype == "Default"
  473. filttype := "filt"
  474. else if rftype == "DW"
  475. filttype := "filt2"
  476.  
  477.  
  478. filtplot = plot(switch_rangefilter and showrfline?filt:na, color=filtcolor, linewidth=2, title='Range Filter')
  479. filtplot2 = plot(switch_rangefilter2 ?filt2:na, color=filt2_color, linewidth=2, title='Range Filter')
  480.  
  481.  
  482.  
  483.  
  484.  
  485. ////////////////////////////////
  486. /////Trend Trader
  487. //////////////////////////////////
  488. ttgroupname = '------------------------Trend Trader------------------------'
  489. ttLength = input.int(21, minval=1,group=ttgroupname)
  490. ttMultiplier = input.float(3, minval=0.000001,group=ttgroupname)
  491. avgTR = ta.wma(ta.atr(1), ttLength)
  492. highestC = ta.highest(ttLength)
  493. lowestC = ta.lowest(ttLength)
  494. hiLimit = highestC[1] - avgTR[1] * ttMultiplier
  495. loLimit = lowestC[1] + avgTR[1] * ttMultiplier
  496. ret = 0.0
  497. pos = 0.0
  498. ret:= close > hiLimit and close > loLimit ? hiLimit :
  499. close < loLimit and close < hiLimit ? loLimit : nz(ret[1], close)
  500. pos:= close > ret ? 1 :close < ret ? -1 : nz(pos[1], 0)
  501. if pos != pos[1] and pos == 1
  502. alert("Color changed - Buy", alert.freq_once_per_bar_close)
  503. if pos != pos[1] and pos == -1
  504. alert("Color changed - Sell", alert.freq_once_per_bar_close)
  505.  
  506.  
  507. ttlong = close > ret
  508. ttshort = close < ret
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516. ////////////////////////////////
  517. /// RQK
  518. ////////////////////////////////
  519.  
  520. rqkgroupname = '------------------------RQK------------------------'
  521. rqksrc = input.source(close, 'Source', group=rqkgroupname)
  522. h2 = input.float(8., 'Lookback Window', minval=3., tooltip='The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50', group=rqkgroupname)
  523. r = input.float(8., 'Relative Weighting', step=0.25, group=rqkgroupname, tooltip='Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25')
  524. x_0 = input.int(25, "Start Regression at Bar", group=rqkgroupname, tooltip='Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25')
  525. smoothColors = input.bool(false, "Smooth Colors", group=rqkgroupname, tooltip="Uses a crossover based mechanism to determine colors. This often results in less color transitions overall.", inline='1')
  526. lag = input.int(2, "Lag", group=rqkgroupname, tooltip="Lag for crossover detection. Lower values result in earlier crossovers. Recommended range: 1-2", inline='1')
  527. size = array.size(array.from(rqksrc)) // size of the data series
  528.  
  529. // Further Reading:
  530. // The Kernel Cookbook: Advice on Covariance functions. David Duvenaud. Published June 2014.
  531. // Estimation of the bandwidth parameter in Nadaraya-Watson kernel non-parametric regression based on universal threshold level. Ali T, Heyam Abd Al-Majeed Hayawi, Botani I. Published February 26, 2021.
  532. kernel_regression(_rqksrc, _size, _h2) =>
  533. float _currentWeight = 0.
  534. float _cumulativeWeight = 0.
  535. for i = 0 to _size + x_0
  536. y = _rqksrc[i]
  537. w = math.pow(1 + (math.pow(i, 2) / ((math.pow(_h2, 2) * 2 * r))), -r)
  538. _currentWeight += y*w
  539. _cumulativeWeight += w
  540. _currentWeight / _cumulativeWeight
  541.  
  542. // Estimations
  543. yhat1 = kernel_regression(rqksrc, size, h2)
  544. yhat2 = kernel_regression(rqksrc, size, h2-lag)
  545.  
  546. // Rates of Change
  547. bool wasBearish = yhat1[2] > yhat1[1]
  548. bool wasBullish = yhat1[2] < yhat1[1]
  549. bool isBearish = yhat1[1] > yhat1
  550. bool isBullish = yhat1[1] < yhat1
  551. bool isBearishChange = isBearish and wasBullish
  552. bool isBullishChange = isBullish and wasBearish
  553.  
  554. // Crossovers
  555. bool isBullishCross = ta.crossover(yhat2, yhat1)
  556. bool isBearishCross = ta.crossunder(yhat2, yhat1)
  557. bool isBullishSmooth = yhat2 > yhat1
  558. bool isBearishSmooth = yhat2 < yhat1
  559.  
  560. // Colors
  561. color c_bullish = input.color(#3AFF17, 'Bullish Color', group='Colors')
  562. color c_bearish = input.color(#FD1707, 'Bearish Color', group='Colors')
  563. color colorByCross = isBullishSmooth ? c_bullish : c_bearish
  564. color colorByRate = isBullish ? c_bullish : c_bearish
  565. color plotColor = smoothColors ? colorByCross : colorByRate
  566.  
  567.  
  568.  
  569.  
  570. rqkuptrend = yhat1[1] < yhat1
  571. rqkdowntrend = yhat1[1] > yhat1
  572.  
  573.  
  574.  
  575. ////////////////////////////////
  576. ///// Super Trend
  577. //////////////////////////////
  578.  
  579.  
  580.  
  581. Periods = input(title='ATR Period', defval=10, group='--------------------SuperTrend----------------------------')
  582. stsrc = input(hl2, title='Source', group='--------------------SuperTrend----------------------------')
  583. Multiplier = input.float(title='ATR Multiplier', step=0.1, defval=3.0, group='--------------------SuperTrend----------------------------')
  584. changeATR = input(title='Change ATR Calculation Method ?', defval=true, group='--------------------SuperTrend----------------------------')
  585. showsignals = input(title='Show Buy/Sell Signals ?', defval=true, group='--------------------SuperTrend----------------------------')
  586. highlighting = input(title='Highlighter On/Off ?', defval=true, group='--------------------SuperTrend----------------------------')
  587. statr2 = ta.sma(ta.tr, Periods)
  588. statr = changeATR ? ta.atr(Periods) : statr2
  589. stup = stsrc - Multiplier * statr
  590. up1 = nz(stup[1], stup)
  591. stup := close[1] > up1 ? math.max(stup, up1) : stup
  592. dn = stsrc + Multiplier * statr
  593. dn1 = nz(dn[1], dn)
  594. dn := close[1] < dn1 ? math.min(dn, dn1) : dn
  595. sttrend = 1
  596. sttrend := nz(sttrend[1], sttrend)
  597. sttrend := sttrend == -1 and close > dn1 ? 1 : sttrend == 1 and close < up1 ? -1 : sttrend
  598. upPlot = plot(sttrend == 1 and switch_supertrend ? stup : na, title='Up Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.green, 0))
  599. stbuySignal = sttrend == 1 and sttrend[1] == -1
  600. plotshape(stbuySignal and switch_supertrend ? stup : na, title='UpTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))
  601. //plotshape(stbuySignal and showsignals ? up : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
  602. dnPlot = plot(sttrend != 1 and switch_supertrend ? dn : na , title='Down Trend', style=plot.style_linebr, linewidth=2, color=color.new(color.red, 0))
  603. stsellSignal = sttrend == -1 and sttrend[1] == 1
  604. plotshape(stsellSignal and switch_supertrend ? dn : na, title='DownTrend Begins', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))
  605. //plotshape(sellSignal and showsignals ? dn : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
  606. //mPlot = plot(showst ? ohlc4:na, title='', style=plot.style_circles, linewidth=0)
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613. //////////////////////////////////////////////
  614. ////// Ichimoku
  615. /////////////////////////////////////////////
  616.  
  617. conversionPeriods = input.int(9, minval=1, title="Conversion Line Length")
  618. basePeriods = input.int(26, minval=1, title="Base Line Length")
  619. laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length")
  620. displacement = input.int(26, minval=1, title="Lagging Span")
  621. donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
  622. conversionLine = donchian(conversionPeriods)
  623. baseLine = donchian(basePeriods)
  624. leadLine1 = math.avg(conversionLine, baseLine)
  625. leadLine2 = donchian(laggingSpan2Periods)
  626. ChikouSpan = close[25] + (close - close[25])
  627. lead1 = leadLine1[displacement - 1]
  628. lead2 = leadLine2[displacement - 1]
  629. plot(switch_ichi?conversionLine:na, color=#2962FF, title="Conversion Line",linewidth = 1)
  630. plot(switch_ichi ? baseLine:na, color=#B71C1C, title="Base Line",linewidth = 1)
  631. plot(switch_ichi?close:na, offset = -displacement + 1, color=#43A047, title="Lagging Span")
  632. p1 = plot(switch_ichi?leadLine1:na, offset = displacement - 1, color=#A5D6A7,
  633. title="Leading Span A")
  634. p2 = plot(switch_ichi?leadLine2:na, offset = displacement - 1, color=#EF9A9A,
  635. title="Leading Span B")
  636.  
  637.  
  638. fill(p1, p2, color = leadLine1 > leadLine2 and switch_ichi ? color.rgb(67, 160, 71, 70) : color.rgb(244, 67, 54, 70))
  639.  
  640.  
  641.  
  642.  
  643. ichi_long = conversionLine > baseLine and leadLine1> leadLine2 and close >leadLine1[displacement -1] and close >leadLine2[displacement -1] and (ChikouSpan > leadLine1[50] and ChikouSpan > leadLine2[50])
  644. ichi_short = conversionLine < baseLine and leadLine1 < leadLine2 and close < leadLine1[displacement -1] and close < leadLine2[displacement -1] and (ChikouSpan < leadLine2[50] and ChikouSpan < leadLine1[50])
  645.  
  646.  
  647.  
  648. //////////////////////////////
  649. ///////// SuperIchi
  650. /////////////////////////////
  651. tenkan_len = input(9,'Tenkan          ',inline='tenkan')
  652. tenkan_mult = input(2.,'',inline='tenkan')
  653.  
  654. kijun_len = input(26,'Kijun             ',inline='kijun')
  655. kijun_mult = input(4.,'',inline='kijun')
  656.  
  657. spanB_len = input(52,'Senkou Span B ',inline='span')
  658. spanB_mult = input(6.,'',inline='span')
  659.  
  660. offset = input(26,'Displacement')
  661. //------------------------------------------------------------------------------
  662. avg(src,length,mult)=>
  663. atr = ta.atr(length)*mult
  664. up = hl2 + atr
  665. dn = hl2 - atr
  666. upper = 0.,lower = 0.
  667. upper := src[1] < upper[1] ? math.min(up,upper[1]) : up
  668. lower := src[1] > lower[1] ? math.max(dn,lower[1]) : dn
  669.  
  670. os = 0,max = 0.,min = 0.
  671. os := src > upper ? 1 : src < lower ? 0 : os[1]
  672. spt = os == 1 ? lower : upper
  673. max := ta.cross(src,spt) ? math.max(src,max[1]) : os == 1 ? math.max(src,max[1]) : spt
  674. min := ta.cross(src,spt) ? math.min(src,min[1]) : os == 0 ? math.min(src,min[1]) : spt
  675. math.avg(max,min)
  676. //------------------------------------------------------------------------------
  677. tenkan = avg(close,tenkan_len,tenkan_mult)
  678. kijun = avg(close,kijun_len,kijun_mult)
  679.  
  680. senkouA = math.avg(kijun,tenkan)
  681. senkouB = avg(close,spanB_len,spanB_mult)
  682. //------------------------------------------------------------------------------
  683. tenkan_css = #2157f3
  684. kijun_css = #ff5d00
  685.  
  686. cloud_a = color.new(color.teal,80)
  687. cloud_b = color.new(color.red,80)
  688.  
  689. chikou_css = #7b1fa2
  690.  
  691. plot(switch_superichi?tenkan:na,'Tenkan-Sen',tenkan_css)
  692. plot(switch_superichi?kijun:na,'Kijun-Sen',kijun_css)
  693.  
  694.  
  695.  
  696. A = plot(switch_superichi ? senkouA:na,'Senkou Span A',na,offset=offset-1)
  697. B = plot(switch_superichi ? senkouB:na,'Senkou Span B',na,offset=offset-1)
  698. fill(A,B,senkouA > senkouB and switch_superichi? cloud_a : cloud_b)
  699.  
  700. plot(switch_superichi?close:na,'Chikou',chikou_css,offset=-offset+1,display=display.none)
  701.  
  702.  
  703. superichi_long = tenkan > kijun and senkouA> senkouB and close >senkouA[displacement -1] and close >senkouB[displacement -1] and (ChikouSpan > senkouA[50] and ChikouSpan > senkouB[50])
  704. superichi_short = tenkan < kijun and senkouA < senkouB and close < senkouA[displacement -1] and close < senkouB[displacement -1] and (ChikouSpan < senkouB[50] and ChikouSpan < senkouA[50])
  705.  
  706. //////////////////////////////////
  707. ///////////Donchian Channel Ribbon
  708. ///////////////////////////////////
  709. donchiangroup = "-------------------------Donchian Channel Ribbon-------------------------"
  710. dlen = input.int(defval=15, title='Donchian Channel Period', group=donchiangroup)
  711.  
  712. dchannel(len) =>
  713. float hh = ta.highest(len)
  714. float ll = ta.lowest(len)
  715.  
  716. int trend = 0
  717. trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
  718. trend
  719.  
  720. dchannelalt(len, maintrend) =>
  721. float hh = ta.highest(len)
  722. float ll = ta.lowest(len)
  723.  
  724. int trend = 0
  725. trend := close > hh[1] ? 1 : close < ll[1] ? -1 : nz(trend[1])
  726. maintrend == 1 ? trend == 1 ? #00FF00ff : #00FF009f : maintrend == -1 ? trend == -1 ? #FF0000ff : #FF00009f : na
  727.  
  728. maintrend = dchannel(dlen)
  729.  
  730. donchian_long = maintrend == 1 ? true:na
  731. donchian_short = maintrend == -1 ? true:na
  732.  
  733.  
  734. ////////////////////////////////
  735. // DMI code
  736. ////////////////////////////////
  737.  
  738. adxlen = input(5, title="ADX", group='-------------------------DMI-------------------------', inline='dmi')
  739. keyLevel = input(20, title='ADX limit',group='-------------------------DMI-------------------------', inline='dmi')
  740. dilen = input.int(10, title="DI Length",group='-------------------------DMI-------------------------', inline='dmi')
  741.  
  742.  
  743. lensig = adxlen
  744. upp = ta.change(high)
  745. downn = ta.change(low)
  746. plusDM = na(upp) ? na : upp > downn and upp > 0 ? upp : 0
  747. minusDM = na(downn) ? na : downn > upp and downn > 0 ? downn : 0
  748. trur = ta.rma(ta.tr, dilen)
  749. plus = fixnan(100 * ta.rma(plusDM, dilen) / trur)
  750. minus = fixnan(100 * ta.rma(minusDM, dilen) / trur)
  751. sum = plus + minus
  752. adxx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  753. dirmov(dilen) =>
  754. up = ta.change(high)
  755. down = -ta.change(low)
  756. truerange = ta.rma(ta.tr, dilen)
  757. plus = fixnan(100 * ta.rma(up > down and up > 0 ? up : 0, dilen) / truerange)
  758. minus = fixnan(100 * ta.rma(down > up and down > 0 ? down : 0, dilen) / truerange)
  759. [plus, minus]
  760.  
  761. adx(dilen, adxlen) =>
  762. [plus, minus] = dirmov(dilen)
  763. sum = plus + minus
  764. adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
  765. [adx, plus, minus]
  766.  
  767. [adx, diplus, diminus] = adx(dilen, adxlen)
  768.  
  769. ////////////////////////////////////////////////
  770. //Parabolic SAR
  771. ///////////////////////////////////////////////
  772. //showsar = input.bool (false, "Show SAR", group='-------------------------Parabolic SAR-------------------------')
  773.  
  774. start = input.float(0.02, group='-------------------------Parabolic SAR-------------------------', inline ='sar')
  775. increment = input.float(0.02, group='-------------------------Parabolic SAR-------------------------', inline ='sar')
  776. maximum = input.float(0.2, 'Max Value', group='-------------------------Parabolic SAR-------------------------', inline ='sar')
  777. out = ta.sar(start, increment, maximum)
  778. sarcolor = if (out>close)
  779. color.red
  780. else
  781. color.green
  782.  
  783. if (switch_sar )
  784. color.red
  785. else
  786. color.green
  787. plot(switch_sar ? out : na, 'ParabolicSAR', style=plot.style_cross, color=sarcolor)
  788.  
  789.  
  790. //////////////////////////////////////////////////
  791. ///////// CCI
  792. /////////////////////////////////////////////////
  793. ccilength = input.int(20,title="CCI Length", minval=1,inline="cci", group="---------------------- CCI ------------------------")
  794. ccisrc = input(hlc3, title="Source",inline="cci", group="---------------------- CCI ------------------------")
  795. cciupperband = input.int(100,title="Upper Band",inline="cci2", group="---------------------- CCI ------------------------")
  796. ccilowerband = input.int(-100,title="Lower Band",inline="cci2", group="---------------------- CCI ------------------------")
  797.  
  798. ma = ta.sma(ccisrc, ccilength)
  799. cci = (ccisrc - ma) / (0.015 * ta.dev(ccisrc, ccilength))
  800.  
  801.  
  802.  
  803.  
  804. typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing",inline="cci4")
  805. smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing",inline="cci3")
  806.  
  807. smoothingLine = ma(cci, smoothingLength, typeMA)
  808. // plot(smoothingLine, title="Smoothing Line", color=#f37f20, display=display.none)
  809.  
  810.  
  811. ccilong = cci > cciupperband
  812. ccishort = cci < ccilowerband
  813.  
  814.  
  815.  
  816.  
  817.  
  818. ///////////////////////////////////////////////
  819. /////// B-Xtrender
  820. /////////////////////////////////////////////
  821.  
  822. bxgroup= "---------------------- B-Xtrender ------------------------"
  823. short_l1 = input(5, title='Short - L1',group=bxgroup)
  824. short_l2 = input(20, title='Short - L2',group=bxgroup)
  825. short_l3 = input(15, title='Short - L3',group=bxgroup)
  826.  
  827. long_l1 = input(5, title='Long - L1',group=bxgroup)
  828. long_l2 = input(10, title='Long - L2',group=bxgroup)
  829.  
  830. shortTermXtrender = ta.rsi(ta.ema(close, short_l1) - ta.ema(close, short_l2), short_l3) - 50
  831. longTermXtrender = ta.rsi(ta.ema(close, long_l1), long_l2) - 50
  832.  
  833. shortXtrenderCol = shortTermXtrender > 0 ? shortTermXtrender > shortTermXtrender[1] ? color.lime : #228B22 : shortTermXtrender > shortTermXtrender[1] ? color.red : #8B0000
  834. // plot(shortTermXtrender, color=shortXtrenderCol, style=plot.style_columns, linewidth=1, title='B-Xtrender Osc. - Histogram', transp=50)
  835.  
  836. t3(src, len) =>
  837. xe1_1 = ta.ema(src, len)
  838. xe2_1 = ta.ema(xe1_1, len)
  839. xe3_1 = ta.ema(xe2_1, len)
  840. xe4_1 = ta.ema(xe3_1, len)
  841. xe5_1 = ta.ema(xe4_1, len)
  842. xe6_1 = ta.ema(xe5_1, len)
  843. b_1 = 0.7
  844. c1_1 = -b_1 * b_1 * b_1
  845. c2_1 = 3 * b_1 * b_1 + 3 * b_1 * b_1 * b_1
  846. c3_1 = -6 * b_1 * b_1 - 3 * b_1 - 3 * b_1 * b_1 * b_1
  847. c4_1 = 1 + 3 * b_1 + b_1 * b_1 * b_1 + 3 * b_1 * b_1
  848. nT3Average_1 = c1_1 * xe6_1 + c2_1 * xe5_1 + c3_1 * xe4_1 + c4_1 * xe3_1
  849. nT3Average_1
  850.  
  851. maShortTermXtrender = t3(shortTermXtrender, 5)
  852.  
  853. colShortTermXtrender = maShortTermXtrender > maShortTermXtrender[1] ? color.lime : color.red
  854.  
  855. longXtrenderCol = longTermXtrender > 0 ? longTermXtrender > longTermXtrender[1] ? color.lime : #228B22 : longTermXtrender > longTermXtrender[1] ? color.red : #8B0000
  856. macollongXtrenderCol = longTermXtrender > longTermXtrender[1] ? color.lime : color.red
  857.  
  858. bx_long = bool(na)
  859. bx_short = bool(na)
  860.  
  861. if bxtype == "Short Term trend"
  862. bx_long := maShortTermXtrender > maShortTermXtrender[1]
  863. bx_short := maShortTermXtrender < maShortTermXtrender[1]
  864. else if bxtype == "Short and Long term trend"
  865. bx_long := maShortTermXtrender > maShortTermXtrender[1] and (longTermXtrender > 0 and longTermXtrender > longTermXtrender[1]) and (shortTermXtrender > shortTermXtrender[1] and shortTermXtrender > 0)
  866. bx_short := maShortTermXtrender < maShortTermXtrender[1] and (longTermXtrender < 0 and longTermXtrender < longTermXtrender[1]) and (shortTermXtrender < shortTermXtrender[1] and shortTermXtrender < 0)
  867.  
  868.  
  869.  
  870. ////////////////////////////////////////////////
  871. ////// Bull Bear Power Trend (BBPT)
  872. ///////////////////////////////////////////////
  873.  
  874.  
  875. BullTrend_hist = 0.0
  876. BearTrend_hist = 0.0
  877.  
  878. BullTrend = (close - ta.lowest(low, 50)) / ta.atr(5)
  879. BearTrend = (ta.highest(high, 50) - close) / ta.atr(5)
  880. BearTrend2 = -1 * BearTrend
  881.  
  882.  
  883.  
  884. Trend = BullTrend - BearTrend
  885.  
  886. if BullTrend < 2
  887. BullTrend_hist := BullTrend - 2
  888. BullTrend_hist
  889. //plot(BullTrend_hist, title='Bear Trend Hist', color=color.new(#FF0000, 0), linewidth=1, style=plot.style_columns)
  890.  
  891. if BearTrend2 > -2
  892. BearTrend_hist := BearTrend2 + 2
  893. BearTrend_hist
  894. //plot(BearTrend_hist, title='Bull Trend Hist', color=color.new(#008000, 0), linewidth=1, style=plot.style_columns)
  895.  
  896.  
  897. bbpt_long = bool(na)
  898. bbpt_short = bool(na)
  899. if bbpttype =="Follow Trend"
  900. bbpt_long := BearTrend_hist > 0 and Trend>=2
  901. bbpt_short := BullTrend_hist < 0 and Trend<=-2
  902. else if bbpttype == "Without Trend"
  903. bbpt_long := BearTrend_hist > 0
  904. bbpt_short := BullTrend_hist < 0
  905.  
  906.  
  907. ///////////////////////////////////////////////
  908. //////////// VWAP
  909. /////////////////////////////////////////////
  910.  
  911.  
  912. hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="---------------------VWAP Settings-------------------------")
  913. var anchor = input.string(defval = "Session", title="Anchor Period",
  914. options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="---------------------VWAP Settings-------------------------")
  915. srcvwap = input(title = "Source", defval = hlc3, group="---------------------VWAP Settings-------------------------")
  916. offsetvwap = input(0, title="Offset", group="---------------------VWAP Settings-------------------------")
  917.  
  918. showBand_1 = input(true, title="", group="Standard Deviation Bands Settings", inline="band_1")
  919. stdevMult_1 = input(1.0, title="Bands Multiplier #1", group="Standard Deviation Bands Settings", inline="band_1")
  920. showBand_2 = input(false, title="", group="Standard Deviation Bands Settings", inline="band_2")
  921. stdevMult_2 = input(2.0, title="Bands Multiplier #2", group="Standard Deviation Bands Settings", inline="band_2")
  922. showBand_3 = input(false, title="", group="Standard Deviation Bands Settings", inline="band_3")
  923. stdevMult_3 = input(3.0, title="Bands Multiplier #3", group="Standard Deviation Bands Settings", inline="band_3")
  924.  
  925. if barstate.islast and ta.cum(volume) == 0
  926. runtime.error("No volume is provided by the data vendor.")
  927.  
  928. new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
  929. new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
  930. new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
  931.  
  932. isNewPeriod = switch anchor
  933. "Earnings" => not na(new_earnings)
  934. "Dividends" => not na(new_dividends)
  935. "Splits" => not na(new_split)
  936. "Session" => timeframe.change("D")
  937. "Week" => timeframe.change("W")
  938. "Month" => timeframe.change("M")
  939. "Quarter" => timeframe.change("3M")
  940. "Year" => timeframe.change("12M")
  941. "Decade" => timeframe.change("12M") and year % 10 == 0
  942. "Century" => timeframe.change("12M") and year % 100 == 0
  943. => false
  944.  
  945. isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits"
  946. if na(srcvwap[1]) and not isEsdAnchor
  947. isNewPeriod := true
  948.  
  949. float vwapValue = na
  950. float upperBandValue1 = na
  951. float lowerBandValue1 = na
  952. float upperBandValue2 = na
  953. float lowerBandValue2 = na
  954. float upperBandValue3 = na
  955. float lowerBandValue3 = na
  956.  
  957. if not (hideonDWM and timeframe.isdwm)
  958. [_vwap, _stdevUpper, _] = ta.vwap(srcvwap, isNewPeriod, 1)
  959. vwapValue := _vwap
  960. stdevAbs = _stdevUpper - _vwap
  961. upperBandValue1 := _vwap + stdevAbs * stdevMult_1
  962. lowerBandValue1 := _vwap - stdevAbs * stdevMult_1
  963. upperBandValue2 := _vwap + stdevAbs * stdevMult_2
  964. lowerBandValue2 := _vwap - stdevAbs * stdevMult_2
  965. upperBandValue3 := _vwap + stdevAbs * stdevMult_3
  966. lowerBandValue3 := _vwap - stdevAbs * stdevMult_3
  967.  
  968. plot(switch_vwap? vwapValue:na, title="VWAP", color=#2962FF, offset=offsetvwap)
  969.  
  970.  
  971. long_vwap = close>vwapValue
  972. short_vwap = close < vwapValue
  973.  
  974.  
  975.  
  976.  
  977. ////////////////////////////////////////////////
  978. ////// Chandelier Exit
  979. ///////////////////////////////////////////////
  980.  
  981.  
  982. ChandelierE = "--------------Chandelier Exit--------------------"
  983.  
  984. ce_length = input(title='ATR Period', defval=22)
  985. ce_mult = input.float(title='ATR Multiplier', step=0.1, defval=3.0)
  986. showLabels = input(title='Show Buy/Sell Labels ?', defval=true)
  987. useClose = input(title='Use Close Price for Extremums ?', defval=true)
  988. highlightState = input(title='Highlight State ?', defval=true)
  989.  
  990. ce_atr = ce_mult * ta.atr(ce_length)
  991.  
  992. longStop = (useClose ? ta.highest(close, ce_length) : ta.highest(ce_length)) - ce_atr
  993. longStopPrev = nz(longStop[1], longStop)
  994. longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop
  995.  
  996. shortStop = (useClose ? ta.lowest(close, ce_length) : ta.lowest(ce_length)) + ce_atr
  997. shortStopPrev = nz(shortStop[1], shortStop)
  998. shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
  999.  
  1000. var int dir = 1
  1001. dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir
  1002.  
  1003.  
  1004. ce_long = dir == 1
  1005. ce_short = dir == -1
  1006.  
  1007. ////////////////////////////////////////////////
  1008. ////// SSL Channel
  1009. ///////////////////////////////////////////////
  1010.  
  1011.  
  1012. group_ssl = "------------SSL Channel-------------------"
  1013. SSLperiod = input(title='Period', defval=10, group=group_ssl)
  1014. SSLlen = input(title='Period', defval=10, group=group_ssl)
  1015. smaHigh = ta.sma(high, SSLlen)
  1016. smaLow = ta.sma(low, SSLlen)
  1017. Hlv = int(na)
  1018. Hlv := close > smaHigh ? 1 : close < smaLow ? -1 : Hlv[1]
  1019. sslDown = Hlv < 0 ? smaHigh : smaLow
  1020. sslUp = Hlv < 0 ? smaLow : smaHigh
  1021.  
  1022. ssl_long = sslUp>sslDown
  1023. ssl_short = sslUp<sslDown
  1024. ////////////////////////////////////////////////
  1025. ////// Chaikin Money Flow
  1026. ///////////////////////////////////////////////
  1027.  
  1028. group_chaikin = "--------------Chaiken Money Flow----------------"
  1029. chaiking_length = input.int(20, minval=1, group = group_chaikin )
  1030. ad = close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume
  1031. mf = math.sum(ad, chaiking_length) / math.sum(volume, chaiking_length)
  1032.  
  1033. chaikin_long = mf>0
  1034. chaikin_short = mf<0
  1035.  
  1036. ////////////////////////////////////////////////
  1037. ////// Vortex INdex
  1038. ///////////////////////////////////////////////
  1039.  
  1040. period_ = input.int(14, title="Length", minval=2, group='-------------------------Vortex Index-------------------------', inline = 'vi')
  1041. viupper = input.float(1.1, title="Upper band",group='-------------------------Vortex Index-------------------------', inline = 'vi')
  1042. vilower = input.float(0.9, title="Lower Band", group='-------------------------Vortex Index-------------------------', inline = 'vi')
  1043.  
  1044. VMP = math.sum( math.abs( high - low[1]), period_ )
  1045. VMM = math.sum( math.abs( low - high[1]), period_ )
  1046. STR = math.sum( ta.atr(1), period_ )
  1047. vip = VMP / STR
  1048. vim = VMM / STR
  1049. //plot(VIP, title="VI +", color=#2962FF)
  1050. //plot(VIM, title="VI -", color=#E91E63)
  1051.  
  1052.  
  1053.  
  1054. /////////////////////////////////////////////////
  1055. ////////Waddar Atar explosion (WAR)
  1056. //////////////////////////////////////////////////
  1057. group_wae = "-------------------Waddah Attar Explosion-----------------------"
  1058.  
  1059.  
  1060. wae_sensitivity = input(150, title="Sensitivity",group=group_wae)
  1061. wae_fastLength=input(20, title="FastEMA Length",group=group_wae)
  1062. wae_slowLength=input(40, title="SlowEMA Length",group=group_wae)
  1063. channelLength=input(20, title="BB Channel Length",group=group_wae)
  1064. wae_mult=input(2.0, title="BB Stdev Multiplier",group=group_wae)
  1065.  
  1066. deadzone = nz(ta.rma(ta.tr(true),100)) * 3.7
  1067.  
  1068. calc_macd(source, wae_fastLength, wae_slowLength) =>
  1069. fastMA = ta.ema(source, wae_fastLength)
  1070. slowMA = ta.ema(source, wae_slowLength)
  1071. fastMA - slowMA
  1072.  
  1073. calc_BBUpper(source, length, wae_mult) =>
  1074. basis = ta.sma(source, length)
  1075. dev = wae_mult * ta.stdev(source, length)
  1076. basis + dev
  1077.  
  1078. calc_BBLower(source, length, wae_mult) =>
  1079. basis = ta.sma(source, length)
  1080. dev = wae_mult * ta.stdev(source, length)
  1081. basis - dev
  1082.  
  1083. t1 = (calc_macd(close, wae_fastLength, wae_slowLength) - calc_macd(close[1], wae_fastLength, wae_slowLength))*wae_sensitivity
  1084.  
  1085. e1 = (calc_BBUpper(close, channelLength, wae_mult) - calc_BBLower(close, channelLength, wae_mult))
  1086.  
  1087. trendUp = (t1 >= 0) ? t1 : 0
  1088. trendDown = (t1 < 0) ? (-1*t1) : 0
  1089.  
  1090.  
  1091. wae_long = trendUp and trendUp >e1 and e1 > deadzone and trendUp>deadzone
  1092. wae_short = trendDown and trendDown >e1 and e1 > deadzone and trendDown>deadzone
  1093.  
  1094.  
  1095.  
  1096. /////////////////////////////////////////////////
  1097. ////////Volatility Oscillator
  1098. //////////////////////////////////////////////////
  1099. group_vo = "-------------------Volatility Oscillator-----------------------"
  1100. volength = input(100, group = group_vo)
  1101. spike = close - open
  1102. vox = ta.stdev(spike,volength)
  1103. voy = ta.stdev(spike,volength) * -1
  1104.  
  1105. vo_long = spike > vox
  1106. vo_short = spike < voy
  1107.  
  1108.  
  1109. //////////////////////////////////////////////////
  1110. ////////Damiani Volatmeter
  1111. //////////////////////////////////////////////////
  1112. int vis_atr = input.int(13,title="Vis ATR", group='-------------------------Damiani Volatmeter-------------------------', inline = '1')
  1113. int vis_std = input.int(20,title="Vis STD", group='-------------------------Damiani Volatmeter-------------------------', inline = '1')
  1114. int sed_atr = input.int(40,title="Sed ATR", group='-------------------------Damiani Volatmeter-------------------------', inline = '1')
  1115. int sed_std = input.int(100,title="SEd STD", group='-------------------------Damiani Volatmeter-------------------------', inline = '1')
  1116. float threshold_level = input.float(1.4,title="Threshold", group='-------------------------Damiani Volatmeter-------------------------', inline = '1')
  1117. bool lag_supressor = input.bool(true,title="Lag Supressor", group='-------------------------Damiani Volatmeter-------------------------', inline = '1')
  1118. lag_s_K = 0.5
  1119.  
  1120.  
  1121. vol = 0.0
  1122. s1=nz(vol[1], 0)
  1123. s3=nz(vol[3], 0)
  1124.  
  1125. vol := lag_supressor ? ta.atr(vis_atr) / ta.atr(sed_atr) + lag_s_K*(s1-s3) : ta.atr(vis_atr) / ta.atr(sed_atr)
  1126. anti_thres = ta.stdev(close, vis_std) / ta.stdev(close, sed_std)
  1127. t = threshold_level - anti_thres
  1128. vol_m = vol > t ? -1 : 0.03
  1129.  
  1130.  
  1131.  
  1132.  
  1133. //////////////////////////////////////////////
  1134. /////// MACD
  1135. /////////////////////////////////////////////
  1136.  
  1137. fast_length = input(title="Fast Length", defval=12,group='-------------------------MACD-------------------------')
  1138. slow_length = input(title="Slow Length", defval=26,group='-------------------------MACD-------------------------')
  1139. macdsrc = input(title="Source", defval=close,group='-------------------------MACD-------------------------')
  1140. signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9,group='-------------------------MACD-------------------------')
  1141. sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"],group='-------------------------MACD-------------------------')
  1142. sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"],group='-------------------------MACD-------------------------')
  1143.  
  1144. fast_ma = sma_source == "SMA" ? ta.sma(macdsrc, fast_length) : ta.ema(macdsrc, fast_length)
  1145. slow_ma = sma_source == "SMA" ? ta.sma(macdsrc, slow_length) : ta.ema(macdsrc, slow_length)
  1146. macdd = fast_ma - slow_ma
  1147. signal = sma_signal == "SMA" ? ta.sma(macdd, signal_length) : ta.ema(macdd, signal_length)
  1148. hist = macdd - signal
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154. /////////////////////////////////////////////
  1155. ///// Awesome Oscillator
  1156. ////////////////////////////////////////////
  1157.  
  1158.  
  1159. nLengthSlow = input(34, title="Length Slow")
  1160. nLengthFast = input(5, title="Length Fast")
  1161. reverse = input(false, title="Trade reverse")
  1162. xSMA1_hl2 = ta.sma(hl2, nLengthFast)
  1163. xSMA2_hl2 = ta.sma(hl2, nLengthSlow)
  1164. xSMA1_SMA2 = xSMA1_hl2 - xSMA2_hl2
  1165. xSMA_hl2 = ta.sma(xSMA1_SMA2, nLengthFast)
  1166. nRes = xSMA1_SMA2 - xSMA_hl2
  1167.  
  1168.  
  1169.  
  1170.  
  1171. //// zero line cross (standard code)
  1172. ao = ta.sma(hl2,5) - ta.sma(hl2,34)
  1173. diff = ao - ao[1]
  1174.  
  1175.  
  1176. ao_long = bool(na)
  1177. ao_short = bool(na)
  1178.  
  1179. if aotype == "AC Zero Line Cross"
  1180. ao_long := nRes > nRes[1] and nRes > 0
  1181. ao_short := nRes < nRes[1] and nRes < 0
  1182. else if aotype == "AC Momentum Bar"
  1183. ao_long := nRes > nRes[1]
  1184. ao_short := nRes < nRes[1]
  1185. else if aotype == "Zero Line Cross"
  1186. ao_long := ao > 0
  1187. ao_short := ao < 0
  1188.  
  1189.  
  1190.  
  1191.  
  1192. /////////////////////////////////////////////
  1193. ///// WolfPack ID
  1194. ////////////////////////////////////////////
  1195.  
  1196. wolfgroup = "-------------------Wolf Pack ID ---------------------"
  1197. input1 = input(title='Fast Length', group=wolfgroup,defval=3)
  1198. input2 = input(title='Slow Length',group=wolfgroup, defval=8)
  1199. pivR = input(title='Wolfpack Wave Pivot Lookback Right', group=wolfgroup,defval=1)
  1200. pivL = input(title='Wolfpack Wave Pivot Lookback Left',group=wolfgroup, defval=15)
  1201. fastmaa = ta.ema(close, input1)
  1202. fastmab = ta.ema(close, input2)
  1203. wolfsrc = close
  1204. bspread = (fastmaa - fastmab) * 1.001
  1205. adline = 0
  1206. m = bspread > 0 ? color.new(color.lime, 0) : color.new(color.red, 0)
  1207. wolfup = ta.rma(math.max(ta.change(wolfsrc), 0), 3)
  1208. wolfdown = ta.rma(-math.min(ta.change(wolfsrc), 0), 3)
  1209. lbR = input(title='Divergence Pivot Lookback Right',group=wolfgroup, defval=1)
  1210. lbL = input(title='Divergence Pivot Lookback Left', group=wolfgroup,defval=10)
  1211. rangeUpper = input(title='Max of Lookback Range',group=wolfgroup, defval=100)
  1212. rangeLower = input(title='Min of Lookback Range', group=wolfgroup,defval=2)
  1213.  
  1214.  
  1215. osc = bspread
  1216.  
  1217. _inRange(cond) =>
  1218. bars = ta.barssince(cond == true)
  1219. rangeLower <= bars and bars <= rangeUpper
  1220.  
  1221.  
  1222.  
  1223. wolf_long = bspread > 0
  1224. wolf_short = bspread < 0
  1225.  
  1226.  
  1227.  
  1228.  
  1229. /////////////////////////////////////////////
  1230. ///// BB Oscillator
  1231. ////////////////////////////////////////////
  1232. bbgroup = "-------------------Bollinger Band (BB) Oscillator ---------------------"
  1233.  
  1234. bbosc_length = input.int(20, minval=1,group=bbgroup)
  1235. bbosc_src = input(close, title='Source',group=bbgroup)
  1236. bbosc_mult = input.float(2.0, minval=0.001, maxval=50, title='StdDev',group=bbgroup)
  1237. bbosc_basis = ta.sma(bbosc_src, bbosc_length)
  1238. dlength = input.int(4, minval=1, title='Trigger Length',group=bbgroup)
  1239. bbosc_offset = input.int(0, 'Offset', minval=-500, maxval=500,group=bbgroup, tooltip = "Use Offset and Show Last to turn indicator into a widget.\nExample:\nOffset = 120\nShow Last = 100 ")
  1240. bbosc_last = input(0, 'Show Last',group=bbgroup)
  1241. bbosc_dev = bbosc_mult * ta.stdev(bbosc_src, bbosc_length)
  1242. bbosc_upper = bbosc_basis + bbosc_dev
  1243. bbosc_lower = bbosc_basis - bbosc_dev
  1244. upercent = (bbosc_upper - close) / (bbosc_upper + close / 2)
  1245. lpercent = (bbosc_lower - close) / (bbosc_lower + close / 2)
  1246. bpercent = (bbosc_basis - close) / (bbosc_basis + close / 2)
  1247. usmooth = ta.wma(upercent, 6)
  1248. lsmooth = ta.wma(lpercent, 6)
  1249. bsmooth = ta.wma(bpercent, 6)
  1250. d1 = ta.sma(bsmooth, 2)
  1251. j = (bsmooth + d1) * -1
  1252. d2 = ta.sma(j, dlength)
  1253.  
  1254.  
  1255.  
  1256. bbosc_long = bool(na)
  1257. bbosc_short = bool(na)
  1258.  
  1259.  
  1260. bbcycle = 0
  1261. bbup = ta.crossover(j, usmooth)
  1262. bbdown = ta.crossunder(j, lsmooth)
  1263. bbcycle := bbup ? 1 : bbdown ? -1 : bbcycle[1]
  1264.  
  1265. if bbtype == "Entering Lower/Upper Band"
  1266. bbosc_long := j > d2 and (j==lsmooth or j>lsmooth) and bbcycle==-1
  1267. bbosc_short:= j < d2 and (j==usmooth or j<usmooth) and bbcycle==1
  1268. else if bbtype == "Exiting Lower/Upper Band"
  1269. bbosc_long := j > d2 and (j>usmooth)
  1270. bbosc_short:= j < d2 and (j<lsmooth)
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277. //////////////////////////////////////////////
  1278. /////// Trend Meter
  1279. //////////////////////////////////////////////
  1280.  
  1281.  
  1282. ShowTrendBar = true
  1283.  
  1284. WTSetups = input.bool(true, 'Wave Trend Filtered by Trend', group='-------------------------Trend Meter-------------------------', inline = 'tm')
  1285.  
  1286. TMSetups = input.bool(true, 'All 3 Trend Meters Now Align', group='-------------------------Trend Meter-------------------------', inline = 'tm2')
  1287.  
  1288. MSBar1 = 'Trend Filter' // input(title= "1 - Wave Trend Signals", defval = "Trend Filter", options = ["N/A", "Trend Filter", "Filter X", "Filter X + Trend Filter"])
  1289.  
  1290.  
  1291. MSBar2 = 'Trend Filter' // input(title= "2 - Wave Trend Signals", defval = "Filter X", options = ["N/A", "Trend Filter", "Filter X", "Filter X + Trend Filter"])
  1292.  
  1293.  
  1294.  
  1295. TrendBar1 = input.string(title='Trend Meter 1', defval='MACD Crossover - Fast - 8, 21, 5', options=['MACD Crossover - 12, 26, 9', 'MACD Crossover - Fast - 8, 21, 5', 'Mom Dad Cross (Top Dog Trading)', 'RSI Signal Line Cross - RSI 13, Sig 21', 'RSI 13: > or < 50', 'RSI 5: > or < 50', 'Trend Candles', 'N/A'], group='Trend Meters') // "MA Crossover", "DAD Direction (Top Dog Trading)",
  1296.  
  1297. TrendBar2 = input.string(title='Trend Meter 2', defval='RSI 13: > or < 50', options=['MACD Crossover - 12, 26, 9', 'MACD Crossover - Fast - 8, 21, 5', 'Mom Dad Cross (Top Dog Trading)', 'RSI Signal Line Cross - RSI 13, Sig 21', 'RSI 13: > or < 50', 'RSI 5: > or < 50', 'Trend Candles', 'N/A'], group='Trend Meters') // "MA Crossover", "DAD Direction (Top Dog Trading)",
  1298.  
  1299. TrendBar3 = input.string(title='Trend Meter 3', defval='RSI 5: > or < 50', options=['MACD Crossover - 12, 26, 9', 'MACD Crossover - Fast - 8, 21, 5', 'Mom Dad Cross (Top Dog Trading)', 'RSI Signal Line Cross - RSI 13, Sig 21', 'RSI 13: > or < 50', 'RSI 5: > or < 50', 'Trend Candles', 'N/A'], group='Trend Meters') // "MA Crossover", "DAD Direction (Top Dog Trading)",
  1300.  
  1301. TrendBar4 = input.string(title='Trend Bar 1', defval='MA Crossover', options=['MA Crossover', 'MA Direction - Fast MA - TB1', 'MA Direction - Slow MA - TB1', 'N/A'], group='Trend Bars') // "MACD Crossover - 12, 26 9", "MACD Crossover - Fast - 8, 21, 5", "DAD Direction (Top Dog Trading)",
  1302.  
  1303. TrendBar5 = input.string(title='Trend Bar 2', defval='MA Crossover', options=['MA Crossover', 'MA Direction - Fast MA - TB2', 'MA Direction - Slow MA - TB2', 'N/A'], group='Trend Bars') // "MACD Crossover - 12, 26 9", "MACD Crossover - Fast - 8, 21, 5", "DAD Direction (Top Dog Trading)",
  1304.  
  1305.  
  1306. ////////////////Signals - Wave Trend/////////////////////////////////////////////////////////////////////////////////////////////////
  1307.  
  1308.  
  1309. // Wave Trend - RSI
  1310.  
  1311. RSIMC = ta.rsi(close, 14)
  1312.  
  1313. // Wave Trend
  1314.  
  1315. ap = hlc3 // input(hlc3, "Wave Trend - Source")
  1316. n1 = 9 //input(9, "Wave Trend - WT Channel Length")
  1317. n2 = 12 // input(12, "Wave Trend - WT Average Length")
  1318. esa = ta.ema(ap, n1)
  1319. de = ta.ema(math.abs(ap - esa), n1)
  1320. ci = (ap - esa) / (0.015 * de)
  1321. tci = ta.ema(ci, n2)
  1322. wt11 = tci
  1323. wt22 = ta.sma(wt11, 3)
  1324.  
  1325. // Wave Trend - Overbought & Oversold lines
  1326.  
  1327. obLevel2 = 60 // input( 60, "Wave Trend - WT Very Overbought")
  1328. obLevel = 50 // input( 50, "Wave Trend - WT Overbought")
  1329. osLevel = -50 // input(-50, "Wave Trend - WT Oversold")
  1330. osLevel2 = -60 // input(-60, "Wave Trend - WT Very Oversold")
  1331.  
  1332. // Wave Trend - Conditions
  1333.  
  1334. WTCross = ta.cross(wt11, wt22)
  1335. WTCrossUp = wt22 - wt11 <= 0
  1336. WTCrossDown = wt22 - wt11 >= 0
  1337. WTOverSold = wt22 <= osLevel2
  1338. WTOverBought = wt22 >= obLevel2
  1339.  
  1340.  
  1341. // MA Inputs
  1342.  
  1343. MA1_Length = input.int(5, title='Fast MA', minval=1, group='Trend Bar 1 - Settings', inline='TB1 Fast')
  1344. MA1_Type = input.string(title='', defval='EMA', options=['EMA', 'SMA'], group='Trend Bar 1 - Settings', inline='TB1 Fast')
  1345.  
  1346. MA2_Length = input.int(11, title='Slow MA', minval=1, group='Trend Bar 1 - Settings', inline='TB1 Slow')
  1347. MA2_Type = input.string(title='', defval='EMA', options=['EMA', 'SMA'], group='Trend Bar 1 - Settings', inline='TB1 Slow')
  1348.  
  1349. MA3_Length = input.int(9, title='Fast MA', minval=1, group='Trend Bar 2 - Settings', inline='TB2 Fast')
  1350. MA3_Type = input.string(title='', defval='EMA', options=['EMA', 'SMA'], group='Trend Bar 2 - Settings', inline='TB2 Fast')
  1351.  
  1352. MA4_Length = input.int(21, title='Slow MA', minval=1, group='Trend Bar 2 - Settings', inline='TB2 Slow')
  1353. MA4_Type = input.string(title='', defval='SMA', options=['EMA', 'SMA'], group='Trend Bar 2 - Settings', inline='TB2 Slow')
  1354.  
  1355.  
  1356. // MA Calculations
  1357.  
  1358. Close = request.security(syminfo.tickerid, timeframe.period, close, lookahead=barmerge.lookahead_on)
  1359.  
  1360.  
  1361. MA1 = if MA1_Type == 'SMA'
  1362. ta.sma(Close, MA1_Length)
  1363. else
  1364. ta.ema(Close, MA1_Length)
  1365.  
  1366.  
  1367. MA2 = if MA2_Type == 'SMA'
  1368. ta.sma(Close, MA2_Length)
  1369. else
  1370. ta.ema(Close, MA2_Length)
  1371.  
  1372.  
  1373. MA3 = if MA3_Type == 'SMA'
  1374. ta.sma(Close, MA3_Length)
  1375. else
  1376. ta.ema(Close, MA3_Length)
  1377.  
  1378.  
  1379. MA4 = if MA4_Type == 'SMA'
  1380. ta.sma(Close, MA4_Length)
  1381. else
  1382. ta.ema(Close, MA4_Length)
  1383.  
  1384.  
  1385. // MA Crossover Condition
  1386.  
  1387. MACrossover1 = MA1 > MA2 ? 1 : 0
  1388.  
  1389. MACrossover2 = MA3 > MA4 ? 1 : 0
  1390.  
  1391. // MA Direction Condition
  1392.  
  1393. MA1Direction = MA1 > MA1[1] ? 1 : 0
  1394.  
  1395. MA2Direction = MA2 > MA2[1] ? 1 : 0
  1396.  
  1397. MA3Direction = MA3 > MA3[1] ? 1 : 0
  1398.  
  1399. MA4Direction = MA4 > MA4[1] ? 1 : 0
  1400.  
  1401. // MA Direction Change Condition
  1402.  
  1403. MA1PositiveDirectionChange = MA1Direction and not MA1Direction[1] ? 1 : 0
  1404.  
  1405. MA2PositiveDirectionChange = MA2Direction and not MA2Direction[1] ? 1 : 0
  1406.  
  1407. MA3PositiveDirectionChange = MA3Direction and not MA3Direction[1] ? 1 : 0
  1408.  
  1409. MA4PositiveDirectionChange = MA4Direction and not MA4Direction[1] ? 1 : 0
  1410.  
  1411.  
  1412. MA1NegativeDirectionChange = not MA1Direction and MA1Direction[1] ? 1 : 0
  1413.  
  1414. MA2NegativeDirectionChange = not MA2Direction and MA2Direction[1] ? 1 : 0
  1415.  
  1416. MA3NegativeDirectionChange = not MA3Direction and MA3Direction[1] ? 1 : 0
  1417.  
  1418. MA4NegativeDirectionChange = not MA4Direction and MA4Direction[1] ? 1 : 0
  1419.  
  1420.  
  1421. // MACD and MOM & DAD - Top Dog Trading
  1422.  
  1423. // Standard MACD Calculations
  1424.  
  1425. MACDfastMA = 12
  1426. MACDslowMA = 26
  1427. MACDsignalSmooth = 9
  1428.  
  1429.  
  1430. MACDLine = ta.ema(close, MACDfastMA) - ta.ema(close, MACDslowMA)
  1431.  
  1432. SignalLine = ta.ema(MACDLine, MACDsignalSmooth)
  1433.  
  1434. MACDHistogram = MACDLine - SignalLine
  1435.  
  1436.  
  1437. // MACD- Background Color Change Condition
  1438.  
  1439. MACDHistogramCross = MACDHistogram > 0 ? 1 : 0
  1440.  
  1441. MACDLineOverZero = MACDLine > 0 ? 1 : 0
  1442.  
  1443. MACDLineOverZeroandHistogramCross = MACDHistogramCross and MACDLineOverZero ? 1 : 0
  1444.  
  1445. MACDLineUnderZeroandHistogramCross = not MACDHistogramCross and not MACDLineOverZero ? 1 : 0
  1446.  
  1447.  
  1448. // Fast MACD Calculations
  1449.  
  1450. FastMACDfastMA = 8
  1451. FastMACDslowMA = 21
  1452. FastMACDsignalSmooth = 5
  1453.  
  1454.  
  1455. FastMACDLine = ta.ema(close, FastMACDfastMA) - ta.ema(close, FastMACDslowMA)
  1456.  
  1457. FastSignalLine = ta.ema(FastMACDLine, FastMACDsignalSmooth)
  1458.  
  1459. FastMACDHistogram = FastMACDLine - FastSignalLine
  1460.  
  1461. // Fast MACD- Background Color Change Condition
  1462.  
  1463. FastMACDHistogramCross = FastMACDHistogram > 0 ? 1 : 0
  1464.  
  1465. FastMACDLineOverZero = FastMACDLine > 0 ? 1 : 0
  1466.  
  1467. FastMACDLineOverZeroandHistogramCross = FastMACDHistogramCross and FastMACDLineOverZero ? 1 : 0
  1468.  
  1469. FastMACDLineUnderZeroandHistogramCross = not FastMACDHistogramCross and not FastMACDLineOverZero ? 1 : 0
  1470.  
  1471.  
  1472. // Top Dog Trading - Mom Dad Calculations
  1473.  
  1474. TopDog_Fast_MA = 5
  1475. TopDog_Slow_MA = 20
  1476. TopDog_Sig = 30
  1477.  
  1478.  
  1479. TopDogMom = ta.ema(close, TopDog_Fast_MA) - ta.ema(close, TopDog_Slow_MA)
  1480.  
  1481. TopDogDad = ta.ema(TopDogMom, TopDog_Sig)
  1482.  
  1483. // Top Dog Dad - Background Color Change Condition
  1484.  
  1485. TopDogDadDirection = TopDogDad > TopDogDad[1] ? 1 : 0
  1486.  
  1487. TopDogMomOverDad = TopDogMom > TopDogDad ? 1 : 0
  1488.  
  1489. TopDogMomOverZero = TopDogMom > 0 ? 1 : 0
  1490.  
  1491. TopDogDadDirectandMomOverZero = TopDogDadDirection and TopDogMomOverZero ? 1 : 0
  1492.  
  1493. TopDogDadDirectandMomUnderZero = not TopDogDadDirection and not TopDogMomOverZero ? 1 : 0
  1494.  
  1495.  
  1496.  
  1497. ////// Trend Barmeter Calculations //////
  1498.  
  1499.  
  1500. haclose_tm = ohlc4
  1501. haopen_tm = 0.0
  1502. haopen_tm := na(haopen_tm[1]) ? (open + close) / 2 : (haopen_tm[1] + haclose_tm[1]) / 2
  1503. //hahigh = max(high, max(haopen_tm, haclose_tm))
  1504. //halow = min(low, min(haopen_tm, haclose_tm))
  1505.  
  1506. ccolor = haclose_tm - haopen_tm > 0 ? 1 : 0
  1507.  
  1508. inside6 = haopen_tm <= math.max(haopen_tm[6], haclose_tm[6]) and haopen_tm >= math.min(haopen_tm[6], haclose_tm[6]) and haclose_tm <= math.max(haopen_tm[6], haclose_tm[6]) and haclose_tm >= math.min(haopen_tm[6], haclose_tm[6]) ? 1 : 0
  1509.  
  1510. inside5 = haopen_tm <= math.max(haopen_tm[5], haclose_tm[5]) and haopen_tm >= math.min(haopen_tm[5], haclose_tm[5]) and haclose_tm <= math.max(haopen_tm[5], haclose_tm[5]) and haclose_tm >= math.min(haopen_tm[5], haclose_tm[5]) ? 1 : 0
  1511.  
  1512. inside4 = haopen_tm <= math.max(haopen_tm[4], haclose_tm[4]) and haopen_tm >= math.min(haopen_tm[4], haclose_tm[4]) and haclose_tm <= math.max(haopen_tm[4], haclose_tm[4]) and haclose_tm >= math.min(haopen_tm[4], haclose_tm[4]) ? 1 : 0
  1513.  
  1514. inside3 = haopen_tm <= math.max(haopen_tm[3], haclose_tm[3]) and haopen_tm >= math.min(haopen_tm[3], haclose_tm[3]) and haclose_tm <= math.max(haopen_tm[3], haclose_tm[3]) and haclose_tm >= math.min(haopen_tm[3], haclose_tm[3]) ? 1 : 0
  1515.  
  1516. inside2 = haopen_tm <= math.max(haopen_tm[2], haclose_tm[2]) and haopen_tm >= math.min(haopen_tm[2], haclose_tm[2]) and haclose_tm <= math.max(haopen_tm[2], haclose_tm[2]) and haclose_tm >= math.min(haopen_tm[2], haclose_tm[2]) ? 1 : 0
  1517.  
  1518. inside1 = haopen_tm <= math.max(haopen_tm[1], haclose_tm[1]) and haopen_tm >= math.min(haopen_tm[1], haclose_tm[1]) and haclose_tm <= math.max(haopen_tm[1], haclose_tm[1]) and haclose_tm >= math.min(haopen_tm[1], haclose_tm[1]) ? 1 : 0
  1519.  
  1520.  
  1521. colorvalue = inside6 ? ccolor[6] : inside5 ? ccolor[5] : inside4 ? ccolor[4] : inside3 ? ccolor[3] : inside2 ? ccolor[2] : inside1 ? ccolor[1] : ccolor
  1522.  
  1523. TrendBarTrend_Candle_Color = colorvalue ? #288a75 : color.red
  1524.  
  1525. TrendBarTrend_Candle = colorvalue ? 1 : 0
  1526.  
  1527.  
  1528.  
  1529.  
  1530. // RSI 5 Trend Barmeter Calculations
  1531.  
  1532. RSI5 = ta.rsi(close, 5)
  1533.  
  1534. RSI5Above50 = RSI5 > 50 ? 1 : 0
  1535.  
  1536. RSI5Color = RSI5Above50 ? #288a75 : color.red
  1537.  
  1538. TrendBarRSI5Color = RSI5Above50 ? #288a75 : color.red
  1539.  
  1540.  
  1541. // RSI 5 Trend Barmeter Calculations
  1542.  
  1543. RSI13 = ta.rsi(close, 13)
  1544.  
  1545.  
  1546. // Linear Regression Calculation For RSI Signal Line
  1547.  
  1548. SignalLineLength1 = 21
  1549.  
  1550. x = bar_index
  1551. y = RSI13
  1552. x_ = ta.sma(x, SignalLineLength1)
  1553. y_ = ta.sma(y, SignalLineLength1)
  1554. mx = ta.stdev(x, SignalLineLength1)
  1555. my = ta.stdev(y, SignalLineLength1)
  1556. c = ta.correlation(x, y, SignalLineLength1)
  1557. slope = c * (my / mx)
  1558. inter = y_ - slope * x_
  1559. LinReg1 = x * slope + inter
  1560.  
  1561.  
  1562. RSISigDirection = LinReg1 > LinReg1[1] ? 1 : 0
  1563.  
  1564. RSISigCross = RSI13 > LinReg1 ? 1 : 0
  1565.  
  1566. RSI13Above50 = RSI13 > 50 ? 1 : 0
  1567.  
  1568.  
  1569. // Trend Barmeter Color Calculation
  1570.  
  1571. RSI13Color = RSI13Above50 ? #288a75 : color.red
  1572.  
  1573. TrendBarRSI13Color = RSI13Above50 ? #288a75 : color.red
  1574.  
  1575. TrendBarRSISigCrossColor = RSISigCross ? #288a75 : color.red
  1576.  
  1577. TrendBarMACDColor = MACDHistogramCross ? #288a75 : color.red
  1578.  
  1579. TrendBarFastMACDColor = FastMACDHistogramCross ? #288a75 : color.red
  1580.  
  1581. TrendBarMACrossColor = MACrossover1 ? #288a75 : color.red
  1582.  
  1583. TrendBarMomOverDadColor = TopDogMomOverDad ? #288a75 : color.red
  1584.  
  1585. TrendBarDadDirectionColor = TopDogDadDirection ? #288a75 : color.red
  1586.  
  1587.  
  1588. TrendBar1Result = TrendBar1 == 'MA Crossover' ? MACrossover1 : TrendBar1 == 'MACD Crossover - 12, 26, 9' ? MACDHistogramCross : TrendBar1 == 'MACD Crossover - Fast - 8, 21, 5' ? FastMACDHistogramCross : TrendBar1 == 'Mom Dad Cross (Top Dog Trading)' ? TopDogMomOverDad : TrendBar1 == 'DAD Direction (Top Dog Trading)' ? TopDogDadDirection : TrendBar1 == 'RSI Signal Line Cross - RSI 13, Sig 21' ? RSISigCross : TrendBar1 == 'RSI 5: > or < 50' ? RSI5Above50 : TrendBar1 == 'RSI 13: > or < 50' ? RSI13Above50 : TrendBar1 == 'Trend Candles' ? TrendBarTrend_Candle : na
  1589.  
  1590. TrendBar2Result = TrendBar2 == 'MA Crossover' ? MACrossover1 : TrendBar2 == 'MACD Crossover - 12, 26, 9' ? MACDHistogramCross : TrendBar2 == 'MACD Crossover - Fast - 8, 21, 5' ? FastMACDHistogramCross : TrendBar2 == 'Mom Dad Cross (Top Dog Trading)' ? TopDogMomOverDad : TrendBar2 == 'DAD Direction (Top Dog Trading)' ? TopDogDadDirection : TrendBar2 == 'RSI Signal Line Cross - RSI 13, Sig 21' ? RSISigCross : TrendBar2 == 'RSI 5: > or < 50' ? RSI5Above50 : TrendBar2 == 'RSI 13: > or < 50' ? RSI13Above50 : TrendBar2 == 'Trend Candles' ? TrendBarTrend_Candle : na
  1591.  
  1592. TrendBar3Result = TrendBar3 == 'MA Crossover' ? MACrossover1 : TrendBar3 == 'MACD Crossover - 12, 26, 9' ? MACDHistogramCross : TrendBar3 == 'MACD Crossover - Fast - 8, 21, 5' ? FastMACDHistogramCross : TrendBar3 == 'Mom Dad Cross (Top Dog Trading)' ? TopDogMomOverDad : TrendBar3 == 'DAD Direction (Top Dog Trading)' ? TopDogDadDirection : TrendBar3 == 'RSI Signal Line Cross - RSI 13, Sig 21' ? RSISigCross : TrendBar3 == 'RSI 5: > or < 50' ? RSI5Above50 : TrendBar3 == 'RSI 13: > or < 50' ? RSI13Above50 : TrendBar3 == 'Trend Candles' ? TrendBarTrend_Candle : na
  1593.  
  1594.  
  1595. TrendBars2Positive = TrendBar1Result and TrendBar2Result or TrendBar1Result and TrendBar3Result or TrendBar2Result and TrendBar3Result ? 1 : 0
  1596.  
  1597. TrendBars2Negative = not TrendBar1Result and not TrendBar2Result or not TrendBar1Result and not TrendBar3Result or not TrendBar2Result and not TrendBar3Result ? 1 : 0
  1598.  
  1599.  
  1600. TrendBars3Positive = TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0
  1601.  
  1602. TrendBars3Negative = not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0
  1603.  
  1604. FilterXUp = FastMACDHistogramCross and ta.ema(close, 15) > ta.ema(close, 15)[1]
  1605.  
  1606. FilterXDown = not FastMACDHistogramCross and ta.ema(close, 15) < ta.ema(close, 15)[1]
  1607.  
  1608.  
  1609.  
  1610. TrendFilterPlus = ta.ema(close, 15) > ta.ema(close, 20) and ta.ema(close, 20) > ta.ema(close, 30) and ta.ema(close, 30) > ta.ema(close, 40) and ta.ema(close, 40) > ta.ema(close, 50) ? 1 : 0
  1611.  
  1612. TrendFilterMinus = ta.ema(close, 15) < ta.ema(close, 20) and ta.ema(close, 20) < ta.ema(close, 30) and ta.ema(close, 30) < ta.ema(close, 40) and ta.ema(close, 40) < ta.ema(close, 50) ? 1 : 0
  1613.  
  1614.  
  1615.  
  1616.  
  1617. MSBar1PositiveWaveTrendSignal = MSBar1 == 'Filter X' ? FilterXUp and WTCross and WTCrossUp : MSBar1 == 'Trend Filter' ? TrendFilterPlus and WTCross and WTCrossUp : MSBar1 == 'Filter X + Trend Filter' ? FilterXUp and TrendFilterPlus and WTCross and WTCrossUp : WTCross and WTCrossUp
  1618. MSBar1NegativeWaveTrendSignal = MSBar1 == 'Filter X' ? FilterXDown and WTCross and WTCrossDown : MSBar1 == 'Trend Filter' ? TrendFilterMinus and WTCross and WTCrossDown : MSBar1 == 'Filter X + Trend Filter' ? FilterXDown and TrendFilterMinus and WTCross and WTCrossDown : WTCross and WTCrossDown
  1619.  
  1620. MSBar2PositiveWaveTrendSignal = MSBar2 == 'Filter X' ? FilterXUp and WTCross and WTCrossUp : MSBar2 == 'Trend Filter' ? TrendFilterPlus and WTCross and WTCrossUp : MSBar2 == 'Filter X + Trend Filter' ? FilterXUp and TrendFilterPlus and WTCross and WTCrossUp : WTCross and WTCrossUp
  1621. MSBar2NegativeWaveTrendSignal = MSBar2 == 'Filter X' ? FilterXDown and WTCross and WTCrossDown : MSBar2 == 'Trend Filter' ? TrendFilterMinus and WTCross and WTCrossDown : MSBar2 == 'Filter X + Trend Filter' ? FilterXDown and TrendFilterMinus and WTCross and WTCrossDown : WTCross and WTCrossDown
  1622.  
  1623.  
  1624. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1625.  
  1626. BackgroundColorChangePositive = TrendBars3Positive and not TrendBars3Positive[1]
  1627. BackgroundColorChangeNegative = TrendBars3Negative and not TrendBars3Negative[1]
  1628.  
  1629. // Signals Color Calculations
  1630.  
  1631. MSBar1Color = MSBar1PositiveWaveTrendSignal ? #288a75 : MSBar1NegativeWaveTrendSignal ? color.red : na
  1632.  
  1633. MSBar2Color = BackgroundColorChangePositive ? #288a75 : BackgroundColorChangeNegative ? color.red : na
  1634.  
  1635.  
  1636. // Trend Barmeter Color Assignments
  1637.  
  1638. TrendBar1Color = TrendBar1 == 'N/A' ? na : TrendBar1 == 'MACD Crossover - 12, 26, 9' ? TrendBarMACDColor : TrendBar1 == 'MACD Crossover - Fast - 8, 21, 5' ? TrendBarFastMACDColor : TrendBar1 == 'Mom Dad Cross (Top Dog Trading)' ? TrendBarMomOverDadColor : TrendBar1 == 'DAD Direction (Top Dog Trading)' ? TrendBarDadDirectionColor : TrendBar1 == 'RSI Signal Line Cross - RSI 13, Sig 21' ? TrendBarRSISigCrossColor : TrendBar1 == 'RSI 5: > or < 50' ? TrendBarRSI5Color : TrendBar1 == 'RSI 13: > or < 50' ? TrendBarRSI13Color : TrendBar1 == 'Trend Candles' ? TrendBarTrend_Candle_Color : TrendBar1 == 'MA Crossover' ? TrendBarMACrossColor : na
  1639.  
  1640. TrendBar2Color = TrendBar2 == 'N/A' ? na : TrendBar2 == 'MACD Crossover - 12, 26, 9' ? TrendBarMACDColor : TrendBar2 == 'MACD Crossover - Fast - 8, 21, 5' ? TrendBarFastMACDColor : TrendBar2 == 'Mom Dad Cross (Top Dog Trading)' ? TrendBarMomOverDadColor : TrendBar2 == 'DAD Direction (Top Dog Trading)' ? TrendBarDadDirectionColor : TrendBar2 == 'RSI Signal Line Cross - RSI 13, Sig 21' ? TrendBarRSISigCrossColor : TrendBar2 == 'RSI 5: > or < 50' ? TrendBarRSI5Color : TrendBar2 == 'RSI 13: > or < 50' ? TrendBarRSI13Color : TrendBar2 == 'Trend Candles' ? TrendBarTrend_Candle_Color : TrendBar2 == 'MA Crossover' ? TrendBarMACrossColor : na
  1641.  
  1642. TrendBar3Color = TrendBar3 == 'N/A' ? na : TrendBar3 == 'MACD Crossover - 12, 26, 9' ? TrendBarMACDColor : TrendBar3 == 'MACD Crossover - Fast - 8, 21, 5' ? TrendBarFastMACDColor : TrendBar3 == 'Mom Dad Cross (Top Dog Trading)' ? TrendBarMomOverDadColor : TrendBar3 == 'DAD Direction (Top Dog Trading)' ? TrendBarDadDirectionColor : TrendBar3 == 'RSI Signal Line Cross - RSI 13, Sig 21' ? TrendBarRSISigCrossColor : TrendBar3 == 'RSI 5: > or < 50' ? TrendBarRSI5Color : TrendBar3 == 'RSI 13: > or < 50' ? TrendBarRSI13Color : TrendBar3 == 'Trend Candles' ? TrendBarTrend_Candle_Color : TrendBar3 == 'MA Crossover' ? TrendBarMACrossColor : na
  1643.  
  1644.  
  1645. CrossoverType2 = TrendBar4 == 'DAD Direction (Top Dog Trading)' ? TopDogDadDirection : TrendBar4 == 'MACD Crossover' ? MACDHistogramCross : TrendBar4 == 'MA Direction - Fast MA - TB1' ? MA1Direction : TrendBar4 == 'MA Direction - Slow MA - TB1' ? MA2Direction : MACrossover1
  1646.  
  1647. color_1 = color.new(color.green, 15)
  1648. color_2 = color.new(color.red, 20)
  1649. TrendBar4Color1 = TrendBar4 == 'N/A' ? na : CrossoverType2 ? color_1 : color_2
  1650.  
  1651. // TrendBar4Color2 = TrendBar4=="N/A" ? na : TrendBar4=="DAD Direction (Top Dog Trading)" and TopDogDadDirectandMomOverZero ? color(green, 70) : TrendBar4=="DAD Direction (Top Dog Trading)" and TopDogDadDirectandMomUnderZero ? color(red, 70) : TrendBar4=="MACD Crossover - 12, 26, 9" and MACDLineOverZeroandHistogramCross ? color(green, 70) : TrendBar4=="MACD Crossover - 12, 26, 9" and MACDLineUnderZeroandHistogramCross ? color(red, 70) : TrendBar4=="MA Crossover" and CrossoverType2 ? color(green, 40) : TrendBar4=="MA Crossover" and not CrossoverType2 ? color(red, 40) : TrendBar4=="MA Direction - Fast MA" and CrossoverType2 ? color(green, 40) : TrendBar4=="MA Direction - Fast MA" and not CrossoverType2 ? color(red, 40) : na
  1652.  
  1653.  
  1654. CrossoverType3 = TrendBar5 == 'DAD Direction (Top Dog Trading)' ? TopDogDadDirection : TrendBar5 == 'MACD Crossover' ? MACDHistogramCross : TrendBar5 == 'MA Direction - Fast MA - TB2' ? MA3Direction : TrendBar5 == 'MA Direction - Slow MA - TB2' ? MA4Direction : MACrossover2
  1655.  
  1656. color_3 = color.new(color.green, 15)
  1657. color_4 = color.new(color.red, 20)
  1658. TrendBar5Color1 = TrendBar5 == 'N/A' ? na : CrossoverType3 ? color_3 : color_4
  1659.  
  1660. // TrendBar5Color2 = TrendBar5=="N/A" ? na : TrendBar5=="DAD Direction (Top Dog Trading)" and TopDogDadDirectandMomOverZero ? color(green, 70) : TrendBar5=="DAD Direction (Top Dog Trading)" and TopDogDadDirectandMomUnderZero ? color(red, 70) : TrendBar5=="MACD Crossover - 12, 26, 9" and MACDLineOverZeroandHistogramCross ? color(green, 70) : TrendBar5=="MACD Crossover - 12, 26, 9" and MACDLineUnderZeroandHistogramCross ? color(red, 70) : TrendBar5=="MA Crossover" and CrossoverType3 ? color(green, 40) : TrendBar5=="MA Crossover" and not CrossoverType3 ? color(red, 40) : TrendBar5=="MA Direction - Fast MA" and CrossoverType3 ? color(green, 40) : TrendBar5=="MA Direction - Fast MA" and not CrossoverType3 ? color(red, 40) : na
  1661.  
  1662.  
  1663.  
  1664. TrendBar3BarsSame = TrendBars3Positive ? color.green : TrendBars3Negative ? color.red : na
  1665.  
  1666. TrendMetersNoLongerAlign = (not TrendBars3Positive or not TrendBars3Negative) and TrendBars3Positive[1] or (not TrendBars3Positive or not TrendBars3Negative) and TrendBars3Negative[1]
  1667.  
  1668. // alertcondition(TrendMetersNoLongerAlign, title='3 Trend Meters No Longer Align', message='3 Trend Meters No Longer Align - Trend Meter')
  1669.  
  1670.  
  1671. RapidColorChangePositive = TrendBars3Positive and (TrendBars3Negative[1] or TrendBars3Negative[2])
  1672. RapidColorChangeNegative = TrendBars3Negative and (TrendBars3Positive[1] or TrendBars3Positive[2])
  1673.  
  1674.  
  1675. MaxValueMACrossUp = ta.crossover(ta.ema(Close, 5), ta.ema(Close, 11))
  1676. MaxValueMACrossDown = ta.crossunder(ta.ema(Close, 5), ta.ema(Close, 11))
  1677.  
  1678. TB1MACrossUp = ta.crossover(MA1, MA2)
  1679. TB1MACrossDown = ta.crossunder(MA1, MA2)
  1680.  
  1681.  
  1682.  
  1683. TB2MACrossUp = ta.crossover(MA3, MA4)
  1684. TB2MACrossDown = ta.crossunder(MA3, MA4)
  1685.  
  1686.  
  1687. TB1Green = MA1 > MA2
  1688. TB1Red = MA1 < MA2
  1689.  
  1690. TB2Green = MA3 > MA4
  1691. TB2Red = MA3 < MA4
  1692.  
  1693. TB12Green = TB1Green and TB2Green and (TB1MACrossUp or TB2MACrossUp)
  1694. TB12Red = TB1Red and TB2Red and (TB1MACrossDown or TB2MACrossDown)
  1695.  
  1696.  
  1697.  
  1698. /////////////////////////////////
  1699. /////// Stochastic
  1700. /////////////////////////////////
  1701. groupname = "==================Stochastic=================="
  1702. len = input.int(14, minval=1, title="Length",group=groupname)
  1703. smoothK = input.int(3, minval=1, title="K Smoothing",group=groupname)
  1704. smoothD = input.int(3, minval=1, title="D Smoothing",group=groupname)
  1705. upLine = input.int(80, minval=50, maxval=90, title="Overbought level",group=groupname)
  1706. lowLine = input.int(20, minval=10, maxval=50, title="Oversold level",group=groupname)
  1707. // sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?")
  1708. // sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?")
  1709. // sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?")
  1710.  
  1711.  
  1712. //Resolutioon for MTF
  1713. resstoch = timeframe.period
  1714. //Stoch formula
  1715. kk = ta.sma(ta.stoch(close, high, low, len), smoothK)
  1716. dd = ta.sma(kk, smoothD)
  1717. outK = request.security(syminfo.tickerid, resstoch, kk)
  1718. outD = request.security(syminfo.tickerid, resstoch, dd)
  1719.  
  1720. //definitions for Cross
  1721. aboveLine = outK > upLine ? 1 : 0
  1722. belowLine = outK < lowLine ? 1 : 0
  1723. stoch_long = bool (na)
  1724. stoch_short = bool (na)
  1725. if stochtype == "CrossOver"
  1726. stoch_long := (outK[1] < outD[1] and outK > outD) ? 1 : 0
  1727. stoch_short := (outK[1] > outD[1] and outK < outD) ? 1 : 0
  1728. else if stochtype == "CrossOver in OB & OS levels"
  1729. stoch_long := (outK[1] < outD[1] and outK[1] < lowLine[1]) and (outK > outD) and outK > lowLine? 1 : 0
  1730. stoch_short := (outK[1] > outD[1] and outK[1] > upLine[1]) and (outK < outD) and outK < upLine? 1 : 0
  1731. else if stochtype == "%K above/below %D"
  1732. stoch_long := outK > outD
  1733. stoch_short := outK < outD
  1734.  
  1735.  
  1736.  
  1737.  
  1738. ///////////////////////////////////////////////
  1739. ///////RSI
  1740. ///////////////////////////////////////////////
  1741.  
  1742.  
  1743.  
  1744. rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="---------------------RSI Settings---------------------")
  1745. rsiSourceInput = input.source(close, "Source", group="---------------------RSI Settings---------------------")
  1746. maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="---------------------RSI Settings---------------------")
  1747. rsi_upper = input.int(defval=80, title='Overbought Zone', group="---------------------RSI Settings---------------------", inline='zone')
  1748. rsi_lower = input.int(defval=20, title='Oversold Zone', group="---------------------RSI Settings---------------------", inline='zone')
  1749.  
  1750. respectrsilevel = input.int(defval=50, minval=1, title='RSI MidLine', group="---------------------RSI Settings---------------------")
  1751. maLengthInput = input.int(14, title="MA Length", group="---------------------RSI Settings---------------------")
  1752.  
  1753. up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  1754. down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  1755. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  1756. rsiMA = ma(rsi, maLengthInput, maTypeInput)
  1757. isBB = maTypeInput == "Bollinger Bands"
  1758.  
  1759.  
  1760.  
  1761.  
  1762. ///////////////////////////////////////////////
  1763. /// HULL SUITE
  1764. //////////////////////////////////////////////
  1765.  
  1766. //INPUT
  1767. hullsrc = input(close, title='Source',group="---------------------HullSuite Settings---------------------")
  1768. modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'],group="---------------------HullSuite Settings---------------------")
  1769. hull_length = input(55, title='hull_length(180-200 for floating S/R , 55 for swing entry)',group="---------------------HullSuite Settings---------------------")
  1770. hull_lengthMult = input(1.0, title='hull_length multiplier (Used to view higher timeframes with straight band)',group="---------------------HullSuite Settings---------------------")
  1771.  
  1772. useHtf = input(false, title='Show Hull MA from X timeframe? (good for scalping)',group="---------------------HullSuite Settings---------------------")
  1773. htf = input.timeframe('240', title='Higher timeframe',group="---------------------HullSuite Settings---------------------")
  1774.  
  1775. switchColor = input(true, 'Color Hull according to trend?',group="---------------------HullSuite Settings---------------------")
  1776. candleCol = input(false, title='Color candles based on Hull\'s Trend?',group="---------------------HullSuite Settings---------------------")
  1777. visualSwitch = input(true, title='Show as a Band?'),group="---------------------HullSuite Settings---------------------"
  1778. thicknesSwitch = input(1, title='Line Thickness',group="---------------------HullSuite Settings---------------------")
  1779. transpSwitch = input.int(40, title='Band Transparency', step=5,group="---------------------HullSuite Settings---------------------")
  1780.  
  1781. //FUNCTIONS
  1782. //HMA
  1783. HMA(_hullsrc, _hull_length) =>
  1784. ta.wma(2 * ta.wma(_hullsrc, _hull_length / 2) - ta.wma(_hullsrc, _hull_length), math.round(math.sqrt(_hull_length)))
  1785. //EHMA
  1786. EHMA(_hullsrc, _hull_length) =>
  1787. ta.ema(2 * ta.ema(_hullsrc, _hull_length / 2) - ta.ema(_hullsrc, _hull_length), math.round(math.sqrt(_hull_length)))
  1788. //THMA
  1789. THMA(_hullsrc, _hull_length) =>
  1790. ta.wma(ta.wma(_hullsrc, _hull_length / 3) * 3 - ta.wma(_hullsrc, _hull_length / 2) - ta.wma(_hullsrc, _hull_length), _hull_length)
  1791.  
  1792. //SWITCH
  1793. Mode(modeSwitch, hullsrc, len) =>
  1794. modeSwitch == 'Hma' ? HMA(hullsrc, len) : modeSwitch == 'Ehma' ? EHMA(hullsrc, len) : modeSwitch == 'Thma' ? THMA(hullsrc, len / 2) : na
  1795.  
  1796. //OUT
  1797. _hull = Mode(modeSwitch, hullsrc, int(hull_length * hull_lengthMult))
  1798. HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull
  1799. MHULL = HULL[0]
  1800. SHULL = HULL[2]
  1801.  
  1802. //COLOR
  1803. hullColor = switchColor ? HULL > HULL[2] ? #00ff00 : #ff0000 : #ff9800
  1804.  
  1805.  
  1806.  
  1807. ////////////////////////////////////////////////
  1808. //ATR Automation
  1809. ///////////////////////////////////////////////
  1810.  
  1811.  
  1812. Showtable = input.bool (false, "Show ATR SL/TP Table", group='-------------------------ATR-------------------------')
  1813.  
  1814. TimeFrame = input.timeframe("", "Timeframe the ATR is Calculated off of", group='-------------------------ATR-------------------------')
  1815. ATRPercentageRisk = input.float (1.5, "SL ATR", group='-------------------------ATR-------------------------')
  1816. ATRPercentageReward = input.float (2, "TP ATR", group='-------------------------ATR-------------------------')
  1817.  
  1818.  
  1819.  
  1820. ShowStop = input.bool (true, "Long Stop Price", group='-------------------------ATR-------------------------')
  1821. ShowStopS = input.bool (true, "Short Stop Price", group='-------------------------ATR-------------------------')
  1822.  
  1823. ShowATR = input.bool(true, "Show ATR on the table?", group='-------------------------ATR-------------------------')
  1824.  
  1825. PlotLongStop = input.bool(true, "A line on the Long Stop Level", tooltip = "These will keep moving", group='-------------------------ATR-------------------------')
  1826. PlotShortStop = input.bool(true, "A line on the Short Stop Level", tooltip = "These will keep moving", group='-------------------------ATR-------------------------')
  1827.  
  1828. textcolor = input.color(color.white, "Color of Table Text")
  1829.  
  1830. BoxPlacement = input.string(position.bottom_center, "Box Placement", options = [position.bottom_right, position.bottom_left, position.top_right, position.top_center, position.bottom_center])
  1831.  
  1832. //import time frame
  1833. O = request.security(syminfo.ticker, TimeFrame, open)
  1834. H = request.security(syminfo.ticker, TimeFrame, high)
  1835. L = request.security(syminfo.ticker, TimeFrame, low)
  1836. C = request.security(syminfo.ticker, TimeFrame, close)
  1837.  
  1838. //Indicator math stuff
  1839. atr = request.security(syminfo.ticker, TimeFrame, ta.atr(14))
  1840. atr2 = math.round(atr,6)
  1841. dtr = request.security(syminfo.ticker, "", math.round(high - low,2))
  1842. atrp = math.round(dtr/atr * 100)
  1843.  
  1844. //position size math stuff
  1845. ATRPRisk = ATRPercentageRisk * atr2
  1846. ATRPReward = ATRPercentageReward * atr2
  1847.  
  1848. Stop = C - ATRPRisk
  1849. StopS = C + ATRPRisk
  1850.  
  1851. Stop2 = C + ATRPReward
  1852. StopS2 = C - ATRPReward
  1853.  
  1854. var table myTable = table.new(BoxPlacement, 3, 8, border_width=1)
  1855. if barstate.islast
  1856.  
  1857. if switch_atr
  1858. //Table Cells
  1859. table.cell(myTable, 0,0, "ATR " + str.tostring(atr2),text_color = ShowATR and switch_atr ? textcolor : na, bgcolor =color.black)
  1860. table.cell(myTable, 1,0, "Long",text_color = ShowATR and switch_atr ? textcolor : na, bgcolor = color.green)
  1861. table.cell(myTable, 2,0, "Short",text_color = ShowATR and switch_atr ? textcolor : na, bgcolor = color.red)
  1862. table.cell(myTable, 0,2, "SL",text_color = ShowATR and switch_atr ? textcolor : na, bgcolor = color.red)
  1863. table.cell(myTable, 0,1, "TP",text_color = ShowATR and switch_atr ? textcolor : na, bgcolor = color.green)
  1864.  
  1865. table.cell(myTable, 1,2, ShowStop? str.tostring(Stop):na, text_color = ShowStop and switch_atr ? textcolor : na, bgcolor = color.red)
  1866. table.cell(myTable, 2,2, ShowStopS? str.tostring(StopS):na, text_color = ShowStopS and switch_atr ? textcolor : na, bgcolor = color.red)
  1867.  
  1868.  
  1869. table.cell(myTable, 1,1, ShowStop? str.tostring(Stop2):na, text_color = ShowStop and switch_atr ? textcolor : na, bgcolor = color.green)
  1870. table.cell(myTable, 2,1, ShowStopS? str.tostring(StopS2):na, text_color = ShowStopS and switch_atr ? textcolor : na,bgcolor = color.green)
  1871.  
  1872.  
  1873.  
  1874. //////////////////////////////////////////////////////////////////////////////////
  1875. //Dynamic Support resistance with divergence.
  1876. ///////////////////////////////////////////////////////////////////////////////////
  1877.  
  1878.  
  1879. import HeWhoMustNotBeNamed/zigzag/3 as zg
  1880. import HeWhoMustNotBeNamed/enhanced_ta/8 as eta
  1881. import HeWhoMustNotBeNamed/supertrend/4 as st
  1882.  
  1883.  
  1884. //showsrd = input.bool (true, "Show S/R Divergences", group='------------------------S/R Divergence-------------------------')
  1885.  
  1886. maxItems = input.int(5, step=5, title="Max Depth", group='------------------------S/R Divergence-------------------------')
  1887.  
  1888. showZigzag1 = input.bool(true, "",group='------------------------S/R Divergence-------------------------', inline="z1")
  1889. zigzag1Length = input.int(8, "", group='------------------------S/R Divergence-------------------------', inline="z1")
  1890.  
  1891. showZigzag2 = input.bool(true, "", group='------------------------S/R Divergence-------------------------', inline="z2")
  1892. zigzag2Length = input.int(13, "", group='------------------------S/R Divergence-------------------------', inline="z2")
  1893.  
  1894. var useAlternativeSource = true
  1895. source = close
  1896.  
  1897. oscillatorType = input.string('rsi', title='Oscillator Source       ', options=["cci", "cmo", "cog", "mfi", "roc", "rsi", "stoch", "tsi", "wpr"], group='------------------------S/R Divergence-------------------------', inline='osc')
  1898. useExternalSource = input.bool(false, title='External Source', group='------------------------S/R Divergence-------------------------', inline="osce")
  1899. externalSource = input.source(close, title='', group='------------------------S/R Divergence-------------------------', inline="osce")
  1900.  
  1901. var history = 1
  1902. var waitForClose = true
  1903. var atrMaType = "rma"
  1904. var atrMultiplier = 1
  1905.  
  1906. add_to_array(arr, val, maxItems)=>
  1907. array.unshift(arr, val)
  1908. if(array.size(arr) > maxItems)
  1909. array.pop(arr)
  1910.  
  1911. add_to_line_array(arr, val, maxItems)=>
  1912. array.unshift(arr, val)
  1913. if(array.size(arr) > maxItems)
  1914. line.delete(array.pop(arr))
  1915.  
  1916. add_to_label_array(arr, val, maxItems)=>
  1917. array.unshift(arr, val)
  1918. if(array.size(arr) > maxItems)
  1919. label.delete(array.pop(arr))
  1920.  
  1921. getSentimentDetails(sentiment) =>
  1922. [sentimentSymbol, sentimentColor] = switch sentiment
  1923. 4 => ['⬆', color.green]
  1924. -4 => ['⬇', color.red]
  1925. 3 => ['↗', color.lime]
  1926. -3 => ['↘', color.orange]
  1927. 2 => ['⤴',color.rgb(202, 224, 13, 0)]
  1928. -2 => ['⤵',color.rgb(250, 128, 114, 0)]
  1929. => ['▣', color.silver]
  1930. [sentimentSymbol, sentimentColor]
  1931.  
  1932. plot_support_resistence(showZigzag, zigzagLength, srArray, lnArray, lblArray, maxItems, largest, switch_supportresistance )=>
  1933. if(showZigzag and switch_supportresistance )
  1934. length = zigzagLength * 3
  1935. longLength = zigzagLength*5
  1936. atrLength = zigzagLength*5
  1937. [oscillator, overbought, oversold] = eta.oscillator(oscillatorType, length, length, longLength)
  1938. [dir_zigzag, supertrend] = st.supertrend_zigzag(length=zigzagLength, history = history, useAlternativeSource = useAlternativeSource, alternativeSource=source,
  1939. waitForClose=waitForClose, atrlength=atrLength, multiplier=atrMultiplier, atrMaType=atrMaType)
  1940. [zigzagpivots, zigzagpivotbars, zigzagpivotdirs, zigzagpivotratios, zigzagoscillators,
  1941. zigzagoscillatordirs, zigzagtrendbias, zigzagdivergence,
  1942. newPivot, doublePivot] =
  1943. zg.zigzag(zigzagLength, oscillatorSource=useExternalSource ? externalSource : oscillator, directionBias = dir_zigzag)
  1944. if(array.size(zigzagpivots)>1)
  1945. price = array.get(zigzagpivots, 1)
  1946. divergence = array.get(zigzagdivergence, 1)
  1947.  
  1948. if(math.abs(divergence) == 2 or math.abs(divergence) == 3)
  1949. if(array.indexof(srArray, price) == -1)
  1950. add_to_array(srArray, price, maxItems)
  1951. [sentimentSymbol, sentimentColor] = getSentimentDetails(divergence)
  1952. lblSize = largest? size.normal : size.small
  1953. lnStyle = largest? line.style_solid : line.style_dashed
  1954. ln = line.new(time, price, time+1, price, extend=extend.right, xloc=xloc.bar_time, color=sentimentColor, style=lnStyle, width=largest? 1 : 0)
  1955. lbl = label.new(time, price, sentimentSymbol, color=sentimentColor, xloc=xloc.bar_time, textcolor=sentimentColor, style=label.style_none, yloc=yloc.price, size=lblSize)
  1956. add_to_line_array(lnArray, ln, maxItems)
  1957. add_to_label_array(lblArray, lbl, maxItems)
  1958.  
  1959. var srArray1 = array.new_float()
  1960. var srArray2 = array.new_float()
  1961.  
  1962. var lnArray1 = array.new_line()
  1963. var lblArray1 = array.new_label()
  1964.  
  1965. var lnArray2 = array.new_line()
  1966. var lblArray2 = array.new_label()
  1967.  
  1968. plot_support_resistence(showZigzag1, zigzag1Length, srArray1, lnArray1, lblArray1, maxItems, zigzag1Length>zigzag2Length, switch_supportresistance )
  1969. plot_support_resistence(showZigzag2, zigzag2Length, srArray2, lnArray2, lblArray2, maxItems, zigzag2Length>zigzag1Length, switch_supportresistance )
  1970.  
  1971.  
  1972. /////////////////////////
  1973. /// STC overlay signal
  1974. /////////////////////////
  1975.  
  1976. fastLength = input(title='MACD Fast Length', defval=23, group='------------------------STC-------------------------')
  1977. slowLength = input(title='MACD Slow Length', defval=50, group='------------------------STC-------------------------')
  1978. cycleLength = input(title='Cycle Length', defval=10, group='------------------------STC-------------------------')
  1979. d1Length = input(title='1st %D Length', defval=3, group='------------------------STC-------------------------')
  1980. d2Length = input(title='2nd %D Length', defval=3, group='------------------------STC-------------------------')
  1981. srcstc = input(title='Source', defval=close, group='------------------------STC-------------------------')
  1982. upper = input(title='Upper Band', defval=75, group='------------------------STC-------------------------')
  1983. lower = input(title='Lower Band', defval=25, group='------------------------STC-------------------------')
  1984. v_show_last = input(2000, "Plotting Length", group='------------------------STC-------------------------')
  1985.  
  1986. macd = ta.ema(srcstc, fastLength) - ta.ema(srcstc, slowLength)
  1987. k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLength)))
  1988. d = ta.ema(k, d1Length)
  1989. kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
  1990. stc = ta.ema(kd, d2Length)
  1991. stc := math.max(math.min(stc, 100), 0)
  1992.  
  1993. stcColor1 = stc > stc[1] ? color.green : color.red
  1994. stcColor2 = stc > upper ? color.green : stc <= lower ? color.red : color.orange
  1995.  
  1996.  
  1997. // buySignal = ta.crossover(stc, lower)
  1998. // sellSignal = ta.crossunder(stc, upper)
  1999. upperCrossover = ta.crossover(stc, upper)
  2000. upperCrossunder = ta.crossunder(stc, upper)
  2001. lowerCrossover = ta.crossover(stc, lower)
  2002. lowerCrossunder = ta.crossunder(stc, lower)
  2003. stcup = stc >= upper
  2004. stcdown = stc <= lower
  2005.  
  2006.  
  2007. plotshape(stcdown and switch_stc? true :na, style=shape.circle, location=location.top , show_last = v_show_last, color=color.new(color.red, 0), title='STC Sell')
  2008. plotshape(stcup and switch_stc? true:na, style=shape.circle, location=location.top, show_last = v_show_last, color=color.new(color.green, 0), title='STC Buy')
  2009.  
  2010.  
  2011.  
  2012. //////////////////////////////////////////////////////
  2013. //vector candles
  2014. /////////////////////////////////////////////////////
  2015.  
  2016. // Indicator Settings
  2017.  
  2018.  
  2019.  
  2020. var overideCandleColours = input.bool(title='Override Candles with PVSRA Colour', defval=true, tooltip="Indicator must be dragged to the top of the Object Tree to display correctly", group='------------------------PVSRA-------------------------')
  2021.  
  2022. var bool override_imnt = input.bool(defval=false, title="Overide Symbol", group='------------------------PVSRA-------------------------', inline="0")
  2023. var string pvsra_sym = input.symbol(title="", defval="BINANCE:BTCUSDTPERP", group='------------------------PVSRA-------------------------', inline="0")
  2024.  
  2025. var Bull200CandleColor = input.color(color.new(color.lime, 0), title="200% Volume", group='------------------------PVSRA-------------------------', inline="1")
  2026. var Bear200CandleColor = input.color(color.new(color.red, 0), title="", group='------------------------PVSRA-------------------------', inline = "1")
  2027.  
  2028. var Bull150CandleColor = input.color(color.new(color.blue, 0), title="150% Volume", group='------------------------PVSRA-------------------------', inline="2")
  2029. var Bear150CandleColor = input.color(color.new(color.fuchsia, 0), title="", group='------------------------PVSRA-------------------------', inline="2")
  2030.  
  2031. var BullNormCandleColor = input.color(color.new(#999999, 0), title="Norm Volume", group='------------------------PVSRA-------------------------', inline="3")
  2032. var BearNormCandleColor = input.color(color.new(#4d4d4d, 0), title="", group='------------------------PVSRA-------------------------', inline="3")
  2033.  
  2034.  
  2035. var color candleColor = na
  2036. var color imbalanceColor = na
  2037. var color imbalancedLineColor = na
  2038.  
  2039. var color NO_COLOR = na
  2040.  
  2041.  
  2042. var bool chartIs120MinOrMore = false
  2043.  
  2044.  
  2045.  
  2046.  
  2047. // Logic to reference another Instruments Volume Profile
  2048.  
  2049.  
  2050. pvsra_imnt(sresolution,sseries) => request.security(override_imnt ? pvsra_sym : syminfo.tickerid ,sresolution,sseries, barmerge.gaps_off,barmerge.lookahead_off)
  2051. volume_imnt = override_imnt == true? pvsra_imnt("",volume): volume
  2052. high_imnt = override_imnt == true? pvsra_imnt("",high): high
  2053. low_imnt = override_imnt == true? pvsra_imnt("",low): low
  2054. close_imnt = override_imnt == true? pvsra_imnt("",close): close
  2055. open_imnt = override_imnt == true? pvsra_imnt("",open): open
  2056.  
  2057.  
  2058.  
  2059. av = ta.sma(volume_imnt, 10)//sum_2 = math.sum(volume, 10)
  2060. value2 = volume_imnt * (high_imnt - low_imnt)
  2061. hivalue2 = ta.highest(value2, 10)
  2062. imnt_override_pvsra_calc_part2 = volume_imnt >= av * 1.5 ? 2 : 0
  2063. va = volume_imnt >= av * 2 or value2 >= hivalue2 ? 1 : imnt_override_pvsra_calc_part2
  2064.  
  2065.  
  2066. // Bull or bear Candle Colors
  2067. isBull = close_imnt > open_imnt
  2068.  
  2069.  
  2070. var bool is200Bull = na
  2071. var bool is150Bull = na
  2072. var bool is100Bull = na
  2073. var bool is200Bear = na
  2074. var bool is150Bear = na
  2075. var bool is100Bear = na
  2076.  
  2077.  
  2078. if isBull
  2079. if va == 1
  2080. candleColor := Bull200CandleColor
  2081. is200Bull := true
  2082. else
  2083. if va == 2
  2084. candleColor := Bull150CandleColor
  2085. is150Bull := true
  2086. else
  2087. is200Bull := false
  2088. is150Bull := false
  2089. candleColor := BullNormCandleColor
  2090. imbalanceColor := na
  2091. imbalancedLineColor := na
  2092. else
  2093. if va == 1
  2094. candleColor := Bear200CandleColor
  2095. is200Bear := true
  2096. else
  2097. if va == 2
  2098. candleColor := Bear150CandleColor
  2099. is150Bear := true
  2100. else
  2101. is200Bear := false
  2102. is150Bear := false
  2103. candleColor := BearNormCandleColor
  2104. imbalanceColor := na
  2105. imbalancedLineColor := na
  2106.  
  2107. barcolor(overideCandleColours and switch_pvsra ? candleColor : NO_COLOR)
  2108. plotcandle(open, high, low, close, color=(overideCandleColours and switch_pvsra ? candleColor : NO_COLOR), wickcolor=(overideCandleColours and switch_pvsra? candleColor : NO_COLOR), bordercolor=(overideCandleColours and switch_pvsra? candleColor : NO_COLOR), display = display.all)
  2109.  
  2110.  
  2111. ///////////////////////////////////////////////////
  2112. //////// SUpply/Demand POI
  2113. //////////////////////////////////////////////////
  2114. // INDICATOR SETTINGS
  2115. poi_group = '======== Supply/Demand Zone ========='
  2116. swing_length = input.int(10, title = 'Swing High/Low Length', group = poi_group, minval = 1, maxval = 50)
  2117. history_of_demand_to_keep = input.int(20, title = 'History To Keep', minval = 5, maxval = 50, group = poi_group)
  2118. box_width = input.float(2.5, title = 'Supply/Demand Box Width', group = poi_group, minval = 1, maxval = 10, step = 0.5)
  2119.  
  2120. // INDICATOR VISUAL SETTINGS
  2121. show_zigzag = input.bool(false, title = 'Show Zig Zag', group = 'Visual Settings', inline = '1')
  2122. show_price_action_labels = input.bool(false, title = 'Show Price Action Labels', group = 'Visual Settings', inline = '2')
  2123.  
  2124. supply_color = input.color(color.new(#EDEDED,70), title = 'Supply', group = 'Visual Settings', inline = '3')
  2125. supply_outline_color = input.color(color.new(color.white,100), title = 'Outline', group = 'Visual Settings', inline = '3')
  2126.  
  2127. demand_color = input.color(color.new(#00FFFF,70), title = 'Demand', group = 'Visual Settings', inline = '4')
  2128. demand_outline_color = input.color(color.new(color.white,100), title = 'Outline', group = 'Visual Settings', inline = '4')
  2129.  
  2130. bos_label_color = input.color(color.white, title = 'BOS Label', group = 'Visual Settings', inline = '5')
  2131. poi_label_color = input.color(color.white, title = 'POI Label', group = 'Visual Settings', inline = '7')
  2132.  
  2133. swing_type_color = input.color(color.black, title = 'Price Action Label', group = 'Visual Settings', inline = '8')
  2134. zigzag_color = input.color(color.new(#000000,0), title = 'Zig Zag', group = 'Visual Settings', inline = '9')
  2135.  
  2136. //
  2137. //END SETTINGS
  2138. //
  2139.  
  2140. atrpoi = ta.atr(50)
  2141. //
  2142. //FUNCTIONS
  2143. //
  2144.  
  2145. // FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY
  2146. f_array_add_pop(array, new_value_to_add) =>
  2147. array.unshift(array, new_value_to_add)
  2148. array.pop(array)
  2149.  
  2150. // FUNCTION SWING H & L LABELS
  2151. f_sh_sl_labels(array, swing_type) =>
  2152.  
  2153. var string label_text = na
  2154. if swing_type == 1
  2155. if array.get(array, 0) >= array.get(array, 1)
  2156. label_text := 'HH'
  2157. else
  2158. label_text := 'LH'
  2159. label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_down, textcolor = swing_type_color, color = color.new(swing_type_color, 100), size = size.tiny)
  2160.  
  2161. else if swing_type == -1
  2162. if array.get(array, 0) >= array.get(array, 1)
  2163. label_text := 'HL'
  2164. else
  2165. label_text := 'LL'
  2166. label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_up, textcolor = swing_type_color, color = color.new(swing_type_color, 100), size = size.tiny)
  2167.  
  2168. // FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING
  2169. f_check_overlapping(new_poi, box_array, atrpoi) =>
  2170.  
  2171. atr_threshold = atrpoi * 2
  2172. okay_to_draw = true
  2173.  
  2174. for i = 0 to array.size(box_array) - 1
  2175. top = box.get_top(array.get(box_array, i))
  2176. bottom = box.get_bottom(array.get(box_array, i))
  2177. poi = (top + bottom) / 2
  2178.  
  2179. upper_boundary = poi + atr_threshold
  2180. lower_boundary = poi - atr_threshold
  2181.  
  2182. if new_poi >= lower_boundary and new_poi <= upper_boundary
  2183. okay_to_draw := false
  2184. break
  2185. else
  2186. okay_to_draw := true
  2187. okay_to_draw
  2188.  
  2189.  
  2190. // FUNCTION TO DRAW SUPPLY OR DEMAND ZONE
  2191. f_supply_demand(value_array, bn_array, box_array, label_array, box_type, atrpoi) =>
  2192.  
  2193. atr_buffer = atrpoi * (box_width / 10)
  2194. box_left = array.get(bn_array, 0)
  2195. box_right = bar_index
  2196.  
  2197. var float box_top = 0.00
  2198. var float box_bottom = 0.00
  2199. var float poi = 0.00
  2200.  
  2201.  
  2202. if box_type == 1
  2203. box_top := array.get(value_array, 0)
  2204. box_bottom := box_top - atr_buffer
  2205. poi := (box_top + box_bottom) / 2
  2206. else if box_type == -1
  2207. box_bottom := array.get(value_array, 0)
  2208. box_top := box_bottom + atr_buffer
  2209. poi := (box_top + box_bottom) / 2
  2210.  
  2211. okay_to_draw = f_check_overlapping(poi, box_array, atrpoi)
  2212. // okay_to_draw = true
  2213.  
  2214. //delete oldest box, and then create a new box and add it to the array
  2215. if box_type == 1 and okay_to_draw and switch_poi
  2216. box.delete( array.get(box_array, array.size(box_array) - 1) )
  2217. f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = supply_outline_color,
  2218. bgcolor = supply_color, extend = extend.right, text = 'SUPPLY', text_halign = text.align_center, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
  2219.  
  2220. box.delete( array.get(label_array, array.size(label_array) - 1) )
  2221. f_array_add_pop(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi, border_color = color.new(poi_label_color,90),
  2222. bgcolor = color.new(poi_label_color,90), extend = extend.right, text = 'POI', text_halign = text.align_left, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
  2223.  
  2224. else if box_type == -1 and okay_to_draw and switch_poi
  2225. box.delete( array.get(box_array, array.size(box_array) - 1) )
  2226. f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = demand_outline_color,
  2227. bgcolor = demand_color, extend = extend.right, text = 'DEMAND', text_halign = text.align_center, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
  2228.  
  2229. box.delete( array.get(label_array, array.size(label_array) - 1) )
  2230. f_array_add_pop(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi, border_color = color.new(poi_label_color,90),
  2231. bgcolor = color.new(poi_label_color,90), extend = extend.right, text = 'POI', text_halign = text.align_left, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
  2232.  
  2233.  
  2234. // FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN
  2235. f_sd_to_bos(box_array, bos_array, label_array, zone_type) =>
  2236.  
  2237. if zone_type == 1 and switch_poi
  2238. for i = 0 to array.size(box_array) - 1
  2239. level_to_break = box.get_top(array.get(box_array,i))
  2240. // if ta.crossover(close, level_to_break)
  2241. if close >= level_to_break
  2242. copied_box = box.copy(array.get(box_array,i))
  2243. f_array_add_pop(bos_array, copied_box)
  2244. mid = (box.get_top(array.get(box_array,i)) + box.get_bottom(array.get(box_array,i))) / 2
  2245. box.set_top(array.get(bos_array,0), mid)
  2246. box.set_bottom(array.get(bos_array,0), mid)
  2247. box.set_extend( array.get(bos_array,0), extend.none)
  2248. box.set_right( array.get(bos_array,0), bar_index)
  2249. box.set_text( array.get(bos_array,0), 'BOS' )
  2250. box.set_text_color( array.get(bos_array,0), bos_label_color)
  2251. box.set_text_size( array.get(bos_array,0), size.small)
  2252. box.set_text_halign( array.get(bos_array,0), text.align_center)
  2253. box.set_text_valign( array.get(bos_array,0), text.align_center)
  2254. box.delete(array.get(box_array, i))
  2255. box.delete(array.get(label_array, i))
  2256.  
  2257.  
  2258. if zone_type == -1 and switch_poi
  2259. for i = 0 to array.size(box_array) - 1
  2260. level_to_break = box.get_bottom(array.get(box_array,i))
  2261. // if ta.crossunder(close, level_to_break)
  2262. if close <= level_to_break
  2263. copied_box = box.copy(array.get(box_array,i))
  2264. f_array_add_pop(bos_array, copied_box)
  2265. mid = (box.get_top(array.get(box_array,i)) + box.get_bottom(array.get(box_array,i))) / 2
  2266. box.set_top(array.get(bos_array,0), mid)
  2267. box.set_bottom(array.get(bos_array,0), mid)
  2268. box.set_extend( array.get(bos_array,0), extend.none)
  2269. box.set_right( array.get(bos_array,0), bar_index)
  2270. box.set_text( array.get(bos_array,0), 'BOS' )
  2271. box.set_text_color( array.get(bos_array,0), bos_label_color)
  2272. box.set_text_size( array.get(bos_array,0), size.small)
  2273. box.set_text_halign( array.get(bos_array,0), text.align_center)
  2274. box.set_text_valign( array.get(bos_array,0), text.align_center)
  2275. box.delete(array.get(box_array, i))
  2276. box.delete(array.get(label_array, i))
  2277.  
  2278.  
  2279.  
  2280. // FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT
  2281. f_extend_box_endpoint(box_array) =>
  2282.  
  2283. for i = 0 to array.size(box_array) - 1
  2284. box.set_right(array.get(box_array, i), bar_index + 100)
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290. // CALCULATE SWING HIGHS & SWING LOWS
  2291. swing_high = ta.pivothigh(high, swing_length, swing_length)
  2292. swing_low = ta.pivotlow(low, swing_length, swing_length)
  2293.  
  2294. // ARRAYS FOR SWING H/L & BN
  2295. var swing_high_values = array.new_float(5,0.00)
  2296. var swing_low_values = array.new_float(5,0.00)
  2297.  
  2298. var swing_high_bns = array.new_int(5,0)
  2299. var swing_low_bns = array.new_int(5,0)
  2300.  
  2301. // ARRAYS FOR SUPPLY / DEMAND
  2302. var current_supply_box = array.new_box(history_of_demand_to_keep, na)
  2303. var current_demand_box = array.new_box(history_of_demand_to_keep, na)
  2304.  
  2305. // ARRAYS FOR SUPPLY / DEMAND POI LABELS
  2306. var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
  2307. var current_demand_poi = array.new_box(history_of_demand_to_keep, na)
  2308.  
  2309. // ARRAYS FOR BOS
  2310. var supply_bos = array.new_box(5, na)
  2311. var demand_bos = array.new_box(5, na)
  2312. //
  2313. //END CALCULATIONS
  2314. //
  2315.  
  2316. // NEW SWING HIGH
  2317. if not na(swing_high)
  2318.  
  2319. //MANAGE SWING HIGH VALUES
  2320. f_array_add_pop(swing_high_values, swing_high)
  2321. f_array_add_pop(swing_high_bns, bar_index[swing_length])
  2322. if show_price_action_labels
  2323. f_sh_sl_labels(swing_high_values, 1)
  2324.  
  2325. f_supply_demand(swing_high_values, swing_high_bns, current_supply_box, current_supply_poi, 1, atrpoi)
  2326.  
  2327. // NEW SWING LOW
  2328. else if not na(swing_low)
  2329.  
  2330. //MANAGE SWING LOW VALUES
  2331. f_array_add_pop(swing_low_values, swing_low)
  2332. f_array_add_pop(swing_low_bns, bar_index[swing_length])
  2333. if show_price_action_labels
  2334. f_sh_sl_labels(swing_low_values, -1)
  2335.  
  2336. f_supply_demand(swing_low_values, swing_low_bns, current_demand_box, current_demand_poi, -1, atrpoi)
  2337.  
  2338.  
  2339. f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)
  2340. f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)
  2341.  
  2342. f_extend_box_endpoint(current_supply_box)
  2343. f_extend_box_endpoint(current_demand_box)
  2344.  
  2345. //ZIG ZAG
  2346. h = ta.highest(high, swing_length * 2 + 1)
  2347. l = ta.lowest(low, swing_length * 2 + 1)
  2348. f_isMin(len) =>
  2349. l == low[len]
  2350. f_isMax(len) =>
  2351. h == high[len]
  2352.  
  2353. var dirUp = false
  2354. var lastLow = high * 100
  2355. var lastHigh = 0.0
  2356. var timeLow = bar_index
  2357. var timeHigh = bar_index
  2358. var line li = na
  2359.  
  2360. f_drawLine() =>
  2361. _li_color = show_zigzag and switch_poi ? zigzag_color : color.new(#ffffff,100)
  2362. line.new(timeHigh - swing_length, lastHigh, timeLow - swing_length, lastLow, xloc.bar_index, color=_li_color, width=2)
  2363.  
  2364. if dirUp
  2365. if f_isMin(swing_length) and low[swing_length] < lastLow
  2366. lastLow := low[swing_length]
  2367. timeLow := bar_index
  2368. line.delete(li)
  2369. li := f_drawLine()
  2370. li
  2371.  
  2372. if f_isMax(swing_length) and high[swing_length] > lastLow
  2373. lastHigh := high[swing_length]
  2374. timeHigh := bar_index
  2375. dirUp := false
  2376. li := f_drawLine()
  2377. li
  2378.  
  2379. if not dirUp
  2380. if f_isMax(swing_length) and high[swing_length] > lastHigh
  2381. lastHigh := high[swing_length]
  2382. timeHigh := bar_index
  2383. line.delete(li)
  2384. li := f_drawLine()
  2385. li
  2386. if f_isMin(swing_length) and low[swing_length] < lastHigh
  2387. lastLow := low[swing_length]
  2388. timeLow := bar_index
  2389. dirUp := true
  2390. li := f_drawLine()
  2391. if f_isMax(swing_length) and high[swing_length] > lastLow
  2392. lastHigh := high[swing_length]
  2393. timeHigh := bar_index
  2394. dirUp := false
  2395. li := f_drawLine()
  2396. li
  2397.  
  2398.  
  2399.  
  2400.  
  2401. ///////////////////////////////////////////////////
  2402. /////////// Vector Zone
  2403. //////////////////////////////////////////////////
  2404.  
  2405. import TradersReality/Traders_Reality_Lib/1 as trLib
  2406.  
  2407. color redVectorColor = input.color(title='Vector: Red', group='------------Liquidity Zone---------------', defval=color.red, inline='vectors')
  2408. color greenVectorColor = input.color(title='Green', group='------------Liquidity Zone---------------', defval=color.lime, inline='vectors')
  2409. color violetVectorColor = input.color(title='Violet', group='------------Liquidity Zone---------------', defval=color.fuchsia, inline='vectors')
  2410. color blueVectorColor = input.color(title='Blue', group='------------Liquidity Zone---------------', defval=color.blue, inline='vectors', tooltip='Bull bars are green and bear bars are red when the bar is with volume >= 200% of the average volume of the 10 previous bars, or bars where the product of candle spread x candle volume is >= the highest for the 10 previous bars.\n Bull bars are blue and bear are violet when the bar is with with volume >= 150% of the average volume of the 10 previous bars.')
  2411. color regularCandleUpColor = input.color(title='Regular: Up Candle', group='------------Liquidity Zone---------------', defval=#999999, inline='nonVectors')
  2412. color regularCandleDownColor = input.color(title='Down Candle', group='------------Liquidity Zone---------------', defval=#4d4d4d, inline='nonVectors', tooltip='Bull bars are light gray and bear are dark gray when none of the red/green/blue/violet vector conditions are met.')
  2413. bool setcandlecolors = input.bool(false, title='Set PVSRA candle colors?', group='------------Liquidity Zone---------------', inline='setCandle')
  2414.  
  2415. int zonesMax = input.int(500, 'Maximum zones to draw', group='------------Liquidity Zone---------------')
  2416. string zoneType = input.string(group='------------Liquidity Zone---------------', defval='Body only', title='Zone top/bottom is defined with: ', options=['Body only', 'Body with wicks'])
  2417. string zoneUpdateType = input.string(group='------------Liquidity Zone---------------', defval='Body with wicks', title='Zones are cleared using candle: ', options=['Body only', 'Body with wicks'])
  2418. int borderWidth = input.int(0, 'Zone border width', group='------------Liquidity Zone---------------')
  2419. bool colorOverride = input.bool(true, 'Override color?' , group='------------Liquidity Zone---------------', inline="vcz1")
  2420. color zoneColor = input.color(title='Color', group='------------Liquidity Zone---------------', defval=color.rgb(255, 230, 75, 90), inline="vcz1", tooltip='the vector candle zones color to use if you dont not want to use the PVSRA Candle Colors.')
  2421. int transperancy = input.int(90, 'Zone Transperancy', minval = 0, maxval = 100, group='------------Liquidity Zone---------------', tooltip='If the vector candle zones color is not overriden, then we want to set the transparancy of the vector candle colors as defined by the PBSRA candle colors. This setting only affects the candle zone colors not the candle colors themselves.')
  2422.  
  2423. bool overrideSym = input.bool(group='PVSRA Override', title='Override chart symbol?', defval=false, inline='pvsra')
  2424. string pvsraSym = input.string(group='PVSRA Override', title='', defval='INDEX:BTCUSD', tooltip='You can use INDEX:BTCUSD or you can combine multiple feeds, for example BINANCE:BTCUSDT+COINBASE:BTCUSD. Note that adding too many will slow things down.', inline='pvsra')
  2425.  
  2426.  
  2427.  
  2428. pvsraVolume(overrideSymbolX, pvsraSymbolX, tickerIdX) =>
  2429. request.security(overrideSymbolX ? pvsraSymbolX : tickerIdX, '', volume, barmerge.gaps_off, barmerge.lookahead_off)
  2430. pvsraHigh(overrideSymbolX, pvsraSymbolX, tickerIdX) =>
  2431. request.security(overrideSymbolX ? pvsraSymbolX : tickerIdX, '', high, barmerge.gaps_off, barmerge.lookahead_off)
  2432. pvsraLow(overrideSymbolX, pvsraSymbolX, tickerIdX) =>
  2433. request.security(overrideSymbolX ? pvsraSymbolX : tickerIdX, '', low, barmerge.gaps_off, barmerge.lookahead_off)
  2434. pvsraClose(overrideSymbolX, pvsraSymbolX, tickerIdX) =>
  2435. request.security(overrideSymbolX ? pvsraSymbolX : tickerIdX, '', close, barmerge.gaps_off, barmerge.lookahead_off)
  2436. pvsraOpen(overrideSymbolX, pvsraSymbolX, tickerIdX) =>
  2437. request.security(overrideSymbolX ? pvsraSymbolX : tickerIdX, '', open, barmerge.gaps_off, barmerge.lookahead_off)
  2438.  
  2439.  
  2440. pvsraVolume = pvsraVolume(overrideSym, pvsraSym, syminfo.tickerid)
  2441. pvsraHigh = pvsraHigh(overrideSym, pvsraSym, syminfo.tickerid)
  2442. pvsraLow = pvsraLow(overrideSym, pvsraSym, syminfo.tickerid)
  2443. pvsraClose = pvsraClose(overrideSym, pvsraSym, syminfo.tickerid)
  2444. pvsraOpen = pvsraOpen(overrideSym, pvsraSym, syminfo.tickerid)
  2445. [pvsraColor, alertFlag, averageVolume, volumeSpread, highestVolumeSpread] = trLib.calcPvsra(pvsraVolume, pvsraHigh, pvsraLow, pvsraClose, pvsraOpen, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, regularCandleDownColor, regularCandleUpColor)
  2446.  
  2447.  
  2448. var zoneBoxesAbove = array.new_box()
  2449. var zoneBoxesBelow = array.new_box()
  2450.  
  2451.  
  2452. barcolor(setcandlecolors ? pvsraColor : na)
  2453. pvsra = trLib.getPvsraFlagByColor(switch_vectorzone ? pvsraColor:na, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, regularCandleUpColor)
  2454. trLib.updateZones(pvsra, 0, zoneBoxesBelow, zonesMax, pvsraHigh, pvsraLow, pvsraOpen, pvsraClose, transperancy, zoneUpdateType, zoneColor, zoneType, borderWidth, colorOverride, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor)
  2455. trLib.updateZones(pvsra, 1, zoneBoxesAbove, zonesMax, pvsraHigh, pvsraLow, pvsraOpen, pvsraClose, transperancy, zoneUpdateType, zoneColor, zoneType, borderWidth, colorOverride, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor)
  2456. trLib.cleanarr(zoneBoxesAbove)
  2457. trLib.cleanarr(zoneBoxesBelow)
  2458.  
  2459.  
  2460.  
  2461.  
  2462. //*****************
  2463. // Market sessions
  2464. //*****************
  2465.  
  2466.  
  2467. string weekend_sessions = ':1234567'
  2468. string no_weekend_sessions = ':23456'
  2469.  
  2470. bool show_rectangle1 = input.bool(group='Market session: London (0800-1630 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session1conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2471. bool show_label1 = input.bool(group='Market session: London (0800-1630 UTC+0) - DST Aware', defval=true, title='Label?', inline='session1conf') and show_rectangle1 and show_markets
  2472. bool show_or1 = input.bool(group='Market session: London (0800-1630 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session1conf', tooltip='This controls the shaded area for the session') and show_rectangle1 and show_markets
  2473. string sess1Label = input.string(group='Market session: London (0800-1630 UTC+0) - DST Aware', defval='London', title='Name:', inline='session1style')
  2474. color sess1col = input.color(group='Market session: London (0800-1630 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(120, 123, 134, 75), inline='session1style')
  2475. color sess1colLabel = input.color(group='Market session: London (0800-1630 UTC+0) - DST Aware', title='Label', defval=color.rgb(120, 123, 134, 0), inline='session1style')
  2476. string sess1TimeX = '0800-1630'//input.session(group='Market session: London (0800-1630 UTC+0)', defval='0800-1630', title='Time (UTC+0):', inline='session1style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST and times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2477. sess1Time = show_markets_weekends ? sess1TimeX + weekend_sessions : sess1TimeX + no_weekend_sessions
  2478.  
  2479.  
  2480. bool show_rectangle2 = input.bool(group='Market session: New York (1430-2100 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session2conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2481. bool show_label2 = input.bool(group='Market session: New York (1430-2100 UTC+0) - DST Aware', defval=true, title='Label?', inline='session2conf') and show_rectangle2 and show_markets
  2482. bool show_or2 = input.bool(group='Market session: New York (1430-2100 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session2conf', tooltip='This controls the shaded area for the session') and show_rectangle2 and show_markets
  2483. string sess2Label = input.string(group='Market session: New York (1430-2100 UTC+0) - DST Aware', defval='NewYork', title='Name:', inline='session2style')
  2484. color sess2col = input.color(group='Market session: New York (1430-2100 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(251, 86, 91, 75), inline='session2style')
  2485. color sess2colLabel = input.color(group='Market session: New York (1430-2100 UTC+0) - DST Aware', title='Label', defval=color.rgb(253, 84, 87, 25), inline='session2style')
  2486. string sess2TimeX = '1430-2100'//input.session(group='Market session: New York (1430-2100 UTC+0)', defval='1430-2100', title='Time (UTC+0):', inline='session2style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2487. sess2Time = show_markets_weekends ? sess2TimeX + weekend_sessions : sess2TimeX + no_weekend_sessions
  2488.  
  2489.  
  2490. bool show_rectangle3 = input.bool(group='Market session: Tokyo (0000-0600 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session3conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2491. bool show_label3 = input.bool(group='Market session: Tokyo (0000-0600 UTC+0) - DST Aware', defval=true, title='Label?', inline='session3conf') and show_rectangle3 and show_markets
  2492. bool show_or3 = input.bool(group='Market session: Tokyo (0000-0600 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session3conf', tooltip='This controls the shaded area for the session') and show_rectangle3 and show_markets
  2493. string sess3Label = input.string(group='Market session: Tokyo (0000-0600 UTC+0) - DST Aware', defval='Tokyo', title='Name:', inline='session3style')
  2494. color sess3col = input.color(group='Market session: Tokyo (0000-0600 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(80, 174, 85, 75), inline='session3style')
  2495. color sess3colLabel = input.color(group='Market session: Tokyo (0000-0600 UTC+0) - DST Aware', title='Label', defval=color.rgb(80, 174, 85, 25), inline='session3style')
  2496. string sess3TimeX = '0000-0600'//input.session(group='Market session: Tokyo (0000-0600 UTC+0)', defval='0000-0600', title='Time (UTC+0):', inline='session3style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2497. sess3Time = show_markets_weekends ? sess3TimeX + weekend_sessions : sess3TimeX + no_weekend_sessions
  2498.  
  2499.  
  2500. bool show_rectangle4 = input.bool(group='Market session: Hong Kong (0130-0800 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session4conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2501. bool show_label4 = input.bool(group='Market session: Hong Kong (0130-0800 UTC+0) - DST Aware', defval=true, title='Label?', inline='session4conf') and show_rectangle4 and show_markets
  2502. bool show_or4 = input.bool(group='Market session: Hong Kong (0130-0800 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session4conf', tooltip='This controls the shaded area for the session') and show_rectangle4 and show_markets
  2503. string sess4Label = input.string(group='Market session: Hong Kong (0130-0800 UTC+0) - DST Aware', defval='HongKong', title='Name:', inline='session4style')
  2504. color sess4col = input.color(group='Market session: Hong Kong (0130-0800 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(128, 127, 23, 75), inline='session4style')
  2505. color sess4colLabel = input.color(group='Market session: Hong Kong (0130-0800 UTC+0) - DST Aware', title='Label', defval=color.rgb(128, 127, 23, 25), inline='session4style')
  2506. string sess4TimeX = '0130-0800'//input.session(group='Market session: Hong Kong (0130-0800 UTC+0)', defval='0130-0800', title='Time (UTC+0):', inline='session4style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2507. sess4Time = show_markets_weekends ? sess4TimeX + weekend_sessions : sess4TimeX + no_weekend_sessions
  2508.  
  2509. bool show_rectangle5 = input.bool(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session5conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2510. bool show_label5 = input.bool(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0) - DST Aware', defval=true, title='Label?', inline='session5conf') and show_rectangle5 and show_markets
  2511. bool show_or5 = input.bool(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session5conf', tooltip='This controls the shaded area for the session') and show_rectangle5 and show_markets
  2512. string sess5Label = input.string(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0) - DST Aware', defval='Sydney', title='Name:', inline='session5style')
  2513. color sess5col = input.color(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(37, 228, 123, 75), inline='session5style')
  2514. color sess5colLabel = input.color(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0) - DST Aware', title='Label', defval=color.rgb(37, 228, 123, 25), inline='session5style')
  2515. string sess5TimeX = '2200-0600'//input.session(group='Market session: Sydney (NZX+ASX 2200-0600 UTC+0)', defval='2200-0600', title='Time (UTC+0):', inline='session5style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2516. sess5Time = show_markets_weekends ? sess5TimeX + weekend_sessions : sess5TimeX + no_weekend_sessions
  2517.  
  2518. bool show_rectangle6 = input.bool(group='Market session: EU Brinks (0800-0900 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session6conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2519. bool show_label6 = input.bool(group='Market session: EU Brinks (0800-0900 UTC+0) - DST Aware', defval=true, title='Label?', inline='session6conf') and show_rectangle6 and show_markets
  2520. bool show_or6 = input.bool(group='Market session: EU Brinks (0800-0900 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session6conf', tooltip='This controls the shaded area for the session') and show_rectangle6 and show_markets
  2521. string sess6Label = input.string(group='Market session: EU Brinks (0800-0900 UTC+0) - DST Aware', defval='EU Brinks', title='Name:', inline='session6style')
  2522. color sess6col = input.color(group='Market session: EU Brinks (0800-0900 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(255, 255, 255, 65), inline='session6style')
  2523. color sess6colLabel = input.color(group='Market session: EU Brinks (0800-0900 UTC+0) - DST Aware', title='Label', defval=color.rgb(255, 255, 255, 25), inline='session6style')
  2524. string sess6TimeX = '0800-0900'//input.session(group='Market session: EU Brinks (0800-0900 UTC+0)', defval='0800-0900', title='Time (UTC+0):', inline='session6style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2525. sess6Time = show_markets_weekends ? sess6TimeX + weekend_sessions : sess6TimeX + no_weekend_sessions
  2526.  
  2527. bool show_rectangle7 = input.bool(group='Market session: US Brinks (1400-1500 UTC+0) - DST Aware', defval=true, title='Show: session?', inline='session7conf', tooltip='If this checkbox is off, Label and Open Range have no effect') and show_markets
  2528. bool show_label7 = input.bool(group='Market session: US Brinks (1400-1500 UTC+0) - DST Aware', defval=true, title='Label?', inline='session7conf') and show_rectangle7 and show_markets
  2529. bool show_or7 = input.bool(group='Market session: US Brinks (1400-1500 UTC+0) - DST Aware', defval=true, title='Opening Range?', inline='session7conf', tooltip='This controls the shaded area for the session') and show_rectangle7 and show_markets
  2530. string sess7Label = input.string(group='Market session: US Brinks (1400-1500 UTC+0) - DST Aware', defval='US Brinks', title='Name:', inline='session7style')
  2531. color sess7col = input.color(group='Market session: US Brinks (1400-1500 UTC+0) - DST Aware', title='Color: Box', defval=color.rgb(255, 255, 255, 65), inline='session7style')
  2532. color sess7colLabel = input.color(group='Market session: US Brinks (1400-1500 UTC+0) - DST Aware', title='Label', defval=color.rgb(255, 255, 255, 25), inline='session7style')
  2533. string sess7TimeX = '1400-1500'//input.session(group='Market session: US Brinks (1400-1500 UTC+0)', defval='1400-1500', title='Time (UTC+0):', inline='session7style', tooltip='Normally you will not want to adjust these times. Defaults are taken as if the session is NOT in DST times must be in UTC+0. Note due to limitations of pinescript some values sellected here other than the default might not work correctly on all exchanges.')
  2534. sess7Time = show_markets_weekends ? sess7TimeX + weekend_sessions : sess7TimeX + no_weekend_sessions
  2535.  
  2536.  
  2537.  
  2538. splitSessionString(sessXTime) =>
  2539. //session stirng looks like this: 0000-0000:1234567 ie start time, end time, day of the week
  2540. //we need to parse the sessXTime string into hours and min for start and end times so we can use those in the timestampfunction below
  2541.  
  2542. //string times contains "0000-2300" as an example
  2543. string times = array.get(str.split(sessXTime, ':'), 0)
  2544.  
  2545. //string startTime contains "0000"
  2546. string startTime = array.get(str.split(times, '-'), 0)
  2547. //string endTime contains "2300"
  2548. string endTime = array.get(str.split(times, '-'), 1)
  2549.  
  2550. //now we need to get the start hour and start min, sing 0 index - hour is the characters in index 0 and index 1 while min is the chars at index 2 and 3
  2551. string[] startTimeChars = str.split(startTime, '')
  2552. string[] endTimeChars = str.split(endTime, '')
  2553.  
  2554. //so now startHour contains 00 and start min contains 00
  2555. string startHour = array.get(startTimeChars, 0) + array.get(startTimeChars, 1)
  2556. string startMin = array.get(startTimeChars, 2) + array.get(startTimeChars, 3)
  2557.  
  2558. //so now endHour contains 23 and end min contains 00
  2559. string endHour = array.get(endTimeChars, 0) + array.get(endTimeChars, 1)
  2560. string endMin = array.get(endTimeChars, 2) + array.get(endTimeChars, 3)
  2561. [startHour, startMin, endHour, endMin]
  2562.  
  2563. calc_session_startend(sessXTime, gmt) =>
  2564. [startHour, startMin, endHour, endMin] = splitSessionString(sessXTime)
  2565. targetstartTimeX = timestamp(gmt, year, month, dayofmonth, math.round(str.tonumber(startHour)), math.round(str.tonumber(startMin)), 00)
  2566. targetendTimeX = timestamp(gmt, year, month, dayofmonth, math.round(str.tonumber(endHour)), math.round(str.tonumber(endMin)), 00)
  2567. time_now = timestamp(year, month, dayofmonth, hour, minute, 00)
  2568. midnight_exchange = timestamp(year, month, dayofmonth, 00, 00, 00)
  2569.  
  2570.  
  2571. //if start hour is greater than end hour we are dealing with a session that starts towards the end of one day
  2572. //and ends the next day. ie advance the end time by 24 hours - its the next day
  2573. bool adjusted = false
  2574. if gmt == 'GMT+0'
  2575. if math.round(str.tonumber(startHour)) > math.round(str.tonumber(endHour))
  2576. if time_now - targetstartTimeX >= 0
  2577. targetendTimeX := targetendTimeX + 24 * 60 * 60 * 1000
  2578. adjusted := true
  2579. targetendTimeX
  2580. if gmt == 'GMT+1'
  2581. if math.round(str.tonumber(startHour)) == 0
  2582. startHour := '24'
  2583. if math.round(str.tonumber(endHour)) == 0
  2584. endHour := '24'
  2585. if math.round(str.tonumber(startHour))-1 > math.round(str.tonumber(endHour))-1
  2586. if time_now - targetstartTimeX >= 0
  2587. targetendTimeX := targetendTimeX + 24 * 60 * 60 * 1000
  2588. adjusted := true
  2589. targetendTimeX
  2590.  
  2591.  
  2592.  
  2593. if targetstartTimeX < midnight_exchange and midnight_exchange < targetendTimeX and not adjusted
  2594. targetendTimeX := targetendTimeX + 24 * 60 * 60 * 1000
  2595. targetendTimeX
  2596.  
  2597. [targetstartTimeX,targetendTimeX]
  2598.  
  2599.  
  2600. draw_open_range(sessXTime, sessXcol, show_orX, gmt)=>
  2601. if show_orX
  2602. // Initialize variables on bar zero only, so they preserve their values across bars.
  2603. var hi = float(na)
  2604. var lo = float(na)
  2605. var box hiLoBox = na
  2606. // Detect changes in timeframe.
  2607. session = time(timeframe.period, sessXTime, gmt)
  2608. bool newTF = session and not session[1]
  2609. if newTF
  2610. // New bar in higher timeframe; reset values and create new lines and box.
  2611. [targetstartTimeX,targetendTimeX] = calc_session_startend(sessXTime, gmt)
  2612. sessionDuration = math.round(math.abs(time - targetendTimeX)/(timeframe.multiplier*60*1000))
  2613.  
  2614. hi := high
  2615. lo := low
  2616. hiLoBox := box.new(bar_index, hi, timeframe.multiplier == 1? bar_index : bar_index+sessionDuration, lo, border_color = na, bgcolor = sessXcol)
  2617. int(na)
  2618. else
  2619. if timeframe.multiplier == 1 and (na(session[1]) and not na(session) or session[1] < session)
  2620. box.set_right(hiLoBox, bar_index+1)
  2621. int(na)
  2622. draw_session_hilo(sessXTime, show_rectangleX, show_labelX, sessXcolLabel, sessXLabel, gmt)=>
  2623. if show_rectangleX
  2624. // Initialize variables on bar zero only, so they preserve their values across bars.
  2625. var hi = float(0)
  2626. var lo = float(10000000000.0)
  2627.  
  2628. var line line_t = na
  2629. var line line_b = na
  2630. var label line_label = na
  2631. // var box hiLoBox = na
  2632. // Detect changes in timeframe.
  2633. session = time(timeframe.period, sessXTime, gmt)
  2634. sessLineStyleX = rectStyle == 'Solid' ? line.style_solid : line.style_dashed
  2635. bool newTF = session and not session[1]
  2636. hi := newTF ? high : session ? math.max(high, hi[1]) : hi[1]
  2637. lo := newTF ? low : session ? math.min(low, lo[1]) : lo[1]
  2638.  
  2639. if newTF
  2640. beginIndex = bar_index
  2641. [targetstartTimeX,targetendTimeX] = calc_session_startend(sessXTime, gmt)
  2642. sessionDuration = math.round(math.abs(time - targetendTimeX)/(timeframe.multiplier*60*1000))
  2643.  
  2644. line_t := line.new(beginIndex, hi, timeframe.multiplier == 1? bar_index : bar_index+sessionDuration, hi, xloc=xloc.bar_index, style=sessLineStyleX, color=sessXcolLabel)
  2645. line_b := line.new(beginIndex, lo, timeframe.multiplier == 1? bar_index : bar_index+sessionDuration, lo, xloc=xloc.bar_index, style=sessLineStyleX, color=sessXcolLabel)
  2646. line.delete(line_t[1])
  2647. line.delete(line_b[1])
  2648. if show_labelX
  2649. line_label := label.new(beginIndex, hi, sessXLabel, xloc=xloc.bar_index, textcolor=sessXcolLabel, style=label.style_none, size=size.normal, textalign=text.align_right)
  2650. label.delete(line_label[1])
  2651.  
  2652. int(na)
  2653. else
  2654. if na(session[1]) and not na(session) or session[1] < session
  2655. if timeframe.multiplier == 1
  2656. line.set_x2(line_t,bar_index+1)
  2657. line.set_x2(line_b,bar_index+1)
  2658. line.set_y1(line_t,hi)
  2659. line.set_y2(line_t,hi)
  2660. line.set_y1(line_b,lo)
  2661. line.set_y2(line_b,lo)
  2662. if show_labelX and not na(line_label)
  2663. label.set_y(line_label, hi)
  2664. int(na)
  2665.  
  2666.  
  2667.  
  2668.  
  2669. //*****************************//
  2670. // Daylight Savings Time Flags //
  2671. //*****************************//
  2672.  
  2673. int previousSunday = dayofmonth - dayofweek + 1
  2674. bool nyDST = na
  2675. bool ukDST = na
  2676. bool sydDST = na
  2677.  
  2678. if month < 3 or month > 11
  2679. nyDST := false
  2680. ukDST := false
  2681. sydDST := true
  2682. else if month > 4 and month < 10
  2683. nyDST := true
  2684. ukDST := true
  2685. sydDST := false
  2686. else if month == 3
  2687. nyDST := previousSunday >= 8
  2688. ukDST := previousSunday >= 24
  2689. sydDST := true
  2690. else if month == 4
  2691. nyDST := true
  2692. ukDST := true
  2693. sydDST := previousSunday <= 0
  2694. else if month == 10
  2695. nyDST := true
  2696. ukDST := previousSunday <= 24
  2697. sydDST := previousSunday >= 0
  2698. else // month == 11
  2699. nyDST := previousSunday <= 0
  2700. ukDST := false
  2701. sydDST := true
  2702.  
  2703.  
  2704.  
  2705.  
  2706. if ukDST
  2707. draw_open_range(sess1Time,sess1col,show_or1,'GMT+1')
  2708. draw_session_hilo(sess1Time, show_rectangle1, show_label1, sess1colLabel, sess1Label, 'GMT+1')
  2709. else
  2710. draw_open_range(sess1Time,sess1col,show_or1,'GMT+0')
  2711. draw_session_hilo(sess1Time, show_rectangle1, show_label1, sess1colLabel, sess1Label, 'GMT+0')
  2712.  
  2713. if nyDST
  2714. draw_open_range(sess2Time,sess2col,show_or2,'GMT+1')
  2715. draw_session_hilo(sess2Time, show_rectangle2, show_label2, sess2colLabel, sess2Label, 'GMT+1')
  2716. else
  2717. draw_open_range(sess2Time,sess2col,show_or2,'GMT+0')
  2718. draw_session_hilo(sess2Time, show_rectangle2, show_label2, sess2colLabel, sess2Label, 'GMT+0')
  2719.  
  2720. // Tokyo
  2721. draw_open_range(sess3Time,sess3col,show_or3,'GMT+0')
  2722. draw_session_hilo(sess3Time, show_rectangle3, show_label3, sess3colLabel, sess3Label, 'GMT+0')
  2723.  
  2724. // Hong Kong
  2725. draw_open_range(sess4Time,sess4col,show_or4,'GMT+0')
  2726. draw_session_hilo(sess4Time, show_rectangle4, show_label4, sess4colLabel, sess4Label, 'GMT+0')
  2727.  
  2728. if sydDST
  2729. draw_open_range(sess5Time,sess5col,show_or5,'GMT+1')
  2730. draw_session_hilo(sess5Time, show_rectangle5, show_label5, sess5colLabel, sess5Label, 'GMT+1')
  2731. else
  2732. draw_open_range(sess5Time,sess5col,show_or5,'GMT+0')
  2733. draw_session_hilo(sess5Time, show_rectangle5, show_label5, sess5colLabel, sess5Label, 'GMT+0')
  2734.  
  2735.  
  2736. if nyDST
  2737. draw_open_range(sess7Time,sess7col,show_or7,'GMT+1')
  2738. draw_session_hilo(sess7Time, show_rectangle7, show_label7, sess7colLabel, sess7Label, 'GMT+1')
  2739. else
  2740. draw_open_range(sess7Time,sess7col,show_or7,'GMT+0')
  2741. draw_session_hilo(sess7Time, show_rectangle7, show_label7, sess7colLabel, sess7Label, 'GMT+0')
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747. //////////////////////////////////////////////////
  2748. ////QQE MOD
  2749. /////////////////////////////////////////////////
  2750. RSI_Period = input(6, title='RSI Length', group='------------------------QQE-------------------------')
  2751. SF = input(5, title='RSI Smoothing', group='------------------------QQE-------------------------')
  2752. QQE = input(3, title='Fast QQE Factor', group='------------------------QQE-------------------------')
  2753. ThreshHold = input(3, title='Thresh-hold', group='------------------------QQE-------------------------')
  2754. //
  2755.  
  2756. srcqqe = input(close, title='RSI Source', group='------------------------QQE-------------------------')
  2757. //
  2758.  
  2759. //
  2760. Wilders_Period = RSI_Period * 2 - 1
  2761.  
  2762.  
  2763. Rsi = ta.rsi(srcqqe, RSI_Period)
  2764. RsiMa = ta.ema(Rsi, SF)
  2765. AtrRsi = math.abs(RsiMa[1] - RsiMa)
  2766. MaAtrRsi = ta.ema(AtrRsi, Wilders_Period)
  2767. dar = ta.ema(MaAtrRsi, Wilders_Period) * QQE
  2768.  
  2769. longband = 0.0
  2770. shortband = 0.0
  2771. trend = 0
  2772.  
  2773. DeltaFastAtrRsi = dar
  2774. RSIndex = RsiMa
  2775. newshortband = RSIndex + DeltaFastAtrRsi
  2776. newlongband = RSIndex - DeltaFastAtrRsi
  2777. longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? math.max(longband[1], newlongband) : newlongband
  2778. shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? math.min(shortband[1], newshortband) : newshortband
  2779. cross_1 = ta.cross(longband[1], RSIndex)
  2780. trend := ta.cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1)
  2781. FastAtrRsiTL = trend == 1 ? longband : shortband
  2782.  
  2783.  
  2784. length = input.int(50, minval=1, title='Bollinger Length', group='------------------------QQE-------------------------')
  2785. multqqe = input.float(0.35, minval=0.001, maxval=5, step=0.1, title='BB Multiplier', group='------------------------QQE-------------------------')
  2786. basis = ta.sma(FastAtrRsiTL - 50, length)
  2787. dev = multqqe * ta.stdev(FastAtrRsiTL - 50, length)
  2788. upperqqe = basis + dev
  2789. lowerqqe = basis - dev
  2790. color_bar = RsiMa - 50 > upperqqe ? #00c3ff : RsiMa - 50 < lowerqqe ? #ff0062 : color.gray
  2791.  
  2792.  
  2793. //
  2794. // Zero cross
  2795. QQEzlong = 0
  2796. QQEzlong := nz(QQEzlong[1])
  2797. QQEzshort = 0
  2798. QQEzshort := nz(QQEzshort[1])
  2799. QQEzlong := RSIndex >= 50 ? QQEzlong + 1 : 0
  2800. QQEzshort := RSIndex < 50 ? QQEzshort + 1 : 0
  2801. //
  2802.  
  2803.  
  2804. ////////////////////////////////////////////////////////////////
  2805.  
  2806. RSI_Period2 = input(6, title='RSI Length', group='------------------------QQE-------------------------')
  2807. SF2 = input(5, title='RSI Smoothing', group='------------------------QQE-------------------------')
  2808. QQE2 = input(1.61, title='Fast QQE2 Factor', group='------------------------QQE-------------------------')
  2809. ThreshHold2 = input(3, title='Thresh-hold', group='------------------------QQE-------------------------')
  2810.  
  2811. src2 = input(close, title='RSI Source', group='------------------------QQE-------------------------')
  2812. //
  2813.  
  2814. //
  2815. Wilders_Period2 = RSI_Period2 * 2 - 1
  2816.  
  2817.  
  2818. Rsi2 = ta.rsi(src2, RSI_Period2)
  2819. RsiMa2 = ta.ema(Rsi2, SF2)
  2820. AtrRsi2 = math.abs(RsiMa2[1] - RsiMa2)
  2821. MaAtrRsi2 = ta.ema(AtrRsi2, Wilders_Period2)
  2822. dar2 = ta.ema(MaAtrRsi2, Wilders_Period2) * QQE2
  2823. longband2 = 0.0
  2824. shortband2 = 0.0
  2825. trend2 = 0
  2826.  
  2827. DeltaFastAtrRsi2 = dar2
  2828. RSIndex2 = RsiMa2
  2829. newshortband2 = RSIndex2 + DeltaFastAtrRsi2
  2830. newlongband2 = RSIndex2 - DeltaFastAtrRsi2
  2831. longband2 := RSIndex2[1] > longband2[1] and RSIndex2 > longband2[1] ? math.max(longband2[1], newlongband2) : newlongband2
  2832. shortband2 := RSIndex2[1] < shortband2[1] and RSIndex2 < shortband2[1] ? math.min(shortband2[1], newshortband2) : newshortband2
  2833. cross_2 = ta.cross(longband2[1], RSIndex2)
  2834. trend2 := ta.cross(RSIndex2, shortband2[1]) ? 1 : cross_2 ? -1 : nz(trend2[1], 1)
  2835. FastAtrRsi2TL = trend2 == 1 ? longband2 : shortband2
  2836.  
  2837.  
  2838. //
  2839. // Zero cross
  2840. QQE2zlong = 0
  2841. QQE2zlong := nz(QQE2zlong[1])
  2842. QQE2zshort = 0
  2843. QQE2zshort := nz(QQE2zshort[1])
  2844. QQE2zlong := RSIndex2 >= 50 ? QQE2zlong + 1 : 0
  2845. QQE2zshort := RSIndex2 < 50 ? QQE2zshort + 1 : 0
  2846. //
  2847. qqeline = FastAtrRsi2TL - 50
  2848. hcolor2 = RsiMa2 - 50 > ThreshHold2 ? color.silver : RsiMa2 - 50 < 0 - ThreshHold2 ? color.silver : na
  2849.  
  2850.  
  2851. Greenbar1 = RsiMa2 - 50 > ThreshHold2
  2852. Greenbar2 = RsiMa - 50 > upperqqe
  2853.  
  2854. Redbar1 = RsiMa2 - 50 < 0 - ThreshHold2
  2855. Redbar2 = RsiMa - 50 < lowerqqe
  2856.  
  2857.  
  2858.  
  2859. /////////////////////////////////////////////////
  2860. /////////////// Volume Up/Down
  2861. ////////////////////////////////////////////////
  2862. lowerTimeframeTooltip = "The indicator scans lower timeframe data to approximate Up/Down volume. By default, the timeframe is chosen automatically. These inputs override this with a custom timeframe.
  2863. \n\nHigher timeframes provide more historical data, but the data will be less precise."
  2864. useCustomTimeframeInput = input.bool(false, "Use custom timeframe", tooltip = lowerTimeframeTooltip)
  2865. lowerTimeframeInput = input.timeframe("1", "Timeframe")
  2866.  
  2867. upAndDownVolume() =>
  2868. posVol = 0.0
  2869. negVol = 0.0
  2870.  
  2871. switch
  2872. close > open => posVol += volume
  2873. close < open => negVol -= volume
  2874. close >= close[1] => posVol += volume
  2875. close < close[1] => negVol -= volume
  2876.  
  2877. [posVol, negVol]
  2878.  
  2879. lowerTimeframe = switch
  2880. useCustomTimeframeInput => lowerTimeframeInput
  2881. timeframe.isintraday => "1"
  2882. timeframe.isdaily => "5"
  2883. => "60"
  2884.  
  2885. [upVolumeArray, downVolumeArray] = request.security_lower_tf(syminfo.tickerid, lowerTimeframe, upAndDownVolume())
  2886.  
  2887. upVolume = array.sum(upVolumeArray)
  2888. downVolume = array.sum(downVolumeArray)
  2889. delta = upVolume + downVolume
  2890. prevdelta = delta[1]
  2891.  
  2892.  
  2893. var cumVol = 0.
  2894. cumVol += nz(volume)
  2895. if barstate.islast and cumVol == 0
  2896. runtime.error("The data vendor doesn't provide volume data for this symbol.")
  2897.  
  2898.  
  2899.  
  2900.  
  2901. respectemavalue = ta.ema(src, respectemaperiod)
  2902. isaboverespectema = close > respectemavalue
  2903. isbelowrespectema = close < respectemavalue
  2904.  
  2905.  
  2906.  
  2907. isqqebarabove = Greenbar1 and Greenbar2
  2908. isqqebarbelow = Redbar1 and Redbar2
  2909.  
  2910.  
  2911.  
  2912. dv2up = bool (na)
  2913.  
  2914.  
  2915.  
  2916. dvup = bool (na)
  2917.  
  2918. if dvtype == 'Threshold'
  2919. dvup := vol > t and vol>=1.1
  2920. else if dvtype == '10p Difference'
  2921. dvup := vol > t and (vol - t >= 0.1)
  2922. else
  2923. dvup := vol > t
  2924.  
  2925.  
  2926. sarup = out < close
  2927. sardown = out > close
  2928.  
  2929. longvol = bool(na)
  2930. shortvol = bool (na)
  2931.  
  2932.  
  2933.  
  2934. if volumetype == 'Delta'
  2935. longvol := delta > 0 and delta > delta[1]
  2936. shortvol := delta < 0 and delta < delta[1]
  2937. else
  2938. longvol := upVolume > upVolume[1]
  2939. shortvol := downVolume < downVolume[1]
  2940.  
  2941. longCond = bool(na)
  2942. shortCond = bool(na)
  2943.  
  2944.  
  2945. longCond2 = bool(na)
  2946. shortCond2 = bool(na)
  2947.  
  2948. vipcondition = bool(na)
  2949. vimcondition = bool(na)
  2950.  
  2951.  
  2952. if vitype == 'Simple'
  2953. vipcondition := vip > vim
  2954. vimcondition := vip < vim
  2955. else
  2956. vipcondition := vip > vim and vip > viupper and vip > vip[1] and vim < vim[1] and vim[1] <= vilower and vip[1] >= viupper
  2957. vimcondition := vip < vim and vim > viupper and vim > vim[1] and vip < vip [1] and vip[1] <= vilower and vim [1] >= viupper
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963. vipcondition2 = vip > vim
  2964. vimcondition2 = vip < vim
  2965.  
  2966. ///////////////////////////////////ADX Condition ////////////////////////////////////////
  2967. adxcycle = 0
  2968. adxup = ta.crossover(adx, keyLevel)
  2969. adxdown = ta.crossunder(adx, keyLevel)
  2970. adxcycle := adxup ? 1 : adxdown ? -1 : adxcycle[1]
  2971. adxcondition = string(na)
  2972.  
  2973. adxupcondition = bool(na)
  2974. adxdowncondition = bool (na)
  2975. if adxtype == 'Adx & +Di -Di'
  2976. adxupcondition := diplus > diminus and adx>=keyLevel
  2977. adxdowncondition := diplus < diminus and adx>=keyLevel
  2978. if adxtype == 'Adx Only'
  2979. adxupcondition := adx>keyLevel
  2980. adxdowncondition := adx>keyLevel
  2981. else
  2982. if adxcycle == -1
  2983. adxupcondition := diplus > diminus and adx>=keyLevel and diplus - diminus > 1
  2984. adxdowncondition := diplus < diminus and adx>=keyLevel and diminus - diplus > 1
  2985. else if adxcycle==1
  2986. adxupcondition := diplus > diminus and adx>=keyLevel and adx<55 and (adx>adx[1] or (diplus > diplus[1] and diminus < diminus[1])) and diplus - diminus > 1
  2987. adxdowncondition := diplus < diminus and adx>=keyLevel and adx<55 and (adx>adx[1] or (diplus < diplus[1] and diminus > diminus[1])) and diminus - diplus > 1
  2988.  
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994. ///////////////adx condition end/////////////////////////////////////////////////////
  2995.  
  2996. justcontinue = bool(true)
  2997.  
  2998. isstup = bool(na)
  2999. isstdown = bool(na)
  3000. isstup := sttrend == 1
  3001. isstdown := sttrend != 1
  3002.  
  3003. ismacdup = bool(na)
  3004. ismacddown = bool(na)
  3005.  
  3006. isqqeabove = bool(na)
  3007. isqqebelow = bool(na)
  3008.  
  3009. if qqetype == 'Line'
  3010. isqqeabove := qqeline>0
  3011. isqqebelow := qqeline<0
  3012. else if qqetype == 'Bar'
  3013. isqqeabove := RsiMa2 - 50 > 0 and (Greenbar1 and Greenbar2)
  3014. isqqebelow := RsiMa2 - 50 < 0 and (Redbar1 and Redbar2)
  3015. else if qqetype == 'Line & Bar'
  3016. isqqeabove := RsiMa2 - 50 > 0 and (Greenbar1 and Greenbar2) and qqeline>0
  3017. isqqebelow := RsiMa2 - 50 < 0 and (Redbar1 and Redbar2) and qqeline<0
  3018.  
  3019.  
  3020.  
  3021. rsimalong2 = bool(na)
  3022. rsimashort2 = bool(na)
  3023.  
  3024. rsimalong2:= rsiMA >= rsiMA[1]
  3025. rsimashort2:= rsiMA <= rsiMA[1]
  3026.  
  3027.  
  3028. rsilimitlong = rsi >= rsilimitup
  3029. rsilimitshort = rsi <= rsilimitdown
  3030.  
  3031. rsimalimitlong = rsiMA >= rsimalimitup
  3032. rsimalimitshort = rsiMA <= rsimalimitdown
  3033.  
  3034.  
  3035.  
  3036. leadinglongcond = bool(na)
  3037. leadingshortcond = bool(na)
  3038.  
  3039.  
  3040. if leadingindicator == 'Range Filter'
  3041.  
  3042. if rftype == 'Default'
  3043. leadinglongcond := src > filt and src > src[1] and upward > 0 or src > filt and src < src[1] and upward > 0
  3044. leadingshortcond := src < filt and src < src[1] and downward > 0 or src < filt and src > src[1] and downward > 0
  3045. else if rftype == 'DW'
  3046. leadinglongcond := rfupward
  3047. leadingshortcond := rfdownward
  3048.  
  3049. else if leadingindicator == 'DMI (Adx)'
  3050. // respectadx := true
  3051. if adxtype == 'Basic'
  3052. leadinglongcond := diplus > diminus and adx>=keyLevel
  3053. leadingshortcond := diplus < diminus and adx>=keyLevel
  3054. else
  3055. if adxcycle == -1
  3056. leadinglongcond := diplus > diminus and adx>=keyLevel and diplus - diminus > 1
  3057. leadingshortcond := diplus < diminus and adx>=keyLevel and diminus - diplus > 1
  3058. else if adxcycle==1
  3059. leadinglongcond := diplus > diminus and adx>=keyLevel and adx<55 and (adx>adx[1] or (diplus > diplus[1] and diminus < diminus[1])) and diplus - diminus > 1
  3060. leadingshortcond := diplus < diminus and adx>=keyLevel and adx<55 and (adx>adx[1] or (diplus < diplus[1] and diminus > diminus[1])) and diminus - diplus > 1
  3061. else if leadingindicator == 'Parabolic SAR (PSAR)'
  3062. // respectsar := true
  3063. leadinglongcond := out < close
  3064. leadingshortcond := out > close
  3065. else if leadingindicator == 'RQK'
  3066. // respectsar := true
  3067. leadinglongcond := rqkuptrend
  3068. leadingshortcond := rqkdowntrend
  3069.  
  3070. else if leadingindicator == 'Trend Trader'
  3071. // respectsar := true
  3072. leadinglongcond := ttlong
  3073. leadingshortcond := ttshort
  3074.  
  3075.  
  3076. else if leadingindicator == 'Donchian Trend Ribbon'
  3077. // respectsar := true
  3078. leadinglongcond := donchian_long
  3079. leadingshortcond := donchian_short
  3080.  
  3081.  
  3082.  
  3083. else if leadingindicator == '2 EMA Cross'
  3084. // respectsar := true
  3085. leadinglongcond := first_2ema > second_2ema
  3086. leadingshortcond := first_2ema < second_2ema
  3087.  
  3088.  
  3089. else if leadingindicator == '3 EMA Cross'
  3090. // respectsar := true
  3091. leadinglongcond := first_3ema > second_3ema and first_3ema > third_3ema and second_3ema>third_3ema
  3092. leadingshortcond := first_3ema < second_3ema and first_3ema < third_3ema and second_3ema<third_3ema
  3093.  
  3094. else if leadingindicator == 'Chandelier Exit'
  3095. // respectsar := true
  3096. leadinglongcond := ce_long
  3097. leadingshortcond := ce_short
  3098.  
  3099. else if leadingindicator == 'Stochastic'
  3100. // respectsar := true
  3101. leadinglongcond := stoch_long
  3102. leadingshortcond := stoch_short
  3103.  
  3104. else if leadingindicator == 'Vortex Index'
  3105. // respectvi := true
  3106.  
  3107. if vitype == 'Simple'
  3108. leadinglongcond := vip > vim
  3109. leadingshortcond := vip < vim
  3110. else
  3111. leadinglongcond := vip > vim and vip > viupper and vip > vip[1] and vim < vim[1] and vim[1] <= vilower and vip[1] >= viupper
  3112. leadingshortcond := vip < vim and vim > viupper and vim > vim[1] and vip < vip [1] and vip[1] <= vilower and vim [1] >= viupper
  3113.  
  3114. else if leadingindicator == 'Schaff Trend Cycle (STC)'
  3115. // respectstc := true
  3116. leadinglongcond := stc >= upper
  3117. leadingshortcond := stc <= upper
  3118. else if leadingindicator == 'Wolfpack Id'
  3119. // respectstc := true
  3120. leadinglongcond := wolf_long
  3121. leadingshortcond := wolf_short
  3122.  
  3123.  
  3124. else if leadingindicator == 'B-Xtrender'
  3125. // respectstc := true
  3126. leadinglongcond := bx_long
  3127. leadingshortcond := bx_short
  3128.  
  3129.  
  3130. else if leadingindicator == 'Bull Bear Power Trend'
  3131. // respectstc := true
  3132. leadinglongcond := bbpt_long
  3133. leadingshortcond := bbpt_short
  3134.  
  3135. else if leadingindicator == 'QQE Mod'
  3136. // respectqqe := true
  3137. if qqetype == 'Line'
  3138. leadinglongcond := qqeline>0
  3139. leadingshortcond := qqeline<0
  3140. else if qqetype == 'Bar'
  3141. leadinglongcond := RsiMa2 - 50 > 0 and (Greenbar1 and Greenbar2)
  3142. leadingshortcond := RsiMa2 - 50 < 0 and (Redbar1 and Redbar2)
  3143. else if qqetype == 'Line & Bar'
  3144. leadinglongcond := RsiMa2 - 50 > 0 and (Greenbar1 and Greenbar2) and qqeline>0
  3145. leadingshortcond := RsiMa2 - 50 < 0 and (Redbar1 and Redbar2) and qqeline<0
  3146.  
  3147.  
  3148.  
  3149. else if leadingindicator == 'MACD'
  3150. // respectqqe := true
  3151. if macdtype == 'MACD Crossover'
  3152. leadinglongcond := macdd > signal
  3153. leadingshortcond := macdd < signal
  3154. else if macdtype == 'Zero line crossover'
  3155. leadinglongcond := macdd > signal and macdd > 0.00000
  3156. leadingshortcond := macdd < signal and macdd < 0.00000
  3157.  
  3158.  
  3159.  
  3160. else if leadingindicator == 'RSI'
  3161. // respectqqe := true
  3162. if rsitype == 'RSI MA Cross'
  3163. leadinglongcond := rsi > rsiMA
  3164. leadingshortcond := rsi < rsiMA
  3165. else if rsitype == 'RSI Exits OB/OS zones'
  3166. leadinglongcond := rsi > rsi_lower and rsi[1] < rsi_lower
  3167. leadingshortcond := rsi < rsi_upper and rsi[1] > rsi_upper
  3168. else if rsitype == 'RSI Level'
  3169. leadinglongcond := rsi > respectrsilevel
  3170. leadingshortcond := rsi < respectrsilevel
  3171.  
  3172. else if leadingindicator == 'Chaikin Money Flow'
  3173. // respectqqe := true
  3174. leadinglongcond := chaikin_long
  3175. leadingshortcond := chaikin_short
  3176.  
  3177.  
  3178.  
  3179. else if leadingindicator == 'Volatility Oscillator'
  3180. // respectqqe := true
  3181. leadinglongcond := vo_long
  3182. leadingshortcond := vo_short
  3183.  
  3184.  
  3185. else if leadingindicator == 'SSL Channel'
  3186. // respectqqe := true
  3187. leadinglongcond := ssl_long
  3188. leadingshortcond := ssl_short
  3189.  
  3190. else if leadingindicator == 'Awesome Oscillator'
  3191. // respectqqe := true
  3192. leadinglongcond := ao_long
  3193. leadingshortcond := ao_short
  3194.  
  3195.  
  3196. else if leadingindicator == 'Supertrend'
  3197.  
  3198. leadinglongcond := sttrend == 1
  3199. leadingshortcond := sttrend != 1
  3200.  
  3201. else if leadingindicator == 'Waddah Attar Explosion'
  3202.  
  3203. leadinglongcond := wae_long
  3204. leadingshortcond := wae_short
  3205.  
  3206.  
  3207. else if leadingindicator == 'Hull Suite'
  3208. leadinglongcond := HULL > HULL[2]
  3209. leadingshortcond := HULL < HULL[2]
  3210.  
  3211.  
  3212. else if leadingindicator == 'BB Oscillator'
  3213. leadinglongcond := bbosc_long
  3214. leadingshortcond := bbosc_short
  3215.  
  3216. else if leadingindicator == 'Ichimoku Cloud'
  3217. leadinglongcond := ichi_long
  3218. leadingshortcond := ichi_short
  3219.  
  3220. else if leadingindicator == 'VWAP'
  3221. leadinglongcond := long_vwap
  3222. leadingshortcond := short_vwap
  3223.  
  3224. else if leadingindicator == 'SuperIchi'
  3225. leadinglongcond := superichi_long
  3226. leadingshortcond := superichi_short
  3227.  
  3228. else if leadingindicator == 'Trend Meter'
  3229. if tmtype == '3 TM and 2 TB change to same color'
  3230. leadinglongcond := TB1Green and TB2Green and (TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0)
  3231. leadingshortcond := TB1Red and TB2Red and (not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0)
  3232. else if tmtype == '3 TM change to same color'
  3233. leadinglongcond := TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0
  3234. leadingshortcond := not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0
  3235. else if tmtype == '3 TM, 2 TB and Wavetrend change to same color'
  3236. leadinglongcond := TB1Green and TB2Green and (TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0) and MSBar1PositiveWaveTrendSignal
  3237. leadingshortcond := TB1Red and TB2Red and (not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0) and MSBar1NegativeWaveTrendSignal
  3238. else if leadingindicator == 'CCI'
  3239. leadinglongcond := ccilong
  3240. leadingshortcond := ccishort
  3241.  
  3242.  
  3243. tmup = bool(na)
  3244. tmdown = bool(na)
  3245.  
  3246. if tmtype == '3 TM and 2 TB change to same color'
  3247. tmup := TB1Green and TB2Green and (TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0)
  3248. tmdown := TB1Red and TB2Red and (not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0)
  3249. else if tmtype == '3 TM change to same color'
  3250. tmup := TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0
  3251. tmdown := not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0
  3252. else if tmtype == '3 TM, 2 TB and Wavetrend change to same color'
  3253. tmup := TB1Green and TB2Green and (TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0) and MSBar1PositiveWaveTrendSignal
  3254. tmdown := TB1Red and TB2Red and (not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0) and MSBar1NegativeWaveTrendSignal
  3255.  
  3256. hullup = bool(na)
  3257. hulldown = bool(na)
  3258. if respecthull
  3259. hullup := HULL > HULL[2]
  3260. hulldown := HULL < HULL[2]
  3261.  
  3262. rsiup = bool (na)
  3263. rsidown = bool (na)
  3264.  
  3265. if rsitype == 'RSI MA Cross'
  3266. rsiup := rsi > rsiMA
  3267. rsidown := rsi < rsiMA
  3268. else if rsitype == 'RSI Exits OB/OS zones'
  3269. rsiup := rsi > rsi_lower and rsi[1] < rsi_lower
  3270. rsidown := rsi < rsi_upper and rsi[1] > rsi_upper
  3271. else if rsitype == 'RSI Level'
  3272. rsiup := rsi > respectrsilevel
  3273. rsidown := rsi < respectrsilevel
  3274.  
  3275.  
  3276. if macdtype == 'MACD Crossover'
  3277. ismacdup := macdd > signal
  3278. ismacddown := macdd < signal
  3279. else if macdtype == 'Zero line crossover'
  3280. ismacdup := macdd > signal and macdd > 0.00000
  3281. ismacddown := macdd < signal and macdd < 0.00000
  3282.  
  3283. ema2_long = first_2ema > second_2ema
  3284. ema2_short = first_2ema < second_2ema
  3285.  
  3286. uprf = bool (na)
  3287. downrf = bool(na)
  3288.  
  3289.  
  3290. if rftype == 'Default'
  3291. uprf := src > filt and src > src[1] and upward > 0 or src > filt and src < src[1] and upward > 0
  3292. downrf := src < filt and src < src[1] and downward > 0 or src < filt and src > src[1] and downward > 0
  3293. else if rftype == 'DW'
  3294. uprf := rfupward
  3295. downrf := rfdownward
  3296.  
  3297. ema3_long = first_3ema > second_3ema and first_3ema > third_3ema and second_3ema>third_3ema
  3298. ema3_short = first_3ema < second_3ema and first_3ema < third_3ema and second_3ema<third_3ema
  3299.  
  3300.  
  3301. longCond := leadinglongcond and (respectrf?uprf:justcontinue) and
  3302. (respectadx?adxupcondition:justcontinue) and (respectdonchian?donchian_long:justcontinue) and (respectbbpt?bbpt_long:justcontinue) and (respectrqk?rqkuptrend:justcontinue) and (respectbx?bx_long:justcontinue) and (respectbbosc?bbosc_long:justcontinue) and (respectwae?wae_long:justcontinue) and (respectce?ce_long:justcontinue) and (respectssl?ssl_long:justcontinue) and (respect2ma?ema2_long:justcontinue) and (respect3ma?ema3_long:justcontinue) and (respectstochastic?stoch_long:justcontinue) and (respectcci?ccilong:justcontinue) and (respectst?isstup:justcontinue) and (respectrsi?rsiup:justcontinue) and (respectrsimalimit?rsimalimitlong:justcontinue) and (respectrsilimit?rsilimitlong:justcontinue) and (respectrsima?rsimalong2:justcontinue) and (respectema?isaboverespectema:justcontinue) and (respectqqe?isqqeabove:justcontinue) and (respectsar?sarup:justcontinue) and
  3303. (respectvol?longvol:justcontinue) and (respectchaikin?chaikin_long:justcontinue) and (respectvwap?long_vwap:justcontinue) and (respectvo?vo_long:justcontinue) and (respectao?ao_long:justcontinue) and (respectsuperichi?superichi_long:justcontinue) and (respectwolf?wolf_long:justcontinue) and (respectichi?ichi_long:justcontinue) and (respectmacd?ismacdup:justcontinue) and (respecthull?hullup:justcontinue) and (respectvi?vipcondition:justcontinue) and (respecttm?tmup:justcontinue) and (respectstc?stcup:justcontinue) and (respectdv?dvup:justcontinue)
  3304.  
  3305. shortCond := leadingshortcond and (respectrf?downrf:justcontinue) and
  3306. (respectadx?adxdowncondition:justcontinue) and (respectdonchian?donchian_short:justcontinue) and (respectbbpt?bbpt_short:justcontinue) and (respectrqk?rqkdowntrend:justcontinue) and (respectbx?bx_short:justcontinue) and (respectbbosc?bbosc_short:justcontinue) and (respectwae?wae_short:justcontinue) and (respectce?ce_short:justcontinue) and (respectssl?ssl_short:justcontinue) and (respectchaikin?chaikin_short:justcontinue) and (respect2ma?ema2_short:justcontinue) and (respect3ma?ema3_short:justcontinue) and (respectstochastic?stoch_short:justcontinue) and (respectcci?ccishort:justcontinue) and (respectrsimalimit?rsimalimitshort:justcontinue) and (respectrsilimit?rsilimitshort:justcontinue) and (respectrsima?rsimashort2:justcontinue) and (respectst?isstdown:justcontinue) and (respectrsi?rsidown:justcontinue) and (respectema?isbelowrespectema:justcontinue) and (respectqqe?isqqebelow:justcontinue) and (respectsar?sardown:justcontinue) and
  3307. (respectvol?shortvol:justcontinue) and (respectvwap?short_vwap:justcontinue) and (respectvo?vo_short:justcontinue) and (respectao?ao_short:justcontinue) and (respectsuperichi?superichi_short:justcontinue) and (respectwolf?wolf_short:justcontinue) and (respectichi?ichi_short:justcontinue) and (respectmacd?ismacddown:justcontinue) and (respecthull?hulldown:justcontinue) and (respectvi?vimcondition:justcontinue) and (respecttm?tmdown:justcontinue) and (respectstc?stcdown:justcontinue) and (respectdv?dvup:justcontinue)
  3308.  
  3309.  
  3310.  
  3311.  
  3312.  
  3313. var int leadinglong_count = 0
  3314. var int leadinglong_count2 = 0
  3315.  
  3316. var int leadingshort_count = 0
  3317. var int leadingshort_count2 = 0
  3318.  
  3319.  
  3320. if leadinglongcond
  3321. leadinglong_count := leadinglong_count + 1
  3322. leadinglong_count2 := leadinglong_count
  3323.  
  3324. for i = 1 to 100
  3325. if leadinglongcond[i]
  3326. leadinglong_count := leadinglong_count + 1
  3327. leadinglong_count2 := leadinglong_count
  3328.  
  3329. else
  3330. leadinglong_count := 0
  3331. break
  3332.  
  3333.  
  3334. if leadingshortcond
  3335. leadingshort_count := leadingshort_count + 1
  3336. leadingshort_count2 := leadingshort_count
  3337.  
  3338. for i = 1 to 100
  3339. if leadingshortcond[i]
  3340. leadingshort_count := leadingshort_count + 1
  3341. leadingshort_count2 := leadingshort_count
  3342.  
  3343. else
  3344. leadingshort_count := 0
  3345. break
  3346.  
  3347. CondIni = 0
  3348.  
  3349. longCondition = bool (na)
  3350. shortCondition = bool(na)
  3351.  
  3352.  
  3353.  
  3354.  
  3355. // if expiry option is used
  3356. longcond_withexpiry = longCond and leadinglong_count2 <= signalexpiry
  3357. shortcond_withexpiry = shortCond and leadingshort_count2 <= signalexpiry
  3358.  
  3359.  
  3360. //without expiry
  3361. longCondition := longcond_withexpiry and CondIni[1] == -1
  3362. shortCondition := shortcond_withexpiry and CondIni[1] == 1
  3363.  
  3364.  
  3365.  
  3366. if respect_expiry_count
  3367. if alternatesignal
  3368. longCondition := longcond_withexpiry and CondIni[1] == -1 and leadinglong_count2 <= signalexpiry
  3369. shortCondition := shortcond_withexpiry and CondIni[1] == 1 and leadingshort_count2 <= signalexpiry
  3370.  
  3371. else
  3372. longCondition := longcond_withexpiry and leadinglong_count2 <= signalexpiry
  3373. shortCondition := shortcond_withexpiry and leadingshort_count2 <= signalexpiry
  3374.  
  3375.  
  3376. else
  3377.  
  3378. if alternatesignal
  3379. longCondition := longcond_withexpiry and CondIni[1] == -1
  3380. shortCondition := shortcond_withexpiry and CondIni[1] == 1
  3381.  
  3382. else
  3383. longCondition := longcond_withexpiry
  3384. shortCondition := shortcond_withexpiry
  3385.  
  3386.  
  3387.  
  3388. CondIni := longcond_withexpiry ? 1 : shortcond_withexpiry ? -1 : CondIni[1]
  3389.  
  3390.  
  3391. is_expiry_count_crossed_long = leadinglong_count2 > signalexpiry
  3392. is_expiry_count_crossed_short = leadingshort_count2 > signalexpiry
  3393.  
  3394.  
  3395.  
  3396.  
  3397.  
  3398. plotshape(longCondition[1] ?false :longCondition, title='Buy Signal', text='long', textcolor=color.new(color.white, 0), style=shape.labelup, size=size.tiny, location=location.belowbar, color=color.new(color.green, 0))
  3399. plotshape(shortCondition, title='Sell Signal', text='short', textcolor=color.new(color.white, 0), style=shape.labeldown, size=size.tiny, location=location.abovebar, color=color.new(color.red, 0))
  3400. //plotchar(is_expiry_count_crossed_long, title='count')
  3401. plotshape(is_expiry_count_crossed_long and not is_expiry_count_crossed_long[1] and CondIni == -1 ? true:false, title='Expired Signal',text='', textcolor=color.new(color.white, 0), style=shape.circle, size=size.tiny, location=location.abovebar, color=color.new(color.red, 0))
  3402. plotshape(is_expiry_count_crossed_short and not is_expiry_count_crossed_short[1] and CondIni == 1? true:false, title='Expired Signal',text='', textcolor=color.new(color.white, 0), style=shape.circle, size=size.tiny, location=location.belowbar, color=color.new(#dd1111, 0))
  3403.  
  3404.  
  3405.  
  3406. alertcondition(longCondition, title='Buy Alert', message='BUY')
  3407. alertcondition(shortCondition, title='Sell Alert', message='SELL')
  3408.  
  3409.  
  3410.  
  3411. rsitype2 = rsitype
  3412. if rsitype2 == "RSI Level"
  3413. rsitype2 := "RSI Level (" + str.tostring(respectrsilevel) +")"
  3414.  
  3415.  
  3416. confirmation_counter = array.new_string(0)
  3417. confirmation_val = array.new_string(0)
  3418. confirmation_val_short = array.new_string(0)
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424. pushConfirmation(respect, label, longCondition, shortCondition) =>
  3425. if respect
  3426. array.push(confirmation_counter, label)
  3427. array.push(confirmation_val, longCondition ? "✔️" : "❌")
  3428. array.push(confirmation_val_short, shortCondition ? "✔️" : "❌")
  3429.  
  3430. pushConfirmation(respectema, "EMA", isaboverespectema, isbelowrespectema)
  3431. pushConfirmation(respect2ma, "2 EMA Cross (" + str.tostring(respect2maperiod_1) + "," + str.tostring(respect2maperiod_2) + ")", ema2_long, ema2_short)
  3432. pushConfirmation(respect3ma, "3 EMA Cross (" + str.tostring(respect3maperiod_1) + "," + str.tostring(respect3maperiod_2) + "," + str.tostring(respect3maperiod_3) + ")", ema3_long, ema3_short)
  3433. pushConfirmation(respectrf, "Range Filter", uprf, downrf)
  3434. pushConfirmation(respectrqk, "RQK", rqkuptrend, rqkdowntrend)
  3435. pushConfirmation(respectst, "SuperTrend", isstup, isstdown)
  3436. pushConfirmation(respectdonchian, "Donchian Trend Ribbon", donchian_long, donchian_short)
  3437. pushConfirmation(respectbx, "B-Xtrender (" + str.tostring(bxtype) + ")", bx_long, bx_short)
  3438. pushConfirmation(respectbbpt, "Bull Bear Power Trend (" + str.tostring(bbpttype) + ")", bbpt_long, bbpt_short)
  3439. pushConfirmation(respectvwap, "VWAP", long_vwap, short_vwap)
  3440. pushConfirmation(respectichi, "Ichimoku Cloud", ichi_long, ichi_short)
  3441. pushConfirmation(respectsuperichi, "Superichi", superichi_long, superichi_short)
  3442. pushConfirmation(respectbbosc, "BB Oscillator", bbosc_long, bbosc_short)
  3443. pushConfirmation(respecttm, "Trend Meter", tmup, tmdown)
  3444. pushConfirmation(respectce, "Chandelier Exit", ce_long, ce_short)
  3445. pushConfirmation(respectcci, "CCI", ccilong, ccishort)
  3446. pushConfirmation(respectadx, "DMI (Adx) (" + str.tostring(adxtype) + ")", adxupcondition, adxdowncondition)
  3447. pushConfirmation(respectsar, "Parabolic SAR", sarup, sardown)
  3448. pushConfirmation(respectssl, "SSL Channel", ssl_long, ssl_short)
  3449. pushConfirmation(respectvo, "Volatility Oscillator", vo_long, vo_short)
  3450. pushConfirmation(respectdv, "DV", dvup, dvup) // Note: Both are 'dvup'. Double-check if it's intended.
  3451. pushConfirmation(respectstochastic, "Stochastic (" + str.tostring(stochtype) + ")", stoch_long, stoch_short)
  3452. pushConfirmation(respectrsi, "RSI (" + str.tostring(rsitype2) + ")", rsiup, rsidown)
  3453. pushConfirmation(respectmacd, "MACD (" + str.tostring(macdtype) + ")", ismacdup, ismacddown)
  3454. pushConfirmation(respectstc, "Schaff Trend Cycle", stcup, stcdown)
  3455. pushConfirmation(respectwae, "Waddah Attar Explosion", wae_long, wae_short)
  3456.  
  3457. pushConfirmation(respectchaikin, "Chaikin Money Flow", chaikin_long, chaikin_short)
  3458. pushConfirmation(respectvol, "Volume", longvol, shortvol)
  3459. pushConfirmation(respectao, "Awesome Oscillator(" + str.tostring(aotype) + ")", ao_long, ao_short)
  3460. pushConfirmation(respectwolf, "Wolfpack Id", wolf_long, wolf_short)
  3461. pushConfirmation(respectqqe, "QQE Mod (" + str.tostring(qqetype) + ")", isqqeabove, isqqebelow)
  3462. pushConfirmation(respecthull, "HullSuite", hullup, hulldown)
  3463. pushConfirmation(respectvi, "Vortex Index (" + str.tostring(vitype) + ")", vipcondition, vimcondition)
  3464.  
  3465.  
  3466.  
  3467.  
  3468. leadingstatus = leadinglongcond ? "✔️" : "❌"
  3469. leadingstatus_short = leadingshortcond ? "✔️" : "❌"
  3470.  
  3471.  
  3472. rowcount = int(na)
  3473. if array.size(confirmation_counter) ==0
  3474. rowcount := 5
  3475. else
  3476. rowcount := array.size(confirmation_counter)+4
  3477.  
  3478.  
  3479. if showdashboard
  3480. var table tab1 = table.new(i_tab1Ypos + '_' + i_tab1Xpos, 3, rowcount, color.rgb(42, 46, 57), color.rgb(204, 204, 204), 0, color.rgb(77, 71, 71), 1)
  3481.  
  3482.  
  3483. table.cell(tab1, 1, 0,"Long", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(61, 189, 72),text_color=color.white)
  3484. table.cell(tab1, 2, 0,"Short", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(243, 77, 77),text_color=color.white)
  3485.  
  3486.  
  3487. table.cell(tab1, 0, 1, "Leading Indicator", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(68, 68, 67),text_color=color.white)
  3488. table.cell(tab1, 1, 1,"", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(68, 68, 67),text_color=color.white)
  3489. table.cell(tab1, 2, 1,"", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(68, 68, 67),text_color=color.white)
  3490.  
  3491.  
  3492. table.cell(tab1, 0, 2, leadingindicator, text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3493. table.cell(tab1, 1, 2, leadingstatus, text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3494. table.cell(tab1, 2, 2, leadingstatus_short, text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3495.  
  3496.  
  3497. table.cell(tab1, 0, 3, "Confirmation Indicators", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(68, 68, 67),text_color=color.white)
  3498. table.cell(tab1, 1, 3, "", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(68, 68, 67),text_color=color.white)
  3499. table.cell(tab1, 2, 3, "", text_halign=text.align_left, text_size=size.normal, bgcolor=color.rgb(68, 68, 67),text_color=color.white)
  3500.  
  3501. if array.size(confirmation_counter) > 0
  3502. for i=0 to array.size(confirmation_counter)-1
  3503. table.cell(tab1, 0, 4+i, array.get(confirmation_counter,i), text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3504. else
  3505. table.cell(tab1, 0, 4, "None Selected", text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3506.  
  3507.  
  3508. if array.size(confirmation_val) > 0
  3509. for j=0 to array.size(confirmation_val)-1
  3510. table.cell(tab1, 1, 4+j, array.get(confirmation_val,j), text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3511. table.cell(tab1, 2, 4+j, array.get(confirmation_val_short,j), text_halign=text.align_left, text_size=size.normal, text_color=color.white)
  3512.  
  3513.  
  3514.  
  3515. iff_1 = close[0] == close[1] ? color.rgb(42, 46, 57) : color.rgb(42, 46, 57)
  3516. iff_2 = close[0] < close[1] ? color.red : iff_1
  3517. // ALERTS {
  3518.  
Comments
  • hemal9022
    1 year
    # text 0.12 KB | 0 0
    1. i got all types of premium tradingview indicators codes available on telegram -
    2. https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment