Results 1 to 2 of 2
 0 Attachment(s)    

Thread: Max Orders with a dynamic close

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    15

    Default Max Orders with a dynamic close

    Could use some help on opening more than one trade when all trades are closed dynamically (no set take profit or stop loss, just waits for an internal signal to do either).

    So, I know I need and extern int MaxOrders = 10. How can I open multiple positions (say MaxOrders 10), and close the correct orders?

    Here is the code for my dynamic order closing:

    for (int i = 0; i < Total; i ++) {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
    IsTrade = True;
    if(OrderType() == OP_BUY) {
    //Close

    //Here is where I begin looking to exit a buy

    if (CloseBuy1_2 > CloseBuy1_1 || CloseBuy2_2 > CloseBuy2_1 || (Sell5_1<Sell6_1&&Bid>OrderOpenPrice())) Order = SIGNAL_CLOSEBUY;

    if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if(Bid - OrderOpenPrice() > Point * TrailingStop) {
    if(OrderStopLoss() < Bid - Point * TrailingStop) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }

    } else {
    //Close

    //Looking to exit a sell

    if (CloseSell1_2 > CloseSell1_1 || CloseSell2_2 > CloseSell2_1 || (Buy5_1>Buy6_1&&Ask<OrderOpenPrice())) Order = SIGNAL_CLOSESELL;

    if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
    if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }

    }
    }
    }

  2. #2
    Junior Member
    Join Date
    Mar 2009
    Posts
    15

    Default

    So, anyone have any ideas?

Similar Threads

  1. Close all orders if profit is positive
    By luisneves in forum MQL programming
    Replies: 2
    Last Post: 01-15-2013, 13:58
  2. Close all buy and close all sell orders
    By q8m2002 in forum Scripts and other tools
    Replies: 11
    Last Post: 12-01-2012, 04:38
  3. Looking for script that will close orders
    By traffik in forum Scripts and other tools
    Replies: 3
    Last Post: 06-28-2012, 01:00
  4. How to close open orders?
    By juhanimi in forum MQL programming
    Replies: 0
    Last Post: 03-05-2009, 08:49

Tags for this Thread

closing, profit, signal, slippage, stop, trailing

Posting Permissions

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