//+------------------------------------------------------------------+
//|                                       Damon smDashBoard_v1.4.mq4 |
//|                                                  © 2008 SwingMan |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "© 2008 SwingMan"
#property link      ""
//+------------------------------------------------------------------+
//| Idee from:                                                       |
//| OzFX TriggeredPairs v14;  Copyright © 2008, Daud                 |
//| TRO_Dashboard.mq4;        Copyright © 2008, TRO                  |
//| MT4_DASHBOARD_V1.5.mq4    Copyright © 2008, OTCFX                |
//--------------------------------------------------------------------
// v1.3 2008.03.26  Write Entry Prices, show Alerts for Reversal Signals
// v1.4 2008.03.26  Write High/Low for the last bar, Close for the current Bars
//                  For TimeFrame = 0, take the time frame of the chart
//+------------------------------------------------------------------+


#property indicator_separate_window

//---- extern inputs -------------------------------------------------
extern string PairsList = "AUDUSD,EURUSD,GBPUSD,USDCAD,USDCHF,USDJPY,GBPJPY,GBPCHF,EURGBP,NZDUSD,EURJPY,EURCHF,EURAUD,EURCAD";//- This is where you add the currency pairs you want 
extern string SymbolSuffix = "";//- If your broker names the currency pairs with a suffix for a mini account (like an "m", for example), enter the suffix here
extern int TimeFrame = 0;
extern bool SendAlert_ReverseSignals = true;
//--------------------------------------------------------------------

//---- constants
string windowsName = "Damon smDashBoard_v1.4";
string sLabelCode = "ATPDashBoard_";
string sNonLagMA_Name = "Damon smNonLagMA_v1";
int Corner_LeftUp = 0;
int Corner_RightUp = 1;
int Corner_LeftDn = 2;
int Corner_RightDn = 3;
//-- SilverTrend
int Period_SilverTrend = 9;
int Period_NonLagMA = 9;
int Period_RSI = 14;
int colSTn = 0;
int colST1 = 1;
int colNLn = 2;
int colNL1 = 3;
int colAC = 4;
int colAO = 5;
int colRSI = 6;

//---- colors
color colorTitle = DodgerBlue;
color colorTime = Orange;
color colorPlusIndi  = Green;
color colorMinusIndi = Red;
color colorNeutralIndi = Orange;
color colorPlusMA = Blue;
color colorMinusMA = Red;
color colorChangeMA = Gold;
color colorLongST = Lime;
color colorShortST = Red;
color colorPlusSignal  = DeepSkyBlue;
color colorMinusSignal = Magenta;
//--NL
color colorPlusNLMA = DodgerBlue;//SkyBlue;
color colorMinusNLMA = OrangeRed;//Tomato;
color colorChangeNLMAup = Gold;
color colorChangeNLMAdn = DarkOrange;

//---- variables
string Pair[24]; //Pairs array
double PairPrice[24];
int NumberSymbols;
int k;
int iWindow, iCorner;
int xCol[50], yRow[50];
string Title1[50], Title2[50];
datetime oldTime;
int xCurrentTime, yCurrentTime;
int Signal[24][50];
bool CurrentTimeFrameOK;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   iCorner = Corner_LeftUp;
   CurrentTimeFrameOK = false;
   if (TimeFrame == 0) TimeFrame = Period();

   IndicatorShortName(windowsName);
   SetIndexLabel(0,windowsName);
   
   for (int i=0; i<=50; i++) {
      Title1[i] = "";
      Title2[i] = "";
   }
/*   
   iWindow = WindowFind(windowsName);
   if (iWindow==-1) iWindow=1;

   Get_PairListNames();   
   Set_Initialisations();
   //---- titles
   Show_TitlesUpper();
   Show_TitlesLeft();
*/   
//----
   return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{  
   Delete_TextObjects();
   Sleep(500);
   Delete_TextObjects();   
//----
   return(0);
}

void Delete_TextObjects()
{
   ObjectsDeleteAll(1,OBJ_LABEL);
   ObjectsDeleteAll(1,OBJ_TEXT);
   ObjectsDeleteAll(1,OBJ_ARROW);
   return;
}

