
#property indicator_chart_window
#property strict
#property indicator_buffers 2
#property indicator_color1 clrLime
#property indicator_color2 clrRed

extern string Indicator1 = "Indicator1";
extern int BuyBuffer1 = 0;
extern int SellBuffer1 = 1;

extern string Indicator2 = "Indicator2";
extern int BuyBuffer2 = 0;
extern int SellBuffer2 = 1;

extern string Indicator3 = "Indicator3";
extern int BuyBuffer3 = 0;
extern int SellBuffer3 = 1;

extern string Indicator4 = "Indicator4";
extern int BuyBuffer4 = 0;
extern int SellBuffer4 = 1;

extern string Indicator5 = "Indicator5";
extern int BuyBuffer5 = 0;
extern int SellBuffer5 = 1;

extern int ArrowShift = 10;
extern bool SignalOnClosedCandle = true;

double BuyArrows[];
double SellArrows[];

int OnInit()
{
    SetIndexBuffer(0, BuyArrows);
    SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 2);
    SetIndexArrow(0, 233);
    SetIndexLabel(0, "Buy Signal");

    SetIndexBuffer(1, SellArrows);
    SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 2);
    SetIndexArrow(1, 234);
    SetIndexLabel(1, "Sell Signal");

    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[])
{
    int counted_bars = prev_calculated > 0 ? prev_calculated - 1 : 0;

    for (int i = rates_total - counted_bars - 2; i >= 0; i--)
    {
        int idx = SignalOnClosedCandle ? i + 1 : i;
        if (idx >= rates_total - 1) continue;

        double b1 = iCustom(NULL, 0, Indicator1, BuyBuffer1, idx);
        double s1 = iCustom(NULL, 0, Indicator1, SellBuffer1, idx);
        double b2 = iCustom(NULL, 0, Indicator2, BuyBuffer2, idx);
        double s2 = iCustom(NULL, 0, Indicator2, SellBuffer2, idx);
        double b3 = iCustom(NULL, 0, Indicator3, BuyBuffer3, idx);
        double s3 = iCustom(NULL, 0, Indicator3, SellBuffer3, idx);
        double b4 = iCustom(NULL, 0, Indicator4, BuyBuffer4, idx);
        double s4 = iCustom(NULL, 0, Indicator4, SellBuffer4, idx);
        double b5 = iCustom(NULL, 0, Indicator5, BuyBuffer5, idx);
        double s5 = iCustom(NULL, 0, Indicator5, SellBuffer5, idx);

        BuyArrows[i] = EMPTY_VALUE;
        SellArrows[i] = EMPTY_VALUE;

        if (!IsEmpty(b1) && !IsEmpty(b2) && !IsEmpty(b3) && !IsEmpty(b4) && !IsEmpty(b5)) {
            BuyArrows[i] = Low[i] - (ArrowShift * Point);
            if (i == 0) Alert("BT Combiner: Buy Signal");
        }

        if (!IsEmpty(s1) && !IsEmpty(s2) && !IsEmpty(s3) && !IsEmpty(s4) && !IsEmpty(s5)) {
            SellArrows[i] = High[i] + (ArrowShift * Point);
            if (i == 0) Alert("BT Combiner: Sell Signal");
        }
    }

    return(rates_total);
}

bool IsEmpty(double val)
{
    return (val == EMPTY_VALUE || val == 0.0 || val == WRONG_VALUE);
}
