2019独角兽企业重金招聘Python工程师标准>>>
//+------------------------------------------------------------------+
//| myEA20180115.mq4 |
//| Copyright 2017,CuiYi |
//| 1010333562@qq.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,CuiYi"
#property link "1010333562@qq.com"
#property version "1.00"
#property strict
#define MAGICMA 19880305extern double Lots=0.02;int CalculateCurrentOrder(string symbol){int buys=0,sells=0;for(int i=0;i<OrdersTotal();i=i+1){if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;if(OrderSymbol()=="EURUSD" && OrderMagicNumber()==MAGICMA){if(OrderType()==OP_BUY) buys++;if(OrderType()==OP_SELL) sells++;}}if(buys>0) return(buys);else return(-sells);}void CheckForOpen(){double ma1,ma2,ma3,ma4;int res;ma1=iMA(NULL,5,6,0,MODE_EMA,PRICE_CLOSE,1);ma2=iMA(NULL,5,18,0,MODE_EMA,PRICE_CLOSE,1);ma3=iMA(NULL,5,6,0,MODE_EMA,PRICE_CLOSE,2);ma4=iMA(NULL,5,180,0,MODE_EMA,PRICE_CLOSE,2);if(ma1>ma2 && ma3<ma4){res=OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,0,"",MAGICMA,0,Blue);return;}if(ma1<ma2 && ma3>ma4){res=OrderSend("EURUSD",OP_SELL,Lots,Bid,3,0,0,"",MAGICMA,0,Red);return;}}void CheckForClose(){double ma1,ma2,ma3,ma4;ma1=iMA(NULL,5,6,0,MODE_EMA,PRICE_CLOSE,1);ma2=iMA(NULL,5,18,0,MODE_EMA,PRICE_CLOSE,1);ma3=iMA(NULL,5,6,0,MODE_EMA,PRICE_CLOSE,2);ma4=iMA(NULL,5,18,0,MODE_EMA,PRICE_CLOSE,2);for(int i=0;i<OrdersTotal();i++){if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;if(OrderMagicNumber()==MAGICMA || OrderSymbol()=="EURUSD"){if(OrderType()==OP_BUY){if(ma1<ma2 && ma3>ma4) {if(!OrderClose(OrderTicket(),Lots,Bid,3,White))Print("OrderClose error ",GetLastError());}break;}if(OrderType()==OP_SELL){if(ma1>ma2 && ma3<ma4){if(OrderClose(OrderTicket(),Lots,Ask,3,White))Print("OrderClose error ",GetLastError());}break;}}}}void start(){if(Bars<100 || IsTradeAllowed()==false) return;if(CalculateCurrentOrder(Symbol())==0) CheckForOpen();else CheckForClose();}