Forums › ProRealTime English forum › ProOrder support › Trailing stops remaining static when there are multiple positions › Reply To: Trailing stops remaining static when there are multiple positions
05/09/2019 at 2:36 PM
#98084
For fun (yes I know I’m sad) I decided to create a version that has a trailing take profit as well as a trailing stop loss. So as price moves against you your take profit expectations decrease. Not tested!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
sl = 20 //Stop loss distance slmove = 3 //Price move needed to move stop loss slminstop = 5 //Minimum stop loss distance allowed tp = 20 //Take profit distance tpmove = 3 //Price move needed to move take profit tpminstop = 5 //Minimum take profit distance allowed sl = max(sl, slminstop) tp = max(tp, tpminstop) if longonmarket and adj then slprice = positionprice - sl tpprice = positionprice + tp adj = 0 endif if shortonmarket and adj then slprice = positionprice + sl tpprice = positionprice - tp adj = 0 endif if not onmarket and (your long entry conditions) then buy 1 contract at market slprice = close - sl tpprice = close + tp adj = 1 endif if not onmarket and (your short entry conditions) then sellshort 1 contract at market slprice = close + sl tpprice = close - tp adj = 1 endif if longonmarket and high - sl > slprice + slmove then slprice = min(high - sl, close - slminstop) endif if longonmarket and low + tp < tpprice - tpmove then tpprice = max(low + tp, close + tpminstop) endif if shortonmarket and low + sl < slprice - slmove then slprice = max(low + sl, close + slminstop) endif if shortonmarket and high - tp > tpprice + tpmove then tpprice = min(high - tp, close - tpminstop) endif sell at slprice stop exitshort at slprice stop sell at tpprice limit exitshort at tpprice limit |