Summing orderprofit and closing all trades

 

Hi,

I would like to know how I can 1) obtain the total profit on all my open trades, and then 2) say close all orders if this value is above a certain number. Any ideas?

Sp

 
spanero:

I would like to know how I can 1) obtain the total profit on all my open trades, and then 2) say close all orders if this value is above a certain number. Any ideas?

Profit/loss on open trades is simply AccountEquity() minus AccountBalance(). For code to close all open orders, do a search on this forum - that question comes up about once a week. The standard way of doing it is to loop down from OrdersTotal()-1 to zero.

 
jjc:

Profit/loss on open trades is simply AccountEquity() minus AccountBalance(). For code to close all open orders, do a search on this forum - that question comes up about once a week. The standard way of doing it is to loop down from OrdersTotal()-1 to zero.

... and in that loop simply select each order, then match it against a symbol if necessary, then close it.

Doesn't anyone ever BOTHER to search the forums these days?


CB

Reason: