//------------------------------------------------------------------ // // original idea and tradestation code by John Ehlers // this version by mladen // #property copyright "www.forex-station.com" #property link "www.forex-station.com" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 5 #property indicator_label1 "BP Strong up" #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrLimeGreen #property indicator_width1 2 #property indicator_label2 "BP Weak up" #property indicator_type2 DRAW_HISTOGRAM #property indicator_color2 clrLimeGreen #property indicator_label3 "BP Strong down" #property indicator_type3 DRAW_HISTOGRAM #property indicator_color3 clrPaleVioletRed #property indicator_width3 2 #property indicator_label4 "BP weak down" #property indicator_type4 DRAW_HISTOGRAM #property indicator_color4 clrPaleVioletRed #property indicator_label5 "Band pass filter" #property indicator_type5 DRAW_LINE #property indicator_color5 clrDarkGray #property indicator_width5 2 #property indicator_level1 0 #property strict // // // // // enum enPrices { pr_close, // Close pr_open, // Open pr_high, // High pr_low, // Low pr_median, // Median pr_typical, // Typical pr_weighted, // Weighted pr_average, // Average (high+low+open+close)/4 pr_medianb, // Average median body (open+close)/2 pr_tbiased, // Trend biased price pr_tbiased2, // Trend biased (extreme) price pr_haclose, // Heiken ashi close pr_haopen , // Heiken ashi open pr_hahigh, // Heiken ashi high pr_halow, // Heiken ashi low pr_hamedian, // Heiken ashi median pr_hatypical, // Heiken ashi typical pr_haweighted, // Heiken ashi weighted pr_haaverage, // Heiken ashi average pr_hamedianb, // Heiken ashi median body pr_hatbiased, // Heiken ashi trend biased price pr_hatbiased2, // Heiken ashi trend biased (extreme) price pr_habclose, // Heiken ashi (better formula) close pr_habopen , // Heiken ashi (better formula) open pr_habhigh, // Heiken ashi (better formula) high pr_hablow, // Heiken ashi (better formula) low pr_habmedian, // Heiken ashi (better formula) median pr_habtypical, // Heiken ashi (better formula) typical pr_habweighted,// Heiken ashi (better formula) weighted pr_habaverage, // Heiken ashi (better formula) average pr_habmedianb, // Heiken ashi (better formula) median body pr_habtbiased, // Heiken ashi (better formula) trend biased price pr_habtbiased2 // Heiken ashi (better formula) trend biased (extreme) price }; input int BandPassPeriod = 50; input enPrices Price = pr_median; // Price to use input double Delta = 0.1; double bphuu[],bphud[],bphdd[],bphdu[],bp[],prices[],slope[],trend[]; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int OnInit() { IndicatorDigits(_Digits); IndicatorBuffers(8); SetIndexBuffer(0,bphuu, INDICATOR_DATA); SetIndexBuffer(1,bphud, INDICATOR_DATA); SetIndexBuffer(2,bphdd, INDICATOR_DATA); SetIndexBuffer(3,bphdu, INDICATOR_DATA); SetIndexBuffer(4,bp, INDICATOR_DATA); SetIndexBuffer(5,prices,INDICATOR_CALCULATIONS); SetIndexBuffer(6,slope, INDICATOR_CALCULATIONS); SetIndexBuffer(7,trend, INDICATOR_CALCULATIONS); IndicatorShortName("Band pass "+(string)BandPassPeriod+","+DoubleToStr(Delta,2)+")"); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ } //+------------------------------------------------------------------+ //| Band pass Oscillator | //+------------------------------------------------------------------+ // // 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[]) { int i,counted_bars=prev_calculated; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit = fmin(rates_total-counted_bars,rates_total-1); // // // // // double beta = cos(2.0*M_PI/BandPassPeriod); double gamma = 1.0 / cos(4.0*M_PI*Delta/BandPassPeriod); double alpha = gamma - sqrt(gamma*gamma-1.0); for(i=limit; i>=0; i--) { prices[i] = getPrice(Price,open,close,high,low,i,rates_total); bp[i] = (ibp[i+1]) ? 1 : (bp[i]0) ? 1 : (bp[i]<0) ? -1 : trend[i+1] : 0; bphuu[i] = (trend[i] == 1 && slope[i] == 1) ? bp[i] : EMPTY_VALUE; bphud[i] = (trend[i] == 1 && slope[i] ==-1) ? bp[i] : EMPTY_VALUE; bphdd[i] = (trend[i] ==-1 && slope[i] ==-1) ? bp[i] : EMPTY_VALUE; bphdu[i] = (trend[i] ==-1 && slope[i] == 1) ? bp[i] : EMPTY_VALUE; } return(rates_total); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // #define _prHABF(_prtype) (_prtype>=pr_habclose && _prtype<=pr_habtbiased2) #define _priceInstances 1 #define _priceInstancesSize 4 double workHa[][_priceInstances*_priceInstancesSize]; double getPrice(int tprice, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars, int instanceNo=0) { if (tprice>=pr_haclose) { if (ArrayRange(workHa,0)!= bars) ArrayResize(workHa,bars); instanceNo*=_priceInstancesSize; int r = bars-i-1; // // // // // double haOpen = (r>0) ? (workHa[r-1][instanceNo+2] + workHa[r-1][instanceNo+3])/2.0 : (open[i]+close[i])/2;; double haClose = (open[i]+high[i]+low[i]+close[i]) / 4.0; if (_prHABF(tprice)) if (high[i]!=low[i]) haClose = (open[i]+close[i])/2.0+(((close[i]-open[i])/(high[i]-low[i]))*fabs((close[i]-open[i])/2.0)); else haClose = (open[i]+close[i])/2.0; double haHigh = fmax(high[i], fmax(haOpen,haClose)); double haLow = fmin(low[i] , fmin(haOpen,haClose)); // // // // // if(haOpenhaOpen) return((haHigh+haClose)/2.0); else return((haLow+haClose)/2.0); case pr_hatbiased2: case pr_habtbiased2: if (haClose>haOpen) return(haHigh); if (haCloseopen[i]) return((high[i]+close[i])/2.0); else return((low[i]+close[i])/2.0); case pr_tbiased2: if (close[i]>open[i]) return(high[i]); if (close[i]