HalfTrend
"HalfTrend [everget]" by everget, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: HalfTrend [everget] (v3.0), read 2026-11-15T18:29:01.407Z; source language v6.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
HalfTrend [everget] by everget, ported from Pine v6. Overlay indicator with 3 plots, 4 marker series, 2 fills and 5 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// (Notice added by FloSignals: the author's source carries none. It was published open-source on 2021-01-24; since 2019-07-26 the platform it was published on has released such a script under MPL-2.0 automatically.)
// Copyright (c) 2021-present, Alex Orekhov (everget)
// HalfTrend script may be freely distributed under the terms of the GPL-3.0 license.
// ------------------------------------------------------------------------------------------------
// Original author: everget
// Original title: HalfTrend [everget]
// Licence: MPL-2.0 (the notice above was added by FloSignals; the original carries none)
// Pine version: 6
// Fetched: 2026-11-15
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=6
indicator('HalfTrend', overlay=true)
const string calcGroup = 'Calculation'
amplitude = input.int(2, title='Amplitude', group=calcGroup)
channelDeviation = input.int(2, title='Channel Deviation', group=calcGroup)
const string visualGroup = 'Visuals'
showArrows = input.bool(true, title='Show Arrows', group=visualGroup)
showChannels = input.bool(true, title='Show Channels', group=visualGroup)
showLabels = input.bool(true, title='Show Buy/Sell Labels', group=visualGroup)
//---
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 = na
float arrowDown = na
atr2 = ta.atr(100) / 2
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
const color buyColor = color.blue
const color sellColor = color.red
const color textColor = color.white
const color buyFillColor = color.new(buyColor, 85)
const color sellFillColor = color.new(sellColor, 85)
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=sellColor)
atrLowPlot = plot(showChannels ? atrLow : na, title='ATR Low', style=plot.style_circles, color=buyColor)
fill(htPlot, atrHighPlot, title='ATR High Ribbon', color=sellFillColor)
fill(htPlot, atrLowPlot, title='ATR Low Ribbon', color=buyFillColor)
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=buyColor)
plotshape(showArrows and sellSignal ? atrHigh : na, title='Arrow Down', style=shape.triangledown, location=location.absolute, size=size.tiny, color=sellColor)
plotshape(showLabels and buySignal ? atrLow : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=buyColor, textcolor=textColor)
plotshape(showLabels and sellSignal ? atrHigh : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=sellColor, textcolor=textColor)
alertcondition(buySignal, title='HalfTrend Buy', message='HalfTrend Buy, {{exchange}}:{{ticker}}')
alertcondition(sellSignal, title='HalfTrend Sell', message='HalfTrend Sell, {{exchange}}:{{ticker}}')
This file is under the Mozilla Public License 2.0; it is a port of the original by everget, with the original licence header kept and the changes made for FloScript noted in the file.
- v1
Library refresh 2026-11-15
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.