我想将长短策略转变为长策略

时间:2020-11-03 16:14:30

标签: pine-script

我如何才能长期做这种策略,关闭多头头寸而不是做空呢?

非常感谢!

//Noro
//2019

//@version=3
strategy(title = "Noro's TrendTrader Strategy v1.0", shorttitle = "TT str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings

len        = input(21, minval=1)

mult       = input(3, minval=1)

//Line

atr        = wma(atr(1), len)

highestC   = highest(len)

lowestC    = lowest(len)

hiLimit    = highestC[1] - (atr[1] * mult)

loLimit    = lowestC[1] + (atr[1] * mult)

ret = 0.0

ret := close > hiLimit and close > loLimit ? hiLimit : close < loLimit and close < hiLimit ? loLimit : nz(ret[1])

plot(ret, color= blue , title = "Trend Trader")

//Trading

if low > ret and close < open

    strategy.entry("L", strategy.long)

if high < ret and close > open

    strategy.entry("S", strategy.short)

1 个答案:

答案 0 :(得分:0)

您的策略在满足条件(high < ret and close > open时执行空头头寸,并自动平仓多头头寸。

要长期关闭而不是短暂执行,请更改第39行:

strategy.entry("S", strategy.short)

strategy.close("L", when = high < ret and close > open)

enter image description here