//####################################################################
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   if (Time[0] == oldTime) return(0);
   oldTime = Time[0];
   int    counted_bars=IndicatorCounted();   
//----   
   iWindow = WindowFind(windowsName);
   if (iWindow==-1) iWindow=1;
   //-- whole calculation
   if (TimeFrame == Period() || CurrentTimeFrameOK==false) {
      Get_PairListNames();   
      Set_Initialisations();
      //---- titles
      Show_TitlesUpper();
      Show_TitlesLeft();   
   
      //---- signals
      Get_SilverTrend(1);    // ST
      Get_NonLagMA(1);       // NL 
   
      Get_WilliamsAccelerator(1); // AC
      Get_AwesomeOscillator(1);   // AO
      Get_RSI(1);   // RSI
   
      //---- tick values
      //Get_TickValues();

      //---- trading signals
      Get_ReverseSignal(1);

      Write_CurrentTime(xCurrentTime, yCurrentTime);
      CurrentTimeFrameOK = true;
   } else
   //-- write only prices
   {
      Show_OnlyPrices();
      Write_CurrentTime(xCurrentTime, yCurrentTime);
   }
//----
   return(0);
}
//+------------------------------------------------------------------+

//####################################################################

//+------------------------------------------------------------------+
//|   Initialisations
//+------------------------------------------------------------------+
int yTitle1 = 30;
int yTitle2 = 50;
int nTitles = 20;
int xLeftTitle = 20;
int xPrice = 100;
int xScanner;

int rowStep = 20;
int colStep = 50;

int colDB_Pairs;
int colDB_Spread, colDB_High, colDB_Low, colDB_Close, colDB_LastPrice;
int colDB_ST, colDB_NL, colDB_AC, colDB_AO, colDB_RSI, colDB_RevSig;

void Set_ColumnNumbers()
{
   colDB_Pairs = 1;

   colDB_Spread= colDB_Pairs +1;
   colDB_High  = colDB_Spread+1;
   colDB_Low   = colDB_High  +1;
   colDB_Close = colDB_Low   +1;
   colDB_LastPrice = colDB_Close;
   
   colDB_ST     = colDB_LastPrice + 1;
   colDB_NL     = colDB_ST + 1;
   colDB_AC     = colDB_NL + 1; 
   colDB_AO     = colDB_AC + 1; 
   colDB_RSI    = colDB_AO +1;
   colDB_RevSig = colDB_RSI + 1;
}

void Set_Initialisations()
{
   int i;
   Set_ColumnNumbers();
   Title1[colDB_Pairs] = "Pairs";
   Title1[colDB_Spread]= "Spread";  
   Title1[colDB_High]  = "Last Bar";  
   Title1[colDB_Close] = "Current";
   //Title1[colDB_Close] = "("+TimeToStr(TimeCurrent(),TIME_MINUTES)+")";
   
   Title1[colDB_ST]  = "ST";
   Title1[colDB_NL]  = "NL";
   Title1[colDB_AC]  = "AC";
   Title1[colDB_AO]  = "AO";      
   Title1[colDB_RSI] = "RSI";
   
   //-- tick value
//   Title1[8] = "TickVal";
   
   //-- signals
   Title1[colDB_RevSig] = "Reverse";
   /*Title1[9] = "Contin";
   Title1[10] = "DPTT";
   Title1[11] = "1UDCT";
   Title1[12] = "ACCT";*/

//   Title2[2] = "("+TimeToStr(TimeCurrent(),TIME_MINUTES)+")";
//   Title2[colDB_Spread]= "Spread";
   Title2[colDB_High]  = "High";
   Title2[colDB_Low]   = "Low";
   Title2[colDB_Close] = "Close";
   
   Title2[colDB_ST] = "last";
   Title2[colDB_NL] = "last";
   Title2[colDB_AC] = "[ 1]";
   Title2[colDB_AO] = "[ 1]";      
   Title2[colDB_RSI] = "[ 1]";
//   Title2[8] = "("+AccountCurrency()+")";
   //-- signals
   Title2[colDB_RevSig] = "signal";
   /*Title2[9] = "signal";
   Title2[10] = "signal";
   Title2[11] = "signal";
   Title2[12] = "signal";*/
   
   //---- x Columns   
   xCol[colDB_Pairs] = xLeftTitle;
   xCol[colDB_Spread]= xPrice;
   xCol[colDB_High]  = xCol[colDB_Spread] + colStep;
   xCol[colDB_Low]   = xCol[colDB_High] + colStep;
   xCol[colDB_Close] = xCol[colDB_Low] + colStep;
   //-- adjust xCol
   xCol[colDB_High]  = xCol[colDB_High] -10;
   xCol[colDB_Low]   = xCol[colDB_Low] -10;
   
   
   xScanner = xCol[colDB_Close] + colStep;
   xCol[colDB_ST] = xScanner;
   for (i=colDB_ST+1; i<nTitles; i++)
      xCol[i] = xCol[i-1] + colStep;   
   
   //---- y Rows
   yRow[0] = yTitle2 + rowStep;
   for (i=1; i<=NumberSymbols; i++)
      yRow[i] = yRow[i-1] + rowStep;   
   //---- CurrentTime   
   xCurrentTime = xLeftTitle; 
   yCurrentTime = yRow[NumberSymbols] + rowStep;  
}

