Trading Times Enhancement

 

Guys - MrPip was kind enough to show us a nice procedure to only trade during certain periods. I have modified it a bit to allow any time period to cross over midnight. In the old version if you had a trading time of say 1700 - 800 it would just mess up. A strategy I'm using needs the flexibility for every time period to check to see if it overlaps midnight and calculates the proper trading time.

If anyone wants to use this you just need to stick this in global are before the init and start procedures. Someone may tell me thats bad coding but my EA is functioning perfect now. Plus I can pick three separate trading windows (like 1500 - 2000, 2300 - 400, 600 - 900, or whatever you want.

The value CheckTradingTimes needs to be included in your buy/sell process or whatever check you will be using. So you need to remember when CheckTradingTimes is TRUE it really means DO NOT TRADE - Bad Time.

Enjoy and please test if you get a chance.

Minnelli

Forex Signal Providers - Journal

//+------------------------------------------------------------------+

//| CODE FOR TRADING TIMES - VARIABLES - From TradingTimes.mq4 |

//| Edited by Minnelli - http://minnelli.com/forex |

//+------------------------------------------------------------------+

extern string sm0="--Trading Hours--";

extern string sm1=" Times are GMT when UseDST=false";

extern bool UseTradingHours = true;

extern string sm2 = "GMT Offset default is for FXDD";

extern int GMT_Offset = 3;

extern bool UseDST = false;

extern string sm3 = "Use Asian Market if trading only 1 period";

extern bool TradeAsianMarket = true;

extern int myAsianStart = 2200; // Start trades after time 2200

extern int myAsianStop = 100; // Stop trading after time 100

extern bool TradeEuropeanMarket = false;

extern int myEurStart = 700; // Start trades after time 700

extern int myEurStop = 900; // Stop trading after time 900

extern bool TradeNewYorkMarket = false;

extern int myNYStart = 1300; // Start trades after time 1300

extern int myNYStop = 1500; // Stop trading after time 1500

int AsianStart; // Start trades after time

int AsianStop; // Stop trading after time

int EurStart; // Start trades after time

int EurStop; // Stop trading after time

int NYStart; // Start trades after time

int NYStop; // Stop trading after time

bool CheckTradingTimes;

//+------------------------------------------------------------------+

//| CHECK TRADING TIMES (START) |

//+------------------------------------------------------------------+

bool CheckTradingTimes()

{

bool StopTrading;

int ct;

bool AsianMidnight;

bool EurMidnight;

bool NYMidnight;

ct = Hour() * 100 + Minute();

//+------------------------------------------------------------------+

//| TIME CORRECTION |

//+------------------------------------------------------------------+

int TimeCorrection;

TimeCorrection = 100 * GMT_Offset;

if (UseDST == true)

{TimeCorrection = TimeCorrection - 100; }

AsianStart = myAsianStart + TimeCorrection;

AsianStop = myAsianStop + TimeCorrection;

EurStart = myEurStart + TimeCorrection;

EurStop = myEurStop + TimeCorrection;

NYStart = myNYStart + TimeCorrection;

NYStop = myNYStop + TimeCorrection;

//+------------------------------------------------------------------+

//| STOP TRADING CHECK |

//+------------------------------------------------------------------+

StopTrading = true;

//+------------------------------------------------------------------+

//| Check trading Asian Market |

//+------------------------------------------------------------------+

if (StopTrading == true)

{

if (TradeAsianMarket == true)

{

if (AsianStop - AsianStart < 0) AsianMidnight=true;

if ((AsianMidnight==false && ct>=AsianStart && ct<=AsianStop)) StopTrading = false;

if ((AsianMidnight==true && ct>=AsianStart && ct<=2400)) StopTrading = false;

if ((AsianMidnight==true && ct>=000 && ct<=AsianStop)) StopTrading = false;

}

}

//+------------------------------------------------------------------+

//| Check Trading European Market |

//+------------------------------------------------------------------+

if (StopTrading == true)

{

if (TradeEuropeanMarket == true)

{

if (EurStop - EurStart < 0) EurMidnight=true;

if ((EurMidnight==false&&ct>=EurStart && ct<=EurStop)) StopTrading = false;

if ((EurMidnight==true&&ct>=EurStart && ct<=2400)) StopTrading = false;

if ((EurMidnight==true&&ct>=000 && ct<=EurStop)) StopTrading = false;

}

}

//+------------------------------------------------------------------+

//| Check Trading New York Market |

//+------------------------------------------------------------------+

if (StopTrading == true)

{

if (TradeNewYorkMarket == true)

{

if (NYStop - NYStart < 0) NYMidnight=true;

if ((NYMidnight==false&&ct>=NYStart && ct<=NYStop)) StopTrading = false;

if ((NYMidnight==true&&ct>=NYStart && ct<=2400)) StopTrading = false;

if ((NYMidnight==true&&ct>=000 && ct<=NYStop)) StopTrading = false;

}

}

//+------------------------------------------------------------------+

//| Return value to CheckTradingTimes |

//+------------------------------------------------------------------+

return(StopTrading);

}

//+------------------------------------------------------------------+

//| CHECK TRADING TIMES (END) |

//+------------------------------------------------------------------+

 

Hi Minnelli,

I trying to use your code to intergrate it with the HedgeEA 6.1, basically the EA trades 24hours all I want it to do is to trade at certain times as indicated by your EA. I have added the code and complied it but it don't seem to work during the back test, could you please have a look thanks

Cheers.

 

How To Make Time Setting Function For EA?

hello, i am newbie in forex

Can someone tell me can we put time setting code for ea?

if i can put it, how to code it?

For example, i am using stoch ea when ranging time or non active trading time and easy to get 10pips daily but by doing manually. Yes, i am using this ea for my testing:-https://www.forex-tsd.com/expert-advisors-metatrader-4/440-stoch-hellkas-ea.html

Let say, from 11pm to 3am, i need time setting for ea so that i am not manually make trading and sitting on the my pc 24hours for that time, i just set time on my ea and let the ea running itself and not make trading before and after the time that i have set on ea.

When i open my pc and trading platform on 11pm, i just run my ea and put the time setting from that time and until certain time and i can left my pc still open and ea running with this time setting to auto trade for me.

Im using the stoch ea for my study for MQL but i need some support because

I'm not a programmer and have background in IT.

Thanks for any help!!!

 

It is timefilter.

 

For example:

Timefilters.

For any kinds of timefilter, in the beginning of the code type the following:

extern bool UseHourTrade = True;

extern int FromHourTrade = 8;

extern int ToHourTrade = 17;[/CODE]

1. Timefilter with comments.

After this code

int start() {

type the following:

[CODE]if (UseHourTrade){

if((Hour()>=FromHourTrade)&&(Hour()<=ToHourTrade))

Comment("Trading Hours");

else

{

Comment("Non-trading Hours");

return(0);

}

}

EA will trade from 8 am till last bar (or last tick) before 18.

 

Thanks for the snippet of code.

 

Code to add Tradetimes

Hello All, just wondering what code to change/add in an EA make it trade within a certain time?

Thanks

 

No-trade period rectangle

I'm trying to display a rectangle that identifies no-trade times (e.g. just before & after major news) that goes the height of the chart. Does someone have some code that they could share with me to do that?

Thanks,

Mark.

 

Hour and Minute Time Filter

Hello

extern bool UseHourTrade = True;

extern int FromHourTrade = 8;

extern int ToHourTrade = 17;

It is just for the beginning of the time frame ...

How can I add this the minute frame ? Like 09:15 ?

Thank you...