Trailing Stop code don’t work

Forums ProRealTime English forum ProOrder support Trailing Stop code don’t work

Viewing 6 posts - 1 through 6 (of 6 total)
  • #185186

    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

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

    #185190

    Hi,

    I tested with 5/1 and it not working.

    #185191
    #185193

    exit if newsl>0 from the condition

    #187071

    Hi @fifi743,

    Thanks, it’s working!

     

     

     

Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login