admin

Volatility Stop

15096 lượt xem
2052
15096 15
The Volatility Stop Indicator is able to define the current trend. When a downward trend is determined a red line above the prices bars is plotted; when an upward trend is determined a green line below the prices bars is plotted. These lines are generally used as trailing stops. The Volatility Stop Indicator is more used as an exit tool than an entry tool. When the price crosses the VStop value, the trend reverses and VStop moves to the other side of price.

We'd like to present you VStop indicator written in Pine Script. Please notice new Pine Script features used in this indicator: variables max_, min_, is_uptrend, vstop. We may refer to previous values of the indicator in the source code (e.g. vstop, is a vstop value on the previous bar) before the actual vstop variable definition. Enjoy and leave your comments!
Gỡ bỏ khỏi Script Ưa thích Thêm vào Script Ưa thích
study("Volatility Stop", shorttitle="VStop", overlay=true)
length = input(20)
mult = input(2)
atr_ = atr(length)
max1 = max(nz(max_[1]), close)
min1 = min(nz(min_[1]), close)
is_uptrend_prev = nz(is_uptrend[1], true)
stop = is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
vstop_prev = nz(vstop[1])
vstop1 = is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend = close - vstop1 >= 0
is_trend_changed = is_uptrend != is_uptrend_prev
max_ = is_trend_changed ? close : max1
min_ = is_trend_changed ? close : min1
vstop = is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
For better tweaking you can add
mult = input(2, type=float )
For the 3min chart I use
6 / 1.3
+4 Phản hồi
hi, could you please show me how to create an ALERT on tradingview for this code? I'm combing this with an RSI for entry and exits
+7 Phản hồi
You need to pre-declare variables in version 3. The below will work

//@version=3
study("Volatility Stop Custom", shorttitle="VStop", overlay=true)

length = input(20)
mult = input(2)

atr_ = atr(length)

max_ = 0.0
min_ = 0.0

is_uptrend = false
is_uptrend_prev = false
stop = 0.0
vstop = 0.0
vstop1 =0.0
vstop_prev = 0.0
is_trend_changed = false


max1 = max(nz(max_), close)
min1 = min(nz(min_), close)

is_uptrend_prev := nz(is_uptrend, true)
stop := is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
vstop_prev := nz(vstop)
vstop1 := is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend := close - vstop1 >= 0
is_trend_changed := is_uptrend != is_uptrend_prev

max_ := is_trend_changed ? close : max1
min_ := is_trend_changed ? close : min1

vstop := is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
+4 Phản hồi
BobHoward21 BobHoward21
@BobHoward21, Oops, forgot tradingview strips out square brackets. Correct version can be found here
+5 Phản hồi
hi
can you please convert this script to //@version=3
+3 Phản hồi
BobHoward21 anilpune
@anilpune,

//@version=3
study("Volatility Stop Custom", shorttitle="VStop", overlay=true)

length = input(20)
mult = input(2)

atr_ = atr(length)

max_ = 0.0
min_ = 0.0

is_uptrend = false
is_uptrend_prev = false
stop = 0.0
vstop = 0.0
vstop1 =0.0
vstop_prev = 0.0
is_trend_changed = false


max1 = max(nz(max_), close)
min1 = min(nz(min_), close)

is_uptrend_prev := nz(is_uptrend, true)
stop := is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
vstop_prev := nz(vstop)
vstop1 := is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend := close - vstop1 >= 0
is_trend_changed := is_uptrend != is_uptrend_prev

max_ := is_trend_changed ? close : max1
min_ := is_trend_changed ? close : min1

vstop := is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
Phản hồi
BobHoward21 anilpune
@anilpune, Oops, forgot tradingview strips out square brackets. Correct version can be found here
+1 Phản hồi
I happened to add a compiler directive "//@version=3" prior to the "study" line and it won't compile.
When I removed the compiler directive, it works!
Just wondering why ... the inquiring mind would like to know ...
Phản hồi
Trailing Stops? Over the last 4 months he was quite the "leading" indicator for the top currency pairs, including DYX. Whatever you're doing, do not stop!
Phản hồi
what's a strategy for using this ind?
+2 Phản hồi
Trang chủ Bộ lọc cổ phiếu Bộ lọc Forex Bộ lọc Tiền điện tử Lịch kinh tế Cách thức hoạt động Tính năng Biểu đồ Giá Quy tắc Áp dụng Người điều hành Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Nhận trợ giúp Yêu cầu tính năng Blog & Tin tức Câu hỏi thường gặp Wiki Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Nhận trợ giúp Các ý tưởng đã đăng Người theo dõi Đang theo dõi Tin nhắn riêng Trò chuyện Đăng xuất