USDJPY trading strategy – 1minTF – SAR and EMA

USDJPY trading strategy – 1minTF – SAR and EMA

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..

 

Share this

Risk disclosure:

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 : How to import ITF files into ProRealTime platform?

PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

  1. Nicolas • 05/28/2016 #

    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!

  2. grizzly • 05/28/2016 #

    Hi Nicolas,
    Yes sorry forgot to mention – this was backtested with a 1 pip spread.
    Enjoy!

  3. noisette • 05/28/2016 #

    Hi Grizzly,
    Thanks for this idea.
    I think that there is a little mistake line 35: Yous should have SELL istead of SELLSHORT.

  4. Hockeytrader • 05/28/2016 #

    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.

    • grizzly • 05/28/2016 #

      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/

  5. Pablo Carmona del Moral • 05/28/2016 #

    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/

    • grizzly • 05/28/2016 #

      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!

  6. Hockeytrader • 05/28/2016 #

    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? 

    • grizzly • 05/28/2016 #

      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.

  7. Nicolas • 05/28/2016 #

    Hi Grizzly, should I change the code accordingly to the mistake that noisette has spotted? Thanks.

    • grizzly • 05/28/2016 #

      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 

  8. Hockeytrader • 05/28/2016 #

    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

  9. manel • 05/28/2016 #

     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.  

    • grizzly • 05/28/2016 #

      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. 

    • grizzly • 05/28/2016 #

      Strong Results today – short off the 109.95 , system took profit 109.27

    • manel • 05/28/2016 #

      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.   

    • grizzly • 05/28/2016 #

      Hi Manel,
      Current system took a short again at 109.29 ; about to be stopped out ~109.55
       

    • manel • 05/28/2016 #

      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.

    • grizzly • 05/28/2016 #

      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

    • manel • 05/28/2016 #

      Ah ok, thanks for the explanation. Was wondering why there were stops on on some and not on others.

    • grizzly • 05/28/2016 #

      Fairly flat day today. 

    • manel • 05/28/2016 #

      Yep, not much movement. Current live short at 108.69 at an increased exposure of 5 presumably due to the run of recent profits.

    • grizzly • 05/28/2016 #

      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

    • fredd81 • 05/28/2016 #

      Mine is still short at  109,044, for over one day now.

    • manel • 05/28/2016 #

      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. 

    • fredd81 • 05/28/2016 #

      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 : 

    • manel • 05/28/2016 #

      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. 

    • grizzly • 05/28/2016 #

      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.

    • manel • 05/28/2016 #

      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. 

    • grizzly • 05/28/2016 #

      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
       

    • grizzly • 05/28/2016 #

      //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
       

    • manel • 05/28/2016 #

      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.

  10. CKW • 05/28/2016 #

    Hi Grizzly,
    Thanks for your sharing. I do not understand well the purpose of line 27,28.
    Can you explain to me?
    Thanks!
     

    • grizzly • 05/28/2016 #

      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)

    • grizzly • 05/28/2016 #

      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

    • Nicolas • 05/28/2016 #

      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!
       

  11. CKW • 05/28/2016 #

    Thanks Grizzly. This should be useful!
     
     

  12. dwgfx • 05/28/2016 #

     Hi Grizzly
    mm3= exponentialaverage[200*3] does this mean mm3=600if Yes, why not code it as 600?

    • grizzly • 05/28/2016 #

      Hi dwgfx
      The code can be 600. Upon creation, i used “x” where 200 in order to optimise the results.

  13. markouk • 05/28/2016 #

    What is the USD/JPY mini? I cannot find it when I search on IG.

  14. markouk • 05/28/2016 #

    Is it under Forex:Spots:Minor FX?

  15. dwgfx • 05/28/2016 #

    Hi Grizzly, I thought I would check in to see how the strategy is going?

    • grizzly • 05/28/2016 #

      @Nicholas – I can’t seem to post screenshots here ? 

    • Nicolas • 05/28/2016 #

      No sorry. I’m working on a robust solution for that and to keep the syntax highlighting at the same time,not easy

  16. grizzly • 05/28/2016 #

    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.
     
    😉
     
     

    • fredd81 • 05/28/2016 #

      Hi grizzly
      Can you please upload the new settings? loosing money since last week in total

  17. grizzly • 05/28/2016 #

    @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

  18. fredd81 • 05/28/2016 #

     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

  19. AleX • 05/28/2016 #

    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?

  20. fredd81 • 05/28/2016 #

    grizzly, did you have any improvements to share? 

    • grizzly • 05/28/2016 #

      Nothing more to share on this one Fredd. Enjoy the code!

  21. AleX • 05/28/2016 #

    Grizzly in demo mode this strategy for two weeks is in red. Its seems not profitable. Do you have same results?
     

  22. fredd81 • 05/28/2016 #

    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. 
     
     

    • grizzly • 05/28/2016 #

       
      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.

    • grizzly • 05/28/2016 #

      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

  23. luigiR • 05/28/2016 #

    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

  24. mr.brymas • 05/28/2016 #

    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.

    • mr.brymas • 05/28/2016 #

      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.

    • grizzly • 05/28/2016 #

      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
       

  25. luigiR • 05/28/2016 #

    Hey, someone can help me !
    how I must change in the code to enter in real trade but with only one contract?
    thanks

    • grizzly • 05/28/2016 #

       
      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

       

    • mr.brymas • 05/28/2016 #

      I saw now that the equity curve looked pretty much the same. I hope that someone can backest it further back 🙂

  26. luigiR • 05/28/2016 #

    Hi grizzly, Thanks a lot, I would try to launch in real…

  27. luigiR • 05/28/2016 #

    and…what you think about put in your code a trailing stop?

  28. Dymjohn • 05/28/2016 #

     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

  29. Elsborgtrading • 05/28/2016 #

    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
     

  30. Fabio Anthony Terrenzio • 05/28/2016 #

    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?

  31. pascal3431 • 05/28/2016 #

    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 ?

  32. pascal3431 • 05/28/2016 #

    Sorry i have an error on downloading the graph PRT …

  33. volpiemanuele • 05/28/2016 #

    hi,
    can I have the latest full code of this strategy ? Thansk

  34. Steve • 05/28/2016 #

    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

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
Doctrading
4 years ago
Stanko Ciao doctrading, grazie per il tuo contributo. Volevo chiederti se hai tenuto in osservazion...
Stanko Buongiorno doctradinge buongiorno a tutti. Vorrei riportare all'attenzione questo sistema p...
Meta Signals Pro Hi, Yes I am monitoring all the strategies posted on this site and I confirm that the strat...
juanj @Holy Grail, glad you like it. Would you perhaps mind sharing your results here: https://www...
CaptainCaveman I am reluctant to say this buy I was a member of Dr Elder trading group for a while . The fa...
micquan The design is too complex and the performance is low.
Francesco78 Hi Pepmartorell, please let's continue the discussion on the forum thread so that we can sha...
Francesco78 Hi Pepmartorell, please let's continue the discussion on the forum thread so that we can sha...
Jusmih1 Hi there, i am looking at your Strategy however when you put in automatic trading mode its ...
Doctrading Defparam cumulateorders = false n=1 // Plus le "ratio" monte, moins il y a de positions ...
Malloc Bonjour :) Je sais que cette stratégie a été partagée il y a de ça plusieurs années mais ...
lilo789 Hi guys! Do you know if it is possible to set the buy size to a relative % of the available...

Top