Hi all, i have previously had a word document with a bunch of algostuff written down, my computer with that document however has crashed and for some reason, the only thing i didnt get out from it, was the following thing:
I have previously asked for help with this: https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/
Im not sure if it has been requested before but i could not find it, using the search bar, altough i know i have asked about this before (im pretty sure at least). Sorry for asking about it again now maybe 1-2 years later 🙂 Would appreciate the help as i dont think its too hard to do, i just want it done right.
I have earlier recieved help to modify the MFE trailing stop in the link so that it would Start after XX pips in profit. This is the code:
//trailing stop
trailingstop = 80 // 65
StartTrailingStopValue = 30 // 20
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-close > StartTrailingStopValue*pointsize then
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if close-tradeprice(1) > StartTrailingStopValue*pointsize then
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
However what i need help with is to evolve this MFE trailing stop further, i hope my example is easy to understand.
Lets say the Target = 100 pips.
If the trade is currently 50 pips in profit: Start a trailing stop loss of 25 pips.
But if the trade moves up and is now 85 pips in profit: Start a trailing stop loss of 10 pips.
So in other words: If the trade moves very close to the target, i want to change the stop loss so it gets tighter. I had one code with 3 levels in total, but i think only 2 is needed, at least for my use 🙂
Any help is very appreciated.