Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Expert Advisor | Open Close

The author of the idea - Ilnaz

mq5 code author - barabashkakvn

The EA analyzes candles #1 and #2.

Example of opening and closing for SELL

MetaTrader Experts, Indicators, Scripts and Libraries

Open conditions - there is no a single position on the market

      //--- buy        if((rates[1].open>rates[2].open) && (rates[1].close<rates[2].close))          {           double lot=TradeSizeOptimized();           OpenBuy(lot,0.0,0.0);           return;          }        //--- sell        if((rates[1].open<rates[2].open) && (rates[1].close>rates[2].close))          {           double lot=TradeSizeOptimized();           OpenSell(lot,0.0,0.0);           return;          }  

If there is an open position, check the close condition

      if(rates[1].open<rates[2].open && (rates[1].close<rates[2].close))          {           ClosePositions(POSITION_TYPE_BUY);           return;          }        if(rates[1].open>rates[2].open && (rates[1].close>rates[2].close))          {           ClosePositions(POSITION_TYPE_SELL);           return;          }  
23090