Simple Trailing stop

Since my exchange doesn't support trailing stop I made a script for it.

It is fully configurable, which means you can set the bars for calculation, the offset and sources for trigger and calculation.

The original purpose for me was to send a command to my bot. If you like it please comment and check out my other scripts.
Phát hành các Ghi chú: somehow the alertcondition didn't make it into initial release. Thus added now.
Phát hành các Ghi chú:
  • Change wording for better understanding
  • Update to newest Pinescript version 4
  • Add Option for shifting the whole thing to the right

Adjust the Options to your liking. One thing to note that using close for Trigger means that Signal can trigger though it closes above Stopline, while low can only cross once ;).
Hope it helps someone, more coming soon again.

Gỡ bỏ khỏi Script Ưa thích Add to favorite indicators

Bình luận

Hey Sir, can you explain what "Source Trailing Stop calculation" and "Source Trigger" are? i dont understand what these option do.
+9 Phản hồi
@migm, Well the first is the source that is used to draw the Trailing-Stop line. The second is the source that triggers the signal when crossing the line, which is useful if you don't want it to trigger when you use signals on close of the bar only and use close for example. That way a short dip breaking the line wouldn't trigger the signal when close gets above again afterwards.

Sorry for my bad explanation, I hope it's understandable
Phản hồi
this is very useful. Not only for the bot but for backtesting.
However, by adding this code to my simple script I get an error message "Add to Chart operation failed, reason: The script must have one study() or strategy() function call"
I'm new to pinescript, trying to learn step by step so I'd much appreciate some help :)
I believe there should be an exit() command in order to backtest with the trailing stop, right?
Here is my code, a simple EMA crossover.. I

short_ema = ema(close, 9)
long_ema = ema(close, 30)

plot(short_ema, color =red)
plot(short_ema, color =green)

entry() => crossover( short_ema, long_ema)
exit() => crossunder( short_ema, long_ema)

strategy.entry(id = "long_ma", long = true, when = entry())
strategy.close(id = "long_ma", when = exit())

+6 Phản hồi
You can have both integrated Trailing Stop and Trailing Take profit, and create alerts from it.

+1 Phản hồi
Damasta cyatophilum
@cyatophilum, true, just copy this code and do it for the other side. Would be a great Beginner level scripting example
Phản hồi
Any way to make this into a two-way stop? I.e. stops for closing longs.
+1 Phản hồi
cryptohan cryptohan
Nevermind! It was as simple as changing (1-(offset/100) to (1+(offset/100).

Great work, very much appreciated!
Phản hồi
wow exactly what i was looking for. Works great with trading view. THANK YOU!
+1 Phản hồi
Oh my bad for having the early WIP-strat report in here, long time no publish :O
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 đồ Trả phí Giới thiệu bạn Quy tắc Áp dụng Trung tâm Trợ giúp Giải pháp cho Website & Nhà môi giới Widget Giải pháp biểu đồ Thư viện Biểu đồ Lightweight Blog & Tin tức Twitter
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm 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