Replacing faulty trailing stop loss with exit conditions

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #252016 quote
    Ahimsa
    Participant
    New

    Hi everyone,

    Have other people had the same problems with trailing stop losses on short time frames (1 second) as I have? When you write a strategy, the strategy cannot ‘see’ the previous level of a stop loss, so instead it reassesses the stop every second. This wouldn’t be a problem, except for the fact that when a new stop loss is placed each second, it is subject to IG’s minimum stop loss threshold. This results in the stop loss being repeatedly pushed back in the opposite direction, thus defeating the whole objective of a trailing stop loss. I completely understand about IG’s minimum, however the previous stop level isn’t being honoured after it’s started trailing. I did put in a technical support request to IG several weeks ago.

    I was wondering if I could get round this by rewriting the stop loss conditions as ‘exit conditions’.

    Originaly, for long trades (mirror logic for short trades) my trailing stop was to follow the LOWEST of the following which could change throughout the trade:

      1. The SMA 89
      2. The SMA55
      3. The SMA 21
      4. The highest level of the lower Bollinger Band for the lifetime of the trade.

    Here’s the code for the trailing stop (below). Does anyone know how I can rewite this code below as an ‘exit condition’? The highest level of each line would have to be ‘remembered’ in the code for the lifetime of the trade in order to trigger the exit. Many thanks in advance.

    //trailing stop loss
    if longonmarket and go=0 then
    ll=min(sma21,min(sma55,min(sma89,bbdn)))
    if ll>itradeprice+MinProfitTrailing*pointsize then
    buytrailing=max(buystoploss,max(buytrailing,ll))
    set stop price buytrailing
    endif
    else
    buytrailing=buystoploss
    endif
    if shortonmarket and go=0 then
    hh=max(sma21,max(sma55,max(sma89,bbdn)))
    if hh<itradeprice-MinProfitTrailing*pointsize then
    selltrailing=min(sellstoploss,min(selltrailing,hh))
    set stop price selltrailing
    endif
    else
    selltrailing=sellstoploss
    endif
    
    
    
    GraHal thanked this post
    #252023 quote
    Iván González
    Moderator
    Master

    Maybe this could help you:

    sma89=average[89](close)
    sma55=average[55](close)
    sma21=average[21](close)
    
    if not longonmarket and close>sma21 and close>sma55 and close>sma89 then
       stoploss=min(sma21,min(sma55,sma89))
       buy 1 contract at market
       set stop price stoploss
    endif
    
    If longonmarket then
       trailingstop=max(stoploss,min(sma21,min(sma55,sma89)))
       set stop price trailingstop
    endif
    
    graphonprice sma21 coloured("cyan")
    graphonprice sma55 coloured("blue")
    graphonprice sma89 coloured("darkblue")
    graphonprice stoploss coloured("fuchsia")
    graphonprice trailingstop coloured("red")
    
    #252024 quote
    PeterSt
    Participant
    Master

    Hi,

    A Trailing System which uses a native TF of 1 second, can not exist; there would be no headroom to trail. Think about this carefully and you will give up on it right away.

    The solution is using a somewhat larger TF (could be 3 seconds) for the trailing commands (Pending orders !), while using an underlaying 1 second system to apply the other things you want the “speed” for. In functional terms : set the TF of the chart to 1 second as you are used to, but use the TimeFrame command to set an e.g. 3 second TF around that.
    This is somewhat more difficult to explain, but if you make a base like this for it, you will automatically start to understand.

    In practice you will see that 3 seconds is still not giving you much headroom to trail down, though technically it can work. In other words, you can just as well use 5 seconds or 10 seconds or anything, as long as you re-optimize all.
    Think in terms of : the more headroom I give my system to trail down but also to recover from that “dip”, the longer the trailing can last and the more your trade can earn. All to some degree of course and all in the “balance” you foresee or backtest.

    Good luck !

    #252314 quote
    Ahimsa
    Participant
    New

    @Ivan thanks for looking at this. I’m revisiting my strategy without trailing stop losses because the bug is hard coded into Prorealtime’s platform and it’s a known issue in Prorealtime.


    @PeterSt
    IG’s native stop loss in Prorealtime doesn’t have this problem, even on a one second chart. The problem is due to the fact that the external algorithm cannot ‘see’ the placement of previous stop losses. So it responds by replacing the stop loss every second where each new stop is subject to IG’s minimum. But thanks for looking at this.

    #252318 quote
    PeterSt
    Participant
    Master

    I was not talking about a technical problem … (it just works). But functionally you can not do this. No headroom for trailing … So no need to hunt it either. 🙂

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

Replacing faulty trailing stop loss with exit conditions


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Ahimsa @ahimsa Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by PeterSt
4 months, 1 week ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/30/2025
Status: Active
Attachments: No files
Logo Logo
Loading...