如何在最近n天内进行SMA Crossover?
例如最近10个交易日内20日上方的交叉收盘价
答案 0 :(得分:0)
//@version=3
study("My Script")
numBars = input(title="Number of days", type=integer, defval=20, minval=1, maxval=300)
sma = sma(close, numBars)
// the next two string are used in case the chart's resolution differs from daily
securDaily = security(tickerid, 'D', close)
daylyRes = period == 'D' ? close : securDaily
crossed = 0
for i = 0 to numBars
if crossover(sma[i], daylyRes[i])
crossed := 1
break
plot(crossed)
在这种情况下,for循环很有用。