Trailing stop con i canali di donchian
Forums › ProRealTime forum Italiano › Supporto ProOrder › Trailing stop con i canali di donchian
- This topic has 1 reply, 2 voices, and was last updated 2 years ago by robertogozzi.
Tagged: canale di donchian, donchian, newsl, PipSize, pointsize, stop loss, stoploss, trailing stop
-
-
03/25/2022 at 9:12 AM #190455
salve a tutti,
grazie all’aiuto di Roberto Gozzi ho scritto una versione di trailing stop che sfrutta i canali di Donchian per seguire il prezzo.
il funzionamento è il seguente: per essere attivato il trailing stop su un trade long è necessario che sia il close che il canale di donchian inferiore sia sopra il prezzo di entrata;
successivamente lo stop segue il canale di donchian inferiore.
per la versione short il meccanismo è l’opposto.
Siccome alcune volte i canali di Donchian si avvicinano troppo al prezzo sforando al distanza minima di stop, è stata aggiunta una distanza minima per lo stop stesso, onde evitare che una strategia possa fallire.
allego il codice, sia per chi volesse usarlo o prenderne spunto
saluti a tutti
Donchian Trailing Stop123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051//resetting variables when no trades are on marketDONKYDOWN=DonchianChannelDown[5]DONKYUP=DonchianChannelUp[5]distance=6if not onmarket thenNEWSL = 0endif//case SHORT orderif shortonmarket AND NEWSL=0 thenIF CLOSE<TRADEPRICE(1) AND DONKYDOWN<TRADEPRICE(1) THENNEWSL= DONKYUP*PIPSIZEENDIFENDIFIF NEWSL>0 AND CLOSE<NEWSL AND DONKYUP<DONKYUP[1] THENNEWSL= DONKYUP*PIPSIZEENDIF//case LONG orderif LONGONMARKET AND NEWSL=0 thenIF CLOSE>TRADEPRICE(1) AND DONKYDOWN>TRADEPRICE(1) THENNEWSL= DONKYDOWN*PIPSIZEENDIFENDIFIF NEWSL>0 AND CLOSE>NEWSL AND DONKYDOWN>DONKYDOWN[1] THENNEWSL=DONKYDOWN*PIPSIZEENDIF//exit on trailing stop price levelsif newSL>0 thenif longonmarket thenif (close-distance)>newSL thensell at newsl stopelsif(close+distance)<newsl thensell at newsl limitelsesell at marketendifelsif shortonmarket thenif (close+distance)< newsl thenexitshort at newsl stopelsif (close-distance)>newsl thenexitshort at newsl limitelseexitshort at marketendifendifendif, sia per chi volesse contribuire a migliorarlo.
1 user thanked author for this post.
03/26/2022 at 1:33 PM #190516Ho tolto PIPSIZE dove lo avevi messo e l’ho aggiunto alla distanza; ho anche aggiunto la verifica che il nuovo stop loss venga aggiornato solo se maggiore (se Long) o minore (se Short) del precedente:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849//resetting variables when no trades are on marketDONKYDOWN = DonchianChannelDown[5]DONKYUP = DonchianChannelUp[5]distance = 6 * PipSizeif not onmarket thenNEWSL = 0endif//case SHORT orderif shortonmarket AND NEWSL=0 thenIF CLOSE<TRADEPRICE(1) AND DONKYDOWN<TRADEPRICE(1) THENNEWSL= DONKYUPENDIFENDIFIF NEWSL>0 AND CLOSE<NEWSL AND DONKYUP<DONKYUP[1] THENNEWSL = max(NEWSL,DONKYUP)ENDIF//case LONG orderif LONGONMARKET AND NEWSL=0 thenIF CLOSE>TRADEPRICE(1) AND DONKYDOWN>TRADEPRICE(1) THENNEWSL= DONKYDOWNENDIFENDIFIF NEWSL>0 AND CLOSE>NEWSL AND DONKYDOWN>DONKYDOWN[1] THENNEWSL = min(NEWSL,DONKYDOWN)ENDIF//exit on trailing stop price levelsif newSL>0 thenif longonmarket thenif (close-distance)>newSL thensell at newsl stopelsif (close+distance)<newsl thensell at newsl limitelsesell at marketendifelsif shortonmarket thenif (close+distance)< newsl thenexitshort at newsl stopelsif (close-distance)>newsl thenexitshort at newsl limitelseexitshort at marketendifendifendifTi riepilogo l’uso di PIPZISE:
a) serve per fare in modo che certi calcoli tra pips (punti) e prezzi valgano per ogni strumento, che abbia un rapporto prezzo/pip di 1:1 (come il DAX ed altri indici), oppure 1:100 (come Aud/Jpy) o 1:10000 (come Eur/Usd), in quanto fa si che sia la piattaforma ad eseguire le dovute conversioni. Sommare 1 al prezzo del DAX, ad esempio 14000, da come risultato 14001 (rapporto 1:1), mentre lo stesso 1 aggiunto ad Eur/Usd, diciamo 1.0980, darebbe come risultato 2.0980, se lo sottrai darebbe 0.0980, prezzi inarrivabili!!!
b) differenza di prezzo / pipsize = differenza in punti/pips (es. Eur/Usd, 0.0135 diventano 135 punti) si usa per convertire un prezzo, o una differenza espressa comunque sotto forma di prezzo, in PIP/PUNTI
c) differenza di punti * pipsize = differenza in prezzo (es. Eur/Usd, 18 punti diventano 0.0018 di prezzo) si usa per convertire PIPS/PUNTI in prezzo o differenza di prezzo (ad esempio se il RANGE è di 0.0035, RANGE*PipSize lo converte in 35 Pips/Punti). -
AuthorPosts
Find exclusive trading pro-tools on