How to not trade during SWAP

 
I don't want my EA to trade during SWAP period. It is ridiculously to trade at swap time as Spread can be as wide as a six lane express way. How can I use time to tell my EA to jump swap period say 10 minutes before and 10 minutes after swap time. A small sample code will be appreciated.

Did I say sample code?
Sorry, I am not asking again.
I withdrawal my question. Let me try it myself.
 
macpee:
I don't want my EA to trade during SWAP period. It is ridiculously to trade at swap time as Spread can be as wide as a six lane express way. How can I use time to tell my EA to jump swap period say 10 minutes before and 10 minutes after swap time. A small sample code will be appreciated.

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.

 
Fernando Carreiro #:

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.

 
Fernando Carreiro #:

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);


;
 
macpee #: 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.

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!

Reason: