Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

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

author EAcpu | 2 reads | 0 comments |

MACD and SAR - expert for MetaTrader 5

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_1  bid());
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_1  InpMoreLessBuy_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:

MACD and SAR - expert for MetaTrader 5


Attachment download

📎 macd_and_sar.mq5 (34.2 KB)

Source: MQL5 #20827

Verification code Refresh