H4 D1 Panel

Author: Copyright © 2020, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
H4 D1 Panel
ÿþ//+------------------------------------------------------------------+

//|                                                  H4 D1 Panel.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.001"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

//+------------------------ PanelDialog -----------------------------+

#include <Controls\Dialog.mqh>

#include <Canvas\Canvas.mqh>

#include <Controls\BmpButton.mqh>

//+------------------------------------------------------------------+

//| defines                                                          |

//+------------------------------------------------------------------+

//--- indents and gaps

#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)

//--- for buttons

#define BUTTON_WIDTH                        (100)     // size by X coordinate

#define BUTTON_HEIGHT                       (20)      // size by Y coordinate

//+------------------------------------------------------------------+

//| Class CPanelDialog                                            |

//| Usage: main dialog of the Controls application                   |

//+------------------------------------------------------------------+

class CPanelDialog : public CAppDialog

  {

private:

   CCanvas           m_canvas;                        // CCanvas object

   CBmpButton        m_bmp_button;                    // CBmpButton object



public:

                     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);

   //--- displaying text

   virtual void      DisplayingText(void);



protected:

   //--- create dependent controls

   bool              CreateCanvas(void);

  };

//+------------------------------------------------------------------+

//| Event Handling                                                   |

//+------------------------------------------------------------------+

EVENT_MAP_BEGIN(CPanelDialog)

EVENT_MAP_END(CAppDialog)

//+------------------------------------------------------------------+

//| Constructor                                                      |

//+------------------------------------------------------------------+

CPanelDialog::CPanelDialog(void)

  {

  }

//+------------------------------------------------------------------+

//| Destructor                                                       |

//+------------------------------------------------------------------+

CPanelDialog::~CPanelDialog(void)

  {

  }

//+------------------------------------------------------------------+

//| 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)

  {

   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))

      return(false);

//--- create dependent controls

   if(!CreateCanvas())

      return(false);

//--- succeed

   return(true);

  }

//+------------------------------------------------------------------+

//| Displaying Text                                                  |

//+------------------------------------------------------------------+

void CPanelDialog::DisplayingText(void)

  {

   /*

   "         H4         |         D1         "

   "  #2  |  #1  |  #0  |  #2  |  #1  |  #0  "

   " BULL | BULL | BULL | BEAR | BEAR | BULL "

   */

   m_canvas.Erase(ColorToARGB(clrBlue,255));

   MqlRates rates_h4[],rates_d1[];

   ArraySetAsSeries(rates_h4,false);

   ArraySetAsSeries(rates_d1,false);

   int start_pos=0,count=3;

   if(CopyRates(Symbol(),PERIOD_D1,start_pos,count,rates_d1)!=count || CopyRates(Symbol(),PERIOD_H4,start_pos,count,rates_h4)!=count)

     {

      m_canvas.TextOut(5,10,"    ERROR    ",ColorToARGB(clrLawnGreen,255));

     }

   else

     {

      string text_timeframes     = "         H4         |         D1         ";

      string text_bars           = "  #2  |  #1  |  #0  |  #2  |  #1  |  #0  ";

      string text_bull=" BULL ";

      string text_bear=" BEAR ";

      string text_candels_type="";

      for(int i=0; i<count; i++)

        {

         text_candels_type=text_candels_type+((rates_h4[i].open<rates_h4[i].close)?text_bull:text_bear);

         text_candels_type=text_candels_type+"|";

        }

      for(int i=0; i<count; i++)

        {

         text_candels_type=text_candels_type+((rates_d1[i].open<rates_d1[i].close)?text_bull:text_bear);

         if(i<count-1)

            text_candels_type=text_candels_type+"|";

        }

      m_canvas.FontFlagsSet(FW_BOLD);

      m_canvas.TextOut(5,5,text_timeframes,ColorToARGB(clrLawnGreen,255));

      m_canvas.FontFlagsSet(FW_NORMAL);

      m_canvas.TextOut(5,20,text_bars,ColorToARGB(clrLawnGreen,255));

      m_canvas.TextOut(5,35,text_candels_type,ColorToARGB(clrLawnGreen,255));

     }

   m_canvas.Update(true);

  }

//+------------------------------------------------------------------+

//| Create the canvas object                                         |

//+------------------------------------------------------------------+

bool CPanelDialog::CreateCanvas(void)

  {

//--- coordinates

   int x1=1;

   int y1=1;

   int x2=ClientAreaWidth()-2;

   int y2=ClientAreaHeight()-2;

//--- create canvas

   if(!m_canvas.Create("Canvas1",x2,y2,COLOR_FORMAT_XRGB_NOALPHA))

     {

      Print("Error creating canvas: ",GetLastError());

      return(false);

     }

   m_canvas.FontSet("Consolas",-120,FW_THIN);

   m_canvas.Erase(ColorToARGB(clrBlue,255));

   m_canvas.Update(true);

//--- create

   if(!m_bmp_button.Create(m_chart_id,m_name+"BmpButton",m_subwin,x1,y1,x1,y1))

      return(false);

//--- sets the name of bmp files of the control CBmpButton

   if(!m_bmp_button.BmpOnName(m_canvas.ResourceName()))

      return(false);

   if(!Add(m_bmp_button))

      return(false);

//--- succeed

   return(true);

  }

//+------------------------- Indicator ------------------------------+

//---

CPanelDialog   m_dialog;                              // object of CPanelDialog class

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit(void)

  {

//--- create application dialog

   if(!m_dialog.Create(0,"D1 H4 Panel",0,50,50,440,140))

      return(INIT_FAILED);

//--- run application

   if(!m_dialog.Run())

      return(INIT_FAILED);

//--- succeed

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//--- destroy application dialog

   m_dialog.Destroy(reason);

  }

//+------------------------------------------------------------------+

//| 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[])

  {

//---

   m_dialog.DisplayingText();

//--- 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)

  {

   m_dialog.ChartEvent(id,lparam,dparam,sparam);

  }

//+------------------------------------------------------------------+

Comments