首页 MT4EA正文

关闭运行中的订单同时开新的反向订单

大侠 EA 2019-10-02 11:47:26 20519 0 mt4ex4ea开仓工具反向

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);

  }

//+------------------------------------------------------------------+




已售:0
付费内容,免注册,扫一扫即可查看或下载,感谢打赏! 支付2元查看


相关文章

发表评论

评论列表(0人评论 , 20519人围观)
☹还没有评论,来说两句吧...