//+------------------------------------------------------------------+ //| Price_HeatMap_v1.05.mq5 | //| Price HeatMap Copyright 2015, fxborg | //| http://blog.livedoor.jp/fxborg/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, fxborg" #property link "http://blog.livedoor.jp/fxborg/" #property version "1.05" #property indicator_chart_window #define PIP ((_Digits <= 3) ? 0.01 : 0.0001) #property indicator_buffers 47 #property indicator_plots 21 #property indicator_chart_window #property indicator_type1 DRAW_COLOR_ARROW #property indicator_type2 DRAW_COLOR_ARROW #property indicator_type3 DRAW_COLOR_ARROW #property indicator_type4 DRAW_COLOR_ARROW #property indicator_type5 DRAW_COLOR_ARROW #property indicator_type6 DRAW_COLOR_ARROW #property indicator_type7 DRAW_COLOR_ARROW #property indicator_type8 DRAW_COLOR_ARROW #property indicator_type9 DRAW_COLOR_ARROW #property indicator_type10 DRAW_COLOR_ARROW #property indicator_type11 DRAW_COLOR_ARROW #property indicator_type12 DRAW_COLOR_ARROW #property indicator_type13 DRAW_COLOR_ARROW #property indicator_type14 DRAW_COLOR_ARROW #property indicator_type15 DRAW_COLOR_ARROW #property indicator_type16 DRAW_COLOR_ARROW #property indicator_type17 DRAW_COLOR_ARROW #property indicator_type18 DRAW_COLOR_ARROW #property indicator_type19 DRAW_COLOR_ARROW #property indicator_type20 DRAW_COLOR_ARROW #property indicator_type21 DRAW_BARS #property indicator_color21 C'48,64,255' #property indicator_width1 10 #property indicator_width2 10 #property indicator_width3 10 #property indicator_width4 10 #property indicator_width5 10 #property indicator_width6 10 #property indicator_width7 10 #property indicator_width8 10 #property indicator_width9 10 #property indicator_width10 10 #property indicator_width11 10 #property indicator_width12 10 #property indicator_width13 10 #property indicator_width14 10 #property indicator_width15 10 #property indicator_width16 10 #property indicator_width17 10 #property indicator_width18 10 #property indicator_width19 10 #property indicator_width20 10 #property indicator_width21 2 input ENUM_TIMEFRAMES InpHistogramTF=PERIOD_M5; // Histgram Time Frame input int InpPeriod=180; // HistGramPeriod input double InpBinRange=5.0; //BinRange input bool InpShowBars=true; // ShowBars input int InpColorPattern=1; // 1:Green 2:Blue int AvgVolPeriod=100; double Hst1Buf[]; double Hst2Buf[]; double Hst3Buf[]; double Hst4Buf[]; double Hst5Buf[]; double Hst6Buf[]; double Hst7Buf[]; double Hst8Buf[]; double Hst9Buf[]; double Hst10Buf[]; double Hst11Buf[]; double Hst12Buf[]; double Hst13Buf[]; double Hst14Buf[]; double Hst15Buf[]; double Hst16Buf[]; double Hst17Buf[]; double Hst18Buf[]; double Hst19Buf[]; double Hst20Buf[]; double Col1Buf[]; double Col2Buf[]; double Col3Buf[]; double Col4Buf[]; double Col5Buf[]; double Col6Buf[]; double Col7Buf[]; double Col8Buf[]; double Col9Buf[]; double Col10Buf[]; double Col11Buf[]; double Col12Buf[]; double Col13Buf[]; double Col14Buf[]; double Col15Buf[]; double Col16Buf[]; double Col17Buf[]; double Col18Buf[]; double Col19Buf[]; double Col20Buf[]; double VolBuf[]; double OpenBuf[]; double HighBuf[]; double LowBuf[]; double CloseBuf[]; double CandleColBuf[]; double CheckBuf[]; int min_rates_total; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(PeriodSeconds(PERIOD_CURRENT)0) { peak_j=peaks[0]; max_hist=hist[peak_j]; } //--- VolBuf[i]=(double)tick_volume[i]; //--- if(min_rates_total+AvgVolPeriod>=i) continue; long avg=0; //--- for(int k=0;k20) { if(peak_j>-1) pos=(int)MathMax(0,peak_j-5); else pos=(int)MathRound((imax-20)/2); } //--- for(int j=1;j<=20;j++) { int col=0; double peak=EMPTY_VALUE; if(pos=0;j--) { int l =(int)MathRound(lo[j]/PIP); int h =(int)MathRound(hi[j]/PIP); int v=(int)MathRound(MathSqrt(MathMin(vol[j],1))); int min = (int)MathRound((l-offset)/binRange); int max = (int)MathRound((h-offset)/binRange); //--- for normal for(k=min;k<=max;k++)hist[k]+=v; } //--- find peaks int work[][2]; //--- find peaks int peak_count=find_peaks(work,hist,steps,binRange); ArrayResize(peaks,0,peak_count); int top=0; int cnt=0; for(j=peak_count-1;j>=0;j--) { if(j==(peak_count-1))top=work[j][0]; if(work[j][0]>top*0.1) { cnt++; ArrayResize(peaks,cnt,peak_count); peaks[cnt-1]=work[j][1]; } } return (true); } //+------------------------------------------------------------------+ //| Find peaks | //+------------------------------------------------------------------+ int find_peaks(int &peaks[][2],const int &hist[],int steps,double binrange) { if(steps<=10) { ArrayResize(peaks,1); peaks[0][1] = ArrayMaximum(hist); peaks[0][0] =hist[peaks[0][1]]; return 1; } int count=0; for(int i=2;i1) { ArraySort(peaks); } //--- return(count); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void setPlotColor(int plot) { PlotIndexSetInteger(plot,PLOT_COLOR_INDEXES,26); //Set number of colors //Specify colors in loop int n=0; for(int i=0;i<=12;i++) { if(InpColorPattern==2) PlotIndexSetInteger(plot,PLOT_LINE_COLOR,n++,toRGB(100+i*13,0,153+int(MathRound(i*8.5)))); else PlotIndexSetInteger(plot,PLOT_LINE_COLOR,n++,toRGB(100+i*13,153+int(MathRound(i*8.5)),0)); } for(int i=1;i<=13;i++) { if(InpColorPattern==2) PlotIndexSetInteger(plot,PLOT_LINE_COLOR,n++,toRGB(255,0,255-i*15)); else PlotIndexSetInteger(plot,PLOT_LINE_COLOR,n++,toRGB(255,255-i*15,0)); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ color toRGB(int r,int g,int b) { r=MathMin(255,MathMax(0,r)); g=MathMin(255,MathMax(0,g)); b=MathMin(255,MathMax(0,b)); return StringToColor(IntegerToString(r)+","+IntegerToString(g)+","+IntegerToString(b)); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void setEmptyValue(int i) { Hst1Buf[i]=EMPTY_VALUE; Hst2Buf[i]=EMPTY_VALUE; Hst3Buf[i]=EMPTY_VALUE; Hst4Buf[i]=EMPTY_VALUE; Hst5Buf[i]=EMPTY_VALUE; Hst6Buf[i]=EMPTY_VALUE; Hst7Buf[i]=EMPTY_VALUE; Hst8Buf[i]=EMPTY_VALUE; Hst9Buf[i]=EMPTY_VALUE; Hst10Buf[i]=EMPTY_VALUE; Hst11Buf[i]=EMPTY_VALUE; Hst12Buf[i]=EMPTY_VALUE; Hst13Buf[i]=EMPTY_VALUE; Hst14Buf[i]=EMPTY_VALUE; Hst15Buf[i]=EMPTY_VALUE; Hst16Buf[i]=EMPTY_VALUE; Hst17Buf[i]=EMPTY_VALUE; Hst18Buf[i]=EMPTY_VALUE; Hst19Buf[i]=EMPTY_VALUE; Hst20Buf[i]=EMPTY_VALUE; //--- Col1Buf[i]=0; Col2Buf[i]=0; Col3Buf[i]=0; Col4Buf[i]=0; Col5Buf[i]=0; Col6Buf[i]=0; Col7Buf[i]=0; Col8Buf[i]=0; Col9Buf[i]=0; Col10Buf[i]=0; Col11Buf[i]=0; Col12Buf[i]=0; Col13Buf[i]=0; Col14Buf[i]=0; Col15Buf[i]=0; Col16Buf[i]=0; Col17Buf[i]=0; Col18Buf[i]=0; Col19Buf[i]=0; Col20Buf[i]=0; } //+------------------------------------------------------------------+