Bonjour
J’utilise un ATR pour mon stop loss. Le problème est que le stop loss est recalculé après chaque barre.
J’aimerais avoir un stop loss ATR fixe basé sur la valeur ATR lorsque la transaction est initiée et qui restera fixe jusqu’à la fin de la transaction.
Le code actuel est comme ceci (code simplifié) :
Variable :
ATRLengthS = 5
NumATRsS = 5
If not ONMARKET and RSI[14](close)>70 then
Buy 1 Contract at market
endif
If not ONMARKET and RSI[14](close)<30 then
sellshort 1 Contract at market
endif
If LONGONMARKET and RSI[14](close)<30 then
sell 1 Contract at market
endif
If SHORTONMARKET and RSI[14](close)>70 then
exitshort 1 Contract at market
endif
SET STOP LOSS (( AverageTrueRange[ATRLengthS](close)) * NumATRsS )
Quelqu’un peut-il m’aider à coder cela?
Bonjour, il faut mettre en mémoire cet ATR au moment de l’envoi de l’ordre, c’est à dire dans le bloc if-endif des lignes 1 à 3. Pour ce faire, juste avant le endif de la ligne 3 il faut définir la variable qu’on va appeler par exemple monATR:
monATR=AverageTrueRange[ATRLengthS](close)
puis utiliser monATR dans la ligne du set stop loss
Merci pour votre aide.
Je poste le code modifié ci-dessous :
If not ONMARKET and RSI[14](close)>70 then
Buy 1 Contract at market
monatr = ((AverageTrueRange[ATRLengthS](close)) * NumATRsS )
endif
If not ONMARKET and RSI[14](close)<30 then
sellshort 1 Contract at market
monatr = ((AverageTrueRange[ATRLengthS](close)) * NumATRsS )
endif
If LONGONMARKET and RSI[14](close)<30 then
sell 1 Contract at market
endif
If SHORTONMARKET and RSI[14](close)>70 then
exitshort 1 Contract at market
endif
SET STOP LOSS (monatr )
Merci à vous 2, ça marche super bien. Ca va m’être très utile ^^