在pine脚本研究中添加尾随止损

时间:2020-05-30 09:40:40

标签: pine-script

我希望在如下所示的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")

0 个答案:

没有答案