View Single Post
  #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)                                        |
//+------------------------------------------------------------------+ 
Reply With Quote