/*
void Get_TickValues()
{
   int iCol = xCol[8];
   color dColor = colorTime;
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];
      
      string sTickValue = DoubleToStr(MarketInfo(sSymbol,MODE_TICKVALUE),2);
      SetLabelObject(sLabelCode+sSymbol+"_TickVal", sTickValue, dColor, iCol, yRow[i]);
   }
}*/


//+------------------------------------------------------------------+
//| Create Title
//+------------------------------------------------------------------+
void SetLabelObject(string sName, string sText, color dColor, int xx, int yy)
{
   ObjectCreate(sName, OBJ_LABEL, iWindow, 0, 0);
        ObjectSetText(sName,sText,10, "Arial Bold", dColor);
        ObjectSet(sName, OBJPROP_CORNER, iCorner);
        ObjectSet(sName, OBJPROP_XDISTANCE, xx);
        ObjectSet(sName, OBJPROP_YDISTANCE, yy);
}
/*
void SetPriceObject(string sName, string sText, color dColor, int xx, int yy)
{
   ObjectCreate(sName, OBJ_LABEL, iWindow, 0, 0);
        ObjectSetText(sName,sText,20, "Arial Bold", dColor);
        ObjectSet(sName, OBJPROP_CORNER, iCorner);
        ObjectSet(sName, OBJPROP_XDISTANCE, xx);
        ObjectSet(sName, OBJPROP_YDISTANCE, yy);
}*/

void Write_CurrentTime(int xx, int yy)
{
   string sTime = TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES);
   string sTimeFrame = Get_sPeriod(TimeFrame);
   string st = "(" + windowsName + "      "+sTime+"   TimeFrame=" + sTimeFrame + ")";
   SetLabelObject(sLabelCode+"time", st, colorTime, xx, yy);
}

void Show_TitlesLeft()
{
   for (int i=0; i<NumberSymbols; i++) { 
      string sSymbol = Pair[i];
      //-- Names
      SetLabelObject(sLabelCode+sSymbol, sSymbol, colorTitle, xLeftTitle, yRow[i]);
      string Spread = DoubleToStr(MarketInfo(sSymbol, MODE_SPREAD),0);
      SetLabelObject(sLabelCode+sSymbol+"_Spread", Spread, colorNeutralIndi, xCol[colDB_Spread], yRow[i]);
   }   
   //-- Show Prices
   Show_HighLowPrices();
   Show_OnlyPrices();
}

