//--------------------------
static int 开启=0;
if(保护开关==true)
{
if(AllProfit_1>保护启动金额 )
{
开启=1;
}
if(开启==1 && AllProfit_1<=保护金额 )
{
平仓();
}
if( BuyVol_1+SelVol_1==0)
{
开启=0;
}
}
//--------------------------
void 平仓()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true&&OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic_1)
{
if(OrderType()==0)
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),500,0))
{
Print("订单号为",OrderTicket(),"平仓失败",GetLastError());
}
}
if(OrderType()==1)
{
if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),500,0))
{
Print("订单号为",OrderTicket(),"平仓失败",GetLastError());
}
}
if(OrderType()>1)
{
if(!OrderDelete(OrderTicket(),0))
{
Print("订单号为",OrderTicket(),"平仓失败",GetLastError());
}
}
}
}
} |