//+------------------------------------------------------------------+
//|                                         Damon smDashBoard_v1.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                |
//--------------------------------------------------------------------

#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
//--------------------------------------------------------------------

//---- constants
string windowsName = "Damon smDashBoard_v1";
string sLabelCode = "ATPScanner_";
string sNonLagMA_Name = "Damon smNonLagMA_v1";
int TimeFrame = PERIOD_D1;
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;

//---- 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 colorPlusNLMA = SkyBlue;
color colorMinusNLMA = Tomato;
color colorChangeNLMA = Gold;

//---- 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;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   iCorner = Corner_LeftUp;

   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(300);
//   Delete_TextObjects();   
//----
   return(0);
}

void Delete_TextObjects()
{
   ObjectsDeleteAll(0,OBJ_LABEL);
   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;

   Get_PairListNames();   
   Set_Initialisations();
   //---- titles
   Show_TitlesUpper();
   Show_TitlesLeft();   
//----
   Get_SilverTrend(1);    // ST
   Get_NonLagMA(1);       // NL 
   
   Get_WilliamsAccelerator(1); // AC
   Get_AwesomeOscillator(1);   // AO

   Write_CurrentTime(xCurrentTime, yCurrentTime);
//----
   return(0);
}
//+------------------------------------------------------------------+

//####################################################################

//+------------------------------------------------------------------+
//|   Initialisations
//+------------------------------------------------------------------+
int yTitle1 = 30;
int yTitle2 = 50;
int nTitles = 20;
int xLeftTitle = 20;
int xPrice = 100;
int xScanner = 180;

int rowStep = 20;
int colStep = 50;

void Set_Initialisations()
{
   int i;
   Title1[1] = "Pairs";
   Title1[2] = "Price";
   Title1[3] = "ST";
   Title1[4] = "NL";
   Title1[5] = "AC";
   Title1[6] = "AO";      

   Title2[3] = "last";
   Title2[4] = "last";
   
   //---- x Columns   
   xCol[1] = xLeftTitle;
   xCol[2] = xPrice;
   xCol[3] = xScanner;
   for (i=4; 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;  
}

//+------------------------------------------------------------------+
//| 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);
   SetLabelObject(sLabelCode+"time", "(Damon smDashBoard      "+sTime+")", 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]);
      
      //-- 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]+"_Price", DoubleToStr(dClose,iDigits),  dColor, xPrice, yRow[i]);      
   }   
}

void Show_TitlesUpper()   
{  
   for (int i=1; i<nTitles; i++) {
      if (Title1[i] != "")
        SetLabelObject(sLabelCode+"Title1_"+i, Title1[i],  colorTitle, xCol[i], yTitle1);
      if (Title2[i] != "")
        SetLabelObject(sLabelCode+"Title2_"+i, Title2[i],  colorTitle, xCol[i], 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 Cur;
   
   for (i=0, j=0, k=1; i<24 && k>0;)
   {
      k=StringFind(PairsList,",",j);
      if (k==0) Cur=StringSubstr(PairsList,j,0);
      else Cur=StringSubstr(PairsList,j,k-j);
      
      Pair[i]=Cur;
      i++;
     
      j=StringFind(PairsList,",",j)+1;
      if (j==0) break;
   }
   NumberSymbols = i;

   return;
}

//+------------------------------------------------------------------+
//    Get Default Otstup
//+------------------------------------------------------------------+
int Get_DefaultOtstup(string sSymbol)
{
   if (sSymbol == "AUDUSD") return(15);
   if (sSymbol == "EURUSD") return(15);
   if (sSymbol == "GBPUSD") return(20);
   if (sSymbol == "USDCAD") return(10);
   if (sSymbol == "USDCHF") return(15);
   if (sSymbol == "USDJPY") return(15);
   if (sSymbol == "GBPJPY") return(15);
   if (sSymbol == "GBPCHF") return(20);
   if (sSymbol == "EURGBP") return(15);
   if (sSymbol == "NZDUSD") return(10);
   if (sSymbol == "EURJPY") return(15);
   if (sSymbol == "EURCHF") return(20);
   if (sSymbol == "EURAUD") return(30);
   if (sSymbol == "EURCAD") return(20);   
   return(-1);
}

//####################################################################
//+------------------------------------------------------------------+
//|      Awesome Oscillator
//+------------------------------------------------------------------+
void Get_AwesomeOscillator(int iShift)
{
   int iCol = xCol[6];
   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]);
   }
}
   
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);
}

