//+------------------------------------------------------------------+ //| HistogramSample.mq5 | //+------------------------------------------------------------------+ #property copyright "TheXpert" #property link "TheForEXpert@gmail.com" #property version "1.00" //--- display the indicator in the main window #property indicator_chart_window //--- indicator settings #property indicator_buffers 2 #property indicator_plots 1 //--- plot 1 #property indicator_type1 DRAW_HISTOGRAM2 #property indicator_color1 clrRed //--- input parameters input int MaFast=5; // Fast MA input int MaSlow=20; // Slow MA //--- indicator buffers double Fast[]; double Slow[]; //--- indicator handles int FastHandle; int SlowHandle; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- bind indicator buffer SetIndexBuffer(0,Fast,INDICATOR_DATA); SetIndexBuffer(1,Slow,INDICATOR_DATA); //--- obtain the indicators handles FastHandle=iMA(NULL,0,MaFast,0,MODE_EMA,PRICE_CLOSE); SlowHandle=iMA(NULL,0,MaSlow,0,MODE_EMA,PRICE_CLOSE); } //+------------------------------------------------------------------+ //| 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[]) { //--- start variable for calculation of bars int start=prev_calculated; //--- if the bar is generated, recalculate the indicator value on it if(start>0) start--; //--- update the indicator when the new tick arrives if(start