// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.
0
at https://mozilla.org/MPL/2.0/
// © LuxmiAI
//@version=5
indicator("Intraday Trend Candles", shorttitle = "ITC", overlay=true)
// Input parameters
inpPeriod = input.int(21, title="Look Back Period", minval=1)
inpMultiplier = input.float(3.0, title="Multiplier", minval=0.1)
// inpChannelShift = input.int(1, title="Channel Shift", minval=0)
// dispMode = input.string("Bars", title="Display Mode", options=["Bars",
"Candles"])
// Variables
var float prevMax = na
var float prevMin = na
var int prevColor = na
var float line = na
var int linecl = na
// LWMA calculation function
calc_lwma(src, length) =>
sum = 0.0
weight = 0.0
for i = 0 to length - 1
sum += src[i] * (length - i)
weight += (length - i)
sum / weight
// Calculate highest, lowest, and true range
rangeHigh = ta.highest(close, inpPeriod)
rangeLow = ta.lowest(close, inpPeriod)
tr = calc_lwma(high - low, inpPeriod)
// Calculate trend limits
hiLimit = rangeHigh - tr * inpMultiplier
loLimit = rangeLow + tr * inpMultiplier
// Determine the trend line
if close > loLimit and close > hiLimit
line := hiLimit
else if close < loLimit and close < hiLimit
line := loLimit
else
line := na(line) ? close : line[1]
// Determine line color
linecl := close > line ? 1 : close < line ? 2 : linecl[1]
// Alerts for trend reversal
if na(prevColor) == false and prevColor != linecl
if prevColor == 1 and linecl == 2
alert("Bearish trend reversal!")
else if prevColor == 2 and linecl == 1
alert("Bullish trend reversal!")
prevColor := linecl
// Plot settings
plot(line, color=linecl == 1 ? color.blue : linecl == 2 ? color.yellow :
color.gray, style=plot.style_line)
candlecolor = linecl == 1 ? color.blue : linecl == 2 ? color.yellow : color.gray,
plotcandle(open, high, low, close, color = candlecolor, wickcolor = candlecolor,
bordercolor = candlecolor)