ysokayev
Pine Script Scholar
Pine Script Scholar
Posts: 2
Joined: October 30th, 2022
Contact: TradingView Profile

WaveTrend and Multi-Timeframe Trend Reversal

Made this to track momentum change the WaveTrend and heikinashi trend on multi-timeframes. I'll take input but this has worked for me like a charm.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sokayevy

//@version=5
indicator(title = "Diamond V2.0", shorttitle = "D2.0", overlay=true)

//RSI + MFI
rsiMFIShow = input.bool(true, title = 'Show MFI')
rsiMFIperiod = input.int(60,title = 'MFI Period')
rsiMFIMultiplier = input.float(150, title = 'MFI Area multiplier')
rsiMFIPosY = input.float(2.5, title = 'MFI Area Y Pos')

// WaveTrend
wtShow = input.bool(true, title = 'Show WaveTrend')
wtChannelLen = input.int(9, title = 'WT Channel Length')
wtAverageLen = input.int(12, title = 'WT Average Length')
wtMASource = input.source(hlc3, title = 'WT MA Source')
wtMALen = input.int(3, title = 'WT MA Length')

// WaveTrend Overbought & Oversold lines

obLevel = input.int(53, title = 'WT Overbought Level 1')
obLevel2 = input.int(60, title = 'WT Overbought Level 2')
obLevel3 = input.int(100, title = 'WT Overbought Level 3')
osLevel = input.int(-53, title = 'WT Oversold Level 1')
osLevel2 = input.int(-60, title = 'WT Oversold Level 2')
osLevel3 = input.int(-75, title = 'WT Oversold Level 3')

// Sommi Flag
sommiFlagShow = input.bool(true, title = 'Show Sommi flag')
sommiShowVwap = input.bool(false, title = 'Show Sommi F. Wave')
sommiVwapTF = input.string('720', title = 'Sommi F. Wave timeframe')
sommiVwapBearLevel = input.int(0, title = 'F. Wave Bear Level (less than)')
sommiVwapBullLevel = input.int(0, title = 'F. Wave Bull Level (more than)')
soomiFlagWTBearLevel = input.int(0, title = 'WT Bear Level (more than)')
soomiFlagWTBullLevel = input.int(0, title = 'WT Bull Level (less than)')
soomiRSIMFIBearLevel = input.int(0, title = 'Money flow Bear Level (less than)')
soomiRSIMFIBullLevel = input.int(0, title = 'Money flow Bull Level (more than)')

// Sommi Diamond
sommiDiamondShow = input.bool(true, title = 'Show Sommi diamond')
sommiRingShow = input.bool(true, title = 'Show Sommi Ring')

sommiHTCRes = input.string('5', title = 'HTF Candle Res. 1')
sommiHTCRes2 = input.string('10', title = 'HTF Candle Res. 2')
sommiHTCRes3 = input.string('15', title = 'HTF Candle Res. 3')
sommiHTCRes4 = input.string('30', title = 'HTF Candle Res. 4')
sommiHTCRes5 = input.string('60', title = 'HTF Candle Res. 5')

//sommiHTCRes = input.string('15', title = 'HTF Candle Res. 1')
//sommiHTCRes2 = input.string('30', title = 'HTF Candle Res. 2')
//sommiHTCRes3 = input.string('60', title = 'HTF Candle Res. 3')
//sommiHTCRes4 = input.string('120', title = 'HTF Candle Res. 4')
//sommiHTCRes5 = input.string('240', title = 'HTF Candle Res. 5')
soomiDiamondWTBearLevel = input.int(0, title = 'WT Bear Level (More than)')
soomiDiamondWTBullLevel = input.int(0, title = 'WT Bull Level (Less than)')

sommiHTCRes_0 = input.string('60', title = 'HTF Candle Res. 1')
sommiHTCRes2_0 = input.string('240', title = 'HTF Candle Res. 2')

sommiHTCRes_1m = input.string('15', title = 'HTF Candle Res. 1')
sommiHTCRes2_1m = input.string('10', title = 'HTF Candle Res. 2')
sommiHTCRes3_1m = input.string('5', title = 'HTF Candle Res. 3')
sommiHTCRes4_1m = input.string('2', title = 'HTF Candle Res. 4')
sommiHTCRes5_1m = input.string('1', title = 'HTF Candle Res. 5')

// Colors

colorYellow = input.color( color.rgb(255, 245, 158, 30), "Weak Diamond")
colorPink = input.color(color.rgb(247, 82, 95), "Bearish Diamond")
colorBluelight = input.color( color.rgb(34, 171, 148), "Bullish Diamond")
colorPink_2 = input.color(color.rgb(247, 82, 95, 30), "Bearish Cross")
colorBluelight_2 = input.color( color.rgb(34, 171, 148, 30), "Bullish Cross")
colorBlue = input.color( color.rgb(88, 130, 245), "Color 4")

