xmd79

Easy Peasy

Oct 5th, 2021
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.35 KB | None | 0 0
  1.  
  2.  
  3.  
  4. ////// INDICATOR 1 SSL HYBRID /////////
  5.  
  6. //@version=4
  7. //By Mihkel00
  8. // This script is designed for the NNFX Method, so it is recommended for Daily charts only.
  9. // Tried to implement a few VP NNFX Rules
  10. // This script has a SSL / Baseline (you can choose between the SSL or MA), a secondary SSL for continiuation trades and a third SSL for exit trades.
  11. // Alerts added for Baseline entries, SSL2 continuations, Exits.
  12. // Baseline has a Keltner Channel setting for "in zone" Gray Candles
  13. // Added "Candle Size > 1 ATR" Diamonds from my old script with the criteria of being within Baseline ATR range.
  14. // Credits
  15. // Strategy causecelebre https://www.tradingview.com/u/causecelebre/
  16. // SSL Channel ErwinBeckers https://www.tradingview.com/u/ErwinBeckers/
  17. // Moving Averages jiehonglim https://www.tradingview.com/u/jiehonglim/
  18. // Moving Averages everget https://www.tradingview.com/u/everget/
  19. // "Many Moving Averages" script Fractured https://www.tradingview.com/u/Fractured/
  20. study("SSL Hybrid", overlay=true)
  21. show_Baseline = input(title="Show Baseline", type=input.bool, defval=true)
  22. show_SSL1 = input(title="Show SSL1", type=input.bool, defval=false)
  23. show_atr = input(title="Show ATR bands", type=input.bool, defval=true)
  24. //ATR
  25. atrlen = input(14, "ATR Period")
  26. mult = input(1, "ATR Multi", step=0.1)
  27. smoothing = input(title="ATR Smoothing", defval="WMA", options=["RMA", "SMA", "EMA", "WMA"])
  28.  
  29. ma_function(source, atrlen) =>
  30. if smoothing == "RMA"
  31. rma(source, atrlen)
  32. else
  33. if smoothing == "SMA"
  34. sma(source, atrlen)
  35. else
  36. if smoothing == "EMA"
  37. ema(source, atrlen)
  38. else
  39. wma(source, atrlen)
  40. atr_slen = ma_function(tr(true), atrlen)
  41. ////ATR Up/Low Bands
  42. upper_band = atr_slen * mult + close
  43. lower_band = close - atr_slen * mult
  44.  
  45. ////BASELINE / SSL1 / SSL2 / EXIT MOVING AVERAGE VALUES
  46. maType = input(title="SSL1 / Baseline Type", type=input.string, defval="HMA", options=["SMA","EMA","DEMA","TEMA","LSMA","WMA","MF","VAMA","TMA","HMA", "JMA", "Kijun v2", "EDSMA","McGinley"])
  47. len = input(title="SSL1 / Baseline Length", defval=60)
  48.  
  49. SSL2Type = input(title="SSL2 / Continuation Type", type=input.string, defval="JMA", options=["SMA","EMA","DEMA","TEMA","WMA","MF","VAMA","TMA","HMA", "JMA","McGinley"])
  50. len2 = input(title="SSL 2 Length", defval=5)
  51. //
  52. SSL3Type = input(title="EXIT Type", type=input.string, defval="HMA", options=["DEMA","TEMA","LSMA","VAMA","TMA","HMA","JMA", "Kijun v2", "McGinley", "MF"])
  53. len3 = input(title="EXIT Length", defval=15)
  54. src = input(title="Source", type=input.source, defval=close)
  55.  
  56. //
  57. tema(src, len) =>
  58. ema1 = ema(src, len)
  59. ema2 = ema(ema1, len)
  60. ema3 = ema(ema2, len)
  61. (3 * ema1) - (3 * ema2) + ema3
  62. kidiv = input(defval=1,maxval=4, title="Kijun MOD Divider")
  63.  
  64. jurik_phase = input(title="* Jurik (JMA) Only - Phase", type=input.integer, defval=3)
  65. jurik_power = input(title="* Jurik (JMA) Only - Power", type=input.integer, defval=1)
  66. volatility_lookback = input(10, title="* Volatility Adjusted (VAMA) Only - Volatility lookback length")
  67. //MF
  68. beta = input(0.8,minval=0,maxval=1,step=0.1, title="Modular Filter, General Filter Only - Beta")
  69. feedback = input(false, title="Modular Filter Only - Feedback")
  70. z = input(0.5,title="Modular Filter Only - Feedback Weighting",step=0.1, minval=0, maxval=1)
  71. //EDSMA
  72. ssfLength = input(title="EDSMA - Super Smoother Filter Length", type=input.integer, minval=1, defval=20)
  73. ssfPoles = input(title="EDSMA - Super Smoother Filter Poles", type=input.integer, defval=2, options=[2, 3])
  74.  
  75. //----
  76.  
  77. //EDSMA
  78. get2PoleSSF(src, length) =>
  79. PI = 2 * asin(1)
  80. arg = sqrt(2) * PI / length
  81. a1 = exp(-arg)
  82. b1 = 2 * a1 * cos(arg)
  83. c2 = b1
  84. c3 = -pow(a1, 2)
  85. c1 = 1 - c2 - c3
  86.  
  87. ssf = 0.0
  88. ssf := c1 * src + c2 * nz(ssf[1]) + c3 * nz(ssf[2])
  89.  
  90. get3PoleSSF(src, length) =>
  91. PI = 2 * asin(1)
  92.  
  93. arg = PI / length
  94. a1 = exp(-arg)
  95. b1 = 2 * a1 * cos(1.738 * arg)
  96. c1 = pow(a1, 2)
  97.  
  98. coef2 = b1 + c1
  99. coef3 = -(c1 + b1 * c1)
  100. coef4 = pow(c1, 2)
  101. coef1 = 1 - coef2 - coef3 - coef4
  102.  
  103. ssf = 0.0
  104. ssf := coef1 * src + coef2 * nz(ssf[1]) + coef3 * nz(ssf[2]) + coef4 * nz(ssf[3])
  105.  
  106. ma(type, src, len) =>
  107. float result = 0
  108. if type=="TMA"
  109. result := sma(sma(src, ceil(len / 2)), floor(len / 2) + 1)
  110. if type=="MF"
  111. ts=0.,b=0.,c=0.,os=0.
  112. //----
  113. alpha = 2/(len+1)
  114. a = feedback ? z*src + (1-z)*nz(ts[1],src) : src
  115. //----
  116. b := a > alpha*a+(1-alpha)*nz(b[1],a) ? a : alpha*a+(1-alpha)*nz(b[1],a)
  117. c := a < alpha*a+(1-alpha)*nz(c[1],a) ? a : alpha*a+(1-alpha)*nz(c[1],a)
  118. os := a == b ? 1 : a == c ? 0 : os[1]
  119. //----
  120. upper = beta*b+(1-beta)*c
  121. lower = beta*c+(1-beta)*b
  122. ts := os*upper+(1-os)*lower
  123. result := ts
  124. if type=="LSMA"
  125. result := linreg(src, len, 0)
  126. if type=="SMA" // Simple
  127. result := sma(src, len)
  128. if type=="EMA" // Exponential
  129. result := ema(src, len)
  130. if type=="DEMA" // Double Exponential
  131. e = ema(src, len)
  132. result := 2 * e - ema(e, len)
  133. if type=="TEMA" // Triple Exponential
  134. e = ema(src, len)
  135. result := 3 * (e - ema(e, len)) + ema(ema(e, len), len)
  136. if type=="WMA" // Weighted
  137. result := wma(src, len)
  138. if type=="VAMA" // Volatility Adjusted
  139. /// Copyright © 2019 to present, Joris Duyck (JD)
  140. mid=ema(src,len)
  141. dev=src-mid
  142. vol_up=highest(dev,volatility_lookback)
  143. vol_down=lowest(dev,volatility_lookback)
  144. result := mid+avg(vol_up,vol_down)
  145. if type=="HMA" // Hull
  146. result := wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))
  147. if type=="JMA" // Jurik
  148. /// Copyright © 2018 Alex Orekhov (everget)
  149. /// Copyright © 2017 Jurik Research and Consulting.
  150. phaseRatio = jurik_phase < -100 ? 0.5 : jurik_phase > 100 ? 2.5 : jurik_phase / 100 + 1.5
  151. beta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2)
  152. alpha = pow(beta, jurik_power)
  153. jma = 0.0
  154. e0 = 0.0
  155. e0 := (1 - alpha) * src + alpha * nz(e0[1])
  156. e1 = 0.0
  157. e1 := (src - e0) * (1 - beta) + beta * nz(e1[1])
  158. e2 = 0.0
  159. e2 := (e0 + phaseRatio * e1 - nz(jma[1])) * pow(1 - alpha, 2) + pow(alpha, 2) * nz(e2[1])
  160. jma := e2 + nz(jma[1])
  161. result := jma
  162. if type=="Kijun v2"
  163. kijun = avg(lowest(len), highest(len))//, (open + close)/2)
  164. conversionLine = avg(lowest(len/kidiv), highest(len/kidiv))
  165. delta = (kijun + conversionLine)/2
  166. result :=delta
  167. if type=="McGinley"
  168. mg = 0.0
  169. mg := na(mg[1]) ? ema(src, len) : mg[1] + (src - mg[1]) / (len * pow(src/mg[1], 4))
  170. result :=mg
  171. if type=="EDSMA"
  172.  
  173. zeros = src - nz(src[2])
  174. avgZeros = (zeros + zeros[1]) / 2
  175.  
  176. // Ehlers Super Smoother Filter
  177. ssf = ssfPoles == 2
  178. ? get2PoleSSF(avgZeros, ssfLength)
  179. : get3PoleSSF(avgZeros, ssfLength)
  180.  
  181. // Rescale filter in terms of Standard Deviations
  182. stdev = stdev(ssf, len)
  183. scaledFilter = stdev != 0
  184. ? ssf / stdev
  185. : 0
  186.  
  187. alpha = 5 * abs(scaledFilter) / len
  188.  
  189. edsma = 0.0
  190. edsma := alpha * src + (1 - alpha) * nz(edsma[1])
  191. result := edsma
  192. result
  193.  
  194. ///SSL 1 and SSL2
  195. emaHigh = ma(maType, high, len)
  196. emaLow = ma(maType, low, len)
  197.  
  198. maHigh = ma(SSL2Type, high, len2)
  199. maLow = ma(SSL2Type, low, len2)
  200.  
  201. ///EXIT
  202. ExitHigh = ma(SSL3Type, high, len3)
  203. ExitLow = ma(SSL3Type, low, len3)
  204.  
  205. ///Keltner Baseline Channel
  206. BBMC = ma(maType, close, len)
  207. useTrueRange = input(true)
  208. multy = input(0.2, step=0.05, title="Base Channel Multiplier")
  209. Keltma = ma(maType, src, len)
  210. range = useTrueRange ? tr : high - low
  211. rangema = ema(range, len)
  212. upperk =Keltma + rangema * multy
  213. lowerk = Keltma - rangema * multy
  214.  
  215. //Baseline Violation Candle
  216. open_pos = open*1
  217. close_pos = close*1
  218. difference = abs(close_pos-open_pos)
  219. atr_violation = difference > atr_slen
  220. InRange = upper_band > BBMC and lower_band < BBMC
  221. candlesize_violation = atr_violation and InRange
  222. plotshape(candlesize_violation, color=color.white, size=size.tiny,style=shape.diamond, location=location.top, transp=0,title="Candle Size > 1xATR")
  223.  
  224.  
  225. //SSL1 VALUES
  226. Hlv = int(na)
  227. Hlv := close > emaHigh ? 1 : close < emaLow ? -1 : Hlv[1]
  228. sslDown = Hlv < 0 ? emaHigh : emaLow
  229.  
  230. //SSL2 VALUES
  231. Hlv2 = int(na)
  232. Hlv2 := close > maHigh ? 1 : close < maLow ? -1 : Hlv2[1]
  233. sslDown2 = Hlv2 < 0 ? maHigh : maLow
  234.  
  235. //EXIT VALUES
  236. Hlv3 = int(na)
  237. Hlv3 := close > ExitHigh ? 1 : close < ExitLow ? -1 : Hlv3[1]
  238. sslExit = Hlv3 < 0 ? ExitHigh : ExitLow
  239. base_cross_Long = crossover(close, sslExit)
  240. base_cross_Short = crossover(sslExit, close)
  241. codiff = base_cross_Long ? 1 : base_cross_Short ? -1 : na
  242.  
  243. //COLORS
  244. show_color_bar = input(title="Color Bars", type=input.bool, defval=true)
  245. color_bar = close > upperk ? #00c3ff : close < lowerk ? #ff0062 : color.gray
  246. color_ssl1 = close > sslDown ? #00c3ff : close < sslDown ? #ff0062 : na
  247.  
  248. //PLOTS
  249. plotarrow(codiff, colorup=#00c3ff, colordown=#ff0062,title="Exit Arrows", transp=20, maxheight=20, offset=0)
  250. p1 = plot(show_Baseline ? BBMC : na, color=color_bar, linewidth=4,transp=0, title='MA Baseline')
  251. DownPlot = plot( show_SSL1 ? sslDown : na, title="SSL1", linewidth=3, color=color_ssl1, transp=10)
  252. barcolor(show_color_bar ? color_bar : na)
  253. up_channel = plot(show_Baseline ? upperk : na, color=color_bar, title="Baseline Upper Channel")
  254. low_channel = plot(show_Baseline ? lowerk : na, color=color_bar, title="Basiline Lower Channel")
  255. fill(up_channel, low_channel, color=color_bar, transp=90)
  256.  
  257. ////SSL2 Continiuation from ATR
  258. atr_crit = input(0.9, step=0.1, title="Continuation ATR Criteria")
  259. upper_half = atr_slen * atr_crit + close
  260. lower_half = close - atr_slen * atr_crit
  261. buy_inatr = lower_half < sslDown2
  262. sell_inatr = upper_half > sslDown2
  263. sell_cont = close < BBMC and close < sslDown2
  264. buy_cont = close > BBMC and close > sslDown2
  265. sell_atr = sell_inatr and sell_cont
  266. buy_atr = buy_inatr and buy_cont
  267. atr_fill = buy_atr ? color.green : sell_atr ? color.purple : color.white
  268. LongPlot = plot(sslDown2, title="SSL2", linewidth=2, color=atr_fill, style=plot.style_circles, transp=0)
  269. u = plot(show_atr ? upper_band : na, "+ATR", color=color.white, transp=80)
  270. l = plot(show_atr ? lower_band : na, "-ATR", color=color.white, transp=80)
  271.  
  272. //ALERTS
  273. alertcondition(crossover(close, sslDown), title='SSL Cross Alert', message='SSL1 has crossed.')
  274. alertcondition(crossover(close, sslDown2), title='SSL2 Cross Alert', message='SSL2 has crossed.')
  275. alertcondition(sell_atr, title='Sell Continuation', message='Sell Continuation.')
  276. alertcondition(buy_atr, title='Buy Continuation', message='Buy Continuation.')
  277. alertcondition(crossover(close, sslExit), title='Exit Sell', message='Exit Sell Alert.')
  278. alertcondition(crossover(sslExit, close), title='Exit Buy', message='Exit Buy Alert.')
  279. alertcondition(crossover(close, upperk ), title='Baseline Buy Entry', message='Base Buy Alert.')
  280. alertcondition(crossover(lowerk, close ), title='Baseline Sell Entry', message='Base Sell Alert.')
  281.  
  282. //////// INDICATOR 2 TOP BOTTOMS ////////////
  283.  
  284. //@version=4
  285. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  286. // © ceyhun
  287.  
  288.  
  289. per = input(14, title="Bottom Period")
  290. loc = low < lowest(low[1], per) and low <= lowest(low[per], per)
  291. bottom = barssince(loc)
  292.  
  293. per2 = input(14, title="Top Period")
  294. loc2 = high > highest(high[1], per2) and high >= highest(high[per2], per2)
  295. top = barssince(loc2)
  296.  
  297. /////BUY-SELL/////
  298. Buy = crossover(bottom, top)
  299. Sell = crossunder(bottom, top)
  300.  
  301. plotshape(Buy,"BUY", shape.labelup, location.belowbar, color.green, text="BUY",textcolor=color.black)
  302. plotshape(Sell,"SELL", shape.labeldown, location.abovebar, color.red, text="SELL",textcolor=color.black)
  303.  
  304. alertcondition(Buy, title="Buy Signal", message="Buy")
  305. alertcondition(Sell, title="Sell Signal", message="Sell")
  306.  
  307. /////////////// INDICATOR 3 PULL BACK STRATEGY SIGNAL //////////
  308.  
  309. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  310. // © PriyankaAgarwal
  311.  
  312. //@version=4
  313.  
  314. sma20 = sma(close,20)
  315. ema34 = ema(close,34)
  316. ema60 = ema(close,60)
  317. ema5 = ema(close,5)
  318. ma200=sma(close,200)
  319. ma100=sma(close,100)
  320.  
  321. var1 = high
  322. var2 = low
  323. var3 = open
  324. var4 = close
  325.  
  326. candlerange = abs(high - low)
  327. bodyrange = abs(open - close)
  328. ucloserange = abs(low - close)
  329. lcloserange = abs(high - close)
  330.  
  331. bodytocandleper = (bodyrange/candlerange)*100
  332.  
  333. ucandlecloseper = (lcloserange/candlerange)*100
  334. lcandlecloseper = (ucloserange/candlerange)*100
  335.  
  336. C_WhiteBody = open < close
  337. C_BlackBody = open > close
  338.  
  339. buy = C_WhiteBody and (bodytocandleper>=80 or ucandlecloseper <=15) and high < ema5 and sma20 > ema34 and ema34 > ema60
  340. sell = C_BlackBody and (bodytocandleper>=80 or lcandlecloseper <=15) and low > ema5 and sma20 < ema34 and ema34 < ema60
  341.  
  342. plot(sma20, title="Simple Moving Avg 20",color=color.red, linewidth=1)
  343. plot(ema34, title="Exp Moving Avg 34",color=color.blue, linewidth=1)
  344. plot(ema60, title="Exp Moving Avg 60",color=color.green, linewidth=1)
  345. plot(ema5, title="Exp Moving Avg 5",color=color.orange, linewidth=2)
  346.  
  347. plot(ma100,color=color.purple,linewidth=2)
  348. plot(ma200,color=color.olive,linewidth=2)
  349.  
  350.  
  351. plotshape(buy, "Up Arrow", shape.triangleup, location.belowbar, color.green , 0,0,"Buy", color.green, true,size.tiny)
  352. plotshape(sell, "Down Arrow", shape.triangledown, location.abovebar, color.red , 0,0,"Sell", color.red, true,size.tiny)
  353.  
  354. ///////// INDICATOR 3 SUPPORT RESİSTANCE ///////
  355.  
  356. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  357. // © LuxAlgo
  358.  
  359. //@version = 4
  360. //
  361. toggleBreaks = input(true, title = "Show Breaks" )
  362. leftBars = input(15, title = "Left Bars ")
  363. rightBars = input(15, title = "Right Bars")
  364. volumeThresh = input(20, title = "Volume Threshold")
  365. //
  366. highUsePivot = fixnan(pivothigh(leftBars, rightBars)[1])
  367. lowUsePivot = fixnan(pivotlow(leftBars, rightBars)[1])
  368. r1 = plot(highUsePivot, color=change(highUsePivot) ? na : #FF0000, linewidth=3, offset=-(rightBars+1), title="Resistance")
  369. s1 = plot(lowUsePivot, color=change(lowUsePivot) ? na : #233dee, linewidth=3, offset=-(rightBars+1), title="Support")
  370.  
  371. //Volume %
  372. short = ema(volume, 5)
  373. long = ema(volume, 10)
  374. osc = 100 * (short - long) / long
  375.  
  376.  
  377. //For breaks with volume
  378. plotshape(toggleBreaks and crossunder(close,lowUsePivot) and not (open - close < high - open) and osc > volumeThresh, title = "Break", text = 'Buy', style = shape.labeldown, location = location.abovebar, color= color.red,textcolor = color.white, transp = 0, size = size.tiny)
  379. plotshape(toggleBreaks and crossover(close,highUsePivot ) and not(open - low > close - open) and osc > volumeThresh, title = "Break", text = 'Sell', style = shape.labelup, location = location.belowbar, color= color.green,textcolor = color.white, transp = 0, size = size.tiny)
  380.  
  381. //For bull / bear wicks
  382. plotshape(toggleBreaks and crossover(close,highUsePivot ) and open - low > close - open , title = "Break", text = 'Bull Wick', style = shape.labelup, location = location.belowbar, color= color.green,textcolor = color.white, transp = 0, size = size.tiny)
  383. plotshape(toggleBreaks and crossunder(close,lowUsePivot) and open - close < high - open , title = "Break", text = 'Bear Wick', style = shape.labeldown, location = location.abovebar, color= color.red,textcolor = color.white, transp = 0, size = size.tiny)
  384.  
  385.  
  386. alertcondition(crossunder(close,lowUsePivot) and osc > volumeThresh , title = "Support Broken" , message = "Support Broken")
  387. alertcondition(crossover(close,highUsePivot) and osc > volumeThresh, title = "Resistance Broken" , message = "Resistance Broken")
  388.  
  389.  
  390. ////////////// INDICATOR 4 WELLES WILDER MA //////////
  391.  
  392. Period = input(14, title="Period", minval=1)
  393. src5 = input(close, title="Source")
  394.  
  395. alpha = 1/ Period
  396. WM = 0.0
  397. WM := alpha*src + (1-alpha)*nz(WM[1])
  398. color1= WM>WM[1]
  399. colorx = color1 ? color.lime : color.yellow
  400. plot(WM, style=plot.style_circles, color=colorx, linewidth=2, title="WM", transp=0)
  401.  
  402.  
  403. //////////// INDICATOR 5 ABCD /////////////////
  404.  
  405. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  406. // © rathiabhi
  407.  
  408. //@version=4
  409. length = input(5)
  410. up1 = pivothigh(high,length,length)
  411. dn1 = pivotlow(low,length,length)
  412. upcount = barssince(not na(up1))
  413. dncount = barssince(not na(dn1))
  414. ppp = (not na(dn1) and dncount[1]>upcount[1]) ? dn1 : (not na(up1) and dncount[1]<upcount[1]) ? up1 : na
  415. up = (not na(up1) and dncount[1]<upcount[1]) ? up1 : na
  416. dn = (not na(dn1) and dncount[1]>upcount[1]) ? dn1 : na
  417.  
  418. plot(up,title="pivot high",offset=-length)
  419. plot(dn,title="pivot low",offset=-length)
  420. plot(ppp,title="pivot line",offset=-length)
  421.  
  422. n = bar_index
  423. a = valuewhen(not na(ppp),n,2)
  424. b = valuewhen(not na(ppp),n,1)
  425. c = valuewhen(not na(ppp),n,0)
  426.  
  427. av = valuewhen(not na(ppp),ppp,2)
  428. bv = valuewhen(not na(ppp),ppp,1)
  429. cv = valuewhen(not na(ppp),ppp,0)
  430.  
  431. //bullish AB=CD pattern
  432. ABCD_bear = av<bv and (bv-cv)<=(0.89*(bv-av)) and (bv-cv)>=(0.38*(bv-av))
  433. ABCD_bear1 = (high-cv)>=(bv-av) and ABCD_bear
  434. label1 = ABCD_bear1 and not(ABCD_bear1[1]) ? label.new(bar_index,high,text="Bearish AB=CD",color=color.red,style=label.style_arrowdown,yloc=yloc.abovebar,
  435. textcolor=color.red,size=size.normal) : na
  436.  
  437. //buearish AB=CD pattern
  438. ABCD_bull = av>bv and (cv-bv)<=(0.89*(av-bv)) and (cv-bv)>=(0.38*(av-bv))
  439. ABCD_bull1 = (cv-low)>=(av-bv) and ABCD_bull
  440. label2 = ABCD_bull1 and not(ABCD_bull1[1]) ? label.new(bar_index,low,text="Bullish AB=CD",color=color.green,style=label.style_arrowup,yloc=yloc.belowbar,
  441. textcolor=color.green,size=size.normal) : na
  442.  
  443.  
  444. ////////// INDICATOR TOP AND BOTTOM CYCLE //////////
  445.  
  446.  
  447.  
  448. //Thresholds
  449. psma_length = input(200, title="Price SMA Length")
  450. threshold = input(2.4, title="Threshold",step=0.1)
  451. optimalbuy = input(0.7, title="Optimal Buy",step=0.1)
  452. optimalsell = input(3.5, title="Optimal Sell",step=0.1)
  453.  
  454. ma6 = sma(close, psma_length)
  455. multiple = close / ma6
  456.  
  457. //Color
  458. opt_sell_signal = multiple > optimalsell
  459. s_signal = multiple[1] > optimalsell and multiple < optimalsell
  460. opt_buy_signal = multiple < optimalbuy
  461. b_signal = multiple[1] < optimalbuy and multiple > optimalbuy
  462. sell_signal = multiple > threshold
  463.  
  464. //Plots
  465. plotshape(s_signal, style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)
  466. plotshape(sell_signal, style = shape.triangledown, location = location.abovebar, color = color.yellow)
  467. plotshape(opt_buy_signal, style = shape.triangleup, location = location.belowbar, color = color.aqua)
  468. plotshape(b_signal, style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)
  469.  
  470.  
  471. //////////////// INDICATOR RSI TOP BOTTOM //////////
  472.  
  473.  
  474. //Inputs
  475. inputW = input(14,title="Length", type=input.integer, minval=1)
  476. resW=input("W", type=input.resolution, title="Resolution")
  477. outW = rsi(close,inputW)
  478. thresholdT = input(88,title="Top")
  479. thresholdB = input(30,title="Bottom")
  480.  
  481.  
  482. //Security
  483. securityW = security(syminfo.tickerid, resW, outW)
  484.  
  485. //Threshold
  486. bottom5 = crossover(thresholdB, securityW) == 1 ? true : false
  487. top5= crossover(thresholdT, securityW) == 1 ? true : false
  488.  
  489. //Plots
  490. plotshape(bottom5, style = shape.arrowup, location = location.belowbar, color = color.green, size = size.small, text="BOTTOM")
  491. plotshape(top, style = shape.arrowdown, location = location.abovebar, color = color.red, size = size.small, text="TOP")
  492.  
  493.  
  494. //////////// INDICATOR HACIM ////////////
  495.  
  496.  
  497. //Source
  498. src7 = input(close, title="Source")
  499.  
  500. //Inputs ////////////
  501. ShowDL = input(true, "Show Volume Detail Label?")
  502. ShowVV = input(true, "Show Volume Values?")
  503. ShowRV = input(true, "Show Relative Volume?")
  504. RVLength = input(21, "Volume MA Length", minval=1)
  505. ShowRVBars = input(true, "Paint High Relative Volume Bars?")
  506. RValue = input(3, "Relative Volume for Bars?")
  507. LabelS = input(title = "Label Size", defval = "Normal", type = input.string, options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'])
  508. label_size = LabelS == 'Tiny' ? size.tiny : LabelS == 'Small' ? size.small : LabelS == 'Normal' ? size.normal : LabelS == 'Large' ? size.large : LabelS == 'Huge' ? size.huge : size.normal
  509.  
  510. string Bstr = ""
  511. string DPBstr = ""
  512. string Sstr = ""
  513. string DPSstr = ""
  514. string TVol = ""
  515. string RVolTB = ""
  516. string RVolTS = ""
  517.  
  518. //Buy - Sell Volume
  519. BuyVol = nz(round(iff((high==low), 0, volume*(close-low)/(high-low))))
  520. SellVol = nz(round(iff((high==low), 0, volume*(high-close)/(high-low))))
  521.  
  522. //Buy-Sell Volume Percent Calculation ////////////
  523. BuyVolumePercent = nz(100 * BuyVol/(BuyVol+SellVol))
  524. SellVolumePercent = nz(100 * SellVol/(BuyVol+SellVol))
  525.  
  526. //Total Volume Calculation ////////////
  527. if(str.length(tostring(volume)) >= 10 and str.length(tostring(volume)) <= 12)
  528. TVol := tostring(volume / 1000000000, "###.###") + "B"
  529.  
  530. if(str.length(tostring(volume)) >= 7 and str.length(tostring(volume)) <= 9)
  531. TVol := tostring(volume / 1000000, "###.###") + "M"
  532.  
  533. if(str.length(tostring(volume)) < 7)
  534. TVol := tostring(volume / 1000) + "K"
  535.  
  536. if(str.length(tostring(volume)) < 4)
  537. TVol := tostring(volume)
  538.  
  539. //Buy-Sell Volume Calculation ////////////
  540. //Buy Volume Billions Calculation
  541. if BuyVolumePercent > 0 and str.length(tostring(BuyVol)) >= 10 and str.length(tostring(SellVol)) <= 12 and ShowVV
  542. Bstr := " - " + tostring(BuyVol / 1000000000, "###.###") + "B"
  543. DPBstr := tostring(BuyVol / 1000000000, "###.###") + "B"
  544.  
  545. //Sell Volume Billions Calculation
  546. if SellVolumePercent > 0 and str.length(tostring(SellVol)) >= 10 and str.length(tostring(SellVol)) <= 12 and ShowVV
  547. Sstr := " - " + tostring(SellVol / 1000000000, "###.###") + "B"
  548. DPSstr := tostring(SellVol / 1000000000, "###.###") + "B"
  549.  
  550. //Buy Volume Millions Calculation
  551. if BuyVolumePercent > 0 and str.length(tostring(BuyVol)) >= 7 and str.length(tostring(SellVol)) <= 9 and ShowVV
  552. Bstr := " - " + tostring(BuyVol / 1000000, "###.###") + "M"
  553. DPBstr := tostring(BuyVol / 1000000, "###.###") + "M"
  554.  
  555. //Sell Volume Millions Calculation
  556. if SellVolumePercent > 0 and str.length(tostring(SellVol)) >= 7 and str.length(tostring(SellVol)) <= 9 and ShowVV
  557. Sstr := " - " + tostring(SellVol / 1000000, "###.###") + "M"
  558. DPSstr := tostring(SellVol / 1000000, "###.###") + "M"
  559.  
  560. //Buy Volume Thousands Calculation
  561. if BuyVolumePercent > 0 and str.length(tostring(BuyVol)) < 7 and ShowVV
  562. Bstr := " - " + tostring(BuyVol / 1000) + "K"
  563. DPBstr := tostring(BuyVol / 1000) + "K"
  564.  
  565. //Sell Thousands Calculation
  566. if SellVolumePercent > 0 and str.length(tostring(SellVol)) < 7 and ShowVV
  567. Sstr := " - " + tostring(SellVol / 1000) + "K"
  568. DPSstr := tostring(SellVol / 1000) + "K"
  569.  
  570. //Buy Volume less than a thousand
  571. if BuyVolumePercent > 0 and str.length(tostring(BuyVol)) < 4 and ShowVV
  572. Bstr := " - " + tostring(BuyVol)
  573. DPBstr := tostring(BuyVol)
  574.  
  575. //Sell Volume less than a thousand
  576. if SellVolumePercent > 0 and str.length(tostring(SellVol)) < 4 and ShowVV
  577. Sstr := " - " + tostring(SellVol)
  578. DPSstr := tostring(SellVol)
  579.  
  580. if BuyVolumePercent == 0 and ShowVV
  581. DPBstr := "0"
  582.  
  583. if SellVolumePercent == 0 and ShowVV
  584. DPSstr := "0"
  585.  
  586. //Relative Volume Calculation ////////////
  587. AVol = sma(volume, RVLength)
  588. RVol = volume/AVol
  589.  
  590. //Relative Volume Label Value ////////////
  591. if(ShowDL)
  592. RVolTB := ShowRV and close > open ? tostring(RVol, "##.#") : na
  593. RVolTS := ShowRV and close < open ? tostring(RVol, "##.#") : na
  594. else
  595. RVolTB := ShowRV and close > open ? tostring(RVol, "##.#") + " - " : na
  596. RVolTS := ShowRV and close < open ? tostring(RVol, "##.#") + " - " : na
  597.  
  598. //Labels ////////////////////////
  599. if(ShowDL)
  600. //Detail Labels //////////////////////////
  601. l = label.new(bar_index, na, (close > open and round(RVol) > 0 ? "Relative Volume : " + RVolTB + "\n" : na) + "Buy Percent : %" + tostring(BuyVolumePercent, "##") + "\n" + "Buy Volume : " + DPBstr + "\n" + "Total Volume : " + TVol, color=color.green, textcolor=color.white, textalign=text.align_left, style=label.style_label_lower_left, size=label_size, yloc=yloc.abovebar)
  602. label.delete(l[1])
  603.  
  604. r = label.new(bar_index, na, (close < open and round(RVol) > 0 ? "Relative Volume : " + RVolTS + "\n" : na) + "Sell Percent : %" + tostring(SellVolumePercent, "##") + "\n" + "Sell Volume : " + DPSstr, color=color.red, textcolor=color.white, textalign=text.align_left, style=label.style_label_upper_left, size=label_size, yloc=yloc.belowbar)
  605. label.delete(r[1])
  606. else
  607. //Small Labels /////////////////////////
  608. l = label.new(bar_index, na, (round(RVol) > 0 ? RVolTB : na) + '%' + tostring(BuyVolumePercent, "##") + Bstr, color=color.green, textcolor=color.white, style=label.style_label_lower_left, size=label_size, yloc=yloc.abovebar)
  609. label.delete(l[1])
  610.  
  611. r = label.new(bar_index, na, (round(RVol) > 0 ? RVolTS : na) + '%' + tostring(SellVolumePercent, "##") + Sstr, color=color.red, textcolor=color.white, style=label.style_label_upper_left, size=label_size, yloc=yloc.belowbar)
  612. label.delete(r[1])
  613.  
  614. //If the relative volume value is greater than the value(Relative Volume for bars) we specify, paint those bars.
  615. barcolor(title="Relative Volume Candles", color= ShowRVBars and close > open and RVol > RValue ? color.blue : na)
  616.  
  617.  
  618.  
Advertisement
Add Comment
Please, Sign In to add comment