Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, degenerate_762, ozgur), 1,311 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Simple 5ema/8ema cross script #409535
10/18/12 20:31
10/18/12 20:31
Joined: Oct 2012
Posts: 75
H
hughbriss Offline OP
Junior Member
hughbriss  Offline OP
Junior Member
H

Joined: Oct 2012
Posts: 75
Hello, this is my first script and is a very basic 5/8 ema cross. It checks the 5/8 ema's of the candle before last and compares them to the latest closed candles 5/8 ema situation.

When there is a fresh crossover (ie it just happened) it enters in the direction of the cross and closes all open orders in the other direction. If there is no cross it just adds on in the direction of the trend.

It makes 6% on eurusd daily charts and 69% on audusd. I'm sure this could be optimised and made better but at the end of the day it is not the best system idea to start with, I just wanted to code something simple as a start.

I'd be grateful if anyone could take a look at the code for me and tell me if it does indeed do what I intended it to do and whether I have coded it elegantly or if I could have done it more simply.

Thanks

Code:
function run()
 
{
     var* ClosePrice = series(priceClose());
     var* PrevClosePrice = series(priceClose(1));
     
     var* prev5ema = series(EMA(PrevClosePrice,5));
     var* curr5ema = series(EMA(ClosePrice,5));
     var* prev8ema = series(EMA(PrevClosePrice,8));
     var* curr8ema = series(EMA(ClosePrice,8));
     
     if (*prev5ema > *prev8ema && *curr5ema < *curr8ema)
          enterShort();
     if (*prev5ema < *prev8ema && *curr5ema > *curr8ema) 
          enterLong();
     if (*prev5ema > *prev8ema && *curr5ema > *curr8ema)
          enterLong();
     if (*prev5ema < *prev8ema && *curr5ema < *curr8ema) 
          enterShort();
          
}


Last edited by hughbriss; 10/18/12 20:32.
Re: Simple 5ema/8ema cross script [Re: hughbriss] #409549
10/19/12 07:33
10/19/12 07:33
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
As far as I see, the script should work as intended, but you can make it simpler. You don't need the 3 extra series from the previous prices. A series already contains all previous prices, as this is the very purpose of a series. Otherwise you could just use normal variables.

Re: Simple 5ema/8ema cross script [Re: jcl] #409550
10/19/12 08:10
10/19/12 08:10
Joined: Oct 2012
Posts: 75
H
hughbriss Offline OP
Junior Member
hughbriss  Offline OP
Junior Member
H

Joined: Oct 2012
Posts: 75
I tried to use just the series but couldn't make it work. When I try to use something like...

PrevClosePrice = ClosePrice(1)

it always gives me errors.

Could you show me how I should have done it? Thanks.

Re: Simple 5ema/8ema cross script [Re: hughbriss] #409551
10/19/12 08:16
10/19/12 08:16
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Code:
function run() 
{
	var *ClosePrice = series(priceClose());
	var *EMA5 = series(EMA(ClosePrice,5));
	var *EMA8 = series(EMA(ClosePrice,8));
	
	if(crossUnder(EMA5,EMA8))
	    enterShort();
	if(crossOver(EMA5,EMA8)) 
	    enterLong();
	if(EMA5[1] > EMA8[1] && EMA5[0] > EMA8[0])
	    enterLong();
	if(EMA5[1] < EMA8[1] && EMA5[0] < EMA8[0]) 
	    enterShort();
}


Re: Simple 5ema/8ema cross script [Re: jcl] #409552
10/19/12 08:36
10/19/12 08:36
Joined: Oct 2012
Posts: 75
H
hughbriss Offline OP
Junior Member
hughbriss  Offline OP
Junior Member
H

Joined: Oct 2012
Posts: 75
Excellent, got it, thanks for your help.

Re: Simple 5ema/8ema cross script [Re: hughbriss] #409588
10/19/12 15:33
10/19/12 15:33
Joined: Oct 2012
Posts: 13
CO
G
gfx Offline
Newbie
gfx  Offline
Newbie
G

Joined: Oct 2012
Posts: 13
CO
hugh, the crossUnder/crossOver enters when the EMAs cross. Why do you also have the 3rd & 4th conditions? Those say "if EMA5 is above/below EMA8 in this bar & previous bar, go long/short." One or the other of those tests will be true on almost every bar -- basically every bar where the crossOver/crossUnder test isn't true! So unless I'm misunderstanding something, that code will trigger an entry on every single bar!?

Re: Simple 5ema/8ema cross script [Re: gfx] #409592
10/19/12 17:20
10/19/12 17:20
Joined: Oct 2012
Posts: 75
H
hughbriss Offline OP
Junior Member
hughbriss  Offline OP
Junior Member
H

Joined: Oct 2012
Posts: 75
Originally Posted By: gfx
hugh, the crossUnder/crossOver enters when the EMAs cross. Why do you also have the 3rd & 4th conditions? Those say "if EMA5 is above/below EMA8 in this bar & previous bar, go long/short." One or the other of those tests will be true on almost every bar -- basically every bar where the crossOver/crossUnder test isn't true! So unless I'm misunderstanding something, that code will trigger an entry on every single bar!?


Hi, yes, that is correct. The idea is that on long trends you will make significant money and on the whipsaws you will lose small. As I said this isn't intended to be a system that I would trade myself but more a way to develop my coding skills.

Re: Simple 5ema/8ema cross script [Re: hughbriss] #410436
11/03/12 06:27
11/03/12 06:27
Joined: Nov 2012
Posts: 209
S
SFF Offline
Member
SFF  Offline
Member
S

Joined: Nov 2012
Posts: 209
Hi,

When I assume that a lot of pips makes a lot pf money(%),
Why is this code only showing small profit of %?

+3% 17009 pip/yr

I did test it with 9 for the shorter and 36 for the longer MA on EUR/USD.

and I am not able to change the slider value by entering the value from the key board directly.

Re: Simple 5ema/8ema cross script [Re: SFF] #410443
11/03/12 08:07
11/03/12 08:07
Joined: Oct 2012
Posts: 75
H
hughbriss Offline OP
Junior Member
hughbriss  Offline OP
Junior Member
H

Joined: Oct 2012
Posts: 75
The low % return is probably due to the large drawdown incurred. Even though it shows a healthy profit in pips per year the capital required to trade the system means that you are only returning a % of your investment.

This is a bit of a quirk of zorro. You start at 0 and then add profits and losses to achieve a final figure. As primarily a trader and not a mathemetician or programmer it makes more sense to me to start with a balance and use % money management to give an end figure that you can relate to the starting balance but I think I'm yet to convince JCL of this.

Re: Simple 5ema/8ema cross script [Re: hughbriss] #410461
11/03/12 11:45
11/03/12 11:45
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The %return is the profit in relation to the start capital. The minimum capital that you need for this strategy is calculated by Zorro and displayed under "Capital" in the message window. You can start with more capital - this will not have an effect on the strategy performance of course - but not with less, as this bears the risk of a margin call.

Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1