// 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]

// WaveTrend 1m
f_wavetrend_1m(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_1 = request.security(syminfo.tickerid, tf, ta.ema(ci, avg))
wt2_1 = request.security(syminfo.tickerid, tf, ta.sma(wt1_1, malen))
wtVwap_1 = wt1_1 - wt2_1
wtOversold_1 = wt2_1 <= osLevel
wtOverbought_1 = wt2_1 >= obLevel
wtCross_1 = ta.cross(wt1_1, wt2_1)
wtCrossUp_1 = wt2_1 - wt1_1 <= 0
wtCrossDown_1 = wt2_1 - wt1_1 >= 0
wtCrosslast_1 = ta.cross(wt1_1[2], wt2_1[2])
wtCrossUplast_1 = wt2_1[2] - wt1_1[2] <= 0
wtCrossDownlast_1 = wt2_1[2] - wt1_1[2] >= 0
[wt1_1, wt2_1, wtOversold_1, wtOverbought_1, wtCross_1, wtCrossUp_1, wtCrossDown_1, wtCrosslast_1, wtCrossUplast_1, wtCrossDownlast_1, wtVwap_1]

// 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_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)
_hl2 = (_high + _low) / 2.0
newBar = ta.change(_open)
candleBodyDir = _close > _open
[candleBodyDir, newBar]


f_findSommiDiamond(tf, tf2, tf3, tf4, tf5, wt1, wt2, wtCross, wtCrossUp, wtCrossDown) =>
[candleBodyDir, newBar] = f_getTFCandle(tf)
[candleBodyDir2, newBar2] = f_getTFCandle(tf2)
[candleBodyDir3, newBar3] = f_getTFCandle(tf3)
[candleBodyDir4, newBar4] = f_getTFCandle(tf4)
[candleBodyDir5, newBar5] = f_getTFCandle(tf5)

bearPattern = wt2 > soomiDiamondWTBearLevel and
wtCross and
wtCrossDown and
not candleBodyDir and
not candleBodyDir2 and
not candleBodyDir3 and
not candleBodyDir4 and
not candleBodyDir5

bullPattern = wt2 < soomiDiamondWTBullLevel and
wtCross and
wtCrossUp and
candleBodyDir and
candleBodyDir2 and
candleBodyDir3 and
candleBodyDir4 and
candleBodyDir5
[bearPattern, bullPattern]

f_findSommiDiamond_0(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]

//RSI+MFI Area
rsiMFI = f_rsimfi(rsiMFIperiod, rsiMFIMultiplier, timeframe.period)
rsiMFIColor = rsiMFI > 0 ? #3ee145 : #ff3d2e

// Calculates WaveTrend
[wt1, wt2, wtOversold, wtOverbought, wtCross, wtCrossUp, wtCrossDown, wtCross_last, wtCrossUp_last, wtCrossDown_last, wtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)

// Wavetrend_0
[wt1_0, wt2_0, wtOversold_0, wtOverbought_0, wtCross_0, wtCrossUp_0, wtCrossDown_0, wtCross_last_0, wtCrossUp_last_0, wtCrossDown_last_0, wtVwap_0] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, timeframe.period)

// Calculate WaveTrend 1m
[wt1_1, wt2_1, wtOversold_1, wtOverbought_1, wtCross_1, wtCrossUp_1, wtCrossDown_1, wtCross_last_1, wtCrossUp_last_1, wtCrossDown_last_1, wtVwap_1] = f_wavetrend_1m(wtMASource, wtChannelLen, wtAverageLen, wtMALen, "10")

// Sommi flag
[sommiBearish, sommiBullish, hvwap] = f_findSommiFlag(sommiVwapTF, wt1, wt2, rsiMFI, wtCross, wtCrossUp, wtCrossDown)

//Sommi diamond
[sommiBearishDiamond, sommiBullishDiamond] = f_findSommiDiamond(sommiHTCRes, sommiHTCRes2, sommiHTCRes3, sommiHTCRes4, sommiHTCRes5, wt1, wt2, wtCross, wtCrossUp, wtCrossDown)

//Sommi diamond 1m
[sommiBearishDiamond_0, sommiBullishDiamond_0] = f_findSommiDiamond_0(sommiHTCRes_0, sommiHTCRes2_0, wt1_0, wt2_0, wtCross_0, wtCrossUp_0, wtCrossDown_0)

//Sommi diamond 1m
[sommiBearishDiamond_1m, sommiBullishDiamond_1m] = f_findSommiDiamond(sommiHTCRes_1m, sommiHTCRes2_1m, sommiHTCRes3_1m, sommiHTCRes4_1m, sommiHTCRes5_1m, wt1_1, wt2_1, wtCross_1, wtCrossUp_1, wtCrossDown_1)

