Pine script 松树脚本中的移动平均

Pine script 松树脚本中的移动平均,pine-script,algorithmic-trading,Pine Script,Algorithmic Trading,我想根据历史数据计算两天内的简单移动平均值。 我使用以下代码来获得前一天的高-低收盘价 // Getting previous 2 days day high low close prev_daily_high = security(syminfo.tickerid, 'D', high) prev_daily_low = security(syminfo.tickerid, 'D', low) prev_daily_close = security(syminfo.tickerid, 'D',

我想根据历史数据计算两天内的简单移动平均值。 我使用以下代码来获得前一天的高-低收盘价

// Getting previous 2 days day high low close
prev_daily_high = security(syminfo.tickerid, 'D', high)
prev_daily_low = security(syminfo.tickerid, 'D', low)
prev_daily_close = security(syminfo.tickerid, 'D', close)
但上面的代码只获取前一天的数据来计算移动平均数,我需要两天的数据

cp=(prev_daily_high+prev_daily_low+prev_daily_close)/3
bc=(prev_daily_high+prev_daily_low)/2
tc=2*cp-bc
下面的代码计算两天的SMA(简单移动平均值),但我获取的数据是一天的“如何获取两天的数据并获得正确的SMA值?”

// two days moving average for the central pivot, top central, bottom central
MAC = sma(cp, 2)
MAB = sma(bc, 2)
MAT = sma(tc, 2)

您需要让
security()
在其HTF上下文中进行计算。在这里,我们使用一个元组通过一次调用获取所有3个值:

MAC = sma(hlc3, 2)
MAB = sma(hl2, 2)
MAT = sma(2*hlc3-hl2, 2)
[dMAC, dMAB, dMAT] = security(syminfo.tickerid, 'D', [MAC, MAB, MAT])
请参阅: