我正在尝试执行“自动锚定” VWAP,它将检测何时找到新的枢轴点(间隔中的最高价格),然后从该点重新加载。 到目前为止,我的代码是:
//@version=3
study("Anchored VWAP2",overlay=true)
//calculating and plotting pivots
pvtLength = 20
pvtHigh = pivothigh(high, pvtLength, pvtLength)
pvtLow = pivotlow(low, pvtLength, pvtLength)
pvtHigh:= fixnan(pvtHigh)
pvtLow:= fixnan(pvtLow)
pvtHighColor = change(pvtHigh) != 0 ? na : maroon
pvtLowColor = change(pvtLow) != 0 ? na : green
plot(pvtHigh, color=pvtHighColor, transp=0, linewidth=1, offset=-pvtLength)
plot(pvtLow, color=pvtLowColor, transp=0, linewidth=1, offset=-pvtLength)
plot(pvtHigh, color=pvtHighColor, transp=0, linewidth=1, offset=0)
plot(pvtLow, color=pvtLowColor, transp=0, linewidth=1, offset=0)
//--------------------------------------------------------
//done with Pivot Points, now VWAP JOB (not working)
start = security(tickerid, '1', time)
newPivotHigh = change(pvtHigh) != 0 ? 1 : 0 //detect when new pivot is found
pivotTime = newPivotHigh ? time-(minute(time)-20) : na //grab the time when it occured (actual time less 20 minutes, because pivot length is always 20)
impulse_func = iff(time == pivotTime, 1, 0) //start plot only when the bar time is the pivot time
newSession = iff(newPivotHigh and change(start), 1, 0) //plot when current time changes and we have a new pivot
startSession = newSession * impulse_func
vwapsum = 0.0
volumesum = 0.0
myvwap = 0.0
vwapsum:= iff(startSession, high*volume, vwapsum[1]+high*volume)
volumesum:= iff(startSession, volume, volumesum[1]+volume)
myvwap:= vwapsum/volumesum
plot(myvwap, linewidth=3, transp=0, title='AVWAP')
答案 0 :(得分:0)
我只是做了一点工作...我遇到的唯一问题是让VWAP从实际的枢轴点开始,而不是向前20小节...在那里为您添加了一些调试内容如果您正在查看ETHUSD图表,那很好。还使它着眼于收盘价,而不是收盘价,因为这是我发现该股时所寻找的东西。让我知道是否可以解决,我确定它不会很难,只是现在想不出办法。
//@version=3
study("Pivot Anchored VWAP",overlay=true)
//calculating and plotting pivots
pvtLength = input(20)
barcalc = pvtLength * 2500 // 1 minute is 2500 unix. 3,600,000 in a day.
pvtHigh = pivothigh(close, pvtLength, pvtLength)
pvtLow = pivotlow(close, pvtLength, pvtLength)
pvtHigh:= fixnan(pvtHigh)
pvtLow:= fixnan(pvtLow)
pvtHighColor = change(pvtHigh) != 0 ? na : maroon
pvtLowColor = change(pvtLow) != 0 ? na : green
plot(pvtHigh, color=pvtHighColor, transp=0, linewidth=1, offset=-pvtLength)
//plot(pvtLow, color=pvtLowColor, transp=0, linewidth=1, offset=-pvtLength)
//plot(pvtHigh, color=pvtHighColor, transp=0, linewidth=1, offset=0)
//plot(pvtLow, color=pvtLowColor, transp=0, linewidth=1, offset=0)
start = security(tickerid, '1', time)
newPivotHigh = change(pvtHigh) != 0 ? 1 : 0 //detect when new pivot is found
pivotTime = newPivotHigh ? time - barcalc : na // calculate in unix instead of minutes, easier to change pivot length that way
impulse_func = iff(time == pivotTime, 1, 0) //start plot only when the bar time is the pivot time
newSession = iff(newPivotHigh and change(start), 1, 0) //plot when current time changes and we have a new pivot
test = iff(time >= pivotTime and time[1] < pivotTime, 1, 0)
pvtvwapstart = iff(time >= pivotTime and time[1] < pivotTime, 1, 0)
pvtvwapsumSrc = close * volume
pvtvwapsumVol = volume
pvtvwapsumSrc := pvtvwapstart ? pvtvwapsumSrc : pvtvwapsumSrc + pvtvwapsumSrc[1]
pvtvwapsumVol := pvtvwapstart ? pvtvwapsumVol : pvtvwapsumVol + pvtvwapsumVol[1]
pvtVWAP = pvtvwapsumSrc/pvtvwapsumVol
plot(newPivotHigh + 228, color=white) ///debug plot when looking at ETHUSD
plot(pvtVWAP, title="Pivot Anchored VWAP", color=red, linewidth=1, transp=45)