Posted BabyPips Strategy

Posted By: TankWolf

Posted BabyPips Strategy - 11/01/12 07:37

I found this strategy posted on BabyPips that had pretty simple rules and I thought would be a great practice. Here are the rules:

Quote:

So the rules are simple.
ATR (11) with MA (21)
ADX (14)

Trade rules:

BUY:

Entry:

1. ADX Is Over 25
2. ATR is above MA
3. +DI crosses -DI
4. SL = Last candles low + 2 pips if SL would be below 10 pips use 15 pips as SL

Exit:

1. Close When TP hits 20 pips


SELL:

Entry:

1. ADX Is Over 25
2. ATR is below MA
3. -DI crosses +DI
4. SL = Last candles high - 2 pips if SL would be below 10 pips use 15 pips as SL

Exit:

1. Close When TP hits 20 pips


Work time:

Start at : 8:00 GMT +0 (London opens)
End: 21:00 GMT +0 (NY closes)

I had back tested it by hand , last month on M5 chart was:
30 Trades
12 bad trades
18 good trades
60% wining

Read more: http://forums.babypips.com/free-forex-trading-systems/48196-simple-60-profitable.html#ixzz2AxCW78k3


The author claims on his backtest for last month that 30 trades would of occurred. In my next post is my code to replicate his strategy.
Posted By: TankWolf

Re: Posted BabyPips Strategy - 11/01/12 07:39

Quote:

function run()
{
set(PARAMETERS+FACTORS+TESTNOW);
BarPeriod = 5;
StartDate = 2006;
NumYears = 7;
NumWFOCycles = 6;
LookBack = 100;

var* Close = series(priceClose());
var* High = series(priceHigh());
var* Low = series(priceLow());
var* PLUSDI14 = series(PlusDI(14));
var* MINUSDI14 = series(MinusDI(14));
var* ADX14 = series(ADX(14));
var* ATR11 = series(ATR(11));
var* SMAATR11 = series(SMA(ATR11,21));
plot("ADX14",ADX14[0],NEW,0x0000CC);
plot("ATR11",ATR11[0],NEW,BLUE);
plot("SMAATR11",SMAATR11[0],NEW,BLUE);

if(hour(0) >= lhour(UTC,7) && hour(0) <= lhour(UTC,21))

if(ADX14[0] > 25 && ATR11[0] > SMAATR11[0] && crossOver(PLUSDI14,MINUSDI14) && NumOpenLong == 0) {
enterLong();
if(Low[1] + (2*PIP) < (10*PIP))
Stop = 15*PIP;
else
Stop = Low[1] + (2*PIP);
}
else if(ADX14[0] > 25 && ATR11[0] < SMAATR11[0] && crossOver(MINUSDI14,PLUSDI14) && NumOpenShort == 0) {
enterShort();
if(High[1] - (2*PIP) < (10*PIP))
Stop = 15*PIP;
else
Stop = Low[1] - (2*PIP);
}
}


This is my attempt at coding the strategy as per the rules, I think Ive got the logic all right but any assistance/advice would be great.
Posted By: TankWolf

Re: Posted BabyPips Strategy - 11/01/12 07:40

The results:
Quote:

Walk-Forward Test Vulture EUR/USD - performance report

Simulation period 03.01.2006-03.10.2012
Test period 10.08.2009-03.10.2012
WFO test cycles 5 x 46905 bars (33 weeks)
Training cycles 6 x 265795 bars (191 weeks)
Lookback time 100 bars (8 hours)
Assumed spread 2.6 PIP (roll -0.06/0.03)
Assumed slippage 10.0 sec
Contracts per lot 800

Gross win/loss 331$ / -107$ (+2797p)
Average profit 71$/year, 6$/month, 0$/day
Max drawdown -48$ (MAE -69$)
Max down time 77 weeks from Apr 2011
Largest margin 5$
Trade volume 72639$ (23070$/year)
Transaction costs -14$ spr, -1$ slp, -2$ rol
Capital required $100

Number of trades 67 (21/year)
Percent winning 39%
Max win/loss 105$ / -21$
Avg trade profit 3$ 41.7p (+13$ / -3$)
Avg trade bars 1135 (+2399 / -333)
Max trade bars 21147 (15 weeks)
Time in market 32%
Max open trades 1
Max win/loss streak 3 / 11 (71.76% / 9.05% per year)

Annual return 71%
Profit factor 3.09 (PRR 2.15)
Sharpe ratio 1.14
Kelly criterion 1.81
OptimalF .557
Ulcer index 12%
Prediction error 60%

