2 times per 5 minutes or 2 times per 5 minute bar? They are different.
- Latter is easy. Reset on a new M5 bar. Count new orders.
static datetime timeM5=0; static int countM5=0, duration = PeriodSeconds(PERIOD_M5); datetime now = TimeCurrent(), nowM5 = now - now % duration; if(nowM5 != timeM5){ timeM5=nowM5; countM5=0; } if(countM5 >= 2) return; : if(sendOK) ++countM5;
- Former is a bit harder since you have two times. Un-count old orders, count new ones.
static datetime timeM5[2]={0,0}; static int countM5=0, duration = PeriodSeconds(PERIOD_M5); datetime now = TimeCurrent(); if(timeM5[1] != 0 && now - timeM5[1] > duration{ timeM5[1]=0; --countM5; } if(timeM5[0] != 0 && now - timeM5[0] > duration{ timeM5[0]=0; --countM5; } if(countM5 >= 2) return; : if(sendOK){ timeM5[1]=timeM5[0]; timeM5[0]=now; ++countM5; }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear reader,
I want to limit my EA to only trade a maximum of 2 times per 5 minutes but I can't figure out the code. Anyone that can help me out?
Thanks in advance!!