首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RSI策略交易视图

RSI策略交易视图
EN

Stack Overflow用户
提问于 2021-06-10 18:00:59
回答 1查看 170关注 0票数 1

我正在尝试写一些代码,目的是当最新的RSI高于40时,显示多头策略。每周RSI和每月RSI都应高于60。

代码语言:javascript
复制
study("rsi", overlay=true)

rsisource= input( title="rsisource", type=input.source, defval=close)

rsilength= input( title="rsisource", type=input.integer, defval=14)


rsivalue= rsi(rsisource, rsilength)

lrsi= input( title="dt", type=input.resolution, defval="D")

wrsi= input( title="dt", type=input.resolution, defual="W")

mrsi= input( title="dt", type=input.resolution, defual="M")



llr=crossover (rsivalue and lrsi, 40)
 
wwr=(rsivalue and wrsi > 60) 

mmr=(rsivalue and mrsi > 60) 

l1=(rsivalue and lrsi > 60) 


if (llr and wwr and mmr)

strategy.entry("buy", strategy.long)

if (l1)

strategy.close("sell")
EN

回答 1

Stack Overflow用户

发布于 2021-06-10 18:45:55

您必须使用security()函数来获得更高的时间范围。

你可能想要这样的东西:(当rsi超过40时买入,当rsi超过60时卖出)

代码语言:javascript
复制
//@version=4
strategy("My Script")

rsi = rsi(close, 14)

rsi_d = security(syminfo.tickerid, "D", rsi)
rsi_w = security(syminfo.tickerid, "W", rsi)
rsi_m = security(syminfo.tickerid, "M", rsi)

if crossover(rsi, 40) and rsi_d > 40 and rsi_w > 40 and rsi_m > 40
    strategy.entry("buy", strategy.long)

if crossover(rsi, 60)
    strategy.close("buy")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67918932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档