+ Reply to Thread
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?

+ 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. Duplicate Orders
    By BillR in forum MQL programming
    Replies: 1
    Last Post: 04-09-2009, 12:58
  3. How to close open orders?
    By juhanimi in forum MQL programming
    Replies: 0
    Last Post: 03-05-2009, 07:49
  4. Dynamic Trading System ( DTS)
    By paradise in forum Ideas for expert advisors
    Replies: 24
    Last Post: 01-06-2009, 23:38
  5. Dynamic Trading System EA
    By funyoo in forum Expert advisors backtesting
    Replies: 0
    Last Post: 12-12-2008, 20:51

Posting Permissions

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