Hi all, I notice my strategy is good at picking entries and then cumulates the position when it meets further entry signals and is in profit. Trouble is that this kind of strategy needs to be very protective over its gains or as quick as they come, they go on the first downturn.
I would like to set an exit point based purely on the position performance, that is I want to lock in some gains by identifying when position performance is turning south. Exactly how, not sure, but something like:
if positionperf < (Highest positionperf over 20 bars *0.95) (i.e. we’re losing 5% from our peak gain in the last 20 bars) then
close position
endif
n= highest[20](POSITIONPERF)
I am trying to identify the point in the last 20 bars when my position was best. From there I will exit position if it falls below a certain %.
However the command above when pushed through the GRAPH command does not produce the expected, it’s blank. Is this the right way or is there a way with SET STOP %TRAILING y? Note I am using cumulative orders.
You could use the “floatingprofit” variable calculation we made for cfta’s pyramiding trading strategy
This is an idea not tested, it may suit your request I think:
if not onmarket then
highestprofit = 0
endif
if onmarket then
//floating profit
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
highestprofit = max(highestprofit,floatingprofit)
endif
The “highestprofit” variable store the maximum profit met while we are still on market. So you can made your own calculation from there.. Would be glad to know if it works for you! Share your code! 🙂
I have doubts that positionperf works like other variables….
that looks exactly what I am looking for 🙂 Thanks
Hi, I need even simpler, but couldn’t have done it without your help Nicolas, thanks
PositionKeepProfit=0.1 // max allowed drop from highest profit peak
//
//other code
//
if not onmarket then
maxperf=0
else
maxperf= max(positionperf, maxperf)
bailout = (1-positionperf/maxperf) > PositionKeepProfit
if bailout and longonmarket then
SELL AT MARKET
exitreason=-9
elsif bailout and shortonmarket then
EXITSHORT AT MARKET
exitreason=-10
endif
endif