There are several implementations of stop-losses, but in general, there are not so many special ones. The Chandelier Exit is the exception to this rule if you ask me.
This script uses the highest high and lowest low values combined with the ATR to calculate a stop-loss line. It also has the ability to produce buying signals, but those are less accurate for some strange reason.
The following script is a copy and paste ready, so you can simply copy this script and paste it inside the script editor to make it work.
Code: Select all
v = Input('Length',22,1,99) -- Inputfield, value 22, range 1-99
at = Input('ATR',22,1,99) -- Inputfield, value 22, range 1-99
m = Input('Multiplier',5,2,99)
hp = GetHighPrices()
lp = GetLowPrices()
cp = GetPrices()
hv = GetHigh(hp, view);
lv = GetLow(lp, view);
p = cp
y = ATR(hp, lp, cp, at);
x = m * y;
cl = hv - x
cs = lv + x
Plot('Price', p, 1, Yellow)
Plot('Long', cl, 1, Red)
Plot('Short', cs, 1, Green)
if (p <= cl) then
LongBuy() -- Signal a buy/long
if (p >= cs) then
ShortSell() -- Signal a sell/short
This indicator is called a stoploss for a reason. It is really perfect to decide when to sell your asset into spot trading or when to go short on leverage trading.
When you look to the used logic then it is noticeable this shares some basic similarities with the ichimoku-cloud which also uses the highest high and lowest low. The ATR is used in this case as well and in this case, it is used as a weight to the lines. This weight setup here can be a good inspiration for other indicators.
Please feel free to leave a comment on how you like this script (or not) and how you think it can be improved.