//test vals inside somiflag
[hwt1, hwt2, hwtOversold, hwtOverbought, hwtCross, hwtCrossUp, hwtCrossDown, hwtCrosslast, hwtCrossUplast, hwtCrossDownlast, hwtVwap] = f_wavetrend(wtMASource, wtChannelLen, wtAverageLen, wtMALen, sommiVwapTF)

//plot(rsiMFI, color = rsiMFIColor)
z = request.security(syminfo.ticker, timeframe.period, wtMASource)
y = request.security(syminfo.ticker, "1000", wtMASource)
a = hwt1 - hwt2
//plot(a, color = color.white)
//plot(wt1, color = color.red)
//plot(wt2, color = color.blue)
//plot(rsiMFI, color = color.green)
//plot(0, color = color.black, linewidth = 3)
checkBearish = ta.barssince(sommiBearishDiamond_0)
checkBullish = ta.barssince(sommiBullishDiamond_0)

sommiBearishDiamond_0 := sommiBearishDiamond_0 and (checkBearish[1] > checkBullish[1])
sommiBullishDiamond_0 := sommiBullishDiamond_0 and (checkBullish[1] > checkBearish[1])

checkBearishRing = ta.barssince(sommiBearishDiamond)
checkBullishRing = ta.barssince(sommiBullishDiamond)

sommiBearishDiamond := sommiBearishDiamond and (checkBearishRing[1] > checkBullishRing[1])
sommiBullishDiamond := sommiBullishDiamond and (checkBullishRing[1] > checkBearishRing[1])

// Sommi flag
plotshape(sommiFlagShow and sommiBearish ? 108 : na, title = 'Sommi weak bearish flag', style = shape.xcross, color = colorPink_2, location = location.abovebar, size = size.tiny)
plotshape(sommiFlagShow and sommiBullish ? -108 : na, title = 'Sommi weak bullish flag', style = shape.xcross, color = colorBluelight_2, location = location.belowbar, size = size.tiny)


// Sommi diamond
plotchar(sommiRingShow and sommiBearishDiamond ? 108 : na, title = 'Sommi bearish Ring', char='◆', color = colorYellow, location = location.abovebar, size = size.tiny)
plotchar(sommiRingShow and sommiBullishDiamond ? -108 : na, title = 'Sommi bullish Ring', char='◆', color = colorYellow, location = location.belowbar, size = size.tiny)

// Sommi diamond_0
plotchar(sommiDiamondShow and sommiBearishDiamond_0 ? 108 : na, title = 'Sommi bearish diamond', char='◆', color = colorPink, location = location.abovebar, size = size.tiny)
plotchar(sommiDiamondShow and sommiBullishDiamond_0 ? -108 : na, title = 'Sommi bullish diamond', char='◆', color = colorBluelight, location = location.belowbar, size = size.tiny)

// Sommi diamond 1min
//plotchar(sommiDiamondShow and sommiBearishDiamond_1m ? 108 : na, title = 'Sommi bearish diamond', char='◯', color = colorPink, location = location.belowbar, size = size.tiny)
//plotchar(sommiDiamondShow and sommiBullishDiamond_1m ? -108 : na, title = 'Sommi bullish diamond', char='◯', color = colorBluelight, location = location.belowbar, size = size.tiny)

// Alerts

alertcondition(sommiBullishDiamond_0, 'Sommi Bullish Diamond')


// SELL
alertcondition(sommiBearishDiamond_0, 'Sommi Bearsish Diamond')

TeresaDee
Pine Script Scholar
Pine Script Scholar
Posts: 3
Joined: November 10th, 2022
Contact: TradingView Profile

Re: WaveTrend and Multi-Timeframe Trend Reversal

Thanks you. Really interesting Code! - you have some line continuation errors in it though - where you have => indicators with no value after them. What's this intended to be?

purplemint22
Pine Script Rookie
Pine Script Rookie
Posts: 17
Joined: October 14th, 2022

Re: WaveTrend and Multi-Timeframe Trend Reversal

I was interested in seeing how this worked too, but I had the same problem when I tried to copy/paste the code into the pine editor. I don't know if some of the formatting changed with it was pasted on the forum. Maybe try to use the code button under the full editor?

sman0357
Pine Script Master
Pine Script Master
Posts: 2
Joined: June 27th, 2023
Contact: TradingView Profile

Re: WaveTrend and Multi-Timeframe Trend Reversal

Set overlay to false.
If you copy and paste, then you will need to fix the indent issues wherever you find the continuation errors.
The indicator is from vumanchu / market cipher.

Return to “Share Your Scripts”