EA16-欧元4H策略

extern double lots = 0.01;
extern int ma1_period = 5; // MACD的短期均线
extern int ma2_period = 13; // MACD的长期均线
extern int t_period = 21; // 赢利目标--21均线
// MACD必须大于0.0045
// 风报比必须大于0.9
string trading_system_name = "round_top"; // 本交易系统的名称
int magic_number = 90904; // 用来区分本系统和外系统的订单
datetime last_order_time =0;
//+------------------------------------------------------------------+
//| 初始化代码 |
//+------------------------------------------------------------------+
int init(){
return(0);
}
//+------------------------------------------------------------------+
//| 反初始化代码 |
//+------------------------------------------------------------------+
int deinit(){
return(0);
}
//+------------------------------------------------------------------+
//| 检查系统中是否已经有特定类型的订单。 |
//+------------------------------------------------------------------+
bool check_orders( bool direction){
int i, order_num, order_type;
order_num = OrdersTotal();
for(i=0; i<order_num; i++){
OrderSelect(i, SELECT_BY_POS);
if( OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic_number ) continue; //不是本系统的订单
order_type = OrderType();
if( direction && order_type==OP_BUY ) return(true);
if( !direction && order_type==OP_SELL ) return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| 主程序 |
//+------------------------------------------------------------------+
int start(){
double ma1, ma2, prv_ma1, prv_ma2, pprv_ma1, pprv_ma2;
double macd1, macd2, macd3, target;
double h, l;
if( TimeMinute(TimeCurrent())>5) return(0);
if( TimeCurrent()-last_order_time <14000) return(0);
target = iMA( NULL, PERIOD_H4, t_period, 0, MODE_EMA, PRICE_CLOSE, 0);
ma1 = iMA( NULL, PERIOD_H4, ma1_period, 0, MODE_EMA, PRICE_CLOSE, 1);
ma2 = iMA( NULL, PERIOD_H4, ma2_period, 0, MODE_EMA, PRICE_CLOSE, 1);
prv_ma1 = iMA( NULL, PERIOD_H4, ma1_period, 0, MODE_EMA, PRICE_CLOSE, 2);
prv_ma2 = iMA( NULL, PERIOD_H4, ma2_period, 0, MODE_EMA, PRICE_CLOSE, 2);
pprv_ma1 = iMA( NULL, PERIOD_H4, ma1_period, 0, MODE_EMA, PRICE_CLOSE, 3);
pprv_ma2 = iMA( NULL, PERIOD_H4, ma2_period, 0, MODE_EMA, PRICE_CLOSE, 3);
macd1 = ma1-ma2;
macd2 = prv_ma1-prv_ma2;
macd3 = pprv_ma1-pprv_ma2;
if( macd2>0 && (macd1>=macd2 || macd3>=macd2 || macd2<=0.0045) ) return(0); if( macd2<0 && (macd1<=macd2 || macd3<=macd2 || macd2>=-0.0045) ) return(0);
h = High[ iHighest( NULL, PERIOD_H4, MODE_HIGH, 3, 1) ];
l = Low [ iLowest( NULL, PERIOD_H4, MODE_LOW, 3, 1) ];
if( macd2<0 && target-Close[0] > 0.9*(Close[0]-l) ){
if( check_orders(true)==false){
RefreshRates();
OrderSend( Symbol(), OP_BUY, lots, Ask, 3, l-0.0001,
target, trading_system_name, magic_number, 0, CLR_NONE);
last_order_time = TimeCurrent();
}
}
if( macd2>0 && Close[0]-target > 0.9*(h-Close[0]) ){
if( check_orders(false)==false){
RefreshRates();
OrderSend( Symbol(), OP_SELL, lots, Bid, 3, h+0.0003,
target+0.0002, trading_system_name, magic_number, 0, CLR_NONE);
last_order_time = TimeCurrent();
}
}
return(0);
}
//+------------------------------------------------------------------+