Strange behaviour MFE Trailing Stop
Forums › ProRealTime English forum › ProOrder support › Strange behaviour MFE Trailing Stop
- This topic has 2 replies, 2 voices, and was last updated 5 years ago by robertogozzi.
Tagged: MFE, trailing stop
-
-
11/22/2018 at 5:59 PM #85515
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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899// Common RulesDefparam Cumulateorders = FalseDefparam Preloadbars = 1000// On/offExtratradecriteria = 1 // I.e. Long; Only Enters When The Current Bar High Is Lower Then The Lowest Daily High From Today, Yesterday And Day Before.// SettingsPositionsize = 1SL = 0.88 // % StoplossPT = 1.41 // % Profit TargetNopl=13 //number of points longNops=14 //number of points short// Day & TimeOnce Entertime = 090000Once Lasttime = 100000Once Closetimefriday=173000Tt1 = Time >= EntertimeTt2 = Time <= LasttimeTradetime = Tt1 And Tt2// [mc] Main CriteriaIf Time = Entertime ThenDayopen=openEndifIf High > Dayopen+nopl ThenMclong=1ElseMclong=0EndifIf Low < Dayopen-nops ThenMcshort=1ElseMcshort=0Endif// [ec] Extra CriteriaIf Extratradecriteria ThenMin1 = 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)elseEclong=1Ecshort=1Endif// Long & Short EntryIf Tradetime ThenIf Mclong and Eclong ThenBuy Positionsize Contract At MarketEndifIf Mcshort and Ecshort ThenSellshort Positionsize Contract At MarketEndifEndif//trailing stoptrailingstop = 100//resetting variables when no trades are on marketif not onmarket thenMAXPRICE = 0priceexit = 0endif//case LONG orderif longonmarket thenMAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current tradeif MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexit = MAXPRICE-trailingstop*pointsize*0.63 //set the exit price at the MFE - trailing stop price levelendifendif//exit on trailing stop price levelsif onmarket and priceexit>0 thenSELL AT priceexit STOPendif// Exit At Closetime FridayIf Onmarket ThenIf (Currentdayofweek=5 And Time>=closetimefriday) ThenSell At MarketExitshort At MarketEndifEndif//Profit & Stop LossSET TARGET %PROFIT PTSet Stop %loss SLIf anyone could explain the reason behind this problem (something in the code?), I would be very grateful.
1 user thanked author for this post.
11/23/2018 at 2:20 AM #85542There are two major logical errors to correct:
1 – as from my pic, when the trade on May 9th is opened PRICEEXIT still retains the previous value because the second previous price on May 7th was not properly closed, but automatically closed when a new one was entered on the 8th, so the status ONMARKET has always been true and lines 72-73 have NEVER been executed (my suggestion is to add a condition at line 58 to check OnMarket status:
1If Tradetime AND Not OnMarket Then2 – you trail stops when LONGONMARKET (lines 77-82) but not when SHORTONMARKET.
I also suggest adding these invaluable lines (only 5 variables for real accounts, unlimited for demo ones?) to debug your code using your dearest friend GRAPH:
12345678graph PTgraph SLgraph Tradepricegraph closegraph Currentdayofweekgraph closetimefridaygraph priceexitgraph onmarket11/23/2018 at 8:11 AM #85549The trade opened on the 8th was obviously opposite to the one opened on the 7th.
-
AuthorPosts
Find exclusive trading pro-tools on