我需要在这些条件下出现 LONG 或 SHORT 信号: - 当 RSI < 30 且 k < 20 并且价格现在高于 100 sma 时,发出多头信号。 - 当 RSI > 70 且 k>80 并且价格现在低于 100 sma 时,会发出做空信号。现在在sma代码中,我没有考虑到价格,我在这方面请求你的帮助
这是我的代码:
//@version=4
strategy("Buy&Sell Strategy depends on AO+Stoch+RSI+ATR by SerdarYILMAZ", shorttitle="Buy&Sell Strategy")
//RSI
rsisource=input(title="rsi source",type=input.source,defval=close)
rsilength=input(title="rsi length",type=input.integer,defval=7)
rsi=rsi(rsisource,rsilength)
hline(70,color=color.orange)
hline(30,color=color.orange)
plot(rsi,color=color.orange)
//Stoch
K=input(title="K",type=input.integer,defval=14)
D=input(title="D",type=input.integer,defval=3)
smooth=input(title="smooth",type=input.integer,defval=3)
k=sma(stoch(close,high,low,K),D)
d=sma(k,smooth)
hline(80)
hline(20)
//ATR
atrlen=input(title="ATR Length", type=input.integer,defval=14)
atrvalue=rma(tr,atrlen)
LongCondition=k<20 and rsi<30
ShortCondition=k>80 and rsi>70
if (LongCondition)
stoploss=low-atrvalue
takeprofit=close+atrvalue
strategy.entry("LONG", strategy.long)
strategy.exit("TP/SL",stop=stoploss,limit=takeprofit)
if (ShortCondition)
stoploss=high+atrvalue
takeprofit=close-atrvalue
strategy.entry("SHORT",strategy.short)
strategy.exit("TP/SL",stop=stoploss,limit=takeprofit)
答案 0 :(得分:0)
价格现在高于/低于 100 sma
但是您没有包含任何基于 sma 100 的条件。在全局作用域中引入 sma100 变量并将其添加到 Long/ShortCondition,如下例所示:
sma100 = sma(close, 100)
LongCondition=k<20 and rsi<30 and close > sma100
ShortCondition=k>80 and rsi>70 and close < sma100