Sorry for my english, i just started to lern pine script I make an Indicator wir support and resistance lines with some help von AI.
It works good, but i have a Problem if i want to “Reset chart view”, it is very small to show all the lines.
//@version=5
indicator("Levels", overlay=true)
// Line color option
lineColor = input(color.new(color.blue, 30), title="Line Color")
// Settings for line display
showLines = input(true, title="Show Lines", group="Levels")
// Arrays to store line IDs and their corresponding support/resistance levels
var float[] supportLevels = array.new_float()
var line[] supportLines = array.new_line()
var float[] resistanceLevels = array.new_float()
var line[] resistanceLines = array.new_line()
// Function to identify bullish and bearish candles
isBullishCandle(open, close) =>
close > open
isBearishCandle(open, close) =>
close < open
// Function to check if a bearish candle follows a bullish candle
isBearishAfterBullish() =>
isBullishCandle(open[1], close[1]) and isBearishCandle(open, close)
// Function to check if a bullish candle follows a bearish candle
isBullishAfterBearish() =>
isBearishCandle(open[1], close[1]) and isBullishCandle(open, close)
// Variable to store the new support level
var float supportLevel = na
// Check for new support levels
if showLines and isBullishAfterBearish()
supportLevel := low
array.push(supportLevels, supportLevel)
supportLineID = line.new(x1=bar_index, y1=supportLevel, x2=bar_index + 10, y2=supportLevel, color=lineColor, width=1, extend=extend.right)
array.push(supportLines, supportLineID)
// Update existing support lines and delete if broken
i = array.size(supportLevels) - 1
while i >= 0
supportLevel := array.get(supportLevels, i)
supportLineID = array.get(supportLines, i)
if (close < supportLevel)
line.delete(supportLineID)
array.remove(supportLevels, i)
array.remove(supportLines, i)
else
line.set_x2(supportLineID, bar_index + 10)
i := i - 1
// Variable to store the new resistance level
var float resistanceLevel = na
// Check for new resistance levels
if showLines and isBearishAfterBullish()
resistanceLevel := high
array.push(resistanceLevels, resistanceLevel)
resistanceLineID = line.new(x1=bar_index, y1=resistanceLevel, x2=bar_index + 10, y2=resistanceLevel, color=lineColor, width=1, extend=extend.right)
array.push(resistanceLines, resistanceLineID)
// Update existing resistance lines and delete if broken
j = array.size(resistanceLevels) - 1
while j >= 0
resistanceLevel := array.get(resistanceLevels, j)
resistanceLineID = array.get(resistanceLines, j)
if (close > resistanceLevel)
line.delete(resistanceLineID)
array.remove(resistanceLevels, j)
array.remove(resistanceLines, j)
else
line.set_x2(resistanceLineID, bar_index + 10)
j := j - 1
I tried with scaling=scaling.none, but the lines don`t follow the price.
New contributor
Karol is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.