//------------------------------------------------------------------ #property copyright "mladen" #property link "www.forex-tsd.com" //------------------------------------------------------------------ #property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 2 #property indicator_label1 "HA smoothed wick high;HA smoothed wick low" #property indicator_type1 DRAW_COLOR_HISTOGRAM2 #property indicator_color1 clrLimeGreen,clrPaleVioletRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 #property indicator_label2 "HA smoothed body high;HA smoothed body low" #property indicator_type2 DRAW_COLOR_HISTOGRAM2 #property indicator_color2 clrLimeGreen,clrPaleVioletRed #property indicator_style2 STYLE_SOLID #property indicator_width2 3 // // // // // enum enMaTypes { mt_sma, // Simple moving average mt_ema, // Exponential moving average mt_smma, // Smoothed MA mt_lwma // Linear weighted MA }; // // // // // input int HALength1 = 6; // Price smoothing period input enMaTypes HAType1 = mt_smma; // Price smoothing method input int HALength2 = 2; // Result smoothing period input enMaTypes HAType2 = mt_lwma; // Result smoothing method input bool AlertsOn = false; // Alerting input bool AlertsOnCurrent = true; // Alert on current bar input bool AlertsOnBody = true; // Alert on body color change input bool AlertsOnWick = true; // Alert on wick color change input bool AlertsMessage = true; // Show alert message input bool AlertsSound = false; // Play alert sound input bool AlertsEmail = false; // Send email message // // // // // double habh[]; double habl[]; double habc[]; double hawh[]; double hawl[]; double hawc[]; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int OnInit() { SetIndexBuffer(0,hawh,INDICATOR_DATA); SetIndexBuffer(1,hawl,INDICATOR_DATA); SetIndexBuffer(2,hawc,INDICATOR_COLOR_INDEX); SetIndexBuffer(3,habh,INDICATOR_DATA); SetIndexBuffer(4,habl,INDICATOR_DATA); SetIndexBuffer(5,habc,INDICATOR_COLOR_INDEX); return(0); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // double workHa[][4]; 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 (ArrayRange(workHa,0)!= rates_total) ArrayResize(workHa,rates_total); // // // // // for (int i=(int)MathMax(prev_calculated-1,0); i0) haOpen = (workHa[i-1][2] + workHa[i-1][3])/2.0; else haOpen = maOpen+maClose; double haClose = (maOpen + maHigh + maLow + maClose) / 4.0; double haHigh = MathMax(maHigh, MathMax(haOpen,haClose)); double haLow = MathMin(maLow , MathMin(haOpen,haClose)); if(haOpen < haClose) { workHa[i][0] = haLow; workHa[i][1] = haHigh; } else { workHa[i][0] = haHigh; workHa[i][1] = haLow; } workHa[i][2] = haOpen; workHa[i][3] = haClose; // // // // // hawh[i] = iMa(HAType2,workHa[i][0],HALength2,i,rates_total,4); hawl[i] = iMa(HAType2,workHa[i][1],HALength2,i,rates_total,5); habh[i] = iMa(HAType2,workHa[i][2],HALength2,i,rates_total,6); habl[i] = iMa(HAType2,workHa[i][3],HALength2,i,rates_total,7); if (i>0) { hawc[i]=hawc[i-1]; habc[i]=habc[i-1]; if (hawh[i]>hawl[i]) hawc[i] = 1; if (hawh[i]habl[i]) habc[i] = 1; if (habh[i]=period) workSma[r][instanceNo+1] = workSma[r-1][instanceNo+1]+(workSma[r][instanceNo]-workSma[r-period][instanceNo])/period; else { workSma[r][instanceNo+1] = 0; for(k=0; k=0; k++) workSma[r][instanceNo+1] += workSma[r-k][instanceNo]; workSma[r][instanceNo+1] /= k; } return(workSma[r][instanceNo+1]); } // // // // // double workEma[][_maWorkBufferx1]; double iEma(double price, double period, int r,int bars, int instanceNo=0) { if (ArrayRange(workEma,0)!= bars) ArrayResize(workEma,bars); // // // // // double alpha = 2.0 / (1.0+period); workEma[r][instanceNo] = workEma[r-1][instanceNo]+alpha*(price-workEma[r-1][instanceNo]); return(workEma[r][instanceNo]); } // // // // // double workSmma[][_maWorkBufferx1]; double iSmma(double price, double period, int r, int bars, int instanceNo=0) { if (ArrayRange(workSmma,0)!= bars) ArrayResize(workSmma,bars); // // // // // if (r=0; k++) { double weight = period-k; sumw += weight; sum += weight*workLwma[r-k][instanceNo]; } return(sum/sumw); }