HighAndLow_TF

Author: IgorM
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
0 Views
0 Downloads
0 Favorites
HighAndLow_TF
ÿþ//+------------------------------------------------------------------+ 

//|                                                HighAndLow_TF.mq4 | 

//|                                            Copyright 2019, IgorM | 

//|                              https://www.mql5.com/ru/users/igorm | 

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

#property copyright "IgorM"

#property link      "https://www.mql5.com/ru/users/igorm"

#property version   "1.01"

#property strict

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_plots   4

//--- plot line1

#property indicator_label1  "O"

#property indicator_type1   DRAW_HISTOGRAM

#property indicator_color1  clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  3



#property indicator_label2  "C"

#property indicator_type2   DRAW_HISTOGRAM

#property indicator_color2  clrBlue

#property indicator_style2  STYLE_SOLID

#property indicator_width2  3



#property indicator_label3  "H"

#property indicator_type3   DRAW_HISTOGRAM

#property indicator_color3  clrRed

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1



#property indicator_label4  "L"

#property indicator_type4   DRAW_HISTOGRAM

#property indicator_color4  clrBlue

#property indicator_style4  STYLE_SOLID

#property indicator_width4  1



//--- input parameters

input ENUM_TIMEFRAMES TimeFrame_=PERIOD_M1;//"09<D@59< 4;O ?>8A:0 2@5<5=8 High&Low

#define       Panel_width     200

#define       Panel_height    150



int bar_chart,old_bar_chart;

double price_ch;

ENUM_TIMEFRAMES TimeFrame;

double b1[],b2[],b3[],b4[];

#include <Controls\Dialog.mqh> 

#include <Controls\Label.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 CControlsDialog                                            | 

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

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

class CControlsDialog : public CAppDialog

  {

private:

   // CLabel object 

public:

   CLabel            m_label1;

   CLabel            m_label2;

   CLabel            m_label3;

   CLabel            m_label4;

   CLabel            m_label5;

                     CControlsDialog(void){};

                    ~CControlsDialog(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);

protected:

   //--- create dependent controls 

   bool              CreateLabel(void);

   //--- handlers of the dependent controls events 

   void              OnClickLabel(void);

  };

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

//| Event Handling                                                   | 

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

EVENT_MAP_BEGIN(CControlsDialog)

EVENT_MAP_END(CAppDialog)



bool CControlsDialog::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);

   if(!CreateLabel()) return(false);

   return(true);

  }

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

//| Create the "CLabel"                                              | 

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

bool CControlsDialog::CreateLabel(void)

  {

//--- coordinates 

   int incy=20;

   int x1=INDENT_RIGHT;

   int y1=5;//INDENT_TOP+CONTROLS_GAP_Y-incy; 

   int x2=x1+100;

   int y2=y1+20;



//--- create 

   if(!m_label1.Create(m_chart_id,m_name+"Label1",m_subwin,x1,y1,x2,y2)) return(false);

   if(!m_label1.Text("")) return(false);

   if(!Add(m_label1)) return(false);

//Label2   

   y1+=incy;

   if(!m_label2.Create(m_chart_id,m_name+"Label2",m_subwin,x1,y1,x2,y2)) return(false);

   if(!m_label2.Text("")) return(false);

   if(!Add(m_label2)) return(false);

//Label3   

   y1+=incy;

   if(!m_label3.Create(m_chart_id,m_name+"Label3",m_subwin,x1,y1,x2,y2)) return(false);

   if(!m_label3.Text("")) return(false);

   if(!Add(m_label3)) return(false);

//Label4   

   y1+=incy;

   if(!m_label4.Create(m_chart_id,m_name+"Label4",m_subwin,x1,y1,x2,y2)) return(false);

   if(!m_label4.Text("")) return(false);

   if(!Add(m_label4)) return(false);



//Label5   

   y1+=incy;

   if(!m_label5.Create(m_chart_id,m_name+"Label5",m_subwin,x1,y1,x2,y2)) return(false);

   if(!m_label5.Text("")) return(false);

   if(!Add(m_label5)) return(false);

   return(true);

  }

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

//| Global Variables                                                 | 

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

CControlsDialog Panel;

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

//| Expert initialization function                                   | 

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

int OnInit()

  {

   TimeFrame = TimeFrame_<=Period() || TimeFrame_==PERIOD_CURRENT ? TimeFrame_ : PERIOD_CURRENT;

   if(!Panel.Create(0,StringConcatenate("5@8>4 ", EnumToString(TimeFrame)),0,10,10,10+Panel_width,10+Panel_height))  return(INIT_FAILED);

   Panel.Run();

   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);

   SetIndexBuffer(0,b1);

   SetIndexBuffer(1,b2);

   SetIndexBuffer(2,b3);

   SetIndexBuffer(3,b4);

   bar_chart=-1;

   old_bar_chart=1;

   OnTimer();

   EventSetTimer(49);

   ChartRedraw();

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 | 

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

void OnDeinit(const int reason)

  {

   Panel.Destroy(reason);

   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,false);

  }

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

//| Expert chart event function                                      | 

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

