Я хочу добавить стоп-лосс, а также трейлинг-стоп-лосс к исследованию сценария Pine, показанному ниже (первоначально предоставленному @quantnomad). Код работает идеально, но скользящий стоп-лосс повысил бы коэффициент прибыльности.
//@version=3
study("Kozlod - Channel Break Out Alerts", overlay=true)
//
// author: Kozlod
// date: 2018-03-16
//
// Params
length = input(title="Length", type=integer, minval=1, maxval=1000, defval=5)
// Calculate up/down bound
upBound = highest(high, length)
downBound = lowest(low, length)
// Initial signals
up = upBound > upBound[1]
down = downBound < downBound[1]
// Filter out signals if oposite signal is also on
up_filt = up and not down
down_filt = down and not up
// Filter out consecutive signals
prev = 0
prev := up_filt ? 1 : down_filt ? -1 : prev[1]
up_final = up_filt and prev[1] == -1
down_final = down_filt and prev[1] == 1
//////////////
// PLOTTING //
//////////////
plot(upBound, color = green)
plot(downBound, color = red)
plotshape(up_final, style = shape.arrowup, color = blue, location = location.belowbar)
plotshape(down_final, style = shape.arrowdown, color = red, location = location.abovebar)
// Create custom alserts
alertcondition(up_final, "up", "up")
alertcondition(down_final, "down", "down")