Salve.
Per un uso su time frame intraday (es.-1H) è possibile aggiungere l’ora/minuti al seguente codice ?
esempio che il vwap sia ancorato sulla barra del giorno es. 202141018 alle ore es. 15.00.
Grazie
Saluti
startDate=20141018
VWAP=undefined
SDup1 = undefined
SDlw1 = undefined
SDup2 = undefined
SDlw2 = undefined
SDup3 = undefined
SDlw3 = undefined
if opendate=startDate then
startbar=barindex
endif
if opendate>=startDate then
barcount=barindex-startbar
d = max(1, barcount)
src = customclose
if volume > 0 THEN
VWAP = summation[d](Volume * src)/summation[d](Volume)
ENDIF
if(barcount=0) then
sd = 0
else
p1 = summation[d](Volume * src)
p2 = summation[d](Volume)
p3 = summation[d](Volume * src * src)
ma = p1/p2
ma2 = p3/p2
sd = SQRT(ABS(ma2 - ma * ma) )
endif
if viewSD then
SDup1 = vwap+sd
SDlw1 = vwap-sd
SDup2 = vwap+sd*2
SDlw2 = vwap-sd*2
SDup3 = vwap+sd*3
SDlw3 = vwap-sd*3
endif
SDup1 = vwap+sd*1
SDlw1 = vwap-sd*1
SDup2 = vwap+sd*2
SDlw2 = vwap-sd*2
SDup3 = vwap+sd*3
SDlw3 = vwap-sd*3
endif
R=1
G=1
B=1
RETURN VWAP coloured(R,G,B) as "VWAP", SDup1 coloured(R,G,B) as "upper 1 STD", SDlw1 coloured(R,G,B) as "lower 1 STD", SDup2 coloured(R,G,B) as "upper 2 STD", SDlw2 coloured(R,G,B) as "lower 2 STD", SDup3 coloured(R,G,B) as "upper 3 STD", SDlw3 coloured(R,G,B) as "lower 3 STD"
Cosa intendi per “ancorato“?
Ancorato nel senso che decidi tu da quale giorno deve inziare il vwap (per semplicità nel codice ho impostato il 18 ottobre 2024).
Vorrei aggiungere la possibilità di decidere anche l’orario per poterlo usare in un time frame intrday.
Ecco, ho aggiunto anche l’orara d’inizio (starttime):
once startDate=20240108
once starttime=090000
once VWAP = undefined
once SDup1 = undefined
once SDlw1 = undefined
once SDup2 = undefined
once SDlw2 = undefined
once SDup3 = undefined
once SDlw3 = undefined
if (opendate=startDate) AND (opentime=starttime) then
startbar=barindex
endif
if (opendate>startDate) or (opendate=startDate) and (opentime>=starttime) then
barcount=barindex-startbar
d = max(1, barcount)
src = customclose
if volume > 0 THEN
VWAP = summation[d](Volume * src)/summation[d](Volume)
ENDIF
if(barcount=0) then
sd = 0
else
p1 = summation[d](Volume * src)
p2 = summation[d](Volume)
p3 = summation[d](Volume * src * src)
ma = p1/p2
ma2 = p3/p2
sd = SQRT(ABS(ma2 - ma * ma) )
endif
if viewSD then
SDup1 = vwap+sd
SDlw1 = vwap-sd
SDup2 = vwap+sd*2
SDlw2 = vwap-sd*2
SDup3 = vwap+sd*3
SDlw3 = vwap-sd*3
endif
SDup1 = vwap+sd*1
SDlw1 = vwap-sd*1
SDup2 = vwap+sd*2
SDlw2 = vwap-sd*2
SDup3 = vwap+sd*3
SDlw3 = vwap-sd*3
endif
R=1
G=1
B=1
RETURN VWAP coloured(R,G,B) as "VWAP", SDup1 coloured(R,G,B) as "upper 1 STD", SDlw1 coloured(R,G,B) as "lower 1 STD", SDup2 coloured(R,G,B) as "upper 2 STD", SDlw2 coloured(R,G,B) as "lower 2 STD", SDup3 coloured(R,G,B) as "upper 3 STD", SDlw3 coloured(R,G,B) as "lower 3 STD"