EA placing 2 orders at the same time?

Back to topics list To post a new topic, please log in or register
DeanDeV 2015.03.28 13:00


I have a MA EA which should only place a single buy/sell order on a cross over. Any way to stop it from placing 2, sometimes 3, on a single crossover?

void OrderEntry(int direction)
   if((Hour()>=StartTimeMA && Hour()<=FinishTimeMA))  //Preferred trading hours
         double MABSL = Ask-(MAStopLoss*Point);
         double MABTP = Ask+(MATakeProfit*Point);

         int buyticket = OrderSend(Symbol(),OP_BUY,MALotSize,Ask,5,0,0,"MA Buy Order",MAMagicNumber,0,Aqua);     //placing order with ecn broker

         double MASSL = Bid+(MAStopLoss*Point);
         double MASTP = Bid-(MATakeProfit*Point);

         int sellticket = OrderSend(Symbol(),OP_SELL,MALotSize,Bid,5,0,0,"MA Sell Order",MAMagicNumber,0,Aqua);
WHRoeder 2015.03.28 13:20 #
DeanDeV: Any way to stop it from placing 2, sometimes 3, on a single crossover?
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Look for open orders and which bar the order was opened on. Or don't look for a signal, look for a change in signal:
    static int direction = -1;
    int dirPrev = direction;
    direction = ...;
    if(dirPrev != direction) OrderEntry(direction);
  3. Don't use int 0 and 1 when you mean bool. Don't use int 0 and 1 when you mean OP_BUY and OP_SELL.
  4. Check your return codes (OrderSend and OrderModify) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  5. if(buyticket>0)OrderModify(buyticket,OrderOpenPrice(),MABSL,MABTP,0,CLR_NONE);
    You can not use any Trade Functions - MQL4 Documentation unless you select the order first.
DeanDeV 2015.03.28 14:39 #
I used this:
int ThisBarTrade           =  0;

if (Bars != ThisBarTrade ) 
   ThisBarTrade = Bars; 

Seems to be working perfectly now. Thanks!
Back to topics list  

To add comments, please log in or register