void Show_HighLowPrices()
{
   for (int i=0; i<NumberSymbols; i++) { 
      string sSymbol = Pair[i];
     
      //-- Prices
      int iDigits = MarketInfo(sSymbol,MODE_DIGITS);
      double dOpen = iOpen(sSymbol,TimeFrame,1);
      double dHigh = iHigh(sSymbol,TimeFrame,1);
      double dLow  = iLow(sSymbol,TimeFrame,1);
      double dClose = iClose(sSymbol,TimeFrame,1);      
      
      if (dClose > dOpen) color dColor = Green; else dColor = Red;      
      SetLabelObject(sLabelCode+Pair[i]+"_High", DoubleToStr(dHigh,iDigits),  dColor, xCol[colDB_High], yRow[i]);
      SetLabelObject(sLabelCode+Pair[i]+"_Low", DoubleToStr(dLow,iDigits),  dColor, xCol[colDB_Low], yRow[i]);
   }   
}


void Show_OnlyPrices()
{
   for (int i=0; i<NumberSymbols; i++) { 
      string sSymbol = Pair[i];
     
      //-- Prices
      int iDigits = MarketInfo(sSymbol,MODE_DIGITS);
      double dClose = iClose(sSymbol,TimeFrame,0);
      double dOpen = iOpen(sSymbol,TimeFrame,0);
      PairPrice[i] = dClose;
      if (dClose > dOpen) color dColor = Green; else dColor = Red;      
      SetLabelObject(sLabelCode+Pair[i]+"_Close", DoubleToStr(dClose,iDigits),  dColor, xCol[colDB_Close], yRow[i]);
   }   
}

void Show_TitlesUpper()   
{  
   int xx1, xx2;
   for (int i=1; i<nTitles; i++) {
      xx1 = xCol[i];
      xx2 = xx1;
      if (i == colDB_Spread) xx1 = xx1 - 15; // adjust xCol
      if (i == colDB_High)   xx1 = xx1 + 15; // adjust xCol
      if (i == colDB_Close)  xx1 = xx1 - 5;  // adjust xCol
      
      if (Title1[i] != "") 
        SetLabelObject(sLabelCode+"Title1_"+i, Title1[i],  colorTitle, xx1, yTitle1);
      if (Title2[i] != "")
        SetLabelObject(sLabelCode+"Title2_"+i, Title2[i],  colorTitle, xx2, yTitle2);        
   }      
}

//+------------------------------------------------------------------+
//| Set Arrows
//+------------------------------------------------------------------+
void SetArrowObject(string sName, int ArrowCode, int iHeight, color dColor, int xx, int yy)
{
   ObjectCreate(sName, OBJ_LABEL, iWindow, 0, 0);
   ObjectSetText(sName,CharToStr(ArrowCode),iHeight, "Wingdings", dColor);
        ObjectSet(sName, OBJPROP_CORNER, iCorner);
        ObjectSet(sName, OBJPROP_XDISTANCE, xx);
        ObjectSet(sName, OBJPROP_YDISTANCE, yy);
}

//####################################################################
//+------------------------------------------------------------------+
//|      Get PairList Names
//+------------------------------------------------------------------+
void Get_PairListNames()
{
   int i,j,k;
   string CurSymbol;
   
   for (i=0, j=0, k=1; i<24 && k>0;)
   {
      k=StringFind(PairsList,",",j);
      if (k==0) CurSymbol=StringSubstr(PairsList,j,0);
      else CurSymbol=StringSubstr(PairsList,j,k-j);
      CurSymbol = CurSymbol + SymbolSuffix;
      //---- check if the pair is allowable
      double dClose = iClose(CurSymbol,TimeFrame,0);      
      if (dClose > 0.0) {
         Pair[i]=CurSymbol;
         i++;
      }
     
      j=StringFind(PairsList,",",j)+1;
      if (j==0) break;
   }
   NumberSymbols = i;

   return;
}

