# Limit trades in a certain time frame

5536

I want to limit trades within a day to x number

is this the best way to do? by checking the history?

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
{
//---

int      Cnt;
ulong    Ticket;
long     EntryType;
datetime DT[1];

Cnt = 0;

if(CopyTime(_Symbol, TimeFrame, 0, 1, DT) <= 0)
{
Cnt = -1;
}
else
{
HistorySelect(DT[0], TimeCurrent());

for(int i = HistoryDealsTotal() - 1; i >= 0; i--)
{
Ticket    = HistoryDealGetTicket(i);
EntryType = HistoryDealGetInteger(Ticket, DEAL_ENTRY);

if(EntryType == DEAL_ENTRY_IN)
{
if(_Symbol == HistoryDealGetString(Ticket, DEAL_SYMBOL))
{
Cnt++;
}
}
}
}

//---
return(Cnt);
}
Moderator
33777

Dua Yong Rew:

I want to limit trades within a day to x number

is this the best way to do? by checking the history?

It's the more reliable way. Any problem with this code ?
5536

Alain Verleyen:
It's the more reliable way. Any problem with this code ?
no problem but its kinda slow. so searching for more opinions :)
Moderator
33777

Dua Yong Rew:
no problem but its kinda slow. so searching for more opinions :)

Don't execute such function on each tick, but only when needed.

By the way, you are counting deals, it can be different from the number of trades depending of what you call a trade.

5536

Alain Verleyen:

Don't execute such function on each tick, but only when needed.

By the way, you are counting deals, it can be different from the number of trades depending of what you call a trade.

that's an interesting idea, so I just need to reset the counter at the start of the day.

How can I restart at start of the day?

Moderator
33777

Dua Yong Rew:

that's an interesting idea, so I just need to reset the counter at the start of the day.

How can I restart at start of the day?

By doing some efforts
5536

Alain Verleyen:
By doing some efforts
Im thinking of newbar. any ideas?