Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Add Close previous order when open new position

  1. #1

    Default Add Close previous order when open new position

    Hi, i would like to make request for code for when the new position is open,automatically the previous order will close.Mean i dont want to use take profit or trailling.

    Example:
    When order buy is open,previous order sell will close
    When order sell is open,previous order buy will close

    i found the code is OrderCloseBy() but i dont know exactly where to put this code

    thanks

  2. #2

    Default

    Problem solve

    put after OrderSend BUY
    {
    OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position

    }

    put after OrderSend SELL
    {
    OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet) ; // close position

    }

    Other code i get from ForexFactory thanks to(Fulltime247,magnumfreak)

    extern int MAGICTerminal=101;
    extern double LOTSize=0.10;
    extern string ORDERComment="Order Comment Text";

    //TOTAL Count..
    int btotal=0; int stotal=0; int ticket=0; double closelots=0; bool xbool;
    for( int cnt=OrdersTotal()-1;cnt>=0;cnt--)
    {
    xbool=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
    if(OrderType()==OP_BUY && OrderMagicNumber()==MAGICTerminal && OrderSymbol()==Symbol()){btotal++; ticket=OrderTicket(); closelots=OrderLots();}
    if(OrderType()==OP_SELL && OrderMagicNumber()==MAGICTerminal && OrderSymbol()==Symbol()){stotal++; ticket=OrderTicket(); closelots=OrderLots();}

    }// END TOTAL count..


    if(WHATEVER YOUR CONDITION FOR A BUY)
    {

    if(btotal>0){OrderClose(ticket,closelots,Bid,3,CLR _NONE);}
    ticket=OrderSend(Symbol(),OP_BUY,LOTSize,Ask,3,0,0 ,ORDERComment,MAGICTerminal,0,Magenta);
    }

    if(WHATEVER YOUR CONDITION FOR A SELL)
    {
    if(stotal>0){OrderClose(ticket,closelots,Ask,3,CLR _NONE);}

    ticket=OrderSend(Symbol(),OP_SELL,LOTSize,Bid,3,0, 0,ORDERComment,MAGICTerminal,0,Lime);
    }

Similar Threads

  1. Open oppsite order if order don't take profit
    By luisneves in forum MQL programming
    Replies: 0
    Last Post: 12-06-2012, 17:09
  2. How program EA for to open order when candle open?
    By Fonscky in forum MQL programming
    Replies: 0
    Last Post: 08-19-2010, 22:56
  3. Open Reverse Position after SL
    By jidonk in forum MQL programming
    Replies: 4
    Last Post: 08-07-2010, 10:11
  4. Open Position at Close Candle
    By Xandra in forum Ideas for expert advisors
    Replies: 1
    Last Post: 12-30-2009, 06:50
  5. Replies: 1
    Last Post: 12-27-2009, 17:48

Tags for this Thread

add, magic, profit, request

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •