//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++
#property copyright   "©  Tankk,  25  июня  2017,  http://forexsystemsru.com/" 
#property link        "https://forexsystemsru.com/1198113-post65.html"   //http://forexsystemsru.com/indikatory-foreks-f41/" 
#property description "Stochastic-X8.4 == Make in Russia by lukas1 aka Victor Lukashuk / lukas1@ngs.ru"    ///Custom Stochastic-X8.4.mq4
#property description " "
#property description "Процентный Диапазон Вильямса [WPR] — динамический индикатор, определяющий перекупленность/перепроданность. WPR похож на Stochastic Oscillator." 
#property description "WPR образует пик и поворачивает вниз прежде, чем цена достигает пика и поворачивает вниз. Точно так же WPR обычно образует впадину и заблаговременно поворачивает вверх."
#property description "WPR загадочным образом предвосхищает ценовые развороты!!!" 
#property description "Добавлены 18 индексов, стрелки, сигналы и матрица  :)) :))"
//#property version   "18.00"
//#property strict
#property indicator_separate_window
#property indicator_buffers 10
//------
#property indicator_color1   clrMaroon   //Brown       //DarkOrchid   //Violet
#property indicator_color2   clrDarkSlateBlue   //RoyalBlue    //Blue
#property indicator_color3   clrOrangeRed   //Tomato      ////Red
#property indicator_color4   clrTeal  //SeaGreen
#property indicator_color5   clrGold        //DarkOrange  
#property indicator_color6   clrMagenta     //SeaGreen
#property indicator_color7   clrDeepSkyBlue   //DodgerBlue
#property indicator_color8   clrRed         //White
#property indicator_color9   clrLightSteelBlue  //White
#property indicator_color10  clrLimeGreen  //ForestGreen  //
//------
#property indicator_width1  2
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2
#property indicator_width5  2
#property indicator_width6  1
#property indicator_width7  1
#property indicator_width8  2
#property indicator_width9  2
#property indicator_width10 2
//------
#property indicator_level1  100
#property indicator_level2  50   //35
#property indicator_level3  15
#property indicator_level4  -15
#property indicator_level5  -50   //-35
#property indicator_level6  -100
//------
#property indicator_levelcolor DarkSlateGray // SteelBlue //C'60,61,62' // 
#property indicator_levelstyle STYLE_DOT
//------
//#property indicator_minimum -150
//#property indicator_maximum  150
//+++======================================================================+++
//+++                   Custom indicator ENUM settings                     +++
//+++======================================================================+++
enum showhisto { NoHisto, Original, MoreLess, CloseOpen, HighLow, CrossZero };
enum calcIndex { NoIndex, AC, ADX, ADXCD, AO, BRBL, CCI, DMR, DPO, FRC, CLMA, MACD, OsMA, MFI, MMNT, RSI, RVI, STO, WPR };
enum arrt { NoArrows, MatrixZero, WPRAngle, WPRCloseOpen, WPRCrossSignal, WPRCrossOverSBL, SignalCrossOverSBL, IndexCrossWPR, IndexCrossSignal, IndexCrossOverSBL };   
enum mtxt { NoMatrix, mxAC, mxADX, mxAO, mxBRBL, mxCCI, mxCCD, mxDMR, mxFRC, mxMA, mxCLMA, mxDPO, mxMFI, mxMFCD, mxMMNT, mxRSI, mxRSCD, mxRVI, mxWPR };
//+++======================================================================+++
//+++                 Custom indicator input parameters                    +++
//+++======================================================================+++

extern int                    History  =  1440;   //Сколько свечей в Истории
extern showhisto            ShowHisto  =  CrossZero;  //Original;
extern bool                 ShowWPRx8  =  true;
extern int                  WPRPeriod  =  16;  //39,   //13 //5,    //parameter of D stoch.
extern int                   WPRShift  =  0;
extern double                    KOEF  =  1.5;  //1.2,

extern bool                ShowSignal  =  true;
extern int                   SignalMA  =  12;  //13;   //5;
extern ENUM_MA_METHOD      SignalMode  =  MODE_LWMA;
extern int                SignalShift  =  0;

extern calcIndex            ShowIndex  =  OsMA;  //CCI;
extern int                IndexPeriod  =  4,  //45,  //13
                            IndexSlow  =  16;  //45;           
extern ENUM_MA_METHOD       IndexMode  =  MODE_LWMA;
extern ENUM_APPLIED_PRICE  IndexPrice  =  PRICE_TYPICAL;
extern int                 IndexShift  =  0;
extern double                 InxKOEF  =  1.0;

