Trailing stop, Breakeven code

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

    There are many different exit codes.

    I am coding 1 min DAX and testing different stops, trailing, breakeven etc.

    It would make it easier for me who is not so good at coding if there was a list on different exits.

    The best thing would be to be able to copy past different exits to a code you made.
    Maybe there is already here on the forum?

    #104147 quote
    GraHal
    Participant
    Master

    Great idea!  I would welcome this also! Hope it comes about!

    If I thought there is support I would raise a spreadsheet and host it on my google drive similar to below

    Snippet Link Library

    Maybe this Thread needs a more appropriate title … e.g EXIT Conditions??

    #104197 quote
    Stefanb
    Participant
    Senior

    Here is one.

     

    // dynamic units based STOP LOSS
    
    myATRLL = 2* averagetruerange[2](close)//8,1
    myATRPL = 3* averagetruerange[6](close)//6,9
    
    SET stop loss myATRLL
    SET target profit myATRPL
    GraHal thanked this post
    #104200 quote
    Stefanb
    Participant
    Senior
    IF NOT LONMARKET THEN
     newSL=0
    ENDIF
     
    IF LONGONMARKET AND close-tradeprice(1)>=30*pipsize THEN
     newSL = tradeprice(1)+5*pipsize
    ENDIF
     
    IF newSL>0 THEN
     SELL AT newSL STOP
    ENDIF

    If current buy order is in gain of 30 points, order will be closed at entry price + 5 points.

    GraHal thanked this post
    #104209 quote
    bullbear
    Participant
    Senior

    This, I am not quite sure if it works but I think so 🙂

     

     

    //trailing stop
    trailingstop = 20
    StartTrailingStopValue = 10
    
    //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)-close > StartTrailingStopValue*pointsize then
    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
    endif
    
    //case LONG order
    if longonmarket then
    MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
    if close-tradeprice(1) > StartTrailingStopValue*pointsize then
    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
    endif
    
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    GraHal thanked this post
    #104211 quote
    bullbear
    Participant
    Senior

    One more 🙂

    enableBreakeven=1 // 
    BESG = 0.25// % break even stop gain
    BESL = 0 // % break even stop level
    underlaying=0.01
    
    if enableBreakeven then
    if not onmarket then
    newsl=0
    endif
    if ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    newsl=0
    endif
    if longonmarket then
    if close-tradeprice(1)>=(((tradeprice(1)/100)*BESG)/(underlaying/100))*pointsize then
    newsl=tradeprice(1)+(((tradeprice(1)/100)*BESL)/(underlaying/100))*pointsize
    endif
    endif
    if shortonmarket then
    if tradeprice(1)-close>=(((tradeprice(1)/100)*BESG)/(underlaying/100))*pointsize then
    newsl=tradeprice(1)-(((tradeprice(1)/100)*BESL)/(underlaying/100))*pointsize
    endif
    endif
    if longonmarket and newsl>0 then
    sell at newsl stop
    endif
    if shortonmarket and newsl>0 then
    exitshort at newsl stop
    endif
    
    endif
    
    SET STOP %LOSS 0.4
    SET TARGET %profit 1
    
    set stop ploss 20
    
    GraHal thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Trailing stop, Breakeven code


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
bullbear @bullbear Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/04/2019
Status: Active
Attachments: No files
Logo Logo
Loading...