TradingView
theCrypster
7 de Mai de 2020 10:45

Percent Trailing Stop (%) - For Study Scripts 

Bitcoin / U. S. DollarKraken

Descrição

===========
Percent Trailing Stop (%) - { FOR STUDY SCRIPTS }
===========

Wow - this is an example of how to implement Alerts relating to a Trailing Stop (%) within your Study Script. It's taken a bit of effort to get this working but I think we got there!

Alerts include Open Long/Short, Trailing Stop Hit, and (the most important one) Movement of Trailing Stop! <- this is actually really quite good, by the way! :)

You can ignore the actual entry/exit orders - they're based on a simple MA cross and are therefore NOT relevant, NOT profitable and NOT recommended!

You should be using this code as a way of adding a Trailing Stop to your own scripts - hope it helps!

Set your "Open Long/Short" Alert to "Once per Bar Close" - Set your "Trailing Stop Hit" Alert to "Once per Bar" - Set your "Move TSL" Alert to "Once per Bar Close". - You're all done! Enjoy.

-----------

Good Luck and Happy Trading!

Notas de Lançamento

UPDATE - Added "plot numbers" instead of plot names to give Alerts more consistent values when triggered.
Comentários
slimer0
Amazing work. But it repaints i suppose.
slimer0
...
Arun_K_Bhaskar
@slimer0, Use barstate.isconfirmed
efficientStork57835
wow we need to make three alerts can u make it a strategy plzzz making 3 alerts is hektic
ergonap
Also, how come the shorts and longs trigger without a close a lot of the time?
ergonap
Hey, I like these. Curious, what is the point of the move TSL?
Supernova432
I think there is a issue as it only takes closing price of the candle and ignores wicks. So if the wick is quite large, there will be even higher discrepancy from the set %.
theCrypster
@Supernova432, Hey Supernova - thanks for getting in touch.

If I understand you correctly, it's actually designed to ignore wicks as you'd want your SL line to mimic close prices - not the high/low (wicks).

If we included wicks in the SL formula (instead of close price) you could end up with an SL price higher (assuming you're Long) than the bar close price, which would end up with confusion whether trading manually or (more importantly) through an auto trading bot.

Let us know if we understood your comment correctly! :)
Supernova432
@theCrypster, thankyou for the clarification. What if you plot the stoploss line after you have confirmed the candle close (using one of the tradingview functions) and once confirmed you can calculate using highest/lowest function the exact price for the stoploss line including the wicks. This will make script more accurate in my opinion, cheers
theCrypster
@Supernova432, Aah! I think I understand now - we've actually included a similar (if not the same!) SL format as the one you've mentioned within our Crypto Tipster strategy.

It looks back a certain period (defined by the user) to find the HL's from that pre-defined range, and places the SL at that high or low. We've then added a % offset to this HL price, so you can tweak and adjust the HL stop by a certain % up or down to suit your needs/requirements.

I'm not going to be publishing this script for public access. But given the info ^ you should be able to write that code for yourself!

All the best
theCrypster
Mais