DEIOParticipant
Veteran
hi all,
about the strategy I’m trying to apply Nicolas code (logic MFE).
I don’t understand why it seems that doesn’t exit at priceexit.
The code seems to be ok.
Anyone can test and let me know if I’m wrong and where ?
Here the code (this code is on TF 5 minutes):
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//WALL STREET
// 5 MIN.
DEFPARAM cumulateorders = FALSE
CONDAVG = 1
AVG = Average[S](close)
FOR C = 1 TO F
IF AVG[C-1] > AVG[C] THEN
IF CONDAVG = 1 THEN
CONDAVG = 1
ENDIF
ELSE
CONDAVG = 0
ENDIF
NEXT
TIMEWORK = 000000
TIMESTOP = 240000
F = 20
S = 200
MFIFAST = MoneyFlowIndex[F]
MFISLOW = MoneyFlowIndex[S]
BASEMFI = MFISLOW[0] > MFISLOW[F] AND MFISLOW[0] > MFISLOW[ROUND(F/2)] AND MFISLOW[0] > MFISLOW[ROUND(F/F)]
CONDMFIL = MFIFAST[0] CROSSES OVER MFISLOW[0]
//trailingstop = ROUND(CLOSE/800) * PIPSIZE
trailingstop = 30
SIZEBUY = 1
IF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THEN
if not onmarket THEN
IF CONDMFIL AND BASEMFI AND CONDAVG THEN
BUY sizebuy SHARES AT highest[F](HIGH) STOP
endif
ENDIF
endif
if not onmarket then
MAXPRICE = 0
priceexit = 0
endif
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 //set the exit price at the MFE - trailing stop price level
endif
endif
if longonmarket and priceexit>0 then
SELL AT priceexit STOP
endif
thx
Moderator’s edit: code edited to apply the correct PRT code format, please use “insert PRT code” button for future occurences (last one at end of first line of tools in message editor), thanks
Have you tried GRAPH the Trailing Stop and use the Cursor Details (right click, Display, bottom of list) as attached … it does look like it exited at the TS ??
I haven’t studied it as I am giving you an idea so you can monitor / look into it further?
Cheers
GraHal
DEIOParticipant
Veteran
hi GraHal,
I did al lot of test and I catch a issue that in my opinion is very important to me.
I ask Nicolas a question but I have no response at the moment.
I posted the question here:
https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/
Let me know your opinion and waiting for the Nicolas one.
thx a lot
bye
Ah yes the MFE Trail will not get you out of Trade like a Trailing Stop … you need a stop loss or a Trailing Stop also.
The MFE Trail follows / trails the Max Favourable Excursion / MFE so that a Trade that was in profit does not end up a losing Trade having not reached it’s Profit Target (as we all have had happen to us and it’s maddening! ).
So yeah you need an MFE Trail and a normal PRT Stop Loss or PRT Trailing Stop.
Even Nicolas other Trailing Stop (link below) will not act as a Stop Loss in the first period after Trade opens because it needs at least one full period to become operational (I think?).
https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
Hope that Helps?
GraHal
DEIOParticipant
Veteran
Ok clear
Just I would suggest to explain this aspect in the link of MFE explanation, especially for the less expert.
Soon I am going to provide the new code of the strategy on WS 6min, with this fix on the first stop loss.
Thx for your cooperation.
Bye
Yes I agree it is confusing DEIO, it would be better if it is called Trailing Gain with the Max Favorable Excursion (MFE)
And better if the term Trailinggain is used in the code instead of Trailingstop?
I look forward to your latest code
GraHal
JanParticipant
Veteran
Hi GraHal,
thanks for sharing the strategy, sounds promising.
How do you practically deal with the fact that often in optimizing with lots of bars (like 100k bars) the equity shows choppy results at the beginning ? Just ignore or ?
(in my opinion the loisy results are caused as the optimalisation of parameters is based on getting the best END results. An optimalisation given 4.000 profit with a loss of 3.000 in the beginning is more favorable for the optimize-machine then a 3.000 profit with 1.000 euro profit in the beginning. However the latter I would like more)
Kind regards,
Jan
Hi Jan, it’s not my Strategy, it’s DEIO’s … he’s doing all the work.
Yes I agree, ignore the early in period poor performance. Often anyway it just looks worse as it shows a below zero equity curve, but there can be just as much drawdown later on but it’s not so obvious as it’s hidden amongst profits above the zero line?
I usually click on several variable values in the Table of Results and compare equity curves … you can get surprising differences, some more as you describe with less of an early in period drawdown.
Cheers
GraHal
Your full explanation was so good Manel, I raised it on the Platform Support Forum under your Quote … hope you don’t mid?!
Hey Grahal – Of course not. Thanks for raising it. Anything to help make this platform better for all users is always appreciated.
And yes, I am a bit of a perfectionist so cannot sit on stuff if it’s not right however I have learnt that also sometimes you have to work with the limitations you are under and not get unduly frustrated :-). It’s a fine balancing act but being constructive is probably the only way to keep sane !
DEIOParticipant
Veteran
hi all,
I am happy to read your considerations about the strategy on WS.
My basic intention anyway is to obtain a strategy that keep me out of the market during negative phase (it could seem to be a stupid idea
but I have seen too strategies make tons of trade which could be avoided…. 🙂
So with this strategy I wait until the market is good to go long… nothing else.
I don’t like strategies with endless code etc..)
Moreover I have inserted in the codea full managing of the MFE criteria (comprhending the first stop loss too).
here the code:
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//WALL STREET
// 6 MIN.
DEFPARAM cumulateorders = FALSE
CONDAVG = 1
AVG = Average[S](close)
FOR C = 1 TO F
IF AVG[C-1] > AVG[C] THEN
IF CONDAVG = 1 THEN
CONDAVG = 1
ENDIF
ELSE
CONDAVG = 0
ENDIF
NEXT
TIMEWORK = 000000
TIMESTOP = 240000
F = 20
S = 200
MFIFAST = MoneyFlowIndex[F]
MFISLOW = MoneyFlowIndex[S]
BASEMFI = MFISLOW[0] > MFISLOW[F] AND MFISLOW[0] > MFISLOW[ROUND(F/2)] AND MFISLOW[0] > MFISLOW[ROUND(F/F)]
CONDMFIL = MFIFAST[0] CROSSES OVER MFISLOW[0]
trail = ROUND(CLOSE/300) * PIPSIZE
firstpriceexit = tradeprice(1) - trail
trailingstop = round(trail / 3)
SIZEBUY = 1
if not onmarket then
MAXPRICE = 0
priceexit = 0
firststop = 0
endif
IF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THEN
if not onmarket THEN
IF CONDMFIL AND BASEMFI AND CONDAVG THEN
BUY sizebuy SHARES AT highest[F](HIGH) STOP
endif
ENDIF
endif
if longonmarket then
if firststop = 0 then
priceexit = firstpriceexit
firststop = 1
endif
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 //set the exit price at the MFE - trailing stop price level
endif
endif
//GRAPH TRADEPRICE(1)
if longonmarket and priceexit>0 then
//graph priceexit AS "PRICEEXIT"
SELL AT priceexit stop
endif
EDIT: post edited – please use the ‘Insert PRT Code’ button when posting code.
Hey results look well good DEIO … good work!!!
Might you consider a Short version?
PS You forgot to use the Insert PRT Code button again; Nicolas was enjoying his Sunday up to this point! 🙂 🙂
Might you consider a Short version?
And here is the LONG / SHORT version!
//———————————————————————————————-
//———————————————————————————————-
//WALL STREET BUY/SELL v1.0
// 6 MIN.
DEFPARAM cumulateorders = FALSE
CONDAVGbull = 1
CONDAVGbear = 1
AVG = Average[S](close)
FOR C = 1 TO F
IF AVG[C-1] > AVG[C] THEN
IF CONDAVGbull = 1 THEN
CONDAVGbull = 1
ENDIF
ELSE
CONDAVGbull = 0
ENDIF
NEXT
FOR C = 1 TO F
IF AVG[C-1] < AVG[C] THEN
IF CONDAVGbear = 1 THEN
CONDAVGbear = 1
ENDIF
ELSE
CONDAVGbear = 0
ENDIF
NEXT
TIMEWORK = 000000
TIMESTOP = 240000
F = 20
S = 200
MFIFAST = MoneyFlowIndex[F]
MFISLOW = MoneyFlowIndex[S]
BASEMFIbull = MFISLOW[0] > MFISLOW[F] AND MFISLOW[0] > MFISLOW[ROUND(F/2)] AND MFISLOW[0] > MFISLOW[ROUND(F/F)]
CONDMFILbull = MFIFAST[0] CROSSES OVER MFISLOW[0]
BASEMFIbear = MFISLOW[9] < MFISLOW[F] AND MFISLOW[7] < MFISLOW[ROUND(F/2)] AND MFISLOW[0] < MFISLOW[ROUND(F/F)]
CONDMFILbear = MFIFAST[1] CROSSES UNDER MFISLOW[1]
trail = ROUND(CLOSE/300) * PIPSIZE
firstpriceexitbull = tradeprice(1) - trail
firstpriceexitbear = tradeprice(1) + trail
trailingstop = round(trail / 3)
SIZEBUY = 1
SIZESELL = 1
if not onmarket then
MAXPRICE = 0
MINPRICE = 0
priceexitbull = 0
priceexitbear = 0
firststopbull = 0
firststopbear = 0
endif
IF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THEN
if not onmarket THEN
IF CONDMFILbull AND BASEMFIbull AND CONDAVGbull THEN
BUY sizebuy SHARES AT highest[F](HIGH) STOP
endif
ENDIF
endif
IF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THEN
if not onmarket THEN
IF CONDMFILbear AND BASEMFIbear AND CONDAVGbear THEN
SELLSHORT sizesell SHARES AT lowest[F](LOW) STOP
endif
ENDIF
endif
if longonmarket then
if firststopbull = 0 then
priceexitbull = firstpriceexitbull
firststopbull = 1
endif
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
priceexitbull = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
if shortonmarket then
if firststopbear = 0 then
priceexitbear = firstpriceexitbear
firststopbear = 1
endif
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is lower than the trailingstop then
priceexitbear = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//GRAPH TRADEPRICE(1)
if longonmarket and priceexitbull>0 then
//graph priceexit AS "PRICEEXIT"
SELL AT priceexitbull stop
endif
if shortonmarket and priceexitbear>0 then
//graph priceexit AS "PRICEEXIT"
EXITSHORT AT priceexitbear stop
endif
Good trades!
Gertrade
JanParticipant
Veteran
Deio,
with the code below, the CONDAVG is only set to 1 if during the complete fast average period (F) the slow average always increases, to my understanding.
Why did you add this code ?
CONDAVG = 1
AVG = Average[S](close)
FOR C = 1 TO F
IF AVG[C–1] > AVG[C] THEN
IF CONDAVG = 1 THEN
CONDAVG = 1
ENDIF
ELSE
CONDAVG = 0
ENDIF
NEXT
Hey thanks Gertrade, I’ve set both DEIO Long only and your Long & Short going Live @ 0.5 Lot size on both … I’ll monitor each trade as it develops and report back.
The Short trades do give a useful boost to profits on backtest, see attached.
Cheers
GraHal
DEIOParticipant
Veteran
HI JanWd,
I set such conditions just because I wanted that tha BASE AVG (the slow one) be always increasing in the last F periods.
If I used the last S periods the condition would be too restrictive and trades would be very few.
you can test it substituting in the loop … FOR C= 1 TO F WITH FOR C = 1 TO s
thx
bye