//+------------------------------------------------------------------+
//    Get Default Otstup
//+------------------------------------------------------------------+
int Get_DefaultOtstup(string sSymbol)
{
   if (sSymbol == "AUDUSD"+SymbolSuffix) return(15);
   if (sSymbol == "EURUSD"+SymbolSuffix) return(15);
   if (sSymbol == "GBPUSD"+SymbolSuffix) return(20);
   if (sSymbol == "USDCAD"+SymbolSuffix) return(10);
   if (sSymbol == "USDCHF"+SymbolSuffix) return(15);
   if (sSymbol == "USDJPY"+SymbolSuffix) return(15);
   if (sSymbol == "GBPJPY"+SymbolSuffix) return(15);
   if (sSymbol == "GBPCHF"+SymbolSuffix) return(20);
   if (sSymbol == "EURGBP"+SymbolSuffix) return(15);
   if (sSymbol == "NZDUSD"+SymbolSuffix) return(10);
   if (sSymbol == "EURJPY"+SymbolSuffix) return(15);
   if (sSymbol == "EURCHF"+SymbolSuffix) return(20);
   if (sSymbol == "EURAUD"+SymbolSuffix) return(30);
   if (sSymbol == "EURCAD"+SymbolSuffix) return(20);
   return(-1);
}

//####################################################################
//+------------------------------------------------------------------+
//|      AO   Awesome Oscillator
//+------------------------------------------------------------------+
void Get_AwesomeOscillator(int iShift)
{
   int iCol = xCol[colDB_AO];
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];
      double dValue = function_AO_Oscillator(sSymbol, TimeFrame, iShift);

      if (dValue > 0) int iArrow = 217; else iArrow = 218;
      if (dValue > 0) color dColor = colorPlusIndi; else dColor = colorMinusIndi;
      SetArrowObject(sLabelCode+sSymbol+"_AO", iArrow, 10, dColor, iCol, yRow[i]);
      //-- signal
      if (dValue > 0) Signal[i][colAO] = 1; else Signal[i][colAO] = -1;
   }
}
   
double function_AO_Oscillator(string symbol, int timeframe, int shift)
{
   double iValue1 = iAO(symbol, TimeFrame, shift);
   double iValue2 = iAO(symbol, TimeFrame, shift+1);
   double iValue = iValue1 - iValue2;
   return(iValue);
}

//+------------------------------------------------------------------+
//|      AC   Williams Accelerator
//+------------------------------------------------------------------+
void Get_WilliamsAccelerator(int iShift)
{
   int iCol = xCol[colDB_AC];
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];
      double dValue = function_AC_Oscillator(sSymbol, TimeFrame, iShift);

      if (dValue > 0) int iArrow = 217; else iArrow = 218;
      if (dValue > 0) color dColor = colorPlusIndi; else dColor = colorMinusIndi;
      SetArrowObject(sLabelCode+sSymbol+"_AC", iArrow, 10, dColor, iCol, yRow[i]);
      //-- signal
      if (dValue > 0) Signal[i][colAC] = 1; else Signal[i][colAC] = -1;
   }
}
   
double function_AC_Oscillator(string symbol, int timeframe, int shift)
{
   double iValue1 = iAC(symbol, TimeFrame, shift);
   double iValue2 = iAC(symbol, TimeFrame, shift+1);
   double iValue = iValue1 - iValue2;
   return(iValue);
}


//####################################################################
//+------------------------------------------------------------------+
//|      ST  Silver Trend
//+------------------------------------------------------------------+
void Get_SilverTrend(int iShift)
{
   int iColN = xCol[colDB_ST];
   int iCol1 = iColN + 15;
   int iArrowN, iArrow1;
   color dColorN, dColor1;
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];
      int iValueN = function_SilverTrend(sSymbol, TimeFrame, iShift+50);
      int iValue1 = function_SilverTrend(sSymbol, TimeFrame, iShift);
      
      switch (iValueN) {
         case  0: iArrowN = 104; dColorN = colorNeutralIndi; Signal[i][colSTn] =  0; break;
         case  1: iArrowN = 217; dColorN = colorPlusIndi;    Signal[i][colSTn] =  1; break;
         case -1: iArrowN = 218; dColorN = colorMinusIndi;   Signal[i][colSTn] = -1; break;
      } 
      switch (iValue1) {
         case  0: iArrow1 = 251; dColor1 = colorNeutralIndi; Signal[i][colST1] =  0; break;
         case  1: iArrow1 = 217; dColor1 = colorPlusIndi;    Signal[i][colST1] =  1; break;
         case -1: iArrow1 = 218; dColor1 = colorMinusIndi;   Signal[i][colST1] = -1; break;
      }       

      SetArrowObject(sLabelCode+sSymbol+"_STN", iArrowN, 10, dColorN, iColN, yRow[i]);
      SetArrowObject(sLabelCode+sSymbol+"_ST1", iArrow1, 10, dColor1, iCol1, yRow[i]);
   }
}

