//@version=5 strategy("2nd Strategy", overlay=true) // VMC Cipher_B_Divergences { // PARAMETERS { // WaveTrend a101 = input.bool(false, "=============== VMC CIPHER_B SETTINGS ===============") wtChannelLen = input(9, title='WT Channel Length') wtAverageLen = input(12, title='WT Average Length') wtMASource = input(hlc3, title='WT MA Source') wtMALen = input(3, title='WT MA Length') // WaveTrend Overbought & Oversold lines obLevel = input(53, title='WT Overbought Level 1') obLevel2 = input(60, title='WT Overbought Level 2') obLevel3 = input(100, title='WT Overbought Level 3') osLevel = input(-53, title='WT Oversold Level 1') osLevel2 = input(-60, title='WT Oversold Level 2') osLevel3 = input(-75, title='WT Oversold Level 3') // Divergence WT showHiddenDiv_nl = input(true, title='Not apply OB/OS Limits on Hidden Divergences') wtDivOBLevel = input(45, title='WT Bearish Divergence min') wtDivOSLevel = input(-65, title='WT Bullish Divergence min') // Divergence extra range wtDivOBLevel_add = input(15, title='WT 2nd Bearish Divergence') wtDivOSLevel_add = input(-40, title='WT 2nd Bullish Divergence 15 min') // RSI+MFI rsiMFIperiod = input(60, title='MFI Period') rsiMFIMultiplier = input.float(150, title='MFI Area multiplier') rsiMFIPosY = input(2.5, title='MFI Area Y Pos') // RSI rsiSRC = input(close, title='RSI Source') rsiLen = input(14, title='RSI Length') rsiOversold = input.int(30, title='RSI Oversold', minval=30, maxval=100) rsiOverbought = input.int(60, title='RSI Overbought', minval=0, maxval=60) // Divergence RSI rsiDivOBLevel = input(60, title='RSI Bearish Divergence min') rsiDivOSLevel = input(30, title='RSI Bullish Divergence min') // RSI Stochastic stochUseLog = input(true, title=' Use Log?') stochAvg = input(false, title='Use Average of both K & D') stochSRC = input(close, title='Stochastic RSI Source') stochLen = input(14, title='Stochastic RSI Length') stochRsiLen = input(14, title='RSI Length ') stochKSmooth = input(3, title='Stochastic RSI K Smooth') stochDSmooth = input(3, title='Stochastic RSI D Smooth') // Schaff Trend Cycle tcSRC = input(close, title='Schaff TC Source') tclength = input(10, title='Schaff TC') tcfastLength = input(23, title='Schaff TC Fast Lenght') tcslowLength = input(50, title='Schaff TC Slow Length') tcfactor = input(0.5, title='Schaff TC Factor') // Sommi Flag sommiVwapTF = input('720', title='Sommi F. Wave timeframe') sommiVwapBearLevel = input(0, title='F. Wave Bear Level (less than)') sommiVwapBullLevel = input(0, title='F. Wave Bull Level (more than)') soomiFlagWTBearLevel = input(0, title='WT Bear Level (more than)') soomiFlagWTBullLevel = input(0, title='WT Bull Level (less than)') soomiRSIMFIBearLevel = input(0, title='Money flow Bear Level (less than)') soomiRSIMFIBullLevel = input(0, title='Money flow Bull Level (more than)') // Sommi Diamond sommiHTCRes = input('60', title='HTF Candle Res. 1') sommiHTCRes2 = input('240', title='HTF Candle Res. 2') soomiDiamondWTBearLevel = input(0, title='WT Bear Level (More than)') soomiDiamondWTBullLevel = input(0, title='WT Bull Level (Less than)') // macd Colors macdWTColorsTF = input('240', title='MACD Colors MACD TF') // Colors colorRed = #ff0000 colorPurple = #e600e6 colorGreen = #3fff00 colorOrange = #e2a400 colorYellow = #ffe500 colorWhite = #ffffff colorPink = #ff00f0 colorBluelight = #31c0ff colorWT1 = #90caf9 colorWT2 = #0d47a1 colorWT2_ = #131722 colormacdWT1a = #4caf58 colormacdWT1b = #af4c4c colormacdWT1c = #7ee57e colormacdWT1d = #ff3535 colormacdWT2a = #305630 colormacdWT2b = #310101 colormacdWT2c = #132213 colormacdWT2d = #770000 // } PARAMETERS // FUNCTIONS { // Divergences f_top_fractal(src) => src[4] < src[2] and src[3] < src[2] and src[2] > src[1] and src[2] > src[0] f_bot_fractal(src) => src[4] > src[2] and src[3] > src[2] and src[2] < src[1] and src[2] < src[0] f_fractalize(src) => f_top_fractal(src) ? 1 : f_bot_fractal(src) ? -1 : 0 f_findDivs(src, topLimit, botLimit, useLimits) => fractalTop = f_fractalize(src) > 0 and (useLimits ? src[2] >= topLimit : true) ? src[2] : na fractalBot = f_fractalize(src) < 0 and (useLimits ? src[2] <= botLimit : true) ? src[2] : na highPrev = ta.valuewhen(fractalTop, src[2], 0)[2] highPrice = ta.valuewhen(fractalTop, high[2], 0)[2] lowPrev = ta.valuewhen(fractalBot, src[2], 0)[2] lowPrice = ta.valuewhen(fractalBot, low[2], 0)[2] bearSignal = fractalTop and high[2] > highPrice and src[2] < highPrev bullSignal = fractalBot and low[2] < lowPrice and src[2] > lowPrev bearDivHidden = fractalTop and high[2] < highPrice and src[2] > highPrev bullDivHidden = fractalBot and low[2] > lowPrice and src[2] < lowPrev [fractalTop, fractalBot, lowPrev, bearSignal, bullSignal, bearDivHidden, bullDivHidden] // RSI+MFI f_rsimfi(_period, _multiplier, _tf) => request.security(syminfo.tickerid, _tf, ta.sma((close - open) / (high - low) * _multiplier, _period) - rsiMFIPosY) // WaveTrend f_wavetrend(src, chlen, avg, malen, tf) => tfsrc = request.security(syminfo.tickerid, tf, src) esa = ta.ema(tfsrc, chlen) de = ta.ema(math.abs(tfsrc - esa), chlen) ci = (tfsrc - esa) / (0.015 * de) wt1 = request.security(syminfo.tickerid, tf, ta.ema(ci, avg)) wt2 = request.security(syminfo.tickerid, tf, ta.sma(wt1, malen)) wtVwap = wt1 - wt2 wtOversold = wt2 <= osLevel wtOverbought = wt2 >= obLevel wtCross = ta.cross(wt1, wt2) wtCrossUp = wt2 - wt1 <= 0 wtCrossDown = wt2 - wt1 >= 0 wtCrosslast = ta.cross(wt1[2], wt2[2]) wtCrossUplast = wt2[2] - wt1[2] <= 0 wtCrossDownlast = wt2[2] - wt1[2] >= 0 [wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCrosslast, wtCrossUplast, wtCrossDownlast, wtVwap] // Schaff Trend Cycle f_tc(src, length, fastLength, slowLength) => ema1 = ta.ema(src, fastLength) ema2 = ta.ema(src, slowLength) macdVal = ema1 - ema2 alpha = ta.lowest(macdVal, length) beta = ta.highest(macdVal, length) - alpha gamma = (macdVal - alpha) / beta * 100 gamma := beta > 0 ? gamma : nz(gamma[1]) delta = gamma delta := na(delta[1]) ? delta : delta[1] + tcfactor * (gamma - delta[1]) epsilon = ta.lowest(delta, length) zeta = ta.highest(delta, length) - epsilon eta = (delta - epsilon) / zeta * 100 eta := zeta > 0 ? eta : nz(eta[1]) stcReturn = eta stcReturn := na(stcReturn[1]) ? stcReturn : stcReturn[1] + tcfactor * (eta - stcReturn[1]) stcReturn // Stochastic RSI f_stochrsi(_src, _stochlen, _rsilen, _smoothk, _smoothd, _log, _avg) => src = _log ? math.log(_src) : _src rsi = ta.rsi(src, _rsilen) kk = ta.sma(ta.stoch(rsi, rsi, rsi, _stochlen), _smoothk) d1 = ta.sma(kk, _smoothd) avg_1 = math.avg(kk, d1) k = _avg ? avg_1 : kk [k, d1] // MACD f_macd(src, fastlen, slowlen, sigsmooth, tf) => fast_ma = request.security(syminfo.tickerid, tf, ta.ema(src, fastlen)) slow_ma = request.security(syminfo.tickerid, tf, ta.ema(src, slowlen)) macd = fast_ma - slow_ma signal = request.security(syminfo.tickerid, tf, ta.sma(macd, sigsmooth)) hist = macd - signal [macd, signal, hist] // MACD Colors on WT f_macdWTColors(tf) => hrsimfi = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, tf) [macd, signal, hist] = f_macd(close, 28, 42, 9, macdWTColorsTF) macdup = macd >= signal macddown = macd <= signal macdWT1Color = macdup ? hrsimfi > 0 ? colormacdWT1c : colormacdWT1a : macddown ? hrsimfi < 0 ? colormacdWT1d : colormacdWT1b : na macdWT2Color = macdup ? hrsimfi < 0 ? colormacdWT2c : colormacdWT2a : macddown ? hrsimfi < 0 ? colormacdWT2d : colormacdWT2b : na [macdWT1Color, macdWT2Color] // Get higher timeframe candle f_getTFCandle(_tf) => _open = request.security(ticker.heikinashi(syminfo.tickerid), _tf, open, barmerge.gaps_off, barmerge.lookahead_on) _close = request.security(ticker.heikinashi(syminfo.tickerid), _tf, close, barmerge.gaps_off, barmerge.lookahead_on) _high = request.security(ticker.heikinashi(syminfo.tickerid), _tf, high, barmerge.gaps_off, barmerge.lookahead_on) _low = request.security(ticker.heikinashi(syminfo.tickerid), _tf, low, barmerge.gaps_off, barmerge.lookahead_on) hl21 = (_high + _low) / 2.0 newBar = ta.change(_open) candleBodyDir = _close > _open [candleBodyDir, newBar] // Sommi flag f_findSommiFlag(tf, wt1, wt2, rsimfi, wtCross, wtCrossUp, wtCrossDown) => [hwt1, hwt2, hwtOversold, hwtOverbought, hwtCross, hwtCrossUp, hwtCrossDown, hwtCrosslast, hwtCrossUplast, hwtCrossDownlast, hwtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, tf) bearPattern = rsimfi < soomiRSIMFIBearLevel and wt2 > soomiFlagWTBearLevel and wtCross and wtCrossDown and hwtVwap < sommiVwapBearLevel bullPattern = rsimfi > soomiRSIMFIBullLevel and wt2 < soomiFlagWTBullLevel and wtCross and wtCrossUp and hwtVwap > sommiVwapBullLevel [bearPattern, bullPattern, hwtVwap] f_findSommiDiamond(tf, tf2, wt1, wt2, wtCross, wtCrossUp, wtCrossDown) => [candleBodyDir, newBar] = f_getTFCandle(tf) [candleBodyDir2, newBar2] = f_getTFCandle(tf2) bearPattern = wt2 >= soomiDiamondWTBearLevel and wtCross and wtCrossDown and not candleBodyDir and not candleBodyDir2 bullPattern = wt2 <= soomiDiamondWTBullLevel and wtCross and wtCrossUp and candleBodyDir and candleBodyDir2 [bearPattern, bullPattern] // } FUNCTIONS // CALCULATE INDICATORS { // RSI rsi = ta.rsi(rsiSRC, rsiLen) rsiColor = rsi <= rsiOversold ? colorGreen : rsi >= rsiOverbought ? colorRed : colorPurple // RSI + MFI Area rsiMFI = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, timeframe.period) rsiMFIColor = rsiMFI > 0 ? #3ee145 : #ff3d2e // Calculates WaveTrend [wt1_1, wt2_1, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last, wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period) // Stochastic RSI [stochK, stochD] = f_stochrsi(stochSRC, stochLen, stochRsiLen, stochKSmooth, stochDSmooth, stochUseLog, stochAvg) // Schaff Trend Cycle tcVal = f_tc(tcSRC, tclength, tcfastLength, tcslowLength) // Sommi flag [sommiBearish, sommiBullish, hvwap] = f_findSommiFlag(sommiVwapTF, wt1_1, wt2_1, rsiMFI, wtCross, wtCrossUp, wtCrossDown) //Sommi diamond [sommiBearishDiamond, sommiBullishDiamond] = f_findSommiDiamond(sommiHTCRes, sommiHTCRes2, wt1_1, wt2_1, wtCross, wtCrossUp, wtCrossDown) // macd colors [macdWT1Color, macdWT2Color] = f_macdWTColors(macdWTColorsTF) // WT Divergences [wtFractalTop, wtFractalBot, wtLow_prev, wtBearDiv, wtBullDiv, wtBearDivHidden, wtBullDivHidden] = f_findDivs(wt2_1, wtDivOBLevel, wtDivOSLevel, true) [wtFractalTop_add, wtFractalBot_add, wtLow_prev_add, wtBearDiv_add, wtBullDiv_add, wtBearDivHidden_add, wtBullDivHidden_add] = f_findDivs(wt2_1, wtDivOBLevel_add, wtDivOSLevel_add, true) [wtFractalTop_nl, wtFractalBot_nl, wtLow_prev_nl, wtBearDiv_nl, wtBullDiv_nl, wtBearDivHidden_nl, wtBullDivHidden_nl] = f_findDivs(wt2_1, 0, 0, false) wtBearDivHidden_ = showHiddenDiv_nl ? wtBearDivHidden_nl : wtBearDivHidden wtBullDivHidden_ = showHiddenDiv_nl ? wtBullDivHidden_nl : wtBullDivHidden wtBearDivColor = wtBearDiv and wtBearDivHidden_ ? colorRed : na wtBullDivColor = wtBullDiv and wtBullDivHidden_ ? colorGreen : na wtBearDivColor_add = wtBearDiv_add and wtBearDivHidden_add ? #9a0202 : na wtBullDivColor_add = wtBullDiv_add and wtBullDivHidden_add ? #1b5e20 : na // RSI Divergences [rsiFractalTop, rsiFractalBot, rsiLow_prev, rsiBearDiv, rsiBullDiv, rsiBearDivHidden, rsiBullDivHidden] = f_findDivs(rsi, rsiDivOBLevel, rsiDivOSLevel, true) [rsiFractalTop_nl, rsiFractalBot_nl, rsiLow_prev_nl, rsiBearDiv_nl, rsiBullDiv_nl, rsiBearDivHidden_nl, rsiBullDivHidden_nl] = f_findDivs(rsi, 0, 0, false) rsiBearDivHidden_ = showHiddenDiv_nl ? rsiBearDivHidden_nl : rsiBearDivHidden rsiBullDivHidden_ = showHiddenDiv_nl ? rsiBullDivHidden_nl : rsiBullDivHidden rsiBearDivColor = rsiBearDiv and rsiBearDivHidden_ ? colorRed : na rsiBullDivColor = rsiBullDiv and rsiBullDivHidden_ ? colorGreen : na // Stoch Divergences [stochFractalTop, stochFractalBot, stochLow_prev, stochBearDiv, stochBullDiv, stochBearDivHidden, stochBullDivHidden] = f_findDivs(stochK, 0, 0, false) stochBearDivColor = stochBearDiv and stochBearDivHidden ? colorRed : na stochBullDivColor = stochBullDiv and stochBullDivHidden ? colorGreen : na // Small Circles WT Cross signalColor = wt2_1 - wt1_1 > 0 ? color.red : color.lime // Buy signal. buySignal = wtCross and wtCrossUp and wtOversold buySignalDiv = wtBullDiv and wtBullDiv_add and stochBullDiv and rsiBullDiv buySignalDiv_color = wtBullDiv ? colorGreen : wtBullDiv_add ? color.new(colorGreen, 60) : true ? colorGreen : na // Sell signal sellSignal = wtCross and wtCrossDown and wtOverbought sellSignalDiv = wtBearDiv and wtBearDiv_add and stochBearDiv and rsiBearDiv sellSignalDiv_color = wtBearDiv ? colorRed : wtBearDiv_add ? color.new(colorRed, 60) : rsiBearDiv ? colorRed : na // Gold Buy lastRsi = ta.valuewhen(wtFractalBot, rsi[2], 0)[2] wtGoldBuy = (wtBullDiv and rsiBullDiv) and wtLow_prev <= osLevel3 and wt2_1 > osLevel3 and wtLow_prev - wt2_1 <= -5 and lastRsi < 30 // } CALCULATE INDICATORS // } // QQE MT4 { a102 = input.bool(false, "=============== QQE4 MT4 SETTINGS ===============") RSI_Period = input(14, title='RSI') SF = input(5, title='Slow Factor') QQE = input(4.236) Wilders_Period = RSI_Period * 2 - 1 Rsi = ta.rsi(close, RSI_Period) RsiMa = ta.ema(Rsi, SF) AtrRsi = math.abs(RsiMa[1] - RsiMa) MaAtrRsi = ta.ema(AtrRsi, Wilders_Period) dar = ta.ema(MaAtrRsi, Wilders_Period) * QQE DeltaFastAtrRsi = dar RSIndex = RsiMa newshortband = RSIndex + DeltaFastAtrRsi newlongband = RSIndex - DeltaFastAtrRsi longband = float(na) longband := RSIndex[1] > longband[1] and RSIndex > longband[1] ? math.max(longband[1], newlongband) : newlongband shortband = float(na) shortband := RSIndex[1] < shortband[1] and RSIndex < shortband[1] ? math.min(shortband[1], newshortband) : newshortband trend = int(na) cross_1 = ta.cross(longband[1], RSIndex) trend := ta.cross(RSIndex, shortband[1]) ? 1 : cross_1 ? -1 : nz(trend[1], 1) FastAtrRsiTL = trend == 1 ? longband : shortband // } // EMA { a103 = input.bool(false, "=============== EMA SETTINGS ===============") ema_length = input.int(144, "EMA Length", minval = 1) ema = ta.ema(close, ema_length) // } // Strategy { wtCon = ta.crossover(wt1_1, wt2_1) and wt2_1 < 0 wtConS = ta.crossunder(wt1_1, wt2_1) and wt2_1 > 0 buy = close > ema and (wtCon or wtCon[1] or wtCon[2] or wtCon[3]) and ta.crossover(RsiMa, FastAtrRsiTL) sell = close < ema and (wtConS or wtConS[1] or wtConS[2] or wtConS[3]) and ta.crossunder(RsiMa, FastAtrRsiTL) a104 = input.bool(false, "=============== STRATEGY SETTINGS ===============") flipSignals = input.bool(false, "Flip Signals") temporaryBool = buy buy := (flipSignals) ? sell : buy sell := (flipSignals) ? temporaryBool : sell tpVal = input.float(2.0, "Take Profit", minval = 0.0001, group = "Strategy Settings") / 100 slVal = input.float(2.0, "Stop Loss", minval = 0.0001, group = "Strategy Settings") / 100 longEntryAlertMessage = input('Long {{ticker}}!', 'Long Entry Alert: ', group = "Alert Settings") shortEntryAlertMessage = input('Short {{ticker}}!', 'Short Entry Alert: ', group = "Alert Settings") longExitAlertMessage = input('Exit Long {{ticker}}!', 'Long Exit Alert: ', group = "Alert Settings") shortExitAlertMessage = input('Exit Short {{ticker}}!', 'Short Exit Alert: ', group = "Alert Settings") tpLong = ta.valuewhen(buy and not buy[1] and (strategy.position_size[1] <= 0 or strategy.position_size == 0), close * (1 + tpVal), 0) slLong = ta.valuewhen(buy and not buy[1] and (strategy.position_size[1] <= 0 or strategy.position_size == 0), close * (1 - slVal), 0) tpShort = ta.valuewhen(sell and not sell[1] and (strategy.position_size[1] >= 0 or strategy.position_size == 0), close * (1 - tpVal), 0) slShort = ta.valuewhen(sell and not sell[1] and (strategy.position_size[1] >= 0 or strategy.position_size == 0), close * (1 + slVal), 0) if buy and strategy.position_size == 0 strategy.entry("Long", strategy.long, alert_message = longEntryAlertMessage) if strategy.position_size > 0 strategy.exit("Close Long", limit = tpLong, stop = slLong, comment_profit = "TP Long", comment_loss = "SL Long", alert_message = longExitAlertMessage) if sell and strategy.position_size == 0 strategy.entry("Short", strategy.short, alert_message = shortEntryAlertMessage) if strategy.position_size < 0 strategy.exit("Close Short", limit = tpShort, stop = slShort, comment_profit = "TP Short", comment_loss = "SL Short", alert_message = shortExitAlertMessage) l1 = plot(strategy.position_size > 0 ? tpLong : na, "TP Long", color.rgb(0,255,0,0), style = plot.style_linebr) l2 = plot(strategy.position_size > 0 ? slLong : na, "SL Long", color.rgb(255,0,0,0), style = plot.style_linebr) l3 = plot(strategy.position_size > 0 ? strategy.position_avg_price : na, "Entry Long", color.white, style = plot.style_linebr) fill(l3,l2, color = color.rgb(255,0,0,90), title = "Background SL Long") fill(l3,l1, color = color.rgb(0,255,0,90), title = "Background TP Long") s1 = plot(strategy.position_size < 0 ? tpShort : na, "TP Short", color.rgb(0,255,0,0), style = plot.style_linebr) s2 = plot(strategy.position_size < 0 ? slShort : na, "SL Short", color.rgb(255,0,0,0), style = plot.style_linebr) s3 = plot(strategy.position_size < 0 ? strategy.position_avg_price : na, "Entry Short", color.white, style = plot.style_linebr) fill(s3,s2, color = color.rgb(255,0,0,90), title = "Background SL Short") fill(s3,s1, color = color.rgb(0,255,0,90), title = "Background TP Short") // }