//+------------------------------------------------------------------+
//|                                     Forex scalping indicator.mq4 |
//|                                 "https://assarv10ea.blogspot.com"|
//*                         "Forex scalping indicator Trend Strategy"|
//+------------------------------------------------------------------+
                                                                                            /*******************************   
                                                                                            ***        NO REPINTA        ***
                                                                                            ********************************/       
#property strict
#property indicator_separate_window
#property indicator_buffers 11
#property indicator_minimum -1
#property indicator_maximum 101

#property indicator_color1 Sienna
#property indicator_style1 0
#property indicator_width1 1

#property indicator_color1 clrNONE
#property indicator_color2 clrNONE
#property indicator_color3 clrNONE
#property indicator_color4 clrNONE


#property indicator_color5 Blue
#property indicator_style5 0
#property indicator_width5 2

#property indicator_color6 Green
#property indicator_style6 0
#property indicator_width6 2

#property indicator_color7 Black
#property indicator_style7 0
#property indicator_width7 2

#property indicator_level1 95
#property indicator_level2 5

#property indicator_levelstyle 2
#property indicator_levelcolor DarkSlateGray



extern int MaxBarsToCount           = 21000;
extern ENUM_TIMEFRAMES   TF          = 0;
extern int RSI1_Period     = 200;            
extern int MA1_Period      = 500;    
extern int RSI11_Period    = 200; 
extern int MA11_Period     = 500;

extern int MA1_Mode         = 0;
extern int MA11_Mode        = 1; 

 int MA1_Price  = 0;         int MA11_Price  = 0;


extern string Linea2 = "Ajustes Linea más rápida";         /* 11 22  y 7 11 es bueno  **   7 22 y 7 33  **  3 100  y  7 11  y 5 3*/
extern int RSI2_Period  = 7;            
extern int MA2_Period   = 22;      
extern int RSI22_Period = 7; 
extern int MA22_Period  = 33;
extern int RSI222_Period = 5; 
extern int MA222_Period  = 3;
          
extern int MA2_Mode    = 0;
extern int MA22_Mode   = 1;
extern int MA222_Mode  = 0;

 int MA2_Price = 0;      int MA22_Price = 0;    int MA222_Price = 0;



extern string                      T5= "***  Topes de Per1  ***";     // CieloL1 unicamente L1
extern double      Cielo    = 90;
extern double      Tierra   = 8;
extern double      CieloL1  = 90;
extern double      TierraL1 = 8;


extern string            T3= "-----Señales----";
extern bool Flechass     = True;
extern bool Cruzando     = True;
extern bool ambas        = False;
extern color clrCielo    = clrRed;
extern color clrTierra   = clrGreen;
extern int  fleC         = 234;
extern int  fleT         = 233;


extern string note8 = "Señales";  /*  En teoría AlertCandle en 1 hace que la alarma se indique al cierre de vela  */

extern int     AlertCandle         = 1;                                                                  
datetime       LastAlertTime       = -999999; 

extern bool  Mensaje = False;
extern bool  Sonido  = False;
extern bool  Celular = False;



string  MA_Method_Price = "SMA0 EMA1 SMMA2 LWMA3||0O,1C 2H 3L,  4Md 5Tp 6WghC:   Md(HL/2),   Tp(HLC/3),    Wgh(HLCC/4)";


//---- buffers
double MA1_Buf1[], MA11_Buf1[];
double MA2[], MA22[], MA222[];
double RSI1_Buf[], RSI11_Buf[];
double RSI2_Buf[], RSI22_Buf[];

double RSIM[], SIM[];


string TFStr;
#define PREFIX ""


