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

39 lines
580 B
Markdown

# 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
```