Trade details OptF ProF Win/Loss Cycles

EUR/USD:L .096 2.87 20/34 ///\/
EUR/USD:S .999 13.75 6/7 /\\//
Posted By: TankWolf

Re: Posted BabyPips Strategy - 11/01/12 07:43

Notice how in my results over the test period of nearly 3 years it only took 67 trades (21 per year). That doesnt look right to me, and according to the strategy creator he had 30 trades alone last month. Perhaps its something to do with the PlusDI & MinusDI functions or the moving average of the ATR. If you check the babypips thread the creator of the strategy combines the two indicators together so I figured that I had to make a moving average of the ATR to replicate that. Also the only difference I forgot to mention in my attempted code for this strategy is I took out the TakeProfit target because it seemed to make the results worse.

As I said above if anyone wants to play around, use this strategy or better it any way please feel free to contribute.
Posted By: jcl

Re: Posted BabyPips Strategy - 11/01/12 10:07

As far as I see, your script matches your description with following exceptions -

- TP is missing and the description says nothing about a limitation to only one open position.

- Stop is set after the trade was already entered - must be set before.

- the hour calculation looks wrong. Correct: if(lhour(UTC) >= 7 and lhour(UTC) <= 21) { ... put the rest here ... }

Posted By: stevegee58

Re: Posted BabyPips Strategy - 11/01/12 10:28

Originally Posted By: jcl

- Stop is set after the trade was already entered - must be set before.


That's an interesting point. With American ECN rules you're required to enter the SL and TP after the trade is entered. They're not allowed to be attached to a pending order.

ZT doesn't seem to handle this distinction natively.
Posted By: jcl

Re: Posted BabyPips Strategy - 11/01/12 10:30

Syntax rules in a programming language and the American ECN rules have not much in common. laugh
Posted By: stevegee58

Re: Posted BabyPips Strategy - 11/01/12 11:15

I have an include file of functions I used in MT4 that act as an extension to the platform and automatically handle the ECN nonsense. It was a pain to implement but now it's transparent.

I could see someone doing something similar in ZT.
Posted By: jcl

Re: Posted BabyPips Strategy - 11/01/12 11:24

No, this is not necessary. The current version is not NFA compliant anyway. NFA compliance will be implemented in one of the next updates. In fact it's already programmed and we're just testing it for release with version 1.04. This has no effect on your script and you won't need to include a file of extension functions.
Posted By: Squalou

Re: Posted BabyPips Strategy - 11/01/12 11:50

Hi,

i'm currently practicing ZT , so i thought i would try this strategy example posted here.
However, the script as posted by TankWolf won't compile with the (supposedly most recent ?) ZT version i downloaded a few days ago, which is 1.01.

It complains about "NumOpenShort" and "NumOpenLong" that do not exist.
Indeed, i cannot find them in the header files (trading structures and macros).
The editor's Command Help does not show them either.
However, the Online User Manual does list them in the "Trade statistics parameters " section.

I replaced them with "NumLongTotal" and "NumShortTotal" respectively to make it work.

Am i missing something ?

Sq
Posted By: hughbriss

Re: Posted BabyPips Strategy - 11/01/12 12:00

I always use numLong(0) and numShort(0) to count the number of open trades if this helps?
Posted By: TankWolf

Re: Posted BabyPips Strategy - 11/01/12 12:08

Im using the beta 1.02 version which now uses those variables. Hughs code should also work.
Posted By: dusktrader

Re: Posted BabyPips Strategy - 07/19/13 10:51

Hello, I'm working my way through all these examples, try to learn how to program with Zorro. On this script, I keep running into an error (with Zorro 1.12.1) that I'm stuck on.

The error is:
(EURUSD::S) Error 010: Invalid stop limit 1.2823
(EURUSD::L) Error 010: Invalid stop limit 1.3034
(EURUSD::S) Error 010: Invalid stop limit 1.3059
(...etc)

What would cause a stop to be invalid? I thought maybe it was too tight in the spread, but that doesn't seem to fix the issue.

