本ea没有参数。直接根据持仓来下反向订单。
比如持仓有1手欧美多单,那么运行这个ea就平掉欧美多单,同时下欧美空单。
//+------------------------------------------------------------------+
//| Close and Reverse.mq4 |
//| Copyright ?2006, Eli Hayun |
//| http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, Eli Hayun"
#property link "http://www.elihayun.com"
//+------------------------------------------------------------------+
//| Close the running orders and open to an opposite direction |
//+------------------------------------------------------------------+
int start()
{
//----
string curr = Symbol();
int ot = OrdersTotal();
int ords[200], ordType[200], ordTicket[200]; double ordLots[200];
string ordComments[200];
int ix=0;
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == Symbol())
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
ords[ix] = o; ordType[ix] = OrderType();
ordLots[ix] = OrderLots(); ordTicket[ix] = OrderTicket();
ordComments[ix] = OrderComment();
ix++;
}
}
for (i=0; i<ix; i++)
{
double ask = MarketInfo(Symbol(), MODE_ASK);
double bid = MarketInfo(Symbol(), MODE_BID);
double prc = 0;
if (ordType[i] == OP_BUY) prc = bid; else prc=ask;
OrderSelect(ords[i], SELECT_BY_POS);
Print("Closing Order # ",ords[i]);
OrderClose(ordTicket[i], ordLots[i],prc,5);
Print("Error ",GetLastError());
}
for (i=0; i<ix; i++)
{
ask = MarketInfo(Symbol(), MODE_ASK);
bid = MarketInfo(Symbol(), MODE_BID);
prc = 0;
int op = ordType[i]; if (op == OP_BUY) { op = OP_SELL; prc = bid;} else { op = OP_BUY; prc=ask;}
OrderSend(Symbol(), op, ordLots[i], prc,5,0,0,ordComments[i]+"[Rev]");
}
//----
return(0);
}
//+------------------------------------------------------------------+
- 上一篇: 第4节 了解白银市场个性
- 下一篇: 新手炒外汇如何才能少走弯路?
最新留言
评:试试
2024-06-25 23:22:21评:方便
2024-05-20 06:36:39评:这个有用,
2024-05-20 06:35:42评:谁有单数为0,禁止此mt4 禁止开单(此mt4 其它图表的ea 或者跟单软件不准开单)的ea 。
2024-05-09 22:42:32评:破解ea 时间限制一般多少钱
2024-05-09 13:34:50评:很牛逼的感觉
2024-05-04 22:37:19评:这个策略还有效吗
2024-05-04 20:34:08评:要个止损用的,谢谢
2024-05-04 19:07:41