// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SatoshisGh0st
//@version=4
study(title = 'SG Market Cipher B', shorttitle = 'SG Cipher')
// PARAMETERS {
// WaveTrend
wtShow = input(true, title = 'Show WaveTrend', type = input.bool, group = 'WaveTrend Settings')
wtBuyShow = input(true, title = 'Show Buy dots', type = input.bool, group = 'WaveTrend Settings')
wtGoldShow = input(true, title = 'Show Gold dots', type = input.bool, group = 'WaveTrend Settings')
wtSellShow = input(true, title = 'Show Sell dots', type = input.bool, group = 'WaveTrend Settings')
wtDivShow = input(true, title = 'Show Div. dots', type = input.bool, group = 'WaveTrend Settings')
vwapShow = input(true, title = 'Show Fast WT', type = input.bool, group = 'WaveTrend Settings')
wtChannelLen = input(9, title = 'WT Channel Length', type = input.integer, group = 'WaveTrend Settings')
wtAverageLen = input(12, title = 'WT Average Length', type = input.integer, group = 'WaveTrend Settings')
wtMASource = input(hlc3, title = 'WT MA Source', type = input.source, group = 'WaveTrend Settings')
wtMALen = input(3, title = 'WT MA Length', type = input.integer, group = 'WaveTrend Settings')
// WaveTrend Overbought & Oversold lines
obLevel = input(53, title = 'WT Overbought Level 1', type = input.integer, group = 'WaveTrend Settings')
obLevel2 = input(60, title = 'WT Overbought Level 2', type = input.integer, group = 'WaveTrend Settings')
obLevel3 = input(100, title = 'WT Overbought Level 3', type = input.integer, group = 'WaveTrend Settings')
osLevel = input(-53, title = 'WT Oversold Level 1', type = input.integer, group = 'WaveTrend Settings')
osLevel2 = input(-60, title = 'WT Oversold Level 2', type = input.integer, group = 'WaveTrend Settings')
osLevel3 = input(-75, title = 'WT Oversold Level 3', type = input.integer, group = 'WaveTrend Settings')
// Divergence WT
wtShowDiv = input(true, title = 'Show WT Regular Divergences', type = input.bool, group = 'WaveTrend Settings')
wtShowHiddenDiv = input(false, title = 'Show WT Hidden Divergences', type = input.bool, group = 'WaveTrend Settings')
showHiddenDiv_nl = input(true, title = 'Not apply OB/OS Limits on Hidden Divergences', type = input.bool, group = 'WaveTrend Settings')
wtDivOBLevel = input(45, title = 'WT Bearish Divergence min', type = input.integer, group = 'WaveTrend Settings')
wtDivOSLevel = input(-65, title = 'WT Bullish Divergence min', type = input.integer, group = 'WaveTrend Settings')
// Divergence extra range
wtDivOBLevel_addshow = input(true, title = 'Show 2nd WT Regular Divergences', type = input.bool, group = 'WaveTrend Settings')
wtDivOBLevel_add = input(15, title = 'WT 2nd Bearish Divergence', type = input.integer, group = 'WaveTrend Settings')
wtDivOSLevel_add = input(-40, title = 'WT 2nd Bullish Divergence 15 min', type = input.integer, group = 'WaveTrend Settings')
// RSI
rsiShow = input(true, title = 'Show RSI', type = input.bool, group = 'RSI Settings')
rsiSRC = input(close, title = 'RSI Source', type = input.source, group = 'RSI Settings')
rsiLen = input(14, title = 'RSI Length', type = input.integer, group = 'RSI Settings')
rsiOversold = input(30, title = 'RSI Oversold', minval = 50, maxval = 100, type = input.integer, group = 'RSI Settings')
rsiOverbought = input(60, title = 'RSI Overbought', minval = 0, maxval = 50, type = input.integer, group = 'RSI Settings')
// Divergence RSI
rsiShowDiv = input(false, title = 'Show RSI Regular Divergences', type = input.bool, group = 'RSI Settings')
rsiShowHiddenDiv = input(false, title = 'Show RSI Hidden Divergences', type = input.bool, group = 'RSI Settings')
rsiDivOBLevel = input(60, title = 'RSI Bearish Divergence min', type = input.integer, group = 'RSI Settings')
rsiDivOSLevel = input(30, title = 'RSI Bullish Divergence min', type = input.integer, group = 'RSI Settings')
// RSI Stochastic
stochShow = input(true, title = 'Show Stochastic RSI', type = input.bool, group = 'Stoch Settings')
stochUseLog = input(true, title=' Use Log?', type = input.bool, group = 'Stoch Settings')
stochAvg = input(false, title='Use Average of both K & D', type = input.bool, group = 'Stoch Settings')
stochSRC = input(close, title = 'Stochastic RSI Source', type = input.source, group = 'Stoch Settings')
stochLen = input(14, title = 'Stochastic RSI Length', type = input.integer, group = 'Stoch Settings')
stochRsiLen = input(14, title = 'RSI Length ', type = input.integer, group = 'Stoch Settings')
stochKSmooth = input(3, title = 'Stochastic RSI K Smooth', type = input.integer, group = 'Stoch Settings')
stochDSmooth = input(3, title = 'Stochastic RSI D Smooth', type = input.integer, group = 'Stoch Settings')
// Divergence stoch
stochShowDiv = input(false, title = 'Show Stoch Regular Divergences', type = input.bool, group = 'Stoch Settings')
stochShowHiddenDiv = input(false, title = 'Show Stoch Hidden Divergences', type = input.bool, group = 'Stoch Settings')
// Schaff Trend Cycle
tcLine = input(false, title="Show Schaff TC line", type=input.bool, group = 'Schaff Settings')
tcSRC = input(close, title = 'Schaff TC Source', type = input.source, group = 'Schaff Settings')
tclength = input(10, title="Schaff TC", type=input.integer, group = 'Schaff Settings')
tcfastLength = input(23, title="Schaff TC Fast Length", type=input.integer, group = 'Schaff Settings')
tcslowLength = input(50, title="Schaff TC Slow Length", type=input.integer, group = 'Schaff Settings')
tcfactor = input(0.5, title="Schaff TC Factor", type=input.float, group = 'Schaff Settings')
// Sommi Flag
sommiFlagShow = input(false, title = 'Show Sommi flag', type = input.bool, group = 'Sommi Settings')
sommiShowVwap = input(false, title = 'Show Sommi F. Wave', type = input.bool, group = 'Sommi Settings')
sommiVwapTF = input('720', title = 'Sommi F. Wave timeframe', type = input.string, group = 'Sommi Settings')
sommiVwapBearLevel = input(0, title = 'F. Wave Bear Level (less than)', type = input.integer, group = 'Sommi Settings')
sommiVwapBullLevel = input(0, title = 'F. Wave Bull Level (more than)', type = input.integer, group = 'Sommi Settings')
soomiFlagWTBearLevel = input(0, title = 'WT Bear Level (more than)', type = input.integer, group = 'Sommi Settings')
soomiFlagWTBullLevel = input(0, title = 'WT Bull Level (less than)', type = input.integer, group = 'Sommi Settings')
// Sommi Diamond
sommiDiamondShow = input(false, title = 'Show Sommi diamond', type = input.bool, group = 'Sommi Settings')
sommiHTCRes = input('60', title = 'HTF Candle Res. 1', type = input.string, group = 'Sommi Settings')
sommiHTCRes2 = input('240', title = 'HTF Candle Res. 2', type = input.string, group = 'Sommi Settings')
soomiDiamondWTBearLevel = input(0, title = 'WT Bear Level (More than)', type = input.integer, group = 'Sommi Settings')
soomiDiamondWTBullLevel = input(0, title = 'WT Bull Level (Less than)', type = input.integer, group = 'Sommi Settings')
// macd Colors
macdWTColorsShow = input(false, title = 'Show MACD Colors', type = input.bool, group = 'MACD Settings')
macdWTColorsTF = input('240', title = 'MACD Colors MACD TF', type = input.string, group = 'MACD Settings')
darkMode = input(false, title = 'DarkMode (Experimental)', type = input.bool)
// Colors
colorRed = #ff0000
colorPurple = #e600e6
colorGreen = #3fff00
colorOrange = #e2a400
colorYellow = #ffe500
colorWhite = #ffffff
colorPink = #ff00f0
colorBluelight = #31c0ff
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 = valuewhen(fractalTop, src[2], 0)[2]
highPrice = valuewhen(fractalTop, high[2], 0)[2]
lowPrev = valuewhen(fractalBot, src[2], 0)[2]
lowPrice = 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]
// Function to calculate WaveTrend
f_wavetrend(src, chlen, avg, malen, tf) =>
tfsrc = security(syminfo.tickerid, tf, src)
esa = ema(tfsrc, chlen)
de = ema(abs(tfsrc - esa), chlen)
ci = (tfsrc - esa) / (0.015 * de)
wt1 = security(syminfo.tickerid, tf, ema(ci, avg))
wt2 = security(syminfo.tickerid, tf, sma(wt1, malen))
wtVwap = wt1 - wt2
wtOversold = wt2 <= osLevel
wtOverbought = wt2 >= obLevel
wtCross = cross(wt1, wt2)
wtCrossUp = wt2 - wt1 <= 0
wtCrossDown = wt2 - wt1 >= 0
wtCrosslast = 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 = ema(src, fastLength)
ema2 = ema(src, slowLength)
macdVal = ema1 - ema2
alpha = lowest(macdVal, length)
beta = 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 = lowest(delta, length)
zeta = 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 ? log(_src) : _src
rsi = rsi(src, _rsilen)
kk = sma(stoch(rsi, rsi, rsi, _stochlen), _smoothk)
d1 = sma(kk, _smoothd)
avg_1 = avg(kk, d1)
k = _avg ? avg_1 : kk
[k, d1]
// MACD
f_macd(src, fastlen, slowlen, sigsmooth, tf) =>
fast_ma = security(syminfo.tickerid, tf, ema(src, fastlen))
slow_ma = security(syminfo.tickerid, tf, ema(src, slowlen))
macd = fast_ma - slow_ma,
signal = security(syminfo.tickerid, tf, sma(macd, sigsmooth))
hist = macd - signal
[macd, signal, hist]
// Get higher timeframe candle
f_getTFCandle(_tf) =>
_open = security(heikinashi(syminfo.tickerid), _tf, open, barmerge.gaps_off, barmerge.lookahead_on)
_close = security(heikinashi(syminfo.tickerid), _tf, close, barmerge.gaps_off, barmerge.lookahead_on)
_high = security(heikinashi(syminfo.tickerid), _tf, high, barmerge.gaps_off, barmerge.lookahead_on)
_low = security(heikinashi(syminfo.tickerid), _tf, low, barmerge.gaps_off, barmerge.lookahead_on)
hl2 = (_high + _low) / 2.0
newBar = change(_open)
candleBodyDir = _close > _open
[candleBodyDir, newBar]
// } FUNCTIONS
// CALCULATE INDICATORS {
// RSI
rsi = rsi(rsiSRC, rsiLen)
rsiobcolor = input(color.new(#e13e3e, 0), 'RSI OverBought', group = 'Color Settings')
rsioscolor = input(color.new(#3ee145, 0), 'RSI OverSold', group = 'Color Settings')
rsinacolor = input(color.new(#c33ee1, 0), 'RSI InBetween', group = 'Color Settings')
rsiColor = rsi <= rsiOversold ? rsioscolor : rsi >= rsiOverbought ? rsiobcolor : rsinacolor
// Calculates WaveTrend
[wt1, wt2, 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)
// WT Divergences
[wtFractalTop, wtFractalBot, wtLow_prev, wtBearDiv, wtBullDiv, wtBearDivHidden, wtBullDivHidden] = f_findDivs(wt2, wtDivOBLevel, wtDivOSLevel, true)
[wtFractalTop_add, wtFractalBot_add, wtLow_prev_add, wtBearDiv_add, wtBullDiv_add, wtBearDivHidden_add, wtBullDivHidden_add] = f_findDivs(wt2, wtDivOBLevel_add, wtDivOSLevel_add, true)
[wtFractalTop_nl, wtFractalBot_nl, wtLow_prev_nl, wtBearDiv_nl, wtBullDiv_nl, wtBearDivHidden_nl, wtBullDivHidden_nl] = f_findDivs(wt2, 0, 0, false)
wtBearDivHidden_ = showHiddenDiv_nl ? wtBearDivHidden_nl : wtBearDivHidden
wtBullDivHidden_ = showHiddenDiv_nl ? wtBullDivHidden_nl : wtBullDivHidden
WTBearDivColorDown = input(color.new(#e60000, 0), 'WT Bear Div', group = 'Color Settings')
wtBullDivColorUp = input(color.new(#00e676, 0), 'WT Bull Div', group = 'Color Settings')
wtBearDivColor = (wtShowDiv and wtBearDiv) or (wtShowHiddenDiv and wtBearDivHidden_) ? WTBearDivColorDown : na
wtBullDivColor = (wtShowDiv and wtBullDiv) or (wtShowHiddenDiv and wtBullDivHidden_) ? wtBullDivColorUp : na
wtBearDivColor_add = (wtShowDiv and (wtDivOBLevel_addshow and wtBearDiv_add)) or (wtShowHiddenDiv and (wtDivOBLevel_addshow and wtBearDivHidden_add)) ? WTBearDivColorDown: na
wtBullDivColor_add = (wtShowDiv and (wtDivOBLevel_addshow and wtBullDiv_add)) or (wtShowHiddenDiv and (wtDivOBLevel_addshow and wtBullDivHidden_add)) ? wtBullDivColorUp : 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
rsiBearColor = #e6000000 //input(color.new(#e60000, 0), 'RSI Bear Div', group = 'Color Settings')
rsiBullColor = #38ff4200 //input(color.new(#38ff42, 0), 'RSI Bull Div', group = 'Color Settings')
rsiBearDivColor = (rsiShowDiv and rsiBearDiv) or (rsiShowHiddenDiv and rsiBearDivHidden_) ? rsiBearColor : na
rsiBullDivColor = (rsiShowDiv and rsiBullDiv) or (rsiShowHiddenDiv and rsiBullDivHidden_) ? rsiBullColor : na
// Stoch Divergences
[stochFractalTop, stochFractalBot, stochLow_prev, stochBearDiv, stochBullDiv, stochBearDivHidden, stochBullDivHidden] = f_findDivs(stochK, 0, 0, false)
stochbearcolor = color.new(#e60000, 0) //input(color.new(#e60000, 0), 'Stoch Bear Div', group = 'Color Settings')
stochbullcolor = color.new(#38ff42, 0) //input(color.new(#38ff42, 0), 'Stoch Bull Div', group = 'Color Settings')
stochBearDivColor = (stochShowDiv and stochBearDiv) or (stochShowHiddenDiv and stochBearDivHidden) ? stochbearcolor : na
stochBullDivColor = (stochShowDiv and stochBullDiv) or (stochShowHiddenDiv and stochBullDivHidden) ? stochbullcolor : na
// Small Circles WT Cross
signalcolorup = input(color.new(#00e676, 0), 'WT Buy Dot', group = 'Color Settings')
signalcolordown = input(color.new(#ff5252, 0), 'WT Sell Dot', group = 'Color Settings')
signalColor = wt2 - wt1 > 0 ? signalcolordown : signalcolorup
// Buy signal.
buySignal = wtCross and wtCrossUp and wtOversold
buySignalDiv = (wtShowDiv and wtBullDiv) or
(wtShowDiv and wtBullDiv_add) or
(stochShowDiv and stochBullDiv) or
(rsiShowDiv and rsiBullDiv)
buySignalDiv_color = wtBullDiv ? colorGreen :
wtBullDiv_add ? color.new(colorGreen, 60) :
rsiShowDiv ? colorGreen : na
// Sell signal
sellSignal = wtCross and wtCrossDown and wtOverbought
sellSignalDiv = (wtShowDiv and wtBearDiv) or
(wtShowDiv and wtBearDiv_add) or
(stochShowDiv and stochBearDiv) or
(rsiShowDiv and rsiBearDiv)
sellSignalDiv_color = wtBearDiv ? colorRed :
wtBearDiv_add ? color.new(colorRed, 60) :
rsiBearDiv ? colorRed : na
// Gold Buy
lastRsi = valuewhen(wtFractalBot, rsi[2], 0)[2]
wtGoldBuy = ((wtShowDiv and wtBullDiv) or (rsiShowDiv and rsiBullDiv)) and
wtLow_prev <= osLevel3 and
wt2 > osLevel3 and
wtLow_prev - wt2 <= -5 and
lastRsi < 30
// } CALCULATE INDICATORS
// DRAW {
bgcolor(darkMode ? color.new(#000000, 0) : na)
zLine = plot(0, color = color.new(colorWhite, 50))
// overboughtColor = obLevel == obLevel2 ? na : color.white
WT1Color = color.rgb(68, 253, 253, 98)
WT2Color = color.rgb(185, 40, 252, 95)
WTInsideColor = color.rgb(214, 213, 213, 75)
WTMainColor = color.rgb(161, 161, 161, 75)
// WT Areas Color Inputs
colorWT1 = input(WT1Color, "WT1 Line", group='Color Settings')
colorWT2 = input(WT2Color, 'WT2 Line', group='Color Settings')
WTInside = input(WTInsideColor, 'WT Line Fill', group='Color Settings')
WTFillTo0 = input(WTMainColor, 'WT Fill to 0', group='Color Settings')
WT1Line = plot(wtShow ? wt1 : na, title = 'WaveTrend 1 line', color=colorWT1, linewidth=1)
WT2Line = plot(wtShow ? wt2 : na, title = 'WaveTrend 2 Line', color=colorWT2, linewidth=1)
WTFill = plot(wtShow ? wt1 : na, title = 'WaveTrend Fill', color=WTInside, linewidth=1)
fill(WT1Line, WT2Line, color=WTInside)
fill(WT1Line, WT2Line, color=WTMainColor, title='WTMainFill')
// PLOT INDICATORS
plot(wtShow ? wt1 : na, title = 'WT1', color = WT1Color, linewidth = 1)
plot(wtShow ? wt2 : na, title = 'WT2', color = WT2Color, linewidth = 1)
// FILL BETWEEN WT1, WT2, AND ZERO LINE
plot0 = plot(0, color=color.gray, title="Zero Line", linewidth=1)
fill(plot(wt2, title = 'WT2 Fill', color = WT2Color, transp = 100), plot0, color = WTFillTo0, transp = 90)
// VWAP
VWAPColor = input(color.rgb(5, 22, 253, 27), "VWAP", group = 'Color Settings')
plot(vwapShow ? wtVwap : na, title = 'VWAP', color = VWAPColor, style = plot.style_area, linewidth = 2, transp = 45)
// WT Div
plot(series = wtFractalTop ? wt2[2] : na, title = 'WT Bearish Divergence', color = wtBearDivColor, linewidth = 2, offset = -2)
plot(series = wtFractalBot ? wt2[2] : na, title = 'WT Bullish Divergence', color = wtBullDivColor, linewidth = 2, offset = -2)
// WT 2nd Div
plot(series = wtFractalTop_add ? wt2[2] : na, title = 'WT 2nd Bearish Divergence', color = wtBearDivColor_add, linewidth = 2, offset = -2)
plot(series = wtFractalBot_add ? wt2[2] : na, title = 'WT 2nd Bullish Divergence', color = wtBullDivColor_add, linewidth = 2, offset = -2)
// RSI
plot(rsiShow ? rsi : na, title = 'RSI', color = rsiColor, linewidth = 2, transp = 25)
// RSI Div
plot(series = rsiFractalTop ? rsi[2] : na, title='RSI Bearish Divergence', color = rsiBearDivColor, linewidth = 1, offset = -2)
plot(series = rsiFractalBot ? rsi[2] : na, title='RSI Bullish Divergence', color = rsiBullDivColor, linewidth = 1, offset = -2)
// Stochastic RSI
stochkcolor = input(color.new(#21baf3, 70), "Stoch K", group = 'Color Settings')
stochdcolor = input(color.new(#673ab7, 90), "Stoch D", group = 'Color Settings')
stochKplot = plot(stochShow ? stochK : na, title = 'Stoch K', color = stochkcolor, linewidth = 2)
stochDplot = plot(stochShow ? stochD : na, title = 'Stoch D', color = stochdcolor, linewidth = 1)
stochFillColor = stochK >= stochD ? #21bbf300 : #3a9eb7ee
fill(stochKplot, stochDplot, title='KD Fill', color=stochFillColor)
// Stoch Div
plot(series = stochFractalTop ? stochK[2] : na, title='Stoch Bearish Divergence', color = stochBearDivColor, linewidth = 1, offset = -2)
plot(series = stochFractalBot ? stochK[2] : na, title='Stoch Bullish Divergence', color = stochBullDivColor, linewidth = 1, offset = -2)
// Schaff Trend Cycle
plot(tcLine ? tcVal : na, color = color.rgb(58, 179, 183), linewidth = 2, title = "Schaff Trend Cycle 1")
plot(tcLine ? tcVal : na, color = color.new(colorWhite, 50), linewidth = 1, title = "Schaff Trend Cycle 2")
// Circles
plotchar(wtCross ? wt2 : na, title = 'Buy and sell circle', char = '•', location = location.absolute, color = signalColor, transp = 15, size = size.tiny)
plotchar(wtBuyShow and buySignal ? -107 : na, title = 'Buy circle', char='·', color = colorGreen, location = location.absolute, size = size.small, transp = 50)
plotchar(wtSellShow and sellSignal ? 105 : na , title = 'Sell circle', char='·', color = colorRed, location = location.absolute, size = size.small, transp = 50)
plotchar(wtDivShow and buySignalDiv ? -106 : na, title = 'Divergence buy circle', char='•', color = buySignalDiv_color, location = location.absolute, size = size.small, offset = -2, transp = 15)
plotchar(wtDivShow and sellSignalDiv ? 106 : na, title = 'Divergence sell circle', char='•', color = sellSignalDiv_color, location = location.absolute, size = size.small, offset = -2, transp = 15)
plotchar(wtGoldBuy and wtGoldShow ? -106 : na, title = 'Gold buy gold circle', char='•', color = colorOrange, location = location.absolute, size = size.normal, offset = -2, transp = 15)
// ALERTS {
// BUY
alertcondition(buySignal, 'Buy (Big green circle)', 'Green circle WaveTrend Oversold')
alertcondition(buySignalDiv, 'Buy (Big green circle + Div)', 'Buy & WT Bullish Divergence & WT Overbought')
alertcondition(wtGoldBuy, 'GOLD Buy (Big GOLDEN circle)', 'Green & GOLD circle WaveTrend Overbought')
alertcondition(wtCross and wtCrossUp, 'Buy (Small green dot)', 'Buy small circle')
// SELL
alertcondition(sellSignal, 'Sell (Big red circle)', 'Red Circle WaveTrend Overbought')
alertcondition(sellSignalDiv, 'Sell (Big red circle + Div)', 'Buy & WT Bearish Divergence & WT Overbought')
alertcondition(wtCross and wtCrossDown, 'Sell (Small red dot)', 'Sell small circle')
////////////-----------------------------------------------------------------------------------------------}
// SG Money
// MFI Calculation Inputs
mfiLength = input(defval=14, title="MFI Length", minval=1, tooltip="Recommended: 14 for daily analysis")
mfiSourceInput = input(defval="hlc3", title="MFI Source", options=["close", "open", "high", "low", "hl2", "hlc3", "ohlc4"], tooltip="Recommended: Typical Price (hlc3) for daily analysis")
useVolume = input(defval=true, title="Use Actual Volume", type=input.bool, tooltip="Recommended: True for daily analysis")
customVolumeInput = input(defval="volume", title="Custom Volume Source")
// Smoothing Inputs
smoothLength = input(defval=3, title="Smoothing Length", minval=1, tooltip="Recommended: 3-5 for daily analysis")
smoothType = input(defval="SMA", title="Smoothing Type", options=["SMA", "EMA", "WMA", "RMA"], tooltip="Recommended: SMA for daily analysis")
// Display Inputs
showRawMFI = input(defval=false, title="Show Raw MFI", type=input.bool)
mfiOffset = input(defval=50.0, title="MFI Center Offset", step=0.1, type=input.float)
mfiMultiplier = input(defval=1.0, title="MFI Multiplier", step=0.1, type=input.float)
// Color Inputs
mfiPositiveColor = input(defval=color.green, title="MFI Positive Color", type=input.color)
mfiNegativeColor = input(defval=color.red, title="MFI Negative Color", type=input.color)
zeroLineColor = input(defval=color.white, title="Zero Line Color", type=input.color)
overboughtColor = input(defval=color.red, title="Overbought Level Color", type=input.color)
oversoldColor = input(defval=color.green, title="Oversold Level Color", type=input.color)
// MFI Source selection
mfiSource = mfiSourceInput == "close" ? close :mfiSourceInput == "open" ? open :mfiSourceInput == "high" ? high :mfiSourceInput == "low" ? low :mfiSourceInput == "hl2" ? hl2 :mfiSourceInput == "hlc3" ? hlc3 :ohlc4
// Volume source selection
volumeSource = useVolume ? volume : customVolumeInput == "volume" ? volume : customVolumeInput == "open" ? open :customVolumeInput == "high" ? high :customVolumeInput == "low" ? low :customVolumeInput == "close" ? close :customVolumeInput == "hl2" ? hl2 :customVolumeInput == "hlc3" ? hlc3 :ohlc4
// Custom MFI calculation
customMFI(src, len, vol) =>
upper = sum(vol * (change(src) <= 0 ? 0 : src), len)
lower = sum(vol * (change(src) >= 0 ? 0 : src), len)
100 - (100 / (1 + upper / lower))
// Smoothing function
smooth(src, len, type) =>type == "SMA" ? sma(src, len) :type == "EMA" ? ema(src, len) :type == "WMA" ? wma(src, len) :rma(src, len)
// Calculate MFI
mfiRaw = customMFI(mfiSource, mfiLength, volumeSource)
mfiSmoothed = smooth(mfiRaw, smoothLength, smoothType)
// Apply offset and multiplier
mfiDisplay = (mfiSmoothed - mfiOffset) * mfiMultiplier
// Determine color
mfiColor = mfiSmoothed > 50 ? mfiPositiveColor : mfiNegativeColor
// Plotting
plot(showRawMFI ? mfiRaw : na, title="Raw MFI", color=color.gray, style=plot.style_circles)
plot_mfi = plot(mfiDisplay, title="Smoothed MFI", color=color.white)
plot_zero = plot(0, title="Zero Line", color=zeroLineColor)
fill(plot_zero, plot_mfi, color=mfiColor, transp=0, title="MFI Fill")
// Overbought/Oversold levels
obLevelHigh = hline(60, "Overbought Line", color=overboughtColor)
osLevelLow = hline(-60, "Oversold Line", color=oversoldColor)
//////////////-----------------------------}
//Trading Bot
// VWAP
vwap = vwap(close)
plot(vwap, color=color.blue, title="VWAP")
// WaveTrend Calculation
n1b = input(10, "Channel Length")
n2b = input(21, "Average Length")
obLevel1b = input(60, "Overbought Level 1")
obLevel2b = input(53, "Overbought Level 2")
osLevel1b = input(-60, "Oversold Level 1")
osLevel2b = input(-53, "Oversold Level 2")
apb = hlc3
esa = ema(apb, n1b)
d = ema(abs(apb - esa), n1b)
ci = (apb - esa) / (0.015 * d)
tcib = ema(ci, n2b)
wt1b = tcib
wt2b = sma(wt1b, 4)
cross_wtb = cross(wt1b, wt2b)
plot(wt1b, color=color.green, title="WaveTrend1")
plot(wt2b, color=color.red, title="WaveTrend2")
hline(obLevel1b, "OverBought 1", color=color.red)
hline(obLevel2b, "OverBought 2", color=color.red)
hline(osLevel1b, "OverSold 1", color=color.green)
hline(osLevel2b, "OverSold 2", color=color.green)
bgcolor(cross_wtb ? na : color.blue, transp=90)
// Money Flow Index Calculation
mf = input(14, title="MFI Length")
mfi = mfiSource
hline(80, "OverBought", color=color.red)
hline(20, "OverSold", color=color.green)
plot(mfi, title="MFI", color=color.orange)
// Signals
var signal = 0
if (crossover(vwap, 0))
signal := 1 // Bullish
if (crossunder(vwap, 0))
signal := -1 // Bearish
if (mfi < 20 and crossover(wt1, wt2))
signal := 1 // Bullish
if (mfi > 80 and crossunder(wt1, wt2))
signal := -1 // Bearish
plotshape(series=signal == 1 ? 1 : na, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=signal == -1 ? 1 : na, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Output for Python script
var float signal_output = na
if (barstate.islast)
signal_output := signal
plot(signal_output, title="Signal Output", color=color.yellow)
Show all 518 lines