Date Based Order

hrabialukasz
131
hrabialukasz  

Hey, 


Does anyone how to setup a program which would buy at current market price but at a specific time. For instance buy EURUSD on this day at 8AM with a stoploss and take profit with X amount of basis points?

Sergey Golubev
Moderator
122387
Sergey Golubev  

This is something similar on CodeBase - 

-----------

Pending orders by time - expert for MetaTrader 5  

The Expert Advisor works with pending orders: it sets Buy Stop and Sell Stop at the specified time. Pending orders are set with the Stop Loss. The EA uses virtual Take Profit, i.e. it monitors open positions, and when the current position profit reaches Take Profit, the EA closes it by market.

-----------

Pending orders by time 2 - expert for MetaTrader 5  

Modification of the Pending orders by time EA: now you can set either a permanent (Lots > 0 and Risk ==0) or dynamic lot (Lots == 0 and Risk > 0). Added trailing.

Sergey Golubev
Moderator
122387
Sergey Golubev  

This is more like that - 

-----------

TimeEA - expert for MetaTrader 5

A Simple Expert Advisor The EA opens a position of the specified type at the time specified in the EA parameters. The position is closed at the time specified in the appropriate parameter.

hrabialukasz
131
hrabialukasz  
Sergey Golubev:

This is more like that - 

-----------

TimeEA - expert for MetaTrader 5

A Simple Expert Advisor The EA opens a position of the specified type at the time specified in the EA parameters. The position is closed at the time specified in the appropriate parameter.

Thanks so much. I've tested it and it works great however I can't set a specific date on it for instance tomorrow(I can set the time but not the date). Have you an idea on how to setup this kind of order or maybe there is a different EA for that?
Sergey Golubev
Moderator
122387
Sergey Golubev  
hrabialukasz:
Thanks so much. I've tested it and it works great however I can't set a specific date on it for instance tomorrow(I can set the time but not the date). Have you an idea on how to setup this kind of order or maybe there is a different EA for that?

I do not know sorry ..

Marco vd Heijden
Moderator
13658
Marco vd Heijden  

Please look into the time structure it incorporates what you need.

struct MqlDateTime 
  { 
   int year;           // Year 
   int mon;            // Month 
   int day;            // Day 
   int hour;           // Hour 
   int min;            // Minutes 
   int sec;            // Seconds 
   int day_of_week;    // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) 
   int day_of_year;    // Day number of the year (January 1st is assigned the number value of zero) 
  };

You can literally make it do what you need.

 Please see: https://www.mql5.com/en/docs/constants/structures/mqldatetime

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Date Type Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Date Type Structure
  • www.mql5.com
Constants, Enumerations and Structures / Data Structures / Date Type Structure - Reference on algorithmic/automated trading language for MetaTrader 5
Marco vd Heijden
Moderator
13658
Marco vd Heijden  

Additionally you can incorporate the calendar control so that it becomes easy to pick your dates.


https://www.mql5.com/en/articles/2537

Graphical Interfaces VIII: The Calendar Control (Chapter 1)
Graphical Interfaces VIII: The Calendar Control (Chapter 1)
  • www.mql5.com
In order to get a better understanding of this library's purpose, please read the first article: Graphical interfaces I: Preparation of the library structure (Chapter 1). A list of chapters with links is provided at the end of articles in each part. You can also download the latest full version of the library from there. Files must be placed...