//+------------------------------------------------------------------+
//|      Williams Accelerator
//+------------------------------------------------------------------+
void Get_WilliamsAccelerator(int iShift)
{
   int iCol = xCol[5];
   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]);
   }
}
   
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);
}


//####################################################################
//+------------------------------------------------------------------+
//|      Silver Trend
//+------------------------------------------------------------------+
void Get_SilverTrend(int iShift)
{
   int iColN = xCol[3];
   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; break;
         case  1: iArrowN = 217; dColorN = colorPlusIndi; break;
         case -1: iArrowN = 218; dColorN = colorMinusIndi;break;
      } 
      switch (iValue1) {
         case  0: iArrow1 = 251; dColor1 = colorNeutralIndi; break;
         case  1: iArrow1 = 217; dColor1 = colorPlusIndi; break;
         case -1: iArrow1 = 218; dColor1 = colorMinusIndi;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;
     
   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_HIGH,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);
      }
   }      
}


//####################################################################
//+------------------------------------------------------------------+
//|      NonLag MA
//+------------------------------------------------------------------+
void Get_NonLagMA(int iShift)
{
   int iColN = xCol[4];
   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);
//if (sSymbol == "GBPJPY")
//Print("Price =",PairPrice[i], "  Value=",iValue1);      
      switch (iValueN) {
         case  2: iArrowN = 217; dColorN = colorChangeNLMA; break;
         case -2: iArrowN = 218; dColorN = colorChangeNLMA; break;
         case  1: iArrowN = 217; dColorN = colorPlusNLMA; break;
         case -1: iArrowN = 218; dColorN = colorMinusNLMA;break;
      } 
      switch (iValue1) {
         case  2: iArrow1 = 217; dColor1 = colorChangeNLMA; break;
         case -2: iArrow1 = 218; dColor1 = colorChangeNLMA; break;
         case  1: iArrow1 = 217; dColor1 = colorPlusNLMA; break;
         case -1: iArrow1 = 218; dColor1 = colorMinusNLMA;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);

//if (symbol == "GBPJPY")
//Print("MABuffer=",dMABuffer0,"  Buffer1=",dMABuffer1, "  Buffer2=",dMABuffer2);
      //-- 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);
/*                       
      double dUpBuffer = iCustom(symbol, timeframe, sNonLagMA_Name,
                       0,Period_NonLagMA,SH, 0,1,0,0,0,0, 1);
      double dDnBuffer = iCustom(symbol, timeframe, sNonLagMA_Name,
                       0,Period_NonLagMA,SH, 0,1,0,0,0,0, 2);                       
*/

/*
double MABuffer[];
double UpBuffer[];
double DnBuffer[];
//---- input parameters ----------------------------------------------
extern int     Price          = 0;  //Apply to Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical price;6-Weighted Close) 
extern int     Length         = 9;  //Period of NonLagMA
extern int     Displace       = 0;  //DispLace or Shift 
extern double  PctFilter      = 0;  //Dynamic filter in decimal
extern int     Color          = 1;  //Switch of Color mode (1-color)  
extern int     ColorBarBack   = 0;  //Bar back for color mode
extern double  Deviation      = 0;  //Up/down deviation        
extern int     AlertMode      = 0;  //Sound Alert switch (0-off,1-on) 
extern int     WarningMode    = 0;  //Sound Warning switch(0-off,1-on) 
//--------------------------------------------------------------------*/                       
      
      /*
      //-- Long signal
      if (dUpBuffer != EMPTY_VALUE) {
         if (SH == 1) iNLMA_Trend = 1;
      }
      
      //-- short signal
      if (dDnBuffer != EMPTY_VALUE) {
         if (SH == 1) iNLMA_Trend = -1;
      }*/
      
      if (iNLMA_Trend != 0) {
         return(iNLMA_Trend);
      }
   }      
}