xmd79

session min/max support&resistance [LM]

Nov 22nd, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. //@version=5
  2.  
  3. 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)
  4.  
  5. i_session = input.session("0000-1400", title="Session", group='general setting', inline='11')
  6. i_showLabels = input.bool(true, title="Show labels", group='general setting', inline='11')
  7.  
  8. i_lineCount = input.int(2, 'Line count', group='line setting', inline='12')
  9. i_extendLines = input.bool(false, 'Extend lines', group='line setting', inline='12')
  10. i_lineThickness = input.int(2, 'Line thickness', minval=1, group='line setting', inline='13')
  11. i_lineStyle = input.string(line.style_dotted, 'Line style', options=[line.style_dotted, line.style_solid, line.style_dashed], group='line setting', inline='13')
  12. i_upColor = input.color(color.green, 'Up color', group='line setting', inline='14')
  13. i_bottomColor = input.color(color.red, 'Bottom color', group='line setting', inline='14')
  14.  
  15. var lineArray = array.new_line()
  16.  
  17. var labelArray = array.new_label()
  18.  
  19. f_drawLine(_x1, _x2, _yValue, _lineColor, _lineThickness, _lineStyle) =>
  20. line.new(x1=_x1, y1=_yValue, x2=_x2, y2=_yValue, color=_lineColor, style=_lineStyle, width=_lineThickness)
  21.  
  22. f_drawLabel(_x, _y, _textColor) =>
  23. label.new(_x, _y, '         ' + str.tostring(_y), xloc.bar_index, yloc.price, #00000000, label.style_none, _textColor)
  24.  
  25. f_extendArray(_lineArray, _labelArray, _extendLines) =>
  26. if array.size(_lineArray) > 0
  27. for _i = array.size(_lineArray) - 1 to 0 by 1
  28.  
  29. x2 = line.get_x2(array.get(_lineArray, _i))
  30. yValue = line.get_y1(array.get(_lineArray, _i))
  31.  
  32. if _extendLines or bar_index - 1 == x2 and not(high > yValue and low < yValue)
  33. if (i_showLabels)
  34. label.set_x(array.get(_labelArray, _i), bar_index)
  35. line.set_x2(array.get(_lineArray, _i), bar_index)
  36.  
  37.  
  38. f_drawLineAndLabel(_x1, _x2, _yValue, _colorLine, _lineCount, _lineThickness, _lineStyle, _array, _labelArray) =>
  39. line l = f_drawLine(_x1, _x2, _yValue, _colorLine, _lineThickness, _lineStyle)
  40.  
  41. if (i_showLabels)
  42. label lab = f_drawLabel(_x2, _yValue, _colorLine)
  43. if array.size(_labelArray) == _lineCount
  44. label.delete(array.shift(_labelArray))
  45.  
  46. array.push(_labelArray, lab)
  47.  
  48. if array.size(_array) == _lineCount
  49. line.delete(array.shift(_array))
  50.  
  51. array.push(_array, l)
  52.  
  53.  
  54. t = time(timeframe.period, i_session)
  55. bool isSessionStart = na(t[1]) and not na(t)
  56. bool isSessionEnd = na(t) and not na(t[1])
  57.  
  58. startIndex = ta.barssince(isSessionStart) + 1
  59. int length = isSessionEnd? startIndex: 1
  60.  
  61. float rangeLow = ta.lowest(low, length)
  62. int rangeLowIndex = math.abs(ta.lowestbars(low, length))
  63.  
  64. float rangeHigh = ta.highest(high, length)
  65. int rangeHighIndex = math.abs(ta.highestbars(high, length))
  66.  
  67.  
  68. if (isSessionEnd)
  69.  
  70. float yValue = na
  71. int x1 = na
  72. int x2 = na
  73.  
  74.  
  75. yValue := rangeHigh
  76. x1 := bar_index[rangeHighIndex]
  77. x2 := bar_index
  78.  
  79. f_drawLineAndLabel(x1, x2, yValue, i_upColor, i_lineCount, i_lineThickness, i_lineStyle, lineArray, labelArray)
  80.  
  81. yValue := rangeLow
  82. x1 := bar_index[rangeLowIndex]
  83.  
  84. f_drawLineAndLabel(x1, x2, yValue, i_bottomColor, i_lineCount, i_lineThickness, i_lineStyle, lineArray, labelArray)
  85.  
  86. f_extendArray(lineArray, labelArray, i_extendLines)
Advertisement
Add Comment
Please, Sign In to add comment