Forex
Google

Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
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-21-2007, 05:30 PM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
Need procedure to only trade at certain times - Please help

Looking for a procedure to Check Time to see if it is within a trade window. My code here is okay but isn't playing nice with the EA when I'm just trying to test a system. Example - I may only want to open trades from 1700GMT - 2000GMT. Anyway, if anyone has a procedure, that would be great. Thanks in advance.

Minnelli
.................................................. .........................................
extern bool xTime = TRUE;
extern int _xTime_GMT_Offset = 3;
extern int _xTime_From = 17;
extern int _xTime_To = 20;
e

bool CheckTime(int ai_start, int ai_stop) {
if (xTime) {
if (ai_stop > 0 && ai_stop < 6 && Period() == xPerMin && ai_start >= _xTime_From + _xTime_GMT_Offset || ai_start <= _xTime_To + _xTime_GMT_Offset) {
g_is_trade_time = TRUE;
return (TRUE);
} else {
g_is_trade_time = FALSE;
return (FALSE);
}
} else {
g_is_trade_time = TRUE;
return (TRUE);
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-21-2007, 06:07 PM
ryanklefas's Avatar
ryanklefas ryanklefas is offline
Senior Member
 
Join Date: Apr 2006
Location: USA
Posts: 438
ryanklefas is on a distinguished road
Quote:
isn't playing nice with the EA when I'm just trying to test a system
What does that mean?

Also, you haven't shown enough code to know what problems you may be encountering.
__________________
"Don't work harder, work smarter." -- my Java professor

Coder for Hire:
http://www.firecell-fx.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-21-2007, 11:34 PM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
Lightbulb

Hi Ryan - thanks for responding. The code works great when the time is say 17 to 5 or 18 to 6. But when I narrow it down to just open trades between 12 and 14 it doesn't follow directions I know I didn't place all of the code but I was only looking for something that would allow me to pick the hours I want to trade and then pass the variable g_is_trade_time = TRUE or FALSE.

I would even take take something like:
000-100 : True:
100-200: True;
200-300: False;
etc...

I just assumed someone had something handy and being the creator the one of the best utility EAs on the forum "Swiss Army EA", you may be the man .

......................
Long run I'm looking for something that can maybe trade session opens for a couple hours. But the basic need is just a simple start trading at x and stop placing order at y. I was hoping to keep it GMT and just use the offset like I have now.

Once we get something we should be able to share it with everyone. I think most folks could use a time to trade piece of code. It can keep them out of session opens or put them in if it's a breakout system.

Minnelli
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-22-2007, 04:19 AM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
Okay came up with - it allows you to pick a time like 17 to 20 or will allow you to jump over midnight for say 17 to 4. The Offset adjusts time according to GMT. The g_is_trade_time is another variable down below in my EA. Now I know I can mod this to handle 3 times if needed.

Globals:
extern int GMT_Offset = 0;
extern int StartHour1 = 22;
extern int EndHour1 = 9;

int StartHour1Adj;
int EndHour1Adj;


Local:
bool CheckTime() { //this is used later to see if CheckTime is TRUE
if (xTime) { //a user defined bool to see if you use time or not

g_is_trade_time = FALSE;
bool midnight=false;

StartHour1Adj=StartHour1+GMT_Offset;
EndHour1Adj=EndHour1+GMT_Offset;

if (EndHour1 - StartHour1 < 0) midnight=true;

if ((midnight==false&&Hour()>=StartHour1Adj&&Hour()<= EndHour1Adj))
{ g_is_trade_time = TRUE; return (TRUE); }

if ((midnight==true&&Hour()>=StartHour1Adj&&Hour()<=2 3))
{ g_is_trade_time = TRUE; return (TRUE); }

if ((midnight==true&&Hour()>=0&&Hour()<=EndHour1Adj))
{ g_is_trade_time = TRUE; return (TRUE); }

else
{ g_is_trade_time = FALSE; return (FALSE); }

}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-22-2007, 04:19 AM
Ruf Ruf is offline
Junior Member
 
Join Date: Jun 2006
Location: Canada
Posts: 8
Ruf is on a distinguished road
How would I make it so I could turn my EA on at say... 6am for 20 minutes, then it shuts off unless a trade is in progress? I know they did something kinda like that in the news trader EA, but i have no idea how to do it. Any help would be awsome
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-22-2007, 04:21 AM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
The SkyDart EA had some good logic but didn't work for me.

Minnelli
Forex Signal Providers - Journal - My review site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-22-2007, 04:21 AM
Nicholishen's Avatar
Nicholishen Nicholishen is offline
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Code:
bool IsTradeTime(int begin, int end){
   if(begin < end){
      if(Hour() >= begin && Hour() < end)return(true);
   } else {
      if(Hour() >= begin || Hour() < end)return(true);
   }
   return(false);
}
__________________
"Anyone who has never made a mistake has never tried anything new." -Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-22-2007, 04:26 AM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
Not sure I had a hard enough time getting the big hand to work Only hours for me...

There is a TimeMinute function available.

I would think you would need to have code like I just posted with CheckTime and say something like:

if(hours() == 6 {return (FALSE);}

Then it would not trade during the 6 o'clock hour. I just have the CheckTime tested before it places trades.

Minnelli
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-22-2007, 04:29 AM
Minnelli Minnelli is offline
Senior Member
 
Join Date: May 2007
Posts: 127
Minnelli is on a distinguished road
Thanks Nicholishen I figured someone would have a simple solution. My problem was getting past midnight on a 18 to 4 hours - I will look at that tomorrow night. Need to get sleep now...Thanks again.

Minnelli
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-22-2007, 08:26 AM
MrPip MrPip is offline
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 551
MrPip is on a distinguished road
Trading Times function

Minnelli,

I have code that does what you want. It allows times like 2215 to 335 or 0900 to 1030.

Attaching file with functions and variables needed to add to your EA.

FYI, I also coded the Skydart EA but only used hours to trade.


Robert
Attached Files
File Type: mq4 TradingTimes.mq4 (4.8 KB, 55 views)

Last edited by MrPip : 06-22-2007 at 08:41 AM. Reason: attaching code
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
Trade only certain times of day? pipsweak Expert Advisors - Metatrader 4 1 04-01-2007 05:20 PM
Changing Times Pervaz General Discussion 3 08-29-2006 10:03 PM
Metatrader times guybraun Metatrader 4 2 02-15-2006 01:53 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 05:28 AM.