Trailing SL Alerts
"Trailing SL Alerts [QuantNomad]" by QuantNomad, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Trailing SL Alerts [QuantNomad] (v1.0), read 2026-11-15T18:51:32.114Z; source language v4.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
Trailing SL Alerts [QuantNomad] by QuantNomad, ported from Pine v4. Overlay indicator with 1 plot, 2 marker series, alerts and 5 inputs.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// (Notice added by FloSignals: the author's source carries none. It was published open-source on 2020-03-03; since 2019-07-26 the platform it was published on has released such a script under MPL-2.0 automatically.)
// ------------------------------------------------------------------------------------------------
// Original author: QuantNomad
// Original title: Trailing SL Alerts [QuantNomad]
// Licence: MPL-2.0 (the notice above was added by FloSignals; the original carries none)
// Pine version: 4
// Fetched: 2026-11-15
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
// Converted by the FloScript converter from a Pine-compatible v4 source.
indicator(title="Trailing SL Alerts", shorttitle="TrSL Alerts [QN]", overlay=true)
////////////
// Inputs //
sl_type = input.string("%", options=["%", "ATR", "Absolute"])
sl_perc = input.float(4, title="% SL")
atr_length = input(10, title="ATR Length")
atr_mult = input.float(2, title="ATR Mult")
sl_absol = input.float(10, title="Absolute SL")
//////////////////
// CALCULATIONS //
// SL values
sl_val = sl_type == "ATR" ? atr_mult * ta.atr(atr_length) : sl_type == "Absolute" ? sl_absol : close * sl_perc / 100
// Init Variables
pos = 0
trailing_sl = 0.0
// Signals
long_signal = nz(pos[1]) != 1 and high > nz(trailing_sl[1])
short_signal = nz(pos[1]) != -1 and low < nz(trailing_sl[1])
// Calculate SL
trailing_sl := short_signal ? high + sl_val : long_signal ? low - sl_val : nz(pos[1]) == 1 ? math.max(low - sl_val, nz(trailing_sl[1])) : nz(pos[1]) == -1 ? math.min(high + sl_val, nz(trailing_sl[1])) : nz(trailing_sl[1])
// Position var
pos := long_signal ? 1 : short_signal ? -1 : nz(pos[1])
//////////////
// PLOTINGS //
plot(trailing_sl, linewidth=2, color=pos == 1 ? color.green : color.red)
plotshape(long_signal, color=color.green, style=shape.arrowup, location=location.abovebar, text="Long")
plotshape(short_signal, color=color.red, style=shape.arrowdown, location=location.belowbar, text="Short")
////////////
// Alerts //
alertcondition(long_signal, "SL Long", "SL Long")
alertcondition(short_signal, "SL Short", "SL Short")
This file is under the Mozilla Public License 2.0; it is a port of the original by QuantNomad, with the original licence header kept and the changes made for FloScript noted in the file.
- v1
Library refresh 2026-11-15
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.