% trail with acceleration

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #228833 quote
    nonetheless
    Participant
    Master

    hi, this is the %trail i’ve been using for some time. it’s mostly Paul’s work with some minor alterations of my own:

    // %trailing stop (inc. cumulative)
    once trailingstoptype = 1
    if trailingstoptype then
    //====================
    trailingpercentlong  = tsl // %
    trailingpercentshort = tss // %
    once acceleratorlong = acl // typically tsl*0.1
    once acceleratorshort= acs // typically tss*0.1
    ts2sensitivity  = 2 // [1] close [2] high/low [3] low/high [4] typicalprice
    PcToKeep = pk   //long % to keep at breakeven
    PcToKeepS = pks //short % to keep at breakeven
    //====================
    once steppercentlong  = (trailingpercentlong/10)*acceleratorlong
    once steppercentshort = (trailingpercentshort/10)*acceleratorshort
    if onmarket then
    trailingstartlong = positionprice*(trailingpercentlong/100)
    trailingstartshort = positionprice*(trailingpercentshort/100)
    trailingsteplong = positionprice*(steppercentlong/100)
    trailingstepshort = positionprice*(steppercentshort/100)
    endif
     
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    newsl           = 0
    mypositionprice = 0
    endif
    positioncount = abs(countofposition)
    if newsl > 0 then
    if positioncount > positioncount[1] then
    if longonmarket then
    newsl = max(newsl,positionprice * newsl / mypositionprice)
    else
    newsl = min(newsl,positionprice * newsl / mypositionprice)
    endif
    endif
    endif
    if ts2sensitivity=1 then
    ts2sensitivitylong=close
    ts2sensitivityshort=close
    elsif ts2sensitivity=2 then
    ts2sensitivitylong=high
    ts2sensitivityshort=low
    elsif ts2sensitivity=3 then
    ts2sensitivitylong=low
    ts2sensitivityshort=high
    elsif ts2sensitivity=4 then
    ts2sensitivitylong=(typicalprice)
    ts2sensitivityshort=(typicalprice)
    endif
    if longonmarket then
    if newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong then
    newsl = positionprice+trailingsteplong+(positionprice/100*pk)
    endif
    if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong then
    newsl = newsl+trailingsteplong
    endif
    endif
    if shortonmarket then
    if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort then
    newsl = positionprice-trailingstepshort-(positionprice/100*pks)
    endif
    if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort then
    newsl = newsl-trailingstepshort
    endif
    endif
    if barindex-tradeindex>1 then
    if longonmarket then
    if newsl>0 then
    sell at newsl stop
    endif
    if newsl>0 then
    if low crosses under newsl then
    sell at market
    endif
    endif
    endif
    if shortonmarket then
    if newsl>0 then
    exitshort at newsl stop
    endif
    if newsl>0 then
    if high crosses over newsl then
    exitshort at market
    endif
    endif
    endif
    endif
    mypositionprice = positionprice
    endif
    
    if (shortonmarket and newsl > 0) or (longonmarket and newsl>0) then
    if positioncount > positioncount[1] then
    if longonmarket then
    newsl = max(newsl,positionprice * newsl / mypositionprice)
    endif
    if shortonmarket then
    newsl = min(newsl,positionprice * newsl / mypositionprice)
    endif
    endif
    endif

    then i had the idea that the accelerator could be increased under certain circumstances, so i tried changing lines 13,14 to this:

    steppercentlong  = (trailingpercentlong/10)*acceleratorlong
    if (longonmarket and cs6) then
    steppercentlong  = (trailingpercentlong/10)*(acceleratorlong*s1)
    endif
    steppercentshort = (trailingpercentshort/10)*acceleratorshort
    if (shortonmarket and cb6) then
    steppercentshort  = (trailingpercentshort/10)*(acceleratorshort*s2)
    endif

    in my test, the algo was running at 5m and cs6/cb6 represent a change of direction for the stochRSI on the 15m TF; when that starts going the wrong way, the accelerator increases.

    s1 and s2 are the multipliers, how much faster you want the step to move.

    this seems to give a small advantage, esp for shorts, but i was expecting more; is there a better way of doing it?

    thanks in advance for any suggestions.

    robertogozzi thanked this post
    #228839 quote
    PeterSt
    Participant
    Master

    I have so many variations on this, that I am pretty sure that no one rule can exist for it. Combine it with where trailing actually starts (see below) and the appliances are endless. Or the trailing distance itself (2nd set you see below for close-by).
    One thing I personally know for sure : also influencing the slope underway (your subject) is only creating extra complexity in your code. All it does further is giving the opportunity to optimize over it. Something I handed out the death penalty over to myself.

    With trailing you’ll earn half of the money. But optimizing over it (any of the trailing parameters) is only not-good-habit. You can just as well set it for once by visualizing it like I show below (that comprises 35 or so pictures for working out on of the parameters) which makes you dizzy anyway, and next let it be waiting for the best” trails (always very nice to watch).

    This mere vague post should try to bring across in the base, that – for me – no changing slopes work (considered slopes which even can turn negative already ?). It is just something without control, BUT which may run into the price at a lucky moment (steeper slope) or avoids the price which gets better later (shallower slope). Make it a linear slope and you do the same, but now with control (see the trend, follow it).

    Helpful a little ? I hope so.
    The best part : your posting in itself. 🙂 🙂

    nonetheless thanked this post
    image_2024-02-27_144707392.png image_2024-02-27_144707392.png image_2024-02-27_145231148.png image_2024-02-27_145231148.png
    #228843 quote
    nonetheless
    Participant
    Master

    hi Peter, thanks for that, an interesting take as always – hope all is good with you!

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

% trail with acceleration


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by nonetheless
1 year, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/27/2024
Status: Active
Attachments: 2 files
Logo Logo
Loading...