//@version=6 // Cipher Wave Lite // Credits: the WaveTrend Oscillator formula is by LazyBear ("WaveTrend Oscillator [WT]", // open source on TradingView); re-implemented in this script, not copied. // For chart reading only. Not financial advice: no dot, line or diamond is a guarantee of profit. // Trading leveraged products carries a high risk of loss. // License: Mozilla Public License 2.0 (TradingView's default for open-source scripts). indicator("Cipher Wave Lite", shorttitle = "Cipher Wave Lite", overlay = false, max_labels_count = 500, max_lines_count = 500) // ---------- Inputs ---------- G_W = "Waves (WaveTrend)" wtCh = input.int(9, "Channel length", minval = 1, group = G_W) wtAvg = input.int(12, "Average length", minval = 1, group = G_W) wtMa = input.int(3, "Wave 2 = SMA of wave 1", minval = 1, group = G_W) obL1 = input.float(53, "Overbought 1 (red dot zone)", group = G_W) obL2 = input.float(60, "Overbought 2", group = G_W) osL1 = input.float(-53, "Oversold 1 (green dot zone)", group = G_W) osL2 = input.float(-60, "Oversold 2", group = G_W) showVw = input.bool(true, "VWAP wave (wave 1 - wave 2)", group = G_W) cW1 = input.color(#84B1DB, "Wave 1", group = G_W, inline = "wc") cW2 = input.color(#224293, "Wave 2", group = G_W, inline = "wc") cVw = input.color(#FFEB3B, "VWAP", group = G_W, inline = "wc") wTr1 = input.int(20, "Wave 1 transparency", minval = 0, maxval = 100, group = G_W) wTr2 = input.int(24, "Wave 2 transparency", minval = 0, maxval = 100, group = G_W) G_D = "Dots" showDots = input.bool(true, "Small green / red dots (wave 1 crosses wave 2 inside the oversold / overbought zone)", group = G_D) cBuy = input.color(#3FFF00, "Green dot", group = G_D, inline = "dc") cSell = input.color(#FF1744, "Red dot", group = G_D, inline = "dc") G_V = "Divergences" showDv = input.bool(true, "Divergences: line peak to peak on the waves + diamond above / below the waves", group = G_V) dvLook = input.int(60, "Compare with the wave swings of the last N bars", minval = 5, group = G_V) dvRight = input.int(1, "Confirm the wave turn after N closed bars (1 = fast, 2 = slower, fewer marks)", minval = 1, maxval = 2, group = G_V) dvStruct = input.bool(true, "Compare only with the swings after the window's major opposite swing (structure)", group = G_V) dvKeep = input.int(10, "Keep the last N divergences of each side on the chart", minval = 1, maxval = 100, group = G_V) dvPt = input.int(16, "Diamond size (points)", minval = 2, maxval = 30, group = G_V) cDvBull = input.color(#E2A400, "Bullish divergence", group = G_V, inline = "vc") cDvBear = input.color(#B44CFF, "Bearish divergence", group = G_V, inline = "vc") // ---------- WaveTrend (LazyBear formula) ---------- wvSrc = hlc3 wvBasis = ta.ema(wvSrc, wtCh) wvDev = ta.ema(math.abs(wvSrc - wvBasis), wtCh) wvNorm = wvDev == 0 ? 0.0 : (wvSrc - wvBasis) / (0.015 * wvDev) wave1 = ta.ema(wvNorm, wtAvg) wave2 = ta.sma(wave1, wtMa) wtVw = wave1 - wave2 // ---------- Dots ---------- crossW = ta.cross(wave1, wave2) buyDot = crossW and wave1 > wave2 and wave2 <= osL1 sellDot = crossW and wave1 < wave2 and wave2 >= obL1 // ---------- Divergences ---------- DV_EDGE = 110.0 // Price extreme of the last n bars (n >= 2) and how many bars ago it was. dvExt(bool top, int n) => float px = top ? high[n - 1] : low[n - 1] int ago = n - 1 for k = n - 2 to 0 v = top ? high[k] : low[k] if top ? v > px : v < px px := v ago := k [px, ago] // Index of the most extreme price swing from index j0 on (the latest one wins a tie). dvRef(array ps, bool top, int j0) => int r = j0 if ps.size() > j0 + 1 for k = j0 + 1 to ps.size() - 1 if top ? ps.get(k) >= ps.get(r) : ps.get(k) <= ps.get(r) r := k r // First swing index to compare with: with the structure rule on, only swings after the // most extreme opposite swing of the window (for tops: after the lowest bottom). dvStart(array ops, array obs, array bs, int wb, bool top) => int j = 0 if dvStruct and ops.size() > 0 int mo = -1 for k = 0 to ops.size() - 1 if obs.get(k) >= wb - dvLook if mo < 0 or (top ? ops.get(k) <= ops.get(mo) : ops.get(k) >= ops.get(mo)) mo := k if mo >= 0 j := bs.size() if bs.size() > 0 for k = bs.size() - 1 to 0 if bs.get(k) > obs.get(mo) j := k j var array dvTopL = array.new() var array