enggulfing/enggulfing filter H1.mq5

74 lines
1.9 KiB
MQL5
Raw Permalink Normal View History

2026-01-26 01:01:30 +07:00
//+------------------------------------------------------------------+
//| Simple Engulfing EA - TEST VERSION |
//+------------------------------------------------------------------+
#property strict
#include <Trade/Trade.mqh>
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;
//filter H1
double h1_open = iOpen(_Symbol, PERIOD_H1, 1);
double h1_close = iClose(_Symbol, PERIOD_H1, 1);
bool H1_Bullish = h1_close > h1_open;
bool H1_Bearish = h1_close < h1_open;
//deteksi enggulfing
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(H1_Bullish && c2 < o2 && c1 > o1 && o1 < c2 && c1 > o2)
{
OpenBuy();
return;
}
// Bearish Engulfing
if(H1_Bearish && 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);
}