MT4: How can I schedule orders?

Hi all,

perhaps, somebody can help me.

My trading system isn’t based on any indicators, it’s based only on probabilities and statistics. This means that orders won’t be opened because of a special constellation of indicators, They are opened at defined times.

In the evening, I can manage this very well by hand, but during the day I can’t because of my job. Therefore, I’m looking for an order tool, an EA or any other good idea to partly automate it.

My imagination: I somewhere must have the possibility to describe my desired order in advance (e.g. in a file or a list or a mask, etc.). For example like this:
“12/12/2011 15.59.58 BUY GOLD 00:25 TP=4.00 SL=40.00”.
And at the defined point of time an EA should guarantee that the position is opened (and TP and SL are set). Closing the trade is no problem. I can do it manually.This is not time critical.

The broker ActivTrades offers SmartOrder, which has the funcionality. But unfortunatelly I trade with fxprimus.

I looked and googled for days, but I can’t find anything workable.
Maybe you have ideas. Every suggestion is welcome.

Best regards and greetings!
Siero

Hi,
Maybe this will help? Now I don’t know if this will work right away because MT4 is not accessible to me right now, but it’s a start. If anything it can easily be fixed.

Open the MetaEditor in MT4, copy & paste the following, save to the Experts folder and compile. If there are any syntax errors, let me know and I’ll tell you how to fix them. Later I’ll be home where I can try it too.

If there are no compile errors, then attach it to a chart and make sure your EA icon has a green symbol, and try it out. You have to set the time (I set it to default 0’s), and your tp and sl setting, as well as 1 to indicate either a buy or sell order.

:slight_smile:

//+------------------------------------------------------------------+
//|                                                     TimeOpen.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+


//---- input parameters
extern double    Lots=1.0;
extern double    Buy=0.0;
extern double    Sell=0.0;
extern double    TP=4;
extern double    SL=40;
extern datetime  _Date=D'0000.00.00 09:00';

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  int ticket;

  double stoploss_buy=0;
  double takeprofit_buy=0;
  double stoploss_sell=0;
  double takeprofit_sell=0;
    
  
  if (SL > 0 && Buy > 0)
  {stoploss_buy = Buy-(SL*Point);  }
  
  if (TP > 0 && Buy > 0)
  {takeprofit_buy = Buy+(TP*Point);  }

  if (SL >  0 && Sell > 0)
  { stoploss_sell = Sell+(SL*Point);  }
  
  if (TP > 0 && Sell> 0)
  { takeprofit_sell = Sell-(TP*Point); }
  
 
  if(LocalTime()>=_Date)
       {
         // Buy order
         if ( (Buy >0) )
         {
            ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,stoploss_buy,takeprofit_buy,"Buy order ",00001,0,CLR_NONE);
           
            if(ticket<0)
            {
               Print("OrderSend failed with error #",GetLastError());
               return(0);
            }
         }
         // Sell order
         if ( (Sell >0) )
         {
            ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,stoploss_sell,takeprofit_sell,"Buy order ",00002,0,CLR_NONE);
            
            if(ticket<0)
            {
               Print("OrderSend failed with error #",GetLastError());
               return(0);
            }
         }
         }
  

//----
   return(0);
  }
//+------------------------------------------------------------------+

Hi Sweet Pip,

thank you very much for your answer. I could compile the code, but a first test seems, that it doesn’t open any positions. I will try it again next week (This week I’m busy).

Best regards
Siero

Any script you use will require some file or even email handling mechanics allowing you to control it while away from your machine as most EAs use extern variables that are set once when the EA is loaded in. Changing these variables interrupt the EA which is ok if you want to manage already opened positions manually.

As far as the script generously posted by SweetPip it’s effectiveness depends on your broker taking stops in terms of prices and not pips. It also depends (as it is currently written) on you setting Buy to Ask when you want to monitor for a long or Sell to Bid when you want to monitor for a short - look at the lines that calculate the stops and take profits. A long stop is ASK-(SL*point). So if u set Buy to 1, that line will calculate an invalid stop of 1 - (40 * point). In fact the best step is to set Buy or Sell to 1 as suggested but to change the two lines that calculate long SL and TP to use ASK instead of Buy and the following two to use BID instead of Sell.

The sell OrderSend comment should read “Sell order” so you can read your logs right.

The if statements that check tickets should have ELSE clauses after them that at least reset Buy and Sell to 0 otherwise this code will open positions every tick once the search time is hit. Resetting time is prudent too and depending what 0000.00.00 means to MT4 that is fine but a safer reset is an arbitrary future date like 2222.11.00 00:00 or 8765.43.21 00:00 so no matter what Buy and Sell are doing there is no way the trade code can trigger (local time is always greater than all dates/times in the past). Check MT4 limits on dates.