Advertisement
JustUncleL

QQE alert V3.0

Mar 17th, 2017
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.22 KB | None | 0 0
  1. //@version=2
  2. //
  3. // Title: QQE Cross Indicator Alert v3.0 by JustUncleL
  4. // Author: JustUncleL
  5. // Date: 10-July-2016
  6. // Version: v3.0
  7. //
  8. // Description:
  9. // A trend following indicator alert that uses fast QQE crosses with Moving Averages
  10. // for trend direction filtering. QQE or Qualitative Quantitative Estimation is based
  11. // on the relative strength index, but uses a smoothing technique as an additional
  12. // transformation. Three crosses can be selected (all selected by default):
  13. // - RSI signal crossing ZERO (XZERO)
  14. // - RSI signal crossing Fast RSIatr line (XQQE)
  15. // - RSI signal exiting the RSI Threshhold Channel (XCHL)
  16. // The (BUY/SELL) alerts can be optionally filtered by the Moving averages:
  17. // - For BUY alert the Close must be above the fast MA and
  18. // fast MA (EMA8) > medium MA (EMA20) > slow MA (SMA50).
  19. // - For SELL alert the Close must be below the fast MA and
  20. // fast MA (EMA8) < medium MA (EMA20) < slow MA (SMA50).
  21. // and/or directional filter:
  22. // - For BUY alert the Close must be above the slow MA (SMA50) and the
  23. // directional MA (EMA20) must be green.
  24. // - For SELL alert the Close must be below the slow MA (SMA50) and the
  25. // directional MA (EMA20) must be red.
  26. //. The XZERO and XQQE are not included in the filtering, but they are used to indicate
  27. // pending BUY/SELL alerts, particularly the XZERO.
  28. // Note: I have found the XQQE cross can also be quite good alert for BUY/SELL as well,
  29. // particularly in direction of current trend. The XZERO I have found
  30. // to be totally unreliable for BUY/SELL alerts.
  31. //
  32. // This indicator should work on any currency pair, most chart timeframes and
  33. // expiry in:
  34. // - 1 to 3 candles for 1min and 5min charts
  35. // - 4 to 8 candles for 15min or longer charts.
  36. // - or use alerts for Scalping in FOREX.
  37. // Don't trade every alert, look for the best set ups.
  38. //
  39. // Mofidifications:
  40. // 3.0 - No repaint on BUY/SELL alert, however, now trades should be taken when the BUY/SELL
  41. // Alert is displayed. The alarm is still generated on the previous candle so you can
  42. // still get a pre-warning, this enables you time to analyse the pending alert.
  43. // - Added option to test success of alerted trades, highlight successful and failed trade bars
  44. // and show simple stats: success rate and number of trades (out of 5000), this will help
  45. // tune the settings for timeframe and currency PAIR.
  46. // 2.0 - Added code to use the medium moving average (EMA20) rising/falling for additional
  47. // trend direction filter.
  48. // - Remove Moving Average cross over signals and other options not used in this indicator.
  49. // - Added code to distinguish between the crosses, now only show Thresh Hold crosses as BUY/SELL
  50. // alerts.
  51. // - Modidied default settings to more well known MA's and slightly different QQE settings, these
  52. // work well at lower timeframes.
  53. // - Added circle plots at bottom of chart to show when actual BUY/SELL alerts occur.
  54. // 1.0 - original
  55. //
  56. // References:
  57. // Some Code borrowed from:
  58. // - "Scalp Jockey - MTF MA Cross Visual Strategizer by JayRogers"
  59. // - "QQE MT4 by glaz"
  60. // Inspiration from:
  61. // - http://www.forexstrategiesresources.com/binary-options-strategies-ii/189-aurora-binary-trading/
  62. // - http://www.forexstrategiesresources.com/metatrader-4-trading-systems-v/652-qqe-smoothed-trading/
  63. // - http://dewinforex.com/forex-indicators/qqe-indicator-not-quite-grail-but-accurately-defines-trend-and-flat.html
  64. // - "Binary option trading by two previous bars" by radixvinni
  65. //
  66. study(title="QQE Cross Indicator Alert v3.0 by JustUncleL", shorttitle="QQEX v3.0", overlay=true,max_bars_back=2000)
  67.  
  68. //
  69. // - INPUTS START
  70. // Fast MA - type, source, length
  71. type1 = input(defval="HullMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  72. len1 = input(defval=8, title="Fast - Length", minval=1)
  73. // Medium Fast MA - type, source, length
  74. type2 = input(defval="HullMA", title="Medium MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  75. len2 = input(defval=21, title="Medium - Length", minval=1)
  76. // Slow MA - type, source, length
  77. type3 = input(defval="HullMA", title="Slow MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  78. len3 = input(defval=34, title="Slow Length", minval=1)
  79. //
  80. // QQE rsi Length, Smoothing, fast ATR factor, source
  81. RSILen = input(6,title='RSI Length')
  82. SF = input(3,title='RSI Smoothing Factor')
  83. QQE = input(2.618,title='Fast QQE Factor')
  84. threshhold = input(10, title="RSI Threshhold")
  85. //
  86. sQQEx = input(true,title="Show QQE Signal crosses")
  87. sQQEz = input(true,title="Show QQE Zero crosses")
  88. sQQEc = input(true,title="Show QQE Thresh Hold Channel Exits")
  89. //
  90. filter = input(false,title="Use Moving Average Filter")
  91. dfilter = input(false, title="Use Trend Directional Filter" )
  92. sall = input(false, title="Use All Crosses in Alert Alarm")
  93. ushunt = input(false, title="Use Shunt Buy/SEll Alert to prevent Repaint")
  94. RSIsrc = input(close,title="Source")
  95. srcclose= RSIsrc
  96. shunt = ushunt ? (RSIsrc==open? 0 : 1) : 0
  97. // - INPUTS END
  98.  
  99. // - FUNCTIONS
  100.  
  101. // Returns MA input selection variant, default to SMA if blank or typo.
  102. variant(type, src, len) =>
  103. v1 = sma(src, len) // Simple
  104. v2 = ema(src, len) // Exponential
  105. v3 = wma(src, len) // Weighted
  106. v4 = vwma(src, len) // Volume Weighted
  107. v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
  108. v6 = 2 * v2 - ema(v2, len) // Double Exponential
  109. v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
  110. v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
  111. v11 = sma(sma(src,len),len) // Triangular
  112. // SuperSmoother filter
  113. // © 2013 John F. Ehlers
  114. a1 = exp(-1.414*3.14159 / len)
  115. b1 = 2*a1*cos(1.414*3.14159 / len)
  116. c2 = b1
  117. c3 = (-a1)*a1
  118. c1 = 1 - c2 - c3
  119. v9 = c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
  120. // Zero Lag Exponential
  121. ema1 = ema(src, len)
  122. ema2 = ema(ema1, len)
  123. v10 = ema1+(ema1-ema2)
  124. // return variant, defaults to SMA if input invalid.
  125. type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="SSMA"?v9 : type=="ZEMA"?v10 : type=="TMA"? v11: v1
  126.  
  127. // - FUNCTIONS END
  128.  
  129. // - Fast ATR QQE
  130. //
  131. Wilders_Period = RSILen * 2 - 1
  132. //
  133. Rsi = rsi(RSIsrc,RSILen)
  134. RSIndex = ema(Rsi, SF)
  135. AtrRsi = abs(RSIndex[1] - RSIndex)
  136. MaAtrRsi = ema(AtrRsi, Wilders_Period)
  137. DeltaFastAtrRsi = ema(MaAtrRsi,Wilders_Period) * QQE
  138. //
  139. newshortband= RSIndex + DeltaFastAtrRsi
  140. newlongband= RSIndex - DeltaFastAtrRsi
  141. longband=RSIndex[1] > longband[1] and RSIndex > longband[1] ? max(longband[1],newlongband) : newlongband
  142. shortband=RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? min(shortband[1],newshortband) : newshortband
  143. trend=cross(RSIndex, shortband[1])? 1 : cross(longband[1], RSIndex) ? -1 : nz(trend[1],1)
  144. FastAtrRsiTL = trend==1 ? longband : shortband
  145.  
  146.  
  147. // - SERIES VARIABLES
  148. // MA's
  149. ma_fast = variant(type1, srcclose, len1)
  150. ma_medium = variant(type2, srcclose, len2)
  151. ma_slow = variant(type3, srcclose, len3)
  152. // Get Direction From Medium Moving Average
  153. direction = rising(ma_medium,3) ? 1 : falling(ma_medium,3) ? -1 : 0
  154. //
  155. // Find all the QQE Crosses
  156. QQExshort = crossover(FastAtrRsiTL, RSIndex)
  157. QQExlong = crossunder(FastAtrRsiTL, RSIndex)
  158. // Zero cross
  159. QQEzlong = crossover(RSIndex,50)
  160. QQEzshort = crossunder(RSIndex,50)
  161. //
  162. // Thresh Hold channel Crosses give the BUY/SELL alerts.
  163. QQEclong = RSIndex>(50+threshhold) ? na(QQEclong[1]) ? 1 : QQEclong[1]+1 : 0
  164. QQEcshort = RSIndex<(50-threshhold) ? na(QQEcshort[1]) ? 1 : QQEcshort[1]+1 : 0
  165.  
  166. //
  167. // Check Filtering.
  168. QQEflong = (not filter or (srcclose>ma_fast and ma_medium>ma_slow and ma_fast>ma_medium)) and
  169. (not dfilter or (direction>0 ))
  170. QQEfshort = (not filter or (srcclose<ma_fast and ma_medium<ma_slow and ma_fast<ma_medium)) and
  171. (not dfilter or (direction<0 ))
  172. //
  173. // Get final BUY / SELL alert determination
  174. buy = QQEclong>0 and QQEflong ? na(buy[1]) ? 1 : buy[1]+1 : 0
  175. sell= QQEcshort>0 and QQEfshort ? na(sell[1]) ? 1 : sell[1]+1 : 0
  176.  
  177. // - SERIES VARIABLES END
  178.  
  179. // - PLOTTING
  180. // Ma's
  181. plot(ma_fast, title="MA Fast", color=black, linewidth=2, transp=0)
  182. plot(ma_medium, title="MA Medium Fast", color=direction<0?red:green, linewidth=3, transp=0)
  183. plot(ma_slow, title="MA Slow", color=blue, linewidth=2, transp=0)
  184. // QQE exit from Thresh Hold Channel
  185. plotshape(sQQEc and QQEclong==1 and buy[shunt]!=1, title="QQE X Over Channel", style=shape.triangleup, location=location.belowbar, text="XC", color=olive, transp=20, size=size.tiny)
  186. plotshape(sQQEc and QQEcshort==1 and sell[shunt]!=1, title="QQE X Under Channel", style=shape.triangledown, location=location.abovebar, text="XC", color=red, transp=20, size=size.tiny)
  187. // QQE crosses
  188. plotshape(sQQEx and QQExlong and QQEclong!=1 and buy[shunt]!=1, title="QQE Cross Over", style=shape.triangleup, location=location.belowbar, text="XQ", color=blue, transp=20, size=size.tiny)
  189. plotshape(sQQEx and QQExshort and QQEcshort!=1 and sell[shunt]!=1, title="QQE Cross Under", style=shape.triangledown, location=location.abovebar, text="XQ", color=black, transp=20, size=size.tiny)
  190. // Signal crosses zero line
  191. plotshape(sQQEz and QQEzlong and QQEclong!=1 and buy[shunt]!=1 and not QQExlong, title="QQE Zero Cross Over", style=shape.triangleup, location=location.belowbar, text="XZ", color=aqua, transp=20, size=size.tiny)
  192. plotshape(sQQEz and QQEzshort and QQEcshort!=1 and sell[shunt]!=1 and not QQExshort, title="QQE Zero Cross Under", style=shape.triangledown, location=location.abovebar, text="XZ", color=fuchsia, transp=20, size=size.tiny)
  193. // Exit ThreshHold Channel
  194. plotshape(buy[shunt]==1, title="QQE BUY", style=shape.arrowup, location=location.belowbar, text="BUY", color=lime, textcolor=green, transp=0, size=size.small)
  195. plotshape(sell[shunt]==1, title="QQE SELL", style=shape.arrowdown, location=location.abovebar, text="SELL", color=red, textcolor=maroon, transp=0, size=size.small)
  196.  
  197. // - PLOTTING END
  198.  
  199. // - ALERTING
  200.  
  201. // can alert just BUY/SELL or all crosses
  202. c_alert = (buy==1 or sell==1) or (sall and (QQExshort or QQExlong or QQEzshort or QQEzlong))
  203. alertcondition(c_alert, title="QQEX Alert", message="QQEX Alert")
  204. alertcondition((QQEclong==1 or QQEcshort==1), title="QQEX XC Alert", message="QQEX XC Alert")
  205. alertcondition((QQExlong or QQExshort), title="QQEX XQ Alert", message="QQEX XQ Alert")
  206. alertcondition((QQEzlong or QQEzshort), title="QQEX XZ Alert", message="QQEX XZ Alert")
  207. //
  208. // show only when alert condition is met and bar closed.
  209. plotshape((buy[1]==1 or sell[1]==1),title= "Cross Alert Completed", location=location.bottom, color=sell[1]==1?red:green, transp=0, style=shape.circle,size=size.auto,offset=-1)
  210.  
  211. //t_alert = direction>0 and (direction[1]<0 or (direction[1]==0 and direction[2]<0))? 1 : direction<0 and (direction[1]>0 or (direction[1]==0 and direction[2]>0))? -1 : na
  212. //alertcondition(t_alert, title="[UL]QQEX Trend Alert", message="[UL]QQEX Trend Alert")
  213. //plotshape(t_alert[1],title= "Trend Alert Completed", location=location.bottom, color=blue, transp=0, style=shape.circle,size=size.auto,offset=-1)
  214.  
  215. // - ALERTING END
  216.  
  217. // ===============================================================
  218. // - STATISTICS
  219. // Generate bar by bar stats
  220. // This idea was inspired by "Binary option trading by two previous bars" by radixvinni
  221. //
  222. // Inputs
  223. //ssuc = input(true,title="Highlight Successfull & Failed Bars")
  224. //nc = input(3,minval=1,title="Number of Candles in trade")
  225.  
  226. //
  227. // Find alert bars and check, trade completed ITM or not
  228. //alert_bar = (buy[nc]==1 or sell[nc]==1)
  229. //correct = (buy[nc]==1 and (close > close[nc])) or (sell[nc]==1 and (close < close[nc]))
  230.  
  231. //
  232. // Show end of trade bar Success(Yellow) or Failure(Black)
  233. //bcolor = alert_bar and correct? yellow: alert_bar? black: na
  234. //barcolor(ssuc?bcolor:na)
  235. //
  236. // Count Successes and failuers
  237. //yellow_bar = (alert_bar and correct)?1:0
  238. //black_bar = (alert_bar and not correct)?1:0
  239. //all_bar = (close>=open)?1:1
  240. //
  241. // Calculate the simple stats
  242. //total_bars = cum(all_bar)
  243. //total_yellow_bars = cum(yellow_bar)
  244. //total_black_bars = cum(black_bar)
  245. //total_trades = total_yellow_bars + total_black_bars
  246. //success_rate = total_trades>0? 100.0*total_yellow_bars/total_trades: 0
  247. //
  248. // Plot dummy shapes, to allow numbers to be displayed in two numbers in format line of indicator
  249. //plotshape(success_rate,"success rate",location=location.bottom, color=bcolor, transp=0, style=shape.triangleup,size=size.auto)
  250. //plotshape(total_trades,"trades made",location=location.bottom, color=bcolor, transp=0, style=shape.triangleup,size=size.auto)
  251. //plotshape(total_bars,"total bars",location=location.bottom, color=bcolor, transp=0, style=shape.triangleup,size=size.auto)
  252. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement