grizzly

USDJPY trading strategy - 1minTF - SAR and EMA

Category: Strategies By: grizzly Created: May 28, 2016, 7:09 PM
May 28, 2016, 7:09 PM
Strategies
78 Comments
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..

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

 

Download
Filename: Week3.jpg
Downloads: 153
Download
Filename: USDJPY_AVGSAR_2.itf
Downloads: 390
grizzly
grizzly Average
Operating in the shadows, I hack problems one by one. My bio is currently encrypted by a complex algorithm. Decryption underway...
Author’s Profile

Comments

Steve
9 years ago
#

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.

Cheers
Steve

volpiemanuele
10 years ago
#

hi,

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

GraHal
10 years ago
#

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

pascal3431
10 years ago
#

Sorry i have an error on downloading the graph PRT ...

pascal3431
10 years ago
#

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 ?

GraHal
10 years ago
#

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     

GraHal
10 years ago
#

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 You
GraHal

#

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?

Elsborgtrading
10 years ago
#

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

 

Dymjohn
10 years ago
#

 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]
regards
dymjohn

GraHal
10 years ago
#

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

Cheers
GraHal

 

 

luigiR
10 years ago
#

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

luigiR
10 years ago
#

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

luigiR
10 years ago
#

Hey, someone can help me !

how I must change in the code to enter in real trade but with only one contract?

thanks

mr.brymas
10 years ago
#

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

grizzly
10 years ago
#

 

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
10 years ago
#

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.

grizzly
10 years ago
#

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 

 

mr.brymas
10 years ago
#

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.

luigiR
10 years ago
#

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

fredd81
10 years ago
#

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
10 years ago
#

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

grizzly
10 years ago
#

 

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.

AleX
10 years ago
#

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

 

fredd81
10 years ago
#

grizzly, did you have any improvements to share? 

grizzly
10 years ago
#

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

AleX
10 years ago
#

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?

fredd81
10 years ago
#

 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 = 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
sell 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

//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
10 years ago
#

@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

ProRealCode ProRealCode
Loading...