Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- //
- // Title: QQE Cross Indicator Alert v3.0 by JustUncleL
- // Author: JustUncleL
- // Date: 10-July-2016
- // Version: v3.0
- //
- // Description:
- // A trend following indicator alert that uses fast QQE crosses with Moving Averages
- // for trend direction filtering. QQE or Qualitative Quantitative Estimation is based
- // on the relative strength index, but uses a smoothing technique as an additional
- // transformation. Three crosses can be selected (all selected by default):
- // - RSI signal crossing ZERO (XZERO)
- // - RSI signal crossing Fast RSIatr line (XQQE)
- // - RSI signal exiting the RSI Threshhold Channel (XCHL)
- // The (BUY/SELL) alerts can be optionally filtered by the Moving averages:
- // - For BUY alert the Close must be above the fast MA and
- // fast MA (EMA8) > medium MA (EMA20) > slow MA (SMA50).
- // - For SELL alert the Close must be below the fast MA and
- // fast MA (EMA8) < medium MA (EMA20) < slow MA (SMA50).
- // and/or directional filter:
- // - For BUY alert the Close must be above the slow MA (SMA50) and the
- // directional MA (EMA20) must be green.
- // - For SELL alert the Close must be below the slow MA (SMA50) and the
- // directional MA (EMA20) must be red.
- //. The XZERO and XQQE are not included in the filtering, but they are used to indicate
- // pending BUY/SELL alerts, particularly the XZERO.
- // Note: I have found the XQQE cross can also be quite good alert for BUY/SELL as well,
- // particularly in direction of current trend. The XZERO I have found
- // to be totally unreliable for BUY/SELL alerts.
- //
- // This indicator should work on any currency pair, most chart timeframes and
- // expiry in:
- // - 1 to 3 candles for 1min and 5min charts
- // - 4 to 8 candles for 15min or longer charts.
- // - or use alerts for Scalping in FOREX.
- // Don't trade every alert, look for the best set ups.
- //
- // Mofidifications:
- // 3.0 - No repaint on BUY/SELL alert, however, now trades should be taken when the BUY/SELL
- // Alert is displayed. The alarm is still generated on the previous candle so you can
- // still get a pre-warning, this enables you time to analyse the pending alert.
- // - Added option to test success of alerted trades, highlight successful and failed trade bars
- // and show simple stats: success rate and number of trades (out of 5000), this will help
- // tune the settings for timeframe and currency PAIR.
- // 2.0 - Added code to use the medium moving average (EMA20) rising/falling for additional
- // trend direction filter.
- // - Remove Moving Average cross over signals and other options not used in this indicator.
- // - Added code to distinguish between the crosses, now only show Thresh Hold crosses as BUY/SELL
- // alerts.
- // - Modidied default settings to more well known MA's and slightly different QQE settings, these
- // work well at lower timeframes.
- // - Added circle plots at bottom of chart to show when actual BUY/SELL alerts occur.
- // 1.0 - original
- //
- // References:
- // Some Code borrowed from:
- // - "Scalp Jockey - MTF MA Cross Visual Strategizer by JayRogers"
- // - "QQE MT4 by glaz"
- // Inspiration from:
- // - http://www.forexstrategiesresources.com/binary-options-strategies-ii/189-aurora-binary-trading/
- // - http://www.forexstrategiesresources.com/metatrader-4-trading-systems-v/652-qqe-smoothed-trading/
- // - http://dewinforex.com/forex-indicators/qqe-indicator-not-quite-grail-but-accurately-defines-trend-and-flat.html
- // - "Binary option trading by two previous bars" by radixvinni
- //
- study(title="QQE Cross Indicator Alert v3.0 by JustUncleL", shorttitle="QQEX v3.0", overlay=true,max_bars_back=2000)
- //
- // - INPUTS START
- // Fast MA - type, source, length
- type1 = input(defval="HullMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- len1 = input(defval=8, title="Fast - Length", minval=1)
- // Medium Fast MA - type, source, length
- type2 = input(defval="HullMA", title="Medium MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- len2 = input(defval=21, title="Medium - Length", minval=1)
- // Slow MA - type, source, length
- type3 = input(defval="HullMA", title="Slow MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- len3 = input(defval=34, title="Slow Length", minval=1)
- //
- // QQE rsi Length, Smoothing, fast ATR factor, source
- RSILen = input(6,title='RSI Length')
- SF = input(3,title='RSI Smoothing Factor')
- QQE = input(2.618,title='Fast QQE Factor')
- threshhold = input(10, title="RSI Threshhold")
- //
- sQQEx = input(true,title="Show QQE Signal crosses")
- sQQEz = input(true,title="Show QQE Zero crosses")
- sQQEc = input(true,title="Show QQE Thresh Hold Channel Exits")
- //
- filter = input(false,title="Use Moving Average Filter")
- dfilter = input(false, title="Use Trend Directional Filter" )
- sall = input(false, title="Use All Crosses in Alert Alarm")
- ushunt = input(false, title="Use Shunt Buy/SEll Alert to prevent Repaint")
- RSIsrc = input(close,title="Source")
- srcclose= RSIsrc
- shunt = ushunt ? (RSIsrc==open? 0 : 1) : 0
- // - INPUTS END
- // - FUNCTIONS
- // Returns MA input selection variant, default to SMA if blank or typo.
- variant(type, src, len) =>
- v1 = sma(src, len) // Simple
- v2 = ema(src, len) // Exponential
- v3 = wma(src, len) // Weighted
- v4 = vwma(src, len) // Volume Weighted
- v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
- v6 = 2 * v2 - ema(v2, len) // Double Exponential
- v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
- v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
- v11 = sma(sma(src,len),len) // Triangular
- // SuperSmoother filter
- // © 2013 John F. Ehlers
- a1 = exp(-1.414*3.14159 / len)
- b1 = 2*a1*cos(1.414*3.14159 / len)
- c2 = b1
- c3 = (-a1)*a1
- c1 = 1 - c2 - c3
- v9 = c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
- // Zero Lag Exponential
- ema1 = ema(src, len)
- ema2 = ema(ema1, len)
- v10 = ema1+(ema1-ema2)
- // return variant, defaults to SMA if input invalid.
- 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
- // - FUNCTIONS END
- // - Fast ATR QQE
- //
- Wilders_Period = RSILen * 2 - 1
- //
- Rsi = rsi(RSIsrc,RSILen)
- RSIndex = ema(Rsi, SF)
- AtrRsi = abs(RSIndex[1] - RSIndex)
- MaAtrRsi = ema(AtrRsi, Wilders_Period)
- DeltaFastAtrRsi = ema(MaAtrRsi,Wilders_Period) * QQE
- //
- newshortband= RSIndex + DeltaFastAtrRsi
- newlongband= RSIndex - DeltaFastAtrRsi
- longband=RSIndex[1] > longband[1] and RSIndex > longband[1] ? max(longband[1],newlongband) : newlongband
- shortband=RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? min(shortband[1],newshortband) : newshortband
- trend=cross(RSIndex, shortband[1])? 1 : cross(longband[1], RSIndex) ? -1 : nz(trend[1],1)
- FastAtrRsiTL = trend==1 ? longband : shortband
- // - SERIES VARIABLES
- // MA's
- ma_fast = variant(type1, srcclose, len1)
- ma_medium = variant(type2, srcclose, len2)
- ma_slow = variant(type3, srcclose, len3)
- // Get Direction From Medium Moving Average
- direction = rising(ma_medium,3) ? 1 : falling(ma_medium,3) ? -1 : 0
- //
- // Find all the QQE Crosses
- QQExshort = crossover(FastAtrRsiTL, RSIndex)
- QQExlong = crossunder(FastAtrRsiTL, RSIndex)
- // Zero cross
- QQEzlong = crossover(RSIndex,50)
- QQEzshort = crossunder(RSIndex,50)
- //
- // Thresh Hold channel Crosses give the BUY/SELL alerts.
- QQEclong = RSIndex>(50+threshhold) ? na(QQEclong[1]) ? 1 : QQEclong[1]+1 : 0
- QQEcshort = RSIndex<(50-threshhold) ? na(QQEcshort[1]) ? 1 : QQEcshort[1]+1 : 0
- //
- // Check Filtering.
- QQEflong = (not filter or (srcclose>ma_fast and ma_medium>ma_slow and ma_fast>ma_medium)) and
- (not dfilter or (direction>0 ))
- QQEfshort = (not filter or (srcclose<ma_fast and ma_medium<ma_slow and ma_fast<ma_medium)) and
- (not dfilter or (direction<0 ))
- //
- // Get final BUY / SELL alert determination
- buy = QQEclong>0 and QQEflong ? na(buy[1]) ? 1 : buy[1]+1 : 0
- sell= QQEcshort>0 and QQEfshort ? na(sell[1]) ? 1 : sell[1]+1 : 0
- // - SERIES VARIABLES END
- // - PLOTTING
- // Ma's
- plot(ma_fast, title="MA Fast", color=black, linewidth=2, transp=0)
- plot(ma_medium, title="MA Medium Fast", color=direction<0?red:green, linewidth=3, transp=0)
- plot(ma_slow, title="MA Slow", color=blue, linewidth=2, transp=0)
- // QQE exit from Thresh Hold Channel
- 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)
- 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)
- // QQE crosses
- 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)
- 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)
- // Signal crosses zero line
- 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)
- 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)
- // Exit ThreshHold Channel
- plotshape(buy[shunt]==1, title="QQE BUY", style=shape.arrowup, location=location.belowbar, text="BUY", color=lime, textcolor=green, transp=0, size=size.small)
- plotshape(sell[shunt]==1, title="QQE SELL", style=shape.arrowdown, location=location.abovebar, text="SELL", color=red, textcolor=maroon, transp=0, size=size.small)
- // - PLOTTING END
- // - ALERTING
- // can alert just BUY/SELL or all crosses
- c_alert = (buy==1 or sell==1) or (sall and (QQExshort or QQExlong or QQEzshort or QQEzlong))
- alertcondition(c_alert, title="QQEX Alert", message="QQEX Alert")
- alertcondition((QQEclong==1 or QQEcshort==1), title="QQEX XC Alert", message="QQEX XC Alert")
- alertcondition((QQExlong or QQExshort), title="QQEX XQ Alert", message="QQEX XQ Alert")
- alertcondition((QQEzlong or QQEzshort), title="QQEX XZ Alert", message="QQEX XZ Alert")
- //
- // show only when alert condition is met and bar closed.
- 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)
- //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
- //alertcondition(t_alert, title="[UL]QQEX Trend Alert", message="[UL]QQEX Trend Alert")
- //plotshape(t_alert[1],title= "Trend Alert Completed", location=location.bottom, color=blue, transp=0, style=shape.circle,size=size.auto,offset=-1)
- // - ALERTING END
- // ===============================================================
- // - STATISTICS
- // Generate bar by bar stats
- // This idea was inspired by "Binary option trading by two previous bars" by radixvinni
- //
- // Inputs
- //ssuc = input(true,title="Highlight Successfull & Failed Bars")
- //nc = input(3,minval=1,title="Number of Candles in trade")
- //
- // Find alert bars and check, trade completed ITM or not
- //alert_bar = (buy[nc]==1 or sell[nc]==1)
- //correct = (buy[nc]==1 and (close > close[nc])) or (sell[nc]==1 and (close < close[nc]))
- //
- // Show end of trade bar Success(Yellow) or Failure(Black)
- //bcolor = alert_bar and correct? yellow: alert_bar? black: na
- //barcolor(ssuc?bcolor:na)
- //
- // Count Successes and failuers
- //yellow_bar = (alert_bar and correct)?1:0
- //black_bar = (alert_bar and not correct)?1:0
- //all_bar = (close>=open)?1:1
- //
- // Calculate the simple stats
- //total_bars = cum(all_bar)
- //total_yellow_bars = cum(yellow_bar)
- //total_black_bars = cum(black_bar)
- //total_trades = total_yellow_bars + total_black_bars
- //success_rate = total_trades>0? 100.0*total_yellow_bars/total_trades: 0
- //
- // Plot dummy shapes, to allow numbers to be displayed in two numbers in format line of indicator
- //plotshape(success_rate,"success rate",location=location.bottom, color=bcolor, transp=0, style=shape.triangleup,size=size.auto)
- //plotshape(total_trades,"trades made",location=location.bottom, color=bcolor, transp=0, style=shape.triangleup,size=size.auto)
- //plotshape(total_bars,"total bars",location=location.bottom, color=bcolor, transp=0, style=shape.triangleup,size=size.auto)
- //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement