# PRC_HalfTrend | indicator # 10.03.2017 # Ported by Mobius Apr 2020 input Amplitude = 3; # 3 def lowpricei; def highpricei; def lowma; def highma; def barindex = barNumber(); def nexttrend; def maxlowprice; def trend; def minhighprice; def up; def down; plot halftrend; lowpricei = Lowest(low, Amplitude); highpricei = Highest(high, Amplitude); lowma = average(low, Amplitude); highma = average(high, Amplitude); if barindex > Amplitude and nexttrend[1] == 1 { maxlowprice = Max(lowpricei, maxlowprice[1]); trend = if highma < maxlowprice[1] and close < low[1] then 1 else trend[1]; nexttrend = if highma < maxlowprice[1] and close < low[1] then 0 else nexttrend[1]; minhighprice = if highma < maxlowprice[1] and close < low[1] then highpricei else minhighprice[1]; } else if nexttrend[1] == 0 { minhighprice = Min(highpricei, minhighprice[1]); trend = if lowma > minhighprice[1] and close > high[1] then 0 else trend[1]; nexttrend = if lowma > minhighprice[1] and close > high[1] then 1 else nexttrend[1]; maxlowprice = if lowma > minhighprice[1] and close > high[1] then lowpricei else maxlowprice[1]; } else { maxlowprice = maxlowprice[1]; trend = trend[1]; nexttrend = nexttrend[1]; minhighprice = minhighprice[1]; } if trend == 0 { up = if trend[1] <> 0 then down[1] else Max(maxlowprice[1], up[1]); down = 0; } else if trend[1] <> 1 { down = up[1]; up = 0;# up[1] este era el error } else if trend == 1 { down = Min(minhighprice, down[1]); up = up[1]; } else { up =up[1]; down = down[1]; } if up > 0 { halftrend = up; } else { halftrend = down; } AssignBackgroundcolor(if close > halftrend then color.dark_GREEN else color.red); #rec countUpTrend = if up and !up[1] then 1 else if up then countUpTrend[1] + 1 else 0; #rec countDownTrend = if !down and down[1] then -1 else if !down then countDownTrend[1] - 1 else 0; #plot data = if countUpTrend > 0 then countUpTrend else countDownTrend; #AssignBackgroundColor(if data > 0 then Color.BLUE else if data < 0 then Color.RED else Color.CURRENT); #AssignBackgroundcolor(if close > halftrend then color.dark_GREEN else color.red); p.s. i originally wrote a much longer intro to this request but when i hit send, i was told my title was too long and i lost the whole thing.  that original title only had 8 words in it, as per your stated max.  if 8 is too many, it's a real pain to follow the rules and get smacked around even so.  sigh.