Advertisement
Guest User

Gui v3

a guest
Dec 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.14 KB | None | 0 0
  1. //@version=4
  2. study("guime v3", overlay=true)
  3.  
  4. //{
  5. adx_len = input(14, minval=1, title="DI adx_length")
  6. adx_lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
  7.  
  8.  
  9. up = change(high)
  10. down = -change(low)
  11. trur = rma(tr, adx_len)
  12.  
  13. plus = fixnan(100 * rma(up > down and up > 0 ? up : 0, adx_len) / trur)
  14. minus = fixnan(100 * rma(down > up and down > 0 ? down : 0, adx_len) / trur)
  15.  
  16. sum = plus + minus
  17. adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adx_lensig)
  18.  
  19. osob = input(40, title="Exhaustion Level for ADX, default = 40")
  20.  
  21.  
  22. col = adx <= 10 ? color.gray : adx > 10 and adx <= 20 and plus > minus ? #98FF98 :
  23. adx > 10 and adx <= 20 and plus < minus ? #E77471 :
  24. adx > 20 and adx <= osob and plus > minus ? color.lime :
  25. adx > 20 and adx <= osob and plus < minus ? color.red :
  26. adx > osob and plus > minus ? color.green :
  27. adx > osob and plus < minus ? color.maroon : color.white
  28. // barcolor(col)
  29.  
  30. // plot(adx, color=col, title="ADX", style=plot.style_columns)
  31. // plot(0, title="0 Line", style=plot.style_line, linewidth=1, color=color.gray)
  32. // plot(10, title="10 Line", style=plot.style_circles, linewidth=1, color=color.gray)
  33. // plot(20, title="20 Line", style=plot.style_circles, linewidth=1, color=color.gray)
  34. // plot(osob, title="10 Line", style=plot.style_circles, linewidth=1, color=color.gray)
  35. //} --------------- ADX ---------------
  36. //{
  37. src = close,
  38. len = input(14, minval=1, title="RSI Length")
  39. len2 = input(12, minval=1, title="EMA of RSI Length")
  40. upp = rma(max(change(src), 0), len)
  41. downn = rma(-min(change(src), 0), len)
  42. rsi = downn == 0 ? 100 : upp == 0 ? 0 : 100 - (100 / (1 + upp / downn))
  43. emaRSI = ema(rsi,len2)
  44.  
  45. // plot(rsi, title="RSI", style=plot.style_line, linewidth=2, color=color.black)
  46. // plot(emaRSI, title="EMA of RSI", style=plot.style_line, linewidth=2, color=color.red)
  47. // band1 = hline(80, title="uppper Line", linestyle=hline.style_dashed, linewidth=1, color=color.red)
  48. // band0 = hline(20, title="Lower Line", linestyle=hline.style_dashed, linewidth=1, color=color.lime)
  49. // band2 = hline(45, title="uppper Line", linestyle=hline.style_dashed, linewidth=1, color=color.gray)
  50. // band3 = hline(50, title="Lower Line", linestyle=hline.style_dashed, linewidth=1, color=color.black)
  51. // band4 = hline(55, title="Lower Line", linestyle=hline.style_dashed, linewidth=1, color=color.gray)
  52.  
  53. //} --------------- EMA ---------------
  54. //{
  55. source = close
  56. useCurrentRes = input(true, title="Use Current Chart Resolution?")
  57. resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=input.resolution, defval="60")
  58. smd = input(true, title="Show MacD & Signal Line? Also Turn Off Dots Below")
  59. sd = input(true, title="Show Dots When MacD Crosses Signal Line?")
  60. sh = input(true, title="Show Histogram?")
  61. macd_colorChange = input(true, title="Change MacD Line Color-Signal Line Cross?")
  62. hist_colorChange = input(true, title="MacD Histogram 4 Colors?")
  63.  
  64. res = useCurrentRes ? timeframe.period : resCustom
  65.  
  66. fastLength = input(12, minval=1)
  67. slowLength = input(26, minval=1)
  68. signalLength = input(9, minval=1)
  69.  
  70. fastMA = ema(source, fastLength)
  71. slowMA = ema(source, slowLength)
  72.  
  73. macd = fastMA - slowMA
  74. signal = sma(macd, signalLength)
  75. hist = macd - signal
  76.  
  77. outMacD = security(syminfo.tickerid, res, macd)
  78. outSignal = security(syminfo.tickerid, res, signal)
  79. outHist = security(syminfo.tickerid, res, hist)
  80.  
  81. histA_IsUp = outHist > outHist[1] and outHist > 0
  82. histA_IsDown = outHist < outHist[1] and outHist > 0
  83. histB_IsDown = outHist < outHist[1] and outHist <= 0
  84. histB_IsUp = outHist > outHist[1] and outHist <= 0
  85.  
  86. //MacD Color Definitions
  87. macd_IsAbove = outMacD >= outSignal
  88. macd_IsBelow = outMacD < outSignal
  89.  
  90. plot_color = hist_colorChange ? histA_IsUp ? color.aqua : histA_IsDown ? color.blue :
  91. histB_IsDown ? color.red : histB_IsUp ? color.maroon : color.yellow : color.gray
  92. macd_color = macd_colorChange ? macd_IsAbove ? color.lime : color.red : color.red
  93. signal_color = macd_colorChange ? macd_IsAbove ? color.yellow : color.yellow : color.lime
  94.  
  95. circleYPosition = outSignal
  96.  
  97. // plot(smd and outMacD ? outMacD : na, title="MACD", color=macd_color, linewidth=4)
  98. // plot(smd and outSignal ? outSignal : na, title="Signal Line", color=signal_color, style=plot.style_line, linewidth=2)
  99. // plot(sh and outHist ? outHist : na, title="Histogram", color=plot_color, style=plot.style_histogram, linewidth=4)
  100. // plot(sd and cross(outMacD, outSignal) ? circleYPosition : na, title="Cross", style=plot.style_circles, linewidth=4, color=macd_color)
  101. // hline(0, '0 Line', linestyle=hline.style_solid, linewidth=2, color=color.black)
  102. //} --------------- MACD ---------------
  103. //{
  104. st_length = input(title="Supertrend ATR Period", type=input.integer, defval=1)
  105. mult = input(title="Supertrend ATR Multiplier", type=input.float, step=0.1, defval=10.0)
  106.  
  107. atr = mult * atr(st_length)
  108.  
  109. longStop = hl2 - atr
  110. longStopPrev = nz(longStop[1], longStop)
  111. longStop := close[1] > longStopPrev ? max(longStop, longStopPrev) : longStop
  112.  
  113. shortStop = hl2 + atr
  114. shortStopPrev = nz(shortStop[1], shortStop)
  115. shortStop := close[1] < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
  116.  
  117. dir = 1
  118. dir := nz(dir[1], dir)
  119. dir := dir == -1 and close > shortStopPrev ? 1 : dir == 1 and close < longStopPrev ? -1 : dir
  120.  
  121.  
  122. longColor = color.blue
  123. shortColor = color.blue
  124.  
  125.  
  126. // //plot
  127. // plot(dir == 1 ? longStop : na, title="BuyLine", style=plot.style_linebr, linewidth=2, color=longColor)
  128. // plotshape(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", style=shape.labelup, location=location.absolute, size=size.normal, text="Buy", transp=0, textcolor = color.white, color=color.green, transp=0)
  129.  
  130. // plot(dir == 1 ? na : shortStop, title="SellLine", style=plot.style_linebr, linewidth=2, color=shortColor)
  131. // plotshape(dir == -1 and dir[1] == 1 ? shortStop : na, title="Sell", style=shape.labeldown, location=location.absolute, size=size.normal, text="Sell", transp=0, textcolor = color.white, color=color.red, transp=0)
  132.  
  133. // barcolor(dir == 1 ? color.green: color.red)
  134.  
  135. // alertcondition(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", message="Buy!")
  136. // alertcondition(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", message="Buy!")
  137. // alertcondition(dir == 1 and dir[1] == -1 ? longStop : na, title="Buy", message="Buy!")
  138. // alertcondition(dir == -1 and dir[1] == 1 ? shortStop : na, title="Sell", message="Sell!")
  139. //} --------------- SUPERTREND ---------------
  140. //{
  141. squeeze_length = input(20, title="BB squeeze_length")
  142. squeeze_mult = input(2.0, title="BB squeeze_multFactor")
  143. squeeze_lengthKC = input(20, title="KC squeeze_length")
  144. squeeze_multKC = input(1.5, title="KC squeeze_multFactor")
  145. SignalPeriod = input(5, title="Signal squeeze_length")
  146.  
  147. useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)
  148.  
  149. // Calculate BB
  150. squeeze_source = close
  151. basis = sma(squeeze_source, squeeze_length)
  152. dev = squeeze_multKC * stdev(squeeze_source, squeeze_length)
  153. upperBB = basis + dev
  154. lowerBB = basis - dev
  155.  
  156. // Calculate KC
  157. ma = sma(squeeze_source, squeeze_lengthKC)
  158. range = useTrueRange ? tr : high - low
  159. rangema = sma(range, squeeze_lengthKC)
  160. upperKC = ma + rangema * squeeze_multKC
  161. lowerKC = ma - rangema * squeeze_multKC
  162.  
  163. sqzOn = lowerBB > lowerKC and upperBB < upperKC
  164. sqzOff = lowerBB < lowerKC and upperBB > upperKC
  165. noSqz = sqzOn == false and sqzOff == false
  166.  
  167. val = linreg(squeeze_source - avg(avg(highest(high, squeeze_lengthKC), lowest(low, squeeze_lengthKC)), sma(close, squeeze_lengthKC)), squeeze_lengthKC, 0)
  168.  
  169. bcolor = iff(val > 0, iff(val > nz(val[1]), color.lime, color.green), iff(val < nz(val[1]), color.red, color.maroon))
  170. scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
  171. // plot(val, color=color.blue, linewidth=2)
  172. // plot(0, color=scolor, style=plot.style_cross, linewidth=2)
  173. // plot(sma(val, SignalPeriod), color=color.red, linewidth=2)
  174. //} --------------- SQUEEZE ---------------
  175. //{
  176. //1 master
  177. useADX = input(false, "Use ADX?")
  178. adx_threshold_buy = input(45, "ADX Greater Than Value (BUY)")
  179. adx_threshold_sell = input(45, "ADX Greater Than Value (SELL)")
  180. //2 master
  181. useRSI = input(false, "Use RSI?")
  182. rsi_threshold_buy = input(45, "RSI Greater Than Value (BUY)")
  183. rsi_threshold_sell = input(45, "RSI Less Than Value (SELL)")
  184. //3 master
  185. useEMA = input(false, "Use EMA of RSI?")
  186. emarsi_threshold_buy = input(45, "EMA of RSI Greater Than Value (BUY)")
  187. emarsi_threshold_sell = input(45, "EMA of RSI Less Than Value (SELL)")
  188. //4 individual
  189. useRSIEMA1 = input(false, "Use RSI Greater Than EMA (BUY)?")
  190. useRSIEMA2 = input(false, "Use RSI Less Than EMA (SELL)?")
  191. useRSIEMA3 = input(false, "Use RSI Crossing UP EMA (BUY)?")
  192. useRSIEMA4 = input(false, "Use RSI Crossing DOWN EMA (SELL)?")
  193. //5 individual
  194. useRSIup = input(false, "Use RSI Line Moving UP (value) % in n bars (BUY)")
  195. useRSIdown = input(false, "Use RSI Line Moving DOWN (value) % in n bars (SELL)")
  196. RSIup = input(45, "RSI Line Moving UP (value) % in n bars (BUY)", type=input.float)
  197. RSIdown = input(45, "RSI Line Moving DOWN (value) % in n bars (SELL)", type=input.float)
  198. rsi_bars = input(2, "Number of bars for RSI Line Movement")
  199. //6 master
  200. useMACD = input(false, "Use MACD?")
  201. macd_threshold_buy = input(45, "MACD Greater Than Value (BUY)", type=input.float)
  202. macd_threshold_sell = input(45, "MACD Less Than Value (SELL)", type=input.float)
  203. //7 master
  204. useMACDHistogram = input(false, "Use MACD Histogram?")
  205. macd_histogram_buy = input(45, "HISTOGRAM Greater Than Value (BUY)", type=input.float)
  206. macd_histogram_sell = input(45, "HISTOGRAM Less Than Value (SELL)", type=input.float)
  207. //8 individual
  208. useMACDsignal1 = input(false, "Use MACD Greater Than MACD Signal Line (BUY)?")
  209. useMACDsignal2 = input(false, "Use MACD Less Than MACD Signal Line (SELL)?")
  210. useMACDsignal3 = input(false, "Use MACD Crossing UP MACD Signal Line (BUY)?")
  211. useMACDsignal4 = input(false, "Use MACD Crossing DOWN MACD Signal Line (SELL)?")
  212. //9 individual
  213. useMACDup = input(false, "Use MACD Line Moving UP (value) % in n bars (BUY)")
  214. useMACDdown = input(false, "Use MACD Line Moving DOWN (value) % in n bars (SELL)")
  215. MACDup = input(0.01, "MACD Line Moving UP (value) % in n bars (BUY)", type=input.float)
  216. MACDdown = input(0.01, "MACD Line Moving DOWN (value) % in n bars (SELL)", type=input.float)
  217. macd_bars = input(2, "Number of bars for MACD Line Movement")
  218. //10 master
  219. useSupertrend = input(false, "Use Supertrend?")
  220. //11 master
  221. useSTline = input(true, "Use Supertrend Line?")
  222. STup = input(0.01, "Supertrend Line Moving UP (value) % in n bars (BUY)", type=input.float)
  223. STdown = input(0.01, "Supertrend Line Moving DOWN (value) % in n bars (SELL)", type=input.float)
  224. st_bars = input(2, "Number of bars for Supertrend Line Movement")
  225. //12 master
  226. useSqueeze = input(false, "Use Squeeze Momentum?")
  227. squeezeup = input(45, "PLOT-BUY Moving UP (value) % in n bars (BUY)", type=input.float)
  228. squeezedown = input(45, "PLOT-SELL Moving DOWN (value) % in n bars (SELL)", type=input.float)
  229. squeeze_bars = input(2, "Number of bars for PLOT Movement")
  230. //13 master
  231. useSqueezePlot = input(false, "Use Squeeze Plot-Buy x Plot-Sell?")
  232. //14 master
  233. useSqueezeValue = input(false, "Use Squeeze Momentum Value?")
  234. squeezeValueup = input(45, "PLOT-BUY Greater Than (value) (BUY)", type=input.float)
  235. squeezeValuedown = input(45, "PLOT-SELL Less Than (value) (SELL)", type=input.float)
  236. //} --------------- ALERT-SETTINGS ---------------
  237. //{
  238. //{
  239. supertrendButtonsOff = not useSupertrend and not useSTline
  240. buyButtonsOff = not useRSIEMA1 and not useRSIEMA3 and not useRSIup and not useMACDsignal1 and not useMACDsignal3 and not useMACDup
  241. individualSelectionBuy = (useRSIEMA1 ? rsi > emaRSI : false) or
  242. (useRSIEMA3 ? crossover(rsi, emaRSI) : false) or
  243. (useRSIup ? (rsi>rsi[rsi_bars]) and abs(change(rsi, rsi_bars))/abs(rsi[rsi_bars])*100 > RSIup : false) or
  244. (useMACDsignal1 ? outMacD > outSignal : false) or
  245. (useMACDsignal3 ? crossover(outMacD, outSignal) : false) or
  246. (useMACDup ? (outMacD>outMacD[macd_bars]) and abs(change(outMacD, macd_bars))/abs(outMacD[macd_bars])*100 > MACDup : false)
  247.  
  248. combinedBuy = (useADX ? adx > adx_threshold_buy : true) and
  249. (useRSI ? rsi > rsi_threshold_buy : true) and
  250. (useEMA ? emaRSI > emarsi_threshold_buy : true) and
  251. (useMACD ? outMacD > macd_threshold_buy : true) and
  252. (useMACDHistogram ? outHist > macd_histogram_buy : true) and
  253. iff(supertrendButtonsOff,true,((useSupertrend ? dir == 1 and dir[1] == -1 : false) or
  254. (useSTline ?
  255. dir == 1 and dir[st_bars] == 1 ?
  256. (longStop > longStop[st_bars]) and abs(change(longStop, st_bars))/abs(longStop[st_bars])*100 > STup :
  257. false : false))) and
  258. (useSqueeze ? (val > val[squeeze_bars]) and abs(change(val, squeeze_bars))/abs(val[squeeze_bars])*100 > squeezeup : true) and
  259. (useSqueezePlot ? val > sma(val, SignalPeriod) : true) and
  260. (useSqueezeValue ? val > squeezeValueup : true) and
  261. iff(buyButtonsOff, true, individualSelectionBuy)
  262. //} BUY
  263.  
  264. //{
  265. sellButtonsOff = not useRSIEMA2 and not useRSIEMA4 and not useRSIdown and not useMACDsignal2 and not useMACDsignal4 and not useMACDdown
  266. individualSelectionSell = (useRSIEMA2 ? rsi < emaRSI : false) or
  267. (useRSIEMA4 ? crossunder(rsi, emaRSI) : false) or
  268. (useRSIdown ? (rsi<rsi[rsi_bars]) and abs(change(rsi, rsi_bars))/abs(rsi[rsi_bars])*100 > RSIdown : false) or
  269. (useMACDsignal2 ? outMacD < outSignal : false) or
  270. (useMACDsignal4 ? crossunder(outMacD, outSignal) : false) or
  271. (useMACDdown ? (outMacD<outMacD[macd_bars]) and abs(change(outMacD, macd_bars))/abs(outMacD[macd_bars])*100 > MACDdown : false)
  272.  
  273. combinedSell = (useADX ? adx > adx_threshold_sell : true) and
  274. (useRSI ? rsi < rsi_threshold_sell : true) and
  275. (useEMA ? emaRSI < emarsi_threshold_sell : true) and
  276. (useMACD ? outMacD < macd_threshold_sell : true) and
  277. (useMACDHistogram ? outHist < macd_histogram_sell : true) and
  278. iff(supertrendButtonsOff,true,((useSupertrend ? dir == -1 and dir[1] == 1 : false) or
  279. (useSTline ?
  280. dir == -1 and dir[st_bars] == -1 ?
  281. (shortStop < shortStop[st_bars]) and abs(change(shortStop, st_bars))/abs(shortStop[st_bars])*100 > STdown :
  282. false : false))) and
  283. (useSqueeze ? (val < val[squeeze_bars]) and abs(change(val, squeeze_bars))/abs(val[squeeze_bars])*100 > squeezedown : true) and
  284. (useSqueezePlot ? val < sma(val, SignalPeriod) : true) and
  285. (useSqueezeValue ? val < squeezeValuedown : true) and
  286. iff(sellButtonsOff, true, individualSelectionSell)
  287.  
  288. //} SELL
  289. alertcondition(combinedBuy,"BUY","BUY")
  290. alertcondition(combinedSell,"SELL","SELL")
  291. alertcondition(combinedSell,"BUYSTOP","BUYSTOP")
  292. alertcondition(combinedBuy,"SELLSTOP","SELLSTOP")
  293. //} --------------- ALERT ---------------
  294. //{
  295. plotshape(combinedBuy,style=shape.triangleup,location=location.belowbar,title="BUY",text="BUY",color=color.green)
  296. plotshape(combinedSell,style=shape.triangledown,location=location.abovebar,title="SELL",text="SELL",color=color.red)
  297. plotshape(combinedSell,style=shape.triangleup,location=location.belowbar,title="BUYSTOP",text="BUYSTOP",color=color.black)
  298. plotshape(combinedBuy,style=shape.triangledown,location=location.abovebar,title="SELLSTOP",text="SELLSTOP",color=color.black)
  299. //} --------------- PLOTS ---------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement