xmd79

Vortex indicator cross support&resistance [LM]

Nov 22nd, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. //@version=5
  2. indicator(title = "Vortex indicator cross support&resistance [LM]", shorttitle="VI S/R [LM]", overlay=true, format=format.price, precision=4)
  3.  
  4. i_period = input.int(56, title="Length", minval=2, group='general setting', inline='11')
  5. i_showLabels = input.bool(true, title="Show labels", group='general setting', inline='11')
  6.  
  7. i_lineCount = input.int(10, 'Line count', group='line setting', inline='12')
  8. i_extendLines = input.bool(false, 'Extend lines', group='line setting', inline='12')
  9. i_lineThickness = input.int(2, 'Line thickness', minval=1, group='line setting', inline='13')
  10. i_lineStyle = input.string(line.style_dotted, 'Line style', options=[line.style_dotted, line.style_solid, line.style_dashed], group='line setting', inline='13')
  11. i_crossoverColor = input.color(color.green, 'Crossover color', group='line setting', inline='14')
  12. i_crossunderColor = input.color(color.red, 'Bottom color', group='line setting', inline='14')
  13.  
  14. var lineArray = array.new_line()
  15.  
  16. var labelArray = array.new_label()
  17.  
  18. f_drawLine(_x1, _x2, _yValue, _lineColor, _lineThickness, _lineStyle) =>
  19. line.new(x1=_x1, y1=_yValue, x2=_x2, y2=_yValue, color=_lineColor, style=_lineStyle, width=_lineThickness)
  20.  
  21. f_drawLabel(_x, _y, _textColor) =>
  22. label.new(_x, _y, '         ' + str.tostring(_y), xloc.bar_index, yloc.price, #00000000, label.style_none, _textColor)
  23.  
  24. f_extendArray(_lineArray, _labelArray, _extendLines) =>
  25. if array.size(_lineArray) > 0
  26. for _i = array.size(_lineArray) - 1 to 0 by 1
  27.  
  28. x2 = line.get_x2(array.get(_lineArray, _i))
  29. yValue = line.get_y1(array.get(_lineArray, _i))
  30.  
  31. if _extendLines or bar_index - 1 == x2 and not(high > yValue and low < yValue)
  32. if (i_showLabels)
  33. label.set_x(array.get(_labelArray, _i), bar_index)
  34. line.set_x2(array.get(_lineArray, _i), bar_index)
  35.  
  36.  
  37. f_drawLineAndLabel(_x1, _x2, _yValue, _colorLine, _lineCount, _lineThickness, _lineStyle, _array, _labelArray) =>
  38. line l = f_drawLine(_x1, _x2, _yValue, _colorLine, _lineThickness, _lineStyle)
  39.  
  40. if (i_showLabels)
  41. label lab = f_drawLabel(_x2, _yValue, _colorLine)
  42. if array.size(_labelArray) == _lineCount
  43. label.delete(array.shift(_labelArray))
  44.  
  45. array.push(_labelArray, lab)
  46.  
  47. if array.size(_array) == _lineCount
  48. line.delete(array.shift(_array))
  49.  
  50. array.push(_array, l)
  51.  
  52. f_tema(_source, _lenght) =>
  53. ema01 = ta.ema(_source, _lenght)
  54. ema02 = ta.ema(ema01 , _lenght)
  55. ema03 = ta.ema(ema02 , _lenght)
  56. output = (3 * (ema01 - ema02) + ema03)
  57.  
  58. vmp = math.sum( math.abs( high - low[1]), i_period )
  59. vmm = math.sum( math.abs( low - high[1]), i_period )
  60. str = math.sum( ta.atr(1), i_period )
  61. vip = f_tema(vmp / str, i_period)
  62. vim = f_tema(vmm / str, i_period)
  63.  
  64.  
  65. hasCrossedUnder = ta.crossunder(vip,vim)
  66. hasCrossedOver = ta.crossover(vip,vim)
  67.  
  68.  
  69. if (hasCrossedUnder)
  70.  
  71. float yValue = low
  72. int x1 = bar_index
  73. int x2 = bar_index
  74.  
  75. f_drawLineAndLabel(x1, x2, yValue, i_crossunderColor, i_lineCount, i_lineThickness, i_lineStyle, lineArray, labelArray)
  76.  
  77. if (hasCrossedOver)
  78.  
  79. float yValue = high
  80. int x1 = bar_index
  81. int x2 = bar_index
  82.  
  83. f_drawLineAndLabel(x1, x2, yValue, i_crossoverColor, i_lineCount, i_lineThickness, i_lineStyle, lineArray, labelArray)
  84.  
  85. f_extendArray(lineArray, labelArray, i_extendLines)
Advertisement
Add Comment
Please, Sign In to add comment