Advertisement
readyset-liqd

Pinescript Indicator: Trend Pooristics with Alerts

May 30th, 2022
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.90 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  3. // © danielx888
  4. // Credits to Joy_Bangla for the Leledc exhaustion bar code
  5. // Credits to VishvaP for the 34 EMA bands code
  6. // Credits to SlumdogTrader for the BB exhaustion code (edited for functionality)
  7. // Credits to Juanc2316 for his code for BB Keltner Squeeze
  8.  
  9. //@version=5
  10. indicator(title='EMA bands trend and scalping indi w/ alerts', shorttitle='Trend Pooristics', overlay=true, max_bars_back=200)
  11.  
  12.  
  13. //////USER INPUTS
  14. //INPUT: OPEN
  15. i_EMAlength = input.int (34, 'EMA Length', minval=1, step=1)
  16. i_topMBmult = input.float (1, 'Top middle band multiplier', 0.1,3,step=0.1,group='Open Conditions')
  17. i_botMBmult = input.float (1, 'Bottom middle band multiplier',0.1,3,step=0.1,group='Open Conditions')
  18. s_useSlowEMA = input.bool (false, title='Use slow EMA filter',tooltip='Condition does not apply to counter-trend trades', group='Open Conditions')
  19. i_slowEMAlen = input.int (200, title='Slow EMA Length', step=1, minval=1, group='Open Conditions')
  20. //INPUT: CLOSE
  21. i_midClose = input.string('Opposite band', 'Close on crosses through middle EMA bands', tooltip='Selecting "Delayed bars inside" will closing positions after specified amount of candles close in between the middle EMA bands without breaking out', options=['Nearest band', 'Opposite band', 'Delayed bars inside'], group='Close Conditions')
  22. i_numBars = input.int (4, 'Delayed close no. of bars', minval=1, maxval=10, step=1, group='Close Conditions')
  23. s_whichBuySellBars = input.string('Inner', 'Which Buy/Sell zone?', options=['Inner', 'Outer'], group='Close Conditions')
  24. //INPUT: KELTNER BUY/SELL ZONES
  25. s_keltnerBuySell = input.bool (false, 'Use Keltner channel multiples for "Buy/Sell Zones"',tooltip='Enables inputting custom multiples and a different/smoother calculation of "Buy/Sell Zones". Default calculation is a multiple of EMA band highs and lows', group='Keltner Buy/Sell Zones')
  26. i_mult = input.float (5.0, "Outer Multiplier", tooltip='Only for "Buy/Sell Zones" calculated by Keltner channels', group='Keltner Buy/Sell Zones')
  27. i_innerMult = input.float (3.0, "Inner Multiplier", tooltip='Only for "Buy/Sell Zones" calculated by Keltner channels', group='Keltner Buy/Sell Zones')
  28. //INPUT: VOLATILITY SQUEEZE FILTER
  29. s_squeezeFilter = input.bool (false, 'Filter out trades during BB-Keltner squeezes', group= 'BB-Keltner squeze')
  30. i_bbCondition = input.string('At Least One', title='Bollinger Band Crossover Condition', options=['Both', 'At Least One'], group= 'BB-Keltner squeze')
  31. i_bbSqueezeLength = input.int (30, minval=1, title='BB Length', group= 'BB-Keltner squeze')
  32. i_ktSqueezeLength = input.int (18, minval=1, title='Keltner Length', group= 'BB-Keltner squeze')
  33. s_useRes = input.bool (false, 'Use current timeframe', group= 'BB-Keltner squeze')
  34. res = (s_useRes ? '' :input.timeframe('360', 'Resolution for BB-Keltner squeeze', group= 'BB-Keltner squeze'))
  35. i_B2mult = input.float (2, minval=0.001, maxval=50, title='BB Standard Deviation', group= 'BB-Keltner squeze')
  36. i_Kmult = input.float (1.5, title='Keltner Range', group= 'BB-Keltner squeze')
  37. //INPUT: BOLLINGER BANDS EXHAUSTION BARS
  38. i_BBlength = input.int (20, minval=1, title='Bollinger Bands SMA Period Length', group='Bollinger Bands Exhaustion Bar Settings')
  39. i_BBmult = input.float (1.8, minval=0.001, maxval=50, title='Bollinger Bands Standard Deviation', group='Bollinger Bands Exhaustion Bar Settings')
  40. i_RSIlength = input.int (8, minval=1, step=1, title='RSI Period Length', group='Bollinger Bands Exhaustion Bar Settings')
  41. i_RSIos = input.int (30, minval=0, maxval=50, step=1,title='RSI Oversold Value', group='Bollinger Bands Exhaustion Bar Settings')
  42. i_RSIob = input.int (70, minval=50, maxval=100, step=1, title='RSI Overbought value', group='Bollinger Bands Exhaustion Bar Settings')
  43. i_srcBB = input.source(close, title='Source', group='Bollinger Bands Exhaustion Bar Settings')
  44. //INPUT: LELEDC
  45. s_reqLeleBuySell = input.bool (false, 'Require Leledc to fall outside Buy/Sell zone to show', group='Leledc Exhaustion Bar Settings')
  46. i_ctLeleBuySell = input.string('Inner', 'Leledc/BB must be outside which Buy/Sell zone to open', options=['Inner', 'Outer'], group='Leledc Exhaustion Bar Settings')
  47. i_leleVol = input.bool (false, 'Require Volume breakout for Leledc bars', group='Leledc Exhaustion Bar Settings')
  48. i_volMult = input.float (1.5,'Volume Multiplier', 0.1,20,0.1, group='Leledc Exhaustion Bar Settings')
  49. i_majLen = input.int (30, 'Highest / Lowest', group='Leledc Exhaustion Bar Settings')
  50. i_majQual = input.int (6, 'Bar count no', group='Leledc Exhaustion Bar Settings')
  51. i_closeVal = input.int (4, 'Close', group='Leledc Exhaustion Bar Settings')
  52. i_bindexSindex = input.int (1, 'bindexSindex', group='Leledc Exhaustion Bar Settings')
  53. //INPUT: VISUAL ELEMENTS
  54. s_trendColor = input.bool (false, 'Enable Trend Bar Color', tooltip='Color bars green when above mid bands, red when below, and gray when inside. Dark green and dark red bars signal a position is kept open from the delayed close settings.', group='Visual Elements')
  55. s_showBuySell = input.bool (true, 'Show "Buy/Sell Zones"', group='Visual Elements')
  56. s_showEMA = input.bool (false, 'Show EMA', group='Visual Elements')
  57. s_showMiddleBands = input.bool (true, 'Show middle EMA bands', group='Visual Elements')
  58. s_showSlowEMA = input.bool (false, 'Show Slow EMA', group='Visual Elements')
  59. s_showMaj = input.bool (true, 'Show Leledc Exhausion Bars', group='Visual Elements')
  60. s_switch1 = input.bool (true, 'Enable Bollinger Bands exhaustion bar coloring', group='Visual Elements')
  61. s_switch2 = input.bool (false, 'Enable Bollinger bands exhaustion bar background coloring', tooltip='Enabling this can help visualize when dialing in Bollinger Bands and RSI settings', group='Visual Elements')
  62. s_colorBuySellBars = input.bool (false, 'Enable Buy/Sell zone failure bar coloring', group='Visual Elements')
  63.  
  64. //EMA
  65. EMA = ta.ema(close, i_EMAlength)
  66. slowEMA = ta.ema(close, i_slowEMAlen)
  67. plot(s_showSlowEMA ? slowEMA : na, 'Slow EMA', color.new(color.gray, 20), 3)
  68.  
  69. //*****************************
  70. // SlumdogTrader's Bollinger Bands + RSI Double Strategy - Profit Trailer
  71. //====================================================================================================//
  72. //BB VARIABLES
  73. BBbasis = ta.sma(i_srcBB, i_BBlength)
  74. BBdev = i_BBmult * ta.stdev(i_srcBB, i_BBlength)
  75. BBupper = BBbasis + BBdev
  76. BBlower = BBbasis - BBdev
  77.  
  78. //RSI VARIABLES
  79. vrsi = ta.rsi(i_srcBB, i_RSIlength)
  80. RSIoverSold = vrsi < i_RSIos
  81. RSIoverBought = vrsi > i_RSIob
  82.  
  83. //BB EXHAUSTION BAR COLOR VARIABLE
  84. OSOBcolor = RSIoverBought and i_srcBB[1] > BBupper and i_srcBB < BBupper ? color.yellow : RSIoverSold and i_srcBB[1] < BBlower and i_srcBB > BBlower ? color.blue : na
  85. bgcolor(s_switch2 ? color.new(OSOBcolor,70) : na)
  86. //====================================================================================================//
  87. //*****************************
  88.  
  89. //KELTNER SELL ZONE
  90. rangema = s_keltnerBuySell ? ta.rma(high - low, i_EMAlength) : 0.0
  91. kt_outersell(_ma) =>
  92. upper = EMA + _ma * i_mult
  93. upper
  94. kt_innersell(_ma) =>
  95. inner_upper = EMA + _ma * i_innerMult
  96. inner_upper
  97. kt_outerbuy(_ma) =>
  98. lower = EMA - _ma * i_mult
  99. lower
  100. kt_innerbuy(_ma) =>
  101. inner_lower = EMA - _ma * i_innerMult
  102. inner_lower
  103. //*****************************
  104.  
  105.  
  106. //*****************************
  107. // BB-Keltner Squeeze-FVBO-2.0
  108. // Modified by Juan C for FVBO Strategy, some source code from Trader-Elisa
  109. //====================================================================================================//
  110. //VARIABLES FOR HTF SOURCES
  111. rp_security(_sym, _res, _src)=> request.security(_sym, _res, _src[barstate.ishistory ? 0 : 1], gaps=barmerge.gaps_on)
  112. srcClose = rp_security(syminfo.tickerid, res, close)
  113. srcHigh = rp_security(syminfo.tickerid, res, high)
  114. srcLow = rp_security(syminfo.tickerid, res, low)
  115.  
  116. //SQUEEZE BOLLINGER BANDS
  117. B2basis = ta.sma(srcClose, i_bbSqueezeLength)
  118. B2dev = i_B2mult * ta.stdev(srcClose, i_bbSqueezeLength)
  119. B2upper = B2basis + B2dev
  120. B2lower = B2basis - B2dev
  121.  
  122. //SQUEEZE KELTNER CHANNELS
  123. Kma = ta.ema(srcClose, i_ktSqueezeLength)
  124. Krange =srcHigh - srcLow
  125. Krangema = ta.ema(Krange, i_ktSqueezeLength)
  126. Kupper = Kma + Krangema * i_Kmult
  127. Klower = Kma - Krangema * i_Kmult
  128.  
  129. //DEFINE SQUEEZE
  130. var bool squeezing = false
  131. if s_squeezeFilter
  132. if i_bbCondition == 'Both' and s_useRes
  133. squeezing := B2upper <= Kupper and B2lower >= Klower ? true : false
  134. squeezing
  135. else if i_bbCondition == 'At Least One' and s_useRes
  136. squeezing := B2upper <= Kupper or B2lower >= Klower ? true : false
  137. squeezing
  138. else if i_bbCondition == 'Both'
  139. squeezing := B2upper[ta.barssince(not srcClose == barstate.isrealtime)] <= Kupper[ta.barssince(not srcClose == barstate.isrealtime)] and B2lower[ta.barssince(not srcClose == barstate.isrealtime)] >= Klower[ta.barssince(not srcClose == barstate.isrealtime)] ? true : false
  140. squeezing
  141. else
  142. squeezing := B2upper[ta.barssince(not srcClose == barstate.isrealtime)] <= Kupper[ta.barssince(not srcClose == barstate.isrealtime)] or B2lower[ta.barssince(not srcClose == barstate.isrealtime)] >= Klower[ta.barssince(not srcClose == barstate.isrealtime)] ? true : false
  143. squeezing
  144.  
  145. //VISUAL
  146. cross_over_color = (squeezing ? color.new(color.aqua, 90) : na)
  147. bgcolor(color=cross_over_color, title='Cross Over Identification Color')
  148. //*****************************
  149.  
  150.  
  151. //*****************************
  152. // © VishvaP 34 EMA Bands v2
  153. //====================================================================================================//
  154. //BUILD EMA MIDDLE BANDS
  155. highShortEMA = ta.ema(high, i_EMAlength)
  156. lowShortEMA = ta.ema(low, i_EMAlength)
  157. middleBandTop = (highShortEMA - EMA) * i_topMBmult + EMA
  158. middleBandBot = (lowShortEMA - EMA) * i_botMBmult + EMA
  159.  
  160. //==============================================//
  161. //1D Bands [Not Used]
  162. //bandsHigh = highShortEMA * math.phi
  163. //bandsLow = lowShortEMA * math.rphi
  164.  
  165. //==============================================//
  166. //INNER BUY/SELL ZONES
  167. shortbandsHigh = s_keltnerBuySell ? kt_innersell(rangema) : ((highShortEMA - EMA) * math.phi) * math.pi + EMA
  168. shortbandsLow = s_keltnerBuySell ? kt_innerbuy(rangema) : (-(EMA - lowShortEMA) * math.phi) * math.pi + EMA
  169. //SMOOTH INNER
  170. shortbandsHighEMA = ta.wma(shortbandsHigh, 8)
  171. shortbandsLowEMA = ta.wma(shortbandsLow, 8)
  172.  
  173. //==============================================//
  174. //OUTER BUY/SELL ZONES
  175. phiExtensionHigh = s_keltnerBuySell ? kt_outersell(rangema) : ((highShortEMA - EMA) * math.phi) * (math.phi + 4) + EMA
  176. phiExtensionLow = s_keltnerBuySell ? kt_outerbuy(rangema) : (-(EMA - lowShortEMA) * math.phi) * (math.phi + 4) + EMA
  177. //SMOOTH OUTER
  178. phiExtensionHighEMA = ta.wma(phiExtensionHigh, 8)
  179. phiExtensionLowEMA = ta.wma(phiExtensionLow, 8)
  180.  
  181. //==============================================//
  182. //PLOT MIDDLE BANDS AND EMA
  183. highP1 = plot(s_showMiddleBands ? middleBandTop : na, color = color.new(color.blue, 100), title = "Top median zone")
  184. lowP1 = plot(s_showMiddleBands ? middleBandBot : na, color = color.new(color.blue, 100), title = "Bottom median zone")
  185. plot(s_showEMA ? EMA : na, color = color.new(color.gray, 0), title = "EMA")
  186.  
  187. //1D bands [not used]
  188. //highP2 = plot(bandsHigh)
  189. //lowP2 = plot(bandsLow)
  190. //PLOT BUY/SELL ZONES
  191. highP3 = plot(s_showBuySell ? shortbandsHighEMA : na, color = color.new(color.yellow, 100), title = "Inner sell zone")
  192. lowP3 = plot(s_showBuySell ? shortbandsLowEMA : na, color = color.new(color.teal, 100), title = "Inner buy zone")
  193. phiPlotHigh = plot(s_showBuySell ? phiExtensionHighEMA : na, color = color.new(color.red, 100), title = "Outer sell zone")
  194. phiPlotLow = plot(s_showBuySell ? phiExtensionLowEMA : na, color = color.new(color.green, 100), title = "Outer buy zone")
  195.  
  196. //==============================================//
  197. //BUY/SELL ZONE AND MIDDLE BAND COLOR FILLS
  198. fill(phiPlotHigh, highP3, color.new(color.red, 85), title = "Sell zone")
  199. fill(lowP3, phiPlotLow, color.new(color.green, 85), title = "Buy zone")
  200. fill(highP1, lowP1, color.new(color.gray, 70), title = "Median zone")
  201. //====================================================================================================//
  202. //*****************************
  203.  
  204. //ASSIGN BANDS FOR COUNTERTREND ENTRIES
  205. float CTbandTop = na
  206. float CTbandBottom = na
  207. if i_ctLeleBuySell == 'Inner'
  208. CTbandTop := shortbandsHighEMA
  209. CTbandBottom := shortbandsLowEMA
  210. else
  211. CTbandTop := phiExtensionHighEMA
  212. CTbandBottom := phiExtensionLowEMA
  213.  
  214. //BUILD VARIABLES FOR CROSSES
  215. crossUpTopMB = open < middleBandTop and close > middleBandTop
  216. wiggleUpTopMB = open > middleBandTop and close > middleBandTop and close[1] <= middleBandTop[1]
  217. crossDownTopMB = open > middleBandTop and close < middleBandTop
  218. wiggleDownTopMB = open < middleBandTop and close < middleBandTop and close[1] >= middleBandTop[1]
  219. failTopMB = crossDownTopMB or wiggleDownTopMB
  220.  
  221. crossUpBotMB = open < middleBandBot and close > middleBandBot
  222. wiggleUpBotMB = open > middleBandBot and close > middleBandBot and close[1] <= middleBandBot[1]
  223. crossDownBotMB = open > middleBandBot and close < middleBandBot
  224. wiggleDownBotMB = open < middleBandBot and close < middleBandBot and close[1] >= middleBandBot[1]
  225. failBotMB = crossUpBotMB or wiggleUpBotMB
  226.  
  227. crossUpBotInnerRB = open < shortbandsLowEMA and close > shortbandsLowEMA
  228. wiggleUpBotInnerRB = open > shortbandsLowEMA and close > shortbandsLowEMA and close[1] <= shortbandsLowEMA[1]
  229. crossUpBotOuterRB = open < phiExtensionLowEMA and close > phiExtensionLowEMA
  230. wiggleUpBotOuterRB = open > phiExtensionLowEMA and close > phiExtensionLowEMA and close[1] <= phiExtensionLowEMA[1]
  231.  
  232. crossUpTopInnerRB = open < shortbandsHighEMA and close > shortbandsHighEMA
  233. wiggleUpTopInnerRB = open > shortbandsHighEMA and close > shortbandsHighEMA and close[1] <= shortbandsHighEMA[1]
  234. crossUpTopOuterRB = open < phiExtensionHighEMA and close > phiExtensionHighEMA
  235. wiggleUpTopOuterRB = open > phiExtensionHighEMA and close > phiExtensionHighEMA and close[1] <= phiExtensionHighEMA[1]
  236.  
  237. crossDownBotInnerRB = open > shortbandsLowEMA and close < shortbandsLowEMA
  238. wiggleDownBotInnerRB = open < shortbandsLowEMA and close < shortbandsLowEMA and close[1] >= shortbandsLowEMA[1]
  239. crossDownBotOuterRB = open > phiExtensionLowEMA and close < phiExtensionLowEMA
  240. wiggleDownBotOuterRB = open < phiExtensionLowEMA and close < phiExtensionLowEMA and close[1] >= phiExtensionLowEMA[1]
  241.  
  242. crossDownTopInnerRB = open > shortbandsHighEMA and close < shortbandsHighEMA
  243. wiggleDownTopInnerRB = open < shortbandsHighEMA and close < shortbandsHighEMA and close[1] >= shortbandsHighEMA[1]
  244. crossDownTopOuterRB = open > phiExtensionHighEMA and close < phiExtensionHighEMA
  245. wiggleDownTopOuterRB = open < phiExtensionHighEMA and close < phiExtensionHighEMA and close[1] >= phiExtensionHighEMA[1]
  246.  
  247. //BUILD VARIABLES FOR CLOSING CONDITIONS
  248. shortMidBreak = s_squeezeFilter ? (crossDownBotMB or wiggleDownBotMB) and squeezing == false : crossDownBotMB or wiggleDownBotMB
  249. longMidBreak = s_squeezeFilter ? (crossUpTopMB or wiggleUpTopMB) and squeezing == false: crossUpTopMB or wiggleUpTopMB
  250.  
  251. //==============================================//
  252.  
  253. //VARIABLES: CONDITIONS OF LOSS OF BUY/SELL ZONES
  254. var bool crossUpRB = false
  255. var bool wiggleUpRB = false
  256. var bool crossDownRB = false
  257. var bool wiggleDownRB = false
  258. if s_whichBuySellBars == 'Inner'
  259. crossUpRB := crossUpBotInnerRB
  260. wiggleUpRB := wiggleUpBotInnerRB
  261. crossDownRB := crossDownTopInnerRB
  262. wiggleDownRB := wiggleDownTopInnerRB
  263. else
  264. crossUpRB := crossUpBotOuterRB
  265. wiggleUpRB := wiggleUpBotOuterRB
  266. crossDownRB := crossDownTopOuterRB
  267. wiggleDownRB := wiggleDownTopOuterRB
  268.  
  269. reverBarColor = crossDownRB or (wiggleDownRB and not crossDownRB[1]) ? color.orange : crossUpRB or (wiggleUpRB and not crossUpRB[1]) ? color.purple : na
  270.  
  271. //DEFINE BARS IN MID
  272. //return true after specified number of bars (i_numBars) closes inside the mid bands but no breakout
  273. inMid = close > middleBandBot and close < middleBandTop and open > middleBandBot and open < middleBandTop
  274. isAllMid() =>
  275. AllMid = true
  276. for t = 0 to i_numBars by 1
  277. if longMidBreak[t] or shortMidBreak[t]
  278. AllMid := false
  279. AllMid
  280. //*****************************
  281. // © Joy_Bangla Leledc Exhaustion V4
  282. //====================================================================================================//
  283. //min = input(false, 'Minor Leledc Exhaustion Bar :: Show')
  284. //min_qual = input(5, 'Minor Leledc Exhausion Bar :: Bar count no')
  285. //min_len = input(5, 'Minor Leledc Exhausion Bar :: Bar count no')
  286.  
  287. reqLeleBuySell = not s_reqLeleBuySell ? true : i_ctLeleBuySell == 'Inner' ? low < shortbandsLowEMA or high > shortbandsHighEMA : low < phiExtensionLowEMA or high > phiExtensionHighEMA
  288.  
  289. leleVol = volume > ta.sma(volume,100)*i_volMult
  290. lele(qual, len) =>
  291. bindex = 0
  292. sindex = 0
  293. bindex := nz(bindex[i_bindexSindex], 0)
  294. sindex := nz(sindex[i_bindexSindex], 0)
  295. ret = 0
  296. if close > close[i_closeVal]
  297. bindex += 1
  298. bindex
  299. if close < close[i_closeVal]
  300. sindex += 1
  301. sindex
  302.  
  303. if i_leleVol and not leleVol
  304. ret := 0
  305. ret
  306. else
  307. if bindex > qual and close < open and high >= ta.highest(high, len) and reqLeleBuySell
  308. bindex := 0
  309. ret := -1
  310. ret
  311. if sindex > qual and close > open and low <= ta.lowest(low, len) and reqLeleBuySell
  312. sindex := 0
  313. ret := 1
  314. ret
  315. return_1 = ret
  316. return_1
  317.  
  318. major = lele(i_majQual, i_majLen)
  319. //minor = lele(min_qual, min_len)
  320.  
  321. plotchar(s_showMaj ? major == -1 ? high : na : na, char='•', location=location.absolute, color=color.new(color.red, 0), size=size.small, title='Major Bearish Leledc')
  322. plotchar(s_showMaj ? major == 1 ? low : na : na, char='•', location=location.absolute, color=color.new(color.lime, 0), size=size.small, title='Major Bullish Leledc')
  323.  
  324. //plotchar(min ? minor == 1 ? high : na : na, char='x', location=location.absolute, color=color.new(color.red, 0), size=size.small)
  325. //plotchar(min ? minor == -1 ? low : na : na, char='x', location=location.absolute, color=color.new(color.lime, 0), size=size.small)
  326.  
  327. //leledcMajorBullish = major == 1 ? low : na
  328. //leledcMajorBearish = major == -1 ? high : na
  329.  
  330. //leledcMinorBullish = minor == 1 ? low : na
  331. //leledcMinorBearish = minor == -1 ? high : na
  332.  
  333. //==============================================//
  334.  
  335. //alertcondition(leledcMajorBullish, title='Major Bullish Leledc', message='Major Bullish Leledc')
  336. //alertcondition(leledcMajorBearish, title='Major Bearish Leledc', message='Major Bearish Leledc')
  337.  
  338. //alertcondition(leledcMinorBullish, title='Minor Bullish Leledc', message='Minor Bullish Leledc')
  339. //alertcondition(leledcMinorBearish, title='Minor Bearish Leledc', message='Minor Bearish Leledc')
  340. //====================================================================================================//
  341. //*****************************
  342.  
  343.  
  344. //==============================================//
  345. //SET BAR COLORS
  346. inFromBelow = ta.barssince(failBotMB) > ta.barssince(failTopMB)
  347. inFromAbove = ta.barssince(failTopMB) > ta.barssince(failBotMB)
  348.  
  349.  
  350. var colorBar = color.new(color.white, 50)
  351. if s_trendColor
  352. if s_switch1
  353. if s_colorBuySellBars
  354. if reverBarColor == color.purple or reverBarColor == color.orange
  355. colorBar := reverBarColor
  356. else if OSOBcolor == color.yellow or OSOBcolor == color.blue
  357. colorBar := OSOBcolor
  358. else if s_useSlowEMA and slowEMA > middleBandTop and close < slowEMA and close > middleBandBot
  359. colorBar := color.new(color.gray, 0)
  360. else if s_useSlowEMA and slowEMA < middleBandBot and close > slowEMA and close < middleBandTop
  361. colorBar := color.new(color.gray, 0)
  362. else if close > middleBandTop
  363. colorBar := color.new(color.green, 0)
  364. else if close < middleBandBot
  365. colorBar := color.new(color.red, 0)
  366. else if (i_midClose == 'Opposite band' and inFromBelow) or (i_midClose == 'Delayed bars inside' and inFromBelow and ta.barssince(failTopMB) < i_numBars)
  367. colorBar := color.new(#0a6136, 20)
  368. else if (i_midClose == 'Opposite band' and inFromAbove) or (i_midClose == 'Delayed bars inside' and inFromAbove and ta.barssince(inFromAbove) < i_numBars)
  369. colorBar := color.new(#600008, 20)
  370. else
  371. colorBar := color.new(color.gray, 0)
  372. else
  373. if OSOBcolor == color.yellow or OSOBcolor == color.blue
  374. colorBar := OSOBcolor
  375. else if s_useSlowEMA and slowEMA > middleBandTop and close < slowEMA and close > middleBandBot
  376. colorBar := color.new(color.gray, 0)
  377. else if s_useSlowEMA and slowEMA < middleBandBot and close > slowEMA and close < middleBandTop
  378. colorBar := color.new(color.gray, 0)
  379. else if close > middleBandTop
  380. colorBar := color.new(color.green, 0)
  381. else if close < middleBandBot
  382. colorBar := color.new(color.red, 0)
  383. else if (i_midClose == 'Opposite band' and inFromBelow) or (i_midClose == 'Delayed bars inside' and inFromBelow and ta.barssince(failTopMB) < i_numBars)
  384. colorBar := color.new(#0a6136, 20)
  385. else if (i_midClose == 'Opposite band' and inFromAbove) or (i_midClose == 'Delayed bars inside' and inFromAbove and ta.barssince(inFromAbove) < i_numBars)
  386. colorBar := color.new(#600008, 20)
  387. else
  388. colorBar := color.new(color.gray, 0)
  389. else if s_colorBuySellBars
  390. if reverBarColor == color.purple or reverBarColor == color.orange
  391. colorBar := reverBarColor
  392. else if s_useSlowEMA and slowEMA > middleBandTop and close < slowEMA and close > middleBandBot
  393. colorBar := color.new(color.gray, 0)
  394. else if s_useSlowEMA and slowEMA < middleBandBot and close > slowEMA and close < middleBandTop
  395. colorBar := color.new(color.gray, 0)
  396. else if close > middleBandTop
  397. colorBar := color.new(color.green, 0)
  398. else if close < middleBandBot
  399. colorBar := color.new(color.red, 0)
  400. else if (i_midClose == 'Opposite band' and inFromBelow) or (i_midClose == 'Delayed bars inside' and inFromBelow and ta.barssince(failTopMB) < i_numBars)
  401. colorBar := color.new(#0a6136, 20)
  402. else if (i_midClose == 'Opposite band' and inFromAbove) or (i_midClose == 'Delayed bars inside' and inFromAbove and ta.barssince(inFromAbove) < i_numBars)
  403. colorBar := color.new(#600008, 20)
  404. else
  405. colorBar := color.new(color.gray, 0)
  406. else
  407. if s_useSlowEMA and slowEMA > middleBandTop and close < slowEMA and close > middleBandBot
  408. colorBar := color.new(color.gray, 0)
  409. else if s_useSlowEMA and slowEMA < middleBandBot and close > slowEMA and close < middleBandTop
  410. colorBar := color.new(color.gray, 0)
  411. else if close > middleBandTop
  412. colorBar := color.new(color.green, 0)
  413. else if close < middleBandBot
  414. colorBar := color.new(color.red, 0)
  415. else if (i_midClose == 'Opposite band' and inFromBelow) or (i_midClose == 'Delayed bars inside' and inFromBelow and ta.barssince(failTopMB) < i_numBars)
  416. colorBar := color.new(#0a6136, 20)
  417. else if (i_midClose == 'Opposite band' and inFromAbove) or (i_midClose == 'Delayed bars inside' and inFromAbove and ta.barssince(failBotMB) < i_numBars)
  418. colorBar := color.new(#600008, 20)
  419. else
  420. colorBar := color.new(color.gray, 0)
  421. else if s_switch1
  422. if s_colorBuySellBars
  423. if reverBarColor == color.purple or reverBarColor == color.orange
  424. colorBar := reverBarColor
  425. else if OSOBcolor == color.yellow or OSOBcolor == color.blue
  426. colorBar := OSOBcolor
  427. else
  428. colorBar := na
  429. else
  430. if OSOBcolor == color.yellow or OSOBcolor == color.blue
  431. colorBar := OSOBcolor
  432. else
  433. colorBar := na
  434. else if s_colorBuySellBars
  435. if reverBarColor == color.purple or reverBarColor == color.orange
  436. colorBar := reverBarColor
  437. else
  438. colorBar := na
  439. else
  440. colorBar := na
  441.  
  442. alertcondition(RSIoverSold and i_srcBB[1] < BBlower and i_srcBB > BBlower, 'Bullish Bollinger Bands Exhaustion Bar', 'Bullish Bollinger Bands Exhaustion Bar')
  443. alertcondition(RSIoverBought and i_srcBB[1] > BBupper and i_srcBB < BBupper, 'Bearish Bollinger Bands Exhaustion Bar', 'Bearish Bollinger Bands Exhaustion Bar')
  444. alertcondition(shortMidBreak, 'Middle Bands Breakdown (Short)', 'Middle Bands Breakdown (Short)')
  445. alertcondition(longMidBreak, 'Middle Bands Breakout (Long)', 'Middle Bands Breakout (Long)')
  446. alertcondition(squeezing and not squeezing[1], 'Volatility Squeeze Beginning', 'Volatility Squeeze Beginning')
  447. alertcondition(not squeezing and squeezing[1], 'Volatility Squeeze Ending', 'Volatility Squeeze Ending')
  448. alertcondition(crossUpTopInnerRB or wiggleUpTopInnerRB, 'Inner Sell Zone Breakout (Close Higher)', 'Inner Sell Zone Breakout (Close Higher)')
  449. alertcondition(crossUpTopOuterRB or wiggleUpTopOuterRB, 'Outer Sell Zone Breakout (Close Higher)', 'Outer Sell Zone Breakout (Close Higher)')
  450. alertcondition(crossDownBotInnerRB or wiggleDownBotInnerRB, 'Inner Buy Zone Breakout (Close Lower)', 'Inner Buy Zone Breakout (Close Lower)')
  451. alertcondition(crossDownBotOuterRB or wiggleDownBotOuterRB, 'Outer Buy Zone Breakout (Close Lower)', 'Outer Buy Zone Breakout (Close Lower)')
  452. alertcondition(reverBarColor == color.purple, 'Buy Zone Failure Bar', 'Buy Zone Failure Bar')
  453. alertcondition(reverBarColor == color.orange, 'Sell Zone Failure Bar', 'Sell Zone Failure Bar')
  454. alertcondition(high > shortbandsHighEMA and close < shortbandsHighEMA and open < shortbandsHighEMA, 'Wick Above Inner Sell Zone', 'Wick Above Inner Sell Zone')
  455. alertcondition(high > phiExtensionHighEMA and close < phiExtensionHighEMA and open < phiExtensionHighEMA, 'Wick Above Outer Sell Zone', 'Wick Above Outer Sell Zone')
  456. alertcondition(low < shortbandsLowEMA and close > shortbandsLowEMA and open > shortbandsLowEMA, 'Wick Below Inner Buy Zone', 'Wick Below Inner Buy Zone')
  457. alertcondition(low < phiExtensionLowEMA and close > phiExtensionLowEMA and open > phiExtensionLowEMA, 'Wick Below Outer Buy Zone', 'Wick Below Outer Buy Zone')
  458. alertcondition(major == 1, 'Major Bullish Leledc', 'Major Bullish Leledc')
  459. alertcondition(major == -1, 'Major Bearish Leledc', 'Major Bearish Leledc')
  460. barcolor(colorBar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement