- //@version=5
- indicator('Better-Trend', overlay=true)
- amplitude = input(title='Amplitude', defval=2)
- channelDeviation = input(title='Channel Deviation', defval=2)
- showArrows = input(title='Show Arrows', defval=true)
- showChannels = input(title='Show Channels', defval=true)
- var int trend = 0
- var int nextTrend = 0
- var float maxLowPrice = nz(low[1], low)
- var float minHighPrice = nz(high[1], high)
- var float up = 0.0
- var float down = 0.0
- float atrHigh = 0.0
- float atrLow = 0.0
- float arrowUp = 1.5
- float arrowDown = 1.5
- atr2 = ta.atr(125) / 1
- dev = channelDeviation * atr2
- highPrice = high[math.abs(ta.highestbars(amplitude))]
- lowPrice = low[math.abs(ta.lowestbars(amplitude))]
- highma = ta.sma(high, amplitude)
- lowma = ta.sma(low, amplitude)
- if nextTrend == 1
- maxLowPrice := math.max(lowPrice, maxLowPrice)
- if highma < maxLowPrice and close < nz(low[1], low)
- trend := 1
- nextTrend := 0
- minHighPrice := highPrice
- minHighPrice
- else
- minHighPrice := math.min(highPrice, minHighPrice)
- if lowma > minHighPrice and close > nz(high[1], high)
- trend := 0
- nextTrend := 1
- maxLowPrice := lowPrice
- maxLowPrice
- if trend == 0
- if not na(trend[1]) and trend[1] != 0
- up := na(down[1]) ? down : down[1]
- arrowUp := up - atr2
- arrowUp
- else
- up := na(up[1]) ? maxLowPrice : math.max(maxLowPrice, up[1])
- up
- atrHigh := up + dev
- atrLow := up - dev
- atrLow
- else
- if not na(trend[1]) and trend[1] != 1
- down := na(up[1]) ? up : up[1]
- arrowDown := down + atr2
- arrowDown
- else
- down := na(down[1]) ? minHighPrice : math.min(minHighPrice, down[1])
- down
- atrHigh := down + dev
- atrLow := down - dev
- atrLow
- ht = trend == 0 ? up : down
- var color buyColor = color.blue
- var color sellColor = color.red
- htColor = trend == 0 ? buyColor : sellColor
- htPlot = plot(ht, title='HalfTrend', linewidth=2, color=htColor)
- atrHighPlot = plot(showChannels ? atrHigh : na, title='ATR High', style=plot.style_circles, color=color.new(sellColor, 0))
- atrLowPlot = plot(showChannels ? atrLow : na, title='ATR Low', style=plot.style_circles, color=color.new(buyColor, 0))
- fill(htPlot, atrHighPlot, title='ATR High Ribbon', color=color.new(sellColor, 90))
- fill(htPlot, atrLowPlot, title='ATR Low Ribbon', color=color.new(buyColor, 90))
- buySignal = not na(arrowUp) and trend == 0 and trend[1] == 1
- sellSignal = not na(arrowDown) and trend == 1 and trend[1] == 0
- plotshape(showArrows and buySignal ? atrLow : na, title='Arrow Up', style=shape.triangleup, location=location.absolute, size=size.tiny, color=color.new(buyColor, 0))
- plotshape(showArrows and sellSignal ? atrHigh : na, title='Arrow Down', style=shape.triangledown, location=location.absolute, size=size.tiny, color=color.new(sellColor, 0))
- alertcondition(buySignal, title='Alert: HalfTrend Buy', message='HalfTrend Buy')
- alertcondition(sellSignal, title='Alert: HalfTrend Sell', message='HalfTrend Sell')
- //High-Close-Low
- High = input.int(125, minval=1, title='High')
- Low = input.int(125, minval=1, title='Low')
- Close = input.int(125, minval=1, title='Close')
- //Regular MA's (Close)
- //SMA1 = input.int(20, minval=1, title='SMA1')
- //SMA2 = input.int(50, minval=1, title='SMA2')
- //SMA3 = input.int(100, minval=1, title='SMA3')
- plot(ta.sma(high, High), color=color.new(color.green, 0), linewidth=2)
- plot(ta.sma(close, Low), color=color.new(color.orange, 0), linewidth=2)
- plot(ta.sma(low, Close), color=color.new(color.red, 0), linewidth=2)
- //plot(ta.sma(close, SMA1), color=color.new(color.green, 0), linewidth=2)
- //plot(ta.sma(close, SMA2), color=color.new(color.orange, 0), linewidth=2)
- //plot(ta.sma(close, SMA3), color=color.new(color.red, 0), linewidth=2)
- basePeriods = input.int(75, minval=25, title='Period')
- donchian(len) =>
- math.avg(ta.lowest(len), ta.highest(len))
- baseLine = donchian(basePeriods)
- plot(baseLine, color=color.new(#991515, 0), title='Kijun-Sen')
[text] Better-Trend
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: