首页 > 解决方案 > 我想将多空策略转换为多头策略

问题描述

我怎样才能使这个策略只做多头,关闭多头头寸而不是做空?

非常感谢!

//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)

标签: pine-script

解决方案


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

要关闭多头而不执行空头更改第 39 行:

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

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

在此处输入图像描述


推荐阅读