1、交易策略ui
2、系統源碼code
//+------------------------------------------------------------------+ //| 20180107.mq4 | //| Copyright 2017,CuiYi | //| 1010333562@qq.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017,CuiYi" #property link "1010333562@qq.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ //----------- 外部變量 -------------- extern int MagicNumber = 123; //----------- 計算現時倉位大小 ---------------------------- 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()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) buys++; if(OrderType()==OP_SELL) sells++; } } if(buys>0) return(buys); else return(-sells); } //------------- 計算交易手數 ---------------------------- double lot=NormalizeDouble(AccountBalance()/5000.0,2); //--------------- 開倉條件 ------------------------------ void CheckForOpen() { double P1,P2,P3,P4; int res; P1=iOpen("EURUSD",5,0); P2=iClose("EURUSD",5,0); P3=iOpen("EURUSD",5,1); P4=iClose("EURUSD",5,1); if(P2>P1 && P4>P3 && P2>P4) { res=OrderSend("EURUSD",OP_BUY,lot,Ask,3,0,0,"",MagicNumber,0,Blue); return; } if(P2<P1 && P4<P3 && P2<P4) { res=OrderSend("EURUSD",OP_SELL,lot,Bid,3,0,0,"",MagicNumber,0,Red); return; } } //------------ 平倉條件 --------------------------- void CheckForClose() { double P1,P2,P3,P4; P1=iOpen("EURUSD",5,0); P2=iClose("EURUSD",5,0); P3=iOpen("EURUSD",5,1); P4=iClose("EURUSD",5,1); for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!="EURUSD") continue; if(OrderType()==OP_BUY) { if(P2<P4 || P2<P1) OrderClose(OrderTicket(),lot,Bid,3,White); break; } if(OrderType()==OP_SELL) { if(P2>P4 || P2>P1) OrderClose(OrderTicket(),lot,Bid,3,White); break; } } } //----------- 控制流 ---------------------- void start() { if(Bars<100 || IsTradeAllowed()==false) return; if(CalculateCurrentOrder(Symbol())==0) CheckForOpen(); else CheckForClose(); }