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.
Nov 14
Phát hành các Ghi chú: somehow the alertcondition didn't make it into initial release. Thus added now.
Gỡ bỏ khỏi Script Ưa thích Thêm vào Script Ưa thích

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
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
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
Great help thanks!

I created a script which is working flawlessly on Tradingview so I wanted to create alert notifications. Buy order is coming after certain conditions get satisfied and I'm creating an alter through alertcondition() function, as follows

//Buy Condition
Buy = condition1 and condition2 and testrange
alertcondition(BuyCond, title = "Buy Signal", message = "Buy Signal Alert")

I'm stuck in the sell order alert notification as I'm using strategy.exit() which has stop, trail_points and trail_offset. So the strategy either hits stop-loss or it starts trailing from a certain percentage with an offset.

//Exit Strategy
strategy.exit("TP/SL", "Enter Long", stop=StopLoss * (1 - sl_inp),
trail_points = close * TrailPer / syminfo.mintick,
trail_offset = close * TrailOffset / syminfo.mintick)

I can't use alertfunction() here as the trailing stoploss and offset are both defined in strategy.exit function. So how can I set up an alert notification for the exit? Please help!
Phản hồi
You can have both integrated Trailing Stop and Trailing Take profit, and create alerts from it.

Phản hồi
wow exactly what i was looking for. Works great with trading view. THANK YOU!
Phản hồi
what do you mean "send a command" to your bot?

How would this fix your exchange not supporting stop loss?
Phản hồi
Kingii91 TheCryptoLabs
@TheCryptoLabs, you can use autoview to send alerts to whatever exchange you're using to buy and sell assets with certain triggers. This way you can completely automate an algorithmic strategy through tradingview
+2 Phản hồi
@Kingii91, not the only way at all. You can use email alerts to send order to many automated trading bot systems like gunbot haasbot and others
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á 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 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