New 1
New 1
New 1
// CIRCLES:
// - LITTLE: They appear at all WaveTrend wave crossings
// - GREEN: The wavetrend waves are at the oversold level and have crossed up
(bullish)
// - RED: The wavetrend waves are at the overbought level and have crossed down
(bearish)
// - PURPLE: Appear when a bullish or bearish divergence is formed and WaveTrend
waves crosses at overbought and oversold points
// - GOLD: When RSI is below 20, WaveTrend waves are below or equal to -80 and
have crossed up (DONT BUY WHEN GOLD CIRCLE APPEAR)
// - None of these circles are certain signs to trade. It is only information
that can help you.
//
// I am not an expert trader or know how to program pine script as such, in fact
it is my first indicator only to study and all the code is copied and modified from
other codes that are published in TradingView.
// I am very grateful to the entire TV community that publishes codes so that
other newbies like me can learn and present their results. This is an attempt to
imitate Market Cipher B.
study(title="Cipher_B", shorttitle="Cipher_B")
// 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
// MA Selector
ma(matype, src, length) =>
if matype == "RMA"
rma(src, length)
else
if matype == "SMA"
sma(src, length)
else
if matype == "EMA"
ema(src, length)
else
if matype == "WMA"
wma(src, length)
else
if matype == "VWMA"
vwma(src, length)
else
src
// } FUNCTIONS
// PARAMETERS {
// WaveTrend MA Params
wtMA = input(defval="EMA", title="WT MA Type", options=["RMA", "SMA", "EMA",
"WMA"])
wtMA1 = input(defval="EMA", title="WT MA Type 1", options=["RMA", "SMA", "EMA",
"WMA"])
wtMA2 = input(defval="EMA", title="WT MA Type 2", options=["RMA", "SMA", "EMA",
"WMA"])
wtMA3 = input(defval="SMA", title="WT MA Type 3", options=["RMA", "SMA", "EMA",
"WMA"])
// WaveTrend MA Source
ap = input(ohlc4, "WaveTrend MA Source")
// WaveTrend MA Length
sp = input(3, "WaveTrend MA Length")
// RSI+MFI Period
rsiMFIperiod = input(60, "RSI+MFI Period")
MFRSIMA = input(defval="SMA", title="MFRSIMA", options=["RMA", "SMA", "EMA", "WMA",
"VWMA"])
// Colors
colorRed = #ff0000
colorPurple = #da00ff
colorGreen = #03ff00
colorOrange = color.orange
colorWT1 = #8ec7fb
colorWT2 = #1353ac
// Divergence WT
WTShowDiv = input(true, 'Show WT Divergences')
WTDivOBLevel = input(35, title="WT Bearish Divergence min")
WTDivOSLevel = input(-65, title="WT Bullish Divergence min")
// Divergence RSI
RSIShowDiv = input(false, 'Show RSI Divergences')
RSIDivOBLevel = input(60)
RSIDivOSLevel = input(30)
// RSI Levels
RSIOversold = input(30, "RSI Oversold", input.integer, minval=50, maxval=100)
RSIOverbought = input(60, "RSI Overbought", input.integer, minval=0, maxval=50)
// } PARAMETERS
// CALCULATE INDICATORS {
// RSI
up = rma(max(change(close), 0), 14)
down = rma(-min(change(close), 0), 14)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
rsiColor = rsi <= RSIOversold ? color.green : rsi >= RSIOverbought ? color.red :
color.purple
// Calculates WaveTrend
esa = ma(wtMA, ap, n1)
de = ma(wtMA1, abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * de)
tci = ma(wtMA2, ci, n2)
wt1 = tci
wt2 = ma(wtMA3, wt1, sp)
// VWAP
vwap_area = wt1 - wt2
// WaveTrend Conditions
WTCross = cross(wt1, wt2)
WTCrossUp = wt2 - wt1 <= 0
// WT Divergence
WTFractal_top = f_fractalize(wt2) > 0 and wt2[2] >= WTDivOBLevel ? wt2[2] : na
WTFractal_bot = f_fractalize(wt2) < 0 and wt2[2] <= WTDivOSLevel ? wt2[2] : na
bearWTSignal = WTFractal_top and high[2] > WTHigh_price and wt2[2] < WTHigh_prev
bullWTSignal = WTFractal_bot and low[2] < WTLow_price and wt2[2] > WTLow_prev
// RSI Divergence
RSIFractal_top = f_fractalize(rsi) > 0 and rsi >= RSIDivOBLevel ? rsi[2] : na
RSIFractal_bot = f_fractalize(rsi) < 0 and rsi <= RSIDivOSLevel ? rsi[2] : na
RSIHigh_prev = valuewhen(RSIFractal_top, rsi[2], 0)[2]
RSIHigh_price = valuewhen(RSIFractal_top, high[2], 0)[2]
RSILow_prev = valuewhen(RSIFractal_bot, rsi[2], 0)[2]
RSILow_price = valuewhen(RSIFractal_bot, low[2], 0)[2]
// Buy signal.
buySignal = WTCross and WTCrossUp and WTOverSold
divBuySignal = WTCross_last and WTCrossUp_last and ((WTShowDiv ? bullWTSignal :
false) or (RSIShowDiv ? bullRSISignal : false))
buySignalColor = buySignal ? color.new(colorGreen, 65) : na
// Sell signal
sellSignal = WTCross and WTCrossDown and WTOverBought
divSellSignal = WTCross_last and WTCrossDown_last and (bearWTSignal)
sellSignalColor = sellSignal ? color.new(colorRed, 65) : na
// Gold Buy
plotWTGoldBuy = WTCrossUp_last and WTGoldBuy
// } CALCULATE INDICATORS
// DRAW {
// 0 Line
plot(0, title="0 Line", color=color.gray)
// Divergences
plot(series = WTFractal_top and WTShowDiv ? wt2[2] : na, title='WT Bearish
Divergence', color=WTCol1, linewidth=2, transp=65, offset=-2)
plot(series = WTFractal_bot and WTShowDiv ? wt2[2] : na, title='WT Bullish
Divergence', color=WTCol2, linewidth=2, transp=65, offset=-2)
plot(series = RSIFractal_top and RSIShowDiv ? rsi[2] : na, title='RSI Bearish
Divergence', color=RSICol1, linewidth=1, transp=65, offset=-2)
plot(series = RSIFractal_bot and RSIShowDiv? rsi[2] : na, title='RSI Bullish
Divergence', color=RSICol2, linewidth=1, transp=65, offset=-2)
// RSI
plot(rsi, title="RSI", color=rsiColor, linewidth=1, transp=35)
// WT Area 1
plot(wt1, style=plot.style_area, title="WT Wave 1", color=colorWT1, transp=0)
// WT Area 2
plot(wt2, style=plot.style_area, title="WT Wave 2", color=colorWT2, transp=10)
// VWAP
plot(vwap_area, title="VWAP", color=color.yellow, style=plot.style_area, transp=35)
// Circles
plot(WTCross ? wt2 : na, title="Buy and sell signals", color=signalColor,
style=plot.style_circles, linewidth=3, transp=35) // Small circles
// } DRAW
// ALERTS {
// BUY
alertcondition(buySignal != 0, "Buy Signal (Big green circle)", "Green circle
WaveTrend Oversold")
alertcondition(divBuySignal != 0, "Buy Signal (Big green circle + Div)", "Buy
signal & WT Bullish Divergence & WT Overbought ")
alertcondition(plotWTGoldBuy != 0, "GOLD Buy Signal (Big GOLDEN circle)", "Green &
GOLD circle WaveTrend Overbought")
// SELL
alertcondition(sellSignal != 0, "Sell Signal (Big red circle)", "Red Circle
WaveTrend Overbought")
alertcondition(divSellSignal != 0, "Sell Signal (Big red circle + Div)", "Buy
signal & WT Bearish Divergence & WT Overbought ")
// } ALERTS