//+------------------------------------------------------------------ #property copyright "mladen" #property link "mladenfx@gmail.com" #property link "https://www.mql5.com" #property description "Hull trend" //+------------------------------------------------------------------ #property indicator_chart_window #property indicator_buffers 14 #property indicator_plots 3 #property indicator_label1 "Hull trend bars" #property indicator_type1 DRAW_COLOR_BARS #property indicator_color1 clrDarkGray,clrDeepSkyBlue,clrSandyBrown #property indicator_label2 "Hull trend candles" #property indicator_type2 DRAW_COLOR_CANDLES #property indicator_color2 clrDarkGray,clrDeepSkyBlue,clrSandyBrown #property indicator_label3 "Hull trend line" #property indicator_type3 DRAW_COLOR_LINE #property indicator_color3 clrDarkGray,clrDeepSkyBlue,clrSandyBrown #property indicator_width3 2 // //--- input parameters // enum enDisplayStyle { dis_automatic, // Automatic display style dis_line, // Display line dis_bars, // Display bars dis_candles // Display candles }; input int inpPeriod = 20; // Hull period input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Price input enDisplayStyle inpDisplayStyle = dis_automatic; // Display style // //--- buffers and global variables declarations // double canh[],canl[],cano[],canc[],cancl[],baro[],barh[],barl[],barc[],barcl[],line[],linecl[],hull[],hullcl[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,baro,INDICATOR_DATA); SetIndexBuffer(1,barh,INDICATOR_DATA); SetIndexBuffer(2,barl,INDICATOR_DATA); SetIndexBuffer(3,barc,INDICATOR_DATA); SetIndexBuffer(4,barcl,INDICATOR_COLOR_INDEX); SetIndexBuffer(5,cano,INDICATOR_DATA); SetIndexBuffer(6,canh,INDICATOR_DATA); SetIndexBuffer(7,canl,INDICATOR_DATA); SetIndexBuffer(8,canc,INDICATOR_DATA); SetIndexBuffer(9,cancl,INDICATOR_COLOR_INDEX); SetIndexBuffer(10,line,INDICATOR_DATA); SetIndexBuffer(11,linecl,INDICATOR_COLOR_INDEX); SetIndexBuffer(12,hull,INDICATOR_CALCULATIONS); SetIndexBuffer(13,hullcl,INDICATOR_CALCULATIONS); //--- IndicatorSetString(INDICATOR_SHORTNAME,"Hull trend ("+(string)inpPeriod+")"); return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator de-initialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ #define displayLine 0 #define displayBars 1 #define displayCandle 2 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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[]) { if(Bars(_Symbol,_Period)0) ? (hull[i]>hull[i-1]) ? 1 : (hull[i]=0; k++) { weight = HalfPeriod-k; hmw += weight; hma += weight*workHull[r-k][instanceNo]; } workHull[r][instanceNo+1]=2.0*hma/hmw; hmw=HmaPeriod; hma=hmw*price; for(int k=1; k=0; k++) { weight = HmaPeriod-k; hmw += weight; hma += weight*workHull[r-k][instanceNo]; } workHull[r][instanceNo+1]-=hma/hmw; hmw=HullPeriod; hma=hmw*workHull[r][instanceNo+1]; for(int k=1; k=0; k++) { weight = HullPeriod-k; hmw += weight; hma += weight*workHull[r-k][1+instanceNo]; } return(hma/hmw); } // //--- // double getPrice(ENUM_APPLIED_PRICE tprice,const double &open[],const double &close[],const double &high[],const double &low[],int i,int _bars) { switch(tprice) { case PRICE_CLOSE: return(close[i]); case PRICE_OPEN: return(open[i]); case PRICE_HIGH: return(high[i]); case PRICE_LOW: return(low[i]); case PRICE_MEDIAN: return((high[i]+low[i])/2.0); case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0); case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0); } return(0); } //+------------------------------------------------------------------+