Breakeven stop code long/short

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #135149 quote
    phoentzs
    Participant
    Master

    Hallo,

    ich benutze den Breakeven trailing stop code hier aus dem Forum.

    https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/

     

    Wie kann man long und short Orders einen einzelnen Breakeven trailing stop zuweisen?

    Wo genau muss ich den Code dann einfügen?

    #135177 quote
    robertogozzi
    Moderator
    Master

    Auf diese Weise können verschiedene Trailing-Stopps für LONG- und SHORT-Trades (nicht getestet) gestartet werden:

     
    //************************************************************************
    //trailing stop function
    trailingstartL = 20 //LONG  trailing will start @trailinstart points profit
    trailingstartS = 20 //SHORT 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
    //first move (breakeven)
     IF newSL=0 AND close-tradeprice(1)>=trailingstartL*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>=trailingstartS*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
    //************************************************************************
    #135184 quote
    phoentzs
    Participant
    Master

    Ach doch so einfach. Sorry, bin kein großer Programmierer.
    Vielen Dank, werde es heute Abend testen.

    #135235 quote
    phoentzs
    Participant
    Master

    Funktioniert super, danke.
    Eröffnen sich noch bessere Möglichkeiten.

    #172744 quote
    phoentzs
    Participant
    Master

    Hallo,

    Kann man in diesen Breakeven Trailing Code eine Funktion hinzufügen, welche einen Mindestabstand zum aktuellen Kurs läßt? Als Beispiel, wenn der Code in seiner Funktion x Punkte nachziehen will, der Mindestabstand zum Kurs aber dadurch unterschritten werden würde(DAX bei IG: 6 Punkte Mindestabstand SL), gibt PRT eine Fehlermeldung und stoppt die Strategie. Aus diesem Grund wäre eine Funktion, die das unterbindet, sehr praktisch.
    Weiß jemand wie man den Code ändern muss?
    Roberto? Nicolas?

    #172745 quote
    robertogozzi
    Moderator
    Master

    Da ist er. Es unterscheidet sich geringfügig von dem, was Sie gefragt haben, Sie wollten, dass es nicht unter der festgelegten Entfernung operiert, während dies auf jeden Fall funktioniert, nur dass am Ausgang überprüft wird, ob der Preis größer oder kleiner als die Entfernung ist oder nicht und basierend auf Diese Überprüfung entscheidet, ob eine schwebende STOP- oder LIMIT-Order platziert oder in MARKET ausgestiegen wird.

    //************************************************************************
    //trailing stop function
    trailingstartL = 20 //LONG  trailing will start @trailinstart points profit
    trailingstartS = 20 //SHORT trailing will start @trailinstart points profit
    trailingstep    = 5 //trailing step to move the "stoploss"
    Distance        = 6 * PipSize
     
    //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)>=trailingstartL*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>=trailingstartS*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 THEN
          IF (close - Distance) > newSL THEN
             SELL             AT newSL STOP
          ELSIF (close + Distance) < newSL THEN
             SELL             AT newSL LIMIT
          ELSE
             SELL             AT Market
          ENDIF 
       ELSIF ShortOnMarket THEN
          IF (close - Distance) > newSL THEN
             EXITSHORT AT newSL LIMIT
          ELSIF (close + Distance) < newSL THEN
             EXITSHORT AT newSL STOP
          ELSE
            EXITSHORT AT Market
          ENDIF
    ENDIF
    //************************************************************************
    phoentzs, icharttop and KumoNoJuzza thanked this post
    #172748 quote
    GraHal
    Participant
    Master

    Link zu oben als Log 292 hier hinzugefügt …

    Bibliothek für Snippet-Links

    robertogozzi and phoentzs thanked this post
    #181630 quote
    phoentzs
    Participant
    Master

    Ist es möglich diesen Trailingstop statt Punkten in Prozent umzubauen? Mit Distance?

    #181632 quote
    robertogozzi
    Moderator
    Master

    Auf welchen Prozentsatz soll berechnet werden?

    #181637 quote
    phoentzs
    Participant
    Master

    Trailingstart in Prozent

    Trailingstep in Prozent

    Distance bleibt als Punkte

    #181640 quote
    robertogozzi
    Moderator
    Master

    Okay, aber wie viel Prozent muss ich berechnen? Zum aktuellen Preis? Oder auf den Einstiegspreis? Oder auf das investierte Kapital? Oder auf Eigenkapital?

    #181642 quote
    phoentzs
    Participant
    Master

    Eigentlich so wie der Code oben in Punkten funktioniert. Nur das der Trailing ab einem Prozentsatz anfängt den Breakeven in Prozentschritten nachzuziehen.
    Ab 0.2%
    step 0.01

    zum Beispiel.
    Ich denke vom aktuellen Preis.

    #181651 quote
    phoentzs
    Participant
    Master

    Ok, ich denke ich habe das Problem erkannt und es scheint nicht an meinen verwendeten Trailingcodes zu liegen. Ich verwende den Code von Nicolas und als %Variante den von Nonethless. Beides gute Arbeiten.
    Zum Problem: kann es sein, dass im Demokonto der Button „Stops nachjustieren“ nicht immer funktioniert? Bei mir wurden heute mehrere Bots im Demokonto angehalten wegen zu geringem Abstand zum Mindeststop des Brokers. Dieselben Bots laufen aber auch Live bei mir. Da scheint es aber sauber zu funktionieren. Hat noch jemand solche Probleme?

    #181660 quote
    GraHal
    Participant
    Master

    Ja, ich habe das gleiche Problem wie Sie auf meinem Demokonto … der Mindeststopp des Brokers war zu kurz … und ich hatte den Button „Stops neu anpassen“ angekreuzt .

    #181663 quote
    phoentzs
    Participant
    Master

    Ok, dann scheint das ein allgemeines Problem zu sein. Ich hatte schon an mir gezweifelt.

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

Breakeven stop code long/short


ProOrder: Automatischer Handel & Backtesting

New Reply
Author
author-avatar
phoentzs @phoentzs Participant
Summary

This topic contains 19 replies,
has 3 voices, and was last updated by phoentzs
3 years, 11 months ago.

Topic Details
Forum: ProOrder: Automatischer Handel & Backtesting
Language: German
Started: 06/08/2020
Status: Active
Attachments: No files
Logo Logo
Loading...