//+------------------------------------------------------------------+ //| 均线穿越EA.mq4 | //| dazzle | //| 1668930294@qq.com | //+------------------------------------------------------------------+ //简单的外汇自动化交易, //当5日均线上穿20日均线买入, //当5日均线下穿20日均线卖出, //止盈50点,止损20点,每手交易0.1手 #property copyright "dazzle" #property link "1668930294@qq.com" #property version "1.00" #property strict extern double TakeProfit=50; //止盈点数 extern double StopLoss=20; //止损点数 extern double Lots=0.1; //交易手数 extern double Poin; //平台最小报价单位 extern int MAPeriodSlow=20; //20日移动平均 extern int MAPeriodFast=5; //5日移动平均 //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- if (Point==0.00001) Poin=0.0001; //5位报价货币对,改变Point值为4位报价 else if (Point==0.001) Poin=0.01;//3位报价货币对,改变Point值为2位报价 else Poin = Point; // //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double myMAslow,myMAfast,myMAslow1,myMAfast1; int i=0; myMAslow=iMA(Symbol(),0,MAPeriodSlow,0,MODE_SMA,PRICE_CLOSE,0); myMAfast=iMA(Symbol(),0,MAPeriodFast,0,MODE_SMA,PRICE_CLOSE,0); myMAslow1=iMA(Symbol(),0,MAPeriodSlow,0,MODE_SMA,PRICE_CLOSE,1); myMAfast1=iMA(Symbol(),0,MAPeriodFast,0,MODE_SMA,PRICE_CLOSE,1); //上穿买入 平掉卖单 if(myMAfast>myMAslow && myMAfast1myMAslow1) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3,clrNONE); if(OrdersTotal()==0) OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Poin,Bid-TakeProfit*Poin,"TF0_1",0,clrRed); } } //+------------------------------------------------------------------+