Stop loss et trailing problème

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #134308 quote
    Fantasio2020
    Participant
    Senior

    Bonjour la communauté…

     

    je travaille depuis quelques temps sur une stratégie sympa….c’est pas encore nickel chrome, mais ça prend forme petit à petit à taton.

    Depuis cette semaine je la teste en Réel et les résultats ne sont pas mauvais, mais j’ai un gros soucis sur la platforme IG avec la stratégie de stop suiveur:

    //Stop Loss & Trailing function
    SET STOP LOSS 21
    trailingstart = 14 //trailing will start @trailinstart points profit
    trailingstep = 7 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL = 0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    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

    le code fonctionne super bien (merci nicolas) seulement le hic c’est que avec le système de stop garanti c’est le coût du stop en cas de perte…. mais également le coût du stop suiveur  qui devient excessif.

    n’y aurait t’il pas moyen de modifier un peu le code du suiveur pour sortir rapidement du marché (exit ou sell) une fois le premier trailing enclenché pour eviter le coût du stop suiveur devenu stop garanti.

     

    Merci pour votre aide.

    #134310 quote
    robertogozzi
    Moderator
    Master

    Vous pouvez essayer de remplacer la ligne 15 par:

    SELL AT MARKET

    et en remplaçant la ligne 27 par:

     EXITSHORT AT MARKET
    Fantasio2020 thanked this post
    #134459 quote
    Fantasio2020
    Participant
    Senior

    Slt Roberto,

    Merci pour la piste…

    malheureusement, je n’obtient pas de meilleurs résultats…au contraire la balance devient négative.

     

    Slts

    #134465 quote
    Scooby
    Participant
    Senior

    J’espère que quelqu’un pourra t’aider, je suis moi même pas bien doué avec les BE et les stop suiveurs sous PRT donc je ne pourrais t’aider :S

    En tout cas les réponses pourront peut être aussi m’aider 🙂

    #134518 quote
    Nicolas
    Keymaster
    Master

    Désolé je ne peux rien faire pour le coût du stop garanti, il coûte ce qu’il coûte 😉

    #134537 quote
    Fantasio2020
    Participant
    Senior

    Bjr Nicolas,

    oui, je comprends bien que tu ne peux rien faire au SL Garanti de IG.

    J’aimerai si c’est possible modifier un peu ton code:

    1. plutôt que de déplacer physiquement le Premier Sl (qui devient alors un stop garanti), j’aimerai le mettre en mémoire (état latent )…dans ce cas, si le prix revient sur “cet état latent” mi en mémoire j’ai deux choix
      1. Sell at Market
      2. ExitShort at Market
    2. si le prix continue à monter ou descendre le nouveau palier devient le nouvel état latent…..etc

    cela devrait éviter que le trailingstep devienne un SL Garanti et engendrer des coûts inutiles….

    Si c’est codable, ce serrait Topissime ….

    Cordialement

    #134541 quote
    Nicolas
    Keymaster
    Master

    Ok mais dans ce cas, tu ne seras pas exécuté pile poil au niveau du trailing stop puisque le code n’est lu qu’en fin de bougie, toutefois avec le MTF tu pourrais descendre en UT pour tester plus souvent le niveau.

    Bref, voici une version qui sort au marché quand on croise le niveau du trailing stop (non testé)

    //Stop Loss & Trailing function
    SET STOP LOSS 21
    trailingstart = 14 //trailing will start @trailinstart points profit
    trailingstep = 7 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL = 0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    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
     if longonmarket and low crosses under newSL then 
      sell at market 
     endif
     if shortonmarket and high crosses over newSL then 
      exitshort at market 
     endif 
    ENDIF
    Fantasio2020 thanked this post
    #134544 quote
    Fantasio2020
    Participant
    Senior

    Je viens de faire un test…:(

    je dirais que la différence corresponds +/- au coût du stop garanti chez IG (plus ou mois 30% aujourd’hui en réel sur cette stratégie)

    pense-tu qu’il est possible de lire le code dans le MTF 1 sec par exemple au lieu de 1 minute…..

    Slts

    Nouveau-Code.png Nouveau-Code.png Ancien-code.png Ancien-code.png
    #134547 quote
    Fantasio2020
    Participant
    Senior

    Par contre:

    Si je corrige avec :

    //stop order to exit the positions
    IF newSL > 0 THEN
    if longonmarket and low < newSL then
    sell at market
    endif
    if shortonmarket and high > newSL then
    exitshort at market
    endif
    ENDIf

    le ratio position gagnantes / perdantes ne change pas, mais le gain lui change

    Ancien-code-1.png Ancien-code-1.png Nouveau-Code-modifié.png Nouveau-Code-modifié.png
    #134551 quote
    Nicolas
    Keymaster
    Master

    possible de lire le code dans le MTF 1 sec par exemple au lieu de 1 minute

    Oui bien sûr, il faut lancer le BT en 1 seconde, il faudra changer le code avec les instructions TIMEFRAME :

    1. la stratégie en UT 1-minute
    2. la gestion des ordres en en UT 1-seconde
    #134552 quote
    Fantasio2020
    Participant
    Senior
    
    //Stop Loss & Trailing function
    SET STOP LOSS 21
    trailingstart = 14 //trailing will start @trailinstart points profit
    trailingstep = 7 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL = 0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    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
     if longonmarket and low crosses under newSL then 
      sell at market 
     endif
     if shortonmarket and high crosses over newSL then 
      exitshort at market 
     endif 
    ENDIF

    Une piste?

    #134561 quote
    Nicolas
    Keymaster
    Master

    Voir les nombreux exemples de l’utilisation de l’instruction TIMEFRAME sur le site, forums:

    https://www.prorealcode.com/documentation/timeframe-probacktest-proorder/

    Première approche sur le multi timeframe avec ProRealTime

    https://www.prorealcode.com/topics-tag/mtf/

    etc.

    Fantasio2020 thanked this post
    #134564 quote
    Fantasio2020
    Participant
    Senior

    C’est Bon Nicolas,

    j’ai trouvé…!!!

    Merci, je vais backtester….le truc c’est que je vais devoir attendre 🙂 car impossible de remonter loin en Backtest en MTF 10 ou 1 sec

    la suite dans quelques jours

    bertrandpinoy thanked this post
    #134596 quote
    Fantasio2020
    Participant
    Senior

    Bsr Nicolas,

    le Backtest semble fonctionner correctement… je ne l’ai pas encore lancé en Réel, car je veux m’assurer qu’il n’y a pas de problèmes.

    Néanmoins, je me demande quand même si en exécutant un ordre de vente au prix du stop, je ne risque pas de le déclencher.

    Ne pourrait on pas exécuter l’ordre de vente disons un pips avant de toucher  le “newsl”?

    Slts

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

Stop loss et trailing problème


ProOrder : Trading Automatique & Backtests

New Reply
Author
Summary

This topic contains 13 replies,
has 4 voices, and was last updated by Fantasio2020
5 years, 9 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 06/02/2020
Status: Active
Attachments: 4 files
Logo Logo
Loading...