problema con ATR
Forums › ProRealTime forum Italiano › Supporto ProBuilder › problema con ATR
- This topic has 11 replies, 3 voices, and was last updated 5 days ago by
robertogozzi.
-
-
02/13/2025 at 12:17 PM #243771
Bene, sei stato gentile, Grazie
Nel proseguire, ho un problema con ATR (non so se devo aprire un altro post)L’obbiettivo è sapere il valore dell’ATR a 5 periodi “giorno” da mettere nel codice per un successivo calcolo.
Ho creato l’indicatore di PRT che mette il nome “ATR (5) D” ma, così non lo legge:1234ValoreIndicatore = CALL "ATR (5) D"IF gettimeframe >= 300 AND gettimeframe <= 14400 THENecc...allora ho fatto questo che, sarebbe ideale:
123456TimeFrame(1 day, updateonclose)ATR5D = AverageTrueRange[5]TimeFrame(Default)ValoreIndicatore = CALL "ATR5D"IF gettimeframe >= 300 AND gettimeframe <= 14400 THENecc...che crea un comodo indicatore “ATR5D” ma, varia il valore se cambio il Time Frame …divento matto
inoltre, come vedi dall’immagine “ATR5D”restituisce un valore diverso da quello corretto di “ATR (5) D” di PRTmi puoi aiutare ?
02/13/2025 at 3:23 PM #243784Si, occorre aprire un nuovo argomento, l’ho aperto io.
Ho anche spostato entrambi nel supporto ProBuilder in quanto si tratta di indicatori.
Questo indicatore puoi metterlo su qualunque TF intraday:
1234Timeframe(Daily,UpdateOnClose)ATRD = AverageTrueRange[5](close)Timeframe(default)RETURN ATRD AS "ATR Daily"il risultato che vedrai è qullo dell’ultima barra GIORNALIERA chiusa, non quella corrente.
C’è una differenza molto lieve, inferiore ad 1 unità solitamente, che penso sia dovuta a qualche differenza negli arrotondamenti.
02/15/2025 at 9:24 AM #24385802/15/2025 at 11:18 AM #243863dopo molti tentativi, questo sembra funzionare :
123456789101112timeframe(1 day, updateonclose)TrueRange = 0FOR i = 0 TO 4 DOTR1 = high[i] - low[i]TR2 = abs(high[i] - close[i+1])TR3 = abs(low[i] - close[i+1])TrueRange = TrueRange + max(TR1, max(TR2, TR3))NEXTATR5D = TrueRange / 5timeframe(default)ValoreIndicatore = ATR5DIF gettimeframe >= 900 AND gettimeframe <= 3600 THENbene…ma adesso da errore su time fame superiori a 1 Day. Ho provato così ma da erori:
1234567891011121314IF gettimeframe <= 86400 THEN // 86400 secondi = 1 giornotimeframe(1 day, updateonclose)TrueRange = 0FOR i = 0 TO 4 DOTR1 = high[i] - low[i]TR2 = abs(high[i] - close[i+1])TR3 = abs(low[i] - close[i+1])TrueRange = TrueRange + max(TR1, max(TR2, TR3))NEXTATR5D = TrueRange / 5timeframe(default)ENDIFValoreIndicatore = ATR5DIF gettimeframe >= 900 AND gettimeframe <= 3600 THEN02/15/2025 at 1:17 PM #243867Le differenze tra gli indicatori non sono dovute agli arrotondamenti, ma alle differenze nei prezzi di chiusura…
I prezzi di chiusura vengono determinati in momenti diversi. Puoi vedere chiaramente la differenza nella “barra di venerdì”: l’opzione “UpdateOnClose” chiude solo domenica sera, mentre senza “UpdateOnClose” viene utilizzata la “Close” della barra di venerdì…1 user thanked author for this post.
02/15/2025 at 2:28 PM #243872dopo molti tentativi, questo sembra funzionare :
123456789101112timeframe(1 day, updateonclose)TrueRange = 0FOR i = 0 TO 4 DOTR1 = high[i] - low[i]TR2 = abs(high[i] - close[i+1])TR3 = abs(low[i] - close[i+1])TrueRange = TrueRange + max(TR1, max(TR2, TR3))NEXTATR5D = TrueRange / 5timeframe(default)ValoreIndicatore = ATR5DIF gettimeframe >= 900 AND gettimeframe <= 3600 THENbene…ma adesso da errore su time fame superiori a 1 Day. Ho provato così ma da erori:
1234567891011121314IF gettimeframe <= 86400 THEN // 86400 secondi = 1 giornotimeframe(1 day, updateonclose)TrueRange = 0FOR i = 0 TO 4 DOTR1 = high[i] - low[i]TR2 = abs(high[i] - close[i+1])TR3 = abs(low[i] - close[i+1])TrueRange = TrueRange + max(TR1, max(TR2, TR3))NEXTATR5D = TrueRange / 5timeframe(default)ENDIFValoreIndicatore = ATR5DIF gettimeframe >= 900 AND gettimeframe <= 3600 THEN02/15/2025 at 2:41 PM #243873Come dicevo a Roberto, sono nuovo.
Questo funziona correttamente (per un successivo calcolo sul prezzo)ma, se alzo il time fame oltre 1 giorno, mi da errore.123456789101112131415161718192021222324252627282930313233343536373839404142434445defparam DrawOnLastBarOnly = trueonce openMorningBox = 000000once closeMorningBox = 073000once maxHighMorningBox = highonce minLowMorningBox = lowtimeframe(1 day, updateonclose)TrueRange = 0FOR i = 0 TO 4 DOTR1 = high[i] - low[i]TR2 = abs(high[i] - close[i+1])TR3 = abs(low[i] - close[i+1])TrueRange = TrueRange + max(TR1, max(TR2, TR3))NEXTATR5D = TrueRange / 5timeframe(default)ValoreIndicatore = ATR5DIF gettimeframe >= 900 AND gettimeframe <= 3600 THENMorningBoxRange = maxHighMorningBox - minLowMorningBoxMorningBoxPercentage = (MorningBoxRange / ValoreIndicatore) * 100DRAWTEXT( ROUND(ValoreIndicatore, 4), LastBar - 1, maxHighMorningBox + (MorningBoxRange * 0.2)) COLOURED(200, 20, 150)DRAWTEXT("ATR5D", LastBar-4, MAXHIGHMorningBox + (MorningBoxRange * 0.2)) COLOURED(200, 20, 150)if OpenTime >= openMorningBox and OpenTime <= closeMorningBox thenif OpenTime = openMorningBox THENbarMorningBox = BarIndexmaxHighMorningBox = highminLowMorningBox = lowLastBar = BarIndexelseLastBar = LastBar + 1endifmaxHighMorningBox = max(maxHighMorningBox,high)minLowMorningBox = min(minLowMorningBox,low)if OpenTime = closeMorningBox thenprevLowMorningBox = minLowMorningBoxprevHighMorningBox = maxHighMorningBoxprevidxMorningBox = barindexMorningBoxRange = maxHighMorningBox - minLowMorningBoxENDIFENDIFdrawrectangle(barMorningBox, minLowMorningBox, LastBar, maxHighMorningBox)COLOURED(0, 200, 0, 60) fillcolor(0, 200, 0, 20)ENDIFRETURN ATR5D02/15/2025 at 3:27 PM #243876Quando utilizzi orari “IntraDay”, ad esempio per la “MorningBox”, devi anche utilizzare timeframe “IntraDay”, altrimenti riceverai un messaggio di errore.
Se utilizzi un orario come “073000”, il timeframe deve essere uguale o inferiore a 30 minuti, altrimenti l’orario “073000” non può essere letto correttamente.(L’ATR giornaliero che calcoli manualmente con il “loop” non corrisponde all’ATR di PRT…)
02/15/2025 at 6:29 PM #243884Il timeframe di default deve essere il più piccolo tra quelli utilizzati, quello che è sul grafico.
02/15/2025 at 7:09 PM #24388702/15/2025 at 8:16 PM #243890credo che il problema sia qui:
12IF gettimeframe <= 86400 THEN // 86400 secondi = 1 giornotimeframe(1 day, updateonclose)non permette la condizione. Come posso fare si che il codice non venga considerato su time frame superiori ?
02/16/2025 at 12:13 AM #243901 -
AuthorPosts
Find exclusive trading pro-tools on