// This source code is subject to the terms of the Mozilla Public License 2.
0 at
[Link]
// © HoanGhetti
//@version=5
indicator("RSI Trendlines with Breakouts [HG]", precision = 2, max_labels_count =
500, max_lines_count = 500)
import HoanGhetti/SimpleTrendlines/3 as tl
g_trendlines = 'Trendline Settings', g_conditions = 'Conditions', g_styling =
'Styling', g_timeframe = 'Timeframe'
input_timeframe = [Link](defval = '', title = 'Timeframe', group =
g_timeframe)
input_pLen = [Link](defval = 4, title = 'Lookback Range', minval = 1, group
= g_trendlines, tooltip = 'How many bars to determine when a swing high/low is
detected.')
input_rLen = [Link](defval = 14, title = 'RSI Length' , minval = 1, group =
g_trendlines)
input_rSrc = [Link](defval = close, title = 'RSI Source', group =
g_trendlines)
input_repaint = [Link](defval = 'On', title = 'Repainting', group =
g_conditions, options = ['On', 'Off: Bar Confirmation'], tooltip = 'Bar
Confirmation: Generates alerts when candle closes. (1 Candle Later)')
input_rsiDiff = [Link](defval = 3, title = 'RSI Difference', group =
g_conditions, tooltip = 'The difference between the current RSI value and the
breakout value.\n\nHow much higher in value should the current RSI be compared to
the breakout value in order to detect a breakout?')
input_rsiCol = [Link](defval = [Link], title = 'RSI Color', group =
g_styling)
input_width = [Link](defval = 2, title = 'Line Width', minval = 1, group =
g_styling)
input_lblType = [Link](defval = 'Simple', title = 'Label Type', group =
g_styling, options = ['Full', 'Simple'])
input_lblSize = [Link](defval = [Link], title = 'Label Size', group =
g_styling, options = [[Link], [Link], [Link], [Link], [Link]])
input_pLowCol = [Link](defval = [Link], title = 'Pivot Low', inline =
'col', group = g_styling)
input_pHighCol = [Link](defval = #089981, title = 'Pivot High', inline =
'col', group = g_styling)
input_override = [Link](defval = false, title = 'Override Text Color', group =
g_styling, inline = 'override')
input_overCol = [Link](defval = [Link], title = ' ', group = g_styling,
inline = 'override')
lblText = switch input_lblType
'Simple' => 'Br'
'Full' => 'Break'
repaint = switch input_repaint
'On' => true
'Off: Bar Confirmation' => false
rsi_v = [Link](input_rSrc, input_rLen)
rsi = input_timeframe == '' ? rsi_v : [Link]([Link],
input_timeframe, rsi_v, lookahead = barmerge.lookahead_on)
pl = fixnan([Link](rsi, 1, input_pLen))
ph = fixnan([Link](rsi, 1, input_pLen))
pivot(float pType) =>
pivot = pType == pl ? pl : ph
xAxis = [Link]([Link](pivot), bar_index, 0) -
[Link]([Link](pivot), bar_index, 1)
prevPivot = [Link]([Link](pivot), pivot, 1)
pivotCond = [Link](pivot) and (pType == pl ? pivot > prevPivot : pivot <
prevPivot)
pData = [Link](x_axis = xAxis, offset = input_pLen, strictMode = true,
strictType = pType == pl ? 0 : 1)
[Link](pivotCond, prevPivot, pivot, rsi)
pData
breakout([Link] this, float pType) =>
var bool hasCrossed = false
if [Link]([Link].get_y1())
hasCrossed := false
[Link](not hasCrossed)
condType = (pType == pl ? rsi < [Link].get_y2() - input_rsiDiff :
rsi > [Link].get_y2() + input_rsiDiff) and not hasCrossed
condition = repaint ? condType : condType and [Link]
if condition
hasCrossed := true
[Link].set_xy2([Link].get_x2(),
[Link].get_y2())
[Link].set_xy2(na, na)
[Link]()
[Link](
bar_index,
[Link].get_y2(),
text = lblText, color = pType == pl ? [Link](input_pLowCol, 50) :
[Link](input_pHighCol, 50),
size = input_lblSize, style = pType == pl ?
label.style_label_lower_left : label.style_label_upper_left,
textcolor = pType == pl ? (input_override ? input_overCol :
input_pLowCol) : input_override ? input_overCol : input_pHighCol)
hasCrossed
method style([Link] this, color col) =>
[Link].set_color(col)
[Link].set_width(input_width)
[Link].set_color(col)
[Link].set_width(input_width)
[Link].set_style(line.style_dashed)
plData = pivot(pl)
phData = pivot(ph)
[Link](input_pLowCol)
[Link](input_pHighCol)
cu = breakout(plData, pl)
co = breakout(phData, ph)
hline(70, title = 'Overbought', color = input_pHighCol, linestyle =
hline.style_dotted)
hline(30, title = 'Oversold', color = input_pLowCol, linestyle =
hline.style_dotted)
plot(rsi, title = 'Relative Strength Index', linewidth = 2, color = input_rsiCol)
alertcondition([Link]([Link].get_y1()), 'New Pivot Low
Trendline')
alertcondition([Link](cu) and cu, 'Pivot Low Breakout')
alertcondition([Link]([Link].get_y1()), 'New Pivot High
Trendline')
alertcondition([Link](co) and co, 'Pivot High Breakout')