void OnChartEvent(const int id,         // event ID   

                  const long& lparam,   // event parameter of the long type 

                  const double& dparam, // event parameter of the double type 

                  const string& sparam) // event parameter of the string type 

  {



   bool     res;

   string   str1,str2,str3,str4,str5;

   int      window,x,y,btf,copyH,hh,ll;

   datetime t_st,t_end,t,t_chart;

   double   high_tf,low_tf;

   double   h[];



   x=(int)lparam; y=(int)dparam; t_chart=0; window=0;

   res=true;

   price_ch=0;



   if(id==CHARTEVENT_CLICK)

     {

      //--- ?@5>1@07C5< :>>@48=0BK X 8 Y  2 B5@<8=0E 40B0/2@5<O 

      if(ChartXYToTimePrice(0,x,y,window,t_chart,price_ch))

        {

         bar_chart=iBarShift(NULL,PERIOD_CURRENT,t_chart);

         if(bar_chart>0)

           {

            t_st=Time[bar_chart];

            t_end=Time[bar_chart-1]-1;

              }else{

            t_st=Time[0];

            t_end=TimeCurrent();

            bar_chart=0;

            b1[old_bar_chart]=EMPTY_VALUE;

            b2[old_bar_chart] = EMPTY_VALUE;

            b3[old_bar_chart] = EMPTY_VALUE;

            b4[old_bar_chart] = EMPTY_VALUE;

           }



         if((bar_chart>=0) && (price_ch<=High[bar_chart]) && (price_ch>=Low[bar_chart]))

           {

            if(bar_chart!=old_bar_chart)

              {

               if(old_bar_chart>=0)

                 {

                  b1[old_bar_chart] = EMPTY_VALUE;

                  b2[old_bar_chart] = EMPTY_VALUE;

                  b3[old_bar_chart] = EMPTY_VALUE;

                  b4[old_bar_chart] = EMPTY_VALUE;

                 }

               if(Open[bar_chart]>Close[bar_chart])

                 {

                  b3[bar_chart] = High[bar_chart];

                  b4[bar_chart] = Low[bar_chart];

                  b1[bar_chart] = Open[bar_chart];

                  b2[bar_chart] = Close[bar_chart];

                    }else{

                  b4[bar_chart] = High[bar_chart];

                  b3[bar_chart] = Low[bar_chart];

                  b2[bar_chart] = Close[bar_chart];

                  b1[bar_chart] = Open[bar_chart];

                 }

               old_bar_chart=bar_chart;

              }



            if(TimeFrame==PERIOD_CURRENT || TimeFrame==Period())

              {

               str1 = StringConcatenate("0@ =0 3@0D8:5 ! ",bar_chart);

               str2 = StringConcatenate("High =  ",DoubleToStr(High[bar_chart],Digits));

               t=Time[bar_chart];

               str3 = TimeToString(t);

               str4 = StringConcatenate("Low =  ",DoubleToStr(Low[bar_chart],Digits));

               str5 = "";

              }

            else

              {

               ResetLastError();

               copyH=CopyHigh(_Symbol,TimeFrame,t_st,t_end,h);

               if(copyH>0)

                 {

                  btf=iBarShift(NULL,TimeFrame,t_end);

                  if(btf<=0)btf=0;

                  hh = iHighest(NULL,TimeFrame,MODE_HIGH,copyH,btf);

                  ll = iLowest(NULL,TimeFrame,MODE_LOW,copyH,btf);

                  high_tf = iHigh(NULL,TimeFrame,hh);

                  low_tf  = iLow(NULL,TimeFrame,ll);

                  str1 = StringConcatenate("0@ =0 3@0D8:5 ! ",bar_chart);

                  str2 = StringConcatenate("High =  ",DoubleToStr(high_tf,Digits));

                  t=iTime(NULL,TimeFrame,hh);

                  str3 = TimeToString(t);

                  str4 = StringConcatenate("Low =  ",DoubleToStr(low_tf,Digits));

                  t=iTime(NULL,TimeFrame,ll);

                  str5=TimeToString(t);

                 }

               else  {res=false;str3=StringConcatenate("H81:0 ! ",GetLastError());}

               if(!res){str1="5B 8AB>@8G5A:8E 40==KE";str4="";str5="";}

              }

           }

         Panel.m_label1.Text(str1);

         Panel.m_label2.Text(str2);

         Panel.m_label3.Text(str3);

         Panel.m_label4.Text(str4);

         Panel.m_label5.Text(str5);

        }

     }

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

  }

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

//| 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(rates_total);

  }

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

//| Timer function                                                   |

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

void OnTimer()

  {

   const ENUM_TIMEFRAMES PeriodTF[9]={PERIOD_M1,PERIOD_M5,PERIOD_M15,PERIOD_M30,PERIOD_H1,PERIOD_H4,PERIOD_D1,PERIOD_W1,PERIOD_MN1};

   static int count=0;

   datetime t[];

   int i,startpos=0;

   if(count++<6)

     {

      for(i=0;i<9;i++){CopyTime(_Symbol,PeriodTF[i],startpos,iBars(_Symbol,PeriodTF[i]),t);}

        }else{

      for(i=0;i<9;i++){CopyTime(_Symbol,PeriodTF[i],startpos,2,t);}

     }

  }

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

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