Navigation´╝ÜHome > Content >

Chris_example.mq4

Time: 2010-10-05 | Download file:Chris_example.mq4

(deleted)

extern string	___________________Separator_04	=	"<<<<< TRADING TIMES OPTIONS >>>>>";
extern bool		TRADE.MONDAY					= 	True;					// True=Yes, False=No
extern bool		TRADE.FRIDAY					= 	True;					// True=Yes, False=No
extern bool 	USE.TRADING.TIMES				=	True;					// True=Yes, False=No (If False, EA runs all the time)
extern string	COMMENT.WARNING					=	"Set Trading Times To Broker Time, Not Gmt";
extern string 	SESSION1.START					=	"12:00";				// Session period starting time
extern string 	SESSION1.END					=	"22:00";				// Session period ending time
extern string 	SESSION2.START					=	"99:99";				// Session period starting time
extern string 	SESSION2.END					=	"99:99";				// Session period ending time
extern string 	SESSION3.START					=	"99:99";				// Session period starting time
extern string 	SESSION3.END					=	"99:99";				// Session period ending time
extern string 	SESSION4.START					=	"99:99";				// Session period starting time
extern string 	SESSION4.END					=	"99:99";				// Session period ending time
// extern int 	GMT.OFFSET						= 	2;



int start()
{
	if (IsNewCandle())
	{
		ExitOnConditionalCandle();

		if (TradingOkay())
		{
			EntryOnConditionalCandle();
			EntryOnShortMaCross();
		}
	}

	// Deal with trailing positions
	HandleTrailingStop();

	return(0);
}


bool CheckTimes(string start, string end) 
{
	// Check for specific time, return true, if current time is within this range.
	if (IsPast(start) && !IsPast(end)) 
		return(true);
	else 
		return(false);
}


//=============================================================================
//
// PURPOSE: 
//     Convert a string time value to an int representing the number of 
//     seconds elapsed since Jan 1, 1970
//
// PARAMETERS:
//     time: the time (string) to check, format: HH:MM
//
// RETURN VALUE:
//     Number of seconds past 1970 "time" represents
//
//=============================================================================
int CalcSecs(string time)
{
	// Calculate time (datetime format: number of secs since 1970)
	int timeSecs = StrToTime(Year() + "." + Month() + "." + Day() + " " + time); // + GMT.OFFSET * 3600;
	
	return(timeSecs);
}


//=============================================================================
//
// PURPOSE: 
//     Given a time value (HH:MM), and optionally a number of hours, check
//     whether the current time is past the time (+ the optional hours)
//
// PARAMETERS:
//     time: the time (string) to check, format: HH:MM
//    hours: optional; hours past "time" to check
//           So if time == "13:00", and hours == 3, 
//           it will return true if it is past 4:00 pm
//
// RETURN VALUE:
//      True: Current time is past time passed in
//     False: Current time is NOT past time passed in
//
//=============================================================================
bool IsPast(string time, int hours=0) 
{
	bool ret = false;
	
	int timeInSecs = CalcSecs(time) + (3600 * hours);
	if (TimeCurrent() > timeInSecs) 
		return(true); 
		
	return(ret);
}


//=============================================================================
//
// PURPOSE: 
//     Check to see that it is okay to place a trade right now
//     (See "TRADING TIMES OPTIONS" section of settings for options)
//
// RETURN VALUE:
//      True: Okay to trade right now
//     False: Forbidden to place a new trade at this time
//
//=============================================================================
bool TradingOkay()
{
	datetime 	closeTime, curTime;
	int			totalPips = 0;
		
	curTime = TimeCurrent();
	
	// Do not trade mondays if set
	if (!TRADE.MONDAY && DayOfWeek() == 1)
		return(false);

	// Do not trade fridays if set
	if (!TRADE.FRIDAY && DayOfWeek() == 5)
		return(false);

	// Do not trade sundays, ever.
	if (DayOfWeek() == 0)
		return(false);

	// Otherwise... deal with actual time constraints	
	if (USE.TRADING.TIMES == false)
		return(true);
	
	if (SESSION1.START != "99:99" && CheckTimes(SESSION1.START, SESSION1.END))
		return(true);

	if (SESSION2.START != "99:99" && CheckTimes(SESSION2.START, SESSION2.END))
		return(true);

	if (SESSION3.START != "99:99" && CheckTimes(SESSION3.START, SESSION3.END))
		return(true);

	if (SESSION4.START != "99:99" && CheckTimes(SESSION4.START, SESSION4.END))
		return(true);
		
	return(false);
}

Recommend