//+------------------------------------------------------------------+ //| PriceHistgram_OnClick.mq4 | //| PriceHistgram_OnClick Copyright 2015, fxborg | //| http://blog.livedoor.jp/fxborg/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://blog.livedoor.jp/fxborg/" #property version "1.02" #property indicator_chart_window //--- input parameters input double InpBinRange=2.5; // Bin range of price histogram input int InpCalcTime=4; // Calculation Time(hour) input int InpShortTermPeriod =3; // Short term period(day) input int InpMediumTermPeriod=7; // Medium term period(day) input int InpLongTermPeriod =26; // Long term period(day) input bool InpUsingVolumeWeight=true; // Using TickVolume input double InpDrawScale=0.5; input color Inp1DayColor=Red; input color InpShortTermColor=Gold; input color InpMediumTermColor=DeepPink; input color InpLongTermColor=Blue; int BinRangeScale=4; double LtBinRange=InpBinRange*BinRangeScale; // Bin range of price histogram //--- int PivotHour=4; // Pivot period (hour) //--- int d1_period=24*12; // for 5min int st_period = InpShortTermPeriod*24*12; // for 5min int mt_period = InpMediumTermPeriod*48; // for 30 int lt_period = InpLongTermPeriod*48; // for 1h //--- int zoom_out_factor=8; string prefix="PRICE_HISTGRAM_"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int deinit() { ObjectDelete(0,"V Line"); cleaningObj(prefix); return(0); } //+------------------------------------------------------------------+ //| 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 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) { //--- //--- the mouse has been clicked on the graphic object if(id==CHARTEVENT_CLICK) { //--- Prepare variables int x =(int)lparam; int y =(int)dparam; datetime dt =0; double price =0; int window=0; //--- Convert the X and Y coordinates in terms of date/time if(ChartXYToTimePrice(0,x,y,window,dt,price)) { //--- Perform reverse conversion: (X,Y) => (Time,Price) if(!ChartTimePriceToXY(0,window,dt,price,x,y)) return; // if(dtreturn; if(dt>TimeLocal()) return; //--- delete lines ObjectDelete(0,"V Line"); //--- create horizontal and vertical lines of the crosshair MqlDateTime tm; TimeToStruct(dt,tm); string datestr=StringFormat("%04d.%02d.%02d %02d:00",tm.year,tm.mon,tm.day,InpCalcTime); datetime t=StringToTime(datestr); generate_histgram(window,t); ObjectCreate(0,"V Line",OBJ_VLINE,window,t,price); ChartRedraw(0); } else return; } } //+------------------------------------------------------------------+ //| Short term peak line | //+------------------------------------------------------------------+ void draw_histgram(int window,datetime t,int offset,const int &d1_vh[],const int &st_vh[],const int &mt_vh[],const int <_vh[]) { int len=MathMin(ArraySize(d1_vh),ArraySize(st_vh)); if(len<1)return; cleaningObj(prefix); int i; int max=0; for(i=0;imax) max=st_vh[i]+d1_vh[i]; } int vline=iBarShift(NULL,Period(),t,false); int pos=vline+MathRound(max*InpDrawScale); //int pos=iBarShift(NULL,Period(),Time[zero],false); double p1,p2; for(i=0;i=0;j--) { int l =(int)MathRound(lo[j]/_Point); int h =(int)MathRound(hi[j]/_Point); int v=1; if(InpUsingVolumeWeight) { v=(int)MathRound(MathSqrt(MathMin(vol[j],1))); } int min = (int)MathRound((l-offset)/binRange); int max = (int)MathRound((h-offset)/binRange); int minZO = (int)MathRound((l-offset)/binRangeZO); int maxZO = (int)MathRound((h-offset)/binRangeZO); //--- for normal for(k=min;k<=max;k++)vh[k]+=v; //--- for zoomout for(k=minZO;k<=maxZO;k++)vhZO[k]+=v; } return(true); } //+------------------------------------------------------------------+ //| Delete all objects with given prefix | //+------------------------------------------------------------------+ void cleaningObj(string Prefix) { int L = StringLen(Prefix); int i = 0; while(i