If anyone can convert this to meta 4 its appreciated.. its just placing a trend line with a adjustable setting of deviation for a stop loss
//@version=5
indicator("Trendline Deviation Stop-Loss", overlay=true)
// Define trajectory anchor points
time1 = timestamp(2025, 03, 24, 11, 00)
time2 = timestamp(2025, 03, 31, 23, 59)
price1 = 1.08584
price2 = 1.0398
// Calculate slope
slope = (price2 - price1) / (time2 - time1)
trendline = price1 + slope * (timenow - time1)
// Deviation calculation
atrLength = input(14, "ATR Length")
deviationPercent = input.float(1.5, "Deviation %", step=0.1) / 100
atrValue = ta.atr(atrLength)
deviation = deviationPercent * atrValue
topDeviation = trendline + deviation
bottomDeviation = trendline - deviation
// Plot trendline and deviation levels
plot(trendline, color=color.blue, title="Main Trendline")
plot(topDeviation, color=color.red, title="Upper Deviation Stop")
plot(bottomDeviation, color=color.green, title="Lower Deviation Stop")
// Alert condition for invalidation
invalidation = close > topDeviation or close < bottomDeviation
alertcondition(invalidation, title="Invalidation Alert", message="Price has breached the deviation stop-loss level!")
//@version=5
indicator("Trendline Deviation Stop-Loss", overlay=true)
// Define trajectory anchor points
time1 = timestamp(2025, 03, 24, 11, 00)
time2 = timestamp(2025, 03, 31, 23, 59)
price1 = 1.08584
price2 = 1.0398
// Calculate slope
slope = (price2 - price1) / (time2 - time1)
trendline = price1 + slope * (timenow - time1)
// Deviation calculation
atrLength = input(14, "ATR Length")
deviationPercent = input.float(1.5, "Deviation %", step=0.1) / 100
atrValue = ta.atr(atrLength)
deviation = deviationPercent * atrValue
topDeviation = trendline + deviation
bottomDeviation = trendline - deviation
// Plot trendline and deviation levels
plot(trendline, color=color.blue, title="Main Trendline")
plot(topDeviation, color=color.red, title="Upper Deviation Stop")
plot(bottomDeviation, color=color.green, title="Lower Deviation Stop")
// Alert condition for invalidation
invalidation = close > topDeviation or close < bottomDeviation
alertcondition(invalidation, title="Invalidation Alert", message="Price has breached the deviation stop-loss level!")
those who can, do. those who cant, talk about those who can