4 registered members (dBc, clonman, TipmyPip, 1 invisible),
18,936
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Simple 5ema/8ema cross script
#409535
10/18/12 20:31
10/18/12 20:31
|
Joined: Oct 2012
Posts: 75
hughbriss
OP
Junior Member
|
OP
Junior Member
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
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]
#409551
10/19/12 08:16
10/19/12 08:16
|
Joined: Jul 2000
Posts: 28,024 Frankfurt
jcl

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 28,024
Frankfurt
|
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: gfx]
#409592
10/19/12 17:20
10/19/12 17:20
|
Joined: Oct 2012
Posts: 75
hughbriss
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2012
Posts: 75
|
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.
|
|
|
|