Hi everyone,
Wanted to share my simple Automated strategy for USD/JPY mini using a 1minute timeframe, with SAR and EMA indicators.
Code also includes money management to adjust for position sizes – adjust this for your liking etc.
Any thoughts or suggestion is welcome! Enjoy..
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 |
DEFPARAM CumulateOrders = false //INDICATORS// mm3= exponentialaverage[200*3] mm2= exponentialaverage[200*1.5] mm1= exponentialaverage[200*1] PARABOLIC = SAR[0.001,0.001,0.2] C1 = PARABOLIC>HIGH //RED SAR = SHORT C2 = PARABOLIC<LOW //GREEN SAR = LONG Spread = 1.1 // //MONEY MGT// Equity = (Strategyprofit+20000) Risk = round(Equity/100000) Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0 streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0 if losses then n = max(abs(round(max(3+risk-2,risk-2))),2) elsif not losses then n = max(abs(round(max(3+risk,risk))),2) endif if streak then n = max(abs(round(max(5+risk,risk))),2) endif // T1 = (barindex-tradeindex>=3) T2 = (barindex-tradeindex>=3) //ENTER LONG// if (mm1>mm2 and mm2>mm3) and c2 AND T1 then buy n contract at breakeven+spread*pipsize limit breakeven = parabolic if T2 and longonmarket then sellshort at breakeven+spread*pipsize stop endif endif //ENTER SHORT// if (mm1<mm2 and mm2<mm3) and c1 and T1 then sellshort n contract at breakeven-spread*pipsize limit breakeven = parabolic if T2 and shortonmarket then exitshort at breakeven-spread*pipsize stop endif endif |
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 :
Filename : download the ITF files
How to import ITF files into ProRealTime platform?
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hi grizzly and thanks for your contribution. Nice coding, well done! Because I’m currently away from my computer, I didn’t test your strategy. Did your backtest were made with spread included?
What you did with your money management is very interesting : increase exposure only if at least 3 trades in a row were in profit, or decrease it when losses come back.. that’s clever. This kind of code snippet deserve a blog post for future reference!
Hi Nicolas,
Yes sorry forgot to mention – this was backtested with a 1 pip spread.
Enjoy!
Hi Grizzly,
Thanks for this idea.
I think that there is a little mistake line 35: Yous should have SELL istead of SELLSHORT.
Nice spot!
Hey Grizzly. I’ll start this strategy on demo tomorrow. That money management code is awesome and i’ll put it in my strategies on demo tomorrow. Thanks for sharing your knowledge.
Hi Hockeytrader,
let me know how you go!
i have posted a slight variation to it here were you can control the Risk Ratio
http://www.prorealcode.com/topic/win-loss-streak/
Hello grizzly, your program is very very good, while looking at the post that you realize 2 weeks ago is the same …. well … because it is so similar that contains the same variables and the same risk management … you you deserve comment mine and I’ve improved as follows varied …. I realize the possibility that more than one brackdown an amount in a candle out immediately without the need for mobiles averages Cruzen, with your program this may also earn 20% more profit …. you can try, and if you do not go, I can answer this message and effected, with love. kisses.
http://www.prorealcode.com/prorealtime-trading-strategies/3-moving-average-trading-strategy-eurusd/
Hi Pablo
In fact the EMA section of my code is an adaption of yours. I typically like to combine this with SAR.
Overall it seems to work quite well!
Hey Grizzly. The strategy has been running overnight and there’s one position opened. I’m trying to figure out the take profits and stop levels. Can you explain it to me?
Hi Hockey
Techinicaly the code doesn’t have a target profit or stop level.
The Parabloc SAR is used to effectively exit the position.
I also have this code currently running with some good results today. Will post performance at end of week.
Hi Grizzly, should I change the code accordingly to the mistake that noisette has spotted? Thanks.
Hi Nicolas – could you run the code with both Sellshort and Sell and see what results are ? Unfortunately I only have access to 100,000 candles with IG index
I guess i have trouble. Check this picture of the backtest and the demo account, Any thoughts on what it does this?
https://imgur.com/delete/89ikhjWdmk4By8u
Hi Grizzly – many thanks for sharing the strategy, the money management code is very inventive. Would be interested to know what live trading results you have this week as well to compare. The stop and reverse levels seem to be working as I can see they are being changed every minute in PRT. I’m also running it in live since yesterday, today has shown 5 losses in a row. Since its been a rangebound market with a some volatility and this strategy is based on parabolic SAR then these losing trades are to be expected. Now waiting for a trending market to gauge how well it works on profits.
Hi Manel, thanks for your feedback..
Monday was profitable , but Tuesday was a loss day (4-5 straight losses).
Will see how this plays out end of week and next.
Strong Results today – short off the 109.95 , system took profit 109.27
Yes, very good trade results today so looks promising. However, I notice the current live short @ 109.29 does not have any stops attached to it like normal. PRT is not creating any, wondering if there is an issue.
Hi Manel,
Current system took a short again at 109.29 ; about to be stopped out ~109.55
Hi – Yes, my position got closed out at 109.56. The short got reopened 7mins later at 109.56 though, so now live with another short, seems strange. Did you also notice that the system did start creating any stops for the previous position until 12am CET ? Do you know why this is ? There are no stops on the new one either.
Hi Manel – yes ; reshorted at 109.56 and currently in the money
There is no Stop attached since the parabolic is < than the entry price. i.e. In the money
Ah ok, thanks for the explanation. Was wondering why there were stops on on some and not on others.
Fairly flat day today.
Yep, not much movement. Current live short at 108.69 at an increased exposure of 5 presumably due to the run of recent profits.
I think we have different results here Manel. My system didn’t engaged short at 108.69.
System executed long ~1hour ago at 108.94
Mine is still short at 109,044, for over one day now.
Ok, so that’s very concerning. Are you running on live or demo ? So far today has been all losses – last position was long +2 @ 108.85 just closed out 10 mins ago @ 107.46 (huge loss due NFP figures just out at 1.30pm). No current position.
Before then my +5 @ 108.69 (loss) ; followed by +5 @ 108.94 (loss) ; -3 @108.70 (loss) ; +3 108.95 (loss); +2 108.85 (loss) . So its strange that my PRT system triggered so many more trades than yours.
It was some error between IG and PRT, restaretd an now it seems to close and open new orders just fine. just runnig 1 contract in demo mode, Have two systems running, one with sellshort on row 35 and one with only sell. just to test the diffrence.
Not much to do about NFP :
Hi – Fred, thanks for the update. This is even more concerning. It makes this whole automated trading process unworkable if systems cannot be relied upon. How are users supposed to know when a system is running fine or when it has a problem ? I’ll contact PRT support to ask them what went wrong, unless someone here has an explanation. Back to the drawing board I guess, I’ve stopped all my trading systems in live for the moment.
Hi Manel – yes i normally have slight differences between Demo and Live PRT in terms of execution when using the exact same code.
I’m editting the code at the moment in light of the NFP drop. That was a big loss unfortunately so down on the week.
Hi – so you had the same trades as me then ? that’s at least good to know that there’s not a huge difference. Yes, I was thinking the same thing re NFP, once every few months it seems that we get a huge move and the system can’t compensate quickly enough. There was a similar situation on 27/04 that caused a 300+ move within minutes which negatively influenced the backtest results significantly. Not sure how you adjust for that other than having an overall or trailing SL trigger perhaps.
I have included this is my code for this week.
You can see that in the case of NFP Friday, the system switches from Long (108.85) to Short (107.97) on the very next candle and rides the short all the way down to 106.80.
//PROTECTION - Volatility spikes e.g. NFP or BoJ days//
GappingLoss = abs(parabolic-close)>(70*pipsize) //~70pip from SAR loss
GappingProfit = abs(parabolic-close)>(50*pipsize) //~50pip from SAR gain
if T1 and longonmarket and positionperf<0 and gappingLoss then
sellshort round(n*1.5) contract at market
//exitshort at parabolic stop - not included
elsif T1 and shortonmarket and positionperf<0 and gappingLoss and c2 then
buy round(n*1.5) contract at market
//sell at parabolic stop - not included
endif
if T1 and longonmarket and positionperf>0 and gappingProfit then
sellshort round(n*1.5) contract at market
//exitshort at parabolic stop - not included
elsif T1 and shortonmarket and positionperf>0 and gappingProfit and c2 then
buy round(n*1.5) contract at market
//sell at parabolic stop - not included
endif
//PROTECTION - Volatility spikes e.g. NFP or BoJ days//
GappingLoss = abs(parabolic-close)>(70*pipsize) //~70pip from SAR loss
GappingProfit = abs(parabolic-close)>(50*pipsize) //~50pip from SAR gain
if T1 and longonmarket and positionperf<0 and gappingLoss then
sellshort round(n*1.5) contract at market
//exitshort at parabolic stop - not included
elsif T1 and shortonmarket and positionperf<0 and gappingLoss and c2 then
buy round(n*1.5) contract at market
//sell at parabolic stop - not included
endif
if T1 and longonmarket and positionperf>0 and gappingProfit then
sellshort round(n*1.5) contract at market
//exitshort at parabolic stop - not included
elsif T1 and shortonmarket and positionperf>0 and gappingProfit and c2 then
buy round(n*1.5) contract at market
//sell at parabolic stop - not included
endif
Hi – Great work on the new code. I can see that it does indeed stop the escalation of losses due to big moves and instead takes the direction of the trend (on both the 03/06 and 28/04 moves).
The best/worst gain/loss of the system is also much more equal now (1:1 compared to 1:3 previously) which I personally think also makes for a more stable strategy. I also checked the 1 min ranges of the rate over the past 3 mths to see if the 70/50 limits were wide enough so as not to cause false trades on any spikes that immediately retraced and couldn’t find anything statistically significant, so hopefully this will be robust enough. Lets see how the testing goes going forward. Thanks again for your contribution here.
Hi Grizzly,
Thanks for your sharing. I do not understand well the purpose of line 27,28.
Can you explain to me?
Thanks!
Hi CKW,
The code below forces a position to be open for at least 3 candles ( 3 x 1 min candles ).
I find this normally helps normalise any premature entry or exits due to spikes.
T1 = (barindex-tradeindex>=3)
T2 = (barindex-tradeindex>=3)
Hi Manel – yes ; reshorted at 109.56 and currently in the money
There is no Stop attached since the parabolic is < than the entry price
Andres post a code in the forum to avoid NFP days, just here in the Spanish forum: http://www.prorealcode.com/topic/dato-de-empleo-usa/
It may be of interest for forex related strategies!
Thanks Grizzly. This should be useful!
Hi Grizzly
mm3= exponentialaverage[200*3] does this mean mm3=600if Yes, why not code it as 600?
Hi dwgfx
The code can be 600. Upon creation, i used “x” where 200 in order to optimise the results.
What is the USD/JPY mini? I cannot find it when I search on IG.
should be there
Is it under Forex:Spots:Minor FX?
CFD
Hi Grizzly, I thought I would check in to see how the strategy is going?
@Nicholas – I can’t seem to post screenshots here ?
No sorry. I’m working on a robust solution for that and to keep the syntax highlighting at the same time,not easy
I’ve made several modifications to the code posted above since then.
Live account results:
Week 1 was ~52k Yen loss due to the NFP which I subsequently fixed up.
Week 2 was ~15k Yen gain
Week 3 was ~62k Yen gain. Short week as I didn’t start running it until 14/06/2016 and neither on the 17/06/2016.
😉
Hi grizzly
Can you please upload the new settings? loosing money since last week in total
@fredd
Happy to help you improve it. Firstly, where are you loosing on the trades and what time zone have you configured ? Im using UTC+1
Hi grizzly
I have all currencies UTC+1
After today im in profit but thats after 3 small wins and one bigger. i saw you hade lower worst trade and better best trade and more win/ loss ratio on you new screenshot, what have you improved ? my code is as follow
Havent changed anything and added NFP code at the bottom
Thx
//————————————————————————-// Main code : USDJPY_AVG+SAR_2//————————————————————————-DEFPARAM CumulateOrders = false//INDICATORS//mm3= exponentialaverage[200*3]mm2= exponentialaverage[200*1.5]mm1= exponentialaverage[200*1]PARABOLIC = SAR[0.001,0.001,0.2]C1 = PARABOLIC>HIGH //RED SAR = SHORTC2 = PARABOLIC<LOW //GREEN SAR = LONGSpread = 1.1//
//MONEY MGT//Equity = (Strategyprofit+20000)Risk = round(Equity/100000)Losses = positionperf(1)<0 and positionperf(2)<0 and positionperf(3)<0streak = positionperf(1)>0 and positionperf(2)>0 and positionperf(3)>0if losses thenn = max(abs(round(max(3+risk-2,risk-2))),2)elsif not losses thenn = max(abs(round(max(3+risk,risk))),2)endifif streak thenn = max(abs(round(max(5+risk,risk))),2)endif//
T1 = (barindex-tradeindex>=3)T2 = (barindex-tradeindex>=3)
//ENTER LONG//if (mm1>mm2 and mm2>mm3) and c2 AND T1 thenbuy n contract at breakeven+spread*pipsize limitbreakeven = parabolicif T2 and longonmarket thensell at breakeven+spread*pipsize stopendifendif
//ENTER SHORT//if (mm1<mm2 and mm2<mm3) and c1 and T1 thensellshort n contract at breakeven-spread*pipsize limitbreakeven = parabolicif T2 and shortonmarket thenexitshort at breakeven-spread*pipsize stopendifendif
//PROTECTION – Volatility spikes e.g. NFP or BoJ days//GappingLoss = abs(parabolic-close)>(70*pipsize) //~70pip from SAR lossGappingProfit = abs(parabolic-close)>(50*pipsize) //~50pip from SAR gain
if T1 and longonmarket and positionperf<0 and gappingLoss thensellshort round(n*1.5) contract at market//exitshort at parabolic stop – not includedelsif T1 and shortonmarket and positionperf<0 and gappingLoss and c2 thenbuy round(n*1.5) contract at market//sell at parabolic stop – not includedendif
if T1 and longonmarket and positionperf>0 and gappingProfit thensellshort round(n*1.5) contract at market//exitshort at parabolic stop – not includedelsif T1 and shortonmarket and positionperf>0 and gappingProfit and c2 thenbuy round(n*1.5) contract at market//sell at parabolic stop – not includedendif
Hello, it seems that this strategy loose all money with 200.000 bars on IG account, and profitable with 100.000. I do something wrong?
grizzly, did you have any improvements to share?
Nothing more to share on this one Fredd. Enjoy the code!
Grizzly in demo mode this strategy for two weeks is in red. Its seems not profitable. Do you have same results?
Same for me and i used it on live account :
Gave ok result on demo for 14 days except NFP so i put it live last week except during brexit
Trying to figure out some optimization for exit earlier in lossing trades.
Guys, my results posted above will be slightly different as I have been running a modified version. It’s largely the same code but with my own Risk parameters which will vary according your account size etc.
Week 4 was ~15k Yen gain. Short week as I stopped the system on Thursday (! day before Brexit vote)
Week 5 – currently a ~40k Yen loss.
My advice is to analyse the back test results and “improve” the code depending on your Risk. Copying pasting what i have shared will yield different results in Live/Demo. Thanks
Hallo grizzly, Thanks for sharing your strategy, I’m a beginner and I would try to launch your system on pro order but I need to know how it’s necessary to change the parameters to buy only one contract.
thanks again and I hope in your reply
bye
Hey grizzly and thank you for your code. I especially like the exit via SAR instead of hard stops! I have the IG version of PRT with only 100000 bars. So if I backtest the code today i can only backtest it to 30/03-16. It would be nice if someone with the real PRT could test the new code that fredd81 summit in the thread and post a picture of the result here 🙂
Take care.
It would also be nice to see a backtest with (n=1) because it gives a much more correct view if the strategy i profitable or not.
Hi Mr.brymas
A very valid point – all my codes have a variable N in for the Risk factor ; but i always rebase this to test how it performs without increasing $ Risk.
Risk = round(Equity/100000) * 0
Hey, someone can help me !
how I must change in the code to enter in real trade but with only one contract?
thanks
Luigi
Use this for always 1 contract:
if losses then
n = max(abs(round(max(1+risk-2,risk-2))),1)
elsif not losses then
n = max(abs(round(max(1+risk,risk))),1)
endif
if streak then
n = max(abs(round(max(1+risk,risk))),1)
endif
I saw now that the equity curve looked pretty much the same. I hope that someone can backest it further back 🙂
Hi grizzly, Thanks a lot, I would try to launch in real…
and…what you think about put in your code a trailing stop?
Can someone explain the coding of the exponential moving average, I know exponentialaverage[200] is a 200 period average but what do these mean:-
mm3= exponentialaverage[200*3]
mm2= exponentialaverage[200*1.5]
mm1= exponentialaverage[200*1]regardsdymjohn
Hi Dymjohn
In the absence of a better explanation … when optimising parameters you could use – for example – X (in place of 200) from 5 to 100 in increments of 5 and thus complete one optimisation run, resulting in max profit at X = 50 and EAs would then end up as …
mm3 = EA[50*3] = EA[150]mm2 = EA[50*1.5] = EA[75]mm1 = EA[50*1]= EA[50]
Hope above makes sense??
CheersGraHal
Hi Grizzly and very nice code. It seems like the BREXIT shout down the Equity curve when backtesting, how did it perform Live?
Cheers Kasper
If you have an EA with 600 period, why you leave 200 DEFPARAM preloadbars? I think this must be set to 600 at least? is it right?
I like this Strategy very much, but the snippet below (starting at Line 34 in the full Code) leaves me thinking it needs improving? Anybody else think the same please?
The weird thing is it works as below, but I cant help thinking that more conditions / trading rationale behind the exit would give more profit? I have tried more conditions in the Strategy but results in less profit 🙁
Hoping this will get the full Strategy ‘back on the radar’ and discussed further by members?
if T2 and longonmarket then
sellshort at breakeven+spread*pipsize stop
endif
endif
Thank YouGraHal
Ha … having spent quite some time using the GRAPH function and still not yet fully understanding when and why everything happens in this Strategy … I now think even the snippet above is very! 🙂 I can’t (yet) improve on it anyway … can you?
GraHal
I tested this strategy: something is not clear ! why does it open short position to the break of the bearish SAR ? (See for example attached graph which shows a losing trade.)The reversal of trend is precisely at the break of the SAR, so why not buy instead of selling ?
Sorry i have an error on downloading the graph PRT …
Hi Pascal
There’s lots not clear to me! 🙂
Are you referring to C1 = PARABOLIC>HIGH //RED SAR = SHORT? If Yes, then attached shows the condition of the SAR break ... the red dots crossing over the High. Does that help at all?
Mmm just remembered, the website doesnt allow pics to be attached to Comments in the Library. Here’s a link and a a few words that may help
The indicator is below prices when prices are rising and above prices when prices are falling.
http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:parabolic_sar
GraHal
hi,
can I have the latest full code of this strategy ? Thansk
Hey Grizzly, I know this probably doesn’t belong to this post, however, don’t know how else to get in touch with you.
Assuming you have an IG linked PRT account, have you managed to get PRT Premium linked to an IG account? I am finding this may not be possible for Australians.
CheersSteve