Hi All,
I am not very familiar with Empty4 and I am struggling to find a way to execute a function call once we have the start of a new Daily bar. I want to execute it only once.
I can make it inside the start() and check if I have a new day, but would be a ridiculous loop for something that can probably be done in one line, by a more experienced Empty4 programmer.
So, if someone can help with this one I will appreciate.
Thanks,
Erick
Execute a function call only once at the Daily Open
- erickva
- Trader
- Posts: 23
- Joined: Thu Feb 09, 2012 10:46 am
- Location: Sydney - Australia
-
dietcoke
- Trader
- Posts: 162
- Joined: Tue Nov 15, 2011 9:59 pm
Re: Execute a function call only once at the Daily Open
erickva wrote:Hi All,
I am not very familiar with Empty4 and I am struggling to find a way to execute a function call once we have the start of a new Daily bar. I want to execute it only once.
I can make it inside the start() and check if I have a new day, but would be a ridiculous loop for something that can probably be done in one line, by a more experienced Empty4 programmer.
So, if someone can help with this one I will appreciate.
Thanks,
Erick
Eg.
Code: Select all
static int D1Bars;
if (D1Bars != iTime(NULL, PERIOD_D1,0) )
{
... your code here
}if (D1Bars != iTime(NULL, PERIOD_D1,0) )
{
... your code here
}
- erickva
- Trader
- Posts: 23
- Joined: Thu Feb 09, 2012 10:46 am
- Location: Sydney - Australia
Re: Execute a function call only once at the Daily Open
Hi dietcoke,
Thanks very much! Exactly what I was looking for!
Guess I just have to update D1Bars anytime I go through my code, so it will run again next day, if it is inside the start():
D1Bars = iTime(NULL, PERIOD_D1,0);
Thank you!
Erick
Thanks very much! Exactly what I was looking for!
Guess I just have to update D1Bars anytime I go through my code, so it will run again next day, if it is inside the start():
D1Bars = iTime(NULL, PERIOD_D1,0);
Thank you!
Erick
- gaheitman
- Trader
- Posts: 655
- Joined: Tue Nov 15, 2011 10:55 pm
- Location: Richmond, VA, US
Re: Execute a function call only once at the Daily Open
Don't forget to set D1Bars = iTime(NULL, PERIOD_D1,0) within the loop. You'll probably also want to add a test to make sure you aren't starting your EA in the middle of the afternoon.dietcoke wrote:erickva wrote:Hi All,
I am not very familiar with Empty4 and I am struggling to find a way to execute a function call once we have the start of a new Daily bar. I want to execute it only once.
I can make it inside the start() and check if I have a new day, but would be a ridiculous loop for something that can probably be done in one line, by a more experienced Empty4 programmer.
So, if someone can help with this one I will appreciate.
Thanks,
Erick
Eg.
static int D1Bars;Code: Select all
static int D1Bars; if (D1Bars != iTime(NULL, PERIOD_D1,0) ) { ... your code here }
if (D1Bars != iTime(NULL, PERIOD_D1,0) )
{
... your code here
}
What I've done in the past is check that TimeDay(iTime(NULL,PERIOD_M1,0)) != TimeDay(iTime(NULL,PERIOD_M1,1)). This makes sure that we've entered a new day, and will only trigger in the first minute of the day.
George
- erickva
- Trader
- Posts: 23
- Joined: Thu Feb 09, 2012 10:46 am
- Location: Sydney - Australia
Re: Execute a function call only once at the Daily Open
Brilliant George, thanks a lot!gaheitman wrote: Don't forget to set D1Bars = iTime(NULL, PERIOD_D1,0) within the loop. You'll probably also want to add a test to make sure you aren't starting your EA in the middle of the afternoon.
What I've done in the past is check that TimeDay(iTime(NULL,PERIOD_M1,0)) != TimeDay(iTime(NULL,PERIOD_M1,1)). This makes sure that we've entered a new day, and will only trigger in the first minute of the day.
George
