Buy sell conditions and alerts when it is above or below 0
Please see below the indicator. It is an oscillator that shows the time segmented volume. I would like to add alerts or alertcondition on it. Buy signal when the bar is above 0, and sell signal when the bar is below 0. I couldn't figure out how to do it.
Thanks for your help
// Written by liw0 active on https://www.tradingview.com/u/liw0
// corrected version by vitelot December 2018 -- no charity required
// If you decide to use my script in your published charts,
// please keep this header as it is now and leave the name unchanged!
// It would make me happy to see my script put to use in other charts :)
// If you like it I would also be happy about a small donation
// BTC 1GyfGTBsVHMbPovFGFeipe7b7ET1aebGx5
// Questions or Comments? Just send me a PM!
// CREDITS: http://quant.stackexchange.com/questions/2816/how-to-calculate-time-segmented-volume
//@version=5
indicator('Time Segmented Volume', shorttitle='TSV', overlay=false)
l = input(defval=13, title='TSV Length')
//t = sum(close>close[1]?volume*close-close[1]:close<close[1]?(volume*-1)*close-close:0,l)
// previous line is non sensical. The correct version follows
t = math.sum(close > close[1] ? volume * (close - close[1]) : close < close[1] ? volume * (close - close[1]) : 0, l)
SwapColor = t > 0 ? color.green : color.red
plot(series=t, title='TSV Histogram', color=SwapColor, style=plot.style_histogram, histbase=0, linewidth=1)
Ok. I figured it out.
if t > 0
alert(message='Buy TSE', freq=alert.freq_once_per_bar)
if t < 0
alert(message='Sell TSE', freq=alert.freq_once_per_bar)