[英]Try to write my strategy on trading view with Pine
I need a LONG or SHORT signal to appear under these conditions: -The LONG signal is given when the RSI is < 30 and k<20 and provided that the price is now above 100 sma.我需要在这些条件下出现多头或空头信号: - 当 RSI < 30 且 k < 20 并且价格现在高于 100 sma 时,给出多头信号。 -The SHORT signal is given when the RSI is >70 and k>80 and provided that the price is now below 100 sma. - 当 RSI > 70 且 k>80 并且价格现在低于 100 sma 时,会发出做空信号。 Now in the sma code, finding the price is not taken into account for me, I ask for your help in this现在在sma代码中,我没有考虑到价格,我在这方面请求你的帮助
This is my code:这是我的代码:
//@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)
price is now above/below 100 sma价格现在高于/低于 100 sma
However you have not included any condition based on sma 100. Introduce the sma100 variable in the global scope and add it to the Long/ShortCondition, as is shown in the example below:但是,您尚未包含任何基于 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.