Trailing stop on lowest low

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #26261 quote
    Ichtiandras
    Participant
    Junior

    Hi. Wondering how to encode “lowest [5] (low)” trailing stop counting from the trade time only and returns and stays with the highest value “lowest [5] (low)” after we have trade. Trailing stop value never goes down after rising, displays only the last maximum value of “lowest [5] (low)” in the trade. Thanks

    #26398 quote
    Nicolas
    Keymaster
    Master

    If I understand correctly, you want your stoploss to move on the last “lowest[5](low)” each time this value is higher than the previous one?

    #26403 quote
    Ichtiandras
    Participant
    Junior

    Yes. After the purchase, the walk up just not down. In order to be stopped in decline.

    #26669 quote
    Nicolas
    Keymaster
    Master

    OK, here we go, this is a code snippet that should work (not tested, please do your own test in ProBacktest with GRAPH instruction):

    //launch a buy order if the buy condition is met
    if buycondition then 
     buy 1 contract at market 
     ll = lowest[5](low)
     stoploss = close-ll
     set stop loss stoploss
    endif 
    
    //make a pseudo trailing stop at each new highest lowest[5](low)
    if not onmarket then 
     ll=0
    endif
    
    if lowest[5](low)>ll and ll>0 then 
     ll=lowest[5](low)
    endif 
    
    if longonmarket then 
     SELL AT ll STOP 
    endif
    
    #28816 quote
    fredd81
    Participant
    Senior

    Hi, trying to get this code to work but it wont, any advice ?

    
    IF c1 and c2 and c3 and NOT ONMARKET THEN
    buy positionsize CONTRACTS at high+2 stop
    
    ll = lowest[5](low)
    stoploss = close-ll
    set stop loss stoploss
    endif
    
    //make a pseudo trailing stop at each new highest lowest[5](low)
    if not onmarket then
    ll=0
    endif
    
    if lowest[5](low)>ll and ll>0 then
    ll=lowest[5](low)
    endif
    
    if longonmarket then
    SELL AT ll STOP
    endif
    
    SET TARGET PPROFIT 40
    #28843 quote
    Nicolas
    Keymaster
    Master

    Did you graph “ll” to see if it’s moving?

    GRAPH ll as "my lowest low trailing stop level !"

    Add this line into your code and launch a backtest please.

    #29366 quote
    fredd81
    Participant
    Senior

    Got it working but not as i thought

    Wanted the stop to be behind the entry price bar on the lowest low within x bars away, took away the trailing but dint work, code as follow

    
    IF c1 AND c2 and c3 AND NOT ONMARKET THEN
    
    buy positionsize CONTRACTS at high+2 stop
    ENDIF
    
    ll = lowest[x](low)
    stoploss = close-ll
    set stop loss stoploss
    
    
    
    if longonmarket then
    SELL AT ll STOP
    endif
    GRAPH ll as "my lowest low trailing stop level !"
    
    SET TARGET PPROFIT 55
    
    #29994 quote
    Nicolas
    Keymaster
    Master

    You should look at this blog article on how to make a stoploss with an indicator value.

    The lowest low of X periods is the lower band of a Donchian Channel of X periods.

    #30003 quote
    juanj
    Participant
    Master

    @Nicolas referring to the recent post at https://www.prorealcode.com/topic/trailing-stop-loss/ can you possibly assist us in coding a manual Trailing Stop that will work the same as the Set Stop pTrailing function. I have attempted to code it but it is unfortunately not working as I imagined it to work.

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

Trailing stop on lowest low


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by juanj
8 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/24/2017
Status: Active
Attachments: No files
Logo Logo
Loading...