Trouble with trailing stop loss

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #69799 quote
    stonecoldjohn
    Participant
    New

    Hi all,

    This is my first post and my first foray into the world of prorealtime so forgive me if this is a simple fix!

    I’ve set up an auto trading system and want a trailing stop loss of 12 points on each order that is executed however it doesn’t seem to be working correctly. Each trade that has been activated so far (on the prorealtime demo platform via IG) has either gone straight down and hit the 12 point stop (as expected) or gone up, in one instance over 30 points, and then stopped out where it entered, finishing with a loss of 2 points (the spread). I can’t for the life of me work out why it isn’t working. My understanding is that if it went up 30 points then with a 12 point trailing stop, I should guarantee a profit of 18 points.

    Anyway, here’s the code. Any help will be much appreciated.

    //-------------------------------------------------------------------------
    // Main code : MySystem(3)
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    c1 = (close > high[1])
    c2 = (close > high[2])
    c3 = (close > high[3])
    c4 = (close > high[4])
    c5 = (close > high[5])
    c6 = (close > high[6])
    c7 = (close > high[7])
    c8 = (close > high[8])
    c9 = (close > high[9])
    c10 = (close > high[10])
    c11 = (close > high[11])
    c12 = (close > high[12])
    c13 = (close > high[13])
    c14 = (close > high[14])
    c15 = (close > high[15])
    c16 = (close > high[16])
    c17 = (close > high[17])
    c18 = (close > high[18])
    c19 = (close > high[19])
    c20 = (close > high[20])
    indicator1 = MACD[12,26,9](close)
    c21 = (indicator1 > 0)
    
    IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 AND c9 AND c10 AND c11 AND c12 AND c13 AND c14 AND c15 AND c16 AND c17 AND c18 AND c19 AND c20 AND c21 THEN
    BUY 3 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    
    
    // Conditions to enter short positions
    c33 = (close < low[1])
    c34 = (close < low[2])
    c35 = (close < low[3])
    c36 = (close < low[4])
    c37 = (close < low[5])
    c38 = (close < low[6])
    c39 = (close < low[7])
    c40 = (close < low[8])
    c41 = (close < low[9])
    c42 = (close < low[10])
    c43 = (close < low[11])
    c44 = (close < low[12])
    c45 = (close < low[13])
    c46 = (close < low[14])
    c47 = (close < low[15])
    c48 = (close < low[16])
    c49 = (close < low[17])
    c50 = (close < low[18])
    c51 = (close < low[19])
    c52 = (close < low[20])
    indicator3 = MACD[12,26,9](close)
    c53 = (indicator3 < 0)
    
    IF c33 AND c34 AND c35 AND c36 AND c37 AND c38 AND c39 AND c40 AND c41 AND c42 AND c43 AND c44 AND c45 AND c46 AND c47 AND c48 AND c49 AND c50 AND c51 AND c52 AND c53 THEN
    SELLSHORT 3 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    
    
    // Stops and targets
    SET STOP pTRAILING 12
    
    #69802 quote
    GraHal
    Participant
    Master

    Hi John

    What Timeframe are you using?

    Is the 30 point gain at the end of the bar as the code is read and executed only at the end of each bar?

    I will run your code now and let you know if have any further thoughts.

    Cheers
    GraHal

    #69803 quote
    stonecoldjohn
    Participant
    New

    Hi GraHal, thanks for the response.

    I’m using a 1 hour time frame on Wallstreet. I had trades open today between 1700 – 1900 on the hour, all closing for a 2 point loss despite all rising by over 12 points. I think the longest time a trade was open was approx. 15 mins so still within that hour bar.

    Cheers,

    John

    #69804 quote
    GraHal
    Participant
    Master

    You used MACD in your code, have you seen the Thread below

    https://www.prorealcode.com/topic/prt-macd-corrupted/

    #69805 quote
    GraHal
    Participant
    Master

    My brain needs rest but I think the main issue is that TS of 12 does not give the market enough room to retrace? Everybody is so twitchy now that a 12 point rise is followed by a retrace and so taking out your stop.

    I got attached with below on the DAX 30 min TF with a spread of 2.

    SET TARGET PPROFIT 328
    SET STOP pTRAILING 250
    John-1.jpg John-1.jpg
    #69811 quote
    Eric
    Participant
    Master

    do you need “p”?

    https://www.prorealcode.com/documentation/trailing/

    i dont use these trailing stops because some issues in the past but maybe they have fixed them now?

    #69812 quote
    GraHal
    Participant
    Master

    all closing for a 2 point loss despite all rising by over 12 points.

    Pick one of the trades and follow it through on a tick by tick chart.

    You will surely see price – after rising by 12+ points  and so causing your TS = 12 to rise to near your TradePrice – price must then be retracing to near your TradePrice and hence taking you out as price hits your TS?

    If price rises by 24+ points then the TS moves up twice (but would still be 12 points behind price) and then price retraces and take you out (on the TS) for a 12 point gain?

    Let us know if above is what you see on a tick chart of the trade?

    Anyway @stonecoldjohn the sun is shining today in the UK (what part of UK are you?) so you should warm up this bank holiday weekend! 🙂

    #69907 quote
    jebus89
    Participant
    Master

    I might be wrong but instead of listing up every candle 20 candles back, cant u just use the following?

    Buysignal = close > highest[20](close)
    shortsignal = Close < lowest[20](close)
    #69912 quote
    GraHal
    Participant
    Master

    @jebus89 I figured he must be looking for a long slow steady trend with no significant retrace within the last 20 hours (as on 1 H TF)??

    But that may be why his stops get taken out very early on in trades because after a such a long slow steady trend over 20 hours then a retrace is very likely??

    Anywhere where is  stonecoldjohn … he can’t be frozen solid after this lovely warm weekend!! Maybe he’s just frozen out of his trades!! 🙂 🙂

    #69955 quote
    Leo
    Participant
    Veteran

    I might be wrong but instead of listing up every candle 20 candles back, cant u just use the following?

    Buysignal = close > highest[20](high[1])
    shortsignal = Close < lowest[20](low[1])

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

Trouble with trailing stop loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 9 replies,
has 5 voices, and was last updated by Leo
7 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/04/2018
Status: Active
Attachments: 1 files
Logo Logo
Loading...