Hi all... I'm a newbee and trying to write an EA. All is going well but I wish to make the EA stay out of trading for 2 periods (candles) after it closes a trade. I've tried using "TimeCurrent()" and adding the seconds of the period but I get a warning of different data types. I seem at a loss as to how to go about it . Any help would be appreciated.
Thanks ron
NextBar = TimeMinute(Time[0]) + 1; << to 2 or 3, you will have a pause of 2-3 minutes.
void OnTick()
{
//---
CheckNextBar(); // starts MAIN
}
....You could use code snippets to suit your purpose
void CheckNextBar() //processing begins at next bar
{
//--initialised to current bar
static int NextBar = TimeMinute(Time[0]); //--note only initialies once
//--up to one minute behind real time
int barTime = TimeMinute(Time[0]);
if(barTime == NextBar)
{
NextBar = TimeMinute(Time[0]) + 1; // add 1 minute and wait
if(NextBar > 59) NextBar = 0; // int Mod(60)
StartMain(); // Start processing
}
//--here is every Tick()
}
Hope you find an answer...
I use this code to manage onTick. I only want to process on each miniute. If you change:
NextBar = TimeMinute(Time[0]) + 1; << to 2 or 3, you will have a pause of 2-3 minutes.
void OnTick()
{
//---
CheckNextBar(); // starts MAIN
}
....You could use code snippets to suit your purpose
void CheckNextBar() //processing begins at next bar
{
//--initialised to current bar
static int NextBar = TimeMinute(Time[0]); //--note only initialies once
//--up to one minute behind real time
int barTime = TimeMinute(Time[0]);
if(barTime == NextBar)
{
NextBar = TimeMinute(Time[0]) + 1; // add 1 minute and wait
if(NextBar > 59) NextBar = 0; // int Mod(60)
StartMain(); // Start processing
}
//--here is every Tick()
}
Hope you find an answer...
Not a good idea if you have a disconnection that misses a bar or more. Check for inequality rather than equality.
I use this code to manage onTick. I only want to process on each miniute. If you change:
NextBar = TimeMinute(Time[0]) + 1; << to 2 or 3, you will have a pause of 2-3 minutes.
void OnTick()
{
//---
CheckNextBar(); // starts MAIN
}
....You could use code snippets to suit your purpose
void CheckNextBar() //processing begins at next bar
{
//--initialised to current bar
static int NextBar = TimeMinute(Time[0]); //--note only initialies once
//--up to one minute behind real time
int barTime = TimeMinute(Time[0]);
if(barTime == NextBar)
{
NextBar = TimeMinute(Time[0]) + 1; // add 1 minute and wait
if(NextBar > 59) NextBar = 0; // int Mod(60)
StartMain(); // Start processing
}
//--here is every Tick()
}
Hope you find an answer...
1) Please use SRC button (or Ctrl-Alt-M) to post code!
2) Time is measured in seconds if you add 1 (or 2,3) you add 1 (or 2,3) seconds!
3) Use either 60 (or 120, 180) or n*60!
4) You may need the function PeriodSeconds(..).
2) Time is measured in seconds if you add 1 (or 2,3) you add 1 (or 2,3) seconds!
3) Use either 60 (or 120, 180) or n*60!
4) You may need the function PeriodSeconds(..).
Hi Carl,
He is using TimeMinute() ... a bit hard to see when not in SRC box (I had to look twice!).
--------------
I use this code to manage onTick. I only want to process on each miniute. If you change:
A simple way to detect a new bar (MT4):
datetime ThisBar = Time[0];
if(LastBar != ThisBar)
{
Print("This is a new bar");
LastBar = ThisBar;
}
Hi all... I'm a newbee and trying to write an EA. All is going well but I wish to make the EA stay out of trading for 2 periods (candles) after it closes a trade. I've tried using "TimeCurrent()" and adding the seconds of the period but I get a warning of different data types. I seem at a loss as to how to go about it . Any help would be appreciated.
Thanks ron
It depends exactly what you want.
Let's say you are trading the H1 chart.
Last order was closed at 13:37
Do you want the next order to be opened on or after 15:00 (so skip the rest of 13:00 candle and the 14:00 candle)
Or do you want the next order to be opened on or after 15:37 (2 hours later)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all... I'm a newbee and trying to write an EA. All is going well but I wish to make the EA stay out of trading for 2 periods (candles) after it closes a trade. I've tried using "TimeCurrent()" and adding the seconds of the period but I get a warning of different data types. I seem at a loss as to how to go about it . Any help would be appreciated.
Thanks ron