The following code was provided courtesy of sangmane. It accummulates profit for a user defined 24 hr period:
I have attempted to alter this code, as follows, to count the # of trades in a user defined 24 hr period. This works fine the first 24 hrs, counts the trades, clears the count to zero at the start of the next 24 hr period but does not accumulate a count after that:
I can not for the life of me see what's wrong. Any help would be greatly appreciated!
Inserted Code
extern int CumProfitStart = 00;
Inserted Code
if(AllowTrade == True) TradeTaken = "No ("+DoubleToStr(cummulativeProfit(CumProfitStart),2)+")";
Inserted Code
[color=black]double[/color] cummulativeProfit(int startHour) { int totalHistory = OrdersHistoryTotal(); //get number of history orders in orders' pool double profit = 0; //set initial profit = 0 datetime thistime = TimeCurrent(); //now use TimeCurrent() instead of Time[0], to avoid logic flaw when run on 24 Hr cycle datetime startTime = StrToTime(TimeToStr(thistime,TIME_DATE)+" "+startHour+":00"); //construct startTime based on startHour and current day, month, year if(thistime<startTime) startTime = startTime-24*60*60; //check if current time is behind startTime, subtract startTime by 24 hours for(int i = totalHistory-1; i>=0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_HISTORY); //check if order's close time behind starttime, exit loop if(OrderCloseTime() < startTime) break; profit += OrderProfit(); } return(NormalizeDouble(profit,2)); //accumulate profit }
I have attempted to alter this code, as follows, to count the # of trades in a user defined 24 hr period. This works fine the first 24 hrs, counts the trades, clears the count to zero at the start of the next 24 hr period but does not accumulate a count after that:
Inserted Code
extern int CountTradesStart = 00;
Inserted Code
Comment...... # Trades Today = ", cummulativeTradeCount(CountTradesStart), "\n",
Inserted Code
[color=red]int[/color] cummulativeTradeCount(int startHour) { int totalHistory = OrdersHistoryTotal(); //get number of history orders in orders' pool int TradeCount = 0; //set initial count = 0 datetime thistime = TimeCurrent(); //now use TimeCurrent() instead of Time[0], to avoid logic flaw when run on 24 Hr cycle datetime startTime = StrToTime(TimeToStr(thistime,TIME_DATE)+" "+startHour+":00"); //construct startTime based on startHour and current day, month, year if(thistime<startTime) startTime = startTime-24*60*60; //check if current time is behind startTime, subtract startTime by 24 hours [color=red]for(int k = totalHistory-1; k>=0; k--) [/color] { OrderSelect(k, SELECT_BY_POS, MODE_HISTORY); //check if order's close time behind starttime, exit loop if(OrderCloseTime() < startTime) break; if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) TradeCount++; } return(TradeCount); // }
I can not for the life of me see what's wrong. Any help would be greatly appreciated!