求大师修改,现在的订单盈利等于或大于刚才止损的定单就平仓
盈利大于5美元就平仓,现在的订单盈利等于或大于刚才止损的定单就平仓
void OnTick()
// {
// for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES)==true)//选中定订 因为只开一个定单
{
if(OrderProfit()<5) //如果价格是盈利大于5美元
double h=OrderProfit() //获取定单的盈亏价格
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL) //不管是多单还空单
{
OrderClose(OrderTicket(),0.01,Bid,300);//就执行平仓
OrderClose(OrderTicket(),0.01,Ask,300);//就执行平仓
}
}
}
}
// }
{
if(OrderSelect(0, SELECT_BY_POS, MODE_HISTORY)==true)//选中刚才止损的订单
{
double t=OrderProfit()//获取定单的止损价格
if h+t<0 //现在的订单盈利等于或大于刚才止损的定单就平仓
{
if(OrderSelect(0, SELECT_BY_POS, MODE_TRADES)==true)//选中持仓的定单
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL) //不管是多单还空单
{
OrderClose(OrderTicket(),OrderLots,300);//就执行平仓
OrderClose(OrderTicket(),0.01,Ask,300);//就执行平仓
}
}
}
}
}
// }
//+------------------------------------------------------------------+ |
|
|
|
|