% trail with acceleration
Forums › ProRealTime English forum › ProOrder support › % trail with acceleration
- This topic has 2 replies, 2 voices, and was last updated 10 months ago by nonetheless.
-
-
02/27/2024 at 1:55 PM #228833
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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899// %trailing stop (inc. cumulative)once trailingstoptype = 1if trailingstoptype then//====================trailingpercentlong = tsl // %trailingpercentshort = tss // %once acceleratorlong = acl // typically tsl*0.1once acceleratorshort= acs // typically tss*0.1ts2sensitivity = 2 // [1] close [2] high/low [3] low/high [4] typicalpricePcToKeep = pk //long % to keep at breakevenPcToKeepS = pks //short % to keep at breakeven//====================once steppercentlong = (trailingpercentlong/10)*acceleratorlongonce steppercentshort = (trailingpercentshort/10)*acceleratorshortif onmarket thentrailingstartlong = positionprice*(trailingpercentlong/100)trailingstartshort = positionprice*(trailingpercentshort/100)trailingsteplong = positionprice*(steppercentlong/100)trailingstepshort = positionprice*(steppercentshort/100)endifif not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thennewsl = 0mypositionprice = 0endifpositioncount = abs(countofposition)if newsl > 0 thenif positioncount > positioncount[1] thenif longonmarket thennewsl = max(newsl,positionprice * newsl / mypositionprice)elsenewsl = min(newsl,positionprice * newsl / mypositionprice)endifendifendifif ts2sensitivity=1 thents2sensitivitylong=closets2sensitivityshort=closeelsif ts2sensitivity=2 thents2sensitivitylong=hights2sensitivityshort=lowelsif ts2sensitivity=3 thents2sensitivitylong=lowts2sensitivityshort=highelsif ts2sensitivity=4 thents2sensitivitylong=(typicalprice)ts2sensitivityshort=(typicalprice)endifif longonmarket thenif newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong thennewsl = positionprice+trailingsteplong+(positionprice/100*pk)endifif newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong thennewsl = newsl+trailingsteplongendifendifif shortonmarket thenif newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort thennewsl = positionprice-trailingstepshort-(positionprice/100*pks)endifif newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort thennewsl = newsl-trailingstepshortendifendifif barindex-tradeindex>1 thenif longonmarket thenif newsl>0 thensell at newsl stopendifif newsl>0 thenif low crosses under newsl thensell at marketendifendifendifif shortonmarket thenif newsl>0 thenexitshort at newsl stopendifif newsl>0 thenif high crosses over newsl thenexitshort at marketendifendifendifendifmypositionprice = positionpriceendifif (shortonmarket and newsl > 0) or (longonmarket and newsl>0) thenif positioncount > positioncount[1] thenif longonmarket thennewsl = max(newsl,positionprice * newsl / mypositionprice)endifif shortonmarket thennewsl = min(newsl,positionprice * newsl / mypositionprice)endifendifendifthen i had the idea that the accelerator could be increased under certain circumstances, so i tried changing lines 13,14 to this:
12345678steppercentlong = (trailingpercentlong/10)*acceleratorlongif (longonmarket and cs6) thensteppercentlong = (trailingpercentlong/10)*(acceleratorlong*s1)endifsteppercentshort = (trailingpercentshort/10)*acceleratorshortif (shortonmarket and cb6) thensteppercentshort = (trailingpercentshort/10)*(acceleratorshort*s2)endifin 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.
1 user thanked author for this post.
02/27/2024 at 3:08 PM #228839I 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. 🙂 🙂1 user thanked author for this post.
02/27/2024 at 3:27 PM #228843hi Peter, thanks for that, an interesting take as always – hope all is good with you!
-
AuthorPosts
Find exclusive trading pro-tools on