Buongiorno, è possibile calcolare la velocità della barra a volume costante?
Vorrei sapere ad esempio quanto tempo impiegano a completarsi le barre a 1.000 contratti.
Grazie mille!
Non sono sicuro che sia quello che desideri, ma se vuoi semplicemente la durata in secondi dell’ultima barra a volume costante potresti fare così:
- Imposti come tipologia di grafico delle barre a volume costante
- Crei e applichi un indicatore fatto così:
secs = openhour*3600 + 60*openminute + opentime mod 60
return secs - secs[1] as "duration"
Se vuoi il valore aggiornato via via (quindi non solo quello a barra chiusa) potresti essere interessato a sostituire openhour/openminute/opentime con hour/minute/time.
Ti ringrazio Daniele.
La durata in secondi è quello che vorrei ottenere mediante indicatore e rappresentazione ad istogramma.
Applicando la tua formula i valori risultano sbagliati ed anche negativi… oltretutto impossibile..
Per cortesia prova a verificarlo.
Grazie,
Nazzareno
Prova questo (io non l’ho provato):
secs = openhour*3600 + 60*openminute + CurrentSecond
x = secs - secs[1]
If x < 0 then
x = x + (24 * 3600)
Endif
Return x as "duration"
// computed julian date
y=openyear
m=openmonth
d=openday
y=y+8000
if(m<3) then
y=y-1
m=m+12
endif
juliandate = (y*365) +(y/4) -(y/100) +(y/400) -1200820 +(m*153+3)/5-92 +d-1
secs = juliandate*86400 + openhour*3600 + 60*openminute + opentime mod 60
return secs - secs[1] as "duration in secs"
Con questa dovrebbe essere quasi sempre corretta. Ovviamente tra due giorni vedrai un picco, e nei finesettimana un picco ancor più grande.
Buongiorno, andando a rileggermi i post passati ho trovato la risposta.
Ecco la formula corretta:
Ora1 = OpenTime //ORA attuale
x = round((Ora1 / 100) - 0.5) * 100 //trovi l'ora ed i minuti, senza secondi
ss1 = Ora1 - x //trovi i secondi
y = round((x / 10000) - 0.5) * 10000 //trovi l'ora senza secondi e senza minuti
mm1 = (x - y) / 100 //trovi i minuti
hh1 = round((Ora1 / 10000) - 0.5)
//////////////////////////////////////////////////////////////////////
Ora2 = OpenTime[1] //ORA della candela precedente
x = round((Ora2 / 100) - 0.5) * 100 //trovi l'ora ed i minuti, senza secondi
ss2 = Ora2 - x //trovi i secondi
y = round((x / 10000) - 0.5) * 10000 //trovi l'ora senza secondi e senza minuti
mm2 = (x - y) / 100 //trovi i minuti
hh2 = round((Ora2 / 10000) - 0.5)
//////////////////////////////////////////////////////////////////////
// Calcolo delle differenze
DiffH = hh1 - hh2 //Differenza tra le ore
IF DiffH < 0 THEN
DiffH = DiffH + 23
ELSIF DiffH=1 THEN
DiffH=0
m1=m1+60
ENDIF
DiffM = mm1 - mm2 //Differenza tra i minuti
IF DiffM < 0 THEN
DiffM = DiffM + 59
ELSIF ss1 < ss2 THEN
DiffM = DiffM - 1
ENDIF
DiffS = ss1 - ss2 //Differenza tra i secondi
IF DiffS < 0 THEN
DiffS = DiffS + 59
ENDIF
//////////////////////////////////////////////////////////////////////
//Riportare tutto in SECONDI
Diff = Diffs + (DiffM * 60) + (DiffH * 3600)
RETURN Diff AS "Secondi"
Creato questo indicatore, vorrei calcolare la differenza tra esso e la sua media mobile esponenziale a 3 periodi.
Non riesco a capire come si fa a richiamare un indicatore personalizzato e mettere il mettere il relativo parametro in una media.
Allora, nel codice che ti ho dato c’era un errore (il mod 60 non dava sempre valori corretti).
Usa questa soluzione, dovrebbe essere corretta, inoltre dovresti teoricamente avere i valori corretti anche a cavallo tra due barre appartenenti a settimane/mesi/anni diversi.
//computed julian date
y=openyear
m=openmonth
d=openday
y=y+8000
if(m<3) then
y=y-1
m=m+12
endif
frac = opentime/100
rounded = round(frac)
// computing floorBase and ceilBase (functions are not available in v10.3)
if rounded > frac then
floorBase = (rounded-1) * 100
else
floorBase = rounded * 100
endif
openseconds = opentime - floorBase
juliandate = (y*365) +(y/4) -(y/100) +(y/400) -1200820 +(m*153+3)/5-92 +d-1
secs = juliandate*86400 + openhour*3600 + 60*openminute + openseconds
return secs - secs[1] as "duration in secs"
Tuttavia se ti è sufficiente che il valore sia corretto semplicemente a cavallo tra le giornate infrasettimanali puoi usare la soluzione di roberto, che sicuramente è più efficiente della mia, però la usi con le costanti “open” ti suggerisco di rimpiazzare “currentsecond” con “openseconds” (come li ho calcolati nel mio codice), perché se una barra dura più minuti “currentsecond” ti sballa il conteggio.
Quindi per capirsi, se non ti interessa avere i valori corretti solo tra giornate adiacenti (quindi infrasettimanale) puoi usare questa:
frac = opentime/100
rounded = round(frac)
// computing floorBase and ceilBase (functions are not available in v10.3)
if rounded > frac then
floorBase = (rounded-1) * 100
else
floorBase = rounded * 100
endif
openseconds = opentime - floorBase
secs = openhour*3600 + 60*openminute + openseconds
x = secs - secs[1]
If x < 0 then
x = x + (24 * 3600)
Endif
Return x as "duration"
(ho calcolato il floor in modo che funzioni anche nella PRTv10… nella v11 hai una funzione diretta per farlo…)
x = // il tuo valore (nel tuo caso il valore che trovavi nel return delle funzioni prima)
ema = ExponentialAverage[3](x)
return x - ema
Ti ringrazio ma il mio problema è rappresentato nella foto. Non capisco dove sbaglio…
Hai scritto “x = mySecondi = …”, probabilmente basta rimuovere “mySecondi =” (e quindi scrivere solo “x = CALL …”) e dovrebbe andare.
Tuttavia se puoi eviterei di usare la CALL.
Quindi io, se usassi il codice che ti ho passato farei così:
//computed julian date
y=openyear
m=openmonth
d=openday
y=y+8000
if(m<3) then
y=y-1
m=m+12
endif
frac = opentime/100
rounded = round(frac)
// computing floorBase and ceilBase (functions are not available in v10.3)
if rounded > frac then
floorBase = (rounded-1) * 100
else
floorBase = rounded * 100
endif
openseconds = opentime - floorBase
juliandate = (y*365) +(y/4) -(y/100) +(y/400) -1200820 +(m*153+3)/5-92 +d-1
secs = juliandate*86400 + openhour*3600 + 60*openminute + openseconds
dur = secs - secs[1]
ema = ExponentialAverage[3](dur)
return dur - ema as "duration - ema[3](dur)"
Però forse stiamo andando un po’ fuori dal topic iniziale…
Scusami Nazzareno se ti ho fatto un po’ impazzire, spero comunque che adesso hai chiaro come fare ciò che desideravi.
Comunque per chiudere posto la mia versione finale corretta (almeno spero eheheh) per fare ciò che richiedevi nel titolo iniziale del topic.
Tieni presente che questo codice per funzionare correttamente richiede che il timezone sia impostato su UTC+00:00.
// Compute julian date (must be used with UTC+00:00 Time Zone)
y=openyear
m=openmonth
d=openday
// The most negative year in the current Julian period is -4713 Gregorian (4714 BC), so we want to add something to y so we can simplify reasoning about our calculations by considering only positive year values. Any value divisible by 4000 could be chosen, since the pattern of leap years in the reformed Gregorian calendar repeats every 4000 years.
y=y+8000
// Since leap days are added at the end of February, it makes sense to consider January and February as the last two months (numbered 13 and 14) of the previous year. That way, leap days are always added at the end of the notional year.
if(m<3) then
y=y-1
m=m+12
endif
// The Julian calendar has normal years of 365 days, plus extra leap days every fourth year.
jd1 = (y*365) + (y - (y mod 4)) /4
// The Gregorian calendar adds the correction that a century year is not a leap year, unless it is also divisible by 400.
jd2 = -(y - (y mod 100)) /100 + (y - (y mod 400)) /400
// This correction allows for the 3287-year difference between the arbitrary positive year offset we added earlier and the real Julian Day epoch of 1st. January, 4713 BC, Julian calendar (24th. November, 4714 BC, Gregorian calendar).
jd3 = -1200820
// With the months starting with March=3 and ending with February=14, there is a simple pattern of month lengths: 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 That is, there are always 30=150/5 days in each month with an additional day every 3/5 month. Since we started with March=3, the first value given would be (3*153+3)/5 = 92, but we want to start from zero so we make a correction.
jd4 = ((m*153+3) - ((m*153+3) mod 5)) /5 - 92
// The Julian Day number goes up once a day. Days of the month are conventionally numbered from 1, so we subtract 1.
jd5 = +d-1
// julian day
jd = jd1 + jd2 + jd3 + jd4 + jd5
frac = opentime/100
rounded = round(frac)
if rounded > frac then
floorBase = (rounded-1) * 100
else
floorBase = rounded * 100
endif
openseconds = opentime - floorBase
secs = jd*86400 + openhour*3600 + 60*openminute + openseconds
return secs - secs[1] as "duration in seconds"
Credits to jd-code per la conversione da data del calendario gregoriano a julian day.
Un saluto, e buona domenica!
Grazie mille.
Davvero molto utile.
Buona Domenica anche a te!