Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // © cAosX
- //@version=5
- var int MAX_BOXES = 80
- var string SENSITIVITY_TOOLTIP = "MIN = 0.01 / MAX = 1.0\nDefines how strong a signal " +
- "must be for the DivinaBox to be displayed. It is highly recommended to use it on a " +
- "chart with reliable volume data."
- var string LINE_STYLE_SOLID = "Solid"
- var string LINE_STYLE_DOTTED = "Dotted"
- var string LINE_STYLE_DASHED = "Dashed"
- resolveLineStyle(style) =>
- switch style
- LINE_STYLE_SOLID => line.style_solid
- LINE_STYLE_DOTTED => line.style_dotted
- LINE_STYLE_DASHED => line.style_dashed
- percentChange(source) =>
- ta.roc(source, 1) / 100
- indicator(
- title = "Divina - Support and Resistance",
- shorttitle = "Divina",
- overlay = true,
- max_boxes_count = MAX_BOXES,
- max_lines_count = MAX_BOXES * 4)
- sensitivityInput = input.float(
- defval = 0.1618,
- title = "Sensitivity",
- minval = 0.01,
- maxval = 1.0,
- step = 0.05,
- tooltip = SENSITIVITY_TOOLTIP)
- sourceInput = input.source(
- defval = close,
- title = "Source")
- boxBorderStyleInput = input.string(
- defval = LINE_STYLE_DASHED,
- title = "Border ",
- options = [LINE_STYLE_SOLID, LINE_STYLE_DOTTED, LINE_STYLE_DASHED],
- inline = "box",
- group = "Divina Box")
- boxBorderColorInput = input.color(
- defval = color.black,
- title = "",
- inline = "box",
- group = "Divina Box")
- boxBackgroundColorInput = input.color(
- defval = color.new(color.black, 100),
- title = "Background",
- group = "Divina Box")
- outerLinesEnabledInput = input.bool(
- defval = true,
- title = "1.618 ",
- inline = "outer_lines",
- group = "Divina Lines")
- outerLinesStyleInput = input.string(
- defval = LINE_STYLE_DOTTED,
- title = "",
- options = [LINE_STYLE_SOLID, LINE_STYLE_DOTTED, LINE_STYLE_DASHED],
- inline ="outer_lines",
- group = "Divina Lines")
- outerLinesColorInput = input.color(
- defval = color.gray,
- title = "",
- inline = "outer_lines",
- group = "Divina Lines")
- innerLinesEnabledInput = input.bool(
- defval = true,
- title = "0.618 ",
- inline = "inner_lines",
- group = "Divina Lines")
- innerLinesStyleInput = input.string(
- defval = LINE_STYLE_DOTTED,
- title = "",
- options = [LINE_STYLE_SOLID, LINE_STYLE_DOTTED, LINE_STYLE_DASHED],
- inline = "inner_lines",
- group = "Divina Lines")
- innerLinesColorInput = input.color(
- defval = color.gray,
- title = "",
- inline = "inner_lines",
- group = "Divina Lines")
- volumeChange = percentChange(volume)
- priceChange = percentChange(sourceInput)
- priceVolumeRatio = math.abs(priceChange / volumeChange)
- condition = priceVolumeRatio >= sensitivityInput
- hi = condition ? high : na
- lo = condition ? low : na
- phiRange = math.rphi * (hi - lo)
- var box[] divinaBoxList = array.new_box(1)
- var line[] divinaInnerTopList = array.new_line(1)
- var line[] divinaInnerBottomList = array.new_line(1)
- var line[] divinaOuterTopList = array.new_line(1)
- var line[] divinaOuterBottomList = array.new_line(1)
- if barstate.isconfirmed and not na(hi) and not na(lo)
- array.push(divinaBoxList, box.new(
- left = bar_index,
- top = hi,
- right = bar_index + 1,
- bottom = lo,
- bgcolor = boxBackgroundColorInput,
- border_color = boxBorderColorInput,
- border_style = resolveLineStyle(boxBorderStyleInput)))
- if array.size(divinaBoxList) > MAX_BOXES
- box.delete(array.shift(divinaBoxList))
- if innerLinesEnabledInput
- array.push(divinaInnerTopList, line.new(
- x1 = bar_index,
- y1 = hi - phiRange,
- x2 = bar_index + 1,
- y2 = hi - phiRange,
- color = innerLinesColorInput,
- style = resolveLineStyle(innerLinesStyleInput)))
- array.push(divinaInnerBottomList, line.new(
- x1 = bar_index,
- y1 = lo + phiRange,
- x2 = bar_index + 1,
- y2= lo + phiRange,
- color = innerLinesColorInput,
- style = resolveLineStyle(innerLinesStyleInput)))
- if array.size(divinaInnerTopList) > MAX_BOXES
- line.delete(array.shift(divinaInnerTopList))
- line.delete(array.shift(divinaInnerBottomList))
- if outerLinesEnabledInput
- array.push(divinaOuterTopList, line.new(
- x1 = bar_index,
- y1 = hi + phiRange,
- x2 = bar_index + 1,
- y2 = hi + phiRange,
- color = outerLinesColorInput,
- style = resolveLineStyle(outerLinesStyleInput)))
- array.push(divinaOuterBottomList, line.new(
- x1 = bar_index,
- y1 = lo - phiRange,
- x2 = bar_index + 1,
- y2 = lo - phiRange,
- color = outerLinesColorInput,
- style = resolveLineStyle(outerLinesStyleInput)))
- if array.size(divinaOuterTopList) > MAX_BOXES
- line.delete(array.shift(divinaOuterTopList))
- line.delete(array.shift(divinaOuterBottomList))
- int(na)
- else
- box.set_right(array.get(divinaBoxList, array.size(divinaBoxList) - 1), bar_index)
- if innerLinesEnabledInput
- line.set_x2(array.get(divinaInnerTopList, array.size(divinaInnerTopList) - 1), bar_index)
- line.set_x2(array.get(divinaInnerBottomList, array.size(divinaInnerBottomList) - 1), bar_index)
- if outerLinesEnabledInput
- line.set_x2(array.get(divinaOuterTopList, array.size(divinaOuterTopList) - 1), bar_index)
- line.set_x2(array.get(divinaOuterBottomList, array.size(divinaOuterBottomList) - 1), bar_index)
- int(na)
Advertisement
Add Comment
Please, Sign In to add comment