string indicatorFileName;
bool   returnBars;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   IndicatorDigits (0);
   IndicatorBuffers(9);

   SetIndexBuffer(0,MA2);        SetIndexStyle(0,DRAW_NONE);  SetIndexLabel(0,NULL);
   SetIndexBuffer(1,MA22);       SetIndexStyle(1,DRAW_NONE);  SetIndexLabel(1,NULL);
   SetIndexBuffer(2,MA1_Buf1);   SetIndexLabel(2,NULL);
   SetIndexBuffer(3,MA11_Buf1);  SetIndexLabel(3,NULL);
   
   SetIndexBuffer(4,RSI1_Buf);   SetIndexStyle(4,DRAW_LINE);  SetIndexLabel(4,"RSI 1");
   SetIndexBuffer(5,RSI11_Buf);  SetIndexStyle(5,DRAW_LINE);  SetIndexLabel(5,"RSI 11");
   
   SetIndexBuffer(6,RSIM);       SetIndexStyle(6,DRAW_LINE);  SetIndexLabel(6,"RSI-M");
   
   SetIndexBuffer(7,RSI2_Buf);   SetIndexStyle(7,DRAW_NONE);  SetIndexLabel(7,NULL);
   SetIndexBuffer(8,RSI22_Buf);  SetIndexStyle(8,DRAW_NONE);  SetIndexLabel(8,NULL);
   SetIndexBuffer(9,MA222);      SetIndexStyle(9,DRAW_NONE);  SetIndexLabel(9,NULL);
   SetIndexBuffer(10,SIM);       SetIndexStyle(10,DRAW_NONE); SetIndexLabel(10,NULL);

 //**************************
     switch(TF)
   {
      case 1     :        TFStr="M1";       break;
      case 5     :        TFStr="M5";       break;
      case 15    :        TFStr="M15";      break;
      case 30    :        TFStr="M30";      break;
      case 60    :        TFStr="H1";       break;
      case 240   :        TFStr="H4";       break;
      case 1440  :        TFStr="D1";       break;
      case 10080 :        TFStr="W1";       break;
      case 43200 :        TFStr="MN1";      break;
      default    :        TFStr="Current";
   } 

//----   

   SetIndexDrawBegin(1,RSI1_Period);
//----


      indicatorFileName = WindowExpertName();
      returnBars        = (TF==-99);

IndicatorShortName("STC 4 RSI ("+TFStr+") -");
  if (TF<Period()) TF=Period();
 
 
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
{
   datetime TimeArray[],TimeArray1[];
   int  counted_bars=IndicatorCounted();
   int  i,limit; 
   
   
 //  if(counted_bars<0) return(-1);       if(counted_bars>0) counted_bars--;
    limit = Bars - counted_bars;
    limit = MathMax(limit,TF/Period());
    limit= MathMin(limit,MaxBarsToCount); 
      ArrayCopySeries(TimeArray, MODE_TIME,Symbol(),TF); 
      ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TF); 
    
  

   for(i=0; i<limit; i++)
   {
   
   int y = iBarShift(NULL,TF,Time[i]);
   
    if (Time[i]<TimeArray[i]) i++;
   
    MA1_Buf1[i] = iMA(NULL, TF, MA1_Period,0, MA1_Mode, MA1_Price, y);
    MA11_Buf1[i]= iMA(NULL, TF, MA11_Period,0, MA11_Mode, MA11_Price, y);

    MA2[i]    = iMA(NULL, TF, MA2_Period  ,0,   MA2_Mode,   MA2_Price, y);
    MA22[i]   = iMA(NULL, TF, MA22_Period, 0,  MA22_Mode,  MA22_Price, y);
    MA222[i]  = iMA(NULL, TF, MA222_Period,0, MA222_Mode, MA222_Price, y);


   }
 
 for(i=0; i<limit;i++)
  {
  int y = iBarShift(NULL,TF,Time[i]);
  
   if (Time[i]<TimeArray1[i]) i++;

   RSI1_Buf[i]     = iRSIOnArray(MA1_Buf1,  0,  RSI1_Period, y);
   RSI11_Buf[i]    = iRSIOnArray(MA11_Buf1, 0, RSI11_Period, y);

  
   RSI2_Buf[i]       = iRSIOnArray(MA2,   0,   RSI2_Period, y);
   RSI22_Buf[i]      = iRSIOnArray(MA22,  0,  RSI22_Period, y);
   double RSI222_Buf = iRSIOnArray(MA222, 0, RSI222_Period, y);
   
  double SI1     = iRSIOnArray (MA2,   0,   RSI2_Period, y+1);
  double SI11    = iRSIOnArray (MA22,  0,  RSI22_Period, y+1);
  double SI111   = iRSIOnArray (MA222, 0, RSI222_Period, y+1);
	
		
   RSIM[i]  =  (RSI2_Buf[i] +  RSI22_Buf[i] + RSI222_Buf) / 3 ;
    SIM[i]  =  (SI1 +  SI11 + SI111) / 3 ;
   
  }



