//+------------------------------------------------------------------+
//| 0307.mq4 |
//| cuiyi |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017,CuiYi"
#property link "[email protected]"
#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);
}
//--------------- 开仓条件 ------------------------------
void CheckForOpen()
{
double P1,P2,P3,P4,P5,Lot;
int res;
P1=iOpen(Symbol(),1440,1);
P2=iClose(Symbol(),1440,1);
P3=Ask;
P4=iLow(Symbol(),1440,1);
P5=iHigh(Symbol(),1440,1);
Lot = NormalizeDouble(AccountBalance()/15000.0,2);
if(P3>P4 && P2>P1 && (P2-P1)>(Ask-Bid)*10)
{
res=OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,"",MagicNumber,0,Blue);
return;
}
if(P3<P5 && P2<P1 && (P1-P2)>(Ask-Bid)*10)
{
res=OrderSend(Symbol(),OP_SELL,Lot,Bid,3,0,0,"",MagicNumber,0,Red);
return;
}
}
//------------ 平仓条件 ---------------------------
void CheckForClose()
{
double P1,P2,P4,P3,P5,P6,P7,P8,Lot;
P1=iClose(Symbol(),1440,1);
P2=iLow(Symbol(),1440,1);
P3=iLow(Symbol(),1440,2);
P4=iHigh(Symbol(),1440,2);
P7=iHigh(Symbol(),1440,1);
P8=iClose(Symbol(),1440,2);
P5=Bid;
P6=Ask;
Lot = NormalizeDouble(AccountBalance()/15000.0,2);
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
if(OrderMagicNumber()==MagicNumber || OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(P1<P3 || (P2-P5)>Point*300)
{
if(!OrderClose(OrderTicket(),Lot,Bid,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
if(OrderType()==OP_SELL)
{
if(P1>P4 || (P6-P7)>Point*300)
{
if(OrderClose(OrderTicket(),Lot,Ask,3,White))
Print("OrderClose error ",GetLastError());
}
break;
}
}
}
}
//----------- 控制流 ----------------------
void start()
{
if(Bars<100 || IsTradeAllowed()==false) return;
if(CalculateCurrentOrder(Symbol())==0) CheckForOpen();
else CheckForClose();
}
日图K线交易系统
猜你喜欢
转载自my.oschina.net/u/3093769/blog/1621056
今日推荐
周排行