int OrdersHistoryTotal( ) Returns the number of closed orders in the account history loaded into the terminal. The history list size depends on the current settings of the "Account history" tab of the terminal
sergery:
the comment is not same as the profit in history list.
why ?
if(OrderType()>2) profit=profit+OrderProfit(); }Do you really expect any pending orders to be in the history and why would they have profit?
#property copyright "test" #property link "http://www.metaquotes.net" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- Comment(""); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); double profit=0; //---- for(int i=OrdersHistoryTotal()-1;i>=0;i--) { if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)) profit=profit+OrderProfit(); } Comment("profit= ",profit); //---- return(0); } //+------------------------------------------------------------------+
the comments do not reflect the pfofit correctly yet
for(int pos=0; pos < OrdersHistoryTotal(); pos++) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL){// Avoid cr/bal https://www.mql5.com/en/forum/126192profit += OrderProfit() + OrderCommission...
Thank you WHRoeder !
Now I got what I need.
if(OrderType()>2)--- this code should be if(OrderType()<=1)
#property copyright "test" #property link "http://www.metaquotes.net" #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- Comment(""); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); double profit=0; //---- for(int i=OrdersHistoryTotal()-1;i>=0;i--) { if(OrderSelect(i, SELECT_BY_POS,MODE_HISTORY)) if(OrderType()<=1) profit=profit+OrderProfit()+OrderSwap()+OrderCommission(); } Comment("profit= ",profit); //---- return(0); } //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
the comment is not same as the profit in history list.
why ?