Author: Copyright 2018, Orangetree
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
WorkHours
ÿþ//+------------------------------------------------------------------+

//|                                                    WorkHours.mq5 |

//|                                       Copyright 2018, Orangetree |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2018, Orangetree"

#property link      "https://www.mql5.com"

#property version   "1.00"



input datetime T0=D'01.01.2019';     // =0G0;> ?5@8>40 4;O @0AGQB0

input int Shift =1;                  // @07=8F0 A <5AB=K< 2@5<5=5<



#include <Graphics\Graphic.mqh>

#include <Controls\Button.mqh>

CButton Button;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

   CGraphic graphic;

   graphic.Create(0,"Graphic"+IntegerToString(ChartID()),0,220,20,970,370);



   graphic.HistoryNameWidth(70);

   graphic.HistoryNameSize(14);

   

   double x[24]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};

   double y[24];

   AverageHour(y);

   CCurve *curve=graphic.CurveAdd(x,y,CURVE_HISTOGRAM);

   curve.HistogramWidth(6);

   curve.Color(Green);

   curve.Name("Hour Volatility");

   graphic.CurvePlotAll();

   graphic.Update();

   

   //--- Button ---------+

   Button.Create(0,"Button",0,890,330,960,360);

   Button.Text("OK");

   ChartRedraw(); 

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

   ObjectsDeleteAll(0);   

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

   

  }



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

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

  { 

     if(sparam=="Button"&&id==1) ExpertRemove();

  }

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

  void AverageHour(double &arr[])

  {

   

   double val[24];

   double n[24];

   ArrayInitialize(n,0);

   ArrayInitialize(val,0);

   datetime t=TimeCurrent();

   int i=0;

   int j=0;

   while(t>T0)

   {

   t=iTime(Symbol(),PERIOD_H1,i);

   

   MqlDateTime tm;

   TimeToStruct(t,tm);

   j =tm.hour;

   j =int(MathMod(j+Shift,24));

   val[j]=val[j]+iHigh(Symbol(),PERIOD_H1,i)-iLow(Symbol(),PERIOD_H1,i);

   n[j]=n[j]+1;

   i=i+1;

   }

   

   for(int k=0;k<24;k++)

   {

   double res;

   if(n[k])res =val[k]/n[k];

   else    res =0;

   NormalizeDouble(res,_Digits);

   int output =int(res*pow(10,_Digits));

   arr[k] =output;

   //Print(k,"   ",n[k],"  ",output);

   }  

 }

Comments