xmd79

EMA MTF Plus

Jan 11th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.55 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. // © mildSnail31034
  3. // Part of this code is copied from Lazy Bear-Range Identifier indicator, Schaff Trend Cycle from everget and OverAtr Bar highlight by
  4. // Jim8080.
  5. // I made this indicator for my use initially, but it could be useful to others as well. This being said, I want to thank the original authors
  6. // for their work and if there are any issues with this, please let me know.
  7. //@version=5
  8. indicator("EMA MTF Plus",overlay=true)
  9. Length=input(12,group="Wicks")
  10. src = input.source(close,group="Wicks")
  11. volf = input.bool(title="Volume filter",defval=true,group="Wicks")
  12. lenvolma = input.int(title="Volume MA",defval=20,group="Wicks")
  13. atrlen = input.int(title="ATR length" , defval=14,group="Strong bars")
  14. atrmult = input.float(title="Body ratio",defval=0.8,group="Strong bars")
  15. macdopt = input.bool(title="Macd filter for triangles",defval=true,group="MACD")
  16. fastLength = input(title='MACD Fast Length', defval=23,group="MACD")
  17. slowLength = input(title='MACD Slow Length', defval=50,group="MACD")
  18. cycleLength = input(title='Cycle Length', defval=10,group="MACD")
  19. d1Length = input(title='1st %D Length', defval=3,group="MACD")
  20. d2Length = input(title='2nd %D Length', defval=3,group="MACD")
  21.  
  22. macd = ta.ema(src, fastLength) - ta.ema(src, slowLength)
  23. k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLength)))
  24. d = ta.ema(k, d1Length)
  25. kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
  26. stc = ta.ema(kd, d2Length)
  27. stc := math.max(math.min(stc, 100), 0)
  28.  
  29. bullmacd = stc[0]>99.6?true:false
  30. bearmacd = stc[0]<0.4?true:false
  31. bullm = macdopt?bullmacd:true
  32. bearm = macdopt?bearmacd:true
  33.  
  34. atrvover= atrmult*ta.atr(atrlen)+open
  35. atrvunder= open-ta.atr(atrlen)*atrmult
  36. isover() => close > atrvover
  37. isunder() => close < atrvunder
  38. barcolor(isover() ? color.yellow: isunder() ? color.fuchsia : na)
  39.  
  40.  
  41.  
  42. volma = ta.ema(volume,lenvolma)
  43.  
  44. volcond = volume>volma?true:false
  45. volfilter=volf?volcond:true
  46.  
  47. wickup=open>close?high-open:high-close
  48. wickdown=open<close?open-low:close-low
  49. wicks = wickup>wickdown?wickup:wickdown
  50. wicksma=ta.ema(wicks,Length)
  51.  
  52.  
  53. hh = high==ta.highest(Length) and ta.highest(high-src,Length) and wickup>wicksma and volfilter and bullm
  54. ll = low==ta.lowest(Length) and ta.highest(src-low,Length) and wickdown>wicksma and volfilter and bearm
  55. plotshape(hh, style=shape.triangledown, size=size.small,color=color.red)
  56. plotshape(ll,style=shape.triangleup, size=size.small , color=color.green, location=location.belowbar)
  57.  
  58. connectRanges=input(false, title="Connect Ranges",group="Ranges")
  59. showMidLine=input(true, title="Show MidLine",group="Ranges")
  60. hc=input(true, title="Highlight Consolidation",group="Ranges")
  61. showEMA=input(true, title="Signal EMA",group="EMAs")
  62. lengthEMA=input(20, title="EMA Length",group="EMAs")
  63. showEMAm=input(true, title="Mid EMA",group="EMAs")
  64. lengthEMAm=input(120, title="EMA Length",group="EMAs")
  65. showEMAb=input(true, title="Base EMA",group="EMAs")
  66. lengthEMAb=input(200, title="EMA Length",group="EMAs")
  67. e=ta.ema(close,lengthEMA)
  68. em=ta.ema(close,lengthEMAm)
  69. eb=ta.ema(close,lengthEMAb)
  70. var up = close
  71. var down = close
  72. down := close<nz(up[1]) and close>down[1] ? nz(down[1]) : low
  73. up := close<nz(up[1]) and close>down[1] ? nz(up[1]) : high
  74. mid = math.avg(up,down)
  75. ul=plot(connectRanges?up:up==nz(up[1])?up:na, color=color.gray, linewidth=2, style=plot.style_linebr, title="Up")
  76. llz=plot(connectRanges?down:down==nz(down[1])?down:na, color=color.gray, linewidth=2, style=plot.style_linebr, title="Down")
  77. dummy=plot(hc?close>e?down:up:na, color=color.gray, style=plot.style_circles, linewidth=0, title="Dummy")
  78. fill(ul,dummy, color=#acfa8745)
  79. fill(dummy,llz, color=#faac8745)
  80. plot(showMidLine?mid:na, color=color.gray, linewidth=1, title="Mid")
  81. plot(showEMA?e:na, title="EMA", color=color.black, linewidth=2)
  82. ebcol = ta.rising(eb,1)?color.green:color.red
  83. emcol = ta.rising(em,1)?color.blue:color.orange
  84. plot(showEMAm?em:na, title="EMA", color=emcol, linewidth=3)
  85. plot(showEMAb?eb:na, title="EMA", color=ebcol, linewidth=4)
  86.  
  87. fast = input(20,inline="period",group="HTF EMA tracker")
  88. slow = input(200,inline="period",group="HTF EMA tracker")
  89. tf1sw = input.bool(title="5min fast",defval=true,inline="tf1",group="HTF EMA tracker")
  90. tf2sw = input.bool(title="15min fast",defval=true,inline="tf2",group="HTF EMA tracker")
  91. tf3sw = input.bool(title="1hr fast",defval=true,inline="tf3",group="HTF EMA tracker")
  92. tf4sw = input.bool(title="4hr fast",defval=true,inline="tf4",group="HTF EMA tracker")
  93. tf5sw = input.bool(title="D fast",defval=true,inline="tf5",group="HTF EMA tracker")
  94. tf6sw = input.bool(title="W fast",defval=true,inline="tf6",group="HTF EMA tracker")
  95. tf1sws = input.bool(title="5min slow",defval=true,inline="tf1",group="HTF EMA tracker")
  96. tf2sws = input.bool(title="15min slow",defval=true,inline="tf2",group="HTF EMA tracker")
  97. tf3sws = input.bool(title="1hr slow",defval=true,inline="tf3",group="HTF EMA tracker")
  98. tf4sws = input.bool(title="4hr slow",defval=true,inline="tf4",group="HTF EMA tracker")
  99. tf5sws = input.bool(title="D slow",defval=true,inline="tf5",group="HTF EMA tracker")
  100. tf6sws = input.bool(title="W slow",defval=true,inline="tf6",group="HTF EMA tracker")
  101.  
  102.  
  103.  
  104. tf1src = input.source(title="",defval=close,inline="tf1",group="HTF EMA tracker")
  105. tf2src = input.source(title="",defval=close,inline="tf2",group="HTF EMA tracker")
  106. tf3src = input.source(title="",defval=close,inline="tf3",group="HTF EMA tracker")
  107. tf4src = input.source(title="",defval=close,inline="tf4",group="HTF EMA tracker")
  108. tf5src = input.source(title="",defval=close,inline="tf5",group="HTF EMA tracker")
  109. tf6src = input.source(title="",defval=close,inline="tf6",group="HTF EMA tracker")
  110.  
  111.  
  112. e1f= request.security(syminfo.tickerid,"5",ta.ema(tf1src,fast))
  113. e1s= request.security(syminfo.tickerid,"5",ta.ema(tf1src,slow))
  114. e2f= request.security(syminfo.tickerid,"15",ta.ema(tf2src,fast))
  115. e2s= request.security(syminfo.tickerid,"15",ta.ema(tf2src,slow))
  116. e3f= request.security(syminfo.tickerid,"60",ta.ema(tf3src,fast))
  117. e3s= request.security(syminfo.tickerid,"60",ta.ema(tf3src,slow))
  118. e4f= request.security(syminfo.tickerid,"240",ta.ema(tf4src,fast))
  119. e4s= request.security(syminfo.tickerid,"240",ta.ema(tf4src,slow))
  120. e5f= request.security(syminfo.tickerid,"D",ta.ema(tf5src,fast))
  121. e5s= request.security(syminfo.tickerid,"D",ta.ema(tf5src,slow))
  122. e6f= request.security(syminfo.tickerid,"W",ta.ema(tf6src,fast))
  123. e6s= request.security(syminfo.tickerid,"W",ta.ema(tf6src,slow))
  124.  
  125. supcol = input.color(title="Support",defval=color.green,inline="col",group="HTF EMA tracker")
  126. rescol = input.color(title="Resistance",defval=color.red,inline="col",group="HTF EMA tracker")
  127.  
  128. e1fcol = close>e1f?supcol:rescol
  129. e1scol = close>e1s?supcol:rescol
  130. e2fcol = close>e2f?supcol:rescol
  131. e2scol = close>e2s?supcol:rescol
  132. e3fcol = close>e3f?supcol:rescol
  133. e3scol = close>e3s?supcol:rescol
  134. e4fcol = close>e4f?supcol:rescol
  135. e4scol = close>e4s?supcol:rescol
  136. e5fcol = close>e5f?supcol:rescol
  137. e5scol = close>e5s?supcol:rescol
  138. e6fcol = close>e6f?supcol:rescol
  139. e6scol = close>e6s?supcol:rescol
  140.  
  141. plot(tf1sw?e1f:na,color=e1fcol,show_last=1,trackprice=true,linewidth=2,title="5m F")
  142. plot(tf1sws?e1s:na,color=e1scol,show_last=1,trackprice=true,linewidth=3,title="5m S")
  143. plot(tf2sw?e2f:na,color=e2fcol,show_last=1,trackprice=true,linewidth=2,title="15m F")
  144. plot(tf2sws?e2s:na,color=e2scol,show_last=1,trackprice=true,linewidth=3,title="15m S")
  145. plot(tf3sw?e3f:na,color=e3fcol,show_last=1,trackprice=true,linewidth=2,title="1h F")
  146. plot(tf3sws?e3s:na,color=e3scol,show_last=1,trackprice=true,linewidth=3,title="1h S")
  147. plot(tf4sw?e4f:na,color=e4fcol,show_last=1,trackprice=true,linewidth=2,title="4h F")
  148. plot(tf4sws?e4s:na,color=e4scol,show_last=1,trackprice=true,linewidth=3,title="4h S")
  149. plot(tf5sw?e5f:na,color=e5fcol,show_last=1,trackprice=true,linewidth=2,title="Daily F")
  150. plot(tf5sws?e5s:na,color=e5scol,show_last=1,trackprice=true,linewidth=3,title="Daily S")
  151. plot(tf6sw?e6f:na,color=e6fcol,show_last=1,trackprice=true,linewidth=2,title="Weekly F")
  152. plot(tf6sws?e6s:na,color=e6scol,show_last=1,trackprice=true,linewidth=3,title="Weekly S")
  153.  
  154. Offset = input(3,group="HTF EMA tracker")
  155.  
  156. plotshape(tf1sw?e1f:na,style=shape.cross,color=e1fcol,show_last=1,text="5m F",location=location.absolute, offset=Offset)
  157. plotshape(tf1sws?e1s:na,style=shape.cross,color=e1scol,show_last=1,text="5m S",location=location.absolute, offset=Offset)
  158. plotshape(tf2sw?e2f:na,style=shape.cross,color=e2fcol,show_last=1,text="15m F",location=location.absolute, offset=Offset)
  159. plotshape(tf2sws?e2s:na,style=shape.cross,color=e2scol,show_last=1,text="15m S",location=location.absolute, offset=Offset)
  160. plotshape(tf3sw?e3f:na,style=shape.cross,color=e3fcol,show_last=1,text="1h F",location=location.absolute, offset=Offset)
  161. plotshape(tf3sws?e3s:na,style=shape.cross,color=e3scol,show_last=1,text="1h S",location=location.absolute, offset=Offset)
  162. plotshape(tf4sw?e4f:na,style=shape.cross,color=e4fcol,show_last=1,text="4h F",location=location.absolute, offset=Offset)
  163. plotshape(tf4sws?e4s:na,style=shape.cross,color=e4scol,show_last=1,text="4h S",location=location.absolute, offset=Offset)
  164. plotshape(tf5sw?e5f:na,style=shape.cross,color=e5fcol,show_last=1,text="D F",location=location.absolute, offset=Offset)
  165. plotshape(tf5sws?e5s:na,style=shape.cross,color=e5scol,show_last=1,text="D S",location=location.absolute, offset=Offset)
  166. plotshape(tf6sw?e6f:na,style=shape.cross,color=e6fcol,show_last=1,text="W F",location=location.absolute, offset=Offset)
  167. plotshape(tf6sws?e6s:na,style=shape.cross,color=e6scol,show_last=1,text="W S",location=location.absolute, offset=Offset)
  168.  
  169.  
  170.  
  171.  
  172.  
Advertisement
Add Comment
Please, Sign In to add comment