//先查询第一单和最后一单的时间
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY)
{
if(OrderOpenTime()>lastBuyTime)
lastBuyTime=OrderOpenTime();//最后一单时间
if(oneBuyTime>0)
{
if(OrderOpenTime()<oneBuyTime)
oneBuyTime=OrderOpenTime();
}
else
{
oneBuyTime=OrderOpenTime();
}
}
if(OrderType()==OP_SELL)
{
if(OrderOpenTime()>lastSellTime)
lastSellTime=OrderOpenTime();//最后一单时间
if(oneSellTime>0)
{
if(OrderOpenTime()<oneSellTime)
oneSellTime=OrderOpenTime();
}
else
{
oneSellTime=OrderOpenTime();
}
}
}
}
//再查询两单的盈利金额
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(oneBuyTime==OrderOpenTime())
{
oneBuyPrice=OrderOpenPrice();//第一单
oneBuyProfit=OrderProfit() + OrderCommission() + OrderSwap();
}
if(oneSellTime==OrderOpenTime())
{
oneSellPrice=OrderOpenPrice();//第一单
oneSellProfit=OrderProfit() + OrderCommission() + OrderSwap();
}
if(lastBuyTime==OrderOpenTime())
{
lastBuyPrice=OrderOpenPrice();//最后一单
lastBuyProfit=OrderProfit() + OrderCommission() + OrderSwap();
}
if(lastSellTime==OrderOpenTime())
{
lastSellPrice=OrderOpenPrice();//最后一单
lastSellProfit=OrderProfit() + OrderCommission() + OrderSwap();
}
}
}
//盈利金额>50
if(oneBuyProfit<0 &&lastBuyProfit-oneBuyProfit>50)
{
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
break;
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(oneSellTime==OrderOpenTime())
{
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),30);
}
if(lastSellTime==OrderOpenTime())
{
OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),30);
}
}
}
} |