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 = _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);

}

}

 
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.

 

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

 

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()<=23))

{ 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); }

}

}

 

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

 

The SkyDart EA had some good logic but didn't work for me.

Minnelli

Forex Signal Providers - Journal - My review site

 
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);

}
 

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

 

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

 

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

Files:
 

Thanks guys. Ill try it out!