//+------------------------------------------------------------------+
//|                                    QQE ADV-v2-Arrows Display.mq4 |
//|                                        Copyright © 2011, tigpips |
//|                                                tigpips@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, tigpips"
#property link      "tigpips@gmail.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red

extern int ArrowOffset = 5;
extern int UpArrowSymbol = 108;
extern int DownArrowSymbol = 108;
extern bool UseBarCount = true;
extern int BarCount=1000;
extern string NOTESETTINGS="=== INDICATOR SETTINGS ===";
extern int    MaxBars = 1000;
extern int    SF=1;
extern int    RSI_Period=8;
extern double DAR_Factor = 3;
string _Sig = "- - - - SIGNAL LINE ALERTS - - - -";
extern bool   Sig_MsgAlerts=true;
extern bool   Sig_SoundAlerts=true;
extern string Sig_SoundAlertFile="alert.wav";
extern bool   Sig_eMailAlerts=false;

     
double RsiMa;
double RsiMa_prev;
double TrLevelSlow;
double TrLevelSlow_prev;

double CrossUp[];
double CrossDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,UpArrowSymbol);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,DownArrowSymbol);
   SetIndexBuffer(0,CrossUp);
   SetIndexBuffer(1,CrossDown);
   
   if(Digits == 5 || Digits == 3)
   {
      ArrowOffset = ArrowOffset * 10;
   }
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit, i, counter;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   
   if(UseBarCount == false)
   {
      limit=Bars-counted_bars;
   }
   else
   {
      if(BarCount >0)
      {
         limit = BarCount;
      }
   }

   for(i = 0; i <= limit; i++) 
   {
      RsiMa = iCustom(NULL, 0, "QQE ADV-v2-wAlerts",NOTESETTINGS,MaxBars,SF,RSI_Period,DAR_Factor,"- - - - SIGNAL LINE ALERTS - - - -",Sig_MsgAlerts,Sig_SoundAlerts,Sig_SoundAlertFile,Sig_eMailAlerts,0,i);
      RsiMa_prev = iCustom(NULL, 0, "QQE ADV-v2-wAlerts",NOTESETTINGS,MaxBars,SF,RSI_Period,DAR_Factor,"- - - - SIGNAL LINE ALERTS - - - -",Sig_MsgAlerts,Sig_SoundAlerts,Sig_SoundAlertFile,Sig_eMailAlerts,0,i+1);
      TrLevelSlow = iCustom(NULL, 0, "QQE ADV-v2-wAlerts",NOTESETTINGS,MaxBars,SF,RSI_Period,DAR_Factor,"- - - - SIGNAL LINE ALERTS - - - -",Sig_MsgAlerts,Sig_SoundAlerts,Sig_SoundAlertFile,Sig_eMailAlerts,1,i);
      TrLevelSlow_prev = iCustom(NULL, 0, "QQE ADV-v2-wAlerts",NOTESETTINGS,MaxBars,SF,RSI_Period,DAR_Factor,"- - - - SIGNAL LINE ALERTS - - - -",Sig_MsgAlerts,Sig_SoundAlerts,Sig_SoundAlertFile,Sig_eMailAlerts,1,i+1);
      
      if(RsiMa_prev < TrLevelSlow_prev && RsiMa > TrLevelSlow)
      {
         CrossUp[i] = Low[i] - (ArrowOffset * Point);
      }
      else if(RsiMa_prev > TrLevelSlow_prev && RsiMa < TrLevelSlow)
      {
         CrossDown[i] = High[i] + (ArrowOffset * Point);
      }
   }
   return(0);
}
//+------------------------------------------------------------------+