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 stop function
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
Je 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.
Bonjour,
je me permets de remonter mon problème. Merci.
me protéger d’un retournement de marché
Essayer …
Set Stop pLoss
OU
Définir le pourcentage de perte d’arrêt
et placez-le après le code Trailing Stop.
https://www.prorealcode.com/documentation/ploss-2/
Justement, la perte d’arrêt est liée à une condition. Donc tant que cette condition n’est pas réunie, le trailing stop doit être actif. Je vais le placer après le trailing stop pour voir ce que cela donne.
Merci.
Bon, alors en mettant la condition de sortie après le trailing stop, cela ne fonctionne pas non plus.
//////////////////////////////// Trend Enveloppes
timePeriod15min =14
Deviation15min =0.1
price15min =customclose
dsma15min = WeightedAverage[timePeriod15min](price15min)
valuesHigh15min = (1 + deviation15min / 100) * dsma15min
valuesLow15min = (1 - deviation15min / 100) * dsma15min
inputs15min = price15min
if (inputs15min > valuesHigh15min)then
trendEnvelop15min = 1
elsif (inputs15min < valuesLow15min) then
trendEnvelop15min = -1
endif
TrendEnvelopUp15min = trendEnvelop15min = 1
TrendEnvelopDn15min = trendEnvelop15min = -1
//////////////////////////////////////////////// STATR
ST15min, ATRADX15min = CALL "Supertrend + ATR ADX Nuage"(close)
STATRUp15min = (ATRADX15min > ST15min)
STATRDn15min = (ATRADX15min < ST15min)
TrendUp15min = TrendEnvelopUp15min and STATRUp15min
TrendDn15min = TrendEnvelopDn15min and STATRDn15min
///////////////////////////////////////////////////////////////////////////////////////
//trailing stop function
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
endif
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
if longonmarket and TrendDn15min then
sell 1 contract at market
endif
if shortonmarket and TrendUp15min then
exitshort 1 contract at market
j’ai joint la formule du trailing stop (pris sur ce site) et ma condition de sortie d’une position (avec sa définition).
Merci.
Essayez comme ci-dessous
si longonmarket et TrendDn15min alors
vendre au marché // 1 contrat supprimé
fin si
si shortonmarket et TrendUp15min alors
exitshort au marché // 1 contrat supprimé
Ci-dessus … l’insertion du code PRT et du traducteur s’est mal passée, mais vous avez compris? 🙂
Bonjour,
merci pour votre retour rapide mais je pense qu’il y a un problème d’affichage non ?
Non pas trop. Je ne suis pas un spécialiste du codage (vous l’aurez sans doute compris).
Essayez ceci (supprimez les mots ‘1 contrat’ …
si longonmarket et TrendDn15min alors
vendre au marché
fin si
si shortonmarket et TrendUp15min alors
sortie courte au marché
Non cela ne fonctionne pas. Les conditions de sortie sont réunies et pourtant aucune action n’est générée.
Si vous souhaitez poster le code complet du Trading System alors je vais tester sur ma plateforme pour trouver le problème ?