Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('session min/max support&resistance [LM]', shorttitle='session S/R [LM]', overlay=true, max_bars_back=5000, max_lines_count=500, max_labels_count=500)
- i_session = input.session("0000-1400", title="Session", group='general setting', inline='11')
- i_showLabels = input.bool(true, title="Show labels", group='general setting', inline='11')
- i_lineCount = input.int(2, 'Line count', group='line setting', inline='12')
- i_extendLines = input.bool(false, 'Extend lines', group='line setting', inline='12')
- i_lineThickness = input.int(2, 'Line thickness', minval=1, group='line setting', inline='13')
- i_lineStyle = input.string(line.style_dotted, 'Line style', options=[line.style_dotted, line.style_solid, line.style_dashed], group='line setting', inline='13')
- i_upColor = input.color(color.green, 'Up color', group='line setting', inline='14')
- i_bottomColor = input.color(color.red, 'Bottom color', group='line setting', inline='14')
- var lineArray = array.new_line()
- var labelArray = array.new_label()
- f_drawLine(_x1, _x2, _yValue, _lineColor, _lineThickness, _lineStyle) =>
- line.new(x1=_x1, y1=_yValue, x2=_x2, y2=_yValue, color=_lineColor, style=_lineStyle, width=_lineThickness)
- f_drawLabel(_x, _y, _textColor) =>
- label.new(_x, _y, ' ' + str.tostring(_y), xloc.bar_index, yloc.price, #00000000, label.style_none, _textColor)
- f_extendArray(_lineArray, _labelArray, _extendLines) =>
- if array.size(_lineArray) > 0
- for _i = array.size(_lineArray) - 1 to 0 by 1
- x2 = line.get_x2(array.get(_lineArray, _i))
- yValue = line.get_y1(array.get(_lineArray, _i))
- if _extendLines or bar_index - 1 == x2 and not(high > yValue and low < yValue)
- if (i_showLabels)
- label.set_x(array.get(_labelArray, _i), bar_index)
- line.set_x2(array.get(_lineArray, _i), bar_index)
- f_drawLineAndLabel(_x1, _x2, _yValue, _colorLine, _lineCount, _lineThickness, _lineStyle, _array, _labelArray) =>
- line l = f_drawLine(_x1, _x2, _yValue, _colorLine, _lineThickness, _lineStyle)
- if (i_showLabels)
- label lab = f_drawLabel(_x2, _yValue, _colorLine)
- if array.size(_labelArray) == _lineCount
- label.delete(array.shift(_labelArray))
- array.push(_labelArray, lab)
- if array.size(_array) == _lineCount
- line.delete(array.shift(_array))
- array.push(_array, l)
- t = time(timeframe.period, i_session)
- bool isSessionStart = na(t[1]) and not na(t)
- bool isSessionEnd = na(t) and not na(t[1])
- startIndex = ta.barssince(isSessionStart) + 1
- int length = isSessionEnd? startIndex: 1
- float rangeLow = ta.lowest(low, length)
- int rangeLowIndex = math.abs(ta.lowestbars(low, length))
- float rangeHigh = ta.highest(high, length)
- int rangeHighIndex = math.abs(ta.highestbars(high, length))
- if (isSessionEnd)
- float yValue = na
- int x1 = na
- int x2 = na
- yValue := rangeHigh
- x1 := bar_index[rangeHighIndex]
- x2 := bar_index
- f_drawLineAndLabel(x1, x2, yValue, i_upColor, i_lineCount, i_lineThickness, i_lineStyle, lineArray, labelArray)
- yValue := rangeLow
- x1 := bar_index[rangeLowIndex]
- f_drawLineAndLabel(x1, x2, yValue, i_bottomColor, i_lineCount, i_lineThickness, i_lineStyle, lineArray, labelArray)
- f_extendArray(lineArray, labelArray, i_extendLines)
Advertisement
Add Comment
Please, Sign In to add comment