Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.27 KB | None | 0 0
  1. //@version=3
  2. study(title = "Renko+Moving Average+RMI Alert R3 by JustUncleL", shorttitle="RENKO_MA_RMI", overlay=true)
  3. //
  4. // Author: JustUncleL
  5. //
  6. // Description:
  7. // This script idea is designed to be used with 10pip brick (recommened) Renko charts. It combines the Renko
  8. // price action with a directional coloured EMA (default length 6) and a RMI (instead of the usual RSI) indicator
  9. // to provide entry and exit signals. RMI is bit like RSI with a built-in momentum factor and works well with Renko.
  10. // Signals can optionally be filtered by Daily or Weekly Open, where by only trade long above open and short below
  11. // open (this option is enabled by default).
  12. // Exit occur when EMA or RMI reverses direction, or optionally (disabled by default) when the Renko prints
  13. // a brick in the reverse direction.
  14. // Each Entry and Exit signal creates an Alertcondition that can be picked up by the TradingView Alarm system.
  15. //
  16. // TIP: To get 10pip Bricks set Renko to "Traditional" type bricks and 0.001 for non-JPY currency pairs, and
  17. // 0.1 for JPY currency pairs. Also set chart Time frame to 5min or 15mins.
  18. //
  19. // References:
  20. // - TheLark Relative Momentum Index (RMI)
  21. //
  22. // Modifications:
  23. // 13-Sep-2017
  24. // - By request, added option to use the more familiar RSI instead of RMI.
  25. //
  26.  
  27. // === INPUTS
  28.  
  29. // Medium Fast MA - type, source, length
  30. ma_type = input(defval="EMA", title="MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
  31. ma_len = input(defval=6, title="MA - Length", minval=1)
  32. ma_src = input(close, title="MA - Source")
  33. exitfirst = input(false,title="Exit Trade on 1st Opposite Renko Brick")
  34. // inputs for RMI function
  35. rmilen = input(4, title="RMI/RSI MA Length")
  36. mom = input(5, title="Momentum Length",minval=0)
  37. ob = input(70,title="Overbought")
  38. os = input(30,title="Oversold")
  39. uRSI = input(false,title="Use RSI instead of RMI")
  40. udopen = input(true,title="Use Daily Open Line Filter")
  41. dperiod = input("1D", title="Period for Daily Open Line", options=["1D","1W","1M"])
  42. //
  43. // === /INPUTS
  44.  
  45. // Constants colours that include fully non-transparent option.
  46. green100 = #008000FF
  47. lime100 = #00FF00FF
  48. red100 = #FF0000FF
  49. blue100 = #0000FFFF
  50. aqua100 = #00FFFFFF
  51. darkred100 = #8B0000FF
  52. gray100 = #808080FF
  53.  
  54. // === FUNCTIONS
  55.  
  56. // - variant(type, src, len)
  57. // Returns MA input selection variant, default to SMA if blank or typo.
  58.  
  59. // SuperSmoother filter
  60. // © 2013 John F. Ehlers
  61. variant_supersmoother(src,len) =>
  62. a1 = exp(-1.414*3.14159 / len)
  63. b1 = 2*a1*cos(1.414*3.14159 / len)
  64. c2 = b1
  65. c3 = (-a1)*a1
  66. c1 = 1 - c2 - c3
  67. v9 = 0.0
  68. v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
  69. v9
  70.  
  71. variant_smoothed(src,len) =>
  72. v5 = 0.0
  73. v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
  74. v5
  75.  
  76. variant_zerolagema(src,len) =>
  77. ema1 = ema(src, len)
  78. ema2 = ema(ema1, len)
  79. v10 = ema1+(ema1-ema2)
  80. v10
  81.  
  82. variant_doubleema(src,len) =>
  83. v2 = ema(src, len)
  84. v6 = 2 * v2 - ema(v2, len)
  85. v6
  86.  
  87. variant_tripleema(src,len) =>
  88. v2 = ema(src, len)
  89. v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
  90. v7
  91.  
  92. // return variant, defaults to SMA
  93. variant(type, src, len) =>
  94. type=="EMA" ? ema(src,len) :
  95. type=="WMA" ? wma(src,len):
  96. type=="VWMA" ? vwma(src,len) :
  97. type=="SMMA" ? variant_smoothed(src,len) :
  98. type=="DEMA" ? variant_doubleema(src,len):
  99. type=="TEMA" ? variant_tripleema(src,len):
  100. type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
  101. type=="SSMA" ? variant_supersmoother(src,len) :
  102. type=="ZEMA" ? variant_zerolagema(src,len) :
  103. type=="TMA" ? sma(sma(src,len),len) : sma(src,len)
  104.  
  105. // - /variant
  106. // === /FUNCTIONS
  107.  
  108.  
  109. dodgerblue = #1E90FF
  110.  
  111. // === Moving Average
  112. ma_series = variant(ma_type,ma_src,ma_len)
  113.  
  114. // Get direction based on MA
  115. direction = 0
  116. direction := rising(ma_series,3) ? 1 : falling(ma_series,3) ? -1 : nz(direction[1])
  117.  
  118. // Plot MA series and color it according too direction
  119. pcol = direction>0 ? lime : direction<0 ? red : na
  120. plot(ma_series, title="MA Plot", color=pcol, linewidth=2,style=line,join=true, transp=10)
  121.  
  122. // === /Moving Average
  123.  
  124.  
  125. // === DAILY OPEN LINE
  126. //
  127. // Test for new Daily Session or start of new month for Daily.
  128. start = security(ticker, dperiod, time, barmerge.gaps_off, barmerge.lookahead_on)
  129. newDay = change(start)
  130.  
  131. // Calculate Annualised Volatility
  132. dopen = 0.0
  133. dopen_ = valuewhen(start[1]<=time, ma_src, 0)
  134. dopen := newDay ? dopen_ : nz(dopen[1],dopen_)
  135. // Plot all Days open
  136. plot(dopen, color = newDay?na:purple, title = "Daily Open",linewidth=2, transp=40)
  137.  
  138. // === /DAILY OPEN LINE
  139.  
  140. // === RMI (Relative Momentum Index)
  141. //
  142. // "... The Relative Momentum Index was developed by Roger Altman
  143. // and was introduced in his article in the February, 1993 issue of
  144. // Technical Analysis of Stocks & Commodities magazine. "
  145. // "... While RSI counts up and down days from close to close, the Relative
  146. // Momentum Index counts up and down days from the close relative to a
  147. // close x number of days ago. "
  148.  
  149. //calc
  150. up = ema(max(ma_src- ma_src[mom],0),rmilen)
  151. dn = ema(max(ma_src[mom] - ma_src,0),rmilen)
  152. //rmi =
  153. rmi = dn == 0 ? 0 : 100 - 100 / (1 + up / dn)
  154.  
  155. // Use RSI instead of RMI
  156. rmi := uRSI ? rsi(ma_src, rmilen) : rmi
  157.  
  158. // === /RMI
  159.  
  160. // === Calculate Alerts
  161. PA = (close>open) and (not udopen or close>dopen)? 1 : (close<open) and (not udopen or close<dopen)? -1 : 0
  162. HAS = direction
  163. RMI = rmi>=rmi[1] and rmi>=ob ? 1 : rmi<=rmi[1] and rmi<=os ? -1 : 0
  164.  
  165. long = PA==1 and HAS==1 and RMI==1
  166. short = PA==-1 and HAS==-1 and RMI==-1
  167.  
  168. olong = 0
  169. olong := olong[1]>0 and (HAS<0 or (not uRSI and RMI<=0) or (exitfirst and (close<open and close[1]>open[1])))? 0 : nz(olong[1])==0 and long? 1 : olong[1]>0 and HAS==1? olong[1]+1 : 0
  170. oshort = 0
  171. oshort := oshort[1]>0 and (HAS>1 or (not uRSI and RMI>=0) or (exitfirst and (close>open and close[1]<open[1])))? 0 : nz(oshort[1])==0 and short? 1 : oshort[1]>0 and HAS==-1? oshort[1]+1 : 0
  172.  
  173. // - Plot Alerts
  174. plotarrow(olong==1?1:na, title="BUY Arrow", colorup=lime, maxheight=60, minheight=50, transp=20,offset=0)
  175. plotarrow(oshort==1?-1:na, title="SELL Arrow", colordown=red, maxheight=60, minheight=50, transp=20,offset=0)
  176. //
  177. plotshape(olong[1]>0 and olong==0, title='BUY Exit', style=shape.xcross, location=location.belowbar, color=gray, text="Exit\nBuy", offset=0,transp=0)
  178. plotshape(oshort[1]>0 and oshort==0, title='Sell Exit', style=shape.xcross, location=location.abovebar, color=gray, text="Exit\nSell", offset=0,transp=0)
  179.  
  180. // - Signal Alerts to TV Alarm system
  181. alertcondition(olong==1,title="Swing BUY Alert",message="BUY")
  182. alertcondition(oshort==1,title="Swing SELL Alert",message="SELL")
  183. alertcondition(olong[1]>0 and olong==0,title="Swing BUY Exit Alert",message="BUY Exit")
  184. alertcondition(oshort[1]>0 and oshort==0,title="Swing SELL Exit Alert",message="SELL Exit")
  185.  
  186. // debug
  187. //plotshape(PA,location=location.bottom)
  188. //plotshape(HAS,location=location.bottom)
  189. //plotshape(RMI,location=location.bottom)
  190. //plotshape(olong,location=location.bottom)
  191. //plotshape(oshort,location=location.bottom)
  192. //
  193. // === /Calculate Alerts
  194.  
  195. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement