double SumTotal() { double achieve = 0; for(int i = OrdersHistoryTotal()-1; i >= 0; i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue; if(OrderMagicNumber()!=iMagicNumber) continue; if(OrderSymbol()!=Symbol()) continue; if(OrderType() != OP_BUY && OrderType() != OP_SELL) continue; double commission = OrderCommission(), profitloss = OrderProfit(), swap = OrderSwap(), orderProfit= commission + profitloss + swap; achieve += orderProfit; Print("Commission for the order is ",commission); Print("Swap for the order is ",swap); Print("Profit for the order is ",profitloss); Print("OrderProfit for the order is ",orderProfit); } return(achieve); }
Konstantin Nikitin:
Thank You for your help Nikitin.
But it still is not counting the whole thing. It is only giving out the last loss.
deedeed :
Summarize all profits Thank You for your help Nikitin.
But it still is not counting the whole thing. It is only giving out the last loss.
achieve += orderProfit;
And come back
return(achieve);
deedeed:
Hi
I am trying to write a code which will give me a sum total of back to back losses including commissions.
I am able to retrieve the last loss and commissions but have no clue as to how to retrieve the sum total of losses when it happens in a row.
Here's what I am talking about. This is the list of my profit loss as an example.
Profit , Loss , Loss2 , Profit2, Loss3, Loss4, Loss5.
I am able to retrieve the details of Loss5.
However, I am looking for a sum total of Loss3+Loss4+Loss5.
Here is the code I have so far. Please help.
Try this:
double SumTotal(const int MN) { double achieve=0.0; for(int i=(OrdersHistoryTotal()-1); i>=0; i --) { if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) { printf("OrderSelect failed with error #%d",GetLastError()); continue; } if(OrderMagicNumber()==MN && OrderSymbol()==_Symbol && (OrderType()==OP_BUY || OrderType()==OP_SELL)) { printf("Magic number: %d",MN); double profitloss=OrderProfit(); double commission=OrderCommission(); double swap=OrderSwap(); double sum=profitloss+commission+swap; if(sum<0.0) { Print("Profit for the order is ",profitloss); Print("Commission for the order is ",commission); Print("Swap for the order is ",swap); achieve+=sum; } else return(achieve); } } return(achieve); }
If the last order is profit then it returns zero otherwise it returns sum of negative profits in the row.
Konstantin Nikitin:
Summarize all profits
Summarize all profits
And come back
When there are two or more consecutive losses.. it is only picking up the last loss. Just tested it. Should I send you the screenshots?
Regards
double SumTotal(const int t=0) { // t = 0 all orders, t <0 losing orders, t> 0 profitable orders double achieve = 0; for(int i = OrdersHistoryTotal()-1; i >= 0; i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue; if(OrderMagicNumber()!=MagicNumber) continue; if(OrderSymbol()!=Symbol()) continue; if(OrderType() != OP_BUY && OrderType() != OP_SELL) continue; double commission = OrderCommission(), profitloss = OrderProfit(), swap = OrderSwap(), orderProfit= commission + profitloss + swap; Print("Commission for the order is ",commission); Print("Swap for the order is ",swap); Print("Profit for the order is ",profitloss); Print("OrderProfit for the order is ",orderProfit); achieve += (t==0 ? orderProfit : (t>0 && orderProfit>0) ? orderProfit : (t<0 && orderProfit<0) ? orderProfit : 0); } return(achieve); }
deedeed: When there are two or more consecutive losses.. it is only picking up the last loss.
Do not assume history is ordered by date, it's not.
Could EA Really Live By Order_History Alone? (ubzen) - MQL4 and MetaTrader 4 - MQL4 programming forum
Count how many lost orders from the last profit order - MQL4 and MetaTrader 4 - MQL4 programming forum
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
Hi
I am trying to write a code which will give me a sum total of back to back losses including commissions.
Here is the code I have so far. Please help.