You are on page 1of 1

-- https://www.tradingview.

com/script/VP32b3aR-Average-True-Range-Trailing-Stops-
Colored/
instrument { name = "ATR Trailing Stops with Arrow", overlay = true,
icon="indicators:ATR" }
period = input (14, "front.period", input.integer, 1 )
multiplier = input (2, "front.newind.multiplier", input.double, 1 )
high_low = input (false, "HighLow", input.boolean)
input_group {
"front.newind.colors",
up = input { default = "#2CAC40", type = input.color },
down = input { default = "#DB4931", type = input.color },
width = input { default = 1, type = input.line_width }
}
atr = rma (tr, period) * multiplier
h = iff (high_low, high, close)
l = iff (high_low, low, close)
atr_ts = iff(close > nz(atr_ts[1], 0) and close[1] > nz(atr_ts[1], 0),
max(nz(atr_ts[1]), h - atr),
iff(close < nz(atr_ts[1], 0) and close[1] < nz(atr_ts[1], 0), min(nz(atr_ts[1]), l
+ atr),
iff(close > nz(atr_ts[1], 0), h - atr, l + atr)))
pos = iff(close[1] < nz(atr_ts[1], 0) and close > nz(atr_ts[1], 0), 1,

iff(close[1] > nz(atr_ts[1], 0) and close < nz(atr_ts[1], 0), -1, nz(pos[1], 0)))
plot (atr_ts, "", pos < 0 and down or up , width)

buy = iff(close[1] < nz(atr_ts[1]) and close > nz(atr_ts[1]), true , false)
sell = iff(close[1] > nz(atr_ts[1]) and close < nz(atr_ts[1]), true , false)

plot_shape((buy == true), "buy", shape_style.triangleup, shape_size.large,


"green",shape_location.belowbar, 0, "BUY","green")
plot_shape((sell ==
true),"sell",shape_style.triangledown,shape_size.large,"red",shape_location.aboveba
r, 0, "SELL", "red")

You might also like