pine-script - 带有止损买单的 RSI 指标
问题描述
我了解当价格高于当前市场价格时会出现买入止损。
我需要了解为什么止损单会出现在这里。我不太明白 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)
感谢有人能花时间解释这里发生了什么,因为我很迷茫。
解决方案
您的脚本行为正确。
这是我对您的代码的再现,添加//@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
你看那goLong
是0
。
12 Mar '20
你看goLong
就变成1
了。
这意味着 Pine 将在下high
一个柱上做多,在当前柱的位置设置止损单。
因此,它希望在 高位继续13 Mar '20
做16.6427452
多12 Mar '20
。
在 上13 Mar '20
,永远不会达到这个止损价,所以它不会做多。
就那一样13 Mar '20
,你看那goLong
还是1
。
重复相同的过程。Pine 将在下high
一个柱上做多,在当前柱的位置设置止损单。因此,它希望在 高位继续14 Mar '20
做12.3718699
多13 Mar '20
。
同样,在 上14 Mar '20
,这个止损价格永远不会达到,所以它不会做多。
对14 Mar '20
了,你看那goLong
还是1
。
同样的过程再次重复。Pine 将在下high
一个柱上做多,在当前柱的位置设置止损单。因此,它希望在 高位继续15 Mar '20
做11.4392802
多14 Mar '20
。
这一次,在 上15 Mar '20
,达到此止损价,系统进入多头头寸。
推荐阅读
- wordpress - 如何改善 AMP 页面加载时间
- python - Python CSV 编写器总是冻结在同一行
- python - ValueError: Mountpoint 不能包含空格。(科拉布)
- c++ - 获取使用 std::chrono 的平均时间
- azure - 通过脚本/API 关闭 Azure 安全中心警报
- javascript - 如何将对象类型转换为json b类型?
- r - How to create a new column made of a sequence without knowning the number of repetitions - data.table
- mule - Mule Dataweave 用特定值替换 Null
- css - Arial 和 Helvetica 作为每个设备的安全网络字体
- jekyll - 如何在 Jekyll 中将时间转换为 UTC?