#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;
input int RSI_Period = 14;
input double RSI_Overbought = 70;
input double RSI_Oversold = 30;
double BuySignal[];
double SellSignal[];
double DonchianHigh[], DonchianLow[];
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 + RSI_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));
double rsi = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
// HTF filter: ColorBar
color htfColor = iBarShift(NULL, HTF, Time[i]) % 2 == 0 ? clrBlue :
clrRed;
// BUY condition (inside Donchian low + HTF blue + reversal candle + RSI)
if (close[i + 1] < open[i + 1] &&
close[i] > open[i] &&
close[i] > open[i + 1] &&
open[i] < close[i + 1] &&
rsi < RSI_Oversold &&
close[i] <= donLow &&
htfColor == clrBlue)
{
BuySignal[i] = Low[i] - 10 * _Point;
}
else BuySignal[i] = EMPTY_VALUE;
// SELL condition (inside Donchian high + HTF red + reversal candle + RSI)
if (close[i + 1] > open[i + 1] &&
close[i] < open[i] &&
close[i] < open[i + 1] &&
open[i] > close[i + 1] &&
rsi > RSI_Overbought &&
close[i] >= donHigh &&
htfColor == clrRed)
{
SellSignal[i] = High[i] + 10 * _Point;
}
else SellSignal[i] = EMPTY_VALUE;
}
return(rates_total);
}