Hi, I’m trying to code my first EA, and it turns out I have no idea what I’m doing.
I’m just wondering if anyone would be kind enough to have a look at what I’ve done so far and then either let me know if I’m on the right track, or if I should throw in the towel. Thanks heaps!
Basically I figured a moving average crossover system would be nice and easy to start with. In plain english what I want is:
“When two MA’s cross each other, put a pending order at the cross”
Whenever I see an EA code, it’s always hundreds of lines of code, and mine has like 30, which is why I’m thinking I have no idea what I’m doing. I’m not sure on the etiquette here, so I’m just going to copy paste the text here, if that’s wrong, please let me know so I can delete it.
Anyway, here it is. Am I way off or am I almost there?
Thanks again.
// Variables
extern double Lots = 0.1;
extern double Maximum risk = 0.01;
extern double Stoploss = 10
extern double Takeprofit = 15
extern double MA1 = 12;
extern double MA2 = 25;
extern bool EnterOpenBar = true;
extern int FastMATime = 0;
extern int FastMAPeriod = 12;
extern int FastMAType = 1; //0:SMA 1:EMA 2:SMMA 3:LWMA
extern int FastMAPrice = close;
extern int SlowMATime = 0;
extern int SlowMAPeriod = 24;
extern int SlowMAType = 0; //0:SMA 1:EMA 2:SMMA 3:LWMA
extern int SlowMAPrice = close;
//Initialization
//Start Function
int start()
FastMACurrent = iMA(NULL, FastMATime, FastMAPeriod, FastMAType, FastMAPrice, Current + 0);
FastMAPrevious = iMA(NULL, FastMATime, FastMAPeriod, FastMAType, FastMAPrice, Current + 1);
SlowMACurrent = iMA(NULL, SlowMATime, SlowMAPeriod, SlowMAType, SlowMAPrice, Current + 0);
SlowMAPrevious = iMA(NULL, SlowMATime, SlowMAPeriod, SlowMAType, SlowMAPrice, Current + 1);
//Order Logic
if (FastMACurrent > SlowMACurrent&& FastMAPrevious < SlowMAPrevious
&& OpenBar){
OpenBuylimit=true;
}
if (FastMACurrent < SlowMACurrent&& FastMAPrevious > SlowMAPrevious
&& OpenBar){
Openselllimit=true;
}