if((BR[1]<=60) && (AR[1]<=60)&& (BR[2]<=60) && (AR[2]<=60)&& (BR[1]>BR[2] && BR[3]>BR[2] && AR[1]>AR[2] && AR[3]>AR[2])&&mark!=1) { SendMail(Symbol() + "5分钟做多预警--MT4邮件提醒" ,Symbol()+" 平台时间 "+TimeToStr(TimeCurrent(),TIME_SECONDS)
You are checking that condition every tick, therefor it sends every tick. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - MQL4 programming forum #1 (2017)
It's OK, we've all been here, myself included! It's a common thing people trip up on as it's not blatantly obvious.
But, yes, as William said, anything that goes into the:
void OnTick(){ }
section will check for the condition(s) on every tick (every time a new price comes in on the server), as long as your condition returns true on each incoming tick, it will fire off an email.
If you want to check the condition on every bar - as opposed to every tick - I use the following;
Hope this helps.
int OnInit(){ datetime BarTime = Time[0]; } void OnTick(){ if(...) if(...) if(...) if(BarTime != Time[0]){ SendMail(...) BarTime = Time[0]; } }
It's OK, we've all been here, myself included! It's a common thing people trip up on as it's not blatantly obvious.
int OnInit(){ datetime BarTime = Time[0]; }
It is no good declaring a variable in OnInit() and then using the variable in OnTick().
Use a static variable in OnTick()
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use