Need Help For "Max Number of Trades Per Day" Code.

 

Hi everybody doing good work here, I am new here and also a trainee programmer.

Pls I need a perfect code to limit the number of trades my EA will make in a day.

Hope experienced people here will help me out.

Thanks.

 
fxtutor:

Hi everybody doing good work here, I am new here and also a trainee programmer.

Pls I need a perfect code to limit the number of trades my EA will make in a day.

Hope experienced people here will help me out.

Thanks.

Can you post what you've come up with so far please?

 
cloudbreaker wrote >>

Can you post what you've come up with so far please?

If you want to limit the number of trades your EA can take you first need to calculate the number of trades that have been taken for the day so far and then allow your ea to open the new order if the total number of trades taken is less than your limit.

The code below will calculate the number of trades taken by referring to the trade history

//Test how many trades have been taken for the day
double LongTrades,ShortTrades;
int trades_total=HistoryTotal();
for(int T=0; T<trades_total; T++)
{
if(OrderSelect(T,SELECT_BY_POS,MODE_HISTORY))
int type=OrderType();
{
if ( OrderMagicNumber() == _MagicNumber )
{
//Add all long trades for the today
if(type==OP_BUY)
{
//test if the order is today's order
if((TimeDayOfYear(OrderOpenTime())==TimeDayOfYear(TimeCurrent())) &&(TimeYear(OrderOpenTime())==TimeYear(TimeCurrent()))) LongTrades++;
//Print ("CurrentDay : ", TimeDayOfYear(TimeCurrent()));
}
//Add all short trades for the today
if(type==OP_SELL)
{
//test if the order is today's order
if((TimeDayOfYear(OrderOpenTime())==TimeDayOfYear(TimeCurrent())) &&(TimeYear(OrderOpenTime())==TimeYear(TimeCurrent()))) ShortTrades++;

}
}
}
}
double totaldaystrades;

totaldaystrades = LongTrades + ShortTrades;
//Print ("totaldaystrades : ", totaldaystrades);