#property copyright "FORALL"
#property version   "1.00"
#property strict
#property indicator_chart_window

#include <GuiFunctions.mqh>

int gFontSize = 12;
string gFontType = "Arial";
int gDefaultPeriod = 60;
color gButtonBack = clrLightBlue;
color gButtonOut  = clrWhite;
color gButtonText = clrBlue;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //DELETE ALL INDICATOR ON ALL WINDOW AND SUBWINDOW

   int NumSubWindows = ChartWindowsTotal(0);
   for(int y=0; y<=NumSubWindows; y++)
     {
      int total=ChartIndicatorsTotal(0,y);
      for(int x=0; x<=total; x++)
        {
        if(ChartIndicatorName(0,y,x)!="MenuCharts")
        {
         ChartIndicatorDelete(0,y,ChartIndicatorName(0,y,x));
         }
        }
     }
   ObjectsDeleteAll();

   //SET BACKGROUND IN BLACK
   setChartColorBackground(clrBlack);
   CreateGui();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void setChartColorBackground(color backgroundColor)
  {
   ChartSetInteger(_Symbol,CHART_COLOR_BACKGROUND,backgroundColor);
   ChartSetInteger(_Symbol,CHART_COLOR_CANDLE_BULL,backgroundColor);
   ChartSetInteger(_Symbol,CHART_COLOR_CANDLE_BEAR,backgroundColor);
  }

