Files
xMQL4/Docs/Samples/TradeOncePerBar.md
2024-01-25 04:03:36 +03:30

580 B

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.

int BarsCount = 0;
if (Bars>BarsCount) {
    Do the algo and then
    BarsCount = Bars;
}
static datetime prevtime = 0;
if(prevtime == Time[0]) return;
prevtime = Time[0];
Do the algo here after the code
if (Time[0] >= TimeCurrent()) {
    Do the algo here
}
int BarsCount = 0
if (Bars>BarsCount) etc.
static datetime prevtime = Time[0];
if (prevtime == Time[0]) return;
prevtime = Time[0];