High Low Range Panel

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
High Low Range Panel
ÿþ//+------------------------------------------------------------------+

//|                                         High Low Range 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.000"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

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

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

//|                                                  PanelDialog.mqh |

//|                              Copyright © 2020, Vladimir Karputov |

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

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

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

#define CONTROLS_GAP_X                      (5)       // gap by X coordinate

#define CONTROLS_GAP_Y                      (5)       // gap by Y coordinate

//--- for buttons

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

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

//--- for the indication area

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

//--- for group controls

#define GROUP_WIDTH                         (150)     // size by X coordinate

#define LIST_HEIGHT                         (179)     // size by Y coordinate

#define RADIO_HEIGHT                        (56)      // size by Y coordinate

#define CHECK_HEIGHT                        (93)      // 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(const double highest, datetime highest_time,

                                    const double lowest, datetime lowest_time, datetime start_time);



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(const double highest,datetime highest_time,

                                  const double lowest,datetime lowest_time,datetime start_time)

  {

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

   string text="Start Time: "+TimeToString(start_time,TIME_DATE|TIME_MINUTES);

   string text_1="Highest: "+DoubleToString(highest,Digits())+"   "+"("+TimeToString(highest_time,TIME_DATE|TIME_MINUTES)+")";

   string text_2="Lowest: "+DoubleToString(lowest,Digits())+"   "+"("+TimeToString(lowest_time,TIME_DATE|TIME_MINUTES)+")";

//---

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

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

   m_canvas.TextOut(5,35,text_2,ColorToARGB(ColorToARGB(clrLawnGreen,255),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("Trebuchet MS",-100,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 ------------------------------+

//--- input parameters

input datetime InpStartTime   = D'2020.01.01 00:00';  // Start Time (located to the left on the chart)

//---

CPanelDialog   m_dialog;                              // object of CPanelDialog class

double         m_highest      = DBL_MIN;

datetime       m_highest_time = 0;

double         m_lowest       = DBL_MAX;

datetime       m_lowest_time  = 0;

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

//| Custom indicator initialization function                         |

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

int OnInit(void)

  {

//--- create application dialog

   if(!m_dialog.Create(0,"High Low Range Panel",0,50,50,300,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[])

  {

//---

   if(prev_calculated==0)

     {

      for(int i=rates_total-1; i>=0; i--)

        {

         if(time[i]<InpStartTime)

            break;

         if(high[i]>m_highest)

           {

            m_highest=high[i];

            m_highest_time=time[i];

           }

         if(low[i]<m_lowest)

           {

            m_lowest=low[i];

            m_lowest_time=time[i];

           }

        }

     }

   else

     {

      int limit=prev_calculated-1;

      for(int i=limit; i<rates_total; i++)

        {

         if(time[i]<InpStartTime)

            break;

         if(high[i]>m_highest)

           {

            m_highest=high[i];

            m_highest_time=time[i];

           }

         if(low[i]<m_lowest)

           {

            m_lowest=low[i];

            m_lowest_time=time[i];

           }

        }

     }

   m_dialog.DisplayingText(m_highest,  m_highest_time,

                           m_lowest, m_lowest_time, InpStartTime);

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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---