平盈利单代码
void 平盈()
{
int slippage=3;
int ask, bid, open;
double point;
bool res = false;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
break;
if(OrderType()==OP_BUY && OrderMagicNumber()==Magic3)
{
point=MarketInfo(OrderSymbol(),MODE_POINT);
if(point==0)
break;
bid=MathRound(MarketInfo(OrderSymbol(),MODE_BID)/point);
open=MathRound(OrderOpenPrice()/point);
if(bid-open<10)
continue;
res=OrderClose(OrderTicket(),OrderLots(),bid*point,slippage);
if(res)
Print("单号:"+OrderTicket()+" 盈利平仓成功");
}
if(OrderType()==OP_SELL && OrderMagicNumber()==Magic3)
{
point=MarketInfo(OrderSymbol(),MODE_POINT);
if(point==0)
break;
ask=MathRound(MarketInfo(OrderSymbol(),MODE_ASK)/point);
open=MathRound(OrderOpenPrice()/point);
if(open-ask<10)
continue;
res=OrderClose(OrderTicket(),OrderLots(),ask*point,slippage);
if(res)
Print("单号:"+OrderTicket()+" 盈利平仓成功");
}
}
}
页:
[1]