StopandTrailingStop

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #80103 quote
    RogerIG
    Participant
    New

    Hallo

    Wie programmiere ich folgendes:

    Ein Buy order wurde geöffnet

    Sobald der aktuelle Preis grösser als der Einstiegspreis plus 10  ist wird ein STOPloss gesetzt  bei aktueller Preis minus 8 (vorher keine SL setzen) . Und wenn dann der aktuelle Preis bei Einstiegspreis plus 30 (also bei 40) ist wird der Stop loss jeweils um 30 Punkte nachgezogen, bei 70 wird er auch wieder um 30 nachgezogen   (Trailing), bis dann die Order über TP order eben SL geschlossen wird.

    Sell ist umgekehrt.

     

    Gruss, RogerIG

    #80121 quote
    Nicolas
    Keymaster
    Master

    Hallo, ich bin mir nicht sicher, ob ich Ihre Anfrage perfekt verstanden habe, aber haben Sie die Trailing-Stop-Codes probiert, die bereits in der Website und in den Foren verfügbar sind?

    Complete trailing stop code function

    Trailing stop with the Max Favorable Excursion (MFE)

    Es gibt auch eine Reihe von Codes in der Code-Snippet-Liste: https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit#gid=0

    #80489 quote
    RogerIG
    Participant
    New

    Hallo Nicolas

    Danke,

    ich habe beide Links geprüft, würde sie kombinieren und für den SL auf 2 zu setzen sobald ich 20 Punkte im Plus bin würde ich folgenden Code
    (leicht angepasst mit trailingdistance) nutzen:

    //trailing stop
    trailingstop = 20
    trailingdistance = 18
    
    //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 of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingdistance*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-trailingdistance*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
    

    geht das so?

    bim zweiten Link, siehe nachfolgend habe ich den Eindruck fehlt der Exit Order für Short, was meinst Du?

    //trailing stop function
    trailingstart = 20 //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)>=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
    //************************************************************************
    
    GRAPH newSL as "trailing"
    
    
    
    
    #80490 quote
    Nicolas
    Keymaster
    Master

    Das scheint mir gut zu sein. Warum denken Sie, dass die Exit-Aufträge nicht auf SHORT gesetzt sind?

    #80495 quote
    RogerIG
    Participant
    New

    ist folgender code nicht nur für exit Long positionen?

    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    #80506 quote
    RogerIG
    Participant
    New

    Hallo Nicolas

    Ok, evtl. habe ich es nicht richtig verstanden. Aber nun eine Frage kann ich folgenden Code einfach zu meinem Code hinzufügen?

    //trailing stop
    trailingstop = 20
    trailingdistance = 18
    
    //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 of the current trade
    if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingdistance*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-trailingdistance*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
    
    //trailing stop function
    trailingstart = 35 //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)>=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
    //************************************************************************
    
    GRAPH newSL as "trailing"
    #80509 quote
    Nicolas
    Keymaster
    Master

    Sie können beide Codes verwenden, aber nicht beide gleichzeitig. Diese beiden Codes beinhalten die Verwaltung der Positionen KAUFEN und VERKAUFEN.

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

StopandTrailingStop


ProOrder: Automatischer Handel & Backtesting

New Reply
Author
author-avatar
RogerIG @rogerig Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Nicolas
7 years, 4 months ago.

Topic Details
Forum: ProOrder: Automatischer Handel & Backtesting
Language: German
Started: 09/10/2018
Status: Active
Attachments: No files
Logo Logo
Loading...