This is a tradingview/pinescript code and I wanted to know is it possible to get this over to MT4. Im more so interested in the candle change option for this as I know we already have the oscillator indi posted somewhere on here.
Code: Select all
//@version=5
//original author @LazyBear
//Assembled by @ClassicScott
//I'm guessing most of you are familir with LazyBear's adaptation of the Wavetrend Oscillator; it's one of the most popular indicators on TradingView.
//I know others have done adaptations of it, but I thought I might as well, because that's kind of a thing I like doing.
//In this version I've added a second Wavetrend plot. This is a thing I like to do. The longer plot gives you a longer timeframe momentum bias, and the shorter
//plot gives you entries and/or exits.
//Here we have one plot with a lookback period of 55, and another with the default set to 6 (change this to 14 if you think you might prefer something slower and
//that will plot similarly to the default RSI settings). With the traditional Wavetrend Oscillator there is a simple moving average on the WTO that is to help provide
//entries and exits. I've done away with this as there are already two plots, and I felt more would just clutter the indicator. Instead of plotting the SMA I've
//plotted the crosses along the bottom and top of the indicator. Also, as is not the case in LazyBear's version, this SMA length is adjustable. By default it i
//set to 3, which is the default setting on the original indicator.
//I've also plotted background colors for when there is what I call a momentum shift. Basically if one or the other oscillators crosses the centerline a colored bar
//is plotted. By default it is turned on for both WTOs, though in practice you might only want it on for the longer one.
//I would say use of the indicator is similar to the original WTO ot many other oscillators. Buying oversold and selling overbought, but being mindful of the momentum
//of the market. If the longer WTO is above the centerline it's best to be looking for dips to the centerline, or for an overbought signal by the faster WTO, and vice
//versa if the longer WTO is below the centerline. That said, you can also adjust the length of the SMA on the faster WTO to fine tune entries or exits, which is kind
//of how you would trade LazyBear's version. In this case you have that additional confirmation of market momentum.
//You can set colored candles to either of the WTO plots via a dropdown menu.
//There are alerts for overbought and oversold situations, centerline crosses, and Wavetrend crosses.
//That's about it. Hope you enjoy this particular implementation of LazyBear's well known indicator.
//Ah yes, last thing: Original version the source is set to hlc3. I've given you the opportunity to change that, so if you prefer using close you can, or whatever
//you want.
indicator(title='+ WaveTrend Oscillator', shorttitle='+ WTO', timeframe='')
src = input(defval=hlc3, title='Source')
//WTO PLOT ONE
channel_len = input.int(defval=8, title='Channel Length', group='Primary Wavetrend Inputs')
average_len = input.int(defval=13, title='Average Length', group='Primary Wavetrend Inputs')
wt_1_ma_len = input.int(defval=3, title='Moving Average Length', group='Primary Wavetrend Inputs')
esa = ta.ema(src, channel_len)
d = ta.ema(math.abs(src - esa), channel_len)
ci = (src - esa) / (0.015 * d)
tci = ta.ema(ci, average_len)
wt_1 = tci
wt_1_ma = ta.sma(wt_1, wt_1_ma_len)
//COLOR INPUTS
wt_1_up = input.color(color.new(#ff9800, 0), title='High', inline='wt 1 color', group='Primary Wavetrend Inputs')
wt_1_down = input.color(color.new(#2962ff, 0), title='Low', inline='wt 1 color', group='Primary Wavetrend Inputs')
wt_1_color = color.from_gradient(wt_1, -80, 80, wt_1_down, wt_1_up)
plot(wt_1, color=wt_1_color, title='Primary Wavetrend')
////////////////////////////////////////////////////////////////////////////////
//WTO PLOT TWO
channel_len_2 = input.int(defval=34, title='Channel Length', group='Secondary Wavetrend Inputs')
average_len_2 = input.int(defval=55, title='Average Length', group='Secondary Wavetrend Inputs')
esa2 = ta.ema(src, channel_len_2)
d2 = ta.ema(math.abs(src - esa2), channel_len_2)
ci2 = (src - esa2) / (0.015 * d2)
tci2 = ta.sma(ci2, average_len_2)
wt_2 = tci2
//COLOR INPUTS
wt_2_up = input.color(color.new(#00bcd4, 0), title='High', inline='wt 2 color', group='Secondary Wavetrend Inputs')
wt_2_down = input.color(color.new(#e91e63, 0), title='Low', inline='wt 2 color', group='Secondary Wavetrend Inputs')
wt_2_color = color.from_gradient(wt_2, -60, 60, wt_2_down, wt_2_up)
plot(wt_2, color=wt_2_color, title='Secondary Wavetrend')
////////////////////////////////////////////////////////////////////////////////
////MOMENTUM CHANGE & BACKGROUND COLORS
//PRIMARY WTO
mom_long_color_1 = input.color(color.new(color.blue, 85), title='Long Background Color', inline='1', group='Primary Wavetrend Inputs')
mom_short_color_1 = input.color(color.new(color.red, 85), title='Short Background Color', inline='1', group='Primary Wavetrend Inputs')
mom_change_long_1 = ta.crossover(wt_1, 0)
mom_change_short_1 = ta.crossunder(wt_1, 0)
bgcolor(mom_change_long_1 ? mom_long_color_1 : na, title='Long Background Color')
bgcolor(mom_change_short_1 ? mom_short_color_1 : na, title='Short Background Color')
//MOVING AVERAGE CROSS SIGNALS ON PRIMARY WAVETREND
plotshape(ta.crossover(wt_1, wt_1_ma), title='Maybe Buy', style=shape.circle, color=color.new(color.blue, 0), location=location.bottom)
plotshape(ta.crossunder(wt_1, wt_1_ma), title='Maybe Sell', style=shape.circle, color=color.new(color.red, 0), location=location.top)
//SECONDARY WTO
mom_long_color_2 = input.color(color.new(color.blue, 85), title='Long Background Color', inline='2', group='Secondary Wavetrend Inputs')
mom_short_color_2 = input.color(color.new(color.red, 85), title='Short Background Color', inline='2', group='Secondary Wavetrend Inputs')
mom_change_long_2 = ta.crossover(wt_2, 0)
mom_change_short_2 = ta.crossunder(wt_2, 0)
bgcolor(mom_change_long_2 ? mom_long_color_2 : na, title='Long Background Color - Secondary WTO')
bgcolor(mom_change_short_2 ? mom_short_color_2 : na, title='Short Background Color - Secondary WTO')
////////////////////////////////////////////////////////////////////////////////
////CANDLE COLOR
candle_color = input.bool(defval=true, title='Colored Candles?', group='Candle Colors')
i_cc_selection = input.string(defval='WT 1 Gradient', options=['WT 1 Gradient', 'WT 1 Center Line', 'WT 1 Extremes', 'WT 2 Gradient', 'WT 2 Center Line'], title='How would you like them colored?', group='Candle Colors', tooltip='Either gradient selection will color candles in a gradient between high and low zones on the oscillator. OB/OS simply colors candles based on where the oscillator is relative to the user-defined high and low zones below.')
////OSCILLATOR RANGE EXTREMES
i_high_extreme = input.string(defval='60', options=['0', '10', '20', '30', '40', '50', '60', '70', '80'], title='High Extreme', group='Candle Colors', tooltip='Numbers located along the far right edge of the indicator. Inputs only affect a difference in the \'OB/OS\' candle color selection. You might want to adjust these if an asset is trending strongly in one direction and you don\'t expect pullbacks in the oscillator to reach all the way back to what would normally be considered overbought or oversold. Does not actually change anything visibly on the indicator itself.')
i_low_extreme = input.string(defval='-60', options=['0', '-10', '-20', '-30', '-40', '-50', '-60', '-70', '-80'], title='Low Extreme', group='Candle Colors')
os_80 = wt_1 <= -80
os_70 = wt_1 <= -70
os_60 = wt_1 <= -60
os_50 = wt_1 <= -50
os_40 = wt_1 <= -40
os_30 = wt_1 <= -30
os_20 = wt_1 <= -20
os_10 = wt_1 <= -10
os_0 = wt_1 <= 0
ob_0 = wt_1 >= 0
ob_10 = wt_1 >= 10
ob_20 = wt_1 >= 20
ob_30 = wt_1 >= 30
ob_40 = wt_1 >= 40
ob_50 = wt_1 >= 50
ob_60 = wt_1 >= 60
ob_70 = wt_1 >= 70
ob_80 = wt_1 >= 80
low_extreme = i_low_extreme == '0' ? os_0 : i_low_extreme == '-10' ? os_10 : i_low_extreme == '-20' ? os_20 : i_low_extreme == '-30' ? os_30 : i_low_extreme == '-40' ? os_40 : i_low_extreme == '-50' ? os_50 : i_low_extreme == '-60' ? os_60 : i_low_extreme == '-70' ? os_70 : i_low_extreme == '-80' ? os_80 : na
high_extreme = i_high_extreme == '0' ? ob_0 : i_high_extreme == '10' ? ob_10 : i_high_extreme == '20' ? ob_20 : i_high_extreme == '30' ? ob_30 : i_high_extreme == '40' ? ob_40 : i_high_extreme == '50' ? ob_50 : i_high_extreme == '60' ? ob_60 : i_high_extreme == '70' ? ob_70 : i_high_extreme == '80' ? ob_80 : na
//COLOR INPUTS
cc_1_up = input.color(color.new(#ff9800, 0), title='WT 1 Up', group='Candle Colors')
cc_1_down = input.color(color.new(#2962ff, 0), title='WT 1 Down', group='Candle Colors')
cc_1_neut = input.color(color.new(#787b86, 0), title='WT 1 Neutral', group='Candle Colors')
cc_1_color = color.from_gradient(wt_1, -60, 60, cc_1_down, cc_1_up)
cc_2_color = wt_1 > 0 ? cc_1_up : cc_1_down
cc_3_color = high_extreme ? cc_1_up : low_extreme ? cc_1_down : cc_1_neut
cc_2_up = input.color(color.new(#00bcd4, 0), title='WT 2 Up', group='Candle Colors')
cc_2_down = input.color(color.new(#e91e63, 0), title='WT 2 Down', group='Candle Colors')
cc_4_color = color.from_gradient(wt_2, -60, 60, cc_2_down, cc_2_up)
cc_5_color = wt_2 > 0 ? cc_2_up : cc_2_down
cc_selection = i_cc_selection == 'WT 1 Gradient' ? cc_1_color : i_cc_selection == 'WT 1 Center Line' ? cc_2_color : i_cc_selection == 'WT 1 Extremes' ? cc_3_color : i_cc_selection == 'WT 2 Gradient' ? cc_4_color : i_cc_selection == 'WT 2 Center Line' ? cc_5_color : na
barcolor(candle_color ? cc_selection : na, title='Colored Candles')
////////////////////////////////////////////////////////////////////////////////
////HORIZONTAL LINES & OB/OS REGIONS
wto_2_overbought = hline(80, color=#ef5350, linestyle=hline.style_dotted, title='80')
wto_1_overbought = hline(60, color=#ef5350, linestyle=hline.style_dotted, title='60')
uline40 = hline(40, color=#787b86, linestyle=hline.style_dotted, title='40')
uline20 = hline(20, color=#787b86, linestyle=hline.style_dotted, title='20')
median = hline(0, color=#787b86, linestyle=hline.style_dashed, title='Median')
dline20 = hline(-20, color=#787b86, linestyle=hline.style_dotted, title='-20')
dline40 = hline(-40, color=#787b86, linestyle=hline.style_dotted, title='-40')
wto_1_oversold = hline(-60, color=#2196f3, linestyle=hline.style_dotted, title='-60')
wto_2_oversold = hline(-80, color=#2196f3, linestyle=hline.style_dotted, title='-80')
fill_col_upper = input.color(color.new(#ff5252, 85), title='Overbought Fill Color', group='Oscillator Extremes')
fill_col_lower = input.color(color.new(#2196f3, 85), title='Oversold Fill Color', group='Oscillator Extremes')
fill(wto_2_overbought, wto_1_overbought, color=fill_col_upper, title='Overbought Region')
fill(wto_2_oversold, wto_1_oversold, color=fill_col_lower, title='Oversold Region')
////////////////////////////////////////////////////////////////////////////////
////DIVERGENCES
i_div_select = input.string(defval='Wavetrend 1', options=['Wavetrend 1', 'Wavetrend 2'], title='Source Select for Divergences', group='Divergences')
div_select = i_div_select == 'Wavetrend 1' ? wt_1 : i_div_select == 'Wavetrend 2' ? wt_2 : na
lkbk_right = input.int(title='Pivot Lookback Right', defval=5, group='Divergences')
lkbk_left = input.int(title='Pivot Lookback Left', defval=5, group='Divergences')
max_range = input.int(title='Max of Lookback Range', defval=60, group='Divergences')
min_range = input.int(title='Min of Lookback Range', defval=5, group='Divergences')
plot_bull = input.bool(title='Bull?', defval=true, group='Divergences')
plot_hdn_bull = input.bool(title='Hidden Bull?', defval=false, group='Divergences')
plot_bear = input.bool(title='Bear?', defval=true, group='Divergences')
plot_hdn_bear = input.bool(title='Hidden Bear?', defval=false, group='Divergences')
////COLOR INPUTS
c_bull = input.color(color.new(color.blue, 0), title='Bull', inline='bull div', group='Divergences')
c_hdn_bull = input.color(color.new(color.yellow, 0), title='Hidden Bull', inline='bull div', group='Divergences')
c_bear = input.color(color.new(color.red, 0), title='Bear', inline='bear div', group='Divergences')
c_hdn_bear = input.color(color.new(color.fuchsia, 0), title='Hidden Bear', inline='bear div', group='Divergences')
c_text = input.color(color.new(color.white, 0), title='Text ', inline='text', group='Divergences')
c_na = color.new(color.white, 100)
pl_found = na(ta.pivotlow(div_select, lkbk_left, lkbk_right)) ? false : true
ph_found = na(ta.pivothigh(div_select, lkbk_left, lkbk_right)) ? false : true
_inRange(cond) =>
bars = ta.barssince(cond == true)
min_range <= bars and bars <= max_range
////
// Bullish
// Osc: Higher Low
osc_hl = div_select[lkbk_right] > ta.valuewhen(pl_found, div_select[lkbk_right], 1) and _inRange(pl_found[1])
// Price: Lower Low
price_ll = low[lkbk_right] < ta.valuewhen(pl_found, low[lkbk_right], 1)
bull_cond = plot_bull and price_ll and osc_hl and pl_found
plot(pl_found ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Bull', linewidth=1, color=bull_cond ? c_bull : c_na)
plotshape(bull_cond ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Bullish Label', text=' Bull ', style=shape.labelup, location=location.absolute, color=c_bull, textcolor=c_text, display=display.none)
////
// Hidden Bullish
// Osc: Lower Low
osc_ll = div_select[lkbk_right] < ta.valuewhen(pl_found, div_select[lkbk_right], 1) and _inRange(pl_found[1])
// Price: Higher Low
price_hl = low[lkbk_right] > ta.valuewhen(pl_found, low[lkbk_right], 1)
hdn_bull_cond = plot_hdn_bull and price_hl and osc_ll and pl_found
plot(pl_found ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Hidden Bull', linewidth=1, color=hdn_bull_cond ? c_hdn_bull : c_na)
plotshape(hdn_bull_cond ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Hidden Bullish Label', text=' H. Bull ', style=shape.labelup, location=location.absolute, color=c_bull, textcolor=c_text, display=display.none)
////
// Bearish
// Osc: Lower High
osc_lh = div_select[lkbk_right] < ta.valuewhen(ph_found, div_select[lkbk_right], 1) and _inRange(ph_found[1])
// Price: Higher High
price_hh = high[lkbk_right] > ta.valuewhen(ph_found, high[lkbk_right], 1)
bear_cond = plot_bear and price_hh and osc_lh and ph_found
plot(ph_found ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Bear', linewidth=1, color=bear_cond ? c_bear : c_na)
plotshape(bear_cond ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Bearish Label', text=' Bear ', style=shape.labeldown, location=location.absolute, color=c_bear, textcolor=c_text, display=display.none)
////
// Hidden Bearish
// Osc: Higher High
osc_hh = div_select[lkbk_right] > ta.valuewhen(ph_found, div_select[lkbk_right], 1) and _inRange(ph_found[1])
// Price: Lower High
price_lh = high[lkbk_right] < ta.valuewhen(ph_found, high[lkbk_right], 1)
hdn_bear_cond = plot_hdn_bear and price_lh and osc_hh and ph_found
plot(ph_found ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Hidden Bear', linewidth=1, color=hdn_bear_cond ? c_hdn_bear : c_na)
plotshape(hdn_bear_cond ? div_select[lkbk_right] : na, offset=-lkbk_right, title='Hidden Bearish Label', text=' H. Bear ', style=shape.labeldown, location=location.absolute, color=c_bear, textcolor=c_text, display=display.none)
////////////////////////////////////////////////////////////////////////////////
//ALERT CONDITIONS
alertcondition(ta.cross(wt_1, -80), title='Primary WTO -80 Cross', message='Primary WTO has crossed the -80 line.')
alertcondition(ta.crossunder(wt_1, -60), title='Primary WTO Cross into Oversold Zone', message='Primary WTO has crossed into oversold zone.')
alertcondition(ta.cross(wt_1, 80), title='Primary WTO 80 Cross', message='Primary WTO has crossed the 80 line.')
alertcondition(ta.crossover(wt_1, 60), title='Primary WTO Cross into Overbought Zone', message='Primary WTO has crossed into overbought zone.')
alertcondition(ta.cross(wt_1, wt_2), title='Primary WTO Crossing Secondary WTO', message='Primary WTO has crossed Secondary WTO.')
alertcondition(ta.cross(wt_1, 0), title='Primary WTO Centerline Cross', message='Primary WTO has crossed the centerline.')
alertcondition(ta.cross(wt_2, 0), title='Secondary WTO Centerline Cross', message='Secondary WTO has crossed the centerline.')
alertcondition(bull_cond, title='Bull Div', message='Wavetrend Oscillator bull div')
alertcondition(hdn_bull_cond, title='Hidden Bull Div', message='Wavetrend Oscillator hidden bull div')
alertcondition(bear_cond, title='Bear Div', message='Wavetrend Oscillator bear div')
alertcondition(hdn_bear_cond, title='Hidden Bear Div', message='Wavetrend Oscillator hidden bear div')