void CreateGui()
  {
   int buttonWidth = 200;
   int buttonHeigth = 40;
   int guiStartX = 50;
   int guiStartY = 50;
   double titleSize=2;
// colomn
   int col1= guiStartX;
   int col2= guiStartX*2+buttonWidth;
   int col3= guiStartX*3+buttonWidth*2;
   int col4= guiStartX*4+buttonWidth*3;
   int col5= guiStartX*5+buttonWidth*4;
   int col6= guiStartX*6+buttonWidth*5;
   int col7= guiStartX*7+buttonWidth*6;
   int col8= guiStartX*8+buttonWidth*7;
   int col9= guiStartX*9+buttonWidth*8;
// row
   double rowMultiplier = 1.4;
   int row1= guiStartY;
   int row2= buttonHeigth*(rowMultiplier*2);
   int row3= buttonHeigth*(rowMultiplier*3);
   int row4= buttonHeigth*(rowMultiplier*4);
   int row5= buttonHeigth*(rowMultiplier*5);
   int row6= buttonHeigth*(rowMultiplier*6);
   int row7= buttonHeigth*(rowMultiplier*7);
   int row8= buttonHeigth*(rowMultiplier*8);
   int row9= buttonHeigth*(rowMultiplier*9);
   int row10= buttonHeigth*(rowMultiplier*10);
   int row11= buttonHeigth*(rowMultiplier*11);
   int row12= buttonHeigth*(rowMultiplier*12);
   int row13= buttonHeigth*(rowMultiplier*13);
   int row14= buttonHeigth*(rowMultiplier*14);
   int row15= buttonHeigth*(rowMultiplier*15);
   int row16= buttonHeigth*(rowMultiplier*16);
   int row17= buttonHeigth*(rowMultiplier*17);
   int row18= buttonHeigth*(rowMultiplier*18);
   int row19= buttonHeigth*(rowMultiplier*19);
   int row20= buttonHeigth*(rowMultiplier*20);
   int row21= buttonHeigth*(rowMultiplier*21);
    int row22= buttonHeigth*(rowMultiplier*22);
     int row23= buttonHeigth*(rowMultiplier*23);
      int row24= buttonHeigth*(rowMultiplier*24);
// FX
   createText("FX","FX",gFontSize*titleSize,clrWhite,col1,row1);
   createText("EUR","EUR",gFontSize,gButtonOut,col2,row1);
   createText("GBP","GBP",gFontSize,gButtonOut,col3,row2);
   createText("AUD","AUD",gFontSize,gButtonOut,col4,row3);
   createText("NZD","NZD",gFontSize,gButtonOut,col5,row4);
   createText("USD","USD",gFontSize,gButtonOut,col6,row5);
   createText("CAD","CAD",gFontSize,gButtonOut,col7,row6);
   createText("CHF","CHF",gFontSize,gButtonOut,col8,row7);
   createText("JPY","JPY",gFontSize,gButtonOut,col9,row8);
   createButton("EURGBP",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row2,"EURGBP",0,gFontSize,gFontType);
   createButton("EURAUD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row3,"EURAUD",0,gFontSize,gFontType);
   createButton("GBPAUD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row3,"GBPAUD",0,gFontSize,gFontType);
   createButton("EURNZD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row4,"EURNZD",0,gFontSize,gFontType);
   createButton("GBPNZD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row4,"GBPNZD",0,gFontSize,gFontType);
   createButton("AUDNZD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row4,"AUDNZD",0,gFontSize,gFontType);
   createButton("EURUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row5,"EURUSD",0,gFontSize,gFontType);
   createButton("GBPUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row5,"GBPUSD",0,gFontSize,gFontType);
   createButton("AUDUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row5,"AUDUSD",0,gFontSize,gFontType);
   createButton("NZDUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row5,"NZDUSD",0,gFontSize,gFontType);
   createButton("EURCAD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row6,"EURCAD",0,gFontSize,gFontType);
   createButton("GBPCAD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row6,"GBPCAD",0,gFontSize,gFontType);
   createButton("AUDCAD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row6,"AUDCAD",0,gFontSize,gFontType);
   createButton("NZDCAD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row6,"NZDCAD",0,gFontSize,gFontType);
   createButton("USDCAD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col6,row6,"USDCAD",0,gFontSize,gFontType);
   createButton("EURCHF",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row7,"EURCHF",0,gFontSize,gFontType);
   createButton("GBPCHF",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row7,"GBPCHF",0,gFontSize,gFontType);
   createButton("AUDCHF",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row7,"AUDCHF",0,gFontSize,gFontType);
   createButton("NZDCHF",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row7,"NZDCHF",0,gFontSize,gFontType);
   createButton("USDCHF",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col6,row7,"USDCHF",0,gFontSize,gFontType);
   createButton("CADCHF",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col7,row7,"CADCHF",0,gFontSize,gFontType);
   createButton("EURJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col2,row8,"EURJPY",0,gFontSize,gFontType);
   createButton("GBPJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row8,"GBPJPY",0,gFontSize,gFontType);
   createButton("AUDJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row8,"AUDJPY",0,gFontSize,gFontType);
   createButton("NZDJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row8,"NZDJPY",0,gFontSize,gFontType);
   createButton("USDJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col6,row8,"USDJPY",0,gFontSize,gFontType);
   createButton("CADJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col7,row8,"CADJPY",0,gFontSize,gFontType);
   createButton("CHFJPY",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col8,row8,"CHFJPY",0,gFontSize,gFontType);
   
   // INDICES
   createText("INDICES","INDICES",gFontSize*titleSize,clrWhite,col1,row9);
   
   createText("AMERICAS","AMERICAS",gFontSize,gButtonOut,col2,row10);
   
   createButton("US500",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row10,"US500",0,gFontSize,gFontType);
   createButton("US30",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row10,"US30",0,gFontSize,gFontType);
   createButton("NAS100",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row10,"NAS100",0,gFontSize,gFontType);
    createButton("USDX",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col6,row10,"USDX",0,gFontSize,gFontType);
    createButton("CA60",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col7,row10,"CA60",0,gFontSize,gFontType);
   
   createText("EUROPE","EUROPE",gFontSize,gButtonOut,col2,row11);
   createButton("UK100",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row11,"UK100",0,gFontSize,gFontType);
   createButton("E35",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row11,"E35",0,gFontSize,gFontType);
    createButton("EUSTX50",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row11,"EUSTX50",0,gFontSize,gFontType);
   createButton("FRA40",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col6,row11,"FRA40",0,gFontSize,gFontType);
  createButton("NETH25",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col7,row11,"NETH25",0,gFontSize,gFontType);
   createButton("GER40",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col8,row11,"GER40",0,gFontSize,gFontType);
   
   
   
  createText("ASIA","ASIA / AUSTRALIA",gFontSize,gButtonOut,col2,row12);
   createButton("JPN225",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row12,"JPN225",0,gFontSize,gFontType);
   createButton("HK50",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row12,"HK50",0,gFontSize,gFontType);
   createButton("CHINAH",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row12,"CHINAH",0,gFontSize,gFontType);
  createButton("AUS200",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col6,row12,"AUS200",0,gFontSize,gFontType);
  
  createText("METALS","METALS",gFontSize*titleSize,clrWhite,col1,row13);
  createText("GOLD","GOLD",gFontSize,gButtonOut,col2,row14);
    createButton("XAUUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row14,"XAUUSD",0,gFontSize,gFontType);
   createButton("XAUEUR",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row14,"XAUEUR",0,gFontSize,gFontType);
    createButton("XAUAUD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col5,row14,"XAUAUD",0,gFontSize,gFontType);
    
    createText("SILVER","SILVER",gFontSize,gButtonOut,col2,row15);
    createButton("XAGUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row15,"XAGUSD",0,gFontSize,gFontType);
    createButton("XAGEUR",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row15,"XAGEUR",0,gFontSize,gFontType);
    createText("ALUM / COPPER","ALUM / COPPER",gFontSize,gButtonOut,col2,row16);
     createButton("XALUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row16,"XALUSD",0,gFontSize,gFontType);
      createButton("XCUUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row16,"XCUUSD",0,gFontSize,gFontType);
   createText("NICKEL / LEAD","NICKEL / LEAD",gFontSize,gButtonOut,col2,row17);
   createButton("XNIUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row17,"XNIUSD",0,gFontSize,gFontType);
    createButton("XPBUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row17,"XPBUSD",0,gFontSize,gFontType);
    
    createText("PALLADIUM / ZINC","PALLADIUM / ZINC",gFontSize,gButtonOut,col2,row18);
    createButton("XPDUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row18,"XPDUSD",0,gFontSize,gFontType);
    createButton("XZNUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row18,"XZNUSD",0,gFontSize,gFontType);
    
    createText("PLATINIUM","PLATINIUM",gFontSize,gButtonOut,col2,row19);
     createButton("XPTUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row19,"XPTUSD",0,gFontSize,gFontType);
    
   createText("ENERGY","ENERGY",gFontSize*titleSize,clrWhite,col1,row20);
   createText("NAT GAS / OIL","NAT GAS / OIL",gFontSize,gButtonOut,col2,row21);
   createButton("XNGUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row21,"XNGUSD",0,gFontSize,gFontType);
    createButton("XBRUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col4,row21,"XBRUSD",0,gFontSize,gFontType);  
      
    createText("WEST TEXAS INTER","WEST TEXAS INT",gFontSize,gButtonOut,col2,row22);
    createButton("XTIUSD",gButtonBack,gButtonOut,gButtonText,buttonWidth,buttonHeigth,col3,row22,"XTIUSD",0,gFontSize,gFontType);
    
    
   
    
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
// minimize
   if(id == CHARTEVENT_OBJECT_CLICK)
     {
     
      LoadChart(sparam);
      
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void LoadChart(string ticker)
  {
   string fileName = ticker+".tpl";
   long newChart = ChartOpen(ticker,gDefaultPeriod);
   ChartApplyTemplate(newChart,fileName);
  }

int ChartWindowsTotal(const long chart_ID=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,CHART_WINDOWS_TOTAL,0,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }
//+------------------------------------------------------------------+
