MFI CROSS strategy to test and improve on Wall Street 6 minutes
Forums › ProRealTime English forum › ProOrder support › MFI CROSS strategy to test and improve on Wall Street 6 minutes
- This topic has 38 replies, 8 voices, and was last updated 6 years ago by DEIO.
-
-
03/15/2018 at 1:45 PM #65366
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):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657//-----------------------------------------------------------------------------------------------//-----------------------------------------------------------------------------------------------//WALL STREET// 5 MIN.DEFPARAM cumulateorders = FALSECONDAVG = 1AVG = Average[S](close)FOR C = 1 TO FIF AVG[C-1] > AVG[C] THENIF CONDAVG = 1 THENCONDAVG = 1ENDIFELSECONDAVG = 0ENDIFNEXTTIMEWORK = 000000TIMESTOP = 240000F = 20S = 200MFIFAST = 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) * PIPSIZEtrailingstop = 30SIZEBUY = 1IF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THENif not onmarket THENIF CONDMFIL AND BASEMFI AND CONDAVG THENBUY sizebuy SHARES AT highest[F](HIGH) STOPendifENDIFendifif not onmarket thenMAXPRICE = 0priceexit = 0endifif 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 //set the exit price at the MFE - trailing stop price levelendifendifif longonmarket and priceexit>0 thenSELL AT priceexit STOPendifthx
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
03/15/2018 at 2:08 PM #65367Have 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
GraHal03/16/2018 at 5:09 PM #65456hi 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
03/16/2018 at 5:27 PM #65460Ah 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?
GraHal03/16/2018 at 5:37 PM #65462Ok 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
03/16/2018 at 6:05 PM #65464Yes 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
GraHal03/17/2018 at 3:11 PM #65499Hi 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
03/17/2018 at 3:49 PM #65505Hi 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
GraHal03/17/2018 at 7:53 PM #65534Your 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 !
1 user thanked author for this post.
03/18/2018 at 8:39 AM #65556hi 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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263//-----------------------------------------------------------------------------------------------//-----------------------------------------------------------------------------------------------//WALL STREET// 6 MIN.DEFPARAM cumulateorders = FALSECONDAVG = 1AVG = Average[S](close)FOR C = 1 TO FIF AVG[C-1] > AVG[C] THENIF CONDAVG = 1 THENCONDAVG = 1ENDIFELSECONDAVG = 0ENDIFNEXTTIMEWORK = 000000TIMESTOP = 240000F = 20S = 200MFIFAST = 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) * PIPSIZEfirstpriceexit = tradeprice(1) - trailtrailingstop = round(trail / 3)SIZEBUY = 1if not onmarket thenMAXPRICE = 0priceexit = 0firststop = 0endifIF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THENif not onmarket THENIF CONDMFIL AND BASEMFI AND CONDAVG THENBUY sizebuy SHARES AT highest[F](HIGH) STOPendifENDIFendifif longonmarket thenif firststop = 0 thenpriceexit = firstpriceexitfirststop = 1endifMAXPRICE = 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 //set the exit price at the MFE - trailing stop price levelendifendif//GRAPH TRADEPRICE(1)if longonmarket and priceexit>0 then//graph priceexit AS "PRICEEXIT"SELL AT priceexit stopendifEDIT: post edited – please use the ‘Insert PRT Code’ button when posting code.
03/18/2018 at 12:27 PM #6556203/19/2018 at 9:14 AM #65648Might you consider a Short version?
And here is the LONG / SHORT version!
WALL STREET BUY/SELL 6 MIN123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103//———————————————————————————————-//———————————————————————————————-//WALL STREET BUY/SELL v1.0// 6 MIN.DEFPARAM cumulateorders = FALSECONDAVGbull = 1CONDAVGbear = 1AVG = Average[S](close)FOR C = 1 TO FIF AVG[C-1] > AVG[C] THENIF CONDAVGbull = 1 THENCONDAVGbull = 1ENDIFELSECONDAVGbull = 0ENDIFNEXTFOR C = 1 TO FIF AVG[C-1] < AVG[C] THENIF CONDAVGbear = 1 THENCONDAVGbear = 1ENDIFELSECONDAVGbear = 0ENDIFNEXTTIMEWORK = 000000TIMESTOP = 240000F = 20S = 200MFIFAST = 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) * PIPSIZEfirstpriceexitbull = tradeprice(1) - trailfirstpriceexitbear = tradeprice(1) + trailtrailingstop = round(trail / 3)SIZEBUY = 1SIZESELL = 1if not onmarket thenMAXPRICE = 0MINPRICE = 0priceexitbull = 0priceexitbear = 0firststopbull = 0firststopbear = 0endifIF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THENif not onmarket THENIF CONDMFILbull AND BASEMFIbull AND CONDAVGbull THENBUY sizebuy SHARES AT highest[F](HIGH) STOPendifENDIFendifIF CURRENTTIME >= TIMEWORK AND TIME <= TIMESTOP THENif not onmarket THENIF CONDMFILbear AND BASEMFIbear AND CONDAVGbear THENSELLSHORT sizesell SHARES AT lowest[F](LOW) STOPendifENDIFendifif longonmarket thenif firststopbull = 0 thenpriceexitbull = firstpriceexitbullfirststopbull = 1endifMAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current tradeif MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexitbull = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price levelendifendifif shortonmarket thenif firststopbear = 0 thenpriceexitbear = firstpriceexitbearfirststopbear = 1endifMINPRICE = MIN(MINPRICE,close) //saving the MFE of the current tradeif tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is lower than the trailingstop thenpriceexitbear = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price levelendifendif//GRAPH TRADEPRICE(1)if longonmarket and priceexitbull>0 then//graph priceexit AS "PRICEEXIT"SELL AT priceexitbull stopendifif shortonmarket and priceexitbear>0 then//graph priceexit AS "PRICEEXIT"EXITSHORT AT priceexitbear stopendifGood trades!
Gertrade
03/19/2018 at 10:45 AM #65652Deio,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 = 1AVG = Average[S](close)FOR C = 1 TO FIF AVG[C–1] > AVG[C] THENIF CONDAVG = 1 THENCONDAVG = 1ENDIFELSECONDAVG = 0ENDIFNEXT03/19/2018 at 12:04 PM #65658Hey 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
GraHal03/20/2018 at 6:18 AM #65788HI 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
-
AuthorPosts
Find exclusive trading pro-tools on