Utilisation du trailing stop et d’une seconde condition
Forums › ProRealTime forum Français › Support ProOrder › Utilisation du trailing stop et d’une seconde condition
- This topic has 19 replies, 3 voices, and was last updated 2 years ago by finplus.
-
-
07/09/2022 at 4:46 PM #197062
Bonjour,
j’utilise le trailing stop trouvé sur les forums de Prorealcode. Ma question est la suivante : j’aimerais ajouter une condition (me protégeant d’un retournement du marché) mais je voudrais que si cette condition n’est pas remplie, le trailing stop soit toujours actif.
La condition de sortie (je la nomme condA) prendrait cette forme :
if longonmarket (par exemple si je suis long) and condA
then sell 1 contract at market
endif.
et à la suite je mets le code du trailing stop. Mais cela ne donne pas les résultats escomptés.
Donc je me demande où je dois positionner cette partie du code (et d’ailleurs est-il bien rédigé) ?
merci.
Trailing Stop123456789101112131415161718192021222324252627282930313233343536373839//trailing stop functiontrailingstart = 5 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THENIF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF07/13/2022 at 5:45 PM #197239Je me permets de remonter ma demande : comment placer une condition de sortie avec un trailing stop (code ci-dessus) en sachant que lorsqu’on est en position (longue ou courte) et donc que le trailing stop devient actif, si la condition de sortie est remplie, cela entraînera la clôture de la position en cours ?
Merci.
07/30/2022 at 6:46 PM #19815607/30/2022 at 7:29 PM #198158me protéger d’un retournement de marché
Essayer …
Set Stop pLoss
OUDéfinir le pourcentage de perte d’arrêt
et placez-le après le code Trailing Stop.
07/30/2022 at 7:50 PM #19816107/31/2022 at 2:05 PM #19819807/31/2022 at 2:09 PM #198199traling stop et condition de sortie d'une position1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283//////////////////////////////// Trend EnveloppestimePeriod15min =14Deviation15min =0.1price15min =customclosedsma15min = WeightedAverage[timePeriod15min](price15min)valuesHigh15min = (1 + deviation15min / 100) * dsma15minvaluesLow15min = (1 - deviation15min / 100) * dsma15mininputs15min = price15minif (inputs15min > valuesHigh15min)thentrendEnvelop15min = 1elsif (inputs15min < valuesLow15min) thentrendEnvelop15min = -1endifTrendEnvelopUp15min = trendEnvelop15min = 1TrendEnvelopDn15min = trendEnvelop15min = -1//////////////////////////////////////////////// STATRST15min, ATRADX15min = CALL "Supertrend + ATR ADX Nuage"(close)STATRUp15min = (ATRADX15min > ST15min)STATRDn15min = (ATRADX15min < ST15min)TrendUp15min = TrendEnvelopUp15min and STATRUp15minTrendDn15min = TrendEnvelopDn15min and STATRDn15min/////////////////////////////////////////////////////////////////////////////////////////trailing stop functiontrailingstart = 5 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THENIF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeendifENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFif longonmarket and TrendDn15min thensell 1 contract at marketendifif shortonmarket and TrendUp15min thenexitshort 1 contract at marketj’ai joint la formule du trailing stop (pris sur ce site) et ma condition de sortie d’une position (avec sa définition).
Merci.
07/31/2022 at 2:33 PM #198201Essayez comme ci-dessous
1234567<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si longonmarket et TrendDn15min alors</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">vendre au marché // 1 contrat supprimé</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">fin si</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">si shortonmarket et TrendUp15min alors</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">exitshort au marché // 1 contrat supprimé</span></span>07/31/2022 at 2:37 PM #19820207/31/2022 at 2:38 PM #19820307/31/2022 at 2:39 PM #19820407/31/2022 at 2:53 PM #19820507/31/2022 at 2:55 PM #19820607/31/2022 at 3:06 PM #19820707/31/2022 at 3:24 PM #198208 -
AuthorPosts
Find exclusive trading pro-tools on