Here's the MQL5 indicator code that fulfills your requirements:
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Orange
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
extern int MA1_Period = 3;
extern int MA2_Period = 60;
extern int MA3_Period = 300;
extern int Max_MA_Range = 10;
extern color Box_Color = MediumPurple;
extern color Text_Color = White;
double ma1Buffer[];
double ma2Buffer[];
double ma3Buffer[];
double sortedMAs[];
int rangeStartBar = -1;
int rangeEndBar = -1;
string breakoutText = "";
void 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[])
{
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
int ma1Handle = iMA(NULL, 0, MA1_Period, 0, MODE_EMA, PRICE_CLOSE);
int ma2Handle = iMA(NULL, 0, MA2_Period, 0, MODE_EMA, PRICE_CLOSE);
int ma3Handle = iMA(NULL, 0, MA3_Period, 0, MODE_EMA, PRICE_CLOSE);
ArrayResize(ma1Buffer, rates_total);
ArrayResize(ma2Buffer, rates_total);
ArrayResize(ma3Buffer, rates_total);
int copied = CopyBuffer(ma1Handle, 0, 0, rates_total, ma1Buffer);
if (copied == -1)
return;
copied = CopyBuffer(ma2Handle, 0, 0, rates_total, ma2Buffer);
if (copied == -1)
return;
copied = CopyBuffer(ma3Handle, 0, 0, rates_total, ma3Buffer);
if (copied == -1)
return;
ArrayResize(sortedMAs, copied);
ArraySetAsSeries(sortedMAs, true);
ArrayCopy(ma1Buffer, sortedMAs, copied);
ArrayCopy(ma2Buffer, sortedMAs, copied, copied);
ArrayCopy(ma3Buffer, sortedMAs, copied, copied * 2);
ArraySort(sortedMAs, WHOLE_ARRAY, 0, MODE_DESCEND);
double priceDifference = sortedMAs[0] - sortedMAs[copied - 1];
if (priceDifference <= Max_MA_Range)
{
if (rangeStartBar == -1)
rangeStartBar = prev_calculated;
rangeEndBar = rates_total - 1;
ObjectCreate(0, "RangeBox", OBJ_RECTANGLE_LABEL, rangeStartBar, normalizedDouble(sortedMAs[0], Digits), rangeEndBar, normalizedDouble(sortedMAs[copied - 1], Digits));
ObjectSetInteger(0, "RangeBox", OBJPROP_COLOR, Box_Color);
ObjectSetText(0, "BREAKOUT", 20, "Arial", Text_Color);
if (prev_calculated != 0 && ObjectGet("RangeBox") != 0)
ObjectMove(0, "RangeBox", rangeStartBar, normalizedDouble(sortedMAs[0], Digits));
}
else
{
if (ObjectGet("RangeBox") != 0)
ObjectDelete(0, "RangeBox");
rangeStartBar = -1;
rangeEndBar = -1;
}
if (rangeStartBar != -1 && rangeEndBar != -1 && close[rates_total - 1] < sortedMAs[0] && close[rates_total - 2] >= sortedMAs[0])
{
// Notify breakout
}
SetIndexBuffer(0, ma1Buffer);
SetIndexBuffer(1, ma2Buffer);
SetIndexBuffer(2, ma3Buffer);
}
Please note that the breakout notification part is not implemented in the code as it requires external libraries or custom coding logic specific to your notification system. You'll need to modify the code to suit your specific notification requirements.