我试图在9 EMA越过20 EMA时用Pinescript编写一些代码,以显示长期策略。相反,我想展示20 EMA穿越9 EMA时的短期策略。这对我来说似乎很好。
当随机RSI显示多头时,我遇到麻烦的地方像第二个long.strategy一样显示,但是我只希望如果9 EMA超过20 EMA则该陈述为真。
这是我的代码:
//@version=2
strategy("Isaac Signals2", overlay=true)
//ema
ema3 = ema(close,9)
ema4 = ema(close,20)
long_ema = crossover(ema3,ema4)
short_ema = crossover(ema4,ema3)
//stochrsi
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
data = (60-k[1])/2
data2 = (k[1]-40)/2
long_stoch = k[1] >= d[1] and k[2] <= d[2] and k <= 60 and k >= 10
short_stoch = k[1] <= d[1] and k[2] >= d[2] and k >= 40 and k <= 95
//entries
if (long_ema)
strategy.entry("buy", strategy.long)
**if (long_ema and long_stoch)
strategy.entry("buy+1", strategy.long)**
if (short_ema)
strategy.entry("sell", strategy.short)
我上面加粗的地方是我要努力的地方。请帮忙!
答案 0 :(得分:0)
可能对您有帮助
//@version=2
strategy("Isaac Signals2", overlay=true)
//ema
ema3 = ema(close,9)
ema4 = ema(close,20)
long_ema = crossover(ema3,ema4)
short_ema = crossover(ema4,ema3)
//stochrsi
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
data = (60-k[1])/2
data2 = (k[1]-40)/2
long_stoch = k[1] >= d[1] and k[2] <= d[2] and k <= 60 and k >= 10
short_stoch = k[1] <= d[1] and k[2] >= d[2] and k >= 40 and k <= 95
//entries
if (long_ema)
strategy.entry("buy", strategy.long)
if (ema3 > ema4 and long_stoch) // ema3 > ema4 means that crossover was already and uptrend is continuing
strategy.entry("buy+1", strategy.long)
if (short_ema)
strategy.entry("sell", strategy.short)