Hello everyone,
I wanted to share with you a strategy that works on the EUR / USD instrument in 15 minutes timeframe.
I have set up a partial position closure but unfortunately it still does not work in real time.
There is something that is problematic for me, some positions last very long time on the market and pay attention to overnight charges!
Good trades!
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
DEFPARAM CumulateOrders = False DEFPARAM PRELOADBARS = 10000 daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0 Horaire = time >= 000000 and time <= 200000 CloturePartielle = 1 PositionsizeA = 1 PositionsizeV = 1 IF CloturePartielle THEN PositionsizeA = 4 PositionsizeV = 3 ENDIF MM = Average[56,3](totalprice) Newhighest=0 FOR a = 0 TO 1 DO IF DHigh(a)>Newhighest or Newhighest=0 THEN Newhighest = DHigh(a) ENDIF NEXT Newlowest=0 FOR b = 0 TO 1 DO IF DLow(b)<Newlowest or Newlowest=0 THEN Newlowest = DLow(b) ENDIF NEXT Milieu = (Newhighest+Newlowest)/2 Surachat = average[10,4]((Newhighest+Milieu)/2) Survente = average[10,4]((Newlowest+Milieu)/2) CA = (MM > Surachat) and (close crosses over Milieu) CV = (MM < Survente) and (close crosses under Milieu) // Long Entries IF Horaire AND CA AND not daysForbiddenEntry AND NOT SHORTONMARKET THEN BUY PositionsizeA CONTRACTS AT MARKET ENDIF IF CloturePartielle THEN IF LONGONMARKET THEN SELL 1 CONTRACTS AT TRADEPRICE + 40*pointsize LIMIT ENDIF IF LONGONMARKET THEN SELL 1 CONTRACTS AT TRADEPRICE + 20*pointsize LIMIT ENDIF IF LONGONMARKET THEN SELL 1 CONTRACTS AT TRADEPRICE + 18*pointsize LIMIT ENDIF ENDIF // Short Entries IF Horaire AND CV AND not daysForbiddenEntry AND NOT LONGONMARKET THEN SELLSHORT PositionsizeV CONTRACTS AT MARKET ENDIF IF CloturePartielle THEN IF SHORTONMARKET THEN EXITSHORT 1 CONTRACTS AT TRADEPRICE - 40*pointsize LIMIT ENDIF IF SHORTONMARKET THEN EXITSHORT 1 CONTRACTS AT TRADEPRICE - 78*pointsize LIMIT ENDIF ENDIF //MFE //trailing stop trailingstop = 33 //resetting variables when no trades are on market if not onmarket then MAXPRICE = 0 MINPRICE = close priceexit = 0 endif //case SHORT order if shortonmarket then MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level endif 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 //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 EXITSHORT AT priceexit STOP SELL AT priceexit STOP endif //SET TARGET pPROFIT 46 SET STOP pLOSS 200 |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
I don’t have enough bars to properly backtest on, but I’m getting 100% win rate out of this without tweaking with 3:1 runup to drawdown. Works with 10 minutes too. A great strategy!!
Thanks, looks to be a great system but ProOrder cannot handle orders that partially closes positions. Can this be changed and still maintain your idea?
@ Finning
Indeed, I did not notice that the system worked in 10 minutes but the drawdown is much more important.
@ Mags67
You can enable or disable the partial closing position.
– To activate the partial closure of position: CloturePartielle = 1 (On)
– To deactivate the partial closure of position: CloturePartielle = 0 (Off)
Matriciel,
It was amazing, 100% winning trades! Thanks for sharing! I suppose you have applied it – just wonder if it works in real the same way? of course apart from slippage.
Also would like to ask a question about trailing stop as a newbie, wonder if you could help me out. Auto trade I set stop as 30P and trailing stop 10p, a sell order sent in (in demo) last night 6pm, overnight the price had gone down 50p and then pulled up 55p the order still open. Also I noticed the stop is actually 10p on the order. Just confused how exactly these stops works on prorealtime. Thanks!
@ snowmei
I did not apply this robot in real because the positions remain too long on the market, in my opinion.
About trailing stop, it is better that you ask ProRealTime or Nicolas to explain their operations.
Why don’t you close all the position before the market close then re-access the situation and open a trade next morning?
IF time = 210000 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
BTW I am new to the site, how to ask Nicolas?
The variable “Schedule” is not mandatory. It does not change much. I integrated it into the robot because the module “Walk Forward” finds a very slight increase in earnings.
Nicolas is the webmaster of this website.
Hi Matriciel, thanks for your share.
I backtested the strategy with 10000€ from january 2017 to june 2019, great results !!! But in February 2018 I have a loss of 8000€ ! So dangerous if it happens the first month you launch the strategy don’t you think?
Yes indeed.
You have to test this strategy in demo mode for a while before launching it in real life to see if it is doing well.
This strategy is to improve, all remarks is good to take! 🙂
hi,i’m new about this,somebody can explain me how does this strategy works?
thanks
hi, can you explane how to try to launch with pro order?
good job
hI, I’m a beginner of ProRealTime, when i try to launch automatic trading, it pops up the message below.
“Trading systems with orders that partially close a position cannot be sent to ProOrder (ex: SELL SHARES AT MARKET). Make sure that no quantity is specified in instructions to close positions (in this case, the instruction closes the entire position). Ex:
SELL AT MARKET
EXITSHORT AT 1.5 LIMIT”
Could you please advise the possible solution for code modification? Many thanks!!
Apparently there is no support for partial closing. If you want to modify to be viable, remove the parts of the code with “CloturePartielle”.
Thank you for sharing I backtested this strategy from May to Sept 2019 ( max I have) on 15 mins time frame EUR/USD – And ends up 10,180 ???
What is the time frame you have in the posting ?
Hallo Matriciel,
Thanks for the code.
I was playing around, and trying to simplify some of your code:
I changed your code:
Newhighest=0
FOR a = 0 TO 1 DO
IF DHigh(a)>Newhighest or Newhighest=0 THEN
Newhighest = DHigh(a)
ENDIF
NEXT
Newlowest=0
FOR b = 0 TO 1 DO
IF DLow(b)<Newlowest or Newlowest=0 THEN
Newlowest = DLow(b)
ENDIF
NEXT
to a (I thought) easier code (see below), but that gives interesting differences : more gross profit, but time to market increases significanty, which is costly : for the Eur/USD for 10 minutes timeframe. I need to investigate further, but I just want to let you know.
Newhighest=max(DHigh(0), DHigh(1))
Newlowest=max(DLow(0), DLow(1))
Hallo Matriciel,
After short investigation, just to let you know:
Newhighest=max(DHigh(0), DHigh(1))
Newlowest=min(DLow(0), DLow(1))
is much shorter and is exactly the same as your code below: (as you use only two periods to compare)
Newhighest=0
FOR a = 0 TO 1 DO
IF DHigh(a)>Newhighest or Newhighest=0 THEN
Newhighest = DHigh(a)
ENDIF
NEXT
Newlowest=0
FOR b = 0 TO 1 DO
IF DLow(b)<Newlowest or Newlowest=0 THEN
Newlowest = DLow(b)
ENDIF
NEXT
Hello Jan Wind,
Indeed, it’s the same thing.
Thanks for the simplification.
Goodmorning Matriciel
Partial closing is a problem with PRT as it does not like more than one limit or more than one stop at the same time (in one bar), as far as I understand .
Presumably you have thought about it, but would SEQUENTIAL CLOSING helps you out as a form of partial closing which will work ?
(I will test myself later, it is a bit different concept, interesting to test what those results are.)
Coded for example like this:
IF CloturePartielle THEN
IF LONGONMARKET THEN
IF countoflongshares = 4 then
SELL 1 CONTRACTS AT TRADEPRICE + 18*pointsize LIMIT
else
IF countoflongshares = 3 then
SELL 1 CONTRACTS AT TRADEPRICE + 20*pointsize LIMIT
else
IF countoflongshares = 2 then
SELL 1 CONTRACTS AT TRADEPRICE + 40*pointsize LIMIT
else
IF countoflongshares = 1 then
SELL 1 CONTRACTS AT TRADEPRICE + 40*pointsize LIMIT
endif
ENDIF
ENDIF
endif
endif
endif
Hi Jan Wind,
You give me an idea.
This is a new version.
Always in 15 minutes timeframe.
Be careful to drawdown !
DEFPARAM CumulateOrders = True
DEFPARAM PRELOADBARS = 10000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Horaire = time >= 000000 and time <= 200000
CloturePartielle = 1// 1 = ON, 0 = OFF
PositionsizeA = 1
PositionsizeV = 1
MAXSHARES = abs(COUNTOFPOSITION) Surachat) and (close crosses over Milieu)
CV = (MM < Survente) and (close crosses under Milieu)
// Long Entries
IF Horaire AND CA AND MAXSHARES AND not daysForbiddenEntry AND NOT SHORTONMARKET THEN
BUY PositionsizeA CONTRACTS AT MARKET
ENDIF
IF CloturePartielle THEN
IF LONGONMARKET AND COUNTOFLONGSHARES <= 16 THEN
SELL 1 CONTRACTS AT TRADEPRICE + 40*pointsize LIMIT
ENDIF
IF LONGONMARKET AND COUNTOFLONGSHARES <= 4 THEN
SELL 1 CONTRACTS AT TRADEPRICE + 20*pointsize LIMIT
ENDIF
IF LONGONMARKET AND COUNTOFLONGSHARES <= 6 THEN
SELL 1 CONTRACTS AT TRADEPRICE + 18*pointsize LIMIT
ENDIF
ENDIF
IF LONGONMARKET AND summation[35](close < close[6]) = 35 THEN
SELL AT MARKET
ENDIF
// Short Entries
IF Horaire AND CV AND MAXSHARES AND not daysForbiddenEntry AND NOT LONGONMARKET THEN
SELLSHORT PositionsizeV CONTRACTS AT MARKET
ENDIF
IF CloturePartielle THEN
IF SHORTONMARKET AND COUNTOFSHORTSHARES <= 20 THEN
EXITSHORT 1 CONTRACTS AT TRADEPRICE – 78*pointsize LIMIT
ENDIF
IF SHORTONMARKET AND COUNTOFLONGSHARES close[6]) = 32 THEN
EXITSHORT AT MARKET
ENDIF
//MFE
//trailing stop
trailingstop = 33
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
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 //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
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//SET TARGET pPROFIT 46
SET STOP pLOSS 200
I will test your new code, thanks for sharing.
Why do you use DEFPARAM PRELOADBARS = 10000 ? You do not use long period averages, that should be calculated at the first bar, as far as I understand.
Are there currency trades in the weekend ? For indices you do not need the code below.
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
The new code you added gives errors when copying it into PRT, at line 11 MAXSHARES = abs(COUNTOFPOSITION) Surachat) and (close crosses over Milieu)
It happens (sometimes) when you paste PRT code into the textboxes here.
Sorry for the copy / paste. The button “Insert PRT code” does not work.
You are right, the “DEFPARAM PRELOADBARS = 10000” is not used in this code. I kept it by habit that serves me in other bots. As for “daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0”, I put it for security.
I will try to deliver the new code.
That’s the missing part of the code.
From line 11 to 28.
MAXSHARES = abs(COUNTOFPOSITION) Surachat) and (close crosses over Milieu)
CV = (MM < Survente) and (close crosses under Milieu)
Decidedly, it really does not work copy / paste! 🙁
It will help if you open a new Discussion Topic on the forum, not sure how to do it exactly (I can not remember how I did it last time),.
If you do not know how to open a new one, could you please add it to my opened topic at https://www.prorealcode.com/topic/di-tema-trendfollowing-strategy-on-dax-5-min/
You can add your new code using the button “PRT code” in the grey fat line above at the right side !
Thanks in advance !
Keep giving error. Can you hang the code with the * .itf file? Thank you
a workaround could be run parallel systems that buy 1 contract each and then sell at different levels
Yes why not. We must work on this solution …
Hi Matriciel ! Super code ! Did you managed to update your new code somewhere ? I wonder which character gets removed in “abs(COUNTOFPOSITION)*Surachat)” ? Probably un petit “/” slash ? Haha. Good job anyway !
@matriciel
Hey, can you upload a new .itf for the whole code (all of the comments in this thread seem to be merging into one);
Hi all,
This is the last version.
Cheers.
The “Add PRT code” button do not work ! 🙁
DEFPARAM CumulateOrders = True
DEFPARAM PRELOADBARS = 10000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Horaire = time >= 000000 and time <= 200000
CloturePartielle = 1// 1 = ON, 0 = OFF
PositionsizeA = 1
PositionsizeV = 1
MAXSHARES = abs(COUNTOFPOSITION) Surachat) and (close crosses over Milieu)
CV = (MM < Survente) and (close crosses under Milieu)
// Long Entries
IF Horaire AND CA AND MAXSHARES AND not daysForbiddenEntry AND NOT SHORTONMARKET THEN
BUY PositionsizeA CONTRACTS AT MARKET
ENDIF
IF CloturePartielle THEN
IF LONGONMARKET AND COUNTOFLONGSHARES <= 16 THEN
SELL 1 CONTRACTS AT TRADEPRICE + 40*pointsize LIMIT
ENDIF
IF LONGONMARKET AND COUNTOFLONGSHARES <= 4 THEN
SELL 1 CONTRACTS AT TRADEPRICE + 20*pointsize LIMIT
ENDIF
IF LONGONMARKET AND COUNTOFLONGSHARES <= 6 THEN
SELL 1 CONTRACTS AT TRADEPRICE + 18*pointsize LIMIT
ENDIF
ENDIF
IF LONGONMARKET AND summation[35](close < close[6]) = 35 THEN
SELL AT MARKET
ENDIF
// Short Entries
IF Horaire AND CV AND MAXSHARES AND not daysForbiddenEntry AND NOT LONGONMARKET THEN
SELLSHORT PositionsizeV CONTRACTS AT MARKET
ENDIF
IF CloturePartielle THEN
IF SHORTONMARKET AND COUNTOFSHORTSHARES <= 20 THEN
EXITSHORT 1 CONTRACTS AT TRADEPRICE – 78*pointsize LIMIT
ENDIF
IF SHORTONMARKET AND COUNTOFLONGSHARES close[6]) = 32 THEN
EXITSHORT AT MARKET
ENDIF
//MFE
//trailing stop
trailingstop = 33
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
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 //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
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//SET TARGET pPROFIT 46
SET STOP pLOSS 200
Still a problem with this line “MAXSHARES = abs(COUNTOFPOSITION) Surachat) and (close crosses over Milieu)
CV = (MM < Survente) and (close crosses under Milieu)" and I get "Surachat" marked. I'm so curious to try it. Any suggestion?
It’s catastrophic, even the copied / pasted does not work!
That’s the piece of code to stick to instead of “Maxshares”
MAXSHARES = abs(COUNTOFPOSITION) Surachat) and (close crosses over Milieu)
still a pb, even in line 47
The update code doesn’t work.
Apparently slashes are removed from the copy paste <<
I opened a topic to discuss this strategy, feel free to join in and submit improvments :
https://www.prorealcode.com/topic/discussing-matriciel-eurusd-dhigh-dlow/
Ok, let’s go ! 🙂
Seems even greater with EURCAD :-). Many thanks for sharing it.
Matriciel tu est chez quel broker car avec IG malheureusement c’est mort avec les clôtures partiel.
merci
Je suis chez IG.
Je sais que la fonction des clôtures partielles n’est pas autorisée pour l’instant chez IG.
Tu peux quand même utiliser ce code en désactivant cette fonction en mettant : CloturePartielle = 0
OKmerci
Bonjour, comment faire fonctionner sous IG ? Je n’arrive pas a corriger le code.
Merci pour votre aide
Bonjour Florian, c’est un code qui tourne sur la plateforme ProRealTime.
Merci Matriciel ! Je cherche depuis quelques jours à améliorer ta stratégie ! Je pense il y a quelque chose à faire ! @juju333 a travaillé également dessus d’après ce que j’ai vu. Avez vous un what’s app Ou mail pour faire groupe de travail sur la stratégie ? A force je me perds sur le forum … A + Flo
ligne 47 le close ne fonctionne pas:
IF SHORTONMARKET AND COUNTOFLONGSHARES close[6]) = 32 THEN
Bonjour Matriciel, merci pour cette stratégie, néanmoins je pense qu’elle ne serait pas rentable si on rajoute les frais de tenu nocturne chez le broker. l’as-tu deja lancer avec proorder sur un compte demo ou live ?
Bonjour olivierrajzman, je suis d’accord avec toi. Les positions restent bien trop longtemps sur le marché; elles engendreront trop de frais overnight. Je ne l’ai jamais lancée en démo ni en live.
Hi, only with CloturePartielle=0 I get a positive result. Just, for I can’t add it to automatic trading because it uses scaled positions.
Hi thanks, it better work on timeframe 1H
Marcus you run this?
ça ne fonctionne pas pour moi
Hi there Matriciel, great setup by the looks of things, ive imported the code and tried to run a backtest but for some reason its not coming up with any results, its simply showing 0.0 % and n/a – n/a … i changed the CloturePartielle to 0 for PRT but still no data return
Any ideas ? i imported via ITF file direct into PRT
Also just to let you know, im using PRT v10.3 as thats all IG allows at the moment… ive tried everything i can think of to recieve the data from probacktest but it keeps coming up blank even if i copy past the code, or if i import the ITF file directly
I tried using the above strategy but since IG doesnt allow partial closing of the positions. Handled the code in a different manner as was mentioned in one of the thread. Code is working fine and we can play it in LIVE too.
Only issue is number of trades which was coming as 100 for 2 years is reduced to only 40 trades. Can anyone help to increase the number of trades.
DEFPARAM CumulateOrders = False
DEFPARAM PRELOADBARS = 10000
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
Horaire = time >= 000000 and time Newhighest or Newhighest=0 THEN
Newhighest = DHigh(a)
ENDIF
NEXT
Newlowest=0
FOR b = 0 TO 1 DO
IF DLow(b) Surachat) and (close crosses over Milieu)
CV = (MM =trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
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 //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
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
//SET TARGET pPROFIT 46
SET STOP pLOSS 200
Updated the code which has now 100% winning rate in last 2yrs. Yes takes average 1 trade per month. This can work as in current IG. Doesnot require partial closure.
DEFPARAM CumulateOrders = False
MM = Average[20,3](totalprice)
Newhighest=max(DHigh(0), DHigh(1))
Newlowest=min(DLow(0), DLow(1))
Milieu = (Newhighest+Newlowest)/2
Surachat = average[10,4]((Newhighest+Milieu)/2)
Survente = average[10,4]((Newlowest+Milieu)/2)
CA = (MM > Surachat) and (close crosses over Milieu)
CV = (MM < Survente) and (close crosses under Milieu)
// Long Entries
IF CA AND NOT SHORTONMARKET THEN
BUY 2 CONTRACTS AT MARKET
ENDIF
IF LONGONMARKET THEN
SELL AT TRADEPRICE + 25*pointsize LIMIT
ENDIF
// Short Entries
IF CV AND NOT LONGONMARKET THEN
SELLSHORT 2 CONTRACTS AT MARKET
ENDIF
IF SHORTONMARKET THEN
EXITSHORT AT TRADEPRICE – 65*pointsize LIMIT
ENDIF
No Stoploss?
Hi Rajesh Deshpande,
Thank you for this code, I see that the code is perfect, but the positions stay in the market for a long time, do you calculate these fees or a way to put a stoploss.
Bonsoir à tous
Je viens de backtest la stategie sur EUR/USD en graphique 1H sur 1 mois et demi
Total : 13 trades
Gagnant : 12
Neutre : 0
Perdant : 1
Resultat brut : – 40
Le trade perdant fait perdre la totalité des gains.
Serait-il possible d’y ajouter un stop loss breakeven ?
Par avance merci pour vos conseil 😉