Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
How do I close opened order after "X" hours? I can use expiration=X to close pending orders, but how can I close active positions after X hours that they have been opened. I have multiple simultaneous orders and open positions that open based on stop prices placed at various levels and they are triggered off at various times.
How do I close opened order after "X" hours? I can use expiration=X to close pending orders, but how can I close active positions after X hours that they have been opened. I have multiple simultaneous orders and open positions that open based on stop prices placed at various levels and they are triggered off at various times.
Hope some of the gurus can help me.
Maji
You could insert this function into your code.
PHP Code:
extern int MaxHours=3;
int YOUR_MAGIC_NUMBER_VARIABLE_HERE=298374;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
1. Can the code posted above be used all by itself as an EA, by simply putting the code into a plain text file and then renaming the text file with the .mq4 extension?
2. If I want to use this code/EA to close trades that have been placed by another different EA, does the Magic Number in this code have to match the Magic Number used in the other EA that placed the trades?
3. If I want this EA to, for example, close all trades after 24 hours after they have been opened, but to ignore Saturday and Sunday, what lines of code would I need to add? In other words, if I set MaxHours to 24 and if a trade was opened on Friday at a certain time, and I want this code/EA to close that trade on Monday at the same certain time, thus ignoring Saturday and Sunday, what lines of code would I need to add to this existing code posted above?
Thank You to anyone who can answer these questions!
1. Can the code posted above be used all by itself as an EA, by simply putting the code into a plain text file and then renaming the text file with the .mq4 extension?
2. If I want to use this code/EA to close trades that have been placed by another different EA, does the Magic Number in this code have to match the Magic Number used in the other EA that placed the trades?
3. If I want this EA to, for example, close all trades after 24 hours after they have been opened, but to ignore Saturday and Sunday, what lines of code would I need to add? In other words, if I set MaxHours to 24 and if a trade was opened on Friday at a certain time, and I want this code/EA to close that trade on Monday at the same certain time, thus ignoring Saturday and Sunday, what lines of code would I need to add to this existing code posted above?
Thank You to anyone who can answer these questions!
1. Yes
2. You have to set your own MN.
3. It's possible, but why. Usually traders close all orders on Friday. If they use weekly or monthly charts, they don't count hours.