//+------------------------------------------------------------------+
//|                                      FXTT_MTF_BollingerBands.mq4 |
//|                                  Copyright 2016, Carlos Oliveira |
//|                                         http://carlosoliveira.me |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Carlos Oliveira"
#property link      "https://www.forextradingtools.eu/?utm_campaign=properties.indicator&utm_medium=special&utm_source=mt4terminal"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 54

#include <Controls\Dialog.mqh>
#include <Controls\CheckGroup.mqh>

extern int FMAPeriod=50;                                    //Fast MA Period
extern int FMAShift=0;                                      //Fast MA shift
extern ENUM_MA_METHOD FMAMethod = MODE_SMA;                 //Fast MA Method
extern ENUM_APPLIED_PRICE FMAAppliedPrice = PRICE_CLOSE;    //Fast MA Applied Price
input string Group1; //---------------------------------------------------
extern int MMAPeriod=100;                                   //Middle MA Period
extern int MMAShift=0;                                      //Middle MA shift
extern ENUM_MA_METHOD MMAMethod = MODE_SMA;                 //Middle MA Method
extern ENUM_APPLIED_PRICE MMAAppliedPrice = PRICE_CLOSE;    //Middle MA Applied Price
input string Group2; //---------------------------------------------------
extern int SMAPeriod=200;                                   //Slow MA Period
extern int SMAShift=0;                                      //Slow MA shift
extern ENUM_MA_METHOD SMAMethod = MODE_SMA;                 //Slow MA Method
extern ENUM_APPLIED_PRICE SMAAppliedPrice = PRICE_CLOSE;    //Slow MA Applied Price

input string Group2_1; //---------------------------------------------------
extern int SMAPeriod4=10;                                   //Fourth MA Period
extern int SMAShift4=0;                                      //Fourth MA shift
extern ENUM_MA_METHOD SMAMethod4 = MODE_SMA;                 //Fourth MA Method
extern ENUM_APPLIED_PRICE SMAAppliedPrice4 = PRICE_CLOSE;    //Fourth MA Applied Price


input string Group2_2; //---------------------------------------------------
extern int SMAPeriod5=20;                                   //Fifth MA Period
extern int SMAShift5=0;                                      //Fifth MA shift
extern ENUM_MA_METHOD SMAMethod5 = MODE_SMA;                 //Fifth MA Method
extern ENUM_APPLIED_PRICE SMAAppliedPrice5 = PRICE_CLOSE;    //Fifth MA Applied Price


input string Group2_3; //---------------------------------------------------
extern int SMAPeriod6=35;                                   //Sixth MA Period
extern int SMAShift6=0;                                      //Sixth MA shift
extern ENUM_MA_METHOD SMAMethod6 = MODE_SMA;                 //Sixth MA Method
extern ENUM_APPLIED_PRICE SMAAppliedPrice6 = PRICE_CLOSE;    //Sixth MA Applied Price




input string Group3; //---------------------------------------------------
extern ENUM_LINE_STYLE UpperStyle = STYLE_DOT;              //Fast MA line style
extern int UpperLineWidth = 1;                              //Fast MA line width
extern color UpperLineColor = clrTomato;                    //Fast MA line color
input string Group4; //---------------------------------------------------
extern ENUM_LINE_STYLE MainStyle = STYLE_DOT;               //Middle MA line style
extern int MainLineWidth = 1;                               //Middle MA line style
extern color MainLineColor=clrMediumSeaGreen;               //Middle MA line style
input string Group5; //---------------------------------------------------
extern ENUM_LINE_STYLE LowerStyle = STYLE_DOT;              //Slow MA line style
extern int LowerLineWidth = 1;                              //Slow MA line style
extern color LowerLineColor = clrPurple;                    //Slow MA line style


input string Group5_1; //---------------------------------------------------
extern ENUM_LINE_STYLE LowerStyle4 = STYLE_DOT;              //Fourth MA line style
extern int LowerLineWidth4 = 1;                              //Fourth MA line style
extern color LowerLineColor4 = clrWhite;                     //Fourth MA line style

input string Group5_2; //---------------------------------------------------
extern ENUM_LINE_STYLE LowerStyle5 = STYLE_DOT;              //Fifth MA line style
extern int LowerLineWidth5 = 1;                              //Fifth MA line style
extern color LowerLineColor5 = clrGold;                      //Fifth MA line style

input string Group5_3; //---------------------------------------------------
extern ENUM_LINE_STYLE LowerStyle6 = STYLE_DOT;              //Sixth MA line style
extern int LowerLineWidth6 = 1;                              //Sixth MA line style
extern color LowerLineColor6 = clrRoyalBlue;                 //Sixth MA line style


//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
//--- indents and gaps
#define OBJPREFIX                            "MTF Six MA" 
#define INDENT_LEFT                         (11)      // indent from left (with allowance for border width)
#define INDENT_TOP                          (11)      // indent from top (with allowance for border width)
#define INDENT_RIGHT                        (11)      // indent from right (with allowance for border width)
#define INDENT_BOTTOM                       (11)      // indent from bottom (with allowance for border width)
#define CONTROLS_GAP_X                      (5)       // gap by X coordinate
#define CONTROLS_GAP_Y                      (5)       // gap by Y coordinate
//--- for group controls
#define GROUP_WIDTH                         (230)     // size by X coordinate
#define GROUP_HEIGHT                        (57)      // size by Y coordinate

