//+------------------------------------------------------------------+
//|                              ARROW_RSI_CROSS50.mq4                                                             
//+------------------------------------------------------------------+
#property copyright "AHGduP"
#property link      "ARROW_RSI_CROSS-70"

#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Violet //CornflowerBlue
#property indicator_width1 1
#property indicator_color2 CornflowerBlue 
#property indicator_width2 1
#property indicator_color3 Aqua 
#property indicator_width3 1

//====================================================
extern int RSIPeriod = 14;
extern int RSI_OB = 70;
extern int RSI_OS = 30;
//====================================================
extern bool Alarm_On = True;
extern int Arrow_Size = 1;
extern int Arrow_Gap = 10; // Arrow gap in points
extern int CountBars = 96;

double bBuffer1[];
double sBuffer1[];
double Buffer[];

int period;
string TimeFrameStr;

//+------------------------------------------------------------------+
int init()
{
    SetIndexStyle(0, DRAW_ARROW, 0, Arrow_Size);
    SetIndexBuffer(0, bBuffer1);
    SetIndexEmptyValue(0, 0);
    SetIndexArrow(0, 234);

    SetIndexStyle(1, DRAW_ARROW, 0, Arrow_Size);
    SetIndexBuffer(1, sBuffer1);
    SetIndexEmptyValue(1, 0);
    SetIndexArrow(1, 233);

    SetIndexStyle(2, DRAW_NONE);
    SetIndexBuffer(2, Buffer);

    period = Period();
    TimeFrameStr = TimeFrameToString(period);

    string ThisName = "RSI";
    string Text = ThisName;
    Text = Text + "  (" + TimeFrameStr;
    Text = Text + ")";
    Text = Text + "( ";
    Text = Text + " " + RSIPeriod;
    Text = Text + ")  ";
    IndicatorShortName(Text);

    return (0);
}

//+------------------------------------------------------------------+
int deinit()
{
    for (int i = ObjectsTotal() - 1; i >= 0; i--)
        ObjectDelete(ObjectName(i));

    return (0);
}

//+------------------------------------------------------------------+
int start()
{
    int limit, counted_bars;

    counted_bars = IndicatorCounted();
    if (counted_bars > 0) counted_bars--;
    limit = Bars - counted_bars;

    for (int i = 0; i < limit; i++)
    {
        Buffer[i] = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
    }

    for (int i = 0; i < limit; i++)
    {
        if (Buffer[i] < RSI_OB && Buffer[i + 1] > RSI_OB)
        {
            bBuffer1[i] = iHigh(NULL, 0, i) + (Arrow_Gap * Point);
        }

        if (Buffer[i] > RSI_OS && Buffer[i + 1] < RSI_OS)
        {
            sBuffer1[i] = iLow(NULL, 0, i) - (Arrow_Gap * Point);
        }
    }

    return (0);
}

//+------------------------------------------------------------------+
string TimeFrameToString(int tf)
{
    string tfs;
    switch (tf)
    {
        case PERIOD_M1:  tfs = "M1"; break;
        case PERIOD_M5:  tfs = "M5"; break;
        case PERIOD_M15: tfs = "M15"; break;
        case PERIOD_M30: tfs = "M30"; break;
        case PERIOD_H1:  tfs = "H1"; break;
        case PERIOD_H4:  tfs = "H4"; break;
        case PERIOD_D1:  tfs = "D1"; break;
        case PERIOD_W1:  tfs = "W1"; break;
        case PERIOD_MN1: tfs = "MN";
    }
    return (tfs);
}
//+------------------------------------------------------------------+