extern mtxt                ShowMatrix  =  mxFRC;  //mxBRBL;  //mxMA
extern int               MatrixPeriod  =  24;  //45;
extern ENUM_MA_METHOD      MatrixMode  =  MODE_LWMA;
extern ENUM_APPLIED_PRICE MatrixPrice  =  PRICE_CLOSE;   
extern int                MatrixShift  =  0;
extern int                     CodeUP  =  167,  //59,   //110 //167 //233 //241
                               CodeDN  =  167;  //59;   //110 //167 //234 //242
                               
extern double              OverBought  =  50,   
                             OverSold  =  -50;
extern arrt                ShowArrows  =  IndexCrossWPR;  
extern int                   ARROWBAR  =  0;           //На каком Баре рисовать Стрелку
extern string        ArrowsIdentifier  =  "";  ///"WPRx8 TT——>";
extern int                   ArrowGap  =  5;            //Дистанция от High/Low свечи (4-значные пипсы)     
extern color                  ArrowUP  =  clrAqua,  //LightCyan,   //Lavender,    //FireBrick,       //Red,
                              ArrowDN  =  clrGold;  //Red;         //Magenta;     //DarkGreen;       //Lime
extern int                      CodUP  =  233,   //225
                                CodDN  =  234,   //226
                            ArrowSize  =  1; 
                            
extern bool             AlertsMessage  =  true,   //false,    
                          AlertsSound  =  true,   //false,
                          AlertsEmail  =  false,
                         AlertsMobile  =  false;
extern string               SoundFile  =  "news.wav";   //"stops.wav"   //"alert2.wav"   //"expert.wav" //Звук сигнала (исполняемый файл) прописан здесь
extern int                   ALERTBAR  =  1;        //На каком Баре сигналить

