//+------------------------------------------------------------------+ //| Simple Engulfing EA - TEST VERSION | //+------------------------------------------------------------------+ #property strict #include input double Lot = 0.1; input int SL_Point = 100; input int TP_Point = 100; input long Magic = 777; CTrade trade; datetime last_bar = 0; //+------------------------------------------------------------------+ void OnTick() { datetime current_bar = iTime(_Symbol, _Period, 0); if(current_bar == last_bar) return; last_bar = current_bar; if(PositionSelect(_Symbol)) return; double o1 = iOpen(_Symbol, _Period, 1); double c1 = iClose(_Symbol, _Period, 1); double o2 = iOpen(_Symbol, _Period, 2); double c2 = iClose(_Symbol, _Period, 2); // Bullish Engulfing if(c2 < o2 && c1 > o1 && o1 < c2 && c1 > o2) { OpenBuy(); return; } // Bearish Engulfing if(c2 > o2 && c1 < o1 && o1 > c2 && c1 < o2) { OpenSell(); return; } } //+------------------------------------------------------------------+ void OpenBuy() { double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); double sl = ask - SL_Point * _Point; double tp = ask + TP_Point * _Point; trade.SetExpertMagicNumber(Magic); trade.Buy(Lot, _Symbol, ask, sl, tp); } //+------------------------------------------------------------------+ void OpenSell() { double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); double sl = bid + SL_Point * _Point; double tp = bid - TP_Point * _Point; trade.SetExpertMagicNumber(Magic); trade.Sell(Lot, _Symbol, bid, sl, tp); }