Breakeven stop code long/short

Viewing 5 posts - 16 through 20 (of 20 total)
  • Author
    Posts
  • #188714 quote
    phoentzs
    Participant
    Master

    Hallo, kann man in dem Code von Roberto aus Post #172745 eine Funktion hinzufügen, dass der Trailingstop erst beginnt zu arbeiten wenn eine andere Bedingung erfüllt ist?

    Zum Beispiel für LONG: Close>MA5, der Code beginnt Gewinne zu sichern.

    Selbiges für SHORT: Close<MA5, der Code beginnt Gewinne zu sichern.

    #188720 quote
    robertogozzi
    Moderator
    Master

    Da ist er:

    //************************************************************************
    //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
    
    MyTScondition = close < .......
    
    IF MyTScondition OR NewSL > 0 THEN 
     //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
     ENDIF
    ENDIF
    //************************************************************************

    Weisen Sie der Variablen MyTScondition die Bedingung Ihrer Wahl zu.

    #188727 quote
    phoentzs
    Participant
    Master

    Aber muss nicht MYTScondition verschiedener Art sein wenn ich für Long und Short unterschiedliche Merkmale habe?
    Für mein Verständnis müßte es nicht in die beiden „if longonmarket… if shortonmarket…“ Blöcke?
    Ich glaub, ich habe es mir gerade selbst beantwortet:

    “if longonmarket and mylongTScondition then“

    Und dann halt nochmal für Short.

    Oder habe ich einen Denkfehler?

    #188730 quote
    robertogozzi
    Moderator
    Master

    Natürlich können Sie, ändern Sie einfach die Zeilen 13-15 wie folgt:

    MyTSconditionL = close < .......
    MyTSconditionS =   .............
    IF MyTSconditionL OR MyTSconditionS OR NewSL > 0 THEN
    #188733 quote
    phoentzs
    Participant
    Master

    Danke Dir. Ich versuche es.

Viewing 5 posts - 16 through 20 (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...