int function_SilverTrend(string symbol, int timeframe, int shiftBar)
{
   int Otstup = Get_DefaultOtstup(symbol);
   int iSilverTrend = 0;
   
   //-- last ST 
   if (shiftBar == 1)  
   for (int SH=1; SH<=shiftBar; SH++) {
      int shiftHighest = iHighest(symbol,timeframe,MODE_HIGH,Period_SilverTrend,SH);
      double SHMax = iHigh(symbol, timeframe, shiftHighest);
      
      int shiftLowest = iLowest(symbol,timeframe,MODE_LOW,Period_SilverTrend,SH);
      double SHMin = iLow(symbol, timeframe, shiftLowest);
      
      //-- Long signal
      if (iClose(symbol, timeframe,SH)<=SHMin+(SHMax-SHMin)*Otstup/100.0)
         iSilverTrend = 1;
      
      //-- short signal
      if (iClose(symbol, timeframe,SH)>=SHMax-(SHMax-SHMin)*Otstup/100.0)
         iSilverTrend = -1;
      
      if (iSilverTrend != 0) {
         return(iSilverTrend);
      }
   } 
   
   //-- before last ST
   else
   for (SH=2; SH<=shiftBar; SH++) {
      shiftHighest = iHighest(symbol,timeframe,MODE_HIGH,Period_SilverTrend,SH);
      SHMax = iHigh(symbol, timeframe, shiftHighest);
      
      shiftLowest = iLowest(symbol,timeframe,MODE_LOW,Period_SilverTrend,SH);
      SHMin = iLow(symbol, timeframe, shiftLowest);
      
      //-- Long signal
      if (iClose(symbol, timeframe,SH)<=SHMin+(SHMax-SHMin)*Otstup/100.0)
         iSilverTrend = 1;
      
      //-- short signal
      if (iClose(symbol, timeframe,SH)>=SHMax-(SHMax-SHMin)*Otstup/100.0)
         iSilverTrend = -1;
      
      if (iSilverTrend != 0)
         return(iSilverTrend);
   }
}


//####################################################################
//+------------------------------------------------------------------+
//|      NL   NonLag MA
//+------------------------------------------------------------------+
void Get_NonLagMA(int iShift)
{ 
   int iColN = xCol[colDB_NL];
   int iCol1 = iColN + 15;
   int iArrowN, iArrow1, iValueN, iValue1;
   color dColorN, dColor1;
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];

      iValueN = function_NonLagMA(sSymbol, TimeFrame, iShift+50);
      iValue1 = function_NonLagMA(sSymbol, TimeFrame, iShift);
      switch (iValueN) {
         case  2: iArrowN = 217; dColorN = colorChangeNLMAup; Signal[i][colNLn] =  2; break; // 2 is change
         case -2: iArrowN = 218; dColorN = colorChangeNLMAdn; Signal[i][colNLn] = -2; break;
         case  1: iArrowN = 217; dColorN = colorPlusNLMA;     Signal[i][colNLn] =  1; break; // 1 is trend
         case -1: iArrowN = 218; dColorN = colorMinusNLMA;    Signal[i][colNLn] = -1; break;
      } 
      switch (iValue1) {
         case  2: iArrow1 = 217; dColor1 = colorChangeNLMAup; Signal[i][colNL1] =  2; break;
         case -2: iArrow1 = 218; dColor1 = colorChangeNLMAdn; Signal[i][colNL1] = -2; break;
         case  1: iArrow1 = 217; dColor1 = colorPlusNLMA;     Signal[i][colNL1] =  1; break;
         case -1: iArrow1 = 218; dColor1 = colorMinusNLMA;    Signal[i][colNL1] = -1; break;
      }     

      SetArrowObject(sLabelCode+sSymbol+"_NLN", iArrowN, 10, dColorN, iColN, yRow[i]);
      SetArrowObject(sLabelCode+sSymbol+"_NL1", iArrow1, 10, dColor1, iCol1, yRow[i]);
   }
}

