# Best Way to Code Trade Once per Bar at Open on MT4 So there are various ways to code an EA to trade once per bar. ```mq4 int BarsCount = 0; if (Bars>BarsCount) { Do the algo and then BarsCount = Bars; } ``` ```mq4 static datetime prevtime = 0; if(prevtime == Time[0]) return; prevtime = Time[0]; Do the algo here after the code ``` ```mq4 if (Time[0] >= TimeCurrent()) { Do the algo here } ``` ```mq4 int BarsCount = 0 if (Bars>BarsCount) etc. ``` ```mq4 static datetime prevtime = Time[0]; if (prevtime == Time[0]) return; prevtime = Time[0]; ``` ```mq4 ```