When playing around with a MFE Trailing Stop, I came across this very strange problem.
On the 9th of may 2018 at 9:21 on the Germany 30 Cash (€1)(3min) a Long trade is entered for a price of 12,920.9. At 11:39 a first temporary top is reached at 12,960.7 (closing price). A difference of 39.8 points.
In my code the MFE Trailing Stop is set to be activated after 100 points. Despite the fact that the top was not higher than 39.8 points the Long trade will be sold at 14:03.
When I changed the parameter of the priceexit I noticed the following.
Formula: priceexit = MAXPRICE-trailingstop*pointsize*0.63
When the value is between 0.63 and 0.70 the problem will arise and the Long trade will be sold at 14:03.
But when this value is lower than 0.63 or higher than 0.71, the MFE Trailing Stop will work normal again. In those instances the system will sell the Long trade on the 10th of may, after 10:00, when a top of 110.90 points is reached.
This seems like a very strange and range specific problem and I don’t know what is causing it. It also only seems to happen at the 9th of may. On the 8th of june, for example, a similar Long trade is activated, but there don’t seem to be any problems with the MFE Trailing Stop.
// Common Rules
Defparam Cumulateorders = False
Defparam Preloadbars = 1000
// On/off
Extratradecriteria = 1 // I.e. Long; Only Enters When The Current Bar High Is Lower Then The Lowest Daily High From Today, Yesterday And Day Before.
// Settings
Positionsize = 1
SL = 0.88 // % Stoploss
PT = 1.41 // % Profit Target
Nopl=13 //number of points long
Nops=14 //number of points short
// Day & Time
Once Entertime = 090000
Once Lasttime = 100000
Once Closetimefriday=173000
Tt1 = Time >= Entertime
Tt2 = Time <= Lasttime
Tradetime = Tt1 And Tt2
// [mc] Main Criteria
If Time = Entertime Then
Dayopen=open
Endif
If High > Dayopen+nopl Then
Mclong=1
Else
Mclong=0
Endif
If Low < Dayopen-nops Then
Mcshort=1
Else
Mcshort=0
Endif
// [ec] Extra Criteria
If Extratradecriteria Then
Min1 = Min(Dhigh(0),dhigh(1))
Min2 = Min(Dhigh(1),dhigh(2))
Max1 = Max(Dlow(0),dlow(1))
Max2 = Max(Dlow(1),dlow(2))
Eclong = High < Min(Min1,min2)
Ecshort = Low > Max(Max1,max2)
else
Eclong=1
Ecshort=1
Endif
// Long & Short Entry
If Tradetime Then
If Mclong and Eclong Then
Buy Positionsize Contract At Market
Endif
If Mcshort and Ecshort Then
Sellshort Positionsize Contract At Market
Endif
Endif
//trailing stop
trailingstop = 100
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
priceexit = 0
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize*0.63 //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
SELL AT priceexit STOP
endif
// Exit At Closetime Friday
If Onmarket Then
If (Currentdayofweek=5 And Time>=closetimefriday) Then
Sell At Market
Exitshort At Market
Endif
Endif
//Profit & Stop Loss
SET TARGET %PROFIT PT
Set Stop %loss SL
If anyone could explain the reason behind this problem (something in the code?), I would be very grateful.