hello guys please i need your help, i developed this EA that uses CCI and moving average filter it was all good but my problem now is that it opens trade on every bar for example if you place it on a 1H chart it will open trade on every 1 hour. please how do i prevent this from happening. Let me explain the EA, if the CCI crosses the zero level upwards and the price is above the EMA it buys vice versa for sell this is the code.
thanks guys
It might be better to know when there is a new bar, and if not a new bar, don't do anything. Something like this.
void OnTick(){ static datetime oldbartime=Time[0]; if(oldbartime==Time[0])return; // your code // oldbartime=Time[0]; }
But if the EA accesses other periods or symbols off a "host" chart, then there's other stuff you have to do..
- Why are you checking bar zero for a buy but bar one for a sell?
- Add a new bar check, as suggested.
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 - You are looking at a signal. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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 guys please i need your help, i developed this EA that uses CCI and moving average filter it was all good but my problem now is that it opens trade on every bar for example if you place it on a 1H chart it will open trade on every 1 hour. please how do i prevent this from happening. Let me explain the EA, if the CCI crosses the zero level upwards and the price is above the EMA it buys vice versa for sell this is the code.
thanks guys