int function_NonLagMA(string symbol, int timeframe, int shiftBar)
{
   int iNLMA_Trend = 0;
     
   for (int SH=1; SH<=shiftBar; SH++) {
      double dMABuffer0 = iCustom(symbol, timeframe, sNonLagMA_Name,
                       0,Period_NonLagMA,SH, 0,1,0,0,0,0, 0, 0);
      double dMABuffer1 = iCustom(symbol, timeframe, sNonLagMA_Name,
                       0,Period_NonLagMA,SH, 0,1,0,0,0,0, 0, 1);
      double dMABuffer2 = iCustom(symbol, timeframe, sNonLagMA_Name,
                       0,Period_NonLagMA,SH, 0,1,0,0,0,0, 0, 2);

      //-- last MA trend
      if (shiftBar ==1) {                 
         //-- long
         if (dMABuffer0 >= dMABuffer1 && dMABuffer1 >= dMABuffer2) return(1);
         if (dMABuffer0 >= dMABuffer1 && dMABuffer1 <= dMABuffer2) return(2);
      
         //-- short
         if (dMABuffer0 < dMABuffer1 && dMABuffer1 < dMABuffer2) return(-1);
         if (dMABuffer0 < dMABuffer1 && dMABuffer1 > dMABuffer2) return(-2);
      }
      //-- last MA trend change
      if (dMABuffer0 >= dMABuffer1 && dMABuffer1 <= dMABuffer2) return(2);
      if (dMABuffer0 < dMABuffer1 && dMABuffer1 > dMABuffer2) return(-2);
   }      
}

//####################################################################
//+------------------------------------------------------------------+
//|      RSI
//+------------------------------------------------------------------+
void Get_RSI(int iShift)   // RSI
{
   int iCol = xCol[colDB_RSI];
   int iArrow;
   color dColor;
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];

      double dValue = iRSI(sSymbol, TimeFrame, Period_RSI, PRICE_CLOSE, iShift);
      if (dValue>=50.0) int iValue = 1; else iValue = -1;      
      switch (iValue) {
         case  1: iArrow = 217; dColor = colorPlusIndi;  Signal[i][colRSI] =  1; break;
         case -1: iArrow = 218; dColor = colorMinusIndi; Signal[i][colRSI] = -1; break;
      } 

      SetArrowObject(sLabelCode+sSymbol+"_RSI", iArrow, 10, dColor, iCol, yRow[i]);
   }
}

