Unable to execute BuyStop and SellStop orders at same time from EA

 

Hey guys,

 

Just wondering if you can offer some insight. I've looked around for answer but have come up short.

I have a few different news trading EA's that straddle the current price with stop orders above and below it at a certain time before a news release. Works good, only problem is, once the stops are reached, actual orders are not opened. The EA's will put the stop orders, but once the price reaches (for example) the SellStop limit, the SellStop order is deleted and no sell order is created. It will leave the BuyStop order open, and if the price retraces up, it will close that one too.

Any ideas? If I manually put on a sellstop / buystop order, it fills just fine, but maybe it's an issue with it being in an EA, or having to opposite stop orders on at the same time? Any way to work around this? Thanks a lot, 

 
I would guess you have to show the code for anyone to answer this.
Also, you might review the code to find any issues.
Check the spreads, the Digits ? How many digits does your broker use etc. ?

Use the SRC feature and copy and paste your code

Read the EA journal and/or Experts tab to see if there is any error messages. This might tell you something
Also the broker may require a separate method for opening the stop order ? Is there a sl and tp that might need to be modified separately or something that I recall reading on the forums.
This didn't apply to me but I recall seeing something mentioned about it.

Anyhow post your code to get better responses
 

Thanks for the response. I am using the News Trader Strategy found in the codebase on mql4.com. It is made by Forex Fellow and posted by Michael. I posted the code below. The EA opens the stop orders properly, but as I said they do not trigger an actual buy/sell signal. I do not get any error messages in the journal either. Any ideas? Oh and I am using a 5 digit broker, but I'm testing this EA with a MetaTrader4 demo account. Thanks for the help,

 
//+------------------------------------------------------------------+
//|                                                   NewsTrader.mq4 |
//|                                                     Forex Fellow |
//|                                              www.forexfellow.com |
//+------------------------------------------------------------------+
#property copyright "Forex Fellow"
#property link      "www.forexfellow.com"

int cnt, ticket =0, ticket2=0, total;
extern int lot = 1;
extern int sl = 10;
extern int tp = 10;
extern int bias = 20//we place our order 20 pips from current price

double orderAsk;
double orderBid;
string OrderCloseDate;
      
int init()
  {
  Print(MarketInfo(Symbol(), MODE_STOPLEVEL));
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   
   //we have to know the time and date of news publication
   //I don't want to write what sombody else has written here https://www.mql5.com/en/articles/1502
   //we can use this indicator to get the date and time of news publications
   //I have put here some example date and 
   int newsDateYear = 2010;
   int newsDateMonth = 3;
   int newsDateDay = 8;
   int newsDateHour = 1;
   int newsDateMinute = 30;
   
   //we need to open order before news publication
   newsDateMinute -= 10//10 minutes before publication
   string orderOpenDate = newsDateDay + "-" + newsDateMonth + "-" + newsDateYear 
                                                + " " + newsDateHour + ":" + newsDateMinute + ":00";
   int currentYear = Year();
   int currentMonth = Month();
   int currentDay = Day();
   int currentHour = Hour();
   int currentMinute = Minute();
   
   //we get current time
   string currentDate = currentDay + "-" + currentMonth + "-" + currentYear 
                                                + " " + currentHour + ":" + currentMinute + ":00";
                                                             
   
   if(orderOpenDate == currentDate)
   { 
      //we place 2 orders: buy stop and sell stop
      if(ticket < 1)
      {
         orderAsk = Ask - bias * Point;
         orderBid = Bid - bias * Point;
         ticket=OrderSend(Symbol(),OP_SELLSTOP,lot,orderBid,1,orderAsk+Point*sl,orderBid-tp*Point,"NewsTrader",2,0,Red); 
      }
      if(ticket2 < 1)
      {
         orderAsk = Ask + bias * Point;
         orderBid = Bid + bias * Point;
         ticket2=OrderSend(Symbol(),OP_BUYSTOP,lot,orderAsk,1,orderBid-Point*sl,orderAsk+tp*Point,"NewsTrader",2,0,Green); 
      }         
   }
   
   
   return(0);
  }
 
I was thinking that maybe the stoploss and takeprofit levels are too small, but even increasing them does nothing to fix the issues. Thanks,
 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.
  2. Check your return codes (OrderSelect) 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
  3. Try opening the orders without SL/TP and then modify.
Reason: