Thanks
That works perfectly
I also Made one that counts the orders 
Cheers
Thanks
That works perfectly
I also Made one that counts the orders 
Cheers
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 well
thanks
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
OK it works for the positions opened by your EA
But it does not count the positions that were already opened before
Any solution fro that?
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 again
Something must have gone wrong somewhere while updating your software
NO even the counter for number of orders has stopped working
before it was working fine, it has stopped showing the right count, or rather no count at all just ZERO
on the menu the load a project and new project does not work anymore
when clicked it just keeps running, the busy signal is shown
On my ubuntu box, also chrome, no problems whatsoever.
In case you want to ahve alook
https://fxdreema.com/shared/wevpLlGdc
Tried that, but it keeps counting and counting
sorry
I have been trying to create the LotsCounter using your suggested variable method
I cant seem to figure it out
It just keeps on counting, so the total amount of Lots just keeps going up
Some help please?
Ok
The color coding sounds nice, visual probably easier to understand. But the current numeric is easy enough, especially if changing to colors is creating a lot work for you
Once you understand it, it works you know
Same for the changing "for each trade " type blocks
I prefer to et it up once instead of having to do it over and over again
It is actually quite logical, you select the trades you wnat to work with and then you apply all kind actions after it
I was just thinking that
if I have some variables like : number of buy orders open, total amount of buy lots open
you might even add them under account trade statistics, no need to create another block
just an idea, dont know if I make sense
Sorry, my enthusiasm got the better of me...
When I get back from a holiday I am way too excited to implement my new ideas 
Thanks
I will have to look into how to do more with the variables option, I am missing out on something there
But happy to see the lazy *ss option in a prefigured block as well
Brilliant
Would you mind droppping a message when the block has been added, so I can update my Ea before market open on Sunday night
Cheers
Another Idea: Can you have the variables and constants that are NOT USED AT AL, automatically light up in another color
will be easier to clean up the left overs of multiple iterations
Cheers
If it is at all possible we could have collapsible block areas.
So we can hide an area and all its block inside it, this would allow for a better overview of all blocks on one screen and its interconnections
It is definitely great software, allowing quick and easy EA development
Thanks for the support
Okay thanks for the reply
I have been thinking during my holiday and will make an indicator to solve this issue
Is there an easy way to count the total number of open lots for buy and sell orders
So in short if I have three open buy trades, one of 0.01 lot, one of 1.5lots and one of 2 lots it would return 3.51
I must have overlooked something but I just cant find it
PS after 2 weeks holliday it was refreshing to see some new colors to the website, looking forward to discovering the updates to the software, cheers
OK thanks
So I write my source code and stick it in a custom block and have it execute every tick or bar, correct?
see picture
But how would I then be able to use the value for negative and positive for further manipulations?
Sorry but I am still having a hard time creating custom code blocks...and how to connect and use them afterwards