//####################################################################
//+------------------------------------------------------------------+
//|      Reverse Signal
//+------------------------------------------------------------------+
void Get_ReverseSignal(int iShift)
{
   int iCol = xCol[colDB_RevSig];
   int iValue, iArrow, iHeight;
   color dColor;
   for (int i=0; i<NumberSymbols; i++) {
      if (PairPrice[i] == 0.0) return;
      string sSymbol = Pair[i];
      
      iValue = 0;
      //---- long signal;  2 is change(new),  1 is trend
      if (Signal[i][colSTn] == 1 || Signal[i][colST1] == 1) {
         if (Signal[i][colNL1] == 2) iValue = 2;
         if (Signal[i][colNL1] == 1) iValue = 1; 
      }         
               
      //---- short signal
      if (Signal[i][colSTn] == -1 || Signal[i][colST1] == -1) {
         if (Signal[i][colNL1] == -2) iValue = -2;
         if (Signal[i][colNL1] == -1) iValue = -1;
      }
      
      //-- write arrows
      switch (iValue) {
         case  0: iArrow = 251; dColor = colorNeutralIndi; iHeight = 10; break; // neutral
         case  1: iArrow = 236; dColor = colorPlusIndi;    iHeight = 10; break; // old signal
         case -1: iArrow = 238; dColor = colorMinusIndi;   iHeight = 10; break;
         case  2: iArrow = 233; dColor = colorPlusSignal;  iHeight = 12; break; // change(new) signal 
         case -2: iArrow = 234; dColor = colorMinusSignal; iHeight = 12; break;         
      } 
      SetArrowObject(sLabelCode+sSymbol+"_RevSig", iArrow, iHeight, dColor, iCol, yRow[i]);
      
      //-- write entry values for change(new) signals
      int xx = iCol + 15;
      if (iValue == 2 || iValue == -2) {
         switch (iValue) {
            case  2: string sValue = Get_EntryPrice(OP_BUY, sSymbol, TimeFrame);
               break; 
            case -2: sValue = Get_EntryPrice(OP_SELL, sSymbol, TimeFrame);
               break;         
         }          
         //-- Prices
         int iDigits = MarketInfo(sSymbol,MODE_DIGITS);
         double dClose = iClose(sSymbol,TimeFrame,1);
         double dOpen = iOpen(sSymbol,TimeFrame,1);
         if (dClose > dOpen) color dColorEntry = Green; else dColorEntry = Red;      
         SetLabelObject(sLabelCode+sSymbol+"_RevVal", sValue, dColorEntry, xx, yRow[i]);
      } else
      {
         SetLabelObject(sLabelCode+sSymbol+"_RevVal", " ", dColorEntry, xx, yRow[i]);
      }
   }
}

string Get_EntryPrice(int iOrderType, string symbol, string timeframe)
{   
   string sPrice;
   int iDigits   = MarketInfo(symbol, MODE_DIGITS);
   double dPoint = MarketInfo(symbol, MODE_POINT);
   
   switch (iOrderType)
   {
      case OP_BUY:         
         double Spread = MarketInfo(symbol, MODE_SPREAD) * dPoint;
         double dValue = iHigh(symbol, TimeFrame, 1) + 1.0*dPoint + Spread;
         sPrice = DoubleToStr(dValue, iDigits);
         if (SendAlert_ReverseSignals) function_SendAlert(iOrderType, symbol, sPrice, timeframe, Spread);
         return(sPrice);
         break;
      case OP_SELL:
         dValue = iLow(symbol, TimeFrame, 1) - 1.0*dPoint;
         sPrice = DoubleToStr(dValue, iDigits);
         if (SendAlert_ReverseSignals) function_SendAlert(iOrderType, symbol, sPrice, timeframe, Spread);
         return(sPrice);
         break;   
   }
}


//####################################################################
//+------------------------------------------------------------------+
//    function SendAlert
//+------------------------------------------------------------------+
void function_SendAlert(int iOrderType, string symbol, string sPrice, string timeframe, double spread)
{   
   string st, sTime;   
   string sPeriod = Get_sPeriod(TimeFrame);
   switch (iOrderType)
   {
      case OP_BUY:
         sTime  = TimeToStr(TimeCurrent(),TIME_MINUTES);  
         st = "Buy "+symbol + "  " + sPrice +  "  (Damon DashBoard ReverseSignal_" + sPeriod + "  " + sTime +")";
         break;
      case OP_SELL:
         sTime  = TimeToStr(TimeCurrent(),TIME_MINUTES);  
         st = "Sell "+symbol + "  " + sPrice +  "  (Damon DashBoard ReverseSignal_" + sPeriod + "  " + sTime +")";
         break;   
   }
   Alert(st);
}

string Get_sPeriod(int timeframe)
{
   if (timeframe == PERIOD_M1) return("M1");
   if (timeframe == PERIOD_M5) return("M5");
   if (timeframe == PERIOD_M15) return("M15");
   if (timeframe == PERIOD_M30) return("M30");
   if (timeframe == PERIOD_H1) return("H1");
   if (timeframe == PERIOD_H4) return("H4");
   if (timeframe == PERIOD_D1) return("D1");
   if (timeframe == PERIOD_W1) return("W1");
   if (timeframe == PERIOD_MN1) return("MN1");
}