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

¥1,686.00

  • Brand: LANCOME
  • Product Code:
  • Availability: In Stock

- +
Main Image

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

      {

         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

      {

         

         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

      {

          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

Write a review

Note: HTML is not translated!
Bad Good