ATR stop loss fixe

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #195286 quote
    Yobouss
    Participant
    New

    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?

    #195296 quote
    JC_Bywan
    Moderator
    Master

    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

    Bodaris thanked this post
    #195370 quote
    Yobouss
    Participant
    New

    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 )
    Bodaris thanked this post
    #223032 quote
    Bodaris
    Participant
    New

    Merci à vous 2, ça marche super bien. Ca va m’être très utile ^^

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

ATR stop loss fixe


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Yobouss @yobouss Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Bodaris
2 years, 4 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 06/14/2022
Status: Active
Attachments: No files
Logo Logo
Loading...