Order Counts longs and shorts NOT working
-
before it was working fine, it has stopped showing the right count, or rather no count at all just ZERO
-
I just tested with an older version of my Ea, and long and short counters work
So I copied the GetStatistics code from the old one to the the new(compiled this morning)
and it works againSomething must have gone wrong somewhere while updating your software
-
This is working for me: https://fxdreema.com/shared/G7P4KlByd
Give me some project that is not working?
-
OK it works for the positions opened by your EA
But it does not count the positions that were already opened beforeAny solution fro that?
-
This is the code that works, which I copy paste over the code in your EA
double GetStatistics(string get="") { if (false) {FeedStatistics();} ////// // main static variables static int start_time=-1; static double initial_money=-1; static double total_net_profit=-1; int shorts_now_count=0; int longs_now_count=0; static int shorts_hist_count=0; static int longs_hist_count=0; static double longs_hist_profit=0; static double longs_hist_loss=0; static double shorts_hist_profit=0; static double shorts_hist_loss=0; static double longs_hist_profit_count=0; static double longs_hist_loss_count=0; static double shorts_hist_profit_count=0; static double shorts_hist_loss_count=0; static double largest_profit_trade=0; static double smallest_profit_trade=0; static double largest_loss_trade=0; static double smallest_loss_trade=0; static double profit_trades_count=0; static double loss_trades_count=0; static double average_profit_trade=0; static double average_loss_trade=0; static int consec_wins=0; static int consec_loss=0; static int last_profit=0; static bool consec_check_started=false; static int max_consec_wins=0; static int max_consec_loss=0; static double avg_consec_wins=0; static double avg_consec_loss=0; static int consec_profits_count=0; static int consec_losses_count=0; static double profit_factor=1; static double gross_profit=0; static double gross_loss=0; static double drawdown_abs=0; static double drawdown_rel=0; static double drawdown_max=0; static double maxpeak=0; static double minpeak=0; static double drawdown_balance_abs=0; static double drawdown_balance_rel=0; static double drawdown_balance_max=0; static double max_balance_peak=0; static double min_balance_peak=0; double profit_factor_live=0; double gross_profit_now=0; double gross_profit_live=0; double gross_loss_now=0; double gross_loss_live=0; ////// ////// // system static variables static int last_checked_trades_ticket=-1; static int last_checked_history_ticket=-1; static int orders_history_total=0; static int orders_history_total_checked=0; static int orders_total=0; double retval=0; ////// int pos=0; if (initial_money==-1) {initial_money=AccountEquity();} if (start_time==-1) {start_time=TimeCurrent();} total_net_profit=AccountEquity()-initial_money; if (OrdersHistoryTotal()!=orders_history_total) { orders_history_total=OrdersHistoryTotal(); for (pos=OrdersHistoryTotal()-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)) { if (OrderOpenTime()>=start_time) { if (orders_history_total>orders_history_total_checked) { orders_history_total_checked++; double PureProfit=OrderProfit()+OrderCommission()+OrderSwap(); if (PureProfit>largest_profit_trade) {largest_profit_trade=PureProfit;} if (PureProfit<largest_loss_trade) {largest_loss_trade=PureProfit;} if (PureProfit>0 && (PureProfit<smallest_profit_trade || smallest_profit_trade==0)) {smallest_profit_trade=PureProfit;} if (PureProfit<0 && (PureProfit>smallest_loss_trade || smallest_loss_trade==0)) {smallest_loss_trade=PureProfit;} if (OrderType()==OP_BUY) {longs_hist_count++;} if (OrderType()==OP_SELL) {shorts_hist_count++;} if (PureProfit>0) { if (OrderType()==OP_BUY) {longs_hist_profit_count++; longs_hist_profit=longs_hist_profit+PureProfit;} if (OrderType()==OP_SELL) {shorts_hist_profit_count++; shorts_hist_profit=shorts_hist_profit+PureProfit;} gross_profit=gross_profit+PureProfit; profit_trades_count++; average_profit_trade=gross_profit/profit_trades_count; if (last_profit>0 || consec_check_started==false) { consec_check_started=true; consec_wins++; } else {consec_wins=1; consec_loss=0; consec_profits_count++;} if (consec_wins>max_consec_wins) {max_consec_wins=consec_wins;} avg_consec_wins=profit_trades_count/(consec_profits_count+1); last_profit=PureProfit; } else if (PureProfit<0) { if (OrderType()==OP_BUY) {longs_hist_loss_count++; longs_hist_loss=longs_hist_loss+PureProfit;} if (OrderType()==OP_SELL) {shorts_hist_loss_count++; shorts_hist_loss=shorts_hist_loss+PureProfit;} gross_loss=gross_loss+PureProfit; loss_trades_count++; average_loss_trade=gross_loss/loss_trades_count; if (last_profit<0 || consec_check_started==false) { consec_check_started=true; consec_loss++; } else { consec_loss=1; consec_wins=0; consec_losses_count++; } if (consec_loss>max_consec_loss) { max_consec_loss=consec_loss; } avg_consec_loss=loss_trades_count/(consec_losses_count+1); last_profit=PureProfit; } } } else {break;} } } } // Equity: Drawdown Maximum && Drawdown Relative if (AccountEquity()>maxpeak) {maxpeak=AccountEquity();} if ((maxpeak-AccountEquity())>drawdown_max) {drawdown_max=(maxpeak-AccountEquity()); drawdown_rel=NormalizeDouble((drawdown_max/maxpeak)*100,2);} // Equity: Drawdown Absolute if ((AccountEquity()<initial_money && (initial_money-AccountEquity())>drawdown_abs) || drawdown_abs==0) {drawdown_abs=(initial_money-AccountEquity());} // Balance: Drawdown Maximum && Drawdown Relative if (AccountBalance()>max_balance_peak) {max_balance_peak=AccountBalance();} if ((max_balance_peak-AccountBalance())>drawdown_balance_max) {drawdown_balance_max=(max_balance_peak-AccountBalance()); drawdown_balance_rel=NormalizeDouble((drawdown_balance_max/max_balance_peak)*100,2);} // Balance: Drawdown Absolute if ((AccountBalance()<initial_money && (initial_money-AccountBalance())>drawdown_balance_abs) || drawdown_balance_abs==0) {drawdown_balance_abs=(initial_money-AccountBalance());} if (get!="") { for (pos=OrdersTotal()-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) { if (OrderType()==OP_BUY) {longs_now_count++;} else if (OrderType()==OP_SELL) {shorts_now_count++;} if (OrderOpenTime()>=start_time) { if (OrderProfit()+OrderCommission()+OrderSwap()>0) { gross_profit_now=gross_profit_now+OrderProfit()+OrderCommission()+OrderSwap(); } else if (OrderProfit()+OrderCommission()+OrderSwap()<0) { gross_loss_now=gross_loss_now+OrderProfit()+OrderCommission()+OrderSwap(); } if (OrderTicket()>last_checked_trades_ticket) { last_checked_trades_ticket=OrderTicket(); } } //else {break;} } } // Profit Factor if (gross_loss<0) { profit_factor=MathAbs(NormalizeDouble(gross_profit/gross_loss,2)); } else { profit_factor=MathAbs(NormalizeDouble(gross_profit,2)); } if (profit_factor==0) {profit_factor=1;} // Gross Profit / Loss (Live) gross_profit_live=gross_profit+gross_profit_now; gross_loss_live=gross_loss+gross_loss_now; // Profit Factor (Live) if ((gross_loss+gross_loss_now)<0) { profit_factor_live=MathAbs(NormalizeDouble(((gross_profit+gross_profit_now)/(gross_loss+gross_loss_now)),2)); } else { profit_factor_live=MathAbs(NormalizeDouble((gross_profit+gross_profit_now),2)); } if (profit_factor_live==0) {profit_factor_live=1;} // Total Trades int longs_total_count =longs_hist_count+longs_now_count; int shorts_total_count =shorts_hist_count+shorts_now_count; int trades_hist_count =longs_hist_count+shorts_hist_count; int trades_now_count =longs_now_count+shorts_now_count; int trades_total_count =longs_total_count+shorts_total_count; if (get=="initial_money") {return(initial_money);} //--- if (get=="profit_factor_history"){return(profit_factor);} if (get=="profit_factor_total") {return(profit_factor_live);} //--- if (get=="gross_profit_history") {return(gross_profit);} if (get=="gross_profit_now") {return(gross_profit_now);} if (get=="gross_profit_total") {return(gross_profit_live);} //--- if (get=="gross_loss_history") {return(gross_loss);} if (get=="gross_loss_now") {return(gross_loss_now);} if (get=="gross_loss_total") {return(gross_loss_live);} //--- if (get=="trades_count_history") {return(trades_hist_count);} if (get=="trades_count_now") {return(trades_now_count);} if (get=="trades_count_total") {return(trades_total_count);} //--- if (get=="longs_count_history") {return(longs_hist_count);} if (get=="longs_count_now") {return(longs_now_count);} if (get=="longs_count_total") {return(longs_total_count);} //--- if (get=="shorts_count_history") {return(shorts_hist_count);} if (get=="shorts_count_now") {return(shorts_now_count);} if (get=="shorts_count_total") {return(shorts_total_count);} //--- if (get=="drawdown_equity_relative") {return(drawdown_rel);} if (get=="drawdown_equity_absolute") {return(drawdown_abs);} if (get=="drawdown_equity_maximal") {return(drawdown_max);} //--- if (get=="drawdown_balance_relative") {return(drawdown_balance_rel);} if (get=="drawdown_balance_absolute") {return(drawdown_balance_abs);} if (get=="drawdown_balance_maximal") {return(drawdown_balance_max);} //--- if (get=="consec_wins_max" || get=="consec_wins_maximum" || get=="consec_wins_maximal") {return(max_consec_wins);} if (get=="consec_wins_avg" || get=="consec_wins_average") {return(avg_consec_wins);} //--- //--- if (get=="consec_losses_max" || get=="consec_losses_maximum" || get=="consec_losses_maximal") {return(max_consec_loss);} if (get=="consec_losses_avg" || get=="consec_losses_average") {return(avg_consec_loss);} } return(-1); }and this is the code in all the EA I compile today and yesterday and your example code as well
double GetStatistics(string get="") { if (false) {FeedStatistics();} ////// // main static variables static int start_time=-1; static double initial_money=-1; static double total_net_profit=-1; int shorts_now_count=0; int longs_now_count=0; static int shorts_hist_count=0; static int longs_hist_count=0; static double longs_hist_profit=0; static double longs_hist_loss=0; static double shorts_hist_profit=0; static double shorts_hist_loss=0; static double longs_hist_profit_count=0; static double longs_hist_loss_count=0; static double shorts_hist_profit_count=0; static double shorts_hist_loss_count=0; static double largest_profit_trade=0; static double smallest_profit_trade=0; static double largest_loss_trade=0; static double smallest_loss_trade=0; static double profit_trades_count=0; static double loss_trades_count=0; static double average_profit_trade=0; static double average_loss_trade=0; static int consec_wins=0; static int consec_loss=0; static int last_profit=0; static bool consec_check_started=false; static int max_consec_wins=0; static int max_consec_loss=0; static double avg_consec_wins=0; static double avg_consec_loss=0; static int consec_profits_count=0; static int consec_losses_count=0; static double profit_factor=1; static double gross_profit=0; static double gross_loss=0; static double drawdown_abs=0; static double drawdown_rel=0; static double drawdown_max=0; static double maxpeak=0; static double minpeak=0; static double drawdown_balance_abs=0; static double drawdown_balance_rel=0; static double drawdown_balance_max=0; static double max_balance_peak=0; static double min_balance_peak=0; double profit_factor_live=0; double gross_profit_now=0; double gross_profit_live=0; double gross_loss_now=0; double gross_loss_live=0; ////// ////// // system static variables static int last_checked_trades_ticket=-1; static int last_checked_history_ticket=-1; static int orders_history_total=0; static int orders_history_total_checked=0; static int orders_total=0; double retval=0; ////// int pos=0; if (initial_money==-1) {initial_money=AccountEquity();} if (start_time==-1) {start_time=TimeCurrent();} total_net_profit=AccountEquity()-initial_money; if (OrdersHistoryTotal()!=orders_history_total) { orders_history_total=OrdersHistoryTotal(); for (pos=OrdersHistoryTotal()-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)) { if (OrderOpenTime()>=start_time) { if (orders_history_total>orders_history_total_checked) { orders_history_total_checked++; double PureProfit=OrderProfit()+OrderCommission()+OrderSwap(); if (PureProfit>largest_profit_trade) {largest_profit_trade=PureProfit;} if (PureProfit<largest_loss_trade) {largest_loss_trade=PureProfit;} if (PureProfit>0 && (PureProfit<smallest_profit_trade || smallest_profit_trade==0)) {smallest_profit_trade=PureProfit;} if (PureProfit<0 && (PureProfit>smallest_loss_trade || smallest_loss_trade==0)) {smallest_loss_trade=PureProfit;} if (OrderType()==OP_BUY) {longs_hist_count++;} if (OrderType()==OP_SELL) {shorts_hist_count++;} if (PureProfit>0) { if (OrderType()==OP_BUY) {longs_hist_profit_count++; longs_hist_profit=longs_hist_profit+PureProfit;} if (OrderType()==OP_SELL) {shorts_hist_profit_count++; shorts_hist_profit=shorts_hist_profit+PureProfit;} gross_profit=gross_profit+PureProfit; profit_trades_count++; average_profit_trade=gross_profit/profit_trades_count; if (last_profit>0 || consec_check_started==false) { consec_check_started=true; consec_wins++; } else {consec_wins=1; consec_loss=0; consec_profits_count++;} if (consec_wins>max_consec_wins) {max_consec_wins=consec_wins;} avg_consec_wins=profit_trades_count/(consec_profits_count+1); last_profit=PureProfit; } else if (PureProfit<0) { if (OrderType()==OP_BUY) {longs_hist_loss_count++; longs_hist_loss=longs_hist_loss+PureProfit;} if (OrderType()==OP_SELL) {shorts_hist_loss_count++; shorts_hist_loss=shorts_hist_loss+PureProfit;} gross_loss=gross_loss+PureProfit; loss_trades_count++; average_loss_trade=gross_loss/loss_trades_count; if (last_profit<0 || consec_check_started==false) { consec_check_started=true; consec_loss++; } else { consec_loss=1; consec_wins=0; consec_losses_count++; } if (consec_loss>max_consec_loss) { max_consec_loss=consec_loss; } avg_consec_loss=loss_trades_count/(consec_losses_count+1); last_profit=PureProfit; } } } else {break;} } } } // Equity: Drawdown Maximum && Drawdown Relative if (AccountEquity()>maxpeak) {maxpeak=AccountEquity();} if ((maxpeak-AccountEquity())>drawdown_max) {drawdown_max=(maxpeak-AccountEquity()); drawdown_rel=NormalizeDouble((drawdown_max/maxpeak)*100,2);} // Equity: Drawdown Absolute if ((AccountEquity()<initial_money && (initial_money-AccountEquity())>drawdown_abs) || drawdown_abs==0) {drawdown_abs=(initial_money-AccountEquity());} // Balance: Drawdown Maximum && Drawdown Relative if (AccountBalance()>max_balance_peak) {max_balance_peak=AccountBalance();} if ((max_balance_peak-AccountBalance())>drawdown_balance_max) {drawdown_balance_max=(max_balance_peak-AccountBalance()); drawdown_balance_rel=NormalizeDouble((drawdown_balance_max/max_balance_peak)*100,2);} // Balance: Drawdown Absolute if ((AccountBalance()<initial_money && (initial_money-AccountBalance())>drawdown_balance_abs) || drawdown_balance_abs==0) {drawdown_balance_abs=(initial_money-AccountBalance());} if (get!="") { for (pos=OrdersTotal()-1; pos>=0; pos--) { if (OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) { if (OrderOpenTime()>=start_time) { if (OrderType()==OP_BUY) {longs_now_count++;} else if (OrderType()==OP_SELL) {shorts_now_count++;} if (OrderProfit()+OrderCommission()+OrderSwap()>0) { gross_profit_now=gross_profit_now+OrderProfit()+OrderCommission()+OrderSwap(); } else if (OrderProfit()+OrderCommission()+OrderSwap()<0) { gross_loss_now=gross_loss_now+OrderProfit()+OrderCommission()+OrderSwap(); } if (OrderTicket()>last_checked_trades_ticket) { last_checked_trades_ticket=OrderTicket(); } } else {break;} } } // Profit Factor if (gross_loss<0) { profit_factor=MathAbs(NormalizeDouble(gross_profit/gross_loss,2)); } else { profit_factor=MathAbs(NormalizeDouble(gross_profit,2)); } if (profit_factor==0) {profit_factor=1;} // Gross Profit / Loss (Live) gross_profit_live=gross_profit+gross_profit_now; gross_loss_live=gross_loss+gross_loss_now; // Profit Factor (Live) if ((gross_loss+gross_loss_now)<0) { profit_factor_live=MathAbs(NormalizeDouble(((gross_profit+gross_profit_now)/(gross_loss+gross_loss_now)),2)); } else { profit_factor_live=MathAbs(NormalizeDouble((gross_profit+gross_profit_now),2)); } if (profit_factor_live==0) {profit_factor_live=1;} // Total Trades int longs_total_count =longs_hist_count+longs_now_count; int shorts_total_count =shorts_hist_count+shorts_now_count; int trades_hist_count =longs_hist_count+shorts_hist_count; int trades_now_count =longs_now_count+shorts_now_count; int trades_total_count =longs_total_count+shorts_total_count; if (get=="initial_money") {return(initial_money);} //--- if (get=="profit_factor_history"){return(profit_factor);} if (get=="profit_factor_total") {return(profit_factor_live);} //--- if (get=="gross_profit_history") {return(gross_profit);} if (get=="gross_profit_now") {return(gross_profit_now);} if (get=="gross_profit_total") {return(gross_profit_live);} //--- if (get=="gross_loss_history") {return(gross_loss);} if (get=="gross_loss_now") {return(gross_loss_now);} if (get=="gross_loss_total") {return(gross_loss_live);} //--- if (get=="trades_count_history") {return(trades_hist_count);} if (get=="trades_count_now") {return(trades_now_count);} if (get=="trades_count_total") {return(trades_total_count);} //--- if (get=="longs_count_history") {return(longs_hist_count);} if (get=="longs_count_now") {return(longs_now_count);} if (get=="longs_count_total") {return(longs_total_count);} //--- if (get=="shorts_count_history") {return(shorts_hist_count);} if (get=="shorts_count_now") {return(shorts_now_count);} if (get=="shorts_count_total") {return(shorts_total_count);} //--- if (get=="drawdown_equity_relative") {return(drawdown_rel);} if (get=="drawdown_equity_absolute") {return(drawdown_abs);} if (get=="drawdown_equity_maximal") {return(drawdown_max);} //--- if (get=="drawdown_balance_relative") {return(drawdown_balance_rel);} if (get=="drawdown_balance_absolute") {return(drawdown_balance_abs);} if (get=="drawdown_balance_maximal") {return(drawdown_balance_max);} //--- if (get=="consec_wins_max" || get=="consec_wins_maximum" || get=="consec_wins_maximal") {return(max_consec_wins);} if (get=="consec_wins_avg" || get=="consec_wins_average") {return(avg_consec_wins);} //--- //--- if (get=="consec_losses_max" || get=="consec_losses_maximum" || get=="consec_losses_maximal") {return(max_consec_loss);} if (get=="consec_losses_avg" || get=="consec_losses_average") {return(avg_consec_loss);} } return(-1); }hope this helps
-
Here is the difference between both codes: http://prntscr.com/894wyt
http://i.imgur.com/bMd5fno.pngstart_time is the time when the EA started to work and obviously longs count and shorts count is calculated after that time now. I remember that I did this modification, but I don't remember why. It was probably after someone's report for some problem.
Normally when I use the start time of the EA, this is to prevent some unexpected bad situations when the EA is reloaded. I don't really remember what was the case for these Trade statistics.
-
OK good we found the reason
so do we go back to the old code? or do you stay with new code?I prefer it gives me a count of all existing open trades wether placed by EA or manual, befroe or after the EA was attached
and I know I repeat myself I would greatly appreciate if we had an option to show open lots as wellthanks
-
Ok, I did that. I'm not sure for the indicator thing. There is a built-in custom indicator for this anyway - iExposure