Open Close – EA MetaTrader 5

The author of the ideaΒ –Β Ilnaz

mq5 code authorΒ –Β barabashkakvn

The EA analyzes candles #1 and #2.

Example of opening and closing for SELL

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;
Β Β Β Β Β Β Β Β }


https://www.mql5.com/ru/code/23090

  SetSellStopLimitOrder - script MetaTrader 5
πŸ“ˆ ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks