Hi everyone, i am new to prorealcode
Can anyone help me code the following trailing stop strategy?
Exit the trade when bookprofit retace 40% from its maximum level (minimum level to be triggered = $1000 bookprofit)
Many thanks!
Does anyone have any suggested solution ?
Just record your maximum profit achieved by comparing the position price to the high for long trades (or low for short trades). Then calculate what value would be 40% lower or higher and place a pending order at that price. Something like this – once again not tested and written after just one coffee! Written for non cumulating positions.
defparam cumulatepositions = false
if not longonmarket and (your long conditions) then
buy 1 contract at market
maxprofit = 0
endif
if not shortonmarket and (your short conditions) then
sellshort 1 contract at market
maxprofit = 0
endif
if longonmarket then
maxprofit = max(high - positionprice, maxprofit)
exitprice = positionprice + (maxprofit * 0.60)
if maxprofit >= 1000 then
sell at exitprice stop
endif
endif
if shortonmarket then
maxprofit = max(positionprice - low, maxprofit)
exitprice = positionprice - (maxprofit * 0.60)
if maxprofit >= 1000 then
exitshort at exitprice stop
endif
endif
By the way, is “set stop %trailing ” not available in ProOrder?
the coding was fine in ProBacktest, yet the program said it cannot be used in ProOrder.
I am currently using PRTv10.3