I think I may have found the answer here:
- 2008.04.15
- www.mql5.com
true
good luck
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New
candle - MQL4 programming forum
bool IsNewBar() { static datetime lastBar; datetime currBar = iTime(Symbol(), Period(), 0); if(lastBar != currBar) { lastBar = currBar; return (true); } else { return(false); } } if (IsNewBar()) { //DO THE DAMN THING }
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New
candle - MQL4 programming forum
Thanks for the heads up. I'm worried about missing ticks.
What I'm doing is using the OrderCloseTime function.
This is what I wrote:
if (Ticket > 0 && buyCount == 0 && sellCount == 0) { bool Selected = OrderSelect(Ticket,SELECT_BY_TICKET,MODE_HISTORY); if (Time[0] > OrderCloseTime()) { StartTime = Time[0]; } }
Ticket is the last order ticket number.
So basically if there are no orders open, and the time > last order close time, then the code can continue.
Will I be missing ticks with my approach?
It seems to be working just fine. Although I can't tell if I'm skipping ticks on the new bar.
Frederick Langemark:
bool IsNewBar() { static datetime lastBar; datetime currBar = iTime(Symbol(), Period(), 0); if(lastBar != currBar) { lastBar = currBar; return (true); } else { return(false); } } if (IsNewBar()) { //DO THE DAMN THING }
Thanks!
This works better than what I did.
Thanks!
This works better than what I did.
My pleasure. Simple code, but certainly gets the job done.
If you want to ensure the script doesn't run on the current bar when loaded to the chart, just add IsNewBar(); to OnInit()
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello
I just started creating my own EAs. Very exciting stuff. But I've got a problem.
After I am stopped out, I would like all EA activity to pause until the next bar opens.
What's happening is that once I'm stopped out, my other order is triggering instantaneously. I don't want this to happen.
I don't want to use the Pause function (time based pause), because that is not the correct way to handle this situation. I need to wait until the next bar opens, then the EA should start checking my conditions.
How do I do this?
Can someone help me?