【发布时间】:2023-02-05 20:53:52
【问题描述】:
请帮我: 我的策略很简单。
多头头寸: signal=> 穿越“Bollinger Bound”的下限 位置触发器=> 蜡烛收盘价高于“Donchian Channels(13)” - 信号发生后
空头头寸: signal=> 穿越“Bollinger Bound”的上限 位置触发器=> 蜡烛收盘价低于“Donchian Channels(13)” - 信号发生后
给出交易信号(signalLong 或 signalLong)后,我等待触发(close>DC_basis 或 close>DC_basis)。我已经使用 ta.barsince 函数编写了这个。
signalLong := low<lower
signalShort := high>upper
since_signalLong = 0
since_signalShort = 0
since_signalLong := ta.barssince(ta.change(signalLong))
since_signalShort := ta.barssince(ta.change(signalShort))
enterLong = false
enterShort = false
enterLong := signalLong[since_signalLong+1] and close > DC_basis
enterShort := signalShort[since_signalShort+1] and close < DC_basis
但触发器被激活后,它会在所有后续蜡烛上进行交易。
如果收盘价 > DC_basis 然后执行多头头寸 (enterLong) //它检查 since_signalShort+1 根蜡烛前的信号(信号在第一次交叉后保持真实直到结束) if close < DC_basis then execute Short position (enterShort) //它检查 since_signalShort+1 根蜡烛前的信号(信号在第一次交叉后保持真实直到结束)
在我看来,这个问题是触发后信号保持“真实”。
我不知道如何在开仓后处理入市信号(enterLong 或 enterShort)。
/@version=5
strategy(title="myStrategy", overlay=true, pyramiding=10)
///////////////BB
length = input.int(20, minval=1)
src = input(close, title="Source")
mult = input.float(3.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
//plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
//fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))
///////////////BB
///////////////DC
DC_length = input.int(13, minval=1)
DC_lower = ta.lowest(DC_length)
DC_upper = ta.highest(DC_length)
DC_basis = math.avg(DC_upper, lower)
plot(DC_basis, "Basis", color=#FF6D00,linewidth = 2)
///////////////DC
signalLong= false
signalShort = false
signalLong := low<lower
signalShort := high>upper
plot(signalLong ? low :na , color=color.green,style=plot.style_cross, linewidth = 5)
plot(signalShort ? high :na , color=color.red,style=plot.style_cross, linewidth = 5)
since_signalLong = 0
since_signalShort = 0
since_signalLong := ta.barssince(ta.change(signalLong))
since_signalShort := ta.barssince(ta.change(signalShort))
enterLong = false
enterShort = false
enterLong := signalLong[since_signalLong+1] and close > DC_basis
enterShort := signalShort[since_signalShort+1] and close < DC_basis
plot(enterLong ? low :na , color=color.green,style=plot.style_circles, linewidth = 5)
plot(enterShort ? high :na , color=color.red,style=plot.style_circles, linewidth = 5)
不正确的
【问题讨论】:
标签: pine-script pine-script-v5 trading tradingview-api