Here is the code I am working with so far:
Code:
function run()
{
	set(PARAMETERS+FACTORS+TESTNOW+NFA);
	BarPeriod = 5;
	StartDate = 2006;
	NumYears = 7;
	NumWFOCycles = 6;
	LookBack = 100;

	var* Close = series(priceClose());
	var* High = series(priceHigh());
	var* Low = series(priceLow());
	var* PLUSDI14 = series(PlusDI(14));
	var* MINUSDI14 = series(MinusDI(14));
	var* ADX14 = series(ADX(14));
	var* ATR11 = series(ATR(11));
	var* SMAATR11 = series(SMA(ATR11,21));
	plot("ADX14",ADX14[0],NEW,0x0000CC);
	plot("ATR11",ATR11[0],NEW,BLUE);
	plot("SMAATR11",SMAATR11[0],NEW,BLUE);

	if(lhour(UTC) >= 7 and lhour(UTC) <= 21)

	if(ADX14[0] > 25 && ATR11[0] > SMAATR11[0] && crossOver(PLUSDI14,MINUSDI14) && NumOpenLong == 0)
	{
		if(Low[1] + (2*PIP) < (10*PIP))
			Stop = 15*PIP;
		else
			Stop = Low[1] + (2*PIP);

		enterLong();
	}
	else if(ADX14[0] > 25 && ATR11[0] < SMAATR11[0] && crossOver(MINUSDI14,PLUSDI14) && NumOpenShort == 0)
	{
		if(High[1] - (2*PIP) < (10*PIP))
			Stop = 15*PIP;
		else
			Stop = Low[1] - (2*PIP);

		enterShort();
	}
}


Thanks if you can offer any tips on this error I'm getting.
Posted By: jcl

Re: Posted BabyPips Strategy - 07/19/13 10:59

A stop is invalid when it's at the wrong side of the price. I think this can happen in your script due to the "Stop = Low[1] - (2*PIP)".
Posted By: dusktrader

Re: Posted BabyPips Strategy - 07/19/13 14:40

I have a stupid question here (sorry, I'm a n00b programmer)... in this script, what is the purpose of:

var* High = series(priceHigh());
var* Low = series(priceLow());

Are not priceHigh() and priceLow() already built-in series that I can pull from? For example, why not just use priceClose() and priceHigh(2) for the current and last bar?

Thanks
Posted By: jcl

Re: Posted BabyPips Strategy - 07/19/13 14:49

priceHigh()/Low() are functions, not series, but there is indeed no reason in the script for the High and Low series. I guess the author just liked series, or he experimented with other indicators where he needed the series.

The script has other bugs, for instance some of the comparisons can never return true. For learning scripting, better start with your own script from scratch.
Posted By: dusktrader

Re: Posted BabyPips Strategy - 07/19/13 15:04

Thanks. At the moment I'm studying these other scripts, which I don't yet fully understand, and gathering tidbits from them. This is how I usually learn...

Yes I will write my own scripts soon, but I learn a lot from studying other ones that are already working.
Posted By: swingtraderkk

Re: Posted BabyPips Strategy - 07/19/13 17:06

Hi all,

Had a go at fixing this according to the rules published.

Not profitable as far as I can see since fixed, was more profitable in its broken state?????

BTW I can see no logic for the ATR rule, except perhaps an indication of momentum in favour of the trade, but if so why does the rule state that the atr should be under its 21d ma for shorts? surely it should be > 21d ma of atr for shorts also?

Haven't time to back test variants, but would appreciate if anyone can spot my errors as I'm a noob too.

Code:
function run()
{
set(PARAMETERS+FACTORS+TESTNOW);
BarPeriod = 5;
StartDate = 2002;
//NumYears = 7;
//NumWFOCycles = 10;
LookBack = 100;

vars Close = series(priceClose());
vars High = series(priceHigh());
vars Low = series(priceLow());
vars PLUSDI14 = series(PlusDI(14));
vars MINUSDI14 = series(MinusDI(14));
vars ADX14 = series(ADX(14));
vars ATR11 = series(ATR(11));
vars SMAATR11 = series(SMA(ATR11,21));

int profit = optimize(20,5,200,5);

if(lhour(UTC) >= 7 and lhour(UTC) <= 21)
	{
	if((ADX14[0] > 25) and (ATR11[0] > SMAATR11[0]) and crossOver(PLUSDI14,MINUSDI14))
		{
			Stop = (max(2+((Close[0]-Low[0])/PIP),15))*PIP;
			TakeProfit = profit*PIP;
			enterLong();			
		}
	else
		{
			if((ADX14[0] > 25) and (ATR11[0] > SMAATR11[0]) and (crossOver(MINUSDI14,PLUSDI14)))
			{
			Stop = (max(2+((High[0]-Close[0])/PIP),15))*PIP;
			TakeProfit = profit*PIP;
			enterShort();
			}
		}
	}
plot("ADX14",ADX14[0],NEW,0x0000CC);
plot("ADX25",25,0,SILVER);
plot("ATR11",ATR11[0],NEW,BLUE);
plot("SMAATR11",SMAATR11[0],0,SILVER);

}

© 2024 lite-C Forums