【问题标题】:RSI indicator with Buy Stop Order带有止损买单的 RSI 指标
【发布时间】:2020-12-08 10:01:54
【问题描述】:

我了解当价格高于当前市场价格时会出现买入止损。

我需要了解为何此处会出现买入止损单。我不太明白 RSI 信号指标如何影响买入止损?

这是代码

//if above 70 , overbought , if below 30, then oversold
strategy(title="Stop Order RSI Strategy", shorttitle="Stop Order RSI", format=format.price, precision=2)

//Inputs
i_oversold = input(30 , title="Oversold")
i_overbought = input(70 , title="Overbought")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)

//Calculations
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

//Plotting
plot(rsi, "RSI", color=#8E1599)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

goLong = rsi < i_oversold
goShort = rsi > i_overbought
strategy.entry("Buy Stop" , stop=high , when = goLong , long = true)
strategy.entry("Sell Stop" , stop=low , when = goShort , long = strategy.short)

感谢有人能花时间解释这里发生了什么,因为我很迷茫。

【问题讨论】:

  • 我已将那段代码放入策略中。它不会在该柱上产生信号。请编辑您的问题并发布整个脚本。
  • @BjornMistiaen 我已经更新并粘贴了整个脚本。非常感谢您对此进行调查。

标签: pine-script algorithmic-trading trading


【解决方案1】:

您的脚本运行正常。
这是我对您的代码的再现,在第一行添加了//@version=4,最后添加了调试部分。

//@version=4
//if above 70 , overbought , if below 30, then oversold
strategy(title="Stop Order RSI Strategy", shorttitle="Stop Order RSI", format=format.price, precision=2)

//Inputs
i_oversold = input(30 , title="Oversold")
i_overbought = input(70 , title="Overbought")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)

//Calculations
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

//Plotting
plot(rsi, "RSI", color=#8E1599)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

goLong = rsi < i_oversold
goShort = rsi > i_overbought
strategy.entry("Buy Stop" , stop=high , when = goLong , long = true)
strategy.entry("Sell Stop" , stop=low , when = goShort , long = strategy.short)

// === DEBUG ===
plotchar(rsi, "rsi", "")
plotchar(i_oversold, "i_oversold", "")
plotchar(i_overbought, "i_overbought", "")
plotchar(goLong, "goLong", "")
plotchar(goShort, "goShort", "")

当您将鼠标悬停在条形上时,调试部分会在数据窗口中显示该条上的变量值,如下所示:

11 Mar '20 上,您会看到goLong0

12 Mar '20 上,您会看到goLong 变为1
这意味着 Pine 将在 下一个 柱上做多,并在 当前 柱的 high 设置止损单。
因此,它希望在16.6427452 上做多13 Mar '20,这是12 Mar '20 的最高点。
13 Mar '20,永远不会达到这个止损价,所以不会做多。

在同一个13 Mar '20 上,您会看到goLong 仍然是1
重复相同的过程。 Pine 将在 下一个 柱上做多,并在 当前 柱的high 设置止损单。因此,它希望在12.3718699 上做多14 Mar '20,这是13 Mar '20 的最高点。
同样,在14 Mar '20 上,从未达到此止损价,因此不会做多。

14 Mar '20 上,您会看到goLong 仍然是1
同样的过程再次重复。 Pine 将在 下一个 柱上做多,并在 当前 柱的high 设置止损单。因此,它希望在11.4392802 上做多15 Mar '20,这是14 Mar '20 的最高点。
这一次,在15 Mar '20,达到了这个止损价,系统进入多头头寸。

【讨论】:

  • 感谢您的解释。但是,我发现很难理解这是如何工作的。在什么情况下会触发此买入止损?我知道当它变长时它会被触发。那么为什么 goLong = 1 时不触发呢?我还是新手,我怎么能理解发生了什么?
  • 这在我的回答中有解释。它尝试在每个goLong=1 上做多,但它只能在达到止损价时进入多头头寸。所以两个条件都必须为真才能进入long。我建议您打开数据窗口并亲自查看每个柱上的值如何变化。我想我不能比这更清楚了。
猜你喜欢
  • 1970-01-01
  • 2020-07-23
  • 2019-11-22
  • 1970-01-01
  • 2020-10-30
  • 1970-01-01
  • 1970-01-01
  • 2015-10-03
  • 2022-10-20
相关资源
最近更新 更多