- select trading time and avoid swap time to trade
- Trying to code EA myself but its not working. Please, help me!
- Mql5 custom spreads and custom swaps during backtesting.
On every OnTick (or you could use OnTimer), read the server time via TimeCurrent. When it is more or equal to 23:50, close all the positions (but collect the details first — Volume, S/L, T/P, current price, etc.). Then when the time is more or equal to 00:10, place the orders again, by restoring them. However, add some logic to consider the current prices again to decide if they should be restored or not. If current prices have moved considerably and some trades may no longer be valid or no longer worth being restored.
Sample code for this may not be plausible, as it may be highly dependent on your existing strategy rules already in place. When I do this for my own EAs, it is almost always adjusted to meet the needs of that specific EA and it is never very general.
On every OnTick (or you could use OnTimer), read the server time via TimeCurrent. When it is more or equal to 23:50, close all the positions (but collect the details first — Volume, S/L, T/P, current price, etc.). Then when the time is more or equal to 00:10, place the orders again, by restoring them. Hever, add some logic to consider the current prices again to decide if they should be restored or not. If current prices have moved considerably and some trades may no longer be valid or no longer worth being restored.
Sample code for this may not be plausible, as it may be highly dependent on your existing strategy rules already in place. When I do this for my own EAs, it is almost always adjusted to meet the needs of that specific EA and it is never very general.
Thanks Fernando. I am highly grateful.
On every OnTick (or you could use OnTimer), read the server time via TimeCurrent. When it is more or equal to 23:50, close all the positions (but collect the details first — Volume, S/L, T/P, current price, etc.). Then when the time is more or equal to 00:10, place the orders again, by restoring them. However, add some logic to consider the current prices again to decide if they should be restored or not. If current prices have moved considerably and some trades may no longer be valid or no longer worth being restored.
Sample code for this may not be plausible, as it may be highly dependent on your existing strategy rules already in place. When I do this for my own EAs, it is almost always adjusted to meet the needs of that specific EA and it is never very general.
I have the following code but I am receiving two warnings: "Implicit conversion from string to number"
I don't know if the code will work as well.
if (TimeHour(TimeCurrent()) > TimeHour("23:50") && TimeHour(TimeCurrent()) < TimeHour("00:10")) return(0); ;
You cannot convert a string into a datetime that way. If you want to use a constant, then use a datetime constant:
if( TimeHour( TimeCurrent() ) > TimeHour( D'23:50:00' ) && TimeHour( TimeCurrent() ) < TimeHour( D'00:10:00' ) ) return( 0 );
However, lets simplify it further:
if( Hour() > 23 && Hour() < 0 ) return( 0 );
Oops! Something seems wrong! Now that it's simplified, you can see that the logic is flawed. In the above example, the "Hour" will NEVER be greater than 23 and it will NEVER be less then 0.
So, you will have to think more about what your objective is and define it in more detail!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use