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.
릴리즈 노트: somehow the alertcondition didn't make it into initial release. Thus added now.
릴리즈 노트:
  • 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.

즐겨찾기 스크립트에서 빼기 즐겨찾기 스크립트에 넣기


Hey Sir, can you explain what "Source Trailing Stop calculation" and "Source Trigger" are? i dont understand what these option do.
+9 응답
@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
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 응답
You can have both integrated Trailing Stop and Trailing Take profit, and create alerts from it.

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

Great work, very much appreciated!
wow exactly what i was looking for. Works great with trading view. THANK YOU!
+1 응답
Oh my bad for having the early WIP-strat report in here, long time no publish :O
홈으로 스탁 스크리너 포렉스 스크리너 크립토 스크리너 이코노믹 캘린더 사용안내 차트 특징 프라이싱 프렌드 리퍼하기 하우스룰(내부규정) 헬프 센터 웹사이트 & 브로커 솔루션 위젯 차팅 솔루션 라이트웨이트 차팅 라이브러리 블로그 & 뉴스 트위터
프로화일 프로화일설정 계정 및 빌링 리퍼드 프렌즈 코인 나의 서포트 티켓 헬프 센터 공개아이디어 팔로어 팔로잉 비밀메시지 채팅 로그아웃