string  DataFileName="data.bin";                      // File name
string  DataDirectoryName="MTFTMA";                   // Folder name
//+------------------------------------------------------------------+
//| Class CPanelDialog                                               |
//| Usage: main dialog of the SimplePanel application                |
//+------------------------------------------------------------------+
class CPanelDialog : public CAppDialog
  {
private:
   CCheckGroup       m_check_group;                   // the check box group object   
public:
   bool              m_M1;
   bool              m_M5;
   bool              m_M15;
   bool              m_M30;
   bool              m_H1;
   bool              m_H4;
   bool              m_D1;
   bool              m_W1;
   bool              m_MN1;

                     CPanelDialog(void);
                    ~CPanelDialog(void);
   //--- create
   virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
   //--- chart event handler
   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
   int               remember_top, remember_left; 
   bool              NoPanelMaximization;
   void              HideShowMaximize(bool max);
   void              WriteIndicatorsData(void);
   void              ReadIndicatorsData(void);
   void              DrawIndicatorsData(void);
   virtual void Maximize();
   virtual void Minimize();
   void              SetMultipleIndexStyle(int idx1,int idx2,int idx3,int style);
protected:
   //--- create dependent controls   
   bool              CreateCheckGroup(void);
   //--- internal event handlers
   virtual bool      OnResize(void);
    
   //--- handlers of the dependent controls events   
   void              OnChangeCheckGroup(void);
   //-- Draw the text labels   
   void              DrawLabels();
   bool              OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam);
  };
  
//+------------------------------------------------------------------+
//| Event Handling                                                   |
//+------------------------------------------------------------------+
EVENT_MAP_BEGIN(CPanelDialog)
ON_EVENT(ON_CHANGE,m_check_group,OnChangeCheckGroup)
ON_OTHER_EVENTS(OnDefault)
EVENT_MAP_END(CAppDialog)

void CPanelDialog::Minimize()
{
    CAppDialog::Minimize();
    if (remember_left != -1) Move(remember_left, remember_top);
}

// Processes click on the panel's Maximize button of the panel.
void CPanelDialog::Maximize()
{
    if (!NoPanelMaximization) CAppDialog::Maximize();
    else if (m_minimized) CAppDialog::Minimize();

    //ShowSelectedTab();

    if (remember_left != -1) Move(remember_left, remember_top);
}

