Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- //
- indicator(shorttitle='WT_mtf', title='WaveTrend mtf', overlay=false)
- n1 = input(14)
- n2 = input(14)
- reaction_wt = input.int(defval=1, title='reaction', minval=1)
- nsc = input(50)
- nsv = input(-50)
- upper = input(true)
- lower = input(true)
- red = #FF0000
- green = #0AAC00
- ap = input(close)
- esa = ta.ema(ap, n1)
- d = ta.ema(math.abs(ap - esa), n1)
- ci = (ap - esa) / (0.015 * d)
- tci = ta.ema(ci, n2)
- wt1 = tci
- wt2 = ta.sma(wt1, 4)
- direction = 0
- direction := ta.rising(wt1, reaction_wt) ? 1 : ta.falling(wt1, reaction_wt) ? -1 : nz(direction[1])
- cambio_direccion = ta.change(direction, 1)
- pcol = direction > 0 ? green : direction < 0 ? red : na
- plot(wt1, title='WT', color=pcol, linewidth=2, style=plot.style_line, transp=0)
- plot(0)
- midpoint = (nsc + nsv) / 2
- ploff = (nsc - midpoint) / 8
- down = ta.crossunder(wt1, wt2) and wt1 >= nsc and upper == true
- up = ta.crossover(wt1, wt2) and wt1 <= nsv and lower == true
- //
- plot(down ? wt2[1] + ploff : na, style=plot.style_cross, color=color.new(red, 0), linewidth=3)
- plot(up ? wt2[1] - ploff : na, style=plot.style_cross, color=color.new(green, 0), linewidth=3)
- //
- // —————————— Inputs
- // ————— Upper TF we will be fetching data from.
- higherTf = input.timeframe('240', 'Interval used for security() calls')
- // ————— Source we will be fetching from higher TF.
- data = wt1
- data1 = wt2
- // —————————— Determine if current interval is smaller that higher timeframe interval selected in Inputs.
- // Get higher interval in ms, using only the smallest values retrieved,
- // since occasional situations generate higher than normal intervals.
- higherTfInt = 10e20
- higherTfInt := math.min(request.security(syminfo.tickerid, higherTf, ta.change(time)), nz(higherTfInt[1], 10e20))
- // Get current interval in ms.
- currentTfInt = 10e20
- currentTfInt := math.min(ta.change(time), nz(currentTfInt[1], 10e20))
- // Compare current and higher TF to make sure it is smaller, otherwise our plots don't make sense.
- chartOnLowerTf = currentTfInt < higherTfInt
- // ————— Find out if higher TF < 1D because we will then append " min" to warning label text.
- tfIsintraday = request.security(syminfo.tickerid, higherTf, timeframe.isintraday)
- sec1ft = request.security(syminfo.tickerid, higherTf, data[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
- sec1ft1 = request.security(syminfo.tickerid, higherTf, data1[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
- //
- down1 = ta.crossunder(sec1ft, sec1ft1) and sec1ft >= nsc and upper == true
- up1 = ta.crossover(sec1ft, sec1ft1) and sec1ft <= nsv and lower == true
- //
- direction1 = 0
- direction1 := ta.rising(sec1ft, reaction_wt) ? 1 : ta.falling(sec1ft, reaction_wt) ? -1 : nz(direction1[1])
- cambio_direccion1 = ta.change(direction1, 1)
- pcol1 = direction1 > 0 ? green : direction1 < 0 ? red : na
- plot(sec1ft, color=pcol1, linewidth=2, style=plot.style_line, transp=0)
- plot(down1 ? sec1ft1[1] + ploff : na, style=plot.style_circles, color=color.new(red, 0), linewidth=5)
- plot(up1 ? sec1ft1[1] - ploff : na, style=plot.style_circles, color=color.new(green, 0), linewidth=5)
- //
- /////// Alerts /////
- alertcondition(down, title='down')
- alertcondition(up, title='up')
- alertcondition(down1, title='down1')
- alertcondition(up1, title='up1')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement