Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. ///@version=2
  2. study(title="candleswissknife", shorttitle="candleswissknife",overlay=false)
  3. res = input(title="Heikin Ashi Candle Time Frame", type=resolution, defval="60")
  4. hshift = input(1,title="Heikin Ashi Candle Time Frame Shift")
  5. res1 = input(title="Heikin Ashi EMA Time Frame", type=resolution, defval="1440")
  6. mhshift = input(0,title="Heikin Ashi EMA Time Frame Shift")
  7. fama = input(1,"Heikin Ashi EMA Period")
  8. test = input(1,"Heikin Ashi EMA Shift")
  9. sloma = input(30,"Slow EMA Period")
  10. slomas = input(1,"Slow EMA Shift")
  11. macdf = input(false,title="With MACD filter")
  12. res2 = input(title="MACD Time Frame", type=resolution, defval="15")
  13. macds = input(1,title="MACD Shift")
  14.  
  15.  
  16. //Heikin Ashi Open/Close Price
  17. ha_t = heikinashi(tickerid)
  18. ha_open = security(ha_t, res, open[hshift])
  19. ha_close = security(ha_t, res, close[hshift])
  20. mha_close = security(ha_t, res1, close[mhshift])
  21.  
  22. //macd
  23. [macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
  24. macdl = security(ha_t,res2,macdLine[macds])
  25. macdsl= security(ha_t,res2,signalLine[macds])
  26.  
  27. //Moving Average
  28. fma = ema(mha_close[test],fama)
  29. sma = ema(ha_close[slomas],sloma)
  30.  
  31. // SETTING UP VARIABLES //
  32.  
  33. src = input(title="Data Source",type=source,defval=ohlc4)
  34.  
  35. // RSI //
  36. rsiprd = input(title="RSI period",type=integer,defval=5)
  37. rv = rsi(src,rsiprd)
  38. ob = input(title="Overbought Level", type=integer, defval=70)
  39. os = input(title="Oversold Level", type=integer, defval=30)
  40.  
  41. // look back periods //
  42. x = input(title = "short lookback period",type=integer,defval=5)
  43. z = input(title = "long lookback period",type=integer,defval=25)
  44. revatr = input(title="ATR Reversal multiplier", type=float, defval=1.618)*atr(rsiprd)
  45. alert = input(title="Alert period", type=integer, defval=25)
  46.  
  47. // END SETUP //
  48.  
  49. ////////////////////////
  50. // BULLISH DIVERGENCE //
  51. ////////////////////////
  52.  
  53. // define lower low in price //
  54.  
  55. srcLL = src > lowest(src,x)+revatr and lowest(src,x)<lowest(src,z)[x]
  56.  
  57. // define higher low in rsi //
  58.  
  59. rsiHL = rv>lowest(rv,x) and lowest(rv,x) > lowest(rv,z)[x] and lowest(rv,x)<os
  60.  
  61. BullishDiv = srcLL and rsiHL
  62. BullishDivAlert = iff(barssince(BullishDiv)<alert,10,0)+50
  63.  
  64. ////////////////////////
  65. // BEARISH DIVERGENCE //
  66. ////////////////////////
  67.  
  68. // define higher high in price //
  69.  
  70. srcHH = src < highest(src,x)-revatr and highest(src,x)>highest(src,z)[x]
  71.  
  72. // define lower high in RSI //
  73.  
  74. rsiLH = rv<highest(rv,x) and highest(rv,x) < highest(rv,z)[x] and highest(rv,x)>ob
  75.  
  76. BearishDiv = srcHH and rsiLH
  77. BearishDivAlert = iff(barssince(BearishDiv)<alert,-10,0)+50
  78.  
  79. zero = plot(50)
  80. osl = plot(30)
  81. obl = plot(70)
  82. BULLD = plot(BullishDivAlert, color = green)
  83. BEARD = plot(BearishDivAlert, color = red)
  84. fill(BULLD,zero,color=green, transp=90)
  85. fill(zero,BEARD,color=red, transp=90)
  86. plot(rv, color = white, linewidth = 2)
  87. oslv = plot(rv<30 ? 20 : 30, color = gray)
  88. oblv = plot(rv>70 ? 80 : 70, color = gray)
  89. fill(osl,oslv, color=blue, transp=90)
  90. fill(oblv,obl, color=red, transp=90)
  91. ///DIRECTIONAL MOVEMENT INDEX///
  92. len3 = input(5, minval=1, title="DI Length")
  93. lensig3 = input(5, title="ADX Smoothing", minval=1, maxval=50)
  94. up3 = change(high)
  95. down3 = -change(low)
  96. plusDM3 = na(up3) ? na : (up3 > down3 and up3 > 0 ? up3 : 0)
  97. minusDM3 = na(down3) ? na : (down3 > up3 and down3 > 0 ? down3 : 0)
  98. trur3 = rma(tr, len3)
  99. plus3 = fixnan(100 * rma(plusDM3, len3) / trur3)
  100. minus3 = fixnan(100 * rma(minusDM3, len3) / trur3)
  101. sum3 = plus3 + minus3
  102. adx3 = 100 * rma(abs(plus3 - minus3) / (sum3 == 0 ? 1 : sum3), lensig3)
  103. plot(plus3, color=white, style=line, linewidth=2, title="+DI")
  104. plot(minus3, color=white, style=line, linewidth=2, title="-DI")
  105. plot(adx3, color=white, style=line, linewidth=3, title="ADX")
  106. // Wells Wilders MA
  107. wwma(l,p) =>
  108. wwma = (nz(wwma[1]) * (l - 1) + p) / l
  109.  
  110. // Inputs
  111. DMIlength = input(10)
  112. Stolength = input(3)
  113.  
  114. // DMI Osc Calc
  115. hiDiff = high - high[1]
  116. loDiff = low[1] - low
  117. plusDM = (hiDiff > loDiff) and (hiDiff > 0) ? hiDiff : 0
  118. minusDM = (loDiff > hiDiff) and (loDiff > 0) ? loDiff : 0
  119. ATR = wwma(DMIlength, tr)
  120. PlusDI = 100 * wwma(DMIlength,plusDM) / ATR
  121. MinusDI = 100 * wwma(DMIlength,minusDM) / ATR
  122. osc = PlusDI - MinusDI
  123.  
  124. // DMI Stochastic Calc
  125. hi = highest(osc, Stolength)
  126. lo = lowest(osc, Stolength)
  127.  
  128. Stoch = sum((osc-lo),Stolength) / sum((hi-lo),Stolength) *100
  129. plot(Stoch, color = white, title = 'Stochastic', linewidth = 2, style = line)
  130.  
  131. p0 = 0
  132. p1 = 5
  133. p2 = 80
  134. p3 = 20
  135.  
  136. crossUp = Stoch[1] < 10 and Stoch >10 ? 1 : 0
  137. crossDown = Stoch[1] > 90 and Stoch < 90 ? 1 : 0
  138.  
  139. //crossP3 = cross(Stoch,p3)
  140.  
  141. //circleYPosition = crossP3
  142. //circleYPosition = p3
  143. //circleYPosition_l = p2
  144.  
  145. plot (p3, color = red, linewidth = 1, title = 'Over Bought')
  146. plot (p2, color = green, linewidth = 1, title = 'Over Sold')
  147.  
  148. //plot(crossUp and crossP3 ? circleYPosition : na, color = green, style = cross, linewidth = 4, title='Long')
  149. //plot(crossUp ? circleYPosition : na, color = green, style = cross, linewidth = 4, title='Long', offset=-1)
  150. //plot(sd and cross_down and cross(sma(ac, 1), achm) ? circleYPosition : na,style=cross, linewidth=6, color=fuchsia)
  151. //plot(crossDown ? circleYPosition_l : na,style=cross, linewidth=6, color=fuchsia, offset=-1)
  152.  
  153. //plot(cross(Stoch,p2) ? Stoch : na, color = Stoch < p2 ? red : na, style = cross, linewidth = 4, title='Short')
  154.  
  155. plotchar(crossUp, title="i", char='B', location=location.bottom, color=green, transp=0, offset=0)
  156. plotchar(crossDown, title="Gann Swing Low Plots-Triangles Up Bottom of Screen",char='S', offset=0, location=location.top, color=red, transp=0)
  157.  
  158. p = input(120,title="Length")
  159.  
  160. //scale
  161. hh = highest(high,p)
  162. ll = lowest(low,p)
  163. scale = hh-ll
  164.  
  165. //dynamic OHLC
  166. dyno = ((open-ll)/scale)*100
  167. dynl = ((low-ll)/scale)*100
  168. dynh = ((high-ll)/scale)*100
  169. dync = ((close-ll)/scale)*100
  170.  
  171. //candle color
  172. color=close>open?1:0
  173.  
  174. //drawcandle
  175. hline(78.6)
  176. hline(61.8)
  177. hline(50)
  178. hline(38.2)
  179. hline(23.6)
  180. plotcandle(dyno,dynh,dynl,dync,title="Candle",color=color==1?green:red)
  181. plot(10,color=green)
  182. plot(30,color=red)
  183. plot(80,color=black)
  184. plot(90,color=red)
  185. //Alert
  186.  
  187. up = dync<70 and crossover(fma,sma) and (macdl > macdsl or macdf == false) ? 1:0
  188. down = crossunder(fma,sma) and (macdl < macdsl or macdf == false ) ? -1:0
  189. plot(up,"Go Long",color=lime,linewidth=20,style=histogram)
  190. plot(down,"Go Short",color=red,linewidth=20,style=histogram)
  191.  
  192. up1 = minus3>20 and crossover(dync,p3)
  193. down1 = crossunder(rv,p2) and dync>80
  194. plot(up1,"Go Long1",color=blue,linewidth=20,style=histogram)
  195. plot(down1,"Go Short1",color=gray,linewidth=20,style=histogram)
  196.  
  197. up2 = crossover(dync,p1) and rv<10
  198. down2 = crossunder(rv,p2) and dync>80
  199. plot(up2,"Go Long2",color=green,linewidth=20,style=histogram)
  200. plot(down2,"Go Short2",color=gray,linewidth=20,style=histogram)
  201. alertcondition(up, title='go long', message='go long')
  202. alertcondition(up1, title='go long1', message='go long1')
  203. alertcondition(up2, title='go long2', message='go long2')
  204. alertcondition(down, title='go short', message='go go short')
  205. alertcondition(down1, title='go short1', message='go short1')
  206. bgcolor(down2 > 0 ? red : na, transp=90)
  207. bgcolor(up2 > 0 ? green : na, transp=50)
  208. bgcolor(up1 > 0 ? blue : na, transp=90)
  209. bgcolor(down < 0 ? red : na, transp=50)
  210. bgcolor(up > 0 ? lime : na, transp=50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement