Forex



Go Back   Forex Trading > Downloads > Expert Advisors - Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

 
 
Thread Tools
 
Old 04-11-2007, 02:17 AM
Junior Member
 
Join Date: Mar 2007
Posts: 10
Hartadi is on a distinguished road
OrderSend problem

Hello All,

This is my first post in this forum. I’m very new with MQL4 and my c language skill is almost nothing

I try to make this simple code, but the result is confusing for me.

Here is my code :

int start()
{
//----
int zero_hour, zero_minute;

zero_hour=Hour();
zero_minute=Minute();

if(zero_hour==0 && zero_minute==0)

OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-20*Point,Ask+60*Point,"My Order",12345,0,Green);

//----
return(0);
}

what I want to do is when the time reach 00.00 then send order to buy.

I run it for 1 month ( 2007.01.01 to 2007.01.31) in M1 period. But why the code make 3 order send at 2007.01.04 00:00 ?

2007.04.11 07:54:24 2007.01.04 00:00 GMT00 GBPUSD,M1: open #4 buy 1.00 GBPUSD at 1.9513 sl: 1.9493 tp: 1.9573 ok
2007.04.11 07:54:24 2007.01.04 00:00 GMT00 GBPUSD,M1: open #3 buy 1.00 GBPUSD at 1.9509 sl: 1.9489 tp: 1.9569 ok
2007.04.11 07:54:24 2007.01.04 00:00 GMT00 GBPUSD,M1: open #2 buy 1.00 GBPUSD at 1.9510 sl: 1.9490 tp: 1.9570 ok
2007.04.11 07:54:23 2007.01.03 08:05 Tester: stop loss #1 at 1.9716 (1.9714 / 1.9718)
2007.04.11 07:54:23 2007.01.03 00:00 GMT00 GBPUSD,M1: open #1 buy 1.00 GBPUSD at 1.9736 sl: 1.9716 tp: 1.9796 ok

what’s wrong with my code?

Bye
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 03:50 AM
bluto's Avatar
Senior Member
 
Join Date: Sep 2006
Posts: 633
bluto is an unknown quantity at this point
Quote:
Originally Posted by Hartadi
Hello All,

This is my first post in this forum. I’m very new with MQL4 and my c language skill is almost nothing

I try to make this simple code, but the result is confusing for me.

Here is my code :

int order_count = 0;

int start()
{
//----
int zero_hour, zero_minute;

zero_hour=Hour();
zero_minute=Minute();

if(zero_hour==0 && zero_minute>0) {order_count=0;}
if(zero_hour==0 && zero_minute==0 && order_count==0)
{
OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-20*Point,Ask+60*Point,"My Order",12345,0,Green);
order_count++;
}

//----
return(0);
}

what I want to do is when the time reach 00.00 then send order to buy.

I run it for 1 month ( 2007.01.01 to 2007.01.31) in M1 period. But why the code make 3 order send at 2007.01.04 00:00 ?

2007.04.11 07:54:24 2007.01.04 00:00 GMT00 GBPUSD,M1: open #4 buy 1.00 GBPUSD at 1.9513 sl: 1.9493 tp: 1.9573 ok
2007.04.11 07:54:24 2007.01.04 00:00 GMT00 GBPUSD,M1: open #3 buy 1.00 GBPUSD at 1.9509 sl: 1.9489 tp: 1.9569 ok
2007.04.11 07:54:24 2007.01.04 00:00 GMT00 GBPUSD,M1: open #2 buy 1.00 GBPUSD at 1.9510 sl: 1.9490 tp: 1.9570 ok
2007.04.11 07:54:23 2007.01.03 08:05 Tester: stop loss #1 at 1.9716 (1.9714 / 1.9718)
2007.04.11 07:54:23 2007.01.03 00:00 GMT00 GBPUSD,M1: open #1 buy 1.00 GBPUSD at 1.9736 sl: 1.9716 tp: 1.9796 ok

what’s wrong with my code?

Bye
The problem is that int start() is called with each tick, and there can be multiple calls during that period where minute == 0 so each call will fire an OrderSend until the time increments by one minute. Try using a simple counter as a limiter. Declare the counter as an EA scope variable above int start() so it will retain it's value and then get reset after the trigger minute. I edited your code above to show this.


Last edited by bluto; 04-11-2007 at 03:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 03:55 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 818
wolfe is on a distinguished road
Hello Hatardi,

I have had the same problem. This is the code I use to prevent this from happening.

