0% found this document useful (0 votes)
6 views2 pages

3

This Pine Script™ code implements an 'Intraday Trend Candles' indicator for trading analysis. It calculates trend limits based on a look-back period and a multiplier, and determines trend lines and their colors based on closing prices. Alerts are generated for bullish and bearish trend reversals, and the indicator is visually represented with colored candles on the chart.

Uploaded by

h.ermenkov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

3

This Pine Script™ code implements an 'Intraday Trend Candles' indicator for trading analysis. It calculates trend limits based on a look-back period and a multiplier, and determines trend lines and their colors based on closing prices. Alerts are generated for bullish and bearish trend reversals, and the indicator is visually represented with colored candles on the chart.

Uploaded by

h.ermenkov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// 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)

You might also like