stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Limit the number of trades per day.
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=367
Page 1 of 1
Author:  MrLong [ Tue Feb 21, 2012 8:10 am ]
Post subject:  Limit the number of trades per day.

This code may be of some use to someone, this is how I govern the number of trades my EA can take in
a specific timeframe.

extern int TF_For_trades = 1440;// THE DAILY TRADES SETTING
extern int daily_trades = 1;


//+------------------------------------------------------------------+
//| Checks number order for the |
//+------------------------------------------------------------------+
int CheckTodaysOrders(){
int TodaysOrders = 0;
for(int i = OrdersTotal()-1; i >=0; i--){
OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && (OrderOpenTime() >= iTime(Symbol(), TF_For_trades, 0))) {
TodaysOrders += 1;
}}

for(i = OrdersHistoryTotal()-1; i >=0; i--){
OrderSelect(i, SELECT_BY_POS,MODE_HISTORY);
if( OrderSymbol()==Symbol() && (OrderOpenTime() >= iTime(Symbol(), TF_For_trades, 0))) {
TodaysOrders += 1;
}}
return(TodaysOrders);
}


and I just call:

if (CheckTodaysOrders() >= daily_trades) SendShort = false;
if (CheckTodaysOrders() >= daily_trades) SendLong = false;

Best Regards
Andy
All times are UTC Page 1 of 1