string time=TimeToStr(TimeCurrent(),TIME_SECONDS;
Print("Current time seconds is ",time);

Then you can decide exactly what time to execute an order.

if (time=="00:00:00")
OrderSend(Symbol(),OP_BUY,lotsize,Ask,slippage,Ask-intStopLoss*Point,Ask+intTakeProfit*Point,"Order", 12345,0,Green);

You can use this to close orders as well at specific times. This works for a 24 hour period, you would have to access date functions for specific days. Hope this helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 04:17 AM
bluto's Avatar
Senior Member
 
Join Date: Sep 2006
Posts: 633
bluto is an unknown quantity at this point
Quote:
Originally Posted by wolfe
Hello Hatardi,

I have had the same problem. This is the code I use to prevent this from happening.

string time=TimeToStr(TimeCurrent(),TIME_SECONDS;
Print("Current time seconds is ",time);

Then you can decide exactly what time to execute an order.

if (time=="00:00:00")
OrderSend(Symbol(),OP_BUY,lotsize,Ask,slippage,Ask-intStopLoss*Point,Ask+intTakeProfit*Point,"Order", 12345,0,Green);

You can use this to close orders as well at specific times. This works for a 24 hour period, you would have to access date functions for specific days. Hope this helps.
That will work as long as you get at least one tick at precisely "00:00:00", otherwise, int start() won't be called and your order won't be placed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 04:42 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 818
wolfe is on a distinguished road
Hello Bluto,

I was wondering about that. I was originally using that with daily bars, I thought there was always a tick at the open of a bar. Is this the case? If so couldn't you set the time for the start of any bar? Such as "01:00:00" for hourly bars, or "01:45:00" for 15 min bars?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 04:55 AM
bluto's Avatar
Senior Member
 
Join Date: Sep 2006
Posts: 633
bluto is an unknown quantity at this point
Quote:
Originally Posted by wolfe
Hello Bluto,

I was wondering about that. I was originally using that with daily bars, I thought there was always a tick at the open of a bar. Is this the case? If so couldn't you set the time for the start of any bar? Such as "01:00:00" for hourly bars, or "01:45:00" for 15 min bars?
I'm not sure about that. If you take a glance at the history data, you'll see cases where an entire minute's worth of data is missing causing a gap...assumedly due to inactivity. I wouldn't trust or depend on broker data feeds to be reliable if I were programming such a precise time driven event as you are. There's lots of ways to skin the cat and do what you're trying to do, but to depend on a tick occuring at a precise time down to the second could be unreliable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 05:14 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 818
wolfe is on a distinguished road
This kind of coding has worked for me in backtesting, however I know backtesting is highly unreliable. I've been working on EA's that rely only on price movements rather than indicators. ALL indicators seem to lag too much to catch
good trades. A lot of the strategies I am testing involve holding a position for an entire bar. I was using this time method of programming to enter and exit trades.
I have no experience with a live account yet, so maybe I do need to find another way to skin the cat. Thanks for your input.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 05:19 AM
bluto's Avatar
Senior Member
 
Join Date: Sep 2006
Posts: 633
bluto is an unknown quantity at this point
Quote:
Originally Posted by wolfe
This kind of coding has worked for me in backtesting, however I know backtesting is highly unreliable. I've been working on EA's that rely only on price movements rather than indicators. ALL indicators seem to lag too much to catch
good trades. A lot of the strategies I am testing involve holding a position for an entire bar. I was using this time method of programming to enter and exit trades.
I have no experience with a live account yet, so maybe I do need to find another way to skin the cat. Thanks for your input.
Keep at it wolfe. You'll be coding up Super-EA's before you know it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 07:44 AM
Junior Member
 
Join Date: Mar 2007
Posts: 10
Hartadi is on a distinguished road
Woow ... thank you very much bluto and wolfe

i have tried the code and it works
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 
Old 04-11-2007, 01:24 PM
Junior Member
 
Join Date: Mar 2007
Posts: 10
Hartadi is on a distinguished road
Hi bluto,

what you said is right. We can not depend on a tick data for my code..

for example there is no order for 2007.01.05 because there is no zero_minute, only zero_hour.

is there any other way to fix my code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
 

Bookmarks
Thread Tools

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
OrderSend and stops Pertti Questions 2 03-12-2007 06:47 AM
EA -- OrderSend issue SaxMan Metatrader 4 2 02-23-2007 04:00 AM
OrderSend question knili Metatrader 4 5 10-03-2006 01:16 AM
OrderSend at a certain time martin80 Metatrader 4 4 09-18-2006 01:47 PM
How many parameters can the OrderSend allow? Aaragorn Questions 6 07-17-2006 11:31 PM


All times are GMT. The time now is 01:46 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.