Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2007, 05:56 PM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
Smile 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

PHP Code:
//+------------------------------------------------------------------+
//| 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 0AsianMidnight=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 0EurMidnight=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 0NYMidnight=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)                                        |
//+------------------------------------------------------------------+ 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-04-2007, 12:21 AM
claypot's Avatar
claypot claypot is offline
Member
 
Join Date: May 2006
Posts: 45
claypot is on a distinguished road
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.
Attached Files
File Type: mq4 HedgeEA_v6.1_with_trading_times.mq4 (37.8 KB, 30 views)
File Type: ex4 HedgeEA_v6.1_with_trading_times.ex4 (28.8 KB, 18 views)
__________________
When in doubt...follow the crowd
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-08-2007, 07:28 AM
rayz rayz is offline
Junior Member
 
Join Date: Jun 2007
Posts: 6
rayz is on a distinguished road
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:-http://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!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-08-2007, 07:35 AM
newdigital newdigital is offline
Administrator
 
Join Date: Sep 2005
Posts: 15,138
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
It is timefilter.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-08-2007, 07:57 AM
newdigital newdigital is offline
Administrator
 
Join Date: Sep 2005
Posts: 15,138
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
For example:

Timefilters.

For any kinds of timefilter, in the beginning of the code type the following:
Code:
extern bool UseHourTrade = True;
extern int  FromHourTrade = 8;
extern int  ToHourTrade = 17;


1. Timefilter with comments.

After this code
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-08-2007, 08:11 AM
et_phonehome_2 et_phonehome_2 is offline
Senior Member
 
Join Date: Feb 2006
Posts: 1,075
et_phonehome_2 is on a distinguished road
Thanks for the snippet of code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-08-2008, 01:31 PM
matrixebiz's Avatar
matrixebiz matrixebiz is offline
Senior Member
 
Join Date: Oct 2006
Posts: 1,038
matrixebiz is on a distinguished road
Code to add Tradetimes

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

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best Trading Times 67-17454 General Discussion 17 11-23-2006 07:58 PM
Trading times - forward & backward tests compared phazei Metatrader 4 1 08-03-2006 01:41 PM
Trading Times dennisros General Discussion 3 02-13-2006 11:42 AM
Trade Times caldolegare General Discussion 7 11-15-2005 01:07 PM


All times are GMT. The time now is 02:49 AM.