pine-script - RSI 背离 - 更高的时间范围
问题描述
我的目标是在 m15 或 m5 中表示 H1 rsi 分歧。我不能resolution=""
在study()
函数中使用参数,因为我需要将此脚本作为策略的一部分插入。
所以我认为我需要使用security()
函数,但我不知道我必须把它们放在哪里。
这是我用于 rsi 分歧的代码:
//@version=4
study("rsi divergence", overlay=false)
//-----Input: divergence-----------------------------------------------------------\\
rsi_len = input(title="rsi len", type=input.integer, defval=14)
pivot_right = input(title="Pivot right", type=input.integer, defval=5)
pivot_left = input(title="Pivot left", type=input.integer, defval=5)
max_range = input(title="Max range", type=input.integer, defval=50)
min_range = input(title="Min range", type=input.integer, defval=5)
rsi_ob = input(title="RSI OB", type=input.integer, defval=70)
rsi_os = input(title="RSI OS", type=input.integer, defval=30)
//-----Declaration: rsi-------------------------------------------------------------\\
rsi = rsi(close, rsi_len)
//-----Plot: rsi--------------------------------------------------------------------\\
plot(rsi, title="RSI", color=color.yellow)
hline(50, linestyle=hline.style_dotted)
ob_line = hline(rsi_ob, linestyle=hline.style_dotted, color=color.white)
os_line = hline(rsi_os, linestyle=hline.style_dotted, color=color.white)
fill(ob_line, os_line, color=color.fuchsia)
//-----Check: pivot low-------------------------------------------------------------\\
pivot_low = na(pivotlow(rsi, pivot_left, pivot_right)) ? false : true
pivot_high = na(pivothigh(rsi, pivot_left, pivot_right)) ? false : true
//-----Declaration: range rsi-------------------------------------------------------------\\
confirm_range(x) =>
bars = barssince(x == true)
min_range <= bars and bars <= max_range
//-----Declaration: divergences-------------------------------------------------------------\\
//long
rsi_check_long = rsi[pivot_right] > valuewhen(pivot_low, rsi[pivot_right], 1) and confirm_range(pivot_low[1])
price_check_long = low[pivot_right] < valuewhen(pivot_low, low[pivot_right], 1)
//short
rsi_check_short = rsi[pivot_right] < valuewhen(pivot_high, rsi[pivot_right], 1) and confirm_range(pivot_high[1])
price_check_short = high[pivot_right] > valuewhen(pivot_high, high[pivot_right], 1)
//-----Conditions-------------------------------------------------------------\\
div_bullCond = price_check_long and rsi_check_long and pivot_low
div_bearCond = price_check_short and rsi_check_short and pivot_high
//-----Plot: divergences-------------------------------------------------------------\\
//long
plot(pivot_low ? rsi[pivot_right] : na, offset=-pivot_right, linewidth=3,
color=(div_bullCond ? color.green : color.new(color.white, 100)))
plotshape(div_bullCond ? rsi[pivot_right] : na, offset=-pivot_right, text=" LONG ",
style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white)
//short
plot(pivot_high ? rsi[pivot_right] : na, offset=-pivot_right, linewidth=3,
color=(div_bearCond ? color.red : color.new(color.white, 100)))
plotshape(div_bearCond ? rsi[pivot_right] : na, offset=-pivot_right, text=" SHORT ",
style=shape.labelup, location=location.absolute, color=color.red, textcolor=color.white)
解决方案
尝试这个
rsi = security(syminfo.tickerid,'60',rsi(close, rsi_len))
推荐阅读
- git - 从 git 中删除已经提交和推送的文件而不删除它
- java - 如何仅为单个 Maven 模块运行测试?
- python - 如何用 numpy 对元组数组进行切片?
- node.js - 使用构建进行部署时反应应用程序中的清单错误
- c++ - gcc 4.8 无法检查 c++ 模板中的类型转换
- java - java.lang.SecurityException:UID 10243 在 Android 10 中没有粗略/精细定位权限
- vert.x - 如何测试不等待对其消息的确认的verticle?
- python - 无法使用 python-twitter 模块验证 Twitter 凭据
- c - 如何在 C 中使用 realloc
- flutter - 如何向后移动一些代码行?