Author: Mohammad Soubra
If you’re diving into automated trading, here’s a straightforward example using the SAR (Stop And Reverse) indicator. Keep in mind, this isn’t a money-making EA; it’s more of a foundational template for coders looking to get their feet wet in the world of algorithmic trading.
Understanding Advanced Money Management:
//+------------------------------------------------------------------+ // Expert AdvancedMM function //+------------------------------------------------------------------+ double AdvancedMM() { int i; double AdvancedMMLots=0; bool profit1=false; int SystemHistoryOrders=0; for(i=0;i<OrdersHistoryTotal();i++) { bool ordsel = OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); if(OrderMagicNumber()==MagicNumber) SystemHistoryOrders++; } bool profit2=false; int LO=0; if(SystemHistoryOrders<2) return(Lots); for(i=OrdersHistoryTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) if(OrderMagicNumber()==MagicNumber) { if(OrderProfit()>=0 && profit1) return(Lots); if(LO==0) { if(OrderProfit()>=0) profit1=true; if(OrderProfit()<0) return(OrderLots()); LO=1; } if(OrderProfit()>=0 && profit2) return(AdvancedMMLots); if(OrderProfit()>=0) profit2=true; if(OrderProfit()<0) { profit1=false; profit2=false; AdvancedMMLots+=OrderLots(); } } } return(AdvancedMMLots); }

Pro Tip: Always trade responsibly and stay informed about your strategies!
- Take care and happy trading!
Related Posts
- Harnessing MQL5 Wizard for Trading Signals: 3 Black Crows & 3 White Soldiers with MFI
- Leveraging MQL5 Wizard: Crafting Trade Signals with Meeting Lines and Stochastic
- Creating a Stochastic-Based EA for Hammer and Hanging Man Patterns in MetaTrader 5
- Creating an Expert Advisor for Dark Cloud Cover and Piercing Line Patterns with CCI Confirmation
- Mastering Trading Signals with MQL5 Wizard: Bullish and Bearish Engulfing Strategies