+ Reply to Thread
Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Add Close previous order when open new position

  1. #1
    Member
    Join Date
    Jan 2009
    Posts
    37

    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
    Member
    Join Date
    Jan 2009
    Posts
    37

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

+ Reply to Thread

Similar Threads

  1. Close all buy and close all sell orders
    By q8m2002 in forum Scripts and other tools
    Replies: 8
    Last Post: 12-17-2010, 05:33
  2. Close all open trades after every x profit
    By begu in forum MQL programming
    Replies: 1
    Last Post: 04-09-2009, 18:03
  3. How to close open orders?
    By juhanimi in forum MQL programming
    Replies: 0
    Last Post: 03-05-2009, 07:49
  4. Friday close price-monday open
    By przem81621 in forum Ideas for expert advisors
    Replies: 4
    Last Post: 02-22-2009, 11:08
  5. Min and max oscillation in pips of a closed position
    By netmastro in forum Indicators
    Replies: 1
    Last Post: 01-22-2009, 10:09

Posting Permissions

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