Trailing Stop code don’t work

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #185186 quote
    RichardVeenRichardVeen
    Participant
    Junior

    Hi,

    I don’t get it, I use the Trailing Stop code but it don’t work.

    What did I wrong?

    trailingstart = 5 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the “stoploss”

    // Position Size
    possize=1

    MA = average[50]

    //profit & loss
    SET TARGET PROFIT 20
    SET STOP pLOSS 20

    //order launch (example) would be set to any other entry conditions
    c1 = close>close[1]

    if c1 AND CLOSE>MA then
    BUY 1 LOT AT MARKET

    //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*pointsize THEN
    newSL = tradeprice(1)+trailingstep*pointsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pointsize THEN
    newSL = newSL+trailingstep*pointsize
    ENDIF
    ENDIF
    endif

    //order launch (example) would be set to any other entry conditions
    c2 = close<close[1]

    if c2 AND CLOSE<MA then
    SELLSHORT 1 LOT AT MARKET

    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF

    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pointsize THEN
    newSL = tradeprice(1)-trailingstep*pointsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pointsize THEN
    newSL = newSL-trailingstep*pointsize
    ENDIF
    ENDIF

    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF

    ENDIF

    #185187 quote
    phoentzsphoentzs
    Participant
    Master

    Try the setting 10/1 instead of 5/5.

    #185190 quote
    RichardVeenRichardVeen
    Participant
    Junior

    Hi,

    I tested with 5/1 and it not working.

    #185191 quote
    fifi743fifi743
    Participant
    Master
    trailingstart = 5 //trailing will start @trailinstart points profit
    trailingstep = 5 //trailing step to move the "stoploss"
    
    // Position Size
    possize=1
    
    MA = average[50]
    
    //profit & loss
    SET TARGET PROFIT 20
    SET STOP pLOSS 20
    
    //order launch (example) would be set to any other entry conditions
    c1 = close>close[1]
    
    if c1 AND CLOSE>MA then
    BUY 1 LOT AT MARKET
    
    //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>=trailingstart*pointsize THEN
    newSL = tradeprice+trailingstep*pointsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pointsize THEN
    newSL = newSL+trailingstep*pointsize
    ENDIF
    ENDIF
    endif
    
    //order launch (example) would be set to any other entry conditions
    c2 = close<close[1]
    
    if c2 AND CLOSE<MA then
    SELLSHORT 1 LOT AT MARKET
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pointsize THEN
    newSL = tradeprice(1)-trailingstep*pointsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pointsize THEN
    newSL = newSL-trailingstep*pointsize
    ENDIF
    ENDIF
    
    
    ENDIF
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    graph newsl
    
    
    #185193 quote
    fifi743fifi743
    Participant
    Master

    exit if newsl>0 from the condition

    #187071 quote
    RichardVeenRichardVeen
    Participant
    Junior

    Hi @fifi743,

    Thanks, it’s working!

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Trailing Stop code don’t work


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by RichardVeenRichardVeen
4 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/11/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...