//+++======================================================================+++
//+++                     Custom indicator buffers                         +++
//+++======================================================================+++
double K10,K11,K12,K13,K14,K15,K16,K17;
double WPRDN[], WPRUP[], CloseDN[], CloseUP[], ClsOpn[];
double MatrixDN[], MatrixUP[];
double WPRx8[], SignalBUF[], IndexBUF[];  
double FLAGDN[], FLAGUP[];   int TimeBar=0;  
datetime LastBarOpenTime;   string PREF;
//+++======================================================================+++
//+++              Custom indicator initialization function                +++
//+++======================================================================+++
int init()
{
   K10=WPRPeriod;  K11=K10*KOEF;   K12=K11*KOEF;   K13=K12*KOEF;
   K14=K13*KOEF;   K15=K14*KOEF;   K16=K15*KOEF;   K17=K16*KOEF;
//+++======================================================================+++
//+++======================================================================+++

   IndicatorBuffers(12);   IndicatorDigits(2);  //(Digits-3);   if (Digits==2 || Digits==3) IndicatorDigits(Digits-1);
//------ 10 распределенных буфера индикатора 
   SetIndexBuffer(0,WPRDN);     //Буфер гистограммы    
   SetIndexBuffer(1,WPRUP);     //Буфер гистограммы    
   SetIndexBuffer(2,CloseDN);     //Буфер гистограммы    
   SetIndexBuffer(3,CloseUP);     //Буфер гистограммы
   SetIndexBuffer(4,ClsOpn);      //Буфер гистограммы
   SetIndexBuffer(5,MatrixDN);    //Буфер Matrix на Buy
   SetIndexBuffer(6,MatrixUP);    //Буфер Matrix на Sell
   SetIndexBuffer(7,WPRx8);     //WPR = ГЛАВНАЯ линия
   SetIndexBuffer(8,SignalBUF);   //Сигнальная на Stoch      
   SetIndexBuffer(9,IndexBUF);    //Буфер Индекса  
   //------
   SetIndexBuffer(10,FLAGDN);  SetIndexStyle(10,DRAW_NONE);  /// ФЛАГИ для СТРЕЛОК.....
   SetIndexBuffer(11,FLAGUP);  SetIndexStyle(11,DRAW_NONE);   
//------ настройка параметров отрисовки    
   if (ShowHisto==NoHisto) int HLT=DRAW_NONE;   else HLT=DRAW_HISTOGRAM; 
   SetIndexStyle(0,HLT);
   SetIndexStyle(1,HLT);  
   SetIndexStyle(2,HLT);
   SetIndexStyle(3,HLT);
   SetIndexStyle(4,HLT);
   //------
   SetIndexStyle(5,DRAW_ARROW);   SetIndexArrow(5,CodeUP);   
   SetIndexStyle(6,DRAW_ARROW);   SetIndexArrow(6,CodeDN);   
   //------
   if (ShowWPRx8) SetIndexStyle(7,DRAW_LINE);   else SetIndexStyle(7,DRAW_NONE);        
   SetIndexStyle(8,DRAW_LINE);
   SetIndexStyle(9,DRAW_LINE);
//------ отображение в DataWindow 
   if (ShowHisto!=NoHisto)  SetIndexLabel(0,"WPR''DN");    else SetIndexLabel(0,NULL);
   if (ShowHisto!=NoHisto)  SetIndexLabel(1,"WPR''UP");    else SetIndexLabel(1,NULL);
   if (ShowHisto!=NoHisto)  SetIndexLabel(2,"CloseDN");    else SetIndexLabel(2,NULL); 
   if (ShowHisto!=NoHisto)  SetIndexLabel(3,"CloseUP");    else SetIndexLabel(3,NULL);
   if (ShowHisto!=NoHisto)  SetIndexLabel(4,"ClsOpn");     else SetIndexLabel(4,NULL);
   //------
   if (ShowMatrix!=NoMatrix) SetIndexLabel(5,"MatrixDN ["+IntegerToString(MatrixPeriod)+"]");   else SetIndexLabel(5,NULL);
   if (ShowMatrix!=NoMatrix) SetIndexLabel(6,"MatrixUP ["+IntegerToString(MatrixPeriod)+"]");   else SetIndexLabel(6,NULL);
   SetIndexLabel(7,"WPRx8  ["+IntegerToString(WPRPeriod)+"]");
   if (ShowSignal) SetIndexLabel(8,"SignalMA   ["+IntegerToString(SignalMA)+"]");     else SetIndexLabel(8,NULL);
   if (ShowIndex!=NoIndex)    SetIndexLabel(9,EnumToString(ShowIndex)+" ["+IntegerToString(IndexPeriod)+"-"+IntegerToString(IndexSlow)+"]");   else SetIndexLabel(9,NULL);
//------ значение 0 отображаться не будет 
  	SetIndexEmptyValue(0,0.0);  	SetIndexEmptyValue(1,0.0);   SetIndexEmptyValue(2,0.0);    ///убираем косяки при "Обрезке Истории"....
  	SetIndexEmptyValue(3,0.0);  	SetIndexEmptyValue(4,0.0);   SetIndexEmptyValue(5,0.0);    
  	SetIndexEmptyValue(6,0.0);  	SetIndexEmptyValue(7,0.0);   SetIndexEmptyValue(8,0.0);    
  	SetIndexEmptyValue(9,0.0);  	//SetIndexEmptyValue(10,0.0);  SetIndexEmptyValue(11,0.0);    
//------ установка сдвига линий при отрисовке 
   SetIndexShift(0,WPRShift);  
   SetIndexShift(1,WPRShift);     
   SetIndexShift(2,WPRShift);     
   SetIndexShift(3,WPRShift);   
   SetIndexShift(4,WPRShift);  
   SetIndexShift(5,MatrixShift);   
   SetIndexShift(6,MatrixShift);  
   SetIndexShift(7,WPRShift);  
   SetIndexShift(8,SignalShift);  
   SetIndexShift(9,IndexShift);  
//------ пропуск отрисовки первых баров   
   SetIndexDrawBegin(0,WPRShift+WPRPeriod);     
   SetIndexDrawBegin(1,WPRShift+WPRPeriod);     
   SetIndexDrawBegin(2,WPRShift+WPRPeriod);  
   SetIndexDrawBegin(3,WPRShift+WPRPeriod);  
   SetIndexDrawBegin(4,WPRShift+WPRPeriod);
   SetIndexDrawBegin(5,MatrixShift+MatrixPeriod);  
   SetIndexDrawBegin(6,MatrixShift+MatrixPeriod);
   SetIndexDrawBegin(7,WPRShift+WPRPeriod);   
   SetIndexDrawBegin(8,SignalShift+SignalMA);   
   SetIndexDrawBegin(9,IndexShift+IndexPeriod);   
   
//------ "короткое имя" для DataWindow и подокна индикатора +++ "уникальное имя индикатора"
   string sim=StringSetChar("",0,164)+DoubleToString(KOEF,2);
   if (ShowSignal)           string labelM = " ->SigMA["+IntegerToString(SignalMA)+"]";
   if (ShowIndex!=NoIndex)   string labelC = " +"+EnumToString(ShowIndex)+ "["+IntegerToString(IndexPeriod)+"-"+IntegerToString(IndexSlow)+"]";
   if (ShowMatrix)           string labelX = " +"+EnumToString(ShowMatrix)+"["+IntegerToString(MatrixPeriod)+"]";
//------
   IndicatorShortName("WPRx8 ["+IntegerToString(WPRPeriod)+"]"+sim+labelM+labelC+labelX);
//------
   if (ArrowsIdentifier!="") PREF = ArrowsIdentifier;
   else PREF = "WPR["+IntegerToString(WPRPeriod)+sim+"] vs "
                        +EnumToString(ShowIndex)+"["+IntegerToString(IndexPeriod)+"-"+IntegerToString(IndexSlow)+"]__"+IntegerToString(ShowArrows)+"''";
//+++======================================================================+++
//---- initialization done
return(0);
}
//+++======================================================================+++
//+++              Custom indicator deinitialization function              +++
//+++======================================================================+++
int deinit()  { ARROWS_DELETE();  return(0); }
//+++======================================================================+++
void ARROWS_DELETE()
{
   string name;
   for (int s=ObjectsTotal()-1; s>=0; s--) {
        name=ObjectName(s);
        if (StringSubstr(name,0,StringLen(PREF))==PREF) {ObjectDelete(name);} }
}
//+++======================================================================+++
bool NewBarTF(int period) 
{
   datetime BarOpenTime=iTime(NULL,period,0);
   if (BarOpenTime!=LastBarOpenTime) {
       LastBarOpenTime=BarOpenTime;
       return (true); } 
   else 
       return (false);
}
//+++======================================================================+++
//+++                 Custom indicator iteration function                  +++
//+++======================================================================+++
int start()
{
    //int i, counted_bars=IndicatorCounted();
    //if(counted_bars<0)    return(-1);
    //   if(History < 1)     History = Bars;
    //   if(counted_bars > 0)    counted_bars -= 0;
    //      int limit = MathMin(History-counted_bars,History-1);  
    //      if(limit<=0) limit=1;          
//+++======================================================================+++
   
   if (History >= 1)  { if (NewBarTF(_Period)) { ARROWS_DELETE(); } }
//--------
   int  i, CountedBars = IndicatorCounted();   /// вариант из "ZZ NRP AA LB TT [x4v5].mq4"......
   if (CountedBars < 0) return (-1);       /// Стандарт-Вариант!!!
   if (CountedBars > 0) CountedBars--;
   int limit = History; 
   if (History==0) { limit = Bars-CountedBars; }     
//**************************************************************************//
//+++======================================================================+++

   double m1,m2,m3,m4,m5,m6,m7,m8;
//------
   for (i=limit; i>=0; i--)    ///for (i=0; i<limit; i++)
    {
     m1 = 2* NormalizeDouble(iWPR(NULL,0,K10,i)+50,Digits+1);
     m2 = 2* NormalizeDouble(iWPR(NULL,0,K11,i)+50,Digits+1);
     m3 = 2* NormalizeDouble(iWPR(NULL,0,K12,i)+50,Digits+1);
     m4 = 2* NormalizeDouble(iWPR(NULL,0,K13,i)+50,Digits+1);
     m5 = 2* NormalizeDouble(iWPR(NULL,0,K14,i)+50,Digits+1);
     m6 = 2* NormalizeDouble(iWPR(NULL,0,K15,i)+50,Digits+1);
     m7 = 2* NormalizeDouble(iWPR(NULL,0,K16,i)+50,Digits+1);
     m8 = 2* NormalizeDouble(iWPR(NULL,0,K17,i)+50,Digits+1);
   //------
     WPRx8[i] = (m1+m2+m3+m4+m5+m6+m7+m8)/8;  
    }
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++

   double JPY=100000;   if (Digits==2 || Digits==3) JPY=1000;
   double JPP=10000;   if (Digits==2 || Digits==3) JPP=100;
   double JP =1000;   if (Digits==2 || Digits==3) JP=10;
   double JT =100;   if (Digits==2 || Digits==3) JT=1;
   double JJ =10;   if (Digits==2 || Digits==3) JJ=0.1;
//+++======================================================================+++
//+++======================================================================+++
//enum showhisto { NoHisto, Original, MoreLess, CloseOpen, HighLow, CrossZero };
     
   for (i=limit; i>=0; i--) 
    {
     if (ShowHisto==Original) {
         if (WPRx8[i]<WPRx8[i+1])  { WPRDN[i]=WPRx8[i];  WPRUP[i]=0; }
         if (WPRx8[i]>WPRx8[i+1])  { WPRUP[i]=WPRx8[i];  WPRDN[i]=0; }
         //------
         if (Close[i]<Open[i])   { CloseDN[i]=WPRx8[i]/2;   CloseUP[i]=0;  ClsOpn[i]=0; } 
         if (Close[i]>Open[i])   { CloseUP[i]=WPRx8[i]/2;   CloseDN[i]=0;  ClsOpn[i]=0; }  
         if (Close[i]==Open[i])  { ClsOpn[i]=WPRx8[i]/2;    CloseDN[i]=0;  CloseUP[i]=0;} }
   //------
     if (ShowHisto==MoreLess) {
         if (WPRx8[i]<WPRx8[i+1])  { WPRDN[i]=WPRx8[i];  WPRUP[i]=0; }
         if (WPRx8[i]>WPRx8[i+1])  { WPRUP[i]=WPRx8[i];  WPRDN[i]=0; } }
   //------
     if (ShowHisto==CloseOpen) {
         if (Close[i]<Open[i])   { CloseDN[i]=WPRx8[i];   CloseUP[i]=0;  ClsOpn[i]=0; } 
         if (Close[i]>Open[i])   { CloseUP[i]=WPRx8[i];   CloseDN[i]=0;  ClsOpn[i]=0; }  
         if (Close[i]==Open[i])  { ClsOpn[i]=WPRx8[i];    CloseDN[i]=0;  CloseUP[i]=0;} }
   //------
     if (ShowHisto==HighLow) {
         if (Low[i]<Low[i+1])     { CloseDN[i]=WPRx8[i];   CloseUP[i]=0;  ClsOpn[i]=0; } 
         if (High[i]>High[i+1])   { CloseUP[i]=WPRx8[i];   CloseDN[i]=0;  ClsOpn[i]=0; }  
         if (Low[i]==Low[i+1])    { ClsOpn[i]=WPRx8[i];    CloseDN[i]=0;  CloseUP[i]=0;} 
         if (High[i]==High[i+1])  { ClsOpn[i]=WPRx8[i];    CloseDN[i]=0;  CloseUP[i]=0;} 
         if (High[i]<High[i+1] && WPRx8[i]>0)  { WPRDN[i]=WPRx8[i];  WPRUP[i]=0; }
         if (Low[i]>Low[i+1] && WPRx8[i]<0)    { WPRUP[i]=WPRx8[i];  WPRDN[i]=0; } }
   //------
     if (ShowHisto==CrossZero) {
         if (WPRx8[i]<0)  { WPRDN[i]=WPRx8[i];  WPRUP[i]=0; }
         if (WPRx8[i]>0)  { WPRUP[i]=WPRx8[i];  WPRDN[i]=0; } }
//+++======================================================================+++
//+++======================================================================+++

     if ((ShowSignal) && (SignalMA>0)) SignalBUF[i] = iMAOnArray(WPRx8,0,SignalMA,0,SignalMode,i);   else SignalBUF[i]=0;  //EMPTY_VALUE;     
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++
//enum calcIndex { NoIndex, AC, ADX, ADXCD, AO, BRBL, CCI, DMR, DPO, FRC, MACD, OsMA, MFI, MMNT, RSI, RVI, STO, WPR };

     if ((ShowIndex==NoIndex) || (IndexPeriod<1))  IndexBUF[i]=0;  //EMPTY_VALUE;    
   //------
     else {
           if (ShowIndex==AC)     IndexBUF[i] = InxKOEF*  JPY* iAC(NULL,0,i);    
           if (ShowIndex==ADX)    IndexBUF[i] = InxKOEF*  (10* (iADX(NULL,0,IndexPeriod,IndexPrice,MODE_PLUSDI,i) - iADX(NULL,0,IndexPeriod,IndexPrice,MODE_MINUSDI,i))) /2;   //или /Koef == так было ДО версии [x15x9x15]
           if (ShowIndex==ADXCD)  IndexBUF[i] = InxKOEF*  ((5* (iADX(NULL,0,IndexPeriod,IndexPrice,MODE_PLUSDI,i) - iADX(NULL,0,IndexPeriod,IndexPrice,MODE_MINUSDI,i))) 
                                                            - (5* (iADX(NULL,0,IndexSlow,IndexPrice,MODE_PLUSDI,i) - iADX(NULL,0,IndexSlow,IndexPrice,MODE_MINUSDI,i))));   
           if (ShowIndex==AO)     IndexBUF[i] = InxKOEF*  JPY* iAO(NULL,0,i);  //или 2*JPP*   
           if (ShowIndex==BRBL)   IndexBUF[i] = InxKOEF*  JPY* ((iBearsPower(NULL,0,IndexPeriod,IndexPrice,i) + iBullsPower(NULL,0,IndexPeriod,IndexPrice,i)) /2);
           if (ShowIndex==CCI)    IndexBUF[i] = InxKOEF*  iCCI(NULL,0,IndexPeriod,IndexPrice,i) /2;   //или /Koef == так было ДО версии [x15x9x15]
           if (ShowIndex==DMR)    IndexBUF[i] = InxKOEF*  100* (NormalizeDouble(iDeMarker(NULL,0,IndexPeriod,i)-0.5,Digits+1));
           if (ShowIndex==DPO)    IndexBUF[i] = InxKOEF*  JPY* (Close[i] - iMA(NULL,0,IndexPeriod,(IndexPeriod/2)+1,IndexMode,IndexPrice,i)); 
           if (ShowIndex==FRC)    IndexBUF[i] = InxKOEF*  JP* iForce(NULL,0,IndexPeriod,IndexMode,IndexPrice,i);     
           if (ShowIndex==CLMA)   IndexBUF[i] = InxKOEF*  JPY* (Close[i] - iMA(NULL,0,IndexPeriod,0,IndexMode,IndexPrice,i));  
           if (ShowIndex==MACD)   IndexBUF[i] = InxKOEF*  JPY* iMACD(NULL,0,IndexPeriod,IndexSlow,1,IndexPrice,MODE_MAIN,i);  
           if (ShowIndex==OsMA)   IndexBUF[i] = InxKOEF*  JPY* iOsMA(NULL,0,IndexPeriod,IndexSlow,SignalMA,IndexPrice,i);     
           if (ShowIndex==MFI)    IndexBUF[i] = InxKOEF*  2* NormalizeDouble(iMFI(NULL,0,IndexPeriod,i)-50,Digits+1);           
           if (ShowIndex==MMNT)   IndexBUF[i] = InxKOEF*  100* NormalizeDouble(iMomentum(NULL,0,IndexPeriod,IndexPrice,i)-100,Digits+1);
           if (ShowIndex==RSI)    IndexBUF[i] = InxKOEF*  2* NormalizeDouble(iRSI(NULL,0,IndexPeriod,IndexPrice,i)-50,Digits+1);    
           if (ShowIndex==RVI)    IndexBUF[i] = InxKOEF*  100* iRVI(NULL,0,IndexPeriod,MODE_MAIN,i);
           if (ShowIndex==STO)    IndexBUF[i] = InxKOEF*  2* NormalizeDouble(iStochastic(NULL,0,IndexPeriod,1,IndexSlow,IndexMode,STO_LOWHIGH,MODE_MAIN,i)-50,Digits+1);
           if (ShowIndex==WPR)    IndexBUF[i] = InxKOEF*  2* NormalizeDouble(iWPR(NULL,0,IndexPeriod,i)+50,Digits+1); }  
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++
//enum mtxt { NoMatrix, mxAC, mxADX, mxAO, mxBRBL, mxCCI, mxCCD, mxDMR, mxFRC, mxMA, mxDPO, mxMFI, mxMFCD, mxMMNT, mxRSI, mxRSCD, mxRVI, mxWPR };
                                            //или 3/-3 == так было в версии [x15x9x15]
     if (ShowMatrix!=NoMatrix) { MatrixDN[i]=0.00001;   MatrixUP[i]=0.00001; }   double Matrix;   
   //------                                                                                      //iClose(NULL,0,i)
     if (ShowMatrix==mxMA)    { Matrix = iMA(NULL,0,MatrixPeriod,0,MatrixMode,MatrixPrice,i);   if (Close[i] > Matrix) MatrixDN[i]=0;   if (Close[i] < Matrix) MatrixUP[i]=0; }   
     if (ShowMatrix==mxCLMA)  { Matrix = Close[i] - iMA(NULL,0,MatrixPeriod,0,MatrixMode,MatrixPrice,i); }
   //------
     if (ShowMatrix==mxAC)    { Matrix = iAC(NULL,0,i); }     
     if (ShowMatrix==mxADX)   { Matrix = iADX(NULL,0,MatrixPeriod,MatrixPrice,MODE_PLUSDI,i) - iADX(NULL,0,MatrixPeriod,MatrixPrice,MODE_MINUSDI,i); }
     if (ShowMatrix==mxAO)    { Matrix = iAO(NULL,0,i); }  
     if (ShowMatrix==mxBRBL)  { Matrix = (iBearsPower(NULL,0,MatrixPeriod,MatrixPrice,i) + iBullsPower(NULL,0,MatrixPeriod,MatrixPrice,i))/2; }  
     if (ShowMatrix==mxCCI)   { Matrix = iCCI(NULL,0,MatrixPeriod,MatrixPrice,i); }  
     if (ShowMatrix==mxCCD)   { Matrix = iCCI(NULL,0,MatrixPeriod*1.5,MatrixPrice,i) - iCCI(NULL,0,MatrixPeriod,MatrixPrice,i); }  
     if (ShowMatrix==mxDMR)   { Matrix = iDeMarker(NULL,0,MatrixPeriod,i);   if (Matrix > 0.5) MatrixDN[i]=0;   if (Matrix < 0.5) MatrixUP[i]=0; }  
     if (ShowMatrix==mxFRC)   { Matrix = iForce(NULL,0,MatrixPeriod,MatrixMode,MatrixPrice,i); }  
     if (ShowMatrix==mxDPO)   { Matrix = Close[i] - iMA(NULL,0,MatrixPeriod,(MatrixPeriod/2)+1,MatrixMode,MatrixPrice,i); }
     if (ShowMatrix==mxMFI)   { Matrix = iMFI(NULL,0,MatrixPeriod,i);   if (Matrix > 50) MatrixDN[i]=0;   if (Matrix < 50) MatrixUP[i]=0; }  
     if (ShowMatrix==mxMFCD)  { Matrix = iMFI(NULL,0,MatrixPeriod,i) - iMFI(NULL,0,MatrixPeriod*4,i); }  
     if (ShowMatrix==mxMMNT)  { Matrix = iMomentum(NULL,0,MatrixPeriod,MatrixPrice,i);   if (Matrix > 100) MatrixDN[i]=0;   if (Matrix < 100) MatrixUP[i]=0; }  
     if (ShowMatrix==mxRSI)   { Matrix = iRSI(NULL,0,MatrixPeriod,MatrixPrice,i);   if (Matrix > 50) MatrixDN[i]=0;   if (Matrix < 50) MatrixUP[i]=0; }  
     if (ShowMatrix==mxRSCD)  { Matrix = iRSI(NULL,0,MatrixPeriod,MatrixPrice,i) - iRSI(NULL,0,MatrixPeriod*4,MatrixPrice,i); }  
     if (ShowMatrix==mxRVI)   { Matrix = iRVI(NULL,0,MatrixPeriod,MODE_MAIN,i); }
     if (ShowMatrix==mxWPR)   { Matrix = iWPR(NULL,0,MatrixPeriod,i);   if (Matrix > -50) MatrixDN[i]=0;   if (Matrix < -50) MatrixUP[i]=0; }  
   //------
     if (ShowMatrix==mxAC || ShowMatrix==mxADX || ShowMatrix==mxAO || ShowMatrix==mxBRBL || ShowMatrix==mxCCI || ShowMatrix==mxCCD || ShowMatrix==mxFRC  
                          || ShowMatrix==mxCLMA || ShowMatrix==mxDPO || ShowMatrix==mxMFCD || ShowMatrix==mxRSCD || ShowMatrix==mxRVI)
        { if (Matrix > 0)  MatrixDN[i]=0;   if (Matrix < 0)  MatrixUP[i]=0; }   ////{ if (Matrix > 0)  MatrixDN[i] = EMPTY_VALUE;   if (Matrix < 0)  MatrixUP[i] = EMPTY_VALUE; }
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++
//enum arrt { No_Arrows, MatrixZero, StochAngle, StochCloseOpen, StochCrossSignal, WPRCrossOverSBL, SignalCrossOverSBL, IndexCrossWPR, IndexCrossSignal, IndexCrossOverSBL };   

     FLAGDN[i]=0;   FLAGUP[i]=0;   
   //------
     if (ShowArrows==MatrixZero) {//EMPTY_VALUE               //EMPTY_VALUE
         if (MatrixDN[i+ARROWBAR] !=0 && MatrixDN[i+1+ARROWBAR] ==0)   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (MatrixUP[i+ARROWBAR] !=0 && MatrixUP[i+1+ARROWBAR] ==0)   { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==WPRAngle) {
         if (WPRDN[i+ARROWBAR] !=0 && WPRDN[i+1+ARROWBAR] ==0)   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (WPRUP[i+ARROWBAR] !=0 && WPRUP[i+1+ARROWBAR] ==0)   { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==WPRCloseOpen) {
         if (CloseDN[i+ARROWBAR] !=0 && CloseDN[i+1+ARROWBAR] ==0)   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (CloseUP[i+ARROWBAR] !=0 && CloseUP[i+1+ARROWBAR] ==0)   { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==WPRCrossSignal) {
         if (WPRx8[i+ARROWBAR] < SignalBUF[i+ARROWBAR] && WPRx8[i+1+ARROWBAR] > SignalBUF[i+1+ARROWBAR])   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (WPRx8[i+ARROWBAR] > SignalBUF[i+ARROWBAR] && WPRx8[i+1+ARROWBAR] < SignalBUF[i+1+ARROWBAR])   { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==WPRCrossOverSBL) {
         if (WPRx8[i+ARROWBAR] < OverBought && WPRx8[i+1+ARROWBAR] > OverBought)   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (WPRx8[i+ARROWBAR] > OverSold   && WPRx8[i+1+ARROWBAR] < OverSold)     { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==SignalCrossOverSBL) {
         if (SignalBUF[i+ARROWBAR] < OverBought && SignalBUF[i+1+ARROWBAR] > OverBought)   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (SignalBUF[i+ARROWBAR] > OverSold   && SignalBUF[i+1+ARROWBAR] < OverSold)     { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==IndexCrossWPR) {
         if (IndexBUF[i+ARROWBAR] < WPRx8[i+ARROWBAR] && IndexBUF[i+1+ARROWBAR] > WPRx8[i+1+ARROWBAR])   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (IndexBUF[i+ARROWBAR] > WPRx8[i+ARROWBAR] && IndexBUF[i+1+ARROWBAR] < WPRx8[i+1+ARROWBAR])   { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==IndexCrossSignal) {
         if (IndexBUF[i+ARROWBAR] < SignalBUF[i+ARROWBAR] && IndexBUF[i+1+ARROWBAR] > SignalBUF[i+1+ARROWBAR])   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (IndexBUF[i+ARROWBAR] > SignalBUF[i+ARROWBAR] && IndexBUF[i+1+ARROWBAR] < SignalBUF[i+1+ARROWBAR])   { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
   //------
     if (ShowArrows==IndexCrossOverSBL) {
         if (IndexBUF[i+ARROWBAR] < OverBought && IndexBUF[i+1+ARROWBAR] > OverBought)   { FLAGDN[i]=-888;  manageArr(i,"ArrDN",true ); }
         if (IndexBUF[i+ARROWBAR] > OverSold   && IndexBUF[i+1+ARROWBAR] < OverSold)     { FLAGUP[i]=888;   manageArr(i,"ArrUP",false); } }
//+++======================================================================+++
    }  ///*КОНЕЦ цикла* for (i=limit; i>=0; i--)   
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++

   if ((ShowArrows!=NoArrows) && (AlertsMessage || AlertsEmail || AlertsMobile || AlertsSound)) 
    {
     string messageDN = ("WPRx8 +Matrix TT - "+Symbol()+", TF ["+IntegerToString(Period())+"] = "+EnumToString(ShowArrows)+" <<<  Arrow DN  ==  SELL");   //BearsBulls Alerts MTF TT
     string messageUP = ("WPRx8 +Matrix TT - "+Symbol()+", TF ["+IntegerToString(Period())+"] = "+EnumToString(ShowArrows)+" >>>  Arrow UP  ==  BUY");   //BearsBulls Alerts MTF TT
   //------
     if (TimeBar!=Time[0] && FLAGDN[ALERTBAR] < 0) {
         if (AlertsMessage) Alert(messageDN);
         if (AlertsEmail)   SendMail(Symbol(),messageDN);
         if (AlertsMobile)  SendNotification(messageDN);
         if (AlertsSound)   PlaySound(SoundFile);   //"stops.wav"   //"news.wav"
         TimeBar=Time[0]; }  //return(0);
   //------
     else 
     if (TimeBar!=Time[0] && FLAGUP[ALERTBAR] > 0) { 
         if (AlertsMessage) Alert(messageUP);
         if (AlertsEmail)   SendMail(Symbol(),messageUP);
         if (AlertsMobile)  SendNotification(messageUP);
         if (AlertsSound)   PlaySound(SoundFile);   //"stops.wav"   //"news.wav"
         TimeBar=Time[0]; }  //return(0);
    }  ///*конец* АЛЕРТОВ для всех.....
//+++======================================================================+++
//+++======================================================================+++
return(0);
}
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++
void manageArr(int z, string text, bool DN)   
{
   string objName = PREF+text+"_"+Time[z]+"_"+Close[z];
   //double Gap = 2.0*iATR(NULL,0,20,z)/4.0;
   double Gap=ArrowGap*Point;   if (Digits==3 || Digits==5) Gap=ArrowGap*10*Point;
//------
   ObjectCreate(objName,OBJ_ARROW, 0, Time[z], 0);
   ObjectSet(objName,OBJPROP_TEXT, text);  
   //ObjectSet(objName,OBJPROP_COLOR, Clr);  
   //ObjectSet(objName,OBJPROP_ARROWCODE, Code);
   ObjectSet(objName,OBJPROP_WIDTH, ArrowSize);  
   ObjectSet(objName,OBJPROP_SELECTABLE, false);  
   ObjectSet(objName,OBJPROP_HIDDEN, true);  
//------
   if (DN) {
            ObjectSet(objName,OBJPROP_COLOR, ArrowDN);  
            ObjectSet(objName,OBJPROP_ARROWCODE, CodDN);
            ObjectSet(objName,OBJPROP_PRICE1, High[z]+Gap*1.3); }   
   //------
   else {  
         ObjectSet(objName,OBJPROP_COLOR, ArrowUP);  
         ObjectSet(objName,OBJPROP_ARROWCODE, CodUP);
         ObjectSet(objName,OBJPROP_PRICE1, Low[z]-Gap); }
}
//+++======================================================================+++
//+++               WPRx8 +Index +Matrix AA TT [x18x9x18x5]                +++
//+++======================================================================+++