我正在尝试写一些代码,目的是当最新的RSI高于40时,显示多头策略。每周RSI和每月RSI都应高于60。
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")发布于 2021-06-10 18:45:55
您必须使用security()函数来获得更高的时间范围。
你可能想要这样的东西:(当rsi超过40时买入,当rsi超过60时卖出)
//@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")https://stackoverflow.com/questions/67918932
复制相似问题