double Lots() { if(OrdersHistoryTotal()>0) { for(int i=OrdersHistoryTotal();i>0;i--) { //Select closed orders starting at the end (most recent first) bool order = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol()) {...} else {...} } // FOR // No history // You know that this is unreachable, the compiler does not. } else {} // end if(OrdersHistoryTotal()>0) ... else ... // You know that this is unreachable the compiler does not. }
If you do this your code simplifies toThe else implies you do the (A) or the else (B) and then continue at C. if(...){ ... return } // A else ... // B // C
There is no else when the previous returns. Simplify if(...){ ... return } // A ... // B
double Lots() { for(int i=OrdersHistoryTotal();i>0;i--) { //Select closed orders starting at the end (most recent first) bool order = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()!=Symbol()) continue; //Check for orders with the same symbol as the chart if(OrderProfit()>0) { //If the order was closed with a profit, increase the amount of lots by 0.01 Print("Previous order closed with profit. Lots increased by 0.01"); return OrderLots()+0.01; } //If the order was closed break even or with a loss Print("Previous order closed without profit. Lots = 0.01"); return 0.01; } // Not my symbol } // FOR //If there is no history at all Print("No history. Lots = 0.01"); return 0.01; }
- Your code stops when you find the first history record that is not _Symbol. The above version doesn't.
- Both versions assume that history is ordered by close time. It isn't always. Don't assume Could EA Really Live By Order_History Alone? - MQL4 forum
- You also have to test order type to ignore deleted pending orders, deposits and withdraws.
- You just check OrderProfit() what about swap and commissions?
- On some brokers (e.g. FXCM) swap and commission is not part of the order but separate entries (type=6) with comment "commission - NN" or "rollover - NNNN" Those must be handled also.
//If there is no history at all Print("No history. Lots = 0.01"); return 0.01; } return(0.01); }
Thank you very much. Thank you also for the explanations, I'll have a look at the problem with sorting orders. Thank very much. The code would be like this (correcting a small mistake)
double Lots() { for(int i=OrdersHistoryTotal();i>0;i--) { //Select closed orders starting at the end (most recent first) bool order = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()!=Symbol()) continue; //Check for orders with the same symbol as the chart if(OrderProfit()>0) { //If the order was closed with a profit, increase the amount of lots by 0.01 Print("Previous order closed with profit. Lots increased by 0.01"); return OrderLots()+0.01; } //If the order was closed break even or with a loss (without a profit) Print("Previous order closed without profit. Lots = 0.01"); return 0.01; } //If there is no history at all Print("No history. Lots = 0.01"); return 0.01; }
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
Hello everyone. I have coded this, and I think that I cover all possibilities. Why is it still saying that this function/method does not return a value?