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:
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:
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
//trailing stop
trailingstop=80// 65
StartTrailingStopValue=30// 20
//resetting variables when no trades are on market
ifnotonmarketthen
MAXPRICE=0
MINPRICE=close
priceexit=0
endif
//case SHORT order
ifshortonmarketthen
MINPRICE=MIN(MINPRICE,close)//saving the MFE of the current trade
ifMAXPRICE-tradeprice(1)>=trailingstop*pointsizethen//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
ifonmarketandpriceexit>0then
EXITSHORTATpriceexitSTOP
SELLATpriceexitSTOP
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 🙂
Nothing to do with your question but at a glance I think the MFE is calculated wrong. When long the MFE is not the close but the high and when short it is not the close but the low. So it should be:
1
2
3
4
5
ifshortonmarketthen
MINPRICE=MIN(MINPRICE,low)//saving the MFE of the current trade
iflongonmarketthen
MAXPRICE=MAX(MAXPRICE,high)//saving the MFE of the current trade
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.