//+------------------------------------------------------------------+ //|
ReversalWithDonchianHTF.mq5 | //| Signal: Engulfing Candle +
Donchian Channel + HTF Color |
//+------------------------------------------------------------------+ #property
indicator_chart_window #property indicator_buffers 2 #property
indicator_color1 Lime #property indicator_color2 Red
input int Donchian_Period = 20; input ENUM_TIMEFRAMES HTF =
PERIOD_H1;
// Indicator buffers double BuySignal[]; double SellSignal[];
int OnInit() { SetIndexBuffer(0, BuySignal, INDICATOR_DATA);
SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 233);
SetIndexBuffer(1, SellSignal, INDICATOR_DATA); SetIndexStyle(1,
DRAW_ARROW); SetIndexArrow(1, 234);
ArraySetAsSeries(BuySignal, true); ArraySetAsSeries(SellSignal, true);
return(INIT_SUCCEEDED); }
int OnCalculate(const int rates_total, const int prev_calculated, const datetime
&time[], const double &open[], const double &high[], const double &low[],
const double &close[], const long &tick_volume[], const long &volume[], const
int &spread[]) { if (rates_total < Donchian_Period + 2) return 0;
for (int i = rates_total - Donchian_Period - 2; i >= 0; i--) { double donHigh =
iHigh(NULL, 0, iHighest(NULL, 0, MODE_HIGH, Donchian_Period, i));
double donLow = iLow(NULL, 0, iLowest(NULL, 0, MODE_LOW,
Donchian_Period, i));
// HTF filter: Use bar index parity as placeholder for color
bool htfBull = iBarShift(NULL, HTF, Time[i]) % 2 == 0;
bool htfBear = !htfBull;
// BUY condition: Engulfing + price near Donchian Low + HTF