松脚本William RSI策略不起作用

时间:2020-05-16 22:51:35

标签: pine-script

当percentR超过-20并超过-80但我的“何时”条件不起作用时,我想做多或做空

strategy("Williams %R", shorttitle="%R", format=format.price, precision=2)
length = input(title="Length", type=input.integer, defval=14)
_pr(length) =>
    max = highest(length)
    min = lowest(length)
    100 * (close - max) / (max - min)
percentR = _pr(length)
strategy.entry("buy", strategy.long, comment="buy", when=crossover(percentR, -20))
strategy.entry("sell", strategy.short, comment="sell", when=crossunder(percentR, -80))

1 个答案:

答案 0 :(得分:0)

这似乎很好。我已将您的头寸规模更改为使用2%的股权。在某些合同价值较大的市场上,您可能需要增加启动资金才能进入头寸。

//@version=4
strategy("Williams %R", shorttitle="%R", format=format.price, precision=2, default_qty_type = strategy.percent_of_equity, default_qty_value = 2)
length = input(title="Length", type=input.integer, defval=14)
_pr(length) =>
    max = highest(length)
    min = lowest(length)
    100 * (close - max) / (max - min)
percentR = _pr(length)
strategy.entry("buy", strategy.long, comment="buy", when=crossover(percentR, -20))
strategy.entry("sell", strategy.short, comment="sell", when=crossunder(percentR, -80))
plot(percentR)
hline(-20)
hline(-80)
plotchar(crossover(percentR, -20), "crossover(percentR, -20)", "▲", location.bottom, size = size.tiny)
plotchar(crossunder(percentR, -80), "crossunder(percentR, -80)", "▼", location.top, size = size.tiny)

enter image description here