Trailing stop by point

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #163800 quote
    AlfredAlfred
    Participant
    Average

    Hi all

    I would like to set a trailing stop by point.

    Such as, DJI, open at 30000 point, target 100 pt and loss 100 pt.

    Sometimes, only 95 pt then drop to stop loss.

    I want to set the openprice + 80 pt = trailing stop to guarantee the point to avoid these situation occur.

    And the stop loss 100pt is unchange.  Anyone can help?

    set target profit 100
    set stop ploss 100
    
    //%trailing stop function
    SET stop pTRAILING  [????] + 80

    Thanks.

    #163810 quote
    jebus89jebus89
    Participant
    Master

    Youre looking for the MFE stop loss i believe! Its on this forum, also grahal has a bunch of different trailing stop loss i think in his library. Should be able to find a lind for that by searching.

    #163822 quote
    nonethelessnonetheless
    Participant
    Master

    Here’s a few options for you, Trailing by Points, by % or by MFE, as Jebus has suggested – take your pick.

    //points trailing stop function
    trailingstart = tst //trailing will start @trailinstart points profit
    trailingstep = st //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
    
    
    //************************************************************************
    
    
    
     // % trailing stop function
    once trailingstop = 1
    if trailingstop then
    
    trailingpercentlong  = tsl // %
    trailingpercentshort = tss // %
    stepPercentlong = stl
    stepPercentshort = sts
    tssensitivity=2 // 1 = close 2 = High/Low 3 = Low/High 4 = typicalprice
    if onmarket then
    trailingstartlong = tradeprice(1)*(trailingpercentlong/100) //trailing will start @trailingstart points profit
    trailingstartshort = tradeprice(1)*(trailingpercentshort/100) //trailing will start @trailingstart points profit
    trailingsteplong = tradeprice(1)*(stepPercentlong/100) //% step to move the stoploss
    trailingstepshort = tradeprice(1)*(stepPercentshort/100) //% step to move the stoploss
    endif
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    if tssensitivity=1 then
    tssensitivitylong=close
    tssensitivityshort=close
    elsif tssensitivity=2 then
    tssensitivitylong=high
    tssensitivityshort=low
    elsif tssensitivity=3 then
    tssensitivitylong=low
    tssensitivityshort=high
    elsif tssensitivity=4 then
    tssensitivitylong=typicalprice
    tssensitivityshort=typicalprice
    endif
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tssensitivitylong-tradeprice(1)>=trailingstartlong THEN
    newSL = tradeprice(1)+trailingsteplong
    ENDIF
    //next moves
    IF newSL>0 AND tssensitivitylong-newSL>trailingsteplong THEN
    newSL = newSL+trailingsteplong
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-tssensitivityshort>=trailingstartshort THEN
    newSL = tradeprice(1)-trailingstepshort
    ENDIF
    //next moves
    IF newSL>0 AND newSL-tssensitivityshort>trailingstepshort THEN
    newSL = newSL-trailingstepshort
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    endif
    
    //************************************************************************
    
    //MFE trailing stop
    trailingstop = 20
     
    //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+trailingstop*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-trailingstop*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
    Alfred thanked this post
    #163849 quote
    jebus89jebus89
    Participant
    Master

    I personally am the most fan of the MFE modified to start after XX pips in profit!

    So if you are +50 pips in profit = no trailing stop loss

    but if that same trade goes +100 pips in profit = actiavte a MFE trailing stop loss.

    #163850 quote
    AlfredAlfred
    Participant
    Average

    Thanks, let me try try 🙂

    #163860 quote
    AlfredAlfred
    Participant
    Average

    I amended line 127 and 135

    to priceexit = tradeprice + – trailingstop*pointsize

    It is my needs! Thanks.

    #163868 quote
    GraHalGraHal
    Participant
    Legend

    Should be able to find a lind for that by searching.

    Snippet Link Library

    Alfred thanked this post
Viewing 7 posts - 1 through 7 (of 7 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 by point


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Alfred @kin08180213 Participant
Summary

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

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