/***********************************************************************************************************************************************************************
***  ***  ***  ***  ***  ***  ***                             F L E C H A S   Y    M A R C A S                         ***  ***  ***  ***  ***  ***  ***   ***  ***  *** 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

for(i=0; i<limit; i++)                                   {

 if  (Flechass == True)     
  {  
   if (  Cruzando == True) {
   
      if  (Close [i] && SIM[i] >= Cielo   &&  RSIM[i] < Cielo )    flechas (i,NULL,7,fleC,clrCielo,2,1);   
      if  (Close [i] && SIM[i] <= Tierra  &&  RSIM[i] > Tierra)    flechas (i,NULL,7,fleT,clrTierra,2,0);  
      
      
   if   (ambas == True) 
      {
        if  (Close [i] && SIM[i] >= Cielo   &&  RSIM[i] < Cielo  && RSI1_Buf[i] <= TierraL1)    flechas (i,NULL,1,234,clrSienna,2,1);   
        if  (Close [i] && SIM[i] <= Tierra  &&  RSIM[i] > Tierra && RSI1_Buf[i] >= CieloL1)     flechas (i,NULL,1,233,clrSienna,2,0);  
       
      }
            
                          }
  }

 
  if  (Flechass == True)     
   {  if (  Cruzando == False) 
      {
      if  (Close [i] && SIM[i] >= Cielo  )    flechas (i,NULL,1,234,clrRed,2,1); 
      if  (Close [i] && SIM[i] <= Tierra )    flechas (i,NULL,1,233,clrGreen,2,0);                
      }
   }

   ProcessAlerts();
                                                    }     

	return(0);
}
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
int deinit()
{
   ObjectsDeleteAll (0,PREFIX,0,-1);
   ObjectsDeleteAll (0,Cruzando,0,0);

   ObjectDelete (WindowsTotal());

return(0);}
//+------------------------------------------------------------------+



/*********************************************************************
*********                 f L E C H A S                ***************
*********************************************************************/
double flechas (int k, string N,int ots,int code,color clr, int size,bool up)
  {           
    string name = PREFIX+N+TimeToStr(Time[k]);  
    double gap = ots*Point;
   
    ObjectCreate(name,OBJ_ARROW,0,Time[k],0);
    ObjectSetInteger(0,name,OBJPROP_COLOR, clr);  
    ObjectSetInteger(0,name,OBJPROP_ARROWCODE,code);
    ObjectSetInteger(0,name,OBJPROP_WIDTH,size);  
    ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
   if (up==1)  {    ObjectSetDouble (0,name,OBJPROP_PRICE1,High[k]+gap*5); }                           
   
   if (up==0)  {    ObjectSetDouble (0,name,OBJPROP_PRICE1,Low[k]-gap*5); }
  
    
  return(0);
  }  

//********************************************************************
//*******                                                   **********
//********************************************************************
int ProcessAlerts()   {

  if (AlertCandle >= 0  &&  Time[0] > LastAlertTime)   {
  
 if (SIM[AlertCandle] >= Cielo   &&  RSIM[AlertCandle] < Cielo )  {
     
   string mensaje1 = Symbol() + "," + Period() + ": V E N D E R"   ;  
            if (Mensaje == True)    Alert (mensaje1);
            if (Sonido == True)     PlaySound("aguila.wav");      
            if (Celular == true)    SendNotification(mensaje1);   
               LastAlertTime = Time[0];
   } 

if (SIM[AlertCandle] <= Tierra   &&  RSIM[AlertCandle] > Tierra  )  {
     
   string mensaje2 = Symbol() + "," + Period() + ": C O M P R A R" ; 
           if (Mensaje == True)    Alert ( mensaje2);
           if (Sonido == True)     PlaySound("aguila.wav");      
           if (Celular == true)    SendNotification(mensaje2); 
               LastAlertTime = Time[0];

    } 

  }  return(0);

}
















/*

 //***************
int ProcessAlerts()   {
   int  counted_bars=IndicatorCounted();   
   int  limit; 
    limit = Bars - counted_bars;
    limit = MathMax(limit,TimeFrame/Period());
    limit= MathMin(limit,MaxBarsToCount); 
for(int i=0; i<limit; i++)                    {
  if (AlertCandle >= 0  &&  Time[0] > LastAlertTime)   {
  
 if (Close [i]  &&  SIM[AlertCandle] >= Cielo   &&  RSIM[AlertCandle] < Cielo )  {
     
   string mensaje1 = Symbol() + "," + Period() + ": V E N D E R"   ;  
            if (Mensaje == True)    Alert (mensaje1);
            if (Sonido == True)     PlaySound("aguila.wav");      
            if (Celular == true)    SendNotification(mensaje1);   
               LastAlertTime = Time[0];
                                                                                  } 

if (Close [i]  && SIM[AlertCandle] <= Tierra   &&  RSIM[AlertCandle] > Tierra  )  {
     
   string mensaje2 = Symbol() + "," + Period() + ": C O M P R A R" ; 
           if (Mensaje == True)    Alert ( mensaje2);
           if (Sonido == True)     PlaySound("aguila.wav");      
           if (Celular == true)    SendNotification(mensaje2); 
               LastAlertTime = Time[0];

                                                                                  } 

                                                       }                       
                                             }  
  return(0);  }
 
 
 */ 