You are on page 1of 1

//@version=5

strategy("Direction Lines with Signals", overlay=true)

// Inputs
length = input(14, title="Period")
rsiLength = input(14, title="RSI Length")
rsiOversold = input(70, title="RSI Oversold")
rsiOverbought = input(30, title="RSI Overbought")

// Calculations
price = close
emaUp = ta.ema(price, length)
emaDown = ta.ema(price, length * 2)
rsi = ta.rsi(close, rsiLength)

// Resistance and support levels


resistance = ta.max(price, length * 2)
support = ta.min(price, length * 2)

// Breakout conditions
isUpBreakout = price > resistance and price[1] <= resistance
isDownBreakout = price < support and price[1] >= support

// Plot lines
plot(emaUp, color=color.blue, linewidth=2, title="Upper Line")
plot(emaDown, color=color.red, linewidth=2, title="Lower Line")

// Plot labels
plotshape(isUpBreakout ? bar_index : na, style=shape.triangleup, color=color.green,
text="B", size=size.small)
plotshape(isDownBreakout ? bar_index : na, style=shape.triangledown,
color=color.red, text="B", size=size.small)
plotshape(price >= resistance ? bar_index : na, style=shape.labelup,
color=color.gray, text="R", size=size.small)
plotshape(price <= support ? bar_index : na, style=shape.labeldown,
color=color.gray, text="S", size=size.small)

// RSI buy/sell signals


isBuy = rsi < rsiOversold
isSell = rsi > rsiOverbought

plotshape(isBuy ? bar_index : na, style=shape.triangleup, color=color.green,


text="Buy", size=size.small)
plotshape(isSell ? bar_index : na, style=shape.triangledown, color=color.red,
text="Sell", size=size.small)

You might also like