void CPanelDialog::HideShowMaximize(bool max = true)
{
    // Remember the panel's location.
    remember_left = Left(); 
    remember_top = Top();

    Hide();
    Show();
    if (!max) NoPanelMaximization = true;
    else NoPanelMaximization = false;
    Maximize();
}
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CPanelDialog::CPanelDialog(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CPanelDialog::~CPanelDialog(void)
  {
   WriteIndicatorsData();
  }
  
//+------------------------------------------------------------------+
//| Handler of resizing                                              |
//+------------------------------------------------------------------+
bool CPanelDialog::OnResize(void)
  {
         
//--- call method of parent class
   if(!CAppDialog::OnResize()) return(false);
//--- succeed
   return(true);
  }  
//+------------------------------------------------------------------+
//| Create                                                           |
//+------------------------------------------------------------------+
bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  {//aici
   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
      return(false);
//--- create dependent controls   
   if(!CreateCheckGroup())
      return(false);

   m_M1=false;
   m_M5=false;
   m_M15=false;
   m_M30=false;
   m_H1=false;
   m_H4=false;
   m_D1=false;
   m_W1=false;
   m_MN1=false;


   remember_left = 10;
   remember_top = 10;
    
   ReadIndicatorsData();

   m_check_group.Check(0, m_M1);
   m_check_group.Check(1, m_M5);
   m_check_group.Check(2, m_M15);
   m_check_group.Check(3, m_M30);
   m_check_group.Check(4,m_H1);
   m_check_group.Check(5,m_H4);
   m_check_group.Check(6,m_D1);
   m_check_group.Check(7,m_W1);
   m_check_group.Check(8,m_MN1);

//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//| Create the "CheckGroup" element                                  |
//+------------------------------------------------------------------+
bool CPanelDialog::CreateCheckGroup(void)
  {//aici

   if(!m_check_group.Create(m_chart_id,m_name+"CheckGroup",m_subwin,0,0,112,170))
      return(false);
   if(!Add(m_check_group))
      return(false);

   if(!m_check_group.AddItem("M1",1<<0))
      return(false);
   if(!m_check_group.AddItem("M5",1<<1))
      return(false);
   if(!m_check_group.AddItem("M15",1<<2))
      return(false);
   if(!m_check_group.AddItem("M30",1<<3))
      return(false);
   if(!m_check_group.AddItem("H1",1<<4))
      return(false);
   if(!m_check_group.AddItem("H4",1<<5))
      return(false);
   if(!m_check_group.AddItem("D1",1<<6))
      return(false);
   if(!m_check_group.AddItem("W1",1<<7))
      return(false);
   if(!m_check_group.AddItem("MN1",1<<8))

      return(false);
//--- succeed
   return(true);
  }
  
   
    
 
//+------------------------------------------------------------------+
//| Event handler                                                    |
//+------------------------------------------------------------------+
void CPanelDialog::OnChangeCheckGroup(void)
  {
   m_M1=m_check_group.Check(0);
   m_M5=m_check_group.Check(1);
   m_M15=m_check_group.Check(2);
   m_M30=m_check_group.Check(3);
   m_H1=m_check_group.Check(4);
   m_H4=m_check_group.Check(5);
   m_D1=m_check_group.Check(6);
   m_W1=m_check_group.Check(7);
   m_MN1=m_check_group.Check(8);

   DrawIndicatorsData();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CPanelDialog::SetMultipleIndexStyle(int idx1,int idx2,int idx3,int style)
  {
   SetIndexStyle(idx1,style);
   SetIndexStyle(idx2,style);
   SetIndexStyle(idx3,style);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CPanelDialog::DrawIndicatorsData()
  {

   if(m_MN1 && _Period<=PERIOD_MN1){
      SetMultipleIndexStyle(0,1,2,DRAW_LINE);
      SetMultipleIndexStyle(3,4,5,DRAW_LINE);}  
   else{
      SetMultipleIndexStyle(0,1,2,DRAW_NONE);
      SetMultipleIndexStyle(3,4,5,DRAW_NONE);} 
 
   if(m_W1 && _Period<=PERIOD_W1){
      SetMultipleIndexStyle(6,7,8,DRAW_LINE);
      SetMultipleIndexStyle(9,10,11,DRAW_LINE);}  
   else{
      SetMultipleIndexStyle(6,7,8,DRAW_NONE);
      SetMultipleIndexStyle(9,10,11,DRAW_NONE);}
      
   if(m_D1 && _Period<=PERIOD_D1){
      SetMultipleIndexStyle(12,13,14,DRAW_LINE);
      SetMultipleIndexStyle(15,16,17,DRAW_LINE);}   
   else{
      SetMultipleIndexStyle(12,13,14,DRAW_NONE);
      SetMultipleIndexStyle(15,16,17,DRAW_NONE);}
      
   if(m_H4 && _Period<=PERIOD_H4){
      SetMultipleIndexStyle(18,19,20,DRAW_LINE);
      SetMultipleIndexStyle(21,22,23,DRAW_LINE);}    
   else{
      SetMultipleIndexStyle(18,19,20,DRAW_NONE);
      SetMultipleIndexStyle(21,22,23,DRAW_NONE);}
      
   if(m_H1 && _Period<=PERIOD_H1){
      SetMultipleIndexStyle(24,25,26,DRAW_LINE);
      SetMultipleIndexStyle(27,28,29,DRAW_LINE);}
   else{
      SetMultipleIndexStyle(24,25,26,DRAW_NONE);
      SetMultipleIndexStyle(27,28,29,DRAW_NONE);}
     
      
   if(m_M30 && _Period<=PERIOD_M30){
      SetMultipleIndexStyle(30,31,32,DRAW_LINE);
      SetMultipleIndexStyle(33,34,35,DRAW_LINE);}
   else{
      SetMultipleIndexStyle(30,31,32,DRAW_NONE);
      SetMultipleIndexStyle(33,34,35,DRAW_NONE);}
      

   if(m_M15 && _Period<=PERIOD_M15){
      SetMultipleIndexStyle(36,37,38,DRAW_LINE);
      SetMultipleIndexStyle(39,40,41,DRAW_LINE);}
   else{
      SetMultipleIndexStyle(36,37,38,DRAW_NONE);
      SetMultipleIndexStyle(39,40,41,DRAW_NONE);}
      
   if(m_M5 && _Period<=PERIOD_M5){
      SetMultipleIndexStyle(42,43,44,DRAW_LINE);
      SetMultipleIndexStyle(45,46,47,DRAW_LINE);}
   else{
      SetMultipleIndexStyle(42,43,44,DRAW_NONE);
      SetMultipleIndexStyle(45,46,47,DRAW_NONE);}
      
       

   if(m_M1 && _Period<=PERIOD_M1){
      SetMultipleIndexStyle(48,49,50,DRAW_LINE);
      SetMultipleIndexStyle(51,52,53,DRAW_LINE);}
   else{
      
      SetMultipleIndexStyle(48,49,50,DRAW_NONE);
      SetMultipleIndexStyle(51,52,53,DRAW_NONE);}
 
   DrawLabels();
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CPanelDialog::DrawLabels()
  {
   string fastText=" "+IntegerToString(FMAPeriod)+" MA";
   string middleText=" "+IntegerToString(MMAPeriod)+" MA";
   string slowText=" "+IntegerToString(SMAPeriod)+" MA";
   
   string fourthText=" "+IntegerToString(SMAPeriod4)+" MA";
   string fifthText=" "+IntegerToString(SMAPeriod5)+" MA";
   string sixthText=" "+IntegerToString(SMAPeriod6)+" MA";

   DrawPriceLabel(m_M1 && _Period<=PERIOD_M1,lblM1h,bufferM1FMA[0],"M1"+fastText,UpperLineColor);
   DrawPriceLabel(m_M1 && _Period<=PERIOD_M1,lblM1m,bufferM1MMA[0],"M1"+middleText,MainLineColor);
   DrawPriceLabel(m_M1 && _Period<=PERIOD_M1,lblM1l,bufferM1SMA[0],"M1"+slowText,LowerLineColor);
   DrawPriceLabel(m_M1 && _Period<=PERIOD_M1,lblM1_4,bufferM1_4[0],"M1"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_M1 && _Period<=PERIOD_M1,lblM1_5,bufferM1_5[0],"M1"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_M1 && _Period<=PERIOD_M1,lblM1_6,bufferM1_6[0],"M1"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_M5 && _Period<=PERIOD_M5,lblM5h,bufferM5FMA[0],"M5"+fastText,UpperLineColor);
   DrawPriceLabel(m_M5 && _Period<=PERIOD_M5,lblM5m,bufferM5MMA[0],"M5"+middleText,MainLineColor);
   DrawPriceLabel(m_M5 && _Period<=PERIOD_M5,lblM5l,bufferM5SMA[0],"M5"+slowText,LowerLineColor);
   DrawPriceLabel(m_M5 && _Period<=PERIOD_M5,lblM5_4,bufferM5_4[0],"M5"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_M5 && _Period<=PERIOD_M5,lblM5_5,bufferM5_5[0],"M5"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_M5 && _Period<=PERIOD_M5,lblM5_6,bufferM5_6[0],"M5"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_M15 && _Period<=PERIOD_M15,lblM15h,bufferM15FMA[0],"M15"+fastText,UpperLineColor);
   DrawPriceLabel(m_M15 && _Period<=PERIOD_M15,lblM15m,bufferM15MMA[0],"M15"+middleText,MainLineColor);
   DrawPriceLabel(m_M15 && _Period<=PERIOD_M15,lblM15l,bufferM15SMA[0],"M15"+slowText,LowerLineColor);
   DrawPriceLabel(m_M15 && _Period<=PERIOD_M15,lblM15_4,bufferM15_4[0],"M15"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_M15 && _Period<=PERIOD_M15,lblM15_5,bufferM15_5[0],"M15"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_M15 && _Period<=PERIOD_M15,lblM15_6,bufferM15_6[0],"M15"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_M30 && _Period<=PERIOD_M30,lblM30h,bufferM30FMA[0],"M30"+fastText,UpperLineColor);
   DrawPriceLabel(m_M30 && _Period<=PERIOD_M30,lblM30m,bufferM30MMA[0],"M30"+middleText,MainLineColor);
   DrawPriceLabel(m_M30 && _Period<=PERIOD_M30,lblM30l,bufferM30SMA[0],"M30"+slowText,LowerLineColor);
   DrawPriceLabel(m_M30 && _Period<=PERIOD_M30,lblM30_4,bufferM30_4[0],"M30"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_M30 && _Period<=PERIOD_M30,lblM30_5,bufferM30_5[0],"M30"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_M30 && _Period<=PERIOD_M30,lblM30_6,bufferM30_6[0],"M30"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_H1 && _Period<=PERIOD_H1,lblH1h,bufferH1FMA[0],"H1"+fastText,UpperLineColor);
   DrawPriceLabel(m_H1 && _Period<=PERIOD_H1,lblH1m,bufferH1MMA[0],"H1"+middleText,MainLineColor);
   DrawPriceLabel(m_H1 && _Period<=PERIOD_H1,lblH1l,bufferH1SMA[0],"H1"+slowText,LowerLineColor);
   DrawPriceLabel(m_H1 && _Period<=PERIOD_H1,lblH1_4,bufferH1_4[0],"H1"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_H1 && _Period<=PERIOD_H1,lblH1_5,bufferH1_5[0],"H1"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_H1 && _Period<=PERIOD_H1,lblH1_6,bufferH1_6[0],"H1"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_H4 && _Period<=PERIOD_H4,lblH4h,bufferH4FMA[0],"H4"+fastText,UpperLineColor);
   DrawPriceLabel(m_H4 && _Period<=PERIOD_H4,lblH4m,bufferH4MMA[0],"H4"+middleText,MainLineColor);
   DrawPriceLabel(m_H4 && _Period<=PERIOD_H4,lblH4l,bufferH4SMA[0],"H4"+slowText,LowerLineColor);
   DrawPriceLabel(m_H4 && _Period<=PERIOD_H4,lblH4_4,bufferH4_4[0],"H4"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_H4 && _Period<=PERIOD_H4,lblH4_5,bufferH4_5[0],"H4"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_H4 && _Period<=PERIOD_H4,lblH4_6,bufferH4_6[0],"H4"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_D1 && _Period<=PERIOD_D1,lblD1h,bufferD1FMA[0],"D1"+fastText,UpperLineColor);
   DrawPriceLabel(m_D1 && _Period<=PERIOD_D1,lblD1m,bufferD1MMA[0],"D1"+middleText,MainLineColor);
   DrawPriceLabel(m_D1 && _Period<=PERIOD_D1,lblD1l,bufferD1SMA[0],"D1"+slowText,LowerLineColor);
   DrawPriceLabel(m_D1 && _Period<=PERIOD_D1,lblD1_4,bufferD1_4[0],"D1"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_D1 && _Period<=PERIOD_D1,lblD1_5,bufferD1_5[0],"D1"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_D1 && _Period<=PERIOD_D1,lblD1_6,bufferD1_6[0],"D1"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_W1 && _Period<=PERIOD_W1,lblW1h,bufferW1FMA[0],"W1"+fastText,UpperLineColor);
   DrawPriceLabel(m_W1 && _Period<=PERIOD_W1,lblW1m,bufferW1MMA[0],"W1"+middleText,MainLineColor);
   DrawPriceLabel(m_W1 && _Period<=PERIOD_W1,lblW1l,bufferW1SMA[0],"W1"+slowText,LowerLineColor);
   DrawPriceLabel(m_W1 && _Period<=PERIOD_W1,lblW1_4,bufferW1_4[0],"W1"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_W1 && _Period<=PERIOD_W1,lblW1_5,bufferW1_5[0],"W1"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_W1 && _Period<=PERIOD_W1,lblW1_6,bufferW1_6[0],"W1"+sixthText,LowerLineColor6);

   DrawPriceLabel(m_MN1,lblMN1h,bufferMN1FMA[0],"MN1"+fastText,UpperLineColor);
   DrawPriceLabel(m_MN1,lblMN1m,bufferMN1MMA[0],"MN1"+middleText,MainLineColor);
   DrawPriceLabel(m_MN1,lblMN1l,bufferMN1SMA[0],"MN1"+slowText,LowerLineColor);
   DrawPriceLabel(m_MN1,lblMN1_4,bufferMN1_4[0],"MN1"+fourthText,LowerLineColor4);
   DrawPriceLabel(m_MN1,lblMN1_5,bufferMN1_5[0],"MN1"+fifthText,LowerLineColor5);
   DrawPriceLabel(m_MN1,lblMN1_6,bufferMN1_6[0],"MN1"+sixthText,LowerLineColor6);
  }
//+------------------------------------------------------------------+
//| Rest events handler                                                    |
//+------------------------------------------------------------------+
bool CPanelDialog::OnDefault(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   return(false);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;

double bufferMN1FMA[];
double bufferMN1MMA[];
double bufferMN1SMA[];
double bufferMN1_4[];
double bufferMN1_5[];
double bufferMN1_6[];

double bufferW1FMA[];
double bufferW1MMA[];
double bufferW1SMA[];
double bufferW1_4[];
double bufferW1_5[];
double bufferW1_6[];

double bufferD1FMA[];
double bufferD1MMA[];
double bufferD1SMA[];
double bufferD1_4[];
double bufferD1_5[];
double bufferD1_6[];

double bufferH4FMA[];
double bufferH4MMA[];
double bufferH4SMA[];
double bufferH4_4[];
double bufferH4_5[];
double bufferH4_6[];

double bufferH1FMA[];
double bufferH1MMA[];
double bufferH1SMA[];
double bufferH1_4[];
double bufferH1_5[];
double bufferH1_6[];

double bufferM30FMA[];
double bufferM30MMA[];
double bufferM30SMA[];
double bufferM30_4[];
double bufferM30_5[];
double bufferM30_6[];



double bufferM15FMA[];
double bufferM15MMA[];
double bufferM15SMA[];
double bufferM15_4[];
double bufferM15_5[];
double bufferM15_6[];

double bufferM5FMA[];
double bufferM5MMA[];
double bufferM5SMA[];
double bufferM5_4[];
double bufferM5_5[];
double bufferM5_6[];

double bufferM1FMA[];
double bufferM1MMA[];
double bufferM1SMA[];
double bufferM1_4[];
double bufferM1_5[];
double bufferM1_6[];

int lblM1h,lblM1m,lblM1l,lblM1_4,lblM1_5,lblM1_6;
int lblM5h,lblM5m,lblM5l,lblM5_4,lblM5_5,lblM5_6;
int lblM15h,lblM15m,lblM15l,lblM15_4,lblM15_5,lblM15_6;
int lblM30h,lblM30m,lblM30l,lblM30_4,lblM30_5,lblM30_6;
int lblH1h,lblH1m,lblH1l,lblH1_4,lblH1_5,lblH1_6;
int lblH4h,lblH4m,lblH4l,lblH4_4,lblH4_5,lblH4_6;
int lblD1h,lblD1m,lblD1l,lblD1_4,lblD1_5,lblD1_6;
int lblW1h,lblW1m,lblW1l,lblW1_4,lblW1_5,lblW1_6;
int lblMN1h,lblMN1m,lblMN1l,lblMN1_4,lblMN1_5,lblMN1_6;
   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   ObjectsDeleteAll(ChartID(),OBJPREFIX);
   
   InitBuffers();
   if(!ExtDialog.Create(0,OBJPREFIX,0,10,10,130,208)) 
      return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
      return(INIT_FAILED);
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(ChartID(),OBJPREFIX);

//--- destroy application dialog
   ExtDialog.Destroy(reason);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
// Call function ManageEvents on every MT4 tick   
   RunIndicators();

   ExtDialog.DrawIndicatorsData();

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
    ExtDialog.ChartEvent(id,lparam,dparam,sparam);


    // Remember the panel's location to have the same location for minimized and maximized states.
    if ((id == CHARTEVENT_CUSTOM + ON_DRAG_END) && (lparam == -1))
    {
        ExtDialog.remember_top = ExtDialog.Top();
        ExtDialog.remember_left = ExtDialog.Left();
    }

    // Call Panel's event handler only if it is not a CHARTEVENT_CHART_CHANGE - workaround for minimization bug on chart switch.
    if (id != CHARTEVENT_CHART_CHANGE) ExtDialog.OnEvent(id, lparam, dparam, sparam);

    if (ExtDialog.Top() < 0) ExtDialog.Move(ExtDialog.Left(), 0);
  
  }
  
  
  string MouseState(uint state)
  {
   string res;
   res+="\nML: "   +(((state& 1)== 1)?"DN":"UP");   // mouse left
   res+="\nMR: "   +(((state& 2)== 2)?"DN":"UP");   // mouse right 
   res+="\nMM: "   +(((state&16)==16)?"DN":"UP");   // mouse middle
   res+="\nMX: "   +(((state&32)==32)?"DN":"UP");   // mouse first X key
   res+="\nMY: "   +(((state&64)==64)?"DN":"UP");   // mouse second X key
   res+="\nSHIFT: "+(((state& 4)== 4)?"DN":"UP");   // shift key
   res+="\nCTRL: " +(((state& 8)== 8)?"DN":"UP");   // control key
   return(res);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
void InitBuffers()
  {

   AddBuffer(0,bufferMN1FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"MN1 Fast MA");
   AddBuffer(1,bufferMN1MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"MN1 Middle MA");
   AddBuffer(2,bufferMN1SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"MN1 Slow MA");
   AddBuffer(3,bufferMN1_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"MN1 Fourth MA");
   AddBuffer(4,bufferMN1_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"MN1 Fifth MA");
   AddBuffer(5,bufferMN1_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"MN1 Sixth MA");

   AddBuffer(6,bufferW1FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"W1 Fast MA");
   AddBuffer(7,bufferW1MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"W1 Middle MA");
   AddBuffer(8,bufferW1SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"W1 Slow MA");
   AddBuffer(9,bufferW1_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"W1 Fourth MA");
   AddBuffer(10,bufferW1_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"W1 Fifth MA");
   AddBuffer(11,bufferW1_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"W1 Sixth MA");

   AddBuffer(12,bufferD1FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"D1 Fast MA");
   AddBuffer(13,bufferD1MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"D1 Middle MA");
   AddBuffer(14,bufferD1SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"D1 Slow MA");
   AddBuffer(15,bufferD1_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"D1 Fourth MA");
   AddBuffer(16,bufferD1_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"D1 Fifth MA");
   AddBuffer(17,bufferD1_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"D1 Sixth MA");

   AddBuffer(18,bufferH4FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"H4 Fast MA");
   AddBuffer(19,bufferH4MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"H4 Middle MA");
   AddBuffer(20,bufferH4SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"H4 Slow MA");
   AddBuffer(21,bufferH4_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"H4 Fourth MA");
   AddBuffer(22,bufferH4_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"H4 Fifth MA");
   AddBuffer(23,bufferH4_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"H4 Sixth MA");

   AddBuffer(24,bufferH1FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"H1 Fast MA");
   AddBuffer(25,bufferH1MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"H1 Middle MA");
   AddBuffer(26,bufferH1SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"H1 Slow MA");
   AddBuffer(27,bufferH1_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"H1 Fourth MA");
   AddBuffer(28,bufferH1_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"H1 Fifth MA");
   AddBuffer(29,bufferH1_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"H1 Sixth MA");

   AddBuffer(30,bufferM30FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"M30 Fast MA");
   AddBuffer(31,bufferM30MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"M30 Middle MA");
   AddBuffer(32,bufferM30SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"M30 Slow MA");
   AddBuffer(33,bufferM30_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"M30 Fourth MA");
   AddBuffer(34,bufferM30_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"M30 Fifth MA");
   AddBuffer(35,bufferM30_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"M30 Sixth MA");

   AddBuffer(36,bufferM15FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"M15 Fast MA");
   AddBuffer(37,bufferM15MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"M15 Middle MA");
   AddBuffer(38,bufferM15SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"M15 Slow MA");
   AddBuffer(39,bufferM15_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"M15 Fourth MA");
   AddBuffer(40,bufferM15_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"M15 Fifth MA");
   AddBuffer(41,bufferM15_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"M15 Sixth MA");

   AddBuffer(42,bufferM5FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"M5 Fast MA");
   AddBuffer(43,bufferM5MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"M5 Middle MA");
   AddBuffer(44,bufferM5SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"M5 Slow MA");
   AddBuffer(45,bufferM5_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"M5 Fourth MA");
   AddBuffer(46,bufferM5_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"M5 Fifth MA");
   AddBuffer(47,bufferM5_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"M5 Sixth MA");

   AddBuffer(48,bufferM1FMA,DRAW_NONE,UpperStyle,UpperLineWidth,UpperLineColor,"M1 Fast MA");
   AddBuffer(49,bufferM1MMA,DRAW_NONE,MainStyle,MainLineWidth,MainLineColor,"M1 Middle MA");
   AddBuffer(50,bufferM1SMA,DRAW_NONE,LowerStyle,LowerLineWidth,LowerLineColor,"M1 Slow MA");
   AddBuffer(51,bufferM1_4,DRAW_NONE,LowerStyle4,LowerLineWidth4,LowerLineColor4,"M1 Fourth MA");
   AddBuffer(52,bufferM1_5,DRAW_NONE,LowerStyle5,LowerLineWidth5,LowerLineColor5,"M1 Fifth MA");
   AddBuffer(53,bufferM1_6,DRAW_NONE,LowerStyle6,LowerLineWidth6,LowerLineColor6,"M1 Sixth MA");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void AddBuffer(int idx,double &buffer[],int type,int style=EMPTY,int width=EMPTY,color clr=clrNONE,string text="")
  {
   SetIndexBuffer(idx,buffer);
   SetIndexStyle(idx,type,style,width,clr);
   SetIndexLabel(idx,text);
  }
//+------------------------------------------------------------------+
int RunIndicators()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   datetime tfMN1[],tfW1[],tfD1[],tfH4[],tfH1[],tfM30[],tfM15[],tfM5[],tfM1[];
   int iMN1=0,iW1=0,iD1=0,iH4=0,iH1=0,iM30=0,iM15=0,iM5=0,iM1=0;

//---- check for possible errors 
   if(counted_bars<0)
      return(-1);

//---- the last counted bar will be recounted 
   if(counted_bars>0)
      counted_bars--;

   ArrayCopySeries(tfMN1,MODE_TIME,Symbol(),PERIOD_MN1);
   ArrayCopySeries(tfW1,MODE_TIME,Symbol(),PERIOD_W1);
   ArrayCopySeries(tfD1,MODE_TIME,Symbol(),PERIOD_D1);
   ArrayCopySeries(tfH4,MODE_TIME,Symbol(),PERIOD_H4);
   ArrayCopySeries(tfH1,MODE_TIME,Symbol(),PERIOD_H1);
   ArrayCopySeries(tfM30,MODE_TIME,Symbol(),PERIOD_M30);
   ArrayCopySeries(tfM15,MODE_TIME,Symbol(),PERIOD_M15);
   ArrayCopySeries(tfM5,MODE_TIME,Symbol(),PERIOD_M5);
   ArrayCopySeries(tfM1,MODE_TIME,Symbol(),PERIOD_M1);

   limit=Bars-counted_bars;

//---- main loop 
   for(int i=0; i<limit; i++)
     {
      if(iMN1<ArraySize(tfMN1) && Time[i]<tfMN1[iMN1]) iMN1++;
      if(iW1<ArraySize(tfW1) && Time[i]<tfW1[iW1]) iW1++;
      if(iD1<ArraySize(tfD1) && Time[i]<tfD1[iD1]) iD1++;
      if(iH4<ArraySize(tfH4) && Time[i]<tfH4[iH4]) iH4++;
      if(iH1<ArraySize(tfH1) && Time[i]<tfH1[iH1]) iH1++;
      if(iM30<ArraySize(tfM30) && Time[i]<tfM30[iM30]) iM30++;
      if(iM15<ArraySize(tfM15) && Time[i]<tfM15[iM15]) iM15++;
      if(iM5<ArraySize(tfM5) && Time[i]<tfM5[iM5]) iM5++;
      if(iM1<ArraySize(tfM1) && Time[i]<tfM1[iM1]) iM1++;

      bufferMN1FMA[i]   = iMA(NULL,PERIOD_MN1,FMAPeriod,FMAShift,FMAMethod, FMAAppliedPrice,iMN1);
      bufferMN1MMA[i]   = iMA(NULL,PERIOD_MN1,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iMN1);
      bufferMN1SMA[i]   = iMA(NULL,PERIOD_MN1,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iMN1);
      bufferMN1_4[i]   = iMA(NULL,PERIOD_MN1,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iMN1);
      bufferMN1_5[i]   = iMA(NULL,PERIOD_MN1,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iMN1);
      bufferMN1_6[i]   = iMA(NULL,PERIOD_MN1,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iMN1);

      bufferW1FMA[i]    = iMA(NULL,PERIOD_W1,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iW1);
      bufferW1MMA[i]    = iMA(NULL,PERIOD_W1,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iW1);
      bufferW1SMA[i]    = iMA(NULL,PERIOD_W1,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iW1);
      bufferW1_4[i]    = iMA(NULL,PERIOD_W1,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iW1);
      bufferW1_5[i]    = iMA(NULL,PERIOD_W1,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iW1);
      bufferW1_6[i]    = iMA(NULL,PERIOD_W1,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iW1);

      bufferD1FMA[i]    = iMA(NULL,PERIOD_D1,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iD1);
      bufferD1MMA[i]    = iMA(NULL,PERIOD_D1,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iD1);
      bufferD1SMA[i]    = iMA(NULL,PERIOD_D1,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iD1);
      bufferD1_4[i]    = iMA(NULL,PERIOD_D1,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iD1);
      bufferD1_5[i]    = iMA(NULL,PERIOD_D1,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iD1);
      bufferD1_6[i]    = iMA(NULL,PERIOD_D1,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iD1);

      bufferH4FMA[i]    = iMA(NULL,PERIOD_H4,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iH4);
      bufferH4MMA[i]    = iMA(NULL,PERIOD_H4,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iH4);
      bufferH4SMA[i]    = iMA(NULL,PERIOD_H4,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iH4);
      bufferH4_4[i]    = iMA(NULL,PERIOD_H4,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iH4);
      bufferH4_5[i]    = iMA(NULL,PERIOD_H4,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iH4);
      bufferH4_6[i]    = iMA(NULL,PERIOD_H4,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iH4);

      bufferH1FMA[i]    = iMA(NULL,PERIOD_H1,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iH1);
      bufferH1MMA[i]    = iMA(NULL,PERIOD_H1,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iH1);
      bufferH1SMA[i]    = iMA(NULL,PERIOD_H1,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iH1);
      bufferH1_4[i]    = iMA(NULL,PERIOD_H1,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iH1);
      bufferH1_5[i]    = iMA(NULL,PERIOD_H1,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iH1);
      bufferH1_6[i]    = iMA(NULL,PERIOD_H1,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iH1);

      bufferM30FMA[i]   = iMA(NULL,PERIOD_M30,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iM30);
      bufferM30MMA[i]   = iMA(NULL,PERIOD_M30,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iM30);
      bufferM30SMA[i]   = iMA(NULL,PERIOD_M30,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iM30);
      bufferM30_4[i]   = iMA(NULL,PERIOD_M30,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iM30);
      bufferM30_5[i]   = iMA(NULL,PERIOD_M30,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iM30);
      bufferM30_6[i]   = iMA(NULL,PERIOD_M30,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iM30);

      bufferM15FMA[i]   = iMA(NULL,PERIOD_M15,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iM15);
      bufferM15MMA[i]   = iMA(NULL,PERIOD_M15,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iM15);
      bufferM15SMA[i]   = iMA(NULL,PERIOD_M15,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iM15);
      bufferM15_4[i]   = iMA(NULL,PERIOD_M15,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iM15);
      bufferM15_5[i]   = iMA(NULL,PERIOD_M15,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iM15);
      bufferM15_6[i]   = iMA(NULL,PERIOD_M15,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iM15);

      bufferM5FMA[i]    = iMA(NULL,PERIOD_M5,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iM5);
      bufferM5MMA[i]    = iMA(NULL,PERIOD_M5,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iM5);
      bufferM5SMA[i]    = iMA(NULL,PERIOD_M5,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iM5);
      bufferM5_4[i]    = iMA(NULL,PERIOD_M5,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iM5);
      bufferM5_5[i]    = iMA(NULL,PERIOD_M5,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iM5);
      bufferM5_6[i]    = iMA(NULL,PERIOD_M5,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iM5);

      bufferM1FMA[i]    = iMA(NULL,PERIOD_M1,FMAPeriod,FMAShift, FMAMethod, FMAAppliedPrice,iM1);
      bufferM1MMA[i]    = iMA(NULL,PERIOD_M1,MMAPeriod,MMAShift,MMAMethod,MMAAppliedPrice,iM1);
      bufferM1SMA[i]    = iMA(NULL,PERIOD_M1,SMAPeriod,SMAShift,SMAMethod,SMAAppliedPrice,iM1);
      bufferM1_4[i]    = iMA(NULL,PERIOD_M1,SMAPeriod4,SMAShift4,SMAMethod4,SMAAppliedPrice4,iM1);
      bufferM1_5[i]    = iMA(NULL,PERIOD_M1,SMAPeriod5,SMAShift5,SMAMethod5,SMAAppliedPrice5,iM1);
      bufferM1_6[i]    = iMA(NULL,PERIOD_M1,SMAPeriod6,SMAShift6,SMAMethod6,SMAAppliedPrice6,iM1);
     }
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawPriceLabel(bool show,int lblHwnd,double price,string text,color foreground,color background=clrLightGray)
  {
   string name=OBJPREFIX+text;
   ObjectDelete(0,name);
   if(show)
     {
      int x,y;
      datetime fwdTime;
      int      window=0;

      ChartTimePriceToXY(0,0,Time[0],price,x,y);
      x = x + 50;
      y = y - 8;
      ChartXYToTimePrice(0,x,y,window,fwdTime,price);

      ObjectCreate(name,OBJ_TEXT,0,fwdTime,price);
      ObjectSetText(name,text,9,"Verdana",foreground);
      ObjectSet(name,OBJPROP_CORNER,0);
      ObjectSet(name,OBJPROP_XDISTANCE,250);
      ObjectSet(name,OBJPROP_YDISTANCE,20);
     }
  }
//+------------------------------------------------------------------+

void CPanelDialog::WriteIndicatorsData()
  {
   bool arr[9];
   string path=DataDirectoryName+"//"+Symbol()+DataFileName;

   arr[0] = m_M1;
   arr[1] = m_M5;
   arr[2] = m_M15;
   arr[3] = m_M30;
   arr[4] = m_H1;
   arr[5] = m_H4;
   arr[6] = m_D1;
   arr[7] = m_W1;
   arr[8] = m_MN1;

//--- open the file
   ResetLastError();
   int handle = FileOpen(path,FILE_READ|FILE_WRITE|FILE_BIN);
   if(handle != INVALID_HANDLE)
     {
      //--- write array data 
      FileWriteArray(handle,arr);
      //--- close the file
      FileClose(handle);
     }
   else
     {
      Print("Failed to open the file, error: "+(string) GetLastError());
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CPanelDialog::ReadIndicatorsData()
  {
   bool arr[];
   string path=DataDirectoryName+"//"+Symbol()+DataFileName;

//--- open the file
   ResetLastError();
   int file_handle = FileOpen(path,FILE_READ|FILE_BIN);
   if(file_handle != INVALID_HANDLE)
     {
      //--- read all data from the file to the array
      FileReadArray(file_handle,arr);
      int size=ArraySize(arr);

      m_M1 = arr[0];
      m_M5 = arr[1];
      m_M15 = arr[2];
      m_M30 = arr[3];
      m_H1 = arr[4];
      m_H4 = arr[5];
      m_D1 = arr[6];
      m_W1 = arr[7];
      m_MN1= arr[8];

      //--- close the file
      FileClose(file_handle);
     }
   else
     {
      Print("File open failed, error: "+(string) GetLastError());
     }

  } 
  
//+------------------------------------------------------------------+
