Code d'un stop suiveur

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #121439 quote
    midel
    Participant
    Senior

    Bonjour,

    Je veux utiliser pour une de mes stratégies un stop suiveur qui, dès que le trade soit positif de “n” points (ts dans la strategie), soit toujours à une distance “n” du cours de clôture et qu’il soit donc remis à jour à chaque fois que ce cours de cloture fait un plus haut pour les longs ou un plus bas pour les shorts.

    Les codes que j’ai pu trouver sur le site ne correspondant pas à cette manière de fonctionner, j’ai réécrit un code. Il fonctionne pour les longs.

    Mais le même code, modifié pour les shorts, ne fonctionne pas. Les trades sont cloturés de suite avec une perte correspondant au spread.

    //-------------------------------------------------------------------------
    //ma strategie 
    
    defparam cumulateorders = false
    defparam preloadbars = 10000
    
    
    if not onmarket then
    sellshort 1 contract at market
    endif
    
    sl = 140
    TS = 60
    
    
    set stop ploss sl
    
    
    //trailing stop
    
    if not onmarket then
    newsl = 0
    endif
    
    
    
    //ts court
    
    if shortonmarket then
    if newsl = 0 and tradeprice - close > ts then
    newsl = close + ts
    elsif  newsl >0 then
    newsl =min(newsl,close + ts)
    endif
    endif
    
    exitshort at newsl stop
    Doc1.jpg Doc1.jpg
    #121441 quote
    Vonasi
    Moderator
    Master

    MIDEL – votre message a été déplacé des forums anglais vers les forums français car vous avez posté en français. Veuillez essayer de poster dans le forum correct pour la langue choisie avec tous les futurs messages.

    #121449 quote
    midel
    Participant
    Senior

    Solution trouvée

    Désolé pour le dérangement !

    #121525 quote
    Nicolas
    Keymaster
    Master

    Pas de soucis @midel , mais ce serait vraiment sympa de poster le code justement, pour les futurs intéressés qui souhaiteraient faire la même chose 🙂 Merci pour le partage et pour la contribution à notre cercle vertueux.

    #121618 quote
    midel
    Participant
    Senior

    En fait, j’ai trouvé sur le site le code qui va bien pour ce que je veux faire.

    // trailing stop
    trailingstop = 100
     
    //resetting variables when no trades are on market
    if not onmarket then
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    endif
     
    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE (Maximum favorable excursion) of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
     
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
    endif
    endif
     
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif

    Par contre, j’aimerais bien savoir pourquoi mon code ne fonctionne pas !

    #121804 quote
    Nicolas
    Keymaster
    Master

    En ajoutant un

    GRAPHONPRICE newsl

     

    à la fin de ton code, tu pourras comprendre où se situe ton niveau de stoploss et ainsi débugger ton code.

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

Code d'un stop suiveur


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
midel @midel Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Nicolas
6 years ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 03/07/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...