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.
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.
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.
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.
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 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.
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.
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.