MACD and SAR - MetaTrader 5 Expert | MT5 EA Download - MetaTrader 5 Resources

Idea from : Gatiss .
MQL5 code by : Vladimir Karputov .
EA analyzes four parameters :
These parameters are combined in the basic formula for buy and sell signals:
Boolean open_buy = (macd_main_1>macd_signal_1 && macd_signal_1< 0 && sar_1bid()); boolean open_sell = (macd_main_1 0 && sar_1>m_symbol. bid ());
However, you can optimize the values of the symbols < and > in any part of the formula. For this purpose, for each flag < and > , their own variables ( InpMoreLessBuy_1 , InpMoreLessBuy_2 , InpMoreLessBuy_3 , InpMoreLessSell_1 , InpMoreLessSell_2 , and InpMoreLessSell_3 ) are introduced. Using these variables, the basic formula is modified as follows:
Boolean open to buy = ( InpMoreLessBuy_1 ? macd_main_1>macd_signal_1 : macd_main_1InpMoreLessBuy_2? macd_signal_1 < 0 : macd_signal_1 > 0 )&& (! InpMoreLessBuy_3 ? sar_1 < m_symbol.Bid () : sar_1 > m_symbol.Bid ()); Boolean opening sales = (! InpMoreLessSell_1 ? macd_main_1 macd_signal_1) && ( InpMoreLessSell_2 ? MACD_signal_1 > 0 : macd_signal_1 < 0 )&& ( InpMoreLessSell_3 ? sar_1 > m_symbol.Bid (): sar_1 < m_symbol.Bid ());
The EA itself only runs when a new bar appears. When a signal is received, positions opposite to the received signal will be closed.
When optimizing the formula, it is also reasonable to optimize the number of positions:

Attachment download
📎 macd_and_sar.mq5 (34.2 KB)
Source: MQL5 #20827
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •